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

Commit b2b9494d authored by Spandan Das's avatar Spandan Das Committed by Automerger Merge Worker
Browse files

Ignore test apexes from bp2build generated tags am: f57a966b

parents a54fd4c0 f57a966b
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
}
+29 −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,
+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
}
+3 −3
Original line number Diff line number Diff line
@@ -433,11 +433,11 @@ func libraryBp2Build(ctx android.TopDownMutatorContext, m *Module) {

	var tagsForStaticVariant bazel.StringListAttribute
	if compilerAttrs.stubsSymbolFile == nil && len(compilerAttrs.stubsVersions.Value) == 0 {
		tagsForStaticVariant = android.ApexAvailableTags(m)
		tagsForStaticVariant = android.ApexAvailableTagsWithoutTestApexes(ctx, m)
	}
	tagsForStaticVariant.Append(bazel.StringListAttribute{Value: staticAttrs.Apex_available})

	tagsForSharedVariant := android.ApexAvailableTags(m)
	tagsForSharedVariant := android.ApexAvailableTagsWithoutTestApexes(ctx, m)
	tagsForSharedVariant.Append(bazel.StringListAttribute{Value: sharedAttrs.Apex_available})

	ctx.CreateBazelTargetModuleWithRestrictions(staticProps,
@@ -3002,7 +3002,7 @@ func sharedOrStaticLibraryBp2Build(ctx android.TopDownMutatorContext, module *Mo
		Bzl_load_location: fmt.Sprintf("//build/bazel/rules/cc:%s.bzl", modType),
	}

	tags := android.ApexAvailableTags(module)
	tags := android.ApexAvailableTagsWithoutTestApexes(ctx, module)

	ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: module.Name(), Tags: tags}, attrs)
}