Paul Duffin | bb7f1ac | 2021-03-29 22:18:45 +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 ( |
Paul Duffin | 6a76645 | 2021-04-12 14:15:22 +0100 | [diff] [blame] | 18 | "fmt" |
| 19 | |
Paul Duffin | bb7f1ac | 2021-03-29 22:18:45 +0100 | [diff] [blame] | 20 | "android/soong/android" |
| 21 | "android/soong/dexpreopt" |
| 22 | ) |
| 23 | |
| 24 | func init() { |
| 25 | registerPlatformBootclasspathBuildComponents(android.InitRegistrationContext) |
| 26 | } |
| 27 | |
| 28 | func registerPlatformBootclasspathBuildComponents(ctx android.RegistrationContext) { |
Paul Duffin | e3ecce6 | 2021-04-29 10:34:11 +0100 | [diff] [blame] | 29 | ctx.RegisterSingletonModuleType("platform_bootclasspath", platformBootclasspathFactory) |
Paul Duffin | bb7f1ac | 2021-03-29 22:18:45 +0100 | [diff] [blame] | 30 | } |
| 31 | |
Paul Duffin | 01b463b | 2021-04-26 20:05:39 +0100 | [diff] [blame] | 32 | // The tags used for the dependencies between the platform bootclasspath and any configured boot |
| 33 | // jars. |
| 34 | var ( |
| 35 | platformBootclasspathArtBootJarDepTag = bootclasspathDependencyTag{name: "art-boot-jar"} |
| 36 | platformBootclasspathNonUpdatableBootJarDepTag = bootclasspathDependencyTag{name: "non-updatable-boot-jar"} |
| 37 | platformBootclasspathUpdatableBootJarDepTag = bootclasspathDependencyTag{name: "updatable-boot-jar"} |
| 38 | ) |
Paul Duffin | b432df9 | 2021-03-22 22:09:42 +0000 | [diff] [blame] | 39 | |
Paul Duffin | bb7f1ac | 2021-03-29 22:18:45 +0100 | [diff] [blame] | 40 | type platformBootclasspathModule struct { |
Paul Duffin | e3ecce6 | 2021-04-29 10:34:11 +0100 | [diff] [blame] | 41 | android.SingletonModuleBase |
Artur Satayev | 97259dc | 2021-04-07 15:17:14 +0100 | [diff] [blame] | 42 | ClasspathFragmentBase |
Paul Duffin | b432df9 | 2021-03-22 22:09:42 +0000 | [diff] [blame] | 43 | |
Paul Duffin | 62d8c3b | 2021-04-07 20:35:11 +0100 | [diff] [blame] | 44 | properties platformBootclasspathProperties |
| 45 | |
Paul Duffin | b432df9 | 2021-03-22 22:09:42 +0000 | [diff] [blame] | 46 | // The apex:module pairs obtained from the configured modules. |
| 47 | // |
| 48 | // Currently only for testing. |
| 49 | configuredModules []android.Module |
Paul Duffin | 62d8c3b | 2021-04-07 20:35:11 +0100 | [diff] [blame] | 50 | |
| 51 | // The apex:module pairs obtained from the fragments. |
| 52 | // |
| 53 | // Currently only for testing. |
| 54 | fragments []android.Module |
Paul Duffin | 6a76645 | 2021-04-12 14:15:22 +0100 | [diff] [blame] | 55 | |
| 56 | // Path to the monolithic hiddenapi-flags.csv file. |
Paul Duffin | 0b65986 | 2021-04-13 13:02:29 +0100 | [diff] [blame] | 57 | hiddenAPIFlagsCSV android.OutputPath |
Paul Duffin | 6a76645 | 2021-04-12 14:15:22 +0100 | [diff] [blame] | 58 | |
| 59 | // Path to the monolithic hiddenapi-index.csv file. |
Paul Duffin | 0b65986 | 2021-04-13 13:02:29 +0100 | [diff] [blame] | 60 | hiddenAPIIndexCSV android.OutputPath |
Paul Duffin | 6a76645 | 2021-04-12 14:15:22 +0100 | [diff] [blame] | 61 | |
| 62 | // Path to the monolithic hiddenapi-unsupported.csv file. |
Paul Duffin | 0b65986 | 2021-04-13 13:02:29 +0100 | [diff] [blame] | 63 | hiddenAPIMetadataCSV android.OutputPath |
Paul Duffin | 62d8c3b | 2021-04-07 20:35:11 +0100 | [diff] [blame] | 64 | } |
| 65 | |
Paul Duffin | 62d8c3b | 2021-04-07 20:35:11 +0100 | [diff] [blame] | 66 | type platformBootclasspathProperties struct { |
Paul Duffin | b67d878 | 2021-04-22 11:49:41 +0100 | [diff] [blame] | 67 | BootclasspathFragmentsDepsProperties |
Paul Duffin | 702210b | 2021-04-08 20:12:41 +0100 | [diff] [blame] | 68 | |
Paul Duffin | 4616977 | 2021-04-14 15:01:56 +0100 | [diff] [blame] | 69 | Hidden_api HiddenAPIFlagFileProperties |
Paul Duffin | bb7f1ac | 2021-03-29 22:18:45 +0100 | [diff] [blame] | 70 | } |
| 71 | |
Paul Duffin | e3ecce6 | 2021-04-29 10:34:11 +0100 | [diff] [blame] | 72 | func platformBootclasspathFactory() android.SingletonModule { |
Paul Duffin | bb7f1ac | 2021-03-29 22:18:45 +0100 | [diff] [blame] | 73 | m := &platformBootclasspathModule{} |
Paul Duffin | 62d8c3b | 2021-04-07 20:35:11 +0100 | [diff] [blame] | 74 | m.AddProperties(&m.properties) |
satayev | 95e9c5b | 2021-04-29 11:50:26 +0100 | [diff] [blame] | 75 | // TODO(satayev): split apex jars into separate configs. |
| 76 | initClasspathFragment(m, BOOTCLASSPATH) |
Paul Duffin | bb7f1ac | 2021-03-29 22:18:45 +0100 | [diff] [blame] | 77 | android.InitAndroidArchModule(m, android.DeviceSupported, android.MultilibCommon) |
| 78 | return m |
| 79 | } |
| 80 | |
Paul Duffin | 6a76645 | 2021-04-12 14:15:22 +0100 | [diff] [blame] | 81 | var _ android.OutputFileProducer = (*platformBootclasspathModule)(nil) |
| 82 | |
Artur Satayev | 97259dc | 2021-04-07 15:17:14 +0100 | [diff] [blame] | 83 | func (b *platformBootclasspathModule) AndroidMkEntries() (entries []android.AndroidMkEntries) { |
| 84 | entries = append(entries, android.AndroidMkEntries{ |
| 85 | Class: "FAKE", |
| 86 | // Need at least one output file in order for this to take effect. |
| 87 | OutputFile: android.OptionalPathForPath(b.hiddenAPIFlagsCSV), |
| 88 | Include: "$(BUILD_PHONY_PACKAGE)", |
| 89 | }) |
satayev | 128ce2f | 2021-05-06 13:21:15 +0100 | [diff] [blame] | 90 | entries = append(entries, b.classpathFragmentBase().androidMkEntries()...) |
Artur Satayev | 97259dc | 2021-04-07 15:17:14 +0100 | [diff] [blame] | 91 | return |
Paul Duffin | 6a76645 | 2021-04-12 14:15:22 +0100 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | // Make the hidden API files available from the platform-bootclasspath module. |
| 95 | func (b *platformBootclasspathModule) OutputFiles(tag string) (android.Paths, error) { |
| 96 | switch tag { |
| 97 | case "hiddenapi-flags.csv": |
| 98 | return android.Paths{b.hiddenAPIFlagsCSV}, nil |
| 99 | case "hiddenapi-index.csv": |
| 100 | return android.Paths{b.hiddenAPIIndexCSV}, nil |
| 101 | case "hiddenapi-metadata.csv": |
| 102 | return android.Paths{b.hiddenAPIMetadataCSV}, nil |
| 103 | } |
| 104 | |
| 105 | return nil, fmt.Errorf("unknown tag %s", tag) |
| 106 | } |
| 107 | |
Paul Duffin | bb7f1ac | 2021-03-29 22:18:45 +0100 | [diff] [blame] | 108 | func (b *platformBootclasspathModule) DepsMutator(ctx android.BottomUpMutatorContext) { |
Paul Duffin | 74431d5 | 2021-04-21 14:10:42 +0100 | [diff] [blame] | 109 | b.hiddenAPIDepsMutator(ctx) |
| 110 | |
Paul Duffin | bb7f1ac | 2021-03-29 22:18:45 +0100 | [diff] [blame] | 111 | if SkipDexpreoptBootJars(ctx) { |
| 112 | return |
| 113 | } |
| 114 | |
| 115 | // Add a dependency onto the dex2oat tool which is needed for creating the boot image. The |
| 116 | // path is retrieved from the dependency by GetGlobalSoongConfig(ctx). |
| 117 | dexpreopt.RegisterToolDeps(ctx) |
| 118 | } |
| 119 | |
Paul Duffin | 74431d5 | 2021-04-21 14:10:42 +0100 | [diff] [blame] | 120 | func (b *platformBootclasspathModule) hiddenAPIDepsMutator(ctx android.BottomUpMutatorContext) { |
| 121 | if ctx.Config().IsEnvTrue("UNSAFE_DISABLE_HIDDENAPI_FLAGS") { |
| 122 | return |
| 123 | } |
| 124 | |
| 125 | // Add dependencies onto the stub lib modules. |
| 126 | sdkKindToStubLibModules := hiddenAPIComputeMonolithicStubLibModules(ctx.Config()) |
| 127 | hiddenAPIAddStubLibDependencies(ctx, sdkKindToStubLibModules) |
| 128 | } |
| 129 | |
Paul Duffin | 4994d26 | 2021-04-22 12:08:59 +0100 | [diff] [blame] | 130 | func (b *platformBootclasspathModule) BootclasspathDepsMutator(ctx android.BottomUpMutatorContext) { |
| 131 | // Add dependencies on all the modules configured in the "art" boot image. |
| 132 | artImageConfig := genBootImageConfigs(ctx)[artBootImageName] |
Paul Duffin | 01b463b | 2021-04-26 20:05:39 +0100 | [diff] [blame] | 133 | addDependenciesOntoBootImageModules(ctx, artImageConfig.modules, platformBootclasspathArtBootJarDepTag) |
Paul Duffin | b432df9 | 2021-03-22 22:09:42 +0000 | [diff] [blame] | 134 | |
Paul Duffin | 01b463b | 2021-04-26 20:05:39 +0100 | [diff] [blame] | 135 | // Add dependencies on all the non-updatable module configured in the "boot" boot image. That does |
| 136 | // not include modules configured in the "art" boot image. |
Paul Duffin | 4994d26 | 2021-04-22 12:08:59 +0100 | [diff] [blame] | 137 | bootImageConfig := b.getImageConfig(ctx) |
Paul Duffin | 01b463b | 2021-04-26 20:05:39 +0100 | [diff] [blame] | 138 | addDependenciesOntoBootImageModules(ctx, bootImageConfig.modules, platformBootclasspathNonUpdatableBootJarDepTag) |
Paul Duffin | b432df9 | 2021-03-22 22:09:42 +0000 | [diff] [blame] | 139 | |
Paul Duffin | 4994d26 | 2021-04-22 12:08:59 +0100 | [diff] [blame] | 140 | // Add dependencies on all the updatable modules. |
| 141 | updatableModules := dexpreopt.GetGlobalConfig(ctx).UpdatableBootJars |
Paul Duffin | 01b463b | 2021-04-26 20:05:39 +0100 | [diff] [blame] | 142 | addDependenciesOntoBootImageModules(ctx, updatableModules, platformBootclasspathUpdatableBootJarDepTag) |
Paul Duffin | 62d8c3b | 2021-04-07 20:35:11 +0100 | [diff] [blame] | 143 | |
Paul Duffin | 4994d26 | 2021-04-22 12:08:59 +0100 | [diff] [blame] | 144 | // Add dependencies on all the fragments. |
| 145 | b.properties.BootclasspathFragmentsDepsProperties.addDependenciesOntoFragments(ctx) |
Paul Duffin | b432df9 | 2021-03-22 22:09:42 +0000 | [diff] [blame] | 146 | } |
| 147 | |
Paul Duffin | 01b463b | 2021-04-26 20:05:39 +0100 | [diff] [blame] | 148 | func addDependenciesOntoBootImageModules(ctx android.BottomUpMutatorContext, modules android.ConfiguredJarList, tag bootclasspathDependencyTag) { |
Paul Duffin | b432df9 | 2021-03-22 22:09:42 +0000 | [diff] [blame] | 149 | for i := 0; i < modules.Len(); i++ { |
| 150 | apex := modules.Apex(i) |
| 151 | name := modules.Jar(i) |
| 152 | |
Paul Duffin | 01b463b | 2021-04-26 20:05:39 +0100 | [diff] [blame] | 153 | addDependencyOntoApexModulePair(ctx, apex, name, tag) |
Paul Duffin | b432df9 | 2021-03-22 22:09:42 +0000 | [diff] [blame] | 154 | } |
| 155 | } |
| 156 | |
Paul Duffin | e3ecce6 | 2021-04-29 10:34:11 +0100 | [diff] [blame] | 157 | // GenerateSingletonBuildActions does nothing and must never do anything. |
| 158 | // |
| 159 | // This module only implements android.SingletonModule so that it can implement |
| 160 | // android.SingletonMakeVarsProvider. |
| 161 | func (b *platformBootclasspathModule) GenerateSingletonBuildActions(android.SingletonContext) { |
| 162 | // Keep empty |
| 163 | } |
| 164 | |
| 165 | func (d *platformBootclasspathModule) MakeVars(ctx android.MakeVarsContext) { |
Paul Duffin | 12d29b7 | 2021-04-29 13:50:01 +0100 | [diff] [blame] | 166 | d.generateHiddenApiMakeVars(ctx) |
Paul Duffin | e3ecce6 | 2021-04-29 10:34:11 +0100 | [diff] [blame] | 167 | } |
| 168 | |
Paul Duffin | bb7f1ac | 2021-03-29 22:18:45 +0100 | [diff] [blame] | 169 | func (b *platformBootclasspathModule) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Paul Duffin | 01b463b | 2021-04-26 20:05:39 +0100 | [diff] [blame] | 170 | // Gather all the dependencies from the art, updatable and non-updatable boot jars. |
| 171 | artModules := gatherApexModulePairDepsWithTag(ctx, platformBootclasspathArtBootJarDepTag) |
| 172 | nonUpdatableModules := gatherApexModulePairDepsWithTag(ctx, platformBootclasspathNonUpdatableBootJarDepTag) |
| 173 | updatableModules := gatherApexModulePairDepsWithTag(ctx, platformBootclasspathUpdatableBootJarDepTag) |
| 174 | |
| 175 | // Concatenate them all, in order as they would appear on the bootclasspath. |
| 176 | var allModules []android.Module |
| 177 | allModules = append(allModules, artModules...) |
| 178 | allModules = append(allModules, nonUpdatableModules...) |
| 179 | allModules = append(allModules, updatableModules...) |
| 180 | b.configuredModules = allModules |
| 181 | |
| 182 | // Gather all the fragments dependencies. |
Paul Duffin | 9bacf56 | 2021-04-28 21:16:02 +0100 | [diff] [blame] | 183 | b.fragments = gatherApexModulePairDepsWithTag(ctx, bootclasspathFragmentDepTag) |
Paul Duffin | b432df9 | 2021-03-22 22:09:42 +0000 | [diff] [blame] | 184 | |
Paul Duffin | f23bc47 | 2021-04-27 12:42:20 +0100 | [diff] [blame] | 185 | // Check the configuration of the boot modules. |
| 186 | // ART modules are checked by the art-bootclasspath-fragment. |
| 187 | b.checkNonUpdatableModules(ctx, nonUpdatableModules) |
| 188 | b.checkUpdatableModules(ctx, updatableModules) |
| 189 | |
satayev | 013485b | 2021-05-06 23:38:10 +0100 | [diff] [blame] | 190 | b.generateClasspathProtoBuildActions(ctx) |
| 191 | |
Paul Duffin | 9b381ef | 2021-04-08 23:01:37 +0100 | [diff] [blame] | 192 | b.generateHiddenAPIBuildActions(ctx, b.configuredModules, b.fragments) |
Paul Duffin | 702210b | 2021-04-08 20:12:41 +0100 | [diff] [blame] | 193 | |
Paul Duffin | bb7f1ac | 2021-03-29 22:18:45 +0100 | [diff] [blame] | 194 | // Nothing to do if skipping the dexpreopt of boot image jars. |
| 195 | if SkipDexpreoptBootJars(ctx) { |
| 196 | return |
| 197 | } |
| 198 | |
Paul Duffin | 7ebebfd | 2021-04-27 19:36:57 +0100 | [diff] [blame^] | 199 | b.generateBootImageBuildActions(ctx, nonUpdatableModules, updatableModules) |
Paul Duffin | bb7f1ac | 2021-03-29 22:18:45 +0100 | [diff] [blame] | 200 | } |
| 201 | |
satayev | 013485b | 2021-05-06 23:38:10 +0100 | [diff] [blame] | 202 | // Generate classpaths.proto config |
| 203 | func (b *platformBootclasspathModule) generateClasspathProtoBuildActions(ctx android.ModuleContext) { |
| 204 | // ART and platform boot jars must have a corresponding entry in DEX2OATBOOTCLASSPATH |
| 205 | classpathJars := configuredJarListToClasspathJars(ctx, b.ClasspathFragmentToConfiguredJarList(ctx), BOOTCLASSPATH, DEX2OATBOOTCLASSPATH) |
satayev | 3db3547 | 2021-05-06 23:59:58 +0100 | [diff] [blame] | 206 | |
satayev | 013485b | 2021-05-06 23:38:10 +0100 | [diff] [blame] | 207 | // TODO(satayev): remove updatable boot jars once each apex has its own fragment |
| 208 | global := dexpreopt.GetGlobalConfig(ctx) |
| 209 | classpathJars = append(classpathJars, configuredJarListToClasspathJars(ctx, global.UpdatableBootJars, BOOTCLASSPATH)...) |
| 210 | |
| 211 | b.classpathFragmentBase().generateClasspathProtoBuildActions(ctx, classpathJars) |
| 212 | } |
| 213 | |
| 214 | func (b *platformBootclasspathModule) ClasspathFragmentToConfiguredJarList(ctx android.ModuleContext) android.ConfiguredJarList { |
| 215 | global := dexpreopt.GetGlobalConfig(ctx) |
| 216 | // TODO(satayev): split ART apex jars into their own classpathFragment |
| 217 | return global.BootJars |
| 218 | } |
| 219 | |
Paul Duffin | f23bc47 | 2021-04-27 12:42:20 +0100 | [diff] [blame] | 220 | // checkNonUpdatableModules ensures that the non-updatable modules supplied are not part of an |
| 221 | // updatable module. |
| 222 | func (b *platformBootclasspathModule) checkNonUpdatableModules(ctx android.ModuleContext, modules []android.Module) { |
| 223 | for _, m := range modules { |
| 224 | apexInfo := ctx.OtherModuleProvider(m, android.ApexInfoProvider).(android.ApexInfo) |
| 225 | fromUpdatableApex := apexInfo.Updatable |
| 226 | if fromUpdatableApex { |
| 227 | // error: this jar is part of an updatable apex |
| 228 | ctx.ModuleErrorf("module %q from updatable apexes %q is not allowed in the framework boot image", ctx.OtherModuleName(m), apexInfo.InApexes) |
| 229 | } else { |
| 230 | // ok: this jar is part of the platform or a non-updatable apex |
| 231 | } |
| 232 | } |
| 233 | } |
| 234 | |
| 235 | // checkUpdatableModules ensures that the updatable modules supplied are not from the platform. |
| 236 | func (b *platformBootclasspathModule) checkUpdatableModules(ctx android.ModuleContext, modules []android.Module) { |
| 237 | for _, m := range modules { |
| 238 | apexInfo := ctx.OtherModuleProvider(m, android.ApexInfoProvider).(android.ApexInfo) |
| 239 | fromUpdatableApex := apexInfo.Updatable |
| 240 | if fromUpdatableApex { |
| 241 | // ok: this jar is part of an updatable apex |
| 242 | } else { |
| 243 | name := ctx.OtherModuleName(m) |
| 244 | if apexInfo.IsForPlatform() { |
| 245 | // error: this jar is part of the platform |
| 246 | ctx.ModuleErrorf("module %q from platform is not allowed in the updatable boot jars list", name) |
| 247 | } else { |
| 248 | // TODO(b/177892522): Treat this as an error. |
| 249 | // Cannot do that at the moment because framework-wifi and framework-tethering are in the |
| 250 | // PRODUCT_UPDATABLE_BOOT_JARS but not marked as updatable in AOSP. |
| 251 | } |
| 252 | } |
| 253 | } |
| 254 | } |
| 255 | |
Paul Duffin | bb7f1ac | 2021-03-29 22:18:45 +0100 | [diff] [blame] | 256 | func (b *platformBootclasspathModule) getImageConfig(ctx android.EarlyModuleContext) *bootImageConfig { |
| 257 | return defaultBootImageConfig(ctx) |
| 258 | } |
Paul Duffin | 702210b | 2021-04-08 20:12:41 +0100 | [diff] [blame] | 259 | |
Paul Duffin | d504c3a | 2021-04-30 08:10:21 +0100 | [diff] [blame] | 260 | // hiddenAPISupportingModule encapsulates the information provided by any module that contributes to |
| 261 | // the hidden API processing. |
| 262 | type hiddenAPISupportingModule struct { |
| 263 | module android.Module |
| 264 | |
| 265 | bootDexJar android.Path |
| 266 | flagsCSV android.Path |
| 267 | indexCSV android.Path |
| 268 | metadataCSV android.Path |
| 269 | } |
| 270 | |
Paul Duffin | 702210b | 2021-04-08 20:12:41 +0100 | [diff] [blame] | 271 | // generateHiddenAPIBuildActions generates all the hidden API related build rules. |
Paul Duffin | 9b381ef | 2021-04-08 23:01:37 +0100 | [diff] [blame] | 272 | func (b *platformBootclasspathModule) generateHiddenAPIBuildActions(ctx android.ModuleContext, modules []android.Module, fragments []android.Module) { |
Paul Duffin | 702210b | 2021-04-08 20:12:41 +0100 | [diff] [blame] | 273 | |
Paul Duffin | 90b8ad3 | 2021-04-13 12:25:01 +0100 | [diff] [blame] | 274 | // Save the paths to the monolithic files for retrieval via OutputFiles(). |
| 275 | b.hiddenAPIFlagsCSV = hiddenAPISingletonPaths(ctx).flags |
| 276 | b.hiddenAPIIndexCSV = hiddenAPISingletonPaths(ctx).index |
| 277 | b.hiddenAPIMetadataCSV = hiddenAPISingletonPaths(ctx).metadata |
Paul Duffin | 6a76645 | 2021-04-12 14:15:22 +0100 | [diff] [blame] | 278 | |
Paul Duffin | 0b65986 | 2021-04-13 13:02:29 +0100 | [diff] [blame] | 279 | // Don't run any hiddenapi rules if UNSAFE_DISABLE_HIDDENAPI_FLAGS=true. This is a performance |
| 280 | // optimization that can be used to reduce the incremental build time but as its name suggests it |
| 281 | // can be unsafe to use, e.g. when the changes affect anything that goes on the bootclasspath. |
Vishnu Nair | 0dbd02a | 2021-04-30 00:24:07 +0000 | [diff] [blame] | 282 | if ctx.Config().IsEnvTrue("UNSAFE_DISABLE_HIDDENAPI_FLAGS") { |
Paul Duffin | 0b65986 | 2021-04-13 13:02:29 +0100 | [diff] [blame] | 283 | paths := android.OutputPaths{b.hiddenAPIFlagsCSV, b.hiddenAPIIndexCSV, b.hiddenAPIMetadataCSV} |
| 284 | for _, path := range paths { |
| 285 | ctx.Build(pctx, android.BuildParams{ |
| 286 | Rule: android.Touch, |
| 287 | Output: path, |
| 288 | }) |
| 289 | } |
| 290 | return |
| 291 | } |
| 292 | |
Paul Duffin | d504c3a | 2021-04-30 08:10:21 +0100 | [diff] [blame] | 293 | // nilPathHandler will check the supplied path and if it is nil then it will either immediately |
| 294 | // report an error, or it will defer the error reporting until it is actually used, depending |
| 295 | // whether missing dependencies are allowed. |
| 296 | var nilPathHandler func(path android.Path, name string, module android.Module) android.Path |
| 297 | if ctx.Config().AllowMissingDependencies() { |
| 298 | nilPathHandler = func(path android.Path, name string, module android.Module) android.Path { |
| 299 | if path == nil { |
| 300 | outputPath := android.PathForModuleOut(ctx, "missing", module.Name(), name) |
| 301 | path = outputPath |
| 302 | |
| 303 | // Create an error rule that pretends to create the output file but will actually fail if it |
| 304 | // is run. |
| 305 | ctx.Build(pctx, android.BuildParams{ |
| 306 | Rule: android.ErrorRule, |
| 307 | Output: outputPath, |
| 308 | Args: map[string]string{ |
| 309 | "error": fmt.Sprintf("missing hidden API file: %s for %s", name, module), |
| 310 | }, |
| 311 | }) |
| 312 | } |
| 313 | return path |
| 314 | } |
| 315 | } else { |
| 316 | nilPathHandler = func(path android.Path, name string, module android.Module) android.Path { |
| 317 | if path == nil { |
| 318 | ctx.ModuleErrorf("module %s does not provide a %s file", module, name) |
| 319 | } |
| 320 | return path |
| 321 | } |
| 322 | } |
| 323 | |
Paul Duffin | 1ba2467 | 2021-04-12 23:26:14 +0100 | [diff] [blame] | 324 | hiddenAPISupportingModules := []hiddenAPISupportingModule{} |
Paul Duffin | 702210b | 2021-04-08 20:12:41 +0100 | [diff] [blame] | 325 | for _, module := range modules { |
Paul Duffin | d504c3a | 2021-04-30 08:10:21 +0100 | [diff] [blame] | 326 | if h, ok := module.(hiddenAPIIntf); ok { |
| 327 | hiddenAPISupportingModule := hiddenAPISupportingModule{ |
| 328 | module: module, |
| 329 | bootDexJar: nilPathHandler(h.bootDexJar(), "bootDexJar", module), |
| 330 | flagsCSV: nilPathHandler(h.flagsCSV(), "flagsCSV", module), |
| 331 | indexCSV: nilPathHandler(h.indexCSV(), "indexCSV", module), |
| 332 | metadataCSV: nilPathHandler(h.metadataCSV(), "metadataCSV", module), |
Paul Duffin | 1ba2467 | 2021-04-12 23:26:14 +0100 | [diff] [blame] | 333 | } |
| 334 | |
Paul Duffin | d504c3a | 2021-04-30 08:10:21 +0100 | [diff] [blame] | 335 | // If any errors were reported when trying to populate the hiddenAPISupportingModule struct |
| 336 | // then don't add it to the list. |
Paul Duffin | 1ba2467 | 2021-04-12 23:26:14 +0100 | [diff] [blame] | 337 | if ctx.Failed() { |
| 338 | continue |
| 339 | } |
| 340 | |
Paul Duffin | d504c3a | 2021-04-30 08:10:21 +0100 | [diff] [blame] | 341 | hiddenAPISupportingModules = append(hiddenAPISupportingModules, hiddenAPISupportingModule) |
Paul Duffin | 4977540 | 2021-04-30 08:58:12 +0100 | [diff] [blame] | 342 | } else if _, ok := module.(*DexImport); ok { |
| 343 | // Ignore this for the purposes of hidden API processing |
Paul Duffin | 702210b | 2021-04-08 20:12:41 +0100 | [diff] [blame] | 344 | } else { |
Paul Duffin | 1ba2467 | 2021-04-12 23:26:14 +0100 | [diff] [blame] | 345 | ctx.ModuleErrorf("module %s of type %s does not support hidden API processing", module, ctx.OtherModuleType(module)) |
Paul Duffin | 702210b | 2021-04-08 20:12:41 +0100 | [diff] [blame] | 346 | } |
| 347 | } |
| 348 | |
Paul Duffin | 1ba2467 | 2021-04-12 23:26:14 +0100 | [diff] [blame] | 349 | moduleSpecificFlagsPaths := android.Paths{} |
| 350 | for _, module := range hiddenAPISupportingModules { |
Paul Duffin | d504c3a | 2021-04-30 08:10:21 +0100 | [diff] [blame] | 351 | moduleSpecificFlagsPaths = append(moduleSpecificFlagsPaths, module.flagsCSV) |
Paul Duffin | 1ba2467 | 2021-04-12 23:26:14 +0100 | [diff] [blame] | 352 | } |
| 353 | |
Paul Duffin | 9b381ef | 2021-04-08 23:01:37 +0100 | [diff] [blame] | 354 | flagFileInfo := b.properties.Hidden_api.hiddenAPIFlagFileInfo(ctx) |
| 355 | for _, fragment := range fragments { |
| 356 | if ctx.OtherModuleHasProvider(fragment, hiddenAPIFlagFileInfoProvider) { |
| 357 | info := ctx.OtherModuleProvider(fragment, hiddenAPIFlagFileInfoProvider).(hiddenAPIFlagFileInfo) |
| 358 | flagFileInfo.append(info) |
| 359 | } |
| 360 | } |
| 361 | |
| 362 | // Store the information for testing. |
| 363 | ctx.SetProvider(hiddenAPIFlagFileInfoProvider, flagFileInfo) |
Paul Duffin | 702210b | 2021-04-08 20:12:41 +0100 | [diff] [blame] | 364 | |
| 365 | outputPath := hiddenAPISingletonPaths(ctx).flags |
| 366 | baseFlagsPath := hiddenAPISingletonPaths(ctx).stubFlags |
Paul Duffin | 9b381ef | 2021-04-08 23:01:37 +0100 | [diff] [blame] | 367 | ruleToGenerateHiddenApiFlags(ctx, outputPath, baseFlagsPath, moduleSpecificFlagsPaths, flagFileInfo) |
Paul Duffin | 00b2bfd | 2021-04-12 17:24:36 +0100 | [diff] [blame] | 368 | |
Paul Duffin | 74431d5 | 2021-04-21 14:10:42 +0100 | [diff] [blame] | 369 | b.generateHiddenAPIStubFlagsRules(ctx, hiddenAPISupportingModules) |
Paul Duffin | 00b2bfd | 2021-04-12 17:24:36 +0100 | [diff] [blame] | 370 | b.generateHiddenAPIIndexRules(ctx, hiddenAPISupportingModules) |
Paul Duffin | 85dee5d | 2021-04-13 00:14:38 +0100 | [diff] [blame] | 371 | b.generatedHiddenAPIMetadataRules(ctx, hiddenAPISupportingModules) |
Paul Duffin | 00b2bfd | 2021-04-12 17:24:36 +0100 | [diff] [blame] | 372 | } |
| 373 | |
Paul Duffin | 74431d5 | 2021-04-21 14:10:42 +0100 | [diff] [blame] | 374 | func (b *platformBootclasspathModule) generateHiddenAPIStubFlagsRules(ctx android.ModuleContext, modules []hiddenAPISupportingModule) { |
| 375 | bootDexJars := android.Paths{} |
| 376 | for _, module := range modules { |
Paul Duffin | d504c3a | 2021-04-30 08:10:21 +0100 | [diff] [blame] | 377 | bootDexJars = append(bootDexJars, module.bootDexJar) |
Paul Duffin | 74431d5 | 2021-04-21 14:10:42 +0100 | [diff] [blame] | 378 | } |
| 379 | |
| 380 | sdkKindToStubPaths := hiddenAPIGatherStubLibDexJarPaths(ctx) |
| 381 | |
| 382 | outputPath := hiddenAPISingletonPaths(ctx).stubFlags |
| 383 | rule := ruleToGenerateHiddenAPIStubFlagsFile(ctx, outputPath, bootDexJars, sdkKindToStubPaths) |
| 384 | rule.Build("platform-bootclasspath-monolithic-hiddenapi-stub-flags", "monolithic hidden API stub flags") |
| 385 | } |
| 386 | |
Paul Duffin | 00b2bfd | 2021-04-12 17:24:36 +0100 | [diff] [blame] | 387 | func (b *platformBootclasspathModule) generateHiddenAPIIndexRules(ctx android.ModuleContext, modules []hiddenAPISupportingModule) { |
| 388 | indexes := android.Paths{} |
| 389 | for _, module := range modules { |
Paul Duffin | d504c3a | 2021-04-30 08:10:21 +0100 | [diff] [blame] | 390 | indexes = append(indexes, module.indexCSV) |
Paul Duffin | 00b2bfd | 2021-04-12 17:24:36 +0100 | [diff] [blame] | 391 | } |
| 392 | |
| 393 | rule := android.NewRuleBuilder(pctx, ctx) |
| 394 | rule.Command(). |
| 395 | BuiltTool("merge_csv"). |
| 396 | Flag("--key_field signature"). |
| 397 | FlagWithArg("--header=", "signature,file,startline,startcol,endline,endcol,properties"). |
| 398 | FlagWithOutput("--output=", hiddenAPISingletonPaths(ctx).index). |
| 399 | Inputs(indexes) |
| 400 | rule.Build("platform-bootclasspath-monolithic-hiddenapi-index", "monolithic hidden API index") |
Paul Duffin | 702210b | 2021-04-08 20:12:41 +0100 | [diff] [blame] | 401 | } |
Paul Duffin | 85dee5d | 2021-04-13 00:14:38 +0100 | [diff] [blame] | 402 | |
| 403 | func (b *platformBootclasspathModule) generatedHiddenAPIMetadataRules(ctx android.ModuleContext, modules []hiddenAPISupportingModule) { |
| 404 | metadataCSVFiles := android.Paths{} |
| 405 | for _, module := range modules { |
Paul Duffin | d504c3a | 2021-04-30 08:10:21 +0100 | [diff] [blame] | 406 | metadataCSVFiles = append(metadataCSVFiles, module.metadataCSV) |
Paul Duffin | 85dee5d | 2021-04-13 00:14:38 +0100 | [diff] [blame] | 407 | } |
| 408 | |
| 409 | rule := android.NewRuleBuilder(pctx, ctx) |
| 410 | |
| 411 | outputPath := hiddenAPISingletonPaths(ctx).metadata |
| 412 | |
| 413 | rule.Command(). |
| 414 | BuiltTool("merge_csv"). |
| 415 | Flag("--key_field signature"). |
| 416 | FlagWithOutput("--output=", outputPath). |
| 417 | Inputs(metadataCSVFiles) |
| 418 | |
| 419 | rule.Build("platform-bootclasspath-monolithic-hiddenapi-metadata", "monolithic hidden API metadata") |
| 420 | } |
Paul Duffin | ad19d38 | 2021-04-26 16:44:00 +0100 | [diff] [blame] | 421 | |
Paul Duffin | 12d29b7 | 2021-04-29 13:50:01 +0100 | [diff] [blame] | 422 | // generateHiddenApiMakeVars generates make variables needed by hidden API related make rules, e.g. |
| 423 | // veridex and run-appcompat. |
| 424 | func (b *platformBootclasspathModule) generateHiddenApiMakeVars(ctx android.MakeVarsContext) { |
| 425 | if ctx.Config().IsEnvTrue("UNSAFE_DISABLE_HIDDENAPI_FLAGS") { |
| 426 | return |
| 427 | } |
| 428 | // INTERNAL_PLATFORM_HIDDENAPI_FLAGS is used by Make rules in art/ and cts/. |
| 429 | ctx.Strict("INTERNAL_PLATFORM_HIDDENAPI_FLAGS", b.hiddenAPIFlagsCSV.String()) |
| 430 | } |
| 431 | |
Paul Duffin | ad19d38 | 2021-04-26 16:44:00 +0100 | [diff] [blame] | 432 | // generateBootImageBuildActions generates ninja rules related to the boot image creation. |
Paul Duffin | 7ebebfd | 2021-04-27 19:36:57 +0100 | [diff] [blame^] | 433 | func (b *platformBootclasspathModule) generateBootImageBuildActions(ctx android.ModuleContext, nonUpdatableModules, updatableModules []android.Module) { |
Paul Duffin | ad19d38 | 2021-04-26 16:44:00 +0100 | [diff] [blame] | 434 | // Force the GlobalSoongConfig to be created and cached for use by the dex_bootjars |
| 435 | // GenerateSingletonBuildActions method as it cannot create it for itself. |
| 436 | dexpreopt.GetGlobalSoongConfig(ctx) |
| 437 | |
| 438 | imageConfig := b.getImageConfig(ctx) |
| 439 | if imageConfig == nil { |
| 440 | return |
| 441 | } |
| 442 | |
| 443 | global := dexpreopt.GetGlobalConfig(ctx) |
| 444 | if !shouldBuildBootImages(ctx.Config(), global) { |
| 445 | return |
| 446 | } |
| 447 | |
| 448 | // Generate the framework profile rule |
| 449 | bootFrameworkProfileRule(ctx, imageConfig) |
Paul Duffin | 4c09442 | 2021-04-26 20:10:48 +0100 | [diff] [blame] | 450 | |
| 451 | // Generate the updatable bootclasspath packages rule. |
| 452 | generateUpdatableBcpPackagesRule(ctx, imageConfig, updatableModules) |
Paul Duffin | f7a5592 | 2021-04-26 23:09:15 +0100 | [diff] [blame] | 453 | |
Paul Duffin | 7ebebfd | 2021-04-27 19:36:57 +0100 | [diff] [blame^] | 454 | // Copy non-updatable module dex jars to their predefined locations. |
| 455 | copyBootJarsToPredefinedLocations(ctx, nonUpdatableModules, imageConfig.modules, imageConfig.dexPaths) |
| 456 | |
| 457 | // Copy updatable module dex jars to their predefined locations. |
| 458 | config := GetUpdatableBootConfig(ctx) |
| 459 | copyBootJarsToPredefinedLocations(ctx, updatableModules, config.modules, config.dexPaths) |
| 460 | |
Paul Duffin | f7a5592 | 2021-04-26 23:09:15 +0100 | [diff] [blame] | 461 | dumpOatRules(ctx, imageConfig) |
Paul Duffin | ad19d38 | 2021-04-26 16:44:00 +0100 | [diff] [blame] | 462 | } |