Correct global excludes not always being excluded
Test: bp2build go tests
Fixes: 266617441
Change-Id: I82418ef8da4cca880d5adac98853805a18a9780e
diff --git a/bp2build/cc_library_conversion_test.go b/bp2build/cc_library_conversion_test.go
index 052bc32..244ca9c 100644
--- a/bp2build/cc_library_conversion_test.go
+++ b/bp2build/cc_library_conversion_test.go
@@ -3437,23 +3437,23 @@
ExpectedBazelTargets: []string{
MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{
"implementation_deps": `[":baz__BP2BUILD__MISSING__DEP"] + select({
- "//build/bazel/rules/apex:non_apex": [":buh__BP2BUILD__MISSING__DEP"],
- "//conditions:default": [],
+ "//build/bazel/rules/apex:in_apex": [],
+ "//conditions:default": [":buh__BP2BUILD__MISSING__DEP"],
})`,
"implementation_dynamic_deps": `[":baz__BP2BUILD__MISSING__DEP"] + select({
- "//build/bazel/rules/apex:non_apex": [":bar__BP2BUILD__MISSING__DEP"],
- "//conditions:default": [],
+ "//build/bazel/rules/apex:in_apex": [],
+ "//conditions:default": [":bar__BP2BUILD__MISSING__DEP"],
})`,
"local_includes": `["."]`,
}),
MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
"implementation_deps": `[":baz__BP2BUILD__MISSING__DEP"] + select({
- "//build/bazel/rules/apex:non_apex": [":buh__BP2BUILD__MISSING__DEP"],
- "//conditions:default": [],
+ "//build/bazel/rules/apex:in_apex": [],
+ "//conditions:default": [":buh__BP2BUILD__MISSING__DEP"],
})`,
"implementation_dynamic_deps": `[":baz__BP2BUILD__MISSING__DEP"] + select({
- "//build/bazel/rules/apex:non_apex": [":bar__BP2BUILD__MISSING__DEP"],
- "//conditions:default": [],
+ "//build/bazel/rules/apex:in_apex": [],
+ "//conditions:default": [":bar__BP2BUILD__MISSING__DEP"],
})`,
"local_includes": `["."]`,
}),
@@ -3483,16 +3483,16 @@
ExpectedBazelTargets: []string{
MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
"implementation_dynamic_deps": `select({
- "//build/bazel/rules/apex:non_apex": [":bar__BP2BUILD__MISSING__DEP"],
- "//conditions:default": [],
+ "//build/bazel/rules/apex:in_apex": [],
+ "//conditions:default": [":bar__BP2BUILD__MISSING__DEP"],
})`,
"dynamic_deps": `select({
- "//build/bazel/rules/apex:non_apex": [":baz__BP2BUILD__MISSING__DEP"],
- "//conditions:default": [],
+ "//build/bazel/rules/apex:in_apex": [],
+ "//conditions:default": [":baz__BP2BUILD__MISSING__DEP"],
})`,
"deps": `select({
- "//build/bazel/rules/apex:non_apex": [":abc__BP2BUILD__MISSING__DEP"],
- "//conditions:default": [],
+ "//build/bazel/rules/apex:in_apex": [],
+ "//conditions:default": [":abc__BP2BUILD__MISSING__DEP"],
})`,
"local_includes": `["."]`,
}),
diff --git a/bp2build/soong_config_module_type_conversion_test.go b/bp2build/soong_config_module_type_conversion_test.go
index 89be767..ba42f34 100644
--- a/bp2build/soong_config_module_type_conversion_test.go
+++ b/bp2build/soong_config_module_type_conversion_test.go
@@ -742,6 +742,101 @@
)`}})
}
+func TestSoongConfigModuleType_UnsetConditionsExcludeLibs(t *testing.T) {
+ bp := `
+soong_config_string_variable {
+ name: "library_linking_strategy",
+ values: [
+ "prefer_static",
+ ],
+}
+
+soong_config_module_type {
+ name: "library_linking_strategy_cc_defaults",
+ module_type: "cc_defaults",
+ config_namespace: "ANDROID",
+ variables: ["library_linking_strategy"],
+ properties: ["shared_libs"],
+}
+
+library_linking_strategy_cc_defaults {
+ name: "library_linking_strategy_lib_a_defaults",
+ soong_config_variables: {
+ library_linking_strategy: {
+ prefer_static: {},
+ conditions_default: {
+ shared_libs: [
+ "lib_a",
+ ],
+ },
+ },
+ },
+}
+
+library_linking_strategy_cc_defaults {
+ name: "library_linking_strategy_merged_defaults",
+ defaults: ["library_linking_strategy_lib_a_defaults"],
+ host_supported: true,
+ soong_config_variables: {
+ library_linking_strategy: {
+ prefer_static: {},
+ conditions_default: {
+ shared_libs: [
+ "lib_b",
+ "lib_c",
+ ],
+ },
+ },
+ },
+ exclude_shared_libs: ["lib_a"],
+}
+
+cc_binary {
+ name: "library_linking_strategy_sample_binary",
+ defaults: ["library_linking_strategy_merged_defaults"],
+ include_build_directory: false,
+}
+
+cc_binary {
+ name: "library_linking_strategy_sample_binary_with_excludes",
+ defaults: ["library_linking_strategy_merged_defaults"],
+ exclude_shared_libs: ["lib_c"],
+ include_build_directory: false,
+}`
+
+ otherDeps := `
+cc_library { name: "lib_a", bazel_module: { bp2build_available: false } }
+cc_library { name: "lib_b", bazel_module: { bp2build_available: false } }
+cc_library { name: "lib_c", bazel_module: { bp2build_available: false } }
+`
+
+ runSoongConfigModuleTypeTest(t, Bp2buildTestCase{
+ Description: "soong config variables - generates selects for library_linking_strategy",
+ ModuleTypeUnderTest: "cc_binary",
+ ModuleTypeUnderTestFactory: cc.BinaryFactory,
+ Blueprint: bp,
+ Filesystem: map[string]string{
+ "foo/bar/Android.bp": otherDeps,
+ },
+ ExpectedBazelTargets: []string{
+ MakeBazelTargetNoRestrictions("cc_binary", "library_linking_strategy_sample_binary", AttrNameToString{
+ "dynamic_deps": `select({
+ "//build/bazel/product_variables:android__library_linking_strategy__prefer_static": [],
+ "//conditions:default": [
+ "//foo/bar:lib_b",
+ "//foo/bar:lib_c",
+ ],
+ })`,
+ }),
+ MakeBazelTargetNoRestrictions("cc_binary", "library_linking_strategy_sample_binary_with_excludes", AttrNameToString{
+ "dynamic_deps": `select({
+ "//build/bazel/product_variables:android__library_linking_strategy__prefer_static": [],
+ "//conditions:default": ["//foo/bar:lib_b"],
+ })`,
+ }),
+ }})
+}
+
func TestSoongConfigModuleType_Defaults(t *testing.T) {
bp := `
soong_config_string_variable {
diff --git a/bp2build/testing.go b/bp2build/testing.go
index c340a8f..92a9bf1 100644
--- a/bp2build/testing.go
+++ b/bp2build/testing.go
@@ -258,6 +258,7 @@
}
func (b BazelTestResult) CompareBazelTargets(t *testing.T, description string, expectedContents []string, actualTargets BazelTargets) {
+ t.Helper()
if actualCount, expectedCount := len(actualTargets), len(expectedContents); actualCount != expectedCount {
t.Errorf("%s: Expected %d bazel target (%s), got %d (%s)",
description, expectedCount, expectedContents, actualCount, actualTargets)