diff options
author | Cole Faust <colefaust@google.com> | 2024-03-26 17:36:37 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2024-03-26 17:36:37 +0000 |
commit | ddde9e29a477ed46d14411c4d252df50e68ee114 (patch) | |
tree | 180631eb8476041e3cf081e1d14edb43cadbab23 | |
parent | 2f42ae62eae587ee36dd6de6e504e6c6e2aaf6df (diff) | |
parent | 0aa21cc8e2183a13452fce4b7e3a69813fe2a1fd (diff) | |
download | soong-ddde9e29a477ed46d14411c4d252df50e68ee114.tar.gz |
Merge "Add the ability to select on arch" into main
-rw-r--r-- | android/arch.go | 1 | ||||
-rw-r--r-- | android/arch_module_context.go | 8 | ||||
-rw-r--r-- | android/base_module_context.go | 9 | ||||
-rw-r--r-- | android/module.go | 5 | ||||
-rw-r--r-- | android/selects_test.go | 25 |
5 files changed, 44 insertions, 4 deletions
diff --git a/android/arch.go b/android/arch.go index 4fe434502..9e79e3175 100644 --- a/android/arch.go +++ b/android/arch.go @@ -693,6 +693,7 @@ func addTargetProperties(m Module, target Target, multiTargets []Target, primary m.base().commonProperties.CompileTarget = target m.base().commonProperties.CompileMultiTargets = multiTargets m.base().commonProperties.CompilePrimary = primaryTarget + m.base().commonProperties.ArchReady = true } // decodeMultilib returns the appropriate compile_multilib property for the module, or the default diff --git a/android/arch_module_context.go b/android/arch_module_context.go index 3cf4b4115..a3a03af02 100644 --- a/android/arch_module_context.go +++ b/android/arch_module_context.go @@ -35,6 +35,7 @@ type ArchModuleContext interface { type archModuleContext struct { // TODO: these should eventually go through a (possibly cached) provider like any other configuration instead // of being special cased. + ready bool os OsType target Target targetPrimary bool @@ -42,6 +43,13 @@ type archModuleContext struct { primaryArch bool } +// ArchReady returns true if the arch mutator has run on the module. Before this returns +// true, the module essentially doesn't have an arch and cannot make decisions based on +// architecture. +func (a *archModuleContext) ArchReady() bool { + return a.ready +} + func (a *archModuleContext) Target() Target { return a.target } diff --git a/android/base_module_context.go b/android/base_module_context.go index 9be3fad9a..3367b0669 100644 --- a/android/base_module_context.go +++ b/android/base_module_context.go @@ -599,7 +599,14 @@ func (m *baseModuleContext) EvaluateConfiguration(ty parser.SelectType, conditio } return "", false case parser.SelectTypeVariant: - m.ModuleErrorf("TODO(b/323382414): Variants are not yet supported in selects") + if condition == "arch" { + if !m.ArchReady() { + m.ModuleErrorf("A select on arch was attempted before the arch mutator ran") + return "", false + } + return m.Arch().ArchType.Name, true + } + m.ModuleErrorf("Unknown variant " + condition) return "", false default: panic("Should be unreachable") diff --git a/android/module.go b/android/module.go index cce4fa6cb..c0597fafb 100644 --- a/android/module.go +++ b/android/module.go @@ -433,6 +433,10 @@ type commonProperties struct { // Set by osMutator CompileOS OsType `blueprint:"mutated"` + // Set to true after the arch mutator has run on this module and set CompileTarget, + // CompileMultiTargets, and CompilePrimary + ArchReady bool `blueprint:"mutated"` + // The Target of artifacts that this module variant is responsible for creating. // // Set by archMutator @@ -1749,6 +1753,7 @@ func (m *ModuleBase) archModuleContextFactory(ctx blueprint.IncomingTransitionCo } return archModuleContext{ + ready: m.commonProperties.ArchReady, os: m.commonProperties.CompileOS, target: m.commonProperties.CompileTarget, targetPrimary: m.commonProperties.CompilePrimary, diff --git a/android/selects_test.go b/android/selects_test.go index aa9c521a2..b4e226f4b 100644 --- a/android/selects_test.go +++ b/android/selects_test.go @@ -231,11 +231,30 @@ func TestSelects(t *testing.T) { my_string: proptools.StringPtr("c.cpp"), }, }, + { + name: "Select on variant", + bp: ` + my_module_type { + name: "foo", + my_string: select(variant("arch"), { + "x86": "my_x86", + "x86_64": "my_x86_64", + "arm": "my_arm", + "arm64": "my_arm64", + _: "my_default", + }), + } + `, + provider: selectsTestProvider{ + my_string: proptools.StringPtr("my_arm64"), + }, + }, } for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { fixtures := GroupFixturePreparers( + PrepareForTestWithArchMutator, FixtureRegisterWithContext(func(ctx RegistrationContext) { ctx.RegisterModuleType("my_module_type", newSelectsMockModule) }), @@ -249,8 +268,8 @@ func TestSelects(t *testing.T) { result := fixtures.RunTestWithBp(t, tc.bp) if tc.expectedError == "" { - m := result.ModuleForTests("foo", "") - p, _ := OtherModuleProvider[selectsTestProvider](result.testContext.OtherModuleProviderAdaptor(), m.Module(), selectsTestProviderKey) + m := result.ModuleForTests("foo", "android_arm64_armv8-a") + p, _ := OtherModuleProvider(result.testContext.OtherModuleProviderAdaptor(), m.Module(), selectsTestProviderKey) if !reflect.DeepEqual(p, tc.provider) { t.Errorf("Expected:\n %q\ngot:\n %q", tc.provider.String(), p.String()) } @@ -310,7 +329,7 @@ func (p *selectsMockModule) GenerateAndroidBuildActions(ctx ModuleContext) { func newSelectsMockModule() Module { m := &selectsMockModule{} m.AddProperties(&m.properties) - InitAndroidArchModule(m, HostAndDeviceSupported, MultilibCommon) + InitAndroidArchModule(m, HostAndDeviceSupported, MultilibFirst) InitDefaultableModule(m) return m } |