Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0725a60e authored by Liz Kammer's avatar Liz Kammer Committed by Gerrit Code Review
Browse files

Merge "Correct global excludes not always being excluded"

parents 1db2ff3e 748d7078
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -152,7 +152,7 @@ func (ll *LabelList) Append(other LabelList) {
		ll.Includes = append(ll.Includes, other.Includes...)
	}
	if len(ll.Excludes) > 0 || len(other.Excludes) > 0 {
		ll.Excludes = append(other.Excludes, other.Excludes...)
		ll.Excludes = append(ll.Excludes, other.Excludes...)
	}
}

@@ -888,7 +888,7 @@ func (lla *LabelListAttribute) ResolveExcludes() {
			// then remove all config-specific excludes
			allLabels := baseLabels.deepCopy()
			allLabels.Append(val)
			lla.ConfigurableValues[axis][config] = SubtractBazelLabelList(allLabels, LabelList{Includes: val.Excludes})
			lla.ConfigurableValues[axis][config] = SubtractBazelLabelList(allLabels, LabelList{Includes: allLabels.Excludes})
		}

		// After going through all configs, delete the duplicates in the config
+7 −2
Original line number Diff line number Diff line
@@ -231,6 +231,7 @@ func TestResolveExcludes(t *testing.T) {
				"all_include",
				"arm_exclude",
				"android_exclude",
				"product_config_exclude",
			},
			[]string{"all_exclude"},
		),
@@ -251,10 +252,10 @@ func TestResolveExcludes(t *testing.T) {
				"a":                        makeLabelList([]string{}, []string{"not_in_value"}),
				"b":                        makeLabelList([]string{"b_val"}, []string{}),
				"c":                        makeLabelList([]string{"c_val"}, []string{}),
				ConditionsDefaultConfigKey: makeLabelList([]string{"c_val", "default", "default2"}, []string{}),
				ConditionsDefaultConfigKey: makeLabelList([]string{"c_val", "default", "default2", "all_exclude"}, []string{}),
			},
			ProductVariableConfigurationAxis("product_only_with_excludes", NoConfigAxis): labelListSelectValues{
				"a": makeLabelList([]string{}, []string{"not_in_value"}),
				"a": makeLabelList([]string{}, []string{"product_config_exclude"}),
			},
		},
	}
@@ -287,6 +288,10 @@ func TestResolveExcludes(t *testing.T) {
			"c":                        makeLabels("c_val"),
			ConditionsDefaultConfigKey: makeLabels("c_val", "default", "default2"),
		},
		ProductVariableConfigurationAxis("product_only_with_excludes", NoConfigAxis): {
			"a":                        nilLabels,
			ConditionsDefaultConfigKey: makeLabels("product_config_exclude"),
		},
	}
	for _, axis := range attr.SortedConfigurationAxes() {
		if _, ok := expectedConfiguredIncludes[axis]; !ok {
+14 −14
Original line number Diff line number Diff line
@@ -3437,23 +3437,23 @@ cc_library {
		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 @@ cc_library_static {
		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": `["."]`,
			}),
+95 −0
Original line number Diff line number Diff line
@@ -742,6 +742,101 @@ cc_library { name: "lib_default", bazel_module: { bp2build_available: false } }
)`}})
}

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 {
+1 −0
Original line number Diff line number Diff line
@@ -258,6 +258,7 @@ func (b BazelTestResult) CompareAllBazelTargets(t *testing.T, description string
}

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)
Loading