diff --git a/cc/binary_sdk_member.go b/cc/binary_sdk_member.go index 55e400e8e..ebf89eaec 100644 --- a/cc/binary_sdk_member.go +++ b/cc/binary_sdk_member.go @@ -40,19 +40,14 @@ type binarySdkMemberType struct { func (mt *binarySdkMemberType) AddDependencies(mctx android.BottomUpMutatorContext, dependencyTag blueprint.DependencyTag, names []string) { targets := mctx.MultiTargets() - for _, lib := range names { + for _, bin := range names { for _, target := range targets { - name, version := StubsLibNameAndVersion(lib) - if version == "" { - version = "latest" - } variations := target.Variations() if mctx.Device() { variations = append(variations, - blueprint.Variation{Mutator: "image", Variation: android.CoreVariation}, - blueprint.Variation{Mutator: "version", Variation: version}) + blueprint.Variation{Mutator: "image", Variation: android.CoreVariation}) } - mctx.AddFarVariationDependencies(variations, dependencyTag, name) + mctx.AddFarVariationDependencies(variations, dependencyTag, bin) } } } diff --git a/cc/cc.go b/cc/cc.go index 006a4a596..e7aa1accd 100644 --- a/cc/cc.go +++ b/cc/cc.go @@ -1871,7 +1871,7 @@ func (c *Module) addSharedLibDependenciesWithVersions(ctx android.BottomUpMutato variations = append([]blueprint.Variation(nil), variations...) - if version != "" && VersionVariantAvailable(c) { + if version != "" && CanBeOrLinkAgainstVersionVariants(c) { // Version is explicitly specified. i.e. libFoo#30 variations = append(variations, blueprint.Variation{Mutator: "version", Variation: version}) depTag.explicitlyVersioned = true @@ -1886,7 +1886,7 @@ func (c *Module) addSharedLibDependenciesWithVersions(ctx android.BottomUpMutato // If the version is not specified, add dependency to all stubs libraries. // The stubs library will be used when the depending module is built for APEX and // the dependent module is not in the same APEX. - if version == "" && VersionVariantAvailable(c) { + if version == "" && CanBeOrLinkAgainstVersionVariants(c) { if dep, ok := deps[0].(*Module); ok { for _, ver := range dep.AllStubsVersions() { // Note that depTag.ExplicitlyVersioned is false in this case. @@ -2492,7 +2492,7 @@ func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps { if ccDep.CcLibrary() && !libDepTag.static() { depIsStubs := ccDep.BuildStubs() - depHasStubs := VersionVariantAvailable(c) && ccDep.HasStubsVariants() + depHasStubs := CanBeOrLinkAgainstVersionVariants(c) && ccDep.HasStubsVariants() depInSameApexes := android.DirectlyInAllApexes(c.InApexes(), depName) depInPlatform := !android.DirectlyInAnyApex(ctx, depName) diff --git a/cc/library.go b/cc/library.go index bf7868ff7..059e29b9c 100644 --- a/cc/library.go +++ b/cc/library.go @@ -1541,7 +1541,7 @@ func createVersionVariations(mctx android.BottomUpMutatorContext, versions []str mctx.CreateAliasVariation("latest", latestVersion) } -func VersionVariantAvailable(module interface { +func CanBeOrLinkAgainstVersionVariants(module interface { Host() bool InRamdisk() bool InRecovery() bool @@ -1549,10 +1549,23 @@ func VersionVariantAvailable(module interface { return !module.Host() && !module.InRamdisk() && !module.InRecovery() } +func CanBeVersionVariant(module interface { + Host() bool + InRamdisk() bool + InRecovery() bool + CcLibraryInterface() bool + Shared() bool + Static() bool +}) bool { + return CanBeOrLinkAgainstVersionVariants(module) && + module.CcLibraryInterface() && (module.Shared() || module.Static()) +} + // 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 && VersionVariantAvailable(library) { + if library, ok := mctx.Module().(LinkableInterface); ok && CanBeVersionVariant(library) { + if library.CcLibrary() && library.BuildSharedVariant() && len(library.StubsVersions()) > 0 && !library.IsSdkVariant() { @@ -1582,7 +1595,7 @@ 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 && VersionVariantAvailable(library) { + if library, ok := mctx.Module().(LinkableInterface); ok && CanBeVersionVariant(library) { createVersionVariations(mctx, library.AllStubsVersions()) } } diff --git a/cc/library_sdk_member.go b/cc/library_sdk_member.go index 41ce29422..765fe710f 100644 --- a/cc/library_sdk_member.go +++ b/cc/library_sdk_member.go @@ -85,8 +85,11 @@ func (mt *librarySdkMemberType) AddDependencies(mctx android.BottomUpMutatorCont variations := target.Variations() if mctx.Device() { variations = append(variations, - blueprint.Variation{Mutator: "image", Variation: android.CoreVariation}, - blueprint.Variation{Mutator: "version", Variation: version}) + 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) diff --git a/rust/rust.go b/rust/rust.go index 6004c6825..1fc3b0e2c 100644 --- a/rust/rust.go +++ b/rust/rust.go @@ -997,11 +997,7 @@ func (mod *Module) DepsMutator(actx android.BottomUpMutatorContext) { } deps := mod.deps(ctx) - commonDepVariations := []blueprint.Variation{} - if cc.VersionVariantAvailable(mod) { - commonDepVariations = append(commonDepVariations, - blueprint.Variation{Mutator: "version", Variation: ""}) - } + var commonDepVariations []blueprint.Variation if !mod.Host() { commonDepVariations = append(commonDepVariations, blueprint.Variation{Mutator: "image", Variation: android.CoreVariation})