diff options
author | Paul Duffin <paulduffin@google.com> | 2020-07-22 13:00:54 +0100 |
---|---|---|
committer | Michael Bestas <mkbestas@lineageos.org> | 2020-12-08 17:39:42 +0200 |
commit | c07f891e1401f402bdb2911165a367beca40b720 (patch) | |
tree | 04720c27299a8e7caf1ba2cd1b8e3eb9058a00fd | |
parent | a0a95f16207e770cb9e233d4f303eae754569320 (diff) |
Avoid creating APEX variant for sdk member
Previously, an APEX variant was created for a module that was a member
of an SDK just in case it had to be replaced with an APEX requested
snapshotted version of that member. That was necessary because that was
the only way to have APEX specific replacements.
Since then a new method called ReplaceDependenciesIf() has been added
which provides fine grained control over which dependencies are
replaced. This change uses that new method to handle the replacements
which allows the APEX variants to be removed.
Bug: 161928524
Test: m nothing
Change-Id: If3869dd6753dc182b099af566b20fbc9c9c6eff7
-rw-r--r-- | apex/apex.go | 2 | ||||
-rw-r--r-- | sdk/java_sdk_test.go | 4 | ||||
-rw-r--r-- | sdk/sdk.go | 41 |
3 files changed, 32 insertions, 15 deletions
diff --git a/apex/apex.go b/apex/apex.go index cb27f46b9..369b7423b 100644 --- a/apex/apex.go +++ b/apex/apex.go @@ -807,7 +807,7 @@ func apexDepsMutator(mctx android.TopDownMutatorContext) { if !ok || !am.CanHaveApexVariants() { return false } - if !parent.(android.DepIsInSameApex).DepIsInSameApex(mctx, child) && !inAnySdk(child) { + if !parent.(android.DepIsInSameApex).DepIsInSameApex(mctx, child) { return false } diff --git a/sdk/java_sdk_test.go b/sdk/java_sdk_test.go index db395c582..d91905d8c 100644 --- a/sdk/java_sdk_test.go +++ b/sdk/java_sdk_test.go @@ -152,8 +152,8 @@ func TestBasicSdkWithJavaLibrary(t *testing.T) { } `) - sdkMemberV1 := result.ctx.ModuleForTests("sdkmember_mysdk_1", "android_common_myapex").Rule("combineJar").Output - sdkMemberV2 := result.ctx.ModuleForTests("sdkmember_mysdk_2", "android_common_myapex2").Rule("combineJar").Output + sdkMemberV1 := result.ctx.ModuleForTests("sdkmember_mysdk_1", "android_common").Rule("combineJar").Output + sdkMemberV2 := result.ctx.ModuleForTests("sdkmember_mysdk_2", "android_common").Rule("combineJar").Output javalibForMyApex := result.ctx.ModuleForTests("myjavalib", "android_common_myapex") javalibForMyApex2 := result.ctx.ModuleForTests("myjavalib", "android_common_myapex2") diff --git a/sdk/sdk.go b/sdk/sdk.go index cb5a6053d..60727a628 100644 --- a/sdk/sdk.go +++ b/sdk/sdk.go @@ -401,13 +401,17 @@ func memberInterVersionMutator(mctx android.BottomUpMutatorContext) { // Step 4: transitively ripple down the SDK requirements from the root modules like APEX to its // descendants func sdkDepsMutator(mctx android.TopDownMutatorContext) { - if m, ok := mctx.Module().(android.SdkAware); ok { + if parent, ok := mctx.Module().(interface { + android.DepIsInSameApex + android.RequiredSdks + }); ok { // Module types for Mainline modules (e.g. APEX) are expected to implement RequiredSdks() // by reading its own properties like `uses_sdks`. - requiredSdks := m.RequiredSdks() + requiredSdks := parent.RequiredSdks() if len(requiredSdks) > 0 { mctx.VisitDirectDeps(func(m android.Module) { - if dep, ok := m.(android.SdkAware); ok { + // Only propagate required sdks from the apex onto its contents. + if dep, ok := m.(android.SdkAware); ok && parent.DepIsInSameApex(mctx, dep) { dep.BuildWithSdks(requiredSdks) } }) @@ -418,15 +422,28 @@ func sdkDepsMutator(mctx android.TopDownMutatorContext) { // Step 5: if libfoo.mysdk.11 is in the context where version 11 of mysdk is requested, the // versioned module is used instead of the un-versioned (in-development) module libfoo func sdkDepsReplaceMutator(mctx android.BottomUpMutatorContext) { - if m, ok := mctx.Module().(android.SdkAware); ok && m.IsInAnySdk() { - if sdk := m.ContainingSdk(); !sdk.Unversioned() { - if m.RequiredSdks().Contains(sdk) { - // Note that this replacement is done only for the modules that have the same - // variations as the current module. Since current module is already mutated for - // apex references in other APEXes are not affected by this replacement. - memberName := m.MemberName() - mctx.ReplaceDependencies(memberName) - } + if versionedSdkMember, ok := mctx.Module().(android.SdkAware); ok && versionedSdkMember.IsInAnySdk() { + if sdk := versionedSdkMember.ContainingSdk(); !sdk.Unversioned() { + // Only replace dependencies to <sdkmember> with <sdkmember@required-version> + // if the depending module requires it. e.g. + // foo -> sdkmember + // will be transformed to: + // foo -> sdkmember@1 + // if and only if foo is a member of an APEX that requires version 1 of the + // sdk containing sdkmember. + memberName := versionedSdkMember.MemberName() + + // Replace dependencies on sdkmember with a dependency on the current module which + // is a versioned prebuilt of the sdkmember if required. + mctx.ReplaceDependenciesIf(memberName, func(from blueprint.Module, tag blueprint.DependencyTag, to blueprint.Module) bool { + // from - foo + // to - sdkmember + replace := false + if parent, ok := from.(android.RequiredSdks); ok { + replace = parent.RequiredSdks().Contains(sdk) + } + return replace + }) } } } |