Loading bp2build/cc_test_conversion_test.go +31 −13 Original line number Diff line number Diff line Loading @@ -121,7 +121,6 @@ cc_test_library { "//conditions:default": [], })`, "gtest": "True", "isolated": "True", "local_includes": `["."]`, "dynamic_deps": `[":cc_test_lib2"] + select({ "//build/bazel/platforms/os:android": [":foolib"], Loading Loading @@ -158,7 +157,6 @@ cc_test { targets: []testBazelTarget{ {"cc_test", "mytest", AttrNameToString{ "gtest": "False", "isolated": "False", "local_includes": `["."]`, "srcs": `["test.cpp"]`, }, Loading @@ -185,7 +183,6 @@ cc_test { "local_includes": `["."]`, "srcs": `["test.cpp"]`, "gtest": "True", "isolated": "True", "deps": `[ ":libgtest_main", ":libgtest", Loading Loading @@ -213,7 +210,6 @@ cc_test { targets: []testBazelTarget{ {"cc_test", "mytest", AttrNameToString{ "gtest": "True", "isolated": "True", "local_includes": `["."]`, "srcs": `["test.cpp"]`, "target_compatible_with": `["//build/bazel/platforms/os:android"]`, Loading Loading @@ -244,7 +240,6 @@ cc_test { targets: []testBazelTarget{ {"cc_test", "mytest", AttrNameToString{ "gtest": "True", "isolated": "True", "local_includes": `["."]`, "srcs": `["test.cpp"]`, "target_compatible_with": `["//build/bazel/platforms/os:android"]`, Loading @@ -271,14 +266,14 @@ cc_test { srcs: ["test.cpp"], test_config_template: "test_config_template.xml", auto_gen_config: true, isolated: true, } ` + simpleModuleDoNotConvertBp2build("cc_library_static", "libgtest_main") + simpleModuleDoNotConvertBp2build("cc_library_static", "libgtest"), ` + simpleModuleDoNotConvertBp2build("cc_library_static", "libgtest_isolated_main") + simpleModuleDoNotConvertBp2build("cc_library", "liblog"), targets: []testBazelTarget{ {"cc_test", "mytest", AttrNameToString{ "auto_generate_test_config": "True", "gtest": "True", "isolated": "True", "local_includes": `["."]`, "srcs": `["test.cpp"]`, "target_compatible_with": `["//build/bazel/platforms/os:android"]`, Loading @@ -288,10 +283,8 @@ cc_test { ]`, "template_install_base": `"/data/local/tmp"`, "template_test_config": `"test_config_template.xml"`, "deps": `[ ":libgtest_main", ":libgtest", ]`, "deps": `[":libgtest_isolated_main"]`, "dynamic_deps": `[":liblog"]`, }, }, }, Loading @@ -312,7 +305,6 @@ cc_test { targets: []testBazelTarget{ {"cc_test", "mytest", AttrNameToString{ "gtest": "True", "isolated": "True", "local_includes": `["."]`, "srcs": `["test.cpp"]`, "target_compatible_with": `["//build/bazel/platforms/os:android"]`, Loading @@ -326,3 +318,29 @@ cc_test { }) } func TestCcTest_WithIsolatedTurnedOn(t *testing.T) { runCcTestTestCase(t, ccTestBp2buildTestCase{ description: "cc test that sets `isolated: true` should run with ligtest_isolated_main instead of libgtest_main", blueprint: ` cc_test { name: "mytest", srcs: ["test.cpp"], isolated: true, } ` + simpleModuleDoNotConvertBp2build("cc_library_static", "libgtest_isolated_main") + simpleModuleDoNotConvertBp2build("cc_library", "liblog"), targets: []testBazelTarget{ {"cc_test", "mytest", AttrNameToString{ "gtest": "True", "local_includes": `["."]`, "srcs": `["test.cpp"]`, "target_compatible_with": `["//build/bazel/platforms/os:android"]`, "deps": `[":libgtest_isolated_main"]`, "dynamic_deps": `[":liblog"]`, }, }, }, }) } cc/test.go +22 −16 Original line number Diff line number Diff line Loading @@ -267,7 +267,7 @@ func (test *testDecorator) gtest() bool { return BoolDefault(test.LinkerProperties.Gtest, true) } func (test *testDecorator) isolated(ctx BaseModuleContext) bool { func (test *testDecorator) isolated(ctx android.EarlyModuleContext) bool { return BoolDefault(test.LinkerProperties.Isolated, false) } Loading Loading @@ -683,7 +683,6 @@ type testBinaryAttributes struct { binaryAttributes Gtest bool Isolated bool tidyAttributes tradefed.TestConfigAttributes Loading Loading @@ -721,15 +720,15 @@ func testBinaryBp2build(ctx android.TopDownMutatorContext, m *Module) { m.convertTidyAttributes(ctx, &testBinaryAttrs.tidyAttributes) gtestIsolated := m.linker.(*testBinary).isolated(ctx) for _, propIntf := range m.GetProperties() { if testLinkerProps, ok := propIntf.(*TestLinkerProperties); ok { testBinaryAttrs.Gtest = proptools.BoolDefault(testLinkerProps.Gtest, true) testBinaryAttrs.Isolated = proptools.BoolDefault(testLinkerProps.Isolated, true) break } } addImplicitGtestDeps(ctx, &testBinaryAttrs) addImplicitGtestDeps(ctx, &testBinaryAttrs, gtestIsolated) for _, testProps := range m.GetProperties() { if p, ok := testProps.(*TestBinaryProperties); ok { Loading @@ -742,7 +741,7 @@ func testBinaryBp2build(ctx android.TopDownMutatorContext, m *Module) { p.Auto_gen_config, p.Test_options.Test_suite_tag, p.Test_config_template, getTradefedConfigOptions(ctx, p, testBinaryAttrs.Isolated), getTradefedConfigOptions(ctx, p, gtestIsolated), &testInstallBase, ) testBinaryAttrs.TestConfigAttributes = testConfigAttributes Loading @@ -765,18 +764,25 @@ func testBinaryBp2build(ctx android.TopDownMutatorContext, m *Module) { // 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) { func addImplicitGtestDeps(ctx android.BazelConversionPathContext, attrs *testBinaryAttributes, gtestIsolated bool) { addDepsAndDedupe := func(lla *bazel.LabelListAttribute, modules []string) { moduleLabels := android.BazelLabelForModuleDeps(ctx, modules) lla.Value.Append(moduleLabels) // Dedupe lla.Value = bazel.FirstUniqueBazelLabelList(lla.Value) } // 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 if attrs.Gtest { gtestDeps := android.BazelLabelForModuleDeps( ctx, []string{ // TODO - b/244433197: Handle canUseSdk if gtestIsolated { addDepsAndDedupe(&attrs.Deps, []string{"libgtest_isolated_main"}) addDepsAndDedupe(&attrs.Dynamic_deps, []string{"liblog"}) } else { addDepsAndDedupe(&attrs.Deps, []string{ "libgtest_main", "libgtest", }, ) attrs.Deps.Value.Append(gtestDeps) // Dedupe attrs.Deps.Value = bazel.FirstUniqueBazelLabelList(attrs.Deps.Value) }) } } // TODO(b/244432609): handle `isolated` property. } Loading
bp2build/cc_test_conversion_test.go +31 −13 Original line number Diff line number Diff line Loading @@ -121,7 +121,6 @@ cc_test_library { "//conditions:default": [], })`, "gtest": "True", "isolated": "True", "local_includes": `["."]`, "dynamic_deps": `[":cc_test_lib2"] + select({ "//build/bazel/platforms/os:android": [":foolib"], Loading Loading @@ -158,7 +157,6 @@ cc_test { targets: []testBazelTarget{ {"cc_test", "mytest", AttrNameToString{ "gtest": "False", "isolated": "False", "local_includes": `["."]`, "srcs": `["test.cpp"]`, }, Loading @@ -185,7 +183,6 @@ cc_test { "local_includes": `["."]`, "srcs": `["test.cpp"]`, "gtest": "True", "isolated": "True", "deps": `[ ":libgtest_main", ":libgtest", Loading Loading @@ -213,7 +210,6 @@ cc_test { targets: []testBazelTarget{ {"cc_test", "mytest", AttrNameToString{ "gtest": "True", "isolated": "True", "local_includes": `["."]`, "srcs": `["test.cpp"]`, "target_compatible_with": `["//build/bazel/platforms/os:android"]`, Loading Loading @@ -244,7 +240,6 @@ cc_test { targets: []testBazelTarget{ {"cc_test", "mytest", AttrNameToString{ "gtest": "True", "isolated": "True", "local_includes": `["."]`, "srcs": `["test.cpp"]`, "target_compatible_with": `["//build/bazel/platforms/os:android"]`, Loading @@ -271,14 +266,14 @@ cc_test { srcs: ["test.cpp"], test_config_template: "test_config_template.xml", auto_gen_config: true, isolated: true, } ` + simpleModuleDoNotConvertBp2build("cc_library_static", "libgtest_main") + simpleModuleDoNotConvertBp2build("cc_library_static", "libgtest"), ` + simpleModuleDoNotConvertBp2build("cc_library_static", "libgtest_isolated_main") + simpleModuleDoNotConvertBp2build("cc_library", "liblog"), targets: []testBazelTarget{ {"cc_test", "mytest", AttrNameToString{ "auto_generate_test_config": "True", "gtest": "True", "isolated": "True", "local_includes": `["."]`, "srcs": `["test.cpp"]`, "target_compatible_with": `["//build/bazel/platforms/os:android"]`, Loading @@ -288,10 +283,8 @@ cc_test { ]`, "template_install_base": `"/data/local/tmp"`, "template_test_config": `"test_config_template.xml"`, "deps": `[ ":libgtest_main", ":libgtest", ]`, "deps": `[":libgtest_isolated_main"]`, "dynamic_deps": `[":liblog"]`, }, }, }, Loading @@ -312,7 +305,6 @@ cc_test { targets: []testBazelTarget{ {"cc_test", "mytest", AttrNameToString{ "gtest": "True", "isolated": "True", "local_includes": `["."]`, "srcs": `["test.cpp"]`, "target_compatible_with": `["//build/bazel/platforms/os:android"]`, Loading @@ -326,3 +318,29 @@ cc_test { }) } func TestCcTest_WithIsolatedTurnedOn(t *testing.T) { runCcTestTestCase(t, ccTestBp2buildTestCase{ description: "cc test that sets `isolated: true` should run with ligtest_isolated_main instead of libgtest_main", blueprint: ` cc_test { name: "mytest", srcs: ["test.cpp"], isolated: true, } ` + simpleModuleDoNotConvertBp2build("cc_library_static", "libgtest_isolated_main") + simpleModuleDoNotConvertBp2build("cc_library", "liblog"), targets: []testBazelTarget{ {"cc_test", "mytest", AttrNameToString{ "gtest": "True", "local_includes": `["."]`, "srcs": `["test.cpp"]`, "target_compatible_with": `["//build/bazel/platforms/os:android"]`, "deps": `[":libgtest_isolated_main"]`, "dynamic_deps": `[":liblog"]`, }, }, }, }) }
cc/test.go +22 −16 Original line number Diff line number Diff line Loading @@ -267,7 +267,7 @@ func (test *testDecorator) gtest() bool { return BoolDefault(test.LinkerProperties.Gtest, true) } func (test *testDecorator) isolated(ctx BaseModuleContext) bool { func (test *testDecorator) isolated(ctx android.EarlyModuleContext) bool { return BoolDefault(test.LinkerProperties.Isolated, false) } Loading Loading @@ -683,7 +683,6 @@ type testBinaryAttributes struct { binaryAttributes Gtest bool Isolated bool tidyAttributes tradefed.TestConfigAttributes Loading Loading @@ -721,15 +720,15 @@ func testBinaryBp2build(ctx android.TopDownMutatorContext, m *Module) { m.convertTidyAttributes(ctx, &testBinaryAttrs.tidyAttributes) gtestIsolated := m.linker.(*testBinary).isolated(ctx) for _, propIntf := range m.GetProperties() { if testLinkerProps, ok := propIntf.(*TestLinkerProperties); ok { testBinaryAttrs.Gtest = proptools.BoolDefault(testLinkerProps.Gtest, true) testBinaryAttrs.Isolated = proptools.BoolDefault(testLinkerProps.Isolated, true) break } } addImplicitGtestDeps(ctx, &testBinaryAttrs) addImplicitGtestDeps(ctx, &testBinaryAttrs, gtestIsolated) for _, testProps := range m.GetProperties() { if p, ok := testProps.(*TestBinaryProperties); ok { Loading @@ -742,7 +741,7 @@ func testBinaryBp2build(ctx android.TopDownMutatorContext, m *Module) { p.Auto_gen_config, p.Test_options.Test_suite_tag, p.Test_config_template, getTradefedConfigOptions(ctx, p, testBinaryAttrs.Isolated), getTradefedConfigOptions(ctx, p, gtestIsolated), &testInstallBase, ) testBinaryAttrs.TestConfigAttributes = testConfigAttributes Loading @@ -765,18 +764,25 @@ func testBinaryBp2build(ctx android.TopDownMutatorContext, m *Module) { // 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) { func addImplicitGtestDeps(ctx android.BazelConversionPathContext, attrs *testBinaryAttributes, gtestIsolated bool) { addDepsAndDedupe := func(lla *bazel.LabelListAttribute, modules []string) { moduleLabels := android.BazelLabelForModuleDeps(ctx, modules) lla.Value.Append(moduleLabels) // Dedupe lla.Value = bazel.FirstUniqueBazelLabelList(lla.Value) } // 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 if attrs.Gtest { gtestDeps := android.BazelLabelForModuleDeps( ctx, []string{ // TODO - b/244433197: Handle canUseSdk if gtestIsolated { addDepsAndDedupe(&attrs.Deps, []string{"libgtest_isolated_main"}) addDepsAndDedupe(&attrs.Dynamic_deps, []string{"liblog"}) } else { addDepsAndDedupe(&attrs.Deps, []string{ "libgtest_main", "libgtest", }, ) attrs.Deps.Value.Append(gtestDeps) // Dedupe attrs.Deps.Value = bazel.FirstUniqueBazelLabelList(attrs.Deps.Value) }) } } // TODO(b/244432609): handle `isolated` property. }