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

Commit 159aebf6 authored by Jooyung Han's avatar Jooyung Han
Browse files

Add version suffix for stub modules' Android.mk

Becase there can be more than one stub libraries, LOCAL_MODULE should be
suffixed with SubName just like NDK stub.

Note that suffix should not be appended to the latest version if the
library is provided by APEX, Otherwise, those libs always need to be
referenced with suffix in .mk files.

Bug: 145796956
Test: m
Merged-In: If503fa651a63b0b215742553b250ecf5e0a30971
Change-Id: If503fa651a63b0b215742553b250ecf5e0a30971
(cherry picked from commit ad4c1876)

Exempt-From-Owner-Approval: cherry-pick from aosp
parent 0c4e0164
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -244,6 +244,9 @@ func (library *libraryDecorator) AndroidMkEntries(ctx AndroidMkContext, entries
	if library.shared() && !library.buildStubs() {
		ctx.subAndroidMk(entries, library.baseInstaller)
	} else {
		if library.buildStubs() {
			entries.SubName = "." + library.stubsVersion()
		}
		entries.ExtraEntries = append(entries.ExtraEntries, func(entries *android.AndroidMkEntries) {
			entries.SetBool("LOCAL_UNINSTALLABLE_MODULE", true)
			if library.buildStubs() {
@@ -254,6 +257,10 @@ func (library *libraryDecorator) AndroidMkEntries(ctx AndroidMkContext, entries
	if len(library.Properties.Stubs.Versions) > 0 &&
		android.DirectlyInAnyApex(ctx, ctx.Name()) && !ctx.InRamdisk() && !ctx.InRecovery() && !ctx.UseVndk() &&
		!ctx.static() {
		if library.buildStubs() && library.isLatestStubVersion() {
			// reference the latest version via its name without suffix when it is provided by apex
			entries.SubName = ""
		}
		if !library.buildStubs() {
			entries.SubName = ".bootstrap"
		}
+24 −14
Original line number Diff line number Diff line
@@ -1284,6 +1284,11 @@ func (library *libraryDecorator) stubsVersion() string {
	return library.MutatedProperties.StubsVersion
}

func (library *libraryDecorator) isLatestStubVersion() bool {
	versions := library.Properties.Stubs.Versions
	return versions[len(versions)-1] == library.stubsVersion()
}

func (library *libraryDecorator) availableFor(what string) bool {
	var list []string
	if library.static() {
@@ -1449,30 +1454,35 @@ func LatestStubsVersionFor(config android.Config, name string) string {
	return ""
}

func checkVersions(ctx android.BaseModuleContext, versions []string) {
	numVersions := make([]int, len(versions))
	for i, v := range versions {
		numVer, err := strconv.Atoi(v)
		if err != nil {
			ctx.PropertyErrorf("versions", "%q is not a number", v)
		}
		numVersions[i] = numVer
	}
	if !sort.IsSorted(sort.IntSlice(numVersions)) {
		ctx.PropertyErrorf("versions", "not sorted: %v", versions)
	}
}

// Version mutator 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 && !library.InRecovery() {
		if library.CcLibrary() && library.BuildSharedVariant() && len(library.StubsVersions()) > 0 {
			versions := []string{}
			for _, v := range library.StubsVersions() {
				if _, err := strconv.Atoi(v); err != nil {
					mctx.PropertyErrorf("versions", "%q is not a number", v)
				}
				versions = append(versions, v)
			versions := library.StubsVersions()
			checkVersions(mctx, versions)
			if mctx.Failed() {
				return
			}
			sort.Slice(versions, func(i, j int) bool {
				left, _ := strconv.Atoi(versions[i])
				right, _ := strconv.Atoi(versions[j])
				return left < right
			})

			// save the list of versions for later use
			copiedVersions := make([]string, len(versions))
			copy(copiedVersions, versions)
			stubsVersionsLock.Lock()
			defer stubsVersionsLock.Unlock()
			stubsVersionsFor(mctx.Config())[mctx.ModuleName()] = copiedVersions
			stubsVersionsFor(mctx.Config())[mctx.ModuleName()] = versions

			// "" is for the non-stubs variant
			versions = append([]string{""}, versions...)