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