diff options
author | 2017-11-30 16:46:47 -0800 | |
---|---|---|
committer | 2017-12-04 17:44:32 -0800 | |
commit | 5c3886de5a1eabb81e7d166a86c29ca324dabf49 (patch) | |
tree | d98c6eb7d8f55b49d19d3a5b4d5e81e135019a08 /android/namespace.go | |
parent | 44c0cd85435d7c90cbf6d5f930a64edac15b42ee (diff) |
require namespaces to be declared only in files named Android.bp
Bug: 65683273
Test: m -j nothing # which runs unit tests
Change-Id: I5edf0e0482809f5ac9fb9dfff342fb404e1c52da
Diffstat (limited to 'android/namespace.go')
-rw-r--r-- | android/namespace.go | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/android/namespace.go b/android/namespace.go index a2ff1a692..b3e718af3 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 @@ func (r *NameResolver) newNamespace(path string) *Namespace { 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 @@ func (r *NameResolver) NewModule(ctx blueprint.NamespaceContext, moduleGroup blu // 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) GetNamespace(ctx blueprint.NamespaceContext) blueprint.Na } 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) |