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