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