diff options
Diffstat (limited to 'android/module.go')
-rw-r--r-- | android/module.go | 112 |
1 files changed, 76 insertions, 36 deletions
diff --git a/android/module.go b/android/module.go index 89c4ddde9..5fe379c8a 100644 --- a/android/module.go +++ b/android/module.go @@ -29,7 +29,6 @@ import ( "android/soong/bazel" "github.com/google/blueprint" - "github.com/google/blueprint/parser" "github.com/google/blueprint/proptools" ) @@ -1043,12 +1042,12 @@ func (m *ModuleBase) baseDepsMutator(ctx BottomUpMutatorContext) { pv := ctx.Config().productVariables fullManifest := pv.DeviceArch != nil && pv.DeviceName != nil if fullManifest { - m.addRequiredDeps(ctx) + addRequiredDeps(ctx) } } // addRequiredDeps adds required, target_required, and host_required as dependencies. -func (m *ModuleBase) addRequiredDeps(ctx BottomUpMutatorContext) { +func addRequiredDeps(ctx BottomUpMutatorContext) { addDep := func(target Target, depName string) { if !ctx.OtherModuleExists(depName) { if ctx.Config().AllowMissingDependencies() { @@ -1061,9 +1060,9 @@ func (m *ModuleBase) addRequiredDeps(ctx BottomUpMutatorContext) { // in build/make/core/main.mk. // TODO(jiyong): the Make-side does this only when the required module is a shared // library or a native test. - bothInAndroid := m.Device() && target.Os.Class == Device - nativeArch := InList(m.Arch().ArchType.Multilib, []string{"lib32", "lib64"}) - sameBitness := m.Arch().ArchType.Multilib == target.Arch.ArchType.Multilib + bothInAndroid := ctx.Device() && target.Os.Class == Device + nativeArch := InList(ctx.Arch().ArchType.Multilib, []string{"lib32", "lib64"}) + sameBitness := ctx.Arch().ArchType.Multilib == target.Arch.ArchType.Multilib if bothInAndroid && nativeArch && !sameBitness { return } @@ -1082,31 +1081,31 @@ func (m *ModuleBase) addRequiredDeps(ctx BottomUpMutatorContext) { hostTargets = append(hostTargets, ctx.Config().Targets[ctx.Config().BuildOS]...) hostTargets = append(hostTargets, ctx.Config().BuildOSCommonTarget) - if m.Device() { - for _, depName := range m.RequiredModuleNames() { + if ctx.Device() { + for _, depName := range ctx.Module().RequiredModuleNames() { for _, target := range deviceTargets { addDep(target, depName) } } - for _, depName := range m.HostRequiredModuleNames() { + for _, depName := range ctx.Module().HostRequiredModuleNames() { for _, target := range hostTargets { addDep(target, depName) } } } - if m.Host() { - for _, depName := range m.RequiredModuleNames() { + if ctx.Host() { + for _, depName := range ctx.Module().RequiredModuleNames() { for _, target := range hostTargets { // When a host module requires another host module, don't make a // dependency if they have different OSes (i.e. hostcross). - if m.Target().HostCross != target.HostCross { + if ctx.Target().HostCross != target.HostCross { continue } addDep(target, depName) } } - for _, depName := range m.TargetRequiredModuleNames() { + for _, depName := range ctx.Module().TargetRequiredModuleNames() { for _, target := range deviceTargets { addDep(target, depName) } @@ -2140,41 +2139,82 @@ func (e configurationEvalutor) PropertyErrorf(property string, fmt string, args e.ctx.OtherModulePropertyErrorf(e.m, property, fmt, args) } -func (e configurationEvalutor) EvaluateConfiguration(ty parser.SelectType, property, condition string) (string, bool) { +func (e configurationEvalutor) EvaluateConfiguration(condition proptools.ConfigurableCondition, property string) proptools.ConfigurableValue { ctx := e.ctx m := e.m - switch ty { - case parser.SelectTypeReleaseVariable: - if v, ok := ctx.Config().productVariables.BuildFlags[condition]; ok { - return v, true + switch condition.FunctionName { + case "release_variable": + if len(condition.Args) != 1 { + ctx.OtherModulePropertyErrorf(m, property, "release_variable requires 1 argument, found %d", len(condition.Args)) + return proptools.ConfigurableValueUndefined() + } + if v, ok := ctx.Config().productVariables.BuildFlags[condition.Args[0]]; ok { + return proptools.ConfigurableValueString(v) } - return "", false - case parser.SelectTypeProductVariable: + return proptools.ConfigurableValueUndefined() + case "product_variable": // TODO(b/323382414): Might add these on a case-by-case basis ctx.OtherModulePropertyErrorf(m, property, "TODO(b/323382414): Product variables are not yet supported in selects") - return "", false - case parser.SelectTypeSoongConfigVariable: - parts := strings.Split(condition, ":") - namespace := parts[0] - variable := parts[1] + return proptools.ConfigurableValueUndefined() + case "soong_config_variable": + if len(condition.Args) != 2 { + ctx.OtherModulePropertyErrorf(m, property, "soong_config_variable requires 2 arguments, found %d", len(condition.Args)) + return proptools.ConfigurableValueUndefined() + } + namespace := condition.Args[0] + variable := condition.Args[1] if n, ok := ctx.Config().productVariables.VendorVars[namespace]; ok { if v, ok := n[variable]; ok { - return v, true + return proptools.ConfigurableValueString(v) } } - return "", false - case parser.SelectTypeVariant: - if condition == "arch" { - if !m.base().ArchReady() { - ctx.OtherModulePropertyErrorf(m, property, "A select on arch was attempted before the arch mutator ran") - return "", false + return proptools.ConfigurableValueUndefined() + case "arch": + if len(condition.Args) != 0 { + ctx.OtherModulePropertyErrorf(m, property, "arch requires no arguments, found %d", len(condition.Args)) + return proptools.ConfigurableValueUndefined() + } + if !m.base().ArchReady() { + ctx.OtherModulePropertyErrorf(m, property, "A select on arch was attempted before the arch mutator ran") + return proptools.ConfigurableValueUndefined() + } + return proptools.ConfigurableValueString(m.base().Arch().ArchType.Name) + case "os": + if len(condition.Args) != 0 { + ctx.OtherModulePropertyErrorf(m, property, "os requires no arguments, found %d", len(condition.Args)) + return proptools.ConfigurableValueUndefined() + } + // the arch mutator runs after the os mutator, we can just use this to enforce that os is ready. + if !m.base().ArchReady() { + ctx.OtherModulePropertyErrorf(m, property, "A select on os was attempted before the arch mutator ran (arch runs after os, we use it to lazily detect that os is ready)") + return proptools.ConfigurableValueUndefined() + } + return proptools.ConfigurableValueString(m.base().Os().Name) + case "boolean_var_for_testing": + // We currently don't have any other boolean variables (we should add support for typing + // the soong config variables), so add this fake one for testing the boolean select + // functionality. + if len(condition.Args) != 0 { + ctx.OtherModulePropertyErrorf(m, property, "boolean_var_for_testing requires 0 arguments, found %d", len(condition.Args)) + return proptools.ConfigurableValueUndefined() + } + + if n, ok := ctx.Config().productVariables.VendorVars["boolean_var"]; ok { + if v, ok := n["for_testing"]; ok { + switch v { + case "true": + return proptools.ConfigurableValueBool(true) + case "false": + return proptools.ConfigurableValueBool(false) + default: + ctx.OtherModulePropertyErrorf(m, property, "testing:my_boolean_var can only be true or false, found %q", v) + } } - return m.base().Arch().ArchType.Name, true } - ctx.OtherModulePropertyErrorf(m, property, "Unknown variant %s", condition) - return "", false + return proptools.ConfigurableValueUndefined() default: - panic("Should be unreachable") + ctx.OtherModulePropertyErrorf(m, property, "Unknown select condition %s", condition.FunctionName) + return proptools.ConfigurableValueUndefined() } } |