Merge "Emit gtest in BUILD files only if Android.bp sets it" into main
This commit is contained in:
@@ -120,7 +120,6 @@ cc_test_library {
|
|||||||
"//build/bazel/platforms/os:windows": [":hostlib"],
|
"//build/bazel/platforms/os:windows": [":hostlib"],
|
||||||
"//conditions:default": [],
|
"//conditions:default": [],
|
||||||
})`,
|
})`,
|
||||||
"gtest": "True",
|
|
||||||
"local_includes": `["."]`,
|
"local_includes": `["."]`,
|
||||||
"dynamic_deps": `[":cc_test_lib2"] + select({
|
"dynamic_deps": `[":cc_test_lib2"] + select({
|
||||||
"//build/bazel/platforms/os:android": [":foolib"],
|
"//build/bazel/platforms/os:android": [":foolib"],
|
||||||
@@ -182,7 +181,6 @@ cc_test {
|
|||||||
"tags": `["no-remote"]`,
|
"tags": `["no-remote"]`,
|
||||||
"local_includes": `["."]`,
|
"local_includes": `["."]`,
|
||||||
"srcs": `["test.cpp"]`,
|
"srcs": `["test.cpp"]`,
|
||||||
"gtest": "True",
|
|
||||||
"deps": `[
|
"deps": `[
|
||||||
":libgtest_main",
|
":libgtest_main",
|
||||||
":libgtest",
|
":libgtest",
|
||||||
@@ -209,7 +207,6 @@ cc_test {
|
|||||||
simpleModuleDoNotConvertBp2build("cc_library_static", "libgtest"),
|
simpleModuleDoNotConvertBp2build("cc_library_static", "libgtest"),
|
||||||
targets: []testBazelTarget{
|
targets: []testBazelTarget{
|
||||||
{"cc_test", "mytest", AttrNameToString{
|
{"cc_test", "mytest", AttrNameToString{
|
||||||
"gtest": "True",
|
|
||||||
"local_includes": `["."]`,
|
"local_includes": `["."]`,
|
||||||
"srcs": `["test.cpp"]`,
|
"srcs": `["test.cpp"]`,
|
||||||
"target_compatible_with": `["//build/bazel/platforms/os:android"]`,
|
"target_compatible_with": `["//build/bazel/platforms/os:android"]`,
|
||||||
@@ -239,7 +236,6 @@ cc_test {
|
|||||||
simpleModuleDoNotConvertBp2build("cc_library_static", "libgtest"),
|
simpleModuleDoNotConvertBp2build("cc_library_static", "libgtest"),
|
||||||
targets: []testBazelTarget{
|
targets: []testBazelTarget{
|
||||||
{"cc_test", "mytest", AttrNameToString{
|
{"cc_test", "mytest", AttrNameToString{
|
||||||
"gtest": "True",
|
|
||||||
"local_includes": `["."]`,
|
"local_includes": `["."]`,
|
||||||
"srcs": `["test.cpp"]`,
|
"srcs": `["test.cpp"]`,
|
||||||
"target_compatible_with": `["//build/bazel/platforms/os:android"]`,
|
"target_compatible_with": `["//build/bazel/platforms/os:android"]`,
|
||||||
@@ -273,7 +269,6 @@ cc_test {
|
|||||||
targets: []testBazelTarget{
|
targets: []testBazelTarget{
|
||||||
{"cc_test", "mytest", AttrNameToString{
|
{"cc_test", "mytest", AttrNameToString{
|
||||||
"auto_generate_test_config": "True",
|
"auto_generate_test_config": "True",
|
||||||
"gtest": "True",
|
|
||||||
"local_includes": `["."]`,
|
"local_includes": `["."]`,
|
||||||
"srcs": `["test.cpp"]`,
|
"srcs": `["test.cpp"]`,
|
||||||
"target_compatible_with": `["//build/bazel/platforms/os:android"]`,
|
"target_compatible_with": `["//build/bazel/platforms/os:android"]`,
|
||||||
@@ -304,7 +299,6 @@ cc_test {
|
|||||||
simpleModuleDoNotConvertBp2build("cc_library_static", "libgtest"),
|
simpleModuleDoNotConvertBp2build("cc_library_static", "libgtest"),
|
||||||
targets: []testBazelTarget{
|
targets: []testBazelTarget{
|
||||||
{"cc_test", "mytest", AttrNameToString{
|
{"cc_test", "mytest", AttrNameToString{
|
||||||
"gtest": "True",
|
|
||||||
"local_includes": `["."]`,
|
"local_includes": `["."]`,
|
||||||
"srcs": `["test.cpp"]`,
|
"srcs": `["test.cpp"]`,
|
||||||
"target_compatible_with": `["//build/bazel/platforms/os:android"]`,
|
"target_compatible_with": `["//build/bazel/platforms/os:android"]`,
|
||||||
@@ -332,7 +326,6 @@ cc_test {
|
|||||||
simpleModuleDoNotConvertBp2build("cc_library", "liblog"),
|
simpleModuleDoNotConvertBp2build("cc_library", "liblog"),
|
||||||
targets: []testBazelTarget{
|
targets: []testBazelTarget{
|
||||||
{"cc_test", "mytest", AttrNameToString{
|
{"cc_test", "mytest", AttrNameToString{
|
||||||
"gtest": "True",
|
|
||||||
"local_includes": `["."]`,
|
"local_includes": `["."]`,
|
||||||
"srcs": `["test.cpp"]`,
|
"srcs": `["test.cpp"]`,
|
||||||
"target_compatible_with": `["//build/bazel/platforms/os:android"]`,
|
"target_compatible_with": `["//build/bazel/platforms/os:android"]`,
|
||||||
@@ -344,3 +337,38 @@ cc_test {
|
|||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestCcTest_GtestExplicitlySpecifiedInAndroidBp(t *testing.T) {
|
||||||
|
runCcTestTestCase(t, ccTestBp2buildTestCase{
|
||||||
|
description: "If `gtest` is explicit in Android.bp, it should be explicit in BUILD files as well",
|
||||||
|
blueprint: `
|
||||||
|
cc_test {
|
||||||
|
name: "mytest_with_gtest",
|
||||||
|
gtest: true,
|
||||||
|
}
|
||||||
|
cc_test {
|
||||||
|
name: "mytest_with_no_gtest",
|
||||||
|
gtest: false,
|
||||||
|
}
|
||||||
|
` + simpleModuleDoNotConvertBp2build("cc_library_static", "libgtest_main") +
|
||||||
|
simpleModuleDoNotConvertBp2build("cc_library_static", "libgtest"),
|
||||||
|
targets: []testBazelTarget{
|
||||||
|
{"cc_test", "mytest_with_gtest", AttrNameToString{
|
||||||
|
"local_includes": `["."]`,
|
||||||
|
"deps": `[
|
||||||
|
":libgtest_main",
|
||||||
|
":libgtest",
|
||||||
|
]`,
|
||||||
|
"gtest": "True",
|
||||||
|
"target_compatible_with": `["//build/bazel/platforms/os:android"]`,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{"cc_test", "mytest_with_no_gtest", AttrNameToString{
|
||||||
|
"local_includes": `["."]`,
|
||||||
|
"gtest": "False",
|
||||||
|
"target_compatible_with": `["//build/bazel/platforms/os:android"]`,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
22
cc/test.go
22
cc/test.go
@@ -682,7 +682,7 @@ func (handler *ccTestBazelHandler) ProcessBazelQueryResponse(ctx android.ModuleC
|
|||||||
type testBinaryAttributes struct {
|
type testBinaryAttributes struct {
|
||||||
binaryAttributes
|
binaryAttributes
|
||||||
|
|
||||||
Gtest bool
|
Gtest *bool
|
||||||
|
|
||||||
tidyAttributes
|
tidyAttributes
|
||||||
tradefed.TestConfigAttributes
|
tradefed.TestConfigAttributes
|
||||||
@@ -720,15 +720,15 @@ func testBinaryBp2build(ctx android.TopDownMutatorContext, m *Module) {
|
|||||||
|
|
||||||
m.convertTidyAttributes(ctx, &testBinaryAttrs.tidyAttributes)
|
m.convertTidyAttributes(ctx, &testBinaryAttrs.tidyAttributes)
|
||||||
|
|
||||||
gtestIsolated := m.linker.(*testBinary).isolated(ctx)
|
testBinary := m.linker.(*testBinary)
|
||||||
for _, propIntf := range m.GetProperties() {
|
gtest := testBinary.gtest()
|
||||||
if testLinkerProps, ok := propIntf.(*TestLinkerProperties); ok {
|
gtestIsolated := testBinary.isolated(ctx)
|
||||||
testBinaryAttrs.Gtest = proptools.BoolDefault(testLinkerProps.Gtest, true)
|
// Use the underling bool pointer for Gtest in attrs
|
||||||
break
|
// This ensures that if this property is not set in Android.bp file, it will not be set in BUILD file either
|
||||||
}
|
// cc_test macro will default gtest to True
|
||||||
}
|
testBinaryAttrs.Gtest = testBinary.LinkerProperties.Gtest
|
||||||
|
|
||||||
addImplicitGtestDeps(ctx, &testBinaryAttrs, gtestIsolated)
|
addImplicitGtestDeps(ctx, &testBinaryAttrs, gtest, gtestIsolated)
|
||||||
|
|
||||||
for _, testProps := range m.GetProperties() {
|
for _, testProps := range m.GetProperties() {
|
||||||
if p, ok := testProps.(*TestBinaryProperties); ok {
|
if p, ok := testProps.(*TestBinaryProperties); ok {
|
||||||
@@ -764,7 +764,7 @@ func testBinaryBp2build(ctx android.TopDownMutatorContext, m *Module) {
|
|||||||
|
|
||||||
// cc_test that builds using gtest needs some additional deps
|
// cc_test that builds using gtest needs some additional deps
|
||||||
// addImplicitGtestDeps makes these deps explicit in the generated BUILD files
|
// addImplicitGtestDeps makes these deps explicit in the generated BUILD files
|
||||||
func addImplicitGtestDeps(ctx android.BazelConversionPathContext, attrs *testBinaryAttributes, gtestIsolated bool) {
|
func addImplicitGtestDeps(ctx android.BazelConversionPathContext, attrs *testBinaryAttributes, gtest, gtestIsolated bool) {
|
||||||
addDepsAndDedupe := func(lla *bazel.LabelListAttribute, modules []string) {
|
addDepsAndDedupe := func(lla *bazel.LabelListAttribute, modules []string) {
|
||||||
moduleLabels := android.BazelLabelForModuleDeps(ctx, modules)
|
moduleLabels := android.BazelLabelForModuleDeps(ctx, modules)
|
||||||
lla.Value.Append(moduleLabels)
|
lla.Value.Append(moduleLabels)
|
||||||
@@ -773,7 +773,7 @@ func addImplicitGtestDeps(ctx android.BazelConversionPathContext, attrs *testBin
|
|||||||
}
|
}
|
||||||
// this must be kept in sync with Soong's implementation in:
|
// this must be kept in sync with Soong's implementation in:
|
||||||
// https://cs.android.com/android/_/android/platform/build/soong/+/460fb2d6d546b5ab493a7e5479998c4933a80f73:cc/test.go;l=300-313;drc=ec7314336a2b35ea30ce5438b83949c28e3ac429;bpv=1;bpt=0
|
// https://cs.android.com/android/_/android/platform/build/soong/+/460fb2d6d546b5ab493a7e5479998c4933a80f73:cc/test.go;l=300-313;drc=ec7314336a2b35ea30ce5438b83949c28e3ac429;bpv=1;bpt=0
|
||||||
if attrs.Gtest {
|
if gtest {
|
||||||
// TODO - b/244433197: Handle canUseSdk
|
// TODO - b/244433197: Handle canUseSdk
|
||||||
if gtestIsolated {
|
if gtestIsolated {
|
||||||
addDepsAndDedupe(&attrs.Deps, []string{"libgtest_isolated_main"})
|
addDepsAndDedupe(&attrs.Deps, []string{"libgtest_isolated_main"})
|
||||||
|
Reference in New Issue
Block a user