Paul Duffin | c6bb7cf | 2021-04-08 17:49:27 +0100 | [diff] [blame] | 1 | // Copyright (C) 2021 The Android Open Source Project |
| 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" |
Paul Duffin | 9b381ef | 2021-04-08 23:01:37 +0100 | [diff] [blame] | 19 | "github.com/google/blueprint" |
Paul Duffin | c6bb7cf | 2021-04-08 17:49:27 +0100 | [diff] [blame] | 20 | ) |
| 21 | |
| 22 | // Contains support for processing hiddenAPI in a modular fashion. |
| 23 | |
Paul Duffin | 74431d5 | 2021-04-21 14:10:42 +0100 | [diff] [blame] | 24 | type hiddenAPIStubsDependencyTag struct { |
| 25 | blueprint.BaseDependencyTag |
| 26 | sdkKind android.SdkKind |
| 27 | } |
| 28 | |
| 29 | func (b hiddenAPIStubsDependencyTag) ExcludeFromApexContents() { |
| 30 | } |
| 31 | |
| 32 | func (b hiddenAPIStubsDependencyTag) ReplaceSourceWithPrebuilt() bool { |
| 33 | return false |
| 34 | } |
| 35 | |
Paul Duffin | 976b0e5 | 2021-04-27 23:20:26 +0100 | [diff] [blame^] | 36 | func (b hiddenAPIStubsDependencyTag) SdkMemberType(child android.Module) android.SdkMemberType { |
| 37 | // If the module is a java_sdk_library then treat it as if it was specific in the java_sdk_libs |
| 38 | // property, otherwise treat if it was specified in the java_header_libs property. |
| 39 | if javaSdkLibrarySdkMemberType.IsInstance(child) { |
| 40 | return javaSdkLibrarySdkMemberType |
| 41 | } |
| 42 | |
| 43 | return javaHeaderLibsSdkMemberType |
| 44 | } |
| 45 | |
| 46 | func (b hiddenAPIStubsDependencyTag) ExportMember() bool { |
| 47 | // Export the module added via this dependency tag from the sdk. |
| 48 | return true |
| 49 | } |
| 50 | |
Paul Duffin | 74431d5 | 2021-04-21 14:10:42 +0100 | [diff] [blame] | 51 | // Avoid having to make stubs content explicitly visible to dependent modules. |
| 52 | // |
| 53 | // This is a temporary workaround to make it easier to migrate to bootclasspath_fragment modules |
| 54 | // with proper dependencies. |
| 55 | // TODO(b/177892522): Remove this and add needed visibility. |
| 56 | func (b hiddenAPIStubsDependencyTag) ExcludeFromVisibilityEnforcement() { |
| 57 | } |
| 58 | |
| 59 | var _ android.ExcludeFromVisibilityEnforcementTag = hiddenAPIStubsDependencyTag{} |
| 60 | var _ android.ReplaceSourceWithPrebuilt = hiddenAPIStubsDependencyTag{} |
| 61 | var _ android.ExcludeFromApexContentsTag = hiddenAPIStubsDependencyTag{} |
Paul Duffin | 976b0e5 | 2021-04-27 23:20:26 +0100 | [diff] [blame^] | 62 | var _ android.SdkMemberTypeDependencyTag = hiddenAPIStubsDependencyTag{} |
Paul Duffin | 74431d5 | 2021-04-21 14:10:42 +0100 | [diff] [blame] | 63 | |
Paul Duffin | 3e7fcc3 | 2021-04-15 13:31:38 +0100 | [diff] [blame] | 64 | // hiddenAPIRelevantSdkKinds lists all the android.SdkKind instances that are needed by the hidden |
| 65 | // API processing. |
| 66 | var hiddenAPIRelevantSdkKinds = []android.SdkKind{ |
| 67 | android.SdkPublic, |
| 68 | android.SdkSystem, |
| 69 | android.SdkTest, |
| 70 | android.SdkCorePlatform, |
| 71 | } |
| 72 | |
Paul Duffin | 74431d5 | 2021-04-21 14:10:42 +0100 | [diff] [blame] | 73 | // hiddenAPIComputeMonolithicStubLibModules computes the set of module names that provide stubs |
| 74 | // needed to produce the hidden API monolithic stub flags file. |
| 75 | func hiddenAPIComputeMonolithicStubLibModules(config android.Config) map[android.SdkKind][]string { |
| 76 | var publicStubModules []string |
| 77 | var systemStubModules []string |
| 78 | var testStubModules []string |
| 79 | var corePlatformStubModules []string |
| 80 | |
| 81 | if config.AlwaysUsePrebuiltSdks() { |
| 82 | // Build configuration mandates using prebuilt stub modules |
| 83 | publicStubModules = append(publicStubModules, "sdk_public_current_android") |
| 84 | systemStubModules = append(systemStubModules, "sdk_system_current_android") |
| 85 | testStubModules = append(testStubModules, "sdk_test_current_android") |
| 86 | } else { |
| 87 | // Use stub modules built from source |
| 88 | publicStubModules = append(publicStubModules, "android_stubs_current") |
| 89 | systemStubModules = append(systemStubModules, "android_system_stubs_current") |
| 90 | testStubModules = append(testStubModules, "android_test_stubs_current") |
| 91 | } |
| 92 | // We do not have prebuilts of the core platform api yet |
| 93 | corePlatformStubModules = append(corePlatformStubModules, "legacy.core.platform.api.stubs") |
| 94 | |
| 95 | // Allow products to define their own stubs for custom product jars that apps can use. |
| 96 | publicStubModules = append(publicStubModules, config.ProductHiddenAPIStubs()...) |
| 97 | systemStubModules = append(systemStubModules, config.ProductHiddenAPIStubsSystem()...) |
| 98 | testStubModules = append(testStubModules, config.ProductHiddenAPIStubsTest()...) |
| 99 | if config.IsEnvTrue("EMMA_INSTRUMENT") { |
| 100 | publicStubModules = append(publicStubModules, "jacoco-stubs") |
| 101 | } |
| 102 | |
| 103 | m := map[android.SdkKind][]string{} |
| 104 | m[android.SdkPublic] = publicStubModules |
| 105 | m[android.SdkSystem] = systemStubModules |
| 106 | m[android.SdkTest] = testStubModules |
| 107 | m[android.SdkCorePlatform] = corePlatformStubModules |
| 108 | return m |
| 109 | } |
| 110 | |
| 111 | // hiddenAPIAddStubLibDependencies adds dependencies onto the modules specified in |
| 112 | // sdkKindToStubLibModules. It adds them in a well known order and uses an SdkKind specific tag to |
| 113 | // identify the source of the dependency. |
| 114 | func hiddenAPIAddStubLibDependencies(ctx android.BottomUpMutatorContext, sdkKindToStubLibModules map[android.SdkKind][]string) { |
| 115 | module := ctx.Module() |
| 116 | for _, sdkKind := range hiddenAPIRelevantSdkKinds { |
| 117 | modules := sdkKindToStubLibModules[sdkKind] |
| 118 | ctx.AddDependency(module, hiddenAPIStubsDependencyTag{sdkKind: sdkKind}, modules...) |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | // hiddenAPIGatherStubLibDexJarPaths gathers the paths to the dex jars from the dependencies added |
| 123 | // in hiddenAPIAddStubLibDependencies. |
| 124 | func hiddenAPIGatherStubLibDexJarPaths(ctx android.ModuleContext) map[android.SdkKind]android.Paths { |
| 125 | m := map[android.SdkKind]android.Paths{} |
| 126 | ctx.VisitDirectDepsIf(isActiveModule, func(module android.Module) { |
| 127 | tag := ctx.OtherModuleDependencyTag(module) |
| 128 | if hiddenAPIStubsTag, ok := tag.(hiddenAPIStubsDependencyTag); ok { |
| 129 | kind := hiddenAPIStubsTag.sdkKind |
| 130 | dexJar := hiddenAPIRetrieveDexJarBuildPath(ctx, module) |
| 131 | if dexJar != nil { |
| 132 | m[kind] = append(m[kind], dexJar) |
| 133 | } |
| 134 | } |
| 135 | }) |
| 136 | return m |
| 137 | } |
| 138 | |
| 139 | // hiddenAPIRetrieveDexJarBuildPath retrieves the DexJarBuildPath from the specified module, if |
| 140 | // available, or reports an error. |
| 141 | func hiddenAPIRetrieveDexJarBuildPath(ctx android.ModuleContext, module android.Module) android.Path { |
| 142 | if j, ok := module.(UsesLibraryDependency); ok { |
| 143 | dexJar := j.DexJarBuildPath() |
| 144 | if dexJar != nil { |
| 145 | return dexJar |
| 146 | } |
| 147 | ctx.ModuleErrorf("dependency %s does not provide a dex jar, consider setting compile_dex: true", module) |
| 148 | } else { |
| 149 | ctx.ModuleErrorf("dependency %s of module type %s does not support providing a dex jar", module, ctx.OtherModuleType(module)) |
| 150 | } |
| 151 | return nil |
| 152 | } |
| 153 | |
| 154 | var sdkKindToHiddenapiListOption = map[android.SdkKind]string{ |
| 155 | android.SdkPublic: "public-stub-classpath", |
| 156 | android.SdkSystem: "system-stub-classpath", |
| 157 | android.SdkTest: "test-stub-classpath", |
| 158 | android.SdkCorePlatform: "core-platform-stub-classpath", |
| 159 | } |
| 160 | |
| 161 | // ruleToGenerateHiddenAPIStubFlagsFile creates a rule to create a hidden API stub flags file. |
| 162 | // |
| 163 | // The rule is initialized but not built so that the caller can modify it and select an appropriate |
| 164 | // name. |
| 165 | func ruleToGenerateHiddenAPIStubFlagsFile(ctx android.BuilderContext, outputPath android.OutputPath, bootDexJars android.Paths, sdkKindToPathList map[android.SdkKind]android.Paths) *android.RuleBuilder { |
| 166 | // Singleton rule which applies hiddenapi on all boot class path dex files. |
| 167 | rule := android.NewRuleBuilder(pctx, ctx) |
| 168 | |
| 169 | tempPath := tempPathForRestat(ctx, outputPath) |
| 170 | |
| 171 | command := rule.Command(). |
| 172 | Tool(ctx.Config().HostToolPath(ctx, "hiddenapi")). |
| 173 | Text("list"). |
| 174 | FlagForEachInput("--boot-dex=", bootDexJars) |
| 175 | |
| 176 | // Iterate over the sdk kinds in a fixed order. |
| 177 | for _, sdkKind := range hiddenAPIRelevantSdkKinds { |
| 178 | paths := sdkKindToPathList[sdkKind] |
| 179 | if len(paths) > 0 { |
| 180 | option := sdkKindToHiddenapiListOption[sdkKind] |
| 181 | command.FlagWithInputList("--"+option+"=", paths, ":") |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | // Add the output path. |
| 186 | command.FlagWithOutput("--out-api-flags=", tempPath) |
| 187 | |
| 188 | commitChangeForRestat(rule, tempPath, outputPath) |
| 189 | return rule |
| 190 | } |
| 191 | |
Paul Duffin | 4616977 | 2021-04-14 15:01:56 +0100 | [diff] [blame] | 192 | // HiddenAPIFlagFileProperties contains paths to the flag files that can be used to augment the |
| 193 | // information obtained from annotations within the source code in order to create the complete set |
| 194 | // of flags that should be applied to the dex implementation jars on the bootclasspath. |
Paul Duffin | c6bb7cf | 2021-04-08 17:49:27 +0100 | [diff] [blame] | 195 | // |
| 196 | // Each property contains a list of paths. With the exception of the Unsupported_packages the paths |
| 197 | // of each property reference a plain text file that contains a java signature per line. The flags |
| 198 | // for each of those signatures will be updated in a property specific way. |
| 199 | // |
| 200 | // The Unsupported_packages property contains a list of paths, each of which is a plain text file |
| 201 | // with one Java package per line. All members of all classes within that package (but not nested |
| 202 | // packages) will be updated in a property specific way. |
Paul Duffin | 4616977 | 2021-04-14 15:01:56 +0100 | [diff] [blame] | 203 | type HiddenAPIFlagFileProperties struct { |
Paul Duffin | c6bb7cf | 2021-04-08 17:49:27 +0100 | [diff] [blame] | 204 | // Marks each signature in the referenced files as being unsupported. |
Paul Duffin | 702210b | 2021-04-08 20:12:41 +0100 | [diff] [blame] | 205 | Unsupported []string `android:"path"` |
Paul Duffin | c6bb7cf | 2021-04-08 17:49:27 +0100 | [diff] [blame] | 206 | |
| 207 | // Marks each signature in the referenced files as being unsupported because it has been removed. |
| 208 | // Any conflicts with other flags are ignored. |
Paul Duffin | 702210b | 2021-04-08 20:12:41 +0100 | [diff] [blame] | 209 | Removed []string `android:"path"` |
Paul Duffin | c6bb7cf | 2021-04-08 17:49:27 +0100 | [diff] [blame] | 210 | |
| 211 | // Marks each signature in the referenced files as being supported only for targetSdkVersion <= R |
| 212 | // and low priority. |
Paul Duffin | 702210b | 2021-04-08 20:12:41 +0100 | [diff] [blame] | 213 | Max_target_r_low_priority []string `android:"path"` |
Paul Duffin | c6bb7cf | 2021-04-08 17:49:27 +0100 | [diff] [blame] | 214 | |
| 215 | // Marks each signature in the referenced files as being supported only for targetSdkVersion <= Q. |
Paul Duffin | 702210b | 2021-04-08 20:12:41 +0100 | [diff] [blame] | 216 | Max_target_q []string `android:"path"` |
Paul Duffin | c6bb7cf | 2021-04-08 17:49:27 +0100 | [diff] [blame] | 217 | |
| 218 | // Marks each signature in the referenced files as being supported only for targetSdkVersion <= P. |
Paul Duffin | 702210b | 2021-04-08 20:12:41 +0100 | [diff] [blame] | 219 | Max_target_p []string `android:"path"` |
Paul Duffin | c6bb7cf | 2021-04-08 17:49:27 +0100 | [diff] [blame] | 220 | |
| 221 | // Marks each signature in the referenced files as being supported only for targetSdkVersion <= O |
| 222 | // and low priority. Any conflicts with other flags are ignored. |
Paul Duffin | 702210b | 2021-04-08 20:12:41 +0100 | [diff] [blame] | 223 | Max_target_o_low_priority []string `android:"path"` |
Paul Duffin | c6bb7cf | 2021-04-08 17:49:27 +0100 | [diff] [blame] | 224 | |
| 225 | // Marks each signature in the referenced files as being blocked. |
Paul Duffin | 702210b | 2021-04-08 20:12:41 +0100 | [diff] [blame] | 226 | Blocked []string `android:"path"` |
Paul Duffin | c6bb7cf | 2021-04-08 17:49:27 +0100 | [diff] [blame] | 227 | |
| 228 | // Marks each signature in every package in the referenced files as being unsupported. |
Paul Duffin | 702210b | 2021-04-08 20:12:41 +0100 | [diff] [blame] | 229 | Unsupported_packages []string `android:"path"` |
| 230 | } |
| 231 | |
Paul Duffin | 4616977 | 2021-04-14 15:01:56 +0100 | [diff] [blame] | 232 | func (p *HiddenAPIFlagFileProperties) hiddenAPIFlagFileInfo(ctx android.ModuleContext) hiddenAPIFlagFileInfo { |
| 233 | info := hiddenAPIFlagFileInfo{categoryToPaths: map[*hiddenAPIFlagFileCategory]android.Paths{}} |
Paul Duffin | e3dc660 | 2021-04-14 09:50:43 +0100 | [diff] [blame] | 234 | for _, category := range hiddenAPIFlagFileCategories { |
Paul Duffin | cc17bfe | 2021-04-19 13:21:20 +0100 | [diff] [blame] | 235 | paths := android.PathsForModuleSrc(ctx, category.propertyValueReader(p)) |
Paul Duffin | e3dc660 | 2021-04-14 09:50:43 +0100 | [diff] [blame] | 236 | info.categoryToPaths[category] = paths |
Paul Duffin | 702210b | 2021-04-08 20:12:41 +0100 | [diff] [blame] | 237 | } |
Paul Duffin | e3dc660 | 2021-04-14 09:50:43 +0100 | [diff] [blame] | 238 | return info |
| 239 | } |
| 240 | |
| 241 | type hiddenAPIFlagFileCategory struct { |
| 242 | // propertyName is the name of the property for this category. |
| 243 | propertyName string |
| 244 | |
Paul Duffin | cc17bfe | 2021-04-19 13:21:20 +0100 | [diff] [blame] | 245 | // propertyValueReader retrieves the value of the property for this category from the set of |
Paul Duffin | e3dc660 | 2021-04-14 09:50:43 +0100 | [diff] [blame] | 246 | // properties. |
Paul Duffin | cc17bfe | 2021-04-19 13:21:20 +0100 | [diff] [blame] | 247 | propertyValueReader func(properties *HiddenAPIFlagFileProperties) []string |
Paul Duffin | e3dc660 | 2021-04-14 09:50:43 +0100 | [diff] [blame] | 248 | |
| 249 | // commandMutator adds the appropriate command line options for this category to the supplied |
| 250 | // command |
| 251 | commandMutator func(command *android.RuleBuilderCommand, path android.Path) |
| 252 | } |
| 253 | |
| 254 | var hiddenAPIFlagFileCategories = []*hiddenAPIFlagFileCategory{ |
Paul Duffin | 4616977 | 2021-04-14 15:01:56 +0100 | [diff] [blame] | 255 | // See HiddenAPIFlagFileProperties.Unsupported |
Paul Duffin | e3dc660 | 2021-04-14 09:50:43 +0100 | [diff] [blame] | 256 | { |
| 257 | propertyName: "unsupported", |
Paul Duffin | cc17bfe | 2021-04-19 13:21:20 +0100 | [diff] [blame] | 258 | propertyValueReader: func(properties *HiddenAPIFlagFileProperties) []string { |
Paul Duffin | e3dc660 | 2021-04-14 09:50:43 +0100 | [diff] [blame] | 259 | return properties.Unsupported |
| 260 | }, |
| 261 | commandMutator: func(command *android.RuleBuilderCommand, path android.Path) { |
| 262 | command.FlagWithInput("--unsupported ", path) |
| 263 | }, |
| 264 | }, |
Paul Duffin | 4616977 | 2021-04-14 15:01:56 +0100 | [diff] [blame] | 265 | // See HiddenAPIFlagFileProperties.Removed |
Paul Duffin | e3dc660 | 2021-04-14 09:50:43 +0100 | [diff] [blame] | 266 | { |
| 267 | propertyName: "removed", |
Paul Duffin | cc17bfe | 2021-04-19 13:21:20 +0100 | [diff] [blame] | 268 | propertyValueReader: func(properties *HiddenAPIFlagFileProperties) []string { |
Paul Duffin | e3dc660 | 2021-04-14 09:50:43 +0100 | [diff] [blame] | 269 | return properties.Removed |
| 270 | }, |
| 271 | commandMutator: func(command *android.RuleBuilderCommand, path android.Path) { |
| 272 | command.FlagWithInput("--unsupported ", path).Flag("--ignore-conflicts ").FlagWithArg("--tag ", "removed") |
| 273 | }, |
| 274 | }, |
Paul Duffin | 4616977 | 2021-04-14 15:01:56 +0100 | [diff] [blame] | 275 | // See HiddenAPIFlagFileProperties.Max_target_r_low_priority |
Paul Duffin | e3dc660 | 2021-04-14 09:50:43 +0100 | [diff] [blame] | 276 | { |
| 277 | propertyName: "max_target_r_low_priority", |
Paul Duffin | cc17bfe | 2021-04-19 13:21:20 +0100 | [diff] [blame] | 278 | propertyValueReader: func(properties *HiddenAPIFlagFileProperties) []string { |
Paul Duffin | e3dc660 | 2021-04-14 09:50:43 +0100 | [diff] [blame] | 279 | return properties.Max_target_r_low_priority |
| 280 | }, |
| 281 | commandMutator: func(command *android.RuleBuilderCommand, path android.Path) { |
| 282 | command.FlagWithInput("--max-target-r ", path).FlagWithArg("--tag ", "lo-prio") |
| 283 | }, |
| 284 | }, |
Paul Duffin | 4616977 | 2021-04-14 15:01:56 +0100 | [diff] [blame] | 285 | // See HiddenAPIFlagFileProperties.Max_target_q |
Paul Duffin | e3dc660 | 2021-04-14 09:50:43 +0100 | [diff] [blame] | 286 | { |
| 287 | propertyName: "max_target_q", |
Paul Duffin | cc17bfe | 2021-04-19 13:21:20 +0100 | [diff] [blame] | 288 | propertyValueReader: func(properties *HiddenAPIFlagFileProperties) []string { |
Paul Duffin | e3dc660 | 2021-04-14 09:50:43 +0100 | [diff] [blame] | 289 | return properties.Max_target_q |
| 290 | }, |
| 291 | commandMutator: func(command *android.RuleBuilderCommand, path android.Path) { |
| 292 | command.FlagWithInput("--max-target-q ", path) |
| 293 | }, |
| 294 | }, |
Paul Duffin | 4616977 | 2021-04-14 15:01:56 +0100 | [diff] [blame] | 295 | // See HiddenAPIFlagFileProperties.Max_target_p |
Paul Duffin | e3dc660 | 2021-04-14 09:50:43 +0100 | [diff] [blame] | 296 | { |
| 297 | propertyName: "max_target_p", |
Paul Duffin | cc17bfe | 2021-04-19 13:21:20 +0100 | [diff] [blame] | 298 | propertyValueReader: func(properties *HiddenAPIFlagFileProperties) []string { |
Paul Duffin | e3dc660 | 2021-04-14 09:50:43 +0100 | [diff] [blame] | 299 | return properties.Max_target_p |
| 300 | }, |
| 301 | commandMutator: func(command *android.RuleBuilderCommand, path android.Path) { |
| 302 | command.FlagWithInput("--max-target-p ", path) |
| 303 | }, |
| 304 | }, |
Paul Duffin | 4616977 | 2021-04-14 15:01:56 +0100 | [diff] [blame] | 305 | // See HiddenAPIFlagFileProperties.Max_target_o_low_priority |
Paul Duffin | e3dc660 | 2021-04-14 09:50:43 +0100 | [diff] [blame] | 306 | { |
| 307 | propertyName: "max_target_o_low_priority", |
Paul Duffin | cc17bfe | 2021-04-19 13:21:20 +0100 | [diff] [blame] | 308 | propertyValueReader: func(properties *HiddenAPIFlagFileProperties) []string { |
Paul Duffin | e3dc660 | 2021-04-14 09:50:43 +0100 | [diff] [blame] | 309 | return properties.Max_target_o_low_priority |
| 310 | }, |
| 311 | commandMutator: func(command *android.RuleBuilderCommand, path android.Path) { |
| 312 | command.FlagWithInput("--max-target-o ", path).Flag("--ignore-conflicts ").FlagWithArg("--tag ", "lo-prio") |
| 313 | }, |
| 314 | }, |
Paul Duffin | 4616977 | 2021-04-14 15:01:56 +0100 | [diff] [blame] | 315 | // See HiddenAPIFlagFileProperties.Blocked |
Paul Duffin | e3dc660 | 2021-04-14 09:50:43 +0100 | [diff] [blame] | 316 | { |
| 317 | propertyName: "blocked", |
Paul Duffin | cc17bfe | 2021-04-19 13:21:20 +0100 | [diff] [blame] | 318 | propertyValueReader: func(properties *HiddenAPIFlagFileProperties) []string { |
Paul Duffin | e3dc660 | 2021-04-14 09:50:43 +0100 | [diff] [blame] | 319 | return properties.Blocked |
| 320 | }, |
| 321 | commandMutator: func(command *android.RuleBuilderCommand, path android.Path) { |
| 322 | command.FlagWithInput("--blocked ", path) |
| 323 | }, |
| 324 | }, |
Paul Duffin | 4616977 | 2021-04-14 15:01:56 +0100 | [diff] [blame] | 325 | // See HiddenAPIFlagFileProperties.Unsupported_packages |
Paul Duffin | e3dc660 | 2021-04-14 09:50:43 +0100 | [diff] [blame] | 326 | { |
| 327 | propertyName: "unsupported_packages", |
Paul Duffin | cc17bfe | 2021-04-19 13:21:20 +0100 | [diff] [blame] | 328 | propertyValueReader: func(properties *HiddenAPIFlagFileProperties) []string { |
Paul Duffin | e3dc660 | 2021-04-14 09:50:43 +0100 | [diff] [blame] | 329 | return properties.Unsupported_packages |
| 330 | }, |
| 331 | commandMutator: func(command *android.RuleBuilderCommand, path android.Path) { |
| 332 | command.FlagWithInput("--unsupported ", path).Flag("--packages ") |
| 333 | }, |
| 334 | }, |
Paul Duffin | 702210b | 2021-04-08 20:12:41 +0100 | [diff] [blame] | 335 | } |
| 336 | |
Paul Duffin | 4616977 | 2021-04-14 15:01:56 +0100 | [diff] [blame] | 337 | // hiddenAPIFlagFileInfo contains paths resolved from HiddenAPIFlagFileProperties |
| 338 | type hiddenAPIFlagFileInfo struct { |
Paul Duffin | e3dc660 | 2021-04-14 09:50:43 +0100 | [diff] [blame] | 339 | // categoryToPaths maps from the flag file category to the paths containing information for that |
| 340 | // category. |
| 341 | categoryToPaths map[*hiddenAPIFlagFileCategory]android.Paths |
Paul Duffin | c6bb7cf | 2021-04-08 17:49:27 +0100 | [diff] [blame] | 342 | } |
Paul Duffin | 702210b | 2021-04-08 20:12:41 +0100 | [diff] [blame] | 343 | |
Paul Duffin | 9b381ef | 2021-04-08 23:01:37 +0100 | [diff] [blame] | 344 | func (i *hiddenAPIFlagFileInfo) append(other hiddenAPIFlagFileInfo) { |
| 345 | for _, category := range hiddenAPIFlagFileCategories { |
| 346 | i.categoryToPaths[category] = append(i.categoryToPaths[category], other.categoryToPaths[category]...) |
| 347 | } |
| 348 | } |
| 349 | |
| 350 | var hiddenAPIFlagFileInfoProvider = blueprint.NewProvider(hiddenAPIFlagFileInfo{}) |
| 351 | |
Paul Duffin | 702210b | 2021-04-08 20:12:41 +0100 | [diff] [blame] | 352 | // ruleToGenerateHiddenApiFlags creates a rule to create the monolithic hidden API flags from the |
| 353 | // flags from all the modules, the stub flags, augmented with some additional configuration files. |
| 354 | // |
| 355 | // baseFlagsPath is the path to the flags file containing all the information from the stubs plus |
| 356 | // an entry for every single member in the dex implementation jars of the individual modules. Every |
| 357 | // signature in any of the other files MUST be included in this file. |
| 358 | // |
| 359 | // moduleSpecificFlagsPaths are the paths to the flags files generated by each module using |
| 360 | // information from the baseFlagsPath as well as from annotations within the source. |
| 361 | // |
| 362 | // augmentationInfo is a struct containing paths to files that augment the information provided by |
| 363 | // the moduleSpecificFlagsPaths. |
| 364 | // ruleToGenerateHiddenApiFlags creates a rule to create the monolithic hidden API flags from the |
| 365 | // flags from all the modules, the stub flags, augmented with some additional configuration files. |
| 366 | // |
| 367 | // baseFlagsPath is the path to the flags file containing all the information from the stubs plus |
| 368 | // an entry for every single member in the dex implementation jars of the individual modules. Every |
| 369 | // signature in any of the other files MUST be included in this file. |
| 370 | // |
| 371 | // moduleSpecificFlagsPaths are the paths to the flags files generated by each module using |
| 372 | // information from the baseFlagsPath as well as from annotations within the source. |
| 373 | // |
| 374 | // augmentationInfo is a struct containing paths to files that augment the information provided by |
| 375 | // the moduleSpecificFlagsPaths. |
Paul Duffin | 4616977 | 2021-04-14 15:01:56 +0100 | [diff] [blame] | 376 | func ruleToGenerateHiddenApiFlags(ctx android.BuilderContext, outputPath android.WritablePath, baseFlagsPath android.Path, moduleSpecificFlagsPaths android.Paths, augmentationInfo hiddenAPIFlagFileInfo) { |
Paul Duffin | d3c1513 | 2021-04-21 22:12:35 +0100 | [diff] [blame] | 377 | tempPath := tempPathForRestat(ctx, outputPath) |
Paul Duffin | 702210b | 2021-04-08 20:12:41 +0100 | [diff] [blame] | 378 | rule := android.NewRuleBuilder(pctx, ctx) |
| 379 | command := rule.Command(). |
| 380 | BuiltTool("generate_hiddenapi_lists"). |
| 381 | FlagWithInput("--csv ", baseFlagsPath). |
| 382 | Inputs(moduleSpecificFlagsPaths). |
| 383 | FlagWithOutput("--output ", tempPath) |
| 384 | |
Paul Duffin | e3dc660 | 2021-04-14 09:50:43 +0100 | [diff] [blame] | 385 | // Add the options for the different categories of flag files. |
| 386 | for _, category := range hiddenAPIFlagFileCategories { |
| 387 | paths := augmentationInfo.categoryToPaths[category] |
| 388 | for _, path := range paths { |
| 389 | category.commandMutator(command, path) |
| 390 | } |
Paul Duffin | 702210b | 2021-04-08 20:12:41 +0100 | [diff] [blame] | 391 | } |
| 392 | |
| 393 | commitChangeForRestat(rule, tempPath, outputPath) |
| 394 | |
| 395 | rule.Build("hiddenAPIFlagsFile", "hiddenapi flags") |
| 396 | } |