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