Merge "Make libtest_* deps explicit in BUILD files" into main am: 35448be862
Original change: https://android-review.googlesource.com/c/platform/build/soong/+/2672196 Change-Id: I221ff71f60968987998d7a6d745547b95c3b8b4e Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -94,7 +94,9 @@ cc_test_library {
|
|||||||
simpleModuleDoNotConvertBp2build("genrule", "data_mod") +
|
simpleModuleDoNotConvertBp2build("genrule", "data_mod") +
|
||||||
simpleModuleDoNotConvertBp2build("cc_binary", "cc_bin") +
|
simpleModuleDoNotConvertBp2build("cc_binary", "cc_bin") +
|
||||||
simpleModuleDoNotConvertBp2build("cc_library", "cc_lib") +
|
simpleModuleDoNotConvertBp2build("cc_library", "cc_lib") +
|
||||||
simpleModuleDoNotConvertBp2build("cc_test_library", "cc_test_lib2"),
|
simpleModuleDoNotConvertBp2build("cc_test_library", "cc_test_lib2") +
|
||||||
|
simpleModuleDoNotConvertBp2build("cc_library_static", "libgtest_main") +
|
||||||
|
simpleModuleDoNotConvertBp2build("cc_library_static", "libgtest"),
|
||||||
targets: []testBazelTarget{
|
targets: []testBazelTarget{
|
||||||
{"cc_library_shared", "cc_test_lib1", AttrNameToString{}},
|
{"cc_library_shared", "cc_test_lib1", AttrNameToString{}},
|
||||||
{"cc_library_static", "cc_test_lib1_bp2build_cc_library_static", AttrNameToString{}},
|
{"cc_library_static", "cc_test_lib1_bp2build_cc_library_static", AttrNameToString{}},
|
||||||
@@ -106,7 +108,11 @@ cc_test_library {
|
|||||||
":cc_bin",
|
":cc_bin",
|
||||||
":cc_lib",
|
":cc_lib",
|
||||||
]`,
|
]`,
|
||||||
"deps": `[":cc_test_lib1_bp2build_cc_library_static"] + select({
|
"deps": `[
|
||||||
|
":cc_test_lib1_bp2build_cc_library_static",
|
||||||
|
":libgtest_main",
|
||||||
|
":libgtest",
|
||||||
|
] + select({
|
||||||
"//build/bazel/platforms/os:darwin": [":hostlib"],
|
"//build/bazel/platforms/os:darwin": [":hostlib"],
|
||||||
"//build/bazel/platforms/os:linux_bionic": [":hostlib"],
|
"//build/bazel/platforms/os:linux_bionic": [":hostlib"],
|
||||||
"//build/bazel/platforms/os:linux_glibc": [":hostlib"],
|
"//build/bazel/platforms/os:linux_glibc": [":hostlib"],
|
||||||
@@ -171,7 +177,8 @@ cc_test {
|
|||||||
srcs: ["test.cpp"],
|
srcs: ["test.cpp"],
|
||||||
test_options: { tags: ["no-remote"] },
|
test_options: { tags: ["no-remote"] },
|
||||||
}
|
}
|
||||||
`,
|
` + simpleModuleDoNotConvertBp2build("cc_library_static", "libgtest_main") +
|
||||||
|
simpleModuleDoNotConvertBp2build("cc_library_static", "libgtest"),
|
||||||
targets: []testBazelTarget{
|
targets: []testBazelTarget{
|
||||||
{"cc_test", "mytest", AttrNameToString{
|
{"cc_test", "mytest", AttrNameToString{
|
||||||
"tags": `["no-remote"]`,
|
"tags": `["no-remote"]`,
|
||||||
@@ -179,6 +186,10 @@ cc_test {
|
|||||||
"srcs": `["test.cpp"]`,
|
"srcs": `["test.cpp"]`,
|
||||||
"gtest": "True",
|
"gtest": "True",
|
||||||
"isolated": "True",
|
"isolated": "True",
|
||||||
|
"deps": `[
|
||||||
|
":libgtest_main",
|
||||||
|
":libgtest",
|
||||||
|
]`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -197,7 +208,8 @@ cc_test {
|
|||||||
srcs: ["test.cpp"],
|
srcs: ["test.cpp"],
|
||||||
test_config: "test_config.xml",
|
test_config: "test_config.xml",
|
||||||
}
|
}
|
||||||
`,
|
` + simpleModuleDoNotConvertBp2build("cc_library_static", "libgtest_main") +
|
||||||
|
simpleModuleDoNotConvertBp2build("cc_library_static", "libgtest"),
|
||||||
targets: []testBazelTarget{
|
targets: []testBazelTarget{
|
||||||
{"cc_test", "mytest", AttrNameToString{
|
{"cc_test", "mytest", AttrNameToString{
|
||||||
"gtest": "True",
|
"gtest": "True",
|
||||||
@@ -206,6 +218,10 @@ cc_test {
|
|||||||
"srcs": `["test.cpp"]`,
|
"srcs": `["test.cpp"]`,
|
||||||
"target_compatible_with": `["//build/bazel/platforms/os:android"]`,
|
"target_compatible_with": `["//build/bazel/platforms/os:android"]`,
|
||||||
"test_config": `"test_config.xml"`,
|
"test_config": `"test_config.xml"`,
|
||||||
|
"deps": `[
|
||||||
|
":libgtest_main",
|
||||||
|
":libgtest",
|
||||||
|
]`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -223,7 +239,8 @@ cc_test {
|
|||||||
name: "mytest",
|
name: "mytest",
|
||||||
srcs: ["test.cpp"],
|
srcs: ["test.cpp"],
|
||||||
}
|
}
|
||||||
`,
|
` + simpleModuleDoNotConvertBp2build("cc_library_static", "libgtest_main") +
|
||||||
|
simpleModuleDoNotConvertBp2build("cc_library_static", "libgtest"),
|
||||||
targets: []testBazelTarget{
|
targets: []testBazelTarget{
|
||||||
{"cc_test", "mytest", AttrNameToString{
|
{"cc_test", "mytest", AttrNameToString{
|
||||||
"gtest": "True",
|
"gtest": "True",
|
||||||
@@ -232,6 +249,10 @@ cc_test {
|
|||||||
"srcs": `["test.cpp"]`,
|
"srcs": `["test.cpp"]`,
|
||||||
"target_compatible_with": `["//build/bazel/platforms/os:android"]`,
|
"target_compatible_with": `["//build/bazel/platforms/os:android"]`,
|
||||||
"test_config": `"AndroidTest.xml"`,
|
"test_config": `"AndroidTest.xml"`,
|
||||||
|
"deps": `[
|
||||||
|
":libgtest_main",
|
||||||
|
":libgtest",
|
||||||
|
]`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -251,7 +272,8 @@ cc_test {
|
|||||||
test_config_template: "test_config_template.xml",
|
test_config_template: "test_config_template.xml",
|
||||||
auto_gen_config: true,
|
auto_gen_config: true,
|
||||||
}
|
}
|
||||||
`,
|
` + simpleModuleDoNotConvertBp2build("cc_library_static", "libgtest_main") +
|
||||||
|
simpleModuleDoNotConvertBp2build("cc_library_static", "libgtest"),
|
||||||
targets: []testBazelTarget{
|
targets: []testBazelTarget{
|
||||||
{"cc_test", "mytest", AttrNameToString{
|
{"cc_test", "mytest", AttrNameToString{
|
||||||
"auto_generate_test_config": "True",
|
"auto_generate_test_config": "True",
|
||||||
@@ -266,8 +288,41 @@ cc_test {
|
|||||||
]`,
|
]`,
|
||||||
"template_install_base": `"/data/local/tmp"`,
|
"template_install_base": `"/data/local/tmp"`,
|
||||||
"template_test_config": `"test_config_template.xml"`,
|
"template_test_config": `"test_config_template.xml"`,
|
||||||
|
"deps": `[
|
||||||
|
":libgtest_main",
|
||||||
|
":libgtest",
|
||||||
|
]`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestCcTest_WithExplicitGTestDepInAndroidBp(t *testing.T) {
|
||||||
|
runCcTestTestCase(t, ccTestBp2buildTestCase{
|
||||||
|
description: "cc test that lists libgtest in Android.bp should not have dups of libgtest in BUILD file",
|
||||||
|
blueprint: `
|
||||||
|
cc_test {
|
||||||
|
name: "mytest",
|
||||||
|
srcs: ["test.cpp"],
|
||||||
|
static_libs: ["libgtest"],
|
||||||
|
}
|
||||||
|
` + simpleModuleDoNotConvertBp2build("cc_library_static", "libgtest_main") +
|
||||||
|
simpleModuleDoNotConvertBp2build("cc_library_static", "libgtest"),
|
||||||
|
targets: []testBazelTarget{
|
||||||
|
{"cc_test", "mytest", AttrNameToString{
|
||||||
|
"gtest": "True",
|
||||||
|
"isolated": "True",
|
||||||
|
"local_includes": `["."]`,
|
||||||
|
"srcs": `["test.cpp"]`,
|
||||||
|
"target_compatible_with": `["//build/bazel/platforms/os:android"]`,
|
||||||
|
"deps": `[
|
||||||
|
":libgtest",
|
||||||
|
":libgtest_main",
|
||||||
|
]`,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
|
20
cc/test.go
20
cc/test.go
@@ -729,6 +729,8 @@ func testBinaryBp2build(ctx android.TopDownMutatorContext, m *Module) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
addImplicitGtestDeps(ctx, &testBinaryAttrs)
|
||||||
|
|
||||||
for _, testProps := range m.GetProperties() {
|
for _, testProps := range m.GetProperties() {
|
||||||
if p, ok := testProps.(*TestBinaryProperties); ok {
|
if p, ok := testProps.(*TestBinaryProperties); ok {
|
||||||
useVendor := false // TODO Bug: 262914724
|
useVendor := false // TODO Bug: 262914724
|
||||||
@@ -760,3 +762,21 @@ func testBinaryBp2build(ctx android.TopDownMutatorContext, m *Module) {
|
|||||||
},
|
},
|
||||||
&testBinaryAttrs)
|
&testBinaryAttrs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// cc_test that builds using gtest needs some additional deps
|
||||||
|
// addImplicitGtestDeps makes these deps explicit in the generated BUILD files
|
||||||
|
func addImplicitGtestDeps(ctx android.BazelConversionPathContext, attrs *testBinaryAttributes) {
|
||||||
|
if attrs.Gtest {
|
||||||
|
gtestDeps := android.BazelLabelForModuleDeps(
|
||||||
|
ctx,
|
||||||
|
[]string{
|
||||||
|
"libgtest_main",
|
||||||
|
"libgtest",
|
||||||
|
},
|
||||||
|
)
|
||||||
|
attrs.Deps.Value.Append(gtestDeps)
|
||||||
|
// Dedupe
|
||||||
|
attrs.Deps.Value = bazel.FirstUniqueBazelLabelList(attrs.Deps.Value)
|
||||||
|
}
|
||||||
|
// TODO(b/244432609): handle `isolated` property.
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user