Fix duplicate deps issue related to stubs

It turns out that we accidentally add deps twice to the apex related
config axes if they exist simultaneously in the android and
no-config axes in the bp2build logic for stubs. This change ensures
that this does not happen.

Fixes: 245518215
Test: Unit tests
Test: bp2build with relevant module
Change-Id: Iab037d60a08a869f6ee00928090d2b544490590b
This commit is contained in:
Trevor Radcliffe 2022-09-12 20:19:26 +00:00
parent 609c3e074f
commit 0ed6b7d90a
2 changed files with 39 additions and 5 deletions

View file

@ -2680,6 +2680,40 @@ cc_library {
)
}
func TestCcLibraryStubsAcrossConfigsDuplicatesRemoved(t *testing.T) {
runCcLibraryTestCase(t, Bp2buildTestCase{
Description: "stub target generation of the same lib across configs should not result in duplicates",
ModuleTypeUnderTest: "cc_library",
ModuleTypeUnderTestFactory: cc.LibraryFactory,
Filesystem: map[string]string{
"bar.map.txt": "",
},
Blueprint: `
cc_library {
name: "barlib",
stubs: { symbol_file: "bar.map.txt", versions: ["28", "29", "current"] },
bazel_module: { bp2build_available: false },
}
cc_library {
name: "foolib",
shared_libs: ["barlib"],
target: {
android: {
shared_libs: ["barlib"],
},
},
bazel_module: { bp2build_available: true },
}`,
ExpectedBazelTargets: makeCcLibraryTargets("foolib", AttrNameToString{
"implementation_dynamic_deps": `select({
"//build/bazel/rules/apex:android-in_apex": [":barlib_stub_libs_current"],
"//conditions:default": [":barlib"],
})`,
"local_includes": `["."]`,
}),
})
}
func TestCcLibraryEscapeLdflags(t *testing.T) {
runCcLibraryTestCase(t, Bp2buildTestCase{
ModuleTypeUnderTest: "cc_library",

View file

@ -933,14 +933,14 @@ func (la *linkerAttributes) bp2buildForAxisAndConfig(ctx android.BazelConversion
(&inApexSelectValue).Append(bazel.MakeLabelList(stubLibLabels))
(&nonApexSelectValue).Append(bazel.MakeLabelList(depsWithStubs))
(&defaultSelectValue).Append(bazel.MakeLabelList(depsWithStubs))
la.implementationDynamicDeps.SetSelectValue(bazel.OsAndInApexAxis, bazel.AndroidAndInApex, inApexSelectValue)
la.implementationDynamicDeps.SetSelectValue(bazel.OsAndInApexAxis, bazel.AndroidAndNonApex, nonApexSelectValue)
la.implementationDynamicDeps.SetSelectValue(bazel.OsAndInApexAxis, bazel.ConditionsDefaultConfigKey, defaultSelectValue)
la.implementationDynamicDeps.SetSelectValue(bazel.OsAndInApexAxis, bazel.AndroidAndInApex, bazel.FirstUniqueBazelLabelList(inApexSelectValue))
la.implementationDynamicDeps.SetSelectValue(bazel.OsAndInApexAxis, bazel.AndroidAndNonApex, bazel.FirstUniqueBazelLabelList(nonApexSelectValue))
la.implementationDynamicDeps.SetSelectValue(bazel.OsAndInApexAxis, bazel.ConditionsDefaultConfigKey, bazel.FirstUniqueBazelLabelList(defaultSelectValue))
} else if config == bazel.OsAndroid {
(&inApexSelectValue).Append(bazel.MakeLabelList(stubLibLabels))
(&nonApexSelectValue).Append(bazel.MakeLabelList(depsWithStubs))
la.implementationDynamicDeps.SetSelectValue(bazel.OsAndInApexAxis, bazel.AndroidAndInApex, inApexSelectValue)
la.implementationDynamicDeps.SetSelectValue(bazel.OsAndInApexAxis, bazel.AndroidAndNonApex, nonApexSelectValue)
la.implementationDynamicDeps.SetSelectValue(bazel.OsAndInApexAxis, bazel.AndroidAndInApex, bazel.FirstUniqueBazelLabelList(inApexSelectValue))
la.implementationDynamicDeps.SetSelectValue(bazel.OsAndInApexAxis, bazel.AndroidAndNonApex, bazel.FirstUniqueBazelLabelList(nonApexSelectValue))
}
}
}