blob: b5f52fd10901eea9abb1f7dd03c2af13207c2457 [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)
satayevd34eb0c2021-08-06 13:20:28 +0100127 // For non test apexes, make sure that all contents are actually declared in make.
Jiakai Zhanga8d86602021-09-26 09:02:17 +0000128 if global.ApexSystemServerJars.Len() > 0 && len(unknown) > 0 && !android.IsModuleInVersionedSdk(ctx.Module()) {
Ulya Trafimoviche5b2b492021-10-04 15:42:53 +0100129 ctx.ModuleErrorf("%s in contents must also be declared in PRODUCT_APEX_SYSTEM_SERVER_JARS", unknown)
satayevd34eb0c2021-08-06 13:20:28 +0100130 }
131
132 return jars
satayevaa86bac2021-05-13 19:01:52 +0100133}
satayev9366a052021-05-17 21:13:44 +0100134
135type systemServerClasspathFragmentContentDependencyTag struct {
136 blueprint.BaseDependencyTag
137}
138
Paul Duffin25322e42021-09-07 14:52:48 +0100139// The systemserverclasspath_fragment contents must never depend on prebuilts.
140func (systemServerClasspathFragmentContentDependencyTag) ReplaceSourceWithPrebuilt() bool {
141 return false
142}
143
Jiakai Zhanga8d86602021-09-26 09:02:17 +0000144// SdkMemberType causes dependencies added with this tag to be automatically added to the sdk as if
145// they were specified using java_systemserver_libs or java_sdk_libs.
146func (b systemServerClasspathFragmentContentDependencyTag) SdkMemberType(child android.Module) android.SdkMemberType {
147 // If the module is a java_sdk_library then treat it as if it was specified in the java_sdk_libs
148 // property, otherwise treat if it was specified in the java_systemserver_libs property.
149 if javaSdkLibrarySdkMemberType.IsInstance(child) {
150 return javaSdkLibrarySdkMemberType
151 }
152
153 return javaSystemserverLibsSdkMemberType
154}
155
156func (b systemServerClasspathFragmentContentDependencyTag) ExportMember() bool {
157 return true
158}
159
Colin Crossc33e5212021-05-25 18:16:02 -0700160// Contents of system server fragments in an apex are considered to be directly in the apex, as if
161// they were listed in java_libs.
162func (systemServerClasspathFragmentContentDependencyTag) CopyDirectlyInAnyApex() {}
163
Jiakai Zhang774dd302021-09-26 03:54:25 +0000164// Contents of system server fragments require files from prebuilt apex files.
165func (systemServerClasspathFragmentContentDependencyTag) RequiresFilesFromPrebuiltApex() {}
166
Paul Duffin25322e42021-09-07 14:52:48 +0100167var _ android.ReplaceSourceWithPrebuilt = systemServerClasspathFragmentContentDepTag
Jiakai Zhanga8d86602021-09-26 09:02:17 +0000168var _ android.SdkMemberDependencyTag = systemServerClasspathFragmentContentDepTag
Colin Crossc33e5212021-05-25 18:16:02 -0700169var _ android.CopyDirectlyInAnyApexTag = systemServerClasspathFragmentContentDepTag
Jiakai Zhang774dd302021-09-26 03:54:25 +0000170var _ android.RequiresFilesFromPrebuiltApexTag = systemServerClasspathFragmentContentDepTag
Colin Crossc33e5212021-05-25 18:16:02 -0700171
satayev9366a052021-05-17 21:13:44 +0100172// The tag used for the dependency between the systemserverclasspath_fragment module and its contents.
173var systemServerClasspathFragmentContentDepTag = systemServerClasspathFragmentContentDependencyTag{}
174
175func IsSystemServerClasspathFragmentContentDepTag(tag blueprint.DependencyTag) bool {
176 return tag == systemServerClasspathFragmentContentDepTag
177}
178
satayev333a1732021-05-17 21:35:26 +0100179func (s *SystemServerClasspathModule) ComponentDepsMutator(ctx android.BottomUpMutatorContext) {
satayev9366a052021-05-17 21:13:44 +0100180 module := ctx.Module()
Jiakai Zhangc9864272021-09-26 03:52:19 +0000181 _, isSourceModule := module.(*SystemServerClasspathModule)
satayev9366a052021-05-17 21:13:44 +0100182
183 for _, name := range s.properties.Contents {
Jiakai Zhangc9864272021-09-26 03:52:19 +0000184 // A systemserverclasspath_fragment must depend only on other source modules, while the
185 // prebuilt_systemserverclasspath_fragment_fragment must only depend on other prebuilt modules.
186 if !isSourceModule {
187 name = android.PrebuiltNameFromSource(name)
188 }
satayev9366a052021-05-17 21:13:44 +0100189 ctx.AddDependency(module, systemServerClasspathFragmentContentDepTag, name)
190 }
191}
braleeb0c1f0c2021-06-07 22:49:13 +0800192
193// Collect information for opening IDE project files in java/jdeps.go.
194func (s *SystemServerClasspathModule) IDEInfo(dpInfo *android.IdeInfo) {
195 dpInfo.Deps = append(dpInfo.Deps, s.properties.Contents...)
196 dpInfo.Paths = append(dpInfo.Paths, s.modulePaths...)
197}
Jiakai Zhangc9864272021-09-26 03:52:19 +0000198
Jiakai Zhanga8d86602021-09-26 09:02:17 +0000199type systemServerClasspathFragmentMemberType struct {
200 android.SdkMemberTypeBase
201}
202
203func (s *systemServerClasspathFragmentMemberType) AddDependencies(ctx android.SdkDependencyContext, dependencyTag blueprint.DependencyTag, names []string) {
204 ctx.AddVariationDependencies(nil, dependencyTag, names...)
205}
206
207func (s *systemServerClasspathFragmentMemberType) IsInstance(module android.Module) bool {
208 _, ok := module.(*SystemServerClasspathModule)
209 return ok
210}
211
212func (s *systemServerClasspathFragmentMemberType) AddPrebuiltModule(ctx android.SdkMemberContext, member android.SdkMember) android.BpModule {
213 return ctx.SnapshotBuilder().AddPrebuiltModule(member, "prebuilt_systemserverclasspath_fragment")
214}
215
216func (s *systemServerClasspathFragmentMemberType) CreateVariantPropertiesStruct() android.SdkMemberProperties {
217 return &systemServerClasspathFragmentSdkMemberProperties{}
218}
219
220type systemServerClasspathFragmentSdkMemberProperties struct {
221 android.SdkMemberPropertiesBase
222
223 // Contents of the systemserverclasspath fragment
224 Contents []string
225}
226
227func (s *systemServerClasspathFragmentSdkMemberProperties) PopulateFromVariant(ctx android.SdkMemberContext, variant android.Module) {
228 module := variant.(*SystemServerClasspathModule)
229
230 s.Contents = module.properties.Contents
231}
232
233func (s *systemServerClasspathFragmentSdkMemberProperties) AddToPropertySet(ctx android.SdkMemberContext, propertySet android.BpPropertySet) {
234 builder := ctx.SnapshotBuilder()
235 requiredMemberDependency := builder.SdkMemberReferencePropertyTag(true)
236
237 if len(s.Contents) > 0 {
238 propertySet.AddPropertyWithTag("contents", s.Contents, requiredMemberDependency)
239 }
240}
241
242var _ android.SdkMemberType = (*systemServerClasspathFragmentMemberType)(nil)
243
Jiakai Zhangc9864272021-09-26 03:52:19 +0000244// A prebuilt version of the systemserverclasspath_fragment module.
245type prebuiltSystemServerClasspathModule struct {
246 SystemServerClasspathModule
247 prebuilt android.Prebuilt
248}
249
250func (module *prebuiltSystemServerClasspathModule) Prebuilt() *android.Prebuilt {
251 return &module.prebuilt
252}
253
254func (module *prebuiltSystemServerClasspathModule) Name() string {
255 return module.prebuilt.Name(module.ModuleBase.Name())
256}
257
Jiakai Zhang774dd302021-09-26 03:54:25 +0000258func (module *prebuiltSystemServerClasspathModule) RequiredFilesFromPrebuiltApex(ctx android.BaseModuleContext) []string {
259 return nil
260}
261
262var _ android.RequiredFilesFromPrebuiltApex = (*prebuiltSystemServerClasspathModule)(nil)
263
Jiakai Zhangc9864272021-09-26 03:52:19 +0000264func prebuiltSystemServerClasspathModuleFactory() android.Module {
265 m := &prebuiltSystemServerClasspathModule{}
266 m.AddProperties(&m.properties)
267 // This doesn't actually have any prebuilt files of its own so pass a placeholder for the srcs
268 // array.
269 android.InitPrebuiltModule(m, &[]string{"placeholder"})
270 android.InitApexModule(m)
Jiakai Zhanga8d86602021-09-26 09:02:17 +0000271 android.InitSdkAwareModule(m)
Jiakai Zhangc9864272021-09-26 03:52:19 +0000272 android.InitAndroidArchModule(m, android.DeviceSupported, android.MultilibCommon)
273 return m
274}