blob: 79d2ee9f7dd4f5f41c8cf3defbd7cc46e65b51ed [file] [log] [blame]
satayev95e9c5b2021-04-29 11:50:26 +01001// Copyright 2021 Google Inc. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package java
16
17import (
18 "android/soong/android"
satayev013485b2021-05-06 23:38:10 +010019 "android/soong/dexpreopt"
Colin Crossc33e5212021-05-25 18:16:02 -070020
satayev9366a052021-05-17 21:13:44 +010021 "github.com/google/blueprint"
satayev95e9c5b2021-04-29 11:50:26 +010022)
23
24func init() {
25 registerSystemserverClasspathBuildComponents(android.InitRegistrationContext)
Jiakai Zhanga8d86602021-09-26 09:02:17 +000026
27 android.RegisterSdkMemberType(&systemServerClasspathFragmentMemberType{
28 SdkMemberTypeBase: android.SdkMemberTypeBase{
29 PropertyName: "systemserverclasspath_fragments",
30 SupportsSdk: true,
Paul Duffinf861df72022-07-01 15:56:06 +000031
32 // This was only added in Tiramisu.
33 SupportedBuildReleaseSpecification: "Tiramisu+",
Jiakai Zhanga8d86602021-09-26 09:02:17 +000034 },
35 })
satayev95e9c5b2021-04-29 11:50:26 +010036}
37
38func registerSystemserverClasspathBuildComponents(ctx android.RegistrationContext) {
satayev95e9c5b2021-04-29 11:50:26 +010039 ctx.RegisterModuleType("platform_systemserverclasspath", platformSystemServerClasspathFactory)
satayevaa86bac2021-05-13 19:01:52 +010040 ctx.RegisterModuleType("systemserverclasspath_fragment", systemServerClasspathFactory)
Jiakai Zhangc9864272021-09-26 03:52:19 +000041 ctx.RegisterModuleType("prebuilt_systemserverclasspath_fragment", prebuiltSystemServerClasspathModuleFactory)
satayev95e9c5b2021-04-29 11:50:26 +010042}
43
44type platformSystemServerClasspathModule struct {
45 android.ModuleBase
46
47 ClasspathFragmentBase
48}
49
50func platformSystemServerClasspathFactory() android.Module {
51 m := &platformSystemServerClasspathModule{}
52 initClasspathFragment(m, SYSTEMSERVERCLASSPATH)
53 android.InitAndroidArchModule(m, android.DeviceSupported, android.MultilibCommon)
54 return m
55}
56
satayevaa86bac2021-05-13 19:01:52 +010057func (p *platformSystemServerClasspathModule) AndroidMkEntries() (entries []android.AndroidMkEntries) {
58 return p.classpathFragmentBase().androidMkEntries()
satayev95e9c5b2021-04-29 11:50:26 +010059}
60
satayevaa86bac2021-05-13 19:01:52 +010061func (p *platformSystemServerClasspathModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
satayevb3090502021-06-15 17:49:10 +010062 configuredJars := p.configuredJars(ctx)
63 classpathJars := configuredJarListToClasspathJars(ctx, configuredJars, p.classpathType)
Jiakai Zhangcee9e192021-10-29 19:46:45 +000064 standaloneConfiguredJars := p.standaloneConfiguredJars(ctx)
65 standaloneClasspathJars := configuredJarListToClasspathJars(ctx, standaloneConfiguredJars, STANDALONE_SYSTEMSERVER_JARS)
Jiakai Zhang389a6472021-12-14 18:54:06 +000066 configuredJars = configuredJars.AppendList(&standaloneConfiguredJars)
Jiakai Zhangcee9e192021-10-29 19:46:45 +000067 classpathJars = append(classpathJars, standaloneClasspathJars...)
satayevb3090502021-06-15 17:49:10 +010068 p.classpathFragmentBase().generateClasspathProtoBuildActions(ctx, configuredJars, classpathJars)
satayev013485b2021-05-06 23:38:10 +010069}
70
satayev142ed272021-06-15 16:21:17 +010071func (p *platformSystemServerClasspathModule) configuredJars(ctx android.ModuleContext) android.ConfiguredJarList {
satayevb3090502021-06-15 17:49:10 +010072 // TODO(satayev): include any apex jars that don't populate their classpath proto config.
73 return dexpreopt.GetGlobalConfig(ctx).SystemServerJars
satayev95e9c5b2021-04-29 11:50:26 +010074}
satayevaa86bac2021-05-13 19:01:52 +010075
Jiakai Zhangcee9e192021-10-29 19:46:45 +000076func (p *platformSystemServerClasspathModule) standaloneConfiguredJars(ctx android.ModuleContext) android.ConfiguredJarList {
77 return dexpreopt.GetGlobalConfig(ctx).StandaloneSystemServerJars
78}
79
satayev333a1732021-05-17 21:35:26 +010080type SystemServerClasspathModule struct {
satayevaa86bac2021-05-13 19:01:52 +010081 android.ModuleBase
satayev333a1732021-05-17 21:35:26 +010082 android.ApexModuleBase
Jiakai Zhanga8d86602021-09-26 09:02:17 +000083 android.SdkBase
satayevaa86bac2021-05-13 19:01:52 +010084
85 ClasspathFragmentBase
satayev9366a052021-05-17 21:13:44 +010086
87 properties systemServerClasspathFragmentProperties
braleeb0c1f0c2021-06-07 22:49:13 +080088
89 // Collect the module directory for IDE info in java/jdeps.go.
90 modulePaths []string
satayev9366a052021-05-17 21:13:44 +010091}
92
satayev333a1732021-05-17 21:35:26 +010093func (s *SystemServerClasspathModule) ShouldSupportSdkVersion(ctx android.BaseModuleContext, sdkVersion android.ApiLevel) error {
94 return nil
95}
96
satayev9366a052021-05-17 21:13:44 +010097type systemServerClasspathFragmentProperties struct {
Jiakai Zhangcee9e192021-10-29 19:46:45 +000098 // List of system_server classpath jars, could be either java_library, or java_sdk_library.
satayev9366a052021-05-17 21:13:44 +010099 //
100 // The order of this list matters as it is the order that is used in the SYSTEMSERVERCLASSPATH.
101 Contents []string
Jiakai Zhangcee9e192021-10-29 19:46:45 +0000102
103 // List of jars that system_server loads dynamically using separate classloaders.
104 //
105 // The order does not matter.
106 Standalone_contents []string
satayevaa86bac2021-05-13 19:01:52 +0100107}
108
109func systemServerClasspathFactory() android.Module {
satayev333a1732021-05-17 21:35:26 +0100110 m := &SystemServerClasspathModule{}
satayev9366a052021-05-17 21:13:44 +0100111 m.AddProperties(&m.properties)
satayev333a1732021-05-17 21:35:26 +0100112 android.InitApexModule(m)
Jiakai Zhanga8d86602021-09-26 09:02:17 +0000113 android.InitSdkAwareModule(m)
satayevaa86bac2021-05-13 19:01:52 +0100114 initClasspathFragment(m, SYSTEMSERVERCLASSPATH)
115 android.InitAndroidArchModule(m, android.DeviceSupported, android.MultilibCommon)
116 return m
117}
118
satayev333a1732021-05-17 21:35:26 +0100119func (s *SystemServerClasspathModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Jiakai Zhangcee9e192021-10-29 19:46:45 +0000120 if len(s.properties.Contents) == 0 && len(s.properties.Standalone_contents) == 0 {
121 ctx.PropertyErrorf("contents", "Either contents or standalone_contents needs to be non-empty")
satayev9366a052021-05-17 21:13:44 +0100122 }
123
satayevb3090502021-06-15 17:49:10 +0100124 configuredJars := s.configuredJars(ctx)
125 classpathJars := configuredJarListToClasspathJars(ctx, configuredJars, s.classpathType)
Jiakai Zhangcee9e192021-10-29 19:46:45 +0000126 standaloneConfiguredJars := s.standaloneConfiguredJars(ctx)
127 standaloneClasspathJars := configuredJarListToClasspathJars(ctx, standaloneConfiguredJars, STANDALONE_SYSTEMSERVER_JARS)
Jiakai Zhang389a6472021-12-14 18:54:06 +0000128 configuredJars = configuredJars.AppendList(&standaloneConfiguredJars)
Jiakai Zhangcee9e192021-10-29 19:46:45 +0000129 classpathJars = append(classpathJars, standaloneClasspathJars...)
satayevb3090502021-06-15 17:49:10 +0100130 s.classpathFragmentBase().generateClasspathProtoBuildActions(ctx, configuredJars, classpathJars)
braleeb0c1f0c2021-06-07 22:49:13 +0800131
132 // Collect the module directory for IDE info in java/jdeps.go.
133 s.modulePaths = append(s.modulePaths, ctx.ModuleDir())
satayevaa86bac2021-05-13 19:01:52 +0100134}
135
satayev142ed272021-06-15 16:21:17 +0100136func (s *SystemServerClasspathModule) configuredJars(ctx android.ModuleContext) android.ConfiguredJarList {
satayev703c67a2021-05-20 21:33:41 +0100137 global := dexpreopt.GetGlobalConfig(ctx)
138
satayevd604b212021-07-21 14:23:52 +0100139 possibleUpdatableModules := gatherPossibleApexModuleNamesAndStems(ctx, s.properties.Contents, systemServerClasspathFragmentContentDepTag)
satayevd34eb0c2021-08-06 13:20:28 +0100140 jars, unknown := global.ApexSystemServerJars.Filter(possibleUpdatableModules)
141 // TODO(satayev): remove geotz ssc_fragment, since geotz is not part of SSCP anymore.
142 _, unknown = android.RemoveFromList("geotz", unknown)
Keun young Parkd64ab232021-10-18 08:42:23 -0700143 // This module only exists in car products.
144 // So ignore it even if it is not in PRODUCT_APEX_SYSTEM_SERVER_JARS.
145 // TODO(b/203233647): Add better mechanism to make it optional.
146 _, unknown = android.RemoveFromList("car-frameworks-service-module", unknown)
Samiul Islam7b385c52021-10-11 22:47:13 +0100147
Alan Stokesbcd567e2021-11-12 15:21:43 +0000148 // This module is optional, so it is not present in all products.
149 // (See PRODUCT_ISOLATED_COMPILATION_ENABLED.)
150 // So ignore it even if it is not in PRODUCT_APEX_SYSTEM_SERVER_JARS.
151 // TODO(b/203233647): Add better mechanism to make it optional.
152 _, unknown = android.RemoveFromList("service-compos", unknown)
153
Samiul Islam7b385c52021-10-11 22:47:13 +0100154 // TODO(satayev): for apex_test we want to include all contents unconditionally to classpaths
155 // config. However, any test specific jars would not be present in ApexSystemServerJars. Instead,
156 // we should check if we are creating a config for apex_test via ApexInfo and amend the values.
157 // This is an exception to support end-to-end test for ApexdUnitTests, until such support exists.
158 if android.InList("test_service-apexd", possibleUpdatableModules) {
159 jars = jars.Append("com.android.apex.test_package", "test_service-apexd")
160 } else if global.ApexSystemServerJars.Len() > 0 && len(unknown) > 0 && !android.IsModuleInVersionedSdk(ctx.Module()) {
161 // For non test apexes, make sure that all contents are actually declared in make.
Ulya Trafimoviche5b2b492021-10-04 15:42:53 +0100162 ctx.ModuleErrorf("%s in contents must also be declared in PRODUCT_APEX_SYSTEM_SERVER_JARS", unknown)
satayevd34eb0c2021-08-06 13:20:28 +0100163 }
164
165 return jars
satayevaa86bac2021-05-13 19:01:52 +0100166}
satayev9366a052021-05-17 21:13:44 +0100167
Jiakai Zhangcee9e192021-10-29 19:46:45 +0000168func (s *SystemServerClasspathModule) standaloneConfiguredJars(ctx android.ModuleContext) android.ConfiguredJarList {
169 global := dexpreopt.GetGlobalConfig(ctx)
170
171 possibleUpdatableModules := gatherPossibleApexModuleNamesAndStems(ctx, s.properties.Standalone_contents, systemServerClasspathFragmentContentDepTag)
172 jars, _ := global.ApexStandaloneSystemServerJars.Filter(possibleUpdatableModules)
173
174 // TODO(jiakaiz): add a check to ensure that the contents are declared in make.
175
176 return jars
177}
178
satayev9366a052021-05-17 21:13:44 +0100179type systemServerClasspathFragmentContentDependencyTag struct {
180 blueprint.BaseDependencyTag
181}
182
Paul Duffin25322e42021-09-07 14:52:48 +0100183// The systemserverclasspath_fragment contents must never depend on prebuilts.
184func (systemServerClasspathFragmentContentDependencyTag) ReplaceSourceWithPrebuilt() bool {
185 return false
186}
187
Jiakai Zhanga8d86602021-09-26 09:02:17 +0000188// SdkMemberType causes dependencies added with this tag to be automatically added to the sdk as if
189// they were specified using java_systemserver_libs or java_sdk_libs.
190func (b systemServerClasspathFragmentContentDependencyTag) SdkMemberType(child android.Module) android.SdkMemberType {
191 // If the module is a java_sdk_library then treat it as if it was specified in the java_sdk_libs
192 // property, otherwise treat if it was specified in the java_systemserver_libs property.
193 if javaSdkLibrarySdkMemberType.IsInstance(child) {
194 return javaSdkLibrarySdkMemberType
195 }
196
197 return javaSystemserverLibsSdkMemberType
198}
199
200func (b systemServerClasspathFragmentContentDependencyTag) ExportMember() bool {
201 return true
202}
203
Colin Crossc33e5212021-05-25 18:16:02 -0700204// Contents of system server fragments in an apex are considered to be directly in the apex, as if
205// they were listed in java_libs.
206func (systemServerClasspathFragmentContentDependencyTag) CopyDirectlyInAnyApex() {}
207
Jiakai Zhang774dd302021-09-26 03:54:25 +0000208// Contents of system server fragments require files from prebuilt apex files.
209func (systemServerClasspathFragmentContentDependencyTag) RequiresFilesFromPrebuiltApex() {}
210
Paul Duffin25322e42021-09-07 14:52:48 +0100211var _ android.ReplaceSourceWithPrebuilt = systemServerClasspathFragmentContentDepTag
Jiakai Zhanga8d86602021-09-26 09:02:17 +0000212var _ android.SdkMemberDependencyTag = systemServerClasspathFragmentContentDepTag
Colin Crossc33e5212021-05-25 18:16:02 -0700213var _ android.CopyDirectlyInAnyApexTag = systemServerClasspathFragmentContentDepTag
Jiakai Zhang774dd302021-09-26 03:54:25 +0000214var _ android.RequiresFilesFromPrebuiltApexTag = systemServerClasspathFragmentContentDepTag
Colin Crossc33e5212021-05-25 18:16:02 -0700215
satayev9366a052021-05-17 21:13:44 +0100216// The tag used for the dependency between the systemserverclasspath_fragment module and its contents.
217var systemServerClasspathFragmentContentDepTag = systemServerClasspathFragmentContentDependencyTag{}
218
219func IsSystemServerClasspathFragmentContentDepTag(tag blueprint.DependencyTag) bool {
220 return tag == systemServerClasspathFragmentContentDepTag
221}
222
satayev333a1732021-05-17 21:35:26 +0100223func (s *SystemServerClasspathModule) ComponentDepsMutator(ctx android.BottomUpMutatorContext) {
satayev9366a052021-05-17 21:13:44 +0100224 module := ctx.Module()
Jiakai Zhangc9864272021-09-26 03:52:19 +0000225 _, isSourceModule := module.(*SystemServerClasspathModule)
Jiakai Zhangcee9e192021-10-29 19:46:45 +0000226 var deps []string
227 deps = append(deps, s.properties.Contents...)
228 deps = append(deps, s.properties.Standalone_contents...)
satayev9366a052021-05-17 21:13:44 +0100229
Jiakai Zhangcee9e192021-10-29 19:46:45 +0000230 for _, name := range deps {
Jiakai Zhangc9864272021-09-26 03:52:19 +0000231 // A systemserverclasspath_fragment must depend only on other source modules, while the
232 // prebuilt_systemserverclasspath_fragment_fragment must only depend on other prebuilt modules.
233 if !isSourceModule {
234 name = android.PrebuiltNameFromSource(name)
235 }
satayev9366a052021-05-17 21:13:44 +0100236 ctx.AddDependency(module, systemServerClasspathFragmentContentDepTag, name)
237 }
238}
braleeb0c1f0c2021-06-07 22:49:13 +0800239
240// Collect information for opening IDE project files in java/jdeps.go.
241func (s *SystemServerClasspathModule) IDEInfo(dpInfo *android.IdeInfo) {
242 dpInfo.Deps = append(dpInfo.Deps, s.properties.Contents...)
Jiakai Zhangcee9e192021-10-29 19:46:45 +0000243 dpInfo.Deps = append(dpInfo.Deps, s.properties.Standalone_contents...)
braleeb0c1f0c2021-06-07 22:49:13 +0800244 dpInfo.Paths = append(dpInfo.Paths, s.modulePaths...)
245}
Jiakai Zhangc9864272021-09-26 03:52:19 +0000246
Jiakai Zhanga8d86602021-09-26 09:02:17 +0000247type systemServerClasspathFragmentMemberType struct {
248 android.SdkMemberTypeBase
249}
250
251func (s *systemServerClasspathFragmentMemberType) AddDependencies(ctx android.SdkDependencyContext, dependencyTag blueprint.DependencyTag, names []string) {
252 ctx.AddVariationDependencies(nil, dependencyTag, names...)
253}
254
255func (s *systemServerClasspathFragmentMemberType) IsInstance(module android.Module) bool {
256 _, ok := module.(*SystemServerClasspathModule)
257 return ok
258}
259
260func (s *systemServerClasspathFragmentMemberType) AddPrebuiltModule(ctx android.SdkMemberContext, member android.SdkMember) android.BpModule {
261 return ctx.SnapshotBuilder().AddPrebuiltModule(member, "prebuilt_systemserverclasspath_fragment")
262}
263
264func (s *systemServerClasspathFragmentMemberType) CreateVariantPropertiesStruct() android.SdkMemberProperties {
265 return &systemServerClasspathFragmentSdkMemberProperties{}
266}
267
268type systemServerClasspathFragmentSdkMemberProperties struct {
269 android.SdkMemberPropertiesBase
270
Jiakai Zhangcee9e192021-10-29 19:46:45 +0000271 // List of system_server classpath jars, could be either java_library, or java_sdk_library.
272 //
273 // The order of this list matters as it is the order that is used in the SYSTEMSERVERCLASSPATH.
Jiakai Zhanga8d86602021-09-26 09:02:17 +0000274 Contents []string
Jiakai Zhangcee9e192021-10-29 19:46:45 +0000275
276 // List of jars that system_server loads dynamically using separate classloaders.
277 //
278 // The order does not matter.
279 Standalone_contents []string
Jiakai Zhanga8d86602021-09-26 09:02:17 +0000280}
281
282func (s *systemServerClasspathFragmentSdkMemberProperties) PopulateFromVariant(ctx android.SdkMemberContext, variant android.Module) {
283 module := variant.(*SystemServerClasspathModule)
284
285 s.Contents = module.properties.Contents
Jiakai Zhangcee9e192021-10-29 19:46:45 +0000286 s.Standalone_contents = module.properties.Standalone_contents
Jiakai Zhanga8d86602021-09-26 09:02:17 +0000287}
288
289func (s *systemServerClasspathFragmentSdkMemberProperties) AddToPropertySet(ctx android.SdkMemberContext, propertySet android.BpPropertySet) {
290 builder := ctx.SnapshotBuilder()
291 requiredMemberDependency := builder.SdkMemberReferencePropertyTag(true)
292
293 if len(s.Contents) > 0 {
294 propertySet.AddPropertyWithTag("contents", s.Contents, requiredMemberDependency)
295 }
Jiakai Zhangcee9e192021-10-29 19:46:45 +0000296
297 if len(s.Standalone_contents) > 0 {
298 propertySet.AddPropertyWithTag("standalone_contents", s.Standalone_contents, requiredMemberDependency)
299 }
Jiakai Zhanga8d86602021-09-26 09:02:17 +0000300}
301
302var _ android.SdkMemberType = (*systemServerClasspathFragmentMemberType)(nil)
303
Jiakai Zhangc9864272021-09-26 03:52:19 +0000304// A prebuilt version of the systemserverclasspath_fragment module.
305type prebuiltSystemServerClasspathModule struct {
306 SystemServerClasspathModule
307 prebuilt android.Prebuilt
308}
309
310func (module *prebuiltSystemServerClasspathModule) Prebuilt() *android.Prebuilt {
311 return &module.prebuilt
312}
313
314func (module *prebuiltSystemServerClasspathModule) Name() string {
315 return module.prebuilt.Name(module.ModuleBase.Name())
316}
317
Jiakai Zhang774dd302021-09-26 03:54:25 +0000318func (module *prebuiltSystemServerClasspathModule) RequiredFilesFromPrebuiltApex(ctx android.BaseModuleContext) []string {
319 return nil
320}
321
322var _ android.RequiredFilesFromPrebuiltApex = (*prebuiltSystemServerClasspathModule)(nil)
323
Jiakai Zhangc9864272021-09-26 03:52:19 +0000324func prebuiltSystemServerClasspathModuleFactory() android.Module {
325 m := &prebuiltSystemServerClasspathModule{}
326 m.AddProperties(&m.properties)
327 // This doesn't actually have any prebuilt files of its own so pass a placeholder for the srcs
328 // array.
329 android.InitPrebuiltModule(m, &[]string{"placeholder"})
330 android.InitApexModule(m)
Jiakai Zhanga8d86602021-09-26 09:02:17 +0000331 android.InitSdkAwareModule(m)
Jiakai Zhangc9864272021-09-26 03:52:19 +0000332 android.InitAndroidArchModule(m, android.DeviceSupported, android.MultilibCommon)
333 return m
334}