From dbd4809b0680bb807785148577bcbe07ece9ea90 Mon Sep 17 00:00:00 2001 From: Liz Kammer Date: Mon, 21 Sep 2020 22:24:17 +0000 Subject: [PATCH] Enable defaults in soong_config_module_type props Test: go tests Test: m Change-Id: I8fe8c17320086034f4745b2da974a2c73c949eaf --- android/defaults.go | 2 + android/soong_config_modules_test.go | 87 +++++++++++++++++++++++++--- 2 files changed, 82 insertions(+), 7 deletions(-) diff --git a/android/defaults.go b/android/defaults.go index 0892adfac..eb013d7ab 100644 --- a/android/defaults.go +++ b/android/defaults.go @@ -95,6 +95,8 @@ func InitDefaultableModule(module DefaultableModule) { module.setProperties(module.(Module).GetProperties(), module.(Module).base().variableProperties) module.AddProperties(module.defaults()) + + module.base().customizableProperties = module.GetProperties() } // A restricted subset of context methods, similar to LoadHookContext. diff --git a/android/soong_config_modules_test.go b/android/soong_config_modules_test.go index f0f14626e..3cd8c22f3 100644 --- a/android/soong_config_modules_test.go +++ b/android/soong_config_modules_test.go @@ -19,8 +19,24 @@ import ( "testing" ) +type soongConfigTestDefaultsModuleProperties struct { +} + +type soongConfigTestDefaultsModule struct { + ModuleBase + DefaultsModuleBase +} + +func soongConfigTestDefaultsModuleFactory() Module { + m := &soongConfigTestDefaultsModule{} + m.AddProperties(&soongConfigTestModuleProperties{}) + InitDefaultsModule(m) + return m +} + type soongConfigTestModule struct { ModuleBase + DefaultableModuleBase props soongConfigTestModuleProperties } @@ -32,6 +48,7 @@ func soongConfigTestModuleFactory() Module { m := &soongConfigTestModule{} m.AddProperties(&m.props) InitAndroidModule(m) + InitDefaultableModule(m) return m } @@ -41,13 +58,13 @@ func TestSoongConfigModule(t *testing.T) { t.Parallel() configBp := ` soong_config_module_type { - name: "acme_test_defaults", - module_type: "test_defaults", + name: "acme_test", + module_type: "test", config_namespace: "acme", variables: ["board", "feature1", "FEATURE3"], bool_variables: ["feature2"], value_variables: ["size"], - properties: ["cflags", "srcs"], + properties: ["cflags", "srcs", "defaults"], } soong_config_string_variable { @@ -67,14 +84,20 @@ func TestSoongConfigModule(t *testing.T) { importBp := ` soong_config_module_type_import { from: "SoongConfig.bp", - module_types: ["acme_test_defaults"], + module_types: ["acme_test"], } ` bp := ` - acme_test_defaults { + test_defaults { + name: "foo_defaults", + cflags: ["DEFAULT"], + } + + acme_test { name: "foo", cflags: ["-DGENERIC"], + defaults: ["foo_defaults"], soong_config_variables: { board: { soc_a: { @@ -98,6 +121,46 @@ func TestSoongConfigModule(t *testing.T) { }, }, } + + test_defaults { + name: "foo_defaults_a", + cflags: ["DEFAULT_A"], + } + + test_defaults { + name: "foo_defaults_b", + cflags: ["DEFAULT_B"], + } + + acme_test { + name: "foo_with_defaults", + cflags: ["-DGENERIC"], + defaults: ["foo_defaults"], + soong_config_variables: { + board: { + soc_a: { + cflags: ["-DSOC_A"], + defaults: ["foo_defaults_a"], + }, + soc_b: { + cflags: ["-DSOC_B"], + defaults: ["foo_defaults_b"], + }, + }, + size: { + cflags: ["-DSIZE=%s"], + }, + feature1: { + cflags: ["-DFEATURE1"], + }, + feature2: { + cflags: ["-DFEATURE2"], + }, + FEATURE3: { + cflags: ["-DFEATURE3"], + }, + }, + } ` run := func(t *testing.T, bp string, fs map[string][]byte) { @@ -118,7 +181,9 @@ func TestSoongConfigModule(t *testing.T) { ctx.RegisterModuleType("soong_config_module_type", soongConfigModuleTypeFactory) ctx.RegisterModuleType("soong_config_string_variable", soongConfigStringVariableDummyFactory) ctx.RegisterModuleType("soong_config_bool_variable", soongConfigBoolVariableDummyFactory) - ctx.RegisterModuleType("test_defaults", soongConfigTestModuleFactory) + ctx.RegisterModuleType("test_defaults", soongConfigTestDefaultsModuleFactory) + ctx.RegisterModuleType("test", soongConfigTestModuleFactory) + ctx.PreArchMutators(RegisterDefaultsPreArchMutators) ctx.Register(config) _, errs := ctx.ParseBlueprintsFiles("Android.bp") @@ -126,10 +191,18 @@ func TestSoongConfigModule(t *testing.T) { _, errs = ctx.PrepareBuildActions(config) FailIfErrored(t, errs) + basicCFlags := []string{"DEFAULT", "-DGENERIC", "-DSIZE=42", "-DSOC_A", "-DFEATURE1"} + foo := ctx.ModuleForTests("foo", "").Module().(*soongConfigTestModule) - if g, w := foo.props.Cflags, []string{"-DGENERIC", "-DSIZE=42", "-DSOC_A", "-DFEATURE1"}; !reflect.DeepEqual(g, w) { + if g, w := foo.props.Cflags, basicCFlags; !reflect.DeepEqual(g, w) { t.Errorf("wanted foo cflags %q, got %q", w, g) } + + fooDefaults := ctx.ModuleForTests("foo_with_defaults", "").Module().(*soongConfigTestModule) + if g, w := fooDefaults.props.Cflags, append([]string{"DEFAULT_A"}, basicCFlags...); !reflect.DeepEqual(g, w) { + t.Errorf("wanted foo_with_defaults cflags %q, got %q", w, g) + } + } t.Run("single file", func(t *testing.T) {