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" |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 32 | ) |
| 33 | |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 34 | // A tag to associated a dependency with a specific api scope. |
| 35 | type scopeDependencyTag struct { |
| 36 | blueprint.BaseDependencyTag |
| 37 | name string |
| 38 | apiScope *apiScope |
Paul Duffin | c878250 | 2020-04-29 20:45:27 +0100 | [diff] [blame] | 39 | |
| 40 | // Function for extracting appropriate path information from the dependency. |
Colin Cross | dcf71b2 | 2021-02-01 13:59:03 -0800 | [diff] [blame] | 41 | depInfoExtractor func(paths *scopePaths, ctx android.ModuleContext, dep android.Module) error |
Paul Duffin | c878250 | 2020-04-29 20:45:27 +0100 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | // Extract tag specific information from the dependency. |
| 45 | func (tag scopeDependencyTag) extractDepInfo(ctx android.ModuleContext, dep android.Module, paths *scopePaths) { |
Colin Cross | dcf71b2 | 2021-02-01 13:59:03 -0800 | [diff] [blame] | 46 | err := tag.depInfoExtractor(paths, ctx, dep) |
Paul Duffin | c878250 | 2020-04-29 20:45:27 +0100 | [diff] [blame] | 47 | if err != nil { |
| 48 | ctx.ModuleErrorf("has an invalid {scopeDependencyTag: %s} dependency on module %s: %s", tag.name, ctx.OtherModuleName(dep), err.Error()) |
| 49 | } |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 50 | } |
| 51 | |
Paul Duffin | 80342d7 | 2020-06-26 22:08:43 +0100 | [diff] [blame] | 52 | var _ android.ReplaceSourceWithPrebuilt = (*scopeDependencyTag)(nil) |
| 53 | |
| 54 | func (tag scopeDependencyTag) ReplaceSourceWithPrebuilt() bool { |
| 55 | return false |
| 56 | } |
| 57 | |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 58 | // Provides information about an api scope, e.g. public, system, test. |
| 59 | type apiScope struct { |
| 60 | // The name of the api scope, e.g. public, system, test |
| 61 | name string |
| 62 | |
Paul Duffin | 97b53b8 | 2020-05-05 14:40:52 +0100 | [diff] [blame] | 63 | // The api scope that this scope extends. |
Paul Duffin | d0b9fca | 2022-09-30 18:11:41 +0100 | [diff] [blame] | 64 | // |
| 65 | // This organizes the scopes into an extension hierarchy. |
| 66 | // |
| 67 | // If set this means that the API provided by this scope includes the API provided by the scope |
| 68 | // set in this field. |
Paul Duffin | 97b53b8 | 2020-05-05 14:40:52 +0100 | [diff] [blame] | 69 | extends *apiScope |
| 70 | |
Paul Duffin | d0b9fca | 2022-09-30 18:11:41 +0100 | [diff] [blame] | 71 | // The next api scope that a library that uses this scope can access. |
| 72 | // |
| 73 | // This organizes the scopes into an access hierarchy. |
| 74 | // |
| 75 | // If set this means that a library that can access this API can also access the API provided by |
| 76 | // the scope set in this field. |
| 77 | // |
| 78 | // A module that sets sdk_version: "<scope>_current" should have access to the <scope> API of |
| 79 | // every java_sdk_library that it depends on. If the library does not provide an API for <scope> |
| 80 | // then it will traverse up this access hierarchy to find an API that it does provide. |
| 81 | // |
| 82 | // If this is not set then it defaults to the scope set in extends. |
| 83 | canAccess *apiScope |
| 84 | |
Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 85 | // The legacy enabled status for a specific scope can be dependent on other |
| 86 | // properties that have been specified on the library so it is provided by |
| 87 | // a function that can determine the status by examining those properties. |
| 88 | legacyEnabledStatus func(module *SdkLibrary) bool |
| 89 | |
| 90 | // The default enabled status for non-legacy behavior, which is triggered by |
| 91 | // explicitly enabling at least one api scope. |
| 92 | defaultEnabledStatus bool |
| 93 | |
| 94 | // Gets a pointer to the scope specific properties. |
| 95 | scopeSpecificProperties func(module *SdkLibrary) *ApiScopeProperties |
| 96 | |
Paul Duffin | 46a26a8 | 2020-04-07 19:27:04 +0100 | [diff] [blame] | 97 | // The name of the field in the dynamically created structure. |
| 98 | fieldName string |
| 99 | |
Paul Duffin | 6b836ba | 2020-05-13 19:19:49 +0100 | [diff] [blame] | 100 | // The name of the property in the java_sdk_library_import |
| 101 | propertyName string |
| 102 | |
Jihoon Kang | b743155 | 2024-01-22 19:40:08 +0000 | [diff] [blame] | 103 | // The tag to use to depend on the prebuilt stubs library module |
| 104 | prebuiltStubsTag scopeDependencyTag |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 105 | |
Jihoon Kang | bd09345 | 2023-12-26 19:08:01 +0000 | [diff] [blame] | 106 | // The tag to use to depend on the everything stubs library module. |
| 107 | everythingStubsTag scopeDependencyTag |
| 108 | |
| 109 | // The tag to use to depend on the exportable stubs library module. |
| 110 | exportableStubsTag scopeDependencyTag |
| 111 | |
Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 112 | // The tag to use to depend on the stubs source module (if separate from the API module). |
| 113 | stubsSourceTag scopeDependencyTag |
| 114 | |
Paul Duffin | c878250 | 2020-04-29 20:45:27 +0100 | [diff] [blame] | 115 | // The tag to use to depend on the stubs source and API module. |
| 116 | stubsSourceAndApiTag scopeDependencyTag |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 117 | |
Paul Duffin | 958806b | 2022-05-16 13:10:47 +0000 | [diff] [blame] | 118 | // The tag to use to depend on the module that provides the latest version of the API .txt file. |
| 119 | latestApiModuleTag scopeDependencyTag |
| 120 | |
| 121 | // The tag to use to depend on the module that provides the latest version of the API removed.txt |
| 122 | // file. |
| 123 | latestRemovedApiModuleTag scopeDependencyTag |
| 124 | |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 125 | // The scope specific prefix to add to the api file base of "current.txt" or "removed.txt". |
| 126 | apiFilePrefix string |
| 127 | |
Paul Duffin | d0b9fca | 2022-09-30 18:11:41 +0100 | [diff] [blame] | 128 | // 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] | 129 | // module name. |
| 130 | moduleSuffix string |
| 131 | |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 132 | // SDK version that the stubs library is built against. Note that this is always |
| 133 | // *current. Older stubs library built with a numbered SDK version is created from |
| 134 | // the prebuilt jar. |
| 135 | sdkVersion string |
Paul Duffin | 1fb487d | 2020-04-07 18:50:10 +0100 | [diff] [blame] | 136 | |
Paul Duffin | 15f34ef | 2020-07-20 18:04:44 +0100 | [diff] [blame] | 137 | // The annotation that identifies this API level, empty for the public API scope. |
| 138 | annotation string |
| 139 | |
Paul Duffin | 1fb487d | 2020-04-07 18:50:10 +0100 | [diff] [blame] | 140 | // Extra arguments to pass to droidstubs for this scope. |
Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 141 | // |
Paul Duffin | 15f34ef | 2020-07-20 18:04:44 +0100 | [diff] [blame] | 142 | // This is not used directly but is used to construct the droidstubsArgs. |
| 143 | extraArgs []string |
Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 144 | |
Paul Duffin | 15f34ef | 2020-07-20 18:04:44 +0100 | [diff] [blame] | 145 | // The args that must be passed to droidstubs to generate the API and stubs source |
| 146 | // for this scope, constructed dynamically by initApiScope(). |
Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 147 | // |
| 148 | // The API only includes the additional members that this scope adds over the scope |
| 149 | // that it extends. |
Paul Duffin | 15f34ef | 2020-07-20 18:04:44 +0100 | [diff] [blame] | 150 | // |
| 151 | // The stubs source must include the definitions of everything that is in this |
| 152 | // api scope and all the scopes that this one extends. |
| 153 | droidstubsArgs []string |
Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 154 | |
Anton Hansson | 6478ac1 | 2020-05-02 11:19:36 +0100 | [diff] [blame] | 155 | // Whether the api scope can be treated as unstable, and should skip compat checks. |
| 156 | unstable bool |
Jihoon Kang | 1c92c3e | 2023-03-23 17:44:51 +0000 | [diff] [blame] | 157 | |
| 158 | // Represents the SDK kind of this scope. |
| 159 | kind android.SdkKind |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | // Initialize a scope, creating and adding appropriate dependency tags |
| 163 | func initApiScope(scope *apiScope) *apiScope { |
Paul Duffin | c878250 | 2020-04-29 20:45:27 +0100 | [diff] [blame] | 164 | name := scope.name |
Paul Duffin | 46dc45a | 2020-05-14 15:39:10 +0100 | [diff] [blame] | 165 | scopeByName[name] = scope |
| 166 | allScopeNames = append(allScopeNames, name) |
Paul Duffin | 6b836ba | 2020-05-13 19:19:49 +0100 | [diff] [blame] | 167 | scope.propertyName = strings.ReplaceAll(name, "-", "_") |
| 168 | scope.fieldName = proptools.FieldNameForProperty(scope.propertyName) |
Jihoon Kang | b743155 | 2024-01-22 19:40:08 +0000 | [diff] [blame] | 169 | scope.prebuiltStubsTag = scopeDependencyTag{ |
Paul Duffin | c878250 | 2020-04-29 20:45:27 +0100 | [diff] [blame] | 170 | name: name + "-stubs", |
| 171 | apiScope: scope, |
| 172 | depInfoExtractor: (*scopePaths).extractStubsLibraryInfoFromDependency, |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 173 | } |
Jihoon Kang | bd09345 | 2023-12-26 19:08:01 +0000 | [diff] [blame] | 174 | scope.everythingStubsTag = scopeDependencyTag{ |
| 175 | name: name + "-stubs-everything", |
| 176 | apiScope: scope, |
| 177 | depInfoExtractor: (*scopePaths).extractEverythingStubsLibraryInfoFromDependency, |
| 178 | } |
| 179 | scope.exportableStubsTag = scopeDependencyTag{ |
| 180 | name: name + "-stubs-exportable", |
| 181 | apiScope: scope, |
| 182 | depInfoExtractor: (*scopePaths).extractExportableStubsLibraryInfoFromDependency, |
| 183 | } |
Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 184 | scope.stubsSourceTag = scopeDependencyTag{ |
| 185 | name: name + "-stubs-source", |
| 186 | apiScope: scope, |
| 187 | depInfoExtractor: (*scopePaths).extractStubsSourceInfoFromDep, |
| 188 | } |
Paul Duffin | c878250 | 2020-04-29 20:45:27 +0100 | [diff] [blame] | 189 | scope.stubsSourceAndApiTag = scopeDependencyTag{ |
| 190 | name: name + "-stubs-source-and-api", |
| 191 | apiScope: scope, |
| 192 | depInfoExtractor: (*scopePaths).extractStubsSourceAndApiInfoFromApiStubsProvider, |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 193 | } |
Paul Duffin | 958806b | 2022-05-16 13:10:47 +0000 | [diff] [blame] | 194 | scope.latestApiModuleTag = scopeDependencyTag{ |
| 195 | name: name + "-latest-api", |
| 196 | apiScope: scope, |
| 197 | depInfoExtractor: (*scopePaths).extractLatestApiPath, |
| 198 | } |
| 199 | scope.latestRemovedApiModuleTag = scopeDependencyTag{ |
| 200 | name: name + "-latest-removed-api", |
| 201 | apiScope: scope, |
| 202 | depInfoExtractor: (*scopePaths).extractLatestRemovedApiPath, |
| 203 | } |
Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 204 | |
| 205 | // To get the args needed to generate the stubs source append all the args from |
| 206 | // this scope and all the scopes it extends as each set of args adds additional |
| 207 | // members to the stubs. |
Paul Duffin | 15f34ef | 2020-07-20 18:04:44 +0100 | [diff] [blame] | 208 | var scopeSpecificArgs []string |
| 209 | if scope.annotation != "" { |
| 210 | scopeSpecificArgs = []string{"--show-annotation", scope.annotation} |
Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 211 | } |
Paul Duffin | 15f34ef | 2020-07-20 18:04:44 +0100 | [diff] [blame] | 212 | for s := scope; s != nil; s = s.extends { |
| 213 | scopeSpecificArgs = append(scopeSpecificArgs, s.extraArgs...) |
Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 214 | |
Paul Duffin | 15f34ef | 2020-07-20 18:04:44 +0100 | [diff] [blame] | 215 | // Ensure that the generated stubs includes all the API elements from the API scope |
| 216 | // that this scope extends. |
| 217 | if s != scope && s.annotation != "" { |
| 218 | scopeSpecificArgs = append(scopeSpecificArgs, "--show-for-stub-purposes-annotation", s.annotation) |
| 219 | } |
| 220 | } |
Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 221 | |
Paul Duffin | d0b9fca | 2022-09-30 18:11:41 +0100 | [diff] [blame] | 222 | // By default, a library that can access a scope can also access the scope it extends. |
| 223 | if scope.canAccess == nil { |
| 224 | scope.canAccess = scope.extends |
| 225 | } |
| 226 | |
Paul Duffin | 15f34ef | 2020-07-20 18:04:44 +0100 | [diff] [blame] | 227 | // Escape any special characters in the arguments. This is needed because droidstubs |
| 228 | // passes these directly to the shell command. |
| 229 | scope.droidstubsArgs = proptools.ShellEscapeList(scopeSpecificArgs) |
Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 230 | |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 231 | return scope |
| 232 | } |
| 233 | |
Anton Hansson | 08f476b | 2021-04-07 15:32:19 +0100 | [diff] [blame] | 234 | func (scope *apiScope) stubsLibraryModuleNameSuffix() string { |
| 235 | return ".stubs" + scope.moduleSuffix |
| 236 | } |
| 237 | |
Jihoon Kang | fa4a90d | 2023-12-20 02:53:38 +0000 | [diff] [blame] | 238 | func (scope *apiScope) exportableStubsLibraryModuleNameSuffix() string { |
| 239 | return ".stubs.exportable" + scope.moduleSuffix |
| 240 | } |
| 241 | |
Jihoon Kang | 1c92c3e | 2023-03-23 17:44:51 +0000 | [diff] [blame] | 242 | func (scope *apiScope) apiLibraryModuleName(baseName string) string { |
| 243 | return scope.stubsLibraryModuleName(baseName) + ".from-text" |
| 244 | } |
| 245 | |
Jihoon Kang | 2261a82 | 2024-09-12 00:01:54 +0000 | [diff] [blame] | 246 | func (scope *apiScope) sourceStubsLibraryModuleName(baseName string) string { |
Jihoon Kang | 1147b31 | 2023-06-08 23:25:57 +0000 | [diff] [blame] | 247 | return scope.stubsLibraryModuleName(baseName) + ".from-source" |
| 248 | } |
| 249 | |
Jihoon Kang | fa4a90d | 2023-12-20 02:53:38 +0000 | [diff] [blame] | 250 | func (scope *apiScope) exportableSourceStubsLibraryModuleName(baseName string) string { |
| 251 | return scope.exportableStubsLibraryModuleName(baseName) + ".from-source" |
| 252 | } |
| 253 | |
Paul Duffin | c3091c8 | 2020-05-08 14:16:20 +0100 | [diff] [blame] | 254 | func (scope *apiScope) stubsLibraryModuleName(baseName string) string { |
Anton Hansson | 08f476b | 2021-04-07 15:32:19 +0100 | [diff] [blame] | 255 | return baseName + scope.stubsLibraryModuleNameSuffix() |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 256 | } |
| 257 | |
Jihoon Kang | fa4a90d | 2023-12-20 02:53:38 +0000 | [diff] [blame] | 258 | func (scope *apiScope) exportableStubsLibraryModuleName(baseName string) string { |
| 259 | return baseName + scope.exportableStubsLibraryModuleNameSuffix() |
| 260 | } |
| 261 | |
Paul Duffin | c878250 | 2020-04-29 20:45:27 +0100 | [diff] [blame] | 262 | func (scope *apiScope) stubsSourceModuleName(baseName string) string { |
Paul Duffin | dd9d074 | 2020-05-08 15:52:37 +0100 | [diff] [blame] | 263 | return baseName + ".stubs.source" + scope.moduleSuffix |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 264 | } |
| 265 | |
Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 266 | func (scope *apiScope) String() string { |
| 267 | return scope.name |
| 268 | } |
| 269 | |
Paul Duffin | 958806b | 2022-05-16 13:10:47 +0000 | [diff] [blame] | 270 | // snapshotRelativeDir returns the snapshot directory into which the files related to scopes will |
| 271 | // be stored. |
| 272 | func (scope *apiScope) snapshotRelativeDir() string { |
| 273 | return filepath.Join("sdk_library", scope.name) |
| 274 | } |
| 275 | |
| 276 | // snapshotRelativeCurrentApiTxtPath returns the snapshot path to the API .txt file for the named |
| 277 | // library. |
| 278 | func (scope *apiScope) snapshotRelativeCurrentApiTxtPath(name string) string { |
| 279 | return filepath.Join(scope.snapshotRelativeDir(), name+".txt") |
| 280 | } |
| 281 | |
| 282 | // snapshotRelativeRemovedApiTxtPath returns the snapshot path to the removed API .txt file for the |
| 283 | // named library. |
| 284 | func (scope *apiScope) snapshotRelativeRemovedApiTxtPath(name string) string { |
| 285 | return filepath.Join(scope.snapshotRelativeDir(), name+"-removed.txt") |
| 286 | } |
| 287 | |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 288 | type apiScopes []*apiScope |
| 289 | |
| 290 | func (scopes apiScopes) Strings(accessor func(*apiScope) string) []string { |
| 291 | var list []string |
| 292 | for _, scope := range scopes { |
| 293 | list = append(list, accessor(scope)) |
| 294 | } |
| 295 | return list |
| 296 | } |
| 297 | |
Jihoon Kang | a96a7b1 | 2023-09-20 23:43:32 +0000 | [diff] [blame] | 298 | // Method that maps the apiScopes properties to the index of each apiScopes elements. |
| 299 | // apiScopes property to be used as the key can be specified with the input accessor. |
| 300 | // Only a string property of apiScope can be used as the key of the map. |
| 301 | func (scopes apiScopes) MapToIndex(accessor func(*apiScope) string) map[string]int { |
| 302 | ret := make(map[string]int) |
| 303 | for i, scope := range scopes { |
| 304 | ret[accessor(scope)] = i |
| 305 | } |
| 306 | return ret |
| 307 | } |
| 308 | |
Jihoon Kang | 98aa8fa | 2024-06-07 11:06:57 +0000 | [diff] [blame] | 309 | func (scopes apiScopes) ConvertStubsLibraryExportableToEverything(name string) string { |
| 310 | for _, scope := range scopes { |
| 311 | if strings.HasSuffix(name, scope.exportableStubsLibraryModuleNameSuffix()) { |
| 312 | return strings.TrimSuffix(name, scope.exportableStubsLibraryModuleNameSuffix()) + |
| 313 | scope.stubsLibraryModuleNameSuffix() |
| 314 | } |
| 315 | } |
| 316 | return name |
| 317 | } |
| 318 | |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 319 | var ( |
Paul Duffin | 46dc45a | 2020-05-14 15:39:10 +0100 | [diff] [blame] | 320 | scopeByName = make(map[string]*apiScope) |
| 321 | allScopeNames []string |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 322 | apiScopePublic = initApiScope(&apiScope{ |
Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 323 | name: "public", |
| 324 | |
| 325 | // Public scope is enabled by default for both legacy and non-legacy modes. |
| 326 | legacyEnabledStatus: func(module *SdkLibrary) bool { |
| 327 | return true |
| 328 | }, |
| 329 | defaultEnabledStatus: true, |
| 330 | |
| 331 | scopeSpecificProperties: func(module *SdkLibrary) *ApiScopeProperties { |
| 332 | return &module.sdkLibraryProperties.Public |
| 333 | }, |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 334 | sdkVersion: "current", |
Jihoon Kang | 1c92c3e | 2023-03-23 17:44:51 +0000 | [diff] [blame] | 335 | kind: android.SdkPublic, |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 336 | }) |
| 337 | apiScopeSystem = initApiScope(&apiScope{ |
Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 338 | name: "system", |
| 339 | extends: apiScopePublic, |
| 340 | legacyEnabledStatus: (*SdkLibrary).generateTestAndSystemScopesByDefault, |
| 341 | scopeSpecificProperties: func(module *SdkLibrary) *ApiScopeProperties { |
| 342 | return &module.sdkLibraryProperties.System |
| 343 | }, |
Paul Duffin | 15f34ef | 2020-07-20 18:04:44 +0100 | [diff] [blame] | 344 | apiFilePrefix: "system-", |
| 345 | moduleSuffix: ".system", |
| 346 | sdkVersion: "system_current", |
| 347 | annotation: "android.annotation.SystemApi(client=android.annotation.SystemApi.Client.PRIVILEGED_APPS)", |
Jihoon Kang | 1c92c3e | 2023-03-23 17:44:51 +0000 | [diff] [blame] | 348 | kind: android.SdkSystem, |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 349 | }) |
| 350 | apiScopeTest = initApiScope(&apiScope{ |
Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 351 | name: "test", |
Anton Hansson | 4fe970f | 2020-10-09 10:16:49 +0100 | [diff] [blame] | 352 | extends: apiScopeSystem, |
Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 353 | legacyEnabledStatus: (*SdkLibrary).generateTestAndSystemScopesByDefault, |
| 354 | scopeSpecificProperties: func(module *SdkLibrary) *ApiScopeProperties { |
| 355 | return &module.sdkLibraryProperties.Test |
| 356 | }, |
Paul Duffin | 15f34ef | 2020-07-20 18:04:44 +0100 | [diff] [blame] | 357 | apiFilePrefix: "test-", |
| 358 | moduleSuffix: ".test", |
| 359 | sdkVersion: "test_current", |
| 360 | annotation: "android.annotation.TestApi", |
| 361 | unstable: true, |
Jihoon Kang | 1c92c3e | 2023-03-23 17:44:51 +0000 | [diff] [blame] | 362 | kind: android.SdkTest, |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 363 | }) |
Paul Duffin | 8f265b9 | 2020-04-28 14:13:56 +0100 | [diff] [blame] | 364 | apiScopeModuleLib = initApiScope(&apiScope{ |
Paul Duffin | 6b836ba | 2020-05-13 19:19:49 +0100 | [diff] [blame] | 365 | name: "module-lib", |
Paul Duffin | 8f265b9 | 2020-04-28 14:13:56 +0100 | [diff] [blame] | 366 | extends: apiScopeSystem, |
Paul Duffin | 0c5bae5 | 2020-06-02 13:00:08 +0100 | [diff] [blame] | 367 | // The module-lib scope is disabled by default in legacy mode. |
Paul Duffin | 8f265b9 | 2020-04-28 14:13:56 +0100 | [diff] [blame] | 368 | // |
| 369 | // Enabling this would break existing usages. |
| 370 | legacyEnabledStatus: func(module *SdkLibrary) bool { |
| 371 | return false |
| 372 | }, |
| 373 | scopeSpecificProperties: func(module *SdkLibrary) *ApiScopeProperties { |
| 374 | return &module.sdkLibraryProperties.Module_lib |
| 375 | }, |
| 376 | apiFilePrefix: "module-lib-", |
| 377 | moduleSuffix: ".module_lib", |
| 378 | sdkVersion: "module_current", |
Paul Duffin | 15f34ef | 2020-07-20 18:04:44 +0100 | [diff] [blame] | 379 | annotation: "android.annotation.SystemApi(client=android.annotation.SystemApi.Client.MODULE_LIBRARIES)", |
Jihoon Kang | 1c92c3e | 2023-03-23 17:44:51 +0000 | [diff] [blame] | 380 | kind: android.SdkModule, |
Paul Duffin | 8f265b9 | 2020-04-28 14:13:56 +0100 | [diff] [blame] | 381 | }) |
Paul Duffin | 0c5bae5 | 2020-06-02 13:00:08 +0100 | [diff] [blame] | 382 | apiScopeSystemServer = initApiScope(&apiScope{ |
| 383 | name: "system-server", |
| 384 | extends: apiScopePublic, |
Paul Duffin | d0b9fca | 2022-09-30 18:11:41 +0100 | [diff] [blame] | 385 | |
| 386 | // The system-server scope can access the module-lib scope. |
| 387 | // |
| 388 | // A module that provides a system-server API is appended to the standard bootclasspath that is |
| 389 | // used by the system server. So, it should be able to access module-lib APIs provided by |
| 390 | // libraries on the bootclasspath. |
| 391 | canAccess: apiScopeModuleLib, |
| 392 | |
Paul Duffin | 0c5bae5 | 2020-06-02 13:00:08 +0100 | [diff] [blame] | 393 | // The system-server scope is disabled by default in legacy mode. |
| 394 | // |
| 395 | // Enabling this would break existing usages. |
| 396 | legacyEnabledStatus: func(module *SdkLibrary) bool { |
| 397 | return false |
| 398 | }, |
| 399 | scopeSpecificProperties: func(module *SdkLibrary) *ApiScopeProperties { |
| 400 | return &module.sdkLibraryProperties.System_server |
| 401 | }, |
| 402 | apiFilePrefix: "system-server-", |
| 403 | moduleSuffix: ".system_server", |
| 404 | sdkVersion: "system_server_current", |
Paul Duffin | 15f34ef | 2020-07-20 18:04:44 +0100 | [diff] [blame] | 405 | annotation: "android.annotation.SystemApi(client=android.annotation.SystemApi.Client.SYSTEM_SERVER)", |
| 406 | extraArgs: []string{ |
| 407 | "--hide-annotation", "android.annotation.Hide", |
Paul Duffin | 0c5bae5 | 2020-06-02 13:00:08 +0100 | [diff] [blame] | 408 | // com.android.* classes are okay in this interface" |
Paul Duffin | 15f34ef | 2020-07-20 18:04:44 +0100 | [diff] [blame] | 409 | "--hide", "InternalClasses", |
Paul Duffin | 0c5bae5 | 2020-06-02 13:00:08 +0100 | [diff] [blame] | 410 | }, |
Jihoon Kang | 1c92c3e | 2023-03-23 17:44:51 +0000 | [diff] [blame] | 411 | kind: android.SdkSystemServer, |
Paul Duffin | 0c5bae5 | 2020-06-02 13:00:08 +0100 | [diff] [blame] | 412 | }) |
Jihoon Kang | 98aa8fa | 2024-06-07 11:06:57 +0000 | [diff] [blame] | 413 | AllApiScopes = apiScopes{ |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 414 | apiScopePublic, |
| 415 | apiScopeSystem, |
| 416 | apiScopeTest, |
Paul Duffin | 8f265b9 | 2020-04-28 14:13:56 +0100 | [diff] [blame] | 417 | apiScopeModuleLib, |
Paul Duffin | 0c5bae5 | 2020-06-02 13:00:08 +0100 | [diff] [blame] | 418 | apiScopeSystemServer, |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 419 | } |
Jihoon Kang | b0f4c02 | 2024-08-06 00:15:25 +0000 | [diff] [blame] | 420 | apiLibraryAdditionalProperties = map[string]string{ |
| 421 | "legacy.i18n.module.platform.api": "i18n.module.public.api.stubs.source.api.contribution", |
| 422 | "stable.i18n.module.platform.api": "i18n.module.public.api.stubs.source.api.contribution", |
| 423 | "conscrypt.module.platform.api": "conscrypt.module.public.api.stubs.source.api.contribution", |
Jihoon Kang | 0c705a4 | 2023-08-02 06:44:57 +0000 | [diff] [blame] | 424 | } |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 425 | ) |
| 426 | |
Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 427 | var ( |
| 428 | javaSdkLibrariesLock sync.Mutex |
| 429 | ) |
| 430 | |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 431 | // TODO: these are big features that are currently missing |
Jiyong Park | 1be9691 | 2018-05-28 18:02:19 +0900 | [diff] [blame] | 432 | // 1) disallowing linking to the runtime shared lib |
| 433 | // 2) HTML generation |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 434 | |
| 435 | func init() { |
Paul Duffin | 43dc1cc | 2019-12-19 11:18:54 +0000 | [diff] [blame] | 436 | RegisterSdkLibraryBuildComponents(android.InitRegistrationContext) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 437 | |
Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 438 | android.RegisterMakeVarsProvider(pctx, func(ctx android.MakeVarsContext) { |
| 439 | javaSdkLibraries := javaSdkLibraries(ctx.Config()) |
| 440 | sort.Strings(*javaSdkLibraries) |
| 441 | ctx.Strict("JAVA_SDK_LIBRARIES", strings.Join(*javaSdkLibraries, " ")) |
| 442 | }) |
Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 443 | |
| 444 | // Register sdk member types. |
Paul Duffin | 976b0e5 | 2021-04-27 23:20:26 +0100 | [diff] [blame] | 445 | android.RegisterSdkMemberType(javaSdkLibrarySdkMemberType) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 446 | } |
| 447 | |
Paul Duffin | 43dc1cc | 2019-12-19 11:18:54 +0000 | [diff] [blame] | 448 | func RegisterSdkLibraryBuildComponents(ctx android.RegistrationContext) { |
| 449 | ctx.RegisterModuleType("java_sdk_library", SdkLibraryFactory) |
| 450 | ctx.RegisterModuleType("java_sdk_library_import", sdkLibraryImportFactory) |
| 451 | } |
| 452 | |
Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 453 | // Properties associated with each api scope. |
| 454 | type ApiScopeProperties struct { |
| 455 | // Indicates whether the api surface is generated. |
| 456 | // |
| 457 | // If this is set for any scope then all scopes must explicitly specify if they |
| 458 | // are enabled. This is to prevent new usages from depending on legacy behavior. |
| 459 | // |
| 460 | // Otherwise, if this is not set for any scope then the default behavior is |
| 461 | // scope specific so please refer to the scope specific property documentation. |
| 462 | Enabled *bool |
Paul Duffin | 87a05a3 | 2020-05-12 11:50:28 +0100 | [diff] [blame] | 463 | |
| 464 | // The sdk_version to use for building the stubs. |
| 465 | // |
| 466 | // 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] | 467 | // |
Paul Duffin | 87a05a3 | 2020-05-12 11:50:28 +0100 | [diff] [blame] | 468 | // 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] | 469 | // will be none. This is used for java_sdk_library instances that are used |
| 470 | // to create stubs that contribute to the core_current sdk version. |
| 471 | // 2) Otherwise, it is assumed that this library extends but does not |
| 472 | // contribute directly to a specific sdk_version and so this uses the |
| 473 | // sdk_version appropriate for the api scope. e.g. public will use |
| 474 | // sdk_version: current, system will use sdk_version: system_current, etc. |
Paul Duffin | 87a05a3 | 2020-05-12 11:50:28 +0100 | [diff] [blame] | 475 | // |
| 476 | // This does not affect the sdk_version used for either generating the stubs source |
| 477 | // or the API file. They both have to use the same sdk_version as is used for |
| 478 | // compiling the implementation library. |
| 479 | Sdk_version *string |
Mark White | 9421c4c | 2023-08-10 00:07:03 +0000 | [diff] [blame] | 480 | |
| 481 | // Extra libs used when compiling stubs for this scope. |
| 482 | Libs []string |
Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 483 | } |
| 484 | |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 485 | type sdkLibraryProperties struct { |
Anton Hansson | f8ea372 | 2021-09-16 14:24:13 +0100 | [diff] [blame] | 486 | // List of source files that are needed to compile the API, but are not part of runtime library. |
| 487 | Api_srcs []string `android:"arch_variant"` |
| 488 | |
Paul Duffin | 5df7930 | 2020-05-16 15:52:12 +0100 | [diff] [blame] | 489 | // Visibility for impl library module. If not specified then defaults to the |
| 490 | // visibility property. |
| 491 | Impl_library_visibility []string |
| 492 | |
Paul Duffin | 4911a89 | 2020-04-29 23:35:13 +0100 | [diff] [blame] | 493 | // Visibility for stubs library modules. If not specified then defaults to the |
| 494 | // visibility property. |
| 495 | Stubs_library_visibility []string |
| 496 | |
| 497 | // Visibility for stubs source modules. If not specified then defaults to the |
| 498 | // visibility property. |
| 499 | Stubs_source_visibility []string |
| 500 | |
Anton Hansson | 7f66efa | 2020-10-08 14:47:23 +0100 | [diff] [blame] | 501 | // List of Java libraries that will be in the classpath when building the implementation lib |
| 502 | Impl_only_libs []string `android:"arch_variant"` |
| 503 | |
Paul Duffin | 77590a8 | 2022-04-28 14:13:30 +0000 | [diff] [blame] | 504 | // List of Java libraries that will included in the implementation lib. |
| 505 | Impl_only_static_libs []string `android:"arch_variant"` |
| 506 | |
Sundong Ahn | f043cf6 | 2018-06-25 16:04:37 +0900 | [diff] [blame] | 507 | // List of Java libraries that will be in the classpath when building stubs |
| 508 | Stub_only_libs []string `android:"arch_variant"` |
| 509 | |
Anton Hansson | dae54cd | 2021-04-21 16:30:10 +0100 | [diff] [blame] | 510 | // List of Java libraries that will included in stub libraries |
| 511 | Stub_only_static_libs []string `android:"arch_variant"` |
| 512 | |
Paul Duffin | 7a586d3 | 2019-12-30 17:09:34 +0000 | [diff] [blame] | 513 | // list of package names that will be documented and publicized as API. |
| 514 | // This allows the API to be restricted to a subset of the source files provided. |
| 515 | // If this is unspecified then all the source files will be treated as being part |
| 516 | // of the API. |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 517 | Api_packages []string |
| 518 | |
Paul Duffin | 749f98f | 2019-12-30 17:23:46 +0000 | [diff] [blame] | 519 | // the relative path to the directory containing the api specification files. |
| 520 | // Defaults to "api". |
| 521 | Api_dir *string |
| 522 | |
Paul Duffin | dfa131e | 2020-05-15 20:37:11 +0100 | [diff] [blame] | 523 | // Determines whether a runtime implementation library is built; defaults to false. |
| 524 | // |
| 525 | // 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] | 526 | // it is as if shared_library: false, was set. |
Paul Duffin | 43db9be | 2019-12-30 17:35:49 +0000 | [diff] [blame] | 527 | Api_only *bool |
| 528 | |
Paul Duffin | 1151247 | 2019-02-11 15:55:17 +0000 | [diff] [blame] | 529 | // local files that are used within user customized droiddoc options. |
| 530 | Droiddoc_option_files []string |
| 531 | |
Spandan Das | 93e9599 | 2021-07-29 18:26:39 +0000 | [diff] [blame] | 532 | // additional droiddoc options. |
Paul Duffin | 1151247 | 2019-02-11 15:55:17 +0000 | [diff] [blame] | 533 | // Available variables for substitution: |
| 534 | // |
| 535 | // $(location <label>): the path to the droiddoc_option_files with name <label> |
Sundong Ahn | dd567f9 | 2018-07-31 17:19:11 +0900 | [diff] [blame] | 536 | Droiddoc_options []string |
| 537 | |
Paul Duffin | e22c2ab | 2020-05-20 19:35:27 +0100 | [diff] [blame] | 538 | // is set to true, Metalava will allow framework SDK to contain annotations. |
| 539 | Annotations_enabled *bool |
| 540 | |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 541 | // a list of top-level directories containing files to merge qualifier annotations |
| 542 | // (i.e. those intended to be included in the stubs written) from. |
| 543 | Merge_annotations_dirs []string |
| 544 | |
| 545 | // a list of top-level directories containing Java stub files to merge show/hide annotations from. |
| 546 | Merge_inclusion_annotations_dirs []string |
| 547 | |
Paul Duffin | 4f5c1ef | 2020-11-19 14:53:43 +0000 | [diff] [blame] | 548 | // If set to true then don't create dist rules. |
| 549 | No_dist *bool |
Sundong Ahn | 80a87b3 | 2019-05-13 15:02:50 +0900 | [diff] [blame] | 550 | |
Paul Duffin | 3131025 | 2020-11-20 21:26:20 +0000 | [diff] [blame] | 551 | // The stem for the artifacts that are copied to the dist, if not specified |
| 552 | // then defaults to the base module name. |
| 553 | // |
| 554 | // For each scope the following artifacts are copied to the apistubs/<scope> |
| 555 | // directory in the dist. |
| 556 | // * stubs impl jar -> <dist-stem>.jar |
| 557 | // * API specification file -> api/<dist-stem>.txt |
| 558 | // * Removed API specification file -> api/<dist-stem>-removed.txt |
| 559 | // |
| 560 | // Also used to construct the name of the filegroup (created by prebuilt_apis) |
| 561 | // that references the latest released API and remove API specification files. |
| 562 | // * API specification filegroup -> <dist-stem>.api.<scope>.latest |
| 563 | // * Removed API specification filegroup -> <dist-stem>-removed.api.<scope>.latest |
Jaewoong Jung | 1a97ee0 | 2021-03-09 13:25:02 -0800 | [diff] [blame] | 564 | // * API incompatibilities baseline filegroup -> <dist-stem>-incompatibilities.api.<scope>.latest |
Paul Duffin | 3131025 | 2020-11-20 21:26:20 +0000 | [diff] [blame] | 565 | Dist_stem *string |
| 566 | |
Colin Cross | 986b69a | 2021-06-01 13:13:40 -0700 | [diff] [blame] | 567 | // 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] | 568 | // 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] | 569 | // in the public Android SDK. |
| 570 | Dist_group *string |
| 571 | |
Anton Hansson | dff2c78 | 2020-12-21 17:10:01 +0000 | [diff] [blame] | 572 | // A compatibility mode that allows historical API-tracking files to not exist. |
| 573 | // Do not use. |
| 574 | Unsafe_ignore_missing_latest_api bool |
| 575 | |
Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 576 | // indicates whether system and test apis should be generated. |
| 577 | Generate_system_and_test_apis bool `blueprint:"mutated"` |
| 578 | |
| 579 | // The properties specific to the public api scope |
| 580 | // |
| 581 | // Unless explicitly specified by using public.enabled the public api scope is |
| 582 | // enabled by default in both legacy and non-legacy mode. |
| 583 | Public ApiScopeProperties |
| 584 | |
| 585 | // The properties specific to the system api scope |
| 586 | // |
| 587 | // In legacy mode the system api scope is enabled by default when sdk_version |
| 588 | // is set to something other than "none". |
| 589 | // |
| 590 | // In non-legacy mode the system api scope is disabled by default. |
| 591 | System ApiScopeProperties |
| 592 | |
| 593 | // The properties specific to the test api scope |
| 594 | // |
| 595 | // In legacy mode the test api scope is enabled by default when sdk_version |
| 596 | // is set to something other than "none". |
| 597 | // |
| 598 | // In non-legacy mode the test api scope is disabled by default. |
| 599 | Test ApiScopeProperties |
Paul Duffin | 37e0b77 | 2019-12-30 17:20:10 +0000 | [diff] [blame] | 600 | |
Paul Duffin | 0c5bae5 | 2020-06-02 13:00:08 +0100 | [diff] [blame] | 601 | // The properties specific to the module-lib api scope |
Paul Duffin | 8f265b9 | 2020-04-28 14:13:56 +0100 | [diff] [blame] | 602 | // |
Zi Wang | b2179e3 | 2023-01-31 15:53:30 -0800 | [diff] [blame] | 603 | // Unless explicitly specified by using module_lib.enabled the module_lib api |
| 604 | // scope is disabled by default. |
Paul Duffin | 8f265b9 | 2020-04-28 14:13:56 +0100 | [diff] [blame] | 605 | Module_lib ApiScopeProperties |
| 606 | |
Paul Duffin | 0c5bae5 | 2020-06-02 13:00:08 +0100 | [diff] [blame] | 607 | // The properties specific to the system-server api scope |
| 608 | // |
Zi Wang | b2179e3 | 2023-01-31 15:53:30 -0800 | [diff] [blame] | 609 | // Unless explicitly specified by using system_server.enabled the |
| 610 | // system_server api scope is disabled by default. |
Paul Duffin | 0c5bae5 | 2020-06-02 13:00:08 +0100 | [diff] [blame] | 611 | System_server ApiScopeProperties |
| 612 | |
Jiyong Park | 932cdfe | 2020-05-28 00:19:53 +0900 | [diff] [blame] | 613 | // Determines if the stubs are preferred over the implementation library |
| 614 | // for linking, even when the client doesn't specify sdk_version. When this |
| 615 | // is set to true, such clients are provided with the widest API surface that |
| 616 | // this lib provides. Note however that this option doesn't affect the clients |
| 617 | // that are in the same APEX as this library. In that case, the clients are |
| 618 | // always linked with the implementation library. Default is false. |
| 619 | Default_to_stubs *bool |
| 620 | |
Paul Duffin | 160fe41 | 2020-05-10 19:32:20 +0100 | [diff] [blame] | 621 | // Properties related to api linting. |
| 622 | Api_lint struct { |
| 623 | // Enable api linting. |
| 624 | Enabled *bool |
Anton Hansson | fd1c0d2 | 2023-11-02 15:18:09 +0000 | [diff] [blame] | 625 | |
| 626 | // If API lint is enabled, this flag controls whether a set of legitimate lint errors |
| 627 | // are turned off. The default is true. |
| 628 | Legacy_errors_allowed *bool |
Paul Duffin | 160fe41 | 2020-05-10 19:32:20 +0100 | [diff] [blame] | 629 | } |
| 630 | |
Jihoon Kang | 6592e87 | 2023-12-19 01:13:16 +0000 | [diff] [blame] | 631 | // a list of aconfig_declarations module names that the stubs generated in this module |
| 632 | // depend on. |
| 633 | Aconfig_declarations []string |
| 634 | |
Jihoon Kang | 48e2ac9 | 2024-07-29 21:18:46 +0000 | [diff] [blame] | 635 | // Determines if the module generates the stubs from the api signature files |
| 636 | // instead of the source Java files. Defaults to true. |
| 637 | Build_from_text_stub *bool |
| 638 | |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 639 | // TODO: determines whether to create HTML doc or not |
Paul Duffin | e840995 | 2022-09-22 16:24:46 +0100 | [diff] [blame] | 640 | // Html_doc *bool |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 641 | } |
| 642 | |
Paul Duffin | 0f8faff | 2020-05-20 16:18:00 +0100 | [diff] [blame] | 643 | // Paths to outputs from java_sdk_library and java_sdk_library_import. |
| 644 | // |
| 645 | // Fields that are android.Paths are always set (during GenerateAndroidBuildActions). |
| 646 | // OptionalPaths are always set by java_sdk_library but may not be set by |
| 647 | // java_sdk_library_import as not all instances provide that information. |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 648 | type scopePaths struct { |
Paul Duffin | 0f8faff | 2020-05-20 16:18:00 +0100 | [diff] [blame] | 649 | // The path (represented as Paths for convenience when returning) to the stubs header jar. |
| 650 | // |
| 651 | // That is the jar that is created by turbine. |
| 652 | stubsHeaderPath android.Paths |
| 653 | |
| 654 | // The path (represented as Paths for convenience when returning) to the stubs implementation jar. |
| 655 | // |
| 656 | // This is not the implementation jar, it still only contains stubs. |
| 657 | stubsImplPath android.Paths |
| 658 | |
Paul Duffin | 1267d87 | 2021-04-16 17:21:36 +0100 | [diff] [blame] | 659 | // The dex jar for the stubs. |
| 660 | // |
| 661 | // This is not the implementation jar, it still only contains stubs. |
Martin Stjernholm | 8be1e6d | 2021-09-15 03:34:04 +0100 | [diff] [blame] | 662 | stubsDexJarPath OptionalDexJarPath |
Paul Duffin | 1267d87 | 2021-04-16 17:21:36 +0100 | [diff] [blame] | 663 | |
Jihoon Kang | bd09345 | 2023-12-26 19:08:01 +0000 | [diff] [blame] | 664 | // The exportable dex jar for the stubs. |
| 665 | // This is not the implementation jar, it still only contains stubs. |
| 666 | // Includes unflagged apis and flagged apis enabled by release configurations. |
| 667 | exportableStubsDexJarPath OptionalDexJarPath |
| 668 | |
Paul Duffin | 0f8faff | 2020-05-20 16:18:00 +0100 | [diff] [blame] | 669 | // The API specification file, e.g. system_current.txt. |
| 670 | currentApiFilePath android.OptionalPath |
| 671 | |
| 672 | // The specification of API elements removed since the last release. |
| 673 | removedApiFilePath android.OptionalPath |
| 674 | |
| 675 | // The stubs source jar. |
| 676 | stubsSrcJar android.OptionalPath |
Anton Hansson | d78eb76 | 2021-09-21 15:25:12 +0100 | [diff] [blame] | 677 | |
| 678 | // Extracted annotations. |
| 679 | annotationsZip android.OptionalPath |
Paul Duffin | 958806b | 2022-05-16 13:10:47 +0000 | [diff] [blame] | 680 | |
| 681 | // The path to the latest API file. |
Jihoon Kang | 5623e54 | 2024-01-31 23:27:26 +0000 | [diff] [blame] | 682 | latestApiPaths android.Paths |
Paul Duffin | 958806b | 2022-05-16 13:10:47 +0000 | [diff] [blame] | 683 | |
| 684 | // The path to the latest removed API file. |
Jihoon Kang | 5623e54 | 2024-01-31 23:27:26 +0000 | [diff] [blame] | 685 | latestRemovedApiPaths android.Paths |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 686 | } |
| 687 | |
Colin Cross | dcf71b2 | 2021-02-01 13:59:03 -0800 | [diff] [blame] | 688 | func (paths *scopePaths) extractStubsLibraryInfoFromDependency(ctx android.ModuleContext, dep android.Module) error { |
Colin Cross | 313aa54 | 2023-12-13 13:47:44 -0800 | [diff] [blame] | 689 | if lib, ok := android.OtherModuleProvider(ctx, dep, JavaInfoProvider); ok { |
Colin Cross | dcf71b2 | 2021-02-01 13:59:03 -0800 | [diff] [blame] | 690 | paths.stubsHeaderPath = lib.HeaderJars |
| 691 | paths.stubsImplPath = lib.ImplementationJars |
Paul Duffin | 1267d87 | 2021-04-16 17:21:36 +0100 | [diff] [blame] | 692 | |
| 693 | libDep := dep.(UsesLibraryDependency) |
Spandan Das | 59a4a2b | 2024-01-09 21:35:56 +0000 | [diff] [blame] | 694 | paths.stubsDexJarPath = libDep.DexJarBuildPath(ctx) |
Jihoon Kang | bd09345 | 2023-12-26 19:08:01 +0000 | [diff] [blame] | 695 | paths.exportableStubsDexJarPath = libDep.DexJarBuildPath(ctx) |
| 696 | return nil |
| 697 | } else { |
| 698 | return fmt.Errorf("expected module that has JavaInfoProvider, e.g. java_library") |
| 699 | } |
| 700 | } |
| 701 | |
| 702 | func (paths *scopePaths) extractEverythingStubsLibraryInfoFromDependency(ctx android.ModuleContext, dep android.Module) error { |
| 703 | if lib, ok := android.OtherModuleProvider(ctx, dep, JavaInfoProvider); ok { |
| 704 | paths.stubsHeaderPath = lib.HeaderJars |
Jihoon Kang | f55a5f7 | 2024-01-08 08:56:20 +0000 | [diff] [blame] | 705 | if !ctx.Config().ReleaseHiddenApiExportableStubs() { |
| 706 | paths.stubsImplPath = lib.ImplementationJars |
| 707 | } |
Jihoon Kang | bd09345 | 2023-12-26 19:08:01 +0000 | [diff] [blame] | 708 | |
| 709 | libDep := dep.(UsesLibraryDependency) |
| 710 | paths.stubsDexJarPath = libDep.DexJarBuildPath(ctx) |
| 711 | return nil |
| 712 | } else { |
| 713 | return fmt.Errorf("expected module that has JavaInfoProvider, e.g. java_library") |
| 714 | } |
| 715 | } |
| 716 | |
| 717 | func (paths *scopePaths) extractExportableStubsLibraryInfoFromDependency(ctx android.ModuleContext, dep android.Module) error { |
Jihoon Kang | f55a5f7 | 2024-01-08 08:56:20 +0000 | [diff] [blame] | 718 | if lib, ok := android.OtherModuleProvider(ctx, dep, JavaInfoProvider); ok { |
| 719 | if ctx.Config().ReleaseHiddenApiExportableStubs() { |
| 720 | paths.stubsImplPath = lib.ImplementationJars |
| 721 | } |
| 722 | |
Jihoon Kang | bd09345 | 2023-12-26 19:08:01 +0000 | [diff] [blame] | 723 | libDep := dep.(UsesLibraryDependency) |
| 724 | paths.exportableStubsDexJarPath = libDep.DexJarBuildPath(ctx) |
Paul Duffin | c878250 | 2020-04-29 20:45:27 +0100 | [diff] [blame] | 725 | return nil |
| 726 | } else { |
Colin Cross | dcf71b2 | 2021-02-01 13:59:03 -0800 | [diff] [blame] | 727 | return fmt.Errorf("expected module that has JavaInfoProvider, e.g. java_library") |
Paul Duffin | c878250 | 2020-04-29 20:45:27 +0100 | [diff] [blame] | 728 | } |
| 729 | } |
| 730 | |
Jihoon Kang | ee11328 | 2024-01-23 00:16:41 +0000 | [diff] [blame] | 731 | 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] | 732 | if apiStubsProvider, ok := dep.(ApiStubsProvider); ok { |
Jihoon Kang | ee11328 | 2024-01-23 00:16:41 +0000 | [diff] [blame] | 733 | err := action(apiStubsProvider) |
| 734 | if err != nil { |
| 735 | return err |
| 736 | } |
Jihoon Kang | f55a5f7 | 2024-01-08 08:56:20 +0000 | [diff] [blame] | 737 | return nil |
| 738 | } else { |
| 739 | return fmt.Errorf("expected module that implements ExportableApiStubsSrcProvider, e.g. droidstubs") |
| 740 | } |
| 741 | } |
| 742 | |
Jihoon Kang | ee11328 | 2024-01-23 00:16:41 +0000 | [diff] [blame] | 743 | 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] | 744 | if apiStubsProvider, ok := dep.(ApiStubsSrcProvider); ok { |
Jihoon Kang | ee11328 | 2024-01-23 00:16:41 +0000 | [diff] [blame] | 745 | err := action(apiStubsProvider) |
| 746 | if err != nil { |
| 747 | return err |
| 748 | } |
Paul Duffin | 0f8faff | 2020-05-20 16:18:00 +0100 | [diff] [blame] | 749 | return nil |
| 750 | } else { |
| 751 | return fmt.Errorf("expected module that implements ApiStubsSrcProvider, e.g. droidstubs") |
| 752 | } |
| 753 | } |
| 754 | |
Jihoon Kang | ee11328 | 2024-01-23 00:16:41 +0000 | [diff] [blame] | 755 | func (paths *scopePaths) extractApiInfoFromApiStubsProvider(provider ApiStubsProvider, stubsType StubsType) error { |
| 756 | var annotationsZip, currentApiFilePath, removedApiFilePath android.Path |
| 757 | annotationsZip, annotationsZipErr := provider.AnnotationsZip(stubsType) |
| 758 | currentApiFilePath, currentApiFilePathErr := provider.ApiFilePath(stubsType) |
| 759 | removedApiFilePath, removedApiFilePathErr := provider.RemovedApiFilePath(stubsType) |
Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 760 | |
Jihoon Kang | ee11328 | 2024-01-23 00:16:41 +0000 | [diff] [blame] | 761 | combinedError := errors.Join(annotationsZipErr, currentApiFilePathErr, removedApiFilePathErr) |
| 762 | |
| 763 | if combinedError == nil { |
| 764 | paths.annotationsZip = android.OptionalPathForPath(annotationsZip) |
| 765 | paths.currentApiFilePath = android.OptionalPathForPath(currentApiFilePath) |
| 766 | paths.removedApiFilePath = android.OptionalPathForPath(removedApiFilePath) |
| 767 | } |
| 768 | return combinedError |
Jihoon Kang | f55a5f7 | 2024-01-08 08:56:20 +0000 | [diff] [blame] | 769 | } |
| 770 | |
Jihoon Kang | ee11328 | 2024-01-23 00:16:41 +0000 | [diff] [blame] | 771 | func (paths *scopePaths) extractStubsSourceInfoFromApiStubsProviders(provider ApiStubsSrcProvider, stubsType StubsType) error { |
| 772 | stubsSrcJar, err := provider.StubsSrcJar(stubsType) |
| 773 | if err == nil { |
| 774 | paths.stubsSrcJar = android.OptionalPathForPath(stubsSrcJar) |
| 775 | } |
| 776 | return err |
Jihoon Kang | f55a5f7 | 2024-01-08 08:56:20 +0000 | [diff] [blame] | 777 | } |
| 778 | |
Colin Cross | dcf71b2 | 2021-02-01 13:59:03 -0800 | [diff] [blame] | 779 | func (paths *scopePaths) extractStubsSourceInfoFromDep(ctx android.ModuleContext, dep android.Module) error { |
Jihoon Kang | 2a26b13 | 2024-06-24 07:39:40 +0000 | [diff] [blame] | 780 | stubsType := Everything |
| 781 | if ctx.Config().ReleaseHiddenApiExportableStubs() { |
| 782 | stubsType = Exportable |
| 783 | } |
Jihoon Kang | ee11328 | 2024-01-23 00:16:41 +0000 | [diff] [blame] | 784 | return paths.treatDepAsApiStubsSrcProvider(dep, func(provider ApiStubsSrcProvider) error { |
Jihoon Kang | 2a26b13 | 2024-06-24 07:39:40 +0000 | [diff] [blame] | 785 | return paths.extractStubsSourceInfoFromApiStubsProviders(provider, stubsType) |
Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 786 | }) |
| 787 | } |
| 788 | |
Colin Cross | dcf71b2 | 2021-02-01 13:59:03 -0800 | [diff] [blame] | 789 | func (paths *scopePaths) extractStubsSourceAndApiInfoFromApiStubsProvider(ctx android.ModuleContext, dep android.Module) error { |
Jihoon Kang | 2a26b13 | 2024-06-24 07:39:40 +0000 | [diff] [blame] | 790 | stubsType := Everything |
Jihoon Kang | f55a5f7 | 2024-01-08 08:56:20 +0000 | [diff] [blame] | 791 | if ctx.Config().ReleaseHiddenApiExportableStubs() { |
Jihoon Kang | 2a26b13 | 2024-06-24 07:39:40 +0000 | [diff] [blame] | 792 | stubsType = Exportable |
Jihoon Kang | f55a5f7 | 2024-01-08 08:56:20 +0000 | [diff] [blame] | 793 | } |
Jihoon Kang | ee11328 | 2024-01-23 00:16:41 +0000 | [diff] [blame] | 794 | return paths.treatDepAsApiStubsProvider(dep, func(provider ApiStubsProvider) error { |
Jihoon Kang | 2a26b13 | 2024-06-24 07:39:40 +0000 | [diff] [blame] | 795 | extractApiInfoErr := paths.extractApiInfoFromApiStubsProvider(provider, stubsType) |
| 796 | extractStubsSourceInfoErr := paths.extractStubsSourceInfoFromApiStubsProviders(provider, stubsType) |
Jihoon Kang | ee11328 | 2024-01-23 00:16:41 +0000 | [diff] [blame] | 797 | return errors.Join(extractApiInfoErr, extractStubsSourceInfoErr) |
Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 798 | }) |
| 799 | } |
| 800 | |
Jihoon Kang | 5623e54 | 2024-01-31 23:27:26 +0000 | [diff] [blame] | 801 | func extractOutputPaths(dep android.Module) (android.Paths, error) { |
Paul Duffin | 958806b | 2022-05-16 13:10:47 +0000 | [diff] [blame] | 802 | var paths android.Paths |
| 803 | if sourceFileProducer, ok := dep.(android.SourceFileProducer); ok { |
| 804 | paths = sourceFileProducer.Srcs() |
Jihoon Kang | 5623e54 | 2024-01-31 23:27:26 +0000 | [diff] [blame] | 805 | return paths, nil |
Paul Duffin | 958806b | 2022-05-16 13:10:47 +0000 | [diff] [blame] | 806 | } else { |
Jihoon Kang | 5623e54 | 2024-01-31 23:27:26 +0000 | [diff] [blame] | 807 | return nil, fmt.Errorf("module %q does not produce source files", dep) |
Paul Duffin | 958806b | 2022-05-16 13:10:47 +0000 | [diff] [blame] | 808 | } |
Paul Duffin | 958806b | 2022-05-16 13:10:47 +0000 | [diff] [blame] | 809 | } |
| 810 | |
| 811 | func (paths *scopePaths) extractLatestApiPath(ctx android.ModuleContext, dep android.Module) error { |
Jihoon Kang | 5623e54 | 2024-01-31 23:27:26 +0000 | [diff] [blame] | 812 | outputPaths, err := extractOutputPaths(dep) |
| 813 | paths.latestApiPaths = outputPaths |
Paul Duffin | 958806b | 2022-05-16 13:10:47 +0000 | [diff] [blame] | 814 | return err |
| 815 | } |
| 816 | |
| 817 | func (paths *scopePaths) extractLatestRemovedApiPath(ctx android.ModuleContext, dep android.Module) error { |
Jihoon Kang | 5623e54 | 2024-01-31 23:27:26 +0000 | [diff] [blame] | 818 | outputPaths, err := extractOutputPaths(dep) |
| 819 | paths.latestRemovedApiPaths = outputPaths |
Paul Duffin | 958806b | 2022-05-16 13:10:47 +0000 | [diff] [blame] | 820 | return err |
| 821 | } |
| 822 | |
Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 823 | type commonToSdkLibraryAndImportProperties struct { |
Paul Duffin | dfa131e | 2020-05-15 20:37:11 +0100 | [diff] [blame] | 824 | // Specifies whether this module can be used as an Android shared library; defaults |
| 825 | // to true. |
| 826 | // |
| 827 | // An Android shared library is one that can be referenced in a <uses-library> element |
| 828 | // in an AndroidManifest.xml. |
| 829 | Shared_library *bool |
Paul Duffin | a2ae7e0 | 2020-09-11 11:55:00 +0100 | [diff] [blame] | 830 | |
| 831 | // Files containing information about supported java doc tags. |
| 832 | Doctag_files []string `android:"path"` |
Pedro Loureiro | 9956e5e | 2021-09-07 17:21:59 +0000 | [diff] [blame] | 833 | |
| 834 | // Signals that this shared library is part of the bootclasspath starting |
| 835 | // on the version indicated in this attribute. |
| 836 | // |
| 837 | // This will make platforms at this level and above to ignore |
| 838 | // <uses-library> tags with this library name because the library is already |
| 839 | // available |
| 840 | On_bootclasspath_since *string |
| 841 | |
| 842 | // Signals that this shared library was part of the bootclasspath before |
| 843 | // (but not including) the version indicated in this attribute. |
| 844 | // |
| 845 | // The system will automatically add a <uses-library> tag with this library to |
| 846 | // apps that target any SDK less than the version indicated in this attribute. |
| 847 | On_bootclasspath_before *string |
| 848 | |
| 849 | // Indicates that PackageManager should ignore this shared library if the |
| 850 | // platform is below the version indicated in this attribute. |
| 851 | // |
| 852 | // This means that the device won't recognise this library as installed. |
| 853 | Min_device_sdk *string |
| 854 | |
| 855 | // Indicates that PackageManager should ignore this shared library if the |
| 856 | // platform is above the version indicated in this attribute. |
| 857 | // |
| 858 | // This means that the device won't recognise this library as installed. |
| 859 | Max_device_sdk *string |
Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 860 | } |
| 861 | |
Paul Duffin | 71b33cc | 2021-06-23 11:39:47 +0100 | [diff] [blame] | 862 | // commonSdkLibraryAndImportModule defines the interface that must be provided by a module that |
| 863 | // embeds the commonToSdkLibraryAndImport struct. |
| 864 | type commonSdkLibraryAndImportModule interface { |
Paul Duffin | d796f6f | 2022-11-23 23:06:05 +0000 | [diff] [blame] | 865 | android.Module |
Paul Duffin | 71b33cc | 2021-06-23 11:39:47 +0100 | [diff] [blame] | 866 | |
Spandan Das | 23956d1 | 2024-01-19 00:22:22 +0000 | [diff] [blame] | 867 | // Returns the name of the root java_sdk_library that creates the child stub libraries |
| 868 | // This is the `name` as it appears in Android.bp, and not the name in Soong's build graph |
| 869 | // (with the prebuilt_ prefix) |
| 870 | // |
| 871 | // e.g. in the following java_sdk_library_import |
| 872 | // java_sdk_library_import { |
| 873 | // name: "framework-foo.v1", |
| 874 | // source_module_name: "framework-foo", |
| 875 | // } |
| 876 | // the values returned by |
| 877 | // 1. Name(): prebuilt_framework-foo.v1 # unique |
| 878 | // 2. BaseModuleName(): framework-foo # the source |
| 879 | // 3. RootLibraryName: framework-foo.v1 # the undecordated `name` from Android.bp |
| 880 | RootLibraryName() string |
| 881 | } |
| 882 | |
| 883 | func (m *SdkLibrary) RootLibraryName() string { |
| 884 | return m.BaseModuleName() |
| 885 | } |
| 886 | |
| 887 | func (m *SdkLibraryImport) RootLibraryName() string { |
| 888 | // m.BaseModuleName refers to the source of the import |
| 889 | // use moduleBase.Name to get the name of the module as it appears in the .bp file |
| 890 | return m.ModuleBase.Name() |
Paul Duffin | 71b33cc | 2021-06-23 11:39:47 +0100 | [diff] [blame] | 891 | } |
| 892 | |
Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 893 | // Common code between sdk library and sdk library import |
| 894 | type commonToSdkLibraryAndImport struct { |
Paul Duffin | 71b33cc | 2021-06-23 11:39:47 +0100 | [diff] [blame] | 895 | module commonSdkLibraryAndImportModule |
Paul Duffin | c3091c8 | 2020-05-08 14:16:20 +0100 | [diff] [blame] | 896 | |
Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 897 | scopePaths map[*apiScope]*scopePaths |
Paul Duffin | 1b1e806 | 2020-05-08 13:44:43 +0100 | [diff] [blame] | 898 | |
Paul Duffin | dfa131e | 2020-05-15 20:37:11 +0100 | [diff] [blame] | 899 | commonSdkLibraryProperties commonToSdkLibraryAndImportProperties |
Paul Duffin | 859fe96 | 2020-05-15 10:20:31 +0100 | [diff] [blame] | 900 | |
Paul Duffin | a2ae7e0 | 2020-09-11 11:55:00 +0100 | [diff] [blame] | 901 | // Paths to commonSdkLibraryProperties.Doctag_files |
| 902 | doctagPaths android.Paths |
| 903 | |
Paul Duffin | 859fe96 | 2020-05-15 10:20:31 +0100 | [diff] [blame] | 904 | // Functionality related to this being used as a component of a java_sdk_library. |
| 905 | EmbeddableSdkLibraryComponent |
Jihoon Kang | 8479dea | 2024-04-04 01:19:05 +0000 | [diff] [blame] | 906 | |
| 907 | // Path to the header jars of the implementation library |
| 908 | // This is non-empty only when api_only is false. |
| 909 | implLibraryHeaderJars android.Paths |
Jihoon Kang | a3a0546 | 2024-04-05 00:36:44 +0000 | [diff] [blame] | 910 | |
| 911 | // The reference to the implementation library created by the source module. |
| 912 | // Is nil if the source module does not exist. |
| 913 | implLibraryModule *Library |
Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 914 | } |
| 915 | |
Paul Duffin | 71b33cc | 2021-06-23 11:39:47 +0100 | [diff] [blame] | 916 | func (c *commonToSdkLibraryAndImport) initCommon(module commonSdkLibraryAndImportModule) { |
| 917 | c.module = module |
Paul Duffin | 1b1e806 | 2020-05-08 13:44:43 +0100 | [diff] [blame] | 918 | |
Paul Duffin | 71b33cc | 2021-06-23 11:39:47 +0100 | [diff] [blame] | 919 | module.AddProperties(&c.commonSdkLibraryProperties) |
Paul Duffin | 859fe96 | 2020-05-15 10:20:31 +0100 | [diff] [blame] | 920 | |
| 921 | // Initialize this as an sdk library component. |
Paul Duffin | 71b33cc | 2021-06-23 11:39:47 +0100 | [diff] [blame] | 922 | c.initSdkLibraryComponent(module) |
Paul Duffin | 1b1e806 | 2020-05-08 13:44:43 +0100 | [diff] [blame] | 923 | } |
| 924 | |
| 925 | func (c *commonToSdkLibraryAndImport) initCommonAfterDefaultsApplied(ctx android.DefaultableHookContext) bool { |
Spandan Das | 23956d1 | 2024-01-19 00:22:22 +0000 | [diff] [blame] | 926 | namePtr := proptools.StringPtr(c.module.RootLibraryName()) |
Paul Duffin | 3f0290e | 2021-06-30 18:25:36 +0100 | [diff] [blame] | 927 | c.sdkLibraryComponentProperties.SdkLibraryName = namePtr |
| 928 | |
Paul Duffin | dfa131e | 2020-05-15 20:37:11 +0100 | [diff] [blame] | 929 | // Only track this sdk library if this can be used as a shared library. |
| 930 | if c.sharedLibrary() { |
| 931 | // Use the name specified in the module definition as the owner. |
Paul Duffin | 3f0290e | 2021-06-30 18:25:36 +0100 | [diff] [blame] | 932 | c.sdkLibraryComponentProperties.SdkLibraryToImplicitlyTrack = namePtr |
Paul Duffin | dfa131e | 2020-05-15 20:37:11 +0100 | [diff] [blame] | 933 | } |
Paul Duffin | 859fe96 | 2020-05-15 10:20:31 +0100 | [diff] [blame] | 934 | |
Paul Duffin | 1b1e806 | 2020-05-08 13:44:43 +0100 | [diff] [blame] | 935 | return true |
Paul Duffin | c3091c8 | 2020-05-08 14:16:20 +0100 | [diff] [blame] | 936 | } |
| 937 | |
Paul Duffin | ea8f808 | 2021-06-24 13:25:57 +0100 | [diff] [blame] | 938 | // uniqueApexVariations provides common implementation of the ApexModule.UniqueApexVariations |
| 939 | // method. |
| 940 | func (c *commonToSdkLibraryAndImport) uniqueApexVariations() bool { |
| 941 | // A java_sdk_library that is a shared library produces an XML file that makes the shared library |
| 942 | // usable from an AndroidManifest.xml's <uses-library> entry. That XML file contains the name of |
| 943 | // the APEX and so it needs a unique variation per APEX. |
| 944 | return c.sharedLibrary() |
| 945 | } |
| 946 | |
Paul Duffin | a2ae7e0 | 2020-09-11 11:55:00 +0100 | [diff] [blame] | 947 | func (c *commonToSdkLibraryAndImport) generateCommonBuildActions(ctx android.ModuleContext) { |
| 948 | c.doctagPaths = android.PathsForModuleSrc(ctx, c.commonSdkLibraryProperties.Doctag_files) |
| 949 | } |
| 950 | |
Jihoon Kang | a3a0546 | 2024-04-05 00:36:44 +0000 | [diff] [blame] | 951 | func (c *commonToSdkLibraryAndImport) getImplLibraryModule() *Library { |
| 952 | return c.implLibraryModule |
| 953 | } |
| 954 | |
Paul Duffin | 46dc45a | 2020-05-14 15:39:10 +0100 | [diff] [blame] | 955 | // The component names for different outputs of the java_sdk_library. |
| 956 | // |
| 957 | // They are similar to the names used for the child modules it creates |
| 958 | const ( |
| 959 | stubsSourceComponentName = "stubs.source" |
| 960 | |
| 961 | apiTxtComponentName = "api.txt" |
| 962 | |
| 963 | removedApiTxtComponentName = "removed-api.txt" |
Anton Hansson | d78eb76 | 2021-09-21 15:25:12 +0100 | [diff] [blame] | 964 | |
| 965 | annotationsComponentName = "annotations.zip" |
Paul Duffin | 46dc45a | 2020-05-14 15:39:10 +0100 | [diff] [blame] | 966 | ) |
| 967 | |
mrziwang | 9f7b9f4 | 2024-07-10 12:18:06 -0700 | [diff] [blame] | 968 | func (module *commonToSdkLibraryAndImport) setOutputFiles(ctx android.ModuleContext) { |
| 969 | if module.doctagPaths != nil { |
| 970 | ctx.SetOutputFiles(module.doctagPaths, ".doctags") |
| 971 | } |
| 972 | for _, scopeName := range android.SortedKeys(scopeByName) { |
| 973 | paths := module.findScopePaths(scopeByName[scopeName]) |
| 974 | if paths == nil { |
| 975 | continue |
Paul Duffin | 46dc45a | 2020-05-14 15:39:10 +0100 | [diff] [blame] | 976 | } |
mrziwang | 9f7b9f4 | 2024-07-10 12:18:06 -0700 | [diff] [blame] | 977 | componentToOutput := map[string]android.OptionalPath{ |
| 978 | stubsSourceComponentName: paths.stubsSrcJar, |
| 979 | apiTxtComponentName: paths.currentApiFilePath, |
| 980 | removedApiTxtComponentName: paths.removedApiFilePath, |
| 981 | annotationsComponentName: paths.annotationsZip, |
| 982 | } |
| 983 | for _, component := range android.SortedKeys(componentToOutput) { |
| 984 | if componentToOutput[component].Valid() { |
| 985 | ctx.SetOutputFiles(android.Paths{componentToOutput[component].Path()}, "."+scopeName+"."+component) |
Paul Duffin | a2ae7e0 | 2020-09-11 11:55:00 +0100 | [diff] [blame] | 986 | } |
| 987 | } |
Paul Duffin | 46dc45a | 2020-05-14 15:39:10 +0100 | [diff] [blame] | 988 | } |
| 989 | } |
| 990 | |
Paul Duffin | 803a956 | 2020-05-20 11:52:25 +0100 | [diff] [blame] | 991 | func (c *commonToSdkLibraryAndImport) getScopePathsCreateIfNeeded(scope *apiScope) *scopePaths { |
Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 992 | if c.scopePaths == nil { |
| 993 | c.scopePaths = make(map[*apiScope]*scopePaths) |
| 994 | } |
| 995 | paths := c.scopePaths[scope] |
| 996 | if paths == nil { |
| 997 | paths = &scopePaths{} |
| 998 | c.scopePaths[scope] = paths |
| 999 | } |
| 1000 | |
| 1001 | return paths |
| 1002 | } |
| 1003 | |
Paul Duffin | 803a956 | 2020-05-20 11:52:25 +0100 | [diff] [blame] | 1004 | func (c *commonToSdkLibraryAndImport) findScopePaths(scope *apiScope) *scopePaths { |
| 1005 | if c.scopePaths == nil { |
| 1006 | return nil |
| 1007 | } |
| 1008 | |
| 1009 | return c.scopePaths[scope] |
| 1010 | } |
| 1011 | |
| 1012 | // If this does not support the requested api scope then find the closest available |
| 1013 | // scope it does support. Returns nil if no such scope is available. |
| 1014 | func (c *commonToSdkLibraryAndImport) findClosestScopePath(scope *apiScope) *scopePaths { |
Paul Duffin | d0b9fca | 2022-09-30 18:11:41 +0100 | [diff] [blame] | 1015 | for s := scope; s != nil; s = s.canAccess { |
Paul Duffin | 803a956 | 2020-05-20 11:52:25 +0100 | [diff] [blame] | 1016 | if paths := c.findScopePaths(s); paths != nil { |
| 1017 | return paths |
| 1018 | } |
| 1019 | } |
| 1020 | |
| 1021 | // This should never happen outside tests as public should be the base scope for every |
| 1022 | // scope and is enabled by default. |
| 1023 | return nil |
| 1024 | } |
| 1025 | |
Paul Duffin | 1267d87 | 2021-04-16 17:21:36 +0100 | [diff] [blame] | 1026 | // selectScopePaths returns the *scopePaths appropriate for the specific kind. |
| 1027 | // |
| 1028 | // If the module does not support the specific kind then it will return the *scopePaths for the |
| 1029 | // closest kind which is a subset of the requested kind. e.g. if requesting android.SdkModule then |
| 1030 | // it will return *scopePaths for android.SdkSystem if available or android.SdkPublic of not. |
| 1031 | func (c *commonToSdkLibraryAndImport) selectScopePaths(ctx android.BaseModuleContext, kind android.SdkKind) *scopePaths { |
Paul Duffin | 32cf58a | 2021-05-18 16:32:50 +0100 | [diff] [blame] | 1032 | apiScope := sdkKindToApiScope(kind) |
Paul Duffin | b05d429 | 2020-05-20 12:19:10 +0100 | [diff] [blame] | 1033 | |
Paul Duffin | 803a956 | 2020-05-20 11:52:25 +0100 | [diff] [blame] | 1034 | paths := c.findClosestScopePath(apiScope) |
| 1035 | if paths == nil { |
| 1036 | var scopes []string |
Jihoon Kang | 98aa8fa | 2024-06-07 11:06:57 +0000 | [diff] [blame] | 1037 | for _, s := range AllApiScopes { |
Paul Duffin | 803a956 | 2020-05-20 11:52:25 +0100 | [diff] [blame] | 1038 | if c.findScopePaths(s) != nil { |
| 1039 | scopes = append(scopes, s.name) |
| 1040 | } |
| 1041 | } |
Spandan Das | 23956d1 | 2024-01-19 00:22:22 +0000 | [diff] [blame] | 1042 | 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] | 1043 | return nil |
| 1044 | } |
| 1045 | |
Paul Duffin | 1267d87 | 2021-04-16 17:21:36 +0100 | [diff] [blame] | 1046 | return paths |
| 1047 | } |
| 1048 | |
Paul Duffin | 32cf58a | 2021-05-18 16:32:50 +0100 | [diff] [blame] | 1049 | // sdkKindToApiScope maps from android.SdkKind to apiScope. |
| 1050 | func sdkKindToApiScope(kind android.SdkKind) *apiScope { |
| 1051 | var apiScope *apiScope |
| 1052 | switch kind { |
| 1053 | case android.SdkSystem: |
| 1054 | apiScope = apiScopeSystem |
| 1055 | case android.SdkModule: |
| 1056 | apiScope = apiScopeModuleLib |
| 1057 | case android.SdkTest: |
| 1058 | apiScope = apiScopeTest |
| 1059 | case android.SdkSystemServer: |
| 1060 | apiScope = apiScopeSystemServer |
| 1061 | default: |
| 1062 | apiScope = apiScopePublic |
| 1063 | } |
| 1064 | return apiScope |
| 1065 | } |
| 1066 | |
Paul Duffin | 1267d87 | 2021-04-16 17:21:36 +0100 | [diff] [blame] | 1067 | // to satisfy SdkLibraryDependency interface |
Martin Stjernholm | 8be1e6d | 2021-09-15 03:34:04 +0100 | [diff] [blame] | 1068 | func (c *commonToSdkLibraryAndImport) SdkApiStubDexJar(ctx android.BaseModuleContext, kind android.SdkKind) OptionalDexJarPath { |
Paul Duffin | 1267d87 | 2021-04-16 17:21:36 +0100 | [diff] [blame] | 1069 | paths := c.selectScopePaths(ctx, kind) |
| 1070 | if paths == nil { |
Martin Stjernholm | 8be1e6d | 2021-09-15 03:34:04 +0100 | [diff] [blame] | 1071 | return makeUnsetDexJarPath() |
Paul Duffin | 1267d87 | 2021-04-16 17:21:36 +0100 | [diff] [blame] | 1072 | } |
| 1073 | |
| 1074 | return paths.stubsDexJarPath |
Paul Duffin | b05d429 | 2020-05-20 12:19:10 +0100 | [diff] [blame] | 1075 | } |
| 1076 | |
Paul Duffin | 32cf58a | 2021-05-18 16:32:50 +0100 | [diff] [blame] | 1077 | // to satisfy SdkLibraryDependency interface |
Jihoon Kang | bd09345 | 2023-12-26 19:08:01 +0000 | [diff] [blame] | 1078 | func (c *commonToSdkLibraryAndImport) SdkApiExportableStubDexJar(ctx android.BaseModuleContext, kind android.SdkKind) OptionalDexJarPath { |
| 1079 | paths := c.selectScopePaths(ctx, kind) |
| 1080 | if paths == nil { |
| 1081 | return makeUnsetDexJarPath() |
| 1082 | } |
| 1083 | |
| 1084 | return paths.exportableStubsDexJarPath |
| 1085 | } |
| 1086 | |
| 1087 | // to satisfy SdkLibraryDependency interface |
Paul Duffin | 32cf58a | 2021-05-18 16:32:50 +0100 | [diff] [blame] | 1088 | func (c *commonToSdkLibraryAndImport) SdkRemovedTxtFile(ctx android.BaseModuleContext, kind android.SdkKind) android.OptionalPath { |
| 1089 | apiScope := sdkKindToApiScope(kind) |
| 1090 | paths := c.findScopePaths(apiScope) |
| 1091 | if paths == nil { |
| 1092 | return android.OptionalPath{} |
| 1093 | } |
| 1094 | |
| 1095 | return paths.removedApiFilePath |
| 1096 | } |
| 1097 | |
Paul Duffin | 859fe96 | 2020-05-15 10:20:31 +0100 | [diff] [blame] | 1098 | func (c *commonToSdkLibraryAndImport) sdkComponentPropertiesForChildLibrary() interface{} { |
| 1099 | componentProps := &struct { |
Paul Duffin | 3f0290e | 2021-06-30 18:25:36 +0100 | [diff] [blame] | 1100 | SdkLibraryName *string |
Paul Duffin | 859fe96 | 2020-05-15 10:20:31 +0100 | [diff] [blame] | 1101 | SdkLibraryToImplicitlyTrack *string |
Paul Duffin | dfa131e | 2020-05-15 20:37:11 +0100 | [diff] [blame] | 1102 | }{} |
| 1103 | |
Spandan Das | 23956d1 | 2024-01-19 00:22:22 +0000 | [diff] [blame] | 1104 | namePtr := proptools.StringPtr(c.module.RootLibraryName()) |
Paul Duffin | 3f0290e | 2021-06-30 18:25:36 +0100 | [diff] [blame] | 1105 | componentProps.SdkLibraryName = namePtr |
| 1106 | |
Paul Duffin | dfa131e | 2020-05-15 20:37:11 +0100 | [diff] [blame] | 1107 | if c.sharedLibrary() { |
Paul Duffin | 859fe96 | 2020-05-15 10:20:31 +0100 | [diff] [blame] | 1108 | // Mark the stubs library as being components of this java_sdk_library so that |
| 1109 | // any app that includes code which depends (directly or indirectly) on the stubs |
| 1110 | // library will have the appropriate <uses-library> invocation inserted into its |
| 1111 | // manifest if necessary. |
Paul Duffin | 3f0290e | 2021-06-30 18:25:36 +0100 | [diff] [blame] | 1112 | componentProps.SdkLibraryToImplicitlyTrack = namePtr |
Paul Duffin | 859fe96 | 2020-05-15 10:20:31 +0100 | [diff] [blame] | 1113 | } |
| 1114 | |
| 1115 | return componentProps |
| 1116 | } |
| 1117 | |
Paul Duffin | dfa131e | 2020-05-15 20:37:11 +0100 | [diff] [blame] | 1118 | func (c *commonToSdkLibraryAndImport) sharedLibrary() bool { |
| 1119 | return proptools.BoolDefault(c.commonSdkLibraryProperties.Shared_library, true) |
| 1120 | } |
| 1121 | |
Paul Duffin | f4600f6 | 2021-05-13 22:34:45 +0100 | [diff] [blame] | 1122 | // Check if the stub libraries should be compiled for dex |
| 1123 | func (c *commonToSdkLibraryAndImport) stubLibrariesCompiledForDex() bool { |
| 1124 | // Always compile the dex file files for the stub libraries if they will be used on the |
| 1125 | // bootclasspath. |
| 1126 | return !c.sharedLibrary() |
| 1127 | } |
| 1128 | |
Paul Duffin | 859fe96 | 2020-05-15 10:20:31 +0100 | [diff] [blame] | 1129 | // Properties related to the use of a module as an component of a java_sdk_library. |
| 1130 | type SdkLibraryComponentProperties struct { |
Paul Duffin | 3f0290e | 2021-06-30 18:25:36 +0100 | [diff] [blame] | 1131 | // The name of the java_sdk_library/_import module. |
| 1132 | SdkLibraryName *string `blueprint:"mutated"` |
Paul Duffin | 859fe96 | 2020-05-15 10:20:31 +0100 | [diff] [blame] | 1133 | |
| 1134 | // The name of the java_sdk_library/_import to add to a <uses-library> entry |
| 1135 | // in the AndroidManifest.xml of any Android app that includes code that references |
| 1136 | // this module. If not set then no java_sdk_library/_import is tracked. |
| 1137 | SdkLibraryToImplicitlyTrack *string `blueprint:"mutated"` |
| 1138 | } |
| 1139 | |
| 1140 | // Structure to be embedded in a module struct that needs to support the |
| 1141 | // SdkLibraryComponentDependency interface. |
| 1142 | type EmbeddableSdkLibraryComponent struct { |
| 1143 | sdkLibraryComponentProperties SdkLibraryComponentProperties |
| 1144 | } |
| 1145 | |
Paul Duffin | 71b33cc | 2021-06-23 11:39:47 +0100 | [diff] [blame] | 1146 | func (e *EmbeddableSdkLibraryComponent) initSdkLibraryComponent(module android.Module) { |
| 1147 | module.AddProperties(&e.sdkLibraryComponentProperties) |
Paul Duffin | 859fe96 | 2020-05-15 10:20:31 +0100 | [diff] [blame] | 1148 | } |
| 1149 | |
| 1150 | // to satisfy SdkLibraryComponentDependency |
Paul Duffin | 3f0290e | 2021-06-30 18:25:36 +0100 | [diff] [blame] | 1151 | func (e *EmbeddableSdkLibraryComponent) SdkLibraryName() *string { |
| 1152 | return e.sdkLibraryComponentProperties.SdkLibraryName |
| 1153 | } |
| 1154 | |
| 1155 | // to satisfy SdkLibraryComponentDependency |
Ulya Trafimovich | 39b437b | 2020-09-23 16:42:35 +0100 | [diff] [blame] | 1156 | func (e *EmbeddableSdkLibraryComponent) OptionalSdkLibraryImplementation() *string { |
Ulya Trafimovich | 78645fb | 2021-07-16 15:29:25 +0100 | [diff] [blame] | 1157 | // For shared libraries, this is the same as the SDK library name. If a Java library or app |
| 1158 | // depends on a component library (e.g. a stub library) it still needs to know the name of the |
| 1159 | // run-time library and the corresponding module that provides the implementation. This name is |
| 1160 | // passed to manifest_fixer (to be added to AndroidManifest.xml) and added to CLC (to be used |
| 1161 | // in dexpreopt). |
| 1162 | // |
| 1163 | // For non-shared SDK (component or not) libraries this returns `nil`, as they are not |
| 1164 | // <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] | 1165 | return e.sdkLibraryComponentProperties.SdkLibraryToImplicitlyTrack |
| 1166 | } |
| 1167 | |
Paul Duffin | 859fe96 | 2020-05-15 10:20:31 +0100 | [diff] [blame] | 1168 | // Implemented by modules that are (or possibly could be) a component of a java_sdk_library |
| 1169 | // (including the java_sdk_library) itself. |
| 1170 | type SdkLibraryComponentDependency interface { |
Ulya Trafimovich | 31e444e | 2020-08-14 17:32:16 +0100 | [diff] [blame] | 1171 | UsesLibraryDependency |
| 1172 | |
Paul Duffin | 3f0290e | 2021-06-30 18:25:36 +0100 | [diff] [blame] | 1173 | // SdkLibraryName returns the name of the java_sdk_library/_import module. |
| 1174 | SdkLibraryName() *string |
| 1175 | |
Ulya Trafimovich | 39b437b | 2020-09-23 16:42:35 +0100 | [diff] [blame] | 1176 | // The name of the implementation library for the optional SDK library or nil, if there isn't one. |
| 1177 | OptionalSdkLibraryImplementation() *string |
Paul Duffin | 859fe96 | 2020-05-15 10:20:31 +0100 | [diff] [blame] | 1178 | } |
| 1179 | |
| 1180 | // Make sure that all the module types that are components of java_sdk_library/_import |
| 1181 | // and which can be referenced (directly or indirectly) from an android app implement |
| 1182 | // the SdkLibraryComponentDependency interface. |
| 1183 | var _ SdkLibraryComponentDependency = (*Library)(nil) |
| 1184 | var _ SdkLibraryComponentDependency = (*Import)(nil) |
| 1185 | var _ SdkLibraryComponentDependency = (*SdkLibrary)(nil) |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 1186 | var _ SdkLibraryComponentDependency = (*SdkLibraryImport)(nil) |
Paul Duffin | 859fe96 | 2020-05-15 10:20:31 +0100 | [diff] [blame] | 1187 | |
Paul Duffin | 32cf58a | 2021-05-18 16:32:50 +0100 | [diff] [blame] | 1188 | // 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] | 1189 | type SdkLibraryDependency interface { |
| 1190 | SdkLibraryComponentDependency |
| 1191 | |
Jihoon Kang | bd09345 | 2023-12-26 19:08:01 +0000 | [diff] [blame] | 1192 | // SdkApiStubDexJar returns the dex jar for the stubs for the prebuilt |
| 1193 | // java_sdk_library_import module. It is needed by the hiddenapi processing tool which |
| 1194 | // processes dex files. |
Martin Stjernholm | 8be1e6d | 2021-09-15 03:34:04 +0100 | [diff] [blame] | 1195 | SdkApiStubDexJar(ctx android.BaseModuleContext, kind android.SdkKind) OptionalDexJarPath |
Paul Duffin | f4600f6 | 2021-05-13 22:34:45 +0100 | [diff] [blame] | 1196 | |
Jihoon Kang | bd09345 | 2023-12-26 19:08:01 +0000 | [diff] [blame] | 1197 | // SdkApiExportableStubDexJar returns the exportable dex jar for the stubs for |
| 1198 | // java_sdk_library module. It is needed by the hiddenapi processing tool which processes |
| 1199 | // dex files. |
| 1200 | SdkApiExportableStubDexJar(ctx android.BaseModuleContext, kind android.SdkKind) OptionalDexJarPath |
| 1201 | |
Paul Duffin | 32cf58a | 2021-05-18 16:32:50 +0100 | [diff] [blame] | 1202 | // SdkRemovedTxtFile returns the optional path to the removed.txt file for the specified sdk kind. |
| 1203 | SdkRemovedTxtFile(ctx android.BaseModuleContext, kind android.SdkKind) android.OptionalPath |
| 1204 | |
Paul Duffin | f4600f6 | 2021-05-13 22:34:45 +0100 | [diff] [blame] | 1205 | // sharedLibrary returns true if this can be used as a shared library. |
| 1206 | sharedLibrary() bool |
Jihoon Kang | a3a0546 | 2024-04-05 00:36:44 +0000 | [diff] [blame] | 1207 | |
Jihoon Kang | 28c9657 | 2024-09-11 23:44:44 +0000 | [diff] [blame] | 1208 | // getImplLibraryModule returns the pointer to the implementation library submodule of this |
| 1209 | // sdk library. |
Jihoon Kang | a3a0546 | 2024-04-05 00:36:44 +0000 | [diff] [blame] | 1210 | getImplLibraryModule() *Library |
Paul Duffin | 859fe96 | 2020-05-15 10:20:31 +0100 | [diff] [blame] | 1211 | } |
| 1212 | |
Jihoon Kang | 28c9657 | 2024-09-11 23:44:44 +0000 | [diff] [blame] | 1213 | type SdkLibraryInfo struct { |
| 1214 | // GeneratingLibs is the names of the library modules that this sdk library |
| 1215 | // generates. Note that this only includes the name of the modules that other modules can |
| 1216 | // depend on, and is not a holistic list of generated modules. |
| 1217 | GeneratingLibs []string |
| 1218 | } |
| 1219 | |
| 1220 | var SdkLibraryInfoProvider = blueprint.NewProvider[SdkLibraryInfo]() |
| 1221 | |
| 1222 | func getGeneratingLibs(ctx android.ModuleContext, sdkVersion android.SdkSpec, sdkLibraryModuleName string, sdkInfo SdkLibraryInfo) []string { |
| 1223 | apiLevel := sdkVersion.ApiLevel |
| 1224 | if apiLevel.IsPreview() { |
| 1225 | return sdkInfo.GeneratingLibs |
| 1226 | } |
| 1227 | |
| 1228 | generatingPrebuilts := []string{} |
| 1229 | for _, apiScope := range AllApiScopes { |
| 1230 | scopePrebuiltModuleName := prebuiltApiModuleName("sdk", sdkLibraryModuleName, apiScope.name, apiLevel.String()) |
| 1231 | if ctx.OtherModuleExists(scopePrebuiltModuleName) { |
| 1232 | generatingPrebuilts = append(generatingPrebuilts, scopePrebuiltModuleName) |
| 1233 | } |
| 1234 | } |
| 1235 | return generatingPrebuilts |
| 1236 | } |
| 1237 | |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 1238 | type SdkLibrary struct { |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 1239 | Library |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1240 | |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 1241 | sdkLibraryProperties sdkLibraryProperties |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1242 | |
Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 1243 | // Map from api scope to the scope specific property structure. |
| 1244 | scopeToProperties map[*apiScope]*ApiScopeProperties |
| 1245 | |
Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 1246 | commonToSdkLibraryAndImport |
Jihoon Kang | a3a0546 | 2024-04-05 00:36:44 +0000 | [diff] [blame] | 1247 | |
| 1248 | builtInstalledForApex []dexpreopterInstall |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1249 | } |
| 1250 | |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 1251 | var _ SdkLibraryDependency = (*SdkLibrary)(nil) |
Colin Cross | 897d2ed | 2019-02-11 14:03:51 -0800 | [diff] [blame] | 1252 | |
Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 1253 | func (module *SdkLibrary) generateTestAndSystemScopesByDefault() bool { |
| 1254 | return module.sdkLibraryProperties.Generate_system_and_test_apis |
| 1255 | } |
| 1256 | |
Jihoon Kang | a3a0546 | 2024-04-05 00:36:44 +0000 | [diff] [blame] | 1257 | func (module *SdkLibrary) DexJarBuildPath(ctx android.ModuleErrorfContext) OptionalDexJarPath { |
| 1258 | if module.implLibraryModule != nil { |
| 1259 | return module.implLibraryModule.DexJarBuildPath(ctx) |
| 1260 | } |
| 1261 | return makeUnsetDexJarPath() |
| 1262 | } |
| 1263 | |
| 1264 | func (module *SdkLibrary) DexJarInstallPath() android.Path { |
| 1265 | if module.implLibraryModule != nil { |
| 1266 | return module.implLibraryModule.DexJarInstallPath() |
| 1267 | } |
| 1268 | return nil |
| 1269 | } |
| 1270 | |
Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 1271 | func (module *SdkLibrary) getGeneratedApiScopes(ctx android.EarlyModuleContext) apiScopes { |
| 1272 | // Check to see if any scopes have been explicitly enabled. If any have then all |
| 1273 | // must be. |
| 1274 | anyScopesExplicitlyEnabled := false |
Jihoon Kang | 98aa8fa | 2024-06-07 11:06:57 +0000 | [diff] [blame] | 1275 | for _, scope := range AllApiScopes { |
Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 1276 | scopeProperties := module.scopeToProperties[scope] |
| 1277 | if scopeProperties.Enabled != nil { |
| 1278 | anyScopesExplicitlyEnabled = true |
| 1279 | break |
| 1280 | } |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 1281 | } |
Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 1282 | |
| 1283 | var generatedScopes apiScopes |
| 1284 | enabledScopes := make(map[*apiScope]struct{}) |
Jihoon Kang | 98aa8fa | 2024-06-07 11:06:57 +0000 | [diff] [blame] | 1285 | for _, scope := range AllApiScopes { |
Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 1286 | scopeProperties := module.scopeToProperties[scope] |
| 1287 | // If any scopes are explicitly enabled then ignore the legacy enabled status. |
| 1288 | // This is to ensure that any new usages of this module type do not rely on legacy |
| 1289 | // behaviour. |
| 1290 | defaultEnabledStatus := false |
| 1291 | if anyScopesExplicitlyEnabled { |
| 1292 | defaultEnabledStatus = scope.defaultEnabledStatus |
| 1293 | } else { |
| 1294 | defaultEnabledStatus = scope.legacyEnabledStatus(module) |
| 1295 | } |
| 1296 | enabled := proptools.BoolDefault(scopeProperties.Enabled, defaultEnabledStatus) |
| 1297 | if enabled { |
| 1298 | enabledScopes[scope] = struct{}{} |
| 1299 | generatedScopes = append(generatedScopes, scope) |
| 1300 | } |
| 1301 | } |
| 1302 | |
| 1303 | // Now check to make sure that any scope that is extended by an enabled scope is also |
| 1304 | // enabled. |
Jihoon Kang | 98aa8fa | 2024-06-07 11:06:57 +0000 | [diff] [blame] | 1305 | for _, scope := range AllApiScopes { |
Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 1306 | if _, ok := enabledScopes[scope]; ok { |
| 1307 | extends := scope.extends |
| 1308 | if extends != nil { |
| 1309 | if _, ok := enabledScopes[extends]; !ok { |
| 1310 | ctx.ModuleErrorf("enabled api scope %q depends on disabled scope %q", scope, extends) |
| 1311 | } |
| 1312 | } |
| 1313 | } |
| 1314 | } |
| 1315 | |
| 1316 | return generatedScopes |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 1317 | } |
| 1318 | |
satayev | 758968a | 2021-12-06 11:42:40 +0000 | [diff] [blame] | 1319 | var _ android.ModuleWithMinSdkVersionCheck = (*SdkLibrary)(nil) |
| 1320 | |
satayev | 8f088b0 | 2021-12-06 11:40:46 +0000 | [diff] [blame] | 1321 | func (module *SdkLibrary) CheckMinSdkVersion(ctx android.ModuleContext) { |
Jihoon Kang | a3a0546 | 2024-04-05 00:36:44 +0000 | [diff] [blame] | 1322 | CheckMinSdkVersion(ctx, &module.Library) |
| 1323 | } |
| 1324 | |
| 1325 | func CheckMinSdkVersion(ctx android.ModuleContext, module *Library) { |
Spandan Das | 8c9ae7e | 2023-03-03 21:20:36 +0000 | [diff] [blame] | 1326 | android.CheckMinSdkVersion(ctx, module.MinSdkVersion(ctx), func(c android.ModuleContext, do android.PayloadDepsCallback) { |
satayev | 8f088b0 | 2021-12-06 11:40:46 +0000 | [diff] [blame] | 1327 | ctx.WalkDeps(func(child android.Module, parent android.Module) bool { |
| 1328 | isExternal := !module.depIsInSameApex(ctx, child) |
| 1329 | if am, ok := child.(android.ApexModule); ok { |
| 1330 | if !do(ctx, parent, am, isExternal) { |
| 1331 | return false |
| 1332 | } |
| 1333 | } |
| 1334 | return !isExternal |
| 1335 | }) |
| 1336 | }) |
| 1337 | } |
| 1338 | |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 1339 | type sdkLibraryComponentTag struct { |
| 1340 | blueprint.BaseDependencyTag |
| 1341 | name string |
| 1342 | } |
| 1343 | |
| 1344 | // Mark this tag so dependencies that use it are excluded from visibility enforcement. |
| 1345 | func (t sdkLibraryComponentTag) ExcludeFromVisibilityEnforcement() {} |
| 1346 | |
| 1347 | var xmlPermissionsFileTag = sdkLibraryComponentTag{name: "xml-permissions-file"} |
Paul Duffin | e74ac73 | 2020-02-06 13:51:46 +0000 | [diff] [blame] | 1348 | |
Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 1349 | func IsXmlPermissionsFileDepTag(depTag blueprint.DependencyTag) bool { |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 1350 | if dt, ok := depTag.(sdkLibraryComponentTag); ok { |
Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 1351 | return dt == xmlPermissionsFileTag |
| 1352 | } |
| 1353 | return false |
| 1354 | } |
| 1355 | |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 1356 | var implLibraryTag = sdkLibraryComponentTag{name: "impl-library"} |
Paul Duffin | 5df7930 | 2020-05-16 15:52:12 +0100 | [diff] [blame] | 1357 | |
Jeongik Cha | aaa6dcd | 2024-05-22 00:41:28 +0900 | [diff] [blame] | 1358 | var _ android.InstallNeededDependencyTag = sdkLibraryComponentTag{} |
| 1359 | |
Jihoon Kang | 46d66de | 2024-05-22 22:42:39 +0000 | [diff] [blame] | 1360 | // To satisfy the CopyDirectlyInAnyApexTag interface. Implementation library of the sdk library |
| 1361 | // in an apex is considered to be directly in the apex, as if it was listed in java_libs. |
| 1362 | func (t sdkLibraryComponentTag) CopyDirectlyInAnyApex() {} |
| 1363 | |
| 1364 | var _ android.CopyDirectlyInAnyApexTag = implLibraryTag |
| 1365 | |
Jeongik Cha | aaa6dcd | 2024-05-22 00:41:28 +0900 | [diff] [blame] | 1366 | func (t sdkLibraryComponentTag) InstallDepNeeded() bool { |
| 1367 | return t.name == "xml-permissions-file" || t.name == "impl-library" |
| 1368 | } |
| 1369 | |
Paul Duffin | 44f1d84 | 2020-06-26 20:17:02 +0100 | [diff] [blame] | 1370 | // Add the dependencies on the child modules in the component deps mutator. |
| 1371 | func (module *SdkLibrary) ComponentDepsMutator(ctx android.BottomUpMutatorContext) { |
Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 1372 | for _, apiScope := range module.getGeneratedApiScopes(ctx) { |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 1373 | // Add dependencies to the stubs library |
Spandan Das | 877f39d | 2023-03-29 16:19:51 +0000 | [diff] [blame] | 1374 | stubModuleName := module.stubsLibraryModuleName(apiScope) |
Jihoon Kang | bd09345 | 2023-12-26 19:08:01 +0000 | [diff] [blame] | 1375 | ctx.AddVariationDependencies(nil, apiScope.everythingStubsTag, stubModuleName) |
Jihoon Kang | 1147b31 | 2023-06-08 23:25:57 +0000 | [diff] [blame] | 1376 | |
Jihoon Kang | bd09345 | 2023-12-26 19:08:01 +0000 | [diff] [blame] | 1377 | exportableStubModuleName := module.exportableStubsLibraryModuleName(apiScope) |
| 1378 | ctx.AddVariationDependencies(nil, apiScope.exportableStubsTag, exportableStubModuleName) |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 1379 | |
Paul Duffin | 15f34ef | 2020-07-20 18:04:44 +0100 | [diff] [blame] | 1380 | // Add a dependency on the stubs source in order to access both stubs source and api information. |
Jihoon Kang | 96ce83b | 2024-09-23 22:09:44 +0000 | [diff] [blame^] | 1381 | ctx.AddVariationDependencies(nil, apiScope.stubsSourceAndApiTag, module.droidstubsModuleName(apiScope)) |
Paul Duffin | 958806b | 2022-05-16 13:10:47 +0000 | [diff] [blame] | 1382 | |
| 1383 | if module.compareAgainstLatestApi(apiScope) { |
| 1384 | // Add dependencies on the latest finalized version of the API .txt file. |
| 1385 | latestApiModuleName := module.latestApiModuleName(apiScope) |
| 1386 | ctx.AddDependency(module, apiScope.latestApiModuleTag, latestApiModuleName) |
| 1387 | |
| 1388 | // Add dependencies on the latest finalized version of the remove API .txt file. |
| 1389 | latestRemovedApiModuleName := module.latestRemovedApiModuleName(apiScope) |
| 1390 | ctx.AddDependency(module, apiScope.latestRemovedApiModuleTag, latestRemovedApiModuleName) |
| 1391 | } |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 1392 | } |
| 1393 | |
Paul Duffin | dfa131e | 2020-05-15 20:37:11 +0100 | [diff] [blame] | 1394 | if module.requiresRuntimeImplementationLibrary() { |
Paul Duffin | 5df7930 | 2020-05-16 15:52:12 +0100 | [diff] [blame] | 1395 | // Add dependency to the rule for generating the implementation library. |
| 1396 | ctx.AddDependency(module, implLibraryTag, module.implLibraryModuleName()) |
| 1397 | |
Paul Duffin | dfa131e | 2020-05-15 20:37:11 +0100 | [diff] [blame] | 1398 | if module.sharedLibrary() { |
| 1399 | // Add dependency to the rule for generating the xml permissions file |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 1400 | ctx.AddDependency(module, xmlPermissionsFileTag, module.xmlPermissionsModuleName()) |
Paul Duffin | dfa131e | 2020-05-15 20:37:11 +0100 | [diff] [blame] | 1401 | } |
Paul Duffin | 44f1d84 | 2020-06-26 20:17:02 +0100 | [diff] [blame] | 1402 | } |
| 1403 | } |
Paul Duffin | e74ac73 | 2020-02-06 13:51:46 +0000 | [diff] [blame] | 1404 | |
Paul Duffin | 44f1d84 | 2020-06-26 20:17:02 +0100 | [diff] [blame] | 1405 | // Add other dependencies as normal. |
| 1406 | func (module *SdkLibrary) DepsMutator(ctx android.BottomUpMutatorContext) { |
Jihoon Kang | e4a9017 | 2024-07-18 22:49:08 +0000 | [diff] [blame] | 1407 | // If the module does not create an implementation library or defaults to stubs, |
| 1408 | // mark the top level sdk library as stubs module as the module will provide stubs via |
| 1409 | // "magic" when listed as a dependency in the Android.bp files. |
| 1410 | notCreateImplLib := proptools.Bool(module.sdkLibraryProperties.Api_only) |
| 1411 | preferStubs := proptools.Bool(module.sdkLibraryProperties.Default_to_stubs) |
| 1412 | module.properties.Is_stubs_module = proptools.BoolPtr(notCreateImplLib || preferStubs) |
| 1413 | |
Anton Hansson | e77fccc | 2021-01-20 16:52:41 +0000 | [diff] [blame] | 1414 | var missingApiModules []string |
| 1415 | for _, apiScope := range module.getGeneratedApiScopes(ctx) { |
| 1416 | if apiScope.unstable { |
| 1417 | continue |
| 1418 | } |
Paul Duffin | 958806b | 2022-05-16 13:10:47 +0000 | [diff] [blame] | 1419 | if m := module.latestApiModuleName(apiScope); !ctx.OtherModuleExists(m) { |
Anton Hansson | e77fccc | 2021-01-20 16:52:41 +0000 | [diff] [blame] | 1420 | missingApiModules = append(missingApiModules, m) |
| 1421 | } |
Paul Duffin | 958806b | 2022-05-16 13:10:47 +0000 | [diff] [blame] | 1422 | if m := module.latestRemovedApiModuleName(apiScope); !ctx.OtherModuleExists(m) { |
Anton Hansson | e77fccc | 2021-01-20 16:52:41 +0000 | [diff] [blame] | 1423 | missingApiModules = append(missingApiModules, m) |
| 1424 | } |
Paul Duffin | 958806b | 2022-05-16 13:10:47 +0000 | [diff] [blame] | 1425 | if m := module.latestIncompatibilitiesModuleName(apiScope); !ctx.OtherModuleExists(m) { |
Jaewoong Jung | 1a97ee0 | 2021-03-09 13:25:02 -0800 | [diff] [blame] | 1426 | missingApiModules = append(missingApiModules, m) |
| 1427 | } |
Anton Hansson | e77fccc | 2021-01-20 16:52:41 +0000 | [diff] [blame] | 1428 | } |
| 1429 | if len(missingApiModules) != 0 && !module.sdkLibraryProperties.Unsafe_ignore_missing_latest_api { |
| 1430 | m := module.Name() + " is missing tracking files for previously released library versions.\n" |
| 1431 | m += "You need to do one of the following:\n" |
| 1432 | m += "- Add `unsafe_ignore_missing_latest_api: true` to your blueprint (to disable compat tracking)\n" |
| 1433 | m += "- Add a set of prebuilt txt files representing the last released version of this library for compat checking.\n" |
| 1434 | m += " (the current set of API files can be used as a seed for this compatibility tracking\n" |
| 1435 | m += "\n" |
| 1436 | m += "The following filegroup modules are missing:\n " |
| 1437 | m += strings.Join(missingApiModules, "\n ") + "\n" |
| 1438 | 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." |
| 1439 | ctx.ModuleErrorf(m) |
| 1440 | } |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1441 | } |
| 1442 | |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 1443 | func (module *SdkLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Spandan Das | 5ae65ee | 2024-04-16 22:03:26 +0000 | [diff] [blame] | 1444 | if disableSourceApexVariant(ctx) { |
| 1445 | // Prebuilts are active, do not create the installation rules for the source javalib. |
| 1446 | // Even though the source javalib is not used, we need to hide it to prevent duplicate installation rules. |
| 1447 | // TODO (b/331665856): Implement a principled solution for this. |
| 1448 | module.HideFromMake() |
| 1449 | } |
satayev | 8f088b0 | 2021-12-06 11:40:46 +0000 | [diff] [blame] | 1450 | |
Paul Duffin | a2ae7e0 | 2020-09-11 11:55:00 +0100 | [diff] [blame] | 1451 | module.generateCommonBuildActions(ctx) |
| 1452 | |
Jihoon Kang | a3a0546 | 2024-04-05 00:36:44 +0000 | [diff] [blame] | 1453 | module.stem = proptools.StringDefault(module.overridableProperties.Stem, ctx.ModuleName()) |
| 1454 | |
| 1455 | module.provideHiddenAPIPropertyInfo(ctx) |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 1456 | |
Paul Duffin | b97b157 | 2021-04-29 21:50:40 +0100 | [diff] [blame] | 1457 | // Collate the components exported by this module. All scope specific modules are exported but |
| 1458 | // the impl and xml component modules are not. |
| 1459 | exportedComponents := map[string]struct{}{} |
| 1460 | |
Sundong Ahn | 57368eb | 2018-07-06 11:20:23 +0900 | [diff] [blame] | 1461 | // 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] | 1462 | // 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] | 1463 | // the recorded paths will be returned depending on the link type of the caller. |
| 1464 | ctx.VisitDirectDeps(func(to android.Module) { |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1465 | tag := ctx.OtherModuleDependencyTag(to) |
| 1466 | |
Paul Duffin | c878250 | 2020-04-29 20:45:27 +0100 | [diff] [blame] | 1467 | // Extract information from any of the scope specific dependencies. |
| 1468 | if scopeTag, ok := tag.(scopeDependencyTag); ok { |
| 1469 | apiScope := scopeTag.apiScope |
Paul Duffin | 803a956 | 2020-05-20 11:52:25 +0100 | [diff] [blame] | 1470 | scopePaths := module.getScopePathsCreateIfNeeded(apiScope) |
Paul Duffin | c878250 | 2020-04-29 20:45:27 +0100 | [diff] [blame] | 1471 | |
| 1472 | // Extract information from the dependency. The exact information extracted |
| 1473 | // is determined by the nature of the dependency which is determined by the tag. |
| 1474 | scopeTag.extractDepInfo(ctx, to, scopePaths) |
Paul Duffin | b97b157 | 2021-04-29 21:50:40 +0100 | [diff] [blame] | 1475 | |
| 1476 | exportedComponents[ctx.OtherModuleName(to)] = struct{}{} |
Jihoon Kang | 4b9220a | 2024-08-22 22:11:04 +0000 | [diff] [blame] | 1477 | |
| 1478 | ctx.Phony(ctx.ModuleName(), scopePaths.stubsHeaderPath...) |
Sundong Ahn | 20e998b | 2018-07-24 11:19:26 +0900 | [diff] [blame] | 1479 | } |
Jihoon Kang | 8479dea | 2024-04-04 01:19:05 +0000 | [diff] [blame] | 1480 | |
| 1481 | if tag == implLibraryTag { |
| 1482 | if dep, ok := android.OtherModuleProvider(ctx, to, JavaInfoProvider); ok { |
| 1483 | module.implLibraryHeaderJars = append(module.implLibraryHeaderJars, dep.HeaderJars...) |
Jihoon Kang | a3a0546 | 2024-04-05 00:36:44 +0000 | [diff] [blame] | 1484 | module.implLibraryModule = to.(*Library) |
| 1485 | android.SetProvider(ctx, JavaInfoProvider, dep) |
Jihoon Kang | 8479dea | 2024-04-04 01:19:05 +0000 | [diff] [blame] | 1486 | } |
| 1487 | } |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1488 | }) |
Paul Duffin | b97b157 | 2021-04-29 21:50:40 +0100 | [diff] [blame] | 1489 | |
Jihoon Kang | a3a0546 | 2024-04-05 00:36:44 +0000 | [diff] [blame] | 1490 | apexInfo, _ := android.ModuleProvider(ctx, android.ApexInfoProvider) |
| 1491 | if !apexInfo.IsForPlatform() { |
| 1492 | module.hideApexVariantFromMake = true |
| 1493 | } |
| 1494 | |
| 1495 | if module.implLibraryModule != nil { |
| 1496 | if ctx.Device() { |
| 1497 | module.classesJarPaths = android.Paths{module.implLibraryModule.implementationJarFile} |
| 1498 | module.bootDexJarPath = module.implLibraryModule.bootDexJarPath |
| 1499 | module.uncompressDexState = module.implLibraryModule.uncompressDexState |
| 1500 | module.active = module.implLibraryModule.active |
| 1501 | } |
| 1502 | |
| 1503 | module.outputFile = module.implLibraryModule.outputFile |
| 1504 | module.dexJarFile = makeDexJarPathFromPath(module.implLibraryModule.dexJarFile.Path()) |
| 1505 | module.headerJarFile = module.implLibraryModule.headerJarFile |
| 1506 | module.implementationAndResourcesJar = module.implLibraryModule.implementationAndResourcesJar |
| 1507 | module.builtInstalledForApex = module.implLibraryModule.builtInstalledForApex |
| 1508 | module.dexpreopter.configPath = module.implLibraryModule.dexpreopter.configPath |
| 1509 | module.dexpreopter.outputProfilePathOnHost = module.implLibraryModule.dexpreopter.outputProfilePathOnHost |
| 1510 | |
Jihoon Kang | 34155e3 | 2024-05-20 19:08:49 +0000 | [diff] [blame] | 1511 | // Properties required for Library.AndroidMkEntries |
| 1512 | module.logtagsSrcs = module.implLibraryModule.logtagsSrcs |
| 1513 | module.dexpreopter.builtInstalled = module.implLibraryModule.dexpreopter.builtInstalled |
| 1514 | module.jacocoReportClassesFile = module.implLibraryModule.jacocoReportClassesFile |
| 1515 | module.dexer.proguardDictionary = module.implLibraryModule.dexer.proguardDictionary |
| 1516 | module.dexer.proguardUsageZip = module.implLibraryModule.dexer.proguardUsageZip |
| 1517 | module.linter.reports = module.implLibraryModule.linter.reports |
Jihoon Kang | 629e2a3 | 2024-06-25 20:47:49 +0000 | [diff] [blame] | 1518 | module.linter.outputs.depSets = module.implLibraryModule.LintDepSets() |
Jihoon Kang | 34155e3 | 2024-05-20 19:08:49 +0000 | [diff] [blame] | 1519 | |
Jihoon Kang | a3a0546 | 2024-04-05 00:36:44 +0000 | [diff] [blame] | 1520 | if !module.Host() { |
| 1521 | module.hostdexInstallFile = module.implLibraryModule.hostdexInstallFile |
| 1522 | } |
| 1523 | |
Colin Cross | a6182ab | 2024-08-21 10:47:44 -0700 | [diff] [blame] | 1524 | if installFilesInfo, ok := android.OtherModuleProvider(ctx, module.implLibraryModule, android.InstallFilesProvider); ok { |
| 1525 | if installFilesInfo.CheckbuildTarget != nil { |
| 1526 | ctx.CheckbuildFile(installFilesInfo.CheckbuildTarget) |
| 1527 | } |
| 1528 | } |
Jihoon Kang | a3a0546 | 2024-04-05 00:36:44 +0000 | [diff] [blame] | 1529 | android.SetProvider(ctx, blueprint.SrcsFileProviderKey, blueprint.SrcsFileProviderData{SrcPaths: module.implLibraryModule.uniqueSrcFiles.Strings()}) |
| 1530 | } |
| 1531 | |
Paul Duffin | b97b157 | 2021-04-29 21:50:40 +0100 | [diff] [blame] | 1532 | // 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] | 1533 | exportedComponentInfo := android.ExportedComponentsInfo{Components: android.SortedKeys(exportedComponents)} |
Colin Cross | 4021302 | 2023-12-13 15:19:49 -0800 | [diff] [blame] | 1534 | android.SetProvider(ctx, android.ExportedComponentsInfoProvider, exportedComponentInfo) |
Paul Duffin | 958806b | 2022-05-16 13:10:47 +0000 | [diff] [blame] | 1535 | |
| 1536 | // Provide additional information for inclusion in an sdk's generated .info file. |
| 1537 | additionalSdkInfo := map[string]interface{}{} |
| 1538 | additionalSdkInfo["dist_stem"] = module.distStem() |
Paul Duffin | e840995 | 2022-09-22 16:24:46 +0100 | [diff] [blame] | 1539 | baseModuleName := module.distStem() |
Paul Duffin | 958806b | 2022-05-16 13:10:47 +0000 | [diff] [blame] | 1540 | scopes := map[string]interface{}{} |
| 1541 | additionalSdkInfo["scopes"] = scopes |
| 1542 | for scope, scopePaths := range module.scopePaths { |
| 1543 | scopeInfo := map[string]interface{}{} |
| 1544 | scopes[scope.name] = scopeInfo |
| 1545 | scopeInfo["current_api"] = scope.snapshotRelativeCurrentApiTxtPath(baseModuleName) |
| 1546 | scopeInfo["removed_api"] = scope.snapshotRelativeRemovedApiTxtPath(baseModuleName) |
Jihoon Kang | 5623e54 | 2024-01-31 23:27:26 +0000 | [diff] [blame] | 1547 | if p := scopePaths.latestApiPaths; len(p) > 0 { |
| 1548 | // The last path in the list is the one that applies to this scope, the |
| 1549 | // preceding ones, if any, are for the scope(s) that it extends. |
| 1550 | scopeInfo["latest_api"] = p[len(p)-1].String() |
Paul Duffin | 958806b | 2022-05-16 13:10:47 +0000 | [diff] [blame] | 1551 | } |
Jihoon Kang | 5623e54 | 2024-01-31 23:27:26 +0000 | [diff] [blame] | 1552 | if p := scopePaths.latestRemovedApiPaths; len(p) > 0 { |
| 1553 | // The last path in the list is the one that applies to this scope, the |
| 1554 | // preceding ones, if any, are for the scope(s) that it extends. |
| 1555 | scopeInfo["latest_removed_api"] = p[len(p)-1].String() |
Paul Duffin | 958806b | 2022-05-16 13:10:47 +0000 | [diff] [blame] | 1556 | } |
| 1557 | } |
Colin Cross | 4021302 | 2023-12-13 15:19:49 -0800 | [diff] [blame] | 1558 | android.SetProvider(ctx, android.AdditionalSdkInfoProvider, android.AdditionalSdkInfo{additionalSdkInfo}) |
mrziwang | 9f7b9f4 | 2024-07-10 12:18:06 -0700 | [diff] [blame] | 1559 | module.setOutputFiles(ctx) |
Jihoon Kang | 28c9657 | 2024-09-11 23:44:44 +0000 | [diff] [blame] | 1560 | |
| 1561 | var generatingLibs []string |
| 1562 | for _, apiScope := range AllApiScopes { |
| 1563 | if _, ok := module.scopePaths[apiScope]; ok { |
| 1564 | generatingLibs = append(generatingLibs, module.stubsLibraryModuleName(apiScope)) |
| 1565 | } |
| 1566 | } |
| 1567 | |
mrziwang | 9f7b9f4 | 2024-07-10 12:18:06 -0700 | [diff] [blame] | 1568 | if module.requiresRuntimeImplementationLibrary() && module.implLibraryModule != nil { |
Jihoon Kang | 28c9657 | 2024-09-11 23:44:44 +0000 | [diff] [blame] | 1569 | generatingLibs = append(generatingLibs, module.implLibraryModuleName()) |
mrziwang | 9f7b9f4 | 2024-07-10 12:18:06 -0700 | [diff] [blame] | 1570 | setOutputFiles(ctx, module.implLibraryModule.Module) |
| 1571 | } |
Jihoon Kang | 28c9657 | 2024-09-11 23:44:44 +0000 | [diff] [blame] | 1572 | |
| 1573 | android.SetProvider(ctx, SdkLibraryInfoProvider, SdkLibraryInfo{ |
| 1574 | GeneratingLibs: generatingLibs, |
| 1575 | }) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1576 | } |
| 1577 | |
Jihoon Kang | a3a0546 | 2024-04-05 00:36:44 +0000 | [diff] [blame] | 1578 | func (module *SdkLibrary) BuiltInstalledForApex() []dexpreopterInstall { |
| 1579 | return module.builtInstalledForApex |
| 1580 | } |
| 1581 | |
Jiyong Park | 0b0e1b9 | 2019-12-03 13:24:29 +0900 | [diff] [blame] | 1582 | func (module *SdkLibrary) AndroidMkEntries() []android.AndroidMkEntries { |
Paul Duffin | dfa131e | 2020-05-15 20:37:11 +0100 | [diff] [blame] | 1583 | if !module.requiresRuntimeImplementationLibrary() { |
Paul Duffin | 43db9be | 2019-12-30 17:35:49 +0000 | [diff] [blame] | 1584 | return nil |
| 1585 | } |
Jiyong Park | 0b0e1b9 | 2019-12-03 13:24:29 +0900 | [diff] [blame] | 1586 | entriesList := module.Library.AndroidMkEntries() |
Jihoon Kang | a3a0546 | 2024-04-05 00:36:44 +0000 | [diff] [blame] | 1587 | entries := &entriesList[0] |
| 1588 | entries.Required = append(entries.Required, module.implLibraryModuleName()) |
Yo Chiang | 07d7507 | 2020-06-05 17:43:19 +0800 | [diff] [blame] | 1589 | if module.sharedLibrary() { |
Yo Chiang | 07d7507 | 2020-06-05 17:43:19 +0800 | [diff] [blame] | 1590 | entries.Required = append(entries.Required, module.xmlPermissionsModuleName()) |
| 1591 | } |
Jiyong Park | 0b0e1b9 | 2019-12-03 13:24:29 +0900 | [diff] [blame] | 1592 | return entriesList |
Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 1593 | } |
| 1594 | |
Anton Hansson | 5fd5d24 | 2020-03-27 19:43:19 +0000 | [diff] [blame] | 1595 | // The dist path of the stub artifacts |
| 1596 | func (module *SdkLibrary) apiDistPath(apiScope *apiScope) string { |
Colin Cross | f0eace9 | 2021-06-02 13:02:23 -0700 | [diff] [blame] | 1597 | return path.Join("apistubs", module.distGroup(), apiScope.name) |
Anton Hansson | 5fd5d24 | 2020-03-27 19:43:19 +0000 | [diff] [blame] | 1598 | } |
| 1599 | |
Paul Duffin | 12ceb46 | 2019-12-24 20:31:31 +0000 | [diff] [blame] | 1600 | // Get the sdk version for use when compiling the stubs library. |
Paul Duffin | 780c5f4 | 2020-05-12 15:52:55 +0100 | [diff] [blame] | 1601 | func (module *SdkLibrary) sdkVersionForStubsLibrary(mctx android.EarlyModuleContext, apiScope *apiScope) string { |
Paul Duffin | 87a05a3 | 2020-05-12 11:50:28 +0100 | [diff] [blame] | 1602 | scopeProperties := module.scopeToProperties[apiScope] |
| 1603 | if scopeProperties.Sdk_version != nil { |
| 1604 | return proptools.String(scopeProperties.Sdk_version) |
| 1605 | } |
| 1606 | |
Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 1607 | sdkDep := decodeSdkDep(mctx, android.SdkContext(&module.Library)) |
Paul Duffin | 12ceb46 | 2019-12-24 20:31:31 +0000 | [diff] [blame] | 1608 | if sdkDep.hasStandardLibs() { |
| 1609 | // 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] | 1610 | return apiScope.sdkVersion |
Paul Duffin | 12ceb46 | 2019-12-24 20:31:31 +0000 | [diff] [blame] | 1611 | } else { |
| 1612 | // Otherwise, use no system module. |
| 1613 | return "none" |
| 1614 | } |
| 1615 | } |
| 1616 | |
Paul Duffin | 3131025 | 2020-11-20 21:26:20 +0000 | [diff] [blame] | 1617 | func (module *SdkLibrary) distStem() string { |
| 1618 | return proptools.StringDefault(module.sdkLibraryProperties.Dist_stem, module.BaseModuleName()) |
| 1619 | } |
| 1620 | |
Colin Cross | 986b69a | 2021-06-01 13:13:40 -0700 | [diff] [blame] | 1621 | // distGroup returns the subdirectory of the dist path of the stub artifacts. |
| 1622 | func (module *SdkLibrary) distGroup() string { |
Colin Cross | 59b92bf | 2021-06-01 14:07:56 -0700 | [diff] [blame] | 1623 | return proptools.StringDefault(module.sdkLibraryProperties.Dist_group, "unknown") |
Colin Cross | 986b69a | 2021-06-01 13:13:40 -0700 | [diff] [blame] | 1624 | } |
| 1625 | |
Paul Duffin | 958806b | 2022-05-16 13:10:47 +0000 | [diff] [blame] | 1626 | func latestPrebuiltApiModuleName(name string, apiScope *apiScope) string { |
| 1627 | return PrebuiltApiModuleName(name, apiScope.name, "latest") |
| 1628 | } |
| 1629 | |
Jihoon Kang | 748a24d | 2024-03-20 21:29:39 +0000 | [diff] [blame] | 1630 | func latestPrebuiltApiCombinedModuleName(name string, apiScope *apiScope) string { |
| 1631 | return PrebuiltApiCombinedModuleName(name, apiScope.name, "latest") |
| 1632 | } |
| 1633 | |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 1634 | func (module *SdkLibrary) latestApiFilegroupName(apiScope *apiScope) string { |
Paul Duffin | 958806b | 2022-05-16 13:10:47 +0000 | [diff] [blame] | 1635 | return ":" + module.latestApiModuleName(apiScope) |
| 1636 | } |
| 1637 | |
| 1638 | func (module *SdkLibrary) latestApiModuleName(apiScope *apiScope) string { |
Jihoon Kang | 748a24d | 2024-03-20 21:29:39 +0000 | [diff] [blame] | 1639 | return latestPrebuiltApiCombinedModuleName(module.distStem(), apiScope) |
Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 1640 | } |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1641 | |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 1642 | func (module *SdkLibrary) latestRemovedApiFilegroupName(apiScope *apiScope) string { |
Paul Duffin | 958806b | 2022-05-16 13:10:47 +0000 | [diff] [blame] | 1643 | return ":" + module.latestRemovedApiModuleName(apiScope) |
| 1644 | } |
| 1645 | |
| 1646 | func (module *SdkLibrary) latestRemovedApiModuleName(apiScope *apiScope) string { |
Jihoon Kang | 748a24d | 2024-03-20 21:29:39 +0000 | [diff] [blame] | 1647 | return latestPrebuiltApiCombinedModuleName(module.distStem()+"-removed", apiScope) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1648 | } |
| 1649 | |
Jaewoong Jung | 1a97ee0 | 2021-03-09 13:25:02 -0800 | [diff] [blame] | 1650 | func (module *SdkLibrary) latestIncompatibilitiesFilegroupName(apiScope *apiScope) string { |
Paul Duffin | 958806b | 2022-05-16 13:10:47 +0000 | [diff] [blame] | 1651 | return ":" + module.latestIncompatibilitiesModuleName(apiScope) |
| 1652 | } |
| 1653 | |
| 1654 | func (module *SdkLibrary) latestIncompatibilitiesModuleName(apiScope *apiScope) string { |
| 1655 | return latestPrebuiltApiModuleName(module.distStem()+"-incompatibilities", apiScope) |
Jaewoong Jung | 1a97ee0 | 2021-03-09 13:25:02 -0800 | [diff] [blame] | 1656 | } |
| 1657 | |
Jihoon Kang | 0c705a4 | 2023-08-02 06:44:57 +0000 | [diff] [blame] | 1658 | // The listed modules' stubs contents do not match the corresponding txt files, |
| 1659 | // but require additional api contributions to generate the full stubs. |
| 1660 | // This method returns the name of the additional api contribution module |
| 1661 | // for corresponding sdk_library modules. |
| 1662 | func (module *SdkLibrary) apiLibraryAdditionalApiContribution() string { |
| 1663 | if val, ok := apiLibraryAdditionalProperties[module.Name()]; ok { |
Jihoon Kang | b0f4c02 | 2024-08-06 00:15:25 +0000 | [diff] [blame] | 1664 | return val |
Jihoon Kang | 0c705a4 | 2023-08-02 06:44:57 +0000 | [diff] [blame] | 1665 | } |
| 1666 | return "" |
| 1667 | } |
| 1668 | |
Anton Hansson | 944e77d | 2020-08-19 11:40:22 +0100 | [diff] [blame] | 1669 | func childModuleVisibility(childVisibility []string) []string { |
| 1670 | if childVisibility == nil { |
| 1671 | // No child visibility set. The child will use the visibility of the sdk_library. |
| 1672 | return nil |
| 1673 | } |
| 1674 | |
| 1675 | // Prepend an override to ignore the sdk_library's visibility, and rely on the child visibility. |
| 1676 | var visibility []string |
| 1677 | visibility = append(visibility, "//visibility:override") |
| 1678 | visibility = append(visibility, childVisibility...) |
| 1679 | return visibility |
| 1680 | } |
| 1681 | |
Paul Duffin | 958806b | 2022-05-16 13:10:47 +0000 | [diff] [blame] | 1682 | func (module *SdkLibrary) compareAgainstLatestApi(apiScope *apiScope) bool { |
| 1683 | return !(apiScope.unstable || module.sdkLibraryProperties.Unsafe_ignore_missing_latest_api) |
| 1684 | } |
| 1685 | |
Paul Duffin | ea8f808 | 2021-06-24 13:25:57 +0100 | [diff] [blame] | 1686 | // Implements android.ApexModule |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 1687 | func (module *SdkLibrary) DepIsInSameApex(mctx android.BaseModuleContext, dep android.Module) bool { |
| 1688 | depTag := mctx.OtherModuleDependencyTag(dep) |
| 1689 | if depTag == xmlPermissionsFileTag { |
| 1690 | return true |
| 1691 | } |
Jihoon Kang | a3a0546 | 2024-04-05 00:36:44 +0000 | [diff] [blame] | 1692 | if dep.Name() == module.implLibraryModuleName() { |
| 1693 | return true |
| 1694 | } |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 1695 | return module.Library.DepIsInSameApex(mctx, dep) |
| 1696 | } |
| 1697 | |
Paul Duffin | ea8f808 | 2021-06-24 13:25:57 +0100 | [diff] [blame] | 1698 | // Implements android.ApexModule |
| 1699 | func (module *SdkLibrary) UniqueApexVariations() bool { |
| 1700 | return module.uniqueApexVariations() |
| 1701 | } |
| 1702 | |
Jihoon Kang | b0f4c02 | 2024-08-06 00:15:25 +0000 | [diff] [blame] | 1703 | func (module *SdkLibrary) ModuleBuildFromTextStubs() bool { |
| 1704 | return proptools.BoolDefault(module.sdkLibraryProperties.Build_from_text_stub, true) |
Jihoon Kang | 80456fd | 2023-11-15 19:22:14 +0000 | [diff] [blame] | 1705 | } |
| 1706 | |
Colin Cross | 571cccf | 2019-02-04 11:22:08 -0800 | [diff] [blame] | 1707 | var javaSdkLibrariesKey = android.NewOnceKey("javaSdkLibraries") |
| 1708 | |
Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 1709 | func javaSdkLibraries(config android.Config) *[]string { |
Colin Cross | 571cccf | 2019-02-04 11:22:08 -0800 | [diff] [blame] | 1710 | return config.Once(javaSdkLibrariesKey, func() interface{} { |
Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 1711 | return &[]string{} |
| 1712 | }).(*[]string) |
| 1713 | } |
| 1714 | |
Paul Duffin | 749f98f | 2019-12-30 17:23:46 +0000 | [diff] [blame] | 1715 | func (module *SdkLibrary) getApiDir() string { |
| 1716 | return proptools.StringDefault(module.sdkLibraryProperties.Api_dir, "api") |
| 1717 | } |
| 1718 | |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1719 | // For a java_sdk_library module, create internal modules for stubs, docs, |
| 1720 | // runtime libs and xml file. If requested, the stubs and docs are created twice |
| 1721 | // once for public API level and once for system API level |
Paul Duffin | f022920 | 2020-04-29 16:47:28 +0100 | [diff] [blame] | 1722 | func (module *SdkLibrary) CreateInternalModules(mctx android.DefaultableHookContext) { |
Paul Duffin | a18abc2 | 2020-05-16 18:54:24 +0100 | [diff] [blame] | 1723 | if len(module.properties.Srcs) == 0 { |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 1724 | mctx.PropertyErrorf("srcs", "java_sdk_library must specify srcs") |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 1725 | return |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 1726 | } |
| 1727 | |
Paul Duffin | 37e0b77 | 2019-12-30 17:20:10 +0000 | [diff] [blame] | 1728 | // 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] | 1729 | // then assume it provides both system and test apis. |
Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 1730 | sdkDep := decodeSdkDep(mctx, android.SdkContext(&module.Library)) |
Paul Duffin | 37e0b77 | 2019-12-30 17:20:10 +0000 | [diff] [blame] | 1731 | hasSystemAndTestApis := sdkDep.hasStandardLibs() |
Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 1732 | module.sdkLibraryProperties.Generate_system_and_test_apis = hasSystemAndTestApis |
Paul Duffin | 4f5c1ef | 2020-11-19 14:53:43 +0000 | [diff] [blame] | 1733 | |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 1734 | missingCurrentApi := false |
Inseob Kim | 8098faa | 2019-03-18 10:19:51 +0900 | [diff] [blame] | 1735 | |
Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 1736 | generatedScopes := module.getGeneratedApiScopes(mctx) |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 1737 | |
Paul Duffin | 749f98f | 2019-12-30 17:23:46 +0000 | [diff] [blame] | 1738 | apiDir := module.getApiDir() |
Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 1739 | for _, scope := range generatedScopes { |
Inseob Kim | 8098faa | 2019-03-18 10:19:51 +0900 | [diff] [blame] | 1740 | for _, api := range []string{"current.txt", "removed.txt"} { |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 1741 | path := path.Join(mctx.ModuleDir(), apiDir, scope.apiFilePrefix+api) |
Inseob Kim | 8098faa | 2019-03-18 10:19:51 +0900 | [diff] [blame] | 1742 | p := android.ExistentPathForSource(mctx, path) |
| 1743 | if !p.Valid() { |
Colin Cross | 18f840c | 2021-05-20 17:56:54 -0700 | [diff] [blame] | 1744 | if mctx.Config().AllowMissingDependencies() { |
| 1745 | mctx.AddMissingDependencies([]string{path}) |
| 1746 | } else { |
| 1747 | mctx.ModuleErrorf("Current api file %#v doesn't exist", path) |
| 1748 | missingCurrentApi = true |
| 1749 | } |
Inseob Kim | 8098faa | 2019-03-18 10:19:51 +0900 | [diff] [blame] | 1750 | } |
| 1751 | } |
| 1752 | } |
| 1753 | |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 1754 | if missingCurrentApi { |
Inseob Kim | 8098faa | 2019-03-18 10:19:51 +0900 | [diff] [blame] | 1755 | script := "build/soong/scripts/gen-java-current-api-files.sh" |
| 1756 | p := android.ExistentPathForSource(mctx, script) |
| 1757 | |
| 1758 | if !p.Valid() { |
| 1759 | panic(fmt.Sprintf("script file %s doesn't exist", script)) |
| 1760 | } |
| 1761 | |
| 1762 | mctx.ModuleErrorf("One or more current api files are missing. "+ |
| 1763 | "You can update them by:\n"+ |
Paul Duffin | 37e0b77 | 2019-12-30 17:20:10 +0000 | [diff] [blame] | 1764 | "%s %q %s && m update-api", |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 1765 | script, filepath.Join(mctx.ModuleDir(), apiDir), |
Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 1766 | strings.Join(generatedScopes.Strings(func(s *apiScope) string { return s.apiFilePrefix }), " ")) |
Inseob Kim | 8098faa | 2019-03-18 10:19:51 +0900 | [diff] [blame] | 1767 | return |
| 1768 | } |
| 1769 | |
Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 1770 | for _, scope := range generatedScopes { |
Paul Duffin | 15f34ef | 2020-07-20 18:04:44 +0100 | [diff] [blame] | 1771 | // Use the stubs source name for legacy reasons. |
Jihoon Kang | 96ce83b | 2024-09-23 22:09:44 +0000 | [diff] [blame^] | 1772 | module.createDroidstubs(mctx, scope, module.droidstubsModuleName(scope), scope.droidstubsArgs) |
Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 1773 | |
Jihoon Kang | 96ce83b | 2024-09-23 22:09:44 +0000 | [diff] [blame^] | 1774 | module.createFromSourceStubsLibrary(mctx, scope) |
| 1775 | module.createExportableFromSourceStubsLibrary(mctx, scope) |
Jihoon Kang | 1c92c3e | 2023-03-23 17:44:51 +0000 | [diff] [blame] | 1776 | |
Jihoon Kang | b0f4c02 | 2024-08-06 00:15:25 +0000 | [diff] [blame] | 1777 | if mctx.Config().BuildFromTextStub() && module.ModuleBuildFromTextStubs() { |
| 1778 | module.createApiLibrary(mctx, scope) |
Jihoon Kang | 0c705a4 | 2023-08-02 06:44:57 +0000 | [diff] [blame] | 1779 | } |
Jihoon Kang | b0f4c02 | 2024-08-06 00:15:25 +0000 | [diff] [blame] | 1780 | module.createTopLevelStubsLibrary(mctx, scope) |
Jihoon Kang | fa4a90d | 2023-12-20 02:53:38 +0000 | [diff] [blame] | 1781 | module.createTopLevelExportableStubsLibrary(mctx, scope) |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 1782 | } |
| 1783 | |
Paul Duffin | dfa131e | 2020-05-15 20:37:11 +0100 | [diff] [blame] | 1784 | if module.requiresRuntimeImplementationLibrary() { |
Paul Duffin | 5df7930 | 2020-05-16 15:52:12 +0100 | [diff] [blame] | 1785 | // Create child module to create an implementation library. |
| 1786 | // |
| 1787 | // This temporarily creates a second implementation library that can be explicitly |
| 1788 | // referenced. |
| 1789 | // |
| 1790 | // TODO(b/156618935) - update comment once only one implementation library is created. |
| 1791 | module.createImplLibrary(mctx) |
| 1792 | |
Paul Duffin | dfa131e | 2020-05-15 20:37:11 +0100 | [diff] [blame] | 1793 | // Only create an XML permissions file that declares the library as being usable |
| 1794 | // as a shared library if required. |
| 1795 | if module.sharedLibrary() { |
| 1796 | module.createXmlFile(mctx) |
| 1797 | } |
Paul Duffin | 43db9be | 2019-12-30 17:35:49 +0000 | [diff] [blame] | 1798 | |
| 1799 | // record java_sdk_library modules so that they are exported to make |
| 1800 | javaSdkLibraries := javaSdkLibraries(mctx.Config()) |
| 1801 | javaSdkLibrariesLock.Lock() |
| 1802 | defer javaSdkLibrariesLock.Unlock() |
| 1803 | *javaSdkLibraries = append(*javaSdkLibraries, module.BaseModuleName()) |
| 1804 | } |
Anton Hansson | 7f66efa | 2020-10-08 14:47:23 +0100 | [diff] [blame] | 1805 | |
Paul Duffin | 77590a8 | 2022-04-28 14:13:30 +0000 | [diff] [blame] | 1806 | // 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] | 1807 | module.properties.Libs = append(module.properties.Libs, module.sdkLibraryProperties.Impl_only_libs...) |
Cole Faust | b749347 | 2024-08-28 11:55:52 -0700 | [diff] [blame] | 1808 | module.properties.Static_libs.AppendSimpleValue(module.sdkLibraryProperties.Impl_only_static_libs) |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 1809 | } |
| 1810 | |
| 1811 | func (module *SdkLibrary) InitSdkLibraryProperties() { |
Colin Cross | ce6734e | 2020-06-15 16:09:53 -0700 | [diff] [blame] | 1812 | module.addHostAndDeviceProperties() |
| 1813 | module.AddProperties(&module.sdkLibraryProperties) |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 1814 | |
Paul Duffin | 71b33cc | 2021-06-23 11:39:47 +0100 | [diff] [blame] | 1815 | module.initSdkLibraryComponent(module) |
Paul Duffin | 859fe96 | 2020-05-15 10:20:31 +0100 | [diff] [blame] | 1816 | |
Paul Duffin | a18abc2 | 2020-05-16 18:54:24 +0100 | [diff] [blame] | 1817 | module.properties.Installable = proptools.BoolPtr(true) |
| 1818 | module.deviceProperties.IsSDKLibrary = true |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 1819 | } |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 1820 | |
Paul Duffin | dfa131e | 2020-05-15 20:37:11 +0100 | [diff] [blame] | 1821 | func (module *SdkLibrary) requiresRuntimeImplementationLibrary() bool { |
| 1822 | return !proptools.Bool(module.sdkLibraryProperties.Api_only) |
| 1823 | } |
| 1824 | |
Jihoon Kang | fa3f078 | 2024-08-21 20:42:18 +0000 | [diff] [blame] | 1825 | func moduleStubLinkType(j *Module) (stub bool, ret sdkLinkType) { |
| 1826 | kind := android.ToSdkKind(proptools.String(j.properties.Stub_contributing_api)) |
| 1827 | switch kind { |
| 1828 | case android.SdkPublic: |
Anton Hansson | 2d0c194 | 2020-05-25 12:20:51 +0100 | [diff] [blame] | 1829 | return true, javaSdk |
Jihoon Kang | fa3f078 | 2024-08-21 20:42:18 +0000 | [diff] [blame] | 1830 | case android.SdkSystem: |
Anton Hansson | 2d0c194 | 2020-05-25 12:20:51 +0100 | [diff] [blame] | 1831 | return true, javaSystem |
Jihoon Kang | fa3f078 | 2024-08-21 20:42:18 +0000 | [diff] [blame] | 1832 | case android.SdkModule: |
Anton Hansson | 2d0c194 | 2020-05-25 12:20:51 +0100 | [diff] [blame] | 1833 | return true, javaModule |
Jihoon Kang | fa3f078 | 2024-08-21 20:42:18 +0000 | [diff] [blame] | 1834 | case android.SdkTest: |
Anton Hansson | 2d0c194 | 2020-05-25 12:20:51 +0100 | [diff] [blame] | 1835 | return true, javaSystem |
Jihoon Kang | fa3f078 | 2024-08-21 20:42:18 +0000 | [diff] [blame] | 1836 | case android.SdkSystemServer: |
Jihoon Kang | 1147b31 | 2023-06-08 23:25:57 +0000 | [diff] [blame] | 1837 | return true, javaSystemServer |
Jihoon Kang | fa3f078 | 2024-08-21 20:42:18 +0000 | [diff] [blame] | 1838 | // Default value for all modules other than java_sdk_library-generated stub submodules |
| 1839 | case android.SdkInvalid: |
| 1840 | return false, javaPlatform |
| 1841 | default: |
| 1842 | 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] | 1843 | } |
Anton Hansson | 2d0c194 | 2020-05-25 12:20:51 +0100 | [diff] [blame] | 1844 | } |
| 1845 | |
Jaewoong Jung | 4f158ee | 2019-07-11 10:05:35 -0700 | [diff] [blame] | 1846 | // java_sdk_library is a special Java library that provides optional platform APIs to apps. |
| 1847 | // In practice, it can be viewed as a combination of several modules: 1) stubs library that clients |
| 1848 | // are linked against to, 2) droiddoc module that internally generates API stubs source files, |
| 1849 | // 3) the real runtime shared library that implements the APIs, and 4) XML file for adding |
| 1850 | // 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] | 1851 | func SdkLibraryFactory() android.Module { |
| 1852 | module := &SdkLibrary{} |
Paul Duffin | c3091c8 | 2020-05-08 14:16:20 +0100 | [diff] [blame] | 1853 | |
| 1854 | // Initialize information common between source and prebuilt. |
Paul Duffin | 71b33cc | 2021-06-23 11:39:47 +0100 | [diff] [blame] | 1855 | module.initCommon(module) |
Paul Duffin | c3091c8 | 2020-05-08 14:16:20 +0100 | [diff] [blame] | 1856 | |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 1857 | module.InitSdkLibraryProperties() |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 1858 | android.InitApexModule(module) |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 1859 | InitJavaModule(module, android.HostAndDeviceSupported) |
Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 1860 | |
| 1861 | // Initialize the map from scope to scope specific properties. |
| 1862 | scopeToProperties := make(map[*apiScope]*ApiScopeProperties) |
Jihoon Kang | 98aa8fa | 2024-06-07 11:06:57 +0000 | [diff] [blame] | 1863 | for _, scope := range AllApiScopes { |
Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 1864 | scopeToProperties[scope] = scope.scopeSpecificProperties(module) |
| 1865 | } |
| 1866 | module.scopeToProperties = scopeToProperties |
| 1867 | |
Paul Duffin | 4911a89 | 2020-04-29 23:35:13 +0100 | [diff] [blame] | 1868 | // Add the properties containing visibility rules so that they are checked. |
Paul Duffin | 5df7930 | 2020-05-16 15:52:12 +0100 | [diff] [blame] | 1869 | android.AddVisibilityProperty(module, "impl_library_visibility", &module.sdkLibraryProperties.Impl_library_visibility) |
Paul Duffin | 4911a89 | 2020-04-29 23:35:13 +0100 | [diff] [blame] | 1870 | android.AddVisibilityProperty(module, "stubs_library_visibility", &module.sdkLibraryProperties.Stubs_library_visibility) |
| 1871 | android.AddVisibilityProperty(module, "stubs_source_visibility", &module.sdkLibraryProperties.Stubs_source_visibility) |
| 1872 | |
Paul Duffin | 1b1e806 | 2020-05-08 13:44:43 +0100 | [diff] [blame] | 1873 | module.SetDefaultableHook(func(ctx android.DefaultableHookContext) { |
Paul Duffin | dfa131e | 2020-05-15 20:37:11 +0100 | [diff] [blame] | 1874 | // If no implementation is required then it cannot be used as a shared library |
| 1875 | // either. |
| 1876 | if !module.requiresRuntimeImplementationLibrary() { |
| 1877 | // If shared_library has been explicitly set to true then it is incompatible |
| 1878 | // with api_only: true. |
| 1879 | if proptools.Bool(module.commonSdkLibraryProperties.Shared_library) { |
| 1880 | ctx.PropertyErrorf("api_only/shared_library", "inconsistent settings, shared_library and api_only cannot both be true") |
| 1881 | } |
| 1882 | // Set shared_library: false. |
| 1883 | module.commonSdkLibraryProperties.Shared_library = proptools.BoolPtr(false) |
| 1884 | } |
| 1885 | |
Paul Duffin | 1b1e806 | 2020-05-08 13:44:43 +0100 | [diff] [blame] | 1886 | if module.initCommonAfterDefaultsApplied(ctx) { |
| 1887 | module.CreateInternalModules(ctx) |
| 1888 | } |
| 1889 | }) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1890 | return module |
| 1891 | } |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 1892 | |
| 1893 | // |
| 1894 | // SDK library prebuilts |
| 1895 | // |
| 1896 | |
Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 1897 | // Properties associated with each api scope. |
| 1898 | type sdkLibraryScopeProperties struct { |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 1899 | Jars []string `android:"path"` |
| 1900 | |
| 1901 | Sdk_version *string |
| 1902 | |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 1903 | // List of shared java libs that this module has dependencies to |
| 1904 | Libs []string |
Paul Duffin | 3d1248c | 2020-04-09 00:10:17 +0100 | [diff] [blame] | 1905 | |
Paul Duffin | c878250 | 2020-04-29 20:45:27 +0100 | [diff] [blame] | 1906 | // The stubs source. |
Paul Duffin | 3d1248c | 2020-04-09 00:10:17 +0100 | [diff] [blame] | 1907 | Stub_srcs []string `android:"path"` |
Paul Duffin | 1fd005d | 2020-04-09 01:08:11 +0100 | [diff] [blame] | 1908 | |
| 1909 | // The current.txt |
Paul Duffin | 0f8faff | 2020-05-20 16:18:00 +0100 | [diff] [blame] | 1910 | Current_api *string `android:"path"` |
Paul Duffin | 1fd005d | 2020-04-09 01:08:11 +0100 | [diff] [blame] | 1911 | |
| 1912 | // The removed.txt |
Paul Duffin | 0f8faff | 2020-05-20 16:18:00 +0100 | [diff] [blame] | 1913 | Removed_api *string `android:"path"` |
Anton Hansson | d78eb76 | 2021-09-21 15:25:12 +0100 | [diff] [blame] | 1914 | |
| 1915 | // Annotation zip |
| 1916 | Annotations *string `android:"path"` |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 1917 | } |
| 1918 | |
Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 1919 | type sdkLibraryImportProperties struct { |
Paul Duffin | fcfd791 | 2020-01-31 17:54:30 +0000 | [diff] [blame] | 1920 | // List of shared java libs, common to all scopes, that this module has |
| 1921 | // dependencies to |
| 1922 | Libs []string |
Paul Duffin | 1267d87 | 2021-04-16 17:21:36 +0100 | [diff] [blame] | 1923 | |
| 1924 | // If set to true, compile dex files for the stubs. Defaults to false. |
| 1925 | Compile_dex *bool |
Paul Duffin | 869de14 | 2021-07-15 14:14:41 +0100 | [diff] [blame] | 1926 | |
| 1927 | // 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] | 1928 | Permitted_packages []string |
Spandan Das | 23956d1 | 2024-01-19 00:22:22 +0000 | [diff] [blame] | 1929 | |
| 1930 | // Name of the source soong module that gets shadowed by this prebuilt |
| 1931 | // If unspecified, follows the naming convention that the source module of |
| 1932 | // the prebuilt is Name() without "prebuilt_" prefix |
| 1933 | Source_module_name *string |
Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 1934 | } |
| 1935 | |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 1936 | type SdkLibraryImport struct { |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 1937 | android.ModuleBase |
| 1938 | android.DefaultableModuleBase |
| 1939 | prebuilt android.Prebuilt |
Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 1940 | android.ApexModuleBase |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 1941 | |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 1942 | hiddenAPI |
Jiakai Zhang | 204356f | 2021-09-09 08:12:46 +0000 | [diff] [blame] | 1943 | dexpreopter |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 1944 | |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 1945 | properties sdkLibraryImportProperties |
| 1946 | |
Paul Duffin | 46a26a8 | 2020-04-07 19:27:04 +0100 | [diff] [blame] | 1947 | // Map from api scope to the scope specific property structure. |
| 1948 | scopeProperties map[*apiScope]*sdkLibraryScopeProperties |
| 1949 | |
Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 1950 | commonToSdkLibraryAndImport |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 1951 | |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 1952 | // The reference to the xml permissions module created by the source module. |
| 1953 | // Is nil if the source module does not exist. |
| 1954 | xmlPermissionsFileModule *sdkLibraryXml |
Paul Duffin | 3985351 | 2021-02-26 11:09:39 +0000 | [diff] [blame] | 1955 | |
Jeongik Cha | d5fe878 | 2021-07-08 01:13:11 +0900 | [diff] [blame] | 1956 | // 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] | 1957 | dexJarFile OptionalDexJarPath |
| 1958 | dexJarFileErr error |
Jeongik Cha | d5fe878 | 2021-07-08 01:13:11 +0900 | [diff] [blame] | 1959 | |
| 1960 | // Expected install file path of the source module(sdk_library) |
| 1961 | // or dex implementation jar obtained from the prebuilt_apex, if any. |
| 1962 | installFile android.Path |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 1963 | } |
| 1964 | |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 1965 | var _ SdkLibraryDependency = (*SdkLibraryImport)(nil) |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 1966 | |
Paul Duffin | 46a26a8 | 2020-04-07 19:27:04 +0100 | [diff] [blame] | 1967 | // The type of a structure that contains a field of type sdkLibraryScopeProperties |
| 1968 | // for each apiscope in allApiScopes, e.g. something like: |
Colin Cross | d079e0b | 2022-08-16 10:27:33 -0700 | [diff] [blame] | 1969 | // |
| 1970 | // struct { |
| 1971 | // Public sdkLibraryScopeProperties |
| 1972 | // System sdkLibraryScopeProperties |
| 1973 | // ... |
| 1974 | // } |
Paul Duffin | 46a26a8 | 2020-04-07 19:27:04 +0100 | [diff] [blame] | 1975 | var allScopeStructType = createAllScopePropertiesStructType() |
| 1976 | |
| 1977 | // Dynamically create a structure type for each apiscope in allApiScopes. |
| 1978 | func createAllScopePropertiesStructType() reflect.Type { |
| 1979 | var fields []reflect.StructField |
Jihoon Kang | 98aa8fa | 2024-06-07 11:06:57 +0000 | [diff] [blame] | 1980 | for _, apiScope := range AllApiScopes { |
Paul Duffin | 46a26a8 | 2020-04-07 19:27:04 +0100 | [diff] [blame] | 1981 | field := reflect.StructField{ |
| 1982 | Name: apiScope.fieldName, |
| 1983 | Type: reflect.TypeOf(sdkLibraryScopeProperties{}), |
| 1984 | } |
| 1985 | fields = append(fields, field) |
| 1986 | } |
| 1987 | |
| 1988 | return reflect.StructOf(fields) |
| 1989 | } |
| 1990 | |
| 1991 | // Create an instance of the scope specific structure type and return a map |
| 1992 | // from apiscope to a pointer to each scope specific field. |
| 1993 | func createPropertiesInstance() (interface{}, map[*apiScope]*sdkLibraryScopeProperties) { |
| 1994 | allScopePropertiesPtr := reflect.New(allScopeStructType) |
| 1995 | allScopePropertiesStruct := allScopePropertiesPtr.Elem() |
| 1996 | scopeProperties := make(map[*apiScope]*sdkLibraryScopeProperties) |
| 1997 | |
Jihoon Kang | 98aa8fa | 2024-06-07 11:06:57 +0000 | [diff] [blame] | 1998 | for _, apiScope := range AllApiScopes { |
Paul Duffin | 46a26a8 | 2020-04-07 19:27:04 +0100 | [diff] [blame] | 1999 | field := allScopePropertiesStruct.FieldByName(apiScope.fieldName) |
| 2000 | scopeProperties[apiScope] = field.Addr().Interface().(*sdkLibraryScopeProperties) |
| 2001 | } |
| 2002 | |
| 2003 | return allScopePropertiesPtr.Interface(), scopeProperties |
| 2004 | } |
| 2005 | |
Jaewoong Jung | 4f158ee | 2019-07-11 10:05:35 -0700 | [diff] [blame] | 2006 | // java_sdk_library_import imports a prebuilt java_sdk_library. |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 2007 | func sdkLibraryImportFactory() android.Module { |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 2008 | module := &SdkLibraryImport{} |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 2009 | |
Paul Duffin | 46a26a8 | 2020-04-07 19:27:04 +0100 | [diff] [blame] | 2010 | allScopeProperties, scopeToProperties := createPropertiesInstance() |
| 2011 | module.scopeProperties = scopeToProperties |
Jiakai Zhang | 9c4dc19 | 2023-02-09 00:09:24 +0800 | [diff] [blame] | 2012 | module.AddProperties(&module.properties, allScopeProperties, &module.importDexpreoptProperties) |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 2013 | |
Paul Duffin | c3091c8 | 2020-05-08 14:16:20 +0100 | [diff] [blame] | 2014 | // Initialize information common between source and prebuilt. |
Paul Duffin | 71b33cc | 2021-06-23 11:39:47 +0100 | [diff] [blame] | 2015 | module.initCommon(module) |
Paul Duffin | c3091c8 | 2020-05-08 14:16:20 +0100 | [diff] [blame] | 2016 | |
Paul Duffin | 0bdcb27 | 2020-02-06 15:24:57 +0000 | [diff] [blame] | 2017 | android.InitPrebuiltModule(module, &[]string{""}) |
Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 2018 | android.InitApexModule(module) |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 2019 | InitJavaModule(module, android.HostAndDeviceSupported) |
| 2020 | |
Paul Duffin | 1b1e806 | 2020-05-08 13:44:43 +0100 | [diff] [blame] | 2021 | module.SetDefaultableHook(func(mctx android.DefaultableHookContext) { |
| 2022 | if module.initCommonAfterDefaultsApplied(mctx) { |
| 2023 | module.createInternalModules(mctx) |
| 2024 | } |
| 2025 | }) |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 2026 | return module |
| 2027 | } |
| 2028 | |
Paul Duffin | 630b11e | 2021-07-15 13:35:26 +0100 | [diff] [blame] | 2029 | var _ PermittedPackagesForUpdatableBootJars = (*SdkLibraryImport)(nil) |
| 2030 | |
| 2031 | func (module *SdkLibraryImport) PermittedPackagesForUpdatableBootJars() []string { |
| 2032 | return module.properties.Permitted_packages |
| 2033 | } |
| 2034 | |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 2035 | func (module *SdkLibraryImport) Prebuilt() *android.Prebuilt { |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 2036 | return &module.prebuilt |
| 2037 | } |
| 2038 | |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 2039 | func (module *SdkLibraryImport) Name() string { |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 2040 | return module.prebuilt.Name(module.ModuleBase.Name()) |
| 2041 | } |
| 2042 | |
Spandan Das | 23956d1 | 2024-01-19 00:22:22 +0000 | [diff] [blame] | 2043 | func (module *SdkLibraryImport) BaseModuleName() string { |
| 2044 | return proptools.StringDefault(module.properties.Source_module_name, module.ModuleBase.Name()) |
| 2045 | } |
| 2046 | |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 2047 | func (module *SdkLibraryImport) createInternalModules(mctx android.DefaultableHookContext) { |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 2048 | |
Paul Duffin | 5006151 | 2020-01-21 16:31:05 +0000 | [diff] [blame] | 2049 | // 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] | 2050 | if mctx.Config().AlwaysUsePrebuiltSdks() { |
Paul Duffin | 5006151 | 2020-01-21 16:31:05 +0000 | [diff] [blame] | 2051 | module.prebuilt.ForcePrefer() |
| 2052 | } |
| 2053 | |
Paul Duffin | 46a26a8 | 2020-04-07 19:27:04 +0100 | [diff] [blame] | 2054 | for apiScope, scopeProperties := range module.scopeProperties { |
Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 2055 | if len(scopeProperties.Jars) == 0 { |
| 2056 | continue |
| 2057 | } |
| 2058 | |
Paul Duffin | bbb546b | 2020-04-09 00:07:11 +0100 | [diff] [blame] | 2059 | module.createJavaImportForStubs(mctx, apiScope, scopeProperties) |
Paul Duffin | 3d1248c | 2020-04-09 00:10:17 +0100 | [diff] [blame] | 2060 | |
Paul Duffin | 0f8faff | 2020-05-20 16:18:00 +0100 | [diff] [blame] | 2061 | if len(scopeProperties.Stub_srcs) > 0 { |
| 2062 | module.createPrebuiltStubsSources(mctx, apiScope, scopeProperties) |
| 2063 | } |
Jihoon Kang | 71c8683 | 2023-09-13 01:01:53 +0000 | [diff] [blame] | 2064 | |
| 2065 | if scopeProperties.Current_api != nil { |
| 2066 | module.createPrebuiltApiContribution(mctx, apiScope, scopeProperties) |
| 2067 | } |
Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 2068 | } |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 2069 | |
| 2070 | javaSdkLibraries := javaSdkLibraries(mctx.Config()) |
| 2071 | javaSdkLibrariesLock.Lock() |
| 2072 | defer javaSdkLibrariesLock.Unlock() |
| 2073 | *javaSdkLibraries = append(*javaSdkLibraries, module.BaseModuleName()) |
| 2074 | } |
| 2075 | |
Paul Duffin | 44f1d84 | 2020-06-26 20:17:02 +0100 | [diff] [blame] | 2076 | // Add the dependencies on the child module in the component deps mutator so that it |
| 2077 | // creates references to the prebuilt and not the source modules. |
| 2078 | func (module *SdkLibraryImport) ComponentDepsMutator(ctx android.BottomUpMutatorContext) { |
Paul Duffin | 46a26a8 | 2020-04-07 19:27:04 +0100 | [diff] [blame] | 2079 | for apiScope, scopeProperties := range module.scopeProperties { |
Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 2080 | if len(scopeProperties.Jars) == 0 { |
| 2081 | continue |
| 2082 | } |
| 2083 | |
| 2084 | // Add dependencies to the prebuilt stubs library |
Jihoon Kang | b743155 | 2024-01-22 19:40:08 +0000 | [diff] [blame] | 2085 | ctx.AddVariationDependencies(nil, apiScope.prebuiltStubsTag, android.PrebuiltNameFromSource(module.stubsLibraryModuleName(apiScope))) |
Paul Duffin | 0f8faff | 2020-05-20 16:18:00 +0100 | [diff] [blame] | 2086 | |
| 2087 | if len(scopeProperties.Stub_srcs) > 0 { |
| 2088 | // Add dependencies to the prebuilt stubs source library |
Jihoon Kang | 96ce83b | 2024-09-23 22:09:44 +0000 | [diff] [blame^] | 2089 | ctx.AddVariationDependencies(nil, apiScope.stubsSourceTag, android.PrebuiltNameFromSource(module.droidstubsModuleName(apiScope))) |
Paul Duffin | 0f8faff | 2020-05-20 16:18:00 +0100 | [diff] [blame] | 2090 | } |
Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 2091 | } |
Paul Duffin | 44f1d84 | 2020-06-26 20:17:02 +0100 | [diff] [blame] | 2092 | } |
| 2093 | |
| 2094 | // Add other dependencies as normal. |
| 2095 | func (module *SdkLibraryImport) DepsMutator(ctx android.BottomUpMutatorContext) { |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 2096 | |
| 2097 | implName := module.implLibraryModuleName() |
| 2098 | if ctx.OtherModuleExists(implName) { |
| 2099 | ctx.AddVariationDependencies(nil, implLibraryTag, implName) |
| 2100 | |
| 2101 | xmlPermissionsModuleName := module.xmlPermissionsModuleName() |
| 2102 | if module.sharedLibrary() && ctx.OtherModuleExists(xmlPermissionsModuleName) { |
| 2103 | // Add dependency to the rule for generating the xml permissions file |
| 2104 | ctx.AddDependency(module, xmlPermissionsFileTag, xmlPermissionsModuleName) |
| 2105 | } |
| 2106 | } |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 2107 | } |
| 2108 | |
Jiyong Park | 45bf82e | 2020-12-15 22:29:02 +0900 | [diff] [blame] | 2109 | var _ android.ApexModule = (*SdkLibraryImport)(nil) |
| 2110 | |
| 2111 | // Implements android.ApexModule |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 2112 | func (module *SdkLibraryImport) DepIsInSameApex(mctx android.BaseModuleContext, dep android.Module) bool { |
| 2113 | depTag := mctx.OtherModuleDependencyTag(dep) |
| 2114 | if depTag == xmlPermissionsFileTag { |
| 2115 | return true |
| 2116 | } |
| 2117 | |
| 2118 | // None of the other dependencies of the java_sdk_library_import are in the same apex |
| 2119 | // as the one that references this module. |
| 2120 | return false |
| 2121 | } |
| 2122 | |
Jiyong Park | 45bf82e | 2020-12-15 22:29:02 +0900 | [diff] [blame] | 2123 | // Implements android.ApexModule |
Dan Albert | c806053 | 2020-07-22 22:32:17 -0700 | [diff] [blame] | 2124 | func (module *SdkLibraryImport) ShouldSupportSdkVersion(ctx android.BaseModuleContext, |
| 2125 | sdkVersion android.ApiLevel) error { |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 2126 | // we don't check prebuilt modules for sdk_version |
| 2127 | return nil |
| 2128 | } |
| 2129 | |
Paul Duffin | ea8f808 | 2021-06-24 13:25:57 +0100 | [diff] [blame] | 2130 | // Implements android.ApexModule |
| 2131 | func (module *SdkLibraryImport) UniqueApexVariations() bool { |
| 2132 | return module.uniqueApexVariations() |
| 2133 | } |
| 2134 | |
Paul Duffin | 09817d6 | 2022-04-28 17:45:11 +0100 | [diff] [blame] | 2135 | // MinSdkVersion - Implements hiddenAPIModule |
Spandan Das | 8c9ae7e | 2023-03-03 21:20:36 +0000 | [diff] [blame] | 2136 | func (module *SdkLibraryImport) MinSdkVersion(ctx android.EarlyModuleContext) android.ApiLevel { |
| 2137 | return android.NoneApiLevel |
Paul Duffin | 09817d6 | 2022-04-28 17:45:11 +0100 | [diff] [blame] | 2138 | } |
| 2139 | |
| 2140 | var _ hiddenAPIModule = (*SdkLibraryImport)(nil) |
| 2141 | |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 2142 | func (module *SdkLibraryImport) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Paul Duffin | a2ae7e0 | 2020-09-11 11:55:00 +0100 | [diff] [blame] | 2143 | module.generateCommonBuildActions(ctx) |
| 2144 | |
Jeongik Cha | d5fe878 | 2021-07-08 01:13:11 +0900 | [diff] [blame] | 2145 | // Assume that source module(sdk_library) is installed in /<sdk_library partition>/framework |
| 2146 | module.installFile = android.PathForModuleInstall(ctx, "framework", module.Stem()+".jar") |
| 2147 | |
Paul Duffin | 0f8faff | 2020-05-20 16:18:00 +0100 | [diff] [blame] | 2148 | // Record the paths to the prebuilt stubs library and stubs source. |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 2149 | ctx.VisitDirectDeps(func(to android.Module) { |
| 2150 | tag := ctx.OtherModuleDependencyTag(to) |
| 2151 | |
Paul Duffin | 0f8faff | 2020-05-20 16:18:00 +0100 | [diff] [blame] | 2152 | // Extract information from any of the scope specific dependencies. |
| 2153 | if scopeTag, ok := tag.(scopeDependencyTag); ok { |
| 2154 | apiScope := scopeTag.apiScope |
| 2155 | scopePaths := module.getScopePathsCreateIfNeeded(apiScope) |
| 2156 | |
| 2157 | // Extract information from the dependency. The exact information extracted |
| 2158 | // is determined by the nature of the dependency which is determined by the tag. |
| 2159 | scopeTag.extractDepInfo(ctx, to, scopePaths) |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 2160 | } else if tag == implLibraryTag { |
| 2161 | if implLibrary, ok := to.(*Library); ok { |
| 2162 | module.implLibraryModule = implLibrary |
| 2163 | } else { |
| 2164 | ctx.ModuleErrorf("implementation library must be of type *java.Library but was %T", to) |
| 2165 | } |
| 2166 | } else if tag == xmlPermissionsFileTag { |
| 2167 | if xmlPermissionsFileModule, ok := to.(*sdkLibraryXml); ok { |
| 2168 | module.xmlPermissionsFileModule = xmlPermissionsFileModule |
| 2169 | } else { |
| 2170 | ctx.ModuleErrorf("xml permissions file module must be of type *sdkLibraryXml but was %T", to) |
| 2171 | } |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 2172 | } |
| 2173 | }) |
Paul Duffin | 0f8faff | 2020-05-20 16:18:00 +0100 | [diff] [blame] | 2174 | |
| 2175 | // Populate the scope paths with information from the properties. |
| 2176 | for apiScope, scopeProperties := range module.scopeProperties { |
| 2177 | if len(scopeProperties.Jars) == 0 { |
| 2178 | continue |
| 2179 | } |
| 2180 | |
| 2181 | paths := module.getScopePathsCreateIfNeeded(apiScope) |
Anton Hansson | d78eb76 | 2021-09-21 15:25:12 +0100 | [diff] [blame] | 2182 | paths.annotationsZip = android.OptionalPathForModuleSrc(ctx, scopeProperties.Annotations) |
Paul Duffin | 0f8faff | 2020-05-20 16:18:00 +0100 | [diff] [blame] | 2183 | paths.currentApiFilePath = android.OptionalPathForModuleSrc(ctx, scopeProperties.Current_api) |
| 2184 | paths.removedApiFilePath = android.OptionalPathForModuleSrc(ctx, scopeProperties.Removed_api) |
| 2185 | } |
Paul Duffin | 3985351 | 2021-02-26 11:09:39 +0000 | [diff] [blame] | 2186 | |
| 2187 | if ctx.Device() { |
| 2188 | // If this is a variant created for a prebuilt_apex then use the dex implementation jar |
| 2189 | // obtained from the associated deapexer module. |
Colin Cross | ff694a8 | 2023-12-13 15:54:49 -0800 | [diff] [blame] | 2190 | ai, _ := android.ModuleProvider(ctx, android.ApexInfoProvider) |
Paul Duffin | 3985351 | 2021-02-26 11:09:39 +0000 | [diff] [blame] | 2191 | if ai.ForPrebuiltApex { |
Paul Duffin | 3985351 | 2021-02-26 11:09:39 +0000 | [diff] [blame] | 2192 | // Get the path of the dex implementation jar from the `deapexer` module. |
Spandan Das | fae468e | 2023-12-12 23:23:53 +0000 | [diff] [blame] | 2193 | di, err := android.FindDeapexerProviderForModule(ctx) |
| 2194 | if err != nil { |
| 2195 | // An error was found, possibly due to multiple apexes in the tree that export this library |
| 2196 | // Defer the error till a client tries to call DexJarBuildPath |
| 2197 | module.dexJarFileErr = err |
Spandan Das | 3a39201 | 2024-01-17 18:26:27 +0000 | [diff] [blame] | 2198 | module.initHiddenAPIError(err) |
Spandan Das | fae468e | 2023-12-12 23:23:53 +0000 | [diff] [blame] | 2199 | return |
Martin Stjernholm | 4482560 | 2021-09-17 01:44:12 +0100 | [diff] [blame] | 2200 | } |
Spandan Das | 5be6333 | 2023-12-13 00:06:32 +0000 | [diff] [blame] | 2201 | dexJarFileApexRootRelative := ApexRootRelativePathToJavaLib(module.BaseModuleName()) |
Jiakai Zhang | 81e4681 | 2023-02-08 21:56:07 +0800 | [diff] [blame] | 2202 | if dexOutputPath := di.PrebuiltExportPath(dexJarFileApexRootRelative); dexOutputPath != nil { |
Martin Stjernholm | 8be1e6d | 2021-09-15 03:34:04 +0100 | [diff] [blame] | 2203 | dexJarFile := makeDexJarPathFromPath(dexOutputPath) |
| 2204 | module.dexJarFile = dexJarFile |
Jiakai Zhang | 204356f | 2021-09-09 08:12:46 +0000 | [diff] [blame] | 2205 | installPath := android.PathForModuleInPartitionInstall( |
Jiakai Zhang | 81e4681 | 2023-02-08 21:56:07 +0800 | [diff] [blame] | 2206 | ctx, "apex", ai.ApexVariationName, dexJarFileApexRootRelative) |
Jiakai Zhang | 204356f | 2021-09-09 08:12:46 +0000 | [diff] [blame] | 2207 | module.installFile = installPath |
Martin Stjernholm | 8be1e6d | 2021-09-15 03:34:04 +0100 | [diff] [blame] | 2208 | module.initHiddenAPI(ctx, dexJarFile, module.findScopePaths(apiScopePublic).stubsImplPath[0], nil) |
Jiakai Zhang | 204356f | 2021-09-09 08:12:46 +0000 | [diff] [blame] | 2209 | |
Spandan Das | e21a8d4 | 2024-01-23 23:56:29 +0000 | [diff] [blame] | 2210 | module.dexpreopter.installPath = module.dexpreopter.getInstallPath(ctx, android.RemoveOptionalPrebuiltPrefix(ctx.ModuleName()), installPath) |
Jiakai Zhang | 204356f | 2021-09-09 08:12:46 +0000 | [diff] [blame] | 2211 | module.dexpreopter.isSDKLibrary = true |
Spandan Das | e21a8d4 | 2024-01-23 23:56:29 +0000 | [diff] [blame] | 2212 | module.dexpreopter.uncompressedDex = shouldUncompressDex(ctx, android.RemoveOptionalPrebuiltPrefix(ctx.ModuleName()), &module.dexpreopter) |
Jiakai Zhang | 81e4681 | 2023-02-08 21:56:07 +0800 | [diff] [blame] | 2213 | |
| 2214 | if profilePath := di.PrebuiltExportPath(dexJarFileApexRootRelative + ".prof"); profilePath != nil { |
| 2215 | module.dexpreopter.inputProfilePathOnHost = profilePath |
| 2216 | } |
Paul Duffin | 3985351 | 2021-02-26 11:09:39 +0000 | [diff] [blame] | 2217 | } else { |
| 2218 | // This should never happen as a variant for a prebuilt_apex is only created if the |
| 2219 | // prebuilt_apex has been configured to export the java library dex file. |
Martin Stjernholm | 4482560 | 2021-09-17 01:44:12 +0100 | [diff] [blame] | 2220 | 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] | 2221 | } |
| 2222 | } |
| 2223 | } |
mrziwang | 9f7b9f4 | 2024-07-10 12:18:06 -0700 | [diff] [blame] | 2224 | |
Jihoon Kang | 28c9657 | 2024-09-11 23:44:44 +0000 | [diff] [blame] | 2225 | var generatingLibs []string |
| 2226 | for _, apiScope := range AllApiScopes { |
| 2227 | if scopeProperties, ok := module.scopeProperties[apiScope]; ok { |
| 2228 | if len(scopeProperties.Jars) == 0 { |
| 2229 | continue |
| 2230 | } |
| 2231 | generatingLibs = append(generatingLibs, module.stubsLibraryModuleName(apiScope)) |
| 2232 | } |
| 2233 | } |
| 2234 | |
mrziwang | 9f7b9f4 | 2024-07-10 12:18:06 -0700 | [diff] [blame] | 2235 | module.setOutputFiles(ctx) |
| 2236 | if module.implLibraryModule != nil { |
Jihoon Kang | 28c9657 | 2024-09-11 23:44:44 +0000 | [diff] [blame] | 2237 | generatingLibs = append(generatingLibs, module.implLibraryModuleName()) |
mrziwang | 9f7b9f4 | 2024-07-10 12:18:06 -0700 | [diff] [blame] | 2238 | setOutputFiles(ctx, module.implLibraryModule.Module) |
| 2239 | } |
Jihoon Kang | 28c9657 | 2024-09-11 23:44:44 +0000 | [diff] [blame] | 2240 | |
| 2241 | android.SetProvider(ctx, SdkLibraryInfoProvider, SdkLibraryInfo{ |
| 2242 | GeneratingLibs: generatingLibs, |
| 2243 | }) |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 2244 | } |
| 2245 | |
Ulya Trafimovich | dbf3166 | 2020-12-17 12:07:54 +0000 | [diff] [blame] | 2246 | // to satisfy UsesLibraryDependency interface |
Spandan Das | 59a4a2b | 2024-01-09 21:35:56 +0000 | [diff] [blame] | 2247 | func (module *SdkLibraryImport) DexJarBuildPath(ctx android.ModuleErrorfContext) OptionalDexJarPath { |
Paul Duffin | 3985351 | 2021-02-26 11:09:39 +0000 | [diff] [blame] | 2248 | // The dex implementation jar extracted from the .apex file should be used in preference to the |
| 2249 | // source. |
Spandan Das | fae468e | 2023-12-12 23:23:53 +0000 | [diff] [blame] | 2250 | if module.dexJarFileErr != nil { |
Spandan Das | 59a4a2b | 2024-01-09 21:35:56 +0000 | [diff] [blame] | 2251 | ctx.ModuleErrorf(module.dexJarFileErr.Error()) |
Spandan Das | fae468e | 2023-12-12 23:23:53 +0000 | [diff] [blame] | 2252 | } |
Martin Stjernholm | 8be1e6d | 2021-09-15 03:34:04 +0100 | [diff] [blame] | 2253 | if module.dexJarFile.IsSet() { |
Paul Duffin | 3985351 | 2021-02-26 11:09:39 +0000 | [diff] [blame] | 2254 | return module.dexJarFile |
| 2255 | } |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 2256 | if module.implLibraryModule == nil { |
Martin Stjernholm | 8be1e6d | 2021-09-15 03:34:04 +0100 | [diff] [blame] | 2257 | return makeUnsetDexJarPath() |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 2258 | } else { |
Spandan Das | 59a4a2b | 2024-01-09 21:35:56 +0000 | [diff] [blame] | 2259 | return module.implLibraryModule.DexJarBuildPath(ctx) |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 2260 | } |
| 2261 | } |
| 2262 | |
Ulya Trafimovich | dbf3166 | 2020-12-17 12:07:54 +0000 | [diff] [blame] | 2263 | // to satisfy UsesLibraryDependency interface |
Ulya Trafimovich | 31e444e | 2020-08-14 17:32:16 +0100 | [diff] [blame] | 2264 | func (module *SdkLibraryImport) DexJarInstallPath() android.Path { |
Jeongik Cha | d5fe878 | 2021-07-08 01:13:11 +0900 | [diff] [blame] | 2265 | return module.installFile |
Ulya Trafimovich | 31e444e | 2020-08-14 17:32:16 +0100 | [diff] [blame] | 2266 | } |
| 2267 | |
Ulya Trafimovich | dbf3166 | 2020-12-17 12:07:54 +0000 | [diff] [blame] | 2268 | // to satisfy UsesLibraryDependency interface |
| 2269 | func (module *SdkLibraryImport) ClassLoaderContexts() dexpreopt.ClassLoaderContextMap { |
| 2270 | return nil |
| 2271 | } |
| 2272 | |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 2273 | // to satisfy apex.javaDependency interface |
| 2274 | func (module *SdkLibraryImport) JacocoReportClassesFile() android.Path { |
| 2275 | if module.implLibraryModule == nil { |
| 2276 | return nil |
| 2277 | } else { |
| 2278 | return module.implLibraryModule.JacocoReportClassesFile() |
| 2279 | } |
| 2280 | } |
| 2281 | |
| 2282 | // to satisfy apex.javaDependency interface |
Colin Cross | 08dca38 | 2020-07-21 20:31:17 -0700 | [diff] [blame] | 2283 | func (module *SdkLibraryImport) LintDepSets() LintDepSets { |
| 2284 | if module.implLibraryModule == nil { |
| 2285 | return LintDepSets{} |
| 2286 | } else { |
| 2287 | return module.implLibraryModule.LintDepSets() |
| 2288 | } |
| 2289 | } |
| 2290 | |
Spandan Das | 17854f5 | 2022-01-14 21:19:14 +0000 | [diff] [blame] | 2291 | func (module *SdkLibraryImport) GetStrictUpdatabilityLinting() bool { |
Jaewoong Jung | 476b9d6 | 2021-05-10 15:30:00 -0700 | [diff] [blame] | 2292 | if module.implLibraryModule == nil { |
| 2293 | return false |
| 2294 | } else { |
Spandan Das | 17854f5 | 2022-01-14 21:19:14 +0000 | [diff] [blame] | 2295 | return module.implLibraryModule.GetStrictUpdatabilityLinting() |
Jaewoong Jung | 476b9d6 | 2021-05-10 15:30:00 -0700 | [diff] [blame] | 2296 | } |
| 2297 | } |
| 2298 | |
Spandan Das | 17854f5 | 2022-01-14 21:19:14 +0000 | [diff] [blame] | 2299 | func (module *SdkLibraryImport) SetStrictUpdatabilityLinting(strictLinting bool) { |
Jaewoong Jung | 476b9d6 | 2021-05-10 15:30:00 -0700 | [diff] [blame] | 2300 | if module.implLibraryModule != nil { |
Spandan Das | 17854f5 | 2022-01-14 21:19:14 +0000 | [diff] [blame] | 2301 | module.implLibraryModule.SetStrictUpdatabilityLinting(strictLinting) |
Jaewoong Jung | 476b9d6 | 2021-05-10 15:30:00 -0700 | [diff] [blame] | 2302 | } |
| 2303 | } |
| 2304 | |
Colin Cross | 08dca38 | 2020-07-21 20:31:17 -0700 | [diff] [blame] | 2305 | // to satisfy apex.javaDependency interface |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 2306 | func (module *SdkLibraryImport) Stem() string { |
| 2307 | return module.BaseModuleName() |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 2308 | } |
Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 2309 | |
Paul Duffin | 44b481b | 2020-06-17 16:59:43 +0100 | [diff] [blame] | 2310 | var _ ApexDependency = (*SdkLibraryImport)(nil) |
| 2311 | |
| 2312 | // to satisfy java.ApexDependency interface |
| 2313 | func (module *SdkLibraryImport) HeaderJars() android.Paths { |
| 2314 | if module.implLibraryModule == nil { |
| 2315 | return nil |
| 2316 | } else { |
| 2317 | return module.implLibraryModule.HeaderJars() |
| 2318 | } |
| 2319 | } |
| 2320 | |
| 2321 | // to satisfy java.ApexDependency interface |
| 2322 | func (module *SdkLibraryImport) ImplementationAndResourcesJars() android.Paths { |
| 2323 | if module.implLibraryModule == nil { |
| 2324 | return nil |
| 2325 | } else { |
| 2326 | return module.implLibraryModule.ImplementationAndResourcesJars() |
| 2327 | } |
| 2328 | } |
| 2329 | |
Jiakai Zhang | 204356f | 2021-09-09 08:12:46 +0000 | [diff] [blame] | 2330 | // to satisfy java.DexpreopterInterface interface |
| 2331 | func (module *SdkLibraryImport) IsInstallable() bool { |
| 2332 | return true |
| 2333 | } |
| 2334 | |
Paul Duffin | fef5500 | 2021-06-17 14:56:05 +0100 | [diff] [blame] | 2335 | var _ android.RequiredFilesFromPrebuiltApex = (*SdkLibraryImport)(nil) |
| 2336 | |
Paul Duffin | b4bbf2c | 2021-06-17 15:59:07 +0100 | [diff] [blame] | 2337 | func (module *SdkLibraryImport) RequiredFilesFromPrebuiltApex(ctx android.BaseModuleContext) []string { |
Paul Duffin | fef5500 | 2021-06-17 14:56:05 +0100 | [diff] [blame] | 2338 | name := module.BaseModuleName() |
Jiakai Zhang | 81e4681 | 2023-02-08 21:56:07 +0800 | [diff] [blame] | 2339 | return requiredFilesFromPrebuiltApexForImport(name, &module.dexpreopter) |
Paul Duffin | fef5500 | 2021-06-17 14:56:05 +0100 | [diff] [blame] | 2340 | } |
| 2341 | |
Spandan Das | 2ea84dd | 2024-01-25 22:12:50 +0000 | [diff] [blame] | 2342 | func (j *SdkLibraryImport) UseProfileGuidedDexpreopt() bool { |
| 2343 | return proptools.Bool(j.importDexpreoptProperties.Dex_preopt.Profile_guided) |
| 2344 | } |
| 2345 | |
Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 2346 | type sdkLibrarySdkMemberType struct { |
| 2347 | android.SdkMemberTypeBase |
| 2348 | } |
| 2349 | |
Paul Duffin | 296701e | 2021-07-14 10:29:36 +0100 | [diff] [blame] | 2350 | func (s *sdkLibrarySdkMemberType) AddDependencies(ctx android.SdkDependencyContext, dependencyTag blueprint.DependencyTag, names []string) { |
| 2351 | ctx.AddVariationDependencies(nil, dependencyTag, names...) |
Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 2352 | } |
| 2353 | |
| 2354 | func (s *sdkLibrarySdkMemberType) IsInstance(module android.Module) bool { |
| 2355 | _, ok := module.(*SdkLibrary) |
| 2356 | return ok |
| 2357 | } |
| 2358 | |
| 2359 | func (s *sdkLibrarySdkMemberType) AddPrebuiltModule(ctx android.SdkMemberContext, member android.SdkMember) android.BpModule { |
| 2360 | return ctx.SnapshotBuilder().AddPrebuiltModule(member, "java_sdk_library_import") |
| 2361 | } |
| 2362 | |
| 2363 | func (s *sdkLibrarySdkMemberType) CreateVariantPropertiesStruct() android.SdkMemberProperties { |
| 2364 | return &sdkLibrarySdkMemberProperties{} |
| 2365 | } |
| 2366 | |
Paul Duffin | 976b0e5 | 2021-04-27 23:20:26 +0100 | [diff] [blame] | 2367 | var javaSdkLibrarySdkMemberType = &sdkLibrarySdkMemberType{ |
| 2368 | android.SdkMemberTypeBase{ |
| 2369 | PropertyName: "java_sdk_libs", |
| 2370 | SupportsSdk: true, |
| 2371 | }, |
| 2372 | } |
| 2373 | |
Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 2374 | type sdkLibrarySdkMemberProperties struct { |
| 2375 | android.SdkMemberPropertiesBase |
| 2376 | |
Paul Duffin | e840995 | 2022-09-22 16:24:46 +0100 | [diff] [blame] | 2377 | // Stem name for files in the sdk snapshot. |
| 2378 | // |
| 2379 | // This is used to construct the path names of various sdk library files in the sdk snapshot to |
| 2380 | // make sure that they match the finalized versions of those files in prebuilts/sdk. |
| 2381 | // |
| 2382 | // This property is marked as keep so that it will be kept in all instances of this struct, will |
| 2383 | // not be cleared but will be copied to common structs. That is needed because this field is used |
| 2384 | // to construct many file names for other parts of this struct and so it needs to be present in |
| 2385 | // all structs. If it was not marked as keep then it would be cleared in some structs and so would |
| 2386 | // be unavailable for generating file names if there were other properties that were still set. |
| 2387 | Stem string `sdk:"keep"` |
| 2388 | |
Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 2389 | // Scope to per scope properties. |
Paul Duffin | 106a3a4 | 2022-01-27 16:39:06 +0000 | [diff] [blame] | 2390 | Scopes map[*apiScope]*scopeProperties |
Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 2391 | |
Paul Duffin | 3d1248c | 2020-04-09 00:10:17 +0100 | [diff] [blame] | 2392 | // The Java stubs source files. |
| 2393 | Stub_srcs []string |
Paul Duffin | f7a6433 | 2020-05-13 16:54:55 +0100 | [diff] [blame] | 2394 | |
| 2395 | // The naming scheme. |
| 2396 | Naming_scheme *string |
Paul Duffin | d7eb1c2 | 2020-05-26 20:57:10 +0100 | [diff] [blame] | 2397 | |
| 2398 | // True if the java_sdk_library_import is for a shared library, false |
| 2399 | // otherwise. |
| 2400 | Shared_library *bool |
Paul Duffin | a2ae7e0 | 2020-09-11 11:55:00 +0100 | [diff] [blame] | 2401 | |
Paul Duffin | 1267d87 | 2021-04-16 17:21:36 +0100 | [diff] [blame] | 2402 | // True if the stub imports should produce dex jars. |
| 2403 | Compile_dex *bool |
| 2404 | |
Paul Duffin | a2ae7e0 | 2020-09-11 11:55:00 +0100 | [diff] [blame] | 2405 | // The paths to the doctag files to add to the prebuilt. |
| 2406 | Doctag_paths android.Paths |
Paul Duffin | 869de14 | 2021-07-15 14:14:41 +0100 | [diff] [blame] | 2407 | |
| 2408 | Permitted_packages []string |
Pedro Loureiro | 9956e5e | 2021-09-07 17:21:59 +0000 | [diff] [blame] | 2409 | |
| 2410 | // Signals that this shared library is part of the bootclasspath starting |
| 2411 | // on the version indicated in this attribute. |
| 2412 | // |
| 2413 | // This will make platforms at this level and above to ignore |
| 2414 | // <uses-library> tags with this library name because the library is already |
| 2415 | // available |
| 2416 | On_bootclasspath_since *string |
| 2417 | |
| 2418 | // Signals that this shared library was part of the bootclasspath before |
| 2419 | // (but not including) the version indicated in this attribute. |
| 2420 | // |
| 2421 | // The system will automatically add a <uses-library> tag with this library to |
| 2422 | // apps that target any SDK less than the version indicated in this attribute. |
| 2423 | On_bootclasspath_before *string |
| 2424 | |
| 2425 | // Indicates that PackageManager should ignore this shared library if the |
| 2426 | // platform is below the version indicated in this attribute. |
| 2427 | // |
| 2428 | // This means that the device won't recognise this library as installed. |
| 2429 | Min_device_sdk *string |
| 2430 | |
| 2431 | // Indicates that PackageManager should ignore this shared library if the |
| 2432 | // platform is above the version indicated in this attribute. |
| 2433 | // |
| 2434 | // This means that the device won't recognise this library as installed. |
| 2435 | Max_device_sdk *string |
Jiakai Zhang | 9c4dc19 | 2023-02-09 00:09:24 +0800 | [diff] [blame] | 2436 | |
| 2437 | DexPreoptProfileGuided *bool `supported_build_releases:"UpsideDownCake+"` |
Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 2438 | } |
| 2439 | |
| 2440 | type scopeProperties struct { |
Paul Duffin | 1fd005d | 2020-04-09 01:08:11 +0100 | [diff] [blame] | 2441 | Jars android.Paths |
| 2442 | StubsSrcJar android.Path |
| 2443 | CurrentApiFile android.Path |
| 2444 | RemovedApiFile android.Path |
Paul Duffin | e7babdb | 2022-02-10 13:06:54 +0000 | [diff] [blame] | 2445 | AnnotationsZip android.Path `supported_build_releases:"Tiramisu+"` |
Paul Duffin | 1fd005d | 2020-04-09 01:08:11 +0100 | [diff] [blame] | 2446 | SdkVersion string |
Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 2447 | } |
| 2448 | |
| 2449 | func (s *sdkLibrarySdkMemberProperties) PopulateFromVariant(ctx android.SdkMemberContext, variant android.Module) { |
| 2450 | sdk := variant.(*SdkLibrary) |
| 2451 | |
Paul Duffin | e840995 | 2022-09-22 16:24:46 +0100 | [diff] [blame] | 2452 | // Copy the stem name for files in the sdk snapshot. |
| 2453 | s.Stem = sdk.distStem() |
| 2454 | |
Paul Duffin | 106a3a4 | 2022-01-27 16:39:06 +0000 | [diff] [blame] | 2455 | s.Scopes = make(map[*apiScope]*scopeProperties) |
Jihoon Kang | 98aa8fa | 2024-06-07 11:06:57 +0000 | [diff] [blame] | 2456 | for _, apiScope := range AllApiScopes { |
Paul Duffin | 803a956 | 2020-05-20 11:52:25 +0100 | [diff] [blame] | 2457 | paths := sdk.findScopePaths(apiScope) |
| 2458 | if paths == nil { |
| 2459 | continue |
| 2460 | } |
| 2461 | |
Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 2462 | jars := paths.stubsImplPath |
| 2463 | if len(jars) > 0 { |
| 2464 | properties := scopeProperties{} |
| 2465 | properties.Jars = jars |
Paul Duffin | 780c5f4 | 2020-05-12 15:52:55 +0100 | [diff] [blame] | 2466 | properties.SdkVersion = sdk.sdkVersionForStubsLibrary(ctx.SdkModuleContext(), apiScope) |
Paul Duffin | 0f8faff | 2020-05-20 16:18:00 +0100 | [diff] [blame] | 2467 | properties.StubsSrcJar = paths.stubsSrcJar.Path() |
Paul Duffin | 10269f1 | 2020-06-19 18:39:55 +0100 | [diff] [blame] | 2468 | if paths.currentApiFilePath.Valid() { |
| 2469 | properties.CurrentApiFile = paths.currentApiFilePath.Path() |
| 2470 | } |
| 2471 | if paths.removedApiFilePath.Valid() { |
| 2472 | properties.RemovedApiFile = paths.removedApiFilePath.Path() |
| 2473 | } |
Anton Hansson | d78eb76 | 2021-09-21 15:25:12 +0100 | [diff] [blame] | 2474 | // The annotations zip is only available for modules that set annotations_enabled: true. |
| 2475 | if paths.annotationsZip.Valid() { |
| 2476 | properties.AnnotationsZip = paths.annotationsZip.Path() |
| 2477 | } |
Paul Duffin | 106a3a4 | 2022-01-27 16:39:06 +0000 | [diff] [blame] | 2478 | s.Scopes[apiScope] = &properties |
Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 2479 | } |
| 2480 | } |
| 2481 | |
Paul Duffin | d7eb1c2 | 2020-05-26 20:57:10 +0100 | [diff] [blame] | 2482 | s.Shared_library = proptools.BoolPtr(sdk.sharedLibrary()) |
Paul Duffin | 1267d87 | 2021-04-16 17:21:36 +0100 | [diff] [blame] | 2483 | s.Compile_dex = sdk.dexProperties.Compile_dex |
Paul Duffin | a2ae7e0 | 2020-09-11 11:55:00 +0100 | [diff] [blame] | 2484 | s.Doctag_paths = sdk.doctagPaths |
Paul Duffin | 869de14 | 2021-07-15 14:14:41 +0100 | [diff] [blame] | 2485 | s.Permitted_packages = sdk.PermittedPackagesForUpdatableBootJars() |
Pedro Loureiro | 9956e5e | 2021-09-07 17:21:59 +0000 | [diff] [blame] | 2486 | s.On_bootclasspath_since = sdk.commonSdkLibraryProperties.On_bootclasspath_since |
| 2487 | s.On_bootclasspath_before = sdk.commonSdkLibraryProperties.On_bootclasspath_before |
| 2488 | s.Min_device_sdk = sdk.commonSdkLibraryProperties.Min_device_sdk |
| 2489 | s.Max_device_sdk = sdk.commonSdkLibraryProperties.Max_device_sdk |
Jiakai Zhang | 9c4dc19 | 2023-02-09 00:09:24 +0800 | [diff] [blame] | 2490 | |
Jihoon Kang | a3a0546 | 2024-04-05 00:36:44 +0000 | [diff] [blame] | 2491 | implLibrary := sdk.getImplLibraryModule() |
| 2492 | if implLibrary != nil && implLibrary.dexpreopter.dexpreoptProperties.Dex_preopt_result.Profile_guided { |
Jiakai Zhang | 9c4dc19 | 2023-02-09 00:09:24 +0800 | [diff] [blame] | 2493 | s.DexPreoptProfileGuided = proptools.BoolPtr(true) |
| 2494 | } |
Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 2495 | } |
| 2496 | |
| 2497 | func (s *sdkLibrarySdkMemberProperties) AddToPropertySet(ctx android.SdkMemberContext, propertySet android.BpPropertySet) { |
Paul Duffin | f7a6433 | 2020-05-13 16:54:55 +0100 | [diff] [blame] | 2498 | if s.Naming_scheme != nil { |
| 2499 | propertySet.AddProperty("naming_scheme", proptools.String(s.Naming_scheme)) |
| 2500 | } |
Paul Duffin | d7eb1c2 | 2020-05-26 20:57:10 +0100 | [diff] [blame] | 2501 | if s.Shared_library != nil { |
| 2502 | propertySet.AddProperty("shared_library", *s.Shared_library) |
| 2503 | } |
Paul Duffin | 1267d87 | 2021-04-16 17:21:36 +0100 | [diff] [blame] | 2504 | if s.Compile_dex != nil { |
| 2505 | propertySet.AddProperty("compile_dex", *s.Compile_dex) |
| 2506 | } |
Paul Duffin | 869de14 | 2021-07-15 14:14:41 +0100 | [diff] [blame] | 2507 | if len(s.Permitted_packages) > 0 { |
| 2508 | propertySet.AddProperty("permitted_packages", s.Permitted_packages) |
| 2509 | } |
Jiakai Zhang | 9c4dc19 | 2023-02-09 00:09:24 +0800 | [diff] [blame] | 2510 | dexPreoptSet := propertySet.AddPropertySet("dex_preopt") |
| 2511 | if s.DexPreoptProfileGuided != nil { |
| 2512 | dexPreoptSet.AddProperty("profile_guided", proptools.Bool(s.DexPreoptProfileGuided)) |
| 2513 | } |
Paul Duffin | f7a6433 | 2020-05-13 16:54:55 +0100 | [diff] [blame] | 2514 | |
Paul Duffin | e840995 | 2022-09-22 16:24:46 +0100 | [diff] [blame] | 2515 | stem := s.Stem |
| 2516 | |
Jihoon Kang | 98aa8fa | 2024-06-07 11:06:57 +0000 | [diff] [blame] | 2517 | for _, apiScope := range AllApiScopes { |
Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 2518 | if properties, ok := s.Scopes[apiScope]; ok { |
Paul Duffin | 6b836ba | 2020-05-13 19:19:49 +0100 | [diff] [blame] | 2519 | scopeSet := propertySet.AddPropertySet(apiScope.propertyName) |
Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 2520 | |
Paul Duffin | 958806b | 2022-05-16 13:10:47 +0000 | [diff] [blame] | 2521 | scopeDir := apiScope.snapshotRelativeDir() |
Paul Duffin | 3d1248c | 2020-04-09 00:10:17 +0100 | [diff] [blame] | 2522 | |
Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 2523 | var jars []string |
| 2524 | for _, p := range properties.Jars { |
Paul Duffin | e840995 | 2022-09-22 16:24:46 +0100 | [diff] [blame] | 2525 | dest := filepath.Join(scopeDir, stem+"-stubs.jar") |
Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 2526 | ctx.SnapshotBuilder().CopyToSnapshot(p, dest) |
| 2527 | jars = append(jars, dest) |
| 2528 | } |
| 2529 | scopeSet.AddProperty("jars", jars) |
| 2530 | |
Paul Duffin | 22628d5 | 2021-05-12 23:13:22 +0100 | [diff] [blame] | 2531 | if ctx.SdkModuleContext().Config().IsEnvTrue("SOONG_SDK_SNAPSHOT_USE_SRCJAR") { |
| 2532 | // Copy the stubs source jar into the snapshot zip as is. |
Paul Duffin | e840995 | 2022-09-22 16:24:46 +0100 | [diff] [blame] | 2533 | srcJarSnapshotPath := filepath.Join(scopeDir, stem+".srcjar") |
Paul Duffin | 22628d5 | 2021-05-12 23:13:22 +0100 | [diff] [blame] | 2534 | ctx.SnapshotBuilder().CopyToSnapshot(properties.StubsSrcJar, srcJarSnapshotPath) |
| 2535 | scopeSet.AddProperty("stub_srcs", []string{srcJarSnapshotPath}) |
| 2536 | } else { |
| 2537 | // Merge the stubs source jar into the snapshot zip so that when it is unpacked |
| 2538 | // the source files are also unpacked. |
Paul Duffin | e840995 | 2022-09-22 16:24:46 +0100 | [diff] [blame] | 2539 | snapshotRelativeDir := filepath.Join(scopeDir, stem+"_stub_sources") |
Paul Duffin | 22628d5 | 2021-05-12 23:13:22 +0100 | [diff] [blame] | 2540 | ctx.SnapshotBuilder().UnzipToSnapshot(properties.StubsSrcJar, snapshotRelativeDir) |
| 2541 | scopeSet.AddProperty("stub_srcs", []string{snapshotRelativeDir}) |
| 2542 | } |
Paul Duffin | 3d1248c | 2020-04-09 00:10:17 +0100 | [diff] [blame] | 2543 | |
Paul Duffin | 1fd005d | 2020-04-09 01:08:11 +0100 | [diff] [blame] | 2544 | if properties.CurrentApiFile != nil { |
Paul Duffin | e840995 | 2022-09-22 16:24:46 +0100 | [diff] [blame] | 2545 | currentApiSnapshotPath := apiScope.snapshotRelativeCurrentApiTxtPath(stem) |
Paul Duffin | 1fd005d | 2020-04-09 01:08:11 +0100 | [diff] [blame] | 2546 | ctx.SnapshotBuilder().CopyToSnapshot(properties.CurrentApiFile, currentApiSnapshotPath) |
| 2547 | scopeSet.AddProperty("current_api", currentApiSnapshotPath) |
| 2548 | } |
| 2549 | |
| 2550 | if properties.RemovedApiFile != nil { |
Paul Duffin | e840995 | 2022-09-22 16:24:46 +0100 | [diff] [blame] | 2551 | removedApiSnapshotPath := apiScope.snapshotRelativeRemovedApiTxtPath(stem) |
Paul Duffin | 3dbf9fd | 2020-06-02 13:00:02 +0100 | [diff] [blame] | 2552 | ctx.SnapshotBuilder().CopyToSnapshot(properties.RemovedApiFile, removedApiSnapshotPath) |
Paul Duffin | 1fd005d | 2020-04-09 01:08:11 +0100 | [diff] [blame] | 2553 | scopeSet.AddProperty("removed_api", removedApiSnapshotPath) |
| 2554 | } |
| 2555 | |
Anton Hansson | d78eb76 | 2021-09-21 15:25:12 +0100 | [diff] [blame] | 2556 | if properties.AnnotationsZip != nil { |
Paul Duffin | e840995 | 2022-09-22 16:24:46 +0100 | [diff] [blame] | 2557 | annotationsSnapshotPath := filepath.Join(scopeDir, stem+"_annotations.zip") |
Anton Hansson | d78eb76 | 2021-09-21 15:25:12 +0100 | [diff] [blame] | 2558 | ctx.SnapshotBuilder().CopyToSnapshot(properties.AnnotationsZip, annotationsSnapshotPath) |
| 2559 | scopeSet.AddProperty("annotations", annotationsSnapshotPath) |
| 2560 | } |
| 2561 | |
Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 2562 | if properties.SdkVersion != "" { |
| 2563 | scopeSet.AddProperty("sdk_version", properties.SdkVersion) |
| 2564 | } |
| 2565 | } |
| 2566 | } |
| 2567 | |
Paul Duffin | a2ae7e0 | 2020-09-11 11:55:00 +0100 | [diff] [blame] | 2568 | if len(s.Doctag_paths) > 0 { |
| 2569 | dests := []string{} |
| 2570 | for _, p := range s.Doctag_paths { |
| 2571 | dest := filepath.Join("doctags", p.Rel()) |
| 2572 | ctx.SnapshotBuilder().CopyToSnapshot(p, dest) |
| 2573 | dests = append(dests, dest) |
| 2574 | } |
| 2575 | propertySet.AddProperty("doctag_files", dests) |
| 2576 | } |
Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 2577 | } |
Spandan Das | dee1a74 | 2024-08-09 17:37:25 +0000 | [diff] [blame] | 2578 | |
| 2579 | // 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] | 2580 | func (s *SdkLibrary) IDEInfo(ctx android.BaseModuleContext, dpInfo *android.IdeInfo) { |
| 2581 | s.Library.IDEInfo(ctx, dpInfo) |
Spandan Das | dee1a74 | 2024-08-09 17:37:25 +0000 | [diff] [blame] | 2582 | if s.implLibraryModule != nil { |
| 2583 | dpInfo.Deps = append(dpInfo.Deps, s.implLibraryModule.Name()) |
| 2584 | } else { |
| 2585 | // This java_sdk_library does not have an implementation (it sets `api_only` to true). |
| 2586 | // Examples of this are `art.module.intra.core.api` (IntraCore api surface). |
| 2587 | // Return the "public" stubs for these. |
| 2588 | stubPaths := s.findClosestScopePath(apiScopePublic) |
| 2589 | if len(stubPaths.stubsHeaderPath) > 0 { |
| 2590 | dpInfo.Jars = append(dpInfo.Jars, stubPaths.stubsHeaderPath[0].String()) |
| 2591 | } |
| 2592 | } |
| 2593 | } |