Fix prebuilt library stubs

There were multiple stacked issues with prebuilt library stubs that
cancelled eachother out.  Prebuilts were never considered to be
DirectlyInAnyApex by the AndroidMk logic to handle stubs libraries
because it looked it up in the global list of modules in apexes
using the name with the "prebuilt_" prefix.  Fixing that to use
ctx.BaseModuleName() exposed a second issue, that stubs variants
for prebuilt libraries were never created, so there was no latest
version to expose to Make.

Making the *prebuiltLibraryLinker type work with all of the
methods that handle stubs should really be done with an interface
and methods implemented on *libraryDecorator, but that would
also cause other types like that embed libraryDecorator to
participate in stubs that may trigger more issues.  I'd like
to replace those methods anyways, so just manually handle
*prebuiltLibraryLinker for now.

Test: m checkbuild
Change-Id: I1267ee01659ad9ab11d75318c6c6bdbf8f72a061
This commit is contained in:
Colin Cross 2020-09-23 20:37:24 -07:00
parent 4e1f2bd0d8
commit d48fe734cd
2 changed files with 40 additions and 2 deletions

View file

@ -33,7 +33,7 @@ var (
) )
type AndroidMkContext interface { type AndroidMkContext interface {
Name() string BaseModuleName() string
Target() android.Target Target() android.Target
subAndroidMk(*android.AndroidMkEntries, interface{}) subAndroidMk(*android.AndroidMkEntries, interface{})
Arch() android.Arch Arch() android.Arch
@ -278,7 +278,7 @@ func (library *libraryDecorator) AndroidMkEntries(ctx AndroidMkContext, entries
}) })
} }
if len(library.Properties.Stubs.Versions) > 0 && if len(library.Properties.Stubs.Versions) > 0 &&
android.DirectlyInAnyApex(ctx, ctx.Name()) && !ctx.InRamdisk() && !ctx.InRecovery() && !ctx.UseVndk() && android.DirectlyInAnyApex(ctx, ctx.BaseModuleName()) && !ctx.InRamdisk() && !ctx.InRecovery() && !ctx.UseVndk() &&
!ctx.static() { !ctx.static() {
if library.buildStubs() && library.isLatestStubVersion() { if library.buildStubs() && library.isLatestStubVersion() {
// reference the latest version via its name without suffix when it is provided by apex // reference the latest version via its name without suffix when it is provided by apex

View file

@ -740,6 +740,9 @@ func (c *Module) StubsVersions() []string {
if library, ok := c.linker.(*libraryDecorator); ok { if library, ok := c.linker.(*libraryDecorator); ok {
return library.Properties.Stubs.Versions return library.Properties.Stubs.Versions
} }
if library, ok := c.linker.(*prebuiltLibraryLinker); ok {
return library.Properties.Stubs.Versions
}
} }
panic(fmt.Errorf("StubsVersions called on non-library module: %q", c.BaseModuleName())) panic(fmt.Errorf("StubsVersions called on non-library module: %q", c.BaseModuleName()))
} }
@ -749,6 +752,9 @@ func (c *Module) CcLibrary() bool {
if _, ok := c.linker.(*libraryDecorator); ok { if _, ok := c.linker.(*libraryDecorator); ok {
return true return true
} }
if _, ok := c.linker.(*prebuiltLibraryLinker); ok {
return true
}
} }
return false return false
} }
@ -774,6 +780,14 @@ func (c *Module) SetBuildStubs() {
c.Properties.PreventInstall = true c.Properties.PreventInstall = true
return return
} }
if library, ok := c.linker.(*prebuiltLibraryLinker); ok {
library.MutatedProperties.BuildStubs = true
c.Properties.HideFromMake = true
c.sanitize = nil
c.stl = nil
c.Properties.PreventInstall = true
return
}
if _, ok := c.linker.(*llndkStubDecorator); ok { if _, ok := c.linker.(*llndkStubDecorator); ok {
c.Properties.HideFromMake = true c.Properties.HideFromMake = true
return return
@ -787,6 +801,9 @@ func (c *Module) BuildStubs() bool {
if library, ok := c.linker.(*libraryDecorator); ok { if library, ok := c.linker.(*libraryDecorator); ok {
return library.buildStubs() return library.buildStubs()
} }
if library, ok := c.linker.(*prebuiltLibraryLinker); ok {
return library.buildStubs()
}
} }
panic(fmt.Errorf("BuildStubs called on non-library module: %q", c.BaseModuleName())) panic(fmt.Errorf("BuildStubs called on non-library module: %q", c.BaseModuleName()))
} }
@ -796,6 +813,10 @@ func (c *Module) SetAllStubsVersions(versions []string) {
library.MutatedProperties.AllStubsVersions = versions library.MutatedProperties.AllStubsVersions = versions
return return
} }
if library, ok := c.linker.(*prebuiltLibraryLinker); ok {
library.MutatedProperties.AllStubsVersions = versions
return
}
if llndk, ok := c.linker.(*llndkStubDecorator); ok { if llndk, ok := c.linker.(*llndkStubDecorator); ok {
llndk.libraryDecorator.MutatedProperties.AllStubsVersions = versions llndk.libraryDecorator.MutatedProperties.AllStubsVersions = versions
return return
@ -806,6 +827,9 @@ func (c *Module) AllStubsVersions() []string {
if library, ok := c.linker.(*libraryDecorator); ok { if library, ok := c.linker.(*libraryDecorator); ok {
return library.MutatedProperties.AllStubsVersions return library.MutatedProperties.AllStubsVersions
} }
if library, ok := c.linker.(*prebuiltLibraryLinker); ok {
return library.MutatedProperties.AllStubsVersions
}
if llndk, ok := c.linker.(*llndkStubDecorator); ok { if llndk, ok := c.linker.(*llndkStubDecorator); ok {
return llndk.libraryDecorator.MutatedProperties.AllStubsVersions return llndk.libraryDecorator.MutatedProperties.AllStubsVersions
} }
@ -818,6 +842,10 @@ func (c *Module) SetStubsVersion(version string) {
library.MutatedProperties.StubsVersion = version library.MutatedProperties.StubsVersion = version
return return
} }
if library, ok := c.linker.(*prebuiltLibraryLinker); ok {
library.MutatedProperties.StubsVersion = version
return
}
if llndk, ok := c.linker.(*llndkStubDecorator); ok { if llndk, ok := c.linker.(*llndkStubDecorator); ok {
llndk.libraryDecorator.MutatedProperties.StubsVersion = version llndk.libraryDecorator.MutatedProperties.StubsVersion = version
return return
@ -831,6 +859,9 @@ func (c *Module) StubsVersion() string {
if library, ok := c.linker.(*libraryDecorator); ok { if library, ok := c.linker.(*libraryDecorator); ok {
return library.MutatedProperties.StubsVersion return library.MutatedProperties.StubsVersion
} }
if library, ok := c.linker.(*prebuiltLibraryLinker); ok {
return library.MutatedProperties.StubsVersion
}
if llndk, ok := c.linker.(*llndkStubDecorator); ok { if llndk, ok := c.linker.(*llndkStubDecorator); ok {
return llndk.libraryDecorator.MutatedProperties.StubsVersion return llndk.libraryDecorator.MutatedProperties.StubsVersion
} }
@ -1073,6 +1104,8 @@ func (c *Module) getVndkExtendsModuleName() string {
func (c *Module) IsStubs() bool { func (c *Module) IsStubs() bool {
if library, ok := c.linker.(*libraryDecorator); ok { if library, ok := c.linker.(*libraryDecorator); ok {
return library.buildStubs() return library.buildStubs()
} else if library, ok := c.linker.(*prebuiltLibraryLinker); ok {
return library.buildStubs()
} else if _, ok := c.linker.(*llndkStubDecorator); ok { } else if _, ok := c.linker.(*llndkStubDecorator); ok {
return true return true
} }
@ -1930,6 +1963,11 @@ func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
buildStubs = true buildStubs = true
} }
} }
if library, ok := c.linker.(*prebuiltLibraryLinker); ok {
if library.buildStubs() {
buildStubs = true
}
}
} }
rewriteSnapshotLibs := func(lib string, snapshotMap *snapshotMap) string { rewriteSnapshotLibs := func(lib string, snapshotMap *snapshotMap) string {