Merge "Allow namespace config to be tested properly" am: 73d394dec2
Original change: https://android-review.googlesource.com/c/platform/build/soong/+/2292017 Change-Id: I0209340278dfca4abe0fe6c13a070dde783b8820 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
commit
38a5a9e80e
5 changed files with 75 additions and 25 deletions
|
@ -658,7 +658,7 @@ func (t *TestPathContext) AddNinjaFileDeps(deps ...string) {
|
||||||
|
|
||||||
func createFixture(t *testing.T, buildDir string, preparers []*simpleFixturePreparer) Fixture {
|
func createFixture(t *testing.T, buildDir string, preparers []*simpleFixturePreparer) Fixture {
|
||||||
config := TestConfig(buildDir, nil, "", nil)
|
config := TestConfig(buildDir, nil, "", nil)
|
||||||
ctx := NewTestContext(config)
|
ctx := newTestContextForFixture(config)
|
||||||
fixture := &fixture{
|
fixture := &fixture{
|
||||||
preparers: preparers,
|
preparers: preparers,
|
||||||
t: t,
|
t: t,
|
||||||
|
@ -790,6 +790,16 @@ func (f *fixture) RunTest() *TestResult {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Create and set the Context's NameInterface. It needs to be created here as it depends on the
|
||||||
|
// configuration that has been prepared for this fixture.
|
||||||
|
resolver := NewNameResolver(ctx.config)
|
||||||
|
|
||||||
|
// Set the NameInterface in the main Context.
|
||||||
|
ctx.SetNameInterface(resolver)
|
||||||
|
|
||||||
|
// Set the NameResolver in the TestContext.
|
||||||
|
ctx.NameResolver = resolver
|
||||||
|
|
||||||
ctx.Register()
|
ctx.Register()
|
||||||
var ninjaDeps []string
|
var ninjaDeps []string
|
||||||
extraNinjaDeps, errs := ctx.ParseBlueprintsFiles("ignored")
|
extraNinjaDeps, errs := ctx.ParseBlueprintsFiles("ignored")
|
||||||
|
|
|
@ -91,7 +91,27 @@ type NameResolver struct {
|
||||||
namespaceExportFilter func(*Namespace) bool
|
namespaceExportFilter func(*Namespace) bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewNameResolver(namespaceExportFilter func(*Namespace) bool) *NameResolver {
|
// NameResolverConfig provides the subset of the Config interface needed by the
|
||||||
|
// NewNameResolver function.
|
||||||
|
type NameResolverConfig interface {
|
||||||
|
// ExportedNamespaces is the list of namespaces that Soong must export to
|
||||||
|
// make.
|
||||||
|
ExportedNamespaces() []string
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewNameResolver(config NameResolverConfig) *NameResolver {
|
||||||
|
namespacePathsToExport := make(map[string]bool)
|
||||||
|
|
||||||
|
for _, namespaceName := range config.ExportedNamespaces() {
|
||||||
|
namespacePathsToExport[namespaceName] = true
|
||||||
|
}
|
||||||
|
|
||||||
|
namespacePathsToExport["."] = true // always export the root namespace
|
||||||
|
|
||||||
|
namespaceExportFilter := func(namespace *Namespace) bool {
|
||||||
|
return namespacePathsToExport[namespace.Path]
|
||||||
|
}
|
||||||
|
|
||||||
r := &NameResolver{
|
r := &NameResolver{
|
||||||
namespacesByDir: sync.Map{},
|
namespacesByDir: sync.Map{},
|
||||||
namespaceExportFilter: namespaceExportFilter,
|
namespaceExportFilter: namespaceExportFilter,
|
||||||
|
|
|
@ -602,6 +602,36 @@ func TestRename(t *testing.T) {
|
||||||
// RunTest will report any errors
|
// RunTest will report any errors
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestNamespace_Exports(t *testing.T) {
|
||||||
|
result := GroupFixturePreparers(
|
||||||
|
prepareForTestWithNamespace,
|
||||||
|
FixtureModifyProductVariables(func(variables FixtureProductVariables) {
|
||||||
|
variables.NamespacesToExport = []string{"dir1"}
|
||||||
|
}),
|
||||||
|
dirBpToPreparer(map[string]string{
|
||||||
|
"dir1": `
|
||||||
|
soong_namespace {
|
||||||
|
}
|
||||||
|
test_module {
|
||||||
|
name: "a",
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
"dir2": `
|
||||||
|
soong_namespace {
|
||||||
|
}
|
||||||
|
test_module {
|
||||||
|
name: "b",
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
}),
|
||||||
|
).RunTest(t)
|
||||||
|
|
||||||
|
aModule := result.Module("a", "")
|
||||||
|
AssertBoolEquals(t, "a exported", true, aModule.ExportedToMake())
|
||||||
|
bModule := result.Module("b", "")
|
||||||
|
AssertBoolEquals(t, "b not exported", false, bModule.ExportedToMake())
|
||||||
|
}
|
||||||
|
|
||||||
// some utils to support the tests
|
// some utils to support the tests
|
||||||
|
|
||||||
var prepareForTestWithNamespace = GroupFixturePreparers(
|
var prepareForTestWithNamespace = GroupFixturePreparers(
|
||||||
|
|
|
@ -30,19 +30,11 @@ import (
|
||||||
"github.com/google/blueprint/proptools"
|
"github.com/google/blueprint/proptools"
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewTestContext(config Config) *TestContext {
|
func newTestContextForFixture(config Config) *TestContext {
|
||||||
namespaceExportFilter := func(namespace *Namespace) bool {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
nameResolver := NewNameResolver(namespaceExportFilter)
|
|
||||||
ctx := &TestContext{
|
ctx := &TestContext{
|
||||||
Context: &Context{blueprint.NewContext(), config},
|
Context: &Context{blueprint.NewContext(), config},
|
||||||
NameResolver: nameResolver,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.SetNameInterface(nameResolver)
|
|
||||||
|
|
||||||
ctx.postDeps = append(ctx.postDeps, registerPathDepsMutator)
|
ctx.postDeps = append(ctx.postDeps, registerPathDepsMutator)
|
||||||
|
|
||||||
ctx.SetFs(ctx.config.fs)
|
ctx.SetFs(ctx.config.fs)
|
||||||
|
@ -53,6 +45,16 @@ func NewTestContext(config Config) *TestContext {
|
||||||
return ctx
|
return ctx
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func NewTestContext(config Config) *TestContext {
|
||||||
|
ctx := newTestContextForFixture(config)
|
||||||
|
|
||||||
|
nameResolver := NewNameResolver(config)
|
||||||
|
ctx.NameResolver = nameResolver
|
||||||
|
ctx.SetNameInterface(nameResolver)
|
||||||
|
|
||||||
|
return ctx
|
||||||
|
}
|
||||||
|
|
||||||
var PrepareForTestWithArchMutator = GroupFixturePreparers(
|
var PrepareForTestWithArchMutator = GroupFixturePreparers(
|
||||||
// Configure architecture targets in the fixture config.
|
// Configure architecture targets in the fixture config.
|
||||||
FixtureModifyConfig(modifyTestConfigToSupportArchMutator),
|
FixtureModifyConfig(modifyTestConfigToSupportArchMutator),
|
||||||
|
|
|
@ -106,19 +106,7 @@ func init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func newNameResolver(config android.Config) *android.NameResolver {
|
func newNameResolver(config android.Config) *android.NameResolver {
|
||||||
namespacePathsToExport := make(map[string]bool)
|
return android.NewNameResolver(config)
|
||||||
|
|
||||||
for _, namespaceName := range config.ExportedNamespaces() {
|
|
||||||
namespacePathsToExport[namespaceName] = true
|
|
||||||
}
|
|
||||||
|
|
||||||
namespacePathsToExport["."] = true // always export the root namespace
|
|
||||||
|
|
||||||
exportFilter := func(namespace *android.Namespace) bool {
|
|
||||||
return namespacePathsToExport[namespace.Path]
|
|
||||||
}
|
|
||||||
|
|
||||||
return android.NewNameResolver(exportFilter)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func newContext(configuration android.Config) *android.Context {
|
func newContext(configuration android.Config) *android.Context {
|
||||||
|
|
Loading…
Reference in a new issue