blob: d75635c43970d1c21c832f2f3881f78bf14568eb [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)
61 p.classpathFragmentBase().generateClasspathProtoBuildActions(ctx, configuredJars, classpathJars)
satayev013485b2021-05-06 23:38:10 +010062}
63
satayev142ed272021-06-15 16:21:17 +010064func (p *platformSystemServerClasspathModule) configuredJars(ctx android.ModuleContext) android.ConfiguredJarList {
satayevb3090502021-06-15 17:49:10 +010065 // TODO(satayev): include any apex jars that don't populate their classpath proto config.
66 return dexpreopt.GetGlobalConfig(ctx).SystemServerJars
satayev95e9c5b2021-04-29 11:50:26 +010067}
satayevaa86bac2021-05-13 19:01:52 +010068
satayev333a1732021-05-17 21:35:26 +010069type SystemServerClasspathModule struct {
satayevaa86bac2021-05-13 19:01:52 +010070 android.ModuleBase
satayev333a1732021-05-17 21:35:26 +010071 android.ApexModuleBase
Jiakai Zhanga8d86602021-09-26 09:02:17 +000072 android.SdkBase
satayevaa86bac2021-05-13 19:01:52 +010073
74 ClasspathFragmentBase
satayev9366a052021-05-17 21:13:44 +010075
76 properties systemServerClasspathFragmentProperties
braleeb0c1f0c2021-06-07 22:49:13 +080077
78 // Collect the module directory for IDE info in java/jdeps.go.
79 modulePaths []string
satayev9366a052021-05-17 21:13:44 +010080}
81
satayev333a1732021-05-17 21:35:26 +010082func (s *SystemServerClasspathModule) ShouldSupportSdkVersion(ctx android.BaseModuleContext, sdkVersion android.ApiLevel) error {
83 return nil
84}
85
satayev9366a052021-05-17 21:13:44 +010086type systemServerClasspathFragmentProperties struct {
87 // The contents of this systemserverclasspath_fragment, could be either java_library, or java_sdk_library.
88 //
89 // The order of this list matters as it is the order that is used in the SYSTEMSERVERCLASSPATH.
90 Contents []string
satayevaa86bac2021-05-13 19:01:52 +010091}
92
93func systemServerClasspathFactory() android.Module {
satayev333a1732021-05-17 21:35:26 +010094 m := &SystemServerClasspathModule{}
satayev9366a052021-05-17 21:13:44 +010095 m.AddProperties(&m.properties)
satayev333a1732021-05-17 21:35:26 +010096 android.InitApexModule(m)
Jiakai Zhanga8d86602021-09-26 09:02:17 +000097 android.InitSdkAwareModule(m)
satayevaa86bac2021-05-13 19:01:52 +010098 initClasspathFragment(m, SYSTEMSERVERCLASSPATH)
99 android.InitAndroidArchModule(m, android.DeviceSupported, android.MultilibCommon)
100 return m
101}
102
satayev333a1732021-05-17 21:35:26 +0100103func (s *SystemServerClasspathModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
satayev9366a052021-05-17 21:13:44 +0100104 if len(s.properties.Contents) == 0 {
105 ctx.PropertyErrorf("contents", "empty contents are not allowed")
106 }
107
satayevb3090502021-06-15 17:49:10 +0100108 configuredJars := s.configuredJars(ctx)
109 classpathJars := configuredJarListToClasspathJars(ctx, configuredJars, s.classpathType)
110 s.classpathFragmentBase().generateClasspathProtoBuildActions(ctx, configuredJars, classpathJars)
braleeb0c1f0c2021-06-07 22:49:13 +0800111
112 // Collect the module directory for IDE info in java/jdeps.go.
113 s.modulePaths = append(s.modulePaths, ctx.ModuleDir())
satayevaa86bac2021-05-13 19:01:52 +0100114}
115
satayev142ed272021-06-15 16:21:17 +0100116func (s *SystemServerClasspathModule) configuredJars(ctx android.ModuleContext) android.ConfiguredJarList {
satayev703c67a2021-05-20 21:33:41 +0100117 global := dexpreopt.GetGlobalConfig(ctx)
118
satayevd604b212021-07-21 14:23:52 +0100119 possibleUpdatableModules := gatherPossibleApexModuleNamesAndStems(ctx, s.properties.Contents, systemServerClasspathFragmentContentDepTag)
satayevd34eb0c2021-08-06 13:20:28 +0100120 jars, unknown := global.ApexSystemServerJars.Filter(possibleUpdatableModules)
121 // TODO(satayev): remove geotz ssc_fragment, since geotz is not part of SSCP anymore.
122 _, unknown = android.RemoveFromList("geotz", unknown)
Keun young Parkd64ab232021-10-18 08:42:23 -0700123 // This module only exists in car products.
124 // So ignore it even if it is not in PRODUCT_APEX_SYSTEM_SERVER_JARS.
125 // TODO(b/203233647): Add better mechanism to make it optional.
126 _, unknown = android.RemoveFromList("car-frameworks-service-module", unknown)
Samiul Islam7b385c52021-10-11 22:47:13 +0100127
128 // TODO(satayev): for apex_test we want to include all contents unconditionally to classpaths
129 // config. However, any test specific jars would not be present in ApexSystemServerJars. Instead,
130 // we should check if we are creating a config for apex_test via ApexInfo and amend the values.
131 // This is an exception to support end-to-end test for ApexdUnitTests, until such support exists.
132 if android.InList("test_service-apexd", possibleUpdatableModules) {
133 jars = jars.Append("com.android.apex.test_package", "test_service-apexd")
134 } else if global.ApexSystemServerJars.Len() > 0 && len(unknown) > 0 && !android.IsModuleInVersionedSdk(ctx.Module()) {
135 // For non test apexes, make sure that all contents are actually declared in make.
Ulya Trafimoviche5b2b492021-10-04 15:42:53 +0100136 ctx.ModuleErrorf("%s in contents must also be declared in PRODUCT_APEX_SYSTEM_SERVER_JARS", unknown)
satayevd34eb0c2021-08-06 13:20:28 +0100137 }
138
139 return jars
satayevaa86bac2021-05-13 19:01:52 +0100140}
satayev9366a052021-05-17 21:13:44 +0100141
142type systemServerClasspathFragmentContentDependencyTag struct {
143 blueprint.BaseDependencyTag
144}
145
Paul Duffin25322e42021-09-07 14:52:48 +0100146// The systemserverclasspath_fragment contents must never depend on prebuilts.
147func (systemServerClasspathFragmentContentDependencyTag) ReplaceSourceWithPrebuilt() bool {
148 return false
149}
150
Jiakai Zhanga8d86602021-09-26 09:02:17 +0000151// SdkMemberType causes dependencies added with this tag to be automatically added to the sdk as if
152// they were specified using java_systemserver_libs or java_sdk_libs.
153func (b systemServerClasspathFragmentContentDependencyTag) SdkMemberType(child android.Module) android.SdkMemberType {
154 // If the module is a java_sdk_library then treat it as if it was specified in the java_sdk_libs
155 // property, otherwise treat if it was specified in the java_systemserver_libs property.
156 if javaSdkLibrarySdkMemberType.IsInstance(child) {
157 return javaSdkLibrarySdkMemberType
158 }
159
160 return javaSystemserverLibsSdkMemberType
161}
162
163func (b systemServerClasspathFragmentContentDependencyTag) ExportMember() bool {
164 return true
165}
166
Colin Crossc33e5212021-05-25 18:16:02 -0700167// Contents of system server fragments in an apex are considered to be directly in the apex, as if
168// they were listed in java_libs.
169func (systemServerClasspathFragmentContentDependencyTag) CopyDirectlyInAnyApex() {}
170
Jiakai Zhang774dd302021-09-26 03:54:25 +0000171// Contents of system server fragments require files from prebuilt apex files.
172func (systemServerClasspathFragmentContentDependencyTag) RequiresFilesFromPrebuiltApex() {}
173
Paul Duffin25322e42021-09-07 14:52:48 +0100174var _ android.ReplaceSourceWithPrebuilt = systemServerClasspathFragmentContentDepTag
Jiakai Zhanga8d86602021-09-26 09:02:17 +0000175var _ android.SdkMemberDependencyTag = systemServerClasspathFragmentContentDepTag
Colin Crossc33e5212021-05-25 18:16:02 -0700176var _ android.CopyDirectlyInAnyApexTag = systemServerClasspathFragmentContentDepTag
Jiakai Zhang774dd302021-09-26 03:54:25 +0000177var _ android.RequiresFilesFromPrebuiltApexTag = systemServerClasspathFragmentContentDepTag
Colin Crossc33e5212021-05-25 18:16:02 -0700178
satayev9366a052021-05-17 21:13:44 +0100179// The tag used for the dependency between the systemserverclasspath_fragment module and its contents.
180var systemServerClasspathFragmentContentDepTag = systemServerClasspathFragmentContentDependencyTag{}
181
182func IsSystemServerClasspathFragmentContentDepTag(tag blueprint.DependencyTag) bool {
183 return tag == systemServerClasspathFragmentContentDepTag
184}
185
satayev333a1732021-05-17 21:35:26 +0100186func (s *SystemServerClasspathModule) ComponentDepsMutator(ctx android.BottomUpMutatorContext) {
satayev9366a052021-05-17 21:13:44 +0100187 module := ctx.Module()
Jiakai Zhangc9864272021-09-26 03:52:19 +0000188 _, isSourceModule := module.(*SystemServerClasspathModule)
satayev9366a052021-05-17 21:13:44 +0100189
190 for _, name := range s.properties.Contents {
Jiakai Zhangc9864272021-09-26 03:52:19 +0000191 // A systemserverclasspath_fragment must depend only on other source modules, while the
192 // prebuilt_systemserverclasspath_fragment_fragment must only depend on other prebuilt modules.
193 if !isSourceModule {
194 name = android.PrebuiltNameFromSource(name)
195 }
satayev9366a052021-05-17 21:13:44 +0100196 ctx.AddDependency(module, systemServerClasspathFragmentContentDepTag, name)
197 }
198}
braleeb0c1f0c2021-06-07 22:49:13 +0800199
200// Collect information for opening IDE project files in java/jdeps.go.
201func (s *SystemServerClasspathModule) IDEInfo(dpInfo *android.IdeInfo) {
202 dpInfo.Deps = append(dpInfo.Deps, s.properties.Contents...)
203 dpInfo.Paths = append(dpInfo.Paths, s.modulePaths...)
204}
Jiakai Zhangc9864272021-09-26 03:52:19 +0000205
Jiakai Zhanga8d86602021-09-26 09:02:17 +0000206type systemServerClasspathFragmentMemberType struct {
207 android.SdkMemberTypeBase
208}
209
210func (s *systemServerClasspathFragmentMemberType) AddDependencies(ctx android.SdkDependencyContext, dependencyTag blueprint.DependencyTag, names []string) {
211 ctx.AddVariationDependencies(nil, dependencyTag, names...)
212}
213
214func (s *systemServerClasspathFragmentMemberType) IsInstance(module android.Module) bool {
215 _, ok := module.(*SystemServerClasspathModule)
216 return ok
217}
218
219func (s *systemServerClasspathFragmentMemberType) AddPrebuiltModule(ctx android.SdkMemberContext, member android.SdkMember) android.BpModule {
220 return ctx.SnapshotBuilder().AddPrebuiltModule(member, "prebuilt_systemserverclasspath_fragment")
221}
222
223func (s *systemServerClasspathFragmentMemberType) CreateVariantPropertiesStruct() android.SdkMemberProperties {
224 return &systemServerClasspathFragmentSdkMemberProperties{}
225}
226
227type systemServerClasspathFragmentSdkMemberProperties struct {
228 android.SdkMemberPropertiesBase
229
230 // Contents of the systemserverclasspath fragment
231 Contents []string
232}
233
234func (s *systemServerClasspathFragmentSdkMemberProperties) PopulateFromVariant(ctx android.SdkMemberContext, variant android.Module) {
235 module := variant.(*SystemServerClasspathModule)
236
237 s.Contents = module.properties.Contents
238}
239
240func (s *systemServerClasspathFragmentSdkMemberProperties) AddToPropertySet(ctx android.SdkMemberContext, propertySet android.BpPropertySet) {
241 builder := ctx.SnapshotBuilder()
242 requiredMemberDependency := builder.SdkMemberReferencePropertyTag(true)
243
244 if len(s.Contents) > 0 {
245 propertySet.AddPropertyWithTag("contents", s.Contents, requiredMemberDependency)
246 }
247}
248
249var _ android.SdkMemberType = (*systemServerClasspathFragmentMemberType)(nil)
250
Jiakai Zhangc9864272021-09-26 03:52:19 +0000251// A prebuilt version of the systemserverclasspath_fragment module.
252type prebuiltSystemServerClasspathModule struct {
253 SystemServerClasspathModule
254 prebuilt android.Prebuilt
255}
256
257func (module *prebuiltSystemServerClasspathModule) Prebuilt() *android.Prebuilt {
258 return &module.prebuilt
259}
260
261func (module *prebuiltSystemServerClasspathModule) Name() string {
262 return module.prebuilt.Name(module.ModuleBase.Name())
263}
264
Jiakai Zhang774dd302021-09-26 03:54:25 +0000265func (module *prebuiltSystemServerClasspathModule) RequiredFilesFromPrebuiltApex(ctx android.BaseModuleContext) []string {
266 return nil
267}
268
269var _ android.RequiredFilesFromPrebuiltApex = (*prebuiltSystemServerClasspathModule)(nil)
270
Jiakai Zhangc9864272021-09-26 03:52:19 +0000271func prebuiltSystemServerClasspathModuleFactory() android.Module {
272 m := &prebuiltSystemServerClasspathModule{}
273 m.AddProperties(&m.properties)
274 // This doesn't actually have any prebuilt files of its own so pass a placeholder for the srcs
275 // array.
276 android.InitPrebuiltModule(m, &[]string{"placeholder"})
277 android.InitApexModule(m)
Jiakai Zhanga8d86602021-09-26 09:02:17 +0000278 android.InitSdkAwareModule(m)
Jiakai Zhangc9864272021-09-26 03:52:19 +0000279 android.InitAndroidArchModule(m, android.DeviceSupported, android.MultilibCommon)
280 return m
281}