Merge changes I7876b077,Ib2e7d5e6,I7d2d2e02,Ibf5322f8 am: dcc42b6f7e

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

Change-Id: Ifefcf876e203406967f44c035495dbba49c4362f
This commit is contained in:
Jiakai Zhang
2021-09-30 15:24:48 +00:00
committed by Automerger Merge Worker
7 changed files with 472 additions and 21 deletions

View File

@@ -102,6 +102,10 @@ type PrebuiltCommonProperties struct {
// List of bootclasspath fragments inside this prebuilt APEX bundle and for which this APEX
// bundle will create an APEX variant.
Exported_bootclasspath_fragments []string
// List of systemserverclasspath fragments inside this prebuilt APEX bundle and for which this
// APEX bundle will create an APEX variant.
Exported_systemserverclasspath_fragments []string
}
// initPrebuiltCommon initializes the prebuiltCommon structure and performs initialization of the
@@ -169,7 +173,8 @@ func (p *prebuiltCommon) initApexFilesForAndroidMk(ctx android.ModuleContext) {
tag := ctx.OtherModuleDependencyTag(child)
name := android.RemoveOptionalPrebuiltPrefix(ctx.OtherModuleName(child))
if java.IsBootclasspathFragmentContentDepTag(tag) || tag == exportedJavaLibTag {
if java.IsBootclasspathFragmentContentDepTag(tag) ||
java.IsSystemServerClasspathFragmentContentDepTag(tag) || tag == exportedJavaLibTag {
// If the exported java module provides a dex jar path then add it to the list of apexFiles.
path := child.(interface {
DexJarBuildPath() java.OptionalDexJarPath
@@ -189,8 +194,9 @@ func (p *prebuiltCommon) initApexFilesForAndroidMk(ctx android.ModuleContext) {
}
p.apexFilesForAndroidMk = append(p.apexFilesForAndroidMk, af)
}
} else if tag == exportedBootclasspathFragmentTag {
// Visit the children of the bootclasspath_fragment.
} else if tag == exportedBootclasspathFragmentTag ||
tag == exportedSystemserverclasspathFragmentTag {
// Visit the children of the bootclasspath_fragment and systemserver_fragment.
return true
}
@@ -306,21 +312,31 @@ func prebuiltApexModuleCreatorMutator(ctx android.TopDownMutatorContext) {
}
}
func (p *prebuiltCommon) getExportedDependencies() map[string]exportedDependencyTag {
dependencies := make(map[string]exportedDependencyTag)
for _, dep := range p.prebuiltCommonProperties.Exported_java_libs {
dependencies[dep] = exportedJavaLibTag
}
for _, dep := range p.prebuiltCommonProperties.Exported_bootclasspath_fragments {
dependencies[dep] = exportedBootclasspathFragmentTag
}
for _, dep := range p.prebuiltCommonProperties.Exported_systemserverclasspath_fragments {
dependencies[dep] = exportedSystemserverclasspathFragmentTag
}
return dependencies
}
// prebuiltApexContentsDeps adds dependencies onto the prebuilt apex module's contents.
func (p *prebuiltCommon) prebuiltApexContentsDeps(ctx android.BottomUpMutatorContext) {
module := ctx.Module()
// Add dependencies onto the java modules that represent the java libraries that are provided by
// and exported from this prebuilt apex.
for _, exported := range p.prebuiltCommonProperties.Exported_java_libs {
dep := android.PrebuiltNameFromSource(exported)
ctx.AddDependency(module, exportedJavaLibTag, dep)
}
// Add dependencies onto the bootclasspath fragment modules that are exported from this prebuilt
// apex.
for _, exported := range p.prebuiltCommonProperties.Exported_bootclasspath_fragments {
dep := android.PrebuiltNameFromSource(exported)
ctx.AddDependency(module, exportedBootclasspathFragmentTag, dep)
for dep, tag := range p.getExportedDependencies() {
prebuiltDep := android.PrebuiltNameFromSource(dep)
ctx.AddDependency(module, tag, prebuiltDep)
}
}
@@ -571,9 +587,9 @@ func createApexSelectorModule(ctx android.TopDownMutatorContext, name string, ap
// A deapexer module is only needed when the prebuilt apex specifies one or more modules in either
// the `exported_java_libs` or `exported_bootclasspath_fragments` properties as that indicates that
// the listed modules need access to files from within the prebuilt .apex file.
func createDeapexerModuleIfNeeded(ctx android.TopDownMutatorContext, deapexerName string, apexFileSource string, properties *PrebuiltCommonProperties) {
func (p *prebuiltCommon) createDeapexerModuleIfNeeded(ctx android.TopDownMutatorContext, deapexerName string, apexFileSource string) {
// Only create the deapexer module if it is needed.
if len(properties.Exported_java_libs)+len(properties.Exported_bootclasspath_fragments) == 0 {
if len(p.getExportedDependencies()) == 0 {
return
}
@@ -669,8 +685,9 @@ func (t exportedDependencyTag) RequiresFilesFromPrebuiltApex() {}
var _ android.RequiresFilesFromPrebuiltApexTag = exportedDependencyTag{}
var (
exportedJavaLibTag = exportedDependencyTag{name: "exported_java_libs"}
exportedBootclasspathFragmentTag = exportedDependencyTag{name: "exported_bootclasspath_fragments"}
exportedJavaLibTag = exportedDependencyTag{name: "exported_java_libs"}
exportedBootclasspathFragmentTag = exportedDependencyTag{name: "exported_bootclasspath_fragments"}
exportedSystemserverclasspathFragmentTag = exportedDependencyTag{name: "exported_systemserverclasspath_fragments"}
)
var _ prebuiltApexModuleCreator = (*Prebuilt)(nil)
@@ -711,7 +728,7 @@ func (p *Prebuilt) createPrebuiltApexModules(ctx android.TopDownMutatorContext)
createApexSelectorModule(ctx, apexSelectorModuleName, &p.properties.ApexFileProperties)
apexFileSource := ":" + apexSelectorModuleName
createDeapexerModuleIfNeeded(ctx, deapexerModuleName(baseModuleName), apexFileSource, p.prebuiltCommonProperties)
p.createDeapexerModuleIfNeeded(ctx, deapexerModuleName(baseModuleName), apexFileSource)
// Add a source reference to retrieve the selected apex from the selector module.
p.prebuiltCommonProperties.Selected_apex = proptools.StringPtr(apexFileSource)
@@ -914,7 +931,7 @@ func (a *ApexSet) createPrebuiltApexModules(ctx android.TopDownMutatorContext) {
createApexExtractorModule(ctx, apexExtractorModuleName, &a.properties.ApexExtractorProperties)
apexFileSource := ":" + apexExtractorModuleName
createDeapexerModuleIfNeeded(ctx, deapexerModuleName(baseModuleName), apexFileSource, a.prebuiltCommonProperties)
a.createDeapexerModuleIfNeeded(ctx, deapexerModuleName(baseModuleName), apexFileSource)
// After passing the arch specific src properties to the creating the apex selector module
a.prebuiltCommonProperties.Selected_apex = proptools.StringPtr(apexFileSource)

View File

@@ -181,3 +181,53 @@ func TestSystemServerClasspathFragmentWithContentNotInMake(t *testing.T) {
}
`)
}
func TestPrebuiltSystemserverclasspathFragmentContents(t *testing.T) {
result := android.GroupFixturePreparers(
prepareForTestWithSystemserverclasspathFragment,
prepareForTestWithMyapex,
dexpreopt.FixtureSetApexSystemServerJars("myapex:foo"),
).RunTestWithBp(t, `
prebuilt_apex {
name: "myapex",
arch: {
arm64: {
src: "myapex-arm64.apex",
},
arm: {
src: "myapex-arm.apex",
},
},
exported_systemserverclasspath_fragments: ["mysystemserverclasspathfragment"],
}
java_import {
name: "foo",
jars: ["foo.jar"],
apex_available: [
"myapex",
],
}
prebuilt_systemserverclasspath_fragment {
name: "mysystemserverclasspathfragment",
prefer: true,
contents: [
"foo",
],
apex_available: [
"myapex",
],
}
`)
java.CheckModuleDependencies(t, result.TestContext, "myapex", "android_common_myapex", []string{
`myapex.apex.selector`,
`prebuilt_mysystemserverclasspathfragment`,
})
java.CheckModuleDependencies(t, result.TestContext, "mysystemserverclasspathfragment", "android_common_myapex", []string{
`myapex.deapexer`,
`prebuilt_foo`,
})
}