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