blob: 26796a6ccfab75b1d09ec879ceb3eccc8fa55a31 [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)
26}
27
28func registerSystemserverClasspathBuildComponents(ctx android.RegistrationContext) {
satayev95e9c5b2021-04-29 11:50:26 +010029 ctx.RegisterModuleType("platform_systemserverclasspath", platformSystemServerClasspathFactory)
satayevaa86bac2021-05-13 19:01:52 +010030 ctx.RegisterModuleType("systemserverclasspath_fragment", systemServerClasspathFactory)
Jiakai Zhangc9864272021-09-26 03:52:19 +000031 ctx.RegisterModuleType("prebuilt_systemserverclasspath_fragment", prebuiltSystemServerClasspathModuleFactory)
satayev95e9c5b2021-04-29 11:50:26 +010032}
33
34type platformSystemServerClasspathModule struct {
35 android.ModuleBase
36
37 ClasspathFragmentBase
38}
39
40func platformSystemServerClasspathFactory() android.Module {
41 m := &platformSystemServerClasspathModule{}
42 initClasspathFragment(m, SYSTEMSERVERCLASSPATH)
43 android.InitAndroidArchModule(m, android.DeviceSupported, android.MultilibCommon)
44 return m
45}
46
satayevaa86bac2021-05-13 19:01:52 +010047func (p *platformSystemServerClasspathModule) AndroidMkEntries() (entries []android.AndroidMkEntries) {
48 return p.classpathFragmentBase().androidMkEntries()
satayev95e9c5b2021-04-29 11:50:26 +010049}
50
satayevaa86bac2021-05-13 19:01:52 +010051func (p *platformSystemServerClasspathModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
satayevb3090502021-06-15 17:49:10 +010052 configuredJars := p.configuredJars(ctx)
53 classpathJars := configuredJarListToClasspathJars(ctx, configuredJars, p.classpathType)
54 p.classpathFragmentBase().generateClasspathProtoBuildActions(ctx, configuredJars, classpathJars)
satayev013485b2021-05-06 23:38:10 +010055}
56
satayev142ed272021-06-15 16:21:17 +010057func (p *platformSystemServerClasspathModule) configuredJars(ctx android.ModuleContext) android.ConfiguredJarList {
satayevb3090502021-06-15 17:49:10 +010058 // TODO(satayev): include any apex jars that don't populate their classpath proto config.
59 return dexpreopt.GetGlobalConfig(ctx).SystemServerJars
satayev95e9c5b2021-04-29 11:50:26 +010060}
satayevaa86bac2021-05-13 19:01:52 +010061
satayev333a1732021-05-17 21:35:26 +010062type SystemServerClasspathModule struct {
satayevaa86bac2021-05-13 19:01:52 +010063 android.ModuleBase
satayev333a1732021-05-17 21:35:26 +010064 android.ApexModuleBase
satayevaa86bac2021-05-13 19:01:52 +010065
66 ClasspathFragmentBase
satayev9366a052021-05-17 21:13:44 +010067
68 properties systemServerClasspathFragmentProperties
braleeb0c1f0c2021-06-07 22:49:13 +080069
70 // Collect the module directory for IDE info in java/jdeps.go.
71 modulePaths []string
satayev9366a052021-05-17 21:13:44 +010072}
73
satayev333a1732021-05-17 21:35:26 +010074func (s *SystemServerClasspathModule) ShouldSupportSdkVersion(ctx android.BaseModuleContext, sdkVersion android.ApiLevel) error {
75 return nil
76}
77
satayev9366a052021-05-17 21:13:44 +010078type systemServerClasspathFragmentProperties struct {
79 // The contents of this systemserverclasspath_fragment, could be either java_library, or java_sdk_library.
80 //
81 // The order of this list matters as it is the order that is used in the SYSTEMSERVERCLASSPATH.
82 Contents []string
satayevaa86bac2021-05-13 19:01:52 +010083}
84
85func systemServerClasspathFactory() android.Module {
satayev333a1732021-05-17 21:35:26 +010086 m := &SystemServerClasspathModule{}
satayev9366a052021-05-17 21:13:44 +010087 m.AddProperties(&m.properties)
satayev333a1732021-05-17 21:35:26 +010088 android.InitApexModule(m)
satayevaa86bac2021-05-13 19:01:52 +010089 initClasspathFragment(m, SYSTEMSERVERCLASSPATH)
90 android.InitAndroidArchModule(m, android.DeviceSupported, android.MultilibCommon)
91 return m
92}
93
satayev333a1732021-05-17 21:35:26 +010094func (s *SystemServerClasspathModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
satayev9366a052021-05-17 21:13:44 +010095 if len(s.properties.Contents) == 0 {
96 ctx.PropertyErrorf("contents", "empty contents are not allowed")
97 }
98
satayevb3090502021-06-15 17:49:10 +010099 configuredJars := s.configuredJars(ctx)
100 classpathJars := configuredJarListToClasspathJars(ctx, configuredJars, s.classpathType)
101 s.classpathFragmentBase().generateClasspathProtoBuildActions(ctx, configuredJars, classpathJars)
braleeb0c1f0c2021-06-07 22:49:13 +0800102
103 // Collect the module directory for IDE info in java/jdeps.go.
104 s.modulePaths = append(s.modulePaths, ctx.ModuleDir())
satayevaa86bac2021-05-13 19:01:52 +0100105}
106
satayev142ed272021-06-15 16:21:17 +0100107func (s *SystemServerClasspathModule) configuredJars(ctx android.ModuleContext) android.ConfiguredJarList {
satayev703c67a2021-05-20 21:33:41 +0100108 global := dexpreopt.GetGlobalConfig(ctx)
109
satayevd604b212021-07-21 14:23:52 +0100110 possibleUpdatableModules := gatherPossibleApexModuleNamesAndStems(ctx, s.properties.Contents, systemServerClasspathFragmentContentDepTag)
satayevd34eb0c2021-08-06 13:20:28 +0100111 jars, unknown := global.ApexSystemServerJars.Filter(possibleUpdatableModules)
112 // TODO(satayev): remove geotz ssc_fragment, since geotz is not part of SSCP anymore.
113 _, unknown = android.RemoveFromList("geotz", unknown)
114
115 // For non test apexes, make sure that all contents are actually declared in make.
116 if global.ApexSystemServerJars.Len() > 0 && len(unknown) > 0 {
117 ctx.ModuleErrorf("%s in contents must also be declared in PRODUCT_UPDATABLE_SYSTEM_SERVER_JARS", unknown)
118 }
119
120 return jars
satayevaa86bac2021-05-13 19:01:52 +0100121}
satayev9366a052021-05-17 21:13:44 +0100122
123type systemServerClasspathFragmentContentDependencyTag struct {
124 blueprint.BaseDependencyTag
125}
126
Paul Duffin25322e42021-09-07 14:52:48 +0100127// The systemserverclasspath_fragment contents must never depend on prebuilts.
128func (systemServerClasspathFragmentContentDependencyTag) ReplaceSourceWithPrebuilt() bool {
129 return false
130}
131
Colin Crossc33e5212021-05-25 18:16:02 -0700132// Contents of system server fragments in an apex are considered to be directly in the apex, as if
133// they were listed in java_libs.
134func (systemServerClasspathFragmentContentDependencyTag) CopyDirectlyInAnyApex() {}
135
Jiakai Zhang774dd302021-09-26 03:54:25 +0000136// Contents of system server fragments require files from prebuilt apex files.
137func (systemServerClasspathFragmentContentDependencyTag) RequiresFilesFromPrebuiltApex() {}
138
Paul Duffin25322e42021-09-07 14:52:48 +0100139var _ android.ReplaceSourceWithPrebuilt = systemServerClasspathFragmentContentDepTag
Colin Crossc33e5212021-05-25 18:16:02 -0700140var _ android.CopyDirectlyInAnyApexTag = systemServerClasspathFragmentContentDepTag
Jiakai Zhang774dd302021-09-26 03:54:25 +0000141var _ android.RequiresFilesFromPrebuiltApexTag = systemServerClasspathFragmentContentDepTag
Colin Crossc33e5212021-05-25 18:16:02 -0700142
satayev9366a052021-05-17 21:13:44 +0100143// The tag used for the dependency between the systemserverclasspath_fragment module and its contents.
144var systemServerClasspathFragmentContentDepTag = systemServerClasspathFragmentContentDependencyTag{}
145
146func IsSystemServerClasspathFragmentContentDepTag(tag blueprint.DependencyTag) bool {
147 return tag == systemServerClasspathFragmentContentDepTag
148}
149
satayev333a1732021-05-17 21:35:26 +0100150func (s *SystemServerClasspathModule) ComponentDepsMutator(ctx android.BottomUpMutatorContext) {
satayev9366a052021-05-17 21:13:44 +0100151 module := ctx.Module()
Jiakai Zhangc9864272021-09-26 03:52:19 +0000152 _, isSourceModule := module.(*SystemServerClasspathModule)
satayev9366a052021-05-17 21:13:44 +0100153
154 for _, name := range s.properties.Contents {
Jiakai Zhangc9864272021-09-26 03:52:19 +0000155 // A systemserverclasspath_fragment must depend only on other source modules, while the
156 // prebuilt_systemserverclasspath_fragment_fragment must only depend on other prebuilt modules.
157 if !isSourceModule {
158 name = android.PrebuiltNameFromSource(name)
159 }
satayev9366a052021-05-17 21:13:44 +0100160 ctx.AddDependency(module, systemServerClasspathFragmentContentDepTag, name)
161 }
162}
braleeb0c1f0c2021-06-07 22:49:13 +0800163
164// Collect information for opening IDE project files in java/jdeps.go.
165func (s *SystemServerClasspathModule) IDEInfo(dpInfo *android.IdeInfo) {
166 dpInfo.Deps = append(dpInfo.Deps, s.properties.Contents...)
167 dpInfo.Paths = append(dpInfo.Paths, s.modulePaths...)
168}
Jiakai Zhangc9864272021-09-26 03:52:19 +0000169
170// A prebuilt version of the systemserverclasspath_fragment module.
171type prebuiltSystemServerClasspathModule struct {
172 SystemServerClasspathModule
173 prebuilt android.Prebuilt
174}
175
176func (module *prebuiltSystemServerClasspathModule) Prebuilt() *android.Prebuilt {
177 return &module.prebuilt
178}
179
180func (module *prebuiltSystemServerClasspathModule) Name() string {
181 return module.prebuilt.Name(module.ModuleBase.Name())
182}
183
Jiakai Zhang774dd302021-09-26 03:54:25 +0000184func (module *prebuiltSystemServerClasspathModule) RequiredFilesFromPrebuiltApex(ctx android.BaseModuleContext) []string {
185 return nil
186}
187
188var _ android.RequiredFilesFromPrebuiltApex = (*prebuiltSystemServerClasspathModule)(nil)
189
Jiakai Zhangc9864272021-09-26 03:52:19 +0000190func prebuiltSystemServerClasspathModuleFactory() android.Module {
191 m := &prebuiltSystemServerClasspathModule{}
192 m.AddProperties(&m.properties)
193 // This doesn't actually have any prebuilt files of its own so pass a placeholder for the srcs
194 // array.
195 android.InitPrebuiltModule(m, &[]string{"placeholder"})
196 android.InitApexModule(m)
197 android.InitAndroidArchModule(m, android.DeviceSupported, android.MultilibCommon)
198 return m
199}