2017-11-30 01:47:17 +01:00
// Copyright 2017 Google Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package android
import (
"path/filepath"
2017-12-02 02:10:33 +01:00
"reflect"
2017-11-30 01:47:17 +01:00
"testing"
"github.com/google/blueprint"
)
func TestDependingOnModuleInSameNamespace ( t * testing . T ) {
2021-07-06 23:36:33 +02:00
result := GroupFixturePreparers (
prepareForTestWithNamespace ,
dirBpToPreparer ( map [ string ] string {
2017-11-30 01:47:17 +01:00
"dir1" : `
2021-07-06 23:36:33 +02:00
soong_namespace {
}
test_module {
name : "a" ,
}
test_module {
name : "b" ,
deps : [ "a" ] ,
}
2017-11-30 01:47:17 +01:00
` ,
2021-07-06 23:36:33 +02:00
} ) ,
) . RunTest ( t )
2017-11-30 01:47:17 +01:00
2021-07-06 23:36:33 +02:00
a := getModule ( result , "a" )
b := getModule ( result , "b" )
if ! dependsOn ( result , b , a ) {
2017-11-30 01:47:17 +01:00
t . Errorf ( "module b does not depend on module a in the same namespace" )
}
}
func TestDependingOnModuleInRootNamespace ( t * testing . T ) {
2021-07-06 23:36:33 +02:00
result := GroupFixturePreparers (
prepareForTestWithNamespace ,
dirBpToPreparer ( map [ string ] string {
2017-11-30 01:47:17 +01:00
"." : `
2021-07-06 23:36:33 +02:00
test_module {
name : "b" ,
deps : [ "a" ] ,
}
test_module {
name : "a" ,
}
2017-11-30 01:47:17 +01:00
` ,
2021-07-06 23:36:33 +02:00
} ) ,
) . RunTest ( t )
2017-11-30 01:47:17 +01:00
2021-07-06 23:36:33 +02:00
a := getModule ( result , "a" )
b := getModule ( result , "b" )
if ! dependsOn ( result , b , a ) {
2017-11-30 01:47:17 +01:00
t . Errorf ( "module b in root namespace does not depend on module a in the root namespace" )
}
}
func TestImplicitlyImportRootNamespace ( t * testing . T ) {
2021-07-06 23:36:33 +02:00
GroupFixturePreparers (
prepareForTestWithNamespace ,
dirBpToPreparer ( map [ string ] string {
2017-11-30 01:47:17 +01:00
"." : `
2021-07-06 23:36:33 +02:00
test_module {
name : "a" ,
}
2017-11-30 01:47:17 +01:00
` ,
"dir1" : `
2021-07-06 23:36:33 +02:00
soong_namespace {
}
test_module {
name : "b" ,
deps : [ "a" ] ,
}
2017-11-30 01:47:17 +01:00
` ,
2021-07-06 23:36:33 +02:00
} ) ,
) . RunTest ( t )
2017-11-30 01:47:17 +01:00
2021-07-06 23:36:33 +02:00
// RunTest will report any errors
2017-11-30 01:47:17 +01:00
}
2019-06-14 20:26:09 +02:00
func TestDependingOnBlueprintModuleInRootNamespace ( t * testing . T ) {
2021-07-06 23:36:33 +02:00
GroupFixturePreparers (
prepareForTestWithNamespace ,
dirBpToPreparer ( map [ string ] string {
2019-06-14 20:26:09 +02:00
"." : `
2021-07-06 23:36:33 +02:00
blueprint_test_module {
name : "a" ,
}
2019-06-14 20:26:09 +02:00
` ,
"dir1" : `
2021-07-06 23:36:33 +02:00
soong_namespace {
}
blueprint_test_module {
name : "b" ,
deps : [ "a" ] ,
}
2019-06-14 20:26:09 +02:00
` ,
2021-07-06 23:36:33 +02:00
} ) ,
) . RunTest ( t )
2019-06-14 20:26:09 +02:00
2021-07-06 23:36:33 +02:00
// RunTest will report any errors
2019-06-14 20:26:09 +02:00
}
2017-11-30 01:47:17 +01:00
func TestDependingOnModuleInImportedNamespace ( t * testing . T ) {
2021-07-06 23:36:33 +02:00
result := GroupFixturePreparers (
prepareForTestWithNamespace ,
dirBpToPreparer ( map [ string ] string {
2017-11-30 01:47:17 +01:00
"dir1" : `
2021-07-06 23:36:33 +02:00
soong_namespace {
}
test_module {
name : "a" ,
}
2017-11-30 01:47:17 +01:00
` ,
"dir2" : `
2021-07-06 23:36:33 +02:00
soong_namespace {
imports : [ "dir1" ] ,
}
test_module {
name : "b" ,
deps : [ "a" ] ,
}
2017-11-30 01:47:17 +01:00
` ,
2021-07-06 23:36:33 +02:00
} ) ,
) . RunTest ( t )
2017-11-30 01:47:17 +01:00
2021-07-06 23:36:33 +02:00
a := getModule ( result , "a" )
b := getModule ( result , "b" )
if ! dependsOn ( result , b , a ) {
2017-11-30 01:47:17 +01:00
t . Errorf ( "module b does not depend on module a in the same namespace" )
}
}
func TestDependingOnModuleInNonImportedNamespace ( t * testing . T ) {
2021-07-06 23:36:33 +02:00
GroupFixturePreparers (
prepareForTestWithNamespace ,
dirBpToPreparer ( map [ string ] string {
2017-11-30 01:47:17 +01:00
"dir1" : `
2021-07-06 23:36:33 +02:00
soong_namespace {
}
test_module {
name : "a" ,
}
2017-11-30 01:47:17 +01:00
` ,
"dir2" : `
2021-07-06 23:36:33 +02:00
soong_namespace {
}
test_module {
name : "a" ,
}
2017-11-30 01:47:17 +01:00
` ,
"dir3" : `
2021-07-06 23:36:33 +02:00
soong_namespace {
}
test_module {
name : "b" ,
deps : [ "a" ] ,
}
2017-11-30 01:47:17 +01:00
` ,
2021-07-06 23:36:33 +02:00
} ) ,
) .
2023-03-31 22:48:42 +02:00
ExtendWithErrorHandler ( FixtureExpectsOneErrorPattern ( ` \ Qdir3 / Android . bp : 4 : 5 : "b" depends on undefined module "a" .
2017-11-30 01:47:17 +01:00
Module "b" is defined in namespace "dir3" which can read these 2 namespaces : [ "dir3" "." ]
2023-03-31 22:48:42 +02:00
Module "a" can be found in these namespaces : [ "dir1" "dir2" ] \ E
Or did you mean [ "soong_namespace" ] ? ` ) ) .
2021-07-06 23:36:33 +02:00
RunTest ( t )
2017-11-30 01:47:17 +01:00
}
func TestDependingOnModuleByFullyQualifiedReference ( t * testing . T ) {
2021-07-06 23:36:33 +02:00
result := GroupFixturePreparers (
prepareForTestWithNamespace ,
dirBpToPreparer ( map [ string ] string {
2017-11-30 01:47:17 +01:00
"dir1" : `
2021-07-06 23:36:33 +02:00
soong_namespace {
}
test_module {
name : "a" ,
}
2017-11-30 01:47:17 +01:00
` ,
"dir2" : `
2021-07-06 23:36:33 +02:00
soong_namespace {
}
test_module {
name : "b" ,
deps : [ "//dir1:a" ] ,
}
2017-11-30 01:47:17 +01:00
` ,
2021-07-06 23:36:33 +02:00
} ) ,
) . RunTest ( t )
a := getModule ( result , "a" )
b := getModule ( result , "b" )
if ! dependsOn ( result , b , a ) {
2017-11-30 01:47:17 +01:00
t . Errorf ( "module b does not depend on module a" )
}
}
func TestSameNameInTwoNamespaces ( t * testing . T ) {
2021-07-06 23:36:33 +02:00
result := GroupFixturePreparers (
prepareForTestWithNamespace ,
dirBpToPreparer ( map [ string ] string {
2017-11-30 01:47:17 +01:00
"dir1" : `
2021-07-06 23:36:33 +02:00
soong_namespace {
}
test_module {
name : "a" ,
id : "1" ,
}
test_module {
name : "b" ,
deps : [ "a" ] ,
id : "2" ,
}
2017-11-30 01:47:17 +01:00
` ,
"dir2" : `
2021-07-06 23:36:33 +02:00
soong_namespace {
}
test_module {
name : "a" ,
id : "3" ,
}
test_module {
name : "b" ,
deps : [ "a" ] ,
id : "4" ,
}
2017-11-30 01:47:17 +01:00
` ,
2021-07-06 23:36:33 +02:00
} ) ,
) . RunTest ( t )
2017-11-30 01:47:17 +01:00
2021-07-06 23:36:33 +02:00
one := findModuleById ( result , "1" )
two := findModuleById ( result , "2" )
three := findModuleById ( result , "3" )
four := findModuleById ( result , "4" )
if ! dependsOn ( result , two , one ) {
2017-11-30 01:47:17 +01:00
t . Fatalf ( "Module 2 does not depend on module 1 in its namespace" )
}
2021-07-06 23:36:33 +02:00
if dependsOn ( result , two , three ) {
2017-11-30 01:47:17 +01:00
t . Fatalf ( "Module 2 depends on module 3 in another namespace" )
}
2021-07-06 23:36:33 +02:00
if ! dependsOn ( result , four , three ) {
2017-11-30 01:47:17 +01:00
t . Fatalf ( "Module 4 does not depend on module 3 in its namespace" )
}
2021-07-06 23:36:33 +02:00
if dependsOn ( result , four , one ) {
2017-11-30 01:47:17 +01:00
t . Fatalf ( "Module 4 depends on module 1 in another namespace" )
}
}
func TestSearchOrder ( t * testing . T ) {
2021-07-06 23:36:33 +02:00
result := GroupFixturePreparers (
prepareForTestWithNamespace ,
dirBpToPreparer ( map [ string ] string {
2017-11-30 01:47:17 +01:00
"dir1" : `
2021-07-06 23:36:33 +02:00
soong_namespace {
}
test_module {
name : "a" ,
id : "1" ,
}
2017-11-30 01:47:17 +01:00
` ,
"dir2" : `
2021-07-06 23:36:33 +02:00
soong_namespace {
}
test_module {
name : "a" ,
id : "2" ,
}
test_module {
name : "b" ,
id : "3" ,
}
2017-11-30 01:47:17 +01:00
` ,
"dir3" : `
2021-07-06 23:36:33 +02:00
soong_namespace {
}
test_module {
name : "a" ,
id : "4" ,
}
test_module {
name : "b" ,
id : "5" ,
}
test_module {
name : "c" ,
id : "6" ,
}
2017-11-30 01:47:17 +01:00
` ,
"." : `
2021-07-06 23:36:33 +02:00
test_module {
name : "a" ,
id : "7" ,
}
test_module {
name : "b" ,
id : "8" ,
}
test_module {
name : "c" ,
id : "9" ,
}
test_module {
name : "d" ,
id : "10" ,
}
2017-11-30 01:47:17 +01:00
` ,
"dir4" : `
2021-07-06 23:36:33 +02:00
soong_namespace {
imports : [ "dir1" , "dir2" , "dir3" ]
}
test_module {
name : "test_me" ,
id : "0" ,
deps : [ "a" , "b" , "c" , "d" ] ,
}
2017-11-30 01:47:17 +01:00
` ,
2021-07-06 23:36:33 +02:00
} ) ,
) . RunTest ( t )
2017-11-30 01:47:17 +01:00
2021-07-06 23:36:33 +02:00
testMe := findModuleById ( result , "0" )
if ! dependsOn ( result , testMe , findModuleById ( result , "1" ) ) {
2017-11-30 01:47:17 +01:00
t . Errorf ( "test_me doesn't depend on id 1" )
}
2021-07-06 23:36:33 +02:00
if ! dependsOn ( result , testMe , findModuleById ( result , "3" ) ) {
2017-11-30 01:47:17 +01:00
t . Errorf ( "test_me doesn't depend on id 3" )
}
2021-07-06 23:36:33 +02:00
if ! dependsOn ( result , testMe , findModuleById ( result , "6" ) ) {
2017-11-30 01:47:17 +01:00
t . Errorf ( "test_me doesn't depend on id 6" )
}
2021-07-06 23:36:33 +02:00
if ! dependsOn ( result , testMe , findModuleById ( result , "10" ) ) {
2017-11-30 01:47:17 +01:00
t . Errorf ( "test_me doesn't depend on id 10" )
}
2021-07-06 23:36:33 +02:00
if numDeps ( result , testMe ) != 4 {
t . Errorf ( "num dependencies of test_me = %v, not 4\n" , numDeps ( result , testMe ) )
2017-11-30 01:47:17 +01:00
}
}
func TestTwoNamespacesCanImportEachOther ( t * testing . T ) {
2021-07-06 23:36:33 +02:00
GroupFixturePreparers (
prepareForTestWithNamespace ,
dirBpToPreparer ( map [ string ] string {
2017-11-30 01:47:17 +01:00
"dir1" : `
2021-07-06 23:36:33 +02:00
soong_namespace {
imports : [ "dir2" ]
}
test_module {
name : "a" ,
}
test_module {
name : "c" ,
deps : [ "b" ] ,
}
2017-11-30 01:47:17 +01:00
` ,
"dir2" : `
2021-07-06 23:36:33 +02:00
soong_namespace {
imports : [ "dir1" ] ,
}
test_module {
name : "b" ,
deps : [ "a" ] ,
}
2017-11-30 01:47:17 +01:00
` ,
2021-07-06 23:36:33 +02:00
} ) ,
) . RunTest ( t )
2017-11-30 01:47:17 +01:00
2021-07-06 23:36:33 +02:00
// RunTest will report any errors
2017-11-30 01:47:17 +01:00
}
func TestImportingNonexistentNamespace ( t * testing . T ) {
2021-07-06 23:36:33 +02:00
GroupFixturePreparers (
prepareForTestWithNamespace ,
dirBpToPreparer ( map [ string ] string {
2017-11-30 01:47:17 +01:00
"dir1" : `
2021-07-06 23:36:33 +02:00
soong_namespace {
imports : [ "a_nonexistent_namespace" ]
}
test_module {
name : "a" ,
deps : [ "a_nonexistent_module" ]
}
2017-11-30 01:47:17 +01:00
` ,
2021-07-06 23:36:33 +02:00
} ) ,
) .
// should complain about the missing namespace and not complain about the unresolvable dependency
ExtendWithErrorHandler ( FixtureExpectsOneErrorPattern ( ` \Qdir1/Android.bp:2:5: module "soong_namespace": namespace a_nonexistent_namespace does not exist\E ` ) ) .
RunTest ( t )
2017-11-30 01:47:17 +01:00
}
func TestNamespacesDontInheritParentNamespaces ( t * testing . T ) {
2021-07-06 23:36:33 +02:00
GroupFixturePreparers (
prepareForTestWithNamespace ,
dirBpToPreparer ( map [ string ] string {
2017-11-30 01:47:17 +01:00
"dir1" : `
2021-07-06 23:36:33 +02:00
soong_namespace {
}
test_module {
name : "a" ,
}
2017-11-30 01:47:17 +01:00
` ,
"dir1/subdir1" : `
2021-07-06 23:36:33 +02:00
soong_namespace {
}
test_module {
name : "b" ,
deps : [ "a" ] ,
}
2017-11-30 01:47:17 +01:00
` ,
2021-07-06 23:36:33 +02:00
} ) ,
) .
2023-03-31 22:48:42 +02:00
ExtendWithErrorHandler ( FixtureExpectsOneErrorPattern ( ` \ Qdir1 / subdir1 / Android . bp : 4 : 5 : "b" depends on undefined module "a" .
2017-11-30 01:47:17 +01:00
Module "b" is defined in namespace "dir1/subdir1" which can read these 2 namespaces : [ "dir1/subdir1" "." ]
2023-03-31 22:48:42 +02:00
Module "a" can be found in these namespaces : [ "dir1" ] \ E
Or did you mean [ "soong_namespace" ] ? ` ) ) .
2021-07-06 23:36:33 +02:00
RunTest ( t )
2017-11-30 01:47:17 +01:00
}
func TestModulesDoReceiveParentNamespace ( t * testing . T ) {
2021-07-06 23:36:33 +02:00
GroupFixturePreparers (
prepareForTestWithNamespace ,
dirBpToPreparer ( map [ string ] string {
2017-11-30 01:47:17 +01:00
"dir1" : `
2021-07-06 23:36:33 +02:00
soong_namespace {
}
test_module {
name : "a" ,
}
2017-11-30 01:47:17 +01:00
` ,
"dir1/subdir" : `
2021-07-06 23:36:33 +02:00
test_module {
name : "b" ,
deps : [ "a" ] ,
}
2017-11-30 01:47:17 +01:00
` ,
2021-07-06 23:36:33 +02:00
} ) ,
) . RunTest ( t )
2017-11-30 01:47:17 +01:00
2021-07-06 23:36:33 +02:00
// RunTest will report any errors
2017-11-30 01:47:17 +01:00
}
func TestNamespaceImportsNotTransitive ( t * testing . T ) {
2021-07-06 23:36:33 +02:00
GroupFixturePreparers (
prepareForTestWithNamespace ,
dirBpToPreparer ( map [ string ] string {
2017-11-30 01:47:17 +01:00
"dir1" : `
2021-07-06 23:36:33 +02:00
soong_namespace {
}
test_module {
name : "a" ,
}
2017-11-30 01:47:17 +01:00
` ,
"dir2" : `
2021-07-06 23:36:33 +02:00
soong_namespace {
imports : [ "dir1" ] ,
}
test_module {
name : "b" ,
deps : [ "a" ] ,
}
2017-11-30 01:47:17 +01:00
` ,
"dir3" : `
2021-07-06 23:36:33 +02:00
soong_namespace {
imports : [ "dir2" ] ,
}
test_module {
name : "c" ,
deps : [ "a" ] ,
}
2017-11-30 01:47:17 +01:00
` ,
2021-07-06 23:36:33 +02:00
} ) ,
) .
2023-03-31 22:48:42 +02:00
ExtendWithErrorHandler ( FixtureExpectsOneErrorPattern ( ` \ Qdir3 / Android . bp : 5 : 5 : "c" depends on undefined module "a" .
2017-11-30 01:47:17 +01:00
Module "c" is defined in namespace "dir3" which can read these 3 namespaces : [ "dir3" "dir2" "." ]
2023-03-31 22:48:42 +02:00
Module "a" can be found in these namespaces : [ "dir1" ] \ E
Or did you mean [ "b" ] ? ` ) ) .
2021-07-06 23:36:33 +02:00
RunTest ( t )
2017-11-30 01:47:17 +01:00
}
func TestTwoNamepacesInSameDir ( t * testing . T ) {
2021-07-06 23:36:33 +02:00
GroupFixturePreparers (
prepareForTestWithNamespace ,
dirBpToPreparer ( map [ string ] string {
2017-11-30 01:47:17 +01:00
"dir1" : `
2021-07-06 23:36:33 +02:00
soong_namespace {
}
soong_namespace {
}
2017-11-30 01:47:17 +01:00
` ,
2021-07-06 23:36:33 +02:00
} ) ,
) .
ExtendWithErrorHandler ( FixtureExpectsOneErrorPattern ( ` \Qdir1/Android.bp:4:5: namespace dir1 already exists\E ` ) ) .
RunTest ( t )
2017-11-30 01:47:17 +01:00
}
func TestNamespaceNotAtTopOfFile ( t * testing . T ) {
2021-07-06 23:36:33 +02:00
GroupFixturePreparers (
prepareForTestWithNamespace ,
dirBpToPreparer ( map [ string ] string {
2017-11-30 01:47:17 +01:00
"dir1" : `
2021-07-06 23:36:33 +02:00
test_module {
name : "a"
}
soong_namespace {
}
2017-11-30 01:47:17 +01:00
` ,
2021-07-06 23:36:33 +02:00
} ) ,
) .
ExtendWithErrorHandler ( FixtureExpectsOneErrorPattern ( ` \Qdir1/Android.bp:5:5: a namespace must be the first module in the file\E ` ) ) .
RunTest ( t )
2017-11-30 01:47:17 +01:00
}
func TestTwoModulesWithSameNameInSameNamespace ( t * testing . T ) {
2021-07-06 23:36:33 +02:00
GroupFixturePreparers (
prepareForTestWithNamespace ,
dirBpToPreparer ( map [ string ] string {
2017-11-30 01:47:17 +01:00
"dir1" : `
2021-07-06 23:36:33 +02:00
soong_namespace {
}
test_module {
name : "a"
}
test_module {
name : "a"
}
2017-11-30 01:47:17 +01:00
` ,
2021-07-06 23:36:33 +02:00
} ) ,
) .
ExtendWithErrorHandler ( FixtureExpectsOneErrorPattern ( ` \ Qdir1 / Android . bp : 7 : 5 : module "a" already defined
dir1 / Android . bp : 4 : 5 <- - previous definition here \ E ` ) ) .
RunTest ( t )
2017-11-30 01:47:17 +01:00
}
2017-12-01 01:46:47 +01:00
func TestDeclaringNamespaceInNonAndroidBpFile ( t * testing . T ) {
2021-07-06 23:36:33 +02:00
GroupFixturePreparers (
prepareForTestWithNamespace ,
FixtureWithRootAndroidBp ( `
2017-12-01 01:46:47 +01:00
build = [ "include.bp" ]
2021-07-06 23:36:33 +02:00
` ) ,
FixtureAddTextFile ( "include.bp" , `
2017-12-01 01:46:47 +01:00
soong_namespace {
}
2021-07-06 23:36:33 +02:00
` ) ,
) .
ExtendWithErrorHandler ( FixtureExpectsOneErrorPattern (
` \Qinclude.bp:2:5: A namespace may only be declared in a file named Android.bp\E ` ,
) ) .
RunTest ( t )
2017-12-01 01:46:47 +01:00
}
2017-12-02 02:10:33 +01:00
// so that the generated .ninja file will have consistent names
func TestConsistentNamespaceNames ( t * testing . T ) {
2021-07-06 23:36:33 +02:00
result := GroupFixturePreparers (
prepareForTestWithNamespace ,
dirBpToPreparer ( map [ string ] string {
2017-12-02 02:10:33 +01:00
"dir1" : "soong_namespace{}" ,
"dir2" : "soong_namespace{}" ,
"dir3" : "soong_namespace{}" ,
2021-07-06 23:36:33 +02:00
} ) ,
) . RunTest ( t )
2017-12-02 02:10:33 +01:00
2021-07-06 23:36:33 +02:00
ns1 , _ := result . NameResolver . namespaceAt ( "dir1" )
ns2 , _ := result . NameResolver . namespaceAt ( "dir2" )
ns3 , _ := result . NameResolver . namespaceAt ( "dir3" )
2017-12-02 02:10:33 +01:00
actualIds := [ ] string { ns1 . id , ns2 . id , ns3 . id }
expectedIds := [ ] string { "1" , "2" , "3" }
if ! reflect . DeepEqual ( actualIds , expectedIds ) {
t . Errorf ( "Incorrect namespace ids.\nactual: %s\nexpected: %s\n" , actualIds , expectedIds )
}
}
2018-04-16 22:58:10 +02:00
// so that the generated .ninja file will have consistent names
func TestRename ( t * testing . T ) {
2021-07-06 23:36:33 +02:00
GroupFixturePreparers (
prepareForTestWithNamespace ,
dirBpToPreparer ( map [ string ] string {
2018-04-16 22:58:10 +02:00
"dir1" : `
2021-07-06 23:36:33 +02:00
soong_namespace {
}
test_module {
name : "a" ,
deps : [ "c" ] ,
}
test_module {
name : "b" ,
rename : "c" ,
}
` ,
} ) ,
) . RunTest ( t )
2017-11-30 01:47:17 +01:00
2021-07-06 23:36:33 +02:00
// RunTest will report any errors
2017-11-30 01:47:17 +01:00
}
2022-11-08 13:21:15 +01:00
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 ( ) )
}
2021-07-06 23:36:33 +02:00
// some utils to support the tests
2021-03-16 23:02:08 +01:00
2021-07-06 23:36:33 +02:00
var prepareForTestWithNamespace = GroupFixturePreparers (
FixtureRegisterWithContext ( registerNamespaceBuildComponents ) ,
FixtureRegisterWithContext ( func ( ctx RegistrationContext ) {
ctx . PreArchMutators ( RegisterNamespaceMutator )
} ) ,
FixtureModifyContext ( func ( ctx * TestContext ) {
ctx . RegisterModuleType ( "test_module" , newTestModule )
ctx . Context . RegisterModuleType ( "blueprint_test_module" , newBlueprintTestModule )
ctx . PreDepsMutators ( func ( ctx RegisterMutatorsContext ) {
ctx . BottomUp ( "rename" , renameMutator )
} )
} ) ,
)
2017-11-30 01:47:17 +01:00
2021-07-06 23:36:33 +02:00
// dirBpToPreparer takes a map from directory to the contents of the Android.bp file and produces a
// FixturePreparer.
func dirBpToPreparer ( bps map [ string ] string ) FixturePreparer {
files := make ( MockFS , len ( bps ) )
2017-12-01 01:46:47 +01:00
files [ "Android.bp" ] = [ ] byte ( "" )
for dir , text := range bps {
files [ filepath . Join ( dir , "Android.bp" ) ] = [ ] byte ( text )
}
2021-07-06 23:36:33 +02:00
return files . AddToFixture ( )
2017-11-30 01:47:17 +01:00
}
2021-07-06 23:36:33 +02:00
func dependsOn ( result * TestResult , module TestingModule , possibleDependency TestingModule ) bool {
2017-11-30 01:47:17 +01:00
depends := false
visit := func ( dependency blueprint . Module ) {
if dependency == possibleDependency . module {
depends = true
}
}
2021-07-06 23:36:33 +02:00
result . VisitDirectDeps ( module . module , visit )
2017-11-30 01:47:17 +01:00
return depends
}
2021-07-06 23:36:33 +02:00
func numDeps ( result * TestResult , module TestingModule ) int {
2017-11-30 01:47:17 +01:00
count := 0
visit := func ( dependency blueprint . Module ) {
count ++
}
2021-07-06 23:36:33 +02:00
result . VisitDirectDeps ( module . module , visit )
2017-11-30 01:47:17 +01:00
return count
}
2021-07-06 23:36:33 +02:00
func getModule ( result * TestResult , moduleName string ) TestingModule {
return result . ModuleForTests ( moduleName , "" )
2017-11-30 01:47:17 +01:00
}
2021-07-06 23:36:33 +02:00
func findModuleById ( result * TestResult , id string ) ( module TestingModule ) {
2017-11-30 01:47:17 +01:00
visit := func ( candidate blueprint . Module ) {
testModule , ok := candidate . ( * testModule )
if ok {
if testModule . properties . Id == id {
2021-07-06 23:36:33 +02:00
module = newTestingModule ( result . config , testModule )
2017-11-30 01:47:17 +01:00
}
}
}
2021-07-06 23:36:33 +02:00
result . VisitAllModules ( visit )
2017-11-30 01:47:17 +01:00
return module
}
type testModule struct {
ModuleBase
properties struct {
2018-04-16 22:58:10 +02:00
Rename string
Deps [ ] string
Id string
2017-11-30 01:47:17 +01:00
}
}
func ( m * testModule ) DepsMutator ( ctx BottomUpMutatorContext ) {
2018-04-16 22:58:10 +02:00
if m . properties . Rename != "" {
ctx . Rename ( m . properties . Rename )
}
2017-11-30 01:47:17 +01:00
for _ , d := range m . properties . Deps {
ctx . AddDependency ( ctx . Module ( ) , nil , d )
}
}
func ( m * testModule ) GenerateAndroidBuildActions ( ModuleContext ) {
}
2018-04-16 22:58:10 +02:00
func renameMutator ( ctx BottomUpMutatorContext ) {
if m , ok := ctx . Module ( ) . ( * testModule ) ; ok {
if m . properties . Rename != "" {
ctx . Rename ( m . properties . Rename )
}
}
}
2017-11-30 01:47:17 +01:00
func newTestModule ( ) Module {
m := & testModule { }
m . AddProperties ( & m . properties )
InitAndroidModule ( m )
return m
}
2019-06-14 20:26:09 +02:00
type blueprintTestModule struct {
blueprint . SimpleName
properties struct {
Deps [ ] string
}
}
2021-07-06 23:36:33 +02:00
func ( b * blueprintTestModule ) DynamicDependencies ( _ blueprint . DynamicDependerModuleContext ) [ ] string {
2019-06-14 20:26:09 +02:00
return b . properties . Deps
}
func ( b * blueprintTestModule ) GenerateBuildActions ( blueprint . ModuleContext ) {
}
func newBlueprintTestModule ( ) ( blueprint . Module , [ ] interface { } ) {
m := & blueprintTestModule { }
return m , [ ] interface { } { & m . properties , & m . SimpleName . Properties }
}