Test changes to prepare for allowlist v2
This implements a number of in-place unit test changes to prepare for some fundamental changes to bp2build ("allowlist v2"). This will change bp2build so that rdeps of unconverted or missing modules will not be converted by bp2build. Bug: 301312260 Test: Unit tests Test: Unit tests, with a local copy of allowlist v2 on Change-Id: I8c8c0a24ba173e213fffcb0f8d7e99845705f4a7
This commit is contained in:
@@ -102,6 +102,7 @@ android_library {
|
|||||||
sdk_version: "current",
|
sdk_version: "current",
|
||||||
}
|
}
|
||||||
`,
|
`,
|
||||||
|
StubbedBuildDefinitions: []string{"lib_dep"},
|
||||||
ExpectedBazelTargets: []string{
|
ExpectedBazelTargets: []string{
|
||||||
MakeBazelTarget(
|
MakeBazelTarget(
|
||||||
"android_library",
|
"android_library",
|
||||||
|
@@ -348,19 +348,6 @@ custom {
|
|||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
|
||||||
Description: "non-existent dep",
|
|
||||||
Blueprint: `custom {
|
|
||||||
name: "has_dep",
|
|
||||||
arch_paths: [":dep"],
|
|
||||||
bazel_module: { bp2build_available: true },
|
|
||||||
}`,
|
|
||||||
ExpectedBazelTargets: []string{
|
|
||||||
MakeBazelTarget("custom", "has_dep", AttrNameToString{
|
|
||||||
"arch_paths": `[":dep__BP2BUILD__MISSING__DEP"]`,
|
|
||||||
}),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
Description: "arch-variant srcs",
|
Description: "arch-variant srcs",
|
||||||
Blueprint: `custom {
|
Blueprint: `custom {
|
||||||
|
@@ -559,8 +559,8 @@ func TestCcLibraryWholeStaticLibsAlwaysLink(t *testing.T) {
|
|||||||
ModuleTypeUnderTest: "cc_library",
|
ModuleTypeUnderTest: "cc_library",
|
||||||
ModuleTypeUnderTestFactory: cc.LibraryFactory,
|
ModuleTypeUnderTestFactory: cc.LibraryFactory,
|
||||||
Dir: "foo/bar",
|
Dir: "foo/bar",
|
||||||
StubbedBuildDefinitions: []string{"//foo/bar:prebuilt_whole_static_lib_for_shared", "//foo/bar:prebuilt_whole_static_lib_for_static",
|
StubbedBuildDefinitions: []string{"//foo/bar:whole_static_lib_for_shared", "//foo/bar:whole_static_lib_for_static",
|
||||||
"//foo/bar:prebuilt_whole_static_lib_for_both"},
|
"//foo/bar:whole_static_lib_for_both"},
|
||||||
Filesystem: map[string]string{
|
Filesystem: map[string]string{
|
||||||
"foo/bar/Android.bp": `
|
"foo/bar/Android.bp": `
|
||||||
cc_library {
|
cc_library {
|
||||||
@@ -3355,6 +3355,7 @@ func TestCcLibraryWithTargetApex(t *testing.T) {
|
|||||||
Description: "cc_library with target.apex",
|
Description: "cc_library with target.apex",
|
||||||
ModuleTypeUnderTest: "cc_library",
|
ModuleTypeUnderTest: "cc_library",
|
||||||
ModuleTypeUnderTestFactory: cc.LibraryFactory,
|
ModuleTypeUnderTestFactory: cc.LibraryFactory,
|
||||||
|
StubbedBuildDefinitions: []string{"bar", "baz", "buh"},
|
||||||
Blueprint: `
|
Blueprint: `
|
||||||
cc_library {
|
cc_library {
|
||||||
name: "foo",
|
name: "foo",
|
||||||
@@ -3366,27 +3367,29 @@ cc_library {
|
|||||||
exclude_static_libs: ["buh"],
|
exclude_static_libs: ["buh"],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}`,
|
}` + simpleModule("cc_library_static", "baz") +
|
||||||
|
simpleModule("cc_library_static", "buh") +
|
||||||
|
simpleModule("cc_library_static", "bar"),
|
||||||
ExpectedBazelTargets: []string{
|
ExpectedBazelTargets: []string{
|
||||||
MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{
|
MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{
|
||||||
"implementation_deps": `[":baz__BP2BUILD__MISSING__DEP"] + select({
|
"implementation_deps": `[":baz"] + select({
|
||||||
"//build/bazel/rules/apex:in_apex": [],
|
"//build/bazel/rules/apex:in_apex": [],
|
||||||
"//conditions:default": [":buh__BP2BUILD__MISSING__DEP"],
|
"//conditions:default": [":buh"],
|
||||||
})`,
|
})`,
|
||||||
"implementation_dynamic_deps": `[":baz__BP2BUILD__MISSING__DEP"] + select({
|
"implementation_dynamic_deps": `[":baz"] + select({
|
||||||
"//build/bazel/rules/apex:in_apex": [],
|
"//build/bazel/rules/apex:in_apex": [],
|
||||||
"//conditions:default": [":bar__BP2BUILD__MISSING__DEP"],
|
"//conditions:default": [":bar"],
|
||||||
})`,
|
})`,
|
||||||
"local_includes": `["."]`,
|
"local_includes": `["."]`,
|
||||||
}),
|
}),
|
||||||
MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
|
MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
|
||||||
"implementation_deps": `[":baz__BP2BUILD__MISSING__DEP"] + select({
|
"implementation_deps": `[":baz"] + select({
|
||||||
"//build/bazel/rules/apex:in_apex": [],
|
"//build/bazel/rules/apex:in_apex": [],
|
||||||
"//conditions:default": [":buh__BP2BUILD__MISSING__DEP"],
|
"//conditions:default": [":buh"],
|
||||||
})`,
|
})`,
|
||||||
"implementation_dynamic_deps": `[":baz__BP2BUILD__MISSING__DEP"] + select({
|
"implementation_dynamic_deps": `[":baz"] + select({
|
||||||
"//build/bazel/rules/apex:in_apex": [],
|
"//build/bazel/rules/apex:in_apex": [],
|
||||||
"//conditions:default": [":bar__BP2BUILD__MISSING__DEP"],
|
"//conditions:default": [":bar"],
|
||||||
})`,
|
})`,
|
||||||
"local_includes": `["."]`,
|
"local_includes": `["."]`,
|
||||||
}),
|
}),
|
||||||
@@ -3412,20 +3415,23 @@ cc_library_static {
|
|||||||
exclude_static_libs: ["abc"],
|
exclude_static_libs: ["abc"],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}`,
|
}` + simpleModule("cc_library_static", "bar") +
|
||||||
|
simpleModule("cc_library_static", "baz") +
|
||||||
|
simpleModule("cc_library_static", "abc"),
|
||||||
|
StubbedBuildDefinitions: []string{"bar", "baz", "abc"},
|
||||||
ExpectedBazelTargets: []string{
|
ExpectedBazelTargets: []string{
|
||||||
MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
|
MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
|
||||||
"implementation_dynamic_deps": `select({
|
"implementation_dynamic_deps": `select({
|
||||||
"//build/bazel/rules/apex:in_apex": [],
|
"//build/bazel/rules/apex:in_apex": [],
|
||||||
"//conditions:default": [":bar__BP2BUILD__MISSING__DEP"],
|
"//conditions:default": [":bar"],
|
||||||
})`,
|
})`,
|
||||||
"dynamic_deps": `select({
|
"dynamic_deps": `select({
|
||||||
"//build/bazel/rules/apex:in_apex": [],
|
"//build/bazel/rules/apex:in_apex": [],
|
||||||
"//conditions:default": [":baz__BP2BUILD__MISSING__DEP"],
|
"//conditions:default": [":baz"],
|
||||||
})`,
|
})`,
|
||||||
"deps": `select({
|
"deps": `select({
|
||||||
"//build/bazel/rules/apex:in_apex": [],
|
"//build/bazel/rules/apex:in_apex": [],
|
||||||
"//conditions:default": [":abc__BP2BUILD__MISSING__DEP"],
|
"//conditions:default": [":abc"],
|
||||||
})`,
|
})`,
|
||||||
"local_includes": `["."]`,
|
"local_includes": `["."]`,
|
||||||
}),
|
}),
|
||||||
@@ -5198,7 +5204,7 @@ ndk_headers {
|
|||||||
name: "libfoo_headers",
|
name: "libfoo_headers",
|
||||||
from: "from",
|
from: "from",
|
||||||
to: "to",
|
to: "to",
|
||||||
srcs: ["from/foo.h", "from/foo_other.h"]
|
srcs: ["foo.h", "foo_other.h"]
|
||||||
}
|
}
|
||||||
`,
|
`,
|
||||||
ExpectedBazelTargets: []string{
|
ExpectedBazelTargets: []string{
|
||||||
@@ -5206,8 +5212,8 @@ ndk_headers {
|
|||||||
"strip_import_prefix": `"from"`,
|
"strip_import_prefix": `"from"`,
|
||||||
"import_prefix": `"to"`,
|
"import_prefix": `"to"`,
|
||||||
"hdrs": `[
|
"hdrs": `[
|
||||||
"from/foo.h",
|
"foo.h",
|
||||||
"from/foo_other.h",
|
"foo_other.h",
|
||||||
]`,
|
]`,
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
|
@@ -70,10 +70,6 @@ func TestCcLibraryHeadersSimple(t *testing.T) {
|
|||||||
runCcLibraryHeadersTestCase(t, Bp2buildTestCase{
|
runCcLibraryHeadersTestCase(t, Bp2buildTestCase{
|
||||||
Description: "cc_library_headers test",
|
Description: "cc_library_headers test",
|
||||||
Filesystem: map[string]string{
|
Filesystem: map[string]string{
|
||||||
"lib-1/lib1a.h": "",
|
|
||||||
"lib-1/lib1b.h": "",
|
|
||||||
"lib-2/lib2a.h": "",
|
|
||||||
"lib-2/lib2b.h": "",
|
|
||||||
"dir-1/dir1a.h": "",
|
"dir-1/dir1a.h": "",
|
||||||
"dir-1/dir1b.h": "",
|
"dir-1/dir1b.h": "",
|
||||||
"dir-2/dir2a.h": "",
|
"dir-2/dir2a.h": "",
|
||||||
@@ -86,7 +82,6 @@ func TestCcLibraryHeadersSimple(t *testing.T) {
|
|||||||
cc_library_headers {
|
cc_library_headers {
|
||||||
name: "foo_headers",
|
name: "foo_headers",
|
||||||
export_include_dirs: ["dir-1", "dir-2"],
|
export_include_dirs: ["dir-1", "dir-2"],
|
||||||
header_libs: ["lib-1", "lib-2"],
|
|
||||||
|
|
||||||
arch: {
|
arch: {
|
||||||
arm64: {
|
arm64: {
|
||||||
@@ -322,7 +317,7 @@ func TestCcLibraryHeadersExportedStaticLibHeadersReexported(t *testing.T) {
|
|||||||
runCcLibraryHeadersTestCase(t, Bp2buildTestCase{
|
runCcLibraryHeadersTestCase(t, Bp2buildTestCase{
|
||||||
Description: "cc_library_headers exported_static_lib_headers is reexported",
|
Description: "cc_library_headers exported_static_lib_headers is reexported",
|
||||||
Filesystem: map[string]string{},
|
Filesystem: map[string]string{},
|
||||||
StubbedBuildDefinitions: []string{"foo_export"},
|
StubbedBuildDefinitions: []string{"foo_export", "foo_no_reexport"},
|
||||||
Blueprint: soongCcLibraryHeadersPreamble + `
|
Blueprint: soongCcLibraryHeadersPreamble + `
|
||||||
cc_library_headers {
|
cc_library_headers {
|
||||||
name: "foo_headers",
|
name: "foo_headers",
|
||||||
@@ -330,7 +325,8 @@ cc_library_headers {
|
|||||||
static_libs: ["foo_export", "foo_no_reexport"],
|
static_libs: ["foo_export", "foo_no_reexport"],
|
||||||
bazel_module: { bp2build_available: true },
|
bazel_module: { bp2build_available: true },
|
||||||
}
|
}
|
||||||
` + simpleModule("cc_library_headers", "foo_export"),
|
` + simpleModule("cc_library_headers", "foo_export") +
|
||||||
|
simpleModule("cc_library_headers", "foo_no_reexport"),
|
||||||
ExpectedBazelTargets: []string{
|
ExpectedBazelTargets: []string{
|
||||||
MakeBazelTarget("cc_library_headers", "foo_headers", AttrNameToString{
|
MakeBazelTarget("cc_library_headers", "foo_headers", AttrNameToString{
|
||||||
"deps": `[":foo_export"]`,
|
"deps": `[":foo_export"]`,
|
||||||
@@ -343,7 +339,7 @@ func TestCcLibraryHeadersExportedSharedLibHeadersReexported(t *testing.T) {
|
|||||||
runCcLibraryHeadersTestCase(t, Bp2buildTestCase{
|
runCcLibraryHeadersTestCase(t, Bp2buildTestCase{
|
||||||
Description: "cc_library_headers exported_shared_lib_headers is reexported",
|
Description: "cc_library_headers exported_shared_lib_headers is reexported",
|
||||||
Filesystem: map[string]string{},
|
Filesystem: map[string]string{},
|
||||||
StubbedBuildDefinitions: []string{"foo_export"},
|
StubbedBuildDefinitions: []string{"foo_export", "foo_no_reexport"},
|
||||||
Blueprint: soongCcLibraryHeadersPreamble + `
|
Blueprint: soongCcLibraryHeadersPreamble + `
|
||||||
cc_library_headers {
|
cc_library_headers {
|
||||||
name: "foo_headers",
|
name: "foo_headers",
|
||||||
@@ -351,7 +347,8 @@ cc_library_headers {
|
|||||||
shared_libs: ["foo_export", "foo_no_reexport"],
|
shared_libs: ["foo_export", "foo_no_reexport"],
|
||||||
bazel_module: { bp2build_available: true },
|
bazel_module: { bp2build_available: true },
|
||||||
}
|
}
|
||||||
` + simpleModule("cc_library_headers", "foo_export"),
|
` + simpleModule("cc_library_headers", "foo_export") +
|
||||||
|
simpleModule("cc_library_headers", "foo_no_reexport"),
|
||||||
ExpectedBazelTargets: []string{
|
ExpectedBazelTargets: []string{
|
||||||
MakeBazelTarget("cc_library_headers", "foo_headers", AttrNameToString{
|
MakeBazelTarget("cc_library_headers", "foo_headers", AttrNameToString{
|
||||||
"deps": `[":foo_export"]`,
|
"deps": `[":foo_export"]`,
|
||||||
@@ -364,7 +361,7 @@ func TestCcLibraryHeadersExportedHeaderLibHeadersReexported(t *testing.T) {
|
|||||||
runCcLibraryHeadersTestCase(t, Bp2buildTestCase{
|
runCcLibraryHeadersTestCase(t, Bp2buildTestCase{
|
||||||
Description: "cc_library_headers exported_header_lib_headers is reexported",
|
Description: "cc_library_headers exported_header_lib_headers is reexported",
|
||||||
Filesystem: map[string]string{},
|
Filesystem: map[string]string{},
|
||||||
StubbedBuildDefinitions: []string{"foo_export"},
|
StubbedBuildDefinitions: []string{"foo_export", "foo_no_reexport"},
|
||||||
Blueprint: soongCcLibraryHeadersPreamble + `
|
Blueprint: soongCcLibraryHeadersPreamble + `
|
||||||
cc_library_headers {
|
cc_library_headers {
|
||||||
name: "foo_headers",
|
name: "foo_headers",
|
||||||
@@ -372,7 +369,8 @@ cc_library_headers {
|
|||||||
header_libs: ["foo_export", "foo_no_reexport"],
|
header_libs: ["foo_export", "foo_no_reexport"],
|
||||||
bazel_module: { bp2build_available: true },
|
bazel_module: { bp2build_available: true },
|
||||||
}
|
}
|
||||||
` + simpleModule("cc_library_headers", "foo_export"),
|
` + simpleModule("cc_library_headers", "foo_export") +
|
||||||
|
simpleModule("cc_library_headers", "foo_no_reexport"),
|
||||||
ExpectedBazelTargets: []string{
|
ExpectedBazelTargets: []string{
|
||||||
MakeBazelTarget("cc_library_headers", "foo_headers", AttrNameToString{
|
MakeBazelTarget("cc_library_headers", "foo_headers", AttrNameToString{
|
||||||
"deps": `[":foo_export"]`,
|
"deps": `[":foo_export"]`,
|
||||||
@@ -426,7 +424,7 @@ cc_prebuilt_library_headers {
|
|||||||
func TestPrebuiltCcLibraryHeadersPreferredRdepUpdated(t *testing.T) {
|
func TestPrebuiltCcLibraryHeadersPreferredRdepUpdated(t *testing.T) {
|
||||||
runCcLibraryHeadersTestCase(t, Bp2buildTestCase{
|
runCcLibraryHeadersTestCase(t, Bp2buildTestCase{
|
||||||
Description: "cc_library_headers prebuilt preferred is used as rdep",
|
Description: "cc_library_headers prebuilt preferred is used as rdep",
|
||||||
StubbedBuildDefinitions: []string{"foo_export"},
|
StubbedBuildDefinitions: []string{"foo_export", "//foo/bar:foo_headers"},
|
||||||
Filesystem: map[string]string{
|
Filesystem: map[string]string{
|
||||||
"foo/bar/Android.bp": simpleModule("cc_library_headers", "foo_headers"),
|
"foo/bar/Android.bp": simpleModule("cc_library_headers", "foo_headers"),
|
||||||
},
|
},
|
||||||
@@ -458,7 +456,7 @@ cc_library_shared {
|
|||||||
func TestPrebuiltCcLibraryHeadersRdepUpdated(t *testing.T) {
|
func TestPrebuiltCcLibraryHeadersRdepUpdated(t *testing.T) {
|
||||||
runCcLibraryHeadersTestCase(t, Bp2buildTestCase{
|
runCcLibraryHeadersTestCase(t, Bp2buildTestCase{
|
||||||
Description: "cc_library_headers not preferred is not used for rdep",
|
Description: "cc_library_headers not preferred is not used for rdep",
|
||||||
StubbedBuildDefinitions: []string{"foo_export"},
|
StubbedBuildDefinitions: []string{"foo_export", "//foo/bar:foo_headers"},
|
||||||
Filesystem: map[string]string{
|
Filesystem: map[string]string{
|
||||||
"foo/bar/Android.bp": simpleModule("cc_library_headers", "foo_headers"),
|
"foo/bar/Android.bp": simpleModule("cc_library_headers", "foo_headers"),
|
||||||
},
|
},
|
||||||
|
@@ -15,16 +15,22 @@
|
|||||||
package bp2build
|
package bp2build
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
"android/soong/android"
|
"android/soong/android"
|
||||||
"android/soong/genrule"
|
"android/soong/genrule"
|
||||||
"testing"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func registerModulesForGensrcsTests(ctx android.RegistrationContext) {
|
||||||
|
ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
|
||||||
|
}
|
||||||
|
|
||||||
func TestGensrcs(t *testing.T) {
|
func TestGensrcs(t *testing.T) {
|
||||||
testcases := []struct {
|
testcases := []struct {
|
||||||
name string
|
name string
|
||||||
bp string
|
bp string
|
||||||
expectedBazelAttrs AttrNameToString
|
expectedBazelAttrs AttrNameToString
|
||||||
|
stubbedBuildDefinitions []string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "gensrcs with common usage of properties",
|
name: "gensrcs with common usage of properties",
|
||||||
@@ -37,18 +43,22 @@ func TestGensrcs(t *testing.T) {
|
|||||||
data: ["foo/file.txt", ":external_files"],
|
data: ["foo/file.txt", ":external_files"],
|
||||||
output_extension: "out",
|
output_extension: "out",
|
||||||
bazel_module: { bp2build_available: true },
|
bazel_module: { bp2build_available: true },
|
||||||
|
}
|
||||||
|
filegroup {
|
||||||
|
name: "external_files",
|
||||||
}`,
|
}`,
|
||||||
|
stubbedBuildDefinitions: []string{"external_files"},
|
||||||
expectedBazelAttrs: AttrNameToString{
|
expectedBazelAttrs: AttrNameToString{
|
||||||
"srcs": `[
|
"srcs": `[
|
||||||
"test/input.txt",
|
"test/input.txt",
|
||||||
":external_files__BP2BUILD__MISSING__DEP",
|
":external_files",
|
||||||
]`,
|
]`,
|
||||||
"tools": `["program.py"]`,
|
"tools": `["program.py"]`,
|
||||||
"output_extension": `"out"`,
|
"output_extension": `"out"`,
|
||||||
"cmd": `"$(location program.py) $(SRC) $(OUT) $(location foo/file.txt) $(location :external_files__BP2BUILD__MISSING__DEP)"`,
|
"cmd": `"$(location program.py) $(SRC) $(OUT) $(location foo/file.txt) $(location :external_files)"`,
|
||||||
"data": `[
|
"data": `[
|
||||||
"foo/file.txt",
|
"foo/file.txt",
|
||||||
":external_files__BP2BUILD__MISSING__DEP",
|
":external_files",
|
||||||
]`,
|
]`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -73,12 +83,13 @@ func TestGensrcs(t *testing.T) {
|
|||||||
MakeBazelTargetNoRestrictions("gensrcs", "foo", test.expectedBazelAttrs),
|
MakeBazelTargetNoRestrictions("gensrcs", "foo", test.expectedBazelAttrs),
|
||||||
}
|
}
|
||||||
t.Run(test.name, func(t *testing.T) {
|
t.Run(test.name, func(t *testing.T) {
|
||||||
RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {},
|
RunBp2BuildTestCase(t, registerModulesForGensrcsTests,
|
||||||
Bp2buildTestCase{
|
Bp2buildTestCase{
|
||||||
ModuleTypeUnderTest: "gensrcs",
|
ModuleTypeUnderTest: "gensrcs",
|
||||||
ModuleTypeUnderTestFactory: genrule.GenSrcsFactory,
|
ModuleTypeUnderTestFactory: genrule.GenSrcsFactory,
|
||||||
Blueprint: test.bp,
|
Blueprint: test.bp,
|
||||||
ExpectedBazelTargets: expectedBazelTargets,
|
ExpectedBazelTargets: expectedBazelTargets,
|
||||||
|
StubbedBuildDefinitions: test.stubbedBuildDefinitions,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@@ -635,7 +635,7 @@ func TestJavaLibraryAidlNonAdjacentAidlFilegroup(t *testing.T) {
|
|||||||
Description: "java_library with non adjacent aidl filegroup",
|
Description: "java_library with non adjacent aidl filegroup",
|
||||||
ModuleTypeUnderTest: "java_library",
|
ModuleTypeUnderTest: "java_library",
|
||||||
ModuleTypeUnderTestFactory: java.LibraryFactory,
|
ModuleTypeUnderTestFactory: java.LibraryFactory,
|
||||||
StubbedBuildDefinitions: []string{"A_aidl"},
|
StubbedBuildDefinitions: []string{"//path/to/A:A_aidl"},
|
||||||
Filesystem: map[string]string{
|
Filesystem: map[string]string{
|
||||||
"path/to/A/Android.bp": `
|
"path/to/A/Android.bp": `
|
||||||
filegroup {
|
filegroup {
|
||||||
|
Reference in New Issue
Block a user