Refactor bp2build tests for allowlist v2
Allowlist v2 will change bp2build by automatically disabling rdeps of
unconvertible modules. Many bp2build tests create bp2build stub modules
without an implementation,
This CL changes setup of such tests to also contain a BUILD file with
"stub implementations" of equivalent targets, to keep these test targets
convertible.
To verify this change in-place, this CL removes `bp2build_available:
false` from these dependencies.
This is a test-only change for bp2build tests.
Bug: 285631638
Test: m bp2build
Change-Id: I489480cbc4158a416b7abf57c35a6e2bc2ad6173
diff --git a/bp2build/cc_library_conversion_test.go b/bp2build/cc_library_conversion_test.go
index 76dc590..ec603c2 100644
--- a/bp2build/cc_library_conversion_test.go
+++ b/bp2build/cc_library_conversion_test.go
@@ -35,19 +35,16 @@
soongCcVersionLibBp = `
cc_library_static {
name: "libbuildversion",
- bazel_module: { bp2build_available: false },
}
`
soongCcProtoLibraries = `
cc_library {
name: "libprotobuf-cpp-lite",
- bazel_module: { bp2build_available: false },
}
cc_library {
name: "libprotobuf-cpp-full",
- bazel_module: { bp2build_available: false },
}`
soongCcProtoPreamble = soongCcLibraryPreamble + soongCcProtoLibraries
@@ -55,6 +52,7 @@
func runCcLibraryTestCase(t *testing.T, tc Bp2buildTestCase) {
t.Helper()
+ tc.StubbedBuildDefinitions = append(tc.StubbedBuildDefinitions, "libprotobuf-cpp-lite", "libprotobuf-cpp-full")
RunBp2BuildTestCase(t, registerCcLibraryModuleTypes, tc)
}
@@ -73,6 +71,7 @@
Description: "cc_library - simple example",
ModuleTypeUnderTest: "cc_library",
ModuleTypeUnderTestFactory: cc.LibraryFactory,
+ StubbedBuildDefinitions: []string{"//build/soong/cc/libbuildversion:libbuildversion", "some-headers"},
Filesystem: map[string]string{
soongCcVersionLibBpPath: soongCcVersionLibBp,
"android.cpp": "",
@@ -95,7 +94,7 @@
"foo-dir/a.h": "",
},
Blueprint: soongCcLibraryPreamble +
- SimpleModuleDoNotConvertBp2build("cc_library_headers", "some-headers") + `
+ simpleModule("cc_library_headers", "some-headers") + `
cc_library {
name: "foo-lib",
srcs: ["impl.cpp"],
@@ -169,6 +168,7 @@
Description: "cc_library - trimmed example of //bionic/linker:ld-android",
ModuleTypeUnderTest: "cc_library",
ModuleTypeUnderTestFactory: cc.LibraryFactory,
+ StubbedBuildDefinitions: []string{"libc_headers"},
Filesystem: map[string]string{
"ld-android.cpp": "",
"linked_list.h": "",
@@ -177,7 +177,7 @@
"linker_cfi.h": "",
},
Blueprint: soongCcLibraryPreamble +
- SimpleModuleDoNotConvertBp2build("cc_library_headers", "libc_headers") + `
+ simpleModule("cc_library_headers", "libc_headers") + `
cc_library {
name: "fake-ld-android",
srcs: ["ld_android.cpp"],
@@ -320,54 +320,49 @@
cc_library_static {
name: "static_dep_for_shared",
- bazel_module: { bp2build_available: false },
}
cc_library_static {
name: "static_dep_for_static",
- bazel_module: { bp2build_available: false },
}
cc_library_static {
name: "static_dep_for_both",
- bazel_module: { bp2build_available: false },
}
cc_library_static {
name: "whole_static_lib_for_shared",
- bazel_module: { bp2build_available: false },
}
cc_library_static {
name: "whole_static_lib_for_static",
- bazel_module: { bp2build_available: false },
}
cc_library_static {
name: "whole_static_lib_for_both",
- bazel_module: { bp2build_available: false },
}
cc_library_static {
name: "whole_and_static_lib_for_both",
- bazel_module: { bp2build_available: false },
}
cc_library {
name: "shared_dep_for_shared",
- bazel_module: { bp2build_available: false },
}
cc_library {
name: "shared_dep_for_static",
- bazel_module: { bp2build_available: false },
}
cc_library {
name: "shared_dep_for_both",
- bazel_module: { bp2build_available: false },
}
`,
+ StubbedBuildDefinitions: []string{"static_dep_for_shared", "static_dep_for_static",
+ "static_dep_for_both", "whole_static_lib_for_shared", "whole_static_lib_for_static",
+ "whole_static_lib_for_both", "whole_and_static_lib_for_both", "shared_dep_for_shared",
+ "shared_dep_for_static", "shared_dep_for_both",
+ },
ExpectedBazelTargets: []string{
MakeBazelTarget("cc_library_static", "a_bp2build_cc_library_static", AttrNameToString{
"copts": `[
@@ -458,24 +453,34 @@
},
include_build_directory: false,
}
-` + SimpleModuleDoNotConvertBp2build("cc_library_static", "static_dep_for_shared") +
- SimpleModuleDoNotConvertBp2build("cc_library_static", "implementation_static_dep_for_shared") +
- SimpleModuleDoNotConvertBp2build("cc_library_static", "static_dep_for_static") +
- SimpleModuleDoNotConvertBp2build("cc_library_static", "implementation_static_dep_for_static") +
- SimpleModuleDoNotConvertBp2build("cc_library_static", "static_dep_for_both") +
- SimpleModuleDoNotConvertBp2build("cc_library_static", "implementation_static_dep_for_both") +
- SimpleModuleDoNotConvertBp2build("cc_library_static", "whole_static_dep_for_shared") +
- SimpleModuleDoNotConvertBp2build("cc_library_static", "not_explicitly_exported_whole_static_dep_for_shared") +
- SimpleModuleDoNotConvertBp2build("cc_library_static", "whole_static_dep_for_static") +
- SimpleModuleDoNotConvertBp2build("cc_library_static", "not_explicitly_exported_whole_static_dep_for_static") +
- SimpleModuleDoNotConvertBp2build("cc_library_static", "whole_static_dep_for_both") +
- SimpleModuleDoNotConvertBp2build("cc_library_static", "not_explicitly_exported_whole_static_dep_for_both") +
- SimpleModuleDoNotConvertBp2build("cc_library", "shared_dep_for_shared") +
- SimpleModuleDoNotConvertBp2build("cc_library", "implementation_shared_dep_for_shared") +
- SimpleModuleDoNotConvertBp2build("cc_library", "shared_dep_for_static") +
- SimpleModuleDoNotConvertBp2build("cc_library", "implementation_shared_dep_for_static") +
- SimpleModuleDoNotConvertBp2build("cc_library", "shared_dep_for_both") +
- SimpleModuleDoNotConvertBp2build("cc_library", "implementation_shared_dep_for_both"),
+` + simpleModule("cc_library_static", "static_dep_for_shared") +
+ simpleModule("cc_library_static", "implementation_static_dep_for_shared") +
+ simpleModule("cc_library_static", "static_dep_for_static") +
+ simpleModule("cc_library_static", "implementation_static_dep_for_static") +
+ simpleModule("cc_library_static", "static_dep_for_both") +
+ simpleModule("cc_library_static", "implementation_static_dep_for_both") +
+ simpleModule("cc_library_static", "whole_static_dep_for_shared") +
+ simpleModule("cc_library_static", "not_explicitly_exported_whole_static_dep_for_shared") +
+ simpleModule("cc_library_static", "whole_static_dep_for_static") +
+ simpleModule("cc_library_static", "not_explicitly_exported_whole_static_dep_for_static") +
+ simpleModule("cc_library_static", "whole_static_dep_for_both") +
+ simpleModule("cc_library_static", "not_explicitly_exported_whole_static_dep_for_both") +
+ simpleModule("cc_library", "shared_dep_for_shared") +
+ simpleModule("cc_library", "implementation_shared_dep_for_shared") +
+ simpleModule("cc_library", "shared_dep_for_static") +
+ simpleModule("cc_library", "implementation_shared_dep_for_static") +
+ simpleModule("cc_library", "shared_dep_for_both") +
+ simpleModule("cc_library", "implementation_shared_dep_for_both"),
+ StubbedBuildDefinitions: []string{"static_dep_for_shared", "implementation_static_dep_for_shared",
+ "static_dep_for_static", "implementation_static_dep_for_static", "static_dep_for_both",
+ "implementation_static_dep_for_both", "whole_static_dep_for_shared",
+ "not_explicitly_exported_whole_static_dep_for_shared", "whole_static_dep_for_static",
+ "not_explicitly_exported_whole_static_dep_for_static", "whole_static_dep_for_both",
+ "not_explicitly_exported_whole_static_dep_for_both", "shared_dep_for_shared",
+ "implementation_shared_dep_for_shared", "shared_dep_for_static",
+ "implementation_shared_dep_for_static", "shared_dep_for_both",
+ "implementation_shared_dep_for_both",
+ },
ExpectedBazelTargets: []string{
MakeBazelTarget("cc_library_static", "a_bp2build_cc_library_static", AttrNameToString{
"copts": `[
@@ -550,6 +555,8 @@
ModuleTypeUnderTest: "cc_library",
ModuleTypeUnderTestFactory: cc.LibraryFactory,
Dir: "foo/bar",
+ StubbedBuildDefinitions: []string{"//foo/bar:prebuilt_whole_static_lib_for_shared", "//foo/bar:prebuilt_whole_static_lib_for_static",
+ "//foo/bar:prebuilt_whole_static_lib_for_both"},
Filesystem: map[string]string{
"foo/bar/Android.bp": `
cc_library {
@@ -666,6 +673,10 @@
cc_library_static { name: "android_dep_for_shared" }
`,
},
+ StubbedBuildDefinitions: []string{"//foo/bar:static_dep_for_shared", "//foo/bar:static_dep_for_static",
+ "//foo/bar:static_dep_for_both", "//foo/bar:arm_static_dep_for_shared", "//foo/bar:arm_whole_static_dep_for_shared",
+ "//foo/bar:arm_shared_dep_for_shared", "//foo/bar:x86_dep_for_static", "//foo/bar:android_dep_for_shared",
+ },
Blueprint: soongCcLibraryPreamble,
ExpectedBazelTargets: []string{
MakeBazelTarget("cc_library_static", "a_bp2build_cc_library_static", AttrNameToString{
@@ -747,6 +758,7 @@
ModuleTypeUnderTest: "cc_library",
ModuleTypeUnderTestFactory: cc.LibraryFactory,
Dir: "foo/bar",
+ StubbedBuildDefinitions: []string{"//foo/bar:shared_filegroup", "//foo/bar:static_filegroup", "//foo/bar:both_filegroup"},
Filesystem: map[string]string{
"foo/bar/both_source.cpp": "",
"foo/bar/both_source.cc": "",
@@ -1018,10 +1030,10 @@
Description: "cc_library shared_libs",
ModuleTypeUnderTest: "cc_library",
ModuleTypeUnderTestFactory: cc.LibraryFactory,
+ StubbedBuildDefinitions: []string{"mylib"},
Blueprint: soongCcLibraryPreamble + `
cc_library {
name: "mylib",
- bazel_module: { bp2build_available: false },
}
cc_library {
@@ -1182,6 +1194,10 @@
ModuleTypeUnderTest: "cc_library",
ModuleTypeUnderTestFactory: cc.LibraryFactory,
Filesystem: map[string]string{},
+ StubbedBuildDefinitions: []string{"arm_whole_static_lib_excludes", "malloc_not_svelte_whole_static_lib",
+ "arm_static_lib_excludes", "malloc_not_svelte_whole_static_lib_excludes", "arm_shared_lib_excludes",
+ "malloc_not_svelte_static_lib_excludes", "arm_shared_lib_excludes", "malloc_not_svelte_shared_lib",
+ },
Blueprint: soongCcLibraryStaticPreamble + `
cc_library {
name: "foo_static",
@@ -1223,37 +1239,30 @@
cc_library {
name: "arm_whole_static_lib_excludes",
- bazel_module: { bp2build_available: false },
}
cc_library {
name: "malloc_not_svelte_whole_static_lib",
- bazel_module: { bp2build_available: false },
}
cc_library {
name: "malloc_not_svelte_whole_static_lib_excludes",
- bazel_module: { bp2build_available: false },
}
cc_library {
name: "arm_static_lib_excludes",
- bazel_module: { bp2build_available: false },
}
cc_library {
name: "malloc_not_svelte_static_lib_excludes",
- bazel_module: { bp2build_available: false },
}
cc_library {
name: "arm_shared_lib_excludes",
- bazel_module: { bp2build_available: false },
}
cc_library {
name: "malloc_not_svelte_shared_lib",
- bazel_module: { bp2build_available: false },
}
`,
ExpectedBazelTargets: makeCcLibraryTargets("foo_static", AttrNameToString{
@@ -1289,6 +1298,7 @@
ModuleTypeUnderTest: "cc_library",
ModuleTypeUnderTestFactory: cc.LibraryFactory,
Filesystem: map[string]string{},
+ StubbedBuildDefinitions: []string{"malloc_not_svelte_header_lib"},
Blueprint: soongCcLibraryStaticPreamble + `
cc_library {
name: "foo_static",
@@ -1303,7 +1313,6 @@
cc_library {
name: "malloc_not_svelte_header_lib",
- bazel_module: { bp2build_available: false },
}
`,
ExpectedBazelTargets: makeCcLibraryTargets("foo_static", AttrNameToString{
@@ -1813,10 +1822,10 @@
Description: "cc_library system_shared_libs empty for linux_bionic variant",
ModuleTypeUnderTest: "cc_library",
ModuleTypeUnderTestFactory: cc.LibraryFactory,
+ StubbedBuildDefinitions: []string{"libc_musl"},
Blueprint: soongCcLibraryPreamble + `
cc_library {
name: "libc_musl",
- bazel_module: { bp2build_available: false },
}
cc_library {
@@ -1844,6 +1853,7 @@
Description: "cc_library system_shared_libs empty for bionic variant",
ModuleTypeUnderTest: "cc_library",
ModuleTypeUnderTestFactory: cc.LibraryFactory,
+ StubbedBuildDefinitions: []string{"libc_musl"},
Blueprint: soongCcLibraryPreamble + `
cc_library {
name: "libc_musl",
@@ -1875,10 +1885,10 @@
Description: "cc_library system_shared_lib empty for musl variant",
ModuleTypeUnderTest: "cc_library",
ModuleTypeUnderTestFactory: cc.LibraryFactory,
+ StubbedBuildDefinitions: []string{"libc_musl"},
Blueprint: soongCcLibraryPreamble + `
cc_library {
name: "libc_musl",
- bazel_module: { bp2build_available: false },
}
cc_library {
@@ -1928,14 +1938,13 @@
Description: "cc_library system_shared_libs set for shared and root",
ModuleTypeUnderTest: "cc_library",
ModuleTypeUnderTestFactory: cc.LibraryFactory,
+ StubbedBuildDefinitions: []string{"libc", "libm"},
Blueprint: soongCcLibraryPreamble + `
cc_library {
name: "libc",
- bazel_module: { bp2build_available: false },
}
cc_library {
name: "libm",
- bazel_module: { bp2build_available: false },
}
cc_library {
@@ -2506,6 +2515,7 @@
runCcLibraryTestCase(t, Bp2buildTestCase{
ModuleTypeUnderTest: "cc_library",
ModuleTypeUnderTestFactory: cc.LibraryFactory,
+ StubbedBuildDefinitions: []string{"//path/to/A:a_fg_proto"},
Filesystem: map[string]string{
"path/to/A/Android.bp": `
filegroup {
@@ -2549,11 +2559,12 @@
runCcLibraryTestCase(t, Bp2buildTestCase{
ModuleTypeUnderTest: "cc_library",
ModuleTypeUnderTestFactory: cc.LibraryFactory,
+ StubbedBuildDefinitions: []string{"a_fg_proto", "b_protos", "c-proto-srcs", "proto-srcs-d"},
Blueprint: soongCcProtoPreamble +
- SimpleModuleDoNotConvertBp2build("filegroup", "a_fg_proto") +
- SimpleModuleDoNotConvertBp2build("filegroup", "b_protos") +
- SimpleModuleDoNotConvertBp2build("filegroup", "c-proto-srcs") +
- SimpleModuleDoNotConvertBp2build("filegroup", "proto-srcs-d") + `
+ simpleModule("filegroup", "a_fg_proto") +
+ simpleModule("filegroup", "b_protos") +
+ simpleModule("filegroup", "c-proto-srcs") +
+ simpleModule("filegroup", "proto-srcs-d") + `
cc_library {
name: "a",
srcs: [":a_fg_proto"],
@@ -2849,11 +2860,11 @@
Filesystem: map[string]string{
"bar.map.txt": "",
},
+ StubbedBuildDefinitions: []string{"barlib"},
Blueprint: `
cc_library {
name: "barlib",
stubs: { symbol_file: "bar.map.txt", versions: ["28", "29", "current"] },
- bazel_module: { bp2build_available: false },
}
cc_library {
name: "foolib",
@@ -2884,16 +2895,15 @@
Filesystem: map[string]string{
"bar.map.txt": "",
},
- Blueprint: SimpleModuleDoNotConvertBp2build("cc_library", "bazlib") + `
+ StubbedBuildDefinitions: []string{"bazlib", "quxlib", "barlib"},
+ Blueprint: simpleModule("cc_library", "bazlib") + `
cc_library {
name: "quxlib",
stubs: { symbol_file: "bar.map.txt", versions: ["current"] },
- bazel_module: { bp2build_available: false },
}
cc_library {
name: "barlib",
stubs: { symbol_file: "bar.map.txt", versions: ["28", "29", "current"] },
- bazel_module: { bp2build_available: false },
}
cc_library {
name: "foolib",
@@ -3007,18 +3017,18 @@
cc_library {
name: "foo",
- runtime_libs: ["foo"],
+ runtime_libs: ["bar"],
}`,
ExpectedBazelTargets: []string{
MakeBazelTarget("cc_library_shared", "bar", AttrNameToString{
"local_includes": `["."]`,
}),
MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{
- "runtime_deps": `[":foo"]`,
+ "runtime_deps": `[":bar"]`,
"local_includes": `["."]`,
}),
MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
- "runtime_deps": `[":foo"]`,
+ "runtime_deps": `[":bar"]`,
"local_includes": `["."]`,
}),
},
@@ -3229,6 +3239,7 @@
Description: "cc_library with non aidl filegroup",
ModuleTypeUnderTest: "cc_library",
ModuleTypeUnderTestFactory: cc.LibraryFactory,
+ StubbedBuildDefinitions: []string{"//path/to/A:A_aidl"},
Filesystem: map[string]string{
"path/to/A/Android.bp": `
filegroup {
@@ -3518,6 +3529,7 @@
Description: "cc_aidl_library depends on libs from parent cc_library_static",
ModuleTypeUnderTest: "cc_library",
ModuleTypeUnderTestFactory: cc.LibraryFactory,
+ StubbedBuildDefinitions: []string{"bar-static", "baz-static", "bar-shared", "baz-shared"},
Blueprint: `
cc_library_static {
name: "foo",
@@ -3539,10 +3551,10 @@
"baz-shared",
],
}` +
- SimpleModuleDoNotConvertBp2build("cc_library_static", "bar-static") +
- SimpleModuleDoNotConvertBp2build("cc_library_static", "baz-static") +
- SimpleModuleDoNotConvertBp2build("cc_library", "bar-shared") +
- SimpleModuleDoNotConvertBp2build("cc_library", "baz-shared"),
+ simpleModule("cc_library_static", "bar-static") +
+ simpleModule("cc_library_static", "baz-static") +
+ simpleModule("cc_library", "bar-shared") +
+ simpleModule("cc_library", "baz-shared"),
ExpectedBazelTargets: []string{
MakeBazelTarget("aidl_library", "foo_aidl_library", AttrNameToString{
"srcs": `["Foo.aidl"]`,
@@ -4086,17 +4098,16 @@
Description: "cc_library with in apex with stub shared_libs and export_shared_lib_headers",
ModuleTypeUnderTest: "cc_library",
ModuleTypeUnderTestFactory: cc.LibraryFactory,
+ StubbedBuildDefinitions: []string{"barlib", "bazlib"},
Blueprint: `
cc_library {
name: "barlib",
stubs: { symbol_file: "bar.map.txt", versions: ["28", "29", "current"] },
- bazel_module: { bp2build_available: false },
apex_available: ["//apex_available:platform",],
}
cc_library {
name: "bazlib",
stubs: { symbol_file: "bar.map.txt", versions: ["28", "29", "current"] },
- bazel_module: { bp2build_available: false },
apex_available: ["//apex_available:platform",],
}
cc_library {
@@ -4472,6 +4483,7 @@
Description: "cc_library is built from .y/.yy files",
ModuleTypeUnderTest: "cc_library",
ModuleTypeUnderTestFactory: cc.LibraryFactory,
+ StubbedBuildDefinitions: []string{"staticlib", "sharedlib"},
Blueprint: soongCcLibraryPreamble + `cc_library {
name: "a",
srcs: [
@@ -4488,11 +4500,9 @@
}
cc_library_static {
name: "staticlib",
- bazel_module: { bp2build_available: false },
}
cc_library {
name: "sharedlib",
- bazel_module: { bp2build_available: false },
}
`,
ExpectedBazelTargets: []string{
@@ -4746,7 +4756,7 @@
canonical_path_from_root: true,
}
}
-` + SimpleModuleDoNotConvertBp2build("cc_library", "libprotobuf-cpp-lite"),
+` + simpleModule("cc_library", "libprotobuf-cpp-lite"),
Filesystem: map[string]string{
"bar/Android.bp": "",
"baz/subbaz/Android.bp": "",
@@ -4814,7 +4824,7 @@
canonical_path_from_root: false,
}
}
-` + SimpleModuleDoNotConvertBp2build("cc_library", "libprotobuf-cpp-lite"),
+` + simpleModule("cc_library", "libprotobuf-cpp-lite"),
Filesystem: map[string]string{
"bar/Android.bp": "",
"baz/subbaz/Android.bp": "",
@@ -4884,7 +4894,7 @@
include_dirs: ["bar"],
}
}
-` + SimpleModuleDoNotConvertBp2build("cc_library", "libprotobuf-cpp-lite"),
+` + simpleModule("cc_library", "libprotobuf-cpp-lite"),
Filesystem: map[string]string{
"bar/Android.bp": "",
"bar/bar.proto": "",
@@ -4955,7 +4965,7 @@
include_dirs: ["baz"],
}
}
-` + SimpleModuleDoNotConvertBp2build("cc_library", "libprotobuf-cpp-lite"),
+` + simpleModule("cc_library", "libprotobuf-cpp-lite"),
Filesystem: map[string]string{
"bar/Android.bp": "", // package boundary
"baz/Android.bp": "",
@@ -4990,7 +5000,14 @@
Description: "cc_library depends on .proto files using proto.local_include_dirs",
ModuleTypeUnderTest: "cc_library",
ModuleTypeUnderTestFactory: cc.LibraryFactory,
- Blueprint: SimpleModuleDoNotConvertBp2build("cc_library", "libprotobuf-cpp-lite"),
+ Blueprint: `
+cc_library {
+ name: "libprotobuf-cpp-lite",
+ // TODO: b/285631638 - A stubbed proto library dependency does not work as a protolib
+ // dependency of cc_library_static.
+ bazel_module: { bp2build_available: false },
+}
+`,
Filesystem: map[string]string{
"foo/Android.bp": `cc_library_static {
name: "foo",
@@ -5047,7 +5064,7 @@
Description: "proto_library generated for proto.include_dirs is compatible for all axes",
ModuleTypeUnderTest: "cc_library",
ModuleTypeUnderTestFactory: cc.LibraryFactory,
- Blueprint: SimpleModuleDoNotConvertBp2build("cc_library", "libprotobuf-cpp-lite") + `
+ Blueprint: simpleModule("cc_library", "libprotobuf-cpp-lite") + `
cc_library {
name: "foo_device",
device_supported: true, // this is the default behavior, but added explicitly here for illustration