diff options
author | Colin Cross <ccross@android.com> | 2018-04-16 13:58:10 -0700 |
---|---|---|
committer | Colin Cross <ccross@android.com> | 2018-04-16 21:38:15 +0000 |
commit | eafb10c23a77432329678917ed6453e9d1c15abe (patch) | |
tree | 9640ce8eff24905253dc392afab01a34f1582fcf /android/namespace_test.go | |
parent | 8f9ab6a26b16dacb319c746a0e07152e34cdc372 (diff) | |
download | build_soong-eafb10c23a77432329678917ed6453e9d1c15abe.tar.gz build_soong-eafb10c23a77432329678917ed6453e9d1c15abe.tar.bz2 build_soong-eafb10c23a77432329678917ed6453e9d1c15abe.zip |
Fix module rename inside namespace
Rename was expecting fully qualified names, but context.go always
passes it short names.
Bug: 77922456
Test: TestRename in namespace_test.go
Change-Id: I552ff39fd8ed6ba6da4262925060b45104840ff7
Diffstat (limited to 'android/namespace_test.go')
-rw-r--r-- | android/namespace_test.go | 38 |
1 files changed, 36 insertions, 2 deletions
diff --git a/android/namespace_test.go b/android/namespace_test.go index 8bec0add..9a791a53 100644 --- a/android/namespace_test.go +++ b/android/namespace_test.go @@ -582,6 +582,25 @@ func TestConsistentNamespaceNames(t *testing.T) { } } +// so that the generated .ninja file will have consistent names +func TestRename(t *testing.T) { + _ = setupTest(t, + map[string]string{ + "dir1": ` + soong_namespace { + } + test_module { + name: "a", + deps: ["c"], + } + test_module { + name: "b", + rename: "c", + } + `}) + // setupTest will report any errors +} + // some utils to support the tests func mockFiles(bps map[string]string) (files map[string][]byte) { @@ -607,6 +626,9 @@ func setupTestFromFiles(bps map[string][]byte) (ctx *TestContext, errs []error) ctx.RegisterModuleType("test_module", ModuleFactoryAdaptor(newTestModule)) ctx.RegisterModuleType("soong_namespace", ModuleFactoryAdaptor(NamespaceFactory)) ctx.PreArchMutators(RegisterNamespaceMutator) + ctx.PreDepsMutators(func(ctx RegisterMutatorsContext) { + ctx.BottomUp("rename", renameMutator) + }) ctx.Register() _, errs = ctx.ParseBlueprintsFiles("Android.bp") @@ -672,12 +694,16 @@ func findModuleById(ctx *TestContext, id string) (module TestingModule) { type testModule struct { ModuleBase properties struct { - Deps []string - Id string + Rename string + Deps []string + Id string } } func (m *testModule) DepsMutator(ctx BottomUpMutatorContext) { + if m.properties.Rename != "" { + ctx.Rename(m.properties.Rename) + } for _, d := range m.properties.Deps { ctx.AddDependency(ctx.Module(), nil, d) } @@ -686,6 +712,14 @@ func (m *testModule) DepsMutator(ctx BottomUpMutatorContext) { func (m *testModule) GenerateAndroidBuildActions(ModuleContext) { } +func renameMutator(ctx BottomUpMutatorContext) { + if m, ok := ctx.Module().(*testModule); ok { + if m.properties.Rename != "" { + ctx.Rename(m.properties.Rename) + } + } +} + func newTestModule() Module { m := &testModule{} m.AddProperties(&m.properties) |