diff --git a/apex/prebuilt.go b/apex/prebuilt.go index d59f8bfec..55a9e421a 100644 --- a/apex/prebuilt.go +++ b/apex/prebuilt.go @@ -103,6 +103,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 @@ -174,7 +178,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 @@ -194,8 +199,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 } @@ -311,21 +317,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) } } @@ -576,9 +592,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 } @@ -674,8 +690,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) @@ -716,7 +733,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) @@ -919,7 +936,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) diff --git a/apex/systemserver_classpath_fragment_test.go b/apex/systemserver_classpath_fragment_test.go index 822d2773e..dc682faa4 100644 --- a/apex/systemserver_classpath_fragment_test.go +++ b/apex/systemserver_classpath_fragment_test.go @@ -188,6 +188,19 @@ func TestPrebuiltSystemserverclasspathFragmentContents(t *testing.T) { 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"], @@ -208,7 +221,13 @@ func TestPrebuiltSystemserverclasspathFragmentContents(t *testing.T) { } `) - java.CheckModuleDependencies(t, result.TestContext, "mysystemserverclasspathfragment", "android_common", []string{ + 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`, }) } diff --git a/java/systemserver_classpath_fragment.go b/java/systemserver_classpath_fragment.go index e2738d7fa..26796a6cc 100644 --- a/java/systemserver_classpath_fragment.go +++ b/java/systemserver_classpath_fragment.go @@ -133,8 +133,12 @@ func (systemServerClasspathFragmentContentDependencyTag) ReplaceSourceWithPrebui // they were listed in java_libs. func (systemServerClasspathFragmentContentDependencyTag) CopyDirectlyInAnyApex() {} +// Contents of system server fragments require files from prebuilt apex files. +func (systemServerClasspathFragmentContentDependencyTag) RequiresFilesFromPrebuiltApex() {} + var _ android.ReplaceSourceWithPrebuilt = systemServerClasspathFragmentContentDepTag var _ android.CopyDirectlyInAnyApexTag = systemServerClasspathFragmentContentDepTag +var _ android.RequiresFilesFromPrebuiltApexTag = systemServerClasspathFragmentContentDepTag // The tag used for the dependency between the systemserverclasspath_fragment module and its contents. var systemServerClasspathFragmentContentDepTag = systemServerClasspathFragmentContentDependencyTag{} @@ -177,6 +181,12 @@ func (module *prebuiltSystemServerClasspathModule) Name() string { return module.prebuilt.Name(module.ModuleBase.Name()) } +func (module *prebuiltSystemServerClasspathModule) RequiredFilesFromPrebuiltApex(ctx android.BaseModuleContext) []string { + return nil +} + +var _ android.RequiredFilesFromPrebuiltApex = (*prebuiltSystemServerClasspathModule)(nil) + func prebuiltSystemServerClasspathModuleFactory() android.Module { m := &prebuiltSystemServerClasspathModule{} m.AddProperties(&m.properties)