Merge "Export OsTypeList through a function." am: d7d72398d5

Original change: https://android-review.googlesource.com/c/platform/build/soong/+/1664302

Change-Id: I503c635420dfcfe61301d85151615e59d6020011
This commit is contained in:
Jingwen Chen
2021-04-07 06:00:35 +00:00
committed by Automerger Merge Worker
2 changed files with 15 additions and 9 deletions

View File

@@ -167,7 +167,8 @@ func newArch(name, multilib string) ArchType {
return 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 { func ArchTypeList() []ArchType {
return append([]ArchType(nil), archTypeList...) return append([]ArchType(nil), archTypeList...)
} }
@@ -266,7 +267,7 @@ func newOsType(name string, class OsClass, defDisabled bool, archTypes ...ArchTy
DefaultDisabled: defDisabled, DefaultDisabled: defDisabled,
} }
OsTypeList = append(OsTypeList, os) osTypeList = append(osTypeList, os)
if _, found := commonTargetMap[name]; found { if _, found := commonTargetMap[name]; found {
panic(fmt.Errorf("Found Os type duplicate during OsType registration: %q", name)) 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. // osByName returns the OsType that has the given name, or NoOsType if none match.
func osByName(name string) OsType { func osByName(name string) OsType {
for _, os := range OsTypeList { for _, os := range osTypeList {
if os.Name == name { if os.Name == name {
return os return os
} }
@@ -312,9 +313,9 @@ var BuildArch = func() ArchType {
}() }()
var ( 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. // 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 // commonTargetMap maps names of OsTypes to the corresponding common Target, i.e. the
// Target with the same OsType and the common ArchType. // Target with the same OsType and the common ArchType.
commonTargetMap = make(map[string]Target) commonTargetMap = make(map[string]Target)
@@ -347,6 +348,11 @@ var (
CommonArch = Arch{ArchType: Common} 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. // Target specifies the OS and architecture that a module is being compiled for.
type Target struct { type Target struct {
// Os the OS that the module is being compiled for (e.g. "linux_glibc", "android"). // 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 // 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. // passed to InitAndroidArchModule and the device_supported and host_supported properties.
var moduleOSList []OsType var moduleOSList []OsType
for _, os := range OsTypeList { for _, os := range osTypeList {
for _, t := range mctx.Config().Targets[os] { for _, t := range mctx.Config().Targets[os] {
if base.supportsTarget(t) { if base.supportsTarget(t) {
moduleOSList = append(moduleOSList, os) moduleOSList = append(moduleOSList, os)
@@ -838,7 +844,7 @@ func createArchPropTypeDesc(props reflect.Type) []archPropTypeDesc {
"Arm_on_x86_64", "Arm_on_x86_64",
"Native_bridge", "Native_bridge",
} }
for _, os := range OsTypeList { for _, os := range osTypeList {
// Add all the OSes. // Add all the OSes.
targets = append(targets, os.Field) targets = append(targets, os.Field)
@@ -1742,7 +1748,7 @@ func (m *ModuleBase) GetTargetProperties(dst interface{}) map[OsType]interface{}
} }
// Iterate over the supported OS types // Iterate over the supported OS types
for _, os := range OsTypeList { for _, os := range osTypeList {
// e.g android, linux_bionic // e.g android, linux_bionic
field := os.Field field := os.Field

View File

@@ -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. // Compute the list of possible os types that this sdk could support.
func (s *sdk) getPossibleOsTypes() []android.OsType { func (s *sdk) getPossibleOsTypes() []android.OsType {
var osTypes []android.OsType var osTypes []android.OsType
for _, osType := range android.OsTypeList { for _, osType := range android.OsTypeList() {
if s.DeviceSupported() { if s.DeviceSupported() {
if osType.Class == android.Device && osType != android.Fuchsia { if osType.Class == android.Device && osType != android.Fuchsia {
osTypes = append(osTypes, osType) osTypes = append(osTypes, osType)