| Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1 | // Copyright 2018 Google Inc. All rights reserved. | 
|  | 2 | // | 
|  | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); | 
|  | 4 | // you may not use this file except in compliance with the License. | 
|  | 5 | // You may obtain a copy of the License at | 
|  | 6 | // | 
|  | 7 | //     http://www.apache.org/licenses/LICENSE-2.0 | 
|  | 8 | // | 
|  | 9 | // Unless required by applicable law or agreed to in writing, software | 
|  | 10 | // distributed under the License is distributed on an "AS IS" BASIS, | 
|  | 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
|  | 12 | // See the License for the specific language governing permissions and | 
|  | 13 | // limitations under the License. | 
|  | 14 |  | 
|  | 15 | package java | 
|  | 16 |  | 
|  | 17 | import ( | 
| Jihoon Kang | ee11328 | 2024-01-23 00:16:41 +0000 | [diff] [blame] | 18 | "errors" | 
| Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 19 | "fmt" | 
|  | 20 | "path" | 
| Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 21 | "path/filepath" | 
| Paul Duffin | 46a26a8 | 2020-04-07 19:27:04 +0100 | [diff] [blame] | 22 | "reflect" | 
| Paul Duffin | 46dc45a | 2020-05-14 15:39:10 +0100 | [diff] [blame] | 23 | "regexp" | 
| Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 24 | "sort" | 
| Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 25 | "strings" | 
| Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 26 | "sync" | 
| Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 27 |  | 
| Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 28 | "github.com/google/blueprint" | 
| Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 29 | "github.com/google/blueprint/proptools" | 
| Paul Duffin | 46a26a8 | 2020-04-07 19:27:04 +0100 | [diff] [blame] | 30 |  | 
|  | 31 | "android/soong/android" | 
| Ulya Trafimovich | dbf3166 | 2020-12-17 12:07:54 +0000 | [diff] [blame] | 32 | "android/soong/dexpreopt" | 
| ThiƩbaud Weksteen | 00e8b31 | 2024-03-18 14:06:00 +1100 | [diff] [blame] | 33 | "android/soong/etc" | 
| Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 34 | ) | 
|  | 35 |  | 
| Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 36 | const ( | 
| Pedro Loureiro | 9956e5e | 2021-09-07 17:21:59 +0000 | [diff] [blame] | 37 | sdkXmlFileSuffix = ".xml" | 
| Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 38 | ) | 
|  | 39 |  | 
| Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 40 | // A tag to associated a dependency with a specific api scope. | 
|  | 41 | type scopeDependencyTag struct { | 
|  | 42 | blueprint.BaseDependencyTag | 
|  | 43 | name     string | 
|  | 44 | apiScope *apiScope | 
| Paul Duffin | c878250 | 2020-04-29 20:45:27 +0100 | [diff] [blame] | 45 |  | 
|  | 46 | // Function for extracting appropriate path information from the dependency. | 
| Colin Cross | dcf71b2 | 2021-02-01 13:59:03 -0800 | [diff] [blame] | 47 | depInfoExtractor func(paths *scopePaths, ctx android.ModuleContext, dep android.Module) error | 
| Paul Duffin | c878250 | 2020-04-29 20:45:27 +0100 | [diff] [blame] | 48 | } | 
|  | 49 |  | 
|  | 50 | // Extract tag specific information from the dependency. | 
|  | 51 | func (tag scopeDependencyTag) extractDepInfo(ctx android.ModuleContext, dep android.Module, paths *scopePaths) { | 
| Colin Cross | dcf71b2 | 2021-02-01 13:59:03 -0800 | [diff] [blame] | 52 | err := tag.depInfoExtractor(paths, ctx, dep) | 
| Paul Duffin | c878250 | 2020-04-29 20:45:27 +0100 | [diff] [blame] | 53 | if err != nil { | 
|  | 54 | ctx.ModuleErrorf("has an invalid {scopeDependencyTag: %s} dependency on module %s: %s", tag.name, ctx.OtherModuleName(dep), err.Error()) | 
|  | 55 | } | 
| Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 56 | } | 
|  | 57 |  | 
| Paul Duffin | 80342d7 | 2020-06-26 22:08:43 +0100 | [diff] [blame] | 58 | var _ android.ReplaceSourceWithPrebuilt = (*scopeDependencyTag)(nil) | 
|  | 59 |  | 
|  | 60 | func (tag scopeDependencyTag) ReplaceSourceWithPrebuilt() bool { | 
|  | 61 | return false | 
|  | 62 | } | 
|  | 63 |  | 
| Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 64 | // Provides information about an api scope, e.g. public, system, test. | 
|  | 65 | type apiScope struct { | 
|  | 66 | // The name of the api scope, e.g. public, system, test | 
|  | 67 | name string | 
|  | 68 |  | 
| Paul Duffin | 97b53b8 | 2020-05-05 14:40:52 +0100 | [diff] [blame] | 69 | // The api scope that this scope extends. | 
| Paul Duffin | d0b9fca | 2022-09-30 18:11:41 +0100 | [diff] [blame] | 70 | // | 
|  | 71 | // This organizes the scopes into an extension hierarchy. | 
|  | 72 | // | 
|  | 73 | // If set this means that the API provided by this scope includes the API provided by the scope | 
|  | 74 | // set in this field. | 
| Paul Duffin | 97b53b8 | 2020-05-05 14:40:52 +0100 | [diff] [blame] | 75 | extends *apiScope | 
|  | 76 |  | 
| Paul Duffin | d0b9fca | 2022-09-30 18:11:41 +0100 | [diff] [blame] | 77 | // The next api scope that a library that uses this scope can access. | 
|  | 78 | // | 
|  | 79 | // This organizes the scopes into an access hierarchy. | 
|  | 80 | // | 
|  | 81 | // If set this means that a library that can access this API can also access the API provided by | 
|  | 82 | // the scope set in this field. | 
|  | 83 | // | 
|  | 84 | // A module that sets sdk_version: "<scope>_current" should have access to the <scope> API of | 
|  | 85 | // every java_sdk_library that it depends on. If the library does not provide an API for <scope> | 
|  | 86 | // then it will traverse up this access hierarchy to find an API that it does provide. | 
|  | 87 | // | 
|  | 88 | // If this is not set then it defaults to the scope set in extends. | 
|  | 89 | canAccess *apiScope | 
|  | 90 |  | 
| Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 91 | // The legacy enabled status for a specific scope can be dependent on other | 
|  | 92 | // properties that have been specified on the library so it is provided by | 
|  | 93 | // a function that can determine the status by examining those properties. | 
|  | 94 | legacyEnabledStatus func(module *SdkLibrary) bool | 
|  | 95 |  | 
|  | 96 | // The default enabled status for non-legacy behavior, which is triggered by | 
|  | 97 | // explicitly enabling at least one api scope. | 
|  | 98 | defaultEnabledStatus bool | 
|  | 99 |  | 
|  | 100 | // Gets a pointer to the scope specific properties. | 
|  | 101 | scopeSpecificProperties func(module *SdkLibrary) *ApiScopeProperties | 
|  | 102 |  | 
| Paul Duffin | 46a26a8 | 2020-04-07 19:27:04 +0100 | [diff] [blame] | 103 | // The name of the field in the dynamically created structure. | 
|  | 104 | fieldName string | 
|  | 105 |  | 
| Paul Duffin | 6b836ba | 2020-05-13 19:19:49 +0100 | [diff] [blame] | 106 | // The name of the property in the java_sdk_library_import | 
|  | 107 | propertyName string | 
|  | 108 |  | 
| Jihoon Kang | b743155 | 2024-01-22 19:40:08 +0000 | [diff] [blame] | 109 | // The tag to use to depend on the prebuilt stubs library module | 
|  | 110 | prebuiltStubsTag scopeDependencyTag | 
| Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 111 |  | 
| Jihoon Kang | bd09345 | 2023-12-26 19:08:01 +0000 | [diff] [blame] | 112 | // The tag to use to depend on the everything stubs library module. | 
|  | 113 | everythingStubsTag scopeDependencyTag | 
|  | 114 |  | 
|  | 115 | // The tag to use to depend on the exportable stubs library module. | 
|  | 116 | exportableStubsTag scopeDependencyTag | 
|  | 117 |  | 
| Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 118 | // The tag to use to depend on the stubs source module (if separate from the API module). | 
|  | 119 | stubsSourceTag scopeDependencyTag | 
|  | 120 |  | 
|  | 121 | // The tag to use to depend on the API file generating module (if separate from the stubs source module). | 
|  | 122 | apiFileTag scopeDependencyTag | 
|  | 123 |  | 
| Paul Duffin | c878250 | 2020-04-29 20:45:27 +0100 | [diff] [blame] | 124 | // The tag to use to depend on the stubs source and API module. | 
|  | 125 | stubsSourceAndApiTag scopeDependencyTag | 
| Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 126 |  | 
| Paul Duffin | 958806b | 2022-05-16 13:10:47 +0000 | [diff] [blame] | 127 | // The tag to use to depend on the module that provides the latest version of the API .txt file. | 
|  | 128 | latestApiModuleTag scopeDependencyTag | 
|  | 129 |  | 
|  | 130 | // The tag to use to depend on the module that provides the latest version of the API removed.txt | 
|  | 131 | // file. | 
|  | 132 | latestRemovedApiModuleTag scopeDependencyTag | 
|  | 133 |  | 
| Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 134 | // The scope specific prefix to add to the api file base of "current.txt" or "removed.txt". | 
|  | 135 | apiFilePrefix string | 
|  | 136 |  | 
| Paul Duffin | d0b9fca | 2022-09-30 18:11:41 +0100 | [diff] [blame] | 137 | // The scope specific suffix to add to the sdk library module name to construct a scope specific | 
| Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 138 | // module name. | 
|  | 139 | moduleSuffix string | 
|  | 140 |  | 
| Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 141 | // SDK version that the stubs library is built against. Note that this is always | 
|  | 142 | // *current. Older stubs library built with a numbered SDK version is created from | 
|  | 143 | // the prebuilt jar. | 
|  | 144 | sdkVersion string | 
| Paul Duffin | 1fb487d | 2020-04-07 18:50:10 +0100 | [diff] [blame] | 145 |  | 
| Paul Duffin | 15f34ef | 2020-07-20 18:04:44 +0100 | [diff] [blame] | 146 | // The annotation that identifies this API level, empty for the public API scope. | 
|  | 147 | annotation string | 
|  | 148 |  | 
| Paul Duffin | 1fb487d | 2020-04-07 18:50:10 +0100 | [diff] [blame] | 149 | // Extra arguments to pass to droidstubs for this scope. | 
| Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 150 | // | 
| Paul Duffin | 15f34ef | 2020-07-20 18:04:44 +0100 | [diff] [blame] | 151 | // This is not used directly but is used to construct the droidstubsArgs. | 
|  | 152 | extraArgs []string | 
| Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 153 |  | 
| Paul Duffin | 15f34ef | 2020-07-20 18:04:44 +0100 | [diff] [blame] | 154 | // The args that must be passed to droidstubs to generate the API and stubs source | 
|  | 155 | // for this scope, constructed dynamically by initApiScope(). | 
| Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 156 | // | 
|  | 157 | // The API only includes the additional members that this scope adds over the scope | 
|  | 158 | // that it extends. | 
| Paul Duffin | 15f34ef | 2020-07-20 18:04:44 +0100 | [diff] [blame] | 159 | // | 
|  | 160 | // The stubs source must include the definitions of everything that is in this | 
|  | 161 | // api scope and all the scopes that this one extends. | 
|  | 162 | droidstubsArgs []string | 
| Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 163 |  | 
| Anton Hansson | 6478ac1 | 2020-05-02 11:19:36 +0100 | [diff] [blame] | 164 | // Whether the api scope can be treated as unstable, and should skip compat checks. | 
|  | 165 | unstable bool | 
| Jihoon Kang | 1c92c3e | 2023-03-23 17:44:51 +0000 | [diff] [blame] | 166 |  | 
|  | 167 | // Represents the SDK kind of this scope. | 
|  | 168 | kind android.SdkKind | 
| Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 169 | } | 
|  | 170 |  | 
|  | 171 | // Initialize a scope, creating and adding appropriate dependency tags | 
|  | 172 | func initApiScope(scope *apiScope) *apiScope { | 
| Paul Duffin | c878250 | 2020-04-29 20:45:27 +0100 | [diff] [blame] | 173 | name := scope.name | 
| Paul Duffin | 46dc45a | 2020-05-14 15:39:10 +0100 | [diff] [blame] | 174 | scopeByName[name] = scope | 
|  | 175 | allScopeNames = append(allScopeNames, name) | 
| Paul Duffin | 6b836ba | 2020-05-13 19:19:49 +0100 | [diff] [blame] | 176 | scope.propertyName = strings.ReplaceAll(name, "-", "_") | 
|  | 177 | scope.fieldName = proptools.FieldNameForProperty(scope.propertyName) | 
| Jihoon Kang | b743155 | 2024-01-22 19:40:08 +0000 | [diff] [blame] | 178 | scope.prebuiltStubsTag = scopeDependencyTag{ | 
| Paul Duffin | c878250 | 2020-04-29 20:45:27 +0100 | [diff] [blame] | 179 | name:             name + "-stubs", | 
|  | 180 | apiScope:         scope, | 
|  | 181 | depInfoExtractor: (*scopePaths).extractStubsLibraryInfoFromDependency, | 
| Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 182 | } | 
| Jihoon Kang | bd09345 | 2023-12-26 19:08:01 +0000 | [diff] [blame] | 183 | scope.everythingStubsTag = scopeDependencyTag{ | 
|  | 184 | name:             name + "-stubs-everything", | 
|  | 185 | apiScope:         scope, | 
|  | 186 | depInfoExtractor: (*scopePaths).extractEverythingStubsLibraryInfoFromDependency, | 
|  | 187 | } | 
|  | 188 | scope.exportableStubsTag = scopeDependencyTag{ | 
|  | 189 | name:             name + "-stubs-exportable", | 
|  | 190 | apiScope:         scope, | 
|  | 191 | depInfoExtractor: (*scopePaths).extractExportableStubsLibraryInfoFromDependency, | 
|  | 192 | } | 
| Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 193 | scope.stubsSourceTag = scopeDependencyTag{ | 
|  | 194 | name:             name + "-stubs-source", | 
|  | 195 | apiScope:         scope, | 
|  | 196 | depInfoExtractor: (*scopePaths).extractStubsSourceInfoFromDep, | 
|  | 197 | } | 
|  | 198 | scope.apiFileTag = scopeDependencyTag{ | 
|  | 199 | name:             name + "-api", | 
|  | 200 | apiScope:         scope, | 
|  | 201 | depInfoExtractor: (*scopePaths).extractApiInfoFromDep, | 
|  | 202 | } | 
| Paul Duffin | c878250 | 2020-04-29 20:45:27 +0100 | [diff] [blame] | 203 | scope.stubsSourceAndApiTag = scopeDependencyTag{ | 
|  | 204 | name:             name + "-stubs-source-and-api", | 
|  | 205 | apiScope:         scope, | 
|  | 206 | depInfoExtractor: (*scopePaths).extractStubsSourceAndApiInfoFromApiStubsProvider, | 
| Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 207 | } | 
| Paul Duffin | 958806b | 2022-05-16 13:10:47 +0000 | [diff] [blame] | 208 | scope.latestApiModuleTag = scopeDependencyTag{ | 
|  | 209 | name:             name + "-latest-api", | 
|  | 210 | apiScope:         scope, | 
|  | 211 | depInfoExtractor: (*scopePaths).extractLatestApiPath, | 
|  | 212 | } | 
|  | 213 | scope.latestRemovedApiModuleTag = scopeDependencyTag{ | 
|  | 214 | name:             name + "-latest-removed-api", | 
|  | 215 | apiScope:         scope, | 
|  | 216 | depInfoExtractor: (*scopePaths).extractLatestRemovedApiPath, | 
|  | 217 | } | 
| Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 218 |  | 
|  | 219 | // To get the args needed to generate the stubs source append all the args from | 
|  | 220 | // this scope and all the scopes it extends as each set of args adds additional | 
|  | 221 | // members to the stubs. | 
| Paul Duffin | 15f34ef | 2020-07-20 18:04:44 +0100 | [diff] [blame] | 222 | var scopeSpecificArgs []string | 
|  | 223 | if scope.annotation != "" { | 
|  | 224 | scopeSpecificArgs = []string{"--show-annotation", scope.annotation} | 
| Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 225 | } | 
| Paul Duffin | 15f34ef | 2020-07-20 18:04:44 +0100 | [diff] [blame] | 226 | for s := scope; s != nil; s = s.extends { | 
|  | 227 | scopeSpecificArgs = append(scopeSpecificArgs, s.extraArgs...) | 
| Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 228 |  | 
| Paul Duffin | 15f34ef | 2020-07-20 18:04:44 +0100 | [diff] [blame] | 229 | // Ensure that the generated stubs includes all the API elements from the API scope | 
|  | 230 | // that this scope extends. | 
|  | 231 | if s != scope && s.annotation != "" { | 
|  | 232 | scopeSpecificArgs = append(scopeSpecificArgs, "--show-for-stub-purposes-annotation", s.annotation) | 
|  | 233 | } | 
|  | 234 | } | 
| Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 235 |  | 
| Paul Duffin | d0b9fca | 2022-09-30 18:11:41 +0100 | [diff] [blame] | 236 | // By default, a library that can access a scope can also access the scope it extends. | 
|  | 237 | if scope.canAccess == nil { | 
|  | 238 | scope.canAccess = scope.extends | 
|  | 239 | } | 
|  | 240 |  | 
| Paul Duffin | 15f34ef | 2020-07-20 18:04:44 +0100 | [diff] [blame] | 241 | // Escape any special characters in the arguments. This is needed because droidstubs | 
|  | 242 | // passes these directly to the shell command. | 
|  | 243 | scope.droidstubsArgs = proptools.ShellEscapeList(scopeSpecificArgs) | 
| Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 244 |  | 
| Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 245 | return scope | 
|  | 246 | } | 
|  | 247 |  | 
| Anton Hansson | 08f476b | 2021-04-07 15:32:19 +0100 | [diff] [blame] | 248 | func (scope *apiScope) stubsLibraryModuleNameSuffix() string { | 
|  | 249 | return ".stubs" + scope.moduleSuffix | 
|  | 250 | } | 
|  | 251 |  | 
| Jihoon Kang | fa4a90d | 2023-12-20 02:53:38 +0000 | [diff] [blame] | 252 | func (scope *apiScope) exportableStubsLibraryModuleNameSuffix() string { | 
|  | 253 | return ".stubs.exportable" + scope.moduleSuffix | 
|  | 254 | } | 
|  | 255 |  | 
| Jihoon Kang | 1c92c3e | 2023-03-23 17:44:51 +0000 | [diff] [blame] | 256 | func (scope *apiScope) apiLibraryModuleName(baseName string) string { | 
|  | 257 | return scope.stubsLibraryModuleName(baseName) + ".from-text" | 
|  | 258 | } | 
|  | 259 |  | 
| Jihoon Kang | 1147b31 | 2023-06-08 23:25:57 +0000 | [diff] [blame] | 260 | func (scope *apiScope) sourceStubLibraryModuleName(baseName string) string { | 
|  | 261 | return scope.stubsLibraryModuleName(baseName) + ".from-source" | 
|  | 262 | } | 
|  | 263 |  | 
| Jihoon Kang | fa4a90d | 2023-12-20 02:53:38 +0000 | [diff] [blame] | 264 | func (scope *apiScope) exportableSourceStubsLibraryModuleName(baseName string) string { | 
|  | 265 | return scope.exportableStubsLibraryModuleName(baseName) + ".from-source" | 
|  | 266 | } | 
|  | 267 |  | 
| Paul Duffin | c3091c8 | 2020-05-08 14:16:20 +0100 | [diff] [blame] | 268 | func (scope *apiScope) stubsLibraryModuleName(baseName string) string { | 
| Anton Hansson | 08f476b | 2021-04-07 15:32:19 +0100 | [diff] [blame] | 269 | return baseName + scope.stubsLibraryModuleNameSuffix() | 
| Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 270 | } | 
|  | 271 |  | 
| Jihoon Kang | fa4a90d | 2023-12-20 02:53:38 +0000 | [diff] [blame] | 272 | func (scope *apiScope) exportableStubsLibraryModuleName(baseName string) string { | 
|  | 273 | return baseName + scope.exportableStubsLibraryModuleNameSuffix() | 
|  | 274 | } | 
|  | 275 |  | 
| Paul Duffin | c878250 | 2020-04-29 20:45:27 +0100 | [diff] [blame] | 276 | func (scope *apiScope) stubsSourceModuleName(baseName string) string { | 
| Paul Duffin | dd9d074 | 2020-05-08 15:52:37 +0100 | [diff] [blame] | 277 | return baseName + ".stubs.source" + scope.moduleSuffix | 
| Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 278 | } | 
|  | 279 |  | 
| Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 280 | func (scope *apiScope) apiModuleName(baseName string) string { | 
| Paul Duffin | dd9d074 | 2020-05-08 15:52:37 +0100 | [diff] [blame] | 281 | return baseName + ".api" + scope.moduleSuffix | 
| Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 282 | } | 
|  | 283 |  | 
| Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 284 | func (scope *apiScope) String() string { | 
|  | 285 | return scope.name | 
|  | 286 | } | 
|  | 287 |  | 
| Paul Duffin | 958806b | 2022-05-16 13:10:47 +0000 | [diff] [blame] | 288 | // snapshotRelativeDir returns the snapshot directory into which the files related to scopes will | 
|  | 289 | // be stored. | 
|  | 290 | func (scope *apiScope) snapshotRelativeDir() string { | 
|  | 291 | return filepath.Join("sdk_library", scope.name) | 
|  | 292 | } | 
|  | 293 |  | 
|  | 294 | // snapshotRelativeCurrentApiTxtPath returns the snapshot path to the API .txt file for the named | 
|  | 295 | // library. | 
|  | 296 | func (scope *apiScope) snapshotRelativeCurrentApiTxtPath(name string) string { | 
|  | 297 | return filepath.Join(scope.snapshotRelativeDir(), name+".txt") | 
|  | 298 | } | 
|  | 299 |  | 
|  | 300 | // snapshotRelativeRemovedApiTxtPath returns the snapshot path to the removed API .txt file for the | 
|  | 301 | // named library. | 
|  | 302 | func (scope *apiScope) snapshotRelativeRemovedApiTxtPath(name string) string { | 
|  | 303 | return filepath.Join(scope.snapshotRelativeDir(), name+"-removed.txt") | 
|  | 304 | } | 
|  | 305 |  | 
| Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 306 | type apiScopes []*apiScope | 
|  | 307 |  | 
|  | 308 | func (scopes apiScopes) Strings(accessor func(*apiScope) string) []string { | 
|  | 309 | var list []string | 
|  | 310 | for _, scope := range scopes { | 
|  | 311 | list = append(list, accessor(scope)) | 
|  | 312 | } | 
|  | 313 | return list | 
|  | 314 | } | 
|  | 315 |  | 
| Jihoon Kang | a96a7b1 | 2023-09-20 23:43:32 +0000 | [diff] [blame] | 316 | // Method that maps the apiScopes properties to the index of each apiScopes elements. | 
|  | 317 | // apiScopes property to be used as the key can be specified with the input accessor. | 
|  | 318 | // Only a string property of apiScope can be used as the key of the map. | 
|  | 319 | func (scopes apiScopes) MapToIndex(accessor func(*apiScope) string) map[string]int { | 
|  | 320 | ret := make(map[string]int) | 
|  | 321 | for i, scope := range scopes { | 
|  | 322 | ret[accessor(scope)] = i | 
|  | 323 | } | 
|  | 324 | return ret | 
|  | 325 | } | 
|  | 326 |  | 
| Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 327 | var ( | 
| Paul Duffin | 46dc45a | 2020-05-14 15:39:10 +0100 | [diff] [blame] | 328 | scopeByName    = make(map[string]*apiScope) | 
|  | 329 | allScopeNames  []string | 
| Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 330 | apiScopePublic = initApiScope(&apiScope{ | 
| Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 331 | name: "public", | 
|  | 332 |  | 
|  | 333 | // Public scope is enabled by default for both legacy and non-legacy modes. | 
|  | 334 | legacyEnabledStatus: func(module *SdkLibrary) bool { | 
|  | 335 | return true | 
|  | 336 | }, | 
|  | 337 | defaultEnabledStatus: true, | 
|  | 338 |  | 
|  | 339 | scopeSpecificProperties: func(module *SdkLibrary) *ApiScopeProperties { | 
|  | 340 | return &module.sdkLibraryProperties.Public | 
|  | 341 | }, | 
| Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 342 | sdkVersion: "current", | 
| Jihoon Kang | 1c92c3e | 2023-03-23 17:44:51 +0000 | [diff] [blame] | 343 | kind:       android.SdkPublic, | 
| Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 344 | }) | 
|  | 345 | apiScopeSystem = initApiScope(&apiScope{ | 
| Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 346 | name:                "system", | 
|  | 347 | extends:             apiScopePublic, | 
|  | 348 | legacyEnabledStatus: (*SdkLibrary).generateTestAndSystemScopesByDefault, | 
|  | 349 | scopeSpecificProperties: func(module *SdkLibrary) *ApiScopeProperties { | 
|  | 350 | return &module.sdkLibraryProperties.System | 
|  | 351 | }, | 
| Paul Duffin | 15f34ef | 2020-07-20 18:04:44 +0100 | [diff] [blame] | 352 | apiFilePrefix: "system-", | 
|  | 353 | moduleSuffix:  ".system", | 
|  | 354 | sdkVersion:    "system_current", | 
|  | 355 | annotation:    "android.annotation.SystemApi(client=android.annotation.SystemApi.Client.PRIVILEGED_APPS)", | 
| Jihoon Kang | 1c92c3e | 2023-03-23 17:44:51 +0000 | [diff] [blame] | 356 | kind:          android.SdkSystem, | 
| Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 357 | }) | 
|  | 358 | apiScopeTest = initApiScope(&apiScope{ | 
| Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 359 | name:                "test", | 
| Anton Hansson | 4fe970f | 2020-10-09 10:16:49 +0100 | [diff] [blame] | 360 | extends:             apiScopeSystem, | 
| Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 361 | legacyEnabledStatus: (*SdkLibrary).generateTestAndSystemScopesByDefault, | 
|  | 362 | scopeSpecificProperties: func(module *SdkLibrary) *ApiScopeProperties { | 
|  | 363 | return &module.sdkLibraryProperties.Test | 
|  | 364 | }, | 
| Paul Duffin | 15f34ef | 2020-07-20 18:04:44 +0100 | [diff] [blame] | 365 | apiFilePrefix: "test-", | 
|  | 366 | moduleSuffix:  ".test", | 
|  | 367 | sdkVersion:    "test_current", | 
|  | 368 | annotation:    "android.annotation.TestApi", | 
|  | 369 | unstable:      true, | 
| Jihoon Kang | 1c92c3e | 2023-03-23 17:44:51 +0000 | [diff] [blame] | 370 | kind:          android.SdkTest, | 
| Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 371 | }) | 
| Paul Duffin | 8f265b9 | 2020-04-28 14:13:56 +0100 | [diff] [blame] | 372 | apiScopeModuleLib = initApiScope(&apiScope{ | 
| Paul Duffin | 6b836ba | 2020-05-13 19:19:49 +0100 | [diff] [blame] | 373 | name:    "module-lib", | 
| Paul Duffin | 8f265b9 | 2020-04-28 14:13:56 +0100 | [diff] [blame] | 374 | extends: apiScopeSystem, | 
| Paul Duffin | 0c5bae5 | 2020-06-02 13:00:08 +0100 | [diff] [blame] | 375 | // The module-lib scope is disabled by default in legacy mode. | 
| Paul Duffin | 8f265b9 | 2020-04-28 14:13:56 +0100 | [diff] [blame] | 376 | // | 
|  | 377 | // Enabling this would break existing usages. | 
|  | 378 | legacyEnabledStatus: func(module *SdkLibrary) bool { | 
|  | 379 | return false | 
|  | 380 | }, | 
|  | 381 | scopeSpecificProperties: func(module *SdkLibrary) *ApiScopeProperties { | 
|  | 382 | return &module.sdkLibraryProperties.Module_lib | 
|  | 383 | }, | 
|  | 384 | apiFilePrefix: "module-lib-", | 
|  | 385 | moduleSuffix:  ".module_lib", | 
|  | 386 | sdkVersion:    "module_current", | 
| Paul Duffin | 15f34ef | 2020-07-20 18:04:44 +0100 | [diff] [blame] | 387 | annotation:    "android.annotation.SystemApi(client=android.annotation.SystemApi.Client.MODULE_LIBRARIES)", | 
| Jihoon Kang | 1c92c3e | 2023-03-23 17:44:51 +0000 | [diff] [blame] | 388 | kind:          android.SdkModule, | 
| Paul Duffin | 8f265b9 | 2020-04-28 14:13:56 +0100 | [diff] [blame] | 389 | }) | 
| Paul Duffin | 0c5bae5 | 2020-06-02 13:00:08 +0100 | [diff] [blame] | 390 | apiScopeSystemServer = initApiScope(&apiScope{ | 
|  | 391 | name:    "system-server", | 
|  | 392 | extends: apiScopePublic, | 
| Paul Duffin | d0b9fca | 2022-09-30 18:11:41 +0100 | [diff] [blame] | 393 |  | 
|  | 394 | // The system-server scope can access the module-lib scope. | 
|  | 395 | // | 
|  | 396 | // A module that provides a system-server API is appended to the standard bootclasspath that is | 
|  | 397 | // used by the system server. So, it should be able to access module-lib APIs provided by | 
|  | 398 | // libraries on the bootclasspath. | 
|  | 399 | canAccess: apiScopeModuleLib, | 
|  | 400 |  | 
| Paul Duffin | 0c5bae5 | 2020-06-02 13:00:08 +0100 | [diff] [blame] | 401 | // The system-server scope is disabled by default in legacy mode. | 
|  | 402 | // | 
|  | 403 | // Enabling this would break existing usages. | 
|  | 404 | legacyEnabledStatus: func(module *SdkLibrary) bool { | 
|  | 405 | return false | 
|  | 406 | }, | 
|  | 407 | scopeSpecificProperties: func(module *SdkLibrary) *ApiScopeProperties { | 
|  | 408 | return &module.sdkLibraryProperties.System_server | 
|  | 409 | }, | 
|  | 410 | apiFilePrefix: "system-server-", | 
|  | 411 | moduleSuffix:  ".system_server", | 
|  | 412 | sdkVersion:    "system_server_current", | 
| Paul Duffin | 15f34ef | 2020-07-20 18:04:44 +0100 | [diff] [blame] | 413 | annotation:    "android.annotation.SystemApi(client=android.annotation.SystemApi.Client.SYSTEM_SERVER)", | 
|  | 414 | extraArgs: []string{ | 
|  | 415 | "--hide-annotation", "android.annotation.Hide", | 
| Paul Duffin | 0c5bae5 | 2020-06-02 13:00:08 +0100 | [diff] [blame] | 416 | // com.android.* classes are okay in this interface" | 
| Paul Duffin | 15f34ef | 2020-07-20 18:04:44 +0100 | [diff] [blame] | 417 | "--hide", "InternalClasses", | 
| Paul Duffin | 0c5bae5 | 2020-06-02 13:00:08 +0100 | [diff] [blame] | 418 | }, | 
| Jihoon Kang | 1c92c3e | 2023-03-23 17:44:51 +0000 | [diff] [blame] | 419 | kind: android.SdkSystemServer, | 
| Paul Duffin | 0c5bae5 | 2020-06-02 13:00:08 +0100 | [diff] [blame] | 420 | }) | 
| Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 421 | allApiScopes = apiScopes{ | 
|  | 422 | apiScopePublic, | 
|  | 423 | apiScopeSystem, | 
|  | 424 | apiScopeTest, | 
| Paul Duffin | 8f265b9 | 2020-04-28 14:13:56 +0100 | [diff] [blame] | 425 | apiScopeModuleLib, | 
| Paul Duffin | 0c5bae5 | 2020-06-02 13:00:08 +0100 | [diff] [blame] | 426 | apiScopeSystemServer, | 
| Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 427 | } | 
| Jihoon Kang | 0c705a4 | 2023-08-02 06:44:57 +0000 | [diff] [blame] | 428 | apiLibraryAdditionalProperties = map[string]struct { | 
|  | 429 | FullApiSurfaceStubLib     string | 
|  | 430 | AdditionalApiContribution string | 
|  | 431 | }{ | 
|  | 432 | "legacy.i18n.module.platform.api": { | 
|  | 433 | FullApiSurfaceStubLib:     "legacy.core.platform.api.stubs", | 
|  | 434 | AdditionalApiContribution: "i18n.module.public.api.stubs.source.api.contribution", | 
|  | 435 | }, | 
|  | 436 | "stable.i18n.module.platform.api": { | 
|  | 437 | FullApiSurfaceStubLib:     "stable.core.platform.api.stubs", | 
|  | 438 | AdditionalApiContribution: "i18n.module.public.api.stubs.source.api.contribution", | 
|  | 439 | }, | 
|  | 440 | "conscrypt.module.platform.api": { | 
|  | 441 | FullApiSurfaceStubLib:     "stable.core.platform.api.stubs", | 
|  | 442 | AdditionalApiContribution: "conscrypt.module.public.api.stubs.source.api.contribution", | 
|  | 443 | }, | 
|  | 444 | } | 
| Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 445 | ) | 
|  | 446 |  | 
| Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 447 | var ( | 
|  | 448 | javaSdkLibrariesLock sync.Mutex | 
|  | 449 | ) | 
|  | 450 |  | 
| Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 451 | // TODO: these are big features that are currently missing | 
| Jiyong Park | 1be9691 | 2018-05-28 18:02:19 +0900 | [diff] [blame] | 452 | // 1) disallowing linking to the runtime shared lib | 
|  | 453 | // 2) HTML generation | 
| Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 454 |  | 
|  | 455 | func init() { | 
| Paul Duffin | 43dc1cc | 2019-12-19 11:18:54 +0000 | [diff] [blame] | 456 | RegisterSdkLibraryBuildComponents(android.InitRegistrationContext) | 
| Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 457 |  | 
| Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 458 | android.RegisterMakeVarsProvider(pctx, func(ctx android.MakeVarsContext) { | 
|  | 459 | javaSdkLibraries := javaSdkLibraries(ctx.Config()) | 
|  | 460 | sort.Strings(*javaSdkLibraries) | 
|  | 461 | ctx.Strict("JAVA_SDK_LIBRARIES", strings.Join(*javaSdkLibraries, " ")) | 
|  | 462 | }) | 
| Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 463 |  | 
|  | 464 | // Register sdk member types. | 
| Paul Duffin | 976b0e5 | 2021-04-27 23:20:26 +0100 | [diff] [blame] | 465 | android.RegisterSdkMemberType(javaSdkLibrarySdkMemberType) | 
| Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 466 | } | 
|  | 467 |  | 
| Paul Duffin | 43dc1cc | 2019-12-19 11:18:54 +0000 | [diff] [blame] | 468 | func RegisterSdkLibraryBuildComponents(ctx android.RegistrationContext) { | 
|  | 469 | ctx.RegisterModuleType("java_sdk_library", SdkLibraryFactory) | 
|  | 470 | ctx.RegisterModuleType("java_sdk_library_import", sdkLibraryImportFactory) | 
|  | 471 | } | 
|  | 472 |  | 
| Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 473 | // Properties associated with each api scope. | 
|  | 474 | type ApiScopeProperties struct { | 
|  | 475 | // Indicates whether the api surface is generated. | 
|  | 476 | // | 
|  | 477 | // If this is set for any scope then all scopes must explicitly specify if they | 
|  | 478 | // are enabled. This is to prevent new usages from depending on legacy behavior. | 
|  | 479 | // | 
|  | 480 | // Otherwise, if this is not set for any scope then the default  behavior is | 
|  | 481 | // scope specific so please refer to the scope specific property documentation. | 
|  | 482 | Enabled *bool | 
| Paul Duffin | 87a05a3 | 2020-05-12 11:50:28 +0100 | [diff] [blame] | 483 |  | 
|  | 484 | // The sdk_version to use for building the stubs. | 
|  | 485 | // | 
|  | 486 | // If not specified then it will use an sdk_version determined as follows: | 
| Trevor Radcliffe | df8aa1f | 2021-11-04 14:25:39 +0000 | [diff] [blame] | 487 | // | 
| Paul Duffin | 87a05a3 | 2020-05-12 11:50:28 +0100 | [diff] [blame] | 488 | // 1) If the sdk_version specified on the java_sdk_library is none then this | 
| Trevor Radcliffe | df8aa1f | 2021-11-04 14:25:39 +0000 | [diff] [blame] | 489 | // will be none. This is used for java_sdk_library instances that are used | 
|  | 490 | // to create stubs that contribute to the core_current sdk version. | 
|  | 491 | // 2) Otherwise, it is assumed that this library extends but does not | 
|  | 492 | // contribute directly to a specific sdk_version and so this uses the | 
|  | 493 | // sdk_version appropriate for the api scope. e.g. public will use | 
|  | 494 | // sdk_version: current, system will use sdk_version: system_current, etc. | 
| Paul Duffin | 87a05a3 | 2020-05-12 11:50:28 +0100 | [diff] [blame] | 495 | // | 
|  | 496 | // This does not affect the sdk_version used for either generating the stubs source | 
|  | 497 | // or the API file. They both have to use the same sdk_version as is used for | 
|  | 498 | // compiling the implementation library. | 
|  | 499 | Sdk_version *string | 
| Mark White | 9421c4c | 2023-08-10 00:07:03 +0000 | [diff] [blame] | 500 |  | 
|  | 501 | // Extra libs used when compiling stubs for this scope. | 
|  | 502 | Libs []string | 
| Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 503 | } | 
|  | 504 |  | 
| Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 505 | type sdkLibraryProperties struct { | 
| Anton Hansson | f8ea372 | 2021-09-16 14:24:13 +0100 | [diff] [blame] | 506 | // List of source files that are needed to compile the API, but are not part of runtime library. | 
|  | 507 | Api_srcs []string `android:"arch_variant"` | 
|  | 508 |  | 
| Paul Duffin | 5df7930 | 2020-05-16 15:52:12 +0100 | [diff] [blame] | 509 | // Visibility for impl library module. If not specified then defaults to the | 
|  | 510 | // visibility property. | 
|  | 511 | Impl_library_visibility []string | 
|  | 512 |  | 
| Paul Duffin | 4911a89 | 2020-04-29 23:35:13 +0100 | [diff] [blame] | 513 | // Visibility for stubs library modules. If not specified then defaults to the | 
|  | 514 | // visibility property. | 
|  | 515 | Stubs_library_visibility []string | 
|  | 516 |  | 
|  | 517 | // Visibility for stubs source modules. If not specified then defaults to the | 
|  | 518 | // visibility property. | 
|  | 519 | Stubs_source_visibility []string | 
|  | 520 |  | 
| Anton Hansson | 7f66efa | 2020-10-08 14:47:23 +0100 | [diff] [blame] | 521 | // List of Java libraries that will be in the classpath when building the implementation lib | 
|  | 522 | Impl_only_libs []string `android:"arch_variant"` | 
|  | 523 |  | 
| Paul Duffin | 77590a8 | 2022-04-28 14:13:30 +0000 | [diff] [blame] | 524 | // List of Java libraries that will included in the implementation lib. | 
|  | 525 | Impl_only_static_libs []string `android:"arch_variant"` | 
|  | 526 |  | 
| Sundong Ahn | f043cf6 | 2018-06-25 16:04:37 +0900 | [diff] [blame] | 527 | // List of Java libraries that will be in the classpath when building stubs | 
|  | 528 | Stub_only_libs []string `android:"arch_variant"` | 
|  | 529 |  | 
| Anton Hansson | dae54cd | 2021-04-21 16:30:10 +0100 | [diff] [blame] | 530 | // List of Java libraries that will included in stub libraries | 
|  | 531 | Stub_only_static_libs []string `android:"arch_variant"` | 
|  | 532 |  | 
| Paul Duffin | 7a586d3 | 2019-12-30 17:09:34 +0000 | [diff] [blame] | 533 | // list of package names that will be documented and publicized as API. | 
|  | 534 | // This allows the API to be restricted to a subset of the source files provided. | 
|  | 535 | // If this is unspecified then all the source files will be treated as being part | 
|  | 536 | // of the API. | 
| Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 537 | Api_packages []string | 
|  | 538 |  | 
| Jiyong Park | 5a2c9d7 | 2018-05-01 22:25:41 +0900 | [diff] [blame] | 539 | // list of package names that must be hidden from the API | 
|  | 540 | Hidden_api_packages []string | 
|  | 541 |  | 
| Paul Duffin | 749f98f | 2019-12-30 17:23:46 +0000 | [diff] [blame] | 542 | // the relative path to the directory containing the api specification files. | 
|  | 543 | // Defaults to "api". | 
|  | 544 | Api_dir *string | 
|  | 545 |  | 
| Paul Duffin | dfa131e | 2020-05-15 20:37:11 +0100 | [diff] [blame] | 546 | // Determines whether a runtime implementation library is built; defaults to false. | 
|  | 547 | // | 
|  | 548 | // If true then it also prevents the module from being used as a shared module, i.e. | 
| MƄrten Kongstad | 81d9095 | 2022-05-25 16:27:11 +0200 | [diff] [blame] | 549 | // it is as if shared_library: false, was set. | 
| Paul Duffin | 43db9be | 2019-12-30 17:35:49 +0000 | [diff] [blame] | 550 | Api_only *bool | 
|  | 551 |  | 
| Paul Duffin | 1151247 | 2019-02-11 15:55:17 +0000 | [diff] [blame] | 552 | // local files that are used within user customized droiddoc options. | 
|  | 553 | Droiddoc_option_files []string | 
|  | 554 |  | 
| Spandan Das | 93e9599 | 2021-07-29 18:26:39 +0000 | [diff] [blame] | 555 | // additional droiddoc options. | 
| Paul Duffin | 1151247 | 2019-02-11 15:55:17 +0000 | [diff] [blame] | 556 | // Available variables for substitution: | 
|  | 557 | // | 
|  | 558 | //  $(location <label>): the path to the droiddoc_option_files with name <label> | 
| Sundong Ahn | dd567f9 | 2018-07-31 17:19:11 +0900 | [diff] [blame] | 559 | Droiddoc_options []string | 
|  | 560 |  | 
| Paul Duffin | e22c2ab | 2020-05-20 19:35:27 +0100 | [diff] [blame] | 561 | // is set to true, Metalava will allow framework SDK to contain annotations. | 
|  | 562 | Annotations_enabled *bool | 
|  | 563 |  | 
| Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 564 | // a list of top-level directories containing files to merge qualifier annotations | 
|  | 565 | // (i.e. those intended to be included in the stubs written) from. | 
|  | 566 | Merge_annotations_dirs []string | 
|  | 567 |  | 
|  | 568 | // a list of top-level directories containing Java stub files to merge show/hide annotations from. | 
|  | 569 | Merge_inclusion_annotations_dirs []string | 
|  | 570 |  | 
| Paul Duffin | 4f5c1ef | 2020-11-19 14:53:43 +0000 | [diff] [blame] | 571 | // If set to true then don't create dist rules. | 
|  | 572 | No_dist *bool | 
| Sundong Ahn | 80a87b3 | 2019-05-13 15:02:50 +0900 | [diff] [blame] | 573 |  | 
| Paul Duffin | 3131025 | 2020-11-20 21:26:20 +0000 | [diff] [blame] | 574 | // The stem for the artifacts that are copied to the dist, if not specified | 
|  | 575 | // then defaults to the base module name. | 
|  | 576 | // | 
|  | 577 | // For each scope the following artifacts are copied to the apistubs/<scope> | 
|  | 578 | // directory in the dist. | 
|  | 579 | // * stubs impl jar -> <dist-stem>.jar | 
|  | 580 | // * API specification file -> api/<dist-stem>.txt | 
|  | 581 | // * Removed API specification file -> api/<dist-stem>-removed.txt | 
|  | 582 | // | 
|  | 583 | // Also used to construct the name of the filegroup (created by prebuilt_apis) | 
|  | 584 | // that references the latest released API and remove API specification files. | 
|  | 585 | // * API specification filegroup -> <dist-stem>.api.<scope>.latest | 
|  | 586 | // * Removed API specification filegroup -> <dist-stem>-removed.api.<scope>.latest | 
| Jaewoong Jung | 1a97ee0 | 2021-03-09 13:25:02 -0800 | [diff] [blame] | 587 | // * API incompatibilities baseline filegroup -> <dist-stem>-incompatibilities.api.<scope>.latest | 
| Paul Duffin | 3131025 | 2020-11-20 21:26:20 +0000 | [diff] [blame] | 588 | Dist_stem *string | 
|  | 589 |  | 
| Colin Cross | 986b69a | 2021-06-01 13:13:40 -0700 | [diff] [blame] | 590 | // The subdirectory for the artifacts that are copied to the dist directory.  If not specified | 
| Colin Cross | 3dd6625 | 2021-06-01 14:05:09 -0700 | [diff] [blame] | 591 | // then defaults to "unknown".  Should be set to "android" for anything that should be published | 
| Colin Cross | 986b69a | 2021-06-01 13:13:40 -0700 | [diff] [blame] | 592 | // in the public Android SDK. | 
|  | 593 | Dist_group *string | 
|  | 594 |  | 
| Anton Hansson | dff2c78 | 2020-12-21 17:10:01 +0000 | [diff] [blame] | 595 | // A compatibility mode that allows historical API-tracking files to not exist. | 
|  | 596 | // Do not use. | 
|  | 597 | Unsafe_ignore_missing_latest_api bool | 
|  | 598 |  | 
| Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 599 | // indicates whether system and test apis should be generated. | 
|  | 600 | Generate_system_and_test_apis bool `blueprint:"mutated"` | 
|  | 601 |  | 
|  | 602 | // The properties specific to the public api scope | 
|  | 603 | // | 
|  | 604 | // Unless explicitly specified by using public.enabled the public api scope is | 
|  | 605 | // enabled by default in both legacy and non-legacy mode. | 
|  | 606 | Public ApiScopeProperties | 
|  | 607 |  | 
|  | 608 | // The properties specific to the system api scope | 
|  | 609 | // | 
|  | 610 | // In legacy mode the system api scope is enabled by default when sdk_version | 
|  | 611 | // is set to something other than "none". | 
|  | 612 | // | 
|  | 613 | // In non-legacy mode the system api scope is disabled by default. | 
|  | 614 | System ApiScopeProperties | 
|  | 615 |  | 
|  | 616 | // The properties specific to the test api scope | 
|  | 617 | // | 
|  | 618 | // In legacy mode the test api scope is enabled by default when sdk_version | 
|  | 619 | // is set to something other than "none". | 
|  | 620 | // | 
|  | 621 | // In non-legacy mode the test api scope is disabled by default. | 
|  | 622 | Test ApiScopeProperties | 
| Paul Duffin | 37e0b77 | 2019-12-30 17:20:10 +0000 | [diff] [blame] | 623 |  | 
| Paul Duffin | 0c5bae5 | 2020-06-02 13:00:08 +0100 | [diff] [blame] | 624 | // The properties specific to the module-lib api scope | 
| Paul Duffin | 8f265b9 | 2020-04-28 14:13:56 +0100 | [diff] [blame] | 625 | // | 
| Zi Wang | b2179e3 | 2023-01-31 15:53:30 -0800 | [diff] [blame] | 626 | // Unless explicitly specified by using module_lib.enabled the module_lib api | 
|  | 627 | // scope is disabled by default. | 
| Paul Duffin | 8f265b9 | 2020-04-28 14:13:56 +0100 | [diff] [blame] | 628 | Module_lib ApiScopeProperties | 
|  | 629 |  | 
| Paul Duffin | 0c5bae5 | 2020-06-02 13:00:08 +0100 | [diff] [blame] | 630 | // The properties specific to the system-server api scope | 
|  | 631 | // | 
| Zi Wang | b2179e3 | 2023-01-31 15:53:30 -0800 | [diff] [blame] | 632 | // Unless explicitly specified by using system_server.enabled the | 
|  | 633 | // system_server api scope is disabled by default. | 
| Paul Duffin | 0c5bae5 | 2020-06-02 13:00:08 +0100 | [diff] [blame] | 634 | System_server ApiScopeProperties | 
|  | 635 |  | 
| Jiyong Park | 932cdfe | 2020-05-28 00:19:53 +0900 | [diff] [blame] | 636 | // Determines if the stubs are preferred over the implementation library | 
|  | 637 | // for linking, even when the client doesn't specify sdk_version. When this | 
|  | 638 | // is set to true, such clients are provided with the widest API surface that | 
|  | 639 | // this lib provides. Note however that this option doesn't affect the clients | 
|  | 640 | // that are in the same APEX as this library. In that case, the clients are | 
|  | 641 | // always linked with the implementation library. Default is false. | 
|  | 642 | Default_to_stubs *bool | 
|  | 643 |  | 
| Paul Duffin | 160fe41 | 2020-05-10 19:32:20 +0100 | [diff] [blame] | 644 | // Properties related to api linting. | 
|  | 645 | Api_lint struct { | 
|  | 646 | // Enable api linting. | 
|  | 647 | Enabled *bool | 
| Anton Hansson | fd1c0d2 | 2023-11-02 15:18:09 +0000 | [diff] [blame] | 648 |  | 
|  | 649 | // If API lint is enabled, this flag controls whether a set of legitimate lint errors | 
|  | 650 | // are turned off. The default is true. | 
|  | 651 | Legacy_errors_allowed *bool | 
| Paul Duffin | 160fe41 | 2020-05-10 19:32:20 +0100 | [diff] [blame] | 652 | } | 
|  | 653 |  | 
| Jihoon Kang | 80456fd | 2023-11-15 19:22:14 +0000 | [diff] [blame] | 654 | // Determines if the module contributes to any api surfaces. | 
|  | 655 | // This property should be set to true only if the module is listed under | 
|  | 656 | // frameworks-base-api.bootclasspath in frameworks/base/api/Android.bp. | 
|  | 657 | // Otherwise, this property should be set to false. | 
|  | 658 | // Defaults to false. | 
|  | 659 | Contribute_to_android_api *bool | 
|  | 660 |  | 
| Jihoon Kang | 6592e87 | 2023-12-19 01:13:16 +0000 | [diff] [blame] | 661 | // a list of aconfig_declarations module names that the stubs generated in this module | 
|  | 662 | // depend on. | 
|  | 663 | Aconfig_declarations []string | 
|  | 664 |  | 
| Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 665 | // TODO: determines whether to create HTML doc or not | 
| Paul Duffin | e840995 | 2022-09-22 16:24:46 +0100 | [diff] [blame] | 666 | // Html_doc *bool | 
| Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 667 | } | 
|  | 668 |  | 
| Paul Duffin | 0f8faff | 2020-05-20 16:18:00 +0100 | [diff] [blame] | 669 | // Paths to outputs from java_sdk_library and java_sdk_library_import. | 
|  | 670 | // | 
|  | 671 | // Fields that are android.Paths are always set (during GenerateAndroidBuildActions). | 
|  | 672 | // OptionalPaths are always set by java_sdk_library but may not be set by | 
|  | 673 | // java_sdk_library_import as not all instances provide that information. | 
| Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 674 | type scopePaths struct { | 
| Paul Duffin | 0f8faff | 2020-05-20 16:18:00 +0100 | [diff] [blame] | 675 | // The path (represented as Paths for convenience when returning) to the stubs header jar. | 
|  | 676 | // | 
|  | 677 | // That is the jar that is created by turbine. | 
|  | 678 | stubsHeaderPath android.Paths | 
|  | 679 |  | 
|  | 680 | // The path (represented as Paths for convenience when returning) to the stubs implementation jar. | 
|  | 681 | // | 
|  | 682 | // This is not the implementation jar, it still only contains stubs. | 
|  | 683 | stubsImplPath android.Paths | 
|  | 684 |  | 
| Paul Duffin | 1267d87 | 2021-04-16 17:21:36 +0100 | [diff] [blame] | 685 | // The dex jar for the stubs. | 
|  | 686 | // | 
|  | 687 | // This is not the implementation jar, it still only contains stubs. | 
| Martin Stjernholm | 8be1e6d | 2021-09-15 03:34:04 +0100 | [diff] [blame] | 688 | stubsDexJarPath OptionalDexJarPath | 
| Paul Duffin | 1267d87 | 2021-04-16 17:21:36 +0100 | [diff] [blame] | 689 |  | 
| Jihoon Kang | bd09345 | 2023-12-26 19:08:01 +0000 | [diff] [blame] | 690 | // The exportable dex jar for the stubs. | 
|  | 691 | // This is not the implementation jar, it still only contains stubs. | 
|  | 692 | // Includes unflagged apis and flagged apis enabled by release configurations. | 
|  | 693 | exportableStubsDexJarPath OptionalDexJarPath | 
|  | 694 |  | 
| Paul Duffin | 0f8faff | 2020-05-20 16:18:00 +0100 | [diff] [blame] | 695 | // The API specification file, e.g. system_current.txt. | 
|  | 696 | currentApiFilePath android.OptionalPath | 
|  | 697 |  | 
|  | 698 | // The specification of API elements removed since the last release. | 
|  | 699 | removedApiFilePath android.OptionalPath | 
|  | 700 |  | 
|  | 701 | // The stubs source jar. | 
|  | 702 | stubsSrcJar android.OptionalPath | 
| Anton Hansson | d78eb76 | 2021-09-21 15:25:12 +0100 | [diff] [blame] | 703 |  | 
|  | 704 | // Extracted annotations. | 
|  | 705 | annotationsZip android.OptionalPath | 
| Paul Duffin | 958806b | 2022-05-16 13:10:47 +0000 | [diff] [blame] | 706 |  | 
|  | 707 | // The path to the latest API file. | 
| Jihoon Kang | 5623e54 | 2024-01-31 23:27:26 +0000 | [diff] [blame] | 708 | latestApiPaths android.Paths | 
| Paul Duffin | 958806b | 2022-05-16 13:10:47 +0000 | [diff] [blame] | 709 |  | 
|  | 710 | // The path to the latest removed API file. | 
| Jihoon Kang | 5623e54 | 2024-01-31 23:27:26 +0000 | [diff] [blame] | 711 | latestRemovedApiPaths android.Paths | 
| Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 712 | } | 
|  | 713 |  | 
| Colin Cross | dcf71b2 | 2021-02-01 13:59:03 -0800 | [diff] [blame] | 714 | func (paths *scopePaths) extractStubsLibraryInfoFromDependency(ctx android.ModuleContext, dep android.Module) error { | 
| Colin Cross | 313aa54 | 2023-12-13 13:47:44 -0800 | [diff] [blame] | 715 | if lib, ok := android.OtherModuleProvider(ctx, dep, JavaInfoProvider); ok { | 
| Colin Cross | dcf71b2 | 2021-02-01 13:59:03 -0800 | [diff] [blame] | 716 | paths.stubsHeaderPath = lib.HeaderJars | 
|  | 717 | paths.stubsImplPath = lib.ImplementationJars | 
| Paul Duffin | 1267d87 | 2021-04-16 17:21:36 +0100 | [diff] [blame] | 718 |  | 
|  | 719 | libDep := dep.(UsesLibraryDependency) | 
| Spandan Das | 59a4a2b | 2024-01-09 21:35:56 +0000 | [diff] [blame] | 720 | paths.stubsDexJarPath = libDep.DexJarBuildPath(ctx) | 
| Jihoon Kang | bd09345 | 2023-12-26 19:08:01 +0000 | [diff] [blame] | 721 | paths.exportableStubsDexJarPath = libDep.DexJarBuildPath(ctx) | 
|  | 722 | return nil | 
|  | 723 | } else { | 
|  | 724 | return fmt.Errorf("expected module that has JavaInfoProvider, e.g. java_library") | 
|  | 725 | } | 
|  | 726 | } | 
|  | 727 |  | 
|  | 728 | func (paths *scopePaths) extractEverythingStubsLibraryInfoFromDependency(ctx android.ModuleContext, dep android.Module) error { | 
|  | 729 | if lib, ok := android.OtherModuleProvider(ctx, dep, JavaInfoProvider); ok { | 
|  | 730 | paths.stubsHeaderPath = lib.HeaderJars | 
| Jihoon Kang | f55a5f7 | 2024-01-08 08:56:20 +0000 | [diff] [blame] | 731 | if !ctx.Config().ReleaseHiddenApiExportableStubs() { | 
|  | 732 | paths.stubsImplPath = lib.ImplementationJars | 
|  | 733 | } | 
| Jihoon Kang | bd09345 | 2023-12-26 19:08:01 +0000 | [diff] [blame] | 734 |  | 
|  | 735 | libDep := dep.(UsesLibraryDependency) | 
|  | 736 | paths.stubsDexJarPath = libDep.DexJarBuildPath(ctx) | 
|  | 737 | return nil | 
|  | 738 | } else { | 
|  | 739 | return fmt.Errorf("expected module that has JavaInfoProvider, e.g. java_library") | 
|  | 740 | } | 
|  | 741 | } | 
|  | 742 |  | 
|  | 743 | func (paths *scopePaths) extractExportableStubsLibraryInfoFromDependency(ctx android.ModuleContext, dep android.Module) error { | 
| Jihoon Kang | f55a5f7 | 2024-01-08 08:56:20 +0000 | [diff] [blame] | 744 | if lib, ok := android.OtherModuleProvider(ctx, dep, JavaInfoProvider); ok { | 
|  | 745 | if ctx.Config().ReleaseHiddenApiExportableStubs() { | 
|  | 746 | paths.stubsImplPath = lib.ImplementationJars | 
|  | 747 | } | 
|  | 748 |  | 
| Jihoon Kang | bd09345 | 2023-12-26 19:08:01 +0000 | [diff] [blame] | 749 | libDep := dep.(UsesLibraryDependency) | 
|  | 750 | paths.exportableStubsDexJarPath = libDep.DexJarBuildPath(ctx) | 
| Paul Duffin | c878250 | 2020-04-29 20:45:27 +0100 | [diff] [blame] | 751 | return nil | 
|  | 752 | } else { | 
| Colin Cross | dcf71b2 | 2021-02-01 13:59:03 -0800 | [diff] [blame] | 753 | return fmt.Errorf("expected module that has JavaInfoProvider, e.g. java_library") | 
| Paul Duffin | c878250 | 2020-04-29 20:45:27 +0100 | [diff] [blame] | 754 | } | 
|  | 755 | } | 
|  | 756 |  | 
| Jihoon Kang | ee11328 | 2024-01-23 00:16:41 +0000 | [diff] [blame] | 757 | func (paths *scopePaths) treatDepAsApiStubsProvider(dep android.Module, action func(provider ApiStubsProvider) error) error { | 
| Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 758 | if apiStubsProvider, ok := dep.(ApiStubsProvider); ok { | 
| Jihoon Kang | ee11328 | 2024-01-23 00:16:41 +0000 | [diff] [blame] | 759 | err := action(apiStubsProvider) | 
|  | 760 | if err != nil { | 
|  | 761 | return err | 
|  | 762 | } | 
| Jihoon Kang | f55a5f7 | 2024-01-08 08:56:20 +0000 | [diff] [blame] | 763 | return nil | 
|  | 764 | } else { | 
|  | 765 | return fmt.Errorf("expected module that implements ExportableApiStubsSrcProvider, e.g. droidstubs") | 
|  | 766 | } | 
|  | 767 | } | 
|  | 768 |  | 
| Jihoon Kang | ee11328 | 2024-01-23 00:16:41 +0000 | [diff] [blame] | 769 | func (paths *scopePaths) treatDepAsApiStubsSrcProvider(dep android.Module, action func(provider ApiStubsSrcProvider) error) error { | 
| Paul Duffin | 0f8faff | 2020-05-20 16:18:00 +0100 | [diff] [blame] | 770 | if apiStubsProvider, ok := dep.(ApiStubsSrcProvider); ok { | 
| Jihoon Kang | ee11328 | 2024-01-23 00:16:41 +0000 | [diff] [blame] | 771 | err := action(apiStubsProvider) | 
|  | 772 | if err != nil { | 
|  | 773 | return err | 
|  | 774 | } | 
| Paul Duffin | 0f8faff | 2020-05-20 16:18:00 +0100 | [diff] [blame] | 775 | return nil | 
|  | 776 | } else { | 
|  | 777 | return fmt.Errorf("expected module that implements ApiStubsSrcProvider, e.g. droidstubs") | 
|  | 778 | } | 
|  | 779 | } | 
|  | 780 |  | 
| Jihoon Kang | ee11328 | 2024-01-23 00:16:41 +0000 | [diff] [blame] | 781 | func (paths *scopePaths) extractApiInfoFromApiStubsProvider(provider ApiStubsProvider, stubsType StubsType) error { | 
|  | 782 | var annotationsZip, currentApiFilePath, removedApiFilePath android.Path | 
|  | 783 | annotationsZip, annotationsZipErr := provider.AnnotationsZip(stubsType) | 
|  | 784 | currentApiFilePath, currentApiFilePathErr := provider.ApiFilePath(stubsType) | 
|  | 785 | removedApiFilePath, removedApiFilePathErr := provider.RemovedApiFilePath(stubsType) | 
| Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 786 |  | 
| Jihoon Kang | ee11328 | 2024-01-23 00:16:41 +0000 | [diff] [blame] | 787 | combinedError := errors.Join(annotationsZipErr, currentApiFilePathErr, removedApiFilePathErr) | 
|  | 788 |  | 
|  | 789 | if combinedError == nil { | 
|  | 790 | paths.annotationsZip = android.OptionalPathForPath(annotationsZip) | 
|  | 791 | paths.currentApiFilePath = android.OptionalPathForPath(currentApiFilePath) | 
|  | 792 | paths.removedApiFilePath = android.OptionalPathForPath(removedApiFilePath) | 
|  | 793 | } | 
|  | 794 | return combinedError | 
| Jihoon Kang | f55a5f7 | 2024-01-08 08:56:20 +0000 | [diff] [blame] | 795 | } | 
|  | 796 |  | 
| Colin Cross | dcf71b2 | 2021-02-01 13:59:03 -0800 | [diff] [blame] | 797 | func (paths *scopePaths) extractApiInfoFromDep(ctx android.ModuleContext, dep android.Module) error { | 
| Jihoon Kang | ee11328 | 2024-01-23 00:16:41 +0000 | [diff] [blame] | 798 | return paths.treatDepAsApiStubsProvider(dep, func(provider ApiStubsProvider) error { | 
|  | 799 | return paths.extractApiInfoFromApiStubsProvider(provider, Everything) | 
| Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 800 | }) | 
|  | 801 | } | 
|  | 802 |  | 
| Jihoon Kang | ee11328 | 2024-01-23 00:16:41 +0000 | [diff] [blame] | 803 | func (paths *scopePaths) extractStubsSourceInfoFromApiStubsProviders(provider ApiStubsSrcProvider, stubsType StubsType) error { | 
|  | 804 | stubsSrcJar, err := provider.StubsSrcJar(stubsType) | 
|  | 805 | if err == nil { | 
|  | 806 | paths.stubsSrcJar = android.OptionalPathForPath(stubsSrcJar) | 
|  | 807 | } | 
|  | 808 | return err | 
| Jihoon Kang | f55a5f7 | 2024-01-08 08:56:20 +0000 | [diff] [blame] | 809 | } | 
|  | 810 |  | 
| Colin Cross | dcf71b2 | 2021-02-01 13:59:03 -0800 | [diff] [blame] | 811 | func (paths *scopePaths) extractStubsSourceInfoFromDep(ctx android.ModuleContext, dep android.Module) error { | 
| Jihoon Kang | ee11328 | 2024-01-23 00:16:41 +0000 | [diff] [blame] | 812 | return paths.treatDepAsApiStubsSrcProvider(dep, func(provider ApiStubsSrcProvider) error { | 
|  | 813 | return paths.extractStubsSourceInfoFromApiStubsProviders(provider, Everything) | 
| Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 814 | }) | 
|  | 815 | } | 
|  | 816 |  | 
| Colin Cross | dcf71b2 | 2021-02-01 13:59:03 -0800 | [diff] [blame] | 817 | func (paths *scopePaths) extractStubsSourceAndApiInfoFromApiStubsProvider(ctx android.ModuleContext, dep android.Module) error { | 
| Jihoon Kang | f55a5f7 | 2024-01-08 08:56:20 +0000 | [diff] [blame] | 818 | if ctx.Config().ReleaseHiddenApiExportableStubs() { | 
| Jihoon Kang | ee11328 | 2024-01-23 00:16:41 +0000 | [diff] [blame] | 819 | return paths.treatDepAsApiStubsProvider(dep, func(provider ApiStubsProvider) error { | 
|  | 820 | extractApiInfoErr := paths.extractApiInfoFromApiStubsProvider(provider, Exportable) | 
|  | 821 | extractStubsSourceInfoErr := paths.extractStubsSourceInfoFromApiStubsProviders(provider, Exportable) | 
|  | 822 | return errors.Join(extractApiInfoErr, extractStubsSourceInfoErr) | 
| Jihoon Kang | f55a5f7 | 2024-01-08 08:56:20 +0000 | [diff] [blame] | 823 | }) | 
|  | 824 | } | 
| Jihoon Kang | ee11328 | 2024-01-23 00:16:41 +0000 | [diff] [blame] | 825 | return paths.treatDepAsApiStubsProvider(dep, func(provider ApiStubsProvider) error { | 
|  | 826 | extractApiInfoErr := paths.extractApiInfoFromApiStubsProvider(provider, Everything) | 
|  | 827 | extractStubsSourceInfoErr := paths.extractStubsSourceInfoFromApiStubsProviders(provider, Everything) | 
|  | 828 | return errors.Join(extractApiInfoErr, extractStubsSourceInfoErr) | 
| Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 829 | }) | 
|  | 830 | } | 
|  | 831 |  | 
| Jihoon Kang | 5623e54 | 2024-01-31 23:27:26 +0000 | [diff] [blame] | 832 | func extractOutputPaths(dep android.Module) (android.Paths, error) { | 
| Paul Duffin | 958806b | 2022-05-16 13:10:47 +0000 | [diff] [blame] | 833 | var paths android.Paths | 
|  | 834 | if sourceFileProducer, ok := dep.(android.SourceFileProducer); ok { | 
|  | 835 | paths = sourceFileProducer.Srcs() | 
| Jihoon Kang | 5623e54 | 2024-01-31 23:27:26 +0000 | [diff] [blame] | 836 | return paths, nil | 
| Paul Duffin | 958806b | 2022-05-16 13:10:47 +0000 | [diff] [blame] | 837 | } else { | 
| Jihoon Kang | 5623e54 | 2024-01-31 23:27:26 +0000 | [diff] [blame] | 838 | return nil, fmt.Errorf("module %q does not produce source files", dep) | 
| Paul Duffin | 958806b | 2022-05-16 13:10:47 +0000 | [diff] [blame] | 839 | } | 
| Paul Duffin | 958806b | 2022-05-16 13:10:47 +0000 | [diff] [blame] | 840 | } | 
|  | 841 |  | 
|  | 842 | func (paths *scopePaths) extractLatestApiPath(ctx android.ModuleContext, dep android.Module) error { | 
| Jihoon Kang | 5623e54 | 2024-01-31 23:27:26 +0000 | [diff] [blame] | 843 | outputPaths, err := extractOutputPaths(dep) | 
|  | 844 | paths.latestApiPaths = outputPaths | 
| Paul Duffin | 958806b | 2022-05-16 13:10:47 +0000 | [diff] [blame] | 845 | return err | 
|  | 846 | } | 
|  | 847 |  | 
|  | 848 | func (paths *scopePaths) extractLatestRemovedApiPath(ctx android.ModuleContext, dep android.Module) error { | 
| Jihoon Kang | 5623e54 | 2024-01-31 23:27:26 +0000 | [diff] [blame] | 849 | outputPaths, err := extractOutputPaths(dep) | 
|  | 850 | paths.latestRemovedApiPaths = outputPaths | 
| Paul Duffin | 958806b | 2022-05-16 13:10:47 +0000 | [diff] [blame] | 851 | return err | 
|  | 852 | } | 
|  | 853 |  | 
| Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 854 | type commonToSdkLibraryAndImportProperties struct { | 
| Paul Duffin | 1b1e806 | 2020-05-08 13:44:43 +0100 | [diff] [blame] | 855 | // The naming scheme to use for the components that this module creates. | 
|  | 856 | // | 
| Paul Duffin | ee9ad5d | 2020-09-11 13:04:05 +0100 | [diff] [blame] | 857 | // If not specified then it defaults to "default". | 
| Paul Duffin | 1b1e806 | 2020-05-08 13:44:43 +0100 | [diff] [blame] | 858 | // | 
|  | 859 | // This is a temporary mechanism to simplify conversion from separate modules for each | 
|  | 860 | // component that follow a different naming pattern to the default one. | 
|  | 861 | // | 
|  | 862 | // TODO(b/155480189) - Remove once naming inconsistencies have been resolved. | 
| Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 863 | Naming_scheme *string | 
| Paul Duffin | dfa131e | 2020-05-15 20:37:11 +0100 | [diff] [blame] | 864 |  | 
|  | 865 | // Specifies whether this module can be used as an Android shared library; defaults | 
|  | 866 | // to true. | 
|  | 867 | // | 
|  | 868 | // An Android shared library is one that can be referenced in a <uses-library> element | 
|  | 869 | // in an AndroidManifest.xml. | 
|  | 870 | Shared_library *bool | 
| Paul Duffin | a2ae7e0 | 2020-09-11 11:55:00 +0100 | [diff] [blame] | 871 |  | 
|  | 872 | // Files containing information about supported java doc tags. | 
|  | 873 | Doctag_files []string `android:"path"` | 
| Pedro Loureiro | 9956e5e | 2021-09-07 17:21:59 +0000 | [diff] [blame] | 874 |  | 
|  | 875 | // Signals that this shared library is part of the bootclasspath starting | 
|  | 876 | // on the version indicated in this attribute. | 
|  | 877 | // | 
|  | 878 | // This will make platforms at this level and above to ignore | 
|  | 879 | // <uses-library> tags with this library name because the library is already | 
|  | 880 | // available | 
|  | 881 | On_bootclasspath_since *string | 
|  | 882 |  | 
|  | 883 | // Signals that this shared library was part of the bootclasspath before | 
|  | 884 | // (but not including) the version indicated in this attribute. | 
|  | 885 | // | 
|  | 886 | // The system will automatically add a <uses-library> tag with this library to | 
|  | 887 | // apps that target any SDK less than the version indicated in this attribute. | 
|  | 888 | On_bootclasspath_before *string | 
|  | 889 |  | 
|  | 890 | // Indicates that PackageManager should ignore this shared library if the | 
|  | 891 | // platform is below the version indicated in this attribute. | 
|  | 892 | // | 
|  | 893 | // This means that the device won't recognise this library as installed. | 
|  | 894 | Min_device_sdk *string | 
|  | 895 |  | 
|  | 896 | // Indicates that PackageManager should ignore this shared library if the | 
|  | 897 | // platform is above the version indicated in this attribute. | 
|  | 898 | // | 
|  | 899 | // This means that the device won't recognise this library as installed. | 
|  | 900 | Max_device_sdk *string | 
| Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 901 | } | 
|  | 902 |  | 
| Paul Duffin | 71b33cc | 2021-06-23 11:39:47 +0100 | [diff] [blame] | 903 | // commonSdkLibraryAndImportModule defines the interface that must be provided by a module that | 
|  | 904 | // embeds the commonToSdkLibraryAndImport struct. | 
|  | 905 | type commonSdkLibraryAndImportModule interface { | 
| Paul Duffin | d796f6f | 2022-11-23 23:06:05 +0000 | [diff] [blame] | 906 | android.Module | 
| Paul Duffin | 71b33cc | 2021-06-23 11:39:47 +0100 | [diff] [blame] | 907 |  | 
| Spandan Das | 23956d1 | 2024-01-19 00:22:22 +0000 | [diff] [blame] | 908 | // Returns the name of the root java_sdk_library that creates the child stub libraries | 
|  | 909 | // This is the `name` as it appears in Android.bp, and not the name in Soong's build graph | 
|  | 910 | // (with the prebuilt_ prefix) | 
|  | 911 | // | 
|  | 912 | // e.g. in the following java_sdk_library_import | 
|  | 913 | // java_sdk_library_import { | 
|  | 914 | //    name: "framework-foo.v1", | 
|  | 915 | //    source_module_name: "framework-foo", | 
|  | 916 | // } | 
|  | 917 | // the values returned by | 
|  | 918 | // 1. Name(): prebuilt_framework-foo.v1 # unique | 
|  | 919 | // 2. BaseModuleName(): framework-foo # the source | 
|  | 920 | // 3. RootLibraryName: framework-foo.v1 # the undecordated `name` from Android.bp | 
|  | 921 | RootLibraryName() string | 
|  | 922 | } | 
|  | 923 |  | 
|  | 924 | func (m *SdkLibrary) RootLibraryName() string { | 
|  | 925 | return m.BaseModuleName() | 
|  | 926 | } | 
|  | 927 |  | 
|  | 928 | func (m *SdkLibraryImport) RootLibraryName() string { | 
|  | 929 | // m.BaseModuleName refers to the source of the import | 
|  | 930 | // use moduleBase.Name to get the name of the module as it appears in the .bp file | 
|  | 931 | return m.ModuleBase.Name() | 
| Paul Duffin | 71b33cc | 2021-06-23 11:39:47 +0100 | [diff] [blame] | 932 | } | 
|  | 933 |  | 
| Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 934 | // Common code between sdk library and sdk library import | 
|  | 935 | type commonToSdkLibraryAndImport struct { | 
| Paul Duffin | 71b33cc | 2021-06-23 11:39:47 +0100 | [diff] [blame] | 936 | module commonSdkLibraryAndImportModule | 
| Paul Duffin | c3091c8 | 2020-05-08 14:16:20 +0100 | [diff] [blame] | 937 |  | 
| Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 938 | scopePaths map[*apiScope]*scopePaths | 
| Paul Duffin | 1b1e806 | 2020-05-08 13:44:43 +0100 | [diff] [blame] | 939 |  | 
|  | 940 | namingScheme sdkLibraryComponentNamingScheme | 
|  | 941 |  | 
| Paul Duffin | dfa131e | 2020-05-15 20:37:11 +0100 | [diff] [blame] | 942 | commonSdkLibraryProperties commonToSdkLibraryAndImportProperties | 
| Paul Duffin | 859fe96 | 2020-05-15 10:20:31 +0100 | [diff] [blame] | 943 |  | 
| Paul Duffin | a2ae7e0 | 2020-09-11 11:55:00 +0100 | [diff] [blame] | 944 | // Paths to commonSdkLibraryProperties.Doctag_files | 
|  | 945 | doctagPaths android.Paths | 
|  | 946 |  | 
| Paul Duffin | 859fe96 | 2020-05-15 10:20:31 +0100 | [diff] [blame] | 947 | // Functionality related to this being used as a component of a java_sdk_library. | 
|  | 948 | EmbeddableSdkLibraryComponent | 
| Jihoon Kang | 8479dea | 2024-04-04 01:19:05 +0000 | [diff] [blame] | 949 |  | 
|  | 950 | // Path to the header jars of the implementation library | 
|  | 951 | // This is non-empty only when api_only is false. | 
|  | 952 | implLibraryHeaderJars android.Paths | 
| Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 953 | } | 
|  | 954 |  | 
| Paul Duffin | 71b33cc | 2021-06-23 11:39:47 +0100 | [diff] [blame] | 955 | func (c *commonToSdkLibraryAndImport) initCommon(module commonSdkLibraryAndImportModule) { | 
|  | 956 | c.module = module | 
| Paul Duffin | 1b1e806 | 2020-05-08 13:44:43 +0100 | [diff] [blame] | 957 |  | 
| Paul Duffin | 71b33cc | 2021-06-23 11:39:47 +0100 | [diff] [blame] | 958 | module.AddProperties(&c.commonSdkLibraryProperties) | 
| Paul Duffin | 859fe96 | 2020-05-15 10:20:31 +0100 | [diff] [blame] | 959 |  | 
|  | 960 | // Initialize this as an sdk library component. | 
| Paul Duffin | 71b33cc | 2021-06-23 11:39:47 +0100 | [diff] [blame] | 961 | c.initSdkLibraryComponent(module) | 
| Paul Duffin | 1b1e806 | 2020-05-08 13:44:43 +0100 | [diff] [blame] | 962 | } | 
|  | 963 |  | 
|  | 964 | func (c *commonToSdkLibraryAndImport) initCommonAfterDefaultsApplied(ctx android.DefaultableHookContext) bool { | 
| Paul Duffin | dfa131e | 2020-05-15 20:37:11 +0100 | [diff] [blame] | 965 | schemeProperty := proptools.StringDefault(c.commonSdkLibraryProperties.Naming_scheme, "default") | 
| Paul Duffin | 1b1e806 | 2020-05-08 13:44:43 +0100 | [diff] [blame] | 966 | switch schemeProperty { | 
|  | 967 | case "default": | 
|  | 968 | c.namingScheme = &defaultNamingScheme{} | 
|  | 969 | default: | 
|  | 970 | ctx.PropertyErrorf("naming_scheme", "expected 'default' but was %q", schemeProperty) | 
|  | 971 | return false | 
|  | 972 | } | 
|  | 973 |  | 
| Spandan Das | 23956d1 | 2024-01-19 00:22:22 +0000 | [diff] [blame] | 974 | namePtr := proptools.StringPtr(c.module.RootLibraryName()) | 
| Paul Duffin | 3f0290e | 2021-06-30 18:25:36 +0100 | [diff] [blame] | 975 | c.sdkLibraryComponentProperties.SdkLibraryName = namePtr | 
|  | 976 |  | 
| Paul Duffin | dfa131e | 2020-05-15 20:37:11 +0100 | [diff] [blame] | 977 | // Only track this sdk library if this can be used as a shared library. | 
|  | 978 | if c.sharedLibrary() { | 
|  | 979 | // Use the name specified in the module definition as the owner. | 
| Paul Duffin | 3f0290e | 2021-06-30 18:25:36 +0100 | [diff] [blame] | 980 | c.sdkLibraryComponentProperties.SdkLibraryToImplicitlyTrack = namePtr | 
| Paul Duffin | dfa131e | 2020-05-15 20:37:11 +0100 | [diff] [blame] | 981 | } | 
| Paul Duffin | 859fe96 | 2020-05-15 10:20:31 +0100 | [diff] [blame] | 982 |  | 
| Paul Duffin | 1b1e806 | 2020-05-08 13:44:43 +0100 | [diff] [blame] | 983 | return true | 
| Paul Duffin | c3091c8 | 2020-05-08 14:16:20 +0100 | [diff] [blame] | 984 | } | 
|  | 985 |  | 
| Paul Duffin | ea8f808 | 2021-06-24 13:25:57 +0100 | [diff] [blame] | 986 | // uniqueApexVariations provides common implementation of the ApexModule.UniqueApexVariations | 
|  | 987 | // method. | 
|  | 988 | func (c *commonToSdkLibraryAndImport) uniqueApexVariations() bool { | 
|  | 989 | // A java_sdk_library that is a shared library produces an XML file that makes the shared library | 
|  | 990 | // usable from an AndroidManifest.xml's <uses-library> entry. That XML file contains the name of | 
|  | 991 | // the APEX and so it needs a unique variation per APEX. | 
|  | 992 | return c.sharedLibrary() | 
|  | 993 | } | 
|  | 994 |  | 
| Paul Duffin | a2ae7e0 | 2020-09-11 11:55:00 +0100 | [diff] [blame] | 995 | func (c *commonToSdkLibraryAndImport) generateCommonBuildActions(ctx android.ModuleContext) { | 
|  | 996 | c.doctagPaths = android.PathsForModuleSrc(ctx, c.commonSdkLibraryProperties.Doctag_files) | 
|  | 997 | } | 
|  | 998 |  | 
| Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 999 | // Module name of the runtime implementation library | 
|  | 1000 | func (c *commonToSdkLibraryAndImport) implLibraryModuleName() string { | 
| Spandan Das | 23956d1 | 2024-01-19 00:22:22 +0000 | [diff] [blame] | 1001 | return c.module.RootLibraryName() + ".impl" | 
| Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 1002 | } | 
|  | 1003 |  | 
|  | 1004 | // Module name of the XML file for the lib | 
|  | 1005 | func (c *commonToSdkLibraryAndImport) xmlPermissionsModuleName() string { | 
| Spandan Das | 23956d1 | 2024-01-19 00:22:22 +0000 | [diff] [blame] | 1006 | return c.module.RootLibraryName() + sdkXmlFileSuffix | 
| Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 1007 | } | 
|  | 1008 |  | 
| Paul Duffin | c3091c8 | 2020-05-08 14:16:20 +0100 | [diff] [blame] | 1009 | // Name of the java_library module that compiles the stubs source. | 
|  | 1010 | func (c *commonToSdkLibraryAndImport) stubsLibraryModuleName(apiScope *apiScope) string { | 
| Spandan Das | 23956d1 | 2024-01-19 00:22:22 +0000 | [diff] [blame] | 1011 | baseName := c.module.RootLibraryName() | 
| Paul Duffin | 2178762 | 2022-11-25 12:48:20 +0000 | [diff] [blame] | 1012 | return c.namingScheme.stubsLibraryModuleName(apiScope, baseName) | 
| Paul Duffin | c3091c8 | 2020-05-08 14:16:20 +0100 | [diff] [blame] | 1013 | } | 
|  | 1014 |  | 
| Jihoon Kang | fa4a90d | 2023-12-20 02:53:38 +0000 | [diff] [blame] | 1015 | // Name of the java_library module that compiles the exportable stubs source. | 
|  | 1016 | func (c *commonToSdkLibraryAndImport) exportableStubsLibraryModuleName(apiScope *apiScope) string { | 
| Spandan Das | 23956d1 | 2024-01-19 00:22:22 +0000 | [diff] [blame] | 1017 | baseName := c.module.RootLibraryName() | 
| Jihoon Kang | fa4a90d | 2023-12-20 02:53:38 +0000 | [diff] [blame] | 1018 | return c.namingScheme.exportableStubsLibraryModuleName(apiScope, baseName) | 
|  | 1019 | } | 
|  | 1020 |  | 
| Paul Duffin | c3091c8 | 2020-05-08 14:16:20 +0100 | [diff] [blame] | 1021 | // Name of the droidstubs module that generates the stubs source and may also | 
|  | 1022 | // generate/check the API. | 
|  | 1023 | func (c *commonToSdkLibraryAndImport) stubsSourceModuleName(apiScope *apiScope) string { | 
| Spandan Das | 23956d1 | 2024-01-19 00:22:22 +0000 | [diff] [blame] | 1024 | baseName := c.module.RootLibraryName() | 
| Paul Duffin | 2178762 | 2022-11-25 12:48:20 +0000 | [diff] [blame] | 1025 | return c.namingScheme.stubsSourceModuleName(apiScope, baseName) | 
| Paul Duffin | c3091c8 | 2020-05-08 14:16:20 +0100 | [diff] [blame] | 1026 | } | 
|  | 1027 |  | 
| Jihoon Kang | 1c92c3e | 2023-03-23 17:44:51 +0000 | [diff] [blame] | 1028 | // Name of the java_api_library module that generates the from-text stubs source | 
|  | 1029 | // and compiles to a jar file. | 
|  | 1030 | func (c *commonToSdkLibraryAndImport) apiLibraryModuleName(apiScope *apiScope) string { | 
| Spandan Das | 23956d1 | 2024-01-19 00:22:22 +0000 | [diff] [blame] | 1031 | baseName := c.module.RootLibraryName() | 
| Jihoon Kang | 1c92c3e | 2023-03-23 17:44:51 +0000 | [diff] [blame] | 1032 | return c.namingScheme.apiLibraryModuleName(apiScope, baseName) | 
|  | 1033 | } | 
|  | 1034 |  | 
| Jihoon Kang | 1147b31 | 2023-06-08 23:25:57 +0000 | [diff] [blame] | 1035 | // Name of the java_library module that compiles the stubs | 
|  | 1036 | // generated from source Java files. | 
| Jihoon Kang | fa4a90d | 2023-12-20 02:53:38 +0000 | [diff] [blame] | 1037 | func (c *commonToSdkLibraryAndImport) sourceStubsLibraryModuleName(apiScope *apiScope) string { | 
| Spandan Das | 23956d1 | 2024-01-19 00:22:22 +0000 | [diff] [blame] | 1038 | baseName := c.module.RootLibraryName() | 
| Jihoon Kang | fa4a90d | 2023-12-20 02:53:38 +0000 | [diff] [blame] | 1039 | return c.namingScheme.sourceStubsLibraryModuleName(apiScope, baseName) | 
|  | 1040 | } | 
|  | 1041 |  | 
|  | 1042 | // Name of the java_library module that compiles the exportable stubs | 
|  | 1043 | // generated from source Java files. | 
|  | 1044 | func (c *commonToSdkLibraryAndImport) exportableSourceStubsLibraryModuleName(apiScope *apiScope) string { | 
| Spandan Das | 23956d1 | 2024-01-19 00:22:22 +0000 | [diff] [blame] | 1045 | baseName := c.module.RootLibraryName() | 
| Jihoon Kang | fa4a90d | 2023-12-20 02:53:38 +0000 | [diff] [blame] | 1046 | return c.namingScheme.exportableSourceStubsLibraryModuleName(apiScope, baseName) | 
| Jihoon Kang | 1147b31 | 2023-06-08 23:25:57 +0000 | [diff] [blame] | 1047 | } | 
|  | 1048 |  | 
| Paul Duffin | 46dc45a | 2020-05-14 15:39:10 +0100 | [diff] [blame] | 1049 | // The component names for different outputs of the java_sdk_library. | 
|  | 1050 | // | 
|  | 1051 | // They are similar to the names used for the child modules it creates | 
|  | 1052 | const ( | 
|  | 1053 | stubsSourceComponentName = "stubs.source" | 
|  | 1054 |  | 
|  | 1055 | apiTxtComponentName = "api.txt" | 
|  | 1056 |  | 
|  | 1057 | removedApiTxtComponentName = "removed-api.txt" | 
| Anton Hansson | d78eb76 | 2021-09-21 15:25:12 +0100 | [diff] [blame] | 1058 |  | 
|  | 1059 | annotationsComponentName = "annotations.zip" | 
| Paul Duffin | 46dc45a | 2020-05-14 15:39:10 +0100 | [diff] [blame] | 1060 | ) | 
|  | 1061 |  | 
|  | 1062 | // A regular expression to match tags that reference a specific stubs component. | 
|  | 1063 | // | 
|  | 1064 | // It will only match if given a valid scope and a valid component. It is verfy strict | 
|  | 1065 | // to ensure it does not accidentally match a similar looking tag that should be processed | 
|  | 1066 | // by the embedded Library. | 
|  | 1067 | var tagSplitter = func() *regexp.Regexp { | 
|  | 1068 | // Given a list of literal string items returns a regular expression that will | 
|  | 1069 | // match any one of the items. | 
|  | 1070 | choice := func(items ...string) string { | 
|  | 1071 | return `\Q` + strings.Join(items, `\E|\Q`) + `\E` | 
|  | 1072 | } | 
|  | 1073 |  | 
|  | 1074 | // Regular expression to match one of the scopes. | 
|  | 1075 | scopesRegexp := choice(allScopeNames...) | 
|  | 1076 |  | 
|  | 1077 | // Regular expression to match one of the components. | 
| Anton Hansson | d78eb76 | 2021-09-21 15:25:12 +0100 | [diff] [blame] | 1078 | componentsRegexp := choice(stubsSourceComponentName, apiTxtComponentName, removedApiTxtComponentName, annotationsComponentName) | 
| Paul Duffin | 46dc45a | 2020-05-14 15:39:10 +0100 | [diff] [blame] | 1079 |  | 
|  | 1080 | // Regular expression to match any combination of one scope and one component. | 
|  | 1081 | return regexp.MustCompile(fmt.Sprintf(`^\.(%s)\.(%s)$`, scopesRegexp, componentsRegexp)) | 
|  | 1082 | }() | 
|  | 1083 |  | 
|  | 1084 | // For OutputFileProducer interface | 
|  | 1085 | // | 
| Anton Hansson | d78eb76 | 2021-09-21 15:25:12 +0100 | [diff] [blame] | 1086 | // .<scope>.<component name>, for all ComponentNames (for example: .public.removed-api.txt) | 
| Paul Duffin | 46dc45a | 2020-05-14 15:39:10 +0100 | [diff] [blame] | 1087 | func (c *commonToSdkLibraryAndImport) commonOutputFiles(tag string) (android.Paths, error) { | 
|  | 1088 | if groups := tagSplitter.FindStringSubmatch(tag); groups != nil { | 
|  | 1089 | scopeName := groups[1] | 
|  | 1090 | component := groups[2] | 
|  | 1091 |  | 
|  | 1092 | if scope, ok := scopeByName[scopeName]; ok { | 
|  | 1093 | paths := c.findScopePaths(scope) | 
|  | 1094 | if paths == nil { | 
| Spandan Das | 23956d1 | 2024-01-19 00:22:22 +0000 | [diff] [blame] | 1095 | return nil, fmt.Errorf("%q does not provide api scope %s", c.module.RootLibraryName(), scopeName) | 
| Paul Duffin | 46dc45a | 2020-05-14 15:39:10 +0100 | [diff] [blame] | 1096 | } | 
|  | 1097 |  | 
|  | 1098 | switch component { | 
|  | 1099 | case stubsSourceComponentName: | 
|  | 1100 | if paths.stubsSrcJar.Valid() { | 
|  | 1101 | return android.Paths{paths.stubsSrcJar.Path()}, nil | 
|  | 1102 | } | 
|  | 1103 |  | 
|  | 1104 | case apiTxtComponentName: | 
|  | 1105 | if paths.currentApiFilePath.Valid() { | 
|  | 1106 | return android.Paths{paths.currentApiFilePath.Path()}, nil | 
|  | 1107 | } | 
|  | 1108 |  | 
|  | 1109 | case removedApiTxtComponentName: | 
|  | 1110 | if paths.removedApiFilePath.Valid() { | 
|  | 1111 | return android.Paths{paths.removedApiFilePath.Path()}, nil | 
|  | 1112 | } | 
| Anton Hansson | d78eb76 | 2021-09-21 15:25:12 +0100 | [diff] [blame] | 1113 |  | 
|  | 1114 | case annotationsComponentName: | 
|  | 1115 | if paths.annotationsZip.Valid() { | 
|  | 1116 | return android.Paths{paths.annotationsZip.Path()}, nil | 
|  | 1117 | } | 
| Paul Duffin | 46dc45a | 2020-05-14 15:39:10 +0100 | [diff] [blame] | 1118 | } | 
|  | 1119 |  | 
|  | 1120 | return nil, fmt.Errorf("%s not available for api scope %s", component, scopeName) | 
|  | 1121 | } else { | 
|  | 1122 | return nil, fmt.Errorf("unknown scope %s in %s", scope, tag) | 
|  | 1123 | } | 
|  | 1124 |  | 
|  | 1125 | } else { | 
| Paul Duffin | a2ae7e0 | 2020-09-11 11:55:00 +0100 | [diff] [blame] | 1126 | switch tag { | 
|  | 1127 | case ".doctags": | 
|  | 1128 | if c.doctagPaths != nil { | 
|  | 1129 | return c.doctagPaths, nil | 
|  | 1130 | } else { | 
| Spandan Das | 23956d1 | 2024-01-19 00:22:22 +0000 | [diff] [blame] | 1131 | return nil, fmt.Errorf("no doctag_files specified on %s", c.module.RootLibraryName()) | 
| Paul Duffin | a2ae7e0 | 2020-09-11 11:55:00 +0100 | [diff] [blame] | 1132 | } | 
|  | 1133 | } | 
| Paul Duffin | 46dc45a | 2020-05-14 15:39:10 +0100 | [diff] [blame] | 1134 | return nil, nil | 
|  | 1135 | } | 
|  | 1136 | } | 
|  | 1137 |  | 
| Paul Duffin | 803a956 | 2020-05-20 11:52:25 +0100 | [diff] [blame] | 1138 | func (c *commonToSdkLibraryAndImport) getScopePathsCreateIfNeeded(scope *apiScope) *scopePaths { | 
| Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 1139 | if c.scopePaths == nil { | 
|  | 1140 | c.scopePaths = make(map[*apiScope]*scopePaths) | 
|  | 1141 | } | 
|  | 1142 | paths := c.scopePaths[scope] | 
|  | 1143 | if paths == nil { | 
|  | 1144 | paths = &scopePaths{} | 
|  | 1145 | c.scopePaths[scope] = paths | 
|  | 1146 | } | 
|  | 1147 |  | 
|  | 1148 | return paths | 
|  | 1149 | } | 
|  | 1150 |  | 
| Paul Duffin | 803a956 | 2020-05-20 11:52:25 +0100 | [diff] [blame] | 1151 | func (c *commonToSdkLibraryAndImport) findScopePaths(scope *apiScope) *scopePaths { | 
|  | 1152 | if c.scopePaths == nil { | 
|  | 1153 | return nil | 
|  | 1154 | } | 
|  | 1155 |  | 
|  | 1156 | return c.scopePaths[scope] | 
|  | 1157 | } | 
|  | 1158 |  | 
|  | 1159 | // If this does not support the requested api scope then find the closest available | 
|  | 1160 | // scope it does support. Returns nil if no such scope is available. | 
|  | 1161 | func (c *commonToSdkLibraryAndImport) findClosestScopePath(scope *apiScope) *scopePaths { | 
| Paul Duffin | d0b9fca | 2022-09-30 18:11:41 +0100 | [diff] [blame] | 1162 | for s := scope; s != nil; s = s.canAccess { | 
| Paul Duffin | 803a956 | 2020-05-20 11:52:25 +0100 | [diff] [blame] | 1163 | if paths := c.findScopePaths(s); paths != nil { | 
|  | 1164 | return paths | 
|  | 1165 | } | 
|  | 1166 | } | 
|  | 1167 |  | 
|  | 1168 | // This should never happen outside tests as public should be the base scope for every | 
|  | 1169 | // scope and is enabled by default. | 
|  | 1170 | return nil | 
|  | 1171 | } | 
|  | 1172 |  | 
| Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 1173 | func (c *commonToSdkLibraryAndImport) selectHeaderJarsForSdkVersion(ctx android.BaseModuleContext, sdkVersion android.SdkSpec) android.Paths { | 
| Paul Duffin | b05d429 | 2020-05-20 12:19:10 +0100 | [diff] [blame] | 1174 |  | 
|  | 1175 | // If a specific numeric version has been requested then use prebuilt versions of the sdk. | 
| Jiyong Park | 54105c4 | 2021-03-31 18:17:53 +0900 | [diff] [blame] | 1176 | if !sdkVersion.ApiLevel.IsPreview() { | 
| Spandan Das | 23956d1 | 2024-01-19 00:22:22 +0000 | [diff] [blame] | 1177 | return PrebuiltJars(ctx, c.module.RootLibraryName(), sdkVersion) | 
| Paul Duffin | b05d429 | 2020-05-20 12:19:10 +0100 | [diff] [blame] | 1178 | } | 
|  | 1179 |  | 
| Paul Duffin | 1267d87 | 2021-04-16 17:21:36 +0100 | [diff] [blame] | 1180 | paths := c.selectScopePaths(ctx, sdkVersion.Kind) | 
|  | 1181 | if paths == nil { | 
|  | 1182 | return nil | 
|  | 1183 | } | 
|  | 1184 |  | 
|  | 1185 | return paths.stubsHeaderPath | 
|  | 1186 | } | 
|  | 1187 |  | 
|  | 1188 | // selectScopePaths returns the *scopePaths appropriate for the specific kind. | 
|  | 1189 | // | 
|  | 1190 | // If the module does not support the specific kind then it will return the *scopePaths for the | 
|  | 1191 | // closest kind which is a subset of the requested kind. e.g. if requesting android.SdkModule then | 
|  | 1192 | // it will return *scopePaths for android.SdkSystem if available or android.SdkPublic of not. | 
|  | 1193 | func (c *commonToSdkLibraryAndImport) selectScopePaths(ctx android.BaseModuleContext, kind android.SdkKind) *scopePaths { | 
| Paul Duffin | 32cf58a | 2021-05-18 16:32:50 +0100 | [diff] [blame] | 1194 | apiScope := sdkKindToApiScope(kind) | 
| Paul Duffin | b05d429 | 2020-05-20 12:19:10 +0100 | [diff] [blame] | 1195 |  | 
| Paul Duffin | 803a956 | 2020-05-20 11:52:25 +0100 | [diff] [blame] | 1196 | paths := c.findClosestScopePath(apiScope) | 
|  | 1197 | if paths == nil { | 
|  | 1198 | var scopes []string | 
|  | 1199 | for _, s := range allApiScopes { | 
|  | 1200 | if c.findScopePaths(s) != nil { | 
|  | 1201 | scopes = append(scopes, s.name) | 
|  | 1202 | } | 
|  | 1203 | } | 
| Spandan Das | 23956d1 | 2024-01-19 00:22:22 +0000 | [diff] [blame] | 1204 | ctx.ModuleErrorf("requires api scope %s from %s but it only has %q available", apiScope.name, c.module.RootLibraryName(), scopes) | 
| Paul Duffin | 803a956 | 2020-05-20 11:52:25 +0100 | [diff] [blame] | 1205 | return nil | 
|  | 1206 | } | 
|  | 1207 |  | 
| Paul Duffin | 1267d87 | 2021-04-16 17:21:36 +0100 | [diff] [blame] | 1208 | return paths | 
|  | 1209 | } | 
|  | 1210 |  | 
| Paul Duffin | 32cf58a | 2021-05-18 16:32:50 +0100 | [diff] [blame] | 1211 | // sdkKindToApiScope maps from android.SdkKind to apiScope. | 
|  | 1212 | func sdkKindToApiScope(kind android.SdkKind) *apiScope { | 
|  | 1213 | var apiScope *apiScope | 
|  | 1214 | switch kind { | 
|  | 1215 | case android.SdkSystem: | 
|  | 1216 | apiScope = apiScopeSystem | 
|  | 1217 | case android.SdkModule: | 
|  | 1218 | apiScope = apiScopeModuleLib | 
|  | 1219 | case android.SdkTest: | 
|  | 1220 | apiScope = apiScopeTest | 
|  | 1221 | case android.SdkSystemServer: | 
|  | 1222 | apiScope = apiScopeSystemServer | 
|  | 1223 | default: | 
|  | 1224 | apiScope = apiScopePublic | 
|  | 1225 | } | 
|  | 1226 | return apiScope | 
|  | 1227 | } | 
|  | 1228 |  | 
| Paul Duffin | 1267d87 | 2021-04-16 17:21:36 +0100 | [diff] [blame] | 1229 | // to satisfy SdkLibraryDependency interface | 
| Martin Stjernholm | 8be1e6d | 2021-09-15 03:34:04 +0100 | [diff] [blame] | 1230 | func (c *commonToSdkLibraryAndImport) SdkApiStubDexJar(ctx android.BaseModuleContext, kind android.SdkKind) OptionalDexJarPath { | 
| Paul Duffin | 1267d87 | 2021-04-16 17:21:36 +0100 | [diff] [blame] | 1231 | paths := c.selectScopePaths(ctx, kind) | 
|  | 1232 | if paths == nil { | 
| Martin Stjernholm | 8be1e6d | 2021-09-15 03:34:04 +0100 | [diff] [blame] | 1233 | return makeUnsetDexJarPath() | 
| Paul Duffin | 1267d87 | 2021-04-16 17:21:36 +0100 | [diff] [blame] | 1234 | } | 
|  | 1235 |  | 
|  | 1236 | return paths.stubsDexJarPath | 
| Paul Duffin | b05d429 | 2020-05-20 12:19:10 +0100 | [diff] [blame] | 1237 | } | 
|  | 1238 |  | 
| Paul Duffin | 32cf58a | 2021-05-18 16:32:50 +0100 | [diff] [blame] | 1239 | // to satisfy SdkLibraryDependency interface | 
| Jihoon Kang | bd09345 | 2023-12-26 19:08:01 +0000 | [diff] [blame] | 1240 | func (c *commonToSdkLibraryAndImport) SdkApiExportableStubDexJar(ctx android.BaseModuleContext, kind android.SdkKind) OptionalDexJarPath { | 
|  | 1241 | paths := c.selectScopePaths(ctx, kind) | 
|  | 1242 | if paths == nil { | 
|  | 1243 | return makeUnsetDexJarPath() | 
|  | 1244 | } | 
|  | 1245 |  | 
|  | 1246 | return paths.exportableStubsDexJarPath | 
|  | 1247 | } | 
|  | 1248 |  | 
|  | 1249 | // to satisfy SdkLibraryDependency interface | 
| Paul Duffin | 32cf58a | 2021-05-18 16:32:50 +0100 | [diff] [blame] | 1250 | func (c *commonToSdkLibraryAndImport) SdkRemovedTxtFile(ctx android.BaseModuleContext, kind android.SdkKind) android.OptionalPath { | 
|  | 1251 | apiScope := sdkKindToApiScope(kind) | 
|  | 1252 | paths := c.findScopePaths(apiScope) | 
|  | 1253 | if paths == nil { | 
|  | 1254 | return android.OptionalPath{} | 
|  | 1255 | } | 
|  | 1256 |  | 
|  | 1257 | return paths.removedApiFilePath | 
|  | 1258 | } | 
|  | 1259 |  | 
| Paul Duffin | 859fe96 | 2020-05-15 10:20:31 +0100 | [diff] [blame] | 1260 | func (c *commonToSdkLibraryAndImport) sdkComponentPropertiesForChildLibrary() interface{} { | 
|  | 1261 | componentProps := &struct { | 
| Paul Duffin | 3f0290e | 2021-06-30 18:25:36 +0100 | [diff] [blame] | 1262 | SdkLibraryName              *string | 
| Paul Duffin | 859fe96 | 2020-05-15 10:20:31 +0100 | [diff] [blame] | 1263 | SdkLibraryToImplicitlyTrack *string | 
| Paul Duffin | dfa131e | 2020-05-15 20:37:11 +0100 | [diff] [blame] | 1264 | }{} | 
|  | 1265 |  | 
| Spandan Das | 23956d1 | 2024-01-19 00:22:22 +0000 | [diff] [blame] | 1266 | namePtr := proptools.StringPtr(c.module.RootLibraryName()) | 
| Paul Duffin | 3f0290e | 2021-06-30 18:25:36 +0100 | [diff] [blame] | 1267 | componentProps.SdkLibraryName = namePtr | 
|  | 1268 |  | 
| Paul Duffin | dfa131e | 2020-05-15 20:37:11 +0100 | [diff] [blame] | 1269 | if c.sharedLibrary() { | 
| Paul Duffin | 859fe96 | 2020-05-15 10:20:31 +0100 | [diff] [blame] | 1270 | // Mark the stubs library as being components of this java_sdk_library so that | 
|  | 1271 | // any app that includes code which depends (directly or indirectly) on the stubs | 
|  | 1272 | // library will have the appropriate <uses-library> invocation inserted into its | 
|  | 1273 | // manifest if necessary. | 
| Paul Duffin | 3f0290e | 2021-06-30 18:25:36 +0100 | [diff] [blame] | 1274 | componentProps.SdkLibraryToImplicitlyTrack = namePtr | 
| Paul Duffin | 859fe96 | 2020-05-15 10:20:31 +0100 | [diff] [blame] | 1275 | } | 
|  | 1276 |  | 
|  | 1277 | return componentProps | 
|  | 1278 | } | 
|  | 1279 |  | 
| Paul Duffin | dfa131e | 2020-05-15 20:37:11 +0100 | [diff] [blame] | 1280 | func (c *commonToSdkLibraryAndImport) sharedLibrary() bool { | 
|  | 1281 | return proptools.BoolDefault(c.commonSdkLibraryProperties.Shared_library, true) | 
|  | 1282 | } | 
|  | 1283 |  | 
| Paul Duffin | f4600f6 | 2021-05-13 22:34:45 +0100 | [diff] [blame] | 1284 | // Check if the stub libraries should be compiled for dex | 
|  | 1285 | func (c *commonToSdkLibraryAndImport) stubLibrariesCompiledForDex() bool { | 
|  | 1286 | // Always compile the dex file files for the stub libraries if they will be used on the | 
|  | 1287 | // bootclasspath. | 
|  | 1288 | return !c.sharedLibrary() | 
|  | 1289 | } | 
|  | 1290 |  | 
| Paul Duffin | 859fe96 | 2020-05-15 10:20:31 +0100 | [diff] [blame] | 1291 | // Properties related to the use of a module as an component of a java_sdk_library. | 
|  | 1292 | type SdkLibraryComponentProperties struct { | 
| Paul Duffin | 3f0290e | 2021-06-30 18:25:36 +0100 | [diff] [blame] | 1293 | // The name of the java_sdk_library/_import module. | 
|  | 1294 | SdkLibraryName *string `blueprint:"mutated"` | 
| Paul Duffin | 859fe96 | 2020-05-15 10:20:31 +0100 | [diff] [blame] | 1295 |  | 
|  | 1296 | // The name of the java_sdk_library/_import to add to a <uses-library> entry | 
|  | 1297 | // in the AndroidManifest.xml of any Android app that includes code that references | 
|  | 1298 | // this module. If not set then no java_sdk_library/_import is tracked. | 
|  | 1299 | SdkLibraryToImplicitlyTrack *string `blueprint:"mutated"` | 
|  | 1300 | } | 
|  | 1301 |  | 
|  | 1302 | // Structure to be embedded in a module struct that needs to support the | 
|  | 1303 | // SdkLibraryComponentDependency interface. | 
|  | 1304 | type EmbeddableSdkLibraryComponent struct { | 
|  | 1305 | sdkLibraryComponentProperties SdkLibraryComponentProperties | 
|  | 1306 | } | 
|  | 1307 |  | 
| Paul Duffin | 71b33cc | 2021-06-23 11:39:47 +0100 | [diff] [blame] | 1308 | func (e *EmbeddableSdkLibraryComponent) initSdkLibraryComponent(module android.Module) { | 
|  | 1309 | module.AddProperties(&e.sdkLibraryComponentProperties) | 
| Paul Duffin | 859fe96 | 2020-05-15 10:20:31 +0100 | [diff] [blame] | 1310 | } | 
|  | 1311 |  | 
|  | 1312 | // to satisfy SdkLibraryComponentDependency | 
| Paul Duffin | 3f0290e | 2021-06-30 18:25:36 +0100 | [diff] [blame] | 1313 | func (e *EmbeddableSdkLibraryComponent) SdkLibraryName() *string { | 
|  | 1314 | return e.sdkLibraryComponentProperties.SdkLibraryName | 
|  | 1315 | } | 
|  | 1316 |  | 
|  | 1317 | // to satisfy SdkLibraryComponentDependency | 
| Ulya Trafimovich | 39b437b | 2020-09-23 16:42:35 +0100 | [diff] [blame] | 1318 | func (e *EmbeddableSdkLibraryComponent) OptionalSdkLibraryImplementation() *string { | 
| Ulya Trafimovich | 78645fb | 2021-07-16 15:29:25 +0100 | [diff] [blame] | 1319 | // For shared libraries, this is the same as the SDK library name. If a Java library or app | 
|  | 1320 | // depends on a component library (e.g. a stub library) it still needs to know the name of the | 
|  | 1321 | // run-time library and the corresponding module that provides the implementation. This name is | 
|  | 1322 | // passed to manifest_fixer (to be added to AndroidManifest.xml) and added to CLC (to be used | 
|  | 1323 | // in dexpreopt). | 
|  | 1324 | // | 
|  | 1325 | // For non-shared SDK (component or not) libraries this returns `nil`, as they are not | 
|  | 1326 | // <uses-library> and should not be added to the manifest or to CLC. | 
| Ulya Trafimovich | 39b437b | 2020-09-23 16:42:35 +0100 | [diff] [blame] | 1327 | return e.sdkLibraryComponentProperties.SdkLibraryToImplicitlyTrack | 
|  | 1328 | } | 
|  | 1329 |  | 
| Paul Duffin | 859fe96 | 2020-05-15 10:20:31 +0100 | [diff] [blame] | 1330 | // Implemented by modules that are (or possibly could be) a component of a java_sdk_library | 
|  | 1331 | // (including the java_sdk_library) itself. | 
|  | 1332 | type SdkLibraryComponentDependency interface { | 
| Ulya Trafimovich | 31e444e | 2020-08-14 17:32:16 +0100 | [diff] [blame] | 1333 | UsesLibraryDependency | 
|  | 1334 |  | 
| Paul Duffin | 3f0290e | 2021-06-30 18:25:36 +0100 | [diff] [blame] | 1335 | // SdkLibraryName returns the name of the java_sdk_library/_import module. | 
|  | 1336 | SdkLibraryName() *string | 
|  | 1337 |  | 
| Ulya Trafimovich | 39b437b | 2020-09-23 16:42:35 +0100 | [diff] [blame] | 1338 | // The name of the implementation library for the optional SDK library or nil, if there isn't one. | 
|  | 1339 | OptionalSdkLibraryImplementation() *string | 
| Paul Duffin | 859fe96 | 2020-05-15 10:20:31 +0100 | [diff] [blame] | 1340 | } | 
|  | 1341 |  | 
|  | 1342 | // Make sure that all the module types that are components of java_sdk_library/_import | 
|  | 1343 | // and which can be referenced (directly or indirectly) from an android app implement | 
|  | 1344 | // the SdkLibraryComponentDependency interface. | 
|  | 1345 | var _ SdkLibraryComponentDependency = (*Library)(nil) | 
|  | 1346 | var _ SdkLibraryComponentDependency = (*Import)(nil) | 
|  | 1347 | var _ SdkLibraryComponentDependency = (*SdkLibrary)(nil) | 
| Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 1348 | var _ SdkLibraryComponentDependency = (*SdkLibraryImport)(nil) | 
| Paul Duffin | 859fe96 | 2020-05-15 10:20:31 +0100 | [diff] [blame] | 1349 |  | 
| Paul Duffin | 32cf58a | 2021-05-18 16:32:50 +0100 | [diff] [blame] | 1350 | // Provides access to sdk_version related files, e.g. header and implementation jars. | 
| Paul Duffin | 859fe96 | 2020-05-15 10:20:31 +0100 | [diff] [blame] | 1351 | type SdkLibraryDependency interface { | 
|  | 1352 | SdkLibraryComponentDependency | 
|  | 1353 |  | 
|  | 1354 | // Get the header jars appropriate for the supplied sdk_version. | 
|  | 1355 | // | 
|  | 1356 | // These are turbine generated jars so they only change if the externals of the | 
|  | 1357 | // class changes but it does not contain and implementation or JavaDoc. | 
| Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 1358 | SdkHeaderJars(ctx android.BaseModuleContext, sdkVersion android.SdkSpec) android.Paths | 
| Paul Duffin | 859fe96 | 2020-05-15 10:20:31 +0100 | [diff] [blame] | 1359 |  | 
| Jihoon Kang | bd09345 | 2023-12-26 19:08:01 +0000 | [diff] [blame] | 1360 | // SdkApiStubDexJar returns the dex jar for the stubs for the prebuilt | 
|  | 1361 | // java_sdk_library_import module. It is needed by the hiddenapi processing tool which | 
|  | 1362 | // processes dex files. | 
| Martin Stjernholm | 8be1e6d | 2021-09-15 03:34:04 +0100 | [diff] [blame] | 1363 | SdkApiStubDexJar(ctx android.BaseModuleContext, kind android.SdkKind) OptionalDexJarPath | 
| Paul Duffin | f4600f6 | 2021-05-13 22:34:45 +0100 | [diff] [blame] | 1364 |  | 
| Jihoon Kang | bd09345 | 2023-12-26 19:08:01 +0000 | [diff] [blame] | 1365 | // SdkApiExportableStubDexJar returns the exportable dex jar for the stubs for | 
|  | 1366 | // java_sdk_library module. It is needed by the hiddenapi processing tool which processes | 
|  | 1367 | // dex files. | 
|  | 1368 | SdkApiExportableStubDexJar(ctx android.BaseModuleContext, kind android.SdkKind) OptionalDexJarPath | 
|  | 1369 |  | 
| Paul Duffin | 32cf58a | 2021-05-18 16:32:50 +0100 | [diff] [blame] | 1370 | // SdkRemovedTxtFile returns the optional path to the removed.txt file for the specified sdk kind. | 
|  | 1371 | SdkRemovedTxtFile(ctx android.BaseModuleContext, kind android.SdkKind) android.OptionalPath | 
|  | 1372 |  | 
| Paul Duffin | f4600f6 | 2021-05-13 22:34:45 +0100 | [diff] [blame] | 1373 | // sharedLibrary returns true if this can be used as a shared library. | 
|  | 1374 | sharedLibrary() bool | 
| Paul Duffin | 859fe96 | 2020-05-15 10:20:31 +0100 | [diff] [blame] | 1375 | } | 
|  | 1376 |  | 
| Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 1377 | type SdkLibrary struct { | 
| Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 1378 | Library | 
| Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1379 |  | 
| Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 1380 | sdkLibraryProperties sdkLibraryProperties | 
| Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1381 |  | 
| Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 1382 | // Map from api scope to the scope specific property structure. | 
|  | 1383 | scopeToProperties map[*apiScope]*ApiScopeProperties | 
|  | 1384 |  | 
| Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 1385 | commonToSdkLibraryAndImport | 
| Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1386 | } | 
|  | 1387 |  | 
| Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 1388 | var _ SdkLibraryDependency = (*SdkLibrary)(nil) | 
| Colin Cross | 897d2ed | 2019-02-11 14:03:51 -0800 | [diff] [blame] | 1389 |  | 
| Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 1390 | func (module *SdkLibrary) generateTestAndSystemScopesByDefault() bool { | 
|  | 1391 | return module.sdkLibraryProperties.Generate_system_and_test_apis | 
|  | 1392 | } | 
|  | 1393 |  | 
|  | 1394 | func (module *SdkLibrary) getGeneratedApiScopes(ctx android.EarlyModuleContext) apiScopes { | 
|  | 1395 | // Check to see if any scopes have been explicitly enabled. If any have then all | 
|  | 1396 | // must be. | 
|  | 1397 | anyScopesExplicitlyEnabled := false | 
|  | 1398 | for _, scope := range allApiScopes { | 
|  | 1399 | scopeProperties := module.scopeToProperties[scope] | 
|  | 1400 | if scopeProperties.Enabled != nil { | 
|  | 1401 | anyScopesExplicitlyEnabled = true | 
|  | 1402 | break | 
|  | 1403 | } | 
| Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 1404 | } | 
| Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 1405 |  | 
|  | 1406 | var generatedScopes apiScopes | 
|  | 1407 | enabledScopes := make(map[*apiScope]struct{}) | 
|  | 1408 | for _, scope := range allApiScopes { | 
|  | 1409 | scopeProperties := module.scopeToProperties[scope] | 
|  | 1410 | // If any scopes are explicitly enabled then ignore the legacy enabled status. | 
|  | 1411 | // This is to ensure that any new usages of this module type do not rely on legacy | 
|  | 1412 | // behaviour. | 
|  | 1413 | defaultEnabledStatus := false | 
|  | 1414 | if anyScopesExplicitlyEnabled { | 
|  | 1415 | defaultEnabledStatus = scope.defaultEnabledStatus | 
|  | 1416 | } else { | 
|  | 1417 | defaultEnabledStatus = scope.legacyEnabledStatus(module) | 
|  | 1418 | } | 
|  | 1419 | enabled := proptools.BoolDefault(scopeProperties.Enabled, defaultEnabledStatus) | 
|  | 1420 | if enabled { | 
|  | 1421 | enabledScopes[scope] = struct{}{} | 
|  | 1422 | generatedScopes = append(generatedScopes, scope) | 
|  | 1423 | } | 
|  | 1424 | } | 
|  | 1425 |  | 
|  | 1426 | // Now check to make sure that any scope that is extended by an enabled scope is also | 
|  | 1427 | // enabled. | 
|  | 1428 | for _, scope := range allApiScopes { | 
|  | 1429 | if _, ok := enabledScopes[scope]; ok { | 
|  | 1430 | extends := scope.extends | 
|  | 1431 | if extends != nil { | 
|  | 1432 | if _, ok := enabledScopes[extends]; !ok { | 
|  | 1433 | ctx.ModuleErrorf("enabled api scope %q depends on disabled scope %q", scope, extends) | 
|  | 1434 | } | 
|  | 1435 | } | 
|  | 1436 | } | 
|  | 1437 | } | 
|  | 1438 |  | 
|  | 1439 | return generatedScopes | 
| Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 1440 | } | 
|  | 1441 |  | 
| satayev | 758968a | 2021-12-06 11:42:40 +0000 | [diff] [blame] | 1442 | var _ android.ModuleWithMinSdkVersionCheck = (*SdkLibrary)(nil) | 
|  | 1443 |  | 
| satayev | 8f088b0 | 2021-12-06 11:40:46 +0000 | [diff] [blame] | 1444 | func (module *SdkLibrary) CheckMinSdkVersion(ctx android.ModuleContext) { | 
| Spandan Das | 8c9ae7e | 2023-03-03 21:20:36 +0000 | [diff] [blame] | 1445 | android.CheckMinSdkVersion(ctx, module.MinSdkVersion(ctx), func(c android.ModuleContext, do android.PayloadDepsCallback) { | 
| satayev | 8f088b0 | 2021-12-06 11:40:46 +0000 | [diff] [blame] | 1446 | ctx.WalkDeps(func(child android.Module, parent android.Module) bool { | 
|  | 1447 | isExternal := !module.depIsInSameApex(ctx, child) | 
|  | 1448 | if am, ok := child.(android.ApexModule); ok { | 
|  | 1449 | if !do(ctx, parent, am, isExternal) { | 
|  | 1450 | return false | 
|  | 1451 | } | 
|  | 1452 | } | 
|  | 1453 | return !isExternal | 
|  | 1454 | }) | 
|  | 1455 | }) | 
|  | 1456 | } | 
|  | 1457 |  | 
| Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 1458 | type sdkLibraryComponentTag struct { | 
|  | 1459 | blueprint.BaseDependencyTag | 
|  | 1460 | name string | 
|  | 1461 | } | 
|  | 1462 |  | 
|  | 1463 | // Mark this tag so dependencies that use it are excluded from visibility enforcement. | 
|  | 1464 | func (t sdkLibraryComponentTag) ExcludeFromVisibilityEnforcement() {} | 
|  | 1465 |  | 
|  | 1466 | var xmlPermissionsFileTag = sdkLibraryComponentTag{name: "xml-permissions-file"} | 
| Paul Duffin | e74ac73 | 2020-02-06 13:51:46 +0000 | [diff] [blame] | 1467 |  | 
| Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 1468 | func IsXmlPermissionsFileDepTag(depTag blueprint.DependencyTag) bool { | 
| Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 1469 | if dt, ok := depTag.(sdkLibraryComponentTag); ok { | 
| Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 1470 | return dt == xmlPermissionsFileTag | 
|  | 1471 | } | 
|  | 1472 | return false | 
|  | 1473 | } | 
|  | 1474 |  | 
| Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 1475 | var implLibraryTag = sdkLibraryComponentTag{name: "impl-library"} | 
| Paul Duffin | 5df7930 | 2020-05-16 15:52:12 +0100 | [diff] [blame] | 1476 |  | 
| Paul Duffin | 44f1d84 | 2020-06-26 20:17:02 +0100 | [diff] [blame] | 1477 | // Add the dependencies on the child modules in the component deps mutator. | 
|  | 1478 | func (module *SdkLibrary) ComponentDepsMutator(ctx android.BottomUpMutatorContext) { | 
| Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 1479 | for _, apiScope := range module.getGeneratedApiScopes(ctx) { | 
| Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 1480 | // Add dependencies to the stubs library | 
| Spandan Das | 877f39d | 2023-03-29 16:19:51 +0000 | [diff] [blame] | 1481 | stubModuleName := module.stubsLibraryModuleName(apiScope) | 
| Jihoon Kang | bd09345 | 2023-12-26 19:08:01 +0000 | [diff] [blame] | 1482 | ctx.AddVariationDependencies(nil, apiScope.everythingStubsTag, stubModuleName) | 
| Jihoon Kang | 1147b31 | 2023-06-08 23:25:57 +0000 | [diff] [blame] | 1483 |  | 
| Jihoon Kang | bd09345 | 2023-12-26 19:08:01 +0000 | [diff] [blame] | 1484 | exportableStubModuleName := module.exportableStubsLibraryModuleName(apiScope) | 
|  | 1485 | ctx.AddVariationDependencies(nil, apiScope.exportableStubsTag, exportableStubModuleName) | 
| Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 1486 |  | 
| Paul Duffin | 15f34ef | 2020-07-20 18:04:44 +0100 | [diff] [blame] | 1487 | // Add a dependency on the stubs source in order to access both stubs source and api information. | 
|  | 1488 | ctx.AddVariationDependencies(nil, apiScope.stubsSourceAndApiTag, module.stubsSourceModuleName(apiScope)) | 
| Paul Duffin | 958806b | 2022-05-16 13:10:47 +0000 | [diff] [blame] | 1489 |  | 
|  | 1490 | if module.compareAgainstLatestApi(apiScope) { | 
|  | 1491 | // Add dependencies on the latest finalized version of the API .txt file. | 
|  | 1492 | latestApiModuleName := module.latestApiModuleName(apiScope) | 
|  | 1493 | ctx.AddDependency(module, apiScope.latestApiModuleTag, latestApiModuleName) | 
|  | 1494 |  | 
|  | 1495 | // Add dependencies on the latest finalized version of the remove API .txt file. | 
|  | 1496 | latestRemovedApiModuleName := module.latestRemovedApiModuleName(apiScope) | 
|  | 1497 | ctx.AddDependency(module, apiScope.latestRemovedApiModuleTag, latestRemovedApiModuleName) | 
|  | 1498 | } | 
| Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 1499 | } | 
|  | 1500 |  | 
| Paul Duffin | dfa131e | 2020-05-15 20:37:11 +0100 | [diff] [blame] | 1501 | if module.requiresRuntimeImplementationLibrary() { | 
| Paul Duffin | 5df7930 | 2020-05-16 15:52:12 +0100 | [diff] [blame] | 1502 | // Add dependency to the rule for generating the implementation library. | 
|  | 1503 | ctx.AddDependency(module, implLibraryTag, module.implLibraryModuleName()) | 
|  | 1504 |  | 
| Paul Duffin | dfa131e | 2020-05-15 20:37:11 +0100 | [diff] [blame] | 1505 | if module.sharedLibrary() { | 
|  | 1506 | // Add dependency to the rule for generating the xml permissions file | 
| Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 1507 | ctx.AddDependency(module, xmlPermissionsFileTag, module.xmlPermissionsModuleName()) | 
| Paul Duffin | dfa131e | 2020-05-15 20:37:11 +0100 | [diff] [blame] | 1508 | } | 
| Paul Duffin | 44f1d84 | 2020-06-26 20:17:02 +0100 | [diff] [blame] | 1509 | } | 
|  | 1510 | } | 
| Paul Duffin | e74ac73 | 2020-02-06 13:51:46 +0000 | [diff] [blame] | 1511 |  | 
| Paul Duffin | 44f1d84 | 2020-06-26 20:17:02 +0100 | [diff] [blame] | 1512 | // Add other dependencies as normal. | 
|  | 1513 | func (module *SdkLibrary) DepsMutator(ctx android.BottomUpMutatorContext) { | 
| Anton Hansson | e77fccc | 2021-01-20 16:52:41 +0000 | [diff] [blame] | 1514 | var missingApiModules []string | 
|  | 1515 | for _, apiScope := range module.getGeneratedApiScopes(ctx) { | 
|  | 1516 | if apiScope.unstable { | 
|  | 1517 | continue | 
|  | 1518 | } | 
| Paul Duffin | 958806b | 2022-05-16 13:10:47 +0000 | [diff] [blame] | 1519 | if m := module.latestApiModuleName(apiScope); !ctx.OtherModuleExists(m) { | 
| Anton Hansson | e77fccc | 2021-01-20 16:52:41 +0000 | [diff] [blame] | 1520 | missingApiModules = append(missingApiModules, m) | 
|  | 1521 | } | 
| Paul Duffin | 958806b | 2022-05-16 13:10:47 +0000 | [diff] [blame] | 1522 | if m := module.latestRemovedApiModuleName(apiScope); !ctx.OtherModuleExists(m) { | 
| Anton Hansson | e77fccc | 2021-01-20 16:52:41 +0000 | [diff] [blame] | 1523 | missingApiModules = append(missingApiModules, m) | 
|  | 1524 | } | 
| Paul Duffin | 958806b | 2022-05-16 13:10:47 +0000 | [diff] [blame] | 1525 | if m := module.latestIncompatibilitiesModuleName(apiScope); !ctx.OtherModuleExists(m) { | 
| Jaewoong Jung | 1a97ee0 | 2021-03-09 13:25:02 -0800 | [diff] [blame] | 1526 | missingApiModules = append(missingApiModules, m) | 
|  | 1527 | } | 
| Anton Hansson | e77fccc | 2021-01-20 16:52:41 +0000 | [diff] [blame] | 1528 | } | 
|  | 1529 | if len(missingApiModules) != 0 && !module.sdkLibraryProperties.Unsafe_ignore_missing_latest_api { | 
|  | 1530 | m := module.Name() + " is missing tracking files for previously released library versions.\n" | 
|  | 1531 | m += "You need to do one of the following:\n" | 
|  | 1532 | m += "- Add `unsafe_ignore_missing_latest_api: true` to your blueprint (to disable compat tracking)\n" | 
|  | 1533 | m += "- Add a set of prebuilt txt files representing the last released version of this library for compat checking.\n" | 
|  | 1534 | m += "  (the current set of API files can be used as a seed for this compatibility tracking\n" | 
|  | 1535 | m += "\n" | 
|  | 1536 | m += "The following filegroup modules are missing:\n  " | 
|  | 1537 | m += strings.Join(missingApiModules, "\n  ") + "\n" | 
|  | 1538 | m += "Please see the documentation of the prebuilt_apis module type (and a usage example in prebuilts/sdk) for a convenient way to generate these." | 
|  | 1539 | ctx.ModuleErrorf(m) | 
|  | 1540 | } | 
| Paul Duffin | 44f1d84 | 2020-06-26 20:17:02 +0100 | [diff] [blame] | 1541 | if module.requiresRuntimeImplementationLibrary() { | 
| Paul Duffin | dfa131e | 2020-05-15 20:37:11 +0100 | [diff] [blame] | 1542 | // Only add the deps for the library if it is actually going to be built. | 
|  | 1543 | module.Library.deps(ctx) | 
|  | 1544 | } | 
| Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1545 | } | 
|  | 1546 |  | 
| Paul Duffin | 46dc45a | 2020-05-14 15:39:10 +0100 | [diff] [blame] | 1547 | func (module *SdkLibrary) OutputFiles(tag string) (android.Paths, error) { | 
|  | 1548 | paths, err := module.commonOutputFiles(tag) | 
| Colin Cross | 4acaea9 | 2021-12-10 23:05:02 +0000 | [diff] [blame] | 1549 | if paths != nil || err != nil { | 
| Paul Duffin | 46dc45a | 2020-05-14 15:39:10 +0100 | [diff] [blame] | 1550 | return paths, err | 
|  | 1551 | } | 
| Colin Cross | 4acaea9 | 2021-12-10 23:05:02 +0000 | [diff] [blame] | 1552 | if module.requiresRuntimeImplementationLibrary() { | 
|  | 1553 | return module.Library.OutputFiles(tag) | 
|  | 1554 | } | 
|  | 1555 | if tag == "" { | 
|  | 1556 | return nil, nil | 
|  | 1557 | } | 
|  | 1558 | return nil, fmt.Errorf("unsupported module reference tag %q", tag) | 
| Paul Duffin | 46dc45a | 2020-05-14 15:39:10 +0100 | [diff] [blame] | 1559 | } | 
|  | 1560 |  | 
| Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 1561 | func (module *SdkLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) { | 
| Spandan Das | 5ae65ee | 2024-04-16 22:03:26 +0000 | [diff] [blame] | 1562 | if disableSourceApexVariant(ctx) { | 
|  | 1563 | // Prebuilts are active, do not create the installation rules for the source javalib. | 
|  | 1564 | // Even though the source javalib is not used, we need to hide it to prevent duplicate installation rules. | 
|  | 1565 | // TODO (b/331665856): Implement a principled solution for this. | 
|  | 1566 | module.HideFromMake() | 
|  | 1567 | } | 
| satayev | 8f088b0 | 2021-12-06 11:40:46 +0000 | [diff] [blame] | 1568 | if proptools.String(module.deviceProperties.Min_sdk_version) != "" { | 
|  | 1569 | module.CheckMinSdkVersion(ctx) | 
|  | 1570 | } | 
|  | 1571 |  | 
| Paul Duffin | a2ae7e0 | 2020-09-11 11:55:00 +0100 | [diff] [blame] | 1572 | module.generateCommonBuildActions(ctx) | 
|  | 1573 |  | 
| Paul Duffin | dfa131e | 2020-05-15 20:37:11 +0100 | [diff] [blame] | 1574 | // Only build an implementation library if required. | 
|  | 1575 | if module.requiresRuntimeImplementationLibrary() { | 
| Jihoon Kang | fe914ed | 2024-02-12 22:49:21 +0000 | [diff] [blame] | 1576 | // stubsLinkType must be set before calling Library.GenerateAndroidBuildActions | 
|  | 1577 | module.Library.stubsLinkType = Unknown | 
| Paul Duffin | 43db9be | 2019-12-30 17:35:49 +0000 | [diff] [blame] | 1578 | module.Library.GenerateAndroidBuildActions(ctx) | 
|  | 1579 | } | 
| Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 1580 |  | 
| Paul Duffin | b97b157 | 2021-04-29 21:50:40 +0100 | [diff] [blame] | 1581 | // Collate the components exported by this module. All scope specific modules are exported but | 
|  | 1582 | // the impl and xml component modules are not. | 
|  | 1583 | exportedComponents := map[string]struct{}{} | 
|  | 1584 |  | 
| Sundong Ahn | 57368eb | 2018-07-06 11:20:23 +0900 | [diff] [blame] | 1585 | // Record the paths to the header jars of the library (stubs and impl). | 
| Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 1586 | // When this java_sdk_library is depended upon from others via "libs" property, | 
| Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1587 | // the recorded paths will be returned depending on the link type of the caller. | 
|  | 1588 | ctx.VisitDirectDeps(func(to android.Module) { | 
| Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1589 | tag := ctx.OtherModuleDependencyTag(to) | 
|  | 1590 |  | 
| Paul Duffin | c878250 | 2020-04-29 20:45:27 +0100 | [diff] [blame] | 1591 | // Extract information from any of the scope specific dependencies. | 
|  | 1592 | if scopeTag, ok := tag.(scopeDependencyTag); ok { | 
|  | 1593 | apiScope := scopeTag.apiScope | 
| Paul Duffin | 803a956 | 2020-05-20 11:52:25 +0100 | [diff] [blame] | 1594 | scopePaths := module.getScopePathsCreateIfNeeded(apiScope) | 
| Paul Duffin | c878250 | 2020-04-29 20:45:27 +0100 | [diff] [blame] | 1595 |  | 
|  | 1596 | // Extract information from the dependency. The exact information extracted | 
|  | 1597 | // is determined by the nature of the dependency which is determined by the tag. | 
|  | 1598 | scopeTag.extractDepInfo(ctx, to, scopePaths) | 
| Paul Duffin | b97b157 | 2021-04-29 21:50:40 +0100 | [diff] [blame] | 1599 |  | 
|  | 1600 | exportedComponents[ctx.OtherModuleName(to)] = struct{}{} | 
| Sundong Ahn | 20e998b | 2018-07-24 11:19:26 +0900 | [diff] [blame] | 1601 | } | 
| Jihoon Kang | 8479dea | 2024-04-04 01:19:05 +0000 | [diff] [blame] | 1602 |  | 
|  | 1603 | if tag == implLibraryTag { | 
|  | 1604 | if dep, ok := android.OtherModuleProvider(ctx, to, JavaInfoProvider); ok { | 
|  | 1605 | module.implLibraryHeaderJars = append(module.implLibraryHeaderJars, dep.HeaderJars...) | 
|  | 1606 | } | 
|  | 1607 | } | 
| Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1608 | }) | 
| Paul Duffin | b97b157 | 2021-04-29 21:50:40 +0100 | [diff] [blame] | 1609 |  | 
|  | 1610 | // Make the set of components exported by this module available for use elsewhere. | 
| Cole Faust | 18994c7 | 2023-02-28 16:02:16 -0800 | [diff] [blame] | 1611 | exportedComponentInfo := android.ExportedComponentsInfo{Components: android.SortedKeys(exportedComponents)} | 
| Colin Cross | 4021302 | 2023-12-13 15:19:49 -0800 | [diff] [blame] | 1612 | android.SetProvider(ctx, android.ExportedComponentsInfoProvider, exportedComponentInfo) | 
| Paul Duffin | 958806b | 2022-05-16 13:10:47 +0000 | [diff] [blame] | 1613 |  | 
|  | 1614 | // Provide additional information for inclusion in an sdk's generated .info file. | 
|  | 1615 | additionalSdkInfo := map[string]interface{}{} | 
|  | 1616 | additionalSdkInfo["dist_stem"] = module.distStem() | 
| Paul Duffin | e840995 | 2022-09-22 16:24:46 +0100 | [diff] [blame] | 1617 | baseModuleName := module.distStem() | 
| Paul Duffin | 958806b | 2022-05-16 13:10:47 +0000 | [diff] [blame] | 1618 | scopes := map[string]interface{}{} | 
|  | 1619 | additionalSdkInfo["scopes"] = scopes | 
|  | 1620 | for scope, scopePaths := range module.scopePaths { | 
|  | 1621 | scopeInfo := map[string]interface{}{} | 
|  | 1622 | scopes[scope.name] = scopeInfo | 
|  | 1623 | scopeInfo["current_api"] = scope.snapshotRelativeCurrentApiTxtPath(baseModuleName) | 
|  | 1624 | scopeInfo["removed_api"] = scope.snapshotRelativeRemovedApiTxtPath(baseModuleName) | 
| Jihoon Kang | 5623e54 | 2024-01-31 23:27:26 +0000 | [diff] [blame] | 1625 | if p := scopePaths.latestApiPaths; len(p) > 0 { | 
|  | 1626 | // The last path in the list is the one that applies to this scope, the | 
|  | 1627 | // preceding ones, if any, are for the scope(s) that it extends. | 
|  | 1628 | scopeInfo["latest_api"] = p[len(p)-1].String() | 
| Paul Duffin | 958806b | 2022-05-16 13:10:47 +0000 | [diff] [blame] | 1629 | } | 
| Jihoon Kang | 5623e54 | 2024-01-31 23:27:26 +0000 | [diff] [blame] | 1630 | if p := scopePaths.latestRemovedApiPaths; len(p) > 0 { | 
|  | 1631 | // The last path in the list is the one that applies to this scope, the | 
|  | 1632 | // preceding ones, if any, are for the scope(s) that it extends. | 
|  | 1633 | scopeInfo["latest_removed_api"] = p[len(p)-1].String() | 
| Paul Duffin | 958806b | 2022-05-16 13:10:47 +0000 | [diff] [blame] | 1634 | } | 
|  | 1635 | } | 
| Colin Cross | 4021302 | 2023-12-13 15:19:49 -0800 | [diff] [blame] | 1636 | android.SetProvider(ctx, android.AdditionalSdkInfoProvider, android.AdditionalSdkInfo{additionalSdkInfo}) | 
| Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1637 | } | 
|  | 1638 |  | 
| Jiyong Park | 0b0e1b9 | 2019-12-03 13:24:29 +0900 | [diff] [blame] | 1639 | func (module *SdkLibrary) AndroidMkEntries() []android.AndroidMkEntries { | 
| Paul Duffin | dfa131e | 2020-05-15 20:37:11 +0100 | [diff] [blame] | 1640 | if !module.requiresRuntimeImplementationLibrary() { | 
| Paul Duffin | 43db9be | 2019-12-30 17:35:49 +0000 | [diff] [blame] | 1641 | return nil | 
|  | 1642 | } | 
| Jiyong Park | 0b0e1b9 | 2019-12-03 13:24:29 +0900 | [diff] [blame] | 1643 | entriesList := module.Library.AndroidMkEntries() | 
| Yo Chiang | 07d7507 | 2020-06-05 17:43:19 +0800 | [diff] [blame] | 1644 | if module.sharedLibrary() { | 
|  | 1645 | entries := &entriesList[0] | 
|  | 1646 | entries.Required = append(entries.Required, module.xmlPermissionsModuleName()) | 
|  | 1647 | } | 
| Jiyong Park | 0b0e1b9 | 2019-12-03 13:24:29 +0900 | [diff] [blame] | 1648 | return entriesList | 
| Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 1649 | } | 
|  | 1650 |  | 
| Anton Hansson | 5fd5d24 | 2020-03-27 19:43:19 +0000 | [diff] [blame] | 1651 | // The dist path of the stub artifacts | 
|  | 1652 | func (module *SdkLibrary) apiDistPath(apiScope *apiScope) string { | 
| Colin Cross | f0eace9 | 2021-06-02 13:02:23 -0700 | [diff] [blame] | 1653 | return path.Join("apistubs", module.distGroup(), apiScope.name) | 
| Anton Hansson | 5fd5d24 | 2020-03-27 19:43:19 +0000 | [diff] [blame] | 1654 | } | 
|  | 1655 |  | 
| Paul Duffin | 12ceb46 | 2019-12-24 20:31:31 +0000 | [diff] [blame] | 1656 | // Get the sdk version for use when compiling the stubs library. | 
| Paul Duffin | 780c5f4 | 2020-05-12 15:52:55 +0100 | [diff] [blame] | 1657 | func (module *SdkLibrary) sdkVersionForStubsLibrary(mctx android.EarlyModuleContext, apiScope *apiScope) string { | 
| Paul Duffin | 87a05a3 | 2020-05-12 11:50:28 +0100 | [diff] [blame] | 1658 | scopeProperties := module.scopeToProperties[apiScope] | 
|  | 1659 | if scopeProperties.Sdk_version != nil { | 
|  | 1660 | return proptools.String(scopeProperties.Sdk_version) | 
|  | 1661 | } | 
|  | 1662 |  | 
| Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 1663 | sdkDep := decodeSdkDep(mctx, android.SdkContext(&module.Library)) | 
| Paul Duffin | 12ceb46 | 2019-12-24 20:31:31 +0000 | [diff] [blame] | 1664 | if sdkDep.hasStandardLibs() { | 
|  | 1665 | // If building against a standard sdk then use the sdk version appropriate for the scope. | 
| Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 1666 | return apiScope.sdkVersion | 
| Paul Duffin | 12ceb46 | 2019-12-24 20:31:31 +0000 | [diff] [blame] | 1667 | } else { | 
|  | 1668 | // Otherwise, use no system module. | 
|  | 1669 | return "none" | 
|  | 1670 | } | 
|  | 1671 | } | 
|  | 1672 |  | 
| Paul Duffin | 3131025 | 2020-11-20 21:26:20 +0000 | [diff] [blame] | 1673 | func (module *SdkLibrary) distStem() string { | 
|  | 1674 | return proptools.StringDefault(module.sdkLibraryProperties.Dist_stem, module.BaseModuleName()) | 
|  | 1675 | } | 
|  | 1676 |  | 
| Colin Cross | 986b69a | 2021-06-01 13:13:40 -0700 | [diff] [blame] | 1677 | // distGroup returns the subdirectory of the dist path of the stub artifacts. | 
|  | 1678 | func (module *SdkLibrary) distGroup() string { | 
| Colin Cross | 59b92bf | 2021-06-01 14:07:56 -0700 | [diff] [blame] | 1679 | return proptools.StringDefault(module.sdkLibraryProperties.Dist_group, "unknown") | 
| Colin Cross | 986b69a | 2021-06-01 13:13:40 -0700 | [diff] [blame] | 1680 | } | 
|  | 1681 |  | 
| Paul Duffin | 958806b | 2022-05-16 13:10:47 +0000 | [diff] [blame] | 1682 | func latestPrebuiltApiModuleName(name string, apiScope *apiScope) string { | 
|  | 1683 | return PrebuiltApiModuleName(name, apiScope.name, "latest") | 
|  | 1684 | } | 
|  | 1685 |  | 
| Jihoon Kang | 748a24d | 2024-03-20 21:29:39 +0000 | [diff] [blame] | 1686 | func latestPrebuiltApiCombinedModuleName(name string, apiScope *apiScope) string { | 
|  | 1687 | return PrebuiltApiCombinedModuleName(name, apiScope.name, "latest") | 
|  | 1688 | } | 
|  | 1689 |  | 
| Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 1690 | func (module *SdkLibrary) latestApiFilegroupName(apiScope *apiScope) string { | 
| Paul Duffin | 958806b | 2022-05-16 13:10:47 +0000 | [diff] [blame] | 1691 | return ":" + module.latestApiModuleName(apiScope) | 
|  | 1692 | } | 
|  | 1693 |  | 
|  | 1694 | func (module *SdkLibrary) latestApiModuleName(apiScope *apiScope) string { | 
| Jihoon Kang | 748a24d | 2024-03-20 21:29:39 +0000 | [diff] [blame] | 1695 | return latestPrebuiltApiCombinedModuleName(module.distStem(), apiScope) | 
| Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 1696 | } | 
| Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1697 |  | 
| Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 1698 | func (module *SdkLibrary) latestRemovedApiFilegroupName(apiScope *apiScope) string { | 
| Paul Duffin | 958806b | 2022-05-16 13:10:47 +0000 | [diff] [blame] | 1699 | return ":" + module.latestRemovedApiModuleName(apiScope) | 
|  | 1700 | } | 
|  | 1701 |  | 
|  | 1702 | func (module *SdkLibrary) latestRemovedApiModuleName(apiScope *apiScope) string { | 
| Jihoon Kang | 748a24d | 2024-03-20 21:29:39 +0000 | [diff] [blame] | 1703 | return latestPrebuiltApiCombinedModuleName(module.distStem()+"-removed", apiScope) | 
| Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1704 | } | 
|  | 1705 |  | 
| Jaewoong Jung | 1a97ee0 | 2021-03-09 13:25:02 -0800 | [diff] [blame] | 1706 | func (module *SdkLibrary) latestIncompatibilitiesFilegroupName(apiScope *apiScope) string { | 
| Paul Duffin | 958806b | 2022-05-16 13:10:47 +0000 | [diff] [blame] | 1707 | return ":" + module.latestIncompatibilitiesModuleName(apiScope) | 
|  | 1708 | } | 
|  | 1709 |  | 
|  | 1710 | func (module *SdkLibrary) latestIncompatibilitiesModuleName(apiScope *apiScope) string { | 
|  | 1711 | return latestPrebuiltApiModuleName(module.distStem()+"-incompatibilities", apiScope) | 
| Jaewoong Jung | 1a97ee0 | 2021-03-09 13:25:02 -0800 | [diff] [blame] | 1712 | } | 
|  | 1713 |  | 
| Jihoon Kang | 1c92c3e | 2023-03-23 17:44:51 +0000 | [diff] [blame] | 1714 | func (module *SdkLibrary) contributesToApiSurface(c android.Config) bool { | 
|  | 1715 | _, exists := c.GetApiLibraries()[module.Name()] | 
|  | 1716 | return exists | 
|  | 1717 | } | 
|  | 1718 |  | 
| Jihoon Kang | 0c705a4 | 2023-08-02 06:44:57 +0000 | [diff] [blame] | 1719 | // The listed modules are the special java_sdk_libraries where apiScope.kind do not match the | 
|  | 1720 | // api surface that the module contribute to. For example, the public droidstubs and java_library | 
|  | 1721 | // do not contribute to the public api surface, but contributes to the core platform api surface. | 
|  | 1722 | // This method returns the full api surface stub lib that | 
|  | 1723 | // the generated java_api_library should depend on. | 
|  | 1724 | func (module *SdkLibrary) alternativeFullApiSurfaceStubLib() string { | 
|  | 1725 | if val, ok := apiLibraryAdditionalProperties[module.Name()]; ok { | 
|  | 1726 | return val.FullApiSurfaceStubLib | 
|  | 1727 | } | 
|  | 1728 | return "" | 
|  | 1729 | } | 
|  | 1730 |  | 
|  | 1731 | // The listed modules' stubs contents do not match the corresponding txt files, | 
|  | 1732 | // but require additional api contributions to generate the full stubs. | 
|  | 1733 | // This method returns the name of the additional api contribution module | 
|  | 1734 | // for corresponding sdk_library modules. | 
|  | 1735 | func (module *SdkLibrary) apiLibraryAdditionalApiContribution() string { | 
|  | 1736 | if val, ok := apiLibraryAdditionalProperties[module.Name()]; ok { | 
|  | 1737 | return val.AdditionalApiContribution | 
|  | 1738 | } | 
|  | 1739 | return "" | 
|  | 1740 | } | 
|  | 1741 |  | 
| Anton Hansson | 944e77d | 2020-08-19 11:40:22 +0100 | [diff] [blame] | 1742 | func childModuleVisibility(childVisibility []string) []string { | 
|  | 1743 | if childVisibility == nil { | 
|  | 1744 | // No child visibility set. The child will use the visibility of the sdk_library. | 
|  | 1745 | return nil | 
|  | 1746 | } | 
|  | 1747 |  | 
|  | 1748 | // Prepend an override to ignore the sdk_library's visibility, and rely on the child visibility. | 
|  | 1749 | var visibility []string | 
|  | 1750 | visibility = append(visibility, "//visibility:override") | 
|  | 1751 | visibility = append(visibility, childVisibility...) | 
|  | 1752 | return visibility | 
|  | 1753 | } | 
|  | 1754 |  | 
| Paul Duffin | 5df7930 | 2020-05-16 15:52:12 +0100 | [diff] [blame] | 1755 | // Creates the implementation java library | 
|  | 1756 | func (module *SdkLibrary) createImplLibrary(mctx android.DefaultableHookContext) { | 
| Anton Hansson | 944e77d | 2020-08-19 11:40:22 +0100 | [diff] [blame] | 1757 | visibility := childModuleVisibility(module.sdkLibraryProperties.Impl_library_visibility) | 
|  | 1758 |  | 
| Paul Duffin | 5df7930 | 2020-05-16 15:52:12 +0100 | [diff] [blame] | 1759 | props := struct { | 
| Paul Duffin | 77590a8 | 2022-04-28 14:13:30 +0000 | [diff] [blame] | 1760 | Name           *string | 
|  | 1761 | Visibility     []string | 
|  | 1762 | Instrument     bool | 
|  | 1763 | Libs           []string | 
|  | 1764 | Static_libs    []string | 
|  | 1765 | Apex_available []string | 
| Paul Duffin | 5df7930 | 2020-05-16 15:52:12 +0100 | [diff] [blame] | 1766 | }{ | 
|  | 1767 | Name:       proptools.StringPtr(module.implLibraryModuleName()), | 
| Anton Hansson | 944e77d | 2020-08-19 11:40:22 +0100 | [diff] [blame] | 1768 | Visibility: visibility, | 
| Paul Duffin | 296cf33 | 2020-06-18 21:09:55 +0100 | [diff] [blame] | 1769 | // Set the instrument property to ensure it is instrumented when instrumentation is required. | 
|  | 1770 | Instrument: true, | 
| Anton Hansson | 7f66efa | 2020-10-08 14:47:23 +0100 | [diff] [blame] | 1771 | // Set the impl_only libs. Note that the module's "Libs" get appended as well, via the | 
|  | 1772 | // addition of &module.properties below. | 
|  | 1773 | Libs: module.sdkLibraryProperties.Impl_only_libs, | 
| Paul Duffin | 77590a8 | 2022-04-28 14:13:30 +0000 | [diff] [blame] | 1774 | // Set the impl_only static libs. Note that the module's "static_libs" get appended as well, via the | 
|  | 1775 | // addition of &module.properties below. | 
|  | 1776 | Static_libs: module.sdkLibraryProperties.Impl_only_static_libs, | 
|  | 1777 | // Pass the apex_available settings down so that the impl library can be statically | 
|  | 1778 | // embedded within a library that is added to an APEX. Needed for updatable-media. | 
|  | 1779 | Apex_available: module.ApexAvailable(), | 
| Paul Duffin | 5df7930 | 2020-05-16 15:52:12 +0100 | [diff] [blame] | 1780 | } | 
|  | 1781 |  | 
|  | 1782 | properties := []interface{}{ | 
|  | 1783 | &module.properties, | 
|  | 1784 | &module.protoProperties, | 
|  | 1785 | &module.deviceProperties, | 
| Liz Kammer | a7a64f3 | 2020-07-09 15:16:41 -0700 | [diff] [blame] | 1786 | &module.dexProperties, | 
| Paul Duffin | 5df7930 | 2020-05-16 15:52:12 +0100 | [diff] [blame] | 1787 | &module.dexpreoptProperties, | 
| Colin Cross | 014489c | 2020-06-02 20:09:13 -0700 | [diff] [blame] | 1788 | &module.linter.properties, | 
| Paul Duffin | 5df7930 | 2020-05-16 15:52:12 +0100 | [diff] [blame] | 1789 | &props, | 
|  | 1790 | module.sdkComponentPropertiesForChildLibrary(), | 
|  | 1791 | } | 
|  | 1792 | mctx.CreateModule(LibraryFactory, properties...) | 
|  | 1793 | } | 
|  | 1794 |  | 
| Jihoon Kang | fa4a90d | 2023-12-20 02:53:38 +0000 | [diff] [blame] | 1795 | type libraryProperties struct { | 
|  | 1796 | Name           *string | 
|  | 1797 | Visibility     []string | 
|  | 1798 | Srcs           []string | 
|  | 1799 | Installable    *bool | 
|  | 1800 | Sdk_version    *string | 
|  | 1801 | System_modules *string | 
|  | 1802 | Patch_module   *string | 
|  | 1803 | Libs           []string | 
|  | 1804 | Static_libs    []string | 
|  | 1805 | Compile_dex    *bool | 
|  | 1806 | Java_version   *string | 
|  | 1807 | Openjdk9       struct { | 
|  | 1808 | Srcs       []string | 
|  | 1809 | Javacflags []string | 
|  | 1810 | } | 
|  | 1811 | Dist struct { | 
|  | 1812 | Targets []string | 
|  | 1813 | Dest    *string | 
|  | 1814 | Dir     *string | 
|  | 1815 | Tag     *string | 
|  | 1816 | } | 
| Jihoon Kang | fe914ed | 2024-02-12 22:49:21 +0000 | [diff] [blame] | 1817 | Is_stubs_module *bool | 
| Jihoon Kang | fa4a90d | 2023-12-20 02:53:38 +0000 | [diff] [blame] | 1818 | } | 
| Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1819 |  | 
| Jihoon Kang | fa4a90d | 2023-12-20 02:53:38 +0000 | [diff] [blame] | 1820 | func (module *SdkLibrary) stubsLibraryProps(mctx android.DefaultableHookContext, apiScope *apiScope) libraryProperties { | 
|  | 1821 | props := libraryProperties{} | 
| Jihoon Kang | 786df93 | 2023-09-07 01:18:31 +0000 | [diff] [blame] | 1822 | props.Visibility = []string{"//visibility:override", "//visibility:private"} | 
| Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1823 | // sources are generated from the droiddoc | 
| Paul Duffin | 12ceb46 | 2019-12-24 20:31:31 +0000 | [diff] [blame] | 1824 | sdkVersion := module.sdkVersionForStubsLibrary(mctx, apiScope) | 
| Paul Duffin | 52d398a | 2019-06-11 12:31:14 +0100 | [diff] [blame] | 1825 | props.Sdk_version = proptools.StringPtr(sdkVersion) | 
| Paul Duffin | a18abc2 | 2020-05-16 18:54:24 +0100 | [diff] [blame] | 1826 | props.System_modules = module.deviceProperties.System_modules | 
|  | 1827 | props.Patch_module = module.properties.Patch_module | 
| Paul Duffin | 367ab91 | 2019-12-23 19:40:36 +0000 | [diff] [blame] | 1828 | props.Installable = proptools.BoolPtr(false) | 
| Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 1829 | props.Libs = module.sdkLibraryProperties.Stub_only_libs | 
| Mark White | 9421c4c | 2023-08-10 00:07:03 +0000 | [diff] [blame] | 1830 | props.Libs = append(props.Libs, module.scopeToProperties[apiScope].Libs...) | 
| Anton Hansson | dae54cd | 2021-04-21 16:30:10 +0100 | [diff] [blame] | 1831 | props.Static_libs = module.sdkLibraryProperties.Stub_only_static_libs | 
| Paul Duffin | e22c2ab | 2020-05-20 19:35:27 +0100 | [diff] [blame] | 1832 | // The stub-annotations library contains special versions of the annotations | 
|  | 1833 | // with CLASS retention policy, so that they're kept. | 
|  | 1834 | if proptools.Bool(module.sdkLibraryProperties.Annotations_enabled) { | 
|  | 1835 | props.Libs = append(props.Libs, "stub-annotations") | 
|  | 1836 | } | 
| Paul Duffin | a18abc2 | 2020-05-16 18:54:24 +0100 | [diff] [blame] | 1837 | props.Openjdk9.Srcs = module.properties.Openjdk9.Srcs | 
|  | 1838 | props.Openjdk9.Javacflags = module.properties.Openjdk9.Javacflags | 
| Anton Hansson | 83509b5 | 2020-05-21 09:21:57 +0100 | [diff] [blame] | 1839 | // We compile the stubs for 1.8 in line with the main android.jar stubs, and potential | 
|  | 1840 | // interop with older developer tools that don't support 1.9. | 
|  | 1841 | props.Java_version = proptools.StringPtr("1.8") | 
| Jihoon Kang | fe914ed | 2024-02-12 22:49:21 +0000 | [diff] [blame] | 1842 | props.Is_stubs_module = proptools.BoolPtr(true) | 
| Paul Duffin | f4600f6 | 2021-05-13 22:34:45 +0100 | [diff] [blame] | 1843 |  | 
| Jihoon Kang | fa4a90d | 2023-12-20 02:53:38 +0000 | [diff] [blame] | 1844 | return props | 
|  | 1845 | } | 
|  | 1846 |  | 
|  | 1847 | // Creates a static java library that has API stubs | 
|  | 1848 | func (module *SdkLibrary) createStubsLibrary(mctx android.DefaultableHookContext, apiScope *apiScope) { | 
|  | 1849 |  | 
|  | 1850 | props := module.stubsLibraryProps(mctx, apiScope) | 
|  | 1851 | props.Name = proptools.StringPtr(module.sourceStubsLibraryModuleName(apiScope)) | 
|  | 1852 | props.Srcs = []string{":" + module.stubsSourceModuleName(apiScope)} | 
|  | 1853 |  | 
|  | 1854 | mctx.CreateModule(LibraryFactory, &props, module.sdkComponentPropertiesForChildLibrary()) | 
|  | 1855 | } | 
|  | 1856 |  | 
|  | 1857 | // Create a static java library that compiles the "exportable" stubs | 
|  | 1858 | func (module *SdkLibrary) createExportableStubsLibrary(mctx android.DefaultableHookContext, apiScope *apiScope) { | 
|  | 1859 | props := module.stubsLibraryProps(mctx, apiScope) | 
|  | 1860 | props.Name = proptools.StringPtr(module.exportableSourceStubsLibraryModuleName(apiScope)) | 
|  | 1861 | props.Srcs = []string{":" + module.stubsSourceModuleName(apiScope) + "{.exportable}"} | 
|  | 1862 |  | 
| Paul Duffin | 859fe96 | 2020-05-15 10:20:31 +0100 | [diff] [blame] | 1863 | mctx.CreateModule(LibraryFactory, &props, module.sdkComponentPropertiesForChildLibrary()) | 
| Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1864 | } | 
|  | 1865 |  | 
| Paul Duffin | 6d0886e | 2020-04-07 18:49:53 +0100 | [diff] [blame] | 1866 | // Creates a droidstubs module that creates stubs source files from the given full source | 
| Paul Duffin | c878250 | 2020-04-29 20:45:27 +0100 | [diff] [blame] | 1867 | // files and also updates and checks the API specification files. | 
| Paul Duffin | 15f34ef | 2020-07-20 18:04:44 +0100 | [diff] [blame] | 1868 | func (module *SdkLibrary) createStubsSourcesAndApi(mctx android.DefaultableHookContext, apiScope *apiScope, name string, scopeSpecificDroidstubsArgs []string) { | 
| Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1869 | props := struct { | 
| Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 1870 | Name                             *string | 
| Paul Duffin | 4911a89 | 2020-04-29 23:35:13 +0100 | [diff] [blame] | 1871 | Visibility                       []string | 
| Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 1872 | Srcs                             []string | 
|  | 1873 | Installable                      *bool | 
| Paul Duffin | 52d398a | 2019-06-11 12:31:14 +0100 | [diff] [blame] | 1874 | Sdk_version                      *string | 
| Jihoon Kang | 3198f3c | 2023-01-26 08:08:52 +0000 | [diff] [blame] | 1875 | Api_surface                      *string | 
| Paul Duffin | 12ceb46 | 2019-12-24 20:31:31 +0000 | [diff] [blame] | 1876 | System_modules                   *string | 
| Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 1877 | Libs                             []string | 
| Paul Duffin | 6877e6d | 2020-09-25 19:59:14 +0100 | [diff] [blame] | 1878 | Output_javadoc_comments          *bool | 
| Paul Duffin | 1151247 | 2019-02-11 15:55:17 +0000 | [diff] [blame] | 1879 | Arg_files                        []string | 
| Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 1880 | Args                             *string | 
| Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 1881 | Java_version                     *string | 
| Paul Duffin | e22c2ab | 2020-05-20 19:35:27 +0100 | [diff] [blame] | 1882 | Annotations_enabled              *bool | 
| Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 1883 | Merge_annotations_dirs           []string | 
|  | 1884 | Merge_inclusion_annotations_dirs []string | 
| Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 1885 | Generate_stubs                   *bool | 
| Anton Hansson | e87b03d | 2020-12-21 15:29:34 +0000 | [diff] [blame] | 1886 | Previous_api                     *string | 
| Jihoon Kang | 6592e87 | 2023-12-19 01:13:16 +0000 | [diff] [blame] | 1887 | Aconfig_declarations             []string | 
| Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 1888 | Check_api                        struct { | 
| Anton Hansson | e605615 | 2020-12-31 10:37:27 +0000 | [diff] [blame] | 1889 | Current       ApiToCheck | 
|  | 1890 | Last_released ApiToCheck | 
| Paul Duffin | 160fe41 | 2020-05-10 19:32:20 +0100 | [diff] [blame] | 1891 |  | 
|  | 1892 | Api_lint struct { | 
|  | 1893 | Enabled       *bool | 
|  | 1894 | New_since     *string | 
|  | 1895 | Baseline_file *string | 
|  | 1896 | } | 
| Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 1897 | } | 
| Sundong Ahn | 1b92c82 | 2018-05-29 11:35:17 +0900 | [diff] [blame] | 1898 | Aidl struct { | 
|  | 1899 | Include_dirs       []string | 
|  | 1900 | Local_include_dirs []string | 
|  | 1901 | } | 
| Paul Duffin | 040e906 | 2020-11-23 17:41:36 +0000 | [diff] [blame] | 1902 | Dists []android.Dist | 
| Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1903 | }{} | 
|  | 1904 |  | 
| Paul Duffin | 7b78b4d | 2020-04-28 14:08:32 +0100 | [diff] [blame] | 1905 | // The stubs source processing uses the same compile time classpath when extracting the | 
|  | 1906 | // API from the implementation library as it does when compiling it. i.e. the same | 
|  | 1907 | // * sdk version | 
|  | 1908 | // * system_modules | 
|  | 1909 | // * libs (static_libs/libs) | 
| Paul Duffin | 250e619 | 2019-06-07 10:44:37 +0100 | [diff] [blame] | 1910 |  | 
| Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 1911 | props.Name = proptools.StringPtr(name) | 
| Anton Hansson | 944e77d | 2020-08-19 11:40:22 +0100 | [diff] [blame] | 1912 | props.Visibility = childModuleVisibility(module.sdkLibraryProperties.Stubs_source_visibility) | 
| Paul Duffin | a18abc2 | 2020-05-16 18:54:24 +0100 | [diff] [blame] | 1913 | props.Srcs = append(props.Srcs, module.properties.Srcs...) | 
| Anton Hansson | f8ea372 | 2021-09-16 14:24:13 +0100 | [diff] [blame] | 1914 | props.Srcs = append(props.Srcs, module.sdkLibraryProperties.Api_srcs...) | 
| Paul Duffin | a18abc2 | 2020-05-16 18:54:24 +0100 | [diff] [blame] | 1915 | props.Sdk_version = module.deviceProperties.Sdk_version | 
| Jihoon Kang | 3198f3c | 2023-01-26 08:08:52 +0000 | [diff] [blame] | 1916 | props.Api_surface = &apiScope.name | 
| Paul Duffin | a18abc2 | 2020-05-16 18:54:24 +0100 | [diff] [blame] | 1917 | props.System_modules = module.deviceProperties.System_modules | 
| Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1918 | props.Installable = proptools.BoolPtr(false) | 
| Sundong Ahn | e6f0b05 | 2018-06-05 16:46:14 +0900 | [diff] [blame] | 1919 | // A droiddoc module has only one Libs property and doesn't distinguish between | 
|  | 1920 | // shared libs and static libs. So we need to add both of these libs to Libs property. | 
| Paul Duffin | a18abc2 | 2020-05-16 18:54:24 +0100 | [diff] [blame] | 1921 | props.Libs = module.properties.Libs | 
|  | 1922 | props.Libs = append(props.Libs, module.properties.Static_libs...) | 
| Nikita Ioffe | d732da7 | 2022-11-21 12:38:25 +0000 | [diff] [blame] | 1923 | props.Libs = append(props.Libs, module.sdkLibraryProperties.Stub_only_libs...) | 
| Mark White | 9421c4c | 2023-08-10 00:07:03 +0000 | [diff] [blame] | 1924 | props.Libs = append(props.Libs, module.scopeToProperties[apiScope].Libs...) | 
| Paul Duffin | a18abc2 | 2020-05-16 18:54:24 +0100 | [diff] [blame] | 1925 | props.Aidl.Include_dirs = module.deviceProperties.Aidl.Include_dirs | 
|  | 1926 | props.Aidl.Local_include_dirs = module.deviceProperties.Aidl.Local_include_dirs | 
|  | 1927 | props.Java_version = module.properties.Java_version | 
| Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1928 |  | 
| Paul Duffin | e22c2ab | 2020-05-20 19:35:27 +0100 | [diff] [blame] | 1929 | props.Annotations_enabled = module.sdkLibraryProperties.Annotations_enabled | 
| Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 1930 | props.Merge_annotations_dirs = module.sdkLibraryProperties.Merge_annotations_dirs | 
|  | 1931 | props.Merge_inclusion_annotations_dirs = module.sdkLibraryProperties.Merge_inclusion_annotations_dirs | 
| Jihoon Kang | 6592e87 | 2023-12-19 01:13:16 +0000 | [diff] [blame] | 1932 | props.Aconfig_declarations = module.sdkLibraryProperties.Aconfig_declarations | 
| Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 1933 |  | 
| Paul Duffin | 6d0886e | 2020-04-07 18:49:53 +0100 | [diff] [blame] | 1934 | droidstubsArgs := []string{} | 
| Paul Duffin | 235ffff | 2019-12-24 10:41:30 +0000 | [diff] [blame] | 1935 | if len(module.sdkLibraryProperties.Api_packages) != 0 { | 
| Paul Duffin | 6d0886e | 2020-04-07 18:49:53 +0100 | [diff] [blame] | 1936 | droidstubsArgs = append(droidstubsArgs, "--stub-packages "+strings.Join(module.sdkLibraryProperties.Api_packages, ":")) | 
| Paul Duffin | 235ffff | 2019-12-24 10:41:30 +0000 | [diff] [blame] | 1937 | } | 
|  | 1938 | if len(module.sdkLibraryProperties.Hidden_api_packages) != 0 { | 
| Paul Duffin | 6d0886e | 2020-04-07 18:49:53 +0100 | [diff] [blame] | 1939 | droidstubsArgs = append(droidstubsArgs, | 
| Paul Duffin | 235ffff | 2019-12-24 10:41:30 +0000 | [diff] [blame] | 1940 | android.JoinWithPrefix(module.sdkLibraryProperties.Hidden_api_packages, " --hide-package ")) | 
|  | 1941 | } | 
| Paul Duffin | 6d0886e | 2020-04-07 18:49:53 +0100 | [diff] [blame] | 1942 | droidstubsArgs = append(droidstubsArgs, module.sdkLibraryProperties.Droiddoc_options...) | 
| Anton Hansson | fd1c0d2 | 2023-11-02 15:18:09 +0000 | [diff] [blame] | 1943 | disabledWarnings := []string{"HiddenSuperclass"} | 
|  | 1944 | if proptools.BoolDefault(module.sdkLibraryProperties.Api_lint.Legacy_errors_allowed, true) { | 
|  | 1945 | disabledWarnings = append(disabledWarnings, | 
|  | 1946 | "BroadcastBehavior", | 
|  | 1947 | "DeprecationMismatch", | 
|  | 1948 | "MissingPermission", | 
|  | 1949 | "SdkConstant", | 
|  | 1950 | "Todo", | 
|  | 1951 | ) | 
| Paul Duffin | 235ffff | 2019-12-24 10:41:30 +0000 | [diff] [blame] | 1952 | } | 
| Paul Duffin | 6d0886e | 2020-04-07 18:49:53 +0100 | [diff] [blame] | 1953 | droidstubsArgs = append(droidstubsArgs, android.JoinWithPrefix(disabledWarnings, "--hide ")) | 
| Sundong Ahn | fb2721f | 2018-09-17 13:23:09 +0900 | [diff] [blame] | 1954 |  | 
| Paul Duffin | 6877e6d | 2020-09-25 19:59:14 +0100 | [diff] [blame] | 1955 | // Output Javadoc comments for public scope. | 
|  | 1956 | if apiScope == apiScopePublic { | 
|  | 1957 | props.Output_javadoc_comments = proptools.BoolPtr(true) | 
|  | 1958 | } | 
|  | 1959 |  | 
| Paul Duffin | 1fb487d | 2020-04-07 18:50:10 +0100 | [diff] [blame] | 1960 | // Add in scope specific arguments. | 
| Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 1961 | droidstubsArgs = append(droidstubsArgs, scopeSpecificDroidstubsArgs...) | 
| Paul Duffin | 1151247 | 2019-02-11 15:55:17 +0000 | [diff] [blame] | 1962 | props.Arg_files = module.sdkLibraryProperties.Droiddoc_option_files | 
| Paul Duffin | 6d0886e | 2020-04-07 18:49:53 +0100 | [diff] [blame] | 1963 | props.Args = proptools.StringPtr(strings.Join(droidstubsArgs, " ")) | 
| Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1964 |  | 
| Paul Duffin | 15f34ef | 2020-07-20 18:04:44 +0100 | [diff] [blame] | 1965 | // List of APIs identified from the provided source files are created. They are later | 
|  | 1966 | // compared against to the not-yet-released (a.k.a current) list of APIs and to the | 
|  | 1967 | // last-released (a.k.a numbered) list of API. | 
|  | 1968 | currentApiFileName := apiScope.apiFilePrefix + "current.txt" | 
|  | 1969 | removedApiFileName := apiScope.apiFilePrefix + "removed.txt" | 
|  | 1970 | apiDir := module.getApiDir() | 
|  | 1971 | currentApiFileName = path.Join(apiDir, currentApiFileName) | 
|  | 1972 | removedApiFileName = path.Join(apiDir, removedApiFileName) | 
| Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1973 |  | 
| Paul Duffin | 15f34ef | 2020-07-20 18:04:44 +0100 | [diff] [blame] | 1974 | // check against the not-yet-release API | 
|  | 1975 | props.Check_api.Current.Api_file = proptools.StringPtr(currentApiFileName) | 
|  | 1976 | props.Check_api.Current.Removed_api_file = proptools.StringPtr(removedApiFileName) | 
| Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 1977 |  | 
| Paul Duffin | 958806b | 2022-05-16 13:10:47 +0000 | [diff] [blame] | 1978 | if module.compareAgainstLatestApi(apiScope) { | 
| Paul Duffin | 15f34ef | 2020-07-20 18:04:44 +0100 | [diff] [blame] | 1979 | // check against the latest released API | 
|  | 1980 | latestApiFilegroupName := proptools.StringPtr(module.latestApiFilegroupName(apiScope)) | 
| Anton Hansson | e87b03d | 2020-12-21 15:29:34 +0000 | [diff] [blame] | 1981 | props.Previous_api = latestApiFilegroupName | 
| Paul Duffin | 15f34ef | 2020-07-20 18:04:44 +0100 | [diff] [blame] | 1982 | props.Check_api.Last_released.Api_file = latestApiFilegroupName | 
|  | 1983 | props.Check_api.Last_released.Removed_api_file = proptools.StringPtr( | 
|  | 1984 | module.latestRemovedApiFilegroupName(apiScope)) | 
| Jaewoong Jung | 1a97ee0 | 2021-03-09 13:25:02 -0800 | [diff] [blame] | 1985 | props.Check_api.Last_released.Baseline_file = proptools.StringPtr( | 
|  | 1986 | module.latestIncompatibilitiesFilegroupName(apiScope)) | 
| Paul Duffin | 160fe41 | 2020-05-10 19:32:20 +0100 | [diff] [blame] | 1987 |  | 
| Paul Duffin | 15f34ef | 2020-07-20 18:04:44 +0100 | [diff] [blame] | 1988 | if proptools.Bool(module.sdkLibraryProperties.Api_lint.Enabled) { | 
|  | 1989 | // Enable api lint. | 
|  | 1990 | props.Check_api.Api_lint.Enabled = proptools.BoolPtr(true) | 
|  | 1991 | props.Check_api.Api_lint.New_since = latestApiFilegroupName | 
| Paul Duffin | 160fe41 | 2020-05-10 19:32:20 +0100 | [diff] [blame] | 1992 |  | 
| Paul Duffin | 15f34ef | 2020-07-20 18:04:44 +0100 | [diff] [blame] | 1993 | // If it exists then pass a lint-baseline.txt through to droidstubs. | 
|  | 1994 | baselinePath := path.Join(apiDir, apiScope.apiFilePrefix+"lint-baseline.txt") | 
|  | 1995 | baselinePathRelativeToRoot := path.Join(mctx.ModuleDir(), baselinePath) | 
|  | 1996 | paths, err := mctx.GlobWithDeps(baselinePathRelativeToRoot, nil) | 
|  | 1997 | if err != nil { | 
|  | 1998 | mctx.ModuleErrorf("error checking for presence of %s: %s", baselinePathRelativeToRoot, err) | 
|  | 1999 | } | 
|  | 2000 | if len(paths) == 1 { | 
|  | 2001 | props.Check_api.Api_lint.Baseline_file = proptools.StringPtr(baselinePath) | 
|  | 2002 | } else if len(paths) != 0 { | 
|  | 2003 | mctx.ModuleErrorf("error checking for presence of %s: expected one path, found: %v", baselinePathRelativeToRoot, paths) | 
| Paul Duffin | 160fe41 | 2020-05-10 19:32:20 +0100 | [diff] [blame] | 2004 | } | 
|  | 2005 | } | 
| Paul Duffin | 15f34ef | 2020-07-20 18:04:44 +0100 | [diff] [blame] | 2006 | } | 
| Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 2007 |  | 
| Paul Duffin | 15f34ef | 2020-07-20 18:04:44 +0100 | [diff] [blame] | 2008 | if !Bool(module.sdkLibraryProperties.No_dist) { | 
| Paul Duffin | 040e906 | 2020-11-23 17:41:36 +0000 | [diff] [blame] | 2009 | // Dist the api txt and removed api txt artifacts for sdk builds. | 
|  | 2010 | distDir := proptools.StringPtr(path.Join(module.apiDistPath(apiScope), "api")) | 
| Jihoon Kang | 0216805 | 2024-03-20 00:44:54 +0000 | [diff] [blame] | 2011 | stubsTypeTagPrefix := "" | 
|  | 2012 | if mctx.Config().ReleaseHiddenApiExportableStubs() { | 
|  | 2013 | stubsTypeTagPrefix = ".exportable" | 
|  | 2014 | } | 
| Paul Duffin | 040e906 | 2020-11-23 17:41:36 +0000 | [diff] [blame] | 2015 | for _, p := range []struct { | 
|  | 2016 | tag     string | 
|  | 2017 | pattern string | 
|  | 2018 | }{ | 
| Jihoon Kang | d1799f6 | 2024-02-20 23:01:38 +0000 | [diff] [blame] | 2019 | // "exportable" api files are copied to the dist directory instead of the | 
| Jihoon Kang | 0216805 | 2024-03-20 00:44:54 +0000 | [diff] [blame] | 2020 | // "everything" api files when "RELEASE_HIDDEN_API_EXPORTABLE_STUBS" build flag | 
|  | 2021 | // is set. Otherwise, the "everything" api files are copied to the dist directory. | 
|  | 2022 | {tag: "%s.api.txt", pattern: "%s.txt"}, | 
|  | 2023 | {tag: "%s.removed-api.txt", pattern: "%s-removed.txt"}, | 
| Paul Duffin | 040e906 | 2020-11-23 17:41:36 +0000 | [diff] [blame] | 2024 | } { | 
|  | 2025 | props.Dists = append(props.Dists, android.Dist{ | 
|  | 2026 | Targets: []string{"sdk", "win_sdk"}, | 
|  | 2027 | Dir:     distDir, | 
|  | 2028 | Dest:    proptools.StringPtr(fmt.Sprintf(p.pattern, module.distStem())), | 
| Jihoon Kang | 0216805 | 2024-03-20 00:44:54 +0000 | [diff] [blame] | 2029 | Tag:     proptools.StringPtr(fmt.Sprintf(p.tag, stubsTypeTagPrefix)), | 
| Paul Duffin | 040e906 | 2020-11-23 17:41:36 +0000 | [diff] [blame] | 2030 | }) | 
|  | 2031 | } | 
| Anton Hansson | 5fd5d24 | 2020-03-27 19:43:19 +0000 | [diff] [blame] | 2032 | } | 
|  | 2033 |  | 
| Spandan Das | 2cc80ba | 2023-10-27 17:21:52 +0000 | [diff] [blame] | 2034 | mctx.CreateModule(DroidstubsFactory, &props, module.sdkComponentPropertiesForChildLibrary()).(*Droidstubs).CallHookIfAvailable(mctx) | 
| Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 2035 | } | 
|  | 2036 |  | 
| Jihoon Kang | 0c705a4 | 2023-08-02 06:44:57 +0000 | [diff] [blame] | 2037 | func (module *SdkLibrary) createApiLibrary(mctx android.DefaultableHookContext, apiScope *apiScope, alternativeFullApiSurfaceStub string) { | 
| Jihoon Kang | 1c92c3e | 2023-03-23 17:44:51 +0000 | [diff] [blame] | 2038 | props := struct { | 
| Jihoon Kang | ca198c2 | 2023-06-22 23:13:51 +0000 | [diff] [blame] | 2039 | Name                  *string | 
|  | 2040 | Visibility            []string | 
|  | 2041 | Api_contributions     []string | 
|  | 2042 | Libs                  []string | 
|  | 2043 | Static_libs           []string | 
|  | 2044 | Full_api_surface_stub *string | 
| Jihoon Kang | 4ec2487 | 2023-10-05 17:26:09 +0000 | [diff] [blame] | 2045 | System_modules        *string | 
| Jihoon Kang | 063ec00 | 2023-06-28 01:16:23 +0000 | [diff] [blame] | 2046 | Enable_validation     *bool | 
| Jihoon Kang | 5d70127 | 2024-02-15 21:53:49 +0000 | [diff] [blame] | 2047 | Stubs_type            *string | 
| Jihoon Kang | 1c92c3e | 2023-03-23 17:44:51 +0000 | [diff] [blame] | 2048 | }{} | 
|  | 2049 |  | 
|  | 2050 | props.Name = proptools.StringPtr(module.apiLibraryModuleName(apiScope)) | 
| Jihoon Kang | 786df93 | 2023-09-07 01:18:31 +0000 | [diff] [blame] | 2051 | props.Visibility = []string{"//visibility:override", "//visibility:private"} | 
| Jihoon Kang | 1c92c3e | 2023-03-23 17:44:51 +0000 | [diff] [blame] | 2052 |  | 
|  | 2053 | apiContributions := []string{} | 
|  | 2054 |  | 
|  | 2055 | // Api surfaces are not independent of each other, but have subset relationships, | 
|  | 2056 | // and so does the api files. To generate from-text stubs for api surfaces other than public, | 
|  | 2057 | // all subset api domains' api_contriubtions must be added as well. | 
|  | 2058 | scope := apiScope | 
|  | 2059 | for scope != nil { | 
|  | 2060 | apiContributions = append(apiContributions, module.stubsSourceModuleName(scope)+".api.contribution") | 
|  | 2061 | scope = scope.extends | 
|  | 2062 | } | 
| Jihoon Kang | 0c705a4 | 2023-08-02 06:44:57 +0000 | [diff] [blame] | 2063 | if apiScope == apiScopePublic { | 
|  | 2064 | additionalApiContribution := module.apiLibraryAdditionalApiContribution() | 
|  | 2065 | if additionalApiContribution != "" { | 
|  | 2066 | apiContributions = append(apiContributions, additionalApiContribution) | 
|  | 2067 | } | 
|  | 2068 | } | 
| Jihoon Kang | 1c92c3e | 2023-03-23 17:44:51 +0000 | [diff] [blame] | 2069 |  | 
|  | 2070 | props.Api_contributions = apiContributions | 
|  | 2071 | props.Libs = module.properties.Libs | 
|  | 2072 | props.Libs = append(props.Libs, module.sdkLibraryProperties.Stub_only_libs...) | 
| Mark White | 9421c4c | 2023-08-10 00:07:03 +0000 | [diff] [blame] | 2073 | props.Libs = append(props.Libs, module.scopeToProperties[apiScope].Libs...) | 
| Jihoon Kang | 1c92c3e | 2023-03-23 17:44:51 +0000 | [diff] [blame] | 2074 | props.Libs = append(props.Libs, "stub-annotations") | 
|  | 2075 | props.Static_libs = module.sdkLibraryProperties.Stub_only_static_libs | 
| Jihoon Kang | e7ee256 | 2023-07-25 05:51:46 +0000 | [diff] [blame] | 2076 | props.Full_api_surface_stub = proptools.StringPtr(apiScope.kind.DefaultJavaLibraryName()) | 
| Jihoon Kang | 0c705a4 | 2023-08-02 06:44:57 +0000 | [diff] [blame] | 2077 | if alternativeFullApiSurfaceStub != "" { | 
|  | 2078 | props.Full_api_surface_stub = proptools.StringPtr(alternativeFullApiSurfaceStub) | 
|  | 2079 | } | 
| Jihoon Kang | 1c92c3e | 2023-03-23 17:44:51 +0000 | [diff] [blame] | 2080 |  | 
|  | 2081 | // android_module_lib_stubs_current.from-text only comprises api contributions from art, conscrypt and i18n. | 
|  | 2082 | // Thus, replace with android_module_lib_stubs_current_full.from-text, which comprises every api domains. | 
|  | 2083 | if apiScope.kind == android.SdkModule { | 
| Jihoon Kang | ca198c2 | 2023-06-22 23:13:51 +0000 | [diff] [blame] | 2084 | props.Full_api_surface_stub = proptools.StringPtr(apiScope.kind.DefaultJavaLibraryName() + "_full.from-text") | 
| Jihoon Kang | 1c92c3e | 2023-03-23 17:44:51 +0000 | [diff] [blame] | 2085 | } | 
|  | 2086 |  | 
| Jihoon Kang | d30ac8a | 2023-10-09 18:00:17 +0000 | [diff] [blame] | 2087 | // java_sdk_library modules that set sdk_version as none does not depend on other api | 
|  | 2088 | // domains. Therefore, java_api_library created from such modules should not depend on | 
|  | 2089 | // full_api_surface_stubs but create and compile stubs by the java_api_library module | 
|  | 2090 | // itself. | 
|  | 2091 | if module.SdkVersion(mctx).Kind == android.SdkNone { | 
|  | 2092 | props.Full_api_surface_stub = nil | 
|  | 2093 | } | 
|  | 2094 |  | 
| Jihoon Kang | 4ec2487 | 2023-10-05 17:26:09 +0000 | [diff] [blame] | 2095 | props.System_modules = module.deviceProperties.System_modules | 
| Jihoon Kang | 063ec00 | 2023-06-28 01:16:23 +0000 | [diff] [blame] | 2096 | props.Enable_validation = proptools.BoolPtr(true) | 
| Jihoon Kang | 5d70127 | 2024-02-15 21:53:49 +0000 | [diff] [blame] | 2097 | props.Stubs_type = proptools.StringPtr("everything") | 
| Jihoon Kang | 4ec2487 | 2023-10-05 17:26:09 +0000 | [diff] [blame] | 2098 |  | 
| Spandan Das | 2cc80ba | 2023-10-27 17:21:52 +0000 | [diff] [blame] | 2099 | mctx.CreateModule(ApiLibraryFactory, &props, module.sdkComponentPropertiesForChildLibrary()) | 
| Jihoon Kang | 1c92c3e | 2023-03-23 17:44:51 +0000 | [diff] [blame] | 2100 | } | 
|  | 2101 |  | 
| Jihoon Kang | 0216805 | 2024-03-20 00:44:54 +0000 | [diff] [blame] | 2102 | func (module *SdkLibrary) topLevelStubsLibraryProps(mctx android.DefaultableHookContext, apiScope *apiScope, doDist bool) libraryProperties { | 
| Jihoon Kang | fa4a90d | 2023-12-20 02:53:38 +0000 | [diff] [blame] | 2103 | props := libraryProperties{} | 
|  | 2104 |  | 
| Jihoon Kang | 1147b31 | 2023-06-08 23:25:57 +0000 | [diff] [blame] | 2105 | props.Visibility = childModuleVisibility(module.sdkLibraryProperties.Stubs_library_visibility) | 
|  | 2106 | sdkVersion := module.sdkVersionForStubsLibrary(mctx, apiScope) | 
|  | 2107 | props.Sdk_version = proptools.StringPtr(sdkVersion) | 
|  | 2108 |  | 
| Jihoon Kang | 1147b31 | 2023-06-08 23:25:57 +0000 | [diff] [blame] | 2109 | props.System_modules = module.deviceProperties.System_modules | 
|  | 2110 |  | 
| Jihoon Kang | 1147b31 | 2023-06-08 23:25:57 +0000 | [diff] [blame] | 2111 | // The imports need to be compiled to dex if the java_sdk_library requests it. | 
|  | 2112 | compileDex := module.dexProperties.Compile_dex | 
|  | 2113 | if module.stubLibrariesCompiledForDex() { | 
|  | 2114 | compileDex = proptools.BoolPtr(true) | 
|  | 2115 | } | 
|  | 2116 | props.Compile_dex = compileDex | 
|  | 2117 |  | 
| Jihoon Kang | 0216805 | 2024-03-20 00:44:54 +0000 | [diff] [blame] | 2118 | if !Bool(module.sdkLibraryProperties.No_dist) && doDist { | 
|  | 2119 | props.Dist.Targets = []string{"sdk", "win_sdk"} | 
|  | 2120 | props.Dist.Dest = proptools.StringPtr(fmt.Sprintf("%v.jar", module.distStem())) | 
|  | 2121 | props.Dist.Dir = proptools.StringPtr(module.apiDistPath(apiScope)) | 
|  | 2122 | props.Dist.Tag = proptools.StringPtr(".jar") | 
|  | 2123 | } | 
|  | 2124 |  | 
| Jihoon Kang | fa4a90d | 2023-12-20 02:53:38 +0000 | [diff] [blame] | 2125 | return props | 
|  | 2126 | } | 
|  | 2127 |  | 
|  | 2128 | func (module *SdkLibrary) createTopLevelStubsLibrary( | 
|  | 2129 | mctx android.DefaultableHookContext, apiScope *apiScope, contributesToApiSurface bool) { | 
|  | 2130 |  | 
| Jihoon Kang | 0216805 | 2024-03-20 00:44:54 +0000 | [diff] [blame] | 2131 | // Dist the "everything" stubs when the RELEASE_HIDDEN_API_EXPORTABLE_STUBS build flag is false | 
|  | 2132 | doDist := !mctx.Config().ReleaseHiddenApiExportableStubs() | 
|  | 2133 | props := module.topLevelStubsLibraryProps(mctx, apiScope, doDist) | 
| Jihoon Kang | fa4a90d | 2023-12-20 02:53:38 +0000 | [diff] [blame] | 2134 | props.Name = proptools.StringPtr(module.stubsLibraryModuleName(apiScope)) | 
|  | 2135 |  | 
|  | 2136 | // Add the stub compiling java_library/java_api_library as static lib based on build config | 
|  | 2137 | staticLib := module.sourceStubsLibraryModuleName(apiScope) | 
|  | 2138 | if mctx.Config().BuildFromTextStub() && contributesToApiSurface { | 
|  | 2139 | staticLib = module.apiLibraryModuleName(apiScope) | 
|  | 2140 | } | 
|  | 2141 | props.Static_libs = append(props.Static_libs, staticLib) | 
|  | 2142 |  | 
|  | 2143 | mctx.CreateModule(LibraryFactory, &props, module.sdkComponentPropertiesForChildLibrary()) | 
|  | 2144 | } | 
|  | 2145 |  | 
|  | 2146 | func (module *SdkLibrary) createTopLevelExportableStubsLibrary( | 
|  | 2147 | mctx android.DefaultableHookContext, apiScope *apiScope) { | 
|  | 2148 |  | 
| Jihoon Kang | 0216805 | 2024-03-20 00:44:54 +0000 | [diff] [blame] | 2149 | // Dist the "exportable" stubs when the RELEASE_HIDDEN_API_EXPORTABLE_STUBS build flag is true | 
|  | 2150 | doDist := mctx.Config().ReleaseHiddenApiExportableStubs() | 
|  | 2151 | props := module.topLevelStubsLibraryProps(mctx, apiScope, doDist) | 
| Jihoon Kang | fa4a90d | 2023-12-20 02:53:38 +0000 | [diff] [blame] | 2152 | props.Name = proptools.StringPtr(module.exportableStubsLibraryModuleName(apiScope)) | 
|  | 2153 |  | 
| Jihoon Kang | fa4a90d | 2023-12-20 02:53:38 +0000 | [diff] [blame] | 2154 | staticLib := module.exportableSourceStubsLibraryModuleName(apiScope) | 
|  | 2155 | props.Static_libs = append(props.Static_libs, staticLib) | 
|  | 2156 |  | 
| Jihoon Kang | 1147b31 | 2023-06-08 23:25:57 +0000 | [diff] [blame] | 2157 | mctx.CreateModule(LibraryFactory, &props, module.sdkComponentPropertiesForChildLibrary()) | 
|  | 2158 | } | 
|  | 2159 |  | 
| Paul Duffin | 958806b | 2022-05-16 13:10:47 +0000 | [diff] [blame] | 2160 | func (module *SdkLibrary) compareAgainstLatestApi(apiScope *apiScope) bool { | 
|  | 2161 | return !(apiScope.unstable || module.sdkLibraryProperties.Unsafe_ignore_missing_latest_api) | 
|  | 2162 | } | 
|  | 2163 |  | 
| Paul Duffin | ea8f808 | 2021-06-24 13:25:57 +0100 | [diff] [blame] | 2164 | // Implements android.ApexModule | 
| Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 2165 | func (module *SdkLibrary) DepIsInSameApex(mctx android.BaseModuleContext, dep android.Module) bool { | 
|  | 2166 | depTag := mctx.OtherModuleDependencyTag(dep) | 
|  | 2167 | if depTag == xmlPermissionsFileTag { | 
|  | 2168 | return true | 
|  | 2169 | } | 
|  | 2170 | return module.Library.DepIsInSameApex(mctx, dep) | 
|  | 2171 | } | 
|  | 2172 |  | 
| Paul Duffin | ea8f808 | 2021-06-24 13:25:57 +0100 | [diff] [blame] | 2173 | // Implements android.ApexModule | 
|  | 2174 | func (module *SdkLibrary) UniqueApexVariations() bool { | 
|  | 2175 | return module.uniqueApexVariations() | 
|  | 2176 | } | 
|  | 2177 |  | 
| Jihoon Kang | 80456fd | 2023-11-15 19:22:14 +0000 | [diff] [blame] | 2178 | func (module *SdkLibrary) ContributeToApi() bool { | 
|  | 2179 | return proptools.BoolDefault(module.sdkLibraryProperties.Contribute_to_android_api, false) | 
|  | 2180 | } | 
|  | 2181 |  | 
| Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 2182 | // Creates the xml file that publicizes the runtime library | 
| Paul Duffin | f022920 | 2020-04-29 16:47:28 +0100 | [diff] [blame] | 2183 | func (module *SdkLibrary) createXmlFile(mctx android.DefaultableHookContext) { | 
| Spandan Das | 8c9ae7e | 2023-03-03 21:20:36 +0000 | [diff] [blame] | 2184 | moduleMinApiLevel := module.Library.MinSdkVersion(mctx) | 
| Pedro Loureiro | c362142 | 2021-09-28 15:40:23 +0000 | [diff] [blame] | 2185 | var moduleMinApiLevelStr = moduleMinApiLevel.String() | 
|  | 2186 | if moduleMinApiLevel == android.NoneApiLevel { | 
|  | 2187 | moduleMinApiLevelStr = "current" | 
|  | 2188 | } | 
| Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 2189 | props := struct { | 
| Pedro Loureiro | c362142 | 2021-09-28 15:40:23 +0000 | [diff] [blame] | 2190 | Name                      *string | 
|  | 2191 | Lib_name                  *string | 
|  | 2192 | Apex_available            []string | 
|  | 2193 | On_bootclasspath_since    *string | 
|  | 2194 | On_bootclasspath_before   *string | 
|  | 2195 | Min_device_sdk            *string | 
|  | 2196 | Max_device_sdk            *string | 
|  | 2197 | Sdk_library_min_api_level *string | 
| Jamie Garside | e570ace | 2023-11-27 12:07:36 +0000 | [diff] [blame] | 2198 | Uses_libs_dependencies    []string | 
| Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 2199 | }{ | 
| Pedro Loureiro | c362142 | 2021-09-28 15:40:23 +0000 | [diff] [blame] | 2200 | Name:                      proptools.StringPtr(module.xmlPermissionsModuleName()), | 
|  | 2201 | Lib_name:                  proptools.StringPtr(module.BaseModuleName()), | 
|  | 2202 | Apex_available:            module.ApexProperties.Apex_available, | 
|  | 2203 | On_bootclasspath_since:    module.commonSdkLibraryProperties.On_bootclasspath_since, | 
|  | 2204 | On_bootclasspath_before:   module.commonSdkLibraryProperties.On_bootclasspath_before, | 
|  | 2205 | Min_device_sdk:            module.commonSdkLibraryProperties.Min_device_sdk, | 
|  | 2206 | Max_device_sdk:            module.commonSdkLibraryProperties.Max_device_sdk, | 
|  | 2207 | Sdk_library_min_api_level: &moduleMinApiLevelStr, | 
| Jamie Garside | e570ace | 2023-11-27 12:07:36 +0000 | [diff] [blame] | 2208 | Uses_libs_dependencies:    module.usesLibraryProperties.Uses_libs, | 
| Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 2209 | } | 
| Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 2210 |  | 
| Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 2211 | mctx.CreateModule(sdkLibraryXmlFactory, &props) | 
| Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 2212 | } | 
|  | 2213 |  | 
| Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 2214 | func PrebuiltJars(ctx android.BaseModuleContext, baseName string, s android.SdkSpec) android.Paths { | 
| Jiyong Park | 54105c4 | 2021-03-31 18:17:53 +0900 | [diff] [blame] | 2215 | var ver android.ApiLevel | 
| Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 2216 | var kind android.SdkKind | 
|  | 2217 | if s.UsePrebuilt(ctx) { | 
| Jiyong Park | 54105c4 | 2021-03-31 18:17:53 +0900 | [diff] [blame] | 2218 | ver = s.ApiLevel | 
| Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 2219 | kind = s.Kind | 
| Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 2220 | } else { | 
| Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 2221 | // We don't have prebuilt SDK for the specific sdkVersion. | 
|  | 2222 | // Instead of breaking the build, fallback to use "system_current" | 
| Jiyong Park | 54105c4 | 2021-03-31 18:17:53 +0900 | [diff] [blame] | 2223 | ver = android.FutureApiLevel | 
| Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 2224 | kind = android.SdkSystem | 
| Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 2225 | } | 
| Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 2226 |  | 
|  | 2227 | dir := filepath.Join("prebuilts", "sdk", ver.String(), kind.String()) | 
| Paul Duffin | 5006151 | 2020-01-21 16:31:05 +0000 | [diff] [blame] | 2228 | jar := filepath.Join(dir, baseName+".jar") | 
| Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 2229 | jarPath := android.ExistentPathForSource(ctx, jar) | 
| Sundong Ahn | ae418ac | 2019-02-28 15:01:28 +0900 | [diff] [blame] | 2230 | if !jarPath.Valid() { | 
| Colin Cross | 07c8856 | 2020-01-07 09:34:44 -0800 | [diff] [blame] | 2231 | if ctx.Config().AllowMissingDependencies() { | 
|  | 2232 | return android.Paths{android.PathForSource(ctx, jar)} | 
|  | 2233 | } else { | 
| Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 2234 | ctx.PropertyErrorf("sdk_library", "invalid sdk version %q, %q does not exist", s.Raw, jar) | 
| Colin Cross | 07c8856 | 2020-01-07 09:34:44 -0800 | [diff] [blame] | 2235 | } | 
| Sundong Ahn | ae418ac | 2019-02-28 15:01:28 +0900 | [diff] [blame] | 2236 | return nil | 
|  | 2237 | } | 
| Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 2238 | return android.Paths{jarPath.Path()} | 
|  | 2239 | } | 
|  | 2240 |  | 
| Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 2241 | // Check to see if the other module is within the same set of named APEXes as this module. | 
| Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 2242 | // | 
|  | 2243 | // If either this or the other module are on the platform then this will return | 
|  | 2244 | // false. | 
| Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 2245 | func withinSameApexesAs(ctx android.BaseModuleContext, other android.Module) bool { | 
| Colin Cross | ff694a8 | 2023-12-13 15:54:49 -0800 | [diff] [blame] | 2246 | apexInfo, _ := android.ModuleProvider(ctx, android.ApexInfoProvider) | 
| Colin Cross | 313aa54 | 2023-12-13 13:47:44 -0800 | [diff] [blame] | 2247 | otherApexInfo, _ := android.OtherModuleProvider(ctx, other, android.ApexInfoProvider) | 
| Jiyong Park | ab50b07 | 2021-05-12 17:13:56 +0900 | [diff] [blame] | 2248 | return len(otherApexInfo.InApexVariants) > 0 && reflect.DeepEqual(apexInfo.InApexVariants, otherApexInfo.InApexVariants) | 
| Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 2249 | } | 
|  | 2250 |  | 
| Jihoon Kang | 8479dea | 2024-04-04 01:19:05 +0000 | [diff] [blame] | 2251 | func (module *SdkLibrary) sdkJars(ctx android.BaseModuleContext, sdkVersion android.SdkSpec) android.Paths { | 
| Jiyong Park | 932cdfe | 2020-05-28 00:19:53 +0900 | [diff] [blame] | 2252 | // If the client doesn't set sdk_version, but if this library prefers stubs over | 
|  | 2253 | // the impl library, let's provide the widest API surface possible. To do so, | 
|  | 2254 | // force override sdk_version to module_current so that the closest possible API | 
|  | 2255 | // surface could be found in selectHeaderJarsForSdkVersion | 
| Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 2256 | if module.defaultsToStubs() && !sdkVersion.Specified() { | 
| Jiyong Park | 9231537 | 2021-04-02 08:45:46 +0900 | [diff] [blame] | 2257 | sdkVersion = android.SdkSpecFrom(ctx, "module_current") | 
| Jiyong Park | 932cdfe | 2020-05-28 00:19:53 +0900 | [diff] [blame] | 2258 | } | 
| Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 2259 |  | 
| Paul Duffin | daaa332 | 2020-05-26 18:13:57 +0100 | [diff] [blame] | 2260 | // Only provide access to the implementation library if it is actually built. | 
|  | 2261 | if module.requiresRuntimeImplementationLibrary() { | 
|  | 2262 | // Check any special cases for java_sdk_library. | 
|  | 2263 | // | 
|  | 2264 | // Only allow access to the implementation library in the following condition: | 
|  | 2265 | // * No sdk_version specified on the referencing module. | 
| Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 2266 | // * The referencing module is in the same apex as this. | 
| Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 2267 | if sdkVersion.Kind == android.SdkPrivate || withinSameApexesAs(ctx, module) { | 
| Jihoon Kang | 8479dea | 2024-04-04 01:19:05 +0000 | [diff] [blame] | 2268 | return module.implLibraryHeaderJars | 
| Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 2269 | } | 
| Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 2270 | } | 
| Paul Duffin | b05d429 | 2020-05-20 12:19:10 +0100 | [diff] [blame] | 2271 |  | 
| Paul Duffin | 23970f4 | 2020-05-20 14:20:02 +0100 | [diff] [blame] | 2272 | return module.selectHeaderJarsForSdkVersion(ctx, sdkVersion) | 
| Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 2273 | } | 
|  | 2274 |  | 
| Sundong Ahn | 241cd37 | 2018-07-13 16:16:44 +0900 | [diff] [blame] | 2275 | // to satisfy SdkLibraryDependency interface | 
| Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 2276 | func (module *SdkLibrary) SdkHeaderJars(ctx android.BaseModuleContext, sdkVersion android.SdkSpec) android.Paths { | 
| Jihoon Kang | 8479dea | 2024-04-04 01:19:05 +0000 | [diff] [blame] | 2277 | return module.sdkJars(ctx, sdkVersion) | 
| Sundong Ahn | 241cd37 | 2018-07-13 16:16:44 +0900 | [diff] [blame] | 2278 | } | 
|  | 2279 |  | 
| Colin Cross | 571cccf | 2019-02-04 11:22:08 -0800 | [diff] [blame] | 2280 | var javaSdkLibrariesKey = android.NewOnceKey("javaSdkLibraries") | 
|  | 2281 |  | 
| Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 2282 | func javaSdkLibraries(config android.Config) *[]string { | 
| Colin Cross | 571cccf | 2019-02-04 11:22:08 -0800 | [diff] [blame] | 2283 | return config.Once(javaSdkLibrariesKey, func() interface{} { | 
| Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 2284 | return &[]string{} | 
|  | 2285 | }).(*[]string) | 
|  | 2286 | } | 
|  | 2287 |  | 
| Paul Duffin | 749f98f | 2019-12-30 17:23:46 +0000 | [diff] [blame] | 2288 | func (module *SdkLibrary) getApiDir() string { | 
|  | 2289 | return proptools.StringDefault(module.sdkLibraryProperties.Api_dir, "api") | 
|  | 2290 | } | 
|  | 2291 |  | 
| Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 2292 | // For a java_sdk_library module, create internal modules for stubs, docs, | 
|  | 2293 | // runtime libs and xml file. If requested, the stubs and docs are created twice | 
|  | 2294 | // once for public API level and once for system API level | 
| Paul Duffin | f022920 | 2020-04-29 16:47:28 +0100 | [diff] [blame] | 2295 | func (module *SdkLibrary) CreateInternalModules(mctx android.DefaultableHookContext) { | 
|  | 2296 | // If the module has been disabled then don't create any child modules. | 
|  | 2297 | if !module.Enabled() { | 
|  | 2298 | return | 
|  | 2299 | } | 
|  | 2300 |  | 
| Paul Duffin | a18abc2 | 2020-05-16 18:54:24 +0100 | [diff] [blame] | 2301 | if len(module.properties.Srcs) == 0 { | 
| Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 2302 | mctx.PropertyErrorf("srcs", "java_sdk_library must specify srcs") | 
| Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 2303 | return | 
| Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 2304 | } | 
|  | 2305 |  | 
| Paul Duffin | 37e0b77 | 2019-12-30 17:20:10 +0000 | [diff] [blame] | 2306 | // If this builds against standard libraries (i.e. is not part of the core libraries) | 
| Paul Duffin | 4f5c1ef | 2020-11-19 14:53:43 +0000 | [diff] [blame] | 2307 | // then assume it provides both system and test apis. | 
| Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 2308 | sdkDep := decodeSdkDep(mctx, android.SdkContext(&module.Library)) | 
| Paul Duffin | 37e0b77 | 2019-12-30 17:20:10 +0000 | [diff] [blame] | 2309 | hasSystemAndTestApis := sdkDep.hasStandardLibs() | 
| Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 2310 | module.sdkLibraryProperties.Generate_system_and_test_apis = hasSystemAndTestApis | 
| Paul Duffin | 4f5c1ef | 2020-11-19 14:53:43 +0000 | [diff] [blame] | 2311 |  | 
| Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 2312 | missingCurrentApi := false | 
| Inseob Kim | 8098faa | 2019-03-18 10:19:51 +0900 | [diff] [blame] | 2313 |  | 
| Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 2314 | generatedScopes := module.getGeneratedApiScopes(mctx) | 
| Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 2315 |  | 
| Paul Duffin | 749f98f | 2019-12-30 17:23:46 +0000 | [diff] [blame] | 2316 | apiDir := module.getApiDir() | 
| Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 2317 | for _, scope := range generatedScopes { | 
| Inseob Kim | 8098faa | 2019-03-18 10:19:51 +0900 | [diff] [blame] | 2318 | for _, api := range []string{"current.txt", "removed.txt"} { | 
| Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 2319 | path := path.Join(mctx.ModuleDir(), apiDir, scope.apiFilePrefix+api) | 
| Inseob Kim | 8098faa | 2019-03-18 10:19:51 +0900 | [diff] [blame] | 2320 | p := android.ExistentPathForSource(mctx, path) | 
|  | 2321 | if !p.Valid() { | 
| Colin Cross | 18f840c | 2021-05-20 17:56:54 -0700 | [diff] [blame] | 2322 | if mctx.Config().AllowMissingDependencies() { | 
|  | 2323 | mctx.AddMissingDependencies([]string{path}) | 
|  | 2324 | } else { | 
|  | 2325 | mctx.ModuleErrorf("Current api file %#v doesn't exist", path) | 
|  | 2326 | missingCurrentApi = true | 
|  | 2327 | } | 
| Inseob Kim | 8098faa | 2019-03-18 10:19:51 +0900 | [diff] [blame] | 2328 | } | 
|  | 2329 | } | 
|  | 2330 | } | 
|  | 2331 |  | 
| Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 2332 | if missingCurrentApi { | 
| Inseob Kim | 8098faa | 2019-03-18 10:19:51 +0900 | [diff] [blame] | 2333 | script := "build/soong/scripts/gen-java-current-api-files.sh" | 
|  | 2334 | p := android.ExistentPathForSource(mctx, script) | 
|  | 2335 |  | 
|  | 2336 | if !p.Valid() { | 
|  | 2337 | panic(fmt.Sprintf("script file %s doesn't exist", script)) | 
|  | 2338 | } | 
|  | 2339 |  | 
|  | 2340 | mctx.ModuleErrorf("One or more current api files are missing. "+ | 
|  | 2341 | "You can update them by:\n"+ | 
| Paul Duffin | 37e0b77 | 2019-12-30 17:20:10 +0000 | [diff] [blame] | 2342 | "%s %q %s && m update-api", | 
| Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 2343 | script, filepath.Join(mctx.ModuleDir(), apiDir), | 
| Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 2344 | strings.Join(generatedScopes.Strings(func(s *apiScope) string { return s.apiFilePrefix }), " ")) | 
| Inseob Kim | 8098faa | 2019-03-18 10:19:51 +0900 | [diff] [blame] | 2345 | return | 
|  | 2346 | } | 
|  | 2347 |  | 
| Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 2348 | for _, scope := range generatedScopes { | 
| Paul Duffin | 15f34ef | 2020-07-20 18:04:44 +0100 | [diff] [blame] | 2349 | // Use the stubs source name for legacy reasons. | 
|  | 2350 | module.createStubsSourcesAndApi(mctx, scope, module.stubsSourceModuleName(scope), scope.droidstubsArgs) | 
| Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 2351 |  | 
| Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 2352 | module.createStubsLibrary(mctx, scope) | 
| Jihoon Kang | fa4a90d | 2023-12-20 02:53:38 +0000 | [diff] [blame] | 2353 | module.createExportableStubsLibrary(mctx, scope) | 
| Jihoon Kang | 1c92c3e | 2023-03-23 17:44:51 +0000 | [diff] [blame] | 2354 |  | 
| Jihoon Kang | 0c705a4 | 2023-08-02 06:44:57 +0000 | [diff] [blame] | 2355 | alternativeFullApiSurfaceStubLib := "" | 
|  | 2356 | if scope == apiScopePublic { | 
|  | 2357 | alternativeFullApiSurfaceStubLib = module.alternativeFullApiSurfaceStubLib() | 
|  | 2358 | } | 
|  | 2359 | contributesToApiSurface := module.contributesToApiSurface(mctx.Config()) || alternativeFullApiSurfaceStubLib != "" | 
| Jihoon Kang | 1147b31 | 2023-06-08 23:25:57 +0000 | [diff] [blame] | 2360 | if contributesToApiSurface { | 
| Jihoon Kang | 0c705a4 | 2023-08-02 06:44:57 +0000 | [diff] [blame] | 2361 | module.createApiLibrary(mctx, scope, alternativeFullApiSurfaceStubLib) | 
| Jihoon Kang | 1c92c3e | 2023-03-23 17:44:51 +0000 | [diff] [blame] | 2362 | } | 
| Jihoon Kang | 1147b31 | 2023-06-08 23:25:57 +0000 | [diff] [blame] | 2363 |  | 
|  | 2364 | module.createTopLevelStubsLibrary(mctx, scope, contributesToApiSurface) | 
| Jihoon Kang | fa4a90d | 2023-12-20 02:53:38 +0000 | [diff] [blame] | 2365 | module.createTopLevelExportableStubsLibrary(mctx, scope) | 
| Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 2366 | } | 
|  | 2367 |  | 
| Paul Duffin | dfa131e | 2020-05-15 20:37:11 +0100 | [diff] [blame] | 2368 | if module.requiresRuntimeImplementationLibrary() { | 
| Paul Duffin | 5df7930 | 2020-05-16 15:52:12 +0100 | [diff] [blame] | 2369 | // Create child module to create an implementation library. | 
|  | 2370 | // | 
|  | 2371 | // This temporarily creates a second implementation library that can be explicitly | 
|  | 2372 | // referenced. | 
|  | 2373 | // | 
|  | 2374 | // TODO(b/156618935) - update comment once only one implementation library is created. | 
|  | 2375 | module.createImplLibrary(mctx) | 
|  | 2376 |  | 
| Paul Duffin | dfa131e | 2020-05-15 20:37:11 +0100 | [diff] [blame] | 2377 | // Only create an XML permissions file that declares the library as being usable | 
|  | 2378 | // as a shared library if required. | 
|  | 2379 | if module.sharedLibrary() { | 
|  | 2380 | module.createXmlFile(mctx) | 
|  | 2381 | } | 
| Paul Duffin | 43db9be | 2019-12-30 17:35:49 +0000 | [diff] [blame] | 2382 |  | 
|  | 2383 | // record java_sdk_library modules so that they are exported to make | 
|  | 2384 | javaSdkLibraries := javaSdkLibraries(mctx.Config()) | 
|  | 2385 | javaSdkLibrariesLock.Lock() | 
|  | 2386 | defer javaSdkLibrariesLock.Unlock() | 
|  | 2387 | *javaSdkLibraries = append(*javaSdkLibraries, module.BaseModuleName()) | 
|  | 2388 | } | 
| Anton Hansson | 7f66efa | 2020-10-08 14:47:23 +0100 | [diff] [blame] | 2389 |  | 
| Paul Duffin | 77590a8 | 2022-04-28 14:13:30 +0000 | [diff] [blame] | 2390 | // Add the impl_only_libs and impl_only_static_libs *after* we're done using them in submodules. | 
| Anton Hansson | 7f66efa | 2020-10-08 14:47:23 +0100 | [diff] [blame] | 2391 | module.properties.Libs = append(module.properties.Libs, module.sdkLibraryProperties.Impl_only_libs...) | 
| Paul Duffin | 77590a8 | 2022-04-28 14:13:30 +0000 | [diff] [blame] | 2392 | module.properties.Static_libs = append(module.properties.Static_libs, module.sdkLibraryProperties.Impl_only_static_libs...) | 
| Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 2393 | } | 
|  | 2394 |  | 
|  | 2395 | func (module *SdkLibrary) InitSdkLibraryProperties() { | 
| Colin Cross | ce6734e | 2020-06-15 16:09:53 -0700 | [diff] [blame] | 2396 | module.addHostAndDeviceProperties() | 
|  | 2397 | module.AddProperties(&module.sdkLibraryProperties) | 
| Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 2398 |  | 
| Paul Duffin | 71b33cc | 2021-06-23 11:39:47 +0100 | [diff] [blame] | 2399 | module.initSdkLibraryComponent(module) | 
| Paul Duffin | 859fe96 | 2020-05-15 10:20:31 +0100 | [diff] [blame] | 2400 |  | 
| Paul Duffin | a18abc2 | 2020-05-16 18:54:24 +0100 | [diff] [blame] | 2401 | module.properties.Installable = proptools.BoolPtr(true) | 
|  | 2402 | module.deviceProperties.IsSDKLibrary = true | 
| Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 2403 | } | 
| Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 2404 |  | 
| Paul Duffin | dfa131e | 2020-05-15 20:37:11 +0100 | [diff] [blame] | 2405 | func (module *SdkLibrary) requiresRuntimeImplementationLibrary() bool { | 
|  | 2406 | return !proptools.Bool(module.sdkLibraryProperties.Api_only) | 
|  | 2407 | } | 
|  | 2408 |  | 
| Jiyong Park | 932cdfe | 2020-05-28 00:19:53 +0900 | [diff] [blame] | 2409 | func (module *SdkLibrary) defaultsToStubs() bool { | 
|  | 2410 | return proptools.Bool(module.sdkLibraryProperties.Default_to_stubs) | 
|  | 2411 | } | 
|  | 2412 |  | 
| Paul Duffin | 1b1e806 | 2020-05-08 13:44:43 +0100 | [diff] [blame] | 2413 | // Defines how to name the individual component modules the sdk library creates. | 
|  | 2414 | type sdkLibraryComponentNamingScheme interface { | 
|  | 2415 | stubsLibraryModuleName(scope *apiScope, baseName string) string | 
|  | 2416 |  | 
|  | 2417 | stubsSourceModuleName(scope *apiScope, baseName string) string | 
| Jihoon Kang | 1c92c3e | 2023-03-23 17:44:51 +0000 | [diff] [blame] | 2418 |  | 
|  | 2419 | apiLibraryModuleName(scope *apiScope, baseName string) string | 
| Jihoon Kang | 1147b31 | 2023-06-08 23:25:57 +0000 | [diff] [blame] | 2420 |  | 
| Jihoon Kang | fa4a90d | 2023-12-20 02:53:38 +0000 | [diff] [blame] | 2421 | sourceStubsLibraryModuleName(scope *apiScope, baseName string) string | 
|  | 2422 |  | 
|  | 2423 | exportableStubsLibraryModuleName(scope *apiScope, baseName string) string | 
|  | 2424 |  | 
|  | 2425 | exportableSourceStubsLibraryModuleName(scope *apiScope, baseName string) string | 
| Paul Duffin | 1b1e806 | 2020-05-08 13:44:43 +0100 | [diff] [blame] | 2426 | } | 
|  | 2427 |  | 
|  | 2428 | type defaultNamingScheme struct { | 
|  | 2429 | } | 
|  | 2430 |  | 
|  | 2431 | func (s *defaultNamingScheme) stubsLibraryModuleName(scope *apiScope, baseName string) string { | 
|  | 2432 | return scope.stubsLibraryModuleName(baseName) | 
|  | 2433 | } | 
|  | 2434 |  | 
|  | 2435 | func (s *defaultNamingScheme) stubsSourceModuleName(scope *apiScope, baseName string) string { | 
|  | 2436 | return scope.stubsSourceModuleName(baseName) | 
|  | 2437 | } | 
|  | 2438 |  | 
| Jihoon Kang | 1c92c3e | 2023-03-23 17:44:51 +0000 | [diff] [blame] | 2439 | func (s *defaultNamingScheme) apiLibraryModuleName(scope *apiScope, baseName string) string { | 
|  | 2440 | return scope.apiLibraryModuleName(baseName) | 
|  | 2441 | } | 
|  | 2442 |  | 
| Jihoon Kang | fa4a90d | 2023-12-20 02:53:38 +0000 | [diff] [blame] | 2443 | func (s *defaultNamingScheme) sourceStubsLibraryModuleName(scope *apiScope, baseName string) string { | 
| Jihoon Kang | 1147b31 | 2023-06-08 23:25:57 +0000 | [diff] [blame] | 2444 | return scope.sourceStubLibraryModuleName(baseName) | 
|  | 2445 | } | 
|  | 2446 |  | 
| Jihoon Kang | fa4a90d | 2023-12-20 02:53:38 +0000 | [diff] [blame] | 2447 | func (s *defaultNamingScheme) exportableStubsLibraryModuleName(scope *apiScope, baseName string) string { | 
|  | 2448 | return scope.exportableStubsLibraryModuleName(baseName) | 
|  | 2449 | } | 
|  | 2450 |  | 
|  | 2451 | func (s *defaultNamingScheme) exportableSourceStubsLibraryModuleName(scope *apiScope, baseName string) string { | 
|  | 2452 | return scope.exportableSourceStubsLibraryModuleName(baseName) | 
|  | 2453 | } | 
|  | 2454 |  | 
| Paul Duffin | 1b1e806 | 2020-05-08 13:44:43 +0100 | [diff] [blame] | 2455 | var _ sdkLibraryComponentNamingScheme = (*defaultNamingScheme)(nil) | 
|  | 2456 |  | 
| Jihoon Kang | fa4a90d | 2023-12-20 02:53:38 +0000 | [diff] [blame] | 2457 | func hasStubsLibrarySuffix(name string, apiScope *apiScope) bool { | 
|  | 2458 | return strings.HasSuffix(name, apiScope.stubsLibraryModuleNameSuffix()) || | 
|  | 2459 | strings.HasSuffix(name, apiScope.exportableStubsLibraryModuleNameSuffix()) | 
|  | 2460 | } | 
|  | 2461 |  | 
| Jaewoong Jung | bc15e3a | 2021-03-10 17:02:43 -0800 | [diff] [blame] | 2462 | func moduleStubLinkType(name string) (stub bool, ret sdkLinkType) { | 
| Jihoon Kang | 1147b31 | 2023-06-08 23:25:57 +0000 | [diff] [blame] | 2463 | name = strings.TrimSuffix(name, ".from-source") | 
|  | 2464 |  | 
| Anton Hansson | 2d0c194 | 2020-05-25 12:20:51 +0100 | [diff] [blame] | 2465 | // This suffix-based approach is fragile and could potentially mis-trigger. | 
|  | 2466 | // TODO(b/155164730): Clean this up when modules no longer reference sdk_lib stubs directly. | 
| Jihoon Kang | fa4a90d | 2023-12-20 02:53:38 +0000 | [diff] [blame] | 2467 | if hasStubsLibrarySuffix(name, apiScopePublic) { | 
| Anton Hansson | 08f476b | 2021-04-07 15:32:19 +0100 | [diff] [blame] | 2468 | if name == "hwbinder.stubs" || name == "libcore_private.stubs" { | 
|  | 2469 | // Due to a previous bug, these modules were not considered stubs, so we retain that. | 
|  | 2470 | return false, javaPlatform | 
|  | 2471 | } | 
| Anton Hansson | 2d0c194 | 2020-05-25 12:20:51 +0100 | [diff] [blame] | 2472 | return true, javaSdk | 
|  | 2473 | } | 
| Jihoon Kang | fa4a90d | 2023-12-20 02:53:38 +0000 | [diff] [blame] | 2474 | if hasStubsLibrarySuffix(name, apiScopeSystem) { | 
| Anton Hansson | 2d0c194 | 2020-05-25 12:20:51 +0100 | [diff] [blame] | 2475 | return true, javaSystem | 
|  | 2476 | } | 
| Jihoon Kang | fa4a90d | 2023-12-20 02:53:38 +0000 | [diff] [blame] | 2477 | if hasStubsLibrarySuffix(name, apiScopeModuleLib) { | 
| Anton Hansson | 2d0c194 | 2020-05-25 12:20:51 +0100 | [diff] [blame] | 2478 | return true, javaModule | 
|  | 2479 | } | 
| Jihoon Kang | fa4a90d | 2023-12-20 02:53:38 +0000 | [diff] [blame] | 2480 | if hasStubsLibrarySuffix(name, apiScopeTest) { | 
| Anton Hansson | 2d0c194 | 2020-05-25 12:20:51 +0100 | [diff] [blame] | 2481 | return true, javaSystem | 
|  | 2482 | } | 
| Jihoon Kang | fa4a90d | 2023-12-20 02:53:38 +0000 | [diff] [blame] | 2483 | if hasStubsLibrarySuffix(name, apiScopeSystemServer) { | 
| Jihoon Kang | 1147b31 | 2023-06-08 23:25:57 +0000 | [diff] [blame] | 2484 | return true, javaSystemServer | 
|  | 2485 | } | 
| Anton Hansson | 2d0c194 | 2020-05-25 12:20:51 +0100 | [diff] [blame] | 2486 | return false, javaPlatform | 
|  | 2487 | } | 
|  | 2488 |  | 
| Jaewoong Jung | 4f158ee | 2019-07-11 10:05:35 -0700 | [diff] [blame] | 2489 | // java_sdk_library is a special Java library that provides optional platform APIs to apps. | 
|  | 2490 | // In practice, it can be viewed as a combination of several modules: 1) stubs library that clients | 
|  | 2491 | // are linked against to, 2) droiddoc module that internally generates API stubs source files, | 
|  | 2492 | // 3) the real runtime shared library that implements the APIs, and 4) XML file for adding | 
|  | 2493 | // the runtime lib to the classpath at runtime if requested via <uses-library>. | 
| Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 2494 | func SdkLibraryFactory() android.Module { | 
|  | 2495 | module := &SdkLibrary{} | 
| Paul Duffin | c3091c8 | 2020-05-08 14:16:20 +0100 | [diff] [blame] | 2496 |  | 
|  | 2497 | // Initialize information common between source and prebuilt. | 
| Paul Duffin | 71b33cc | 2021-06-23 11:39:47 +0100 | [diff] [blame] | 2498 | module.initCommon(module) | 
| Paul Duffin | c3091c8 | 2020-05-08 14:16:20 +0100 | [diff] [blame] | 2499 |  | 
| Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 2500 | module.InitSdkLibraryProperties() | 
| Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 2501 | android.InitApexModule(module) | 
| Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 2502 | InitJavaModule(module, android.HostAndDeviceSupported) | 
| Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 2503 |  | 
|  | 2504 | // Initialize the map from scope to scope specific properties. | 
|  | 2505 | scopeToProperties := make(map[*apiScope]*ApiScopeProperties) | 
|  | 2506 | for _, scope := range allApiScopes { | 
|  | 2507 | scopeToProperties[scope] = scope.scopeSpecificProperties(module) | 
|  | 2508 | } | 
|  | 2509 | module.scopeToProperties = scopeToProperties | 
|  | 2510 |  | 
| Paul Duffin | 4911a89 | 2020-04-29 23:35:13 +0100 | [diff] [blame] | 2511 | // Add the properties containing visibility rules so that they are checked. | 
| Paul Duffin | 5df7930 | 2020-05-16 15:52:12 +0100 | [diff] [blame] | 2512 | android.AddVisibilityProperty(module, "impl_library_visibility", &module.sdkLibraryProperties.Impl_library_visibility) | 
| Paul Duffin | 4911a89 | 2020-04-29 23:35:13 +0100 | [diff] [blame] | 2513 | android.AddVisibilityProperty(module, "stubs_library_visibility", &module.sdkLibraryProperties.Stubs_library_visibility) | 
|  | 2514 | android.AddVisibilityProperty(module, "stubs_source_visibility", &module.sdkLibraryProperties.Stubs_source_visibility) | 
|  | 2515 |  | 
| Paul Duffin | 1b1e806 | 2020-05-08 13:44:43 +0100 | [diff] [blame] | 2516 | module.SetDefaultableHook(func(ctx android.DefaultableHookContext) { | 
| Paul Duffin | dfa131e | 2020-05-15 20:37:11 +0100 | [diff] [blame] | 2517 | // If no implementation is required then it cannot be used as a shared library | 
|  | 2518 | // either. | 
|  | 2519 | if !module.requiresRuntimeImplementationLibrary() { | 
|  | 2520 | // If shared_library has been explicitly set to true then it is incompatible | 
|  | 2521 | // with api_only: true. | 
|  | 2522 | if proptools.Bool(module.commonSdkLibraryProperties.Shared_library) { | 
|  | 2523 | ctx.PropertyErrorf("api_only/shared_library", "inconsistent settings, shared_library and api_only cannot both be true") | 
|  | 2524 | } | 
|  | 2525 | // Set shared_library: false. | 
|  | 2526 | module.commonSdkLibraryProperties.Shared_library = proptools.BoolPtr(false) | 
|  | 2527 | } | 
|  | 2528 |  | 
| Paul Duffin | 1b1e806 | 2020-05-08 13:44:43 +0100 | [diff] [blame] | 2529 | if module.initCommonAfterDefaultsApplied(ctx) { | 
|  | 2530 | module.CreateInternalModules(ctx) | 
|  | 2531 | } | 
|  | 2532 | }) | 
| Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 2533 | return module | 
|  | 2534 | } | 
| Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 2535 |  | 
|  | 2536 | // | 
|  | 2537 | // SDK library prebuilts | 
|  | 2538 | // | 
|  | 2539 |  | 
| Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 2540 | // Properties associated with each api scope. | 
|  | 2541 | type sdkLibraryScopeProperties struct { | 
| Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 2542 | Jars []string `android:"path"` | 
|  | 2543 |  | 
|  | 2544 | Sdk_version *string | 
|  | 2545 |  | 
| Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 2546 | // List of shared java libs that this module has dependencies to | 
|  | 2547 | Libs []string | 
| Paul Duffin | 3d1248c | 2020-04-09 00:10:17 +0100 | [diff] [blame] | 2548 |  | 
| Paul Duffin | c878250 | 2020-04-29 20:45:27 +0100 | [diff] [blame] | 2549 | // The stubs source. | 
| Paul Duffin | 3d1248c | 2020-04-09 00:10:17 +0100 | [diff] [blame] | 2550 | Stub_srcs []string `android:"path"` | 
| Paul Duffin | 1fd005d | 2020-04-09 01:08:11 +0100 | [diff] [blame] | 2551 |  | 
|  | 2552 | // The current.txt | 
| Paul Duffin | 0f8faff | 2020-05-20 16:18:00 +0100 | [diff] [blame] | 2553 | Current_api *string `android:"path"` | 
| Paul Duffin | 1fd005d | 2020-04-09 01:08:11 +0100 | [diff] [blame] | 2554 |  | 
|  | 2555 | // The removed.txt | 
| Paul Duffin | 0f8faff | 2020-05-20 16:18:00 +0100 | [diff] [blame] | 2556 | Removed_api *string `android:"path"` | 
| Anton Hansson | d78eb76 | 2021-09-21 15:25:12 +0100 | [diff] [blame] | 2557 |  | 
|  | 2558 | // Annotation zip | 
|  | 2559 | Annotations *string `android:"path"` | 
| Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 2560 | } | 
|  | 2561 |  | 
| Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 2562 | type sdkLibraryImportProperties struct { | 
| Paul Duffin | fcfd791 | 2020-01-31 17:54:30 +0000 | [diff] [blame] | 2563 | // List of shared java libs, common to all scopes, that this module has | 
|  | 2564 | // dependencies to | 
|  | 2565 | Libs []string | 
| Paul Duffin | 1267d87 | 2021-04-16 17:21:36 +0100 | [diff] [blame] | 2566 |  | 
|  | 2567 | // If set to true, compile dex files for the stubs. Defaults to false. | 
|  | 2568 | Compile_dex *bool | 
| Paul Duffin | 869de14 | 2021-07-15 14:14:41 +0100 | [diff] [blame] | 2569 |  | 
|  | 2570 | // If not empty, classes are restricted to the specified packages and their sub-packages. | 
| Paul Duffin | 869de14 | 2021-07-15 14:14:41 +0100 | [diff] [blame] | 2571 | Permitted_packages []string | 
| Spandan Das | 23956d1 | 2024-01-19 00:22:22 +0000 | [diff] [blame] | 2572 |  | 
|  | 2573 | // Name of the source soong module that gets shadowed by this prebuilt | 
|  | 2574 | // If unspecified, follows the naming convention that the source module of | 
|  | 2575 | // the prebuilt is Name() without "prebuilt_" prefix | 
|  | 2576 | Source_module_name *string | 
| Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 2577 | } | 
|  | 2578 |  | 
| Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 2579 | type SdkLibraryImport struct { | 
| Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 2580 | android.ModuleBase | 
|  | 2581 | android.DefaultableModuleBase | 
|  | 2582 | prebuilt android.Prebuilt | 
| Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 2583 | android.ApexModuleBase | 
| Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 2584 |  | 
| Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 2585 | hiddenAPI | 
| Jiakai Zhang | 204356f | 2021-09-09 08:12:46 +0000 | [diff] [blame] | 2586 | dexpreopter | 
| Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 2587 |  | 
| Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 2588 | properties sdkLibraryImportProperties | 
|  | 2589 |  | 
| Paul Duffin | 46a26a8 | 2020-04-07 19:27:04 +0100 | [diff] [blame] | 2590 | // Map from api scope to the scope specific property structure. | 
|  | 2591 | scopeProperties map[*apiScope]*sdkLibraryScopeProperties | 
|  | 2592 |  | 
| Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 2593 | commonToSdkLibraryAndImport | 
| Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 2594 |  | 
|  | 2595 | // The reference to the implementation library created by the source module. | 
|  | 2596 | // Is nil if the source module does not exist. | 
|  | 2597 | implLibraryModule *Library | 
|  | 2598 |  | 
|  | 2599 | // The reference to the xml permissions module created by the source module. | 
|  | 2600 | // Is nil if the source module does not exist. | 
|  | 2601 | xmlPermissionsFileModule *sdkLibraryXml | 
| Paul Duffin | 3985351 | 2021-02-26 11:09:39 +0000 | [diff] [blame] | 2602 |  | 
| Jeongik Cha | d5fe878 | 2021-07-08 01:13:11 +0900 | [diff] [blame] | 2603 | // Build path to the dex implementation jar obtained from the prebuilt_apex, if any. | 
| Spandan Das | fae468e | 2023-12-12 23:23:53 +0000 | [diff] [blame] | 2604 | dexJarFile    OptionalDexJarPath | 
|  | 2605 | dexJarFileErr error | 
| Jeongik Cha | d5fe878 | 2021-07-08 01:13:11 +0900 | [diff] [blame] | 2606 |  | 
|  | 2607 | // Expected install file path of the source module(sdk_library) | 
|  | 2608 | // or dex implementation jar obtained from the prebuilt_apex, if any. | 
|  | 2609 | installFile android.Path | 
| Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 2610 | } | 
|  | 2611 |  | 
| Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 2612 | var _ SdkLibraryDependency = (*SdkLibraryImport)(nil) | 
| Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 2613 |  | 
| Paul Duffin | 46a26a8 | 2020-04-07 19:27:04 +0100 | [diff] [blame] | 2614 | // The type of a structure that contains a field of type sdkLibraryScopeProperties | 
|  | 2615 | // for each apiscope in allApiScopes, e.g. something like: | 
| Colin Cross | d079e0b | 2022-08-16 10:27:33 -0700 | [diff] [blame] | 2616 | // | 
|  | 2617 | //	struct { | 
|  | 2618 | //	  Public sdkLibraryScopeProperties | 
|  | 2619 | //	  System sdkLibraryScopeProperties | 
|  | 2620 | //	  ... | 
|  | 2621 | //	} | 
| Paul Duffin | 46a26a8 | 2020-04-07 19:27:04 +0100 | [diff] [blame] | 2622 | var allScopeStructType = createAllScopePropertiesStructType() | 
|  | 2623 |  | 
|  | 2624 | // Dynamically create a structure type for each apiscope in allApiScopes. | 
|  | 2625 | func createAllScopePropertiesStructType() reflect.Type { | 
|  | 2626 | var fields []reflect.StructField | 
|  | 2627 | for _, apiScope := range allApiScopes { | 
|  | 2628 | field := reflect.StructField{ | 
|  | 2629 | Name: apiScope.fieldName, | 
|  | 2630 | Type: reflect.TypeOf(sdkLibraryScopeProperties{}), | 
|  | 2631 | } | 
|  | 2632 | fields = append(fields, field) | 
|  | 2633 | } | 
|  | 2634 |  | 
|  | 2635 | return reflect.StructOf(fields) | 
|  | 2636 | } | 
|  | 2637 |  | 
|  | 2638 | // Create an instance of the scope specific structure type and return a map | 
|  | 2639 | // from apiscope to a pointer to each scope specific field. | 
|  | 2640 | func createPropertiesInstance() (interface{}, map[*apiScope]*sdkLibraryScopeProperties) { | 
|  | 2641 | allScopePropertiesPtr := reflect.New(allScopeStructType) | 
|  | 2642 | allScopePropertiesStruct := allScopePropertiesPtr.Elem() | 
|  | 2643 | scopeProperties := make(map[*apiScope]*sdkLibraryScopeProperties) | 
|  | 2644 |  | 
|  | 2645 | for _, apiScope := range allApiScopes { | 
|  | 2646 | field := allScopePropertiesStruct.FieldByName(apiScope.fieldName) | 
|  | 2647 | scopeProperties[apiScope] = field.Addr().Interface().(*sdkLibraryScopeProperties) | 
|  | 2648 | } | 
|  | 2649 |  | 
|  | 2650 | return allScopePropertiesPtr.Interface(), scopeProperties | 
|  | 2651 | } | 
|  | 2652 |  | 
| Jaewoong Jung | 4f158ee | 2019-07-11 10:05:35 -0700 | [diff] [blame] | 2653 | // java_sdk_library_import imports a prebuilt java_sdk_library. | 
| Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 2654 | func sdkLibraryImportFactory() android.Module { | 
| Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 2655 | module := &SdkLibraryImport{} | 
| Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 2656 |  | 
| Paul Duffin | 46a26a8 | 2020-04-07 19:27:04 +0100 | [diff] [blame] | 2657 | allScopeProperties, scopeToProperties := createPropertiesInstance() | 
|  | 2658 | module.scopeProperties = scopeToProperties | 
| Jiakai Zhang | 9c4dc19 | 2023-02-09 00:09:24 +0800 | [diff] [blame] | 2659 | module.AddProperties(&module.properties, allScopeProperties, &module.importDexpreoptProperties) | 
| Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 2660 |  | 
| Paul Duffin | c3091c8 | 2020-05-08 14:16:20 +0100 | [diff] [blame] | 2661 | // Initialize information common between source and prebuilt. | 
| Paul Duffin | 71b33cc | 2021-06-23 11:39:47 +0100 | [diff] [blame] | 2662 | module.initCommon(module) | 
| Paul Duffin | c3091c8 | 2020-05-08 14:16:20 +0100 | [diff] [blame] | 2663 |  | 
| Paul Duffin | 0bdcb27 | 2020-02-06 15:24:57 +0000 | [diff] [blame] | 2664 | android.InitPrebuiltModule(module, &[]string{""}) | 
| Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 2665 | android.InitApexModule(module) | 
| Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 2666 | InitJavaModule(module, android.HostAndDeviceSupported) | 
|  | 2667 |  | 
| Paul Duffin | 1b1e806 | 2020-05-08 13:44:43 +0100 | [diff] [blame] | 2668 | module.SetDefaultableHook(func(mctx android.DefaultableHookContext) { | 
|  | 2669 | if module.initCommonAfterDefaultsApplied(mctx) { | 
|  | 2670 | module.createInternalModules(mctx) | 
|  | 2671 | } | 
|  | 2672 | }) | 
| Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 2673 | return module | 
|  | 2674 | } | 
|  | 2675 |  | 
| Paul Duffin | 630b11e | 2021-07-15 13:35:26 +0100 | [diff] [blame] | 2676 | var _ PermittedPackagesForUpdatableBootJars = (*SdkLibraryImport)(nil) | 
|  | 2677 |  | 
|  | 2678 | func (module *SdkLibraryImport) PermittedPackagesForUpdatableBootJars() []string { | 
|  | 2679 | return module.properties.Permitted_packages | 
|  | 2680 | } | 
|  | 2681 |  | 
| Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 2682 | func (module *SdkLibraryImport) Prebuilt() *android.Prebuilt { | 
| Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 2683 | return &module.prebuilt | 
|  | 2684 | } | 
|  | 2685 |  | 
| Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 2686 | func (module *SdkLibraryImport) Name() string { | 
| Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 2687 | return module.prebuilt.Name(module.ModuleBase.Name()) | 
|  | 2688 | } | 
|  | 2689 |  | 
| Spandan Das | 23956d1 | 2024-01-19 00:22:22 +0000 | [diff] [blame] | 2690 | func (module *SdkLibraryImport) BaseModuleName() string { | 
|  | 2691 | return proptools.StringDefault(module.properties.Source_module_name, module.ModuleBase.Name()) | 
|  | 2692 | } | 
|  | 2693 |  | 
| Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 2694 | func (module *SdkLibraryImport) createInternalModules(mctx android.DefaultableHookContext) { | 
| Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 2695 |  | 
| Paul Duffin | 5006151 | 2020-01-21 16:31:05 +0000 | [diff] [blame] | 2696 | // If the build is configured to use prebuilts then force this to be preferred. | 
| Jeongik Cha | 816a23a | 2020-07-08 01:09:23 +0900 | [diff] [blame] | 2697 | if mctx.Config().AlwaysUsePrebuiltSdks() { | 
| Paul Duffin | 5006151 | 2020-01-21 16:31:05 +0000 | [diff] [blame] | 2698 | module.prebuilt.ForcePrefer() | 
|  | 2699 | } | 
|  | 2700 |  | 
| Paul Duffin | 46a26a8 | 2020-04-07 19:27:04 +0100 | [diff] [blame] | 2701 | for apiScope, scopeProperties := range module.scopeProperties { | 
| Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 2702 | if len(scopeProperties.Jars) == 0 { | 
|  | 2703 | continue | 
|  | 2704 | } | 
|  | 2705 |  | 
| Paul Duffin | bbb546b | 2020-04-09 00:07:11 +0100 | [diff] [blame] | 2706 | module.createJavaImportForStubs(mctx, apiScope, scopeProperties) | 
| Paul Duffin | 3d1248c | 2020-04-09 00:10:17 +0100 | [diff] [blame] | 2707 |  | 
| Paul Duffin | 0f8faff | 2020-05-20 16:18:00 +0100 | [diff] [blame] | 2708 | if len(scopeProperties.Stub_srcs) > 0 { | 
|  | 2709 | module.createPrebuiltStubsSources(mctx, apiScope, scopeProperties) | 
|  | 2710 | } | 
| Jihoon Kang | 71c8683 | 2023-09-13 01:01:53 +0000 | [diff] [blame] | 2711 |  | 
|  | 2712 | if scopeProperties.Current_api != nil { | 
|  | 2713 | module.createPrebuiltApiContribution(mctx, apiScope, scopeProperties) | 
|  | 2714 | } | 
| Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 2715 | } | 
| Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 2716 |  | 
|  | 2717 | javaSdkLibraries := javaSdkLibraries(mctx.Config()) | 
|  | 2718 | javaSdkLibrariesLock.Lock() | 
|  | 2719 | defer javaSdkLibrariesLock.Unlock() | 
|  | 2720 | *javaSdkLibraries = append(*javaSdkLibraries, module.BaseModuleName()) | 
|  | 2721 | } | 
|  | 2722 |  | 
| Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 2723 | func (module *SdkLibraryImport) createJavaImportForStubs(mctx android.DefaultableHookContext, apiScope *apiScope, scopeProperties *sdkLibraryScopeProperties) { | 
| Paul Duffin | bbb546b | 2020-04-09 00:07:11 +0100 | [diff] [blame] | 2724 | // Creates a java import for the jar with ".stubs" suffix | 
|  | 2725 | props := struct { | 
| Spandan Das | 23956d1 | 2024-01-19 00:22:22 +0000 | [diff] [blame] | 2726 | Name                             *string | 
|  | 2727 | Source_module_name               *string | 
|  | 2728 | Created_by_java_sdk_library_name *string | 
|  | 2729 | Sdk_version                      *string | 
|  | 2730 | Libs                             []string | 
|  | 2731 | Jars                             []string | 
|  | 2732 | Compile_dex                      *bool | 
| Jihoon Kang | fe914ed | 2024-02-12 22:49:21 +0000 | [diff] [blame] | 2733 | Is_stubs_module                  *bool | 
| Paul Duffin | bf4de04 | 2022-09-27 12:41:52 +0100 | [diff] [blame] | 2734 |  | 
|  | 2735 | android.UserSuppliedPrebuiltProperties | 
| Paul Duffin | bbb546b | 2020-04-09 00:07:11 +0100 | [diff] [blame] | 2736 | }{} | 
| Paul Duffin | c3091c8 | 2020-05-08 14:16:20 +0100 | [diff] [blame] | 2737 | props.Name = proptools.StringPtr(module.stubsLibraryModuleName(apiScope)) | 
| Spandan Das | 23956d1 | 2024-01-19 00:22:22 +0000 | [diff] [blame] | 2738 | props.Source_module_name = proptools.StringPtr(apiScope.stubsLibraryModuleName(module.BaseModuleName())) | 
|  | 2739 | props.Created_by_java_sdk_library_name = proptools.StringPtr(module.RootLibraryName()) | 
| Paul Duffin | bbb546b | 2020-04-09 00:07:11 +0100 | [diff] [blame] | 2740 | props.Sdk_version = scopeProperties.Sdk_version | 
|  | 2741 | // Prepend any of the libs from the legacy public properties to the libs for each of the | 
|  | 2742 | // scopes to avoid having to duplicate them in each scope. | 
|  | 2743 | props.Libs = append(module.properties.Libs, scopeProperties.Libs...) | 
|  | 2744 | props.Jars = scopeProperties.Jars | 
| Paul Duffin | 1dbe3ca | 2020-05-16 09:57:59 +0100 | [diff] [blame] | 2745 |  | 
| Paul Duffin | 38b5785 | 2020-05-13 16:08:09 +0100 | [diff] [blame] | 2746 | // The imports are preferred if the java_sdk_library_import is preferred. | 
| Paul Duffin | bf4de04 | 2022-09-27 12:41:52 +0100 | [diff] [blame] | 2747 | props.CopyUserSuppliedPropertiesFromPrebuilt(&module.prebuilt) | 
| Paul Duffin | 859fe96 | 2020-05-15 10:20:31 +0100 | [diff] [blame] | 2748 |  | 
| Paul Duffin | 1267d87 | 2021-04-16 17:21:36 +0100 | [diff] [blame] | 2749 | // The imports need to be compiled to dex if the java_sdk_library_import requests it. | 
| Paul Duffin | f4600f6 | 2021-05-13 22:34:45 +0100 | [diff] [blame] | 2750 | compileDex := module.properties.Compile_dex | 
|  | 2751 | if module.stubLibrariesCompiledForDex() { | 
|  | 2752 | compileDex = proptools.BoolPtr(true) | 
|  | 2753 | } | 
|  | 2754 | props.Compile_dex = compileDex | 
| Jihoon Kang | fe914ed | 2024-02-12 22:49:21 +0000 | [diff] [blame] | 2755 | props.Is_stubs_module = proptools.BoolPtr(true) | 
| Paul Duffin | 1267d87 | 2021-04-16 17:21:36 +0100 | [diff] [blame] | 2756 |  | 
| Paul Duffin | 859fe96 | 2020-05-15 10:20:31 +0100 | [diff] [blame] | 2757 | mctx.CreateModule(ImportFactory, &props, module.sdkComponentPropertiesForChildLibrary()) | 
| Paul Duffin | bbb546b | 2020-04-09 00:07:11 +0100 | [diff] [blame] | 2758 | } | 
|  | 2759 |  | 
| Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 2760 | func (module *SdkLibraryImport) createPrebuiltStubsSources(mctx android.DefaultableHookContext, apiScope *apiScope, scopeProperties *sdkLibraryScopeProperties) { | 
| Paul Duffin | 3d1248c | 2020-04-09 00:10:17 +0100 | [diff] [blame] | 2761 | props := struct { | 
| Spandan Das | 23956d1 | 2024-01-19 00:22:22 +0000 | [diff] [blame] | 2762 | Name                             *string | 
|  | 2763 | Source_module_name               *string | 
|  | 2764 | Created_by_java_sdk_library_name *string | 
|  | 2765 | Srcs                             []string | 
| Paul Duffin | bf4de04 | 2022-09-27 12:41:52 +0100 | [diff] [blame] | 2766 |  | 
|  | 2767 | android.UserSuppliedPrebuiltProperties | 
| Paul Duffin | 3d1248c | 2020-04-09 00:10:17 +0100 | [diff] [blame] | 2768 | }{} | 
| Paul Duffin | c3091c8 | 2020-05-08 14:16:20 +0100 | [diff] [blame] | 2769 | props.Name = proptools.StringPtr(module.stubsSourceModuleName(apiScope)) | 
| Spandan Das | 23956d1 | 2024-01-19 00:22:22 +0000 | [diff] [blame] | 2770 | props.Source_module_name = proptools.StringPtr(apiScope.stubsSourceModuleName(module.BaseModuleName())) | 
|  | 2771 | props.Created_by_java_sdk_library_name = proptools.StringPtr(module.RootLibraryName()) | 
| Paul Duffin | 3d1248c | 2020-04-09 00:10:17 +0100 | [diff] [blame] | 2772 | props.Srcs = scopeProperties.Stub_srcs | 
| Paul Duffin | 38b5785 | 2020-05-13 16:08:09 +0100 | [diff] [blame] | 2773 |  | 
|  | 2774 | // The stubs source is preferred if the java_sdk_library_import is preferred. | 
| Paul Duffin | bf4de04 | 2022-09-27 12:41:52 +0100 | [diff] [blame] | 2775 | props.CopyUserSuppliedPropertiesFromPrebuilt(&module.prebuilt) | 
|  | 2776 |  | 
| Spandan Das | 2cc80ba | 2023-10-27 17:21:52 +0000 | [diff] [blame] | 2777 | mctx.CreateModule(PrebuiltStubsSourcesFactory, &props, module.sdkComponentPropertiesForChildLibrary()) | 
| Paul Duffin | 3d1248c | 2020-04-09 00:10:17 +0100 | [diff] [blame] | 2778 | } | 
|  | 2779 |  | 
| Jihoon Kang | 71c8683 | 2023-09-13 01:01:53 +0000 | [diff] [blame] | 2780 | func (module *SdkLibraryImport) createPrebuiltApiContribution(mctx android.DefaultableHookContext, apiScope *apiScope, scopeProperties *sdkLibraryScopeProperties) { | 
|  | 2781 | api_file := scopeProperties.Current_api | 
|  | 2782 | api_surface := &apiScope.name | 
|  | 2783 |  | 
|  | 2784 | props := struct { | 
| Spandan Das | 23956d1 | 2024-01-19 00:22:22 +0000 | [diff] [blame] | 2785 | Name                             *string | 
|  | 2786 | Source_module_name               *string | 
|  | 2787 | Created_by_java_sdk_library_name *string | 
|  | 2788 | Api_surface                      *string | 
|  | 2789 | Api_file                         *string | 
|  | 2790 | Visibility                       []string | 
| Jihoon Kang | 71c8683 | 2023-09-13 01:01:53 +0000 | [diff] [blame] | 2791 | }{} | 
|  | 2792 |  | 
|  | 2793 | props.Name = proptools.StringPtr(module.stubsSourceModuleName(apiScope) + ".api.contribution") | 
| Spandan Das | 23956d1 | 2024-01-19 00:22:22 +0000 | [diff] [blame] | 2794 | props.Source_module_name = proptools.StringPtr(apiScope.stubsSourceModuleName(module.BaseModuleName()) + ".api.contribution") | 
|  | 2795 | props.Created_by_java_sdk_library_name = proptools.StringPtr(module.RootLibraryName()) | 
| Jihoon Kang | 71c8683 | 2023-09-13 01:01:53 +0000 | [diff] [blame] | 2796 | props.Api_surface = api_surface | 
|  | 2797 | props.Api_file = api_file | 
|  | 2798 | props.Visibility = []string{"//visibility:override", "//visibility:public"} | 
|  | 2799 |  | 
| Spandan Das | 2cc80ba | 2023-10-27 17:21:52 +0000 | [diff] [blame] | 2800 | mctx.CreateModule(ApiContributionImportFactory, &props, module.sdkComponentPropertiesForChildLibrary()) | 
| Jihoon Kang | 71c8683 | 2023-09-13 01:01:53 +0000 | [diff] [blame] | 2801 | } | 
|  | 2802 |  | 
| Paul Duffin | 44f1d84 | 2020-06-26 20:17:02 +0100 | [diff] [blame] | 2803 | // Add the dependencies on the child module in the component deps mutator so that it | 
|  | 2804 | // creates references to the prebuilt and not the source modules. | 
|  | 2805 | func (module *SdkLibraryImport) ComponentDepsMutator(ctx android.BottomUpMutatorContext) { | 
| Paul Duffin | 46a26a8 | 2020-04-07 19:27:04 +0100 | [diff] [blame] | 2806 | for apiScope, scopeProperties := range module.scopeProperties { | 
| Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 2807 | if len(scopeProperties.Jars) == 0 { | 
|  | 2808 | continue | 
|  | 2809 | } | 
|  | 2810 |  | 
|  | 2811 | // Add dependencies to the prebuilt stubs library | 
| Jihoon Kang | b743155 | 2024-01-22 19:40:08 +0000 | [diff] [blame] | 2812 | ctx.AddVariationDependencies(nil, apiScope.prebuiltStubsTag, android.PrebuiltNameFromSource(module.stubsLibraryModuleName(apiScope))) | 
| Paul Duffin | 0f8faff | 2020-05-20 16:18:00 +0100 | [diff] [blame] | 2813 |  | 
|  | 2814 | if len(scopeProperties.Stub_srcs) > 0 { | 
|  | 2815 | // Add dependencies to the prebuilt stubs source library | 
| Paul Duffin | 864116c | 2021-04-02 10:24:13 +0100 | [diff] [blame] | 2816 | ctx.AddVariationDependencies(nil, apiScope.stubsSourceTag, android.PrebuiltNameFromSource(module.stubsSourceModuleName(apiScope))) | 
| Paul Duffin | 0f8faff | 2020-05-20 16:18:00 +0100 | [diff] [blame] | 2817 | } | 
| Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 2818 | } | 
| Paul Duffin | 44f1d84 | 2020-06-26 20:17:02 +0100 | [diff] [blame] | 2819 | } | 
|  | 2820 |  | 
|  | 2821 | // Add other dependencies as normal. | 
|  | 2822 | func (module *SdkLibraryImport) DepsMutator(ctx android.BottomUpMutatorContext) { | 
| Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 2823 |  | 
|  | 2824 | implName := module.implLibraryModuleName() | 
|  | 2825 | if ctx.OtherModuleExists(implName) { | 
|  | 2826 | ctx.AddVariationDependencies(nil, implLibraryTag, implName) | 
|  | 2827 |  | 
|  | 2828 | xmlPermissionsModuleName := module.xmlPermissionsModuleName() | 
|  | 2829 | if module.sharedLibrary() && ctx.OtherModuleExists(xmlPermissionsModuleName) { | 
|  | 2830 | // Add dependency to the rule for generating the xml permissions file | 
|  | 2831 | ctx.AddDependency(module, xmlPermissionsFileTag, xmlPermissionsModuleName) | 
|  | 2832 | } | 
|  | 2833 | } | 
| Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 2834 | } | 
|  | 2835 |  | 
| Jiyong Park | 45bf82e | 2020-12-15 22:29:02 +0900 | [diff] [blame] | 2836 | var _ android.ApexModule = (*SdkLibraryImport)(nil) | 
|  | 2837 |  | 
|  | 2838 | // Implements android.ApexModule | 
| Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 2839 | func (module *SdkLibraryImport) DepIsInSameApex(mctx android.BaseModuleContext, dep android.Module) bool { | 
|  | 2840 | depTag := mctx.OtherModuleDependencyTag(dep) | 
|  | 2841 | if depTag == xmlPermissionsFileTag { | 
|  | 2842 | return true | 
|  | 2843 | } | 
|  | 2844 |  | 
|  | 2845 | // None of the other dependencies of the java_sdk_library_import are in the same apex | 
|  | 2846 | // as the one that references this module. | 
|  | 2847 | return false | 
|  | 2848 | } | 
|  | 2849 |  | 
| Jiyong Park | 45bf82e | 2020-12-15 22:29:02 +0900 | [diff] [blame] | 2850 | // Implements android.ApexModule | 
| Dan Albert | c806053 | 2020-07-22 22:32:17 -0700 | [diff] [blame] | 2851 | func (module *SdkLibraryImport) ShouldSupportSdkVersion(ctx android.BaseModuleContext, | 
|  | 2852 | sdkVersion android.ApiLevel) error { | 
| Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 2853 | // we don't check prebuilt modules for sdk_version | 
|  | 2854 | return nil | 
|  | 2855 | } | 
|  | 2856 |  | 
| Paul Duffin | ea8f808 | 2021-06-24 13:25:57 +0100 | [diff] [blame] | 2857 | // Implements android.ApexModule | 
|  | 2858 | func (module *SdkLibraryImport) UniqueApexVariations() bool { | 
|  | 2859 | return module.uniqueApexVariations() | 
|  | 2860 | } | 
|  | 2861 |  | 
| Paul Duffin | 09817d6 | 2022-04-28 17:45:11 +0100 | [diff] [blame] | 2862 | // MinSdkVersion - Implements hiddenAPIModule | 
| Spandan Das | 8c9ae7e | 2023-03-03 21:20:36 +0000 | [diff] [blame] | 2863 | func (module *SdkLibraryImport) MinSdkVersion(ctx android.EarlyModuleContext) android.ApiLevel { | 
|  | 2864 | return android.NoneApiLevel | 
| Paul Duffin | 09817d6 | 2022-04-28 17:45:11 +0100 | [diff] [blame] | 2865 | } | 
|  | 2866 |  | 
|  | 2867 | var _ hiddenAPIModule = (*SdkLibraryImport)(nil) | 
|  | 2868 |  | 
| Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 2869 | func (module *SdkLibraryImport) OutputFiles(tag string) (android.Paths, error) { | 
| Paul Duffin | 1e940d5 | 2022-04-29 14:21:25 +0100 | [diff] [blame] | 2870 | paths, err := module.commonOutputFiles(tag) | 
|  | 2871 | if paths != nil || err != nil { | 
|  | 2872 | return paths, err | 
|  | 2873 | } | 
|  | 2874 | if module.implLibraryModule != nil { | 
|  | 2875 | return module.implLibraryModule.OutputFiles(tag) | 
|  | 2876 | } else { | 
|  | 2877 | return nil, nil | 
|  | 2878 | } | 
| Paul Duffin | 46dc45a | 2020-05-14 15:39:10 +0100 | [diff] [blame] | 2879 | } | 
|  | 2880 |  | 
| Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 2881 | func (module *SdkLibraryImport) GenerateAndroidBuildActions(ctx android.ModuleContext) { | 
| Paul Duffin | a2ae7e0 | 2020-09-11 11:55:00 +0100 | [diff] [blame] | 2882 | module.generateCommonBuildActions(ctx) | 
|  | 2883 |  | 
| Jeongik Cha | d5fe878 | 2021-07-08 01:13:11 +0900 | [diff] [blame] | 2884 | // Assume that source module(sdk_library) is installed in /<sdk_library partition>/framework | 
|  | 2885 | module.installFile = android.PathForModuleInstall(ctx, "framework", module.Stem()+".jar") | 
|  | 2886 |  | 
| Paul Duffin | 0f8faff | 2020-05-20 16:18:00 +0100 | [diff] [blame] | 2887 | // Record the paths to the prebuilt stubs library and stubs source. | 
| Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 2888 | ctx.VisitDirectDeps(func(to android.Module) { | 
|  | 2889 | tag := ctx.OtherModuleDependencyTag(to) | 
|  | 2890 |  | 
| Paul Duffin | 0f8faff | 2020-05-20 16:18:00 +0100 | [diff] [blame] | 2891 | // Extract information from any of the scope specific dependencies. | 
|  | 2892 | if scopeTag, ok := tag.(scopeDependencyTag); ok { | 
|  | 2893 | apiScope := scopeTag.apiScope | 
|  | 2894 | scopePaths := module.getScopePathsCreateIfNeeded(apiScope) | 
|  | 2895 |  | 
|  | 2896 | // Extract information from the dependency. The exact information extracted | 
|  | 2897 | // is determined by the nature of the dependency which is determined by the tag. | 
|  | 2898 | scopeTag.extractDepInfo(ctx, to, scopePaths) | 
| Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 2899 | } else if tag == implLibraryTag { | 
|  | 2900 | if implLibrary, ok := to.(*Library); ok { | 
|  | 2901 | module.implLibraryModule = implLibrary | 
|  | 2902 | } else { | 
|  | 2903 | ctx.ModuleErrorf("implementation library must be of type *java.Library but was %T", to) | 
|  | 2904 | } | 
|  | 2905 | } else if tag == xmlPermissionsFileTag { | 
|  | 2906 | if xmlPermissionsFileModule, ok := to.(*sdkLibraryXml); ok { | 
|  | 2907 | module.xmlPermissionsFileModule = xmlPermissionsFileModule | 
|  | 2908 | } else { | 
|  | 2909 | ctx.ModuleErrorf("xml permissions file module must be of type *sdkLibraryXml but was %T", to) | 
|  | 2910 | } | 
| Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 2911 | } | 
|  | 2912 | }) | 
| Paul Duffin | 0f8faff | 2020-05-20 16:18:00 +0100 | [diff] [blame] | 2913 |  | 
|  | 2914 | // Populate the scope paths with information from the properties. | 
|  | 2915 | for apiScope, scopeProperties := range module.scopeProperties { | 
|  | 2916 | if len(scopeProperties.Jars) == 0 { | 
|  | 2917 | continue | 
|  | 2918 | } | 
|  | 2919 |  | 
|  | 2920 | paths := module.getScopePathsCreateIfNeeded(apiScope) | 
| Anton Hansson | d78eb76 | 2021-09-21 15:25:12 +0100 | [diff] [blame] | 2921 | paths.annotationsZip = android.OptionalPathForModuleSrc(ctx, scopeProperties.Annotations) | 
| Paul Duffin | 0f8faff | 2020-05-20 16:18:00 +0100 | [diff] [blame] | 2922 | paths.currentApiFilePath = android.OptionalPathForModuleSrc(ctx, scopeProperties.Current_api) | 
|  | 2923 | paths.removedApiFilePath = android.OptionalPathForModuleSrc(ctx, scopeProperties.Removed_api) | 
|  | 2924 | } | 
| Paul Duffin | 3985351 | 2021-02-26 11:09:39 +0000 | [diff] [blame] | 2925 |  | 
|  | 2926 | if ctx.Device() { | 
|  | 2927 | // If this is a variant created for a prebuilt_apex then use the dex implementation jar | 
|  | 2928 | // obtained from the associated deapexer module. | 
| Colin Cross | ff694a8 | 2023-12-13 15:54:49 -0800 | [diff] [blame] | 2929 | ai, _ := android.ModuleProvider(ctx, android.ApexInfoProvider) | 
| Paul Duffin | 3985351 | 2021-02-26 11:09:39 +0000 | [diff] [blame] | 2930 | if ai.ForPrebuiltApex { | 
| Paul Duffin | 3985351 | 2021-02-26 11:09:39 +0000 | [diff] [blame] | 2931 | // Get the path of the dex implementation jar from the `deapexer` module. | 
| Spandan Das | fae468e | 2023-12-12 23:23:53 +0000 | [diff] [blame] | 2932 | di, err := android.FindDeapexerProviderForModule(ctx) | 
|  | 2933 | if err != nil { | 
|  | 2934 | // An error was found, possibly due to multiple apexes in the tree that export this library | 
|  | 2935 | // Defer the error till a client tries to call DexJarBuildPath | 
|  | 2936 | module.dexJarFileErr = err | 
| Spandan Das | 3a39201 | 2024-01-17 18:26:27 +0000 | [diff] [blame] | 2937 | module.initHiddenAPIError(err) | 
| Spandan Das | fae468e | 2023-12-12 23:23:53 +0000 | [diff] [blame] | 2938 | return | 
| Martin Stjernholm | 4482560 | 2021-09-17 01:44:12 +0100 | [diff] [blame] | 2939 | } | 
| Spandan Das | 5be6333 | 2023-12-13 00:06:32 +0000 | [diff] [blame] | 2940 | dexJarFileApexRootRelative := ApexRootRelativePathToJavaLib(module.BaseModuleName()) | 
| Jiakai Zhang | 81e4681 | 2023-02-08 21:56:07 +0800 | [diff] [blame] | 2941 | if dexOutputPath := di.PrebuiltExportPath(dexJarFileApexRootRelative); dexOutputPath != nil { | 
| Martin Stjernholm | 8be1e6d | 2021-09-15 03:34:04 +0100 | [diff] [blame] | 2942 | dexJarFile := makeDexJarPathFromPath(dexOutputPath) | 
|  | 2943 | module.dexJarFile = dexJarFile | 
| Jiakai Zhang | 204356f | 2021-09-09 08:12:46 +0000 | [diff] [blame] | 2944 | installPath := android.PathForModuleInPartitionInstall( | 
| Jiakai Zhang | 81e4681 | 2023-02-08 21:56:07 +0800 | [diff] [blame] | 2945 | ctx, "apex", ai.ApexVariationName, dexJarFileApexRootRelative) | 
| Jiakai Zhang | 204356f | 2021-09-09 08:12:46 +0000 | [diff] [blame] | 2946 | module.installFile = installPath | 
| Martin Stjernholm | 8be1e6d | 2021-09-15 03:34:04 +0100 | [diff] [blame] | 2947 | module.initHiddenAPI(ctx, dexJarFile, module.findScopePaths(apiScopePublic).stubsImplPath[0], nil) | 
| Jiakai Zhang | 204356f | 2021-09-09 08:12:46 +0000 | [diff] [blame] | 2948 |  | 
| Spandan Das | e21a8d4 | 2024-01-23 23:56:29 +0000 | [diff] [blame] | 2949 | module.dexpreopter.installPath = module.dexpreopter.getInstallPath(ctx, android.RemoveOptionalPrebuiltPrefix(ctx.ModuleName()), installPath) | 
| Jiakai Zhang | 204356f | 2021-09-09 08:12:46 +0000 | [diff] [blame] | 2950 | module.dexpreopter.isSDKLibrary = true | 
| Spandan Das | e21a8d4 | 2024-01-23 23:56:29 +0000 | [diff] [blame] | 2951 | module.dexpreopter.uncompressedDex = shouldUncompressDex(ctx, android.RemoveOptionalPrebuiltPrefix(ctx.ModuleName()), &module.dexpreopter) | 
| Jiakai Zhang | 81e4681 | 2023-02-08 21:56:07 +0800 | [diff] [blame] | 2952 |  | 
|  | 2953 | if profilePath := di.PrebuiltExportPath(dexJarFileApexRootRelative + ".prof"); profilePath != nil { | 
|  | 2954 | module.dexpreopter.inputProfilePathOnHost = profilePath | 
|  | 2955 | } | 
| Paul Duffin | 3985351 | 2021-02-26 11:09:39 +0000 | [diff] [blame] | 2956 | } else { | 
|  | 2957 | // This should never happen as a variant for a prebuilt_apex is only created if the | 
|  | 2958 | // prebuilt_apex has been configured to export the java library dex file. | 
| Martin Stjernholm | 4482560 | 2021-09-17 01:44:12 +0100 | [diff] [blame] | 2959 | ctx.ModuleErrorf("internal error: no dex implementation jar available from prebuilt APEX %s", di.ApexModuleName()) | 
| Paul Duffin | 3985351 | 2021-02-26 11:09:39 +0000 | [diff] [blame] | 2960 | } | 
|  | 2961 | } | 
|  | 2962 | } | 
| Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 2963 | } | 
|  | 2964 |  | 
| Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 2965 | func (module *SdkLibraryImport) sdkJars(ctx android.BaseModuleContext, sdkVersion android.SdkSpec, headerJars bool) android.Paths { | 
| Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 2966 |  | 
|  | 2967 | // For consistency with SdkLibrary make the implementation jar available to libraries that | 
|  | 2968 | // are within the same APEX. | 
|  | 2969 | implLibraryModule := module.implLibraryModule | 
| Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 2970 | if implLibraryModule != nil && withinSameApexesAs(ctx, module) { | 
| Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 2971 | if headerJars { | 
|  | 2972 | return implLibraryModule.HeaderJars() | 
|  | 2973 | } else { | 
|  | 2974 | return implLibraryModule.ImplementationJars() | 
|  | 2975 | } | 
|  | 2976 | } | 
|  | 2977 |  | 
| Paul Duffin | 23970f4 | 2020-05-20 14:20:02 +0100 | [diff] [blame] | 2978 | return module.selectHeaderJarsForSdkVersion(ctx, sdkVersion) | 
| Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 2979 | } | 
|  | 2980 |  | 
| Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 2981 | // to satisfy SdkLibraryDependency interface | 
| Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 2982 | func (module *SdkLibraryImport) SdkHeaderJars(ctx android.BaseModuleContext, sdkVersion android.SdkSpec) android.Paths { | 
| Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 2983 | // This module is just a wrapper for the prebuilt stubs. | 
| Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 2984 | return module.sdkJars(ctx, sdkVersion, true) | 
| Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 2985 | } | 
|  | 2986 |  | 
| Ulya Trafimovich | dbf3166 | 2020-12-17 12:07:54 +0000 | [diff] [blame] | 2987 | // to satisfy UsesLibraryDependency interface | 
| Spandan Das | 59a4a2b | 2024-01-09 21:35:56 +0000 | [diff] [blame] | 2988 | func (module *SdkLibraryImport) DexJarBuildPath(ctx android.ModuleErrorfContext) OptionalDexJarPath { | 
| Paul Duffin | 3985351 | 2021-02-26 11:09:39 +0000 | [diff] [blame] | 2989 | // The dex implementation jar extracted from the .apex file should be used in preference to the | 
|  | 2990 | // source. | 
| Spandan Das | fae468e | 2023-12-12 23:23:53 +0000 | [diff] [blame] | 2991 | if module.dexJarFileErr != nil { | 
| Spandan Das | 59a4a2b | 2024-01-09 21:35:56 +0000 | [diff] [blame] | 2992 | ctx.ModuleErrorf(module.dexJarFileErr.Error()) | 
| Spandan Das | fae468e | 2023-12-12 23:23:53 +0000 | [diff] [blame] | 2993 | } | 
| Martin Stjernholm | 8be1e6d | 2021-09-15 03:34:04 +0100 | [diff] [blame] | 2994 | if module.dexJarFile.IsSet() { | 
| Paul Duffin | 3985351 | 2021-02-26 11:09:39 +0000 | [diff] [blame] | 2995 | return module.dexJarFile | 
|  | 2996 | } | 
| Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 2997 | if module.implLibraryModule == nil { | 
| Martin Stjernholm | 8be1e6d | 2021-09-15 03:34:04 +0100 | [diff] [blame] | 2998 | return makeUnsetDexJarPath() | 
| Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 2999 | } else { | 
| Spandan Das | 59a4a2b | 2024-01-09 21:35:56 +0000 | [diff] [blame] | 3000 | return module.implLibraryModule.DexJarBuildPath(ctx) | 
| Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 3001 | } | 
|  | 3002 | } | 
|  | 3003 |  | 
| Ulya Trafimovich | dbf3166 | 2020-12-17 12:07:54 +0000 | [diff] [blame] | 3004 | // to satisfy UsesLibraryDependency interface | 
| Ulya Trafimovich | 31e444e | 2020-08-14 17:32:16 +0100 | [diff] [blame] | 3005 | func (module *SdkLibraryImport) DexJarInstallPath() android.Path { | 
| Jeongik Cha | d5fe878 | 2021-07-08 01:13:11 +0900 | [diff] [blame] | 3006 | return module.installFile | 
| Ulya Trafimovich | 31e444e | 2020-08-14 17:32:16 +0100 | [diff] [blame] | 3007 | } | 
|  | 3008 |  | 
| Ulya Trafimovich | dbf3166 | 2020-12-17 12:07:54 +0000 | [diff] [blame] | 3009 | // to satisfy UsesLibraryDependency interface | 
|  | 3010 | func (module *SdkLibraryImport) ClassLoaderContexts() dexpreopt.ClassLoaderContextMap { | 
|  | 3011 | return nil | 
|  | 3012 | } | 
|  | 3013 |  | 
| Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 3014 | // to satisfy apex.javaDependency interface | 
|  | 3015 | func (module *SdkLibraryImport) JacocoReportClassesFile() android.Path { | 
|  | 3016 | if module.implLibraryModule == nil { | 
|  | 3017 | return nil | 
|  | 3018 | } else { | 
|  | 3019 | return module.implLibraryModule.JacocoReportClassesFile() | 
|  | 3020 | } | 
|  | 3021 | } | 
|  | 3022 |  | 
|  | 3023 | // to satisfy apex.javaDependency interface | 
| Colin Cross | 08dca38 | 2020-07-21 20:31:17 -0700 | [diff] [blame] | 3024 | func (module *SdkLibraryImport) LintDepSets() LintDepSets { | 
|  | 3025 | if module.implLibraryModule == nil { | 
|  | 3026 | return LintDepSets{} | 
|  | 3027 | } else { | 
|  | 3028 | return module.implLibraryModule.LintDepSets() | 
|  | 3029 | } | 
|  | 3030 | } | 
|  | 3031 |  | 
| Spandan Das | 17854f5 | 2022-01-14 21:19:14 +0000 | [diff] [blame] | 3032 | func (module *SdkLibraryImport) GetStrictUpdatabilityLinting() bool { | 
| Jaewoong Jung | 476b9d6 | 2021-05-10 15:30:00 -0700 | [diff] [blame] | 3033 | if module.implLibraryModule == nil { | 
|  | 3034 | return false | 
|  | 3035 | } else { | 
| Spandan Das | 17854f5 | 2022-01-14 21:19:14 +0000 | [diff] [blame] | 3036 | return module.implLibraryModule.GetStrictUpdatabilityLinting() | 
| Jaewoong Jung | 476b9d6 | 2021-05-10 15:30:00 -0700 | [diff] [blame] | 3037 | } | 
|  | 3038 | } | 
|  | 3039 |  | 
| Spandan Das | 17854f5 | 2022-01-14 21:19:14 +0000 | [diff] [blame] | 3040 | func (module *SdkLibraryImport) SetStrictUpdatabilityLinting(strictLinting bool) { | 
| Jaewoong Jung | 476b9d6 | 2021-05-10 15:30:00 -0700 | [diff] [blame] | 3041 | if module.implLibraryModule != nil { | 
| Spandan Das | 17854f5 | 2022-01-14 21:19:14 +0000 | [diff] [blame] | 3042 | module.implLibraryModule.SetStrictUpdatabilityLinting(strictLinting) | 
| Jaewoong Jung | 476b9d6 | 2021-05-10 15:30:00 -0700 | [diff] [blame] | 3043 | } | 
|  | 3044 | } | 
|  | 3045 |  | 
| Colin Cross | 08dca38 | 2020-07-21 20:31:17 -0700 | [diff] [blame] | 3046 | // to satisfy apex.javaDependency interface | 
| Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 3047 | func (module *SdkLibraryImport) Stem() string { | 
|  | 3048 | return module.BaseModuleName() | 
| Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 3049 | } | 
| Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 3050 |  | 
| Paul Duffin | 44b481b | 2020-06-17 16:59:43 +0100 | [diff] [blame] | 3051 | var _ ApexDependency = (*SdkLibraryImport)(nil) | 
|  | 3052 |  | 
|  | 3053 | // to satisfy java.ApexDependency interface | 
|  | 3054 | func (module *SdkLibraryImport) HeaderJars() android.Paths { | 
|  | 3055 | if module.implLibraryModule == nil { | 
|  | 3056 | return nil | 
|  | 3057 | } else { | 
|  | 3058 | return module.implLibraryModule.HeaderJars() | 
|  | 3059 | } | 
|  | 3060 | } | 
|  | 3061 |  | 
|  | 3062 | // to satisfy java.ApexDependency interface | 
|  | 3063 | func (module *SdkLibraryImport) ImplementationAndResourcesJars() android.Paths { | 
|  | 3064 | if module.implLibraryModule == nil { | 
|  | 3065 | return nil | 
|  | 3066 | } else { | 
|  | 3067 | return module.implLibraryModule.ImplementationAndResourcesJars() | 
|  | 3068 | } | 
|  | 3069 | } | 
|  | 3070 |  | 
| Jiakai Zhang | 204356f | 2021-09-09 08:12:46 +0000 | [diff] [blame] | 3071 | // to satisfy java.DexpreopterInterface interface | 
|  | 3072 | func (module *SdkLibraryImport) IsInstallable() bool { | 
|  | 3073 | return true | 
|  | 3074 | } | 
|  | 3075 |  | 
| Paul Duffin | fef5500 | 2021-06-17 14:56:05 +0100 | [diff] [blame] | 3076 | var _ android.RequiredFilesFromPrebuiltApex = (*SdkLibraryImport)(nil) | 
|  | 3077 |  | 
| Paul Duffin | b4bbf2c | 2021-06-17 15:59:07 +0100 | [diff] [blame] | 3078 | func (module *SdkLibraryImport) RequiredFilesFromPrebuiltApex(ctx android.BaseModuleContext) []string { | 
| Paul Duffin | fef5500 | 2021-06-17 14:56:05 +0100 | [diff] [blame] | 3079 | name := module.BaseModuleName() | 
| Jiakai Zhang | 81e4681 | 2023-02-08 21:56:07 +0800 | [diff] [blame] | 3080 | return requiredFilesFromPrebuiltApexForImport(name, &module.dexpreopter) | 
| Paul Duffin | fef5500 | 2021-06-17 14:56:05 +0100 | [diff] [blame] | 3081 | } | 
|  | 3082 |  | 
| Spandan Das | 2ea84dd | 2024-01-25 22:12:50 +0000 | [diff] [blame] | 3083 | func (j *SdkLibraryImport) UseProfileGuidedDexpreopt() bool { | 
|  | 3084 | return proptools.Bool(j.importDexpreoptProperties.Dex_preopt.Profile_guided) | 
|  | 3085 | } | 
|  | 3086 |  | 
| Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 3087 | // java_sdk_library_xml | 
| Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 3088 | type sdkLibraryXml struct { | 
|  | 3089 | android.ModuleBase | 
|  | 3090 | android.DefaultableModuleBase | 
|  | 3091 | android.ApexModuleBase | 
|  | 3092 |  | 
|  | 3093 | properties sdkLibraryXmlProperties | 
|  | 3094 |  | 
|  | 3095 | outputFilePath android.OutputPath | 
|  | 3096 | installDirPath android.InstallPath | 
| Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 3097 |  | 
|  | 3098 | hideApexVariantFromMake bool | 
| Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 3099 | } | 
|  | 3100 |  | 
|  | 3101 | type sdkLibraryXmlProperties struct { | 
|  | 3102 | // canonical name of the lib | 
|  | 3103 | Lib_name *string | 
| Pedro Loureiro | 9956e5e | 2021-09-07 17:21:59 +0000 | [diff] [blame] | 3104 |  | 
|  | 3105 | // Signals that this shared library is part of the bootclasspath starting | 
|  | 3106 | // on the version indicated in this attribute. | 
|  | 3107 | // | 
|  | 3108 | // This will make platforms at this level and above to ignore | 
|  | 3109 | // <uses-library> tags with this library name because the library is already | 
|  | 3110 | // available | 
|  | 3111 | On_bootclasspath_since *string | 
|  | 3112 |  | 
|  | 3113 | // Signals that this shared library was part of the bootclasspath before | 
|  | 3114 | // (but not including) the version indicated in this attribute. | 
|  | 3115 | // | 
|  | 3116 | // The system will automatically add a <uses-library> tag with this library to | 
|  | 3117 | // apps that target any SDK less than the version indicated in this attribute. | 
|  | 3118 | On_bootclasspath_before *string | 
|  | 3119 |  | 
|  | 3120 | // Indicates that PackageManager should ignore this shared library if the | 
|  | 3121 | // platform is below the version indicated in this attribute. | 
|  | 3122 | // | 
|  | 3123 | // This means that the device won't recognise this library as installed. | 
|  | 3124 | Min_device_sdk *string | 
|  | 3125 |  | 
|  | 3126 | // Indicates that PackageManager should ignore this shared library if the | 
|  | 3127 | // platform is above the version indicated in this attribute. | 
|  | 3128 | // | 
|  | 3129 | // This means that the device won't recognise this library as installed. | 
|  | 3130 | Max_device_sdk *string | 
| Pedro Loureiro | c362142 | 2021-09-28 15:40:23 +0000 | [diff] [blame] | 3131 |  | 
|  | 3132 | // The SdkLibrary's min api level as a string | 
|  | 3133 | // | 
|  | 3134 | // This value comes from the ApiLevel of the MinSdkVersion property. | 
|  | 3135 | Sdk_library_min_api_level *string | 
| Jamie Garside | e570ace | 2023-11-27 12:07:36 +0000 | [diff] [blame] | 3136 |  | 
|  | 3137 | // Uses-libs dependencies that the shared library requires to work correctly. | 
|  | 3138 | // | 
|  | 3139 | // This will add dependency="foo:bar" to the <library> section. | 
|  | 3140 | Uses_libs_dependencies []string | 
| Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 3141 | } | 
|  | 3142 |  | 
|  | 3143 | // java_sdk_library_xml builds the permission xml file for a java_sdk_library. | 
|  | 3144 | // Not to be used directly by users. java_sdk_library internally uses this. | 
|  | 3145 | func sdkLibraryXmlFactory() android.Module { | 
|  | 3146 | module := &sdkLibraryXml{} | 
|  | 3147 |  | 
|  | 3148 | module.AddProperties(&module.properties) | 
|  | 3149 |  | 
|  | 3150 | android.InitApexModule(module) | 
|  | 3151 | android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibCommon) | 
|  | 3152 |  | 
|  | 3153 | return module | 
|  | 3154 | } | 
|  | 3155 |  | 
| Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 3156 | func (module *sdkLibraryXml) UniqueApexVariations() bool { | 
|  | 3157 | // sdkLibraryXml needs a unique variation per APEX because the generated XML file contains the path to the | 
|  | 3158 | // mounted APEX, which contains the name of the APEX. | 
|  | 3159 | return true | 
|  | 3160 | } | 
|  | 3161 |  | 
| Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 3162 | // from android.PrebuiltEtcModule | 
| Jooyung Han | 0703fd8 | 2020-08-26 22:11:53 +0900 | [diff] [blame] | 3163 | func (module *sdkLibraryXml) BaseDir() string { | 
|  | 3164 | return "etc" | 
|  | 3165 | } | 
|  | 3166 |  | 
|  | 3167 | // from android.PrebuiltEtcModule | 
| Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 3168 | func (module *sdkLibraryXml) SubDir() string { | 
|  | 3169 | return "permissions" | 
|  | 3170 | } | 
|  | 3171 |  | 
|  | 3172 | // from android.PrebuiltEtcModule | 
| ThiƩbaud Weksteen | 00e8b31 | 2024-03-18 14:06:00 +1100 | [diff] [blame] | 3173 | func (module *sdkLibraryXml) OutputFiles(tag string) (android.Paths, error) { | 
|  | 3174 | return android.OutputPaths{module.outputFilePath}.Paths(), nil | 
| Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 3175 | } | 
|  | 3176 |  | 
| ThiƩbaud Weksteen | 00e8b31 | 2024-03-18 14:06:00 +1100 | [diff] [blame] | 3177 | var _ etc.PrebuiltEtcModule = (*sdkLibraryXml)(nil) | 
|  | 3178 |  | 
| Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 3179 | // from android.ApexModule | 
|  | 3180 | func (module *sdkLibraryXml) AvailableFor(what string) bool { | 
|  | 3181 | return true | 
|  | 3182 | } | 
|  | 3183 |  | 
|  | 3184 | func (module *sdkLibraryXml) DepsMutator(ctx android.BottomUpMutatorContext) { | 
|  | 3185 | // do nothing | 
|  | 3186 | } | 
|  | 3187 |  | 
| Jiyong Park | 45bf82e | 2020-12-15 22:29:02 +0900 | [diff] [blame] | 3188 | var _ android.ApexModule = (*sdkLibraryXml)(nil) | 
|  | 3189 |  | 
|  | 3190 | // Implements android.ApexModule | 
| Dan Albert | c806053 | 2020-07-22 22:32:17 -0700 | [diff] [blame] | 3191 | func (module *sdkLibraryXml) ShouldSupportSdkVersion(ctx android.BaseModuleContext, | 
|  | 3192 | sdkVersion android.ApiLevel) error { | 
| Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 3193 | // sdkLibraryXml doesn't need to be checked separately because java_sdk_library is checked | 
|  | 3194 | return nil | 
|  | 3195 | } | 
|  | 3196 |  | 
| Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 3197 | // File path to the runtime implementation library | 
| Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 3198 | func (module *sdkLibraryXml) implPath(ctx android.ModuleContext) string { | 
| Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 3199 | implName := proptools.String(module.properties.Lib_name) | 
| Colin Cross | ff694a8 | 2023-12-13 15:54:49 -0800 | [diff] [blame] | 3200 | if apexInfo, _ := android.ModuleProvider(ctx, android.ApexInfoProvider); !apexInfo.IsForPlatform() { | 
| Colin Cross | e07f231 | 2020-08-13 11:24:56 -0700 | [diff] [blame] | 3201 | // TODO(b/146468504): ApexVariationName() is only a soong module name, not apex name. | 
| Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 3202 | // In most cases, this works fine. But when apex_name is set or override_apex is used | 
|  | 3203 | // this can be wrong. | 
| Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 3204 | return fmt.Sprintf("/apex/%s/javalib/%s.jar", apexInfo.ApexVariationName, implName) | 
| Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 3205 | } | 
|  | 3206 | partition := "system" | 
|  | 3207 | if module.SocSpecific() { | 
|  | 3208 | partition = "vendor" | 
|  | 3209 | } else if module.DeviceSpecific() { | 
|  | 3210 | partition = "odm" | 
|  | 3211 | } else if module.ProductSpecific() { | 
|  | 3212 | partition = "product" | 
|  | 3213 | } else if module.SystemExtSpecific() { | 
|  | 3214 | partition = "system_ext" | 
|  | 3215 | } | 
|  | 3216 | return "/" + partition + "/framework/" + implName + ".jar" | 
|  | 3217 | } | 
|  | 3218 |  | 
| Pedro Loureiro | 9956e5e | 2021-09-07 17:21:59 +0000 | [diff] [blame] | 3219 | func formattedOptionalSdkLevelAttribute(ctx android.ModuleContext, attrName string, value *string) string { | 
|  | 3220 | if value == nil { | 
|  | 3221 | return "" | 
|  | 3222 | } | 
|  | 3223 | apiLevel, err := android.ApiLevelFromUser(ctx, *value) | 
|  | 3224 | if err != nil { | 
| Pedro Loureiro | ba6682f | 2021-10-29 09:32:32 +0000 | [diff] [blame] | 3225 | // attributes in bp files have underscores but in the xml have dashes. | 
|  | 3226 | ctx.PropertyErrorf(strings.ReplaceAll(attrName, "-", "_"), err.Error()) | 
| Pedro Loureiro | 9956e5e | 2021-09-07 17:21:59 +0000 | [diff] [blame] | 3227 | return "" | 
|  | 3228 | } | 
| Pedro Loureiro | b638c62 | 2021-12-22 15:28:05 +0000 | [diff] [blame] | 3229 | if apiLevel.IsCurrent() { | 
|  | 3230 | // passing "current" would always mean a future release, never the current (or the current in | 
|  | 3231 | // progress) which means some conditions would never be triggered. | 
|  | 3232 | ctx.PropertyErrorf(strings.ReplaceAll(attrName, "-", "_"), | 
|  | 3233 | `"current" is not an allowed value for this attribute`) | 
|  | 3234 | return "" | 
|  | 3235 | } | 
| Pedro Loureiro | 4899122 | 2022-06-17 20:01:21 +0000 | [diff] [blame] | 3236 | // "safeValue" is safe because it translates finalized codenames to a string | 
|  | 3237 | // with their SDK int. | 
|  | 3238 | safeValue := apiLevel.String() | 
|  | 3239 | return formattedOptionalAttribute(attrName, &safeValue) | 
| Pedro Loureiro | 9956e5e | 2021-09-07 17:21:59 +0000 | [diff] [blame] | 3240 | } | 
|  | 3241 |  | 
|  | 3242 | // formats an attribute for the xml permissions file if the value is not null | 
|  | 3243 | // returns empty string otherwise | 
|  | 3244 | func formattedOptionalAttribute(attrName string, value *string) string { | 
|  | 3245 | if value == nil { | 
|  | 3246 | return "" | 
|  | 3247 | } | 
| Paul Duffin | 1816cde | 2024-04-10 10:58:21 +0100 | [diff] [blame] | 3248 | return fmt.Sprintf("        %s=\"%s\"\n", attrName, *value) | 
| Pedro Loureiro | 9956e5e | 2021-09-07 17:21:59 +0000 | [diff] [blame] | 3249 | } | 
|  | 3250 |  | 
| Jamie Garside | e570ace | 2023-11-27 12:07:36 +0000 | [diff] [blame] | 3251 | func formattedDependenciesAttribute(dependencies []string) string { | 
|  | 3252 | if dependencies == nil { | 
|  | 3253 | return "" | 
|  | 3254 | } | 
| Paul Duffin | 1816cde | 2024-04-10 10:58:21 +0100 | [diff] [blame] | 3255 | return fmt.Sprintf("        dependency=\"%s\"\n", strings.Join(dependencies, ":")) | 
| Jamie Garside | e570ace | 2023-11-27 12:07:36 +0000 | [diff] [blame] | 3256 | } | 
|  | 3257 |  | 
| Pedro Loureiro | 9956e5e | 2021-09-07 17:21:59 +0000 | [diff] [blame] | 3258 | func (module *sdkLibraryXml) permissionsContents(ctx android.ModuleContext) string { | 
|  | 3259 | libName := proptools.String(module.properties.Lib_name) | 
|  | 3260 | libNameAttr := formattedOptionalAttribute("name", &libName) | 
|  | 3261 | filePath := module.implPath(ctx) | 
|  | 3262 | filePathAttr := formattedOptionalAttribute("file", &filePath) | 
| Pedro Loureiro | ba6682f | 2021-10-29 09:32:32 +0000 | [diff] [blame] | 3263 | implicitFromAttr := formattedOptionalSdkLevelAttribute(ctx, "on-bootclasspath-since", module.properties.On_bootclasspath_since) | 
|  | 3264 | implicitUntilAttr := formattedOptionalSdkLevelAttribute(ctx, "on-bootclasspath-before", module.properties.On_bootclasspath_before) | 
|  | 3265 | minSdkAttr := formattedOptionalSdkLevelAttribute(ctx, "min-device-sdk", module.properties.Min_device_sdk) | 
|  | 3266 | maxSdkAttr := formattedOptionalSdkLevelAttribute(ctx, "max-device-sdk", module.properties.Max_device_sdk) | 
| Jamie Garside | e570ace | 2023-11-27 12:07:36 +0000 | [diff] [blame] | 3267 | dependenciesAttr := formattedDependenciesAttribute(module.properties.Uses_libs_dependencies) | 
| Pedro Loureiro | 196d3e6 | 2021-12-22 19:53:01 +0000 | [diff] [blame] | 3268 | // <library> is understood in all android versions whereas <apex-library> is only understood from API T (and ignored before that). | 
|  | 3269 | // similarly, min_device_sdk is only understood from T. So if a library is using that, we need to use the apex-library to make sure this library is not loaded before T | 
| Pedro Loureiro | c362142 | 2021-09-28 15:40:23 +0000 | [diff] [blame] | 3270 | var libraryTag string | 
|  | 3271 | if module.properties.Min_device_sdk != nil { | 
| Paul Duffin | 1816cde | 2024-04-10 10:58:21 +0100 | [diff] [blame] | 3272 | libraryTag = "    <apex-library\n" | 
| Pedro Loureiro | c362142 | 2021-09-28 15:40:23 +0000 | [diff] [blame] | 3273 | } else { | 
| Paul Duffin | 1816cde | 2024-04-10 10:58:21 +0100 | [diff] [blame] | 3274 | libraryTag = "    <library\n" | 
| Pedro Loureiro | c362142 | 2021-09-28 15:40:23 +0000 | [diff] [blame] | 3275 | } | 
| Pedro Loureiro | 9956e5e | 2021-09-07 17:21:59 +0000 | [diff] [blame] | 3276 |  | 
|  | 3277 | return strings.Join([]string{ | 
| Paul Duffin | 1816cde | 2024-04-10 10:58:21 +0100 | [diff] [blame] | 3278 | "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n", | 
|  | 3279 | "<!-- Copyright (C) 2018 The Android Open Source Project\n", | 
|  | 3280 | "\n", | 
|  | 3281 | "    Licensed under the Apache License, Version 2.0 (the \"License\");\n", | 
|  | 3282 | "    you may not use this file except in compliance with the License.\n", | 
|  | 3283 | "    You may obtain a copy of the License at\n", | 
|  | 3284 | "\n", | 
|  | 3285 | "        http://www.apache.org/licenses/LICENSE-2.0\n", | 
|  | 3286 | "\n", | 
|  | 3287 | "    Unless required by applicable law or agreed to in writing, software\n", | 
|  | 3288 | "    distributed under the License is distributed on an \"AS IS\" BASIS,\n", | 
|  | 3289 | "    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n", | 
|  | 3290 | "    See the License for the specific language governing permissions and\n", | 
|  | 3291 | "    limitations under the License.\n", | 
|  | 3292 | "-->\n", | 
|  | 3293 | "<permissions>\n", | 
| Pedro Loureiro | c362142 | 2021-09-28 15:40:23 +0000 | [diff] [blame] | 3294 | libraryTag, | 
| Pedro Loureiro | 9956e5e | 2021-09-07 17:21:59 +0000 | [diff] [blame] | 3295 | libNameAttr, | 
|  | 3296 | filePathAttr, | 
|  | 3297 | implicitFromAttr, | 
|  | 3298 | implicitUntilAttr, | 
|  | 3299 | minSdkAttr, | 
|  | 3300 | maxSdkAttr, | 
| Jamie Garside | e570ace | 2023-11-27 12:07:36 +0000 | [diff] [blame] | 3301 | dependenciesAttr, | 
| Paul Duffin | 1816cde | 2024-04-10 10:58:21 +0100 | [diff] [blame] | 3302 | "    />\n", | 
|  | 3303 | "</permissions>\n", | 
|  | 3304 | }, "") | 
| Pedro Loureiro | 9956e5e | 2021-09-07 17:21:59 +0000 | [diff] [blame] | 3305 | } | 
|  | 3306 |  | 
| Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 3307 | func (module *sdkLibraryXml) GenerateAndroidBuildActions(ctx android.ModuleContext) { | 
| Colin Cross | ff694a8 | 2023-12-13 15:54:49 -0800 | [diff] [blame] | 3308 | apexInfo, _ := android.ModuleProvider(ctx, android.ApexInfoProvider) | 
|  | 3309 | module.hideApexVariantFromMake = !apexInfo.IsForPlatform() | 
| Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 3310 |  | 
| Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 3311 | libName := proptools.String(module.properties.Lib_name) | 
| Pedro Loureiro | c362142 | 2021-09-28 15:40:23 +0000 | [diff] [blame] | 3312 | module.selfValidate(ctx) | 
| Pedro Loureiro | 9956e5e | 2021-09-07 17:21:59 +0000 | [diff] [blame] | 3313 | xmlContent := module.permissionsContents(ctx) | 
| Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 3314 |  | 
|  | 3315 | module.outputFilePath = android.PathForModuleOut(ctx, libName+".xml").OutputPath | 
| Paul Duffin | 1816cde | 2024-04-10 10:58:21 +0100 | [diff] [blame] | 3316 | android.WriteFileRuleVerbatim(ctx, module.outputFilePath, xmlContent) | 
| Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 3317 |  | 
|  | 3318 | module.installDirPath = android.PathForModuleInstall(ctx, "etc", module.SubDir()) | 
|  | 3319 | } | 
|  | 3320 |  | 
|  | 3321 | func (module *sdkLibraryXml) AndroidMkEntries() []android.AndroidMkEntries { | 
| Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 3322 | if module.hideApexVariantFromMake { | 
| satayev | 8f088b0 | 2021-12-06 11:40:46 +0000 | [diff] [blame] | 3323 | return []android.AndroidMkEntries{{ | 
| Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 3324 | Disabled: true, | 
|  | 3325 | }} | 
|  | 3326 | } | 
|  | 3327 |  | 
| satayev | 8f088b0 | 2021-12-06 11:40:46 +0000 | [diff] [blame] | 3328 | return []android.AndroidMkEntries{{ | 
| Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 3329 | Class:      "ETC", | 
|  | 3330 | OutputFile: android.OptionalPathForPath(module.outputFilePath), | 
|  | 3331 | ExtraEntries: []android.AndroidMkExtraEntriesFunc{ | 
| Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 3332 | func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) { | 
| Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 3333 | entries.SetString("LOCAL_MODULE_TAGS", "optional") | 
| Colin Cross | c68db4b | 2021-11-11 18:59:15 -0800 | [diff] [blame] | 3334 | entries.SetString("LOCAL_MODULE_PATH", module.installDirPath.String()) | 
| Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 3335 | entries.SetString("LOCAL_INSTALLED_MODULE_STEM", module.outputFilePath.Base()) | 
|  | 3336 | }, | 
|  | 3337 | }, | 
|  | 3338 | }} | 
|  | 3339 | } | 
| Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 3340 |  | 
| Pedro Loureiro | c362142 | 2021-09-28 15:40:23 +0000 | [diff] [blame] | 3341 | func (module *sdkLibraryXml) selfValidate(ctx android.ModuleContext) { | 
|  | 3342 | module.validateAtLeastTAttributes(ctx) | 
|  | 3343 | module.validateMinAndMaxDeviceSdk(ctx) | 
|  | 3344 | module.validateMinMaxDeviceSdkAndModuleMinSdk(ctx) | 
|  | 3345 | module.validateOnBootclasspathBeforeRequirements(ctx) | 
|  | 3346 | } | 
|  | 3347 |  | 
|  | 3348 | func (module *sdkLibraryXml) validateAtLeastTAttributes(ctx android.ModuleContext) { | 
|  | 3349 | t := android.ApiLevelOrPanic(ctx, "Tiramisu") | 
|  | 3350 | module.attrAtLeastT(ctx, t, module.properties.Min_device_sdk, "min_device_sdk") | 
|  | 3351 | module.attrAtLeastT(ctx, t, module.properties.Max_device_sdk, "max_device_sdk") | 
|  | 3352 | module.attrAtLeastT(ctx, t, module.properties.On_bootclasspath_before, "on_bootclasspath_before") | 
|  | 3353 | module.attrAtLeastT(ctx, t, module.properties.On_bootclasspath_since, "on_bootclasspath_since") | 
|  | 3354 | } | 
|  | 3355 |  | 
|  | 3356 | func (module *sdkLibraryXml) attrAtLeastT(ctx android.ModuleContext, t android.ApiLevel, attr *string, attrName string) { | 
|  | 3357 | if attr != nil { | 
|  | 3358 | if level, err := android.ApiLevelFromUser(ctx, *attr); err == nil { | 
|  | 3359 | // we will inform the user of invalid inputs when we try to write the | 
|  | 3360 | // permissions xml file so we don't need to do it here | 
|  | 3361 | if t.GreaterThan(level) { | 
|  | 3362 | ctx.PropertyErrorf(attrName, "Attribute value needs to be at least T") | 
|  | 3363 | } | 
|  | 3364 | } | 
|  | 3365 | } | 
|  | 3366 | } | 
|  | 3367 |  | 
|  | 3368 | func (module *sdkLibraryXml) validateMinAndMaxDeviceSdk(ctx android.ModuleContext) { | 
|  | 3369 | if module.properties.Min_device_sdk != nil && module.properties.Max_device_sdk != nil { | 
|  | 3370 | min, minErr := android.ApiLevelFromUser(ctx, *module.properties.Min_device_sdk) | 
|  | 3371 | max, maxErr := android.ApiLevelFromUser(ctx, *module.properties.Max_device_sdk) | 
|  | 3372 | if minErr == nil && maxErr == nil { | 
|  | 3373 | // we will inform the user of invalid inputs when we try to write the | 
|  | 3374 | // permissions xml file so we don't need to do it here | 
|  | 3375 | if min.GreaterThan(max) { | 
|  | 3376 | ctx.ModuleErrorf("min_device_sdk can't be greater than max_device_sdk") | 
|  | 3377 | } | 
|  | 3378 | } | 
|  | 3379 | } | 
|  | 3380 | } | 
|  | 3381 |  | 
|  | 3382 | func (module *sdkLibraryXml) validateMinMaxDeviceSdkAndModuleMinSdk(ctx android.ModuleContext) { | 
|  | 3383 | moduleMinApi := android.ApiLevelOrPanic(ctx, *module.properties.Sdk_library_min_api_level) | 
|  | 3384 | if module.properties.Min_device_sdk != nil { | 
|  | 3385 | api, err := android.ApiLevelFromUser(ctx, *module.properties.Min_device_sdk) | 
|  | 3386 | if err == nil { | 
|  | 3387 | if moduleMinApi.GreaterThan(api) { | 
|  | 3388 | ctx.PropertyErrorf("min_device_sdk", "Can't be less than module's min sdk (%s)", moduleMinApi) | 
|  | 3389 | } | 
|  | 3390 | } | 
|  | 3391 | } | 
|  | 3392 | if module.properties.Max_device_sdk != nil { | 
|  | 3393 | api, err := android.ApiLevelFromUser(ctx, *module.properties.Max_device_sdk) | 
|  | 3394 | if err == nil { | 
|  | 3395 | if moduleMinApi.GreaterThan(api) { | 
|  | 3396 | ctx.PropertyErrorf("max_device_sdk", "Can't be less than module's min sdk (%s)", moduleMinApi) | 
|  | 3397 | } | 
|  | 3398 | } | 
|  | 3399 | } | 
|  | 3400 | } | 
|  | 3401 |  | 
|  | 3402 | func (module *sdkLibraryXml) validateOnBootclasspathBeforeRequirements(ctx android.ModuleContext) { | 
|  | 3403 | moduleMinApi := android.ApiLevelOrPanic(ctx, *module.properties.Sdk_library_min_api_level) | 
|  | 3404 | if module.properties.On_bootclasspath_before != nil { | 
|  | 3405 | t := android.ApiLevelOrPanic(ctx, "Tiramisu") | 
|  | 3406 | // if we use the attribute, then we need to do this validation | 
|  | 3407 | if moduleMinApi.LessThan(t) { | 
|  | 3408 | // if minAPi is < T, then we need to have min_device_sdk (which only accepts T+) | 
|  | 3409 | if module.properties.Min_device_sdk == nil { | 
|  | 3410 | ctx.PropertyErrorf("on_bootclasspath_before", "Using this property requires that the module's min_sdk_version or the shared library's min_device_sdk is at least T") | 
|  | 3411 | } | 
|  | 3412 | } | 
|  | 3413 | } | 
|  | 3414 | } | 
|  | 3415 |  | 
| Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 3416 | type sdkLibrarySdkMemberType struct { | 
|  | 3417 | android.SdkMemberTypeBase | 
|  | 3418 | } | 
|  | 3419 |  | 
| Paul Duffin | 296701e | 2021-07-14 10:29:36 +0100 | [diff] [blame] | 3420 | func (s *sdkLibrarySdkMemberType) AddDependencies(ctx android.SdkDependencyContext, dependencyTag blueprint.DependencyTag, names []string) { | 
|  | 3421 | ctx.AddVariationDependencies(nil, dependencyTag, names...) | 
| Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 3422 | } | 
|  | 3423 |  | 
|  | 3424 | func (s *sdkLibrarySdkMemberType) IsInstance(module android.Module) bool { | 
|  | 3425 | _, ok := module.(*SdkLibrary) | 
|  | 3426 | return ok | 
|  | 3427 | } | 
|  | 3428 |  | 
|  | 3429 | func (s *sdkLibrarySdkMemberType) AddPrebuiltModule(ctx android.SdkMemberContext, member android.SdkMember) android.BpModule { | 
|  | 3430 | return ctx.SnapshotBuilder().AddPrebuiltModule(member, "java_sdk_library_import") | 
|  | 3431 | } | 
|  | 3432 |  | 
|  | 3433 | func (s *sdkLibrarySdkMemberType) CreateVariantPropertiesStruct() android.SdkMemberProperties { | 
|  | 3434 | return &sdkLibrarySdkMemberProperties{} | 
|  | 3435 | } | 
|  | 3436 |  | 
| Paul Duffin | 976b0e5 | 2021-04-27 23:20:26 +0100 | [diff] [blame] | 3437 | var javaSdkLibrarySdkMemberType = &sdkLibrarySdkMemberType{ | 
|  | 3438 | android.SdkMemberTypeBase{ | 
|  | 3439 | PropertyName: "java_sdk_libs", | 
|  | 3440 | SupportsSdk:  true, | 
|  | 3441 | }, | 
|  | 3442 | } | 
|  | 3443 |  | 
| Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 3444 | type sdkLibrarySdkMemberProperties struct { | 
|  | 3445 | android.SdkMemberPropertiesBase | 
|  | 3446 |  | 
| Paul Duffin | e840995 | 2022-09-22 16:24:46 +0100 | [diff] [blame] | 3447 | // Stem name for files in the sdk snapshot. | 
|  | 3448 | // | 
|  | 3449 | // This is used to construct the path names of various sdk library files in the sdk snapshot to | 
|  | 3450 | // make sure that they match the finalized versions of those files in prebuilts/sdk. | 
|  | 3451 | // | 
|  | 3452 | // This property is marked as keep so that it will be kept in all instances of this struct, will | 
|  | 3453 | // not be cleared but will be copied to common structs. That is needed because this field is used | 
|  | 3454 | // to construct many file names for other parts of this struct and so it needs to be present in | 
|  | 3455 | // all structs. If it was not marked as keep then it would be cleared in some structs and so would | 
|  | 3456 | // be unavailable for generating file names if there were other properties that were still set. | 
|  | 3457 | Stem string `sdk:"keep"` | 
|  | 3458 |  | 
| Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 3459 | // Scope to per scope properties. | 
| Paul Duffin | 106a3a4 | 2022-01-27 16:39:06 +0000 | [diff] [blame] | 3460 | Scopes map[*apiScope]*scopeProperties | 
| Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 3461 |  | 
| Paul Duffin | 3d1248c | 2020-04-09 00:10:17 +0100 | [diff] [blame] | 3462 | // The Java stubs source files. | 
|  | 3463 | Stub_srcs []string | 
| Paul Duffin | f7a6433 | 2020-05-13 16:54:55 +0100 | [diff] [blame] | 3464 |  | 
|  | 3465 | // The naming scheme. | 
|  | 3466 | Naming_scheme *string | 
| Paul Duffin | d7eb1c2 | 2020-05-26 20:57:10 +0100 | [diff] [blame] | 3467 |  | 
|  | 3468 | // True if the java_sdk_library_import is for a shared library, false | 
|  | 3469 | // otherwise. | 
|  | 3470 | Shared_library *bool | 
| Paul Duffin | a2ae7e0 | 2020-09-11 11:55:00 +0100 | [diff] [blame] | 3471 |  | 
| Paul Duffin | 1267d87 | 2021-04-16 17:21:36 +0100 | [diff] [blame] | 3472 | // True if the stub imports should produce dex jars. | 
|  | 3473 | Compile_dex *bool | 
|  | 3474 |  | 
| Paul Duffin | a2ae7e0 | 2020-09-11 11:55:00 +0100 | [diff] [blame] | 3475 | // The paths to the doctag files to add to the prebuilt. | 
|  | 3476 | Doctag_paths android.Paths | 
| Paul Duffin | 869de14 | 2021-07-15 14:14:41 +0100 | [diff] [blame] | 3477 |  | 
|  | 3478 | Permitted_packages []string | 
| Pedro Loureiro | 9956e5e | 2021-09-07 17:21:59 +0000 | [diff] [blame] | 3479 |  | 
|  | 3480 | // Signals that this shared library is part of the bootclasspath starting | 
|  | 3481 | // on the version indicated in this attribute. | 
|  | 3482 | // | 
|  | 3483 | // This will make platforms at this level and above to ignore | 
|  | 3484 | // <uses-library> tags with this library name because the library is already | 
|  | 3485 | // available | 
|  | 3486 | On_bootclasspath_since *string | 
|  | 3487 |  | 
|  | 3488 | // Signals that this shared library was part of the bootclasspath before | 
|  | 3489 | // (but not including) the version indicated in this attribute. | 
|  | 3490 | // | 
|  | 3491 | // The system will automatically add a <uses-library> tag with this library to | 
|  | 3492 | // apps that target any SDK less than the version indicated in this attribute. | 
|  | 3493 | On_bootclasspath_before *string | 
|  | 3494 |  | 
|  | 3495 | // Indicates that PackageManager should ignore this shared library if the | 
|  | 3496 | // platform is below the version indicated in this attribute. | 
|  | 3497 | // | 
|  | 3498 | // This means that the device won't recognise this library as installed. | 
|  | 3499 | Min_device_sdk *string | 
|  | 3500 |  | 
|  | 3501 | // Indicates that PackageManager should ignore this shared library if the | 
|  | 3502 | // platform is above the version indicated in this attribute. | 
|  | 3503 | // | 
|  | 3504 | // This means that the device won't recognise this library as installed. | 
|  | 3505 | Max_device_sdk *string | 
| Jiakai Zhang | 9c4dc19 | 2023-02-09 00:09:24 +0800 | [diff] [blame] | 3506 |  | 
|  | 3507 | DexPreoptProfileGuided *bool `supported_build_releases:"UpsideDownCake+"` | 
| Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 3508 | } | 
|  | 3509 |  | 
|  | 3510 | type scopeProperties struct { | 
| Paul Duffin | 1fd005d | 2020-04-09 01:08:11 +0100 | [diff] [blame] | 3511 | Jars           android.Paths | 
|  | 3512 | StubsSrcJar    android.Path | 
|  | 3513 | CurrentApiFile android.Path | 
|  | 3514 | RemovedApiFile android.Path | 
| Paul Duffin | e7babdb | 2022-02-10 13:06:54 +0000 | [diff] [blame] | 3515 | AnnotationsZip android.Path `supported_build_releases:"Tiramisu+"` | 
| Paul Duffin | 1fd005d | 2020-04-09 01:08:11 +0100 | [diff] [blame] | 3516 | SdkVersion     string | 
| Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 3517 | } | 
|  | 3518 |  | 
|  | 3519 | func (s *sdkLibrarySdkMemberProperties) PopulateFromVariant(ctx android.SdkMemberContext, variant android.Module) { | 
|  | 3520 | sdk := variant.(*SdkLibrary) | 
|  | 3521 |  | 
| Paul Duffin | e840995 | 2022-09-22 16:24:46 +0100 | [diff] [blame] | 3522 | // Copy the stem name for files in the sdk snapshot. | 
|  | 3523 | s.Stem = sdk.distStem() | 
|  | 3524 |  | 
| Paul Duffin | 106a3a4 | 2022-01-27 16:39:06 +0000 | [diff] [blame] | 3525 | s.Scopes = make(map[*apiScope]*scopeProperties) | 
| Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 3526 | for _, apiScope := range allApiScopes { | 
| Paul Duffin | 803a956 | 2020-05-20 11:52:25 +0100 | [diff] [blame] | 3527 | paths := sdk.findScopePaths(apiScope) | 
|  | 3528 | if paths == nil { | 
|  | 3529 | continue | 
|  | 3530 | } | 
|  | 3531 |  | 
| Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 3532 | jars := paths.stubsImplPath | 
|  | 3533 | if len(jars) > 0 { | 
|  | 3534 | properties := scopeProperties{} | 
|  | 3535 | properties.Jars = jars | 
| Paul Duffin | 780c5f4 | 2020-05-12 15:52:55 +0100 | [diff] [blame] | 3536 | properties.SdkVersion = sdk.sdkVersionForStubsLibrary(ctx.SdkModuleContext(), apiScope) | 
| Paul Duffin | 0f8faff | 2020-05-20 16:18:00 +0100 | [diff] [blame] | 3537 | properties.StubsSrcJar = paths.stubsSrcJar.Path() | 
| Paul Duffin | 10269f1 | 2020-06-19 18:39:55 +0100 | [diff] [blame] | 3538 | if paths.currentApiFilePath.Valid() { | 
|  | 3539 | properties.CurrentApiFile = paths.currentApiFilePath.Path() | 
|  | 3540 | } | 
|  | 3541 | if paths.removedApiFilePath.Valid() { | 
|  | 3542 | properties.RemovedApiFile = paths.removedApiFilePath.Path() | 
|  | 3543 | } | 
| Anton Hansson | d78eb76 | 2021-09-21 15:25:12 +0100 | [diff] [blame] | 3544 | // The annotations zip is only available for modules that set annotations_enabled: true. | 
|  | 3545 | if paths.annotationsZip.Valid() { | 
|  | 3546 | properties.AnnotationsZip = paths.annotationsZip.Path() | 
|  | 3547 | } | 
| Paul Duffin | 106a3a4 | 2022-01-27 16:39:06 +0000 | [diff] [blame] | 3548 | s.Scopes[apiScope] = &properties | 
| Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 3549 | } | 
|  | 3550 | } | 
|  | 3551 |  | 
| Paul Duffin | dfa131e | 2020-05-15 20:37:11 +0100 | [diff] [blame] | 3552 | s.Naming_scheme = sdk.commonSdkLibraryProperties.Naming_scheme | 
| Paul Duffin | d7eb1c2 | 2020-05-26 20:57:10 +0100 | [diff] [blame] | 3553 | s.Shared_library = proptools.BoolPtr(sdk.sharedLibrary()) | 
| Paul Duffin | 1267d87 | 2021-04-16 17:21:36 +0100 | [diff] [blame] | 3554 | s.Compile_dex = sdk.dexProperties.Compile_dex | 
| Paul Duffin | a2ae7e0 | 2020-09-11 11:55:00 +0100 | [diff] [blame] | 3555 | s.Doctag_paths = sdk.doctagPaths | 
| Paul Duffin | 869de14 | 2021-07-15 14:14:41 +0100 | [diff] [blame] | 3556 | s.Permitted_packages = sdk.PermittedPackagesForUpdatableBootJars() | 
| Pedro Loureiro | 9956e5e | 2021-09-07 17:21:59 +0000 | [diff] [blame] | 3557 | s.On_bootclasspath_since = sdk.commonSdkLibraryProperties.On_bootclasspath_since | 
|  | 3558 | s.On_bootclasspath_before = sdk.commonSdkLibraryProperties.On_bootclasspath_before | 
|  | 3559 | s.Min_device_sdk = sdk.commonSdkLibraryProperties.Min_device_sdk | 
|  | 3560 | s.Max_device_sdk = sdk.commonSdkLibraryProperties.Max_device_sdk | 
| Jiakai Zhang | 9c4dc19 | 2023-02-09 00:09:24 +0800 | [diff] [blame] | 3561 |  | 
|  | 3562 | if sdk.dexpreopter.dexpreoptProperties.Dex_preopt_result.Profile_guided { | 
|  | 3563 | s.DexPreoptProfileGuided = proptools.BoolPtr(true) | 
|  | 3564 | } | 
| Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 3565 | } | 
|  | 3566 |  | 
|  | 3567 | func (s *sdkLibrarySdkMemberProperties) AddToPropertySet(ctx android.SdkMemberContext, propertySet android.BpPropertySet) { | 
| Paul Duffin | f7a6433 | 2020-05-13 16:54:55 +0100 | [diff] [blame] | 3568 | if s.Naming_scheme != nil { | 
|  | 3569 | propertySet.AddProperty("naming_scheme", proptools.String(s.Naming_scheme)) | 
|  | 3570 | } | 
| Paul Duffin | d7eb1c2 | 2020-05-26 20:57:10 +0100 | [diff] [blame] | 3571 | if s.Shared_library != nil { | 
|  | 3572 | propertySet.AddProperty("shared_library", *s.Shared_library) | 
|  | 3573 | } | 
| Paul Duffin | 1267d87 | 2021-04-16 17:21:36 +0100 | [diff] [blame] | 3574 | if s.Compile_dex != nil { | 
|  | 3575 | propertySet.AddProperty("compile_dex", *s.Compile_dex) | 
|  | 3576 | } | 
| Paul Duffin | 869de14 | 2021-07-15 14:14:41 +0100 | [diff] [blame] | 3577 | if len(s.Permitted_packages) > 0 { | 
|  | 3578 | propertySet.AddProperty("permitted_packages", s.Permitted_packages) | 
|  | 3579 | } | 
| Jiakai Zhang | 9c4dc19 | 2023-02-09 00:09:24 +0800 | [diff] [blame] | 3580 | dexPreoptSet := propertySet.AddPropertySet("dex_preopt") | 
|  | 3581 | if s.DexPreoptProfileGuided != nil { | 
|  | 3582 | dexPreoptSet.AddProperty("profile_guided", proptools.Bool(s.DexPreoptProfileGuided)) | 
|  | 3583 | } | 
| Paul Duffin | f7a6433 | 2020-05-13 16:54:55 +0100 | [diff] [blame] | 3584 |  | 
| Paul Duffin | e840995 | 2022-09-22 16:24:46 +0100 | [diff] [blame] | 3585 | stem := s.Stem | 
|  | 3586 |  | 
| Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 3587 | for _, apiScope := range allApiScopes { | 
|  | 3588 | if properties, ok := s.Scopes[apiScope]; ok { | 
| Paul Duffin | 6b836ba | 2020-05-13 19:19:49 +0100 | [diff] [blame] | 3589 | scopeSet := propertySet.AddPropertySet(apiScope.propertyName) | 
| Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 3590 |  | 
| Paul Duffin | 958806b | 2022-05-16 13:10:47 +0000 | [diff] [blame] | 3591 | scopeDir := apiScope.snapshotRelativeDir() | 
| Paul Duffin | 3d1248c | 2020-04-09 00:10:17 +0100 | [diff] [blame] | 3592 |  | 
| Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 3593 | var jars []string | 
|  | 3594 | for _, p := range properties.Jars { | 
| Paul Duffin | e840995 | 2022-09-22 16:24:46 +0100 | [diff] [blame] | 3595 | dest := filepath.Join(scopeDir, stem+"-stubs.jar") | 
| Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 3596 | ctx.SnapshotBuilder().CopyToSnapshot(p, dest) | 
|  | 3597 | jars = append(jars, dest) | 
|  | 3598 | } | 
|  | 3599 | scopeSet.AddProperty("jars", jars) | 
|  | 3600 |  | 
| Paul Duffin | 22628d5 | 2021-05-12 23:13:22 +0100 | [diff] [blame] | 3601 | if ctx.SdkModuleContext().Config().IsEnvTrue("SOONG_SDK_SNAPSHOT_USE_SRCJAR") { | 
|  | 3602 | // Copy the stubs source jar into the snapshot zip as is. | 
| Paul Duffin | e840995 | 2022-09-22 16:24:46 +0100 | [diff] [blame] | 3603 | srcJarSnapshotPath := filepath.Join(scopeDir, stem+".srcjar") | 
| Paul Duffin | 22628d5 | 2021-05-12 23:13:22 +0100 | [diff] [blame] | 3604 | ctx.SnapshotBuilder().CopyToSnapshot(properties.StubsSrcJar, srcJarSnapshotPath) | 
|  | 3605 | scopeSet.AddProperty("stub_srcs", []string{srcJarSnapshotPath}) | 
|  | 3606 | } else { | 
|  | 3607 | // Merge the stubs source jar into the snapshot zip so that when it is unpacked | 
|  | 3608 | // the source files are also unpacked. | 
| Paul Duffin | e840995 | 2022-09-22 16:24:46 +0100 | [diff] [blame] | 3609 | snapshotRelativeDir := filepath.Join(scopeDir, stem+"_stub_sources") | 
| Paul Duffin | 22628d5 | 2021-05-12 23:13:22 +0100 | [diff] [blame] | 3610 | ctx.SnapshotBuilder().UnzipToSnapshot(properties.StubsSrcJar, snapshotRelativeDir) | 
|  | 3611 | scopeSet.AddProperty("stub_srcs", []string{snapshotRelativeDir}) | 
|  | 3612 | } | 
| Paul Duffin | 3d1248c | 2020-04-09 00:10:17 +0100 | [diff] [blame] | 3613 |  | 
| Paul Duffin | 1fd005d | 2020-04-09 01:08:11 +0100 | [diff] [blame] | 3614 | if properties.CurrentApiFile != nil { | 
| Paul Duffin | e840995 | 2022-09-22 16:24:46 +0100 | [diff] [blame] | 3615 | currentApiSnapshotPath := apiScope.snapshotRelativeCurrentApiTxtPath(stem) | 
| Paul Duffin | 1fd005d | 2020-04-09 01:08:11 +0100 | [diff] [blame] | 3616 | ctx.SnapshotBuilder().CopyToSnapshot(properties.CurrentApiFile, currentApiSnapshotPath) | 
|  | 3617 | scopeSet.AddProperty("current_api", currentApiSnapshotPath) | 
|  | 3618 | } | 
|  | 3619 |  | 
|  | 3620 | if properties.RemovedApiFile != nil { | 
| Paul Duffin | e840995 | 2022-09-22 16:24:46 +0100 | [diff] [blame] | 3621 | removedApiSnapshotPath := apiScope.snapshotRelativeRemovedApiTxtPath(stem) | 
| Paul Duffin | 3dbf9fd | 2020-06-02 13:00:02 +0100 | [diff] [blame] | 3622 | ctx.SnapshotBuilder().CopyToSnapshot(properties.RemovedApiFile, removedApiSnapshotPath) | 
| Paul Duffin | 1fd005d | 2020-04-09 01:08:11 +0100 | [diff] [blame] | 3623 | scopeSet.AddProperty("removed_api", removedApiSnapshotPath) | 
|  | 3624 | } | 
|  | 3625 |  | 
| Anton Hansson | d78eb76 | 2021-09-21 15:25:12 +0100 | [diff] [blame] | 3626 | if properties.AnnotationsZip != nil { | 
| Paul Duffin | e840995 | 2022-09-22 16:24:46 +0100 | [diff] [blame] | 3627 | annotationsSnapshotPath := filepath.Join(scopeDir, stem+"_annotations.zip") | 
| Anton Hansson | d78eb76 | 2021-09-21 15:25:12 +0100 | [diff] [blame] | 3628 | ctx.SnapshotBuilder().CopyToSnapshot(properties.AnnotationsZip, annotationsSnapshotPath) | 
|  | 3629 | scopeSet.AddProperty("annotations", annotationsSnapshotPath) | 
|  | 3630 | } | 
|  | 3631 |  | 
| Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 3632 | if properties.SdkVersion != "" { | 
|  | 3633 | scopeSet.AddProperty("sdk_version", properties.SdkVersion) | 
|  | 3634 | } | 
|  | 3635 | } | 
|  | 3636 | } | 
|  | 3637 |  | 
| Paul Duffin | a2ae7e0 | 2020-09-11 11:55:00 +0100 | [diff] [blame] | 3638 | if len(s.Doctag_paths) > 0 { | 
|  | 3639 | dests := []string{} | 
|  | 3640 | for _, p := range s.Doctag_paths { | 
|  | 3641 | dest := filepath.Join("doctags", p.Rel()) | 
|  | 3642 | ctx.SnapshotBuilder().CopyToSnapshot(p, dest) | 
|  | 3643 | dests = append(dests, dest) | 
|  | 3644 | } | 
|  | 3645 | propertySet.AddProperty("doctag_files", dests) | 
|  | 3646 | } | 
| Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 3647 | } |