diff --git a/apex/systemserver_classpath_fragment_test.go b/apex/systemserver_classpath_fragment_test.go index a8d5931db..822d2773e 100644 --- a/apex/systemserver_classpath_fragment_test.go +++ b/apex/systemserver_classpath_fragment_test.go @@ -181,3 +181,34 @@ func TestSystemServerClasspathFragmentWithContentNotInMake(t *testing.T) { } `) } + +func TestPrebuiltSystemserverclasspathFragmentContents(t *testing.T) { + result := android.GroupFixturePreparers( + prepareForTestWithSystemserverclasspathFragment, + prepareForTestWithMyapex, + dexpreopt.FixtureSetApexSystemServerJars("myapex:foo"), + ).RunTestWithBp(t, ` + 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, "mysystemserverclasspathfragment", "android_common", []string{ + `prebuilt_foo`, + }) +} diff --git a/java/systemserver_classpath_fragment.go b/java/systemserver_classpath_fragment.go index de2a9787f..e2738d7fa 100644 --- a/java/systemserver_classpath_fragment.go +++ b/java/systemserver_classpath_fragment.go @@ -28,6 +28,7 @@ func init() { func registerSystemserverClasspathBuildComponents(ctx android.RegistrationContext) { ctx.RegisterModuleType("platform_systemserverclasspath", platformSystemServerClasspathFactory) ctx.RegisterModuleType("systemserverclasspath_fragment", systemServerClasspathFactory) + ctx.RegisterModuleType("prebuilt_systemserverclasspath_fragment", prebuiltSystemServerClasspathModuleFactory) } type platformSystemServerClasspathModule struct { @@ -144,8 +145,14 @@ func IsSystemServerClasspathFragmentContentDepTag(tag blueprint.DependencyTag) b func (s *SystemServerClasspathModule) ComponentDepsMutator(ctx android.BottomUpMutatorContext) { module := ctx.Module() + _, isSourceModule := module.(*SystemServerClasspathModule) for _, name := range s.properties.Contents { + // A systemserverclasspath_fragment must depend only on other source modules, while the + // prebuilt_systemserverclasspath_fragment_fragment must only depend on other prebuilt modules. + if !isSourceModule { + name = android.PrebuiltNameFromSource(name) + } ctx.AddDependency(module, systemServerClasspathFragmentContentDepTag, name) } } @@ -155,3 +162,28 @@ func (s *SystemServerClasspathModule) IDEInfo(dpInfo *android.IdeInfo) { dpInfo.Deps = append(dpInfo.Deps, s.properties.Contents...) dpInfo.Paths = append(dpInfo.Paths, s.modulePaths...) } + +// A prebuilt version of the systemserverclasspath_fragment module. +type prebuiltSystemServerClasspathModule struct { + SystemServerClasspathModule + prebuilt android.Prebuilt +} + +func (module *prebuiltSystemServerClasspathModule) Prebuilt() *android.Prebuilt { + return &module.prebuilt +} + +func (module *prebuiltSystemServerClasspathModule) Name() string { + return module.prebuilt.Name(module.ModuleBase.Name()) +} + +func prebuiltSystemServerClasspathModuleFactory() android.Module { + m := &prebuiltSystemServerClasspathModule{} + m.AddProperties(&m.properties) + // This doesn't actually have any prebuilt files of its own so pass a placeholder for the srcs + // array. + android.InitPrebuiltModule(m, &[]string{"placeholder"}) + android.InitApexModule(m) + android.InitAndroidArchModule(m, android.DeviceSupported, android.MultilibCommon) + return m +}