Merge "Avoid creating APEX variant for sdk member"
This commit is contained in:
@@ -704,7 +704,7 @@ func apexDepsMutator(mctx android.TopDownMutatorContext) {
|
|||||||
if !ok || !am.CanHaveApexVariants() {
|
if !ok || !am.CanHaveApexVariants() {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if !parent.(android.DepIsInSameApex).DepIsInSameApex(mctx, child) && !inAnySdk(child) {
|
if !parent.(android.DepIsInSameApex).DepIsInSameApex(mctx, child) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if excludeVndkLibs {
|
if excludeVndkLibs {
|
||||||
|
@@ -204,8 +204,8 @@ func TestBasicSdkWithJavaLibrary(t *testing.T) {
|
|||||||
}
|
}
|
||||||
`)
|
`)
|
||||||
|
|
||||||
sdkMemberV1 := result.ctx.ModuleForTests("sdkmember_mysdk_1", "android_common_myapex").Rule("combineJar").Output
|
sdkMemberV1 := result.ctx.ModuleForTests("sdkmember_mysdk_1", "android_common").Rule("combineJar").Output
|
||||||
sdkMemberV2 := result.ctx.ModuleForTests("sdkmember_mysdk_2", "android_common_myapex2").Rule("combineJar").Output
|
sdkMemberV2 := result.ctx.ModuleForTests("sdkmember_mysdk_2", "android_common").Rule("combineJar").Output
|
||||||
|
|
||||||
javalibForMyApex := result.ctx.ModuleForTests("myjavalib", "android_common_myapex")
|
javalibForMyApex := result.ctx.ModuleForTests("myjavalib", "android_common_myapex")
|
||||||
javalibForMyApex2 := result.ctx.ModuleForTests("myjavalib", "android_common_myapex2")
|
javalibForMyApex2 := result.ctx.ModuleForTests("myjavalib", "android_common_myapex2")
|
||||||
|
41
sdk/sdk.go
41
sdk/sdk.go
@@ -406,13 +406,17 @@ func memberInterVersionMutator(mctx android.BottomUpMutatorContext) {
|
|||||||
// Step 4: transitively ripple down the SDK requirements from the root modules like APEX to its
|
// Step 4: transitively ripple down the SDK requirements from the root modules like APEX to its
|
||||||
// descendants
|
// descendants
|
||||||
func sdkDepsMutator(mctx android.TopDownMutatorContext) {
|
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()
|
// Module types for Mainline modules (e.g. APEX) are expected to implement RequiredSdks()
|
||||||
// by reading its own properties like `uses_sdks`.
|
// by reading its own properties like `uses_sdks`.
|
||||||
requiredSdks := m.RequiredSdks()
|
requiredSdks := parent.RequiredSdks()
|
||||||
if len(requiredSdks) > 0 {
|
if len(requiredSdks) > 0 {
|
||||||
mctx.VisitDirectDeps(func(m android.Module) {
|
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)
|
dep.BuildWithSdks(requiredSdks)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -423,15 +427,28 @@ func sdkDepsMutator(mctx android.TopDownMutatorContext) {
|
|||||||
// Step 5: if libfoo.mysdk.11 is in the context where version 11 of mysdk is requested, the
|
// 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
|
// versioned module is used instead of the un-versioned (in-development) module libfoo
|
||||||
func sdkDepsReplaceMutator(mctx android.BottomUpMutatorContext) {
|
func sdkDepsReplaceMutator(mctx android.BottomUpMutatorContext) {
|
||||||
if m, ok := mctx.Module().(android.SdkAware); ok && m.IsInAnySdk() {
|
if versionedSdkMember, ok := mctx.Module().(android.SdkAware); ok && versionedSdkMember.IsInAnySdk() {
|
||||||
if sdk := m.ContainingSdk(); !sdk.Unversioned() {
|
if sdk := versionedSdkMember.ContainingSdk(); !sdk.Unversioned() {
|
||||||
if m.RequiredSdks().Contains(sdk) {
|
// Only replace dependencies to <sdkmember> with <sdkmember@required-version>
|
||||||
// Note that this replacement is done only for the modules that have the same
|
// if the depending module requires it. e.g.
|
||||||
// variations as the current module. Since current module is already mutated for
|
// foo -> sdkmember
|
||||||
// apex references in other APEXes are not affected by this replacement.
|
// will be transformed to:
|
||||||
memberName := m.MemberName()
|
// foo -> sdkmember@1
|
||||||
mctx.ReplaceDependencies(memberName)
|
// 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
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user