Move stubs related methods out of LinkableInterface

The stubs methods are very specific to cc for now, move them out
of LinkableInterface so they are not shared with rust.  Instead,
create a cc.Module.library field that contains the libraryInterface
to simplify calling libraryInterface methods on cc modules.

Test: all Soong tests
Test: no change to Soong outputs
Change-Id: I0289d866ce1f7a765631fe3101a62b1b4988ba1c
This commit is contained in:
Colin Cross 2020-10-23 17:22:06 -07:00
parent a717db7304
commit 31076b3185
12 changed files with 95 additions and 186 deletions

122
cc/cc.go
View file

@ -377,8 +377,6 @@ type ModuleContextIntf interface {
isForPlatform() bool
apexVariationName() string
apexSdkVersion() android.ApiLevel
hasStubsVariants() bool
isStubs() bool
bootstrap() bool
mustUseVendorVariant() bool
nativeCoverage() bool
@ -623,6 +621,8 @@ type Module struct {
lto *lto
pgo *pgo
library libraryInterface
outputFile android.OptionalPath
cachedToolchain config.Toolchain
@ -731,13 +731,6 @@ func (c *Module) AlwaysSdk() bool {
return c.Properties.AlwaysSdk || Bool(c.Properties.Sdk_variant_only)
}
func (c *Module) StubsVersions(ctx android.BaseMutatorContext) []string {
if versioned, ok := c.linker.(versionedInterface); ok {
return versioned.stubsVersions(ctx)
}
panic(fmt.Errorf("StubsVersions called on non-library module: %q", c.BaseModuleName()))
}
func (c *Module) CcLibrary() bool {
if c.linker != nil {
if _, ok := c.linker.(*libraryDecorator); ok {
@ -761,53 +754,6 @@ func (c *Module) NonCcVariants() bool {
return false
}
func (c *Module) SetBuildStubs() {
if versioned, ok := c.linker.(versionedInterface); ok {
versioned.setBuildStubs()
c.Properties.HideFromMake = true
c.sanitize = nil
c.stl = nil
c.Properties.PreventInstall = true
return
}
panic(fmt.Errorf("SetBuildStubs called on non-library module: %q", c.BaseModuleName()))
}
func (c *Module) BuildStubs() bool {
if versioned, ok := c.linker.(versionedInterface); ok {
return versioned.buildStubs()
}
panic(fmt.Errorf("BuildStubs called on non-library module: %q", c.BaseModuleName()))
}
func (c *Module) SetAllStubsVersions(versions []string) {
if versioned, ok := c.linker.(versionedInterface); ok {
versioned.setAllStubsVersions(versions)
}
}
func (c *Module) AllStubsVersions() []string {
if versioned, ok := c.linker.(versionedInterface); ok {
return versioned.allStubsVersions()
}
return nil
}
func (c *Module) SetStubsVersion(version string) {
if versioned, ok := c.linker.(versionedInterface); ok {
versioned.setStubsVersion(version)
return
}
panic(fmt.Errorf("SetStubsVersion called on non-library module: %q", c.BaseModuleName()))
}
func (c *Module) StubsVersion() string {
if versioned, ok := c.linker.(versionedInterface); ok {
return versioned.stubsVersion()
}
panic(fmt.Errorf("StubsVersion called on non-library module: %q", c.BaseModuleName()))
}
func (c *Module) SetStatic() {
if c.linker != nil {
if library, ok := c.linker.(libraryInterface); ok {
@ -1041,15 +987,15 @@ func (c *Module) getVndkExtendsModuleName() string {
}
func (c *Module) IsStubs() bool {
if versioned, ok := c.linker.(versionedInterface); ok {
return versioned.buildStubs()
if lib := c.library; lib != nil {
return lib.buildStubs()
}
return false
}
func (c *Module) HasStubsVariants() bool {
if versioned, ok := c.linker.(versionedInterface); ok {
return versioned.hasStubsVariants()
if lib := c.library; lib != nil {
return lib.hasStubsVariants()
}
return false
}
@ -1240,10 +1186,15 @@ func (ctx *moduleContextImpl) shouldCreateSourceAbiDump() bool {
// Host modules do not need ABI dumps.
return false
}
if ctx.isStubs() || ctx.isNDKStubLibrary() {
if ctx.isNDKStubLibrary() {
// Stubs do not need ABI dumps.
return false
}
if lib := ctx.mod.library; lib != nil && lib.buildStubs() {
// Stubs do not need ABI dumps.
return false
}
return true
}
@ -1278,14 +1229,6 @@ func (ctx *moduleContextImpl) apexSdkVersion() android.ApiLevel {
return ctx.mod.apexSdkVersion
}
func (ctx *moduleContextImpl) hasStubsVariants() bool {
return ctx.mod.HasStubsVariants()
}
func (ctx *moduleContextImpl) isStubs() bool {
return ctx.mod.IsStubs()
}
func (ctx *moduleContextImpl) bootstrap() bool {
return ctx.mod.bootstrap()
}
@ -2078,18 +2021,20 @@ func checkLinkType(ctx android.BaseModuleContext, from LinkableInterface, to Lin
// Recovery code is not NDK
return
}
if to.ToolchainLibrary() {
// These are always allowed
return
}
if to.NdkPrebuiltStl() {
// These are allowed, but they don't set sdk_version
return
}
if to.StubDecorator() {
// These aren't real libraries, but are the stub shared libraries that are included in
// the NDK.
return
if c, ok := to.(*Module); ok {
if c.ToolchainLibrary() {
// These are always allowed
return
}
if c.NdkPrebuiltStl() {
// These are allowed, but they don't set sdk_version
return
}
if c.StubDecorator() {
// These aren't real libraries, but are the stub shared libraries that are included in
// the NDK.
return
}
}
if strings.HasPrefix(ctx.ModuleName(), "libclang_rt.") && to.Module().Name() == "libc++" {
@ -2341,7 +2286,7 @@ func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
// The reuseObjTag dependency still exists because the LinkageMutator runs before the
// version mutator, so the stubs variant is created from the shared variant that
// already has the reuseObjTag dependency on the static variant.
if !c.BuildStubs() {
if !c.library.buildStubs() {
staticAnalogue := ctx.OtherModuleProvider(dep, StaticLibraryInfoProvider).(StaticLibraryInfo)
objs := staticAnalogue.ReuseObjects
depPaths.Objs = depPaths.Objs.Append(objs)
@ -2383,7 +2328,8 @@ func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
if !libDepTag.explicitlyVersioned && len(sharedLibraryStubsInfo.SharedLibraryStubsInfos) > 0 {
useStubs := false
if m, ok := ccDep.(*Module); ok && m.IsStubs() && c.UseVndk() { // LLNDK
if lib := moduleLibraryInterface(dep); lib.buildStubs() && c.UseVndk() { // LLNDK
if !apexInfo.IsForPlatform() {
// For platform libraries, use current version of LLNDK
// If this is for use_vendor apex we will apply the same rules
@ -2552,8 +2498,8 @@ func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
c.Properties.AndroidMkHeaderLibs = append(
c.Properties.AndroidMkHeaderLibs, makeLibName)
case libDepTag.shared():
if ccDep.CcLibrary() {
if ccDep.BuildStubs() && dep.(android.ApexModule).InAnyApex() {
if lib := moduleLibraryInterface(dep); lib != nil {
if lib.buildStubs() && dep.(android.ApexModule).InAnyApex() {
// Add the dependency to the APEX(es) providing the library so that
// m <module> can trigger building the APEXes as well.
depApexInfo := ctx.OtherModuleProvider(dep, android.ApexInfoProvider).(android.ApexInfo)
@ -2855,12 +2801,10 @@ func (c *Module) getMakeLinkType(actx android.ModuleContext) string {
// Overrides ApexModule.IsInstallabeToApex()
// Only shared/runtime libraries and "test_per_src" tests are installable to APEX.
func (c *Module) IsInstallableToApex() bool {
if shared, ok := c.linker.(interface {
shared() bool
}); ok {
if lib := c.library; lib != nil {
// Stub libs and prebuilt libs in a versioned SDK are not
// installable to APEX even though they are shared libs.
return shared.shared() && !c.IsStubs() && c.ContainingSdk().Unversioned()
return lib.shared() && !lib.buildStubs() && c.ContainingSdk().Unversioned()
} else if _, ok := c.linker.(testPerSrc); ok {
return true
}

View file

@ -174,12 +174,25 @@ func isValidSharedDependency(dependency android.Module) bool {
// TODO(b/144090547): We should be parsing these modules using
// ModuleDependencyTag instead of the current brute-force checking.
if linkable, ok := dependency.(LinkableInterface); !ok || // Discard non-linkables.
!linkable.CcLibraryInterface() || !linkable.Shared() || // Discard static libs.
linkable.UseVndk() || // Discard vendor linked libraries.
linkable, ok := dependency.(LinkableInterface)
if !ok || !linkable.CcLibraryInterface() {
// Discard non-linkables.
return false
}
if !linkable.Shared() {
// Discard static libs.
return false
}
if linkable.UseVndk() {
// Discard vendor linked libraries.
return false
}
if lib := moduleLibraryInterface(dependency); lib != nil && lib.buildStubs() && linkable.CcLibrary() {
// Discard stubs libs (only CCLibrary variants). Prebuilt libraries should not
// be excluded on the basis of they're not CCLibrary()'s.
(linkable.CcLibrary() && linkable.BuildStubs()) {
return false
}

View file

@ -587,7 +587,7 @@ func (library *libraryDecorator) classifySourceAbiDump(ctx ModuleContext) string
}
}
}
if Bool(enabled) || ctx.hasStubsVariants() {
if Bool(enabled) || library.hasStubsVariants() {
return "PLATFORM"
}
return ""
@ -598,7 +598,7 @@ func (library *libraryDecorator) shouldCreateSourceAbiDump(ctx ModuleContext) bo
return false
}
if !ctx.isForPlatform() {
if !ctx.hasStubsVariants() {
if !library.hasStubsVariants() {
// Skip ABI checks if this library is for APEX but isn't exported.
return false
}
@ -1060,7 +1060,7 @@ func (library *libraryDecorator) linkShared(ctx ModuleContext,
stubInfo := ctx.OtherModuleProvider(stub, SharedLibraryInfoProvider).(SharedLibraryInfo)
flagInfo := ctx.OtherModuleProvider(stub, FlagExporterInfoProvider).(FlagExporterInfo)
stubsInfo = append(stubsInfo, SharedLibraryStubsInfo{
Version: stub.(*Module).StubsVersion(),
Version: moduleLibraryInterface(stub).stubsVersion(),
SharedLibraryInfo: stubInfo,
FlagExporterInfo: flagInfo,
})
@ -1384,7 +1384,7 @@ func (library *libraryDecorator) symbolFileForAbiCheck(ctx ModuleContext) *strin
if library.Properties.Header_abi_checker.Symbol_file != nil {
return library.Properties.Header_abi_checker.Symbol_file
}
if ctx.hasStubsVariants() && library.Properties.Stubs.Symbol_file != nil {
if library.hasStubsVariants() && library.Properties.Stubs.Symbol_file != nil {
return library.Properties.Stubs.Symbol_file
}
return nil
@ -1483,6 +1483,7 @@ func NewLibrary(hod android.HostOrDeviceSupported) (*Module, *libraryDecorator)
module.compiler = library
module.linker = library
module.installer = library
module.library = library
return module, library
}
@ -1620,8 +1621,14 @@ func createVersionVariations(mctx android.BottomUpMutatorContext, versions []str
modules := mctx.CreateLocalVariations(variants...)
for i, m := range modules {
if variants[i] != "" {
m.(LinkableInterface).SetBuildStubs()
m.(LinkableInterface).SetStubsVersion(variants[i])
c := m.(*Module)
c.Properties.HideFromMake = true
c.sanitize = nil
c.stl = nil
c.Properties.PreventInstall = true
lib := moduleLibraryInterface(m)
lib.setBuildStubs()
lib.setStubsVersion(variants[i])
// The implementation depends on the stubs
mctx.AddInterVariantDependency(stubImplDepTag, modules[len(modules)-1], modules[i])
}
@ -1670,12 +1677,19 @@ func CanBeVersionVariant(module interface {
module.CcLibraryInterface() && module.Shared()
}
func moduleLibraryInterface(module android.Module) libraryInterface {
if m, ok := module.(*Module); ok {
return m.library
}
return nil
}
// 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 && CanBeVersionVariant(library) {
if library.CcLibraryInterface() && library.BuildSharedVariant() {
versions := library.StubsVersions(mctx)
if library := moduleLibraryInterface(mctx.Module()); library != nil && CanBeVersionVariant(mctx.Module().(*Module)) {
if library.buildShared() {
versions := library.stubsVersions(mctx)
if len(versions) > 0 {
normalizeVersions(mctx, versions)
if mctx.Failed() {
@ -1683,7 +1697,7 @@ func versionSelectorMutator(mctx android.BottomUpMutatorContext) {
}
// 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)
library.setAllStubsVersions(versions)
return
}
}
@ -1693,8 +1707,8 @@ 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 && CanBeVersionVariant(library) {
createVersionVariations(mctx, library.AllStubsVersions())
if library := moduleLibraryInterface(mctx.Module()); library != nil && CanBeVersionVariant(mctx.Module().(*Module)) {
createVersionVariations(mctx, library.allStubsVersions())
return
}

View file

@ -428,22 +428,22 @@ func (p *nativeLibInfoProperties) PopulateFromVariant(ctx android.SdkMemberConte
specifiedDeps := specifiedDeps{}
specifiedDeps = ccModule.linker.linkerSpecifiedDeps(specifiedDeps)
if !ccModule.HasStubsVariants() {
// Propagate dynamic dependencies for implementation libs, but not stubs.
p.SharedLibs = specifiedDeps.sharedLibs
if lib := ccModule.library; lib != nil {
if !lib.hasStubsVariants() {
// Propagate dynamic dependencies for implementation libs, but not stubs.
p.SharedLibs = specifiedDeps.sharedLibs
} else {
// TODO(b/169373910): 1. Only output the specific version (from
// ccModule.StubsVersion()) if the module is versioned. 2. Ensure that all
// the versioned stub libs are retained in the prebuilt tree; currently only
// the stub corresponding to ccModule.StubsVersion() is.
p.StubsVersions = lib.allStubsVersions()
}
}
p.SystemSharedLibs = specifiedDeps.systemSharedLibs
}
p.exportedGeneratedHeaders = exportedInfo.GeneratedHeaders
if ccModule.HasStubsVariants() {
// TODO(b/169373910): 1. Only output the specific version (from
// ccModule.StubsVersion()) if the module is versioned. 2. Ensure that all
// the versioned stub libs are retained in the prebuilt tree; currently only
// the stub corresponding to ccModule.StubsVersion() is.
p.StubsVersions = ccModule.AllStubsVersions()
}
if !p.memberType.noOutputFiles && addOutputFile {
p.outputFile = getRequiredMemberOutputFile(ctx, ccModule)
}

View file

@ -16,16 +16,7 @@ type LinkableInterface interface {
NonCcVariants() bool
StubsVersions(android.BaseMutatorContext) []string
BuildStubs() bool
SetBuildStubs()
SetStubsVersion(string)
StubsVersion() string
SetAllStubsVersions([]string)
AllStubsVersions() []string
HasStubsVariants() bool
SelectedStl() string
ApiLevel() string
BuildStaticVariant() bool
BuildSharedVariant() bool
@ -56,10 +47,6 @@ type LinkableInterface interface {
AlwaysSdk() bool
IsSdkVariant() bool
ToolchainLibrary() bool
NdkPrebuiltStl() bool
StubDecorator() bool
SplitPerApiLevel() bool
}

View file

@ -185,7 +185,7 @@ func (stub *llndkStubDecorator) stubsVersions(ctx android.BaseMutatorContext) []
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 moduleLibraryInterface(impls[0]).allStubsVersions()
}
return nil
}
@ -204,6 +204,7 @@ func NewLLndkStubLibrary() *Module {
module.compiler = stub
module.linker = stub
module.installer = nil
module.library = stub
module.AddProperties(
&module.Properties,
@ -251,6 +252,7 @@ func llndkHeadersFactory() android.Module {
module.compiler = nil
module.linker = decorator
module.installer = nil
module.library = decorator
module.AddProperties(
&module.Properties,

View file

@ -333,6 +333,7 @@ func newStubLibrary() *Module {
module.compiler = stub
module.linker = stub
module.installer = stub
module.library = stub
module.Properties.AlwaysSdk = true
module.Properties.Sdk_version = StringPtr("current")

View file

@ -131,7 +131,7 @@ func (n *ndkSingleton) GenerateBuildActions(ctx android.SingletonContext) {
}
if m, ok := module.(*Module); ok {
if installer, ok := m.installer.(*stubDecorator); ok && m.BuildStubs() {
if installer, ok := m.installer.(*stubDecorator); ok && m.library.buildStubs() {
if ctx.Config().ExcludeDraftNdkApis() &&
installer.properties.Draft {
return

View file

@ -228,6 +228,7 @@ func NewPrebuiltLibrary(hod android.HostOrDeviceSupported) (*Module, *libraryDec
libraryDecorator: library,
}
module.linker = prebuilt
module.library = prebuilt
module.AddProperties(&prebuilt.properties)

View file

@ -66,6 +66,7 @@ func ToolchainLibraryFactory() android.Module {
module.stl = nil
module.sanitize = nil
module.installer = nil
module.library = toolchainLibrary
module.Properties.Sdk_version = StringPtr("current")
return module.Init()
}

View file

@ -313,7 +313,7 @@ func processVndkLibrary(mctx android.BottomUpMutatorContext, m *Module) {
panic(err)
}
if m.HasStubsVariants() && name != "libz" {
if lib := m.library; lib != nil && lib.hasStubsVariants() && name != "libz" {
// b/155456180 libz is the ONLY exception here. We don't want to make
// libz an LLNDK library because we in general can't guarantee that
// libz will behave consistently especially about the compression.

View file

@ -133,14 +133,6 @@ func (mod *Module) ExtraImageVariations(android.BaseModuleContext) []string {
func (c *Module) SetImageVariation(ctx android.BaseModuleContext, variant string, module android.Module) {
}
func (mod *Module) BuildStubs() bool {
return false
}
func (mod *Module) HasStubsVariants() bool {
return false
}
func (mod *Module) SelectedStl() string {
return ""
}
@ -154,10 +146,6 @@ func (mod *Module) NonCcVariants() bool {
panic(fmt.Errorf("NonCcVariants called on non-library module: %q", mod.BaseModuleName()))
}
func (mod *Module) ApiLevel() string {
panic(fmt.Errorf("Called ApiLevel on Rust module %q; stubs libraries are not yet supported.", mod.BaseModuleName()))
}
func (mod *Module) Static() bool {
if mod.compiler != nil {
if library, ok := mod.compiler.(libraryInterface); ok {
@ -233,18 +221,6 @@ func (mod *Module) SplitPerApiLevel() bool {
return false
}
func (mod *Module) ToolchainLibrary() bool {
return false
}
func (mod *Module) NdkPrebuiltStl() bool {
return false
}
func (mod *Module) StubDecorator() bool {
return false
}
type Deps struct {
Dylibs []string
Rlibs []string
@ -466,26 +442,6 @@ func (mod *Module) SetShared() {
panic(fmt.Errorf("SetShared called on non-library module: %q", mod.BaseModuleName()))
}
func (mod *Module) SetBuildStubs() {
panic("SetBuildStubs not yet implemented for rust modules")
}
func (mod *Module) SetStubsVersion(string) {
panic("SetStubsVersion not yet implemented for rust modules")
}
func (mod *Module) StubsVersion() string {
panic("StubsVersion not yet implemented for rust modules")
}
func (mod *Module) SetAllStubsVersions([]string) {
panic("SetAllStubsVersions not yet implemented for rust modules")
}
func (mod *Module) AllStubsVersions() []string {
return nil
}
func (mod *Module) BuildStaticVariant() bool {
if mod.compiler != nil {
if library, ok := mod.compiler.(libraryInterface); ok {
@ -508,16 +464,6 @@ func (mod *Module) Module() android.Module {
return mod
}
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 {
return []string{}
}
}
panic(fmt.Errorf("StubsVersions called on non-library module: %q", mod.BaseModuleName()))
}
func (mod *Module) OutputFile() android.OptionalPath {
return mod.outputFile
}