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" |
Paul Duffin | b432df9 | 2021-03-22 22:09:42 +0000 | [diff] [blame] | 22 | "github.com/google/blueprint" |
Paul Duffin | 62d8c3b | 2021-04-07 20:35:11 +0100 | [diff] [blame] | 23 | "github.com/google/blueprint/proptools" |
Paul Duffin | bb7f1ac | 2021-03-29 22:18:45 +0100 | [diff] [blame] | 24 | ) |
| 25 | |
| 26 | func init() { |
| 27 | registerPlatformBootclasspathBuildComponents(android.InitRegistrationContext) |
| 28 | } |
| 29 | |
| 30 | func registerPlatformBootclasspathBuildComponents(ctx android.RegistrationContext) { |
| 31 | ctx.RegisterModuleType("platform_bootclasspath", platformBootclasspathFactory) |
Paul Duffin | b432df9 | 2021-03-22 22:09:42 +0000 | [diff] [blame] | 32 | |
| 33 | ctx.FinalDepsMutators(func(ctx android.RegisterMutatorsContext) { |
| 34 | ctx.BottomUp("platform_bootclasspath_deps", platformBootclasspathDepsMutator) |
| 35 | }) |
Paul Duffin | bb7f1ac | 2021-03-29 22:18:45 +0100 | [diff] [blame] | 36 | } |
| 37 | |
Paul Duffin | b432df9 | 2021-03-22 22:09:42 +0000 | [diff] [blame] | 38 | type platformBootclasspathDependencyTag struct { |
| 39 | blueprint.BaseDependencyTag |
| 40 | |
| 41 | name string |
| 42 | } |
| 43 | |
| 44 | // Avoid having to make platform bootclasspath content visible to the platform bootclasspath. |
| 45 | // |
| 46 | // This is a temporary workaround to make it easier to migrate to platform bootclasspath with proper |
| 47 | // dependencies. |
| 48 | // TODO(b/177892522): Remove this and add needed visibility. |
| 49 | func (t platformBootclasspathDependencyTag) ExcludeFromVisibilityEnforcement() { |
| 50 | } |
| 51 | |
| 52 | // The tag used for the dependency between the platform bootclasspath and any configured boot jars. |
| 53 | var platformBootclasspathModuleDepTag = platformBootclasspathDependencyTag{name: "module"} |
| 54 | |
Paul Duffin | 62d8c3b | 2021-04-07 20:35:11 +0100 | [diff] [blame] | 55 | // The tag used for the dependency between the platform bootclasspath and bootclasspath_fragments. |
| 56 | var platformBootclasspathFragmentDepTag = platformBootclasspathDependencyTag{name: "fragment"} |
| 57 | |
Paul Duffin | b432df9 | 2021-03-22 22:09:42 +0000 | [diff] [blame] | 58 | var _ android.ExcludeFromVisibilityEnforcementTag = platformBootclasspathDependencyTag{} |
| 59 | |
Paul Duffin | bb7f1ac | 2021-03-29 22:18:45 +0100 | [diff] [blame] | 60 | type platformBootclasspathModule struct { |
| 61 | android.ModuleBase |
Artur Satayev | 97259dc | 2021-04-07 15:17:14 +0100 | [diff] [blame] | 62 | ClasspathFragmentBase |
Paul Duffin | b432df9 | 2021-03-22 22:09:42 +0000 | [diff] [blame] | 63 | |
Paul Duffin | 62d8c3b | 2021-04-07 20:35:11 +0100 | [diff] [blame] | 64 | properties platformBootclasspathProperties |
| 65 | |
Paul Duffin | b432df9 | 2021-03-22 22:09:42 +0000 | [diff] [blame] | 66 | // The apex:module pairs obtained from the configured modules. |
| 67 | // |
| 68 | // Currently only for testing. |
| 69 | configuredModules []android.Module |
Paul Duffin | 62d8c3b | 2021-04-07 20:35:11 +0100 | [diff] [blame] | 70 | |
| 71 | // The apex:module pairs obtained from the fragments. |
| 72 | // |
| 73 | // Currently only for testing. |
| 74 | fragments []android.Module |
Paul Duffin | 6a76645 | 2021-04-12 14:15:22 +0100 | [diff] [blame] | 75 | |
| 76 | // Path to the monolithic hiddenapi-flags.csv file. |
Paul Duffin | 0b65986 | 2021-04-13 13:02:29 +0100 | [diff] [blame] | 77 | hiddenAPIFlagsCSV android.OutputPath |
Paul Duffin | 6a76645 | 2021-04-12 14:15:22 +0100 | [diff] [blame] | 78 | |
| 79 | // Path to the monolithic hiddenapi-index.csv file. |
Paul Duffin | 0b65986 | 2021-04-13 13:02:29 +0100 | [diff] [blame] | 80 | hiddenAPIIndexCSV android.OutputPath |
Paul Duffin | 6a76645 | 2021-04-12 14:15:22 +0100 | [diff] [blame] | 81 | |
| 82 | // Path to the monolithic hiddenapi-unsupported.csv file. |
Paul Duffin | 0b65986 | 2021-04-13 13:02:29 +0100 | [diff] [blame] | 83 | hiddenAPIMetadataCSV android.OutputPath |
Paul Duffin | 62d8c3b | 2021-04-07 20:35:11 +0100 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | // ApexVariantReference specifies a particular apex variant of a module. |
| 87 | type ApexVariantReference struct { |
| 88 | // The name of the module apex variant, i.e. the apex containing the module variant. |
| 89 | // |
| 90 | // If this is not specified then it defaults to "platform" which will cause a dependency to be |
| 91 | // added to the module's platform variant. |
| 92 | Apex *string |
| 93 | |
| 94 | // The name of the module. |
| 95 | Module *string |
| 96 | } |
| 97 | |
| 98 | type platformBootclasspathProperties struct { |
Paul Duffin | 62d8c3b | 2021-04-07 20:35:11 +0100 | [diff] [blame] | 99 | // The names of the bootclasspath_fragment modules that form part of this |
| 100 | // platform_bootclasspath. |
| 101 | Fragments []ApexVariantReference |
Paul Duffin | 702210b | 2021-04-08 20:12:41 +0100 | [diff] [blame] | 102 | |
Paul Duffin | 4616977 | 2021-04-14 15:01:56 +0100 | [diff] [blame] | 103 | Hidden_api HiddenAPIFlagFileProperties |
Paul Duffin | bb7f1ac | 2021-03-29 22:18:45 +0100 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | func platformBootclasspathFactory() android.Module { |
| 107 | m := &platformBootclasspathModule{} |
Paul Duffin | 62d8c3b | 2021-04-07 20:35:11 +0100 | [diff] [blame] | 108 | m.AddProperties(&m.properties) |
Artur Satayev | 97259dc | 2021-04-07 15:17:14 +0100 | [diff] [blame] | 109 | // TODO(satayev): split systemserver and apex jars into separate configs. |
| 110 | initClasspathFragment(m) |
Paul Duffin | bb7f1ac | 2021-03-29 22:18:45 +0100 | [diff] [blame] | 111 | android.InitAndroidArchModule(m, android.DeviceSupported, android.MultilibCommon) |
| 112 | return m |
| 113 | } |
| 114 | |
Paul Duffin | 6a76645 | 2021-04-12 14:15:22 +0100 | [diff] [blame] | 115 | var _ android.OutputFileProducer = (*platformBootclasspathModule)(nil) |
| 116 | |
Artur Satayev | 97259dc | 2021-04-07 15:17:14 +0100 | [diff] [blame] | 117 | func (b *platformBootclasspathModule) AndroidMkEntries() (entries []android.AndroidMkEntries) { |
| 118 | entries = append(entries, android.AndroidMkEntries{ |
| 119 | Class: "FAKE", |
| 120 | // Need at least one output file in order for this to take effect. |
| 121 | OutputFile: android.OptionalPathForPath(b.hiddenAPIFlagsCSV), |
| 122 | Include: "$(BUILD_PHONY_PACKAGE)", |
| 123 | }) |
| 124 | entries = append(entries, b.classpathFragmentBase().getAndroidMkEntries()...) |
| 125 | return |
Paul Duffin | 6a76645 | 2021-04-12 14:15:22 +0100 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | // Make the hidden API files available from the platform-bootclasspath module. |
| 129 | func (b *platformBootclasspathModule) OutputFiles(tag string) (android.Paths, error) { |
| 130 | switch tag { |
| 131 | case "hiddenapi-flags.csv": |
| 132 | return android.Paths{b.hiddenAPIFlagsCSV}, nil |
| 133 | case "hiddenapi-index.csv": |
| 134 | return android.Paths{b.hiddenAPIIndexCSV}, nil |
| 135 | case "hiddenapi-metadata.csv": |
| 136 | return android.Paths{b.hiddenAPIMetadataCSV}, nil |
| 137 | } |
| 138 | |
| 139 | return nil, fmt.Errorf("unknown tag %s", tag) |
| 140 | } |
| 141 | |
Paul Duffin | bb7f1ac | 2021-03-29 22:18:45 +0100 | [diff] [blame] | 142 | func (b *platformBootclasspathModule) DepsMutator(ctx android.BottomUpMutatorContext) { |
Paul Duffin | 74431d5 | 2021-04-21 14:10:42 +0100 | [diff] [blame] | 143 | b.hiddenAPIDepsMutator(ctx) |
| 144 | |
Paul Duffin | bb7f1ac | 2021-03-29 22:18:45 +0100 | [diff] [blame] | 145 | if SkipDexpreoptBootJars(ctx) { |
| 146 | return |
| 147 | } |
| 148 | |
| 149 | // Add a dependency onto the dex2oat tool which is needed for creating the boot image. The |
| 150 | // path is retrieved from the dependency by GetGlobalSoongConfig(ctx). |
| 151 | dexpreopt.RegisterToolDeps(ctx) |
| 152 | } |
| 153 | |
Paul Duffin | 74431d5 | 2021-04-21 14:10:42 +0100 | [diff] [blame] | 154 | func (b *platformBootclasspathModule) hiddenAPIDepsMutator(ctx android.BottomUpMutatorContext) { |
| 155 | if ctx.Config().IsEnvTrue("UNSAFE_DISABLE_HIDDENAPI_FLAGS") { |
| 156 | return |
| 157 | } |
| 158 | |
| 159 | // Add dependencies onto the stub lib modules. |
| 160 | sdkKindToStubLibModules := hiddenAPIComputeMonolithicStubLibModules(ctx.Config()) |
| 161 | hiddenAPIAddStubLibDependencies(ctx, sdkKindToStubLibModules) |
| 162 | } |
| 163 | |
Paul Duffin | b432df9 | 2021-03-22 22:09:42 +0000 | [diff] [blame] | 164 | func platformBootclasspathDepsMutator(ctx android.BottomUpMutatorContext) { |
| 165 | m := ctx.Module() |
| 166 | if p, ok := m.(*platformBootclasspathModule); ok { |
| 167 | // Add dependencies on all the modules configured in the "art" boot image. |
| 168 | artImageConfig := genBootImageConfigs(ctx)[artBootImageName] |
| 169 | addDependenciesOntoBootImageModules(ctx, artImageConfig.modules) |
| 170 | |
| 171 | // Add dependencies on all the modules configured in the "boot" boot image. That does not |
| 172 | // include modules configured in the "art" boot image. |
| 173 | bootImageConfig := p.getImageConfig(ctx) |
| 174 | addDependenciesOntoBootImageModules(ctx, bootImageConfig.modules) |
| 175 | |
| 176 | // Add dependencies on all the updatable modules. |
| 177 | updatableModules := dexpreopt.GetGlobalConfig(ctx).UpdatableBootJars |
| 178 | addDependenciesOntoBootImageModules(ctx, updatableModules) |
Paul Duffin | 62d8c3b | 2021-04-07 20:35:11 +0100 | [diff] [blame] | 179 | |
| 180 | // Add dependencies on all the fragments. |
| 181 | addDependencyOntoApexVariants(ctx, "fragments", p.properties.Fragments, platformBootclasspathFragmentDepTag) |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | func addDependencyOntoApexVariants(ctx android.BottomUpMutatorContext, propertyName string, refs []ApexVariantReference, tag blueprint.DependencyTag) { |
| 186 | for i, ref := range refs { |
| 187 | apex := proptools.StringDefault(ref.Apex, "platform") |
| 188 | |
| 189 | if ref.Module == nil { |
| 190 | ctx.PropertyErrorf(propertyName, "missing module name at position %d", i) |
| 191 | continue |
| 192 | } |
| 193 | name := proptools.String(ref.Module) |
| 194 | |
| 195 | addDependencyOntoApexModulePair(ctx, apex, name, tag) |
Paul Duffin | b432df9 | 2021-03-22 22:09:42 +0000 | [diff] [blame] | 196 | } |
| 197 | } |
| 198 | |
| 199 | func addDependencyOntoApexModulePair(ctx android.BottomUpMutatorContext, apex string, name string, tag blueprint.DependencyTag) { |
| 200 | var variations []blueprint.Variation |
| 201 | if apex != "platform" { |
| 202 | // Pick the correct apex variant. |
| 203 | variations = []blueprint.Variation{ |
| 204 | {Mutator: "apex", Variation: apex}, |
| 205 | } |
| 206 | } |
| 207 | |
| 208 | addedDep := false |
| 209 | if ctx.OtherModuleDependencyVariantExists(variations, name) { |
| 210 | ctx.AddFarVariationDependencies(variations, tag, name) |
| 211 | addedDep = true |
| 212 | } |
| 213 | |
| 214 | // Add a dependency on the prebuilt module if it exists. |
| 215 | prebuiltName := android.PrebuiltNameFromSource(name) |
| 216 | if ctx.OtherModuleDependencyVariantExists(variations, prebuiltName) { |
| 217 | ctx.AddVariationDependencies(variations, tag, prebuiltName) |
| 218 | addedDep = true |
| 219 | } |
| 220 | |
| 221 | // If no appropriate variant existing for this, so no dependency could be added, then it is an |
| 222 | // error, unless missing dependencies are allowed. The simplest way to handle that is to add a |
| 223 | // dependency that will not be satisfied and the default behavior will handle it. |
| 224 | if !addedDep { |
Paul Duffin | 8f146b9 | 2021-04-12 17:24:18 +0100 | [diff] [blame] | 225 | // Add dependency on the unprefixed (i.e. source or renamed prebuilt) module which we know does |
| 226 | // not exist. The resulting error message will contain useful information about the available |
| 227 | // variants. |
| 228 | reportMissingVariationDependency(ctx, variations, name) |
| 229 | |
| 230 | // Add dependency on the missing prefixed prebuilt variant too if a module with that name exists |
| 231 | // so that information about its available variants will be reported too. |
| 232 | if ctx.OtherModuleExists(prebuiltName) { |
| 233 | reportMissingVariationDependency(ctx, variations, prebuiltName) |
| 234 | } |
| 235 | } |
| 236 | } |
| 237 | |
| 238 | // reportMissingVariationDependency intentionally adds a dependency on a missing variation in order |
| 239 | // to generate an appropriate error message with information about the available variations. |
| 240 | func reportMissingVariationDependency(ctx android.BottomUpMutatorContext, variations []blueprint.Variation, name string) { |
| 241 | modules := ctx.AddFarVariationDependencies(variations, nil, name) |
| 242 | if len(modules) != 1 { |
| 243 | panic(fmt.Errorf("Internal Error: expected one module, found %d", len(modules))) |
| 244 | return |
| 245 | } |
| 246 | if modules[0] != nil { |
| 247 | panic(fmt.Errorf("Internal Error: expected module to be missing but was found: %q", modules[0])) |
| 248 | return |
Paul Duffin | b432df9 | 2021-03-22 22:09:42 +0000 | [diff] [blame] | 249 | } |
| 250 | } |
| 251 | |
| 252 | func addDependenciesOntoBootImageModules(ctx android.BottomUpMutatorContext, modules android.ConfiguredJarList) { |
| 253 | for i := 0; i < modules.Len(); i++ { |
| 254 | apex := modules.Apex(i) |
| 255 | name := modules.Jar(i) |
| 256 | |
| 257 | addDependencyOntoApexModulePair(ctx, apex, name, platformBootclasspathModuleDepTag) |
| 258 | } |
| 259 | } |
| 260 | |
Paul Duffin | bb7f1ac | 2021-03-29 22:18:45 +0100 | [diff] [blame] | 261 | func (b *platformBootclasspathModule) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Artur Satayev | 97259dc | 2021-04-07 15:17:14 +0100 | [diff] [blame] | 262 | b.classpathFragmentBase().generateAndroidBuildActions(ctx) |
| 263 | |
Paul Duffin | b432df9 | 2021-03-22 22:09:42 +0000 | [diff] [blame] | 264 | ctx.VisitDirectDepsIf(isActiveModule, func(module android.Module) { |
| 265 | tag := ctx.OtherModuleDependencyTag(module) |
| 266 | if tag == platformBootclasspathModuleDepTag { |
| 267 | b.configuredModules = append(b.configuredModules, module) |
Paul Duffin | 62d8c3b | 2021-04-07 20:35:11 +0100 | [diff] [blame] | 268 | } else if tag == platformBootclasspathFragmentDepTag { |
| 269 | b.fragments = append(b.fragments, module) |
Paul Duffin | b432df9 | 2021-03-22 22:09:42 +0000 | [diff] [blame] | 270 | } |
| 271 | }) |
| 272 | |
Paul Duffin | 9b381ef | 2021-04-08 23:01:37 +0100 | [diff] [blame] | 273 | b.generateHiddenAPIBuildActions(ctx, b.configuredModules, b.fragments) |
Paul Duffin | 702210b | 2021-04-08 20:12:41 +0100 | [diff] [blame] | 274 | |
Paul Duffin | bb7f1ac | 2021-03-29 22:18:45 +0100 | [diff] [blame] | 275 | // Nothing to do if skipping the dexpreopt of boot image jars. |
| 276 | if SkipDexpreoptBootJars(ctx) { |
| 277 | return |
| 278 | } |
| 279 | |
| 280 | // Force the GlobalSoongConfig to be created and cached for use by the dex_bootjars |
| 281 | // GenerateSingletonBuildActions method as it cannot create it for itself. |
| 282 | dexpreopt.GetGlobalSoongConfig(ctx) |
| 283 | |
| 284 | imageConfig := b.getImageConfig(ctx) |
| 285 | if imageConfig == nil { |
| 286 | return |
| 287 | } |
| 288 | |
| 289 | // Construct the boot image info from the config. |
| 290 | info := BootImageInfo{imageConfig: imageConfig} |
| 291 | |
| 292 | // Make it available for other modules. |
| 293 | ctx.SetProvider(BootImageInfoProvider, info) |
| 294 | } |
| 295 | |
| 296 | func (b *platformBootclasspathModule) getImageConfig(ctx android.EarlyModuleContext) *bootImageConfig { |
| 297 | return defaultBootImageConfig(ctx) |
| 298 | } |
Paul Duffin | 702210b | 2021-04-08 20:12:41 +0100 | [diff] [blame] | 299 | |
| 300 | // generateHiddenAPIBuildActions generates all the hidden API related build rules. |
Paul Duffin | 9b381ef | 2021-04-08 23:01:37 +0100 | [diff] [blame] | 301 | func (b *platformBootclasspathModule) generateHiddenAPIBuildActions(ctx android.ModuleContext, modules []android.Module, fragments []android.Module) { |
Paul Duffin | 702210b | 2021-04-08 20:12:41 +0100 | [diff] [blame] | 302 | |
Paul Duffin | 90b8ad3 | 2021-04-13 12:25:01 +0100 | [diff] [blame] | 303 | // Save the paths to the monolithic files for retrieval via OutputFiles(). |
| 304 | b.hiddenAPIFlagsCSV = hiddenAPISingletonPaths(ctx).flags |
| 305 | b.hiddenAPIIndexCSV = hiddenAPISingletonPaths(ctx).index |
| 306 | b.hiddenAPIMetadataCSV = hiddenAPISingletonPaths(ctx).metadata |
Paul Duffin | 6a76645 | 2021-04-12 14:15:22 +0100 | [diff] [blame] | 307 | |
Paul Duffin | 0b65986 | 2021-04-13 13:02:29 +0100 | [diff] [blame] | 308 | // Don't run any hiddenapi rules if UNSAFE_DISABLE_HIDDENAPI_FLAGS=true. This is a performance |
| 309 | // optimization that can be used to reduce the incremental build time but as its name suggests it |
| 310 | // can be unsafe to use, e.g. when the changes affect anything that goes on the bootclasspath. |
| 311 | if ctx.Config().IsEnvTrue("UNSAFE_DISABLE_HIDDENAPI_FLAGS") { |
| 312 | paths := android.OutputPaths{b.hiddenAPIFlagsCSV, b.hiddenAPIIndexCSV, b.hiddenAPIMetadataCSV} |
| 313 | for _, path := range paths { |
| 314 | ctx.Build(pctx, android.BuildParams{ |
| 315 | Rule: android.Touch, |
| 316 | Output: path, |
| 317 | }) |
| 318 | } |
| 319 | return |
| 320 | } |
| 321 | |
Paul Duffin | 1ba2467 | 2021-04-12 23:26:14 +0100 | [diff] [blame] | 322 | hiddenAPISupportingModules := []hiddenAPISupportingModule{} |
Paul Duffin | 702210b | 2021-04-08 20:12:41 +0100 | [diff] [blame] | 323 | for _, module := range modules { |
Paul Duffin | 1ba2467 | 2021-04-12 23:26:14 +0100 | [diff] [blame] | 324 | if h, ok := module.(hiddenAPISupportingModule); ok { |
| 325 | if h.bootDexJar() == nil { |
| 326 | ctx.ModuleErrorf("module %s does not provide a bootDexJar file", module) |
Paul Duffin | 702210b | 2021-04-08 20:12:41 +0100 | [diff] [blame] | 327 | } |
Paul Duffin | 1ba2467 | 2021-04-12 23:26:14 +0100 | [diff] [blame] | 328 | if h.flagsCSV() == nil { |
| 329 | ctx.ModuleErrorf("module %s does not provide a flagsCSV file", module) |
| 330 | } |
| 331 | if h.indexCSV() == nil { |
| 332 | ctx.ModuleErrorf("module %s does not provide an indexCSV file", module) |
| 333 | } |
| 334 | if h.metadataCSV() == nil { |
| 335 | ctx.ModuleErrorf("module %s does not provide a metadataCSV file", module) |
| 336 | } |
| 337 | |
| 338 | if ctx.Failed() { |
| 339 | continue |
| 340 | } |
| 341 | |
| 342 | hiddenAPISupportingModules = append(hiddenAPISupportingModules, h) |
Paul Duffin | 702210b | 2021-04-08 20:12:41 +0100 | [diff] [blame] | 343 | } else { |
Paul Duffin | 1ba2467 | 2021-04-12 23:26:14 +0100 | [diff] [blame] | 344 | ctx.ModuleErrorf("module %s of type %s does not support hidden API processing", module, ctx.OtherModuleType(module)) |
Paul Duffin | 702210b | 2021-04-08 20:12:41 +0100 | [diff] [blame] | 345 | } |
| 346 | } |
| 347 | |
Paul Duffin | 1ba2467 | 2021-04-12 23:26:14 +0100 | [diff] [blame] | 348 | moduleSpecificFlagsPaths := android.Paths{} |
| 349 | for _, module := range hiddenAPISupportingModules { |
| 350 | moduleSpecificFlagsPaths = append(moduleSpecificFlagsPaths, module.flagsCSV()) |
| 351 | } |
| 352 | |
Paul Duffin | 9b381ef | 2021-04-08 23:01:37 +0100 | [diff] [blame] | 353 | flagFileInfo := b.properties.Hidden_api.hiddenAPIFlagFileInfo(ctx) |
| 354 | for _, fragment := range fragments { |
| 355 | if ctx.OtherModuleHasProvider(fragment, hiddenAPIFlagFileInfoProvider) { |
| 356 | info := ctx.OtherModuleProvider(fragment, hiddenAPIFlagFileInfoProvider).(hiddenAPIFlagFileInfo) |
| 357 | flagFileInfo.append(info) |
| 358 | } |
| 359 | } |
| 360 | |
| 361 | // Store the information for testing. |
| 362 | ctx.SetProvider(hiddenAPIFlagFileInfoProvider, flagFileInfo) |
Paul Duffin | 702210b | 2021-04-08 20:12:41 +0100 | [diff] [blame] | 363 | |
| 364 | outputPath := hiddenAPISingletonPaths(ctx).flags |
| 365 | baseFlagsPath := hiddenAPISingletonPaths(ctx).stubFlags |
Paul Duffin | 9b381ef | 2021-04-08 23:01:37 +0100 | [diff] [blame] | 366 | ruleToGenerateHiddenApiFlags(ctx, outputPath, baseFlagsPath, moduleSpecificFlagsPaths, flagFileInfo) |
Paul Duffin | 00b2bfd | 2021-04-12 17:24:36 +0100 | [diff] [blame] | 367 | |
Paul Duffin | 74431d5 | 2021-04-21 14:10:42 +0100 | [diff] [blame] | 368 | b.generateHiddenAPIStubFlagsRules(ctx, hiddenAPISupportingModules) |
Paul Duffin | 00b2bfd | 2021-04-12 17:24:36 +0100 | [diff] [blame] | 369 | b.generateHiddenAPIIndexRules(ctx, hiddenAPISupportingModules) |
Paul Duffin | 85dee5d | 2021-04-13 00:14:38 +0100 | [diff] [blame] | 370 | b.generatedHiddenAPIMetadataRules(ctx, hiddenAPISupportingModules) |
Paul Duffin | 00b2bfd | 2021-04-12 17:24:36 +0100 | [diff] [blame] | 371 | } |
| 372 | |
Paul Duffin | 74431d5 | 2021-04-21 14:10:42 +0100 | [diff] [blame] | 373 | func (b *platformBootclasspathModule) generateHiddenAPIStubFlagsRules(ctx android.ModuleContext, modules []hiddenAPISupportingModule) { |
| 374 | bootDexJars := android.Paths{} |
| 375 | for _, module := range modules { |
| 376 | bootDexJars = append(bootDexJars, module.bootDexJar()) |
| 377 | } |
| 378 | |
| 379 | sdkKindToStubPaths := hiddenAPIGatherStubLibDexJarPaths(ctx) |
| 380 | |
| 381 | outputPath := hiddenAPISingletonPaths(ctx).stubFlags |
| 382 | rule := ruleToGenerateHiddenAPIStubFlagsFile(ctx, outputPath, bootDexJars, sdkKindToStubPaths) |
| 383 | rule.Build("platform-bootclasspath-monolithic-hiddenapi-stub-flags", "monolithic hidden API stub flags") |
| 384 | } |
| 385 | |
Paul Duffin | 00b2bfd | 2021-04-12 17:24:36 +0100 | [diff] [blame] | 386 | func (b *platformBootclasspathModule) generateHiddenAPIIndexRules(ctx android.ModuleContext, modules []hiddenAPISupportingModule) { |
| 387 | indexes := android.Paths{} |
| 388 | for _, module := range modules { |
| 389 | indexes = append(indexes, module.indexCSV()) |
| 390 | } |
| 391 | |
| 392 | rule := android.NewRuleBuilder(pctx, ctx) |
| 393 | rule.Command(). |
| 394 | BuiltTool("merge_csv"). |
| 395 | Flag("--key_field signature"). |
| 396 | FlagWithArg("--header=", "signature,file,startline,startcol,endline,endcol,properties"). |
| 397 | FlagWithOutput("--output=", hiddenAPISingletonPaths(ctx).index). |
| 398 | Inputs(indexes) |
| 399 | rule.Build("platform-bootclasspath-monolithic-hiddenapi-index", "monolithic hidden API index") |
Paul Duffin | 702210b | 2021-04-08 20:12:41 +0100 | [diff] [blame] | 400 | } |
Paul Duffin | 85dee5d | 2021-04-13 00:14:38 +0100 | [diff] [blame] | 401 | |
| 402 | func (b *platformBootclasspathModule) generatedHiddenAPIMetadataRules(ctx android.ModuleContext, modules []hiddenAPISupportingModule) { |
| 403 | metadataCSVFiles := android.Paths{} |
| 404 | for _, module := range modules { |
| 405 | metadataCSVFiles = append(metadataCSVFiles, module.metadataCSV()) |
| 406 | } |
| 407 | |
| 408 | rule := android.NewRuleBuilder(pctx, ctx) |
| 409 | |
| 410 | outputPath := hiddenAPISingletonPaths(ctx).metadata |
| 411 | |
| 412 | rule.Command(). |
| 413 | BuiltTool("merge_csv"). |
| 414 | Flag("--key_field signature"). |
| 415 | FlagWithOutput("--output=", outputPath). |
| 416 | Inputs(metadataCSVFiles) |
| 417 | |
| 418 | rule.Build("platform-bootclasspath-monolithic-hiddenapi-metadata", "monolithic hidden API metadata") |
| 419 | } |