Merge "Correct global excludes not always being excluded"

This commit is contained in:
Liz Kammer 2023-01-26 20:09:14 +00:00 committed by Gerrit Code Review
commit 0725a60e5d
6 changed files with 137 additions and 50 deletions

View file

@ -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

View file

@ -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 {

View file

@ -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": `["."]`,
}),

View file

@ -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 {

View file

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

View file

@ -979,34 +979,22 @@ var (
// resolveTargetApex re-adds the shared and static libs in target.apex.exclude_shared|static_libs props to non-apex variant
// since all libs are already excluded by default
func (la *linkerAttributes) resolveTargetApexProp(ctx android.BazelConversionPathContext, isBinary bool, props *BaseLinkerProperties) {
sharedLibsForNonApex := maybePartitionExportedAndImplementationsDeps(
ctx,
true,
props.Target.Apex.Exclude_shared_libs,
props.Export_shared_lib_headers,
bazelLabelForSharedDeps,
)
dynamicDeps := la.dynamicDeps.SelectValue(bazel.InApexAxis, bazel.NonApex)
implDynamicDeps := la.implementationDynamicDeps.SelectValue(bazel.InApexAxis, bazel.NonApex)
(&dynamicDeps).Append(sharedLibsForNonApex.export)
(&implDynamicDeps).Append(sharedLibsForNonApex.implementation)
la.dynamicDeps.SetSelectValue(bazel.InApexAxis, bazel.NonApex, dynamicDeps)
la.implementationDynamicDeps.SetSelectValue(bazel.InApexAxis, bazel.NonApex, implDynamicDeps)
func (la *linkerAttributes) resolveTargetApexProp(ctx android.BazelConversionPathContext, props *BaseLinkerProperties) {
excludeSharedLibs := bazelLabelForSharedDeps(ctx, props.Target.Apex.Exclude_shared_libs)
sharedExcludes := bazel.LabelList{Excludes: excludeSharedLibs.Includes}
sharedExcludesLabelList := bazel.LabelListAttribute{}
sharedExcludesLabelList.SetSelectValue(bazel.InApexAxis, bazel.InApex, sharedExcludes)
staticLibsForNonApex := maybePartitionExportedAndImplementationsDeps(
ctx,
!isBinary,
props.Target.Apex.Exclude_static_libs,
props.Export_static_lib_headers,
bazelLabelForSharedDeps,
)
deps := la.deps.SelectValue(bazel.InApexAxis, bazel.NonApex)
implDeps := la.implementationDeps.SelectValue(bazel.InApexAxis, bazel.NonApex)
(&deps).Append(staticLibsForNonApex.export)
(&implDeps).Append(staticLibsForNonApex.implementation)
la.deps.SetSelectValue(bazel.InApexAxis, bazel.NonApex, deps)
la.implementationDeps.SetSelectValue(bazel.InApexAxis, bazel.NonApex, implDeps)
la.dynamicDeps.Append(sharedExcludesLabelList)
la.implementationDynamicDeps.Append(sharedExcludesLabelList)
excludeStaticLibs := bazelLabelForStaticDeps(ctx, props.Target.Apex.Exclude_static_libs)
staticExcludes := bazel.LabelList{Excludes: excludeStaticLibs.Includes}
staticExcludesLabelList := bazel.LabelListAttribute{}
staticExcludesLabelList.SetSelectValue(bazel.InApexAxis, bazel.InApex, staticExcludes)
la.deps.Append(staticExcludesLabelList)
la.implementationDeps.Append(staticExcludesLabelList)
}
func (la *linkerAttributes) bp2buildForAxisAndConfig(ctx android.BazelConversionPathContext, isBinary bool, axis bazel.ConfigurationAxis, config string, props *BaseLinkerProperties) {
@ -1040,8 +1028,7 @@ func (la *linkerAttributes) bp2buildForAxisAndConfig(ctx android.BazelConversion
ctx,
!isBinary,
staticLibs,
// Exclude static libs in Exclude_static_libs and Target.Apex.Exclude_static_libs props
append(props.Exclude_static_libs, props.Target.Apex.Exclude_static_libs...),
props.Exclude_static_libs,
props.Export_static_lib_headers,
bazelLabelForStaticDepsExcludes,
)
@ -1080,14 +1067,13 @@ func (la *linkerAttributes) bp2buildForAxisAndConfig(ctx android.BazelConversion
ctx,
!isBinary,
sharedLibs,
// Exclude shared libs in Exclude_shared_libs and Target.Apex.Exclude_shared_libs props
append(props.Exclude_shared_libs, props.Target.Apex.Exclude_shared_libs...),
props.Exclude_shared_libs,
props.Export_shared_lib_headers,
bazelLabelForSharedDepsExcludes,
)
la.dynamicDeps.SetSelectValue(axis, config, sharedDeps.export)
la.implementationDynamicDeps.SetSelectValue(axis, config, sharedDeps.implementation)
la.resolveTargetApexProp(ctx, isBinary, props)
la.resolveTargetApexProp(ctx, props)
if axis == bazel.NoConfigAxis || (axis == bazel.OsConfigurationAxis && config == bazel.OsAndroid) {
// If a dependency in la.implementationDynamicDeps has stubs, its stub variant should be