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