blob: e263cc44ccad06eae13069b731d7e3405f5f2cf8 [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
Alan Stokesbcd567e2021-11-12 15:21:43 +0000128 // This module is optional, so it is not present in all products.
129 // (See PRODUCT_ISOLATED_COMPILATION_ENABLED.)
130 // So ignore it even if it is not in PRODUCT_APEX_SYSTEM_SERVER_JARS.
131 // TODO(b/203233647): Add better mechanism to make it optional.
132 _, unknown = android.RemoveFromList("service-compos", unknown)
133
Samiul Islam7b385c52021-10-11 22:47:13 +0100134 // TODO(satayev): for apex_test we want to include all contents unconditionally to classpaths
135 // config. However, any test specific jars would not be present in ApexSystemServerJars. Instead,
136 // we should check if we are creating a config for apex_test via ApexInfo and amend the values.
137 // This is an exception to support end-to-end test for ApexdUnitTests, until such support exists.
138 if android.InList("test_service-apexd", possibleUpdatableModules) {
139 jars = jars.Append("com.android.apex.test_package", "test_service-apexd")
140 } else if global.ApexSystemServerJars.Len() > 0 && len(unknown) > 0 && !android.IsModuleInVersionedSdk(ctx.Module()) {
141 // For non test apexes, make sure that all contents are actually declared in make.
Ulya Trafimoviche5b2b492021-10-04 15:42:53 +0100142 ctx.ModuleErrorf("%s in contents must also be declared in PRODUCT_APEX_SYSTEM_SERVER_JARS", unknown)
satayevd34eb0c2021-08-06 13:20:28 +0100143 }
144
145 return jars
satayevaa86bac2021-05-13 19:01:52 +0100146}
satayev9366a052021-05-17 21:13:44 +0100147
148type systemServerClasspathFragmentContentDependencyTag struct {
149 blueprint.BaseDependencyTag
150}
151
Paul Duffin25322e42021-09-07 14:52:48 +0100152// The systemserverclasspath_fragment contents must never depend on prebuilts.
153func (systemServerClasspathFragmentContentDependencyTag) ReplaceSourceWithPrebuilt() bool {
154 return false
155}
156
Jiakai Zhanga8d86602021-09-26 09:02:17 +0000157// SdkMemberType causes dependencies added with this tag to be automatically added to the sdk as if
158// they were specified using java_systemserver_libs or java_sdk_libs.
159func (b systemServerClasspathFragmentContentDependencyTag) SdkMemberType(child android.Module) android.SdkMemberType {
160 // If the module is a java_sdk_library then treat it as if it was specified in the java_sdk_libs
161 // property, otherwise treat if it was specified in the java_systemserver_libs property.
162 if javaSdkLibrarySdkMemberType.IsInstance(child) {
163 return javaSdkLibrarySdkMemberType
164 }
165
166 return javaSystemserverLibsSdkMemberType
167}
168
169func (b systemServerClasspathFragmentContentDependencyTag) ExportMember() bool {
170 return true
171}
172
Colin Crossc33e5212021-05-25 18:16:02 -0700173// Contents of system server fragments in an apex are considered to be directly in the apex, as if
174// they were listed in java_libs.
175func (systemServerClasspathFragmentContentDependencyTag) CopyDirectlyInAnyApex() {}
176
Jiakai Zhang774dd302021-09-26 03:54:25 +0000177// Contents of system server fragments require files from prebuilt apex files.
178func (systemServerClasspathFragmentContentDependencyTag) RequiresFilesFromPrebuiltApex() {}
179
Paul Duffin25322e42021-09-07 14:52:48 +0100180var _ android.ReplaceSourceWithPrebuilt = systemServerClasspathFragmentContentDepTag
Jiakai Zhanga8d86602021-09-26 09:02:17 +0000181var _ android.SdkMemberDependencyTag = systemServerClasspathFragmentContentDepTag
Colin Crossc33e5212021-05-25 18:16:02 -0700182var _ android.CopyDirectlyInAnyApexTag = systemServerClasspathFragmentContentDepTag
Jiakai Zhang774dd302021-09-26 03:54:25 +0000183var _ android.RequiresFilesFromPrebuiltApexTag = systemServerClasspathFragmentContentDepTag
Colin Crossc33e5212021-05-25 18:16:02 -0700184
satayev9366a052021-05-17 21:13:44 +0100185// The tag used for the dependency between the systemserverclasspath_fragment module and its contents.
186var systemServerClasspathFragmentContentDepTag = systemServerClasspathFragmentContentDependencyTag{}
187
188func IsSystemServerClasspathFragmentContentDepTag(tag blueprint.DependencyTag) bool {
189 return tag == systemServerClasspathFragmentContentDepTag
190}
191
satayev333a1732021-05-17 21:35:26 +0100192func (s *SystemServerClasspathModule) ComponentDepsMutator(ctx android.BottomUpMutatorContext) {
satayev9366a052021-05-17 21:13:44 +0100193 module := ctx.Module()
Jiakai Zhangc9864272021-09-26 03:52:19 +0000194 _, isSourceModule := module.(*SystemServerClasspathModule)
satayev9366a052021-05-17 21:13:44 +0100195
196 for _, name := range s.properties.Contents {
Jiakai Zhangc9864272021-09-26 03:52:19 +0000197 // A systemserverclasspath_fragment must depend only on other source modules, while the
198 // prebuilt_systemserverclasspath_fragment_fragment must only depend on other prebuilt modules.
199 if !isSourceModule {
200 name = android.PrebuiltNameFromSource(name)
201 }
satayev9366a052021-05-17 21:13:44 +0100202 ctx.AddDependency(module, systemServerClasspathFragmentContentDepTag, name)
203 }
204}
braleeb0c1f0c2021-06-07 22:49:13 +0800205
206// Collect information for opening IDE project files in java/jdeps.go.
207func (s *SystemServerClasspathModule) IDEInfo(dpInfo *android.IdeInfo) {
208 dpInfo.Deps = append(dpInfo.Deps, s.properties.Contents...)
209 dpInfo.Paths = append(dpInfo.Paths, s.modulePaths...)
210}
Jiakai Zhangc9864272021-09-26 03:52:19 +0000211
Jiakai Zhanga8d86602021-09-26 09:02:17 +0000212type systemServerClasspathFragmentMemberType struct {
213 android.SdkMemberTypeBase
214}
215
216func (s *systemServerClasspathFragmentMemberType) AddDependencies(ctx android.SdkDependencyContext, dependencyTag blueprint.DependencyTag, names []string) {
217 ctx.AddVariationDependencies(nil, dependencyTag, names...)
218}
219
220func (s *systemServerClasspathFragmentMemberType) IsInstance(module android.Module) bool {
221 _, ok := module.(*SystemServerClasspathModule)
222 return ok
223}
224
225func (s *systemServerClasspathFragmentMemberType) AddPrebuiltModule(ctx android.SdkMemberContext, member android.SdkMember) android.BpModule {
226 return ctx.SnapshotBuilder().AddPrebuiltModule(member, "prebuilt_systemserverclasspath_fragment")
227}
228
229func (s *systemServerClasspathFragmentMemberType) CreateVariantPropertiesStruct() android.SdkMemberProperties {
230 return &systemServerClasspathFragmentSdkMemberProperties{}
231}
232
233type systemServerClasspathFragmentSdkMemberProperties struct {
234 android.SdkMemberPropertiesBase
235
236 // Contents of the systemserverclasspath fragment
237 Contents []string
238}
239
240func (s *systemServerClasspathFragmentSdkMemberProperties) PopulateFromVariant(ctx android.SdkMemberContext, variant android.Module) {
241 module := variant.(*SystemServerClasspathModule)
242
243 s.Contents = module.properties.Contents
244}
245
246func (s *systemServerClasspathFragmentSdkMemberProperties) AddToPropertySet(ctx android.SdkMemberContext, propertySet android.BpPropertySet) {
247 builder := ctx.SnapshotBuilder()
248 requiredMemberDependency := builder.SdkMemberReferencePropertyTag(true)
249
250 if len(s.Contents) > 0 {
251 propertySet.AddPropertyWithTag("contents", s.Contents, requiredMemberDependency)
252 }
253}
254
255var _ android.SdkMemberType = (*systemServerClasspathFragmentMemberType)(nil)
256
Jiakai Zhangc9864272021-09-26 03:52:19 +0000257// A prebuilt version of the systemserverclasspath_fragment module.
258type prebuiltSystemServerClasspathModule struct {
259 SystemServerClasspathModule
260 prebuilt android.Prebuilt
261}
262
263func (module *prebuiltSystemServerClasspathModule) Prebuilt() *android.Prebuilt {
264 return &module.prebuilt
265}
266
267func (module *prebuiltSystemServerClasspathModule) Name() string {
268 return module.prebuilt.Name(module.ModuleBase.Name())
269}
270
Jiakai Zhang774dd302021-09-26 03:54:25 +0000271func (module *prebuiltSystemServerClasspathModule) RequiredFilesFromPrebuiltApex(ctx android.BaseModuleContext) []string {
272 return nil
273}
274
275var _ android.RequiredFilesFromPrebuiltApex = (*prebuiltSystemServerClasspathModule)(nil)
276
Jiakai Zhangc9864272021-09-26 03:52:19 +0000277func prebuiltSystemServerClasspathModuleFactory() android.Module {
278 m := &prebuiltSystemServerClasspathModule{}
279 m.AddProperties(&m.properties)
280 // This doesn't actually have any prebuilt files of its own so pass a placeholder for the srcs
281 // array.
282 android.InitPrebuiltModule(m, &[]string{"placeholder"})
283 android.InitApexModule(m)
Jiakai Zhanga8d86602021-09-26 09:02:17 +0000284 android.InitSdkAwareModule(m)
Jiakai Zhangc9864272021-09-26 03:52:19 +0000285 android.InitAndroidArchModule(m, android.DeviceSupported, android.MultilibCommon)
286 return m
287}