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

Commit 934d5047 authored by Spandan Das's avatar Spandan Das Committed by Gerrit Code Review
Browse files

Merge changes from topic "bp2build-ignore-test-apex-tags"

* changes:
  Ignore test apexes from bp2build generated tags
  Ignore test apexes from bp2build generated tags
parents 098f49de 39b6cc53
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -462,6 +462,14 @@ const (
	AvailableToGkiApex  = "com.android.gki.*"
)

var (
	AvailableToRecognziedWildcards = []string{
		AvailableToPlatform,
		AvailableToAnyApex,
		AvailableToGkiApex,
	}
)

// CheckAvailableForApex provides the default algorithm for checking the apex availability. When the
// availability is empty, it defaults to ["//apex_available:platform"] which means "available to the
// platform but not available to any APEX". When the list is not empty, `what` is matched against
@@ -925,3 +933,9 @@ func CheckMinSdkVersion(ctx ModuleContext, minSdkVersion ApiLevel, walk WalkPayl
		return true
	})
}

// Implemented by apexBundle.
type ApexTestInterface interface {
	// Return true if the apex bundle is an apex_test
	IsTestApex() bool
}
+36 −0
Original line number Diff line number Diff line
@@ -781,6 +781,35 @@ func ApexAvailableTags(mod Module) bazel.StringListAttribute {
	return attr
}

func ApexAvailableTagsWithoutTestApexes(ctx BaseModuleContext, mod Module) bazel.StringListAttribute {
	attr := bazel.StringListAttribute{}
	if am, ok := mod.(ApexModule); ok {
		apexAvailableWithoutTestApexes := removeTestApexes(ctx, am.apexModuleBase().ApexAvailable())
		// If a user does not specify apex_available in Android.bp, then soong provides a default.
		// To avoid verbosity of BUILD files, remove this default from user-facing BUILD files.
		if len(am.apexModuleBase().ApexProperties.Apex_available) == 0 {
			apexAvailableWithoutTestApexes = []string{}
		}
		attr.Value = ConvertApexAvailableToTags(apexAvailableWithoutTestApexes)
	}
	return attr
}

func removeTestApexes(ctx BaseModuleContext, apex_available []string) []string {
	testApexes := []string{}
	for _, aa := range apex_available {
		// ignore the wildcards
		if InList(aa, AvailableToRecognziedWildcards) {
			continue
		}
		mod, _ := ctx.ModuleFromName(aa)
		if apex, ok := mod.(ApexTestInterface); ok && apex.IsTestApex() {
			testApexes = append(testApexes, aa)
		}
	}
	return RemoveListFromList(CopyOf(apex_available), testApexes)
}

func ConvertApexAvailableToTags(apexAvailable []string) []string {
	if len(apexAvailable) == 0 {
		// We need nil specifically to make bp2build not add the tags property at all,
@@ -794,6 +823,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"},
+4 −0
Original line number Diff line number Diff line
@@ -3811,3 +3811,7 @@ func makeSharedLibsAttributes(config string, libsLabelList bazel.LabelList,
func invalidCompileMultilib(ctx android.TopDownMutatorContext, value string) {
	ctx.PropertyErrorf("compile_multilib", "Invalid value: %s", value)
}

func (a *apexBundle) IsTestApex() bool {
	return a.testApex
}
+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",
Loading