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