blob: 17d301b708beca4b5b342ebe916902ffd7224838 [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
Paul Duffin4e7d1c42022-05-13 13:12:19 +000027 android.RegisterSdkMemberType(SystemServerClasspathFragmentSdkMemberType)
satayev95e9c5b2021-04-29 11:50:26 +010028}
29
30func registerSystemserverClasspathBuildComponents(ctx android.RegistrationContext) {
satayev95e9c5b2021-04-29 11:50:26 +010031 ctx.RegisterModuleType("platform_systemserverclasspath", platformSystemServerClasspathFactory)
satayevaa86bac2021-05-13 19:01:52 +010032 ctx.RegisterModuleType("systemserverclasspath_fragment", systemServerClasspathFactory)
Jiakai Zhangc9864272021-09-26 03:52:19 +000033 ctx.RegisterModuleType("prebuilt_systemserverclasspath_fragment", prebuiltSystemServerClasspathModuleFactory)
satayev95e9c5b2021-04-29 11:50:26 +010034}
35
Paul Duffin4e7d1c42022-05-13 13:12:19 +000036var SystemServerClasspathFragmentSdkMemberType = &systemServerClasspathFragmentMemberType{
37 SdkMemberTypeBase: android.SdkMemberTypeBase{
38 PropertyName: "systemserverclasspath_fragments",
39 SupportsSdk: true,
40
41 // Support for adding systemserverclasspath_fragments to the sdk snapshot was only added in
42 // Tiramisu.
43 SupportedBuildReleaseSpecification: "Tiramisu+",
44 },
45}
46
satayev95e9c5b2021-04-29 11:50:26 +010047type platformSystemServerClasspathModule struct {
48 android.ModuleBase
49
50 ClasspathFragmentBase
51}
52
53func platformSystemServerClasspathFactory() android.Module {
54 m := &platformSystemServerClasspathModule{}
55 initClasspathFragment(m, SYSTEMSERVERCLASSPATH)
56 android.InitAndroidArchModule(m, android.DeviceSupported, android.MultilibCommon)
57 return m
58}
59
satayevaa86bac2021-05-13 19:01:52 +010060func (p *platformSystemServerClasspathModule) AndroidMkEntries() (entries []android.AndroidMkEntries) {
61 return p.classpathFragmentBase().androidMkEntries()
satayev95e9c5b2021-04-29 11:50:26 +010062}
63
satayevaa86bac2021-05-13 19:01:52 +010064func (p *platformSystemServerClasspathModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
satayevb3090502021-06-15 17:49:10 +010065 configuredJars := p.configuredJars(ctx)
66 classpathJars := configuredJarListToClasspathJars(ctx, configuredJars, p.classpathType)
Jiakai Zhangcee9e192021-10-29 19:46:45 +000067 standaloneConfiguredJars := p.standaloneConfiguredJars(ctx)
68 standaloneClasspathJars := configuredJarListToClasspathJars(ctx, standaloneConfiguredJars, STANDALONE_SYSTEMSERVER_JARS)
Jiakai Zhang389a6472021-12-14 18:54:06 +000069 configuredJars = configuredJars.AppendList(&standaloneConfiguredJars)
Jiakai Zhangcee9e192021-10-29 19:46:45 +000070 classpathJars = append(classpathJars, standaloneClasspathJars...)
satayevb3090502021-06-15 17:49:10 +010071 p.classpathFragmentBase().generateClasspathProtoBuildActions(ctx, configuredJars, classpathJars)
satayev013485b2021-05-06 23:38:10 +010072}
73
satayev142ed272021-06-15 16:21:17 +010074func (p *platformSystemServerClasspathModule) configuredJars(ctx android.ModuleContext) android.ConfiguredJarList {
satayevb3090502021-06-15 17:49:10 +010075 // TODO(satayev): include any apex jars that don't populate their classpath proto config.
76 return dexpreopt.GetGlobalConfig(ctx).SystemServerJars
satayev95e9c5b2021-04-29 11:50:26 +010077}
satayevaa86bac2021-05-13 19:01:52 +010078
Jiakai Zhangcee9e192021-10-29 19:46:45 +000079func (p *platformSystemServerClasspathModule) standaloneConfiguredJars(ctx android.ModuleContext) android.ConfiguredJarList {
80 return dexpreopt.GetGlobalConfig(ctx).StandaloneSystemServerJars
81}
82
satayev333a1732021-05-17 21:35:26 +010083type SystemServerClasspathModule struct {
satayevaa86bac2021-05-13 19:01:52 +010084 android.ModuleBase
satayev333a1732021-05-17 21:35:26 +010085 android.ApexModuleBase
satayevaa86bac2021-05-13 19:01:52 +010086
87 ClasspathFragmentBase
satayev9366a052021-05-17 21:13:44 +010088
89 properties systemServerClasspathFragmentProperties
braleeb0c1f0c2021-06-07 22:49:13 +080090
91 // Collect the module directory for IDE info in java/jdeps.go.
92 modulePaths []string
satayev9366a052021-05-17 21:13:44 +010093}
94
satayev333a1732021-05-17 21:35:26 +010095func (s *SystemServerClasspathModule) ShouldSupportSdkVersion(ctx android.BaseModuleContext, sdkVersion android.ApiLevel) error {
96 return nil
97}
98
satayev9366a052021-05-17 21:13:44 +010099type systemServerClasspathFragmentProperties struct {
Jiakai Zhangcee9e192021-10-29 19:46:45 +0000100 // List of system_server classpath jars, could be either java_library, or java_sdk_library.
satayev9366a052021-05-17 21:13:44 +0100101 //
102 // The order of this list matters as it is the order that is used in the SYSTEMSERVERCLASSPATH.
103 Contents []string
Jiakai Zhangcee9e192021-10-29 19:46:45 +0000104
105 // List of jars that system_server loads dynamically using separate classloaders.
106 //
107 // The order does not matter.
108 Standalone_contents []string
satayevaa86bac2021-05-13 19:01:52 +0100109}
110
111func systemServerClasspathFactory() android.Module {
satayev333a1732021-05-17 21:35:26 +0100112 m := &SystemServerClasspathModule{}
satayev9366a052021-05-17 21:13:44 +0100113 m.AddProperties(&m.properties)
satayev333a1732021-05-17 21:35:26 +0100114 android.InitApexModule(m)
satayevaa86bac2021-05-13 19:01:52 +0100115 initClasspathFragment(m, SYSTEMSERVERCLASSPATH)
116 android.InitAndroidArchModule(m, android.DeviceSupported, android.MultilibCommon)
117 return m
118}
119
satayev333a1732021-05-17 21:35:26 +0100120func (s *SystemServerClasspathModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Jiakai Zhangcee9e192021-10-29 19:46:45 +0000121 if len(s.properties.Contents) == 0 && len(s.properties.Standalone_contents) == 0 {
122 ctx.PropertyErrorf("contents", "Either contents or standalone_contents needs to be non-empty")
satayev9366a052021-05-17 21:13:44 +0100123 }
124
satayevb3090502021-06-15 17:49:10 +0100125 configuredJars := s.configuredJars(ctx)
126 classpathJars := configuredJarListToClasspathJars(ctx, configuredJars, s.classpathType)
Jiakai Zhangcee9e192021-10-29 19:46:45 +0000127 standaloneConfiguredJars := s.standaloneConfiguredJars(ctx)
128 standaloneClasspathJars := configuredJarListToClasspathJars(ctx, standaloneConfiguredJars, STANDALONE_SYSTEMSERVER_JARS)
Jiakai Zhang389a6472021-12-14 18:54:06 +0000129 configuredJars = configuredJars.AppendList(&standaloneConfiguredJars)
Jiakai Zhangcee9e192021-10-29 19:46:45 +0000130 classpathJars = append(classpathJars, standaloneClasspathJars...)
satayevb3090502021-06-15 17:49:10 +0100131 s.classpathFragmentBase().generateClasspathProtoBuildActions(ctx, configuredJars, classpathJars)
braleeb0c1f0c2021-06-07 22:49:13 +0800132
133 // Collect the module directory for IDE info in java/jdeps.go.
134 s.modulePaths = append(s.modulePaths, ctx.ModuleDir())
satayevaa86bac2021-05-13 19:01:52 +0100135}
136
satayev142ed272021-06-15 16:21:17 +0100137func (s *SystemServerClasspathModule) configuredJars(ctx android.ModuleContext) android.ConfiguredJarList {
satayev703c67a2021-05-20 21:33:41 +0100138 global := dexpreopt.GetGlobalConfig(ctx)
139
satayevd604b212021-07-21 14:23:52 +0100140 possibleUpdatableModules := gatherPossibleApexModuleNamesAndStems(ctx, s.properties.Contents, systemServerClasspathFragmentContentDepTag)
satayevd34eb0c2021-08-06 13:20:28 +0100141 jars, unknown := global.ApexSystemServerJars.Filter(possibleUpdatableModules)
142 // TODO(satayev): remove geotz ssc_fragment, since geotz is not part of SSCP anymore.
143 _, unknown = android.RemoveFromList("geotz", unknown)
Keun young Parkd64ab232021-10-18 08:42:23 -0700144 // This module only exists in car products.
145 // So ignore it even if it is not in PRODUCT_APEX_SYSTEM_SERVER_JARS.
146 // TODO(b/203233647): Add better mechanism to make it optional.
147 _, unknown = android.RemoveFromList("car-frameworks-service-module", unknown)
Samiul Islam7b385c52021-10-11 22:47:13 +0100148
Alan Stokesbcd567e2021-11-12 15:21:43 +0000149 // This module is optional, so it is not present in all products.
150 // (See PRODUCT_ISOLATED_COMPILATION_ENABLED.)
151 // So ignore it even if it is not in PRODUCT_APEX_SYSTEM_SERVER_JARS.
152 // TODO(b/203233647): Add better mechanism to make it optional.
153 _, unknown = android.RemoveFromList("service-compos", unknown)
154
Samiul Islam7b385c52021-10-11 22:47:13 +0100155 // TODO(satayev): for apex_test we want to include all contents unconditionally to classpaths
156 // config. However, any test specific jars would not be present in ApexSystemServerJars. Instead,
157 // we should check if we are creating a config for apex_test via ApexInfo and amend the values.
158 // This is an exception to support end-to-end test for ApexdUnitTests, until such support exists.
159 if android.InList("test_service-apexd", possibleUpdatableModules) {
160 jars = jars.Append("com.android.apex.test_package", "test_service-apexd")
Paul Duffin458a15b2022-11-25 12:18:24 +0000161 } else if global.ApexSystemServerJars.Len() > 0 && len(unknown) > 0 {
Samiul Islam7b385c52021-10-11 22:47:13 +0100162 // For non test apexes, make sure that all contents are actually declared in make.
Ulya Trafimoviche5b2b492021-10-04 15:42:53 +0100163 ctx.ModuleErrorf("%s in contents must also be declared in PRODUCT_APEX_SYSTEM_SERVER_JARS", unknown)
satayevd34eb0c2021-08-06 13:20:28 +0100164 }
165
166 return jars
satayevaa86bac2021-05-13 19:01:52 +0100167}
satayev9366a052021-05-17 21:13:44 +0100168
Jiakai Zhangcee9e192021-10-29 19:46:45 +0000169func (s *SystemServerClasspathModule) standaloneConfiguredJars(ctx android.ModuleContext) android.ConfiguredJarList {
170 global := dexpreopt.GetGlobalConfig(ctx)
171
172 possibleUpdatableModules := gatherPossibleApexModuleNamesAndStems(ctx, s.properties.Standalone_contents, systemServerClasspathFragmentContentDepTag)
173 jars, _ := global.ApexStandaloneSystemServerJars.Filter(possibleUpdatableModules)
174
175 // TODO(jiakaiz): add a check to ensure that the contents are declared in make.
176
177 return jars
178}
179
satayev9366a052021-05-17 21:13:44 +0100180type systemServerClasspathFragmentContentDependencyTag struct {
181 blueprint.BaseDependencyTag
182}
183
Paul Duffin25322e42021-09-07 14:52:48 +0100184// The systemserverclasspath_fragment contents must never depend on prebuilts.
185func (systemServerClasspathFragmentContentDependencyTag) ReplaceSourceWithPrebuilt() bool {
186 return false
187}
188
Jiakai Zhanga8d86602021-09-26 09:02:17 +0000189// SdkMemberType causes dependencies added with this tag to be automatically added to the sdk as if
190// they were specified using java_systemserver_libs or java_sdk_libs.
191func (b systemServerClasspathFragmentContentDependencyTag) SdkMemberType(child android.Module) android.SdkMemberType {
192 // If the module is a java_sdk_library then treat it as if it was specified in the java_sdk_libs
193 // property, otherwise treat if it was specified in the java_systemserver_libs property.
194 if javaSdkLibrarySdkMemberType.IsInstance(child) {
195 return javaSdkLibrarySdkMemberType
196 }
197
198 return javaSystemserverLibsSdkMemberType
199}
200
201func (b systemServerClasspathFragmentContentDependencyTag) ExportMember() bool {
202 return true
203}
204
Colin Crossc33e5212021-05-25 18:16:02 -0700205// Contents of system server fragments in an apex are considered to be directly in the apex, as if
206// they were listed in java_libs.
207func (systemServerClasspathFragmentContentDependencyTag) CopyDirectlyInAnyApex() {}
208
Jiakai Zhang774dd302021-09-26 03:54:25 +0000209// Contents of system server fragments require files from prebuilt apex files.
210func (systemServerClasspathFragmentContentDependencyTag) RequiresFilesFromPrebuiltApex() {}
211
Paul Duffin25322e42021-09-07 14:52:48 +0100212var _ android.ReplaceSourceWithPrebuilt = systemServerClasspathFragmentContentDepTag
Jiakai Zhanga8d86602021-09-26 09:02:17 +0000213var _ android.SdkMemberDependencyTag = systemServerClasspathFragmentContentDepTag
Colin Crossc33e5212021-05-25 18:16:02 -0700214var _ android.CopyDirectlyInAnyApexTag = systemServerClasspathFragmentContentDepTag
Jiakai Zhang774dd302021-09-26 03:54:25 +0000215var _ android.RequiresFilesFromPrebuiltApexTag = systemServerClasspathFragmentContentDepTag
Colin Crossc33e5212021-05-25 18:16:02 -0700216
satayev9366a052021-05-17 21:13:44 +0100217// The tag used for the dependency between the systemserverclasspath_fragment module and its contents.
218var systemServerClasspathFragmentContentDepTag = systemServerClasspathFragmentContentDependencyTag{}
219
220func IsSystemServerClasspathFragmentContentDepTag(tag blueprint.DependencyTag) bool {
221 return tag == systemServerClasspathFragmentContentDepTag
222}
223
satayev333a1732021-05-17 21:35:26 +0100224func (s *SystemServerClasspathModule) ComponentDepsMutator(ctx android.BottomUpMutatorContext) {
satayev9366a052021-05-17 21:13:44 +0100225 module := ctx.Module()
Jiakai Zhangc9864272021-09-26 03:52:19 +0000226 _, isSourceModule := module.(*SystemServerClasspathModule)
Jiakai Zhangcee9e192021-10-29 19:46:45 +0000227 var deps []string
228 deps = append(deps, s.properties.Contents...)
229 deps = append(deps, s.properties.Standalone_contents...)
satayev9366a052021-05-17 21:13:44 +0100230
Jiakai Zhangcee9e192021-10-29 19:46:45 +0000231 for _, name := range deps {
Jiakai Zhangc9864272021-09-26 03:52:19 +0000232 // A systemserverclasspath_fragment must depend only on other source modules, while the
233 // prebuilt_systemserverclasspath_fragment_fragment must only depend on other prebuilt modules.
234 if !isSourceModule {
235 name = android.PrebuiltNameFromSource(name)
236 }
satayev9366a052021-05-17 21:13:44 +0100237 ctx.AddDependency(module, systemServerClasspathFragmentContentDepTag, name)
238 }
239}
braleeb0c1f0c2021-06-07 22:49:13 +0800240
241// Collect information for opening IDE project files in java/jdeps.go.
242func (s *SystemServerClasspathModule) IDEInfo(dpInfo *android.IdeInfo) {
243 dpInfo.Deps = append(dpInfo.Deps, s.properties.Contents...)
Jiakai Zhangcee9e192021-10-29 19:46:45 +0000244 dpInfo.Deps = append(dpInfo.Deps, s.properties.Standalone_contents...)
braleeb0c1f0c2021-06-07 22:49:13 +0800245 dpInfo.Paths = append(dpInfo.Paths, s.modulePaths...)
246}
Jiakai Zhangc9864272021-09-26 03:52:19 +0000247
Jiakai Zhanga8d86602021-09-26 09:02:17 +0000248type systemServerClasspathFragmentMemberType struct {
249 android.SdkMemberTypeBase
250}
251
252func (s *systemServerClasspathFragmentMemberType) AddDependencies(ctx android.SdkDependencyContext, dependencyTag blueprint.DependencyTag, names []string) {
253 ctx.AddVariationDependencies(nil, dependencyTag, names...)
254}
255
256func (s *systemServerClasspathFragmentMemberType) IsInstance(module android.Module) bool {
257 _, ok := module.(*SystemServerClasspathModule)
258 return ok
259}
260
261func (s *systemServerClasspathFragmentMemberType) AddPrebuiltModule(ctx android.SdkMemberContext, member android.SdkMember) android.BpModule {
262 return ctx.SnapshotBuilder().AddPrebuiltModule(member, "prebuilt_systemserverclasspath_fragment")
263}
264
265func (s *systemServerClasspathFragmentMemberType) CreateVariantPropertiesStruct() android.SdkMemberProperties {
266 return &systemServerClasspathFragmentSdkMemberProperties{}
267}
268
269type systemServerClasspathFragmentSdkMemberProperties struct {
270 android.SdkMemberPropertiesBase
271
Jiakai Zhangcee9e192021-10-29 19:46:45 +0000272 // List of system_server classpath jars, could be either java_library, or java_sdk_library.
273 //
274 // The order of this list matters as it is the order that is used in the SYSTEMSERVERCLASSPATH.
Jiakai Zhanga8d86602021-09-26 09:02:17 +0000275 Contents []string
Jiakai Zhangcee9e192021-10-29 19:46:45 +0000276
277 // List of jars that system_server loads dynamically using separate classloaders.
278 //
279 // The order does not matter.
280 Standalone_contents []string
Jiakai Zhanga8d86602021-09-26 09:02:17 +0000281}
282
283func (s *systemServerClasspathFragmentSdkMemberProperties) PopulateFromVariant(ctx android.SdkMemberContext, variant android.Module) {
284 module := variant.(*SystemServerClasspathModule)
285
286 s.Contents = module.properties.Contents
Jiakai Zhangcee9e192021-10-29 19:46:45 +0000287 s.Standalone_contents = module.properties.Standalone_contents
Jiakai Zhanga8d86602021-09-26 09:02:17 +0000288}
289
290func (s *systemServerClasspathFragmentSdkMemberProperties) AddToPropertySet(ctx android.SdkMemberContext, propertySet android.BpPropertySet) {
291 builder := ctx.SnapshotBuilder()
292 requiredMemberDependency := builder.SdkMemberReferencePropertyTag(true)
293
294 if len(s.Contents) > 0 {
295 propertySet.AddPropertyWithTag("contents", s.Contents, requiredMemberDependency)
296 }
Jiakai Zhangcee9e192021-10-29 19:46:45 +0000297
298 if len(s.Standalone_contents) > 0 {
299 propertySet.AddPropertyWithTag("standalone_contents", s.Standalone_contents, requiredMemberDependency)
300 }
Jiakai Zhanga8d86602021-09-26 09:02:17 +0000301}
302
303var _ android.SdkMemberType = (*systemServerClasspathFragmentMemberType)(nil)
304
Jiakai Zhangc9864272021-09-26 03:52:19 +0000305// A prebuilt version of the systemserverclasspath_fragment module.
306type prebuiltSystemServerClasspathModule struct {
307 SystemServerClasspathModule
308 prebuilt android.Prebuilt
309}
310
311func (module *prebuiltSystemServerClasspathModule) Prebuilt() *android.Prebuilt {
312 return &module.prebuilt
313}
314
315func (module *prebuiltSystemServerClasspathModule) Name() string {
316 return module.prebuilt.Name(module.ModuleBase.Name())
317}
318
Jiakai Zhang774dd302021-09-26 03:54:25 +0000319func (module *prebuiltSystemServerClasspathModule) RequiredFilesFromPrebuiltApex(ctx android.BaseModuleContext) []string {
320 return nil
321}
322
323var _ android.RequiredFilesFromPrebuiltApex = (*prebuiltSystemServerClasspathModule)(nil)
324
Jiakai Zhangc9864272021-09-26 03:52:19 +0000325func prebuiltSystemServerClasspathModuleFactory() android.Module {
326 m := &prebuiltSystemServerClasspathModule{}
327 m.AddProperties(&m.properties)
328 // This doesn't actually have any prebuilt files of its own so pass a placeholder for the srcs
329 // array.
330 android.InitPrebuiltModule(m, &[]string{"placeholder"})
331 android.InitApexModule(m)
332 android.InitAndroidArchModule(m, android.DeviceSupported, android.MultilibCommon)
333 return m
334}