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

Commit 39b6cc53 authored by Spandan Das's avatar Spandan Das
Browse files

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
parent f57a966b
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -800,6 +800,13 @@ func ConvertApexAvailableToTags(apexAvailable []string) []string {
	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(
	bazelProps bazel.BazelTargetModuleProperties,
	commonAttrs CommonAttributes,
+1 −1
Original line number Diff line number Diff line
@@ -234,7 +234,7 @@ func Bp2buildProtoProperties(ctx Bp2buildMutatorContext, m *ModuleBase, srcs baz
			}
		}

		tags := ApexAvailableTags(ctx.Module())
		tags := ApexAvailableTagsWithoutTestApexes(ctx.(TopDownMutatorContext), ctx.Module())

		ctx.CreateBazelTargetModule(
			bazel.BazelTargetModuleProperties{Rule_class: "proto_library"},
+1 −1
Original line number Diff line number Diff line
@@ -661,7 +661,7 @@ func binaryBp2build(ctx android.TopDownMutatorContext, m *Module) {
	// shared with cc_test
	binaryAttrs := binaryBp2buildAttrs(ctx, m)

	tags := android.ApexAvailableTags(m)
	tags := android.ApexAvailableTagsWithoutTestApexes(ctx, m)
	ctx.CreateBazelTargetModule(bazel.BazelTargetModuleProperties{
		Rule_class:        "cc_binary",
		Bzl_load_location: "//build/bazel/rules/cc:cc_binary.bzl",
+2 −2
Original line number Diff line number Diff line
@@ -270,7 +270,7 @@ func bp2buildParseStaticOrSharedProps(ctx android.BazelConversionPathContext, mo
	attrs.Srcs_c = partitionedSrcs[cSrcPartition]
	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))

@@ -923,7 +923,7 @@ func bp2buildCcAidlLibrary(
			return false
		})

		apexAvailableTags := android.ApexAvailableTags(ctx.Module())
		apexAvailableTags := android.ApexAvailableTagsWithoutTestApexes(ctx.(android.TopDownMutatorContext), ctx.Module())
		sdkAttrs := bp2BuildParseSdkAttributes(m)

		if !aidlSrcs.IsEmpty() {
+1 −1
Original line number Diff line number Diff line
@@ -151,7 +151,7 @@ func libraryHeadersBp2Build(ctx android.TopDownMutatorContext, module *Module) {
		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{
		Name: module.Name(),
Loading