Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ddde9e29 authored by Cole Faust's avatar Cole Faust Committed by Gerrit Code Review
Browse files

Merge "Add the ability to select on arch" into main

parents 2f42ae62 0aa21cc8
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -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
+8 −0
Original line number Diff line number Diff line
@@ -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
}
+8 −1
Original line number Diff line number Diff line
@@ -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")
+5 −0
Original line number Diff line number Diff line
@@ -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,
+22 −3
Original line number Diff line number Diff line
@@ -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
}