blob: bad2cf1cf61de9615a4d9da528d6b20250e9844d [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)
Inseob Kimdd532492024-04-30 17:22:58 +090072 p.classpathFragmentBase().installClasspathProto(ctx)
satayev013485b2021-05-06 23:38:10 +010073}
74
satayev142ed272021-06-15 16:21:17 +010075func (p *platformSystemServerClasspathModule) configuredJars(ctx android.ModuleContext) android.ConfiguredJarList {
satayevb3090502021-06-15 17:49:10 +010076 // TODO(satayev): include any apex jars that don't populate their classpath proto config.
77 return dexpreopt.GetGlobalConfig(ctx).SystemServerJars
satayev95e9c5b2021-04-29 11:50:26 +010078}
satayevaa86bac2021-05-13 19:01:52 +010079
Jiakai Zhangcee9e192021-10-29 19:46:45 +000080func (p *platformSystemServerClasspathModule) standaloneConfiguredJars(ctx android.ModuleContext) android.ConfiguredJarList {
81 return dexpreopt.GetGlobalConfig(ctx).StandaloneSystemServerJars
82}
83
satayev333a1732021-05-17 21:35:26 +010084type SystemServerClasspathModule struct {
satayevaa86bac2021-05-13 19:01:52 +010085 android.ModuleBase
satayev333a1732021-05-17 21:35:26 +010086 android.ApexModuleBase
satayevaa86bac2021-05-13 19:01:52 +010087
88 ClasspathFragmentBase
satayev9366a052021-05-17 21:13:44 +010089
90 properties systemServerClasspathFragmentProperties
91}
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)
satayevaa86bac2021-05-13 19:01:52 +0100113 initClasspathFragment(m, SYSTEMSERVERCLASSPATH)
114 android.InitAndroidArchModule(m, android.DeviceSupported, android.MultilibCommon)
115 return m
116}
117
satayev333a1732021-05-17 21:35:26 +0100118func (s *SystemServerClasspathModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Jiakai Zhangcee9e192021-10-29 19:46:45 +0000119 if len(s.properties.Contents) == 0 && len(s.properties.Standalone_contents) == 0 {
120 ctx.PropertyErrorf("contents", "Either contents or standalone_contents needs to be non-empty")
satayev9366a052021-05-17 21:13:44 +0100121 }
122
satayevb3090502021-06-15 17:49:10 +0100123 configuredJars := s.configuredJars(ctx)
124 classpathJars := configuredJarListToClasspathJars(ctx, configuredJars, s.classpathType)
Jiakai Zhangcee9e192021-10-29 19:46:45 +0000125 standaloneConfiguredJars := s.standaloneConfiguredJars(ctx)
126 standaloneClasspathJars := configuredJarListToClasspathJars(ctx, standaloneConfiguredJars, STANDALONE_SYSTEMSERVER_JARS)
Jiakai Zhang389a6472021-12-14 18:54:06 +0000127 configuredJars = configuredJars.AppendList(&standaloneConfiguredJars)
Jiakai Zhangcee9e192021-10-29 19:46:45 +0000128 classpathJars = append(classpathJars, standaloneClasspathJars...)
satayevb3090502021-06-15 17:49:10 +0100129 s.classpathFragmentBase().generateClasspathProtoBuildActions(ctx, configuredJars, classpathJars)
satayevaa86bac2021-05-13 19:01:52 +0100130}
131
satayev142ed272021-06-15 16:21:17 +0100132func (s *SystemServerClasspathModule) configuredJars(ctx android.ModuleContext) android.ConfiguredJarList {
satayev703c67a2021-05-20 21:33:41 +0100133 global := dexpreopt.GetGlobalConfig(ctx)
134
satayevd604b212021-07-21 14:23:52 +0100135 possibleUpdatableModules := gatherPossibleApexModuleNamesAndStems(ctx, s.properties.Contents, systemServerClasspathFragmentContentDepTag)
satayevd34eb0c2021-08-06 13:20:28 +0100136 jars, unknown := global.ApexSystemServerJars.Filter(possibleUpdatableModules)
137 // TODO(satayev): remove geotz ssc_fragment, since geotz is not part of SSCP anymore.
138 _, unknown = android.RemoveFromList("geotz", unknown)
Keun young Parkd64ab232021-10-18 08:42:23 -0700139 // This module only exists in car products.
140 // So ignore it even if it is not in PRODUCT_APEX_SYSTEM_SERVER_JARS.
141 // TODO(b/203233647): Add better mechanism to make it optional.
142 _, unknown = android.RemoveFromList("car-frameworks-service-module", unknown)
Samiul Islam7b385c52021-10-11 22:47:13 +0100143
Alan Stokesbcd567e2021-11-12 15:21:43 +0000144 // This module is optional, so it is not present in all products.
145 // (See PRODUCT_ISOLATED_COMPILATION_ENABLED.)
146 // So ignore it even if it is not in PRODUCT_APEX_SYSTEM_SERVER_JARS.
147 // TODO(b/203233647): Add better mechanism to make it optional.
148 _, unknown = android.RemoveFromList("service-compos", unknown)
149
Samiul Islam7b385c52021-10-11 22:47:13 +0100150 // TODO(satayev): for apex_test we want to include all contents unconditionally to classpaths
151 // config. However, any test specific jars would not be present in ApexSystemServerJars. Instead,
152 // we should check if we are creating a config for apex_test via ApexInfo and amend the values.
153 // This is an exception to support end-to-end test for ApexdUnitTests, until such support exists.
154 if android.InList("test_service-apexd", possibleUpdatableModules) {
155 jars = jars.Append("com.android.apex.test_package", "test_service-apexd")
Paul Duffin458a15b2022-11-25 12:18:24 +0000156 } else if global.ApexSystemServerJars.Len() > 0 && len(unknown) > 0 {
Samiul Islam7b385c52021-10-11 22:47:13 +0100157 // For non test apexes, make sure that all contents are actually declared in make.
Ulya Trafimoviche5b2b492021-10-04 15:42:53 +0100158 ctx.ModuleErrorf("%s in contents must also be declared in PRODUCT_APEX_SYSTEM_SERVER_JARS", unknown)
satayevd34eb0c2021-08-06 13:20:28 +0100159 }
160
161 return jars
satayevaa86bac2021-05-13 19:01:52 +0100162}
satayev9366a052021-05-17 21:13:44 +0100163
Jiakai Zhangcee9e192021-10-29 19:46:45 +0000164func (s *SystemServerClasspathModule) standaloneConfiguredJars(ctx android.ModuleContext) android.ConfiguredJarList {
165 global := dexpreopt.GetGlobalConfig(ctx)
166
167 possibleUpdatableModules := gatherPossibleApexModuleNamesAndStems(ctx, s.properties.Standalone_contents, systemServerClasspathFragmentContentDepTag)
168 jars, _ := global.ApexStandaloneSystemServerJars.Filter(possibleUpdatableModules)
169
170 // TODO(jiakaiz): add a check to ensure that the contents are declared in make.
171
172 return jars
173}
174
satayev9366a052021-05-17 21:13:44 +0100175type systemServerClasspathFragmentContentDependencyTag struct {
176 blueprint.BaseDependencyTag
177}
178
Paul Duffin25322e42021-09-07 14:52:48 +0100179// The systemserverclasspath_fragment contents must never depend on prebuilts.
180func (systemServerClasspathFragmentContentDependencyTag) ReplaceSourceWithPrebuilt() bool {
181 return false
182}
183
Jiakai Zhanga8d86602021-09-26 09:02:17 +0000184// SdkMemberType causes dependencies added with this tag to be automatically added to the sdk as if
185// they were specified using java_systemserver_libs or java_sdk_libs.
186func (b systemServerClasspathFragmentContentDependencyTag) SdkMemberType(child android.Module) android.SdkMemberType {
187 // If the module is a java_sdk_library then treat it as if it was specified in the java_sdk_libs
188 // property, otherwise treat if it was specified in the java_systemserver_libs property.
189 if javaSdkLibrarySdkMemberType.IsInstance(child) {
190 return javaSdkLibrarySdkMemberType
191 }
192
Spandan Das159b2642024-03-20 21:22:47 +0000193 return JavaSystemserverLibsSdkMemberType
Jiakai Zhanga8d86602021-09-26 09:02:17 +0000194}
195
196func (b systemServerClasspathFragmentContentDependencyTag) ExportMember() bool {
197 return true
198}
199
Colin Crossc33e5212021-05-25 18:16:02 -0700200// Contents of system server fragments in an apex are considered to be directly in the apex, as if
201// they were listed in java_libs.
202func (systemServerClasspathFragmentContentDependencyTag) CopyDirectlyInAnyApex() {}
203
Jiakai Zhang774dd302021-09-26 03:54:25 +0000204// Contents of system server fragments require files from prebuilt apex files.
205func (systemServerClasspathFragmentContentDependencyTag) RequiresFilesFromPrebuiltApex() {}
206
Paul Duffin25322e42021-09-07 14:52:48 +0100207var _ android.ReplaceSourceWithPrebuilt = systemServerClasspathFragmentContentDepTag
Jiakai Zhanga8d86602021-09-26 09:02:17 +0000208var _ android.SdkMemberDependencyTag = systemServerClasspathFragmentContentDepTag
Colin Crossc33e5212021-05-25 18:16:02 -0700209var _ android.CopyDirectlyInAnyApexTag = systemServerClasspathFragmentContentDepTag
Jiakai Zhang774dd302021-09-26 03:54:25 +0000210var _ android.RequiresFilesFromPrebuiltApexTag = systemServerClasspathFragmentContentDepTag
Colin Crossc33e5212021-05-25 18:16:02 -0700211
satayev9366a052021-05-17 21:13:44 +0100212// The tag used for the dependency between the systemserverclasspath_fragment module and its contents.
213var systemServerClasspathFragmentContentDepTag = systemServerClasspathFragmentContentDependencyTag{}
214
215func IsSystemServerClasspathFragmentContentDepTag(tag blueprint.DependencyTag) bool {
216 return tag == systemServerClasspathFragmentContentDepTag
217}
218
satayev333a1732021-05-17 21:35:26 +0100219func (s *SystemServerClasspathModule) ComponentDepsMutator(ctx android.BottomUpMutatorContext) {
satayev9366a052021-05-17 21:13:44 +0100220 module := ctx.Module()
Jiakai Zhangc9864272021-09-26 03:52:19 +0000221 _, isSourceModule := module.(*SystemServerClasspathModule)
Jiakai Zhangcee9e192021-10-29 19:46:45 +0000222 var deps []string
223 deps = append(deps, s.properties.Contents...)
224 deps = append(deps, s.properties.Standalone_contents...)
satayev9366a052021-05-17 21:13:44 +0100225
Jiakai Zhangcee9e192021-10-29 19:46:45 +0000226 for _, name := range deps {
Jiakai Zhangc9864272021-09-26 03:52:19 +0000227 // A systemserverclasspath_fragment must depend only on other source modules, while the
228 // prebuilt_systemserverclasspath_fragment_fragment must only depend on other prebuilt modules.
229 if !isSourceModule {
230 name = android.PrebuiltNameFromSource(name)
231 }
satayev9366a052021-05-17 21:13:44 +0100232 ctx.AddDependency(module, systemServerClasspathFragmentContentDepTag, name)
233 }
234}
braleeb0c1f0c2021-06-07 22:49:13 +0800235
236// Collect information for opening IDE project files in java/jdeps.go.
237func (s *SystemServerClasspathModule) IDEInfo(dpInfo *android.IdeInfo) {
238 dpInfo.Deps = append(dpInfo.Deps, s.properties.Contents...)
Jiakai Zhangcee9e192021-10-29 19:46:45 +0000239 dpInfo.Deps = append(dpInfo.Deps, s.properties.Standalone_contents...)
braleeb0c1f0c2021-06-07 22:49:13 +0800240}
Jiakai Zhangc9864272021-09-26 03:52:19 +0000241
Jiakai Zhanga8d86602021-09-26 09:02:17 +0000242type systemServerClasspathFragmentMemberType struct {
243 android.SdkMemberTypeBase
244}
245
246func (s *systemServerClasspathFragmentMemberType) AddDependencies(ctx android.SdkDependencyContext, dependencyTag blueprint.DependencyTag, names []string) {
247 ctx.AddVariationDependencies(nil, dependencyTag, names...)
248}
249
250func (s *systemServerClasspathFragmentMemberType) IsInstance(module android.Module) bool {
251 _, ok := module.(*SystemServerClasspathModule)
252 return ok
253}
254
255func (s *systemServerClasspathFragmentMemberType) AddPrebuiltModule(ctx android.SdkMemberContext, member android.SdkMember) android.BpModule {
256 return ctx.SnapshotBuilder().AddPrebuiltModule(member, "prebuilt_systemserverclasspath_fragment")
257}
258
259func (s *systemServerClasspathFragmentMemberType) CreateVariantPropertiesStruct() android.SdkMemberProperties {
260 return &systemServerClasspathFragmentSdkMemberProperties{}
261}
262
263type systemServerClasspathFragmentSdkMemberProperties struct {
264 android.SdkMemberPropertiesBase
265
Jiakai Zhangcee9e192021-10-29 19:46:45 +0000266 // List of system_server classpath jars, could be either java_library, or java_sdk_library.
267 //
268 // The order of this list matters as it is the order that is used in the SYSTEMSERVERCLASSPATH.
Jiakai Zhanga8d86602021-09-26 09:02:17 +0000269 Contents []string
Jiakai Zhangcee9e192021-10-29 19:46:45 +0000270
271 // List of jars that system_server loads dynamically using separate classloaders.
272 //
273 // The order does not matter.
274 Standalone_contents []string
Jiakai Zhanga8d86602021-09-26 09:02:17 +0000275}
276
277func (s *systemServerClasspathFragmentSdkMemberProperties) PopulateFromVariant(ctx android.SdkMemberContext, variant android.Module) {
278 module := variant.(*SystemServerClasspathModule)
279
280 s.Contents = module.properties.Contents
Jiakai Zhangcee9e192021-10-29 19:46:45 +0000281 s.Standalone_contents = module.properties.Standalone_contents
Jiakai Zhanga8d86602021-09-26 09:02:17 +0000282}
283
284func (s *systemServerClasspathFragmentSdkMemberProperties) AddToPropertySet(ctx android.SdkMemberContext, propertySet android.BpPropertySet) {
285 builder := ctx.SnapshotBuilder()
286 requiredMemberDependency := builder.SdkMemberReferencePropertyTag(true)
287
288 if len(s.Contents) > 0 {
289 propertySet.AddPropertyWithTag("contents", s.Contents, requiredMemberDependency)
290 }
Jiakai Zhangcee9e192021-10-29 19:46:45 +0000291
292 if len(s.Standalone_contents) > 0 {
293 propertySet.AddPropertyWithTag("standalone_contents", s.Standalone_contents, requiredMemberDependency)
294 }
Jiakai Zhanga8d86602021-09-26 09:02:17 +0000295}
296
297var _ android.SdkMemberType = (*systemServerClasspathFragmentMemberType)(nil)
298
Jiakai Zhangc9864272021-09-26 03:52:19 +0000299// A prebuilt version of the systemserverclasspath_fragment module.
300type prebuiltSystemServerClasspathModule struct {
301 SystemServerClasspathModule
302 prebuilt android.Prebuilt
303}
304
305func (module *prebuiltSystemServerClasspathModule) Prebuilt() *android.Prebuilt {
306 return &module.prebuilt
307}
308
309func (module *prebuiltSystemServerClasspathModule) Name() string {
310 return module.prebuilt.Name(module.ModuleBase.Name())
311}
312
Jiakai Zhang774dd302021-09-26 03:54:25 +0000313func (module *prebuiltSystemServerClasspathModule) RequiredFilesFromPrebuiltApex(ctx android.BaseModuleContext) []string {
314 return nil
315}
316
Spandan Das2ea84dd2024-01-25 22:12:50 +0000317func (module *prebuiltSystemServerClasspathModule) UseProfileGuidedDexpreopt() bool {
318 return false
319}
320
Jiakai Zhang774dd302021-09-26 03:54:25 +0000321var _ android.RequiredFilesFromPrebuiltApex = (*prebuiltSystemServerClasspathModule)(nil)
322
Jiakai Zhangc9864272021-09-26 03:52:19 +0000323func prebuiltSystemServerClasspathModuleFactory() android.Module {
324 m := &prebuiltSystemServerClasspathModule{}
325 m.AddProperties(&m.properties)
326 // This doesn't actually have any prebuilt files of its own so pass a placeholder for the srcs
327 // array.
328 android.InitPrebuiltModule(m, &[]string{"placeholder"})
329 android.InitApexModule(m)
330 android.InitAndroidArchModule(m, android.DeviceSupported, android.MultilibCommon)
331 return m
332}