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