Ignore test apexes from bp2build generated tags
Soong does not enforce apex_available on the contents of test apex. To prevent special-casing test apexes in the apex validation aspect in Bazel, drop the test apexes from the tags altogether. ( The core problem I am trying to solve is making sure that stub libraries in Bazel have a single apex available. apex validation happens to be a nice side benefit) Bug: 277651159 Test: go test ./bp2build Change-Id: Ibb3cfedb5c0f2cda0464bf3758c70b67cb5885d1
This commit is contained in:
@@ -800,6 +800,13 @@ func ConvertApexAvailableToTags(apexAvailable []string) []string {
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ConvertApexAvailableToTagsWithoutTestApexes converts a list of apex names to a list of bazel tags
|
||||||
|
// This function drops any test apexes from the input.
|
||||||
|
func ConvertApexAvailableToTagsWithoutTestApexes(ctx BaseModuleContext, apexAvailable []string) []string {
|
||||||
|
noTestApexes := removeTestApexes(ctx, apexAvailable)
|
||||||
|
return ConvertApexAvailableToTags(noTestApexes)
|
||||||
|
}
|
||||||
|
|
||||||
func (t *topDownMutatorContext) createBazelTargetModule(
|
func (t *topDownMutatorContext) createBazelTargetModule(
|
||||||
bazelProps bazel.BazelTargetModuleProperties,
|
bazelProps bazel.BazelTargetModuleProperties,
|
||||||
commonAttrs CommonAttributes,
|
commonAttrs CommonAttributes,
|
||||||
|
@@ -234,7 +234,7 @@ func Bp2buildProtoProperties(ctx Bp2buildMutatorContext, m *ModuleBase, srcs baz
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tags := ApexAvailableTags(ctx.Module())
|
tags := ApexAvailableTagsWithoutTestApexes(ctx.(TopDownMutatorContext), ctx.Module())
|
||||||
|
|
||||||
ctx.CreateBazelTargetModule(
|
ctx.CreateBazelTargetModule(
|
||||||
bazel.BazelTargetModuleProperties{Rule_class: "proto_library"},
|
bazel.BazelTargetModuleProperties{Rule_class: "proto_library"},
|
||||||
|
@@ -661,7 +661,7 @@ func binaryBp2build(ctx android.TopDownMutatorContext, m *Module) {
|
|||||||
// shared with cc_test
|
// shared with cc_test
|
||||||
binaryAttrs := binaryBp2buildAttrs(ctx, m)
|
binaryAttrs := binaryBp2buildAttrs(ctx, m)
|
||||||
|
|
||||||
tags := android.ApexAvailableTags(m)
|
tags := android.ApexAvailableTagsWithoutTestApexes(ctx, m)
|
||||||
ctx.CreateBazelTargetModule(bazel.BazelTargetModuleProperties{
|
ctx.CreateBazelTargetModule(bazel.BazelTargetModuleProperties{
|
||||||
Rule_class: "cc_binary",
|
Rule_class: "cc_binary",
|
||||||
Bzl_load_location: "//build/bazel/rules/cc:cc_binary.bzl",
|
Bzl_load_location: "//build/bazel/rules/cc:cc_binary.bzl",
|
||||||
|
@@ -270,7 +270,7 @@ func bp2buildParseStaticOrSharedProps(ctx android.BazelConversionPathContext, mo
|
|||||||
attrs.Srcs_c = partitionedSrcs[cSrcPartition]
|
attrs.Srcs_c = partitionedSrcs[cSrcPartition]
|
||||||
attrs.Srcs_as = partitionedSrcs[asSrcPartition]
|
attrs.Srcs_as = partitionedSrcs[asSrcPartition]
|
||||||
|
|
||||||
attrs.Apex_available = android.ConvertApexAvailableToTags(apexAvailable)
|
attrs.Apex_available = android.ConvertApexAvailableToTagsWithoutTestApexes(ctx.(android.TopDownMutatorContext), apexAvailable)
|
||||||
|
|
||||||
attrs.Features.Append(convertHiddenVisibilityToFeatureStaticOrShared(ctx, module, isStatic))
|
attrs.Features.Append(convertHiddenVisibilityToFeatureStaticOrShared(ctx, module, isStatic))
|
||||||
|
|
||||||
@@ -923,7 +923,7 @@ func bp2buildCcAidlLibrary(
|
|||||||
return false
|
return false
|
||||||
})
|
})
|
||||||
|
|
||||||
apexAvailableTags := android.ApexAvailableTags(ctx.Module())
|
apexAvailableTags := android.ApexAvailableTagsWithoutTestApexes(ctx.(android.TopDownMutatorContext), ctx.Module())
|
||||||
sdkAttrs := bp2BuildParseSdkAttributes(m)
|
sdkAttrs := bp2BuildParseSdkAttributes(m)
|
||||||
|
|
||||||
if !aidlSrcs.IsEmpty() {
|
if !aidlSrcs.IsEmpty() {
|
||||||
|
@@ -151,7 +151,7 @@ func libraryHeadersBp2Build(ctx android.TopDownMutatorContext, module *Module) {
|
|||||||
Bzl_load_location: "//build/bazel/rules/cc:cc_library_headers.bzl",
|
Bzl_load_location: "//build/bazel/rules/cc:cc_library_headers.bzl",
|
||||||
}
|
}
|
||||||
|
|
||||||
tags := android.ApexAvailableTags(module)
|
tags := android.ApexAvailableTagsWithoutTestApexes(ctx, module)
|
||||||
|
|
||||||
ctx.CreateBazelTargetModule(props, android.CommonAttributes{
|
ctx.CreateBazelTargetModule(props, android.CommonAttributes{
|
||||||
Name: module.Name(),
|
Name: module.Name(),
|
||||||
|
@@ -226,7 +226,7 @@ func objectBp2Build(ctx android.TopDownMutatorContext, m *Module) {
|
|||||||
Bzl_load_location: "//build/bazel/rules/cc:cc_object.bzl",
|
Bzl_load_location: "//build/bazel/rules/cc:cc_object.bzl",
|
||||||
}
|
}
|
||||||
|
|
||||||
tags := android.ApexAvailableTags(m)
|
tags := android.ApexAvailableTagsWithoutTestApexes(ctx, m)
|
||||||
|
|
||||||
ctx.CreateBazelTargetModule(props, android.CommonAttributes{
|
ctx.CreateBazelTargetModule(props, android.CommonAttributes{
|
||||||
Name: m.Name(),
|
Name: m.Name(),
|
||||||
|
@@ -389,7 +389,7 @@ func prebuiltLibraryStaticBp2Build(ctx android.TopDownMutatorContext, module *Mo
|
|||||||
name += "_bp2build_cc_library_static"
|
name += "_bp2build_cc_library_static"
|
||||||
}
|
}
|
||||||
|
|
||||||
tags := android.ApexAvailableTags(module)
|
tags := android.ApexAvailableTagsWithoutTestApexes(ctx, module)
|
||||||
ctx.CreateBazelTargetModuleWithRestrictions(props, android.CommonAttributes{Name: name, Tags: tags}, attrs, prebuiltAttrs.Enabled)
|
ctx.CreateBazelTargetModuleWithRestrictions(props, android.CommonAttributes{Name: name, Tags: tags}, attrs, prebuiltAttrs.Enabled)
|
||||||
|
|
||||||
_true := true
|
_true := true
|
||||||
@@ -420,7 +420,7 @@ func prebuiltLibrarySharedBp2Build(ctx android.TopDownMutatorContext, module *Mo
|
|||||||
}
|
}
|
||||||
|
|
||||||
name := android.RemoveOptionalPrebuiltPrefix(module.Name())
|
name := android.RemoveOptionalPrebuiltPrefix(module.Name())
|
||||||
tags := android.ApexAvailableTags(module)
|
tags := android.ApexAvailableTagsWithoutTestApexes(ctx, module)
|
||||||
ctx.CreateBazelTargetModuleWithRestrictions(props, android.CommonAttributes{Name: name, Tags: tags}, attrs, prebuiltAttrs.Enabled)
|
ctx.CreateBazelTargetModuleWithRestrictions(props, android.CommonAttributes{Name: name, Tags: tags}, attrs, prebuiltAttrs.Enabled)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -650,7 +650,7 @@ func prebuiltObjectBp2Build(ctx android.TopDownMutatorContext, module *Module) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
name := android.RemoveOptionalPrebuiltPrefix(module.Name())
|
name := android.RemoveOptionalPrebuiltPrefix(module.Name())
|
||||||
tags := android.ApexAvailableTags(module)
|
tags := android.ApexAvailableTagsWithoutTestApexes(ctx, module)
|
||||||
ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: name, Tags: tags}, attrs)
|
ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: name, Tags: tags}, attrs)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -813,7 +813,7 @@ func prebuiltBinaryBp2Build(ctx android.TopDownMutatorContext, module *Module) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
name := android.RemoveOptionalPrebuiltPrefix(module.Name())
|
name := android.RemoveOptionalPrebuiltPrefix(module.Name())
|
||||||
tags := android.ApexAvailableTags(module)
|
tags := android.ApexAvailableTagsWithoutTestApexes(ctx, module)
|
||||||
ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: name, Tags: tags}, attrs)
|
ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: name, Tags: tags}, attrs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -207,7 +207,7 @@ func bp2buildProto(ctx android.Bp2buildMutatorContext, m *Module, protoSrcs baze
|
|||||||
protoAttrs.Min_sdk_version = m.Properties.Min_sdk_version
|
protoAttrs.Min_sdk_version = m.Properties.Min_sdk_version
|
||||||
|
|
||||||
name := m.Name() + suffix
|
name := m.Name() + suffix
|
||||||
tags := android.ApexAvailableTags(m)
|
tags := android.ApexAvailableTagsWithoutTestApexes(ctx.(android.TopDownMutatorContext), m)
|
||||||
ctx.CreateBazelTargetModule(
|
ctx.CreateBazelTargetModule(
|
||||||
bazel.BazelTargetModuleProperties{
|
bazel.BazelTargetModuleProperties{
|
||||||
Rule_class: rule_class,
|
Rule_class: rule_class,
|
||||||
|
@@ -38,7 +38,7 @@ type SyspropLibraryLabels struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Bp2buildSysprop(ctx android.Bp2buildMutatorContext, labels SyspropLibraryLabels, srcs bazel.LabelListAttribute, minSdkVersion *string) {
|
func Bp2buildSysprop(ctx android.Bp2buildMutatorContext, labels SyspropLibraryLabels, srcs bazel.LabelListAttribute, minSdkVersion *string) {
|
||||||
apexAvailableTags := android.ApexAvailableTags(ctx.Module())
|
apexAvailableTags := android.ApexAvailableTagsWithoutTestApexes(ctx.(android.TopDownMutatorContext), ctx.Module())
|
||||||
ctx.CreateBazelTargetModule(
|
ctx.CreateBazelTargetModule(
|
||||||
bazel.BazelTargetModuleProperties{
|
bazel.BazelTargetModuleProperties{
|
||||||
Rule_class: "sysprop_library",
|
Rule_class: "sysprop_library",
|
||||||
|
@@ -940,7 +940,7 @@ func (m *Module) ConvertWithBp2build(ctx android.TopDownMutatorContext) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tags := android.ApexAvailableTags(m)
|
tags := android.ApexAvailableTagsWithoutTestApexes(ctx, m)
|
||||||
|
|
||||||
if ctx.ModuleType() == "gensrcs" {
|
if ctx.ModuleType() == "gensrcs" {
|
||||||
// The Output_extension prop is not in an immediately accessible field
|
// The Output_extension prop is not in an immediately accessible field
|
||||||
|
@@ -2839,7 +2839,7 @@ func (m *Library) convertLibraryAttrsBp2Build(ctx android.TopDownMutatorContext)
|
|||||||
return android.IsConvertedToAidlLibrary(ctx, src.OriginalModuleName)
|
return android.IsConvertedToAidlLibrary(ctx, src.OriginalModuleName)
|
||||||
})
|
})
|
||||||
|
|
||||||
apexAvailableTags := android.ApexAvailableTags(ctx.Module())
|
apexAvailableTags := android.ApexAvailableTagsWithoutTestApexes(ctx, ctx.Module())
|
||||||
|
|
||||||
if !aidlSrcs.IsEmpty() {
|
if !aidlSrcs.IsEmpty() {
|
||||||
aidlLibName := m.Name() + "_aidl_library"
|
aidlLibName := m.Name() + "_aidl_library"
|
||||||
|
Reference in New Issue
Block a user