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
diff --git a/cc/cc.go b/cc/cc.go
index 286cf09..3297e41 100644
--- a/cc/cc.go
+++ b/cc/cc.go
@@ -377,8 +377,6 @@
isForPlatform() bool
apexVariationName() string
apexSdkVersion() android.ApiLevel
- hasStubsVariants() bool
- isStubs() bool
bootstrap() bool
mustUseVendorVariant() bool
nativeCoverage() bool
@@ -623,6 +621,8 @@
lto *lto
pgo *pgo
+ library libraryInterface
+
outputFile android.OptionalPath
cachedToolchain config.Toolchain
@@ -731,13 +731,6 @@
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 @@
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) 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 @@
// 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 @@
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 @@
// 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 @@
// 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 @@
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 @@
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 @@
// 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
}
diff --git a/cc/fuzz.go b/cc/fuzz.go
index 681e3bc..fe3c12b 100644
--- a/cc/fuzz.go
+++ b/cc/fuzz.go
@@ -174,12 +174,25 @@
// 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
}
diff --git a/cc/library.go b/cc/library.go
index d77d876..d946629 100644
--- a/cc/library.go
+++ b/cc/library.go
@@ -587,7 +587,7 @@
}
}
}
- if Bool(enabled) || ctx.hasStubsVariants() {
+ if Bool(enabled) || library.hasStubsVariants() {
return "PLATFORM"
}
return ""
@@ -598,7 +598,7 @@
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 @@
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 @@
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 @@
module.compiler = library
module.linker = library
module.installer = library
+ module.library = library
return module, library
}
@@ -1620,8 +1621,14 @@
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 @@
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 @@
}
// 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 @@
// 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
}
diff --git a/cc/library_sdk_member.go b/cc/library_sdk_member.go
index 7f33072..106b2eb 100644
--- a/cc/library_sdk_member.go
+++ b/cc/library_sdk_member.go
@@ -428,22 +428,22 @@
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)
}
diff --git a/cc/linkable.go b/cc/linkable.go
index 177e0c4..60ab6df 100644
--- a/cc/linkable.go
+++ b/cc/linkable.go
@@ -16,16 +16,7 @@
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 @@
AlwaysSdk() bool
IsSdkVariant() bool
- ToolchainLibrary() bool
- NdkPrebuiltStl() bool
- StubDecorator() bool
-
SplitPerApiLevel() bool
}
diff --git a/cc/llndk_library.go b/cc/llndk_library.go
index 9f4444d..3b1d2f4 100644
--- a/cc/llndk_library.go
+++ b/cc/llndk_library.go
@@ -185,7 +185,7 @@
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 @@
module.compiler = stub
module.linker = stub
module.installer = nil
+ module.library = stub
module.AddProperties(
&module.Properties,
@@ -251,6 +252,7 @@
module.compiler = nil
module.linker = decorator
module.installer = nil
+ module.library = decorator
module.AddProperties(
&module.Properties,
diff --git a/cc/ndk_library.go b/cc/ndk_library.go
index 02b38a6..9097e7b 100644
--- a/cc/ndk_library.go
+++ b/cc/ndk_library.go
@@ -333,6 +333,7 @@
module.compiler = stub
module.linker = stub
module.installer = stub
+ module.library = stub
module.Properties.AlwaysSdk = true
module.Properties.Sdk_version = StringPtr("current")
diff --git a/cc/ndk_sysroot.go b/cc/ndk_sysroot.go
index b6733c2..70b15c1 100644
--- a/cc/ndk_sysroot.go
+++ b/cc/ndk_sysroot.go
@@ -131,7 +131,7 @@
}
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
diff --git a/cc/prebuilt.go b/cc/prebuilt.go
index 45d3eb1..8873883 100644
--- a/cc/prebuilt.go
+++ b/cc/prebuilt.go
@@ -228,6 +228,7 @@
libraryDecorator: library,
}
module.linker = prebuilt
+ module.library = prebuilt
module.AddProperties(&prebuilt.properties)
diff --git a/cc/toolchain_library.go b/cc/toolchain_library.go
index 8c546c5..0c934ad 100644
--- a/cc/toolchain_library.go
+++ b/cc/toolchain_library.go
@@ -66,6 +66,7 @@
module.stl = nil
module.sanitize = nil
module.installer = nil
+ module.library = toolchainLibrary
module.Properties.Sdk_version = StringPtr("current")
return module.Init()
}
diff --git a/cc/vndk.go b/cc/vndk.go
index 7d8777c..b2614c5 100644
--- a/cc/vndk.go
+++ b/cc/vndk.go
@@ -313,7 +313,7 @@
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.
diff --git a/rust/rust.go b/rust/rust.go
index 77d9a90..e65b90e 100644
--- a/rust/rust.go
+++ b/rust/rust.go
@@ -133,14 +133,6 @@
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 @@
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 @@
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 @@
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 @@
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
}