require namespaces to be declared only in files named Android.bp
Bug: 65683273
Test: m -j nothing # which runs unit tests
Change-Id: I5edf0e0482809f5ac9fb9dfff342fb404e1c52da
diff --git a/android/namespace.go b/android/namespace.go
index a2ff1a6..b3e718a 100644
--- a/android/namespace.go
+++ b/android/namespace.go
@@ -15,6 +15,7 @@
package android
import (
+ "errors"
"fmt"
"path/filepath"
"sort"
@@ -114,7 +115,13 @@
return namespace
}
-func (r *NameResolver) addNewNamespaceForModule(module *NamespaceModule, dir string) error {
+func (r *NameResolver) addNewNamespaceForModule(module *NamespaceModule, path string) error {
+ fileName := filepath.Base(path)
+ if fileName != "Android.bp" {
+ return errors.New("A namespace may only be declared in a file named Android.bp")
+ }
+ dir := filepath.Dir(path)
+
namespace := r.newNamespace(dir)
module.namespace = namespace
module.resolver = r
@@ -167,7 +174,7 @@
// if this module is a namespace, then save it to our list of namespaces
newNamespace, ok := module.(*NamespaceModule)
if ok {
- err := r.addNewNamespaceForModule(newNamespace, ctx.ModuleDir())
+ err := r.addNewNamespaceForModule(newNamespace, ctx.ModulePath())
if err != nil {
return nil, []error{err}
}
@@ -322,7 +329,7 @@
}
func (r *NameResolver) findNamespaceFromCtx(ctx blueprint.NamespaceContext) *Namespace {
- return r.findNamespace(ctx.ModuleDir())
+ return r.findNamespace(filepath.Dir(ctx.ModulePath()))
}
var _ blueprint.NameInterface = (*NameResolver)(nil)