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. |
Paul Duffin | b432df9 | 2021-03-22 22:09:42 +0000 | [diff] [blame] | 47 | configuredModules []android.Module |
Paul Duffin | 62d8c3b | 2021-04-07 20:35:11 +0100 | [diff] [blame] | 48 | |
| 49 | // The apex:module pairs obtained from the fragments. |
Paul Duffin | 62d8c3b | 2021-04-07 20:35:11 +0100 | [diff] [blame] | 50 | fragments []android.Module |
Paul Duffin | 6a76645 | 2021-04-12 14:15:22 +0100 | [diff] [blame] | 51 | |
| 52 | // Path to the monolithic hiddenapi-flags.csv file. |
Paul Duffin | 0b65986 | 2021-04-13 13:02:29 +0100 | [diff] [blame] | 53 | hiddenAPIFlagsCSV android.OutputPath |
Paul Duffin | 6a76645 | 2021-04-12 14:15:22 +0100 | [diff] [blame] | 54 | |
| 55 | // Path to the monolithic hiddenapi-index.csv file. |
Paul Duffin | 0b65986 | 2021-04-13 13:02:29 +0100 | [diff] [blame] | 56 | hiddenAPIIndexCSV android.OutputPath |
Paul Duffin | 6a76645 | 2021-04-12 14:15:22 +0100 | [diff] [blame] | 57 | |
| 58 | // Path to the monolithic hiddenapi-unsupported.csv file. |
Paul Duffin | 0b65986 | 2021-04-13 13:02:29 +0100 | [diff] [blame] | 59 | hiddenAPIMetadataCSV android.OutputPath |
Paul Duffin | 62d8c3b | 2021-04-07 20:35:11 +0100 | [diff] [blame] | 60 | } |
| 61 | |
Paul Duffin | 62d8c3b | 2021-04-07 20:35:11 +0100 | [diff] [blame] | 62 | type platformBootclasspathProperties struct { |
Paul Duffin | b67d878 | 2021-04-22 11:49:41 +0100 | [diff] [blame] | 63 | BootclasspathFragmentsDepsProperties |
Paul Duffin | 702210b | 2021-04-08 20:12:41 +0100 | [diff] [blame] | 64 | |
Paul Duffin | 4616977 | 2021-04-14 15:01:56 +0100 | [diff] [blame] | 65 | Hidden_api HiddenAPIFlagFileProperties |
Paul Duffin | bb7f1ac | 2021-03-29 22:18:45 +0100 | [diff] [blame] | 66 | } |
| 67 | |
Paul Duffin | e3ecce6 | 2021-04-29 10:34:11 +0100 | [diff] [blame] | 68 | func platformBootclasspathFactory() android.SingletonModule { |
Paul Duffin | bb7f1ac | 2021-03-29 22:18:45 +0100 | [diff] [blame] | 69 | m := &platformBootclasspathModule{} |
Paul Duffin | 62d8c3b | 2021-04-07 20:35:11 +0100 | [diff] [blame] | 70 | m.AddProperties(&m.properties) |
satayev | 95e9c5b | 2021-04-29 11:50:26 +0100 | [diff] [blame] | 71 | // TODO(satayev): split apex jars into separate configs. |
| 72 | initClasspathFragment(m, BOOTCLASSPATH) |
Paul Duffin | bb7f1ac | 2021-03-29 22:18:45 +0100 | [diff] [blame] | 73 | android.InitAndroidArchModule(m, android.DeviceSupported, android.MultilibCommon) |
| 74 | return m |
| 75 | } |
| 76 | |
Paul Duffin | 6a76645 | 2021-04-12 14:15:22 +0100 | [diff] [blame] | 77 | var _ android.OutputFileProducer = (*platformBootclasspathModule)(nil) |
| 78 | |
Artur Satayev | 97259dc | 2021-04-07 15:17:14 +0100 | [diff] [blame] | 79 | func (b *platformBootclasspathModule) AndroidMkEntries() (entries []android.AndroidMkEntries) { |
| 80 | entries = append(entries, android.AndroidMkEntries{ |
| 81 | Class: "FAKE", |
| 82 | // Need at least one output file in order for this to take effect. |
| 83 | OutputFile: android.OptionalPathForPath(b.hiddenAPIFlagsCSV), |
| 84 | Include: "$(BUILD_PHONY_PACKAGE)", |
| 85 | }) |
satayev | 128ce2f | 2021-05-06 13:21:15 +0100 | [diff] [blame] | 86 | entries = append(entries, b.classpathFragmentBase().androidMkEntries()...) |
Artur Satayev | 97259dc | 2021-04-07 15:17:14 +0100 | [diff] [blame] | 87 | return |
Paul Duffin | 6a76645 | 2021-04-12 14:15:22 +0100 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | // Make the hidden API files available from the platform-bootclasspath module. |
| 91 | func (b *platformBootclasspathModule) OutputFiles(tag string) (android.Paths, error) { |
| 92 | switch tag { |
| 93 | case "hiddenapi-flags.csv": |
| 94 | return android.Paths{b.hiddenAPIFlagsCSV}, nil |
| 95 | case "hiddenapi-index.csv": |
| 96 | return android.Paths{b.hiddenAPIIndexCSV}, nil |
| 97 | case "hiddenapi-metadata.csv": |
| 98 | return android.Paths{b.hiddenAPIMetadataCSV}, nil |
| 99 | } |
| 100 | |
| 101 | return nil, fmt.Errorf("unknown tag %s", tag) |
| 102 | } |
| 103 | |
Paul Duffin | bb7f1ac | 2021-03-29 22:18:45 +0100 | [diff] [blame] | 104 | func (b *platformBootclasspathModule) DepsMutator(ctx android.BottomUpMutatorContext) { |
Paul Duffin | 74431d5 | 2021-04-21 14:10:42 +0100 | [diff] [blame] | 105 | b.hiddenAPIDepsMutator(ctx) |
| 106 | |
Paul Duffin | bb7f1ac | 2021-03-29 22:18:45 +0100 | [diff] [blame] | 107 | if SkipDexpreoptBootJars(ctx) { |
| 108 | return |
| 109 | } |
| 110 | |
| 111 | // Add a dependency onto the dex2oat tool which is needed for creating the boot image. The |
| 112 | // path is retrieved from the dependency by GetGlobalSoongConfig(ctx). |
| 113 | dexpreopt.RegisterToolDeps(ctx) |
| 114 | } |
| 115 | |
Paul Duffin | 74431d5 | 2021-04-21 14:10:42 +0100 | [diff] [blame] | 116 | func (b *platformBootclasspathModule) hiddenAPIDepsMutator(ctx android.BottomUpMutatorContext) { |
| 117 | if ctx.Config().IsEnvTrue("UNSAFE_DISABLE_HIDDENAPI_FLAGS") { |
| 118 | return |
| 119 | } |
| 120 | |
| 121 | // Add dependencies onto the stub lib modules. |
Paul Duffin | 31fad80 | 2021-06-18 18:14:25 +0100 | [diff] [blame] | 122 | apiLevelToStubLibModules := hiddenAPIComputeMonolithicStubLibModules(ctx.Config()) |
| 123 | hiddenAPIAddStubLibDependencies(ctx, apiLevelToStubLibModules) |
Paul Duffin | 74431d5 | 2021-04-21 14:10:42 +0100 | [diff] [blame] | 124 | } |
| 125 | |
Paul Duffin | 4994d26 | 2021-04-22 12:08:59 +0100 | [diff] [blame] | 126 | func (b *platformBootclasspathModule) BootclasspathDepsMutator(ctx android.BottomUpMutatorContext) { |
| 127 | // Add dependencies on all the modules configured in the "art" boot image. |
| 128 | artImageConfig := genBootImageConfigs(ctx)[artBootImageName] |
Paul Duffin | 01b463b | 2021-04-26 20:05:39 +0100 | [diff] [blame] | 129 | addDependenciesOntoBootImageModules(ctx, artImageConfig.modules, platformBootclasspathArtBootJarDepTag) |
Paul Duffin | b432df9 | 2021-03-22 22:09:42 +0000 | [diff] [blame] | 130 | |
Paul Duffin | 01b463b | 2021-04-26 20:05:39 +0100 | [diff] [blame] | 131 | // Add dependencies on all the non-updatable module configured in the "boot" boot image. That does |
| 132 | // not include modules configured in the "art" boot image. |
Paul Duffin | 4994d26 | 2021-04-22 12:08:59 +0100 | [diff] [blame] | 133 | bootImageConfig := b.getImageConfig(ctx) |
Paul Duffin | 01b463b | 2021-04-26 20:05:39 +0100 | [diff] [blame] | 134 | addDependenciesOntoBootImageModules(ctx, bootImageConfig.modules, platformBootclasspathNonUpdatableBootJarDepTag) |
Paul Duffin | b432df9 | 2021-03-22 22:09:42 +0000 | [diff] [blame] | 135 | |
Paul Duffin | 4994d26 | 2021-04-22 12:08:59 +0100 | [diff] [blame] | 136 | // Add dependencies on all the updatable modules. |
| 137 | updatableModules := dexpreopt.GetGlobalConfig(ctx).UpdatableBootJars |
Paul Duffin | 01b463b | 2021-04-26 20:05:39 +0100 | [diff] [blame] | 138 | addDependenciesOntoBootImageModules(ctx, updatableModules, platformBootclasspathUpdatableBootJarDepTag) |
Paul Duffin | 62d8c3b | 2021-04-07 20:35:11 +0100 | [diff] [blame] | 139 | |
Paul Duffin | 4994d26 | 2021-04-22 12:08:59 +0100 | [diff] [blame] | 140 | // Add dependencies on all the fragments. |
| 141 | b.properties.BootclasspathFragmentsDepsProperties.addDependenciesOntoFragments(ctx) |
Paul Duffin | b432df9 | 2021-03-22 22:09:42 +0000 | [diff] [blame] | 142 | } |
| 143 | |
Paul Duffin | 01b463b | 2021-04-26 20:05:39 +0100 | [diff] [blame] | 144 | func addDependenciesOntoBootImageModules(ctx android.BottomUpMutatorContext, modules android.ConfiguredJarList, tag bootclasspathDependencyTag) { |
Paul Duffin | b432df9 | 2021-03-22 22:09:42 +0000 | [diff] [blame] | 145 | for i := 0; i < modules.Len(); i++ { |
| 146 | apex := modules.Apex(i) |
| 147 | name := modules.Jar(i) |
| 148 | |
Paul Duffin | 01b463b | 2021-04-26 20:05:39 +0100 | [diff] [blame] | 149 | addDependencyOntoApexModulePair(ctx, apex, name, tag) |
Paul Duffin | b432df9 | 2021-03-22 22:09:42 +0000 | [diff] [blame] | 150 | } |
| 151 | } |
| 152 | |
Paul Duffin | e3ecce6 | 2021-04-29 10:34:11 +0100 | [diff] [blame] | 153 | // GenerateSingletonBuildActions does nothing and must never do anything. |
| 154 | // |
| 155 | // This module only implements android.SingletonModule so that it can implement |
| 156 | // android.SingletonMakeVarsProvider. |
| 157 | func (b *platformBootclasspathModule) GenerateSingletonBuildActions(android.SingletonContext) { |
| 158 | // Keep empty |
| 159 | } |
| 160 | |
| 161 | func (d *platformBootclasspathModule) MakeVars(ctx android.MakeVarsContext) { |
Paul Duffin | 12d29b7 | 2021-04-29 13:50:01 +0100 | [diff] [blame] | 162 | d.generateHiddenApiMakeVars(ctx) |
Paul Duffin | e3ecce6 | 2021-04-29 10:34:11 +0100 | [diff] [blame] | 163 | } |
| 164 | |
Paul Duffin | bb7f1ac | 2021-03-29 22:18:45 +0100 | [diff] [blame] | 165 | func (b *platformBootclasspathModule) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Paul Duffin | 01b463b | 2021-04-26 20:05:39 +0100 | [diff] [blame] | 166 | // Gather all the dependencies from the art, updatable and non-updatable boot jars. |
| 167 | artModules := gatherApexModulePairDepsWithTag(ctx, platformBootclasspathArtBootJarDepTag) |
| 168 | nonUpdatableModules := gatherApexModulePairDepsWithTag(ctx, platformBootclasspathNonUpdatableBootJarDepTag) |
| 169 | updatableModules := gatherApexModulePairDepsWithTag(ctx, platformBootclasspathUpdatableBootJarDepTag) |
| 170 | |
| 171 | // Concatenate them all, in order as they would appear on the bootclasspath. |
| 172 | var allModules []android.Module |
| 173 | allModules = append(allModules, artModules...) |
| 174 | allModules = append(allModules, nonUpdatableModules...) |
| 175 | allModules = append(allModules, updatableModules...) |
| 176 | b.configuredModules = allModules |
| 177 | |
| 178 | // Gather all the fragments dependencies. |
Paul Duffin | 9bacf56 | 2021-04-28 21:16:02 +0100 | [diff] [blame] | 179 | b.fragments = gatherApexModulePairDepsWithTag(ctx, bootclasspathFragmentDepTag) |
Paul Duffin | b432df9 | 2021-03-22 22:09:42 +0000 | [diff] [blame] | 180 | |
Paul Duffin | f23bc47 | 2021-04-27 12:42:20 +0100 | [diff] [blame] | 181 | // Check the configuration of the boot modules. |
| 182 | // ART modules are checked by the art-bootclasspath-fragment. |
| 183 | b.checkNonUpdatableModules(ctx, nonUpdatableModules) |
| 184 | b.checkUpdatableModules(ctx, updatableModules) |
| 185 | |
satayev | 013485b | 2021-05-06 23:38:10 +0100 | [diff] [blame] | 186 | b.generateClasspathProtoBuildActions(ctx) |
| 187 | |
Paul Duffin | c8ead41 | 2021-06-07 19:28:15 +0100 | [diff] [blame] | 188 | bootDexJarByModule := b.generateHiddenAPIBuildActions(ctx, b.configuredModules, b.fragments) |
| 189 | buildRuleForBootJarsPackageCheck(ctx, bootDexJarByModule) |
Paul Duffin | 702210b | 2021-04-08 20:12:41 +0100 | [diff] [blame] | 190 | |
Paul Duffin | bb7f1ac | 2021-03-29 22:18:45 +0100 | [diff] [blame] | 191 | // Nothing to do if skipping the dexpreopt of boot image jars. |
| 192 | if SkipDexpreoptBootJars(ctx) { |
| 193 | return |
| 194 | } |
| 195 | |
Paul Duffin | 7ebebfd | 2021-04-27 19:36:57 +0100 | [diff] [blame] | 196 | b.generateBootImageBuildActions(ctx, nonUpdatableModules, updatableModules) |
Paul Duffin | bb7f1ac | 2021-03-29 22:18:45 +0100 | [diff] [blame] | 197 | } |
| 198 | |
satayev | 013485b | 2021-05-06 23:38:10 +0100 | [diff] [blame] | 199 | // Generate classpaths.proto config |
| 200 | func (b *platformBootclasspathModule) generateClasspathProtoBuildActions(ctx android.ModuleContext) { |
satayev | b309050 | 2021-06-15 17:49:10 +0100 | [diff] [blame] | 201 | configuredJars := b.configuredJars(ctx) |
satayev | 013485b | 2021-05-06 23:38:10 +0100 | [diff] [blame] | 202 | // ART and platform boot jars must have a corresponding entry in DEX2OATBOOTCLASSPATH |
satayev | b309050 | 2021-06-15 17:49:10 +0100 | [diff] [blame] | 203 | classpathJars := configuredJarListToClasspathJars(ctx, configuredJars, BOOTCLASSPATH, DEX2OATBOOTCLASSPATH) |
| 204 | b.classpathFragmentBase().generateClasspathProtoBuildActions(ctx, configuredJars, classpathJars) |
satayev | 013485b | 2021-05-06 23:38:10 +0100 | [diff] [blame] | 205 | } |
| 206 | |
satayev | 142ed27 | 2021-06-15 16:21:17 +0100 | [diff] [blame] | 207 | func (b *platformBootclasspathModule) configuredJars(ctx android.ModuleContext) android.ConfiguredJarList { |
satayev | b309050 | 2021-06-15 17:49:10 +0100 | [diff] [blame] | 208 | // Include all non APEX jars |
| 209 | jars := b.getImageConfig(ctx).modules |
| 210 | |
| 211 | // Include jars from APEXes that don't populate their classpath proto config. |
| 212 | remainingJars := dexpreopt.GetGlobalConfig(ctx).UpdatableBootJars |
| 213 | for _, fragment := range b.fragments { |
| 214 | info := ctx.OtherModuleProvider(fragment, ClasspathFragmentProtoContentInfoProvider).(ClasspathFragmentProtoContentInfo) |
| 215 | if info.ClasspathFragmentProtoGenerated { |
| 216 | remainingJars = remainingJars.RemoveList(info.ClasspathFragmentProtoContents) |
| 217 | } |
| 218 | } |
| 219 | for i := 0; i < remainingJars.Len(); i++ { |
| 220 | jars = jars.Append(remainingJars.Apex(i), remainingJars.Jar(i)) |
| 221 | } |
| 222 | |
| 223 | return jars |
satayev | 013485b | 2021-05-06 23:38:10 +0100 | [diff] [blame] | 224 | } |
| 225 | |
Paul Duffin | f23bc47 | 2021-04-27 12:42:20 +0100 | [diff] [blame] | 226 | // checkNonUpdatableModules ensures that the non-updatable modules supplied are not part of an |
| 227 | // updatable module. |
| 228 | func (b *platformBootclasspathModule) checkNonUpdatableModules(ctx android.ModuleContext, modules []android.Module) { |
| 229 | for _, m := range modules { |
| 230 | apexInfo := ctx.OtherModuleProvider(m, android.ApexInfoProvider).(android.ApexInfo) |
| 231 | fromUpdatableApex := apexInfo.Updatable |
| 232 | if fromUpdatableApex { |
| 233 | // error: this jar is part of an updatable apex |
Jiyong Park | ab50b07 | 2021-05-12 17:13:56 +0900 | [diff] [blame] | 234 | 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] | 235 | } else { |
| 236 | // ok: this jar is part of the platform or a non-updatable apex |
| 237 | } |
| 238 | } |
| 239 | } |
| 240 | |
| 241 | // checkUpdatableModules ensures that the updatable modules supplied are not from the platform. |
| 242 | func (b *platformBootclasspathModule) checkUpdatableModules(ctx android.ModuleContext, modules []android.Module) { |
| 243 | for _, m := range modules { |
| 244 | apexInfo := ctx.OtherModuleProvider(m, android.ApexInfoProvider).(android.ApexInfo) |
| 245 | fromUpdatableApex := apexInfo.Updatable |
| 246 | if fromUpdatableApex { |
| 247 | // ok: this jar is part of an updatable apex |
| 248 | } else { |
| 249 | name := ctx.OtherModuleName(m) |
| 250 | if apexInfo.IsForPlatform() { |
Paul Duffin | 7487a7a | 2021-05-19 09:36:09 +0100 | [diff] [blame] | 251 | // If AlwaysUsePrebuiltSdks() returns true then it is possible that the updatable list will |
| 252 | // include platform variants of a prebuilt module due to workarounds elsewhere. In that case |
| 253 | // do not treat this as an error. |
| 254 | // TODO(b/179354495): Always treat this as an error when migration to bootclasspath_fragment |
| 255 | // modules is complete. |
| 256 | if !ctx.Config().AlwaysUsePrebuiltSdks() { |
| 257 | // error: this jar is part of the platform |
| 258 | ctx.ModuleErrorf("module %q from platform is not allowed in the updatable boot jars list", name) |
| 259 | } |
Paul Duffin | f23bc47 | 2021-04-27 12:42:20 +0100 | [diff] [blame] | 260 | } else { |
| 261 | // TODO(b/177892522): Treat this as an error. |
| 262 | // Cannot do that at the moment because framework-wifi and framework-tethering are in the |
| 263 | // PRODUCT_UPDATABLE_BOOT_JARS but not marked as updatable in AOSP. |
| 264 | } |
| 265 | } |
| 266 | } |
| 267 | } |
| 268 | |
Paul Duffin | bb7f1ac | 2021-03-29 22:18:45 +0100 | [diff] [blame] | 269 | func (b *platformBootclasspathModule) getImageConfig(ctx android.EarlyModuleContext) *bootImageConfig { |
| 270 | return defaultBootImageConfig(ctx) |
| 271 | } |
Paul Duffin | 702210b | 2021-04-08 20:12:41 +0100 | [diff] [blame] | 272 | |
| 273 | // generateHiddenAPIBuildActions generates all the hidden API related build rules. |
Paul Duffin | c8ead41 | 2021-06-07 19:28:15 +0100 | [diff] [blame] | 274 | func (b *platformBootclasspathModule) generateHiddenAPIBuildActions(ctx android.ModuleContext, modules []android.Module, fragments []android.Module) bootDexJarByModule { |
Paul Duffin | 702210b | 2021-04-08 20:12:41 +0100 | [diff] [blame] | 275 | |
Paul Duffin | 90b8ad3 | 2021-04-13 12:25:01 +0100 | [diff] [blame] | 276 | // Save the paths to the monolithic files for retrieval via OutputFiles(). |
| 277 | b.hiddenAPIFlagsCSV = hiddenAPISingletonPaths(ctx).flags |
| 278 | b.hiddenAPIIndexCSV = hiddenAPISingletonPaths(ctx).index |
| 279 | b.hiddenAPIMetadataCSV = hiddenAPISingletonPaths(ctx).metadata |
Paul Duffin | 6a76645 | 2021-04-12 14:15:22 +0100 | [diff] [blame] | 280 | |
Adrian Roos | e95a15e | 2021-06-21 16:03:11 +0200 | [diff] [blame] | 281 | bootDexJarByModule := extractBootDexJarsFromModules(ctx, modules) |
| 282 | |
Paul Duffin | 0b65986 | 2021-04-13 13:02:29 +0100 | [diff] [blame] | 283 | // Don't run any hiddenapi rules if UNSAFE_DISABLE_HIDDENAPI_FLAGS=true. This is a performance |
| 284 | // optimization that can be used to reduce the incremental build time but as its name suggests it |
| 285 | // 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] | 286 | if ctx.Config().IsEnvTrue("UNSAFE_DISABLE_HIDDENAPI_FLAGS") { |
Paul Duffin | 0b65986 | 2021-04-13 13:02:29 +0100 | [diff] [blame] | 287 | paths := android.OutputPaths{b.hiddenAPIFlagsCSV, b.hiddenAPIIndexCSV, b.hiddenAPIMetadataCSV} |
| 288 | for _, path := range paths { |
| 289 | ctx.Build(pctx, android.BuildParams{ |
| 290 | Rule: android.Touch, |
| 291 | Output: path, |
| 292 | }) |
| 293 | } |
Adrian Roos | e95a15e | 2021-06-21 16:03:11 +0200 | [diff] [blame] | 294 | return bootDexJarByModule |
Paul Duffin | 0b65986 | 2021-04-13 13:02:29 +0100 | [diff] [blame] | 295 | } |
| 296 | |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 297 | // Construct a list of ClasspathElement objects from the modules and fragments. |
| 298 | classpathElements := CreateClasspathElements(ctx, modules, fragments) |
| 299 | |
| 300 | monolithicInfo := b.createAndProvideMonolithicHiddenAPIInfo(ctx, classpathElements) |
| 301 | |
| 302 | // Extract the classes jars only from those libraries that do not have corresponding fragments as |
| 303 | // the fragments will have already provided the flags that are needed. |
| 304 | classesJars := monolithicInfo.ClassesJars |
| 305 | |
Paul Duffin | 4539a37 | 2021-06-23 23:20:43 +0100 | [diff] [blame] | 306 | // Create the input to pass to buildRuleToGenerateHiddenAPIStubFlagsFile |
Paul Duffin | 1352f7c | 2021-05-21 22:18:49 +0100 | [diff] [blame] | 307 | input := newHiddenAPIFlagInput() |
| 308 | |
| 309 | // Gather stub library information from the dependencies on modules provided by |
| 310 | // hiddenAPIComputeMonolithicStubLibModules. |
| 311 | input.gatherStubLibInfo(ctx, nil) |
| 312 | |
| 313 | // Use the flag files from this module and all the fragments. |
| 314 | input.FlagFilesByCategory = monolithicInfo.FlagsFilesByCategory |
Paul Duffin | 74431d5 | 2021-04-21 14:10:42 +0100 | [diff] [blame] | 315 | |
Paul Duffin | 537ea3d | 2021-05-14 10:38:00 +0100 | [diff] [blame] | 316 | // Generate the monolithic stub-flags.csv file. |
Paul Duffin | 537ea3d | 2021-05-14 10:38:00 +0100 | [diff] [blame] | 317 | stubFlags := hiddenAPISingletonPaths(ctx).stubFlags |
Paul Duffin | 2e88097 | 2021-06-23 23:29:09 +0100 | [diff] [blame] | 318 | buildRuleToGenerateHiddenAPIStubFlagsFile(ctx, "platform-bootclasspath-monolithic-hiddenapi-stub-flags", "monolithic hidden API stub flags", stubFlags, bootDexJarByModule.bootDexJars(), input, monolithicInfo.StubFlagsPaths) |
Paul Duffin | 537ea3d | 2021-05-14 10:38:00 +0100 | [diff] [blame] | 319 | |
Paul Duffin | 537ea3d | 2021-05-14 10:38:00 +0100 | [diff] [blame] | 320 | // Generate the annotation-flags.csv file from all the module annotations. |
Paul Duffin | d061d40 | 2021-06-07 21:36:01 +0100 | [diff] [blame] | 321 | annotationFlags := android.PathForModuleOut(ctx, "hiddenapi-monolithic", "annotation-flags-from-classes.csv") |
| 322 | buildRuleToGenerateAnnotationFlags(ctx, "intermediate hidden API flags", classesJars, stubFlags, annotationFlags) |
Paul Duffin | 537ea3d | 2021-05-14 10:38:00 +0100 | [diff] [blame] | 323 | |
Paul Duffin | d061d40 | 2021-06-07 21:36:01 +0100 | [diff] [blame] | 324 | // Generate the monolithic hiddenapi-flags.csv file. |
| 325 | // |
| 326 | // Use annotation flags generated directly from the classes jars as well as annotation flag files |
| 327 | // provided by prebuilts. |
| 328 | allAnnotationFlagFiles := android.Paths{annotationFlags} |
| 329 | allAnnotationFlagFiles = append(allAnnotationFlagFiles, monolithicInfo.AnnotationFlagsPaths...) |
Paul Duffin | 537ea3d | 2021-05-14 10:38:00 +0100 | [diff] [blame] | 330 | allFlags := hiddenAPISingletonPaths(ctx).flags |
Paul Duffin | d061d40 | 2021-06-07 21:36:01 +0100 | [diff] [blame] | 331 | buildRuleToGenerateHiddenApiFlags(ctx, "hiddenAPIFlagsFile", "monolithic hidden API flags", allFlags, stubFlags, allAnnotationFlagFiles, monolithicInfo.FlagsFilesByCategory, monolithicInfo.AllFlagsPaths, android.OptionalPath{}) |
Paul Duffin | 537ea3d | 2021-05-14 10:38:00 +0100 | [diff] [blame] | 332 | |
| 333 | // Generate an intermediate monolithic hiddenapi-metadata.csv file directly from the annotations |
| 334 | // in the source code. |
Paul Duffin | d061d40 | 2021-06-07 21:36:01 +0100 | [diff] [blame] | 335 | intermediateMetadataCSV := android.PathForModuleOut(ctx, "hiddenapi-monolithic", "metadata-from-classes.csv") |
| 336 | buildRuleToGenerateMetadata(ctx, "intermediate hidden API metadata", classesJars, stubFlags, intermediateMetadataCSV) |
Paul Duffin | 537ea3d | 2021-05-14 10:38:00 +0100 | [diff] [blame] | 337 | |
Paul Duffin | d061d40 | 2021-06-07 21:36:01 +0100 | [diff] [blame] | 338 | // Generate the monolithic hiddenapi-metadata.csv file. |
| 339 | // |
| 340 | // Use metadata files generated directly from the classes jars as well as metadata files provided |
| 341 | // by prebuilts. |
| 342 | // |
| 343 | // This has the side effect of ensuring that the output file uses | quotes just in case that is |
| 344 | // important for the tools that consume the metadata file. |
| 345 | allMetadataFlagFiles := android.Paths{intermediateMetadataCSV} |
| 346 | allMetadataFlagFiles = append(allMetadataFlagFiles, monolithicInfo.MetadataPaths...) |
Paul Duffin | 537ea3d | 2021-05-14 10:38:00 +0100 | [diff] [blame] | 347 | metadataCSV := hiddenAPISingletonPaths(ctx).metadata |
Paul Duffin | d061d40 | 2021-06-07 21:36:01 +0100 | [diff] [blame] | 348 | b.buildRuleMergeCSV(ctx, "monolithic hidden API metadata", allMetadataFlagFiles, metadataCSV) |
Paul Duffin | 537ea3d | 2021-05-14 10:38:00 +0100 | [diff] [blame] | 349 | |
Paul Duffin | d061d40 | 2021-06-07 21:36:01 +0100 | [diff] [blame] | 350 | // Generate an intermediate monolithic hiddenapi-index.csv file directly from the CSV files in the |
| 351 | // classes jars. |
| 352 | intermediateIndexCSV := android.PathForModuleOut(ctx, "hiddenapi-monolithic", "index-from-classes.csv") |
| 353 | buildRuleToGenerateIndex(ctx, "intermediate hidden API index", classesJars, intermediateIndexCSV) |
| 354 | |
| 355 | // Generate the monolithic hiddenapi-index.csv file. |
| 356 | // |
| 357 | // Use index files generated directly from the classes jars as well as index files provided |
| 358 | // by prebuilts. |
| 359 | allIndexFlagFiles := android.Paths{intermediateIndexCSV} |
| 360 | allIndexFlagFiles = append(allIndexFlagFiles, monolithicInfo.IndexPaths...) |
Paul Duffin | 537ea3d | 2021-05-14 10:38:00 +0100 | [diff] [blame] | 361 | indexCSV := hiddenAPISingletonPaths(ctx).index |
Paul Duffin | d061d40 | 2021-06-07 21:36:01 +0100 | [diff] [blame] | 362 | b.buildRuleMergeCSV(ctx, "monolithic hidden API index", allIndexFlagFiles, indexCSV) |
Paul Duffin | c8ead41 | 2021-06-07 19:28:15 +0100 | [diff] [blame] | 363 | |
| 364 | return bootDexJarByModule |
Paul Duffin | 74431d5 | 2021-04-21 14:10:42 +0100 | [diff] [blame] | 365 | } |
| 366 | |
Paul Duffin | 438eb57 | 2021-05-21 16:58:23 +0100 | [diff] [blame] | 367 | // createAndProvideMonolithicHiddenAPIInfo creates a MonolithicHiddenAPIInfo and provides it for |
| 368 | // testing. |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 369 | func (b *platformBootclasspathModule) createAndProvideMonolithicHiddenAPIInfo(ctx android.ModuleContext, classpathElements ClasspathElements) MonolithicHiddenAPIInfo { |
Paul Duffin | 1352f7c | 2021-05-21 22:18:49 +0100 | [diff] [blame] | 370 | // Create a temporary input structure in which to collate information provided directly by this |
| 371 | // module, either through properties or direct dependencies. |
| 372 | temporaryInput := newHiddenAPIFlagInput() |
| 373 | |
| 374 | // Create paths to the flag files specified in the properties. |
| 375 | temporaryInput.extractFlagFilesFromProperties(ctx, &b.properties.Hidden_api) |
| 376 | |
| 377 | // Create the monolithic info, by starting with the flag files specified on this and then merging |
| 378 | // in information from all the fragment dependencies of this. |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 379 | monolithicInfo := newMonolithicHiddenAPIInfo(ctx, temporaryInput.FlagFilesByCategory, classpathElements) |
Paul Duffin | 438eb57 | 2021-05-21 16:58:23 +0100 | [diff] [blame] | 380 | |
| 381 | // Store the information for testing. |
Paul Duffin | 524c82c | 2021-06-09 14:39:28 +0100 | [diff] [blame] | 382 | ctx.SetProvider(MonolithicHiddenAPIInfoProvider, monolithicInfo) |
Paul Duffin | 438eb57 | 2021-05-21 16:58:23 +0100 | [diff] [blame] | 383 | return monolithicInfo |
| 384 | } |
| 385 | |
Paul Duffin | 537ea3d | 2021-05-14 10:38:00 +0100 | [diff] [blame] | 386 | 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] | 387 | rule := android.NewRuleBuilder(pctx, ctx) |
| 388 | rule.Command(). |
| 389 | BuiltTool("merge_csv"). |
| 390 | Flag("--key_field signature"). |
Paul Duffin | 85dee5d | 2021-04-13 00:14:38 +0100 | [diff] [blame] | 391 | FlagWithOutput("--output=", outputPath). |
Paul Duffin | 537ea3d | 2021-05-14 10:38:00 +0100 | [diff] [blame] | 392 | Inputs(inputPaths) |
Paul Duffin | 85dee5d | 2021-04-13 00:14:38 +0100 | [diff] [blame] | 393 | |
Paul Duffin | 537ea3d | 2021-05-14 10:38:00 +0100 | [diff] [blame] | 394 | rule.Build(desc, desc) |
Paul Duffin | 85dee5d | 2021-04-13 00:14:38 +0100 | [diff] [blame] | 395 | } |
Paul Duffin | ad19d38 | 2021-04-26 16:44:00 +0100 | [diff] [blame] | 396 | |
Paul Duffin | 12d29b7 | 2021-04-29 13:50:01 +0100 | [diff] [blame] | 397 | // generateHiddenApiMakeVars generates make variables needed by hidden API related make rules, e.g. |
| 398 | // veridex and run-appcompat. |
| 399 | func (b *platformBootclasspathModule) generateHiddenApiMakeVars(ctx android.MakeVarsContext) { |
| 400 | if ctx.Config().IsEnvTrue("UNSAFE_DISABLE_HIDDENAPI_FLAGS") { |
| 401 | return |
| 402 | } |
| 403 | // INTERNAL_PLATFORM_HIDDENAPI_FLAGS is used by Make rules in art/ and cts/. |
| 404 | ctx.Strict("INTERNAL_PLATFORM_HIDDENAPI_FLAGS", b.hiddenAPIFlagsCSV.String()) |
| 405 | } |
| 406 | |
Paul Duffin | ad19d38 | 2021-04-26 16:44:00 +0100 | [diff] [blame] | 407 | // generateBootImageBuildActions generates ninja rules related to the boot image creation. |
Paul Duffin | 7ebebfd | 2021-04-27 19:36:57 +0100 | [diff] [blame] | 408 | func (b *platformBootclasspathModule) generateBootImageBuildActions(ctx android.ModuleContext, nonUpdatableModules, updatableModules []android.Module) { |
Paul Duffin | ad19d38 | 2021-04-26 16:44:00 +0100 | [diff] [blame] | 409 | // Force the GlobalSoongConfig to be created and cached for use by the dex_bootjars |
| 410 | // GenerateSingletonBuildActions method as it cannot create it for itself. |
| 411 | dexpreopt.GetGlobalSoongConfig(ctx) |
| 412 | |
| 413 | imageConfig := b.getImageConfig(ctx) |
| 414 | if imageConfig == nil { |
| 415 | return |
| 416 | } |
| 417 | |
| 418 | global := dexpreopt.GetGlobalConfig(ctx) |
| 419 | if !shouldBuildBootImages(ctx.Config(), global) { |
| 420 | return |
| 421 | } |
| 422 | |
| 423 | // Generate the framework profile rule |
| 424 | bootFrameworkProfileRule(ctx, imageConfig) |
Paul Duffin | 4c09442 | 2021-04-26 20:10:48 +0100 | [diff] [blame] | 425 | |
Paul Duffin | 3bc8e21 | 2021-07-16 14:00:37 +0100 | [diff] [blame] | 426 | // If always using prebuilt sdks then do not generate the updatable-bcp-packages.txt file as it |
| 427 | // will break because the prebuilts do not yet specify a permitted_packages property. |
| 428 | // TODO(b/193889859): Remove when the prebuilts have been updated. |
| 429 | if !ctx.Config().AlwaysUsePrebuiltSdks() { |
| 430 | // Generate the updatable bootclasspath packages rule. |
| 431 | generateUpdatableBcpPackagesRule(ctx, imageConfig, updatableModules) |
| 432 | } |
Paul Duffin | f7a5592 | 2021-04-26 23:09:15 +0100 | [diff] [blame] | 433 | |
Paul Duffin | 7ebebfd | 2021-04-27 19:36:57 +0100 | [diff] [blame] | 434 | // Copy non-updatable module dex jars to their predefined locations. |
Paul Duffin | 5f148ca | 2021-06-02 17:24:22 +0100 | [diff] [blame] | 435 | nonUpdatableBootDexJarsByModule := extractEncodedDexJarsFromModules(ctx, nonUpdatableModules) |
| 436 | copyBootJarsToPredefinedLocations(ctx, nonUpdatableBootDexJarsByModule, imageConfig.dexPathsByModule) |
Paul Duffin | 7ebebfd | 2021-04-27 19:36:57 +0100 | [diff] [blame] | 437 | |
| 438 | // Copy updatable module dex jars to their predefined locations. |
| 439 | config := GetUpdatableBootConfig(ctx) |
Paul Duffin | 5f148ca | 2021-06-02 17:24:22 +0100 | [diff] [blame] | 440 | updatableBootDexJarsByModule := extractEncodedDexJarsFromModules(ctx, updatableModules) |
| 441 | copyBootJarsToPredefinedLocations(ctx, updatableBootDexJarsByModule, config.dexPathsByModule) |
Paul Duffin | 7ebebfd | 2021-04-27 19:36:57 +0100 | [diff] [blame] | 442 | |
Paul Duffin | 2fc82ad | 2021-04-29 23:36:12 +0100 | [diff] [blame] | 443 | // Build a profile for the image config and then use that to build the boot image. |
| 444 | profile := bootImageProfileRule(ctx, imageConfig) |
Paul Duffin | 56afb27 | 2021-07-01 22:04:22 +0100 | [diff] [blame] | 445 | |
Paul Duffin | a56be7d | 2021-07-02 13:00:43 +0100 | [diff] [blame] | 446 | // Build boot image files for the android variants. |
| 447 | androidBootImageFilesByArch := buildBootImageVariantsForAndroidOs(ctx, imageConfig, profile) |
| 448 | |
| 449 | // Zip the android variant boot image files up. |
| 450 | buildBootImageZipInPredefinedLocation(ctx, imageConfig, androidBootImageFilesByArch) |
| 451 | |
| 452 | // Build boot image files for the host variants. There are use directly by ART host side tests. |
| 453 | buildBootImageVariantsForBuildOs(ctx, imageConfig, profile) |
Paul Duffin | 2fc82ad | 2021-04-29 23:36:12 +0100 | [diff] [blame] | 454 | |
Paul Duffin | f7a5592 | 2021-04-26 23:09:15 +0100 | [diff] [blame] | 455 | dumpOatRules(ctx, imageConfig) |
Paul Duffin | ad19d38 | 2021-04-26 16:44:00 +0100 | [diff] [blame] | 456 | } |