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

Commit 3146c5cd authored by Colin Cross's avatar Colin Cross
Browse files

Create fewer empty version variants

Don't create empty version variants for binaries, objects, rust
rlibs or rust dylibs.

Test: no change to build.ninja
Change-Id: I62d4d43da476eafdb258a08b5ada758bb2971a1a
parent 1348ce3f
Loading
Loading
Loading
Loading
+3 −8
Original line number Diff line number Diff line
@@ -40,19 +40,14 @@ type binarySdkMemberType struct {

func (mt *binarySdkMemberType) AddDependencies(mctx android.BottomUpMutatorContext, dependencyTag blueprint.DependencyTag, names []string) {
	targets := mctx.MultiTargets()
	for _, lib := range names {
	for _, bin := range names {
		for _, target := range targets {
			name, version := StubsLibNameAndVersion(lib)
			if version == "" {
				version = "latest"
			}
			variations := target.Variations()
			if mctx.Device() {
				variations = append(variations,
					blueprint.Variation{Mutator: "image", Variation: android.CoreVariation},
					blueprint.Variation{Mutator: "version", Variation: version})
					blueprint.Variation{Mutator: "image", Variation: android.CoreVariation})
			}
			mctx.AddFarVariationDependencies(variations, dependencyTag, name)
			mctx.AddFarVariationDependencies(variations, dependencyTag, bin)
		}
	}
}
+3 −3
Original line number Diff line number Diff line
@@ -1871,7 +1871,7 @@ func (c *Module) addSharedLibDependenciesWithVersions(ctx android.BottomUpMutato

	variations = append([]blueprint.Variation(nil), variations...)

	if version != "" && VersionVariantAvailable(c) {
	if version != "" && CanBeOrLinkAgainstVersionVariants(c) {
		// Version is explicitly specified. i.e. libFoo#30
		variations = append(variations, blueprint.Variation{Mutator: "version", Variation: version})
		depTag.explicitlyVersioned = true
@@ -1886,7 +1886,7 @@ func (c *Module) addSharedLibDependenciesWithVersions(ctx android.BottomUpMutato
	// If the version is not specified, add dependency to all stubs libraries.
	// The stubs library will be used when the depending module is built for APEX and
	// the dependent module is not in the same APEX.
	if version == "" && VersionVariantAvailable(c) {
	if version == "" && CanBeOrLinkAgainstVersionVariants(c) {
		if dep, ok := deps[0].(*Module); ok {
			for _, ver := range dep.AllStubsVersions() {
				// Note that depTag.ExplicitlyVersioned is false in this case.
@@ -2492,7 +2492,7 @@ func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {

			if ccDep.CcLibrary() && !libDepTag.static() {
				depIsStubs := ccDep.BuildStubs()
				depHasStubs := VersionVariantAvailable(c) && ccDep.HasStubsVariants()
				depHasStubs := CanBeOrLinkAgainstVersionVariants(c) && ccDep.HasStubsVariants()
				depInSameApexes := android.DirectlyInAllApexes(c.InApexes(), depName)
				depInPlatform := !android.DirectlyInAnyApex(ctx, depName)

+16 −3
Original line number Diff line number Diff line
@@ -1541,7 +1541,7 @@ func createVersionVariations(mctx android.BottomUpMutatorContext, versions []str
	mctx.CreateAliasVariation("latest", latestVersion)
}

func VersionVariantAvailable(module interface {
func CanBeOrLinkAgainstVersionVariants(module interface {
	Host() bool
	InRamdisk() bool
	InRecovery() bool
@@ -1549,10 +1549,23 @@ func VersionVariantAvailable(module interface {
	return !module.Host() && !module.InRamdisk() && !module.InRecovery()
}

func CanBeVersionVariant(module interface {
	Host() bool
	InRamdisk() bool
	InRecovery() bool
	CcLibraryInterface() bool
	Shared() bool
	Static() bool
}) bool {
	return CanBeOrLinkAgainstVersionVariants(module) &&
		module.CcLibraryInterface() && (module.Shared() || module.Static())
}

// versionSelector normalizes the versions in the Stubs.Versions property into MutatedProperties.AllStubsVersions,
// and propagates the value from implementation libraries to llndk libraries with the same name.
func versionSelectorMutator(mctx android.BottomUpMutatorContext) {
	if library, ok := mctx.Module().(LinkableInterface); ok && VersionVariantAvailable(library) {
	if library, ok := mctx.Module().(LinkableInterface); ok && CanBeVersionVariant(library) {

		if library.CcLibrary() && library.BuildSharedVariant() && len(library.StubsVersions()) > 0 &&
			!library.IsSdkVariant() {

@@ -1582,7 +1595,7 @@ func versionSelectorMutator(mctx android.BottomUpMutatorContext) {
// versionMutator splits a module into the mandatory non-stubs variant
// (which is unnamed) and zero or more stubs variants.
func versionMutator(mctx android.BottomUpMutatorContext) {
	if library, ok := mctx.Module().(LinkableInterface); ok && VersionVariantAvailable(library) {
	if library, ok := mctx.Module().(LinkableInterface); ok && CanBeVersionVariant(library) {
		createVersionVariations(mctx, library.AllStubsVersions())
	}
}
+5 −2
Original line number Diff line number Diff line
@@ -85,9 +85,12 @@ func (mt *librarySdkMemberType) AddDependencies(mctx android.BottomUpMutatorCont
			variations := target.Variations()
			if mctx.Device() {
				variations = append(variations,
					blueprint.Variation{Mutator: "image", Variation: android.CoreVariation},
					blueprint.Variation{Mutator: "image", Variation: android.CoreVariation})
				if mt.linkTypes != nil {
					variations = append(variations,
						blueprint.Variation{Mutator: "version", Variation: version})
				}
			}
			if mt.linkTypes == nil {
				mctx.AddFarVariationDependencies(variations, dependencyTag, name)
			} else {
+1 −5
Original line number Diff line number Diff line
@@ -997,11 +997,7 @@ func (mod *Module) DepsMutator(actx android.BottomUpMutatorContext) {
	}

	deps := mod.deps(ctx)
	commonDepVariations := []blueprint.Variation{}
	if cc.VersionVariantAvailable(mod) {
		commonDepVariations = append(commonDepVariations,
			blueprint.Variation{Mutator: "version", Variation: ""})
	}
	var commonDepVariations []blueprint.Variation
	if !mod.Host() {
		commonDepVariations = append(commonDepVariations,
			blueprint.Variation{Mutator: "image", Variation: android.CoreVariation})