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

Commit 3572cf74 authored by Colin Cross's avatar Colin Cross
Browse files

Move LLNDK and NDK versionSelectorMutator special cases into versionedInterface

Implement stubsVersions on *llndkStubDecorator and *stubDecorator to
handle the special cases in versionSelectorMutator.

Test: m checkbuild
Change-Id: Idc985c52f91450df42c0275b2b2acef3f2ed8868
parent bbc941b0
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -717,9 +717,9 @@ func (c *Module) AlwaysSdk() bool {
	return c.Properties.AlwaysSdk || Bool(c.Properties.Sdk_variant_only)
}

func (c *Module) StubsVersions() []string {
func (c *Module) StubsVersions(ctx android.BaseMutatorContext) []string {
	if versioned, ok := c.linker.(versionedInterface); ok {
		return versioned.stubsVersions()
		return versioned.stubsVersions(ctx)
	}
	panic(fmt.Errorf("StubsVersions called on non-library module: %q", c.BaseModuleName()))
}
+12 −38
Original line number Diff line number Diff line
@@ -660,6 +660,8 @@ func (library *libraryDecorator) compile(ctx ModuleContext, flags Flags, deps Pa
}

type libraryInterface interface {
	versionedInterface

	static() bool
	shared() bool
	objs() Objects
@@ -687,7 +689,7 @@ type versionedInterface interface {
	setStubsVersion(string)
	stubsVersion() string

	stubsVersions() []string
	stubsVersions(ctx android.BaseMutatorContext) []string
	setAllStubsVersions([]string)
	allStubsVersions() []string
}
@@ -1371,7 +1373,7 @@ func (library *libraryDecorator) hasStubsVariants() bool {
	return len(library.Properties.Stubs.Versions) > 0
}

func (library *libraryDecorator) stubsVersions() []string {
func (library *libraryDecorator) stubsVersions(ctx android.BaseMutatorContext) []string {
	return library.Properties.Stubs.Versions
}

@@ -1650,38 +1652,9 @@ func CanBeVersionVariant(module interface {
// 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 && CanBeVersionVariant(library) {
		if c, ok := library.(*Module); ok {
			if _, ok := c.linker.(*llndkStubDecorator); ok {
				// Get the versions from the implementation module.
				impls := mctx.GetDirectDepsWithTag(llndkImplDep)
				if len(impls) > 1 {
					panic(fmt.Errorf("Expected single implmenetation library, got %d", len(impls)))
				} else if len(impls) == 1 {
					c.SetAllStubsVersions(impls[0].(*Module).AllStubsVersions())
				}
				return
			}

			if compiler, ok := c.linker.(*stubDecorator); ok {
				if mctx.Os() != android.Android {
					// These modules are always android.DeviceEnabled only, but
					// those include Fuchsia devices, which we don't support.
					mctx.Module().Disable()
					return
				}
				firstVersion, err := nativeApiLevelFromUser(mctx,
					String(compiler.properties.First_version))
				if err != nil {
					mctx.PropertyErrorf("first_version", err.Error())
					return
				}
				c.SetAllStubsVersions(ndkLibraryVersions(mctx, firstVersion))
				return
			}
		}

		if library.CcLibrary() && library.BuildSharedVariant() && len(library.StubsVersions()) > 0 && !library.UseSdk() {
			versions := library.StubsVersions()
		if library.CcLibraryInterface() && library.BuildSharedVariant() {
			versions := library.StubsVersions(mctx)
			if len(versions) > 0 {
				normalizeVersions(mctx, versions)
				if mctx.Failed() {
					return
@@ -1693,6 +1666,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.
+1 −1
Original line number Diff line number Diff line
@@ -16,7 +16,7 @@ type LinkableInterface interface {

	NonCcVariants() bool

	StubsVersions() []string
	StubsVersions(android.BaseMutatorContext) []string
	BuildStubs() bool
	SetBuildStubs()
	SetStubsVersion(string)
+12 −0
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@
package cc

import (
	"fmt"
	"path/filepath"
	"strings"

@@ -170,6 +171,17 @@ func (stub *llndkStubDecorator) buildStubs() bool {
	return true
}

func (stub *llndkStubDecorator) stubsVersions(ctx android.BaseMutatorContext) []string {
	// Get the versions from the implementation module.
	impls := ctx.GetDirectDepsWithTag(llndkImplDep)
	if len(impls) > 1 {
		panic(fmt.Errorf("Expected single implmenetation library, got %d", len(impls)))
	} else if len(impls) == 1 {
		return impls[0].(*Module).AllStubsVersions()
	}
	return nil
}

func NewLLndkStubLibrary() *Module {
	module, library := NewLibrary(android.DeviceSupported)
	library.BuildOnlyShared()
+14 −1
Original line number Diff line number Diff line
@@ -104,7 +104,7 @@ func shouldUseVersionScript(ctx BaseModuleContext, stub *stubDecorator) bool {
	return stub.apiLevel.GreaterThanOrEqualTo(stub.unversionedUntil)
}

func ndkLibraryVersions(ctx android.BottomUpMutatorContext, from android.ApiLevel) []string {
func ndkLibraryVersions(ctx android.BaseMutatorContext, from android.ApiLevel) []string {
	var versions []android.ApiLevel
	versionStrs := []string{}
	for _, version := range ctx.Config().AllSupportedApiLevels() {
@@ -118,6 +118,19 @@ func ndkLibraryVersions(ctx android.BottomUpMutatorContext, from android.ApiLeve
	return versionStrs
}

func (this *stubDecorator) stubsVersions(ctx android.BaseMutatorContext) []string {
	if !ctx.Module().Enabled() {
		return nil
	}
	firstVersion, err := nativeApiLevelFromUser(ctx,
		String(this.properties.First_version))
	if err != nil {
		ctx.PropertyErrorf("first_version", err.Error())
		return nil
	}
	return ndkLibraryVersions(ctx, firstVersion)
}

func (this *stubDecorator) initializeProperties(ctx BaseModuleContext) bool {
	this.apiLevel = nativeApiLevelOrPanic(ctx, this.stubsVersion())

Loading