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