From 2286afd0efed2e8417113152bae31bc0529b28b7 Mon Sep 17 00:00:00 2001 From: Jiyong Park Date: Tue, 16 Jun 2020 21:58:53 +0900 Subject: [PATCH] Don't create version variants for SDK variants When a lib has sdk_version set, an SDK variant and a platform variant are created by the sdkMutator. Then by the versionMutator, if the library had 'stubs.versions' property, one or more versioned variants and one impl variant are created for each of the two (SDK and platform) variants. As a concrete example, cc_library { name: "foo", sdk_version: "current", stubs: { versions: ["1", "2"], }, } would create 6 variants: 1) (sdk: "", version: "") 2) (sdk: "", version: "1") 3) (sdk: "", version: "2") 4) (sdk: "sdk", version: "") 5) (sdk: "sdk", version: "1") 6) (sdk: "sdk", version: "2") This is somewhat uncessary because the need for the SDK mutator is to have the platform variant (sdk:"") of a lib where sdk_version is unset, which actually makes sens for the impl variant (version:""), but not the versioned variants (version:"1" or version:"2"). This is not only unncessary, but also causes duplicate module definitions in the Make side when doing an unbundled build. Specifically, The #1 and #4 above both are emitted to Make and get the same name "foo". To fix the problem and not to create unnecessary variants, the versioned variants are no longer created for the sdk variant. So, foo now has the following variants only. 1) (sdk: "", version: "") // not emitted to Make (by versionMutator) 2) (sdk: "", version: "1") // not emitted to Make (by versionMutator) 3) (sdk: "", version: "2") // emitted to Make (by versionMutator) 4) (sdk: "sdk", version: "") // not emitted to Make (by versionMutator) Bug: 159106705 Test: Add sdk_version:"minimum" to libnativehelper in libnativehelper/Android.bp. m SOONG_ALLOW_MISSING_DEPENDENCIES=true TARGET_BUILD_UNBUNDLED=true libnativehelper Change-Id: I6f02f4189e5504286174ccff1642166da82d00c9 --- cc/cc.go | 4 ++++ cc/library.go | 3 ++- cc/linkable.go | 1 + rust/rust.go | 4 ++++ 4 files changed, 11 insertions(+), 1 deletion(-) diff --git a/cc/cc.go b/cc/cc.go index f80c229cb..79fda1f02 100644 --- a/cc/cc.go +++ b/cc/cc.go @@ -3200,6 +3200,10 @@ func (c *Module) SetImageVariation(ctx android.BaseModuleContext, variant string } } +func (c *Module) IsSdkVariant() bool { + return c.Properties.IsSdkVariant +} + func getCurrentNdkPrebuiltVersion(ctx DepsContext) string { if ctx.Config().PlatformSdkVersionInt() > config.NdkMaxPrebuiltVersionInt { return strconv.Itoa(config.NdkMaxPrebuiltVersionInt) diff --git a/cc/library.go b/cc/library.go index ba8b0f40d..6405e4b79 100644 --- a/cc/library.go +++ b/cc/library.go @@ -1575,7 +1575,8 @@ func VersionVariantAvailable(module interface { // (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.CcLibrary() && library.BuildSharedVariant() && len(library.StubsVersions()) > 0 { + if library.CcLibrary() && library.BuildSharedVariant() && len(library.StubsVersions()) > 0 && + !library.IsSdkVariant() { versions := library.StubsVersions() normalizeVersions(mctx, versions) if mctx.Failed() { diff --git a/cc/linkable.go b/cc/linkable.go index de36f9017..66b1c3fea 100644 --- a/cc/linkable.go +++ b/cc/linkable.go @@ -56,6 +56,7 @@ type LinkableInterface interface { SdkVersion() string AlwaysSdk() bool + IsSdkVariant() bool ToolchainLibrary() bool NdkPrebuiltStl() bool diff --git a/rust/rust.go b/rust/rust.go index 6671dd34a..1272e1d8f 100644 --- a/rust/rust.go +++ b/rust/rust.go @@ -196,6 +196,10 @@ func (mod *Module) AlwaysSdk() bool { return false } +func (mod *Module) IsSdkVariant() bool { + return false +} + func (mod *Module) ToolchainLibrary() bool { return false }