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 ( |
Paul Duffin | 7487a7a | 2021-05-19 09:36:09 +0100 | [diff] [blame] | 18 | "fmt" |
Paul Duffin | dfa1083 | 2021-05-13 17:31:51 +0100 | [diff] [blame] | 19 | "strings" |
| 20 | |
Paul Duffin | c6bb7cf | 2021-04-08 17:49:27 +0100 | [diff] [blame] | 21 | "android/soong/android" |
Paul Duffin | 9b381ef | 2021-04-08 23:01:37 +0100 | [diff] [blame] | 22 | "github.com/google/blueprint" |
Paul Duffin | c6bb7cf | 2021-04-08 17:49:27 +0100 | [diff] [blame] | 23 | ) |
| 24 | |
| 25 | // Contains support for processing hiddenAPI in a modular fashion. |
| 26 | |
Paul Duffin | 74431d5 | 2021-04-21 14:10:42 +0100 | [diff] [blame] | 27 | type hiddenAPIStubsDependencyTag struct { |
| 28 | blueprint.BaseDependencyTag |
| 29 | sdkKind android.SdkKind |
| 30 | } |
| 31 | |
| 32 | func (b hiddenAPIStubsDependencyTag) ExcludeFromApexContents() { |
| 33 | } |
| 34 | |
| 35 | func (b hiddenAPIStubsDependencyTag) ReplaceSourceWithPrebuilt() bool { |
| 36 | return false |
| 37 | } |
| 38 | |
Paul Duffin | 976b0e5 | 2021-04-27 23:20:26 +0100 | [diff] [blame] | 39 | func (b hiddenAPIStubsDependencyTag) SdkMemberType(child android.Module) android.SdkMemberType { |
| 40 | // If the module is a java_sdk_library then treat it as if it was specific in the java_sdk_libs |
| 41 | // property, otherwise treat if it was specified in the java_header_libs property. |
| 42 | if javaSdkLibrarySdkMemberType.IsInstance(child) { |
| 43 | return javaSdkLibrarySdkMemberType |
| 44 | } |
| 45 | |
| 46 | return javaHeaderLibsSdkMemberType |
| 47 | } |
| 48 | |
| 49 | func (b hiddenAPIStubsDependencyTag) ExportMember() bool { |
| 50 | // Export the module added via this dependency tag from the sdk. |
| 51 | return true |
| 52 | } |
| 53 | |
Paul Duffin | 74431d5 | 2021-04-21 14:10:42 +0100 | [diff] [blame] | 54 | // Avoid having to make stubs content explicitly visible to dependent modules. |
| 55 | // |
| 56 | // This is a temporary workaround to make it easier to migrate to bootclasspath_fragment modules |
| 57 | // with proper dependencies. |
| 58 | // TODO(b/177892522): Remove this and add needed visibility. |
| 59 | func (b hiddenAPIStubsDependencyTag) ExcludeFromVisibilityEnforcement() { |
| 60 | } |
| 61 | |
| 62 | var _ android.ExcludeFromVisibilityEnforcementTag = hiddenAPIStubsDependencyTag{} |
| 63 | var _ android.ReplaceSourceWithPrebuilt = hiddenAPIStubsDependencyTag{} |
| 64 | var _ android.ExcludeFromApexContentsTag = hiddenAPIStubsDependencyTag{} |
Paul Duffin | 976b0e5 | 2021-04-27 23:20:26 +0100 | [diff] [blame] | 65 | var _ android.SdkMemberTypeDependencyTag = hiddenAPIStubsDependencyTag{} |
Paul Duffin | 74431d5 | 2021-04-21 14:10:42 +0100 | [diff] [blame] | 66 | |
Paul Duffin | 3e7fcc3 | 2021-04-15 13:31:38 +0100 | [diff] [blame] | 67 | // hiddenAPIRelevantSdkKinds lists all the android.SdkKind instances that are needed by the hidden |
| 68 | // API processing. |
| 69 | var hiddenAPIRelevantSdkKinds = []android.SdkKind{ |
| 70 | android.SdkPublic, |
| 71 | android.SdkSystem, |
| 72 | android.SdkTest, |
| 73 | android.SdkCorePlatform, |
| 74 | } |
| 75 | |
Paul Duffin | 74431d5 | 2021-04-21 14:10:42 +0100 | [diff] [blame] | 76 | // hiddenAPIComputeMonolithicStubLibModules computes the set of module names that provide stubs |
| 77 | // needed to produce the hidden API monolithic stub flags file. |
| 78 | func hiddenAPIComputeMonolithicStubLibModules(config android.Config) map[android.SdkKind][]string { |
| 79 | var publicStubModules []string |
| 80 | var systemStubModules []string |
| 81 | var testStubModules []string |
| 82 | var corePlatformStubModules []string |
| 83 | |
| 84 | if config.AlwaysUsePrebuiltSdks() { |
| 85 | // Build configuration mandates using prebuilt stub modules |
| 86 | publicStubModules = append(publicStubModules, "sdk_public_current_android") |
| 87 | systemStubModules = append(systemStubModules, "sdk_system_current_android") |
| 88 | testStubModules = append(testStubModules, "sdk_test_current_android") |
| 89 | } else { |
| 90 | // Use stub modules built from source |
| 91 | publicStubModules = append(publicStubModules, "android_stubs_current") |
| 92 | systemStubModules = append(systemStubModules, "android_system_stubs_current") |
| 93 | testStubModules = append(testStubModules, "android_test_stubs_current") |
| 94 | } |
| 95 | // We do not have prebuilts of the core platform api yet |
| 96 | corePlatformStubModules = append(corePlatformStubModules, "legacy.core.platform.api.stubs") |
| 97 | |
| 98 | // Allow products to define their own stubs for custom product jars that apps can use. |
| 99 | publicStubModules = append(publicStubModules, config.ProductHiddenAPIStubs()...) |
| 100 | systemStubModules = append(systemStubModules, config.ProductHiddenAPIStubsSystem()...) |
| 101 | testStubModules = append(testStubModules, config.ProductHiddenAPIStubsTest()...) |
| 102 | if config.IsEnvTrue("EMMA_INSTRUMENT") { |
Paul Duffin | 098c878 | 2021-05-14 10:45:25 +0100 | [diff] [blame] | 103 | // Add jacoco-stubs to public, system and test. It doesn't make any real difference as public |
| 104 | // allows everyone access but it is needed to ensure consistent flags between the |
| 105 | // bootclasspath fragment generated flags and the platform_bootclasspath generated flags. |
Paul Duffin | 74431d5 | 2021-04-21 14:10:42 +0100 | [diff] [blame] | 106 | publicStubModules = append(publicStubModules, "jacoco-stubs") |
Paul Duffin | 098c878 | 2021-05-14 10:45:25 +0100 | [diff] [blame] | 107 | systemStubModules = append(systemStubModules, "jacoco-stubs") |
| 108 | testStubModules = append(testStubModules, "jacoco-stubs") |
Paul Duffin | 74431d5 | 2021-04-21 14:10:42 +0100 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | m := map[android.SdkKind][]string{} |
| 112 | m[android.SdkPublic] = publicStubModules |
| 113 | m[android.SdkSystem] = systemStubModules |
| 114 | m[android.SdkTest] = testStubModules |
| 115 | m[android.SdkCorePlatform] = corePlatformStubModules |
| 116 | return m |
| 117 | } |
| 118 | |
| 119 | // hiddenAPIAddStubLibDependencies adds dependencies onto the modules specified in |
| 120 | // sdkKindToStubLibModules. It adds them in a well known order and uses an SdkKind specific tag to |
| 121 | // identify the source of the dependency. |
| 122 | func hiddenAPIAddStubLibDependencies(ctx android.BottomUpMutatorContext, sdkKindToStubLibModules map[android.SdkKind][]string) { |
| 123 | module := ctx.Module() |
| 124 | for _, sdkKind := range hiddenAPIRelevantSdkKinds { |
| 125 | modules := sdkKindToStubLibModules[sdkKind] |
| 126 | ctx.AddDependency(module, hiddenAPIStubsDependencyTag{sdkKind: sdkKind}, modules...) |
| 127 | } |
| 128 | } |
| 129 | |
Paul Duffin | 74431d5 | 2021-04-21 14:10:42 +0100 | [diff] [blame] | 130 | // hiddenAPIRetrieveDexJarBuildPath retrieves the DexJarBuildPath from the specified module, if |
| 131 | // available, or reports an error. |
Paul Duffin | 1093158 | 2021-04-25 10:13:54 +0100 | [diff] [blame] | 132 | func hiddenAPIRetrieveDexJarBuildPath(ctx android.ModuleContext, module android.Module, kind android.SdkKind) android.Path { |
| 133 | var dexJar android.Path |
| 134 | if sdkLibrary, ok := module.(SdkLibraryDependency); ok { |
| 135 | dexJar = sdkLibrary.SdkApiStubDexJar(ctx, kind) |
| 136 | } else if j, ok := module.(UsesLibraryDependency); ok { |
| 137 | dexJar = j.DexJarBuildPath() |
Paul Duffin | 74431d5 | 2021-04-21 14:10:42 +0100 | [diff] [blame] | 138 | } else { |
| 139 | ctx.ModuleErrorf("dependency %s of module type %s does not support providing a dex jar", module, ctx.OtherModuleType(module)) |
Paul Duffin | 1093158 | 2021-04-25 10:13:54 +0100 | [diff] [blame] | 140 | return nil |
Paul Duffin | 74431d5 | 2021-04-21 14:10:42 +0100 | [diff] [blame] | 141 | } |
Paul Duffin | 1093158 | 2021-04-25 10:13:54 +0100 | [diff] [blame] | 142 | |
| 143 | if dexJar == nil { |
| 144 | ctx.ModuleErrorf("dependency %s does not provide a dex jar, consider setting compile_dex: true", module) |
| 145 | } |
| 146 | return dexJar |
Paul Duffin | 74431d5 | 2021-04-21 14:10:42 +0100 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | var sdkKindToHiddenapiListOption = map[android.SdkKind]string{ |
| 150 | android.SdkPublic: "public-stub-classpath", |
| 151 | android.SdkSystem: "system-stub-classpath", |
| 152 | android.SdkTest: "test-stub-classpath", |
| 153 | android.SdkCorePlatform: "core-platform-stub-classpath", |
| 154 | } |
| 155 | |
| 156 | // ruleToGenerateHiddenAPIStubFlagsFile creates a rule to create a hidden API stub flags file. |
| 157 | // |
| 158 | // The rule is initialized but not built so that the caller can modify it and select an appropriate |
| 159 | // name. |
Paul Duffin | 1352f7c | 2021-05-21 22:18:49 +0100 | [diff] [blame^] | 160 | func ruleToGenerateHiddenAPIStubFlagsFile(ctx android.BuilderContext, outputPath android.WritablePath, bootDexJars android.Paths, input HiddenAPIFlagInput) *android.RuleBuilder { |
Paul Duffin | 74431d5 | 2021-04-21 14:10:42 +0100 | [diff] [blame] | 161 | // Singleton rule which applies hiddenapi on all boot class path dex files. |
| 162 | rule := android.NewRuleBuilder(pctx, ctx) |
| 163 | |
| 164 | tempPath := tempPathForRestat(ctx, outputPath) |
| 165 | |
| 166 | command := rule.Command(). |
| 167 | Tool(ctx.Config().HostToolPath(ctx, "hiddenapi")). |
| 168 | Text("list"). |
| 169 | FlagForEachInput("--boot-dex=", bootDexJars) |
| 170 | |
| 171 | // Iterate over the sdk kinds in a fixed order. |
| 172 | for _, sdkKind := range hiddenAPIRelevantSdkKinds { |
Paul Duffin | 1352f7c | 2021-05-21 22:18:49 +0100 | [diff] [blame^] | 173 | paths := input.StubDexJarsByKind[sdkKind] |
Paul Duffin | 74431d5 | 2021-04-21 14:10:42 +0100 | [diff] [blame] | 174 | if len(paths) > 0 { |
| 175 | option := sdkKindToHiddenapiListOption[sdkKind] |
| 176 | command.FlagWithInputList("--"+option+"=", paths, ":") |
| 177 | } |
| 178 | } |
| 179 | |
| 180 | // Add the output path. |
| 181 | command.FlagWithOutput("--out-api-flags=", tempPath) |
| 182 | |
| 183 | commitChangeForRestat(rule, tempPath, outputPath) |
| 184 | return rule |
| 185 | } |
| 186 | |
Paul Duffin | 4616977 | 2021-04-14 15:01:56 +0100 | [diff] [blame] | 187 | // HiddenAPIFlagFileProperties contains paths to the flag files that can be used to augment the |
| 188 | // information obtained from annotations within the source code in order to create the complete set |
| 189 | // 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] | 190 | // |
| 191 | // Each property contains a list of paths. With the exception of the Unsupported_packages the paths |
| 192 | // of each property reference a plain text file that contains a java signature per line. The flags |
| 193 | // for each of those signatures will be updated in a property specific way. |
| 194 | // |
| 195 | // The Unsupported_packages property contains a list of paths, each of which is a plain text file |
| 196 | // with one Java package per line. All members of all classes within that package (but not nested |
| 197 | // packages) will be updated in a property specific way. |
Paul Duffin | 4616977 | 2021-04-14 15:01:56 +0100 | [diff] [blame] | 198 | type HiddenAPIFlagFileProperties struct { |
Paul Duffin | c6bb7cf | 2021-04-08 17:49:27 +0100 | [diff] [blame] | 199 | // Marks each signature in the referenced files as being unsupported. |
Paul Duffin | 702210b | 2021-04-08 20:12:41 +0100 | [diff] [blame] | 200 | Unsupported []string `android:"path"` |
Paul Duffin | c6bb7cf | 2021-04-08 17:49:27 +0100 | [diff] [blame] | 201 | |
| 202 | // Marks each signature in the referenced files as being unsupported because it has been removed. |
| 203 | // Any conflicts with other flags are ignored. |
Paul Duffin | 702210b | 2021-04-08 20:12:41 +0100 | [diff] [blame] | 204 | Removed []string `android:"path"` |
Paul Duffin | c6bb7cf | 2021-04-08 17:49:27 +0100 | [diff] [blame] | 205 | |
| 206 | // Marks each signature in the referenced files as being supported only for targetSdkVersion <= R |
| 207 | // and low priority. |
Paul Duffin | 702210b | 2021-04-08 20:12:41 +0100 | [diff] [blame] | 208 | Max_target_r_low_priority []string `android:"path"` |
Paul Duffin | c6bb7cf | 2021-04-08 17:49:27 +0100 | [diff] [blame] | 209 | |
| 210 | // 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] | 211 | Max_target_q []string `android:"path"` |
Paul Duffin | c6bb7cf | 2021-04-08 17:49:27 +0100 | [diff] [blame] | 212 | |
| 213 | // 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] | 214 | Max_target_p []string `android:"path"` |
Paul Duffin | c6bb7cf | 2021-04-08 17:49:27 +0100 | [diff] [blame] | 215 | |
| 216 | // Marks each signature in the referenced files as being supported only for targetSdkVersion <= O |
| 217 | // and low priority. Any conflicts with other flags are ignored. |
Paul Duffin | 702210b | 2021-04-08 20:12:41 +0100 | [diff] [blame] | 218 | Max_target_o_low_priority []string `android:"path"` |
Paul Duffin | c6bb7cf | 2021-04-08 17:49:27 +0100 | [diff] [blame] | 219 | |
| 220 | // Marks each signature in the referenced files as being blocked. |
Paul Duffin | 702210b | 2021-04-08 20:12:41 +0100 | [diff] [blame] | 221 | Blocked []string `android:"path"` |
Paul Duffin | c6bb7cf | 2021-04-08 17:49:27 +0100 | [diff] [blame] | 222 | |
| 223 | // 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] | 224 | Unsupported_packages []string `android:"path"` |
| 225 | } |
| 226 | |
Paul Duffin | e3dc660 | 2021-04-14 09:50:43 +0100 | [diff] [blame] | 227 | type hiddenAPIFlagFileCategory struct { |
| 228 | // propertyName is the name of the property for this category. |
| 229 | propertyName string |
| 230 | |
Paul Duffin | cc17bfe | 2021-04-19 13:21:20 +0100 | [diff] [blame] | 231 | // 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] | 232 | // properties. |
Paul Duffin | cc17bfe | 2021-04-19 13:21:20 +0100 | [diff] [blame] | 233 | propertyValueReader func(properties *HiddenAPIFlagFileProperties) []string |
Paul Duffin | e3dc660 | 2021-04-14 09:50:43 +0100 | [diff] [blame] | 234 | |
| 235 | // commandMutator adds the appropriate command line options for this category to the supplied |
| 236 | // command |
| 237 | commandMutator func(command *android.RuleBuilderCommand, path android.Path) |
| 238 | } |
| 239 | |
| 240 | var hiddenAPIFlagFileCategories = []*hiddenAPIFlagFileCategory{ |
Paul Duffin | 4616977 | 2021-04-14 15:01:56 +0100 | [diff] [blame] | 241 | // See HiddenAPIFlagFileProperties.Unsupported |
Paul Duffin | e3dc660 | 2021-04-14 09:50:43 +0100 | [diff] [blame] | 242 | { |
| 243 | propertyName: "unsupported", |
Paul Duffin | cc17bfe | 2021-04-19 13:21:20 +0100 | [diff] [blame] | 244 | propertyValueReader: func(properties *HiddenAPIFlagFileProperties) []string { |
Paul Duffin | e3dc660 | 2021-04-14 09:50:43 +0100 | [diff] [blame] | 245 | return properties.Unsupported |
| 246 | }, |
| 247 | commandMutator: func(command *android.RuleBuilderCommand, path android.Path) { |
| 248 | command.FlagWithInput("--unsupported ", path) |
| 249 | }, |
| 250 | }, |
Paul Duffin | 4616977 | 2021-04-14 15:01:56 +0100 | [diff] [blame] | 251 | // See HiddenAPIFlagFileProperties.Removed |
Paul Duffin | e3dc660 | 2021-04-14 09:50:43 +0100 | [diff] [blame] | 252 | { |
| 253 | propertyName: "removed", |
Paul Duffin | cc17bfe | 2021-04-19 13:21:20 +0100 | [diff] [blame] | 254 | propertyValueReader: func(properties *HiddenAPIFlagFileProperties) []string { |
Paul Duffin | e3dc660 | 2021-04-14 09:50:43 +0100 | [diff] [blame] | 255 | return properties.Removed |
| 256 | }, |
| 257 | commandMutator: func(command *android.RuleBuilderCommand, path android.Path) { |
| 258 | command.FlagWithInput("--unsupported ", path).Flag("--ignore-conflicts ").FlagWithArg("--tag ", "removed") |
| 259 | }, |
| 260 | }, |
Paul Duffin | 4616977 | 2021-04-14 15:01:56 +0100 | [diff] [blame] | 261 | // See HiddenAPIFlagFileProperties.Max_target_r_low_priority |
Paul Duffin | e3dc660 | 2021-04-14 09:50:43 +0100 | [diff] [blame] | 262 | { |
| 263 | propertyName: "max_target_r_low_priority", |
Paul Duffin | cc17bfe | 2021-04-19 13:21:20 +0100 | [diff] [blame] | 264 | propertyValueReader: func(properties *HiddenAPIFlagFileProperties) []string { |
Paul Duffin | e3dc660 | 2021-04-14 09:50:43 +0100 | [diff] [blame] | 265 | return properties.Max_target_r_low_priority |
| 266 | }, |
| 267 | commandMutator: func(command *android.RuleBuilderCommand, path android.Path) { |
| 268 | command.FlagWithInput("--max-target-r ", path).FlagWithArg("--tag ", "lo-prio") |
| 269 | }, |
| 270 | }, |
Paul Duffin | 4616977 | 2021-04-14 15:01:56 +0100 | [diff] [blame] | 271 | // See HiddenAPIFlagFileProperties.Max_target_q |
Paul Duffin | e3dc660 | 2021-04-14 09:50:43 +0100 | [diff] [blame] | 272 | { |
| 273 | propertyName: "max_target_q", |
Paul Duffin | cc17bfe | 2021-04-19 13:21:20 +0100 | [diff] [blame] | 274 | propertyValueReader: func(properties *HiddenAPIFlagFileProperties) []string { |
Paul Duffin | e3dc660 | 2021-04-14 09:50:43 +0100 | [diff] [blame] | 275 | return properties.Max_target_q |
| 276 | }, |
| 277 | commandMutator: func(command *android.RuleBuilderCommand, path android.Path) { |
| 278 | command.FlagWithInput("--max-target-q ", path) |
| 279 | }, |
| 280 | }, |
Paul Duffin | 4616977 | 2021-04-14 15:01:56 +0100 | [diff] [blame] | 281 | // See HiddenAPIFlagFileProperties.Max_target_p |
Paul Duffin | e3dc660 | 2021-04-14 09:50:43 +0100 | [diff] [blame] | 282 | { |
| 283 | propertyName: "max_target_p", |
Paul Duffin | cc17bfe | 2021-04-19 13:21:20 +0100 | [diff] [blame] | 284 | propertyValueReader: func(properties *HiddenAPIFlagFileProperties) []string { |
Paul Duffin | e3dc660 | 2021-04-14 09:50:43 +0100 | [diff] [blame] | 285 | return properties.Max_target_p |
| 286 | }, |
| 287 | commandMutator: func(command *android.RuleBuilderCommand, path android.Path) { |
| 288 | command.FlagWithInput("--max-target-p ", path) |
| 289 | }, |
| 290 | }, |
Paul Duffin | 4616977 | 2021-04-14 15:01:56 +0100 | [diff] [blame] | 291 | // See HiddenAPIFlagFileProperties.Max_target_o_low_priority |
Paul Duffin | e3dc660 | 2021-04-14 09:50:43 +0100 | [diff] [blame] | 292 | { |
| 293 | propertyName: "max_target_o_low_priority", |
Paul Duffin | cc17bfe | 2021-04-19 13:21:20 +0100 | [diff] [blame] | 294 | propertyValueReader: func(properties *HiddenAPIFlagFileProperties) []string { |
Paul Duffin | e3dc660 | 2021-04-14 09:50:43 +0100 | [diff] [blame] | 295 | return properties.Max_target_o_low_priority |
| 296 | }, |
| 297 | commandMutator: func(command *android.RuleBuilderCommand, path android.Path) { |
| 298 | command.FlagWithInput("--max-target-o ", path).Flag("--ignore-conflicts ").FlagWithArg("--tag ", "lo-prio") |
| 299 | }, |
| 300 | }, |
Paul Duffin | 4616977 | 2021-04-14 15:01:56 +0100 | [diff] [blame] | 301 | // See HiddenAPIFlagFileProperties.Blocked |
Paul Duffin | e3dc660 | 2021-04-14 09:50:43 +0100 | [diff] [blame] | 302 | { |
| 303 | propertyName: "blocked", |
Paul Duffin | cc17bfe | 2021-04-19 13:21:20 +0100 | [diff] [blame] | 304 | propertyValueReader: func(properties *HiddenAPIFlagFileProperties) []string { |
Paul Duffin | e3dc660 | 2021-04-14 09:50:43 +0100 | [diff] [blame] | 305 | return properties.Blocked |
| 306 | }, |
| 307 | commandMutator: func(command *android.RuleBuilderCommand, path android.Path) { |
| 308 | command.FlagWithInput("--blocked ", path) |
| 309 | }, |
| 310 | }, |
Paul Duffin | 4616977 | 2021-04-14 15:01:56 +0100 | [diff] [blame] | 311 | // See HiddenAPIFlagFileProperties.Unsupported_packages |
Paul Duffin | e3dc660 | 2021-04-14 09:50:43 +0100 | [diff] [blame] | 312 | { |
| 313 | propertyName: "unsupported_packages", |
Paul Duffin | cc17bfe | 2021-04-19 13:21:20 +0100 | [diff] [blame] | 314 | propertyValueReader: func(properties *HiddenAPIFlagFileProperties) []string { |
Paul Duffin | e3dc660 | 2021-04-14 09:50:43 +0100 | [diff] [blame] | 315 | return properties.Unsupported_packages |
| 316 | }, |
| 317 | commandMutator: func(command *android.RuleBuilderCommand, path android.Path) { |
| 318 | command.FlagWithInput("--unsupported ", path).Flag("--packages ") |
| 319 | }, |
| 320 | }, |
Paul Duffin | 702210b | 2021-04-08 20:12:41 +0100 | [diff] [blame] | 321 | } |
| 322 | |
Paul Duffin | 438eb57 | 2021-05-21 16:58:23 +0100 | [diff] [blame] | 323 | // FlagFilesByCategory maps a hiddenAPIFlagFileCategory to the paths to the files in that category. |
| 324 | type FlagFilesByCategory map[*hiddenAPIFlagFileCategory]android.Paths |
| 325 | |
| 326 | // append appends the supplied flags files to the corresponding category in this map. |
| 327 | func (s FlagFilesByCategory) append(other FlagFilesByCategory) { |
| 328 | for _, category := range hiddenAPIFlagFileCategories { |
| 329 | s[category] = append(s[category], other[category]...) |
| 330 | } |
| 331 | } |
| 332 | |
| 333 | // dedup removes duplicates in the flag files, while maintaining the order in which they were |
| 334 | // appended. |
| 335 | func (s FlagFilesByCategory) dedup() { |
| 336 | for category, paths := range s { |
| 337 | s[category] = android.FirstUniquePaths(paths) |
| 338 | } |
| 339 | } |
| 340 | |
Paul Duffin | 2fef136 | 2021-04-15 13:32:00 +0100 | [diff] [blame] | 341 | // hiddenAPIFlagFileInfo contains paths resolved from HiddenAPIFlagFileProperties and also generated |
| 342 | // by hidden API processing. |
| 343 | // |
| 344 | // This is used both for an individual bootclasspath_fragment to provide it to other modules and |
| 345 | // for a module to collate the files from the fragments it depends upon. That is why the fields are |
| 346 | // all Paths even though they are initialized with a single path. |
Paul Duffin | 4616977 | 2021-04-14 15:01:56 +0100 | [diff] [blame] | 347 | type hiddenAPIFlagFileInfo struct { |
Paul Duffin | 438eb57 | 2021-05-21 16:58:23 +0100 | [diff] [blame] | 348 | // FlagFilesByCategory maps from the flag file category to the paths containing information for |
| 349 | // that category. |
| 350 | FlagFilesByCategory FlagFilesByCategory |
Paul Duffin | 2fef136 | 2021-04-15 13:32:00 +0100 | [diff] [blame] | 351 | |
Paul Duffin | 1e6f5c4 | 2021-05-21 16:15:31 +0100 | [diff] [blame] | 352 | // The output from the hidden API processing needs to be made available to other modules. |
| 353 | HiddenAPIFlagOutput |
Paul Duffin | c6bb7cf | 2021-04-08 17:49:27 +0100 | [diff] [blame] | 354 | } |
Paul Duffin | 702210b | 2021-04-08 20:12:41 +0100 | [diff] [blame] | 355 | |
Paul Duffin | 9b381ef | 2021-04-08 23:01:37 +0100 | [diff] [blame] | 356 | var hiddenAPIFlagFileInfoProvider = blueprint.NewProvider(hiddenAPIFlagFileInfo{}) |
| 357 | |
Paul Duffin | 1352f7c | 2021-05-21 22:18:49 +0100 | [diff] [blame^] | 358 | // StubDexJarsByKind maps an android.SdkKind to the paths to stub dex jars appropriate for that |
| 359 | // level. See hiddenAPIRelevantSdkKinds for a list of the acceptable android.SdkKind values. |
| 360 | type StubDexJarsByKind map[android.SdkKind]android.Paths |
| 361 | |
| 362 | // append appends the supplied kind specific stub dex jar pargs to the corresponding kind in this |
| 363 | // map. |
| 364 | func (s StubDexJarsByKind) append(other StubDexJarsByKind) { |
| 365 | for _, kind := range hiddenAPIRelevantSdkKinds { |
| 366 | s[kind] = append(s[kind], other[kind]...) |
| 367 | } |
| 368 | } |
| 369 | |
| 370 | // dedupAndSort removes duplicates in the stub dex jar paths and sorts them into a consistent and |
| 371 | // deterministic order. |
| 372 | func (s StubDexJarsByKind) dedupAndSort() { |
| 373 | for kind, paths := range s { |
| 374 | s[kind] = android.SortedUniquePaths(paths) |
| 375 | } |
| 376 | } |
| 377 | |
| 378 | // HiddenAPIFlagInput encapsulates information obtained from a module and its dependencies that are |
| 379 | // needed for hidden API flag generation. |
| 380 | type HiddenAPIFlagInput struct { |
| 381 | // FlagFilesByCategory contains the flag files that override the initial flags that are derived |
| 382 | // from the stub dex files. |
| 383 | FlagFilesByCategory FlagFilesByCategory |
| 384 | |
| 385 | // StubDexJarsByKind contains the stub dex jars for different android.SdkKind and which determine |
| 386 | // the initial flags for each dex member. |
| 387 | StubDexJarsByKind StubDexJarsByKind |
| 388 | } |
| 389 | |
| 390 | // newHiddenAPIFlagInput creates a new initialize HiddenAPIFlagInput struct. |
| 391 | func newHiddenAPIFlagInput() HiddenAPIFlagInput { |
| 392 | input := HiddenAPIFlagInput{ |
| 393 | FlagFilesByCategory: FlagFilesByCategory{}, |
| 394 | StubDexJarsByKind: StubDexJarsByKind{}, |
| 395 | } |
| 396 | |
| 397 | return input |
| 398 | } |
| 399 | |
| 400 | // gatherStubLibInfo gathers information from the stub libs needed by hidden API processing from the |
| 401 | // dependencies added in hiddenAPIAddStubLibDependencies. |
| 402 | // |
| 403 | // That includes paths to the stub dex jars as well as paths to the *removed.txt files. |
| 404 | func (i *HiddenAPIFlagInput) gatherStubLibInfo(ctx android.ModuleContext, contents []android.Module) { |
| 405 | addFromModule := func(ctx android.ModuleContext, module android.Module, kind android.SdkKind) { |
| 406 | dexJar := hiddenAPIRetrieveDexJarBuildPath(ctx, module, kind) |
| 407 | if dexJar != nil { |
| 408 | i.StubDexJarsByKind[kind] = append(i.StubDexJarsByKind[kind], dexJar) |
| 409 | } |
| 410 | } |
| 411 | |
| 412 | // If the contents includes any java_sdk_library modules then add them to the stubs. |
| 413 | for _, module := range contents { |
| 414 | if _, ok := module.(SdkLibraryDependency); ok { |
| 415 | // Add information for every possible kind needed by hidden API. SdkCorePlatform is not used |
| 416 | // as the java_sdk_library does not have special support for core_platform API, instead it is |
| 417 | // implemented as a customized form of SdkPublic. |
| 418 | for _, kind := range []android.SdkKind{android.SdkPublic, android.SdkSystem, android.SdkTest} { |
| 419 | addFromModule(ctx, module, kind) |
| 420 | } |
| 421 | } |
| 422 | } |
| 423 | |
| 424 | ctx.VisitDirectDepsIf(isActiveModule, func(module android.Module) { |
| 425 | tag := ctx.OtherModuleDependencyTag(module) |
| 426 | if hiddenAPIStubsTag, ok := tag.(hiddenAPIStubsDependencyTag); ok { |
| 427 | kind := hiddenAPIStubsTag.sdkKind |
| 428 | addFromModule(ctx, module, kind) |
| 429 | } |
| 430 | }) |
| 431 | |
| 432 | // Normalize the paths, i.e. remove duplicates and sort. |
| 433 | i.StubDexJarsByKind.dedupAndSort() |
| 434 | } |
| 435 | |
| 436 | // extractFlagFilesFromProperties extracts the paths to flag files that are specified in the |
| 437 | // supplied properties and stores them in this struct. |
| 438 | func (i *HiddenAPIFlagInput) extractFlagFilesFromProperties(ctx android.ModuleContext, p *HiddenAPIFlagFileProperties) { |
| 439 | for _, category := range hiddenAPIFlagFileCategories { |
| 440 | paths := android.PathsForModuleSrc(ctx, category.propertyValueReader(p)) |
| 441 | i.FlagFilesByCategory[category] = paths |
| 442 | } |
| 443 | } |
| 444 | |
Paul Duffin | 1e6f5c4 | 2021-05-21 16:15:31 +0100 | [diff] [blame] | 445 | // HiddenAPIFlagOutput contains paths to output files from the hidden API flag generation for a |
| 446 | // bootclasspath_fragment module. |
| 447 | type HiddenAPIFlagOutput struct { |
| 448 | // The path to the generated stub-flags.csv file. |
| 449 | StubFlagsPath android.Path |
| 450 | |
| 451 | // The path to the generated annotation-flags.csv file. |
| 452 | AnnotationFlagsPath android.Path |
| 453 | |
| 454 | // The path to the generated metadata.csv file. |
| 455 | MetadataPath android.Path |
| 456 | |
| 457 | // The path to the generated index.csv file. |
| 458 | IndexPath android.Path |
| 459 | |
| 460 | // The path to the generated all-flags.csv file. |
| 461 | AllFlagsPath android.Path |
| 462 | } |
| 463 | |
Paul Duffin | dfa1083 | 2021-05-13 17:31:51 +0100 | [diff] [blame] | 464 | // pathForValidation creates a path of the same type as the supplied type but with a name of |
| 465 | // <path>.valid. |
| 466 | // |
| 467 | // e.g. If path is an OutputPath for out/soong/hiddenapi/hiddenapi-flags.csv then this will return |
| 468 | // an OutputPath for out/soong/hiddenapi/hiddenapi-flags.csv.valid |
| 469 | func pathForValidation(ctx android.PathContext, path android.WritablePath) android.WritablePath { |
| 470 | extWithoutLeadingDot := strings.TrimPrefix(path.Ext(), ".") |
| 471 | return path.ReplaceExtension(ctx, extWithoutLeadingDot+".valid") |
| 472 | } |
| 473 | |
Paul Duffin | 2fef136 | 2021-04-15 13:32:00 +0100 | [diff] [blame] | 474 | // buildRuleToGenerateHiddenApiFlags creates a rule to create the monolithic hidden API flags from |
| 475 | // the flags from all the modules, the stub flags, augmented with some additional configuration |
| 476 | // files. |
Paul Duffin | 702210b | 2021-04-08 20:12:41 +0100 | [diff] [blame] | 477 | // |
| 478 | // baseFlagsPath is the path to the flags file containing all the information from the stubs plus |
| 479 | // an entry for every single member in the dex implementation jars of the individual modules. Every |
| 480 | // signature in any of the other files MUST be included in this file. |
| 481 | // |
Paul Duffin | 537ea3d | 2021-05-14 10:38:00 +0100 | [diff] [blame] | 482 | // annotationFlags is the path to the annotation flags file generated from annotation information |
| 483 | // in each module. |
Paul Duffin | 702210b | 2021-04-08 20:12:41 +0100 | [diff] [blame] | 484 | // |
Paul Duffin | 537ea3d | 2021-05-14 10:38:00 +0100 | [diff] [blame] | 485 | // flagFileInfo is a struct containing paths to files that augment the information provided by |
| 486 | // the annotationFlags. |
Paul Duffin | 438eb57 | 2021-05-21 16:58:23 +0100 | [diff] [blame] | 487 | func buildRuleToGenerateHiddenApiFlags(ctx android.BuilderContext, name, desc string, outputPath android.WritablePath, baseFlagsPath android.Path, annotationFlags android.Path, flagFilesByCategory FlagFilesByCategory, allFlagsPaths android.Paths) { |
Paul Duffin | dfa1083 | 2021-05-13 17:31:51 +0100 | [diff] [blame] | 488 | |
| 489 | // The file which is used to record that the flags file is valid. |
| 490 | var validFile android.WritablePath |
| 491 | |
| 492 | // If there are flag files that have been generated by fragments on which this depends then use |
| 493 | // them to validate the flag file generated by the rules created by this method. |
Paul Duffin | 438eb57 | 2021-05-21 16:58:23 +0100 | [diff] [blame] | 494 | if len(allFlagsPaths) > 0 { |
Paul Duffin | dfa1083 | 2021-05-13 17:31:51 +0100 | [diff] [blame] | 495 | // The flags file generated by the rule created by this method needs to be validated to ensure |
| 496 | // that it is consistent with the flag files generated by the individual fragments. |
| 497 | |
| 498 | validFile = pathForValidation(ctx, outputPath) |
| 499 | |
| 500 | // Create a rule to validate the output from the following rule. |
| 501 | rule := android.NewRuleBuilder(pctx, ctx) |
| 502 | rule.Command(). |
| 503 | BuiltTool("verify_overlaps"). |
| 504 | Input(outputPath). |
| 505 | Inputs(allFlagsPaths). |
| 506 | // If validation passes then update the file that records that. |
| 507 | Text("&& touch").Output(validFile) |
| 508 | rule.Build(name+"Validation", desc+" validation") |
| 509 | } |
| 510 | |
| 511 | // Create the rule that will generate the flag files. |
Paul Duffin | d3c1513 | 2021-04-21 22:12:35 +0100 | [diff] [blame] | 512 | tempPath := tempPathForRestat(ctx, outputPath) |
Paul Duffin | 702210b | 2021-04-08 20:12:41 +0100 | [diff] [blame] | 513 | rule := android.NewRuleBuilder(pctx, ctx) |
| 514 | command := rule.Command(). |
| 515 | BuiltTool("generate_hiddenapi_lists"). |
| 516 | FlagWithInput("--csv ", baseFlagsPath). |
Paul Duffin | 537ea3d | 2021-05-14 10:38:00 +0100 | [diff] [blame] | 517 | Input(annotationFlags). |
Paul Duffin | 702210b | 2021-04-08 20:12:41 +0100 | [diff] [blame] | 518 | FlagWithOutput("--output ", tempPath) |
| 519 | |
Paul Duffin | e3dc660 | 2021-04-14 09:50:43 +0100 | [diff] [blame] | 520 | // Add the options for the different categories of flag files. |
| 521 | for _, category := range hiddenAPIFlagFileCategories { |
Paul Duffin | 438eb57 | 2021-05-21 16:58:23 +0100 | [diff] [blame] | 522 | paths := flagFilesByCategory[category] |
Paul Duffin | e3dc660 | 2021-04-14 09:50:43 +0100 | [diff] [blame] | 523 | for _, path := range paths { |
| 524 | category.commandMutator(command, path) |
| 525 | } |
Paul Duffin | 702210b | 2021-04-08 20:12:41 +0100 | [diff] [blame] | 526 | } |
| 527 | |
| 528 | commitChangeForRestat(rule, tempPath, outputPath) |
| 529 | |
Paul Duffin | dfa1083 | 2021-05-13 17:31:51 +0100 | [diff] [blame] | 530 | if validFile != nil { |
| 531 | // Add the file that indicates that the file generated by this is valid. |
| 532 | // |
| 533 | // This will cause the validation rule above to be run any time that the output of this rule |
| 534 | // changes but the validation will run in parallel with other rules that depend on this file. |
| 535 | command.Validation(validFile) |
| 536 | } |
| 537 | |
Paul Duffin | 2fef136 | 2021-04-15 13:32:00 +0100 | [diff] [blame] | 538 | rule.Build(name, desc) |
| 539 | } |
| 540 | |
| 541 | // hiddenAPIGenerateAllFlagsForBootclasspathFragment will generate all the flags for a fragment |
| 542 | // of the bootclasspath. |
| 543 | // |
| 544 | // It takes: |
| 545 | // * Map from android.SdkKind to stub dex jar paths defining the API for that sdk kind. |
| 546 | // * The list of modules that are the contents of the fragment. |
| 547 | // * The additional manually curated flag files to use. |
| 548 | // |
| 549 | // It generates: |
| 550 | // * stub-flags.csv |
| 551 | // * annotation-flags.csv |
| 552 | // * metadata.csv |
| 553 | // * index.csv |
| 554 | // * all-flags.csv |
Paul Duffin | 1352f7c | 2021-05-21 22:18:49 +0100 | [diff] [blame^] | 555 | func hiddenAPIGenerateAllFlagsForBootclasspathFragment(ctx android.ModuleContext, contents []hiddenAPIModule, input HiddenAPIFlagInput) *HiddenAPIFlagOutput { |
Paul Duffin | 2fef136 | 2021-04-15 13:32:00 +0100 | [diff] [blame] | 556 | hiddenApiSubDir := "modular-hiddenapi" |
| 557 | |
Paul Duffin | 1352f7c | 2021-05-21 22:18:49 +0100 | [diff] [blame^] | 558 | // Gather the dex files for the boot libraries provided by this fragment. |
Paul Duffin | 537ea3d | 2021-05-14 10:38:00 +0100 | [diff] [blame] | 559 | bootDexJars := extractBootDexJarsFromHiddenAPIModules(ctx, contents) |
Paul Duffin | 1352f7c | 2021-05-21 22:18:49 +0100 | [diff] [blame^] | 560 | |
| 561 | // Generate the stub-flags.csv. |
Paul Duffin | 2fef136 | 2021-04-15 13:32:00 +0100 | [diff] [blame] | 562 | stubFlagsCSV := android.PathForModuleOut(ctx, hiddenApiSubDir, "stub-flags.csv") |
Paul Duffin | 1352f7c | 2021-05-21 22:18:49 +0100 | [diff] [blame^] | 563 | rule := ruleToGenerateHiddenAPIStubFlagsFile(ctx, stubFlagsCSV, bootDexJars, input) |
Paul Duffin | 2fef136 | 2021-04-15 13:32:00 +0100 | [diff] [blame] | 564 | rule.Build("modularHiddenAPIStubFlagsFile", "modular hiddenapi stub flags") |
| 565 | |
Paul Duffin | 537ea3d | 2021-05-14 10:38:00 +0100 | [diff] [blame] | 566 | // Extract the classes jars from the contents. |
| 567 | classesJars := extractClassJarsFromHiddenAPIModules(ctx, contents) |
| 568 | |
Paul Duffin | 2fef136 | 2021-04-15 13:32:00 +0100 | [diff] [blame] | 569 | // Generate the set of flags from the annotations in the source code. |
| 570 | annotationFlagsCSV := android.PathForModuleOut(ctx, hiddenApiSubDir, "annotation-flags.csv") |
Paul Duffin | 850e61f | 2021-05-14 09:58:48 +0100 | [diff] [blame] | 571 | buildRuleToGenerateAnnotationFlags(ctx, "modular hiddenapi annotation flags", classesJars, stubFlagsCSV, annotationFlagsCSV) |
Paul Duffin | 2fef136 | 2021-04-15 13:32:00 +0100 | [diff] [blame] | 572 | |
| 573 | // Generate the metadata from the annotations in the source code. |
| 574 | metadataCSV := android.PathForModuleOut(ctx, hiddenApiSubDir, "metadata.csv") |
Paul Duffin | 850e61f | 2021-05-14 09:58:48 +0100 | [diff] [blame] | 575 | buildRuleToGenerateMetadata(ctx, "modular hiddenapi metadata", classesJars, stubFlagsCSV, metadataCSV) |
Paul Duffin | 2fef136 | 2021-04-15 13:32:00 +0100 | [diff] [blame] | 576 | |
Paul Duffin | 537ea3d | 2021-05-14 10:38:00 +0100 | [diff] [blame] | 577 | // Generate the index file from the CSV files in the classes jars. |
Paul Duffin | 2fef136 | 2021-04-15 13:32:00 +0100 | [diff] [blame] | 578 | indexCSV := android.PathForModuleOut(ctx, hiddenApiSubDir, "index.csv") |
Paul Duffin | 850e61f | 2021-05-14 09:58:48 +0100 | [diff] [blame] | 579 | buildRuleToGenerateIndex(ctx, "modular hiddenapi index", classesJars, indexCSV) |
Paul Duffin | 2fef136 | 2021-04-15 13:32:00 +0100 | [diff] [blame] | 580 | |
| 581 | // Removed APIs need to be marked and in order to do that the flagFileInfo needs to specify files |
| 582 | // containing dex signatures of all the removed APIs. In the monolithic files that is done by |
| 583 | // manually combining all the removed.txt files for each API and then converting them to dex |
| 584 | // signatures, see the combined-removed-dex module. That will all be done automatically in future. |
| 585 | // For now removed APIs are ignored. |
| 586 | // TODO(b/179354495): handle removed apis automatically. |
| 587 | |
| 588 | // Generate the all-flags.csv which are the flags that will, in future, be encoded into the dex |
| 589 | // files. |
| 590 | outputPath := android.PathForModuleOut(ctx, hiddenApiSubDir, "all-flags.csv") |
Paul Duffin | 1352f7c | 2021-05-21 22:18:49 +0100 | [diff] [blame^] | 591 | buildRuleToGenerateHiddenApiFlags(ctx, "modularHiddenApiAllFlags", "modular hiddenapi all flags", outputPath, stubFlagsCSV, annotationFlagsCSV, input.FlagFilesByCategory, nil) |
Paul Duffin | 2fef136 | 2021-04-15 13:32:00 +0100 | [diff] [blame] | 592 | |
| 593 | // Store the paths in the info for use by other modules and sdk snapshot generation. |
Paul Duffin | 1e6f5c4 | 2021-05-21 16:15:31 +0100 | [diff] [blame] | 594 | output := HiddenAPIFlagOutput{ |
| 595 | StubFlagsPath: stubFlagsCSV, |
| 596 | AnnotationFlagsPath: annotationFlagsCSV, |
| 597 | MetadataPath: metadataCSV, |
| 598 | IndexPath: indexCSV, |
| 599 | AllFlagsPath: outputPath, |
| 600 | } |
| 601 | return &output |
Paul Duffin | 702210b | 2021-04-08 20:12:41 +0100 | [diff] [blame] | 602 | } |
Paul Duffin | 537ea3d | 2021-05-14 10:38:00 +0100 | [diff] [blame] | 603 | |
| 604 | // gatherHiddenAPIModuleFromContents gathers the hiddenAPIModule from the supplied contents. |
| 605 | func gatherHiddenAPIModuleFromContents(ctx android.ModuleContext, contents []android.Module) []hiddenAPIModule { |
| 606 | hiddenAPIModules := []hiddenAPIModule{} |
| 607 | for _, module := range contents { |
| 608 | if hiddenAPI, ok := module.(hiddenAPIModule); ok { |
| 609 | hiddenAPIModules = append(hiddenAPIModules, hiddenAPI) |
| 610 | } else if _, ok := module.(*DexImport); ok { |
| 611 | // Ignore this for the purposes of hidden API processing |
| 612 | } else { |
| 613 | ctx.ModuleErrorf("module %s does not implement hiddenAPIModule", module) |
| 614 | } |
| 615 | } |
| 616 | return hiddenAPIModules |
| 617 | } |
| 618 | |
| 619 | // extractBootDexJarsFromHiddenAPIModules extracts the boot dex jars from the supplied modules. |
| 620 | func extractBootDexJarsFromHiddenAPIModules(ctx android.ModuleContext, contents []hiddenAPIModule) android.Paths { |
| 621 | bootDexJars := android.Paths{} |
| 622 | for _, module := range contents { |
| 623 | bootDexJar := module.bootDexJar() |
| 624 | if bootDexJar == nil { |
Paul Duffin | 7487a7a | 2021-05-19 09:36:09 +0100 | [diff] [blame] | 625 | if ctx.Config().AlwaysUsePrebuiltSdks() { |
| 626 | // TODO(b/179354495): Remove this work around when it is unnecessary. |
| 627 | // Prebuilt modules like framework-wifi do not yet provide dex implementation jars. So, |
| 628 | // create a fake one that will cause a build error only if it is used. |
| 629 | fake := android.PathForModuleOut(ctx, "fake/boot-dex/%s.jar", module.Name()) |
| 630 | |
| 631 | // Create an error rule that pretends to create the output file but will actually fail if it |
| 632 | // is run. |
| 633 | ctx.Build(pctx, android.BuildParams{ |
| 634 | Rule: android.ErrorRule, |
| 635 | Output: fake, |
| 636 | Args: map[string]string{ |
| 637 | "error": fmt.Sprintf("missing dependencies: boot dex jar for %s", module), |
| 638 | }, |
| 639 | }) |
| 640 | bootDexJars = append(bootDexJars, fake) |
| 641 | } else { |
| 642 | ctx.ModuleErrorf("module %s does not provide a dex jar", module) |
| 643 | } |
Paul Duffin | 537ea3d | 2021-05-14 10:38:00 +0100 | [diff] [blame] | 644 | } else { |
| 645 | bootDexJars = append(bootDexJars, bootDexJar) |
| 646 | } |
| 647 | } |
| 648 | return bootDexJars |
| 649 | } |
| 650 | |
| 651 | // extractClassJarsFromHiddenAPIModules extracts the class jars from the supplied modules. |
| 652 | func extractClassJarsFromHiddenAPIModules(ctx android.ModuleContext, contents []hiddenAPIModule) android.Paths { |
| 653 | classesJars := android.Paths{} |
| 654 | for _, module := range contents { |
| 655 | classesJars = append(classesJars, module.classesJars()...) |
| 656 | } |
| 657 | return classesJars |
| 658 | } |