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
This commit is contained in:
parent
bbc941b0d0
commit
3572cf74f9
4
cc/cc.go
4
cc/cc.go
|
@ -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()))
|
||||
}
|
||||
|
|
|
@ -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,47 +1652,19 @@ 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()
|
||||
if library.CcLibraryInterface() && library.BuildSharedVariant() {
|
||||
versions := library.StubsVersions(mctx)
|
||||
if len(versions) > 0 {
|
||||
normalizeVersions(mctx, versions)
|
||||
if mctx.Failed() {
|
||||
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))
|
||||
// Set the versions on the pre-mutated module so they can be read by any llndk modules that
|
||||
// depend on the implementation library and haven't been mutated yet.
|
||||
library.SetAllStubsVersions(versions)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if library.CcLibrary() && library.BuildSharedVariant() && len(library.StubsVersions()) > 0 && !library.UseSdk() {
|
||||
versions := library.StubsVersions()
|
||||
normalizeVersions(mctx, versions)
|
||||
if mctx.Failed() {
|
||||
return
|
||||
}
|
||||
// Set the versions on the pre-mutated module so they can be read by any llndk modules that
|
||||
// depend on the implementation library and haven't been mutated yet.
|
||||
library.SetAllStubsVersions(versions)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ type LinkableInterface interface {
|
|||
|
||||
NonCcVariants() bool
|
||||
|
||||
StubsVersions() []string
|
||||
StubsVersions(android.BaseMutatorContext) []string
|
||||
BuildStubs() bool
|
||||
SetBuildStubs()
|
||||
SetStubsVersion(string)
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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())
|
||||
|
||||
|
|
|
@ -500,7 +500,7 @@ func (mod *Module) Module() android.Module {
|
|||
return mod
|
||||
}
|
||||
|
||||
func (mod *Module) StubsVersions() []string {
|
||||
func (mod *Module) StubsVersions(ctx android.BaseMutatorContext) []string {
|
||||
// For now, Rust has no stubs versions.
|
||||
if mod.compiler != nil {
|
||||
if _, ok := mod.compiler.(libraryInterface); ok {
|
||||
|
|
Loading…
Reference in New Issue