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) { |
LaMont Jones | 0c10e4d | 2023-05-16 00:58:37 +0000 | [diff] [blame] | 29 | ctx.RegisterParallelSingletonModuleType("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 ( |
satayev | d604b21 | 2021-07-21 14:23:52 +0100 | [diff] [blame] | 35 | platformBootclasspathArtBootJarDepTag = bootclasspathDependencyTag{name: "art-boot-jar"} |
| 36 | platformBootclasspathBootJarDepTag = bootclasspathDependencyTag{name: "platform-boot-jar"} |
| 37 | platformBootclasspathApexBootJarDepTag = bootclasspathDependencyTag{name: "apex-boot-jar"} |
Paul Duffin | 01b463b | 2021-04-26 20:05:39 +0100 | [diff] [blame] | 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 |
Anton Hansson | b3738ed | 2023-09-21 16:23:20 +0000 | [diff] [blame^] | 60 | |
| 61 | // Path to a srcjar containing all the transitive sources of the bootclasspath. |
| 62 | srcjar android.OutputPath |
Paul Duffin | 62d8c3b | 2021-04-07 20:35:11 +0100 | [diff] [blame] | 63 | } |
| 64 | |
Paul Duffin | 62d8c3b | 2021-04-07 20:35:11 +0100 | [diff] [blame] | 65 | type platformBootclasspathProperties struct { |
Paul Duffin | b67d878 | 2021-04-22 11:49:41 +0100 | [diff] [blame] | 66 | BootclasspathFragmentsDepsProperties |
Paul Duffin | 702210b | 2021-04-08 20:12:41 +0100 | [diff] [blame] | 67 | |
Paul Duffin | 9b61abb | 2022-07-27 16:16:54 +0000 | [diff] [blame] | 68 | HiddenAPIFlagFileProperties |
Paul Duffin | bb7f1ac | 2021-03-29 22:18:45 +0100 | [diff] [blame] | 69 | } |
| 70 | |
Paul Duffin | e3ecce6 | 2021-04-29 10:34:11 +0100 | [diff] [blame] | 71 | func platformBootclasspathFactory() android.SingletonModule { |
Paul Duffin | bb7f1ac | 2021-03-29 22:18:45 +0100 | [diff] [blame] | 72 | m := &platformBootclasspathModule{} |
Paul Duffin | 62d8c3b | 2021-04-07 20:35:11 +0100 | [diff] [blame] | 73 | m.AddProperties(&m.properties) |
satayev | 95e9c5b | 2021-04-29 11:50:26 +0100 | [diff] [blame] | 74 | initClasspathFragment(m, BOOTCLASSPATH) |
Paul Duffin | bb7f1ac | 2021-03-29 22:18:45 +0100 | [diff] [blame] | 75 | android.InitAndroidArchModule(m, android.DeviceSupported, android.MultilibCommon) |
| 76 | return m |
| 77 | } |
| 78 | |
Paul Duffin | 6a76645 | 2021-04-12 14:15:22 +0100 | [diff] [blame] | 79 | var _ android.OutputFileProducer = (*platformBootclasspathModule)(nil) |
| 80 | |
Artur Satayev | 97259dc | 2021-04-07 15:17:14 +0100 | [diff] [blame] | 81 | func (b *platformBootclasspathModule) AndroidMkEntries() (entries []android.AndroidMkEntries) { |
| 82 | entries = append(entries, android.AndroidMkEntries{ |
| 83 | Class: "FAKE", |
| 84 | // Need at least one output file in order for this to take effect. |
| 85 | OutputFile: android.OptionalPathForPath(b.hiddenAPIFlagsCSV), |
| 86 | Include: "$(BUILD_PHONY_PACKAGE)", |
| 87 | }) |
satayev | 128ce2f | 2021-05-06 13:21:15 +0100 | [diff] [blame] | 88 | entries = append(entries, b.classpathFragmentBase().androidMkEntries()...) |
Artur Satayev | 97259dc | 2021-04-07 15:17:14 +0100 | [diff] [blame] | 89 | return |
Paul Duffin | 6a76645 | 2021-04-12 14:15:22 +0100 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | // Make the hidden API files available from the platform-bootclasspath module. |
| 93 | func (b *platformBootclasspathModule) OutputFiles(tag string) (android.Paths, error) { |
| 94 | switch tag { |
| 95 | case "hiddenapi-flags.csv": |
| 96 | return android.Paths{b.hiddenAPIFlagsCSV}, nil |
| 97 | case "hiddenapi-index.csv": |
| 98 | return android.Paths{b.hiddenAPIIndexCSV}, nil |
| 99 | case "hiddenapi-metadata.csv": |
| 100 | return android.Paths{b.hiddenAPIMetadataCSV}, nil |
Anton Hansson | b3738ed | 2023-09-21 16:23:20 +0000 | [diff] [blame^] | 101 | case ".srcjar": |
| 102 | return android.Paths{b.srcjar}, nil |
Paul Duffin | 6a76645 | 2021-04-12 14:15:22 +0100 | [diff] [blame] | 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 | |
Jiakai Zhang | bc698cd | 2023-05-08 16:28:38 +0000 | [diff] [blame] | 111 | if !dexpreopt.IsDex2oatNeeded(ctx) { |
Qiao Yang | 8d8c660 | 2023-05-05 15:03:24 +0000 | [diff] [blame] | 112 | return |
| 113 | } |
| 114 | |
Paul Duffin | bb7f1ac | 2021-03-29 22:18:45 +0100 | [diff] [blame] | 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) { |
Pratyush | faec4db | 2023-07-20 11:19:04 +0000 | [diff] [blame] | 121 | if ctx.Config().DisableHiddenApiChecks() { |
Paul Duffin | 74431d5 | 2021-04-21 14:10:42 +0100 | [diff] [blame] | 122 | return |
| 123 | } |
| 124 | |
| 125 | // Add dependencies onto the stub lib modules. |
Paul Duffin | 31fad80 | 2021-06-18 18:14:25 +0100 | [diff] [blame] | 126 | apiLevelToStubLibModules := hiddenAPIComputeMonolithicStubLibModules(ctx.Config()) |
| 127 | hiddenAPIAddStubLibDependencies(ctx, apiLevelToStubLibModules) |
Paul Duffin | 74431d5 | 2021-04-21 14:10:42 +0100 | [diff] [blame] | 128 | } |
| 129 | |
Paul Duffin | 4994d26 | 2021-04-22 12:08:59 +0100 | [diff] [blame] | 130 | func (b *platformBootclasspathModule) BootclasspathDepsMutator(ctx android.BottomUpMutatorContext) { |
Jiakai Zhang | cb13b5d | 2023-07-13 11:03:38 +0100 | [diff] [blame] | 131 | // Add dependencies on all the ART jars. |
| 132 | global := dexpreopt.GetGlobalConfig(ctx) |
| 133 | addDependenciesOntoBootImageModules(ctx, global.ArtApexJars, platformBootclasspathArtBootJarDepTag) |
Paul Duffin | b432df9 | 2021-03-22 22:09:42 +0000 | [diff] [blame] | 134 | |
Jiakai Zhang | cb13b5d | 2023-07-13 11:03:38 +0100 | [diff] [blame] | 135 | // Add dependencies on all the non-updatable jars, which are on the platform or in non-updatable |
| 136 | // APEXes. |
Jiakai Zhang | c08c162 | 2023-05-10 18:38:34 +0100 | [diff] [blame] | 137 | addDependenciesOntoBootImageModules(ctx, b.platformJars(ctx), platformBootclasspathBootJarDepTag) |
Paul Duffin | b432df9 | 2021-03-22 22:09:42 +0000 | [diff] [blame] | 138 | |
Jiakai Zhang | cb13b5d | 2023-07-13 11:03:38 +0100 | [diff] [blame] | 139 | // Add dependencies on all the updatable jars, except the ART jars. |
satayev | d604b21 | 2021-07-21 14:23:52 +0100 | [diff] [blame] | 140 | apexJars := dexpreopt.GetGlobalConfig(ctx).ApexBootJars |
| 141 | addDependenciesOntoBootImageModules(ctx, apexJars, platformBootclasspathApexBootJarDepTag) |
Paul Duffin | 62d8c3b | 2021-04-07 20:35:11 +0100 | [diff] [blame] | 142 | |
Paul Duffin | 4994d26 | 2021-04-22 12:08:59 +0100 | [diff] [blame] | 143 | // Add dependencies on all the fragments. |
| 144 | b.properties.BootclasspathFragmentsDepsProperties.addDependenciesOntoFragments(ctx) |
Paul Duffin | b432df9 | 2021-03-22 22:09:42 +0000 | [diff] [blame] | 145 | } |
| 146 | |
Paul Duffin | 01b463b | 2021-04-26 20:05:39 +0100 | [diff] [blame] | 147 | func addDependenciesOntoBootImageModules(ctx android.BottomUpMutatorContext, modules android.ConfiguredJarList, tag bootclasspathDependencyTag) { |
Paul Duffin | b432df9 | 2021-03-22 22:09:42 +0000 | [diff] [blame] | 148 | for i := 0; i < modules.Len(); i++ { |
| 149 | apex := modules.Apex(i) |
| 150 | name := modules.Jar(i) |
| 151 | |
Paul Duffin | 01b463b | 2021-04-26 20:05:39 +0100 | [diff] [blame] | 152 | addDependencyOntoApexModulePair(ctx, apex, name, tag) |
Paul Duffin | b432df9 | 2021-03-22 22:09:42 +0000 | [diff] [blame] | 153 | } |
| 154 | } |
| 155 | |
Paul Duffin | e3ecce6 | 2021-04-29 10:34:11 +0100 | [diff] [blame] | 156 | // GenerateSingletonBuildActions does nothing and must never do anything. |
| 157 | // |
| 158 | // This module only implements android.SingletonModule so that it can implement |
| 159 | // android.SingletonMakeVarsProvider. |
| 160 | func (b *platformBootclasspathModule) GenerateSingletonBuildActions(android.SingletonContext) { |
| 161 | // Keep empty |
| 162 | } |
| 163 | |
| 164 | func (d *platformBootclasspathModule) MakeVars(ctx android.MakeVarsContext) { |
Paul Duffin | 12d29b7 | 2021-04-29 13:50:01 +0100 | [diff] [blame] | 165 | d.generateHiddenApiMakeVars(ctx) |
Paul Duffin | e3ecce6 | 2021-04-29 10:34:11 +0100 | [diff] [blame] | 166 | } |
| 167 | |
Paul Duffin | bb7f1ac | 2021-03-29 22:18:45 +0100 | [diff] [blame] | 168 | func (b *platformBootclasspathModule) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
satayev | d604b21 | 2021-07-21 14:23:52 +0100 | [diff] [blame] | 169 | // Gather all the dependencies from the art, platform, and apex boot jars. |
Paul Duffin | 01b463b | 2021-04-26 20:05:39 +0100 | [diff] [blame] | 170 | artModules := gatherApexModulePairDepsWithTag(ctx, platformBootclasspathArtBootJarDepTag) |
satayev | d604b21 | 2021-07-21 14:23:52 +0100 | [diff] [blame] | 171 | platformModules := gatherApexModulePairDepsWithTag(ctx, platformBootclasspathBootJarDepTag) |
| 172 | apexModules := gatherApexModulePairDepsWithTag(ctx, platformBootclasspathApexBootJarDepTag) |
Paul Duffin | 01b463b | 2021-04-26 20:05:39 +0100 | [diff] [blame] | 173 | |
| 174 | // Concatenate them all, in order as they would appear on the bootclasspath. |
| 175 | var allModules []android.Module |
| 176 | allModules = append(allModules, artModules...) |
satayev | d604b21 | 2021-07-21 14:23:52 +0100 | [diff] [blame] | 177 | allModules = append(allModules, platformModules...) |
| 178 | allModules = append(allModules, apexModules...) |
Paul Duffin | 01b463b | 2021-04-26 20:05:39 +0100 | [diff] [blame] | 179 | b.configuredModules = allModules |
| 180 | |
Anton Hansson | 57162c5 | 2023-09-20 13:41:30 +0000 | [diff] [blame] | 181 | var transitiveSrcFiles android.Paths |
| 182 | for _, module := range allModules { |
| 183 | depInfo := ctx.OtherModuleProvider(module, JavaInfoProvider).(JavaInfo) |
| 184 | if depInfo.TransitiveSrcFiles != nil { |
| 185 | transitiveSrcFiles = append(transitiveSrcFiles, depInfo.TransitiveSrcFiles.ToList()...) |
| 186 | } |
| 187 | } |
| 188 | jarArgs := resourcePathsToJarArgs(transitiveSrcFiles) |
| 189 | jarArgs = append(jarArgs, "-srcjar") // Move srcfiles to the right package |
Anton Hansson | b3738ed | 2023-09-21 16:23:20 +0000 | [diff] [blame^] | 190 | b.srcjar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-transitive.srcjar").OutputPath |
| 191 | TransformResourcesToJar(ctx, b.srcjar, jarArgs, transitiveSrcFiles) |
Anton Hansson | 57162c5 | 2023-09-20 13:41:30 +0000 | [diff] [blame] | 192 | |
Paul Duffin | 01b463b | 2021-04-26 20:05:39 +0100 | [diff] [blame] | 193 | // Gather all the fragments dependencies. |
Paul Duffin | 9bacf56 | 2021-04-28 21:16:02 +0100 | [diff] [blame] | 194 | b.fragments = gatherApexModulePairDepsWithTag(ctx, bootclasspathFragmentDepTag) |
Paul Duffin | b432df9 | 2021-03-22 22:09:42 +0000 | [diff] [blame] | 195 | |
Paul Duffin | f23bc47 | 2021-04-27 12:42:20 +0100 | [diff] [blame] | 196 | // Check the configuration of the boot modules. |
| 197 | // ART modules are checked by the art-bootclasspath-fragment. |
satayev | d604b21 | 2021-07-21 14:23:52 +0100 | [diff] [blame] | 198 | b.checkPlatformModules(ctx, platformModules) |
| 199 | b.checkApexModules(ctx, apexModules) |
Paul Duffin | f23bc47 | 2021-04-27 12:42:20 +0100 | [diff] [blame] | 200 | |
satayev | 013485b | 2021-05-06 23:38:10 +0100 | [diff] [blame] | 201 | b.generateClasspathProtoBuildActions(ctx) |
| 202 | |
Paul Duffin | c8ead41 | 2021-06-07 19:28:15 +0100 | [diff] [blame] | 203 | bootDexJarByModule := b.generateHiddenAPIBuildActions(ctx, b.configuredModules, b.fragments) |
| 204 | buildRuleForBootJarsPackageCheck(ctx, bootDexJarByModule) |
Paul Duffin | 702210b | 2021-04-08 20:12:41 +0100 | [diff] [blame] | 205 | |
Jiakai Zhang | c08c162 | 2023-05-10 18:38:34 +0100 | [diff] [blame] | 206 | b.copyApexBootJarsForAppsDexpreopt(ctx, apexModules) |
Paul Duffin | bb7f1ac | 2021-03-29 22:18:45 +0100 | [diff] [blame] | 207 | } |
| 208 | |
satayev | 013485b | 2021-05-06 23:38:10 +0100 | [diff] [blame] | 209 | // Generate classpaths.proto config |
| 210 | func (b *platformBootclasspathModule) generateClasspathProtoBuildActions(ctx android.ModuleContext) { |
satayev | b309050 | 2021-06-15 17:49:10 +0100 | [diff] [blame] | 211 | configuredJars := b.configuredJars(ctx) |
satayev | 013485b | 2021-05-06 23:38:10 +0100 | [diff] [blame] | 212 | // ART and platform boot jars must have a corresponding entry in DEX2OATBOOTCLASSPATH |
satayev | b309050 | 2021-06-15 17:49:10 +0100 | [diff] [blame] | 213 | classpathJars := configuredJarListToClasspathJars(ctx, configuredJars, BOOTCLASSPATH, DEX2OATBOOTCLASSPATH) |
| 214 | b.classpathFragmentBase().generateClasspathProtoBuildActions(ctx, configuredJars, classpathJars) |
satayev | 013485b | 2021-05-06 23:38:10 +0100 | [diff] [blame] | 215 | } |
| 216 | |
satayev | 142ed27 | 2021-06-15 16:21:17 +0100 | [diff] [blame] | 217 | func (b *platformBootclasspathModule) configuredJars(ctx android.ModuleContext) android.ConfiguredJarList { |
satayev | b309050 | 2021-06-15 17:49:10 +0100 | [diff] [blame] | 218 | // Include all non APEX jars |
Jiakai Zhang | c08c162 | 2023-05-10 18:38:34 +0100 | [diff] [blame] | 219 | jars := b.platformJars(ctx) |
satayev | b309050 | 2021-06-15 17:49:10 +0100 | [diff] [blame] | 220 | |
| 221 | // Include jars from APEXes that don't populate their classpath proto config. |
satayev | d604b21 | 2021-07-21 14:23:52 +0100 | [diff] [blame] | 222 | remainingJars := dexpreopt.GetGlobalConfig(ctx).ApexBootJars |
satayev | b309050 | 2021-06-15 17:49:10 +0100 | [diff] [blame] | 223 | for _, fragment := range b.fragments { |
| 224 | info := ctx.OtherModuleProvider(fragment, ClasspathFragmentProtoContentInfoProvider).(ClasspathFragmentProtoContentInfo) |
| 225 | if info.ClasspathFragmentProtoGenerated { |
| 226 | remainingJars = remainingJars.RemoveList(info.ClasspathFragmentProtoContents) |
| 227 | } |
| 228 | } |
| 229 | for i := 0; i < remainingJars.Len(); i++ { |
| 230 | jars = jars.Append(remainingJars.Apex(i), remainingJars.Jar(i)) |
| 231 | } |
| 232 | |
| 233 | return jars |
satayev | 013485b | 2021-05-06 23:38:10 +0100 | [diff] [blame] | 234 | } |
| 235 | |
Jiakai Zhang | c08c162 | 2023-05-10 18:38:34 +0100 | [diff] [blame] | 236 | func (b *platformBootclasspathModule) platformJars(ctx android.PathContext) android.ConfiguredJarList { |
Jiakai Zhang | cb13b5d | 2023-07-13 11:03:38 +0100 | [diff] [blame] | 237 | global := dexpreopt.GetGlobalConfig(ctx) |
| 238 | return global.BootJars.RemoveList(global.ArtApexJars) |
Jiakai Zhang | c08c162 | 2023-05-10 18:38:34 +0100 | [diff] [blame] | 239 | } |
| 240 | |
satayev | d604b21 | 2021-07-21 14:23:52 +0100 | [diff] [blame] | 241 | // checkPlatformModules ensures that the non-updatable modules supplied are not part of an |
| 242 | // apex module. |
| 243 | func (b *platformBootclasspathModule) checkPlatformModules(ctx android.ModuleContext, modules []android.Module) { |
| 244 | // TODO(satayev): change this check to only allow core-icu4j, all apex jars should not be here. |
Paul Duffin | f23bc47 | 2021-04-27 12:42:20 +0100 | [diff] [blame] | 245 | for _, m := range modules { |
| 246 | apexInfo := ctx.OtherModuleProvider(m, android.ApexInfoProvider).(android.ApexInfo) |
| 247 | fromUpdatableApex := apexInfo.Updatable |
| 248 | if fromUpdatableApex { |
| 249 | // error: this jar is part of an updatable apex |
Jiakai Zhang | c08c162 | 2023-05-10 18:38:34 +0100 | [diff] [blame] | 250 | ctx.ModuleErrorf("module %q from updatable apexes %q is not allowed in the platform bootclasspath", ctx.OtherModuleName(m), apexInfo.InApexVariants) |
Paul Duffin | f23bc47 | 2021-04-27 12:42:20 +0100 | [diff] [blame] | 251 | } else { |
| 252 | // ok: this jar is part of the platform or a non-updatable apex |
| 253 | } |
| 254 | } |
| 255 | } |
| 256 | |
satayev | d604b21 | 2021-07-21 14:23:52 +0100 | [diff] [blame] | 257 | // checkApexModules ensures that the apex modules supplied are not from the platform. |
| 258 | func (b *platformBootclasspathModule) checkApexModules(ctx android.ModuleContext, modules []android.Module) { |
Paul Duffin | f23bc47 | 2021-04-27 12:42:20 +0100 | [diff] [blame] | 259 | for _, m := range modules { |
| 260 | apexInfo := ctx.OtherModuleProvider(m, android.ApexInfoProvider).(android.ApexInfo) |
| 261 | fromUpdatableApex := apexInfo.Updatable |
| 262 | if fromUpdatableApex { |
| 263 | // ok: this jar is part of an updatable apex |
| 264 | } else { |
| 265 | name := ctx.OtherModuleName(m) |
| 266 | if apexInfo.IsForPlatform() { |
Paul Duffin | 7487a7a | 2021-05-19 09:36:09 +0100 | [diff] [blame] | 267 | // If AlwaysUsePrebuiltSdks() returns true then it is possible that the updatable list will |
| 268 | // include platform variants of a prebuilt module due to workarounds elsewhere. In that case |
| 269 | // do not treat this as an error. |
| 270 | // TODO(b/179354495): Always treat this as an error when migration to bootclasspath_fragment |
| 271 | // modules is complete. |
| 272 | if !ctx.Config().AlwaysUsePrebuiltSdks() { |
| 273 | // error: this jar is part of the platform |
satayev | d604b21 | 2021-07-21 14:23:52 +0100 | [diff] [blame] | 274 | ctx.ModuleErrorf("module %q from platform is not allowed in the apex boot jars list", name) |
Paul Duffin | 7487a7a | 2021-05-19 09:36:09 +0100 | [diff] [blame] | 275 | } |
Paul Duffin | f23bc47 | 2021-04-27 12:42:20 +0100 | [diff] [blame] | 276 | } else { |
| 277 | // TODO(b/177892522): Treat this as an error. |
| 278 | // Cannot do that at the moment because framework-wifi and framework-tethering are in the |
satayev | d604b21 | 2021-07-21 14:23:52 +0100 | [diff] [blame] | 279 | // PRODUCT_APEX_BOOT_JARS but not marked as updatable in AOSP. |
Paul Duffin | f23bc47 | 2021-04-27 12:42:20 +0100 | [diff] [blame] | 280 | } |
| 281 | } |
| 282 | } |
| 283 | } |
| 284 | |
Paul Duffin | 702210b | 2021-04-08 20:12:41 +0100 | [diff] [blame] | 285 | // generateHiddenAPIBuildActions generates all the hidden API related build rules. |
Paul Duffin | c8ead41 | 2021-06-07 19:28:15 +0100 | [diff] [blame] | 286 | 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] | 287 | |
Paul Duffin | 90b8ad3 | 2021-04-13 12:25:01 +0100 | [diff] [blame] | 288 | // Save the paths to the monolithic files for retrieval via OutputFiles(). |
| 289 | b.hiddenAPIFlagsCSV = hiddenAPISingletonPaths(ctx).flags |
| 290 | b.hiddenAPIIndexCSV = hiddenAPISingletonPaths(ctx).index |
| 291 | b.hiddenAPIMetadataCSV = hiddenAPISingletonPaths(ctx).metadata |
Paul Duffin | 6a76645 | 2021-04-12 14:15:22 +0100 | [diff] [blame] | 292 | |
Adrian Roos | e95a15e | 2021-06-21 16:03:11 +0200 | [diff] [blame] | 293 | bootDexJarByModule := extractBootDexJarsFromModules(ctx, modules) |
| 294 | |
Pratyush | faec4db | 2023-07-20 11:19:04 +0000 | [diff] [blame] | 295 | // Don't run any hiddenapi rules if hidden api checks are disabled. This is a performance |
Paul Duffin | 0b65986 | 2021-04-13 13:02:29 +0100 | [diff] [blame] | 296 | // optimization that can be used to reduce the incremental build time but as its name suggests it |
| 297 | // can be unsafe to use, e.g. when the changes affect anything that goes on the bootclasspath. |
Pratyush | faec4db | 2023-07-20 11:19:04 +0000 | [diff] [blame] | 298 | if ctx.Config().DisableHiddenApiChecks() { |
Paul Duffin | 0b65986 | 2021-04-13 13:02:29 +0100 | [diff] [blame] | 299 | paths := android.OutputPaths{b.hiddenAPIFlagsCSV, b.hiddenAPIIndexCSV, b.hiddenAPIMetadataCSV} |
| 300 | for _, path := range paths { |
| 301 | ctx.Build(pctx, android.BuildParams{ |
| 302 | Rule: android.Touch, |
| 303 | Output: path, |
| 304 | }) |
| 305 | } |
Adrian Roos | e95a15e | 2021-06-21 16:03:11 +0200 | [diff] [blame] | 306 | return bootDexJarByModule |
Paul Duffin | 0b65986 | 2021-04-13 13:02:29 +0100 | [diff] [blame] | 307 | } |
| 308 | |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 309 | // Construct a list of ClasspathElement objects from the modules and fragments. |
| 310 | classpathElements := CreateClasspathElements(ctx, modules, fragments) |
| 311 | |
| 312 | monolithicInfo := b.createAndProvideMonolithicHiddenAPIInfo(ctx, classpathElements) |
| 313 | |
| 314 | // Extract the classes jars only from those libraries that do not have corresponding fragments as |
| 315 | // the fragments will have already provided the flags that are needed. |
| 316 | classesJars := monolithicInfo.ClassesJars |
| 317 | |
Paul Duffin | 4539a37 | 2021-06-23 23:20:43 +0100 | [diff] [blame] | 318 | // Create the input to pass to buildRuleToGenerateHiddenAPIStubFlagsFile |
Paul Duffin | 1352f7c | 2021-05-21 22:18:49 +0100 | [diff] [blame] | 319 | input := newHiddenAPIFlagInput() |
| 320 | |
| 321 | // Gather stub library information from the dependencies on modules provided by |
| 322 | // hiddenAPIComputeMonolithicStubLibModules. |
| 323 | input.gatherStubLibInfo(ctx, nil) |
| 324 | |
| 325 | // Use the flag files from this module and all the fragments. |
| 326 | input.FlagFilesByCategory = monolithicInfo.FlagsFilesByCategory |
Paul Duffin | 74431d5 | 2021-04-21 14:10:42 +0100 | [diff] [blame] | 327 | |
Paul Duffin | 537ea3d | 2021-05-14 10:38:00 +0100 | [diff] [blame] | 328 | // Generate the monolithic stub-flags.csv file. |
Paul Duffin | 537ea3d | 2021-05-14 10:38:00 +0100 | [diff] [blame] | 329 | stubFlags := hiddenAPISingletonPaths(ctx).stubFlags |
Paul Duffin | 67b9d61 | 2021-07-21 17:38:47 +0100 | [diff] [blame] | 330 | buildRuleToGenerateHiddenAPIStubFlagsFile(ctx, "platform-bootclasspath-monolithic-hiddenapi-stub-flags", "monolithic hidden API stub flags", stubFlags, bootDexJarByModule.bootDexJars(), input, monolithicInfo.StubFlagSubsets) |
Paul Duffin | 537ea3d | 2021-05-14 10:38:00 +0100 | [diff] [blame] | 331 | |
Paul Duffin | 537ea3d | 2021-05-14 10:38:00 +0100 | [diff] [blame] | 332 | // Generate the annotation-flags.csv file from all the module annotations. |
Paul Duffin | d061d40 | 2021-06-07 21:36:01 +0100 | [diff] [blame] | 333 | annotationFlags := android.PathForModuleOut(ctx, "hiddenapi-monolithic", "annotation-flags-from-classes.csv") |
| 334 | buildRuleToGenerateAnnotationFlags(ctx, "intermediate hidden API flags", classesJars, stubFlags, annotationFlags) |
Paul Duffin | 537ea3d | 2021-05-14 10:38:00 +0100 | [diff] [blame] | 335 | |
Paul Duffin | d061d40 | 2021-06-07 21:36:01 +0100 | [diff] [blame] | 336 | // Generate the monolithic hiddenapi-flags.csv file. |
| 337 | // |
| 338 | // Use annotation flags generated directly from the classes jars as well as annotation flag files |
| 339 | // provided by prebuilts. |
| 340 | allAnnotationFlagFiles := android.Paths{annotationFlags} |
| 341 | allAnnotationFlagFiles = append(allAnnotationFlagFiles, monolithicInfo.AnnotationFlagsPaths...) |
Paul Duffin | 537ea3d | 2021-05-14 10:38:00 +0100 | [diff] [blame] | 342 | allFlags := hiddenAPISingletonPaths(ctx).flags |
Paul Duffin | 67b9d61 | 2021-07-21 17:38:47 +0100 | [diff] [blame] | 343 | buildRuleToGenerateHiddenApiFlags(ctx, "hiddenAPIFlagsFile", "monolithic hidden API flags", allFlags, stubFlags, allAnnotationFlagFiles, monolithicInfo.FlagsFilesByCategory, monolithicInfo.FlagSubsets, android.OptionalPath{}) |
Paul Duffin | 537ea3d | 2021-05-14 10:38:00 +0100 | [diff] [blame] | 344 | |
| 345 | // Generate an intermediate monolithic hiddenapi-metadata.csv file directly from the annotations |
| 346 | // in the source code. |
Paul Duffin | d061d40 | 2021-06-07 21:36:01 +0100 | [diff] [blame] | 347 | intermediateMetadataCSV := android.PathForModuleOut(ctx, "hiddenapi-monolithic", "metadata-from-classes.csv") |
| 348 | buildRuleToGenerateMetadata(ctx, "intermediate hidden API metadata", classesJars, stubFlags, intermediateMetadataCSV) |
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 the monolithic hiddenapi-metadata.csv file. |
| 351 | // |
| 352 | // Use metadata files generated directly from the classes jars as well as metadata files provided |
| 353 | // by prebuilts. |
| 354 | // |
| 355 | // This has the side effect of ensuring that the output file uses | quotes just in case that is |
| 356 | // important for the tools that consume the metadata file. |
| 357 | allMetadataFlagFiles := android.Paths{intermediateMetadataCSV} |
| 358 | allMetadataFlagFiles = append(allMetadataFlagFiles, monolithicInfo.MetadataPaths...) |
Paul Duffin | 537ea3d | 2021-05-14 10:38:00 +0100 | [diff] [blame] | 359 | metadataCSV := hiddenAPISingletonPaths(ctx).metadata |
Paul Duffin | d061d40 | 2021-06-07 21:36:01 +0100 | [diff] [blame] | 360 | b.buildRuleMergeCSV(ctx, "monolithic hidden API metadata", allMetadataFlagFiles, metadataCSV) |
Paul Duffin | 537ea3d | 2021-05-14 10:38:00 +0100 | [diff] [blame] | 361 | |
Paul Duffin | d061d40 | 2021-06-07 21:36:01 +0100 | [diff] [blame] | 362 | // Generate an intermediate monolithic hiddenapi-index.csv file directly from the CSV files in the |
| 363 | // classes jars. |
| 364 | intermediateIndexCSV := android.PathForModuleOut(ctx, "hiddenapi-monolithic", "index-from-classes.csv") |
| 365 | buildRuleToGenerateIndex(ctx, "intermediate hidden API index", classesJars, intermediateIndexCSV) |
| 366 | |
| 367 | // Generate the monolithic hiddenapi-index.csv file. |
| 368 | // |
| 369 | // Use index files generated directly from the classes jars as well as index files provided |
| 370 | // by prebuilts. |
| 371 | allIndexFlagFiles := android.Paths{intermediateIndexCSV} |
| 372 | allIndexFlagFiles = append(allIndexFlagFiles, monolithicInfo.IndexPaths...) |
Paul Duffin | 537ea3d | 2021-05-14 10:38:00 +0100 | [diff] [blame] | 373 | indexCSV := hiddenAPISingletonPaths(ctx).index |
Paul Duffin | d061d40 | 2021-06-07 21:36:01 +0100 | [diff] [blame] | 374 | b.buildRuleMergeCSV(ctx, "monolithic hidden API index", allIndexFlagFiles, indexCSV) |
Paul Duffin | c8ead41 | 2021-06-07 19:28:15 +0100 | [diff] [blame] | 375 | |
| 376 | return bootDexJarByModule |
Paul Duffin | 74431d5 | 2021-04-21 14:10:42 +0100 | [diff] [blame] | 377 | } |
| 378 | |
Paul Duffin | 438eb57 | 2021-05-21 16:58:23 +0100 | [diff] [blame] | 379 | // createAndProvideMonolithicHiddenAPIInfo creates a MonolithicHiddenAPIInfo and provides it for |
| 380 | // testing. |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 381 | func (b *platformBootclasspathModule) createAndProvideMonolithicHiddenAPIInfo(ctx android.ModuleContext, classpathElements ClasspathElements) MonolithicHiddenAPIInfo { |
Paul Duffin | 1352f7c | 2021-05-21 22:18:49 +0100 | [diff] [blame] | 382 | // Create a temporary input structure in which to collate information provided directly by this |
| 383 | // module, either through properties or direct dependencies. |
| 384 | temporaryInput := newHiddenAPIFlagInput() |
| 385 | |
| 386 | // Create paths to the flag files specified in the properties. |
Paul Duffin | 9b61abb | 2022-07-27 16:16:54 +0000 | [diff] [blame] | 387 | temporaryInput.extractFlagFilesFromProperties(ctx, &b.properties.HiddenAPIFlagFileProperties) |
Paul Duffin | 1352f7c | 2021-05-21 22:18:49 +0100 | [diff] [blame] | 388 | |
| 389 | // Create the monolithic info, by starting with the flag files specified on this and then merging |
| 390 | // in information from all the fragment dependencies of this. |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 391 | monolithicInfo := newMonolithicHiddenAPIInfo(ctx, temporaryInput.FlagFilesByCategory, classpathElements) |
Paul Duffin | 438eb57 | 2021-05-21 16:58:23 +0100 | [diff] [blame] | 392 | |
| 393 | // Store the information for testing. |
Paul Duffin | 524c82c | 2021-06-09 14:39:28 +0100 | [diff] [blame] | 394 | ctx.SetProvider(MonolithicHiddenAPIInfoProvider, monolithicInfo) |
Paul Duffin | 438eb57 | 2021-05-21 16:58:23 +0100 | [diff] [blame] | 395 | return monolithicInfo |
| 396 | } |
| 397 | |
Paul Duffin | 537ea3d | 2021-05-14 10:38:00 +0100 | [diff] [blame] | 398 | 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] | 399 | rule := android.NewRuleBuilder(pctx, ctx) |
| 400 | rule.Command(). |
| 401 | BuiltTool("merge_csv"). |
| 402 | Flag("--key_field signature"). |
Paul Duffin | 85dee5d | 2021-04-13 00:14:38 +0100 | [diff] [blame] | 403 | FlagWithOutput("--output=", outputPath). |
Paul Duffin | 537ea3d | 2021-05-14 10:38:00 +0100 | [diff] [blame] | 404 | Inputs(inputPaths) |
Paul Duffin | 85dee5d | 2021-04-13 00:14:38 +0100 | [diff] [blame] | 405 | |
Paul Duffin | 537ea3d | 2021-05-14 10:38:00 +0100 | [diff] [blame] | 406 | rule.Build(desc, desc) |
Paul Duffin | 85dee5d | 2021-04-13 00:14:38 +0100 | [diff] [blame] | 407 | } |
Paul Duffin | ad19d38 | 2021-04-26 16:44:00 +0100 | [diff] [blame] | 408 | |
Paul Duffin | 12d29b7 | 2021-04-29 13:50:01 +0100 | [diff] [blame] | 409 | // generateHiddenApiMakeVars generates make variables needed by hidden API related make rules, e.g. |
| 410 | // veridex and run-appcompat. |
| 411 | func (b *platformBootclasspathModule) generateHiddenApiMakeVars(ctx android.MakeVarsContext) { |
| 412 | if ctx.Config().IsEnvTrue("UNSAFE_DISABLE_HIDDENAPI_FLAGS") { |
| 413 | return |
| 414 | } |
| 415 | // INTERNAL_PLATFORM_HIDDENAPI_FLAGS is used by Make rules in art/ and cts/. |
| 416 | ctx.Strict("INTERNAL_PLATFORM_HIDDENAPI_FLAGS", b.hiddenAPIFlagsCSV.String()) |
| 417 | } |
| 418 | |
Jiakai Zhang | d49324d | 2023-02-24 17:05:02 +0000 | [diff] [blame] | 419 | // Copy apex module dex jars to their predefined locations. They will be used for dexpreopt for apps. |
| 420 | func (b *platformBootclasspathModule) copyApexBootJarsForAppsDexpreopt(ctx android.ModuleContext, apexModules []android.Module) { |
| 421 | config := GetApexBootConfig(ctx) |
| 422 | apexBootDexJarsByModule := extractEncodedDexJarsFromModules(ctx, apexModules) |
| 423 | copyBootJarsToPredefinedLocations(ctx, apexBootDexJarsByModule, config.dexPathsByModule) |
Paul Duffin | ad19d38 | 2021-04-26 16:44:00 +0100 | [diff] [blame] | 424 | } |