require namespaces to be declared only in files named Android.bp

Bug: 65683273
Test: m -j nothing # which runs unit tests

Change-Id: I5edf0e0482809f5ac9fb9dfff342fb404e1c52da
This commit is contained in:
Jeff Gaston
2017-11-30 16:46:47 -08:00
parent 44c0cd8543
commit 5c3886de5a
2 changed files with 54 additions and 16 deletions

View File

@@ -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)