blob: 30dd55fa946ec967acf89c2e44e6cbd6adf14c1e [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
90}
91
satayev333a1732021-05-17 21:35:26 +010092func (s *SystemServerClasspathModule) ShouldSupportSdkVersion(ctx android.BaseModuleContext, sdkVersion android.ApiLevel) error {
93 return nil
94}
95
satayev9366a052021-05-17 21:13:44 +010096type systemServerClasspathFragmentProperties struct {
Jiakai Zhangcee9e192021-10-29 19:46:45 +000097 // List of system_server classpath jars, could be either java_library, or java_sdk_library.
satayev9366a052021-05-17 21:13:44 +010098 //
99 // The order of this list matters as it is the order that is used in the SYSTEMSERVERCLASSPATH.
100 Contents []string
Jiakai Zhangcee9e192021-10-29 19:46:45 +0000101
102 // List of jars that system_server loads dynamically using separate classloaders.
103 //
104 // The order does not matter.
105 Standalone_contents []string
satayevaa86bac2021-05-13 19:01:52 +0100106}
107
108func systemServerClasspathFactory() android.Module {
satayev333a1732021-05-17 21:35:26 +0100109 m := &SystemServerClasspathModule{}
satayev9366a052021-05-17 21:13:44 +0100110 m.AddProperties(&m.properties)
satayev333a1732021-05-17 21:35:26 +0100111 android.InitApexModule(m)
satayevaa86bac2021-05-13 19:01:52 +0100112 initClasspathFragment(m, SYSTEMSERVERCLASSPATH)
113 android.InitAndroidArchModule(m, android.DeviceSupported, android.MultilibCommon)
114 return m
115}
116
satayev333a1732021-05-17 21:35:26 +0100117func (s *SystemServerClasspathModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Jiakai Zhangcee9e192021-10-29 19:46:45 +0000118 if len(s.properties.Contents) == 0 && len(s.properties.Standalone_contents) == 0 {
119 ctx.PropertyErrorf("contents", "Either contents or standalone_contents needs to be non-empty")
satayev9366a052021-05-17 21:13:44 +0100120 }
121
satayevb3090502021-06-15 17:49:10 +0100122 configuredJars := s.configuredJars(ctx)
123 classpathJars := configuredJarListToClasspathJars(ctx, configuredJars, s.classpathType)
Jiakai Zhangcee9e192021-10-29 19:46:45 +0000124 standaloneConfiguredJars := s.standaloneConfiguredJars(ctx)
125 standaloneClasspathJars := configuredJarListToClasspathJars(ctx, standaloneConfiguredJars, STANDALONE_SYSTEMSERVER_JARS)
Jiakai Zhang389a6472021-12-14 18:54:06 +0000126 configuredJars = configuredJars.AppendList(&standaloneConfiguredJars)
Jiakai Zhangcee9e192021-10-29 19:46:45 +0000127 classpathJars = append(classpathJars, standaloneClasspathJars...)
satayevb3090502021-06-15 17:49:10 +0100128 s.classpathFragmentBase().generateClasspathProtoBuildActions(ctx, configuredJars, classpathJars)
satayevaa86bac2021-05-13 19:01:52 +0100129}
130
satayev142ed272021-06-15 16:21:17 +0100131func (s *SystemServerClasspathModule) configuredJars(ctx android.ModuleContext) android.ConfiguredJarList {
satayev703c67a2021-05-20 21:33:41 +0100132 global := dexpreopt.GetGlobalConfig(ctx)
133
satayevd604b212021-07-21 14:23:52 +0100134 possibleUpdatableModules := gatherPossibleApexModuleNamesAndStems(ctx, s.properties.Contents, systemServerClasspathFragmentContentDepTag)
satayevd34eb0c2021-08-06 13:20:28 +0100135 jars, unknown := global.ApexSystemServerJars.Filter(possibleUpdatableModules)
136 // TODO(satayev): remove geotz ssc_fragment, since geotz is not part of SSCP anymore.
137 _, unknown = android.RemoveFromList("geotz", unknown)
Keun young Parkd64ab232021-10-18 08:42:23 -0700138 // This module only exists in car products.
139 // So ignore it even if it is not in PRODUCT_APEX_SYSTEM_SERVER_JARS.
140 // TODO(b/203233647): Add better mechanism to make it optional.
141 _, unknown = android.RemoveFromList("car-frameworks-service-module", unknown)
Samiul Islam7b385c52021-10-11 22:47:13 +0100142
Alan Stokesbcd567e2021-11-12 15:21:43 +0000143 // This module is optional, so it is not present in all products.
144 // (See PRODUCT_ISOLATED_COMPILATION_ENABLED.)
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("service-compos", unknown)
148
Samiul Islam7b385c52021-10-11 22:47:13 +0100149 // TODO(satayev): for apex_test we want to include all contents unconditionally to classpaths
150 // config. However, any test specific jars would not be present in ApexSystemServerJars. Instead,
151 // we should check if we are creating a config for apex_test via ApexInfo and amend the values.
152 // This is an exception to support end-to-end test for ApexdUnitTests, until such support exists.
153 if android.InList("test_service-apexd", possibleUpdatableModules) {
154 jars = jars.Append("com.android.apex.test_package", "test_service-apexd")
Paul Duffin458a15b2022-11-25 12:18:24 +0000155 } else if global.ApexSystemServerJars.Len() > 0 && len(unknown) > 0 {
Samiul Islam7b385c52021-10-11 22:47:13 +0100156 // For non test apexes, make sure that all contents are actually declared in make.
Ulya Trafimoviche5b2b492021-10-04 15:42:53 +0100157 ctx.ModuleErrorf("%s in contents must also be declared in PRODUCT_APEX_SYSTEM_SERVER_JARS", unknown)
satayevd34eb0c2021-08-06 13:20:28 +0100158 }
159
160 return jars
satayevaa86bac2021-05-13 19:01:52 +0100161}
satayev9366a052021-05-17 21:13:44 +0100162
Jiakai Zhangcee9e192021-10-29 19:46:45 +0000163func (s *SystemServerClasspathModule) standaloneConfiguredJars(ctx android.ModuleContext) android.ConfiguredJarList {
164 global := dexpreopt.GetGlobalConfig(ctx)
165
166 possibleUpdatableModules := gatherPossibleApexModuleNamesAndStems(ctx, s.properties.Standalone_contents, systemServerClasspathFragmentContentDepTag)
167 jars, _ := global.ApexStandaloneSystemServerJars.Filter(possibleUpdatableModules)
168
169 // TODO(jiakaiz): add a check to ensure that the contents are declared in make.
170
171 return jars
172}
173
satayev9366a052021-05-17 21:13:44 +0100174type systemServerClasspathFragmentContentDependencyTag struct {
175 blueprint.BaseDependencyTag
176}
177
Paul Duffin25322e42021-09-07 14:52:48 +0100178// The systemserverclasspath_fragment contents must never depend on prebuilts.
179func (systemServerClasspathFragmentContentDependencyTag) ReplaceSourceWithPrebuilt() bool {
180 return false
181}
182
Jiakai Zhanga8d86602021-09-26 09:02:17 +0000183// SdkMemberType causes dependencies added with this tag to be automatically added to the sdk as if
184// they were specified using java_systemserver_libs or java_sdk_libs.
185func (b systemServerClasspathFragmentContentDependencyTag) SdkMemberType(child android.Module) android.SdkMemberType {
186 // If the module is a java_sdk_library then treat it as if it was specified in the java_sdk_libs
187 // property, otherwise treat if it was specified in the java_systemserver_libs property.
188 if javaSdkLibrarySdkMemberType.IsInstance(child) {
189 return javaSdkLibrarySdkMemberType
190 }
191
192 return javaSystemserverLibsSdkMemberType
193}
194
195func (b systemServerClasspathFragmentContentDependencyTag) ExportMember() bool {
196 return true
197}
198
Colin Crossc33e5212021-05-25 18:16:02 -0700199// Contents of system server fragments in an apex are considered to be directly in the apex, as if
200// they were listed in java_libs.
201func (systemServerClasspathFragmentContentDependencyTag) CopyDirectlyInAnyApex() {}
202
Jiakai Zhang774dd302021-09-26 03:54:25 +0000203// Contents of system server fragments require files from prebuilt apex files.
204func (systemServerClasspathFragmentContentDependencyTag) RequiresFilesFromPrebuiltApex() {}
205
Paul Duffin25322e42021-09-07 14:52:48 +0100206var _ android.ReplaceSourceWithPrebuilt = systemServerClasspathFragmentContentDepTag
Jiakai Zhanga8d86602021-09-26 09:02:17 +0000207var _ android.SdkMemberDependencyTag = systemServerClasspathFragmentContentDepTag
Colin Crossc33e5212021-05-25 18:16:02 -0700208var _ android.CopyDirectlyInAnyApexTag = systemServerClasspathFragmentContentDepTag
Jiakai Zhang774dd302021-09-26 03:54:25 +0000209var _ android.RequiresFilesFromPrebuiltApexTag = systemServerClasspathFragmentContentDepTag
Colin Crossc33e5212021-05-25 18:16:02 -0700210
satayev9366a052021-05-17 21:13:44 +0100211// The tag used for the dependency between the systemserverclasspath_fragment module and its contents.
212var systemServerClasspathFragmentContentDepTag = systemServerClasspathFragmentContentDependencyTag{}
213
214func IsSystemServerClasspathFragmentContentDepTag(tag blueprint.DependencyTag) bool {
215 return tag == systemServerClasspathFragmentContentDepTag
216}
217
satayev333a1732021-05-17 21:35:26 +0100218func (s *SystemServerClasspathModule) ComponentDepsMutator(ctx android.BottomUpMutatorContext) {
satayev9366a052021-05-17 21:13:44 +0100219 module := ctx.Module()
Jiakai Zhangc9864272021-09-26 03:52:19 +0000220 _, isSourceModule := module.(*SystemServerClasspathModule)
Jiakai Zhangcee9e192021-10-29 19:46:45 +0000221 var deps []string
222 deps = append(deps, s.properties.Contents...)
223 deps = append(deps, s.properties.Standalone_contents...)
satayev9366a052021-05-17 21:13:44 +0100224
Jiakai Zhangcee9e192021-10-29 19:46:45 +0000225 for _, name := range deps {
Jiakai Zhangc9864272021-09-26 03:52:19 +0000226 // A systemserverclasspath_fragment must depend only on other source modules, while the
227 // prebuilt_systemserverclasspath_fragment_fragment must only depend on other prebuilt modules.
228 if !isSourceModule {
229 name = android.PrebuiltNameFromSource(name)
230 }
satayev9366a052021-05-17 21:13:44 +0100231 ctx.AddDependency(module, systemServerClasspathFragmentContentDepTag, name)
232 }
233}
braleeb0c1f0c2021-06-07 22:49:13 +0800234
235// Collect information for opening IDE project files in java/jdeps.go.
236func (s *SystemServerClasspathModule) IDEInfo(dpInfo *android.IdeInfo) {
237 dpInfo.Deps = append(dpInfo.Deps, s.properties.Contents...)
Jiakai Zhangcee9e192021-10-29 19:46:45 +0000238 dpInfo.Deps = append(dpInfo.Deps, s.properties.Standalone_contents...)
braleeb0c1f0c2021-06-07 22:49:13 +0800239}
Jiakai Zhangc9864272021-09-26 03:52:19 +0000240
Jiakai Zhanga8d86602021-09-26 09:02:17 +0000241type systemServerClasspathFragmentMemberType struct {
242 android.SdkMemberTypeBase
243}
244
245func (s *systemServerClasspathFragmentMemberType) AddDependencies(ctx android.SdkDependencyContext, dependencyTag blueprint.DependencyTag, names []string) {
246 ctx.AddVariationDependencies(nil, dependencyTag, names...)
247}
248
249func (s *systemServerClasspathFragmentMemberType) IsInstance(module android.Module) bool {
250 _, ok := module.(*SystemServerClasspathModule)
251 return ok
252}
253
254func (s *systemServerClasspathFragmentMemberType) AddPrebuiltModule(ctx android.SdkMemberContext, member android.SdkMember) android.BpModule {
255 return ctx.SnapshotBuilder().AddPrebuiltModule(member, "prebuilt_systemserverclasspath_fragment")
256}
257
258func (s *systemServerClasspathFragmentMemberType) CreateVariantPropertiesStruct() android.SdkMemberProperties {
259 return &systemServerClasspathFragmentSdkMemberProperties{}
260}
261
262type systemServerClasspathFragmentSdkMemberProperties struct {
263 android.SdkMemberPropertiesBase
264
Jiakai Zhangcee9e192021-10-29 19:46:45 +0000265 // List of system_server classpath jars, could be either java_library, or java_sdk_library.
266 //
267 // The order of this list matters as it is the order that is used in the SYSTEMSERVERCLASSPATH.
Jiakai Zhanga8d86602021-09-26 09:02:17 +0000268 Contents []string
Jiakai Zhangcee9e192021-10-29 19:46:45 +0000269
270 // List of jars that system_server loads dynamically using separate classloaders.
271 //
272 // The order does not matter.
273 Standalone_contents []string
Jiakai Zhanga8d86602021-09-26 09:02:17 +0000274}
275
276func (s *systemServerClasspathFragmentSdkMemberProperties) PopulateFromVariant(ctx android.SdkMemberContext, variant android.Module) {
277 module := variant.(*SystemServerClasspathModule)
278
279 s.Contents = module.properties.Contents
Jiakai Zhangcee9e192021-10-29 19:46:45 +0000280 s.Standalone_contents = module.properties.Standalone_contents
Jiakai Zhanga8d86602021-09-26 09:02:17 +0000281}
282
283func (s *systemServerClasspathFragmentSdkMemberProperties) AddToPropertySet(ctx android.SdkMemberContext, propertySet android.BpPropertySet) {
284 builder := ctx.SnapshotBuilder()
285 requiredMemberDependency := builder.SdkMemberReferencePropertyTag(true)
286
287 if len(s.Contents) > 0 {
288 propertySet.AddPropertyWithTag("contents", s.Contents, requiredMemberDependency)
289 }
Jiakai Zhangcee9e192021-10-29 19:46:45 +0000290
291 if len(s.Standalone_contents) > 0 {
292 propertySet.AddPropertyWithTag("standalone_contents", s.Standalone_contents, requiredMemberDependency)
293 }
Jiakai Zhanga8d86602021-09-26 09:02:17 +0000294}
295
296var _ android.SdkMemberType = (*systemServerClasspathFragmentMemberType)(nil)
297
Jiakai Zhangc9864272021-09-26 03:52:19 +0000298// A prebuilt version of the systemserverclasspath_fragment module.
299type prebuiltSystemServerClasspathModule struct {
300 SystemServerClasspathModule
301 prebuilt android.Prebuilt
302}
303
304func (module *prebuiltSystemServerClasspathModule) Prebuilt() *android.Prebuilt {
305 return &module.prebuilt
306}
307
308func (module *prebuiltSystemServerClasspathModule) Name() string {
309 return module.prebuilt.Name(module.ModuleBase.Name())
310}
311
Jiakai Zhang774dd302021-09-26 03:54:25 +0000312func (module *prebuiltSystemServerClasspathModule) RequiredFilesFromPrebuiltApex(ctx android.BaseModuleContext) []string {
313 return nil
314}
315
316var _ android.RequiredFilesFromPrebuiltApex = (*prebuiltSystemServerClasspathModule)(nil)
317
Jiakai Zhangc9864272021-09-26 03:52:19 +0000318func prebuiltSystemServerClasspathModuleFactory() android.Module {
319 m := &prebuiltSystemServerClasspathModule{}
320 m.AddProperties(&m.properties)
321 // This doesn't actually have any prebuilt files of its own so pass a placeholder for the srcs
322 // array.
323 android.InitPrebuiltModule(m, &[]string{"placeholder"})
324 android.InitApexModule(m)
325 android.InitAndroidArchModule(m, android.DeviceSupported, android.MultilibCommon)
326 return m
327}