Don't create stubs variants of static libraries

Statically linking stub implementations doesn't make sense, don't
create stubs variants of static libraries.

Bug: 170784825
Test: all soong tests
Change-Id: Ie73635244516edf6da884e3a7a275971a9bd7839
This commit is contained in:
Colin Cross 2020-10-23 14:53:06 -07:00
parent 3a456b606e
commit a717db7304
4 changed files with 19 additions and 15 deletions

View file

@ -825,7 +825,7 @@ func TestApexWithStubs(t *testing.T) {
ensureNotContains(t, mylib2Cflags, "-include ")
// Ensure that genstub is invoked with --apex
ensureContains(t, "--apex", ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_static_3").Rule("genStubSrc").Args["flags"])
ensureContains(t, "--apex", ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_shared_3").Rule("genStubSrc").Args["flags"])
ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{
"lib64/mylib.so",
@ -920,11 +920,11 @@ func TestApexWithStubsWithMinSdkVersion(t *testing.T) {
ensureNotContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_shared_29/mylib3.so")
// Ensure that stubs libs are built without -include flags
mylib2Cflags := ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_static").Rule("cc").Args["cFlags"]
mylib2Cflags := ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_shared_29").Rule("cc").Args["cFlags"]
ensureNotContains(t, mylib2Cflags, "-include ")
// Ensure that genstub is invoked with --apex
ensureContains(t, "--apex", ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_static_29").Rule("genStubSrc").Args["flags"])
ensureContains(t, "--apex", ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_shared_29").Rule("genStubSrc").Args["flags"])
ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{
"lib64/mylib.so",

View file

@ -2337,12 +2337,17 @@ func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
}
if depTag == reuseObjTag {
// reusing objects only make sense for cc.Modules.
staticAnalogue := ctx.OtherModuleProvider(dep, StaticLibraryInfoProvider).(StaticLibraryInfo)
objs := staticAnalogue.ReuseObjects
depPaths.Objs = depPaths.Objs.Append(objs)
depExporterInfo := ctx.OtherModuleProvider(dep, FlagExporterInfoProvider).(FlagExporterInfo)
reexportExporter(depExporterInfo)
// Skip reused objects for stub libraries, they use their own stub object file instead.
// 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() {
staticAnalogue := ctx.OtherModuleProvider(dep, StaticLibraryInfoProvider).(StaticLibraryInfo)
objs := staticAnalogue.ReuseObjects
depPaths.Objs = depPaths.Objs.Append(objs)
depExporterInfo := ctx.OtherModuleProvider(dep, FlagExporterInfoProvider).(FlagExporterInfo)
reexportExporter(depExporterInfo)
}
return
}

View file

@ -1665,10 +1665,9 @@ func CanBeVersionVariant(module interface {
InRecovery() bool
CcLibraryInterface() bool
Shared() bool
Static() bool
}) bool {
return CanBeOrLinkAgainstVersionVariants(module) &&
module.CcLibraryInterface() && (module.Shared() || module.Static())
module.CcLibraryInterface() && module.Shared()
}
// versionSelector normalizes the versions in the Stubs.Versions property into MutatedProperties.AllStubsVersions,

View file

@ -86,10 +86,6 @@ func (mt *librarySdkMemberType) AddDependencies(mctx android.BottomUpMutatorCont
if mctx.Device() {
variations = append(variations,
blueprint.Variation{Mutator: "image", Variation: android.CoreVariation})
if mt.linkTypes != nil {
variations = append(variations,
blueprint.Variation{Mutator: "version", Variation: version})
}
}
if mt.linkTypes == nil {
mctx.AddFarVariationDependencies(variations, dependencyTag, name)
@ -97,6 +93,10 @@ func (mt *librarySdkMemberType) AddDependencies(mctx android.BottomUpMutatorCont
for _, linkType := range mt.linkTypes {
libVariations := append(variations,
blueprint.Variation{Mutator: "link", Variation: linkType})
if mctx.Device() && linkType == "shared" {
libVariations = append(libVariations,
blueprint.Variation{Mutator: "version", Variation: version})
}
mctx.AddFarVariationDependencies(libVariations, dependencyTag, name)
}
}