Merge "Transitively add APEX variants for contents of prebuilt_apex/apex_set" am: c76155cd71 am: c8e88cf3f7 am: 85e40bba2c

Original change: https://android-review.googlesource.com/c/platform/build/soong/+/1697056

Change-Id: Ieed47b213f67248c1bc13957036c1037c356789b
This commit is contained in:
Paul Duffin 2021-05-07 09:15:50 +00:00 committed by Automerger Merge Worker
commit f93ca54858
2 changed files with 35 additions and 18 deletions

View File

@ -109,6 +109,13 @@ func (p *prebuiltCommon) deapexerDeps(ctx android.BottomUpMutatorContext) {
}
}
// Implements android.DepInInSameApex
func (p *prebuiltCommon) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
tag := ctx.OtherModuleDependencyTag(dep)
_, ok := tag.(exportedDependencyTag)
return ok
}
// apexInfoMutator marks any modules for which this apex exports a file as requiring an apex
// specific variant and checks that they are supported.
//
@ -141,34 +148,43 @@ func (p *prebuiltCommon) apexInfoMutator(mctx android.TopDownMutatorContext) {
// Collect the list of dependencies.
var dependencies []android.ApexModule
mctx.VisitDirectDeps(func(m android.Module) {
tag := mctx.OtherModuleDependencyTag(m)
mctx.WalkDeps(func(child, parent android.Module) bool {
// If the child is not in the same apex as the parent then exit immediately and do not visit
// any of the child's dependencies.
if !android.IsDepInSameApex(mctx, parent, child) {
return false
}
tag := mctx.OtherModuleDependencyTag(child)
depName := mctx.OtherModuleName(child)
if exportedTag, ok := tag.(exportedDependencyTag); ok {
propertyName := exportedTag.name
depName := mctx.OtherModuleName(m)
// It is an error if the other module is not a prebuilt.
if _, ok := m.(android.PrebuiltInterface); !ok {
if !android.IsModulePrebuilt(child) {
mctx.PropertyErrorf(propertyName, "%q is not a prebuilt module", depName)
return
return false
}
// It is an error if the other module is not an ApexModule.
if _, ok := m.(android.ApexModule); !ok {
if _, ok := child.(android.ApexModule); !ok {
mctx.PropertyErrorf(propertyName, "%q is not usable within an apex", depName)
return
return false
}
// Strip off the prebuilt_ prefix if present before storing content to ensure consistent
// behavior whether there is a corresponding source module present or not.
depName = android.RemoveOptionalPrebuiltPrefix(depName)
// Remember that this module was added as a direct dependency.
contents[depName] = contents[depName].Add(true)
// Add the module to the list of dependencies that need to have an APEX variant.
dependencies = append(dependencies, m.(android.ApexModule))
}
// Strip off the prebuilt_ prefix if present before storing content to ensure consistent
// behavior whether there is a corresponding source module present or not.
depName = android.RemoveOptionalPrebuiltPrefix(depName)
// Remember if this module was added as a direct dependency.
direct := parent == mctx.Module()
contents[depName] = contents[depName].Add(direct)
// Add the module to the list of dependencies that need to have an APEX variant.
dependencies = append(dependencies, child.(android.ApexModule))
return true
})
// Create contents for the prebuilt_apex and store it away for later use.

View File

@ -1296,9 +1296,10 @@ func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) {
if ai.ForPrebuiltApex {
if deapexerModule == nil {
// This should never happen as a variant for a prebuilt_apex is only created if the
// deapxer module has been configured to export the dex implementation jar for this module.
// deapexer module has been configured to export the dex implementation jar for this module.
ctx.ModuleErrorf("internal error: module %q does not depend on a `deapexer` module for prebuilt_apex %q",
j.Name(), ai.ApexVariationName)
return
}
// Get the path of the dex implementation jar from the `deapexer` module.