blob: fa61ea68c21141fdef7319bcecf28ace5b1baaf5 [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,
31 },
32 })
satayev95e9c5b2021-04-29 11:50:26 +010033}
34
35func registerSystemserverClasspathBuildComponents(ctx android.RegistrationContext) {
satayev95e9c5b2021-04-29 11:50:26 +010036 ctx.RegisterModuleType("platform_systemserverclasspath", platformSystemServerClasspathFactory)
satayevaa86bac2021-05-13 19:01:52 +010037 ctx.RegisterModuleType("systemserverclasspath_fragment", systemServerClasspathFactory)
Jiakai Zhangc9864272021-09-26 03:52:19 +000038 ctx.RegisterModuleType("prebuilt_systemserverclasspath_fragment", prebuiltSystemServerClasspathModuleFactory)
satayev95e9c5b2021-04-29 11:50:26 +010039}
40
41type platformSystemServerClasspathModule struct {
42 android.ModuleBase
43
44 ClasspathFragmentBase
45}
46
47func platformSystemServerClasspathFactory() android.Module {
48 m := &platformSystemServerClasspathModule{}
49 initClasspathFragment(m, SYSTEMSERVERCLASSPATH)
50 android.InitAndroidArchModule(m, android.DeviceSupported, android.MultilibCommon)
51 return m
52}
53
satayevaa86bac2021-05-13 19:01:52 +010054func (p *platformSystemServerClasspathModule) AndroidMkEntries() (entries []android.AndroidMkEntries) {
55 return p.classpathFragmentBase().androidMkEntries()
satayev95e9c5b2021-04-29 11:50:26 +010056}
57
satayevaa86bac2021-05-13 19:01:52 +010058func (p *platformSystemServerClasspathModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
satayevb3090502021-06-15 17:49:10 +010059 configuredJars := p.configuredJars(ctx)
60 classpathJars := configuredJarListToClasspathJars(ctx, configuredJars, p.classpathType)
Jiakai Zhangcee9e192021-10-29 19:46:45 +000061 standaloneConfiguredJars := p.standaloneConfiguredJars(ctx)
62 standaloneClasspathJars := configuredJarListToClasspathJars(ctx, standaloneConfiguredJars, STANDALONE_SYSTEMSERVER_JARS)
Jiakai Zhang389a6472021-12-14 18:54:06 +000063 configuredJars = configuredJars.AppendList(&standaloneConfiguredJars)
Jiakai Zhangcee9e192021-10-29 19:46:45 +000064 classpathJars = append(classpathJars, standaloneClasspathJars...)
satayevb3090502021-06-15 17:49:10 +010065 p.classpathFragmentBase().generateClasspathProtoBuildActions(ctx, configuredJars, classpathJars)
satayev013485b2021-05-06 23:38:10 +010066}
67
satayev142ed272021-06-15 16:21:17 +010068func (p *platformSystemServerClasspathModule) configuredJars(ctx android.ModuleContext) android.ConfiguredJarList {
satayevb3090502021-06-15 17:49:10 +010069 // TODO(satayev): include any apex jars that don't populate their classpath proto config.
70 return dexpreopt.GetGlobalConfig(ctx).SystemServerJars
satayev95e9c5b2021-04-29 11:50:26 +010071}
satayevaa86bac2021-05-13 19:01:52 +010072
Jiakai Zhangcee9e192021-10-29 19:46:45 +000073func (p *platformSystemServerClasspathModule) standaloneConfiguredJars(ctx android.ModuleContext) android.ConfiguredJarList {
74 return dexpreopt.GetGlobalConfig(ctx).StandaloneSystemServerJars
75}
76
satayev333a1732021-05-17 21:35:26 +010077type SystemServerClasspathModule struct {
satayevaa86bac2021-05-13 19:01:52 +010078 android.ModuleBase
satayev333a1732021-05-17 21:35:26 +010079 android.ApexModuleBase
Jiakai Zhanga8d86602021-09-26 09:02:17 +000080 android.SdkBase
satayevaa86bac2021-05-13 19:01:52 +010081
82 ClasspathFragmentBase
satayev9366a052021-05-17 21:13:44 +010083
84 properties systemServerClasspathFragmentProperties
braleeb0c1f0c2021-06-07 22:49:13 +080085
86 // Collect the module directory for IDE info in java/jdeps.go.
87 modulePaths []string
satayev9366a052021-05-17 21:13:44 +010088}
89
satayev333a1732021-05-17 21:35:26 +010090func (s *SystemServerClasspathModule) ShouldSupportSdkVersion(ctx android.BaseModuleContext, sdkVersion android.ApiLevel) error {
91 return nil
92}
93
satayev9366a052021-05-17 21:13:44 +010094type systemServerClasspathFragmentProperties struct {
Jiakai Zhangcee9e192021-10-29 19:46:45 +000095 // List of system_server classpath jars, could be either java_library, or java_sdk_library.
satayev9366a052021-05-17 21:13:44 +010096 //
97 // The order of this list matters as it is the order that is used in the SYSTEMSERVERCLASSPATH.
98 Contents []string
Jiakai Zhangcee9e192021-10-29 19:46:45 +000099
100 // List of jars that system_server loads dynamically using separate classloaders.
101 //
102 // The order does not matter.
103 Standalone_contents []string
satayevaa86bac2021-05-13 19:01:52 +0100104}
105
106func systemServerClasspathFactory() android.Module {
satayev333a1732021-05-17 21:35:26 +0100107 m := &SystemServerClasspathModule{}
satayev9366a052021-05-17 21:13:44 +0100108 m.AddProperties(&m.properties)
satayev333a1732021-05-17 21:35:26 +0100109 android.InitApexModule(m)
Jiakai Zhanga8d86602021-09-26 09:02:17 +0000110 android.InitSdkAwareModule(m)
satayevaa86bac2021-05-13 19:01:52 +0100111 initClasspathFragment(m, SYSTEMSERVERCLASSPATH)
112 android.InitAndroidArchModule(m, android.DeviceSupported, android.MultilibCommon)
113 return m
114}
115
satayev333a1732021-05-17 21:35:26 +0100116func (s *SystemServerClasspathModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Jiakai Zhangcee9e192021-10-29 19:46:45 +0000117 if len(s.properties.Contents) == 0 && len(s.properties.Standalone_contents) == 0 {
118 ctx.PropertyErrorf("contents", "Either contents or standalone_contents needs to be non-empty")
satayev9366a052021-05-17 21:13:44 +0100119 }
120
satayevb3090502021-06-15 17:49:10 +0100121 configuredJars := s.configuredJars(ctx)
122 classpathJars := configuredJarListToClasspathJars(ctx, configuredJars, s.classpathType)
Jiakai Zhangcee9e192021-10-29 19:46:45 +0000123 standaloneConfiguredJars := s.standaloneConfiguredJars(ctx)
124 standaloneClasspathJars := configuredJarListToClasspathJars(ctx, standaloneConfiguredJars, STANDALONE_SYSTEMSERVER_JARS)
Jiakai Zhang389a6472021-12-14 18:54:06 +0000125 configuredJars = configuredJars.AppendList(&standaloneConfiguredJars)
Jiakai Zhangcee9e192021-10-29 19:46:45 +0000126 classpathJars = append(classpathJars, standaloneClasspathJars...)
satayevb3090502021-06-15 17:49:10 +0100127 s.classpathFragmentBase().generateClasspathProtoBuildActions(ctx, configuredJars, classpathJars)
braleeb0c1f0c2021-06-07 22:49:13 +0800128
129 // Collect the module directory for IDE info in java/jdeps.go.
130 s.modulePaths = append(s.modulePaths, ctx.ModuleDir())
satayevaa86bac2021-05-13 19:01:52 +0100131}
132
satayev142ed272021-06-15 16:21:17 +0100133func (s *SystemServerClasspathModule) configuredJars(ctx android.ModuleContext) android.ConfiguredJarList {
satayev703c67a2021-05-20 21:33:41 +0100134 global := dexpreopt.GetGlobalConfig(ctx)
135
satayevd604b212021-07-21 14:23:52 +0100136 possibleUpdatableModules := gatherPossibleApexModuleNamesAndStems(ctx, s.properties.Contents, systemServerClasspathFragmentContentDepTag)
satayevd34eb0c2021-08-06 13:20:28 +0100137 jars, unknown := global.ApexSystemServerJars.Filter(possibleUpdatableModules)
138 // TODO(satayev): remove geotz ssc_fragment, since geotz is not part of SSCP anymore.
139 _, unknown = android.RemoveFromList("geotz", unknown)
Keun young Parkd64ab232021-10-18 08:42:23 -0700140 // This module only exists in car products.
141 // So ignore it even if it is not in PRODUCT_APEX_SYSTEM_SERVER_JARS.
142 // TODO(b/203233647): Add better mechanism to make it optional.
143 _, unknown = android.RemoveFromList("car-frameworks-service-module", unknown)
Samiul Islam7b385c52021-10-11 22:47:13 +0100144
Alan Stokesbcd567e2021-11-12 15:21:43 +0000145 // This module is optional, so it is not present in all products.
146 // (See PRODUCT_ISOLATED_COMPILATION_ENABLED.)
147 // So ignore it even if it is not in PRODUCT_APEX_SYSTEM_SERVER_JARS.
148 // TODO(b/203233647): Add better mechanism to make it optional.
149 _, unknown = android.RemoveFromList("service-compos", unknown)
150
Samiul Islam7b385c52021-10-11 22:47:13 +0100151 // TODO(satayev): for apex_test we want to include all contents unconditionally to classpaths
152 // config. However, any test specific jars would not be present in ApexSystemServerJars. Instead,
153 // we should check if we are creating a config for apex_test via ApexInfo and amend the values.
154 // This is an exception to support end-to-end test for ApexdUnitTests, until such support exists.
155 if android.InList("test_service-apexd", possibleUpdatableModules) {
156 jars = jars.Append("com.android.apex.test_package", "test_service-apexd")
157 } else if global.ApexSystemServerJars.Len() > 0 && len(unknown) > 0 && !android.IsModuleInVersionedSdk(ctx.Module()) {
158 // For non test apexes, make sure that all contents are actually declared in make.
Ulya Trafimoviche5b2b492021-10-04 15:42:53 +0100159 ctx.ModuleErrorf("%s in contents must also be declared in PRODUCT_APEX_SYSTEM_SERVER_JARS", unknown)
satayevd34eb0c2021-08-06 13:20:28 +0100160 }
161
162 return jars
satayevaa86bac2021-05-13 19:01:52 +0100163}
satayev9366a052021-05-17 21:13:44 +0100164
Jiakai Zhangcee9e192021-10-29 19:46:45 +0000165func (s *SystemServerClasspathModule) standaloneConfiguredJars(ctx android.ModuleContext) android.ConfiguredJarList {
166 global := dexpreopt.GetGlobalConfig(ctx)
167
168 possibleUpdatableModules := gatherPossibleApexModuleNamesAndStems(ctx, s.properties.Standalone_contents, systemServerClasspathFragmentContentDepTag)
169 jars, _ := global.ApexStandaloneSystemServerJars.Filter(possibleUpdatableModules)
170
171 // TODO(jiakaiz): add a check to ensure that the contents are declared in make.
172
173 return jars
174}
175
satayev9366a052021-05-17 21:13:44 +0100176type systemServerClasspathFragmentContentDependencyTag struct {
177 blueprint.BaseDependencyTag
178}
179
Paul Duffin25322e42021-09-07 14:52:48 +0100180// The systemserverclasspath_fragment contents must never depend on prebuilts.
181func (systemServerClasspathFragmentContentDependencyTag) ReplaceSourceWithPrebuilt() bool {
182 return false
183}
184
Jiakai Zhanga8d86602021-09-26 09:02:17 +0000185// SdkMemberType causes dependencies added with this tag to be automatically added to the sdk as if
186// they were specified using java_systemserver_libs or java_sdk_libs.
187func (b systemServerClasspathFragmentContentDependencyTag) SdkMemberType(child android.Module) android.SdkMemberType {
188 // If the module is a java_sdk_library then treat it as if it was specified in the java_sdk_libs
189 // property, otherwise treat if it was specified in the java_systemserver_libs property.
190 if javaSdkLibrarySdkMemberType.IsInstance(child) {
191 return javaSdkLibrarySdkMemberType
192 }
193
194 return javaSystemserverLibsSdkMemberType
195}
196
197func (b systemServerClasspathFragmentContentDependencyTag) ExportMember() bool {
198 return true
199}
200
Colin Crossc33e5212021-05-25 18:16:02 -0700201// Contents of system server fragments in an apex are considered to be directly in the apex, as if
202// they were listed in java_libs.
203func (systemServerClasspathFragmentContentDependencyTag) CopyDirectlyInAnyApex() {}
204
Jiakai Zhang774dd302021-09-26 03:54:25 +0000205// Contents of system server fragments require files from prebuilt apex files.
206func (systemServerClasspathFragmentContentDependencyTag) RequiresFilesFromPrebuiltApex() {}
207
Paul Duffin25322e42021-09-07 14:52:48 +0100208var _ android.ReplaceSourceWithPrebuilt = systemServerClasspathFragmentContentDepTag
Jiakai Zhanga8d86602021-09-26 09:02:17 +0000209var _ android.SdkMemberDependencyTag = systemServerClasspathFragmentContentDepTag
Colin Crossc33e5212021-05-25 18:16:02 -0700210var _ android.CopyDirectlyInAnyApexTag = systemServerClasspathFragmentContentDepTag
Jiakai Zhang774dd302021-09-26 03:54:25 +0000211var _ android.RequiresFilesFromPrebuiltApexTag = systemServerClasspathFragmentContentDepTag
Colin Crossc33e5212021-05-25 18:16:02 -0700212
satayev9366a052021-05-17 21:13:44 +0100213// The tag used for the dependency between the systemserverclasspath_fragment module and its contents.
214var systemServerClasspathFragmentContentDepTag = systemServerClasspathFragmentContentDependencyTag{}
215
216func IsSystemServerClasspathFragmentContentDepTag(tag blueprint.DependencyTag) bool {
217 return tag == systemServerClasspathFragmentContentDepTag
218}
219
satayev333a1732021-05-17 21:35:26 +0100220func (s *SystemServerClasspathModule) ComponentDepsMutator(ctx android.BottomUpMutatorContext) {
satayev9366a052021-05-17 21:13:44 +0100221 module := ctx.Module()
Jiakai Zhangc9864272021-09-26 03:52:19 +0000222 _, isSourceModule := module.(*SystemServerClasspathModule)
Jiakai Zhangcee9e192021-10-29 19:46:45 +0000223 var deps []string
224 deps = append(deps, s.properties.Contents...)
225 deps = append(deps, s.properties.Standalone_contents...)
satayev9366a052021-05-17 21:13:44 +0100226
Jiakai Zhangcee9e192021-10-29 19:46:45 +0000227 for _, name := range deps {
Jiakai Zhangc9864272021-09-26 03:52:19 +0000228 // A systemserverclasspath_fragment must depend only on other source modules, while the
229 // prebuilt_systemserverclasspath_fragment_fragment must only depend on other prebuilt modules.
230 if !isSourceModule {
231 name = android.PrebuiltNameFromSource(name)
232 }
satayev9366a052021-05-17 21:13:44 +0100233 ctx.AddDependency(module, systemServerClasspathFragmentContentDepTag, name)
234 }
235}
braleeb0c1f0c2021-06-07 22:49:13 +0800236
237// Collect information for opening IDE project files in java/jdeps.go.
238func (s *SystemServerClasspathModule) IDEInfo(dpInfo *android.IdeInfo) {
239 dpInfo.Deps = append(dpInfo.Deps, s.properties.Contents...)
Jiakai Zhangcee9e192021-10-29 19:46:45 +0000240 dpInfo.Deps = append(dpInfo.Deps, s.properties.Standalone_contents...)
braleeb0c1f0c2021-06-07 22:49:13 +0800241 dpInfo.Paths = append(dpInfo.Paths, s.modulePaths...)
242}
Jiakai Zhangc9864272021-09-26 03:52:19 +0000243
Jiakai Zhanga8d86602021-09-26 09:02:17 +0000244type systemServerClasspathFragmentMemberType struct {
245 android.SdkMemberTypeBase
246}
247
248func (s *systemServerClasspathFragmentMemberType) AddDependencies(ctx android.SdkDependencyContext, dependencyTag blueprint.DependencyTag, names []string) {
249 ctx.AddVariationDependencies(nil, dependencyTag, names...)
250}
251
252func (s *systemServerClasspathFragmentMemberType) IsInstance(module android.Module) bool {
253 _, ok := module.(*SystemServerClasspathModule)
254 return ok
255}
256
257func (s *systemServerClasspathFragmentMemberType) AddPrebuiltModule(ctx android.SdkMemberContext, member android.SdkMember) android.BpModule {
258 return ctx.SnapshotBuilder().AddPrebuiltModule(member, "prebuilt_systemserverclasspath_fragment")
259}
260
261func (s *systemServerClasspathFragmentMemberType) CreateVariantPropertiesStruct() android.SdkMemberProperties {
262 return &systemServerClasspathFragmentSdkMemberProperties{}
263}
264
265type systemServerClasspathFragmentSdkMemberProperties struct {
266 android.SdkMemberPropertiesBase
267
Jiakai Zhangcee9e192021-10-29 19:46:45 +0000268 // List of system_server classpath jars, could be either java_library, or java_sdk_library.
269 //
270 // The order of this list matters as it is the order that is used in the SYSTEMSERVERCLASSPATH.
Jiakai Zhanga8d86602021-09-26 09:02:17 +0000271 Contents []string
Jiakai Zhangcee9e192021-10-29 19:46:45 +0000272
273 // List of jars that system_server loads dynamically using separate classloaders.
274 //
275 // The order does not matter.
276 Standalone_contents []string
Jiakai Zhanga8d86602021-09-26 09:02:17 +0000277}
278
279func (s *systemServerClasspathFragmentSdkMemberProperties) PopulateFromVariant(ctx android.SdkMemberContext, variant android.Module) {
280 module := variant.(*SystemServerClasspathModule)
281
282 s.Contents = module.properties.Contents
Jiakai Zhangcee9e192021-10-29 19:46:45 +0000283 s.Standalone_contents = module.properties.Standalone_contents
Jiakai Zhanga8d86602021-09-26 09:02:17 +0000284}
285
286func (s *systemServerClasspathFragmentSdkMemberProperties) AddToPropertySet(ctx android.SdkMemberContext, propertySet android.BpPropertySet) {
287 builder := ctx.SnapshotBuilder()
288 requiredMemberDependency := builder.SdkMemberReferencePropertyTag(true)
289
290 if len(s.Contents) > 0 {
291 propertySet.AddPropertyWithTag("contents", s.Contents, requiredMemberDependency)
292 }
Jiakai Zhangcee9e192021-10-29 19:46:45 +0000293
294 if len(s.Standalone_contents) > 0 {
295 propertySet.AddPropertyWithTag("standalone_contents", s.Standalone_contents, requiredMemberDependency)
296 }
Jiakai Zhanga8d86602021-09-26 09:02:17 +0000297}
298
299var _ android.SdkMemberType = (*systemServerClasspathFragmentMemberType)(nil)
300
Jiakai Zhangc9864272021-09-26 03:52:19 +0000301// A prebuilt version of the systemserverclasspath_fragment module.
302type prebuiltSystemServerClasspathModule struct {
303 SystemServerClasspathModule
304 prebuilt android.Prebuilt
305}
306
307func (module *prebuiltSystemServerClasspathModule) Prebuilt() *android.Prebuilt {
308 return &module.prebuilt
309}
310
311func (module *prebuiltSystemServerClasspathModule) Name() string {
312 return module.prebuilt.Name(module.ModuleBase.Name())
313}
314
Jiakai Zhang774dd302021-09-26 03:54:25 +0000315func (module *prebuiltSystemServerClasspathModule) RequiredFilesFromPrebuiltApex(ctx android.BaseModuleContext) []string {
316 return nil
317}
318
319var _ android.RequiredFilesFromPrebuiltApex = (*prebuiltSystemServerClasspathModule)(nil)
320
Jiakai Zhangc9864272021-09-26 03:52:19 +0000321func prebuiltSystemServerClasspathModuleFactory() android.Module {
322 m := &prebuiltSystemServerClasspathModule{}
323 m.AddProperties(&m.properties)
324 // This doesn't actually have any prebuilt files of its own so pass a placeholder for the srcs
325 // array.
326 android.InitPrebuiltModule(m, &[]string{"placeholder"})
327 android.InitApexModule(m)
Jiakai Zhanga8d86602021-09-26 09:02:17 +0000328 android.InitSdkAwareModule(m)
Jiakai Zhangc9864272021-09-26 03:52:19 +0000329 android.InitAndroidArchModule(m, android.DeviceSupported, android.MultilibCommon)
330 return m
331}