blob: 1b4fda821a104f192840fb674e7d0f4103ea1e80 [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)
123
124 // For non test apexes, make sure that all contents are actually declared in make.
Jiakai Zhanga8d86602021-09-26 09:02:17 +0000125 if global.ApexSystemServerJars.Len() > 0 && len(unknown) > 0 && !android.IsModuleInVersionedSdk(ctx.Module()) {
satayevd34eb0c2021-08-06 13:20:28 +0100126 ctx.ModuleErrorf("%s in contents must also be declared in PRODUCT_UPDATABLE_SYSTEM_SERVER_JARS", unknown)
127 }
128
129 return jars
satayevaa86bac2021-05-13 19:01:52 +0100130}
satayev9366a052021-05-17 21:13:44 +0100131
132type systemServerClasspathFragmentContentDependencyTag struct {
133 blueprint.BaseDependencyTag
134}
135
Paul Duffin25322e42021-09-07 14:52:48 +0100136// The systemserverclasspath_fragment contents must never depend on prebuilts.
137func (systemServerClasspathFragmentContentDependencyTag) ReplaceSourceWithPrebuilt() bool {
138 return false
139}
140
Jiakai Zhanga8d86602021-09-26 09:02:17 +0000141// SdkMemberType causes dependencies added with this tag to be automatically added to the sdk as if
142// they were specified using java_systemserver_libs or java_sdk_libs.
143func (b systemServerClasspathFragmentContentDependencyTag) SdkMemberType(child android.Module) android.SdkMemberType {
144 // If the module is a java_sdk_library then treat it as if it was specified in the java_sdk_libs
145 // property, otherwise treat if it was specified in the java_systemserver_libs property.
146 if javaSdkLibrarySdkMemberType.IsInstance(child) {
147 return javaSdkLibrarySdkMemberType
148 }
149
150 return javaSystemserverLibsSdkMemberType
151}
152
153func (b systemServerClasspathFragmentContentDependencyTag) ExportMember() bool {
154 return true
155}
156
Colin Crossc33e5212021-05-25 18:16:02 -0700157// Contents of system server fragments in an apex are considered to be directly in the apex, as if
158// they were listed in java_libs.
159func (systemServerClasspathFragmentContentDependencyTag) CopyDirectlyInAnyApex() {}
160
Jiakai Zhang774dd302021-09-26 03:54:25 +0000161// Contents of system server fragments require files from prebuilt apex files.
162func (systemServerClasspathFragmentContentDependencyTag) RequiresFilesFromPrebuiltApex() {}
163
Paul Duffin25322e42021-09-07 14:52:48 +0100164var _ android.ReplaceSourceWithPrebuilt = systemServerClasspathFragmentContentDepTag
Jiakai Zhanga8d86602021-09-26 09:02:17 +0000165var _ android.SdkMemberDependencyTag = systemServerClasspathFragmentContentDepTag
Colin Crossc33e5212021-05-25 18:16:02 -0700166var _ android.CopyDirectlyInAnyApexTag = systemServerClasspathFragmentContentDepTag
Jiakai Zhang774dd302021-09-26 03:54:25 +0000167var _ android.RequiresFilesFromPrebuiltApexTag = systemServerClasspathFragmentContentDepTag
Colin Crossc33e5212021-05-25 18:16:02 -0700168
satayev9366a052021-05-17 21:13:44 +0100169// The tag used for the dependency between the systemserverclasspath_fragment module and its contents.
170var systemServerClasspathFragmentContentDepTag = systemServerClasspathFragmentContentDependencyTag{}
171
172func IsSystemServerClasspathFragmentContentDepTag(tag blueprint.DependencyTag) bool {
173 return tag == systemServerClasspathFragmentContentDepTag
174}
175
satayev333a1732021-05-17 21:35:26 +0100176func (s *SystemServerClasspathModule) ComponentDepsMutator(ctx android.BottomUpMutatorContext) {
satayev9366a052021-05-17 21:13:44 +0100177 module := ctx.Module()
Jiakai Zhangc9864272021-09-26 03:52:19 +0000178 _, isSourceModule := module.(*SystemServerClasspathModule)
satayev9366a052021-05-17 21:13:44 +0100179
180 for _, name := range s.properties.Contents {
Jiakai Zhangc9864272021-09-26 03:52:19 +0000181 // A systemserverclasspath_fragment must depend only on other source modules, while the
182 // prebuilt_systemserverclasspath_fragment_fragment must only depend on other prebuilt modules.
183 if !isSourceModule {
184 name = android.PrebuiltNameFromSource(name)
185 }
satayev9366a052021-05-17 21:13:44 +0100186 ctx.AddDependency(module, systemServerClasspathFragmentContentDepTag, name)
187 }
188}
braleeb0c1f0c2021-06-07 22:49:13 +0800189
190// Collect information for opening IDE project files in java/jdeps.go.
191func (s *SystemServerClasspathModule) IDEInfo(dpInfo *android.IdeInfo) {
192 dpInfo.Deps = append(dpInfo.Deps, s.properties.Contents...)
193 dpInfo.Paths = append(dpInfo.Paths, s.modulePaths...)
194}
Jiakai Zhangc9864272021-09-26 03:52:19 +0000195
Jiakai Zhanga8d86602021-09-26 09:02:17 +0000196type systemServerClasspathFragmentMemberType struct {
197 android.SdkMemberTypeBase
198}
199
200func (s *systemServerClasspathFragmentMemberType) AddDependencies(ctx android.SdkDependencyContext, dependencyTag blueprint.DependencyTag, names []string) {
201 ctx.AddVariationDependencies(nil, dependencyTag, names...)
202}
203
204func (s *systemServerClasspathFragmentMemberType) IsInstance(module android.Module) bool {
205 _, ok := module.(*SystemServerClasspathModule)
206 return ok
207}
208
209func (s *systemServerClasspathFragmentMemberType) AddPrebuiltModule(ctx android.SdkMemberContext, member android.SdkMember) android.BpModule {
210 return ctx.SnapshotBuilder().AddPrebuiltModule(member, "prebuilt_systemserverclasspath_fragment")
211}
212
213func (s *systemServerClasspathFragmentMemberType) CreateVariantPropertiesStruct() android.SdkMemberProperties {
214 return &systemServerClasspathFragmentSdkMemberProperties{}
215}
216
217type systemServerClasspathFragmentSdkMemberProperties struct {
218 android.SdkMemberPropertiesBase
219
220 // Contents of the systemserverclasspath fragment
221 Contents []string
222}
223
224func (s *systemServerClasspathFragmentSdkMemberProperties) PopulateFromVariant(ctx android.SdkMemberContext, variant android.Module) {
225 module := variant.(*SystemServerClasspathModule)
226
227 s.Contents = module.properties.Contents
228}
229
230func (s *systemServerClasspathFragmentSdkMemberProperties) AddToPropertySet(ctx android.SdkMemberContext, propertySet android.BpPropertySet) {
231 builder := ctx.SnapshotBuilder()
232 requiredMemberDependency := builder.SdkMemberReferencePropertyTag(true)
233
234 if len(s.Contents) > 0 {
235 propertySet.AddPropertyWithTag("contents", s.Contents, requiredMemberDependency)
236 }
237}
238
239var _ android.SdkMemberType = (*systemServerClasspathFragmentMemberType)(nil)
240
Jiakai Zhangc9864272021-09-26 03:52:19 +0000241// A prebuilt version of the systemserverclasspath_fragment module.
242type prebuiltSystemServerClasspathModule struct {
243 SystemServerClasspathModule
244 prebuilt android.Prebuilt
245}
246
247func (module *prebuiltSystemServerClasspathModule) Prebuilt() *android.Prebuilt {
248 return &module.prebuilt
249}
250
251func (module *prebuiltSystemServerClasspathModule) Name() string {
252 return module.prebuilt.Name(module.ModuleBase.Name())
253}
254
Jiakai Zhang774dd302021-09-26 03:54:25 +0000255func (module *prebuiltSystemServerClasspathModule) RequiredFilesFromPrebuiltApex(ctx android.BaseModuleContext) []string {
256 return nil
257}
258
259var _ android.RequiredFilesFromPrebuiltApex = (*prebuiltSystemServerClasspathModule)(nil)
260
Jiakai Zhangc9864272021-09-26 03:52:19 +0000261func prebuiltSystemServerClasspathModuleFactory() android.Module {
262 m := &prebuiltSystemServerClasspathModule{}
263 m.AddProperties(&m.properties)
264 // This doesn't actually have any prebuilt files of its own so pass a placeholder for the srcs
265 // array.
266 android.InitPrebuiltModule(m, &[]string{"placeholder"})
267 android.InitApexModule(m)
Jiakai Zhanga8d86602021-09-26 09:02:17 +0000268 android.InitSdkAwareModule(m)
Jiakai Zhangc9864272021-09-26 03:52:19 +0000269 android.InitAndroidArchModule(m, android.DeviceSupported, android.MultilibCommon)
270 return m
271}