satayev | 95e9c5b | 2021-04-29 11:50:26 +0100 | [diff] [blame] | 1 | // 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 | |
| 15 | package java |
| 16 | |
| 17 | import ( |
| 18 | "android/soong/android" |
satayev | 013485b | 2021-05-06 23:38:10 +0100 | [diff] [blame] | 19 | "android/soong/dexpreopt" |
Colin Cross | c33e521 | 2021-05-25 18:16:02 -0700 | [diff] [blame] | 20 | |
satayev | 9366a05 | 2021-05-17 21:13:44 +0100 | [diff] [blame] | 21 | "github.com/google/blueprint" |
satayev | 95e9c5b | 2021-04-29 11:50:26 +0100 | [diff] [blame] | 22 | ) |
| 23 | |
| 24 | func init() { |
| 25 | registerSystemserverClasspathBuildComponents(android.InitRegistrationContext) |
Jiakai Zhang | a8d8660 | 2021-09-26 09:02:17 +0000 | [diff] [blame] | 26 | |
| 27 | android.RegisterSdkMemberType(&systemServerClasspathFragmentMemberType{ |
| 28 | SdkMemberTypeBase: android.SdkMemberTypeBase{ |
| 29 | PropertyName: "systemserverclasspath_fragments", |
| 30 | SupportsSdk: true, |
| 31 | }, |
| 32 | }) |
satayev | 95e9c5b | 2021-04-29 11:50:26 +0100 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | func registerSystemserverClasspathBuildComponents(ctx android.RegistrationContext) { |
satayev | 95e9c5b | 2021-04-29 11:50:26 +0100 | [diff] [blame] | 36 | ctx.RegisterModuleType("platform_systemserverclasspath", platformSystemServerClasspathFactory) |
satayev | aa86bac | 2021-05-13 19:01:52 +0100 | [diff] [blame] | 37 | ctx.RegisterModuleType("systemserverclasspath_fragment", systemServerClasspathFactory) |
Jiakai Zhang | c986427 | 2021-09-26 03:52:19 +0000 | [diff] [blame] | 38 | ctx.RegisterModuleType("prebuilt_systemserverclasspath_fragment", prebuiltSystemServerClasspathModuleFactory) |
satayev | 95e9c5b | 2021-04-29 11:50:26 +0100 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | type platformSystemServerClasspathModule struct { |
| 42 | android.ModuleBase |
| 43 | |
| 44 | ClasspathFragmentBase |
| 45 | } |
| 46 | |
| 47 | func platformSystemServerClasspathFactory() android.Module { |
| 48 | m := &platformSystemServerClasspathModule{} |
| 49 | initClasspathFragment(m, SYSTEMSERVERCLASSPATH) |
| 50 | android.InitAndroidArchModule(m, android.DeviceSupported, android.MultilibCommon) |
| 51 | return m |
| 52 | } |
| 53 | |
satayev | aa86bac | 2021-05-13 19:01:52 +0100 | [diff] [blame] | 54 | func (p *platformSystemServerClasspathModule) AndroidMkEntries() (entries []android.AndroidMkEntries) { |
| 55 | return p.classpathFragmentBase().androidMkEntries() |
satayev | 95e9c5b | 2021-04-29 11:50:26 +0100 | [diff] [blame] | 56 | } |
| 57 | |
satayev | aa86bac | 2021-05-13 19:01:52 +0100 | [diff] [blame] | 58 | func (p *platformSystemServerClasspathModule) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
satayev | b309050 | 2021-06-15 17:49:10 +0100 | [diff] [blame] | 59 | configuredJars := p.configuredJars(ctx) |
| 60 | classpathJars := configuredJarListToClasspathJars(ctx, configuredJars, p.classpathType) |
| 61 | p.classpathFragmentBase().generateClasspathProtoBuildActions(ctx, configuredJars, classpathJars) |
satayev | 013485b | 2021-05-06 23:38:10 +0100 | [diff] [blame] | 62 | } |
| 63 | |
satayev | 142ed27 | 2021-06-15 16:21:17 +0100 | [diff] [blame] | 64 | func (p *platformSystemServerClasspathModule) configuredJars(ctx android.ModuleContext) android.ConfiguredJarList { |
satayev | b309050 | 2021-06-15 17:49:10 +0100 | [diff] [blame] | 65 | // TODO(satayev): include any apex jars that don't populate their classpath proto config. |
| 66 | return dexpreopt.GetGlobalConfig(ctx).SystemServerJars |
satayev | 95e9c5b | 2021-04-29 11:50:26 +0100 | [diff] [blame] | 67 | } |
satayev | aa86bac | 2021-05-13 19:01:52 +0100 | [diff] [blame] | 68 | |
satayev | 333a173 | 2021-05-17 21:35:26 +0100 | [diff] [blame] | 69 | type SystemServerClasspathModule struct { |
satayev | aa86bac | 2021-05-13 19:01:52 +0100 | [diff] [blame] | 70 | android.ModuleBase |
satayev | 333a173 | 2021-05-17 21:35:26 +0100 | [diff] [blame] | 71 | android.ApexModuleBase |
Jiakai Zhang | a8d8660 | 2021-09-26 09:02:17 +0000 | [diff] [blame] | 72 | android.SdkBase |
satayev | aa86bac | 2021-05-13 19:01:52 +0100 | [diff] [blame] | 73 | |
| 74 | ClasspathFragmentBase |
satayev | 9366a05 | 2021-05-17 21:13:44 +0100 | [diff] [blame] | 75 | |
| 76 | properties systemServerClasspathFragmentProperties |
bralee | b0c1f0c | 2021-06-07 22:49:13 +0800 | [diff] [blame] | 77 | |
| 78 | // Collect the module directory for IDE info in java/jdeps.go. |
| 79 | modulePaths []string |
satayev | 9366a05 | 2021-05-17 21:13:44 +0100 | [diff] [blame] | 80 | } |
| 81 | |
satayev | 333a173 | 2021-05-17 21:35:26 +0100 | [diff] [blame] | 82 | func (s *SystemServerClasspathModule) ShouldSupportSdkVersion(ctx android.BaseModuleContext, sdkVersion android.ApiLevel) error { |
| 83 | return nil |
| 84 | } |
| 85 | |
satayev | 9366a05 | 2021-05-17 21:13:44 +0100 | [diff] [blame] | 86 | type 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 |
satayev | aa86bac | 2021-05-13 19:01:52 +0100 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | func systemServerClasspathFactory() android.Module { |
satayev | 333a173 | 2021-05-17 21:35:26 +0100 | [diff] [blame] | 94 | m := &SystemServerClasspathModule{} |
satayev | 9366a05 | 2021-05-17 21:13:44 +0100 | [diff] [blame] | 95 | m.AddProperties(&m.properties) |
satayev | 333a173 | 2021-05-17 21:35:26 +0100 | [diff] [blame] | 96 | android.InitApexModule(m) |
Jiakai Zhang | a8d8660 | 2021-09-26 09:02:17 +0000 | [diff] [blame] | 97 | android.InitSdkAwareModule(m) |
satayev | aa86bac | 2021-05-13 19:01:52 +0100 | [diff] [blame] | 98 | initClasspathFragment(m, SYSTEMSERVERCLASSPATH) |
| 99 | android.InitAndroidArchModule(m, android.DeviceSupported, android.MultilibCommon) |
| 100 | return m |
| 101 | } |
| 102 | |
satayev | 333a173 | 2021-05-17 21:35:26 +0100 | [diff] [blame] | 103 | func (s *SystemServerClasspathModule) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
satayev | 9366a05 | 2021-05-17 21:13:44 +0100 | [diff] [blame] | 104 | if len(s.properties.Contents) == 0 { |
| 105 | ctx.PropertyErrorf("contents", "empty contents are not allowed") |
| 106 | } |
| 107 | |
satayev | b309050 | 2021-06-15 17:49:10 +0100 | [diff] [blame] | 108 | configuredJars := s.configuredJars(ctx) |
| 109 | classpathJars := configuredJarListToClasspathJars(ctx, configuredJars, s.classpathType) |
| 110 | s.classpathFragmentBase().generateClasspathProtoBuildActions(ctx, configuredJars, classpathJars) |
bralee | b0c1f0c | 2021-06-07 22:49:13 +0800 | [diff] [blame] | 111 | |
| 112 | // Collect the module directory for IDE info in java/jdeps.go. |
| 113 | s.modulePaths = append(s.modulePaths, ctx.ModuleDir()) |
satayev | aa86bac | 2021-05-13 19:01:52 +0100 | [diff] [blame] | 114 | } |
| 115 | |
satayev | 142ed27 | 2021-06-15 16:21:17 +0100 | [diff] [blame] | 116 | func (s *SystemServerClasspathModule) configuredJars(ctx android.ModuleContext) android.ConfiguredJarList { |
satayev | 703c67a | 2021-05-20 21:33:41 +0100 | [diff] [blame] | 117 | global := dexpreopt.GetGlobalConfig(ctx) |
| 118 | |
satayev | d604b21 | 2021-07-21 14:23:52 +0100 | [diff] [blame] | 119 | possibleUpdatableModules := gatherPossibleApexModuleNamesAndStems(ctx, s.properties.Contents, systemServerClasspathFragmentContentDepTag) |
satayev | d34eb0c | 2021-08-06 13:20:28 +0100 | [diff] [blame] | 120 | 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 Zhang | a8d8660 | 2021-09-26 09:02:17 +0000 | [diff] [blame] | 125 | if global.ApexSystemServerJars.Len() > 0 && len(unknown) > 0 && !android.IsModuleInVersionedSdk(ctx.Module()) { |
Ulya Trafimovich | e5b2b49 | 2021-10-04 15:42:53 +0100 | [diff] [blame^] | 126 | ctx.ModuleErrorf("%s in contents must also be declared in PRODUCT_APEX_SYSTEM_SERVER_JARS", unknown) |
satayev | d34eb0c | 2021-08-06 13:20:28 +0100 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | return jars |
satayev | aa86bac | 2021-05-13 19:01:52 +0100 | [diff] [blame] | 130 | } |
satayev | 9366a05 | 2021-05-17 21:13:44 +0100 | [diff] [blame] | 131 | |
| 132 | type systemServerClasspathFragmentContentDependencyTag struct { |
| 133 | blueprint.BaseDependencyTag |
| 134 | } |
| 135 | |
Paul Duffin | 25322e4 | 2021-09-07 14:52:48 +0100 | [diff] [blame] | 136 | // The systemserverclasspath_fragment contents must never depend on prebuilts. |
| 137 | func (systemServerClasspathFragmentContentDependencyTag) ReplaceSourceWithPrebuilt() bool { |
| 138 | return false |
| 139 | } |
| 140 | |
Jiakai Zhang | a8d8660 | 2021-09-26 09:02:17 +0000 | [diff] [blame] | 141 | // 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. |
| 143 | func (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 | |
| 153 | func (b systemServerClasspathFragmentContentDependencyTag) ExportMember() bool { |
| 154 | return true |
| 155 | } |
| 156 | |
Colin Cross | c33e521 | 2021-05-25 18:16:02 -0700 | [diff] [blame] | 157 | // 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. |
| 159 | func (systemServerClasspathFragmentContentDependencyTag) CopyDirectlyInAnyApex() {} |
| 160 | |
Jiakai Zhang | 774dd30 | 2021-09-26 03:54:25 +0000 | [diff] [blame] | 161 | // Contents of system server fragments require files from prebuilt apex files. |
| 162 | func (systemServerClasspathFragmentContentDependencyTag) RequiresFilesFromPrebuiltApex() {} |
| 163 | |
Paul Duffin | 25322e4 | 2021-09-07 14:52:48 +0100 | [diff] [blame] | 164 | var _ android.ReplaceSourceWithPrebuilt = systemServerClasspathFragmentContentDepTag |
Jiakai Zhang | a8d8660 | 2021-09-26 09:02:17 +0000 | [diff] [blame] | 165 | var _ android.SdkMemberDependencyTag = systemServerClasspathFragmentContentDepTag |
Colin Cross | c33e521 | 2021-05-25 18:16:02 -0700 | [diff] [blame] | 166 | var _ android.CopyDirectlyInAnyApexTag = systemServerClasspathFragmentContentDepTag |
Jiakai Zhang | 774dd30 | 2021-09-26 03:54:25 +0000 | [diff] [blame] | 167 | var _ android.RequiresFilesFromPrebuiltApexTag = systemServerClasspathFragmentContentDepTag |
Colin Cross | c33e521 | 2021-05-25 18:16:02 -0700 | [diff] [blame] | 168 | |
satayev | 9366a05 | 2021-05-17 21:13:44 +0100 | [diff] [blame] | 169 | // The tag used for the dependency between the systemserverclasspath_fragment module and its contents. |
| 170 | var systemServerClasspathFragmentContentDepTag = systemServerClasspathFragmentContentDependencyTag{} |
| 171 | |
| 172 | func IsSystemServerClasspathFragmentContentDepTag(tag blueprint.DependencyTag) bool { |
| 173 | return tag == systemServerClasspathFragmentContentDepTag |
| 174 | } |
| 175 | |
satayev | 333a173 | 2021-05-17 21:35:26 +0100 | [diff] [blame] | 176 | func (s *SystemServerClasspathModule) ComponentDepsMutator(ctx android.BottomUpMutatorContext) { |
satayev | 9366a05 | 2021-05-17 21:13:44 +0100 | [diff] [blame] | 177 | module := ctx.Module() |
Jiakai Zhang | c986427 | 2021-09-26 03:52:19 +0000 | [diff] [blame] | 178 | _, isSourceModule := module.(*SystemServerClasspathModule) |
satayev | 9366a05 | 2021-05-17 21:13:44 +0100 | [diff] [blame] | 179 | |
| 180 | for _, name := range s.properties.Contents { |
Jiakai Zhang | c986427 | 2021-09-26 03:52:19 +0000 | [diff] [blame] | 181 | // 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 | } |
satayev | 9366a05 | 2021-05-17 21:13:44 +0100 | [diff] [blame] | 186 | ctx.AddDependency(module, systemServerClasspathFragmentContentDepTag, name) |
| 187 | } |
| 188 | } |
bralee | b0c1f0c | 2021-06-07 22:49:13 +0800 | [diff] [blame] | 189 | |
| 190 | // Collect information for opening IDE project files in java/jdeps.go. |
| 191 | func (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 Zhang | c986427 | 2021-09-26 03:52:19 +0000 | [diff] [blame] | 195 | |
Jiakai Zhang | a8d8660 | 2021-09-26 09:02:17 +0000 | [diff] [blame] | 196 | type systemServerClasspathFragmentMemberType struct { |
| 197 | android.SdkMemberTypeBase |
| 198 | } |
| 199 | |
| 200 | func (s *systemServerClasspathFragmentMemberType) AddDependencies(ctx android.SdkDependencyContext, dependencyTag blueprint.DependencyTag, names []string) { |
| 201 | ctx.AddVariationDependencies(nil, dependencyTag, names...) |
| 202 | } |
| 203 | |
| 204 | func (s *systemServerClasspathFragmentMemberType) IsInstance(module android.Module) bool { |
| 205 | _, ok := module.(*SystemServerClasspathModule) |
| 206 | return ok |
| 207 | } |
| 208 | |
| 209 | func (s *systemServerClasspathFragmentMemberType) AddPrebuiltModule(ctx android.SdkMemberContext, member android.SdkMember) android.BpModule { |
| 210 | return ctx.SnapshotBuilder().AddPrebuiltModule(member, "prebuilt_systemserverclasspath_fragment") |
| 211 | } |
| 212 | |
| 213 | func (s *systemServerClasspathFragmentMemberType) CreateVariantPropertiesStruct() android.SdkMemberProperties { |
| 214 | return &systemServerClasspathFragmentSdkMemberProperties{} |
| 215 | } |
| 216 | |
| 217 | type systemServerClasspathFragmentSdkMemberProperties struct { |
| 218 | android.SdkMemberPropertiesBase |
| 219 | |
| 220 | // Contents of the systemserverclasspath fragment |
| 221 | Contents []string |
| 222 | } |
| 223 | |
| 224 | func (s *systemServerClasspathFragmentSdkMemberProperties) PopulateFromVariant(ctx android.SdkMemberContext, variant android.Module) { |
| 225 | module := variant.(*SystemServerClasspathModule) |
| 226 | |
| 227 | s.Contents = module.properties.Contents |
| 228 | } |
| 229 | |
| 230 | func (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 | |
| 239 | var _ android.SdkMemberType = (*systemServerClasspathFragmentMemberType)(nil) |
| 240 | |
Jiakai Zhang | c986427 | 2021-09-26 03:52:19 +0000 | [diff] [blame] | 241 | // A prebuilt version of the systemserverclasspath_fragment module. |
| 242 | type prebuiltSystemServerClasspathModule struct { |
| 243 | SystemServerClasspathModule |
| 244 | prebuilt android.Prebuilt |
| 245 | } |
| 246 | |
| 247 | func (module *prebuiltSystemServerClasspathModule) Prebuilt() *android.Prebuilt { |
| 248 | return &module.prebuilt |
| 249 | } |
| 250 | |
| 251 | func (module *prebuiltSystemServerClasspathModule) Name() string { |
| 252 | return module.prebuilt.Name(module.ModuleBase.Name()) |
| 253 | } |
| 254 | |
Jiakai Zhang | 774dd30 | 2021-09-26 03:54:25 +0000 | [diff] [blame] | 255 | func (module *prebuiltSystemServerClasspathModule) RequiredFilesFromPrebuiltApex(ctx android.BaseModuleContext) []string { |
| 256 | return nil |
| 257 | } |
| 258 | |
| 259 | var _ android.RequiredFilesFromPrebuiltApex = (*prebuiltSystemServerClasspathModule)(nil) |
| 260 | |
Jiakai Zhang | c986427 | 2021-09-26 03:52:19 +0000 | [diff] [blame] | 261 | func 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 Zhang | a8d8660 | 2021-09-26 09:02:17 +0000 | [diff] [blame] | 268 | android.InitSdkAwareModule(m) |
Jiakai Zhang | c986427 | 2021-09-26 03:52:19 +0000 | [diff] [blame] | 269 | android.InitAndroidArchModule(m, android.DeviceSupported, android.MultilibCommon) |
| 270 | return m |
| 271 | } |