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" |
Martin Stjernholm | 8be1e6d | 2021-09-15 03:34:04 +0100 | [diff] [blame] | 22 | |
Paul Duffin | 9b381ef | 2021-04-08 23:01:37 +0100 | [diff] [blame] | 23 | "github.com/google/blueprint" |
Paul Duffin | c6bb7cf | 2021-04-08 17:49:27 +0100 | [diff] [blame] | 24 | ) |
| 25 | |
| 26 | // Contains support for processing hiddenAPI in a modular fashion. |
| 27 | |
Paul Duffin | 31fad80 | 2021-06-18 18:14:25 +0100 | [diff] [blame] | 28 | // HiddenAPIScope encapsulates all the information that the hidden API processing needs about API |
| 29 | // scopes, i.e. what is called android.SdkKind and apiScope. It does not just use those as they do |
| 30 | // not provide the information needed by hidden API processing. |
| 31 | type HiddenAPIScope struct { |
| 32 | // The name of the scope, used for debug purposes. |
| 33 | name string |
| 34 | |
| 35 | // The corresponding android.SdkKind, used for retrieving paths from java_sdk_library* modules. |
| 36 | sdkKind android.SdkKind |
| 37 | |
| 38 | // The option needed to passed to "hiddenapi list". |
| 39 | hiddenAPIListOption string |
Paul Duffin | 5cca7c4 | 2021-05-26 10:16:01 +0100 | [diff] [blame] | 40 | |
| 41 | // The name sof the source stub library modules that contain the API provided by the platform, |
| 42 | // i.e. by modules that are not in an APEX. |
| 43 | nonUpdatableSourceModule string |
| 44 | |
| 45 | // The names of the prebuilt stub library modules that contain the API provided by the platform, |
| 46 | // i.e. by modules that are not in an APEX. |
| 47 | nonUpdatablePrebuiltModule string |
Paul Duffin | 31fad80 | 2021-06-18 18:14:25 +0100 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | // initHiddenAPIScope initializes the scope. |
| 51 | func initHiddenAPIScope(apiScope *HiddenAPIScope) *HiddenAPIScope { |
Paul Duffin | 5cca7c4 | 2021-05-26 10:16:01 +0100 | [diff] [blame] | 52 | sdkKind := apiScope.sdkKind |
| 53 | // The platform does not provide a core platform API. |
| 54 | if sdkKind != android.SdkCorePlatform { |
| 55 | kindAsString := sdkKind.String() |
| 56 | var insert string |
| 57 | if sdkKind == android.SdkPublic { |
| 58 | insert = "" |
| 59 | } else { |
| 60 | insert = "." + strings.ReplaceAll(kindAsString, "-", "_") |
| 61 | } |
| 62 | |
| 63 | nonUpdatableModule := "android-non-updatable" |
| 64 | |
| 65 | // Construct the name of the android-non-updatable source module for this scope. |
| 66 | apiScope.nonUpdatableSourceModule = fmt.Sprintf("%s.stubs%s", nonUpdatableModule, insert) |
| 67 | |
| 68 | prebuiltModuleName := func(name string, kind string) string { |
| 69 | return fmt.Sprintf("sdk_%s_current_%s", kind, name) |
| 70 | } |
| 71 | |
| 72 | // Construct the name of the android-non-updatable prebuilt module for this scope. |
| 73 | apiScope.nonUpdatablePrebuiltModule = prebuiltModuleName(nonUpdatableModule, kindAsString) |
| 74 | } |
| 75 | |
Paul Duffin | 31fad80 | 2021-06-18 18:14:25 +0100 | [diff] [blame] | 76 | return apiScope |
| 77 | } |
| 78 | |
Paul Duffin | 5cca7c4 | 2021-05-26 10:16:01 +0100 | [diff] [blame] | 79 | // android-non-updatable takes the name of a module and returns a possibly scope specific name of |
| 80 | // the module. |
| 81 | func (l *HiddenAPIScope) scopeSpecificStubModule(ctx android.BaseModuleContext, name string) string { |
| 82 | // The android-non-updatable is not a java_sdk_library but there are separate stub libraries for |
| 83 | // each scope. |
| 84 | // TODO(b/192067200): Remove special handling of android-non-updatable. |
| 85 | if name == "android-non-updatable" { |
| 86 | if ctx.Config().AlwaysUsePrebuiltSdks() { |
| 87 | return l.nonUpdatablePrebuiltModule |
| 88 | } else { |
| 89 | return l.nonUpdatableSourceModule |
| 90 | } |
| 91 | } else { |
| 92 | // Assume that the module is either a java_sdk_library (or equivalent) and so will provide |
| 93 | // separate stub jars for each scope or is a java_library (or equivalent) in which case it will |
| 94 | // have the same stub jar for each scope. |
| 95 | return name |
| 96 | } |
| 97 | } |
| 98 | |
Paul Duffin | 31fad80 | 2021-06-18 18:14:25 +0100 | [diff] [blame] | 99 | func (l *HiddenAPIScope) String() string { |
| 100 | return fmt.Sprintf("HiddenAPIScope{%s}", l.name) |
| 101 | } |
| 102 | |
| 103 | var ( |
| 104 | PublicHiddenAPIScope = initHiddenAPIScope(&HiddenAPIScope{ |
| 105 | name: "public", |
| 106 | sdkKind: android.SdkPublic, |
| 107 | hiddenAPIListOption: "--public-stub-classpath", |
| 108 | }) |
| 109 | SystemHiddenAPIScope = initHiddenAPIScope(&HiddenAPIScope{ |
| 110 | name: "system", |
| 111 | sdkKind: android.SdkSystem, |
| 112 | hiddenAPIListOption: "--system-stub-classpath", |
| 113 | }) |
| 114 | TestHiddenAPIScope = initHiddenAPIScope(&HiddenAPIScope{ |
| 115 | name: "test", |
| 116 | sdkKind: android.SdkTest, |
| 117 | hiddenAPIListOption: "--test-stub-classpath", |
| 118 | }) |
Paul Duffin | b51db2e | 2021-06-21 14:08:08 +0100 | [diff] [blame] | 119 | ModuleLibHiddenAPIScope = initHiddenAPIScope(&HiddenAPIScope{ |
| 120 | name: "module-lib", |
| 121 | sdkKind: android.SdkModule, |
| 122 | }) |
Paul Duffin | 31fad80 | 2021-06-18 18:14:25 +0100 | [diff] [blame] | 123 | CorePlatformHiddenAPIScope = initHiddenAPIScope(&HiddenAPIScope{ |
| 124 | name: "core-platform", |
| 125 | sdkKind: android.SdkCorePlatform, |
| 126 | hiddenAPIListOption: "--core-platform-stub-classpath", |
| 127 | }) |
| 128 | |
| 129 | // hiddenAPIRelevantSdkKinds lists all the android.SdkKind instances that are needed by the hidden |
| 130 | // API processing. |
| 131 | // |
| 132 | // These are roughly in order from narrowest API surface to widest. Widest means the API stubs |
| 133 | // with the biggest API surface, e.g. test is wider than system is wider than public. |
| 134 | // |
Paul Duffin | b51db2e | 2021-06-21 14:08:08 +0100 | [diff] [blame] | 135 | // Core platform is considered wider than system/module-lib because those modules that provide |
| 136 | // core platform APIs either do not have any system/module-lib APIs at all, or if they do it is |
| 137 | // because the core platform API is being converted to system/module-lib APIs. In either case the |
| 138 | // system/module-lib APIs are subsets of the core platform API. |
Paul Duffin | 31fad80 | 2021-06-18 18:14:25 +0100 | [diff] [blame] | 139 | // |
| 140 | // This is not strictly in order from narrowest to widest as the Test API is wider than system but |
Paul Duffin | b51db2e | 2021-06-21 14:08:08 +0100 | [diff] [blame] | 141 | // is neither wider or narrower than the module-lib or core platform APIs. However, this works |
| 142 | // well enough at the moment. |
Paul Duffin | 31fad80 | 2021-06-18 18:14:25 +0100 | [diff] [blame] | 143 | // TODO(b/191644675): Correctly reflect the sub/superset relationships between APIs. |
| 144 | hiddenAPIScopes = []*HiddenAPIScope{ |
| 145 | PublicHiddenAPIScope, |
| 146 | SystemHiddenAPIScope, |
| 147 | TestHiddenAPIScope, |
Paul Duffin | b51db2e | 2021-06-21 14:08:08 +0100 | [diff] [blame] | 148 | ModuleLibHiddenAPIScope, |
Paul Duffin | 31fad80 | 2021-06-18 18:14:25 +0100 | [diff] [blame] | 149 | CorePlatformHiddenAPIScope, |
| 150 | } |
| 151 | |
| 152 | // The HiddenAPIScope instances that are supported by a java_sdk_library. |
| 153 | // |
| 154 | // CorePlatformHiddenAPIScope is not used as the java_sdk_library does not have special support |
| 155 | // for core_platform API, instead it is implemented as a customized form of PublicHiddenAPIScope. |
| 156 | hiddenAPISdkLibrarySupportedScopes = []*HiddenAPIScope{ |
| 157 | PublicHiddenAPIScope, |
| 158 | SystemHiddenAPIScope, |
| 159 | TestHiddenAPIScope, |
Paul Duffin | b51db2e | 2021-06-21 14:08:08 +0100 | [diff] [blame] | 160 | ModuleLibHiddenAPIScope, |
Paul Duffin | 31fad80 | 2021-06-18 18:14:25 +0100 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | // The HiddenAPIScope instances that are supported by the `hiddenapi list`. |
| 164 | hiddenAPIFlagScopes = []*HiddenAPIScope{ |
| 165 | PublicHiddenAPIScope, |
| 166 | SystemHiddenAPIScope, |
| 167 | TestHiddenAPIScope, |
| 168 | CorePlatformHiddenAPIScope, |
| 169 | } |
| 170 | ) |
| 171 | |
Paul Duffin | 74431d5 | 2021-04-21 14:10:42 +0100 | [diff] [blame] | 172 | type hiddenAPIStubsDependencyTag struct { |
| 173 | blueprint.BaseDependencyTag |
Paul Duffin | 31fad80 | 2021-06-18 18:14:25 +0100 | [diff] [blame] | 174 | |
| 175 | // The api scope for which this dependency was added. |
| 176 | apiScope *HiddenAPIScope |
Paul Duffin | 5cca7c4 | 2021-05-26 10:16:01 +0100 | [diff] [blame] | 177 | |
| 178 | // Indicates that the dependency is not for an API provided by the current bootclasspath fragment |
| 179 | // but is an additional API provided by a module that is not part of the current bootclasspath |
| 180 | // fragment. |
| 181 | fromAdditionalDependency bool |
Paul Duffin | 74431d5 | 2021-04-21 14:10:42 +0100 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | func (b hiddenAPIStubsDependencyTag) ExcludeFromApexContents() { |
| 185 | } |
| 186 | |
| 187 | func (b hiddenAPIStubsDependencyTag) ReplaceSourceWithPrebuilt() bool { |
| 188 | return false |
| 189 | } |
| 190 | |
Paul Duffin | 976b0e5 | 2021-04-27 23:20:26 +0100 | [diff] [blame] | 191 | func (b hiddenAPIStubsDependencyTag) SdkMemberType(child android.Module) android.SdkMemberType { |
Paul Duffin | 5cca7c4 | 2021-05-26 10:16:01 +0100 | [diff] [blame] | 192 | // Do not add additional dependencies to the sdk. |
| 193 | if b.fromAdditionalDependency { |
| 194 | return nil |
| 195 | } |
| 196 | |
Paul Duffin | 976b0e5 | 2021-04-27 23:20:26 +0100 | [diff] [blame] | 197 | // If the module is a java_sdk_library then treat it as if it was specific in the java_sdk_libs |
| 198 | // property, otherwise treat if it was specified in the java_header_libs property. |
| 199 | if javaSdkLibrarySdkMemberType.IsInstance(child) { |
| 200 | return javaSdkLibrarySdkMemberType |
| 201 | } |
| 202 | |
| 203 | return javaHeaderLibsSdkMemberType |
| 204 | } |
| 205 | |
| 206 | func (b hiddenAPIStubsDependencyTag) ExportMember() bool { |
| 207 | // Export the module added via this dependency tag from the sdk. |
| 208 | return true |
| 209 | } |
| 210 | |
Paul Duffin | 74431d5 | 2021-04-21 14:10:42 +0100 | [diff] [blame] | 211 | // Avoid having to make stubs content explicitly visible to dependent modules. |
| 212 | // |
| 213 | // This is a temporary workaround to make it easier to migrate to bootclasspath_fragment modules |
| 214 | // with proper dependencies. |
| 215 | // TODO(b/177892522): Remove this and add needed visibility. |
| 216 | func (b hiddenAPIStubsDependencyTag) ExcludeFromVisibilityEnforcement() { |
| 217 | } |
| 218 | |
| 219 | var _ android.ExcludeFromVisibilityEnforcementTag = hiddenAPIStubsDependencyTag{} |
| 220 | var _ android.ReplaceSourceWithPrebuilt = hiddenAPIStubsDependencyTag{} |
| 221 | var _ android.ExcludeFromApexContentsTag = hiddenAPIStubsDependencyTag{} |
Paul Duffin | f7b3d0d | 2021-09-02 14:29:21 +0100 | [diff] [blame] | 222 | var _ android.SdkMemberDependencyTag = hiddenAPIStubsDependencyTag{} |
Paul Duffin | 74431d5 | 2021-04-21 14:10:42 +0100 | [diff] [blame] | 223 | |
Paul Duffin | 74431d5 | 2021-04-21 14:10:42 +0100 | [diff] [blame] | 224 | // hiddenAPIComputeMonolithicStubLibModules computes the set of module names that provide stubs |
| 225 | // needed to produce the hidden API monolithic stub flags file. |
Paul Duffin | 31fad80 | 2021-06-18 18:14:25 +0100 | [diff] [blame] | 226 | func hiddenAPIComputeMonolithicStubLibModules(config android.Config) map[*HiddenAPIScope][]string { |
Paul Duffin | 74431d5 | 2021-04-21 14:10:42 +0100 | [diff] [blame] | 227 | var publicStubModules []string |
| 228 | var systemStubModules []string |
| 229 | var testStubModules []string |
| 230 | var corePlatformStubModules []string |
| 231 | |
| 232 | if config.AlwaysUsePrebuiltSdks() { |
| 233 | // Build configuration mandates using prebuilt stub modules |
| 234 | publicStubModules = append(publicStubModules, "sdk_public_current_android") |
| 235 | systemStubModules = append(systemStubModules, "sdk_system_current_android") |
| 236 | testStubModules = append(testStubModules, "sdk_test_current_android") |
| 237 | } else { |
| 238 | // Use stub modules built from source |
| 239 | publicStubModules = append(publicStubModules, "android_stubs_current") |
| 240 | systemStubModules = append(systemStubModules, "android_system_stubs_current") |
| 241 | testStubModules = append(testStubModules, "android_test_stubs_current") |
| 242 | } |
| 243 | // We do not have prebuilts of the core platform api yet |
| 244 | corePlatformStubModules = append(corePlatformStubModules, "legacy.core.platform.api.stubs") |
| 245 | |
| 246 | // Allow products to define their own stubs for custom product jars that apps can use. |
| 247 | publicStubModules = append(publicStubModules, config.ProductHiddenAPIStubs()...) |
| 248 | systemStubModules = append(systemStubModules, config.ProductHiddenAPIStubsSystem()...) |
| 249 | testStubModules = append(testStubModules, config.ProductHiddenAPIStubsTest()...) |
| 250 | if config.IsEnvTrue("EMMA_INSTRUMENT") { |
Paul Duffin | 098c878 | 2021-05-14 10:45:25 +0100 | [diff] [blame] | 251 | // Add jacoco-stubs to public, system and test. It doesn't make any real difference as public |
| 252 | // allows everyone access but it is needed to ensure consistent flags between the |
| 253 | // bootclasspath fragment generated flags and the platform_bootclasspath generated flags. |
Paul Duffin | 74431d5 | 2021-04-21 14:10:42 +0100 | [diff] [blame] | 254 | publicStubModules = append(publicStubModules, "jacoco-stubs") |
Paul Duffin | 098c878 | 2021-05-14 10:45:25 +0100 | [diff] [blame] | 255 | systemStubModules = append(systemStubModules, "jacoco-stubs") |
| 256 | testStubModules = append(testStubModules, "jacoco-stubs") |
Paul Duffin | 74431d5 | 2021-04-21 14:10:42 +0100 | [diff] [blame] | 257 | } |
| 258 | |
Paul Duffin | 31fad80 | 2021-06-18 18:14:25 +0100 | [diff] [blame] | 259 | m := map[*HiddenAPIScope][]string{} |
| 260 | m[PublicHiddenAPIScope] = publicStubModules |
| 261 | m[SystemHiddenAPIScope] = systemStubModules |
| 262 | m[TestHiddenAPIScope] = testStubModules |
| 263 | m[CorePlatformHiddenAPIScope] = corePlatformStubModules |
Paul Duffin | 74431d5 | 2021-04-21 14:10:42 +0100 | [diff] [blame] | 264 | return m |
| 265 | } |
| 266 | |
| 267 | // hiddenAPIAddStubLibDependencies adds dependencies onto the modules specified in |
Paul Duffin | 31fad80 | 2021-06-18 18:14:25 +0100 | [diff] [blame] | 268 | // apiScopeToStubLibModules. It adds them in a well known order and uses a HiddenAPIScope specific |
| 269 | // tag to identify the source of the dependency. |
| 270 | func hiddenAPIAddStubLibDependencies(ctx android.BottomUpMutatorContext, apiScopeToStubLibModules map[*HiddenAPIScope][]string) { |
Paul Duffin | 74431d5 | 2021-04-21 14:10:42 +0100 | [diff] [blame] | 271 | module := ctx.Module() |
Paul Duffin | 31fad80 | 2021-06-18 18:14:25 +0100 | [diff] [blame] | 272 | for _, apiScope := range hiddenAPIScopes { |
| 273 | modules := apiScopeToStubLibModules[apiScope] |
| 274 | ctx.AddDependency(module, hiddenAPIStubsDependencyTag{apiScope: apiScope}, modules...) |
Paul Duffin | 74431d5 | 2021-04-21 14:10:42 +0100 | [diff] [blame] | 275 | } |
| 276 | } |
| 277 | |
Paul Duffin | 74431d5 | 2021-04-21 14:10:42 +0100 | [diff] [blame] | 278 | // hiddenAPIRetrieveDexJarBuildPath retrieves the DexJarBuildPath from the specified module, if |
| 279 | // available, or reports an error. |
Paul Duffin | 1093158 | 2021-04-25 10:13:54 +0100 | [diff] [blame] | 280 | func hiddenAPIRetrieveDexJarBuildPath(ctx android.ModuleContext, module android.Module, kind android.SdkKind) android.Path { |
Martin Stjernholm | 8be1e6d | 2021-09-15 03:34:04 +0100 | [diff] [blame] | 281 | var dexJar OptionalDexJarPath |
Paul Duffin | 1093158 | 2021-04-25 10:13:54 +0100 | [diff] [blame] | 282 | if sdkLibrary, ok := module.(SdkLibraryDependency); ok { |
| 283 | dexJar = sdkLibrary.SdkApiStubDexJar(ctx, kind) |
| 284 | } else if j, ok := module.(UsesLibraryDependency); ok { |
| 285 | dexJar = j.DexJarBuildPath() |
Paul Duffin | 74431d5 | 2021-04-21 14:10:42 +0100 | [diff] [blame] | 286 | } else { |
| 287 | 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] | 288 | return nil |
Paul Duffin | 74431d5 | 2021-04-21 14:10:42 +0100 | [diff] [blame] | 289 | } |
Paul Duffin | 1093158 | 2021-04-25 10:13:54 +0100 | [diff] [blame] | 290 | |
Martin Stjernholm | 8be1e6d | 2021-09-15 03:34:04 +0100 | [diff] [blame] | 291 | if !dexJar.Valid() { |
| 292 | ctx.ModuleErrorf("dependency %s does not provide a dex jar: %s", module, dexJar.InvalidReason()) |
| 293 | return nil |
Paul Duffin | 1093158 | 2021-04-25 10:13:54 +0100 | [diff] [blame] | 294 | } |
Martin Stjernholm | 8be1e6d | 2021-09-15 03:34:04 +0100 | [diff] [blame] | 295 | return dexJar.Path() |
Paul Duffin | 74431d5 | 2021-04-21 14:10:42 +0100 | [diff] [blame] | 296 | } |
| 297 | |
Paul Duffin | bd88c88 | 2022-04-07 23:32:19 +0100 | [diff] [blame] | 298 | // HIDDENAPI_STUB_FLAGS_IMPL_FLAGS is the set of flags that identify implementation only signatures, |
| 299 | // i.e. those signatures that are not part of any API (including the hidden API). |
| 300 | var HIDDENAPI_STUB_FLAGS_IMPL_FLAGS = []string{} |
| 301 | |
| 302 | var HIDDENAPI_FLAGS_CSV_IMPL_FLAGS = []string{"blocked"} |
| 303 | |
Paul Duffin | 4539a37 | 2021-06-23 23:20:43 +0100 | [diff] [blame] | 304 | // buildRuleToGenerateHiddenAPIStubFlagsFile creates a rule to create a hidden API stub flags file. |
Paul Duffin | 74431d5 | 2021-04-21 14:10:42 +0100 | [diff] [blame] | 305 | // |
| 306 | // The rule is initialized but not built so that the caller can modify it and select an appropriate |
| 307 | // name. |
Paul Duffin | 67b9d61 | 2021-07-21 17:38:47 +0100 | [diff] [blame] | 308 | func buildRuleToGenerateHiddenAPIStubFlagsFile(ctx android.BuilderContext, name, desc string, outputPath android.WritablePath, bootDexJars android.Paths, input HiddenAPIFlagInput, stubFlagSubsets SignatureCsvSubsets) { |
Paul Duffin | 74431d5 | 2021-04-21 14:10:42 +0100 | [diff] [blame] | 309 | // Singleton rule which applies hiddenapi on all boot class path dex files. |
| 310 | rule := android.NewRuleBuilder(pctx, ctx) |
| 311 | |
| 312 | tempPath := tempPathForRestat(ctx, outputPath) |
| 313 | |
Paul Duffin | f1b358c | 2021-05-17 07:38:47 +0100 | [diff] [blame] | 314 | // Find the widest API stubs provided by the fragments on which this depends, if any. |
Paul Duffin | d2b1e0c | 2021-06-27 20:53:39 +0100 | [diff] [blame] | 315 | dependencyStubDexJars := input.DependencyStubDexJarsByScope.StubDexJarsForWidestAPIScope() |
Paul Duffin | 5cca7c4 | 2021-05-26 10:16:01 +0100 | [diff] [blame] | 316 | |
| 317 | // Add widest API stubs from the additional dependencies of this, if any. |
Paul Duffin | d2b1e0c | 2021-06-27 20:53:39 +0100 | [diff] [blame] | 318 | dependencyStubDexJars = append(dependencyStubDexJars, input.AdditionalStubDexJarsByScope.StubDexJarsForWidestAPIScope()...) |
Paul Duffin | f1b358c | 2021-05-17 07:38:47 +0100 | [diff] [blame] | 319 | |
Paul Duffin | 74431d5 | 2021-04-21 14:10:42 +0100 | [diff] [blame] | 320 | command := rule.Command(). |
| 321 | Tool(ctx.Config().HostToolPath(ctx, "hiddenapi")). |
| 322 | Text("list"). |
Paul Duffin | f1b358c | 2021-05-17 07:38:47 +0100 | [diff] [blame] | 323 | FlagForEachInput("--dependency-stub-dex=", dependencyStubDexJars). |
Paul Duffin | 74431d5 | 2021-04-21 14:10:42 +0100 | [diff] [blame] | 324 | FlagForEachInput("--boot-dex=", bootDexJars) |
| 325 | |
Paul Duffin | 156b5d3 | 2021-06-24 23:06:52 +0100 | [diff] [blame] | 326 | // If no module stub flags paths are provided then this must be being called for a |
| 327 | // bootclasspath_fragment and not the whole platform_bootclasspath. |
Paul Duffin | 67b9d61 | 2021-07-21 17:38:47 +0100 | [diff] [blame] | 328 | if stubFlagSubsets == nil { |
Paul Duffin | 156b5d3 | 2021-06-24 23:06:52 +0100 | [diff] [blame] | 329 | // This is being run on a fragment of the bootclasspath. |
| 330 | command.Flag("--fragment") |
| 331 | } |
| 332 | |
Paul Duffin | 31fad80 | 2021-06-18 18:14:25 +0100 | [diff] [blame] | 333 | // Iterate over the api scopes in a fixed order. |
| 334 | for _, apiScope := range hiddenAPIFlagScopes { |
| 335 | // Merge in the stub dex jar paths for this api scope from the fragments on which it depends. |
| 336 | // They will be needed to resolve dependencies from this fragment's stubs to classes in the |
| 337 | // other fragment's APIs. |
| 338 | var paths android.Paths |
Paul Duffin | 280a31a | 2021-06-27 20:28:29 +0100 | [diff] [blame] | 339 | paths = append(paths, input.DependencyStubDexJarsByScope.StubDexJarsForScope(apiScope)...) |
| 340 | paths = append(paths, input.AdditionalStubDexJarsByScope.StubDexJarsForScope(apiScope)...) |
| 341 | paths = append(paths, input.StubDexJarsByScope.StubDexJarsForScope(apiScope)...) |
Paul Duffin | 74431d5 | 2021-04-21 14:10:42 +0100 | [diff] [blame] | 342 | if len(paths) > 0 { |
Paul Duffin | 31fad80 | 2021-06-18 18:14:25 +0100 | [diff] [blame] | 343 | option := apiScope.hiddenAPIListOption |
| 344 | command.FlagWithInputList(option+"=", paths, ":") |
Paul Duffin | 74431d5 | 2021-04-21 14:10:42 +0100 | [diff] [blame] | 345 | } |
| 346 | } |
| 347 | |
| 348 | // Add the output path. |
| 349 | command.FlagWithOutput("--out-api-flags=", tempPath) |
| 350 | |
Paul Duffin | 2e88097 | 2021-06-23 23:29:09 +0100 | [diff] [blame] | 351 | // If there are stub flag files that have been generated by fragments on which this depends then |
| 352 | // use them to validate the stub flag file generated by the rules created by this method. |
Paul Duffin | 67b9d61 | 2021-07-21 17:38:47 +0100 | [diff] [blame] | 353 | if len(stubFlagSubsets) > 0 { |
Paul Duffin | bd88c88 | 2022-04-07 23:32:19 +0100 | [diff] [blame] | 354 | validFile := buildRuleValidateOverlappingCsvFiles(ctx, name, desc, outputPath, stubFlagSubsets, |
| 355 | HIDDENAPI_STUB_FLAGS_IMPL_FLAGS) |
Paul Duffin | 2e88097 | 2021-06-23 23:29:09 +0100 | [diff] [blame] | 356 | |
| 357 | // Add the file that indicates that the file generated by this is valid. |
| 358 | // |
| 359 | // This will cause the validation rule above to be run any time that the output of this rule |
| 360 | // changes but the validation will run in parallel with other rules that depend on this file. |
| 361 | command.Validation(validFile) |
| 362 | } |
| 363 | |
Paul Duffin | 74431d5 | 2021-04-21 14:10:42 +0100 | [diff] [blame] | 364 | commitChangeForRestat(rule, tempPath, outputPath) |
Paul Duffin | 4539a37 | 2021-06-23 23:20:43 +0100 | [diff] [blame] | 365 | |
| 366 | rule.Build(name, desc) |
Paul Duffin | 74431d5 | 2021-04-21 14:10:42 +0100 | [diff] [blame] | 367 | } |
| 368 | |
Paul Duffin | 4616977 | 2021-04-14 15:01:56 +0100 | [diff] [blame] | 369 | // HiddenAPIFlagFileProperties contains paths to the flag files that can be used to augment the |
| 370 | // information obtained from annotations within the source code in order to create the complete set |
| 371 | // 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] | 372 | // |
| 373 | // Each property contains a list of paths. With the exception of the Unsupported_packages the paths |
| 374 | // of each property reference a plain text file that contains a java signature per line. The flags |
| 375 | // for each of those signatures will be updated in a property specific way. |
| 376 | // |
| 377 | // The Unsupported_packages property contains a list of paths, each of which is a plain text file |
| 378 | // with one Java package per line. All members of all classes within that package (but not nested |
| 379 | // packages) will be updated in a property specific way. |
Paul Duffin | 4616977 | 2021-04-14 15:01:56 +0100 | [diff] [blame] | 380 | type HiddenAPIFlagFileProperties struct { |
Paul Duffin | 9b61abb | 2022-07-27 16:16:54 +0000 | [diff] [blame] | 381 | Hidden_api struct { |
| 382 | // Marks each signature in the referenced files as being unsupported. |
| 383 | Unsupported []string `android:"path"` |
Paul Duffin | c6bb7cf | 2021-04-08 17:49:27 +0100 | [diff] [blame] | 384 | |
Paul Duffin | 9b61abb | 2022-07-27 16:16:54 +0000 | [diff] [blame] | 385 | // Marks each signature in the referenced files as being unsupported because it has been |
| 386 | // removed. Any conflicts with other flags are ignored. |
| 387 | Removed []string `android:"path"` |
Paul Duffin | c6bb7cf | 2021-04-08 17:49:27 +0100 | [diff] [blame] | 388 | |
Paul Duffin | 9b61abb | 2022-07-27 16:16:54 +0000 | [diff] [blame] | 389 | // Marks each signature in the referenced files as being supported only for |
| 390 | // targetSdkVersion <= R and low priority. |
| 391 | Max_target_r_low_priority []string `android:"path"` |
Paul Duffin | c6bb7cf | 2021-04-08 17:49:27 +0100 | [diff] [blame] | 392 | |
Paul Duffin | 9b61abb | 2022-07-27 16:16:54 +0000 | [diff] [blame] | 393 | // Marks each signature in the referenced files as being supported only for |
| 394 | // targetSdkVersion <= Q. |
| 395 | Max_target_q []string `android:"path"` |
Paul Duffin | c6bb7cf | 2021-04-08 17:49:27 +0100 | [diff] [blame] | 396 | |
Paul Duffin | 9b61abb | 2022-07-27 16:16:54 +0000 | [diff] [blame] | 397 | // Marks each signature in the referenced files as being supported only for |
| 398 | // targetSdkVersion <= P. |
| 399 | Max_target_p []string `android:"path"` |
Paul Duffin | c6bb7cf | 2021-04-08 17:49:27 +0100 | [diff] [blame] | 400 | |
Paul Duffin | 9b61abb | 2022-07-27 16:16:54 +0000 | [diff] [blame] | 401 | // Marks each signature in the referenced files as being supported only for |
| 402 | // targetSdkVersion <= O |
| 403 | // and low priority. Any conflicts with other flags are ignored. |
| 404 | Max_target_o_low_priority []string `android:"path"` |
Paul Duffin | c6bb7cf | 2021-04-08 17:49:27 +0100 | [diff] [blame] | 405 | |
Paul Duffin | 9b61abb | 2022-07-27 16:16:54 +0000 | [diff] [blame] | 406 | // Marks each signature in the referenced files as being blocked. |
| 407 | Blocked []string `android:"path"` |
Paul Duffin | c6bb7cf | 2021-04-08 17:49:27 +0100 | [diff] [blame] | 408 | |
Paul Duffin | 9b61abb | 2022-07-27 16:16:54 +0000 | [diff] [blame] | 409 | // Marks each signature in every package in the referenced files as being unsupported. |
| 410 | Unsupported_packages []string `android:"path"` |
| 411 | } |
Paul Duffin | 702210b | 2021-04-08 20:12:41 +0100 | [diff] [blame] | 412 | } |
| 413 | |
Paul Duffin | e3dc660 | 2021-04-14 09:50:43 +0100 | [diff] [blame] | 414 | type hiddenAPIFlagFileCategory struct { |
Paul Duffin | 524c82c | 2021-06-09 14:39:28 +0100 | [diff] [blame] | 415 | // PropertyName is the name of the property for this category. |
| 416 | PropertyName string |
Paul Duffin | e3dc660 | 2021-04-14 09:50:43 +0100 | [diff] [blame] | 417 | |
Paul Duffin | cc17bfe | 2021-04-19 13:21:20 +0100 | [diff] [blame] | 418 | // 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] | 419 | // properties. |
Paul Duffin | cc17bfe | 2021-04-19 13:21:20 +0100 | [diff] [blame] | 420 | propertyValueReader func(properties *HiddenAPIFlagFileProperties) []string |
Paul Duffin | e3dc660 | 2021-04-14 09:50:43 +0100 | [diff] [blame] | 421 | |
| 422 | // commandMutator adds the appropriate command line options for this category to the supplied |
| 423 | // command |
| 424 | commandMutator func(command *android.RuleBuilderCommand, path android.Path) |
| 425 | } |
| 426 | |
Paul Duffin | 32cf58a | 2021-05-18 16:32:50 +0100 | [diff] [blame] | 427 | // The flag file category for removed members of the API. |
| 428 | // |
Paul Duffin | 524c82c | 2021-06-09 14:39:28 +0100 | [diff] [blame] | 429 | // This is extracted from HiddenAPIFlagFileCategories as it is needed to add the dex signatures |
Paul Duffin | 32cf58a | 2021-05-18 16:32:50 +0100 | [diff] [blame] | 430 | // list of removed API members that are generated automatically from the removed.txt files provided |
| 431 | // by API stubs. |
| 432 | var hiddenAPIRemovedFlagFileCategory = &hiddenAPIFlagFileCategory{ |
| 433 | // See HiddenAPIFlagFileProperties.Removed |
Paul Duffin | 524c82c | 2021-06-09 14:39:28 +0100 | [diff] [blame] | 434 | PropertyName: "removed", |
Paul Duffin | 32cf58a | 2021-05-18 16:32:50 +0100 | [diff] [blame] | 435 | propertyValueReader: func(properties *HiddenAPIFlagFileProperties) []string { |
Paul Duffin | 9b61abb | 2022-07-27 16:16:54 +0000 | [diff] [blame] | 436 | return properties.Hidden_api.Removed |
Paul Duffin | 32cf58a | 2021-05-18 16:32:50 +0100 | [diff] [blame] | 437 | }, |
| 438 | commandMutator: func(command *android.RuleBuilderCommand, path android.Path) { |
| 439 | command.FlagWithInput("--unsupported ", path).Flag("--ignore-conflicts ").FlagWithArg("--tag ", "removed") |
| 440 | }, |
| 441 | } |
| 442 | |
Paul Duffin | 3f1ae0b | 2022-07-27 16:27:42 +0000 | [diff] [blame] | 443 | type hiddenAPIFlagFileCategories []*hiddenAPIFlagFileCategory |
| 444 | |
| 445 | func (c hiddenAPIFlagFileCategories) byProperty(name string) *hiddenAPIFlagFileCategory { |
| 446 | for _, category := range c { |
| 447 | if category.PropertyName == name { |
| 448 | return category |
| 449 | } |
| 450 | } |
| 451 | panic(fmt.Errorf("no category exists with property name %q in %v", name, c)) |
| 452 | } |
| 453 | |
| 454 | var HiddenAPIFlagFileCategories = hiddenAPIFlagFileCategories{ |
Paul Duffin | 4616977 | 2021-04-14 15:01:56 +0100 | [diff] [blame] | 455 | // See HiddenAPIFlagFileProperties.Unsupported |
Paul Duffin | e3dc660 | 2021-04-14 09:50:43 +0100 | [diff] [blame] | 456 | { |
Paul Duffin | 524c82c | 2021-06-09 14:39:28 +0100 | [diff] [blame] | 457 | PropertyName: "unsupported", |
Paul Duffin | cc17bfe | 2021-04-19 13:21:20 +0100 | [diff] [blame] | 458 | propertyValueReader: func(properties *HiddenAPIFlagFileProperties) []string { |
Paul Duffin | 9b61abb | 2022-07-27 16:16:54 +0000 | [diff] [blame] | 459 | return properties.Hidden_api.Unsupported |
Paul Duffin | e3dc660 | 2021-04-14 09:50:43 +0100 | [diff] [blame] | 460 | }, |
| 461 | commandMutator: func(command *android.RuleBuilderCommand, path android.Path) { |
| 462 | command.FlagWithInput("--unsupported ", path) |
| 463 | }, |
| 464 | }, |
Paul Duffin | 32cf58a | 2021-05-18 16:32:50 +0100 | [diff] [blame] | 465 | hiddenAPIRemovedFlagFileCategory, |
Paul Duffin | 4616977 | 2021-04-14 15:01:56 +0100 | [diff] [blame] | 466 | // See HiddenAPIFlagFileProperties.Max_target_r_low_priority |
Paul Duffin | e3dc660 | 2021-04-14 09:50:43 +0100 | [diff] [blame] | 467 | { |
Paul Duffin | 524c82c | 2021-06-09 14:39:28 +0100 | [diff] [blame] | 468 | PropertyName: "max_target_r_low_priority", |
Paul Duffin | cc17bfe | 2021-04-19 13:21:20 +0100 | [diff] [blame] | 469 | propertyValueReader: func(properties *HiddenAPIFlagFileProperties) []string { |
Paul Duffin | 9b61abb | 2022-07-27 16:16:54 +0000 | [diff] [blame] | 470 | return properties.Hidden_api.Max_target_r_low_priority |
Paul Duffin | e3dc660 | 2021-04-14 09:50:43 +0100 | [diff] [blame] | 471 | }, |
| 472 | commandMutator: func(command *android.RuleBuilderCommand, path android.Path) { |
| 473 | command.FlagWithInput("--max-target-r ", path).FlagWithArg("--tag ", "lo-prio") |
| 474 | }, |
| 475 | }, |
Paul Duffin | 4616977 | 2021-04-14 15:01:56 +0100 | [diff] [blame] | 476 | // See HiddenAPIFlagFileProperties.Max_target_q |
Paul Duffin | e3dc660 | 2021-04-14 09:50:43 +0100 | [diff] [blame] | 477 | { |
Paul Duffin | 524c82c | 2021-06-09 14:39:28 +0100 | [diff] [blame] | 478 | PropertyName: "max_target_q", |
Paul Duffin | cc17bfe | 2021-04-19 13:21:20 +0100 | [diff] [blame] | 479 | propertyValueReader: func(properties *HiddenAPIFlagFileProperties) []string { |
Paul Duffin | 9b61abb | 2022-07-27 16:16:54 +0000 | [diff] [blame] | 480 | return properties.Hidden_api.Max_target_q |
Paul Duffin | e3dc660 | 2021-04-14 09:50:43 +0100 | [diff] [blame] | 481 | }, |
| 482 | commandMutator: func(command *android.RuleBuilderCommand, path android.Path) { |
| 483 | command.FlagWithInput("--max-target-q ", path) |
| 484 | }, |
| 485 | }, |
Paul Duffin | 4616977 | 2021-04-14 15:01:56 +0100 | [diff] [blame] | 486 | // See HiddenAPIFlagFileProperties.Max_target_p |
Paul Duffin | e3dc660 | 2021-04-14 09:50:43 +0100 | [diff] [blame] | 487 | { |
Paul Duffin | 524c82c | 2021-06-09 14:39:28 +0100 | [diff] [blame] | 488 | PropertyName: "max_target_p", |
Paul Duffin | cc17bfe | 2021-04-19 13:21:20 +0100 | [diff] [blame] | 489 | propertyValueReader: func(properties *HiddenAPIFlagFileProperties) []string { |
Paul Duffin | 9b61abb | 2022-07-27 16:16:54 +0000 | [diff] [blame] | 490 | return properties.Hidden_api.Max_target_p |
Paul Duffin | e3dc660 | 2021-04-14 09:50:43 +0100 | [diff] [blame] | 491 | }, |
| 492 | commandMutator: func(command *android.RuleBuilderCommand, path android.Path) { |
| 493 | command.FlagWithInput("--max-target-p ", path) |
| 494 | }, |
| 495 | }, |
Paul Duffin | 4616977 | 2021-04-14 15:01:56 +0100 | [diff] [blame] | 496 | // See HiddenAPIFlagFileProperties.Max_target_o_low_priority |
Paul Duffin | e3dc660 | 2021-04-14 09:50:43 +0100 | [diff] [blame] | 497 | { |
Paul Duffin | 524c82c | 2021-06-09 14:39:28 +0100 | [diff] [blame] | 498 | PropertyName: "max_target_o_low_priority", |
Paul Duffin | cc17bfe | 2021-04-19 13:21:20 +0100 | [diff] [blame] | 499 | propertyValueReader: func(properties *HiddenAPIFlagFileProperties) []string { |
Paul Duffin | 9b61abb | 2022-07-27 16:16:54 +0000 | [diff] [blame] | 500 | return properties.Hidden_api.Max_target_o_low_priority |
Paul Duffin | e3dc660 | 2021-04-14 09:50:43 +0100 | [diff] [blame] | 501 | }, |
| 502 | commandMutator: func(command *android.RuleBuilderCommand, path android.Path) { |
| 503 | command.FlagWithInput("--max-target-o ", path).Flag("--ignore-conflicts ").FlagWithArg("--tag ", "lo-prio") |
| 504 | }, |
| 505 | }, |
Paul Duffin | 4616977 | 2021-04-14 15:01:56 +0100 | [diff] [blame] | 506 | // See HiddenAPIFlagFileProperties.Blocked |
Paul Duffin | e3dc660 | 2021-04-14 09:50:43 +0100 | [diff] [blame] | 507 | { |
Paul Duffin | 524c82c | 2021-06-09 14:39:28 +0100 | [diff] [blame] | 508 | PropertyName: "blocked", |
Paul Duffin | cc17bfe | 2021-04-19 13:21:20 +0100 | [diff] [blame] | 509 | propertyValueReader: func(properties *HiddenAPIFlagFileProperties) []string { |
Paul Duffin | 9b61abb | 2022-07-27 16:16:54 +0000 | [diff] [blame] | 510 | return properties.Hidden_api.Blocked |
Paul Duffin | e3dc660 | 2021-04-14 09:50:43 +0100 | [diff] [blame] | 511 | }, |
| 512 | commandMutator: func(command *android.RuleBuilderCommand, path android.Path) { |
| 513 | command.FlagWithInput("--blocked ", path) |
| 514 | }, |
| 515 | }, |
Paul Duffin | 4616977 | 2021-04-14 15:01:56 +0100 | [diff] [blame] | 516 | // See HiddenAPIFlagFileProperties.Unsupported_packages |
Paul Duffin | e3dc660 | 2021-04-14 09:50:43 +0100 | [diff] [blame] | 517 | { |
Paul Duffin | 524c82c | 2021-06-09 14:39:28 +0100 | [diff] [blame] | 518 | PropertyName: "unsupported_packages", |
Paul Duffin | cc17bfe | 2021-04-19 13:21:20 +0100 | [diff] [blame] | 519 | propertyValueReader: func(properties *HiddenAPIFlagFileProperties) []string { |
Paul Duffin | 9b61abb | 2022-07-27 16:16:54 +0000 | [diff] [blame] | 520 | return properties.Hidden_api.Unsupported_packages |
Paul Duffin | e3dc660 | 2021-04-14 09:50:43 +0100 | [diff] [blame] | 521 | }, |
| 522 | commandMutator: func(command *android.RuleBuilderCommand, path android.Path) { |
| 523 | command.FlagWithInput("--unsupported ", path).Flag("--packages ") |
| 524 | }, |
| 525 | }, |
Paul Duffin | 702210b | 2021-04-08 20:12:41 +0100 | [diff] [blame] | 526 | } |
| 527 | |
Paul Duffin | 438eb57 | 2021-05-21 16:58:23 +0100 | [diff] [blame] | 528 | // FlagFilesByCategory maps a hiddenAPIFlagFileCategory to the paths to the files in that category. |
| 529 | type FlagFilesByCategory map[*hiddenAPIFlagFileCategory]android.Paths |
| 530 | |
Paul Duffin | 3f1ae0b | 2022-07-27 16:27:42 +0000 | [diff] [blame] | 531 | // append the supplied flags files to the corresponding category in this map. |
Paul Duffin | 438eb57 | 2021-05-21 16:58:23 +0100 | [diff] [blame] | 532 | func (s FlagFilesByCategory) append(other FlagFilesByCategory) { |
Paul Duffin | 524c82c | 2021-06-09 14:39:28 +0100 | [diff] [blame] | 533 | for _, category := range HiddenAPIFlagFileCategories { |
Paul Duffin | 438eb57 | 2021-05-21 16:58:23 +0100 | [diff] [blame] | 534 | s[category] = append(s[category], other[category]...) |
| 535 | } |
| 536 | } |
| 537 | |
Paul Duffin | 3f1ae0b | 2022-07-27 16:27:42 +0000 | [diff] [blame] | 538 | // sort the paths for each category in this map. |
| 539 | func (s FlagFilesByCategory) sort() { |
| 540 | for category, value := range s { |
| 541 | s[category] = android.SortedUniquePaths(value) |
| 542 | } |
| 543 | } |
| 544 | |
Paul Duffin | af99afa | 2021-05-21 22:18:56 +0100 | [diff] [blame] | 545 | // HiddenAPIInfo contains information provided by the hidden API processing. |
Paul Duffin | 2fef136 | 2021-04-15 13:32:00 +0100 | [diff] [blame] | 546 | // |
Paul Duffin | af99afa | 2021-05-21 22:18:56 +0100 | [diff] [blame] | 547 | // That includes paths resolved from HiddenAPIFlagFileProperties and also generated by hidden API |
| 548 | // processing. |
| 549 | type HiddenAPIInfo struct { |
Paul Duffin | 438eb57 | 2021-05-21 16:58:23 +0100 | [diff] [blame] | 550 | // FlagFilesByCategory maps from the flag file category to the paths containing information for |
| 551 | // that category. |
| 552 | FlagFilesByCategory FlagFilesByCategory |
Paul Duffin | 2fef136 | 2021-04-15 13:32:00 +0100 | [diff] [blame] | 553 | |
Paul Duffin | 280a31a | 2021-06-27 20:28:29 +0100 | [diff] [blame] | 554 | // The paths to the stub dex jars for each of the *HiddenAPIScope in hiddenAPIScopes provided by |
| 555 | // this fragment and the fragments on which this depends. |
| 556 | TransitiveStubDexJarsByScope StubDexJarsByModule |
Paul Duffin | 18cf197 | 2021-05-21 22:46:59 +0100 | [diff] [blame] | 557 | |
Paul Duffin | 1e6f5c4 | 2021-05-21 16:15:31 +0100 | [diff] [blame] | 558 | // The output from the hidden API processing needs to be made available to other modules. |
| 559 | HiddenAPIFlagOutput |
Paul Duffin | c6bb7cf | 2021-04-08 17:49:27 +0100 | [diff] [blame] | 560 | } |
Paul Duffin | 702210b | 2021-04-08 20:12:41 +0100 | [diff] [blame] | 561 | |
Paul Duffin | f1b358c | 2021-05-17 07:38:47 +0100 | [diff] [blame] | 562 | func newHiddenAPIInfo() *HiddenAPIInfo { |
| 563 | info := HiddenAPIInfo{ |
Paul Duffin | 31fad80 | 2021-06-18 18:14:25 +0100 | [diff] [blame] | 564 | FlagFilesByCategory: FlagFilesByCategory{}, |
Paul Duffin | 280a31a | 2021-06-27 20:28:29 +0100 | [diff] [blame] | 565 | TransitiveStubDexJarsByScope: StubDexJarsByModule{}, |
Paul Duffin | f1b358c | 2021-05-17 07:38:47 +0100 | [diff] [blame] | 566 | } |
| 567 | return &info |
| 568 | } |
| 569 | |
| 570 | func (i *HiddenAPIInfo) mergeFromFragmentDeps(ctx android.ModuleContext, fragments []android.Module) { |
| 571 | // Merge all the information from the fragments. The fragments form a DAG so it is possible that |
| 572 | // this will introduce duplicates so they will be resolved after processing all the fragments. |
| 573 | for _, fragment := range fragments { |
| 574 | if ctx.OtherModuleHasProvider(fragment, HiddenAPIInfoProvider) { |
| 575 | info := ctx.OtherModuleProvider(fragment, HiddenAPIInfoProvider).(HiddenAPIInfo) |
Paul Duffin | 280a31a | 2021-06-27 20:28:29 +0100 | [diff] [blame] | 576 | i.TransitiveStubDexJarsByScope.addStubDexJarsByModule(info.TransitiveStubDexJarsByScope) |
Paul Duffin | f1b358c | 2021-05-17 07:38:47 +0100 | [diff] [blame] | 577 | } |
| 578 | } |
Paul Duffin | f1b358c | 2021-05-17 07:38:47 +0100 | [diff] [blame] | 579 | } |
| 580 | |
Paul Duffin | 191be3a | 2021-08-10 16:14:16 +0100 | [diff] [blame] | 581 | // StubFlagSubset returns a SignatureCsvSubset that contains a path to a filtered-stub-flags.csv |
| 582 | // file and a path to a signature-patterns.csv file that defines a subset of the monolithic stub |
| 583 | // flags file, i.e. out/soong/hiddenapi/hiddenapi-stub-flags.txt, against which it will be compared. |
Paul Duffin | 67b9d61 | 2021-07-21 17:38:47 +0100 | [diff] [blame] | 584 | func (i *HiddenAPIInfo) StubFlagSubset() SignatureCsvSubset { |
Paul Duffin | 191be3a | 2021-08-10 16:14:16 +0100 | [diff] [blame] | 585 | return SignatureCsvSubset{i.FilteredStubFlagsPath, i.SignaturePatternsPath} |
Paul Duffin | 67b9d61 | 2021-07-21 17:38:47 +0100 | [diff] [blame] | 586 | } |
| 587 | |
Paul Duffin | 191be3a | 2021-08-10 16:14:16 +0100 | [diff] [blame] | 588 | // FlagSubset returns a SignatureCsvSubset that contains a path to a filtered-flags.csv file and a |
Paul Duffin | 67b9d61 | 2021-07-21 17:38:47 +0100 | [diff] [blame] | 589 | // path to a signature-patterns.csv file that defines a subset of the monolithic flags file, i.e. |
| 590 | // out/soong/hiddenapi/hiddenapi-flags.csv, against which it will be compared. |
| 591 | func (i *HiddenAPIInfo) FlagSubset() SignatureCsvSubset { |
Paul Duffin | 191be3a | 2021-08-10 16:14:16 +0100 | [diff] [blame] | 592 | return SignatureCsvSubset{i.FilteredFlagsPath, i.SignaturePatternsPath} |
Paul Duffin | 67b9d61 | 2021-07-21 17:38:47 +0100 | [diff] [blame] | 593 | } |
| 594 | |
Paul Duffin | af99afa | 2021-05-21 22:18:56 +0100 | [diff] [blame] | 595 | var HiddenAPIInfoProvider = blueprint.NewProvider(HiddenAPIInfo{}) |
Paul Duffin | 9b381ef | 2021-04-08 23:01:37 +0100 | [diff] [blame] | 596 | |
Paul Duffin | 280a31a | 2021-06-27 20:28:29 +0100 | [diff] [blame] | 597 | // ModuleStubDexJars contains the stub dex jars provided by a single module. |
| 598 | // |
| 599 | // It maps a *HiddenAPIScope to the path to stub dex jars appropriate for that scope. See |
| 600 | // hiddenAPIScopes for a list of the acceptable *HiddenAPIScope values. |
| 601 | type ModuleStubDexJars map[*HiddenAPIScope]android.Path |
Paul Duffin | 1352f7c | 2021-05-21 22:18:49 +0100 | [diff] [blame] | 602 | |
Paul Duffin | 280a31a | 2021-06-27 20:28:29 +0100 | [diff] [blame] | 603 | // stubDexJarForWidestAPIScope returns the stub dex jars for the widest API scope provided by this |
Paul Duffin | 1352f7c | 2021-05-21 22:18:49 +0100 | [diff] [blame] | 604 | // map. |
Paul Duffin | 280a31a | 2021-06-27 20:28:29 +0100 | [diff] [blame] | 605 | // |
| 606 | // The relative width of APIs is determined by their order in hiddenAPIScopes. |
| 607 | func (s ModuleStubDexJars) stubDexJarForWidestAPIScope() android.Path { |
Paul Duffin | 5cca7c4 | 2021-05-26 10:16:01 +0100 | [diff] [blame] | 608 | for i := len(hiddenAPIScopes) - 1; i >= 0; i-- { |
| 609 | apiScope := hiddenAPIScopes[i] |
Paul Duffin | 280a31a | 2021-06-27 20:28:29 +0100 | [diff] [blame] | 610 | if stubsForAPIScope, ok := s[apiScope]; ok { |
Paul Duffin | 5cca7c4 | 2021-05-26 10:16:01 +0100 | [diff] [blame] | 611 | return stubsForAPIScope |
| 612 | } |
| 613 | } |
| 614 | |
| 615 | return nil |
| 616 | } |
| 617 | |
Paul Duffin | 280a31a | 2021-06-27 20:28:29 +0100 | [diff] [blame] | 618 | // StubDexJarsByModule contains the stub dex jars provided by a set of modules. |
| 619 | // |
| 620 | // It maps a module name to the path to the stub dex jars provided by that module. |
| 621 | type StubDexJarsByModule map[string]ModuleStubDexJars |
| 622 | |
| 623 | // addStubDexJar adds a stub dex jar path provided by the specified module for the specified scope. |
| 624 | func (s StubDexJarsByModule) addStubDexJar(ctx android.ModuleContext, module android.Module, scope *HiddenAPIScope, stubDexJar android.Path) { |
| 625 | name := android.RemoveOptionalPrebuiltPrefix(module.Name()) |
Paul Duffin | 3f0290e | 2021-06-30 18:25:36 +0100 | [diff] [blame] | 626 | |
| 627 | // Each named module provides one dex jar for each scope. However, in some cases different API |
| 628 | // versions of a single classes are provided by separate modules. e.g. the core platform |
| 629 | // version of java.lang.Object is provided by the legacy.art.module.platform.api module but the |
| 630 | // public version is provided by the art.module.public.api module. In those cases it is necessary |
| 631 | // to treat all those modules as they were the same name, otherwise it will result in multiple |
| 632 | // definitions of a single class being passed to hidden API processing which will cause an error. |
Paul Duffin | 280a31a | 2021-06-27 20:28:29 +0100 | [diff] [blame] | 633 | if name == scope.nonUpdatablePrebuiltModule || name == scope.nonUpdatableSourceModule { |
| 634 | // Treat all *android-non-updatable* modules as if they were part of an android-non-updatable |
| 635 | // java_sdk_library. |
| 636 | // TODO(b/192067200): Remove once android-non-updatable is a java_sdk_library or equivalent. |
| 637 | name = "android-non-updatable" |
| 638 | } else if name == "legacy.art.module.platform.api" { |
| 639 | // Treat legacy.art.module.platform.api as if it was an API scope provided by the |
| 640 | // art.module.public.api java_sdk_library which will be the case once the former has been |
| 641 | // migrated to a module_lib API. |
| 642 | name = "art.module.public.api" |
| 643 | } else if name == "legacy.i18n.module.platform.api" { |
| 644 | // Treat legacy.i18n.module.platform.api as if it was an API scope provided by the |
| 645 | // i18n.module.public.api java_sdk_library which will be the case once the former has been |
| 646 | // migrated to a module_lib API. |
| 647 | name = "i18n.module.public.api" |
| 648 | } else if name == "conscrypt.module.platform.api" { |
| 649 | // Treat conscrypt.module.platform.api as if it was an API scope provided by the |
| 650 | // conscrypt.module.public.api java_sdk_library which will be the case once the former has been |
| 651 | // migrated to a module_lib API. |
| 652 | name = "conscrypt.module.public.api" |
Paul Duffin | 3f0290e | 2021-06-30 18:25:36 +0100 | [diff] [blame] | 653 | } else if d, ok := module.(SdkLibraryComponentDependency); ok { |
| 654 | sdkLibraryName := d.SdkLibraryName() |
| 655 | if sdkLibraryName != nil { |
| 656 | // The module is a component of a java_sdk_library so use the name of the java_sdk_library. |
| 657 | // e.g. if this module is `foo.system.stubs` and is part of the `foo` java_sdk_library then |
| 658 | // use `foo` as the name. |
| 659 | name = *sdkLibraryName |
| 660 | } |
Paul Duffin | 280a31a | 2021-06-27 20:28:29 +0100 | [diff] [blame] | 661 | } |
| 662 | stubDexJarsByScope := s[name] |
| 663 | if stubDexJarsByScope == nil { |
| 664 | stubDexJarsByScope = ModuleStubDexJars{} |
| 665 | s[name] = stubDexJarsByScope |
| 666 | } |
| 667 | stubDexJarsByScope[scope] = stubDexJar |
| 668 | } |
| 669 | |
| 670 | // addStubDexJarsByModule adds the stub dex jars in the supplied StubDexJarsByModule to this map. |
| 671 | func (s StubDexJarsByModule) addStubDexJarsByModule(other StubDexJarsByModule) { |
| 672 | for module, stubDexJarsByScope := range other { |
| 673 | s[module] = stubDexJarsByScope |
| 674 | } |
| 675 | } |
| 676 | |
| 677 | // StubDexJarsForWidestAPIScope returns a list of stub dex jars containing the widest API scope |
| 678 | // provided by each module. |
| 679 | // |
| 680 | // The relative width of APIs is determined by their order in hiddenAPIScopes. |
| 681 | func (s StubDexJarsByModule) StubDexJarsForWidestAPIScope() android.Paths { |
| 682 | stubDexJars := android.Paths{} |
| 683 | modules := android.SortedStringKeys(s) |
| 684 | for _, module := range modules { |
| 685 | stubDexJarsByScope := s[module] |
| 686 | |
| 687 | stubDexJars = append(stubDexJars, stubDexJarsByScope.stubDexJarForWidestAPIScope()) |
| 688 | } |
| 689 | |
| 690 | return stubDexJars |
| 691 | } |
| 692 | |
| 693 | // StubDexJarsForScope returns a list of stub dex jars containing the stub dex jars provided by each |
| 694 | // module for the specified scope. |
| 695 | // |
| 696 | // If a module does not provide a stub dex jar for the supplied scope then it does not contribute to |
| 697 | // the returned list. |
| 698 | func (s StubDexJarsByModule) StubDexJarsForScope(scope *HiddenAPIScope) android.Paths { |
| 699 | stubDexJars := android.Paths{} |
| 700 | modules := android.SortedStringKeys(s) |
| 701 | for _, module := range modules { |
| 702 | stubDexJarsByScope := s[module] |
| 703 | // Not every module will have the same set of |
| 704 | if jars, ok := stubDexJarsByScope[scope]; ok { |
| 705 | stubDexJars = append(stubDexJars, jars) |
| 706 | } |
| 707 | } |
| 708 | |
| 709 | return stubDexJars |
| 710 | } |
| 711 | |
Paul Duffin | 1e9e938 | 2022-07-27 15:55:06 +0000 | [diff] [blame] | 712 | type HiddenAPIPropertyInfo struct { |
Paul Duffin | 1352f7c | 2021-05-21 22:18:49 +0100 | [diff] [blame] | 713 | // FlagFilesByCategory contains the flag files that override the initial flags that are derived |
| 714 | // from the stub dex files. |
| 715 | FlagFilesByCategory FlagFilesByCategory |
| 716 | |
Paul Duffin | 1e9e938 | 2022-07-27 15:55:06 +0000 | [diff] [blame] | 717 | // See HiddenAPIFlagFileProperties.Package_prefixes |
| 718 | PackagePrefixes []string |
| 719 | |
| 720 | // See HiddenAPIFlagFileProperties.Single_packages |
| 721 | SinglePackages []string |
| 722 | |
| 723 | // See HiddenAPIFlagFileProperties.Split_packages |
| 724 | SplitPackages []string |
| 725 | } |
| 726 | |
Paul Duffin | 3f1ae0b | 2022-07-27 16:27:42 +0000 | [diff] [blame] | 727 | var hiddenAPIPropertyInfoProvider = blueprint.NewProvider(HiddenAPIPropertyInfo{}) |
| 728 | |
Paul Duffin | 1e9e938 | 2022-07-27 15:55:06 +0000 | [diff] [blame] | 729 | // newHiddenAPIPropertyInfo creates a new initialized HiddenAPIPropertyInfo struct. |
| 730 | func newHiddenAPIPropertyInfo() HiddenAPIPropertyInfo { |
| 731 | return HiddenAPIPropertyInfo{ |
| 732 | FlagFilesByCategory: FlagFilesByCategory{}, |
| 733 | } |
| 734 | } |
| 735 | |
| 736 | // extractFlagFilesFromProperties extracts the paths to flag files that are specified in the |
| 737 | // supplied properties and stores them in this struct. |
| 738 | func (i *HiddenAPIPropertyInfo) extractFlagFilesFromProperties(ctx android.ModuleContext, p *HiddenAPIFlagFileProperties) { |
| 739 | for _, category := range HiddenAPIFlagFileCategories { |
| 740 | paths := android.PathsForModuleSrc(ctx, category.propertyValueReader(p)) |
| 741 | i.FlagFilesByCategory[category] = paths |
| 742 | } |
| 743 | } |
| 744 | |
| 745 | // extractPackageRulesFromProperties extracts the package rules that are specified in the supplied |
| 746 | // properties and stores them in this struct. |
| 747 | func (i *HiddenAPIPropertyInfo) extractPackageRulesFromProperties(p *HiddenAPIPackageProperties) { |
| 748 | i.PackagePrefixes = p.Hidden_api.Package_prefixes |
| 749 | i.SinglePackages = p.Hidden_api.Single_packages |
| 750 | i.SplitPackages = p.Hidden_api.Split_packages |
| 751 | } |
| 752 | |
Paul Duffin | 3f1ae0b | 2022-07-27 16:27:42 +0000 | [diff] [blame] | 753 | func (i *HiddenAPIPropertyInfo) gatherPropertyInfo(ctx android.ModuleContext, contents []android.Module) { |
| 754 | for _, module := range contents { |
| 755 | if ctx.OtherModuleHasProvider(module, hiddenAPIPropertyInfoProvider) { |
| 756 | info := ctx.OtherModuleProvider(module, hiddenAPIPropertyInfoProvider).(HiddenAPIPropertyInfo) |
| 757 | i.FlagFilesByCategory.append(info.FlagFilesByCategory) |
| 758 | i.PackagePrefixes = append(i.PackagePrefixes, info.PackagePrefixes...) |
| 759 | i.SinglePackages = append(i.SinglePackages, info.SinglePackages...) |
| 760 | i.SplitPackages = append(i.SplitPackages, info.SplitPackages...) |
| 761 | } |
| 762 | } |
| 763 | |
| 764 | // Dedup and sort the information to ensure consistent builds. |
| 765 | i.FlagFilesByCategory.sort() |
| 766 | i.PackagePrefixes = android.SortedUniqueStrings(i.PackagePrefixes) |
| 767 | i.SinglePackages = android.SortedUniqueStrings(i.SinglePackages) |
| 768 | i.SplitPackages = android.SortedUniqueStrings(i.SplitPackages) |
| 769 | } |
| 770 | |
Paul Duffin | 1e9e938 | 2022-07-27 15:55:06 +0000 | [diff] [blame] | 771 | // HiddenAPIFlagInput encapsulates information obtained from a module and its dependencies that are |
| 772 | // needed for hidden API flag generation. |
| 773 | type HiddenAPIFlagInput struct { |
| 774 | HiddenAPIPropertyInfo |
| 775 | |
Paul Duffin | 31fad80 | 2021-06-18 18:14:25 +0100 | [diff] [blame] | 776 | // StubDexJarsByScope contains the stub dex jars for different *HiddenAPIScope and which determine |
Paul Duffin | 1352f7c | 2021-05-21 22:18:49 +0100 | [diff] [blame] | 777 | // the initial flags for each dex member. |
Paul Duffin | 280a31a | 2021-06-27 20:28:29 +0100 | [diff] [blame] | 778 | StubDexJarsByScope StubDexJarsByModule |
Paul Duffin | f1b358c | 2021-05-17 07:38:47 +0100 | [diff] [blame] | 779 | |
Paul Duffin | 31fad80 | 2021-06-18 18:14:25 +0100 | [diff] [blame] | 780 | // DependencyStubDexJarsByScope contains the stub dex jars provided by the fragments on which this |
| 781 | // depends. It is the result of merging HiddenAPIInfo.TransitiveStubDexJarsByScope from each |
Paul Duffin | f1b358c | 2021-05-17 07:38:47 +0100 | [diff] [blame] | 782 | // fragment on which this depends. |
Paul Duffin | 280a31a | 2021-06-27 20:28:29 +0100 | [diff] [blame] | 783 | DependencyStubDexJarsByScope StubDexJarsByModule |
Paul Duffin | 32cf58a | 2021-05-18 16:32:50 +0100 | [diff] [blame] | 784 | |
Paul Duffin | 5cca7c4 | 2021-05-26 10:16:01 +0100 | [diff] [blame] | 785 | // AdditionalStubDexJarsByScope contains stub dex jars provided by other modules in addition to |
| 786 | // the ones that are obtained from fragments on which this depends. |
| 787 | // |
| 788 | // These are kept separate from stub dex jars in HiddenAPIFlagInput.DependencyStubDexJarsByScope |
| 789 | // as there are not propagated transitively to other fragments that depend on this. |
Paul Duffin | 280a31a | 2021-06-27 20:28:29 +0100 | [diff] [blame] | 790 | AdditionalStubDexJarsByScope StubDexJarsByModule |
Paul Duffin | 5cca7c4 | 2021-05-26 10:16:01 +0100 | [diff] [blame] | 791 | |
Paul Duffin | 32cf58a | 2021-05-18 16:32:50 +0100 | [diff] [blame] | 792 | // RemovedTxtFiles is the list of removed.txt files provided by java_sdk_library modules that are |
| 793 | // specified in the bootclasspath_fragment's stub_libs and contents properties. |
| 794 | RemovedTxtFiles android.Paths |
Paul Duffin | 1352f7c | 2021-05-21 22:18:49 +0100 | [diff] [blame] | 795 | } |
| 796 | |
Paul Duffin | 1e9e938 | 2022-07-27 15:55:06 +0000 | [diff] [blame] | 797 | // newHiddenAPIFlagInput creates a new initialized HiddenAPIFlagInput struct. |
Paul Duffin | 1352f7c | 2021-05-21 22:18:49 +0100 | [diff] [blame] | 798 | func newHiddenAPIFlagInput() HiddenAPIFlagInput { |
| 799 | input := HiddenAPIFlagInput{ |
Paul Duffin | 1e9e938 | 2022-07-27 15:55:06 +0000 | [diff] [blame] | 800 | HiddenAPIPropertyInfo: newHiddenAPIPropertyInfo(), |
Paul Duffin | 280a31a | 2021-06-27 20:28:29 +0100 | [diff] [blame] | 801 | StubDexJarsByScope: StubDexJarsByModule{}, |
| 802 | DependencyStubDexJarsByScope: StubDexJarsByModule{}, |
| 803 | AdditionalStubDexJarsByScope: StubDexJarsByModule{}, |
Paul Duffin | 1352f7c | 2021-05-21 22:18:49 +0100 | [diff] [blame] | 804 | } |
| 805 | |
| 806 | return input |
| 807 | } |
| 808 | |
| 809 | // gatherStubLibInfo gathers information from the stub libs needed by hidden API processing from the |
| 810 | // dependencies added in hiddenAPIAddStubLibDependencies. |
| 811 | // |
| 812 | // That includes paths to the stub dex jars as well as paths to the *removed.txt files. |
| 813 | func (i *HiddenAPIFlagInput) gatherStubLibInfo(ctx android.ModuleContext, contents []android.Module) { |
Paul Duffin | 31fad80 | 2021-06-18 18:14:25 +0100 | [diff] [blame] | 814 | addFromModule := func(ctx android.ModuleContext, module android.Module, apiScope *HiddenAPIScope) { |
| 815 | sdkKind := apiScope.sdkKind |
| 816 | dexJar := hiddenAPIRetrieveDexJarBuildPath(ctx, module, sdkKind) |
Paul Duffin | 1352f7c | 2021-05-21 22:18:49 +0100 | [diff] [blame] | 817 | if dexJar != nil { |
Paul Duffin | 280a31a | 2021-06-27 20:28:29 +0100 | [diff] [blame] | 818 | i.StubDexJarsByScope.addStubDexJar(ctx, module, apiScope, dexJar) |
Paul Duffin | 1352f7c | 2021-05-21 22:18:49 +0100 | [diff] [blame] | 819 | } |
Paul Duffin | 32cf58a | 2021-05-18 16:32:50 +0100 | [diff] [blame] | 820 | |
| 821 | if sdkLibrary, ok := module.(SdkLibraryDependency); ok { |
Paul Duffin | 31fad80 | 2021-06-18 18:14:25 +0100 | [diff] [blame] | 822 | removedTxtFile := sdkLibrary.SdkRemovedTxtFile(ctx, sdkKind) |
Paul Duffin | 32cf58a | 2021-05-18 16:32:50 +0100 | [diff] [blame] | 823 | i.RemovedTxtFiles = append(i.RemovedTxtFiles, removedTxtFile.AsPaths()...) |
| 824 | } |
Paul Duffin | 1352f7c | 2021-05-21 22:18:49 +0100 | [diff] [blame] | 825 | } |
| 826 | |
| 827 | // If the contents includes any java_sdk_library modules then add them to the stubs. |
| 828 | for _, module := range contents { |
| 829 | if _, ok := module.(SdkLibraryDependency); ok { |
Paul Duffin | 31fad80 | 2021-06-18 18:14:25 +0100 | [diff] [blame] | 830 | // Add information for every possible API scope needed by hidden API. |
| 831 | for _, apiScope := range hiddenAPISdkLibrarySupportedScopes { |
| 832 | addFromModule(ctx, module, apiScope) |
Paul Duffin | 1352f7c | 2021-05-21 22:18:49 +0100 | [diff] [blame] | 833 | } |
| 834 | } |
| 835 | } |
| 836 | |
Paul Duffin | d061d40 | 2021-06-07 21:36:01 +0100 | [diff] [blame] | 837 | ctx.VisitDirectDeps(func(module android.Module) { |
Paul Duffin | 1352f7c | 2021-05-21 22:18:49 +0100 | [diff] [blame] | 838 | tag := ctx.OtherModuleDependencyTag(module) |
| 839 | if hiddenAPIStubsTag, ok := tag.(hiddenAPIStubsDependencyTag); ok { |
Paul Duffin | 31fad80 | 2021-06-18 18:14:25 +0100 | [diff] [blame] | 840 | apiScope := hiddenAPIStubsTag.apiScope |
Paul Duffin | 5cca7c4 | 2021-05-26 10:16:01 +0100 | [diff] [blame] | 841 | if hiddenAPIStubsTag.fromAdditionalDependency { |
| 842 | dexJar := hiddenAPIRetrieveDexJarBuildPath(ctx, module, apiScope.sdkKind) |
| 843 | if dexJar != nil { |
Paul Duffin | 280a31a | 2021-06-27 20:28:29 +0100 | [diff] [blame] | 844 | i.AdditionalStubDexJarsByScope.addStubDexJar(ctx, module, apiScope, dexJar) |
Paul Duffin | 5cca7c4 | 2021-05-26 10:16:01 +0100 | [diff] [blame] | 845 | } |
| 846 | } else { |
| 847 | addFromModule(ctx, module, apiScope) |
| 848 | } |
Paul Duffin | 1352f7c | 2021-05-21 22:18:49 +0100 | [diff] [blame] | 849 | } |
| 850 | }) |
| 851 | |
| 852 | // Normalize the paths, i.e. remove duplicates and sort. |
Paul Duffin | 32cf58a | 2021-05-18 16:32:50 +0100 | [diff] [blame] | 853 | i.RemovedTxtFiles = android.SortedUniquePaths(i.RemovedTxtFiles) |
Paul Duffin | 1352f7c | 2021-05-21 22:18:49 +0100 | [diff] [blame] | 854 | } |
| 855 | |
Paul Duffin | 280a31a | 2021-06-27 20:28:29 +0100 | [diff] [blame] | 856 | func (i *HiddenAPIFlagInput) transitiveStubDexJarsByScope() StubDexJarsByModule { |
Paul Duffin | 31fad80 | 2021-06-18 18:14:25 +0100 | [diff] [blame] | 857 | transitive := i.DependencyStubDexJarsByScope |
Paul Duffin | 280a31a | 2021-06-27 20:28:29 +0100 | [diff] [blame] | 858 | transitive.addStubDexJarsByModule(i.StubDexJarsByScope) |
Paul Duffin | f1b358c | 2021-05-17 07:38:47 +0100 | [diff] [blame] | 859 | return transitive |
| 860 | } |
| 861 | |
Paul Duffin | 1e6f5c4 | 2021-05-21 16:15:31 +0100 | [diff] [blame] | 862 | // HiddenAPIFlagOutput contains paths to output files from the hidden API flag generation for a |
| 863 | // bootclasspath_fragment module. |
| 864 | type HiddenAPIFlagOutput struct { |
Paul Duffin | 1e6f5c4 | 2021-05-21 16:15:31 +0100 | [diff] [blame] | 865 | // The path to the generated annotation-flags.csv file. |
| 866 | AnnotationFlagsPath android.Path |
| 867 | |
| 868 | // The path to the generated metadata.csv file. |
| 869 | MetadataPath android.Path |
| 870 | |
| 871 | // The path to the generated index.csv file. |
| 872 | IndexPath android.Path |
| 873 | |
Paul Duffin | 191be3a | 2021-08-10 16:14:16 +0100 | [diff] [blame] | 874 | // The path to the generated stub-flags.csv file. |
| 875 | StubFlagsPath android.Path |
| 876 | |
Paul Duffin | 1e6f5c4 | 2021-05-21 16:15:31 +0100 | [diff] [blame] | 877 | // The path to the generated all-flags.csv file. |
| 878 | AllFlagsPath android.Path |
Paul Duffin | 67b9d61 | 2021-07-21 17:38:47 +0100 | [diff] [blame] | 879 | |
| 880 | // The path to the generated signature-patterns.txt file which defines the subset of the |
| 881 | // monolithic hidden API files provided in this. |
| 882 | SignaturePatternsPath android.Path |
Paul Duffin | 191be3a | 2021-08-10 16:14:16 +0100 | [diff] [blame] | 883 | |
| 884 | // The path to the generated filtered-stub-flags.csv file. |
| 885 | FilteredStubFlagsPath android.Path |
| 886 | |
| 887 | // The path to the generated filtered-flags.csv file. |
| 888 | FilteredFlagsPath android.Path |
Paul Duffin | 1e6f5c4 | 2021-05-21 16:15:31 +0100 | [diff] [blame] | 889 | } |
| 890 | |
Paul Duffin | 5f148ca | 2021-06-02 17:24:22 +0100 | [diff] [blame] | 891 | // bootDexJarByModule is a map from base module name (without prebuilt_ prefix) to the boot dex |
| 892 | // path. |
| 893 | type bootDexJarByModule map[string]android.Path |
| 894 | |
| 895 | // addPath adds the path for a module to the map. |
| 896 | func (b bootDexJarByModule) addPath(module android.Module, path android.Path) { |
| 897 | b[android.RemoveOptionalPrebuiltPrefix(module.Name())] = path |
| 898 | } |
| 899 | |
Paul Duffin | e521881 | 2021-06-07 13:28:19 +0100 | [diff] [blame] | 900 | // bootDexJars returns the boot dex jar paths sorted by their keys. |
| 901 | func (b bootDexJarByModule) bootDexJars() android.Paths { |
| 902 | paths := android.Paths{} |
| 903 | for _, k := range android.SortedStringKeys(b) { |
| 904 | paths = append(paths, b[k]) |
| 905 | } |
| 906 | return paths |
| 907 | } |
| 908 | |
Paul Duffin | 7f87216 | 2021-06-17 19:33:24 +0100 | [diff] [blame] | 909 | // bootDexJarsWithoutCoverage returns the boot dex jar paths sorted by their keys without coverage |
| 910 | // libraries if present. |
| 911 | func (b bootDexJarByModule) bootDexJarsWithoutCoverage() android.Paths { |
| 912 | paths := android.Paths{} |
| 913 | for _, k := range android.SortedStringKeys(b) { |
| 914 | if k == "jacocoagent" { |
| 915 | continue |
| 916 | } |
| 917 | paths = append(paths, b[k]) |
| 918 | } |
| 919 | return paths |
| 920 | } |
| 921 | |
Paul Duffin | e521881 | 2021-06-07 13:28:19 +0100 | [diff] [blame] | 922 | // HiddenAPIOutput encapsulates the output from the hidden API processing. |
| 923 | type HiddenAPIOutput struct { |
| 924 | HiddenAPIFlagOutput |
| 925 | |
| 926 | // The map from base module name to the path to the encoded boot dex file. |
| 927 | EncodedBootDexFilesByModule bootDexJarByModule |
| 928 | } |
| 929 | |
Paul Duffin | dfa1083 | 2021-05-13 17:31:51 +0100 | [diff] [blame] | 930 | // pathForValidation creates a path of the same type as the supplied type but with a name of |
| 931 | // <path>.valid. |
| 932 | // |
| 933 | // e.g. If path is an OutputPath for out/soong/hiddenapi/hiddenapi-flags.csv then this will return |
| 934 | // an OutputPath for out/soong/hiddenapi/hiddenapi-flags.csv.valid |
| 935 | func pathForValidation(ctx android.PathContext, path android.WritablePath) android.WritablePath { |
| 936 | extWithoutLeadingDot := strings.TrimPrefix(path.Ext(), ".") |
| 937 | return path.ReplaceExtension(ctx, extWithoutLeadingDot+".valid") |
| 938 | } |
| 939 | |
Paul Duffin | 2fef136 | 2021-04-15 13:32:00 +0100 | [diff] [blame] | 940 | // buildRuleToGenerateHiddenApiFlags creates a rule to create the monolithic hidden API flags from |
| 941 | // the flags from all the modules, the stub flags, augmented with some additional configuration |
| 942 | // files. |
Paul Duffin | 702210b | 2021-04-08 20:12:41 +0100 | [diff] [blame] | 943 | // |
| 944 | // baseFlagsPath is the path to the flags file containing all the information from the stubs plus |
| 945 | // an entry for every single member in the dex implementation jars of the individual modules. Every |
| 946 | // signature in any of the other files MUST be included in this file. |
| 947 | // |
Paul Duffin | 537ea3d | 2021-05-14 10:38:00 +0100 | [diff] [blame] | 948 | // annotationFlags is the path to the annotation flags file generated from annotation information |
| 949 | // in each module. |
Paul Duffin | 702210b | 2021-04-08 20:12:41 +0100 | [diff] [blame] | 950 | // |
Paul Duffin | af99afa | 2021-05-21 22:18:56 +0100 | [diff] [blame] | 951 | // hiddenAPIInfo is a struct containing paths to files that augment the information provided by |
Paul Duffin | 537ea3d | 2021-05-14 10:38:00 +0100 | [diff] [blame] | 952 | // the annotationFlags. |
Paul Duffin | 32cf58a | 2021-05-18 16:32:50 +0100 | [diff] [blame] | 953 | func buildRuleToGenerateHiddenApiFlags(ctx android.BuilderContext, name, desc string, |
Paul Duffin | d061d40 | 2021-06-07 21:36:01 +0100 | [diff] [blame] | 954 | outputPath android.WritablePath, baseFlagsPath android.Path, annotationFlagPaths android.Paths, |
Paul Duffin | 67b9d61 | 2021-07-21 17:38:47 +0100 | [diff] [blame] | 955 | flagFilesByCategory FlagFilesByCategory, flagSubsets SignatureCsvSubsets, generatedRemovedDexSignatures android.OptionalPath) { |
Paul Duffin | dfa1083 | 2021-05-13 17:31:51 +0100 | [diff] [blame] | 956 | |
Paul Duffin | dfa1083 | 2021-05-13 17:31:51 +0100 | [diff] [blame] | 957 | // Create the rule that will generate the flag files. |
Paul Duffin | d3c1513 | 2021-04-21 22:12:35 +0100 | [diff] [blame] | 958 | tempPath := tempPathForRestat(ctx, outputPath) |
Paul Duffin | 702210b | 2021-04-08 20:12:41 +0100 | [diff] [blame] | 959 | rule := android.NewRuleBuilder(pctx, ctx) |
| 960 | command := rule.Command(). |
| 961 | BuiltTool("generate_hiddenapi_lists"). |
| 962 | FlagWithInput("--csv ", baseFlagsPath). |
Paul Duffin | d061d40 | 2021-06-07 21:36:01 +0100 | [diff] [blame] | 963 | Inputs(annotationFlagPaths). |
Paul Duffin | 702210b | 2021-04-08 20:12:41 +0100 | [diff] [blame] | 964 | FlagWithOutput("--output ", tempPath) |
| 965 | |
Paul Duffin | e3dc660 | 2021-04-14 09:50:43 +0100 | [diff] [blame] | 966 | // Add the options for the different categories of flag files. |
Paul Duffin | 524c82c | 2021-06-09 14:39:28 +0100 | [diff] [blame] | 967 | for _, category := range HiddenAPIFlagFileCategories { |
Paul Duffin | 438eb57 | 2021-05-21 16:58:23 +0100 | [diff] [blame] | 968 | paths := flagFilesByCategory[category] |
Paul Duffin | e3dc660 | 2021-04-14 09:50:43 +0100 | [diff] [blame] | 969 | for _, path := range paths { |
| 970 | category.commandMutator(command, path) |
| 971 | } |
Paul Duffin | 702210b | 2021-04-08 20:12:41 +0100 | [diff] [blame] | 972 | } |
| 973 | |
Paul Duffin | 32cf58a | 2021-05-18 16:32:50 +0100 | [diff] [blame] | 974 | // If available then pass the automatically generated file containing dex signatures of removed |
| 975 | // API members to the rule so they can be marked as removed. |
| 976 | if generatedRemovedDexSignatures.Valid() { |
| 977 | hiddenAPIRemovedFlagFileCategory.commandMutator(command, generatedRemovedDexSignatures.Path()) |
| 978 | } |
| 979 | |
Paul Duffin | 702210b | 2021-04-08 20:12:41 +0100 | [diff] [blame] | 980 | commitChangeForRestat(rule, tempPath, outputPath) |
| 981 | |
Paul Duffin | 2e88097 | 2021-06-23 23:29:09 +0100 | [diff] [blame] | 982 | // If there are flag files that have been generated by fragments on which this depends then use |
| 983 | // them to validate the flag file generated by the rules created by this method. |
Paul Duffin | 67b9d61 | 2021-07-21 17:38:47 +0100 | [diff] [blame] | 984 | if len(flagSubsets) > 0 { |
Paul Duffin | bd88c88 | 2022-04-07 23:32:19 +0100 | [diff] [blame] | 985 | validFile := buildRuleValidateOverlappingCsvFiles(ctx, name, desc, outputPath, flagSubsets, |
| 986 | HIDDENAPI_FLAGS_CSV_IMPL_FLAGS) |
Paul Duffin | 2e88097 | 2021-06-23 23:29:09 +0100 | [diff] [blame] | 987 | |
Paul Duffin | dfa1083 | 2021-05-13 17:31:51 +0100 | [diff] [blame] | 988 | // Add the file that indicates that the file generated by this is valid. |
| 989 | // |
| 990 | // This will cause the validation rule above to be run any time that the output of this rule |
| 991 | // changes but the validation will run in parallel with other rules that depend on this file. |
| 992 | command.Validation(validFile) |
| 993 | } |
| 994 | |
Paul Duffin | 2fef136 | 2021-04-15 13:32:00 +0100 | [diff] [blame] | 995 | rule.Build(name, desc) |
| 996 | } |
| 997 | |
Paul Duffin | 67b9d61 | 2021-07-21 17:38:47 +0100 | [diff] [blame] | 998 | // SignatureCsvSubset describes a subset of a monolithic flags file, i.e. either |
| 999 | // out/soong/hiddenapi/hiddenapi-stub-flags.txt or out/soong/hiddenapi/hiddenapi-flags.csv |
| 1000 | type SignatureCsvSubset struct { |
| 1001 | // The path to the CSV file containing hidden API flags. |
| 1002 | // |
| 1003 | // It has the dex member signature as the first column, with flags, one per column, in the |
| 1004 | // subsequent columns. |
| 1005 | CsvFile android.Path |
| 1006 | |
| 1007 | // The path to the CSV file containing the signature patterns. |
| 1008 | // |
| 1009 | // It is a single column CSV file with the column containing a signature pattern. |
| 1010 | SignaturePatternsFile android.Path |
| 1011 | } |
| 1012 | |
| 1013 | type SignatureCsvSubsets []SignatureCsvSubset |
| 1014 | |
| 1015 | func (s SignatureCsvSubsets) RelativeToTop() []string { |
| 1016 | result := []string{} |
| 1017 | for _, subset := range s { |
| 1018 | result = append(result, fmt.Sprintf("%s:%s", subset.CsvFile.RelativeToTop(), subset.SignaturePatternsFile.RelativeToTop())) |
| 1019 | } |
| 1020 | return result |
| 1021 | } |
| 1022 | |
| 1023 | // buildRuleSignaturePatternsFile creates a rule to generate a file containing the set of signature |
| 1024 | // patterns that will select a subset of the monolithic flags. |
Paul Duffin | 846beb7 | 2022-03-15 17:45:57 +0000 | [diff] [blame] | 1025 | func buildRuleSignaturePatternsFile( |
| 1026 | ctx android.ModuleContext, flagsPath android.Path, |
| 1027 | splitPackages []string, packagePrefixes []string, singlePackages []string) android.Path { |
Paul Duffin | 67b9d61 | 2021-07-21 17:38:47 +0100 | [diff] [blame] | 1028 | patternsFile := android.PathForModuleOut(ctx, "modular-hiddenapi", "signature-patterns.csv") |
| 1029 | // Create a rule to validate the output from the following rule. |
| 1030 | rule := android.NewRuleBuilder(pctx, ctx) |
Paul Duffin | 1e18e98 | 2021-08-03 15:42:27 +0100 | [diff] [blame] | 1031 | |
| 1032 | // Quote any * in the packages to avoid them being expanded by the shell. |
| 1033 | quotedSplitPackages := []string{} |
| 1034 | for _, pkg := range splitPackages { |
| 1035 | quotedSplitPackages = append(quotedSplitPackages, strings.ReplaceAll(pkg, "*", "\\*")) |
| 1036 | } |
| 1037 | |
Paul Duffin | 67b9d61 | 2021-07-21 17:38:47 +0100 | [diff] [blame] | 1038 | rule.Command(). |
| 1039 | BuiltTool("signature_patterns"). |
| 1040 | FlagWithInput("--flags ", flagsPath). |
Paul Duffin | 1e18e98 | 2021-08-03 15:42:27 +0100 | [diff] [blame] | 1041 | FlagForEachArg("--split-package ", quotedSplitPackages). |
| 1042 | FlagForEachArg("--package-prefix ", packagePrefixes). |
Paul Duffin | 846beb7 | 2022-03-15 17:45:57 +0000 | [diff] [blame] | 1043 | FlagForEachArg("--single-package ", singlePackages). |
Paul Duffin | 67b9d61 | 2021-07-21 17:38:47 +0100 | [diff] [blame] | 1044 | FlagWithOutput("--output ", patternsFile) |
| 1045 | rule.Build("hiddenAPISignaturePatterns", "hidden API signature patterns") |
| 1046 | |
| 1047 | return patternsFile |
| 1048 | } |
| 1049 | |
Paul Duffin | bd88c88 | 2022-04-07 23:32:19 +0100 | [diff] [blame] | 1050 | // buildRuleRemoveSignaturesWithImplementationFlags creates a rule that will remove signatures from |
| 1051 | // the input flags file which have only the implementation flags, i.e. are not part of an API. |
| 1052 | // |
| 1053 | // The implementationFlags specifies the set of default flags that identifies the signature of a |
| 1054 | // private, implementation only, member. Signatures that match those flags are removed from the |
| 1055 | // flags as they are implementation only. |
| 1056 | // |
| 1057 | // This is used to remove implementation only signatures from the signature files that are persisted |
| 1058 | // in the sdk snapshot as the sdk snapshots should not include implementation details. The |
| 1059 | // signatures generated by this method will be compared by the buildRuleValidateOverlappingCsvFiles |
| 1060 | // method which treats any missing signatures as if they were implementation only signatures. |
| 1061 | func buildRuleRemoveSignaturesWithImplementationFlags(ctx android.BuilderContext, |
| 1062 | name string, desc string, inputPath android.Path, filteredPath android.WritablePath, |
| 1063 | implementationFlags []string) { |
| 1064 | |
Paul Duffin | 280bae6 | 2021-07-20 18:03:53 +0100 | [diff] [blame] | 1065 | rule := android.NewRuleBuilder(pctx, ctx) |
Paul Duffin | bd88c88 | 2022-04-07 23:32:19 +0100 | [diff] [blame] | 1066 | implementationFlagPattern := "" |
| 1067 | for _, implementationFlag := range implementationFlags { |
| 1068 | implementationFlagPattern = implementationFlagPattern + "," + implementationFlag |
| 1069 | } |
Paul Duffin | 280bae6 | 2021-07-20 18:03:53 +0100 | [diff] [blame] | 1070 | rule.Command(). |
Paul Duffin | bd88c88 | 2022-04-07 23:32:19 +0100 | [diff] [blame] | 1071 | Text(`grep -vE "^[^,]+` + implementationFlagPattern + `$"`).Input(inputPath). |
| 1072 | Text(">").Output(filteredPath). |
Paul Duffin | 280bae6 | 2021-07-20 18:03:53 +0100 | [diff] [blame] | 1073 | // Grep's exit code depends on whether it finds anything. It is 0 (build success) when it finds |
| 1074 | // something and 1 (build failure) when it does not and 2 (when it encounters an error). |
| 1075 | // However, while it is unlikely it is not an error if this does not find any matches. The |
| 1076 | // following will only run if the grep does not find something and in that case it will treat |
| 1077 | // an exit code of 1 as success and anything else as failure. |
| 1078 | Text("|| test $? -eq 1") |
| 1079 | rule.Build(name, desc) |
| 1080 | } |
| 1081 | |
Paul Duffin | 2e88097 | 2021-06-23 23:29:09 +0100 | [diff] [blame] | 1082 | // buildRuleValidateOverlappingCsvFiles checks that the modular CSV files, i.e. the files generated |
| 1083 | // by the individual bootclasspath_fragment modules are subsets of the monolithic CSV file. |
Paul Duffin | bd88c88 | 2022-04-07 23:32:19 +0100 | [diff] [blame] | 1084 | // |
| 1085 | // The implementationFlags specifies the set of default flags that identifies the signature of a |
| 1086 | // private, implementation only, member. A signature which is present in a monolithic flags subset |
| 1087 | // defined by SignatureCsvSubset but which is not present in the flags file from the corresponding |
| 1088 | // module is assumed to be an implementation only member and so must have these flags. |
| 1089 | func buildRuleValidateOverlappingCsvFiles(ctx android.BuilderContext, name string, desc string, |
| 1090 | monolithicFilePath android.WritablePath, csvSubsets SignatureCsvSubsets, |
| 1091 | implementationFlags []string) android.WritablePath { |
Paul Duffin | 2e88097 | 2021-06-23 23:29:09 +0100 | [diff] [blame] | 1092 | // The file which is used to record that the flags file is valid. |
| 1093 | validFile := pathForValidation(ctx, monolithicFilePath) |
| 1094 | |
| 1095 | // Create a rule to validate the output from the following rule. |
| 1096 | rule := android.NewRuleBuilder(pctx, ctx) |
Paul Duffin | 67b9d61 | 2021-07-21 17:38:47 +0100 | [diff] [blame] | 1097 | command := rule.Command(). |
Paul Duffin | 2e88097 | 2021-06-23 23:29:09 +0100 | [diff] [blame] | 1098 | BuiltTool("verify_overlaps"). |
Paul Duffin | 0c12b78 | 2022-04-08 00:28:11 +0100 | [diff] [blame] | 1099 | FlagWithInput("--monolithic-flags ", monolithicFilePath) |
Paul Duffin | 67b9d61 | 2021-07-21 17:38:47 +0100 | [diff] [blame] | 1100 | |
| 1101 | for _, subset := range csvSubsets { |
| 1102 | command. |
Paul Duffin | 0c12b78 | 2022-04-08 00:28:11 +0100 | [diff] [blame] | 1103 | Flag("--module-flags "). |
Paul Duffin | 67b9d61 | 2021-07-21 17:38:47 +0100 | [diff] [blame] | 1104 | Textf("%s:%s", subset.CsvFile, subset.SignaturePatternsFile). |
| 1105 | Implicit(subset.CsvFile).Implicit(subset.SignaturePatternsFile) |
| 1106 | } |
| 1107 | |
Paul Duffin | bd88c88 | 2022-04-07 23:32:19 +0100 | [diff] [blame] | 1108 | for _, implementationFlag := range implementationFlags { |
| 1109 | command.FlagWithArg("--implementation-flag ", implementationFlag) |
| 1110 | } |
| 1111 | |
Paul Duffin | 67b9d61 | 2021-07-21 17:38:47 +0100 | [diff] [blame] | 1112 | // If validation passes then update the file that records that. |
| 1113 | command.Text("&& touch").Output(validFile) |
Paul Duffin | 2e88097 | 2021-06-23 23:29:09 +0100 | [diff] [blame] | 1114 | rule.Build(name+"Validation", desc+" validation") |
| 1115 | |
| 1116 | return validFile |
| 1117 | } |
| 1118 | |
Paul Duffin | af70518 | 2022-09-14 11:47:34 +0100 | [diff] [blame^] | 1119 | // hiddenAPIFlagRulesForBootclasspathFragment will generate all the flags for a fragment of the |
| 1120 | // bootclasspath. |
Paul Duffin | 2fef136 | 2021-04-15 13:32:00 +0100 | [diff] [blame] | 1121 | // |
| 1122 | // It takes: |
| 1123 | // * Map from android.SdkKind to stub dex jar paths defining the API for that sdk kind. |
| 1124 | // * The list of modules that are the contents of the fragment. |
| 1125 | // * The additional manually curated flag files to use. |
| 1126 | // |
| 1127 | // It generates: |
| 1128 | // * stub-flags.csv |
| 1129 | // * annotation-flags.csv |
| 1130 | // * metadata.csv |
| 1131 | // * index.csv |
| 1132 | // * all-flags.csv |
Paul Duffin | af70518 | 2022-09-14 11:47:34 +0100 | [diff] [blame^] | 1133 | func hiddenAPIFlagRulesForBootclasspathFragment(ctx android.ModuleContext, bootDexInfoByModule bootDexInfoByModule, contents []android.Module, input HiddenAPIFlagInput) HiddenAPIFlagOutput { |
Paul Duffin | 2fef136 | 2021-04-15 13:32:00 +0100 | [diff] [blame] | 1134 | hiddenApiSubDir := "modular-hiddenapi" |
| 1135 | |
Paul Duffin | 1352f7c | 2021-05-21 22:18:49 +0100 | [diff] [blame] | 1136 | // Generate the stub-flags.csv. |
Paul Duffin | 2fef136 | 2021-04-15 13:32:00 +0100 | [diff] [blame] | 1137 | stubFlagsCSV := android.PathForModuleOut(ctx, hiddenApiSubDir, "stub-flags.csv") |
Paul Duffin | 2e88097 | 2021-06-23 23:29:09 +0100 | [diff] [blame] | 1138 | buildRuleToGenerateHiddenAPIStubFlagsFile(ctx, "modularHiddenAPIStubFlagsFile", "modular hiddenapi stub flags", stubFlagsCSV, bootDexInfoByModule.bootDexJars(), input, nil) |
Paul Duffin | 2fef136 | 2021-04-15 13:32:00 +0100 | [diff] [blame] | 1139 | |
Paul Duffin | 537ea3d | 2021-05-14 10:38:00 +0100 | [diff] [blame] | 1140 | // Extract the classes jars from the contents. |
Paul Duffin | dd5993f | 2021-06-10 10:18:22 +0100 | [diff] [blame] | 1141 | classesJars := extractClassesJarsFromModules(contents) |
Paul Duffin | 537ea3d | 2021-05-14 10:38:00 +0100 | [diff] [blame] | 1142 | |
Paul Duffin | 2fef136 | 2021-04-15 13:32:00 +0100 | [diff] [blame] | 1143 | // Generate the set of flags from the annotations in the source code. |
| 1144 | annotationFlagsCSV := android.PathForModuleOut(ctx, hiddenApiSubDir, "annotation-flags.csv") |
Paul Duffin | 850e61f | 2021-05-14 09:58:48 +0100 | [diff] [blame] | 1145 | buildRuleToGenerateAnnotationFlags(ctx, "modular hiddenapi annotation flags", classesJars, stubFlagsCSV, annotationFlagsCSV) |
Paul Duffin | 2fef136 | 2021-04-15 13:32:00 +0100 | [diff] [blame] | 1146 | |
| 1147 | // Generate the metadata from the annotations in the source code. |
| 1148 | metadataCSV := android.PathForModuleOut(ctx, hiddenApiSubDir, "metadata.csv") |
Paul Duffin | 850e61f | 2021-05-14 09:58:48 +0100 | [diff] [blame] | 1149 | buildRuleToGenerateMetadata(ctx, "modular hiddenapi metadata", classesJars, stubFlagsCSV, metadataCSV) |
Paul Duffin | 2fef136 | 2021-04-15 13:32:00 +0100 | [diff] [blame] | 1150 | |
Paul Duffin | 537ea3d | 2021-05-14 10:38:00 +0100 | [diff] [blame] | 1151 | // Generate the index file from the CSV files in the classes jars. |
Paul Duffin | 2fef136 | 2021-04-15 13:32:00 +0100 | [diff] [blame] | 1152 | indexCSV := android.PathForModuleOut(ctx, hiddenApiSubDir, "index.csv") |
Paul Duffin | 850e61f | 2021-05-14 09:58:48 +0100 | [diff] [blame] | 1153 | buildRuleToGenerateIndex(ctx, "modular hiddenapi index", classesJars, indexCSV) |
Paul Duffin | 2fef136 | 2021-04-15 13:32:00 +0100 | [diff] [blame] | 1154 | |
Paul Duffin | af99afa | 2021-05-21 22:18:56 +0100 | [diff] [blame] | 1155 | // Removed APIs need to be marked and in order to do that the hiddenAPIInfo needs to specify files |
Paul Duffin | 2fef136 | 2021-04-15 13:32:00 +0100 | [diff] [blame] | 1156 | // containing dex signatures of all the removed APIs. In the monolithic files that is done by |
| 1157 | // manually combining all the removed.txt files for each API and then converting them to dex |
Paul Duffin | 32cf58a | 2021-05-18 16:32:50 +0100 | [diff] [blame] | 1158 | // signatures, see the combined-removed-dex module. This does that automatically by using the |
| 1159 | // *removed.txt files retrieved from the java_sdk_library modules that are specified in the |
| 1160 | // stub_libs and contents properties of a bootclasspath_fragment. |
| 1161 | removedDexSignatures := buildRuleToGenerateRemovedDexSignatures(ctx, input.RemovedTxtFiles) |
Paul Duffin | 2fef136 | 2021-04-15 13:32:00 +0100 | [diff] [blame] | 1162 | |
| 1163 | // Generate the all-flags.csv which are the flags that will, in future, be encoded into the dex |
| 1164 | // files. |
Paul Duffin | e521881 | 2021-06-07 13:28:19 +0100 | [diff] [blame] | 1165 | allFlagsCSV := android.PathForModuleOut(ctx, hiddenApiSubDir, "all-flags.csv") |
Paul Duffin | d061d40 | 2021-06-07 21:36:01 +0100 | [diff] [blame] | 1166 | buildRuleToGenerateHiddenApiFlags(ctx, "modularHiddenApiAllFlags", "modular hiddenapi all flags", allFlagsCSV, stubFlagsCSV, android.Paths{annotationFlagsCSV}, input.FlagFilesByCategory, nil, removedDexSignatures) |
Paul Duffin | e521881 | 2021-06-07 13:28:19 +0100 | [diff] [blame] | 1167 | |
Paul Duffin | 280bae6 | 2021-07-20 18:03:53 +0100 | [diff] [blame] | 1168 | // Generate the filtered-stub-flags.csv file which contains the filtered stub flags that will be |
| 1169 | // compared against the monolithic stub flags. |
| 1170 | filteredStubFlagsCSV := android.PathForModuleOut(ctx, hiddenApiSubDir, "filtered-stub-flags.csv") |
Paul Duffin | bd88c88 | 2022-04-07 23:32:19 +0100 | [diff] [blame] | 1171 | buildRuleRemoveSignaturesWithImplementationFlags(ctx, "modularHiddenApiFilteredStubFlags", |
| 1172 | "modular hiddenapi filtered stub flags", stubFlagsCSV, filteredStubFlagsCSV, |
| 1173 | HIDDENAPI_STUB_FLAGS_IMPL_FLAGS) |
Paul Duffin | 280bae6 | 2021-07-20 18:03:53 +0100 | [diff] [blame] | 1174 | |
| 1175 | // Generate the filtered-flags.csv file which contains the filtered flags that will be compared |
| 1176 | // against the monolithic flags. |
| 1177 | filteredFlagsCSV := android.PathForModuleOut(ctx, hiddenApiSubDir, "filtered-flags.csv") |
Paul Duffin | bd88c88 | 2022-04-07 23:32:19 +0100 | [diff] [blame] | 1178 | buildRuleRemoveSignaturesWithImplementationFlags(ctx, "modularHiddenApiFilteredFlags", |
| 1179 | "modular hiddenapi filtered flags", allFlagsCSV, filteredFlagsCSV, |
| 1180 | HIDDENAPI_FLAGS_CSV_IMPL_FLAGS) |
Paul Duffin | 280bae6 | 2021-07-20 18:03:53 +0100 | [diff] [blame] | 1181 | |
Paul Duffin | 2fef136 | 2021-04-15 13:32:00 +0100 | [diff] [blame] | 1182 | // Store the paths in the info for use by other modules and sdk snapshot generation. |
Paul Duffin | af70518 | 2022-09-14 11:47:34 +0100 | [diff] [blame^] | 1183 | return HiddenAPIFlagOutput{ |
| 1184 | AnnotationFlagsPath: annotationFlagsCSV, |
| 1185 | MetadataPath: metadataCSV, |
| 1186 | IndexPath: indexCSV, |
| 1187 | StubFlagsPath: stubFlagsCSV, |
| 1188 | AllFlagsPath: allFlagsCSV, |
| 1189 | FilteredStubFlagsPath: filteredStubFlagsCSV, |
| 1190 | FilteredFlagsPath: filteredFlagsCSV, |
Paul Duffin | 1e6f5c4 | 2021-05-21 16:15:31 +0100 | [diff] [blame] | 1191 | } |
Paul Duffin | af70518 | 2022-09-14 11:47:34 +0100 | [diff] [blame^] | 1192 | } |
| 1193 | |
| 1194 | // hiddenAPIEncodeRulesForBootclasspathFragment generates rules to encode hidden API flags into the |
| 1195 | // dex jars in bootDexInfoByModule. |
| 1196 | func hiddenAPIEncodeRulesForBootclasspathFragment(ctx android.ModuleContext, bootDexInfoByModule bootDexInfoByModule, allFlagsCSV android.Path) bootDexJarByModule { |
| 1197 | // Encode the flags into the boot dex files. |
| 1198 | encodedBootDexJarsByModule := bootDexJarByModule{} |
| 1199 | outputDir := android.PathForModuleOut(ctx, "hiddenapi-modular/encoded").OutputPath |
| 1200 | for _, name := range android.SortedStringKeys(bootDexInfoByModule) { |
| 1201 | bootDexInfo := bootDexInfoByModule[name] |
| 1202 | unencodedDex := bootDexInfo.path |
| 1203 | encodedDex := hiddenAPIEncodeDex(ctx, unencodedDex, allFlagsCSV, bootDexInfo.uncompressDex, bootDexInfo.minSdkVersion, outputDir) |
| 1204 | encodedBootDexJarsByModule[name] = encodedDex |
| 1205 | } |
| 1206 | return encodedBootDexJarsByModule |
Paul Duffin | 702210b | 2021-04-08 20:12:41 +0100 | [diff] [blame] | 1207 | } |
Paul Duffin | 537ea3d | 2021-05-14 10:38:00 +0100 | [diff] [blame] | 1208 | |
Paul Duffin | 32cf58a | 2021-05-18 16:32:50 +0100 | [diff] [blame] | 1209 | func buildRuleToGenerateRemovedDexSignatures(ctx android.ModuleContext, removedTxtFiles android.Paths) android.OptionalPath { |
| 1210 | if len(removedTxtFiles) == 0 { |
| 1211 | return android.OptionalPath{} |
| 1212 | } |
| 1213 | |
| 1214 | output := android.PathForModuleOut(ctx, "modular-hiddenapi/removed-dex-signatures.txt") |
| 1215 | |
| 1216 | rule := android.NewRuleBuilder(pctx, ctx) |
| 1217 | rule.Command(). |
| 1218 | BuiltTool("metalava"). |
| 1219 | Flag("--no-banner"). |
| 1220 | Inputs(removedTxtFiles). |
| 1221 | FlagWithOutput("--dex-api ", output) |
| 1222 | rule.Build("modular-hiddenapi-removed-dex-signatures", "modular hiddenapi removed dex signatures") |
| 1223 | return android.OptionalPathForPath(output) |
| 1224 | } |
| 1225 | |
Paul Duffin | dd5993f | 2021-06-10 10:18:22 +0100 | [diff] [blame] | 1226 | // extractBootDexJarsFromModules extracts the boot dex jars from the supplied modules. |
Paul Duffin | e521881 | 2021-06-07 13:28:19 +0100 | [diff] [blame] | 1227 | func extractBootDexJarsFromModules(ctx android.ModuleContext, contents []android.Module) bootDexJarByModule { |
| 1228 | bootDexJars := bootDexJarByModule{} |
Paul Duffin | 537ea3d | 2021-05-14 10:38:00 +0100 | [diff] [blame] | 1229 | for _, module := range contents { |
Paul Duffin | dd5993f | 2021-06-10 10:18:22 +0100 | [diff] [blame] | 1230 | hiddenAPIModule := hiddenAPIModuleFromModule(ctx, module) |
| 1231 | if hiddenAPIModule == nil { |
| 1232 | continue |
| 1233 | } |
Paul Duffin | e521881 | 2021-06-07 13:28:19 +0100 | [diff] [blame] | 1234 | bootDexJar := retrieveBootDexJarFromHiddenAPIModule(ctx, hiddenAPIModule) |
| 1235 | bootDexJars.addPath(module, bootDexJar) |
Paul Duffin | 537ea3d | 2021-05-14 10:38:00 +0100 | [diff] [blame] | 1236 | } |
| 1237 | return bootDexJars |
| 1238 | } |
| 1239 | |
Paul Duffin | dd5993f | 2021-06-10 10:18:22 +0100 | [diff] [blame] | 1240 | func hiddenAPIModuleFromModule(ctx android.BaseModuleContext, module android.Module) hiddenAPIModule { |
| 1241 | if hiddenAPIModule, ok := module.(hiddenAPIModule); ok { |
| 1242 | return hiddenAPIModule |
| 1243 | } else if _, ok := module.(*DexImport); ok { |
| 1244 | // Ignore this for the purposes of hidden API processing |
| 1245 | } else { |
| 1246 | ctx.ModuleErrorf("module %s does not implement hiddenAPIModule", module) |
| 1247 | } |
| 1248 | |
| 1249 | return nil |
| 1250 | } |
| 1251 | |
Paul Duffin | e521881 | 2021-06-07 13:28:19 +0100 | [diff] [blame] | 1252 | // bootDexInfo encapsulates both the path and uncompressDex status retrieved from a hiddenAPIModule. |
| 1253 | type bootDexInfo struct { |
| 1254 | // The path to the dex jar that has not had hidden API flags encoded into it. |
| 1255 | path android.Path |
| 1256 | |
| 1257 | // Indicates whether the dex jar needs uncompressing before encoding. |
| 1258 | uncompressDex bool |
Paul Duffin | 09817d6 | 2022-04-28 17:45:11 +0100 | [diff] [blame] | 1259 | |
| 1260 | // The minimum sdk version that the dex jar will be used on. |
| 1261 | minSdkVersion android.SdkSpec |
Paul Duffin | e521881 | 2021-06-07 13:28:19 +0100 | [diff] [blame] | 1262 | } |
| 1263 | |
| 1264 | // bootDexInfoByModule is a map from module name (as returned by module.Name()) to the boot dex |
| 1265 | // path (as returned by hiddenAPIModule.bootDexJar()) and the uncompressDex flag. |
| 1266 | type bootDexInfoByModule map[string]bootDexInfo |
| 1267 | |
| 1268 | // bootDexJars returns the boot dex jar paths sorted by their keys. |
| 1269 | func (b bootDexInfoByModule) bootDexJars() android.Paths { |
| 1270 | paths := android.Paths{} |
| 1271 | for _, m := range android.SortedStringKeys(b) { |
| 1272 | paths = append(paths, b[m].path) |
| 1273 | } |
| 1274 | return paths |
| 1275 | } |
| 1276 | |
| 1277 | // extractBootDexInfoFromModules extracts the boot dex jar and uncompress dex state from |
| 1278 | // each of the supplied modules which must implement hiddenAPIModule. |
| 1279 | func extractBootDexInfoFromModules(ctx android.ModuleContext, contents []android.Module) bootDexInfoByModule { |
| 1280 | bootDexJarsByModule := bootDexInfoByModule{} |
| 1281 | for _, module := range contents { |
| 1282 | hiddenAPIModule := module.(hiddenAPIModule) |
| 1283 | bootDexJar := retrieveBootDexJarFromHiddenAPIModule(ctx, hiddenAPIModule) |
| 1284 | bootDexJarsByModule[module.Name()] = bootDexInfo{ |
| 1285 | path: bootDexJar, |
| 1286 | uncompressDex: *hiddenAPIModule.uncompressDex(), |
Paul Duffin | 09817d6 | 2022-04-28 17:45:11 +0100 | [diff] [blame] | 1287 | minSdkVersion: hiddenAPIModule.MinSdkVersion(ctx), |
Paul Duffin | e521881 | 2021-06-07 13:28:19 +0100 | [diff] [blame] | 1288 | } |
| 1289 | } |
| 1290 | |
| 1291 | return bootDexJarsByModule |
| 1292 | } |
| 1293 | |
| 1294 | // retrieveBootDexJarFromHiddenAPIModule retrieves the boot dex jar from the hiddenAPIModule. |
| 1295 | // |
Martin Stjernholm | 8be1e6d | 2021-09-15 03:34:04 +0100 | [diff] [blame] | 1296 | // If the module does not provide a boot dex jar, i.e. the returned boot dex jar is unset or |
| 1297 | // invalid, then create a fake path and either report an error immediately or defer reporting of the |
| 1298 | // error until the path is actually used. |
Paul Duffin | e521881 | 2021-06-07 13:28:19 +0100 | [diff] [blame] | 1299 | func retrieveBootDexJarFromHiddenAPIModule(ctx android.ModuleContext, module hiddenAPIModule) android.Path { |
| 1300 | bootDexJar := module.bootDexJar() |
Martin Stjernholm | 8be1e6d | 2021-09-15 03:34:04 +0100 | [diff] [blame] | 1301 | if !bootDexJar.Valid() { |
Paul Duffin | e521881 | 2021-06-07 13:28:19 +0100 | [diff] [blame] | 1302 | fake := android.PathForModuleOut(ctx, fmt.Sprintf("fake/boot-dex/%s.jar", module.Name())) |
Martin Stjernholm | 8be1e6d | 2021-09-15 03:34:04 +0100 | [diff] [blame] | 1303 | handleMissingDexBootFile(ctx, module, fake, bootDexJar.InvalidReason()) |
| 1304 | return fake |
Paul Duffin | e521881 | 2021-06-07 13:28:19 +0100 | [diff] [blame] | 1305 | } |
Martin Stjernholm | 8be1e6d | 2021-09-15 03:34:04 +0100 | [diff] [blame] | 1306 | return bootDexJar.Path() |
Paul Duffin | e521881 | 2021-06-07 13:28:19 +0100 | [diff] [blame] | 1307 | } |
| 1308 | |
Paul Duffin | dd5993f | 2021-06-10 10:18:22 +0100 | [diff] [blame] | 1309 | // extractClassesJarsFromModules extracts the class jars from the supplied modules. |
| 1310 | func extractClassesJarsFromModules(contents []android.Module) android.Paths { |
Paul Duffin | 537ea3d | 2021-05-14 10:38:00 +0100 | [diff] [blame] | 1311 | classesJars := android.Paths{} |
| 1312 | for _, module := range contents { |
Paul Duffin | dd5993f | 2021-06-10 10:18:22 +0100 | [diff] [blame] | 1313 | classesJars = append(classesJars, retrieveClassesJarsFromModule(module)...) |
Paul Duffin | 537ea3d | 2021-05-14 10:38:00 +0100 | [diff] [blame] | 1314 | } |
| 1315 | return classesJars |
| 1316 | } |
Paul Duffin | 5f148ca | 2021-06-02 17:24:22 +0100 | [diff] [blame] | 1317 | |
Paul Duffin | dd5993f | 2021-06-10 10:18:22 +0100 | [diff] [blame] | 1318 | // retrieveClassesJarsFromModule retrieves the classes jars from the supplied module. |
| 1319 | func retrieveClassesJarsFromModule(module android.Module) android.Paths { |
| 1320 | if hiddenAPIModule, ok := module.(hiddenAPIModule); ok { |
| 1321 | return hiddenAPIModule.classesJars() |
| 1322 | } |
| 1323 | |
| 1324 | return nil |
| 1325 | } |
| 1326 | |
Paul Duffin | 5f148ca | 2021-06-02 17:24:22 +0100 | [diff] [blame] | 1327 | // deferReportingMissingBootDexJar returns true if a missing boot dex jar should not be reported by |
| 1328 | // Soong but should instead only be reported in ninja if the file is actually built. |
| 1329 | func deferReportingMissingBootDexJar(ctx android.ModuleContext, module android.Module) bool { |
Paul Duffin | e521881 | 2021-06-07 13:28:19 +0100 | [diff] [blame] | 1330 | // Any missing dependency should be allowed. |
| 1331 | if ctx.Config().AllowMissingDependencies() { |
| 1332 | return true |
| 1333 | } |
| 1334 | |
Paul Duffin | ef083c9 | 2021-06-29 13:36:34 +0100 | [diff] [blame] | 1335 | // A bootclasspath module that is part of a versioned sdk never provides a boot dex jar as there |
| 1336 | // is no equivalently versioned prebuilt APEX file from which it can be obtained. However, |
| 1337 | // versioned bootclasspath modules are processed by Soong so in order to avoid them causing build |
| 1338 | // failures missing boot dex jars need to be deferred. |
| 1339 | if android.IsModuleInVersionedSdk(ctx.Module()) { |
| 1340 | return true |
| 1341 | } |
| 1342 | |
Paul Duffin | 5f148ca | 2021-06-02 17:24:22 +0100 | [diff] [blame] | 1343 | // This is called for both platform_bootclasspath and bootclasspath_fragment modules. |
| 1344 | // |
| 1345 | // A bootclasspath_fragment module should only use the APEX variant of source or prebuilt modules. |
| 1346 | // Ideally, a bootclasspath_fragment module should never have a platform variant created for it |
| 1347 | // but unfortunately, due to b/187910671 it does. |
| 1348 | // |
| 1349 | // That causes issues when obtaining a boot dex jar for a prebuilt module as a prebuilt module |
| 1350 | // used by a bootclasspath_fragment can only provide a boot dex jar when it is part of APEX, i.e. |
| 1351 | // has an APEX variant not a platform variant. |
| 1352 | // |
| 1353 | // There are some other situations when a prebuilt module used by a bootclasspath_fragment cannot |
| 1354 | // provide a boot dex jar: |
| 1355 | // 1. If the bootclasspath_fragment is not exported by the prebuilt_apex/apex_set module then it |
| 1356 | // does not have an APEX variant and only has a platform variant and neither do its content |
| 1357 | // modules. |
| 1358 | // 2. Some build configurations, e.g. setting TARGET_BUILD_USE_PREBUILT_SDKS causes all |
| 1359 | // java_sdk_library_import modules to be treated as preferred and as many of them are not part |
| 1360 | // of an apex they cannot provide a boot dex jar. |
| 1361 | // |
| 1362 | // The first case causes problems when the affected prebuilt modules are preferred but that is an |
| 1363 | // invalid configuration and it is ok for it to fail as the work to enable that is not yet |
| 1364 | // complete. The second case is used for building targets that do not use boot dex jars and so |
| 1365 | // deferring error reporting to ninja is fine as the affected ninja targets should never be built. |
| 1366 | // That is handled above. |
| 1367 | // |
| 1368 | // A platform_bootclasspath module can use libraries from both platform and APEX variants. Unlike |
| 1369 | // the bootclasspath_fragment it supports dex_import modules which provides the dex file. So, it |
| 1370 | // can obtain a boot dex jar from a prebuilt that is not part of an APEX. However, it is assumed |
| 1371 | // that if the library can be part of an APEX then it is the APEX variant that is used. |
| 1372 | // |
| 1373 | // This check handles the slightly different requirements of the bootclasspath_fragment and |
| 1374 | // platform_bootclasspath modules by only deferring error reporting for the platform variant of |
| 1375 | // a prebuilt modules that has other variants which are part of an APEX. |
| 1376 | // |
| 1377 | // TODO(b/187910671): Remove this once platform variants are no longer created unnecessarily. |
| 1378 | if android.IsModulePrebuilt(module) { |
Paul Duffin | ef083c9 | 2021-06-29 13:36:34 +0100 | [diff] [blame] | 1379 | // An inactive source module can still contribute to the APEX but an inactive prebuilt module |
| 1380 | // should not contribute to anything. So, rather than have a missing dex jar cause a Soong |
| 1381 | // failure defer the error reporting to Ninja. Unless the prebuilt build target is explicitly |
| 1382 | // built Ninja should never use the dex jar file. |
| 1383 | if !isActiveModule(module) { |
| 1384 | return true |
| 1385 | } |
| 1386 | |
Paul Duffin | 5f148ca | 2021-06-02 17:24:22 +0100 | [diff] [blame] | 1387 | if am, ok := module.(android.ApexModule); ok && am.InAnyApex() { |
| 1388 | apexInfo := ctx.OtherModuleProvider(module, android.ApexInfoProvider).(android.ApexInfo) |
| 1389 | if apexInfo.IsForPlatform() { |
| 1390 | return true |
| 1391 | } |
| 1392 | } |
| 1393 | } |
| 1394 | |
Paul Duffin | 5f148ca | 2021-06-02 17:24:22 +0100 | [diff] [blame] | 1395 | return false |
| 1396 | } |
| 1397 | |
| 1398 | // handleMissingDexBootFile will either log a warning or create an error rule to create the fake |
| 1399 | // file depending on the value returned from deferReportingMissingBootDexJar. |
Martin Stjernholm | 8be1e6d | 2021-09-15 03:34:04 +0100 | [diff] [blame] | 1400 | func handleMissingDexBootFile(ctx android.ModuleContext, module android.Module, fake android.WritablePath, reason string) { |
Paul Duffin | 5f148ca | 2021-06-02 17:24:22 +0100 | [diff] [blame] | 1401 | if deferReportingMissingBootDexJar(ctx, module) { |
| 1402 | // Create an error rule that pretends to create the output file but will actually fail if it |
| 1403 | // is run. |
| 1404 | ctx.Build(pctx, android.BuildParams{ |
| 1405 | Rule: android.ErrorRule, |
| 1406 | Output: fake, |
| 1407 | Args: map[string]string{ |
Martin Stjernholm | 8be1e6d | 2021-09-15 03:34:04 +0100 | [diff] [blame] | 1408 | "error": fmt.Sprintf("missing boot dex jar dependency for %s: %s", module, reason), |
Paul Duffin | 5f148ca | 2021-06-02 17:24:22 +0100 | [diff] [blame] | 1409 | }, |
| 1410 | }) |
| 1411 | } else { |
Martin Stjernholm | 8be1e6d | 2021-09-15 03:34:04 +0100 | [diff] [blame] | 1412 | ctx.ModuleErrorf("module %s does not provide a dex jar: %s", module, reason) |
Paul Duffin | 5f148ca | 2021-06-02 17:24:22 +0100 | [diff] [blame] | 1413 | } |
| 1414 | } |
| 1415 | |
| 1416 | // retrieveEncodedBootDexJarFromModule returns a path to the boot dex jar from the supplied module's |
| 1417 | // DexJarBuildPath() method. |
| 1418 | // |
| 1419 | // The returned path will usually be to a dex jar file that has been encoded with hidden API flags. |
| 1420 | // However, under certain conditions, e.g. errors, or special build configurations it will return |
| 1421 | // a path to a fake file. |
| 1422 | func retrieveEncodedBootDexJarFromModule(ctx android.ModuleContext, module android.Module) android.Path { |
Martin Stjernholm | 8be1e6d | 2021-09-15 03:34:04 +0100 | [diff] [blame] | 1423 | bootDexJar := module.(interface{ DexJarBuildPath() OptionalDexJarPath }).DexJarBuildPath() |
| 1424 | if !bootDexJar.Valid() { |
Paul Duffin | 5f148ca | 2021-06-02 17:24:22 +0100 | [diff] [blame] | 1425 | fake := android.PathForModuleOut(ctx, fmt.Sprintf("fake/encoded-dex/%s.jar", module.Name())) |
Martin Stjernholm | 8be1e6d | 2021-09-15 03:34:04 +0100 | [diff] [blame] | 1426 | handleMissingDexBootFile(ctx, module, fake, bootDexJar.InvalidReason()) |
| 1427 | return fake |
Paul Duffin | 5f148ca | 2021-06-02 17:24:22 +0100 | [diff] [blame] | 1428 | } |
Martin Stjernholm | 8be1e6d | 2021-09-15 03:34:04 +0100 | [diff] [blame] | 1429 | return bootDexJar.Path() |
Paul Duffin | 5f148ca | 2021-06-02 17:24:22 +0100 | [diff] [blame] | 1430 | } |
| 1431 | |
| 1432 | // extractEncodedDexJarsFromModules extracts the encoded dex jars from the supplied modules. |
| 1433 | func extractEncodedDexJarsFromModules(ctx android.ModuleContext, contents []android.Module) bootDexJarByModule { |
| 1434 | encodedDexJarsByModuleName := bootDexJarByModule{} |
| 1435 | for _, module := range contents { |
| 1436 | path := retrieveEncodedBootDexJarFromModule(ctx, module) |
| 1437 | encodedDexJarsByModuleName.addPath(module, path) |
| 1438 | } |
| 1439 | return encodedDexJarsByModuleName |
| 1440 | } |