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 | 013485b | 2021-05-06 23:38:10 +0100 | [diff] [blame] | 206 | b.classpathFragmentBase().generateClasspathProtoBuildActions(ctx, classpathJars) |
| 207 | } |
| 208 | |
| 209 | func (b *platformBootclasspathModule) ClasspathFragmentToConfiguredJarList(ctx android.ModuleContext) android.ConfiguredJarList { |
satayev | 8fab6f8 | 2021-05-07 00:10:33 +0100 | [diff] [blame] | 210 | return b.getImageConfig(ctx).modules |
satayev | 013485b | 2021-05-06 23:38:10 +0100 | [diff] [blame] | 211 | } |
| 212 | |
Paul Duffin | f23bc47 | 2021-04-27 12:42:20 +0100 | [diff] [blame] | 213 | // checkNonUpdatableModules ensures that the non-updatable modules supplied are not part of an |
| 214 | // updatable module. |
| 215 | func (b *platformBootclasspathModule) checkNonUpdatableModules(ctx android.ModuleContext, modules []android.Module) { |
| 216 | for _, m := range modules { |
| 217 | apexInfo := ctx.OtherModuleProvider(m, android.ApexInfoProvider).(android.ApexInfo) |
| 218 | fromUpdatableApex := apexInfo.Updatable |
| 219 | if fromUpdatableApex { |
| 220 | // error: this jar is part of an updatable apex |
Jiyong Park | ab50b07 | 2021-05-12 17:13:56 +0900 | [diff] [blame] | 221 | ctx.ModuleErrorf("module %q from updatable apexes %q is not allowed in the framework boot image", ctx.OtherModuleName(m), apexInfo.InApexVariants) |
Paul Duffin | f23bc47 | 2021-04-27 12:42:20 +0100 | [diff] [blame] | 222 | } else { |
| 223 | // ok: this jar is part of the platform or a non-updatable apex |
| 224 | } |
| 225 | } |
| 226 | } |
| 227 | |
| 228 | // checkUpdatableModules ensures that the updatable modules supplied are not from the platform. |
| 229 | func (b *platformBootclasspathModule) checkUpdatableModules(ctx android.ModuleContext, modules []android.Module) { |
| 230 | for _, m := range modules { |
| 231 | apexInfo := ctx.OtherModuleProvider(m, android.ApexInfoProvider).(android.ApexInfo) |
| 232 | fromUpdatableApex := apexInfo.Updatable |
| 233 | if fromUpdatableApex { |
| 234 | // ok: this jar is part of an updatable apex |
| 235 | } else { |
| 236 | name := ctx.OtherModuleName(m) |
| 237 | if apexInfo.IsForPlatform() { |
Paul Duffin | 7487a7a | 2021-05-19 09:36:09 +0100 | [diff] [blame] | 238 | // If AlwaysUsePrebuiltSdks() returns true then it is possible that the updatable list will |
| 239 | // include platform variants of a prebuilt module due to workarounds elsewhere. In that case |
| 240 | // do not treat this as an error. |
| 241 | // TODO(b/179354495): Always treat this as an error when migration to bootclasspath_fragment |
| 242 | // modules is complete. |
| 243 | if !ctx.Config().AlwaysUsePrebuiltSdks() { |
| 244 | // error: this jar is part of the platform |
| 245 | ctx.ModuleErrorf("module %q from platform is not allowed in the updatable boot jars list", name) |
| 246 | } |
Paul Duffin | f23bc47 | 2021-04-27 12:42:20 +0100 | [diff] [blame] | 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 | |
| 260 | // generateHiddenAPIBuildActions generates all the hidden API related build rules. |
Paul Duffin | 9b381ef | 2021-04-08 23:01:37 +0100 | [diff] [blame] | 261 | 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] | 262 | |
Paul Duffin | 90b8ad3 | 2021-04-13 12:25:01 +0100 | [diff] [blame] | 263 | // Save the paths to the monolithic files for retrieval via OutputFiles(). |
| 264 | b.hiddenAPIFlagsCSV = hiddenAPISingletonPaths(ctx).flags |
| 265 | b.hiddenAPIIndexCSV = hiddenAPISingletonPaths(ctx).index |
| 266 | b.hiddenAPIMetadataCSV = hiddenAPISingletonPaths(ctx).metadata |
Paul Duffin | 6a76645 | 2021-04-12 14:15:22 +0100 | [diff] [blame] | 267 | |
Paul Duffin | 0b65986 | 2021-04-13 13:02:29 +0100 | [diff] [blame] | 268 | // Don't run any hiddenapi rules if UNSAFE_DISABLE_HIDDENAPI_FLAGS=true. This is a performance |
| 269 | // optimization that can be used to reduce the incremental build time but as its name suggests it |
| 270 | // 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] | 271 | if ctx.Config().IsEnvTrue("UNSAFE_DISABLE_HIDDENAPI_FLAGS") { |
Paul Duffin | 0b65986 | 2021-04-13 13:02:29 +0100 | [diff] [blame] | 272 | paths := android.OutputPaths{b.hiddenAPIFlagsCSV, b.hiddenAPIIndexCSV, b.hiddenAPIMetadataCSV} |
| 273 | for _, path := range paths { |
| 274 | ctx.Build(pctx, android.BuildParams{ |
| 275 | Rule: android.Touch, |
| 276 | Output: path, |
| 277 | }) |
| 278 | } |
| 279 | return |
| 280 | } |
| 281 | |
Paul Duffin | 438eb57 | 2021-05-21 16:58:23 +0100 | [diff] [blame] | 282 | monolithicInfo := b.createAndProvideMonolithicHiddenAPIInfo(ctx, fragments) |
Paul Duffin | 1352f7c | 2021-05-21 22:18:49 +0100 | [diff] [blame] | 283 | // Create the input to pass to ruleToGenerateHiddenAPIStubFlagsFile |
| 284 | input := newHiddenAPIFlagInput() |
| 285 | |
| 286 | // Gather stub library information from the dependencies on modules provided by |
| 287 | // hiddenAPIComputeMonolithicStubLibModules. |
| 288 | input.gatherStubLibInfo(ctx, nil) |
| 289 | |
| 290 | // Use the flag files from this module and all the fragments. |
| 291 | input.FlagFilesByCategory = monolithicInfo.FlagsFilesByCategory |
Paul Duffin | 74431d5 | 2021-04-21 14:10:42 +0100 | [diff] [blame] | 292 | |
Paul Duffin | 438eb57 | 2021-05-21 16:58:23 +0100 | [diff] [blame] | 293 | hiddenAPIModules := gatherHiddenAPIModuleFromContents(ctx, modules) |
| 294 | |
Paul Duffin | 537ea3d | 2021-05-14 10:38:00 +0100 | [diff] [blame] | 295 | // Generate the monolithic stub-flags.csv file. |
| 296 | bootDexJars := extractBootDexJarsFromHiddenAPIModules(ctx, hiddenAPIModules) |
| 297 | stubFlags := hiddenAPISingletonPaths(ctx).stubFlags |
Paul Duffin | 1352f7c | 2021-05-21 22:18:49 +0100 | [diff] [blame] | 298 | rule := ruleToGenerateHiddenAPIStubFlagsFile(ctx, stubFlags, bootDexJars, input) |
Paul Duffin | 74431d5 | 2021-04-21 14:10:42 +0100 | [diff] [blame] | 299 | rule.Build("platform-bootclasspath-monolithic-hiddenapi-stub-flags", "monolithic hidden API stub flags") |
Paul Duffin | 537ea3d | 2021-05-14 10:38:00 +0100 | [diff] [blame] | 300 | |
| 301 | // Extract the classes jars from the contents. |
| 302 | classesJars := extractClassJarsFromHiddenAPIModules(ctx, hiddenAPIModules) |
| 303 | |
| 304 | // Generate the annotation-flags.csv file from all the module annotations. |
| 305 | annotationFlags := android.PathForModuleOut(ctx, "hiddenapi-monolithic", "annotation-flags.csv") |
| 306 | buildRuleToGenerateAnnotationFlags(ctx, "monolithic hiddenapi flags", classesJars, stubFlags, annotationFlags) |
| 307 | |
| 308 | // Generate the monotlithic hiddenapi-flags.csv file. |
| 309 | allFlags := hiddenAPISingletonPaths(ctx).flags |
Paul Duffin | 32cf58a | 2021-05-18 16:32:50 +0100 | [diff] [blame] | 310 | buildRuleToGenerateHiddenApiFlags(ctx, "hiddenAPIFlagsFile", "hiddenapi flags", allFlags, stubFlags, annotationFlags, monolithicInfo.FlagsFilesByCategory, monolithicInfo.AllFlagsPaths, android.OptionalPath{}) |
Paul Duffin | 537ea3d | 2021-05-14 10:38:00 +0100 | [diff] [blame] | 311 | |
| 312 | // Generate an intermediate monolithic hiddenapi-metadata.csv file directly from the annotations |
| 313 | // in the source code. |
| 314 | intermediateMetadataCSV := android.PathForModuleOut(ctx, "hiddenapi-monolithic", "intermediate-metadata.csv") |
| 315 | buildRuleToGenerateMetadata(ctx, "monolithic hidden API metadata", classesJars, stubFlags, intermediateMetadataCSV) |
| 316 | |
| 317 | // Reformat the intermediate file to add | quotes just in case that is important for the tools |
| 318 | // that consume the metadata file. |
| 319 | // TODO(b/179354495): Investigate whether it is possible to remove this reformatting step. |
| 320 | metadataCSV := hiddenAPISingletonPaths(ctx).metadata |
| 321 | b.buildRuleMergeCSV(ctx, "reformat monolithic hidden API metadata", android.Paths{intermediateMetadataCSV}, metadataCSV) |
| 322 | |
| 323 | // Generate the monolithic hiddenapi-index.csv file directly from the CSV files in the classes |
| 324 | // jars. |
| 325 | indexCSV := hiddenAPISingletonPaths(ctx).index |
| 326 | buildRuleToGenerateIndex(ctx, "monolithic hidden API index", classesJars, indexCSV) |
Paul Duffin | 74431d5 | 2021-04-21 14:10:42 +0100 | [diff] [blame] | 327 | } |
| 328 | |
Paul Duffin | 438eb57 | 2021-05-21 16:58:23 +0100 | [diff] [blame] | 329 | // createAndProvideMonolithicHiddenAPIInfo creates a MonolithicHiddenAPIInfo and provides it for |
| 330 | // testing. |
| 331 | func (b *platformBootclasspathModule) createAndProvideMonolithicHiddenAPIInfo(ctx android.ModuleContext, fragments []android.Module) MonolithicHiddenAPIInfo { |
Paul Duffin | 1352f7c | 2021-05-21 22:18:49 +0100 | [diff] [blame] | 332 | // Create a temporary input structure in which to collate information provided directly by this |
| 333 | // module, either through properties or direct dependencies. |
| 334 | temporaryInput := newHiddenAPIFlagInput() |
| 335 | |
| 336 | // Create paths to the flag files specified in the properties. |
| 337 | temporaryInput.extractFlagFilesFromProperties(ctx, &b.properties.Hidden_api) |
| 338 | |
| 339 | // Create the monolithic info, by starting with the flag files specified on this and then merging |
| 340 | // in information from all the fragment dependencies of this. |
| 341 | monolithicInfo := newMonolithicHiddenAPIInfo(ctx, temporaryInput.FlagFilesByCategory, fragments) |
Paul Duffin | 438eb57 | 2021-05-21 16:58:23 +0100 | [diff] [blame] | 342 | |
| 343 | // Store the information for testing. |
Paul Duffin | 524c82c | 2021-06-09 14:39:28 +0100 | [diff] [blame] | 344 | ctx.SetProvider(MonolithicHiddenAPIInfoProvider, monolithicInfo) |
Paul Duffin | 438eb57 | 2021-05-21 16:58:23 +0100 | [diff] [blame] | 345 | return monolithicInfo |
| 346 | } |
| 347 | |
Paul Duffin | 537ea3d | 2021-05-14 10:38:00 +0100 | [diff] [blame] | 348 | func (b *platformBootclasspathModule) buildRuleMergeCSV(ctx android.ModuleContext, desc string, inputPaths android.Paths, outputPath android.WritablePath) { |
Paul Duffin | 00b2bfd | 2021-04-12 17:24:36 +0100 | [diff] [blame] | 349 | rule := android.NewRuleBuilder(pctx, ctx) |
| 350 | rule.Command(). |
| 351 | BuiltTool("merge_csv"). |
| 352 | Flag("--key_field signature"). |
Paul Duffin | 85dee5d | 2021-04-13 00:14:38 +0100 | [diff] [blame] | 353 | FlagWithOutput("--output=", outputPath). |
Paul Duffin | 537ea3d | 2021-05-14 10:38:00 +0100 | [diff] [blame] | 354 | Inputs(inputPaths) |
Paul Duffin | 85dee5d | 2021-04-13 00:14:38 +0100 | [diff] [blame] | 355 | |
Paul Duffin | 537ea3d | 2021-05-14 10:38:00 +0100 | [diff] [blame] | 356 | rule.Build(desc, desc) |
Paul Duffin | 85dee5d | 2021-04-13 00:14:38 +0100 | [diff] [blame] | 357 | } |
Paul Duffin | ad19d38 | 2021-04-26 16:44:00 +0100 | [diff] [blame] | 358 | |
Paul Duffin | 12d29b7 | 2021-04-29 13:50:01 +0100 | [diff] [blame] | 359 | // generateHiddenApiMakeVars generates make variables needed by hidden API related make rules, e.g. |
| 360 | // veridex and run-appcompat. |
| 361 | func (b *platformBootclasspathModule) generateHiddenApiMakeVars(ctx android.MakeVarsContext) { |
| 362 | if ctx.Config().IsEnvTrue("UNSAFE_DISABLE_HIDDENAPI_FLAGS") { |
| 363 | return |
| 364 | } |
| 365 | // INTERNAL_PLATFORM_HIDDENAPI_FLAGS is used by Make rules in art/ and cts/. |
| 366 | ctx.Strict("INTERNAL_PLATFORM_HIDDENAPI_FLAGS", b.hiddenAPIFlagsCSV.String()) |
| 367 | } |
| 368 | |
Paul Duffin | ad19d38 | 2021-04-26 16:44:00 +0100 | [diff] [blame] | 369 | // generateBootImageBuildActions generates ninja rules related to the boot image creation. |
Paul Duffin | 7ebebfd | 2021-04-27 19:36:57 +0100 | [diff] [blame] | 370 | func (b *platformBootclasspathModule) generateBootImageBuildActions(ctx android.ModuleContext, nonUpdatableModules, updatableModules []android.Module) { |
Paul Duffin | ad19d38 | 2021-04-26 16:44:00 +0100 | [diff] [blame] | 371 | // Force the GlobalSoongConfig to be created and cached for use by the dex_bootjars |
| 372 | // GenerateSingletonBuildActions method as it cannot create it for itself. |
| 373 | dexpreopt.GetGlobalSoongConfig(ctx) |
| 374 | |
| 375 | imageConfig := b.getImageConfig(ctx) |
| 376 | if imageConfig == nil { |
| 377 | return |
| 378 | } |
| 379 | |
| 380 | global := dexpreopt.GetGlobalConfig(ctx) |
| 381 | if !shouldBuildBootImages(ctx.Config(), global) { |
| 382 | return |
| 383 | } |
| 384 | |
| 385 | // Generate the framework profile rule |
| 386 | bootFrameworkProfileRule(ctx, imageConfig) |
Paul Duffin | 4c09442 | 2021-04-26 20:10:48 +0100 | [diff] [blame] | 387 | |
| 388 | // Generate the updatable bootclasspath packages rule. |
| 389 | generateUpdatableBcpPackagesRule(ctx, imageConfig, updatableModules) |
Paul Duffin | f7a5592 | 2021-04-26 23:09:15 +0100 | [diff] [blame] | 390 | |
Paul Duffin | 7ebebfd | 2021-04-27 19:36:57 +0100 | [diff] [blame] | 391 | // Copy non-updatable module dex jars to their predefined locations. |
Paul Duffin | 5f148ca | 2021-06-02 17:24:22 +0100 | [diff] [blame^] | 392 | nonUpdatableBootDexJarsByModule := extractEncodedDexJarsFromModules(ctx, nonUpdatableModules) |
| 393 | copyBootJarsToPredefinedLocations(ctx, nonUpdatableBootDexJarsByModule, imageConfig.dexPathsByModule) |
Paul Duffin | 7ebebfd | 2021-04-27 19:36:57 +0100 | [diff] [blame] | 394 | |
| 395 | // Copy updatable module dex jars to their predefined locations. |
| 396 | config := GetUpdatableBootConfig(ctx) |
Paul Duffin | 5f148ca | 2021-06-02 17:24:22 +0100 | [diff] [blame^] | 397 | updatableBootDexJarsByModule := extractEncodedDexJarsFromModules(ctx, updatableModules) |
| 398 | copyBootJarsToPredefinedLocations(ctx, updatableBootDexJarsByModule, config.dexPathsByModule) |
Paul Duffin | 7ebebfd | 2021-04-27 19:36:57 +0100 | [diff] [blame] | 399 | |
Paul Duffin | 2fc82ad | 2021-04-29 23:36:12 +0100 | [diff] [blame] | 400 | // Build a profile for the image config and then use that to build the boot image. |
| 401 | profile := bootImageProfileRule(ctx, imageConfig) |
| 402 | buildBootImage(ctx, imageConfig, profile) |
| 403 | |
Paul Duffin | f7a5592 | 2021-04-26 23:09:15 +0100 | [diff] [blame] | 404 | dumpOatRules(ctx, imageConfig) |
Paul Duffin | ad19d38 | 2021-04-26 16:44:00 +0100 | [diff] [blame] | 405 | } |