Remove apex_available tag in cc_library_static generated from stubs-providing lib

When a cc library has stubs, its static variant shouldn't be included in an apex to ensure the library with stubs isn't statically linked. See https://cs.android.com/android/platform/superproject/+/master:build/soong/apex/apex.go;l=2804;drc=89b01aeaa9e19377ff547baab791277719b8aaf3

This CL modifies bp2build so that it excludes apex_available tag from the static target if the library has stubs. This way, we can ensure that no apex can depend on the static target which results to static linking.

Test: go test
Bug: 255589949
Change-Id: Iedf248994b808436f2440570b094fd06d6284ae9
This commit is contained in:
Vinh Tran
2022-12-20 10:38:48 -05:00
parent 2266e02a3a
commit 55225e343d
2 changed files with 79 additions and 3 deletions

View File

@@ -453,17 +453,23 @@ func libraryBp2Build(ctx android.TopDownMutatorContext, m *Module) {
Bzl_load_location: "//build/bazel/rules/cc:cc_library_shared.bzl",
}
tags := android.ApexAvailableTags(m)
var tagsForStaticVariant bazel.StringListAttribute
if compilerAttrs.stubsSymbolFile == nil && len(compilerAttrs.stubsVersions.Value) == 0 {
tagsForStaticVariant = android.ApexAvailableTags(m)
}
tagsForSharedVariant := android.ApexAvailableTags(m)
ctx.CreateBazelTargetModuleWithRestrictions(staticProps,
android.CommonAttributes{
Name: m.Name() + "_bp2build_cc_library_static",
Tags: tags,
Tags: tagsForStaticVariant,
},
staticTargetAttrs, staticAttrs.Enabled)
ctx.CreateBazelTargetModuleWithRestrictions(sharedProps,
android.CommonAttributes{
Name: m.Name(),
Tags: tags,
Tags: tagsForSharedVariant,
},
sharedTargetAttrs, sharedAttrs.Enabled)