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_binary_conversion_test.go b/bp2build/cc_binary_conversion_test.go
index 3d3b860..c679703 100644
--- a/bp2build/cc_binary_conversion_test.go
+++ b/bp2build/cc_binary_conversion_test.go
@@ -44,10 +44,11 @@
}
type ccBinaryBp2buildTestCase struct {
- description string
- filesystem map[string]string
- blueprint string
- targets []testBazelTarget
+ description string
+ filesystem map[string]string
+ blueprint string
+ targets []testBazelTarget
+ stubbedBuildDefinitions []string
}
func registerCcBinaryModuleTypes(ctx android.RegistrationContext) {
@@ -81,6 +82,7 @@
Description: description,
Blueprint: binaryReplacer.Replace(testCase.blueprint),
Filesystem: testCase.filesystem,
+ StubbedBuildDefinitions: testCase.stubbedBuildDefinitions,
})
})
}
@@ -97,6 +99,7 @@
Description: description,
Blueprint: hostBinaryReplacer.Replace(testCase.blueprint),
Filesystem: testCase.filesystem,
+ StubbedBuildDefinitions: testCase.stubbedBuildDefinitions,
})
})
}
@@ -107,6 +110,7 @@
filesystem: map[string]string{
soongCcVersionLibBpPath: soongCcVersionLibBp,
},
+ stubbedBuildDefinitions: []string{"//build/soong/cc/libbuildversion:libbuildversion"},
blueprint: `
{rule_name} {
name: "foo",
@@ -264,7 +268,8 @@
func TestCcBinarySplitSrcsByLang(t *testing.T) {
runCcHostBinaryTestCase(t, ccBinaryBp2buildTestCase{
- description: "split srcs by lang",
+ description: "split srcs by lang",
+ stubbedBuildDefinitions: []string{"fg_foo"},
blueprint: `
{rule_name} {
name: "foo",
@@ -276,7 +281,7 @@
],
include_build_directory: false,
}
-` + SimpleModuleDoNotConvertBp2build("filegroup", "fg_foo"),
+` + simpleModule("filegroup", "fg_foo"),
targets: []testBazelTarget{
{"cc_binary", "foo", AttrNameToString{
"srcs": `[
@@ -300,17 +305,17 @@
func TestCcBinaryDoNotDistinguishBetweenDepsAndImplementationDeps(t *testing.T) {
runCcBinaryTestCase(t, ccBinaryBp2buildTestCase{
description: "no implementation deps",
+ stubbedBuildDefinitions: []string{"generated_hdr", "export_generated_hdr", "static_dep", "implementation_static_dep",
+ "whole_static_dep", "not_explicitly_exported_whole_static_dep", "shared_dep", "implementation_shared_dep"},
blueprint: `
genrule {
name: "generated_hdr",
cmd: "nothing to see here",
- bazel_module: { bp2build_available: false },
}
genrule {
name: "export_generated_hdr",
cmd: "nothing to see here",
- bazel_module: { bp2build_available: false },
}
{rule_name} {
@@ -326,12 +331,12 @@
export_generated_headers: ["export_generated_hdr"],
}
` +
- SimpleModuleDoNotConvertBp2build("cc_library_static", "static_dep") +
- SimpleModuleDoNotConvertBp2build("cc_library_static", "implementation_static_dep") +
- SimpleModuleDoNotConvertBp2build("cc_library_static", "whole_static_dep") +
- SimpleModuleDoNotConvertBp2build("cc_library_static", "not_explicitly_exported_whole_static_dep") +
- SimpleModuleDoNotConvertBp2build("cc_library", "shared_dep") +
- SimpleModuleDoNotConvertBp2build("cc_library", "implementation_shared_dep"),
+ simpleModule("cc_library_static", "static_dep") +
+ simpleModule("cc_library_static", "implementation_static_dep") +
+ simpleModule("cc_library_static", "whole_static_dep") +
+ simpleModule("cc_library_static", "not_explicitly_exported_whole_static_dep") +
+ simpleModule("cc_library", "shared_dep") +
+ simpleModule("cc_library", "implementation_shared_dep"),
targets: []testBazelTarget{
{"cc_binary", "foo", AttrNameToString{
"deps": `[
@@ -502,6 +507,7 @@
func TestCcBinarySharedProto(t *testing.T) {
runCcBinaryTests(t, ccBinaryBp2buildTestCase{
+ stubbedBuildDefinitions: []string{"libprotobuf-cpp-full", "libprotobuf-cpp-lite"},
blueprint: soongCcProtoLibraries + `{rule_name} {
name: "foo",
srcs: ["foo.proto"],
@@ -524,6 +530,7 @@
func TestCcBinaryStaticProto(t *testing.T) {
runCcBinaryTests(t, ccBinaryBp2buildTestCase{
+ stubbedBuildDefinitions: []string{"libprotobuf-cpp-full", "libprotobuf-cpp-lite"},
blueprint: soongCcProtoLibraries + `{rule_name} {
name: "foo",
srcs: ["foo.proto"],
@@ -1224,13 +1231,13 @@
func TestCcBinaryStatic_SystemSharedLibUsedAsDep(t *testing.T) {
runCcBinaryTestCase(t, ccBinaryBp2buildTestCase{
- description: "cc_library_static system_shared_lib empty for linux_bionic variant",
+ stubbedBuildDefinitions: []string{"libm", "libc"},
+ description: "cc_library_static system_shared_lib empty for linux_bionic variant",
blueprint: soongCcLibraryStaticPreamble +
- SimpleModuleDoNotConvertBp2build("cc_library", "libc") + `
+ simpleModule("cc_library", "libc") + `
cc_library {
name: "libm",
- bazel_module: { bp2build_available: false },
}
cc_binary {