Merge "Fix module rename inside namespace" into pi-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
0f7e692fff
@@ -255,22 +255,7 @@ func (r *NameResolver) ModuleFromName(name string, namespace blueprint.Namespace
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *NameResolver) Rename(oldName string, newName string, namespace blueprint.Namespace) []error {
|
func (r *NameResolver) Rename(oldName string, newName string, namespace blueprint.Namespace) []error {
|
||||||
oldNs := r.findNamespace(oldName)
|
return namespace.(*Namespace).moduleContainer.Rename(oldName, newName, namespace)
|
||||||
newNs := r.findNamespace(newName)
|
|
||||||
if oldNs != newNs {
|
|
||||||
return []error{fmt.Errorf("cannot rename %v to %v because the destination is outside namespace %v", oldName, newName, oldNs.Path)}
|
|
||||||
}
|
|
||||||
|
|
||||||
oldName, err := filepath.Rel(oldNs.Path, oldName)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
newName, err = filepath.Rel(newNs.Path, newName)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return oldNs.moduleContainer.Rename(oldName, newName, nil)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// resolve each element of namespace.importedNamespaceNames and put the result in namespace.visibleNamespaces
|
// resolve each element of namespace.importedNamespaceNames and put the result in namespace.visibleNamespaces
|
||||||
|
@@ -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
|
// some utils to support the tests
|
||||||
|
|
||||||
func mockFiles(bps map[string]string) (files map[string][]byte) {
|
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("test_module", ModuleFactoryAdaptor(newTestModule))
|
||||||
ctx.RegisterModuleType("soong_namespace", ModuleFactoryAdaptor(NamespaceFactory))
|
ctx.RegisterModuleType("soong_namespace", ModuleFactoryAdaptor(NamespaceFactory))
|
||||||
ctx.PreArchMutators(RegisterNamespaceMutator)
|
ctx.PreArchMutators(RegisterNamespaceMutator)
|
||||||
|
ctx.PreDepsMutators(func(ctx RegisterMutatorsContext) {
|
||||||
|
ctx.BottomUp("rename", renameMutator)
|
||||||
|
})
|
||||||
ctx.Register()
|
ctx.Register()
|
||||||
|
|
||||||
_, errs = ctx.ParseBlueprintsFiles("Android.bp")
|
_, errs = ctx.ParseBlueprintsFiles("Android.bp")
|
||||||
@@ -672,12 +694,16 @@ func findModuleById(ctx *TestContext, id string) (module TestingModule) {
|
|||||||
type testModule struct {
|
type testModule struct {
|
||||||
ModuleBase
|
ModuleBase
|
||||||
properties struct {
|
properties struct {
|
||||||
|
Rename string
|
||||||
Deps []string
|
Deps []string
|
||||||
Id string
|
Id string
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *testModule) DepsMutator(ctx BottomUpMutatorContext) {
|
func (m *testModule) DepsMutator(ctx BottomUpMutatorContext) {
|
||||||
|
if m.properties.Rename != "" {
|
||||||
|
ctx.Rename(m.properties.Rename)
|
||||||
|
}
|
||||||
for _, d := range m.properties.Deps {
|
for _, d := range m.properties.Deps {
|
||||||
ctx.AddDependency(ctx.Module(), nil, d)
|
ctx.AddDependency(ctx.Module(), nil, d)
|
||||||
}
|
}
|
||||||
@@ -686,6 +712,14 @@ func (m *testModule) DepsMutator(ctx BottomUpMutatorContext) {
|
|||||||
func (m *testModule) GenerateAndroidBuildActions(ModuleContext) {
|
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 {
|
func newTestModule() Module {
|
||||||
m := &testModule{}
|
m := &testModule{}
|
||||||
m.AddProperties(&m.properties)
|
m.AddProperties(&m.properties)
|
||||||
|
Reference in New Issue
Block a user