From 2f6a21e9570c77e942ff989bf4791b3ae14aea23 Mon Sep 17 00:00:00 2001 From: Jingwen Chen Date: Mon, 5 Apr 2021 07:33:05 +0000 Subject: [PATCH] Export OsTypeList through a function. This is a cleanup CL to make the OsTypeList accessor consistent with ArchTypeList by creating a function that creates a copy of the underlying slice. Test: TH Change-Id: I346c5c3937bbdb8a373e4d7135b896a5274cc1f1 --- android/arch.go | 22 ++++++++++++++-------- sdk/update.go | 2 +- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/android/arch.go b/android/arch.go index 3eff5d5e0..6826f3b0b 100644 --- a/android/arch.go +++ b/android/arch.go @@ -167,7 +167,8 @@ func newArch(name, multilib string) ArchType { return archType } -// ArchTypeList returns the 4 supported ArchTypes for arm, arm64, x86 and x86_64. +// ArchTypeList returns the a slice copy of the 4 supported ArchTypes for arm, +// arm64, x86 and x86_64. func ArchTypeList() []ArchType { return append([]ArchType(nil), archTypeList...) } @@ -266,7 +267,7 @@ func newOsType(name string, class OsClass, defDisabled bool, archTypes ...ArchTy DefaultDisabled: defDisabled, } - OsTypeList = append(OsTypeList, os) + osTypeList = append(osTypeList, os) if _, found := commonTargetMap[name]; found { panic(fmt.Errorf("Found Os type duplicate during OsType registration: %q", name)) @@ -280,7 +281,7 @@ func newOsType(name string, class OsClass, defDisabled bool, archTypes ...ArchTy // osByName returns the OsType that has the given name, or NoOsType if none match. func osByName(name string) OsType { - for _, os := range OsTypeList { + for _, os := range osTypeList { if os.Name == name { return os } @@ -312,9 +313,9 @@ var BuildArch = func() ArchType { }() var ( - // OsTypeList contains a list of all the supported OsTypes, including ones not supported + // osTypeList contains a list of all the supported OsTypes, including ones not supported // by the current build host or the target device. - OsTypeList []OsType + osTypeList []OsType // commonTargetMap maps names of OsTypes to the corresponding common Target, i.e. the // Target with the same OsType and the common ArchType. commonTargetMap = make(map[string]Target) @@ -347,6 +348,11 @@ var ( CommonArch = Arch{ArchType: Common} ) +// OsTypeList returns a slice copy of the supported OsTypes. +func OsTypeList() []OsType { + return append([]OsType(nil), osTypeList...) +} + // Target specifies the OS and architecture that a module is being compiled for. type Target struct { // Os the OS that the module is being compiled for (e.g. "linux_glibc", "android"). @@ -448,7 +454,7 @@ func osMutator(bpctx blueprint.BottomUpMutatorContext) { // Collect a list of OSTypes supported by this module based on the HostOrDevice value // passed to InitAndroidArchModule and the device_supported and host_supported properties. var moduleOSList []OsType - for _, os := range OsTypeList { + for _, os := range osTypeList { for _, t := range mctx.Config().Targets[os] { if base.supportsTarget(t) { moduleOSList = append(moduleOSList, os) @@ -838,7 +844,7 @@ func createArchPropTypeDesc(props reflect.Type) []archPropTypeDesc { "Arm_on_x86_64", "Native_bridge", } - for _, os := range OsTypeList { + for _, os := range osTypeList { // Add all the OSes. targets = append(targets, os.Field) @@ -1742,7 +1748,7 @@ func (m *ModuleBase) GetTargetProperties(dst interface{}) map[OsType]interface{} } // Iterate over the supported OS types - for _, os := range OsTypeList { + for _, os := range osTypeList { // e.g android, linux_bionic field := os.Field diff --git a/sdk/update.go b/sdk/update.go index 828c7b67d..522a8887d 100644 --- a/sdk/update.go +++ b/sdk/update.go @@ -1350,7 +1350,7 @@ func (s *sdk) createMemberSnapshot(ctx *memberContext, member *sdkMember, bpModu // Compute the list of possible os types that this sdk could support. func (s *sdk) getPossibleOsTypes() []android.OsType { var osTypes []android.OsType - for _, osType := range android.OsTypeList { + for _, osType := range android.OsTypeList() { if s.DeviceSupported() { if osType.Class == android.Device && osType != android.Fuchsia { osTypes = append(osTypes, osType)