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 { |
| 676 | if ctx.OtherModuleHasProvider(dep, JavaInfoProvider) { |
| 677 | lib := ctx.OtherModuleProvider(dep, JavaInfoProvider).(JavaInfo) |
| 678 | paths.stubsHeaderPath = lib.HeaderJars |
| 679 | paths.stubsImplPath = lib.ImplementationJars |
Paul Duffin | 1267d87 | 2021-04-16 17:21:36 +0100 | [diff] [blame] | 680 | |
| 681 | libDep := dep.(UsesLibraryDependency) |
| 682 | paths.stubsDexJarPath = libDep.DexJarBuildPath() |
Paul Duffin | c878250 | 2020-04-29 20:45:27 +0100 | [diff] [blame] | 683 | return nil |
| 684 | } else { |
Colin Cross | dcf71b2 | 2021-02-01 13:59:03 -0800 | [diff] [blame] | 685 | return fmt.Errorf("expected module that has JavaInfoProvider, e.g. java_library") |
Paul Duffin | c878250 | 2020-04-29 20:45:27 +0100 | [diff] [blame] | 686 | } |
| 687 | } |
| 688 | |
Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 689 | func (paths *scopePaths) treatDepAsApiStubsProvider(dep android.Module, action func(provider ApiStubsProvider)) error { |
| 690 | if apiStubsProvider, ok := dep.(ApiStubsProvider); ok { |
| 691 | action(apiStubsProvider) |
Paul Duffin | c878250 | 2020-04-29 20:45:27 +0100 | [diff] [blame] | 692 | return nil |
| 693 | } else { |
| 694 | return fmt.Errorf("expected module that implements ApiStubsProvider, e.g. droidstubs") |
| 695 | } |
| 696 | } |
| 697 | |
Paul Duffin | 0f8faff | 2020-05-20 16:18:00 +0100 | [diff] [blame] | 698 | func (paths *scopePaths) treatDepAsApiStubsSrcProvider(dep android.Module, action func(provider ApiStubsSrcProvider)) error { |
| 699 | if apiStubsProvider, ok := dep.(ApiStubsSrcProvider); ok { |
| 700 | action(apiStubsProvider) |
| 701 | return nil |
| 702 | } else { |
| 703 | return fmt.Errorf("expected module that implements ApiStubsSrcProvider, e.g. droidstubs") |
| 704 | } |
| 705 | } |
| 706 | |
Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 707 | func (paths *scopePaths) extractApiInfoFromApiStubsProvider(provider ApiStubsProvider) { |
Anton Hansson | d78eb76 | 2021-09-21 15:25:12 +0100 | [diff] [blame] | 708 | paths.annotationsZip = android.OptionalPathForPath(provider.AnnotationsZip()) |
Paul Duffin | 0f8faff | 2020-05-20 16:18:00 +0100 | [diff] [blame] | 709 | paths.currentApiFilePath = android.OptionalPathForPath(provider.ApiFilePath()) |
| 710 | paths.removedApiFilePath = android.OptionalPathForPath(provider.RemovedApiFilePath()) |
Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 711 | } |
| 712 | |
Colin Cross | dcf71b2 | 2021-02-01 13:59:03 -0800 | [diff] [blame] | 713 | func (paths *scopePaths) extractApiInfoFromDep(ctx android.ModuleContext, dep android.Module) error { |
Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 714 | return paths.treatDepAsApiStubsProvider(dep, func(provider ApiStubsProvider) { |
| 715 | paths.extractApiInfoFromApiStubsProvider(provider) |
| 716 | }) |
| 717 | } |
| 718 | |
Paul Duffin | 0f8faff | 2020-05-20 16:18:00 +0100 | [diff] [blame] | 719 | func (paths *scopePaths) extractStubsSourceInfoFromApiStubsProviders(provider ApiStubsSrcProvider) { |
| 720 | paths.stubsSrcJar = android.OptionalPathForPath(provider.StubsSrcJar()) |
Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 721 | } |
| 722 | |
Colin Cross | dcf71b2 | 2021-02-01 13:59:03 -0800 | [diff] [blame] | 723 | func (paths *scopePaths) extractStubsSourceInfoFromDep(ctx android.ModuleContext, dep android.Module) error { |
Paul Duffin | 0f8faff | 2020-05-20 16:18:00 +0100 | [diff] [blame] | 724 | return paths.treatDepAsApiStubsSrcProvider(dep, func(provider ApiStubsSrcProvider) { |
Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 725 | paths.extractStubsSourceInfoFromApiStubsProviders(provider) |
| 726 | }) |
| 727 | } |
| 728 | |
Colin Cross | dcf71b2 | 2021-02-01 13:59:03 -0800 | [diff] [blame] | 729 | func (paths *scopePaths) extractStubsSourceAndApiInfoFromApiStubsProvider(ctx android.ModuleContext, dep android.Module) error { |
Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 730 | return paths.treatDepAsApiStubsProvider(dep, func(provider ApiStubsProvider) { |
| 731 | paths.extractApiInfoFromApiStubsProvider(provider) |
| 732 | paths.extractStubsSourceInfoFromApiStubsProviders(provider) |
| 733 | }) |
| 734 | } |
| 735 | |
Paul Duffin | 958806b | 2022-05-16 13:10:47 +0000 | [diff] [blame] | 736 | func extractSingleOptionalOutputPath(dep android.Module) (android.OptionalPath, error) { |
| 737 | var paths android.Paths |
| 738 | if sourceFileProducer, ok := dep.(android.SourceFileProducer); ok { |
| 739 | paths = sourceFileProducer.Srcs() |
| 740 | } else { |
| 741 | return android.OptionalPath{}, fmt.Errorf("module %q does not produce source files", dep) |
| 742 | } |
| 743 | if len(paths) != 1 { |
| 744 | return android.OptionalPath{}, fmt.Errorf("expected one path from %q, got %q", dep, paths) |
| 745 | } |
| 746 | return android.OptionalPathForPath(paths[0]), nil |
| 747 | } |
| 748 | |
| 749 | func (paths *scopePaths) extractLatestApiPath(ctx android.ModuleContext, dep android.Module) error { |
| 750 | outputPath, err := extractSingleOptionalOutputPath(dep) |
| 751 | paths.latestApiPath = outputPath |
| 752 | return err |
| 753 | } |
| 754 | |
| 755 | func (paths *scopePaths) extractLatestRemovedApiPath(ctx android.ModuleContext, dep android.Module) error { |
| 756 | outputPath, err := extractSingleOptionalOutputPath(dep) |
| 757 | paths.latestRemovedApiPath = outputPath |
| 758 | return err |
| 759 | } |
| 760 | |
Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 761 | type commonToSdkLibraryAndImportProperties struct { |
Paul Duffin | 1b1e806 | 2020-05-08 13:44:43 +0100 | [diff] [blame] | 762 | // The naming scheme to use for the components that this module creates. |
| 763 | // |
Paul Duffin | ee9ad5d | 2020-09-11 13:04:05 +0100 | [diff] [blame] | 764 | // If not specified then it defaults to "default". |
Paul Duffin | 1b1e806 | 2020-05-08 13:44:43 +0100 | [diff] [blame] | 765 | // |
| 766 | // This is a temporary mechanism to simplify conversion from separate modules for each |
| 767 | // component that follow a different naming pattern to the default one. |
| 768 | // |
| 769 | // TODO(b/155480189) - Remove once naming inconsistencies have been resolved. |
Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 770 | Naming_scheme *string |
Paul Duffin | dfa131e | 2020-05-15 20:37:11 +0100 | [diff] [blame] | 771 | |
| 772 | // Specifies whether this module can be used as an Android shared library; defaults |
| 773 | // to true. |
| 774 | // |
| 775 | // An Android shared library is one that can be referenced in a <uses-library> element |
| 776 | // in an AndroidManifest.xml. |
| 777 | Shared_library *bool |
Paul Duffin | a2ae7e0 | 2020-09-11 11:55:00 +0100 | [diff] [blame] | 778 | |
| 779 | // Files containing information about supported java doc tags. |
| 780 | Doctag_files []string `android:"path"` |
Pedro Loureiro | 9956e5e | 2021-09-07 17:21:59 +0000 | [diff] [blame] | 781 | |
| 782 | // Signals that this shared library is part of the bootclasspath starting |
| 783 | // on the version indicated in this attribute. |
| 784 | // |
| 785 | // This will make platforms at this level and above to ignore |
| 786 | // <uses-library> tags with this library name because the library is already |
| 787 | // available |
| 788 | On_bootclasspath_since *string |
| 789 | |
| 790 | // Signals that this shared library was part of the bootclasspath before |
| 791 | // (but not including) the version indicated in this attribute. |
| 792 | // |
| 793 | // The system will automatically add a <uses-library> tag with this library to |
| 794 | // apps that target any SDK less than the version indicated in this attribute. |
| 795 | On_bootclasspath_before *string |
| 796 | |
| 797 | // Indicates that PackageManager should ignore this shared library if the |
| 798 | // platform is below the version indicated in this attribute. |
| 799 | // |
| 800 | // This means that the device won't recognise this library as installed. |
| 801 | Min_device_sdk *string |
| 802 | |
| 803 | // Indicates that PackageManager should ignore this shared library if the |
| 804 | // platform is above the version indicated in this attribute. |
| 805 | // |
| 806 | // This means that the device won't recognise this library as installed. |
| 807 | Max_device_sdk *string |
Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 808 | } |
| 809 | |
Paul Duffin | 71b33cc | 2021-06-23 11:39:47 +0100 | [diff] [blame] | 810 | // commonSdkLibraryAndImportModule defines the interface that must be provided by a module that |
| 811 | // embeds the commonToSdkLibraryAndImport struct. |
| 812 | type commonSdkLibraryAndImportModule interface { |
Paul Duffin | d796f6f | 2022-11-23 23:06:05 +0000 | [diff] [blame] | 813 | android.Module |
Paul Duffin | 71b33cc | 2021-06-23 11:39:47 +0100 | [diff] [blame] | 814 | |
| 815 | BaseModuleName() string |
| 816 | } |
| 817 | |
Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 818 | // Common code between sdk library and sdk library import |
| 819 | type commonToSdkLibraryAndImport struct { |
Paul Duffin | 71b33cc | 2021-06-23 11:39:47 +0100 | [diff] [blame] | 820 | module commonSdkLibraryAndImportModule |
Paul Duffin | c3091c8 | 2020-05-08 14:16:20 +0100 | [diff] [blame] | 821 | |
Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 822 | scopePaths map[*apiScope]*scopePaths |
Paul Duffin | 1b1e806 | 2020-05-08 13:44:43 +0100 | [diff] [blame] | 823 | |
| 824 | namingScheme sdkLibraryComponentNamingScheme |
| 825 | |
Paul Duffin | dfa131e | 2020-05-15 20:37:11 +0100 | [diff] [blame] | 826 | commonSdkLibraryProperties commonToSdkLibraryAndImportProperties |
Paul Duffin | 859fe96 | 2020-05-15 10:20:31 +0100 | [diff] [blame] | 827 | |
Paul Duffin | a2ae7e0 | 2020-09-11 11:55:00 +0100 | [diff] [blame] | 828 | // Paths to commonSdkLibraryProperties.Doctag_files |
| 829 | doctagPaths android.Paths |
| 830 | |
Paul Duffin | 859fe96 | 2020-05-15 10:20:31 +0100 | [diff] [blame] | 831 | // Functionality related to this being used as a component of a java_sdk_library. |
| 832 | EmbeddableSdkLibraryComponent |
Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 833 | } |
| 834 | |
Paul Duffin | 71b33cc | 2021-06-23 11:39:47 +0100 | [diff] [blame] | 835 | func (c *commonToSdkLibraryAndImport) initCommon(module commonSdkLibraryAndImportModule) { |
| 836 | c.module = module |
Paul Duffin | 1b1e806 | 2020-05-08 13:44:43 +0100 | [diff] [blame] | 837 | |
Paul Duffin | 71b33cc | 2021-06-23 11:39:47 +0100 | [diff] [blame] | 838 | module.AddProperties(&c.commonSdkLibraryProperties) |
Paul Duffin | 859fe96 | 2020-05-15 10:20:31 +0100 | [diff] [blame] | 839 | |
| 840 | // Initialize this as an sdk library component. |
Paul Duffin | 71b33cc | 2021-06-23 11:39:47 +0100 | [diff] [blame] | 841 | c.initSdkLibraryComponent(module) |
Paul Duffin | 1b1e806 | 2020-05-08 13:44:43 +0100 | [diff] [blame] | 842 | } |
| 843 | |
| 844 | func (c *commonToSdkLibraryAndImport) initCommonAfterDefaultsApplied(ctx android.DefaultableHookContext) bool { |
Paul Duffin | dfa131e | 2020-05-15 20:37:11 +0100 | [diff] [blame] | 845 | schemeProperty := proptools.StringDefault(c.commonSdkLibraryProperties.Naming_scheme, "default") |
Paul Duffin | 1b1e806 | 2020-05-08 13:44:43 +0100 | [diff] [blame] | 846 | switch schemeProperty { |
| 847 | case "default": |
| 848 | c.namingScheme = &defaultNamingScheme{} |
| 849 | default: |
| 850 | ctx.PropertyErrorf("naming_scheme", "expected 'default' but was %q", schemeProperty) |
| 851 | return false |
| 852 | } |
| 853 | |
Paul Duffin | 3f0290e | 2021-06-30 18:25:36 +0100 | [diff] [blame] | 854 | namePtr := proptools.StringPtr(c.module.BaseModuleName()) |
| 855 | c.sdkLibraryComponentProperties.SdkLibraryName = namePtr |
| 856 | |
Paul Duffin | dfa131e | 2020-05-15 20:37:11 +0100 | [diff] [blame] | 857 | // Only track this sdk library if this can be used as a shared library. |
| 858 | if c.sharedLibrary() { |
| 859 | // Use the name specified in the module definition as the owner. |
Paul Duffin | 3f0290e | 2021-06-30 18:25:36 +0100 | [diff] [blame] | 860 | c.sdkLibraryComponentProperties.SdkLibraryToImplicitlyTrack = namePtr |
Paul Duffin | dfa131e | 2020-05-15 20:37:11 +0100 | [diff] [blame] | 861 | } |
Paul Duffin | 859fe96 | 2020-05-15 10:20:31 +0100 | [diff] [blame] | 862 | |
Paul Duffin | 1b1e806 | 2020-05-08 13:44:43 +0100 | [diff] [blame] | 863 | return true |
Paul Duffin | c3091c8 | 2020-05-08 14:16:20 +0100 | [diff] [blame] | 864 | } |
| 865 | |
Paul Duffin | ea8f808 | 2021-06-24 13:25:57 +0100 | [diff] [blame] | 866 | // uniqueApexVariations provides common implementation of the ApexModule.UniqueApexVariations |
| 867 | // method. |
| 868 | func (c *commonToSdkLibraryAndImport) uniqueApexVariations() bool { |
| 869 | // A java_sdk_library that is a shared library produces an XML file that makes the shared library |
| 870 | // usable from an AndroidManifest.xml's <uses-library> entry. That XML file contains the name of |
| 871 | // the APEX and so it needs a unique variation per APEX. |
| 872 | return c.sharedLibrary() |
| 873 | } |
| 874 | |
Paul Duffin | a2ae7e0 | 2020-09-11 11:55:00 +0100 | [diff] [blame] | 875 | func (c *commonToSdkLibraryAndImport) generateCommonBuildActions(ctx android.ModuleContext) { |
| 876 | c.doctagPaths = android.PathsForModuleSrc(ctx, c.commonSdkLibraryProperties.Doctag_files) |
| 877 | } |
| 878 | |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 879 | // Module name of the runtime implementation library |
| 880 | func (c *commonToSdkLibraryAndImport) implLibraryModuleName() string { |
Paul Duffin | 71b33cc | 2021-06-23 11:39:47 +0100 | [diff] [blame] | 881 | return c.module.BaseModuleName() + ".impl" |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 882 | } |
| 883 | |
| 884 | // Module name of the XML file for the lib |
| 885 | func (c *commonToSdkLibraryAndImport) xmlPermissionsModuleName() string { |
Paul Duffin | 71b33cc | 2021-06-23 11:39:47 +0100 | [diff] [blame] | 886 | return c.module.BaseModuleName() + sdkXmlFileSuffix |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 887 | } |
| 888 | |
Paul Duffin | c3091c8 | 2020-05-08 14:16:20 +0100 | [diff] [blame] | 889 | // Name of the java_library module that compiles the stubs source. |
| 890 | func (c *commonToSdkLibraryAndImport) stubsLibraryModuleName(apiScope *apiScope) string { |
Paul Duffin | b97b157 | 2021-04-29 21:50:40 +0100 | [diff] [blame] | 891 | baseName := c.module.BaseModuleName() |
Paul Duffin | 2178762 | 2022-11-25 12:48:20 +0000 | [diff] [blame] | 892 | return c.namingScheme.stubsLibraryModuleName(apiScope, baseName) |
Paul Duffin | c3091c8 | 2020-05-08 14:16:20 +0100 | [diff] [blame] | 893 | } |
| 894 | |
| 895 | // Name of the droidstubs module that generates the stubs source and may also |
| 896 | // generate/check the API. |
| 897 | func (c *commonToSdkLibraryAndImport) stubsSourceModuleName(apiScope *apiScope) string { |
Paul Duffin | b97b157 | 2021-04-29 21:50:40 +0100 | [diff] [blame] | 898 | baseName := c.module.BaseModuleName() |
Paul Duffin | 2178762 | 2022-11-25 12:48:20 +0000 | [diff] [blame] | 899 | return c.namingScheme.stubsSourceModuleName(apiScope, baseName) |
Paul Duffin | c3091c8 | 2020-05-08 14:16:20 +0100 | [diff] [blame] | 900 | } |
| 901 | |
Jihoon Kang | 1c92c3e | 2023-03-23 17:44:51 +0000 | [diff] [blame] | 902 | // Name of the java_api_library module that generates the from-text stubs source |
| 903 | // and compiles to a jar file. |
| 904 | func (c *commonToSdkLibraryAndImport) apiLibraryModuleName(apiScope *apiScope) string { |
| 905 | baseName := c.module.BaseModuleName() |
| 906 | return c.namingScheme.apiLibraryModuleName(apiScope, baseName) |
| 907 | } |
| 908 | |
Jihoon Kang | 1147b31 | 2023-06-08 23:25:57 +0000 | [diff] [blame] | 909 | // Name of the java_library module that compiles the stubs |
| 910 | // generated from source Java files. |
| 911 | func (c *commonToSdkLibraryAndImport) sourceStubLibraryModuleName(apiScope *apiScope) string { |
| 912 | baseName := c.module.BaseModuleName() |
| 913 | return c.namingScheme.sourceStubLibraryModuleName(apiScope, baseName) |
| 914 | } |
| 915 | |
Paul Duffin | 46dc45a | 2020-05-14 15:39:10 +0100 | [diff] [blame] | 916 | // The component names for different outputs of the java_sdk_library. |
| 917 | // |
| 918 | // They are similar to the names used for the child modules it creates |
| 919 | const ( |
| 920 | stubsSourceComponentName = "stubs.source" |
| 921 | |
| 922 | apiTxtComponentName = "api.txt" |
| 923 | |
| 924 | removedApiTxtComponentName = "removed-api.txt" |
Anton Hansson | d78eb76 | 2021-09-21 15:25:12 +0100 | [diff] [blame] | 925 | |
| 926 | annotationsComponentName = "annotations.zip" |
Paul Duffin | 46dc45a | 2020-05-14 15:39:10 +0100 | [diff] [blame] | 927 | ) |
| 928 | |
| 929 | // A regular expression to match tags that reference a specific stubs component. |
| 930 | // |
| 931 | // It will only match if given a valid scope and a valid component. It is verfy strict |
| 932 | // to ensure it does not accidentally match a similar looking tag that should be processed |
| 933 | // by the embedded Library. |
| 934 | var tagSplitter = func() *regexp.Regexp { |
| 935 | // Given a list of literal string items returns a regular expression that will |
| 936 | // match any one of the items. |
| 937 | choice := func(items ...string) string { |
| 938 | return `\Q` + strings.Join(items, `\E|\Q`) + `\E` |
| 939 | } |
| 940 | |
| 941 | // Regular expression to match one of the scopes. |
| 942 | scopesRegexp := choice(allScopeNames...) |
| 943 | |
| 944 | // Regular expression to match one of the components. |
Anton Hansson | d78eb76 | 2021-09-21 15:25:12 +0100 | [diff] [blame] | 945 | componentsRegexp := choice(stubsSourceComponentName, apiTxtComponentName, removedApiTxtComponentName, annotationsComponentName) |
Paul Duffin | 46dc45a | 2020-05-14 15:39:10 +0100 | [diff] [blame] | 946 | |
| 947 | // Regular expression to match any combination of one scope and one component. |
| 948 | return regexp.MustCompile(fmt.Sprintf(`^\.(%s)\.(%s)$`, scopesRegexp, componentsRegexp)) |
| 949 | }() |
| 950 | |
| 951 | // For OutputFileProducer interface |
| 952 | // |
Anton Hansson | d78eb76 | 2021-09-21 15:25:12 +0100 | [diff] [blame] | 953 | // .<scope>.<component name>, for all ComponentNames (for example: .public.removed-api.txt) |
Paul Duffin | 46dc45a | 2020-05-14 15:39:10 +0100 | [diff] [blame] | 954 | func (c *commonToSdkLibraryAndImport) commonOutputFiles(tag string) (android.Paths, error) { |
| 955 | if groups := tagSplitter.FindStringSubmatch(tag); groups != nil { |
| 956 | scopeName := groups[1] |
| 957 | component := groups[2] |
| 958 | |
| 959 | if scope, ok := scopeByName[scopeName]; ok { |
| 960 | paths := c.findScopePaths(scope) |
| 961 | if paths == nil { |
Paul Duffin | 71b33cc | 2021-06-23 11:39:47 +0100 | [diff] [blame] | 962 | 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] | 963 | } |
| 964 | |
| 965 | switch component { |
| 966 | case stubsSourceComponentName: |
| 967 | if paths.stubsSrcJar.Valid() { |
| 968 | return android.Paths{paths.stubsSrcJar.Path()}, nil |
| 969 | } |
| 970 | |
| 971 | case apiTxtComponentName: |
| 972 | if paths.currentApiFilePath.Valid() { |
| 973 | return android.Paths{paths.currentApiFilePath.Path()}, nil |
| 974 | } |
| 975 | |
| 976 | case removedApiTxtComponentName: |
| 977 | if paths.removedApiFilePath.Valid() { |
| 978 | return android.Paths{paths.removedApiFilePath.Path()}, nil |
| 979 | } |
Anton Hansson | d78eb76 | 2021-09-21 15:25:12 +0100 | [diff] [blame] | 980 | |
| 981 | case annotationsComponentName: |
| 982 | if paths.annotationsZip.Valid() { |
| 983 | return android.Paths{paths.annotationsZip.Path()}, nil |
| 984 | } |
Paul Duffin | 46dc45a | 2020-05-14 15:39:10 +0100 | [diff] [blame] | 985 | } |
| 986 | |
| 987 | return nil, fmt.Errorf("%s not available for api scope %s", component, scopeName) |
| 988 | } else { |
| 989 | return nil, fmt.Errorf("unknown scope %s in %s", scope, tag) |
| 990 | } |
| 991 | |
| 992 | } else { |
Paul Duffin | a2ae7e0 | 2020-09-11 11:55:00 +0100 | [diff] [blame] | 993 | switch tag { |
| 994 | case ".doctags": |
| 995 | if c.doctagPaths != nil { |
| 996 | return c.doctagPaths, nil |
| 997 | } else { |
Paul Duffin | 71b33cc | 2021-06-23 11:39:47 +0100 | [diff] [blame] | 998 | 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] | 999 | } |
| 1000 | } |
Paul Duffin | 46dc45a | 2020-05-14 15:39:10 +0100 | [diff] [blame] | 1001 | return nil, nil |
| 1002 | } |
| 1003 | } |
| 1004 | |
Paul Duffin | 803a956 | 2020-05-20 11:52:25 +0100 | [diff] [blame] | 1005 | func (c *commonToSdkLibraryAndImport) getScopePathsCreateIfNeeded(scope *apiScope) *scopePaths { |
Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 1006 | if c.scopePaths == nil { |
| 1007 | c.scopePaths = make(map[*apiScope]*scopePaths) |
| 1008 | } |
| 1009 | paths := c.scopePaths[scope] |
| 1010 | if paths == nil { |
| 1011 | paths = &scopePaths{} |
| 1012 | c.scopePaths[scope] = paths |
| 1013 | } |
| 1014 | |
| 1015 | return paths |
| 1016 | } |
| 1017 | |
Paul Duffin | 803a956 | 2020-05-20 11:52:25 +0100 | [diff] [blame] | 1018 | func (c *commonToSdkLibraryAndImport) findScopePaths(scope *apiScope) *scopePaths { |
| 1019 | if c.scopePaths == nil { |
| 1020 | return nil |
| 1021 | } |
| 1022 | |
| 1023 | return c.scopePaths[scope] |
| 1024 | } |
| 1025 | |
| 1026 | // If this does not support the requested api scope then find the closest available |
| 1027 | // scope it does support. Returns nil if no such scope is available. |
| 1028 | func (c *commonToSdkLibraryAndImport) findClosestScopePath(scope *apiScope) *scopePaths { |
Paul Duffin | d0b9fca | 2022-09-30 18:11:41 +0100 | [diff] [blame] | 1029 | for s := scope; s != nil; s = s.canAccess { |
Paul Duffin | 803a956 | 2020-05-20 11:52:25 +0100 | [diff] [blame] | 1030 | if paths := c.findScopePaths(s); paths != nil { |
| 1031 | return paths |
| 1032 | } |
| 1033 | } |
| 1034 | |
| 1035 | // This should never happen outside tests as public should be the base scope for every |
| 1036 | // scope and is enabled by default. |
| 1037 | return nil |
| 1038 | } |
| 1039 | |
Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 1040 | func (c *commonToSdkLibraryAndImport) selectHeaderJarsForSdkVersion(ctx android.BaseModuleContext, sdkVersion android.SdkSpec) android.Paths { |
Paul Duffin | b05d429 | 2020-05-20 12:19:10 +0100 | [diff] [blame] | 1041 | |
| 1042 | // 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] | 1043 | if !sdkVersion.ApiLevel.IsPreview() { |
Paul Duffin | 71b33cc | 2021-06-23 11:39:47 +0100 | [diff] [blame] | 1044 | return PrebuiltJars(ctx, c.module.BaseModuleName(), sdkVersion) |
Paul Duffin | b05d429 | 2020-05-20 12:19:10 +0100 | [diff] [blame] | 1045 | } |
| 1046 | |
Paul Duffin | 1267d87 | 2021-04-16 17:21:36 +0100 | [diff] [blame] | 1047 | paths := c.selectScopePaths(ctx, sdkVersion.Kind) |
| 1048 | if paths == nil { |
| 1049 | return nil |
| 1050 | } |
| 1051 | |
| 1052 | return paths.stubsHeaderPath |
| 1053 | } |
| 1054 | |
| 1055 | // selectScopePaths returns the *scopePaths appropriate for the specific kind. |
| 1056 | // |
| 1057 | // If the module does not support the specific kind then it will return the *scopePaths for the |
| 1058 | // closest kind which is a subset of the requested kind. e.g. if requesting android.SdkModule then |
| 1059 | // it will return *scopePaths for android.SdkSystem if available or android.SdkPublic of not. |
| 1060 | func (c *commonToSdkLibraryAndImport) selectScopePaths(ctx android.BaseModuleContext, kind android.SdkKind) *scopePaths { |
Paul Duffin | 32cf58a | 2021-05-18 16:32:50 +0100 | [diff] [blame] | 1061 | apiScope := sdkKindToApiScope(kind) |
Paul Duffin | b05d429 | 2020-05-20 12:19:10 +0100 | [diff] [blame] | 1062 | |
Paul Duffin | 803a956 | 2020-05-20 11:52:25 +0100 | [diff] [blame] | 1063 | paths := c.findClosestScopePath(apiScope) |
| 1064 | if paths == nil { |
| 1065 | var scopes []string |
| 1066 | for _, s := range allApiScopes { |
| 1067 | if c.findScopePaths(s) != nil { |
| 1068 | scopes = append(scopes, s.name) |
| 1069 | } |
| 1070 | } |
Paul Duffin | 71b33cc | 2021-06-23 11:39:47 +0100 | [diff] [blame] | 1071 | 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] | 1072 | return nil |
| 1073 | } |
| 1074 | |
Paul Duffin | 1267d87 | 2021-04-16 17:21:36 +0100 | [diff] [blame] | 1075 | return paths |
| 1076 | } |
| 1077 | |
Paul Duffin | 32cf58a | 2021-05-18 16:32:50 +0100 | [diff] [blame] | 1078 | // sdkKindToApiScope maps from android.SdkKind to apiScope. |
| 1079 | func sdkKindToApiScope(kind android.SdkKind) *apiScope { |
| 1080 | var apiScope *apiScope |
| 1081 | switch kind { |
| 1082 | case android.SdkSystem: |
| 1083 | apiScope = apiScopeSystem |
| 1084 | case android.SdkModule: |
| 1085 | apiScope = apiScopeModuleLib |
| 1086 | case android.SdkTest: |
| 1087 | apiScope = apiScopeTest |
| 1088 | case android.SdkSystemServer: |
| 1089 | apiScope = apiScopeSystemServer |
| 1090 | default: |
| 1091 | apiScope = apiScopePublic |
| 1092 | } |
| 1093 | return apiScope |
| 1094 | } |
| 1095 | |
Paul Duffin | 1267d87 | 2021-04-16 17:21:36 +0100 | [diff] [blame] | 1096 | // to satisfy SdkLibraryDependency interface |
Martin Stjernholm | 8be1e6d | 2021-09-15 03:34:04 +0100 | [diff] [blame] | 1097 | func (c *commonToSdkLibraryAndImport) SdkApiStubDexJar(ctx android.BaseModuleContext, kind android.SdkKind) OptionalDexJarPath { |
Paul Duffin | 1267d87 | 2021-04-16 17:21:36 +0100 | [diff] [blame] | 1098 | paths := c.selectScopePaths(ctx, kind) |
| 1099 | if paths == nil { |
Martin Stjernholm | 8be1e6d | 2021-09-15 03:34:04 +0100 | [diff] [blame] | 1100 | return makeUnsetDexJarPath() |
Paul Duffin | 1267d87 | 2021-04-16 17:21:36 +0100 | [diff] [blame] | 1101 | } |
| 1102 | |
| 1103 | return paths.stubsDexJarPath |
Paul Duffin | b05d429 | 2020-05-20 12:19:10 +0100 | [diff] [blame] | 1104 | } |
| 1105 | |
Paul Duffin | 32cf58a | 2021-05-18 16:32:50 +0100 | [diff] [blame] | 1106 | // to satisfy SdkLibraryDependency interface |
| 1107 | func (c *commonToSdkLibraryAndImport) SdkRemovedTxtFile(ctx android.BaseModuleContext, kind android.SdkKind) android.OptionalPath { |
| 1108 | apiScope := sdkKindToApiScope(kind) |
| 1109 | paths := c.findScopePaths(apiScope) |
| 1110 | if paths == nil { |
| 1111 | return android.OptionalPath{} |
| 1112 | } |
| 1113 | |
| 1114 | return paths.removedApiFilePath |
| 1115 | } |
| 1116 | |
Paul Duffin | 859fe96 | 2020-05-15 10:20:31 +0100 | [diff] [blame] | 1117 | func (c *commonToSdkLibraryAndImport) sdkComponentPropertiesForChildLibrary() interface{} { |
| 1118 | componentProps := &struct { |
Paul Duffin | 3f0290e | 2021-06-30 18:25:36 +0100 | [diff] [blame] | 1119 | SdkLibraryName *string |
Paul Duffin | 859fe96 | 2020-05-15 10:20:31 +0100 | [diff] [blame] | 1120 | SdkLibraryToImplicitlyTrack *string |
Paul Duffin | dfa131e | 2020-05-15 20:37:11 +0100 | [diff] [blame] | 1121 | }{} |
| 1122 | |
Paul Duffin | 3f0290e | 2021-06-30 18:25:36 +0100 | [diff] [blame] | 1123 | namePtr := proptools.StringPtr(c.module.BaseModuleName()) |
| 1124 | componentProps.SdkLibraryName = namePtr |
| 1125 | |
Paul Duffin | dfa131e | 2020-05-15 20:37:11 +0100 | [diff] [blame] | 1126 | if c.sharedLibrary() { |
Paul Duffin | 859fe96 | 2020-05-15 10:20:31 +0100 | [diff] [blame] | 1127 | // Mark the stubs library as being components of this java_sdk_library so that |
| 1128 | // any app that includes code which depends (directly or indirectly) on the stubs |
| 1129 | // library will have the appropriate <uses-library> invocation inserted into its |
| 1130 | // manifest if necessary. |
Paul Duffin | 3f0290e | 2021-06-30 18:25:36 +0100 | [diff] [blame] | 1131 | componentProps.SdkLibraryToImplicitlyTrack = namePtr |
Paul Duffin | 859fe96 | 2020-05-15 10:20:31 +0100 | [diff] [blame] | 1132 | } |
| 1133 | |
| 1134 | return componentProps |
| 1135 | } |
| 1136 | |
Paul Duffin | dfa131e | 2020-05-15 20:37:11 +0100 | [diff] [blame] | 1137 | func (c *commonToSdkLibraryAndImport) sharedLibrary() bool { |
| 1138 | return proptools.BoolDefault(c.commonSdkLibraryProperties.Shared_library, true) |
| 1139 | } |
| 1140 | |
Paul Duffin | f4600f6 | 2021-05-13 22:34:45 +0100 | [diff] [blame] | 1141 | // Check if the stub libraries should be compiled for dex |
| 1142 | func (c *commonToSdkLibraryAndImport) stubLibrariesCompiledForDex() bool { |
| 1143 | // Always compile the dex file files for the stub libraries if they will be used on the |
| 1144 | // bootclasspath. |
| 1145 | return !c.sharedLibrary() |
| 1146 | } |
| 1147 | |
Paul Duffin | 859fe96 | 2020-05-15 10:20:31 +0100 | [diff] [blame] | 1148 | // Properties related to the use of a module as an component of a java_sdk_library. |
| 1149 | type SdkLibraryComponentProperties struct { |
Paul Duffin | 3f0290e | 2021-06-30 18:25:36 +0100 | [diff] [blame] | 1150 | // The name of the java_sdk_library/_import module. |
| 1151 | SdkLibraryName *string `blueprint:"mutated"` |
Paul Duffin | 859fe96 | 2020-05-15 10:20:31 +0100 | [diff] [blame] | 1152 | |
| 1153 | // The name of the java_sdk_library/_import to add to a <uses-library> entry |
| 1154 | // in the AndroidManifest.xml of any Android app that includes code that references |
| 1155 | // this module. If not set then no java_sdk_library/_import is tracked. |
| 1156 | SdkLibraryToImplicitlyTrack *string `blueprint:"mutated"` |
| 1157 | } |
| 1158 | |
| 1159 | // Structure to be embedded in a module struct that needs to support the |
| 1160 | // SdkLibraryComponentDependency interface. |
| 1161 | type EmbeddableSdkLibraryComponent struct { |
| 1162 | sdkLibraryComponentProperties SdkLibraryComponentProperties |
| 1163 | } |
| 1164 | |
Paul Duffin | 71b33cc | 2021-06-23 11:39:47 +0100 | [diff] [blame] | 1165 | func (e *EmbeddableSdkLibraryComponent) initSdkLibraryComponent(module android.Module) { |
| 1166 | module.AddProperties(&e.sdkLibraryComponentProperties) |
Paul Duffin | 859fe96 | 2020-05-15 10:20:31 +0100 | [diff] [blame] | 1167 | } |
| 1168 | |
| 1169 | // to satisfy SdkLibraryComponentDependency |
Paul Duffin | 3f0290e | 2021-06-30 18:25:36 +0100 | [diff] [blame] | 1170 | func (e *EmbeddableSdkLibraryComponent) SdkLibraryName() *string { |
| 1171 | return e.sdkLibraryComponentProperties.SdkLibraryName |
| 1172 | } |
| 1173 | |
| 1174 | // to satisfy SdkLibraryComponentDependency |
Ulya Trafimovich | 39b437b | 2020-09-23 16:42:35 +0100 | [diff] [blame] | 1175 | func (e *EmbeddableSdkLibraryComponent) OptionalSdkLibraryImplementation() *string { |
Ulya Trafimovich | 78645fb | 2021-07-16 15:29:25 +0100 | [diff] [blame] | 1176 | // For shared libraries, this is the same as the SDK library name. If a Java library or app |
| 1177 | // depends on a component library (e.g. a stub library) it still needs to know the name of the |
| 1178 | // run-time library and the corresponding module that provides the implementation. This name is |
| 1179 | // passed to manifest_fixer (to be added to AndroidManifest.xml) and added to CLC (to be used |
| 1180 | // in dexpreopt). |
| 1181 | // |
| 1182 | // For non-shared SDK (component or not) libraries this returns `nil`, as they are not |
| 1183 | // <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] | 1184 | return e.sdkLibraryComponentProperties.SdkLibraryToImplicitlyTrack |
| 1185 | } |
| 1186 | |
Paul Duffin | 859fe96 | 2020-05-15 10:20:31 +0100 | [diff] [blame] | 1187 | // Implemented by modules that are (or possibly could be) a component of a java_sdk_library |
| 1188 | // (including the java_sdk_library) itself. |
| 1189 | type SdkLibraryComponentDependency interface { |
Ulya Trafimovich | 31e444e | 2020-08-14 17:32:16 +0100 | [diff] [blame] | 1190 | UsesLibraryDependency |
| 1191 | |
Paul Duffin | 3f0290e | 2021-06-30 18:25:36 +0100 | [diff] [blame] | 1192 | // SdkLibraryName returns the name of the java_sdk_library/_import module. |
| 1193 | SdkLibraryName() *string |
| 1194 | |
Ulya Trafimovich | 39b437b | 2020-09-23 16:42:35 +0100 | [diff] [blame] | 1195 | // The name of the implementation library for the optional SDK library or nil, if there isn't one. |
| 1196 | OptionalSdkLibraryImplementation() *string |
Paul Duffin | 859fe96 | 2020-05-15 10:20:31 +0100 | [diff] [blame] | 1197 | } |
| 1198 | |
| 1199 | // Make sure that all the module types that are components of java_sdk_library/_import |
| 1200 | // and which can be referenced (directly or indirectly) from an android app implement |
| 1201 | // the SdkLibraryComponentDependency interface. |
| 1202 | var _ SdkLibraryComponentDependency = (*Library)(nil) |
| 1203 | var _ SdkLibraryComponentDependency = (*Import)(nil) |
| 1204 | var _ SdkLibraryComponentDependency = (*SdkLibrary)(nil) |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 1205 | var _ SdkLibraryComponentDependency = (*SdkLibraryImport)(nil) |
Paul Duffin | 859fe96 | 2020-05-15 10:20:31 +0100 | [diff] [blame] | 1206 | |
Paul Duffin | 32cf58a | 2021-05-18 16:32:50 +0100 | [diff] [blame] | 1207 | // 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] | 1208 | type SdkLibraryDependency interface { |
| 1209 | SdkLibraryComponentDependency |
| 1210 | |
| 1211 | // Get the header jars appropriate for the supplied sdk_version. |
| 1212 | // |
| 1213 | // These are turbine generated jars so they only change if the externals of the |
| 1214 | // class changes but it does not contain and implementation or JavaDoc. |
Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 1215 | SdkHeaderJars(ctx android.BaseModuleContext, sdkVersion android.SdkSpec) android.Paths |
Paul Duffin | 859fe96 | 2020-05-15 10:20:31 +0100 | [diff] [blame] | 1216 | |
| 1217 | // Get the implementation jars appropriate for the supplied sdk version. |
| 1218 | // |
| 1219 | // These are either the implementation jar for the whole sdk library or the implementation |
| 1220 | // jars for the stubs. The latter should only be needed when generating JavaDoc as otherwise |
| 1221 | // they are identical to the corresponding header jars. |
Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 1222 | SdkImplementationJars(ctx android.BaseModuleContext, sdkVersion android.SdkSpec) android.Paths |
Paul Duffin | 1267d87 | 2021-04-16 17:21:36 +0100 | [diff] [blame] | 1223 | |
| 1224 | // SdkApiStubDexJar returns the dex jar for the stubs. It is needed by the hiddenapi processing |
| 1225 | // tool which processes dex files. |
Martin Stjernholm | 8be1e6d | 2021-09-15 03:34:04 +0100 | [diff] [blame] | 1226 | SdkApiStubDexJar(ctx android.BaseModuleContext, kind android.SdkKind) OptionalDexJarPath |
Paul Duffin | f4600f6 | 2021-05-13 22:34:45 +0100 | [diff] [blame] | 1227 | |
Paul Duffin | 32cf58a | 2021-05-18 16:32:50 +0100 | [diff] [blame] | 1228 | // SdkRemovedTxtFile returns the optional path to the removed.txt file for the specified sdk kind. |
| 1229 | SdkRemovedTxtFile(ctx android.BaseModuleContext, kind android.SdkKind) android.OptionalPath |
| 1230 | |
Paul Duffin | f4600f6 | 2021-05-13 22:34:45 +0100 | [diff] [blame] | 1231 | // sharedLibrary returns true if this can be used as a shared library. |
| 1232 | sharedLibrary() bool |
Paul Duffin | 859fe96 | 2020-05-15 10:20:31 +0100 | [diff] [blame] | 1233 | } |
| 1234 | |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 1235 | type SdkLibrary struct { |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 1236 | Library |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1237 | |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 1238 | sdkLibraryProperties sdkLibraryProperties |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1239 | |
Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 1240 | // Map from api scope to the scope specific property structure. |
| 1241 | scopeToProperties map[*apiScope]*ApiScopeProperties |
| 1242 | |
Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 1243 | commonToSdkLibraryAndImport |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1244 | } |
| 1245 | |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 1246 | var _ SdkLibraryDependency = (*SdkLibrary)(nil) |
Colin Cross | 897d2ed | 2019-02-11 14:03:51 -0800 | [diff] [blame] | 1247 | |
Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 1248 | func (module *SdkLibrary) generateTestAndSystemScopesByDefault() bool { |
| 1249 | return module.sdkLibraryProperties.Generate_system_and_test_apis |
| 1250 | } |
| 1251 | |
| 1252 | func (module *SdkLibrary) getGeneratedApiScopes(ctx android.EarlyModuleContext) apiScopes { |
| 1253 | // Check to see if any scopes have been explicitly enabled. If any have then all |
| 1254 | // must be. |
| 1255 | anyScopesExplicitlyEnabled := false |
| 1256 | for _, scope := range allApiScopes { |
| 1257 | scopeProperties := module.scopeToProperties[scope] |
| 1258 | if scopeProperties.Enabled != nil { |
| 1259 | anyScopesExplicitlyEnabled = true |
| 1260 | break |
| 1261 | } |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 1262 | } |
Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 1263 | |
| 1264 | var generatedScopes apiScopes |
| 1265 | enabledScopes := make(map[*apiScope]struct{}) |
| 1266 | for _, scope := range allApiScopes { |
| 1267 | scopeProperties := module.scopeToProperties[scope] |
| 1268 | // If any scopes are explicitly enabled then ignore the legacy enabled status. |
| 1269 | // This is to ensure that any new usages of this module type do not rely on legacy |
| 1270 | // behaviour. |
| 1271 | defaultEnabledStatus := false |
| 1272 | if anyScopesExplicitlyEnabled { |
| 1273 | defaultEnabledStatus = scope.defaultEnabledStatus |
| 1274 | } else { |
| 1275 | defaultEnabledStatus = scope.legacyEnabledStatus(module) |
| 1276 | } |
| 1277 | enabled := proptools.BoolDefault(scopeProperties.Enabled, defaultEnabledStatus) |
| 1278 | if enabled { |
| 1279 | enabledScopes[scope] = struct{}{} |
| 1280 | generatedScopes = append(generatedScopes, scope) |
| 1281 | } |
| 1282 | } |
| 1283 | |
| 1284 | // Now check to make sure that any scope that is extended by an enabled scope is also |
| 1285 | // enabled. |
| 1286 | for _, scope := range allApiScopes { |
| 1287 | if _, ok := enabledScopes[scope]; ok { |
| 1288 | extends := scope.extends |
| 1289 | if extends != nil { |
| 1290 | if _, ok := enabledScopes[extends]; !ok { |
| 1291 | ctx.ModuleErrorf("enabled api scope %q depends on disabled scope %q", scope, extends) |
| 1292 | } |
| 1293 | } |
| 1294 | } |
| 1295 | } |
| 1296 | |
| 1297 | return generatedScopes |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 1298 | } |
| 1299 | |
satayev | 758968a | 2021-12-06 11:42:40 +0000 | [diff] [blame] | 1300 | var _ android.ModuleWithMinSdkVersionCheck = (*SdkLibrary)(nil) |
| 1301 | |
satayev | 8f088b0 | 2021-12-06 11:40:46 +0000 | [diff] [blame] | 1302 | func (module *SdkLibrary) CheckMinSdkVersion(ctx android.ModuleContext) { |
Spandan Das | 8c9ae7e | 2023-03-03 21:20:36 +0000 | [diff] [blame] | 1303 | android.CheckMinSdkVersion(ctx, module.MinSdkVersion(ctx), func(c android.ModuleContext, do android.PayloadDepsCallback) { |
satayev | 8f088b0 | 2021-12-06 11:40:46 +0000 | [diff] [blame] | 1304 | ctx.WalkDeps(func(child android.Module, parent android.Module) bool { |
| 1305 | isExternal := !module.depIsInSameApex(ctx, child) |
| 1306 | if am, ok := child.(android.ApexModule); ok { |
| 1307 | if !do(ctx, parent, am, isExternal) { |
| 1308 | return false |
| 1309 | } |
| 1310 | } |
| 1311 | return !isExternal |
| 1312 | }) |
| 1313 | }) |
| 1314 | } |
| 1315 | |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 1316 | type sdkLibraryComponentTag struct { |
| 1317 | blueprint.BaseDependencyTag |
| 1318 | name string |
| 1319 | } |
| 1320 | |
| 1321 | // Mark this tag so dependencies that use it are excluded from visibility enforcement. |
| 1322 | func (t sdkLibraryComponentTag) ExcludeFromVisibilityEnforcement() {} |
| 1323 | |
| 1324 | var xmlPermissionsFileTag = sdkLibraryComponentTag{name: "xml-permissions-file"} |
Paul Duffin | e74ac73 | 2020-02-06 13:51:46 +0000 | [diff] [blame] | 1325 | |
Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 1326 | func IsXmlPermissionsFileDepTag(depTag blueprint.DependencyTag) bool { |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 1327 | if dt, ok := depTag.(sdkLibraryComponentTag); ok { |
Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 1328 | return dt == xmlPermissionsFileTag |
| 1329 | } |
| 1330 | return false |
| 1331 | } |
| 1332 | |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 1333 | var implLibraryTag = sdkLibraryComponentTag{name: "impl-library"} |
Paul Duffin | 5df7930 | 2020-05-16 15:52:12 +0100 | [diff] [blame] | 1334 | |
Paul Duffin | 44f1d84 | 2020-06-26 20:17:02 +0100 | [diff] [blame] | 1335 | // Add the dependencies on the child modules in the component deps mutator. |
| 1336 | func (module *SdkLibrary) ComponentDepsMutator(ctx android.BottomUpMutatorContext) { |
Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 1337 | for _, apiScope := range module.getGeneratedApiScopes(ctx) { |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 1338 | // Add dependencies to the stubs library |
Spandan Das | 877f39d | 2023-03-29 16:19:51 +0000 | [diff] [blame] | 1339 | stubModuleName := module.stubsLibraryModuleName(apiScope) |
Jihoon Kang | 1147b31 | 2023-06-08 23:25:57 +0000 | [diff] [blame] | 1340 | |
Spandan Das | 877f39d | 2023-03-29 16:19:51 +0000 | [diff] [blame] | 1341 | ctx.AddVariationDependencies(nil, apiScope.stubsTag, stubModuleName) |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 1342 | |
Paul Duffin | 15f34ef | 2020-07-20 18:04:44 +0100 | [diff] [blame] | 1343 | // Add a dependency on the stubs source in order to access both stubs source and api information. |
| 1344 | ctx.AddVariationDependencies(nil, apiScope.stubsSourceAndApiTag, module.stubsSourceModuleName(apiScope)) |
Paul Duffin | 958806b | 2022-05-16 13:10:47 +0000 | [diff] [blame] | 1345 | |
| 1346 | if module.compareAgainstLatestApi(apiScope) { |
| 1347 | // Add dependencies on the latest finalized version of the API .txt file. |
| 1348 | latestApiModuleName := module.latestApiModuleName(apiScope) |
| 1349 | ctx.AddDependency(module, apiScope.latestApiModuleTag, latestApiModuleName) |
| 1350 | |
| 1351 | // Add dependencies on the latest finalized version of the remove API .txt file. |
| 1352 | latestRemovedApiModuleName := module.latestRemovedApiModuleName(apiScope) |
| 1353 | ctx.AddDependency(module, apiScope.latestRemovedApiModuleTag, latestRemovedApiModuleName) |
| 1354 | } |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 1355 | } |
| 1356 | |
Paul Duffin | dfa131e | 2020-05-15 20:37:11 +0100 | [diff] [blame] | 1357 | if module.requiresRuntimeImplementationLibrary() { |
Paul Duffin | 5df7930 | 2020-05-16 15:52:12 +0100 | [diff] [blame] | 1358 | // Add dependency to the rule for generating the implementation library. |
| 1359 | ctx.AddDependency(module, implLibraryTag, module.implLibraryModuleName()) |
| 1360 | |
Paul Duffin | dfa131e | 2020-05-15 20:37:11 +0100 | [diff] [blame] | 1361 | if module.sharedLibrary() { |
| 1362 | // Add dependency to the rule for generating the xml permissions file |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 1363 | ctx.AddDependency(module, xmlPermissionsFileTag, module.xmlPermissionsModuleName()) |
Paul Duffin | dfa131e | 2020-05-15 20:37:11 +0100 | [diff] [blame] | 1364 | } |
Paul Duffin | 44f1d84 | 2020-06-26 20:17:02 +0100 | [diff] [blame] | 1365 | } |
| 1366 | } |
Paul Duffin | e74ac73 | 2020-02-06 13:51:46 +0000 | [diff] [blame] | 1367 | |
Paul Duffin | 44f1d84 | 2020-06-26 20:17:02 +0100 | [diff] [blame] | 1368 | // Add other dependencies as normal. |
| 1369 | func (module *SdkLibrary) DepsMutator(ctx android.BottomUpMutatorContext) { |
Anton Hansson | e77fccc | 2021-01-20 16:52:41 +0000 | [diff] [blame] | 1370 | var missingApiModules []string |
| 1371 | for _, apiScope := range module.getGeneratedApiScopes(ctx) { |
| 1372 | if apiScope.unstable { |
| 1373 | continue |
| 1374 | } |
Paul Duffin | 958806b | 2022-05-16 13:10:47 +0000 | [diff] [blame] | 1375 | if m := module.latestApiModuleName(apiScope); !ctx.OtherModuleExists(m) { |
Anton Hansson | e77fccc | 2021-01-20 16:52:41 +0000 | [diff] [blame] | 1376 | missingApiModules = append(missingApiModules, m) |
| 1377 | } |
Paul Duffin | 958806b | 2022-05-16 13:10:47 +0000 | [diff] [blame] | 1378 | if m := module.latestRemovedApiModuleName(apiScope); !ctx.OtherModuleExists(m) { |
Anton Hansson | e77fccc | 2021-01-20 16:52:41 +0000 | [diff] [blame] | 1379 | missingApiModules = append(missingApiModules, m) |
| 1380 | } |
Paul Duffin | 958806b | 2022-05-16 13:10:47 +0000 | [diff] [blame] | 1381 | if m := module.latestIncompatibilitiesModuleName(apiScope); !ctx.OtherModuleExists(m) { |
Jaewoong Jung | 1a97ee0 | 2021-03-09 13:25:02 -0800 | [diff] [blame] | 1382 | missingApiModules = append(missingApiModules, m) |
| 1383 | } |
Anton Hansson | e77fccc | 2021-01-20 16:52:41 +0000 | [diff] [blame] | 1384 | } |
| 1385 | if len(missingApiModules) != 0 && !module.sdkLibraryProperties.Unsafe_ignore_missing_latest_api { |
| 1386 | m := module.Name() + " is missing tracking files for previously released library versions.\n" |
| 1387 | m += "You need to do one of the following:\n" |
| 1388 | m += "- Add `unsafe_ignore_missing_latest_api: true` to your blueprint (to disable compat tracking)\n" |
| 1389 | m += "- Add a set of prebuilt txt files representing the last released version of this library for compat checking.\n" |
| 1390 | m += " (the current set of API files can be used as a seed for this compatibility tracking\n" |
| 1391 | m += "\n" |
| 1392 | m += "The following filegroup modules are missing:\n " |
| 1393 | m += strings.Join(missingApiModules, "\n ") + "\n" |
| 1394 | 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." |
| 1395 | ctx.ModuleErrorf(m) |
| 1396 | } |
Paul Duffin | 44f1d84 | 2020-06-26 20:17:02 +0100 | [diff] [blame] | 1397 | if module.requiresRuntimeImplementationLibrary() { |
Paul Duffin | dfa131e | 2020-05-15 20:37:11 +0100 | [diff] [blame] | 1398 | // Only add the deps for the library if it is actually going to be built. |
| 1399 | module.Library.deps(ctx) |
| 1400 | } |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1401 | } |
| 1402 | |
Paul Duffin | 46dc45a | 2020-05-14 15:39:10 +0100 | [diff] [blame] | 1403 | func (module *SdkLibrary) OutputFiles(tag string) (android.Paths, error) { |
| 1404 | paths, err := module.commonOutputFiles(tag) |
Colin Cross | 4acaea9 | 2021-12-10 23:05:02 +0000 | [diff] [blame] | 1405 | if paths != nil || err != nil { |
Paul Duffin | 46dc45a | 2020-05-14 15:39:10 +0100 | [diff] [blame] | 1406 | return paths, err |
| 1407 | } |
Colin Cross | 4acaea9 | 2021-12-10 23:05:02 +0000 | [diff] [blame] | 1408 | if module.requiresRuntimeImplementationLibrary() { |
| 1409 | return module.Library.OutputFiles(tag) |
| 1410 | } |
| 1411 | if tag == "" { |
| 1412 | return nil, nil |
| 1413 | } |
| 1414 | return nil, fmt.Errorf("unsupported module reference tag %q", tag) |
Paul Duffin | 46dc45a | 2020-05-14 15:39:10 +0100 | [diff] [blame] | 1415 | } |
| 1416 | |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 1417 | func (module *SdkLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
satayev | 8f088b0 | 2021-12-06 11:40:46 +0000 | [diff] [blame] | 1418 | if proptools.String(module.deviceProperties.Min_sdk_version) != "" { |
| 1419 | module.CheckMinSdkVersion(ctx) |
| 1420 | } |
| 1421 | |
Paul Duffin | a2ae7e0 | 2020-09-11 11:55:00 +0100 | [diff] [blame] | 1422 | module.generateCommonBuildActions(ctx) |
| 1423 | |
Paul Duffin | dfa131e | 2020-05-15 20:37:11 +0100 | [diff] [blame] | 1424 | // Only build an implementation library if required. |
| 1425 | if module.requiresRuntimeImplementationLibrary() { |
Paul Duffin | 43db9be | 2019-12-30 17:35:49 +0000 | [diff] [blame] | 1426 | module.Library.GenerateAndroidBuildActions(ctx) |
| 1427 | } |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 1428 | |
Paul Duffin | b97b157 | 2021-04-29 21:50:40 +0100 | [diff] [blame] | 1429 | // Collate the components exported by this module. All scope specific modules are exported but |
| 1430 | // the impl and xml component modules are not. |
| 1431 | exportedComponents := map[string]struct{}{} |
| 1432 | |
Sundong Ahn | 57368eb | 2018-07-06 11:20:23 +0900 | [diff] [blame] | 1433 | // 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] | 1434 | // 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] | 1435 | // the recorded paths will be returned depending on the link type of the caller. |
| 1436 | ctx.VisitDirectDeps(func(to android.Module) { |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1437 | tag := ctx.OtherModuleDependencyTag(to) |
| 1438 | |
Paul Duffin | c878250 | 2020-04-29 20:45:27 +0100 | [diff] [blame] | 1439 | // Extract information from any of the scope specific dependencies. |
| 1440 | if scopeTag, ok := tag.(scopeDependencyTag); ok { |
| 1441 | apiScope := scopeTag.apiScope |
Paul Duffin | 803a956 | 2020-05-20 11:52:25 +0100 | [diff] [blame] | 1442 | scopePaths := module.getScopePathsCreateIfNeeded(apiScope) |
Paul Duffin | c878250 | 2020-04-29 20:45:27 +0100 | [diff] [blame] | 1443 | |
| 1444 | // Extract information from the dependency. The exact information extracted |
| 1445 | // is determined by the nature of the dependency which is determined by the tag. |
| 1446 | scopeTag.extractDepInfo(ctx, to, scopePaths) |
Paul Duffin | b97b157 | 2021-04-29 21:50:40 +0100 | [diff] [blame] | 1447 | |
| 1448 | exportedComponents[ctx.OtherModuleName(to)] = struct{}{} |
Sundong Ahn | 20e998b | 2018-07-24 11:19:26 +0900 | [diff] [blame] | 1449 | } |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1450 | }) |
Paul Duffin | b97b157 | 2021-04-29 21:50:40 +0100 | [diff] [blame] | 1451 | |
| 1452 | // 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] | 1453 | exportedComponentInfo := android.ExportedComponentsInfo{Components: android.SortedKeys(exportedComponents)} |
Paul Duffin | b97b157 | 2021-04-29 21:50:40 +0100 | [diff] [blame] | 1454 | ctx.SetProvider(android.ExportedComponentsInfoProvider, exportedComponentInfo) |
Paul Duffin | 958806b | 2022-05-16 13:10:47 +0000 | [diff] [blame] | 1455 | |
| 1456 | // Provide additional information for inclusion in an sdk's generated .info file. |
| 1457 | additionalSdkInfo := map[string]interface{}{} |
| 1458 | additionalSdkInfo["dist_stem"] = module.distStem() |
Paul Duffin | e840995 | 2022-09-22 16:24:46 +0100 | [diff] [blame] | 1459 | baseModuleName := module.distStem() |
Paul Duffin | 958806b | 2022-05-16 13:10:47 +0000 | [diff] [blame] | 1460 | scopes := map[string]interface{}{} |
| 1461 | additionalSdkInfo["scopes"] = scopes |
| 1462 | for scope, scopePaths := range module.scopePaths { |
| 1463 | scopeInfo := map[string]interface{}{} |
| 1464 | scopes[scope.name] = scopeInfo |
| 1465 | scopeInfo["current_api"] = scope.snapshotRelativeCurrentApiTxtPath(baseModuleName) |
| 1466 | scopeInfo["removed_api"] = scope.snapshotRelativeRemovedApiTxtPath(baseModuleName) |
| 1467 | if p := scopePaths.latestApiPath; p.Valid() { |
| 1468 | scopeInfo["latest_api"] = p.Path().String() |
| 1469 | } |
| 1470 | if p := scopePaths.latestRemovedApiPath; p.Valid() { |
| 1471 | scopeInfo["latest_removed_api"] = p.Path().String() |
| 1472 | } |
| 1473 | } |
| 1474 | ctx.SetProvider(android.AdditionalSdkInfoProvider, android.AdditionalSdkInfo{additionalSdkInfo}) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1475 | } |
| 1476 | |
Jiyong Park | 0b0e1b9 | 2019-12-03 13:24:29 +0900 | [diff] [blame] | 1477 | func (module *SdkLibrary) AndroidMkEntries() []android.AndroidMkEntries { |
Paul Duffin | dfa131e | 2020-05-15 20:37:11 +0100 | [diff] [blame] | 1478 | if !module.requiresRuntimeImplementationLibrary() { |
Paul Duffin | 43db9be | 2019-12-30 17:35:49 +0000 | [diff] [blame] | 1479 | return nil |
| 1480 | } |
Jiyong Park | 0b0e1b9 | 2019-12-03 13:24:29 +0900 | [diff] [blame] | 1481 | entriesList := module.Library.AndroidMkEntries() |
Yo Chiang | 07d7507 | 2020-06-05 17:43:19 +0800 | [diff] [blame] | 1482 | if module.sharedLibrary() { |
| 1483 | entries := &entriesList[0] |
| 1484 | entries.Required = append(entries.Required, module.xmlPermissionsModuleName()) |
| 1485 | } |
Jiyong Park | 0b0e1b9 | 2019-12-03 13:24:29 +0900 | [diff] [blame] | 1486 | return entriesList |
Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 1487 | } |
| 1488 | |
Anton Hansson | 5fd5d24 | 2020-03-27 19:43:19 +0000 | [diff] [blame] | 1489 | // The dist path of the stub artifacts |
| 1490 | func (module *SdkLibrary) apiDistPath(apiScope *apiScope) string { |
Colin Cross | f0eace9 | 2021-06-02 13:02:23 -0700 | [diff] [blame] | 1491 | return path.Join("apistubs", module.distGroup(), apiScope.name) |
Anton Hansson | 5fd5d24 | 2020-03-27 19:43:19 +0000 | [diff] [blame] | 1492 | } |
| 1493 | |
Paul Duffin | 12ceb46 | 2019-12-24 20:31:31 +0000 | [diff] [blame] | 1494 | // Get the sdk version for use when compiling the stubs library. |
Paul Duffin | 780c5f4 | 2020-05-12 15:52:55 +0100 | [diff] [blame] | 1495 | func (module *SdkLibrary) sdkVersionForStubsLibrary(mctx android.EarlyModuleContext, apiScope *apiScope) string { |
Paul Duffin | 87a05a3 | 2020-05-12 11:50:28 +0100 | [diff] [blame] | 1496 | scopeProperties := module.scopeToProperties[apiScope] |
| 1497 | if scopeProperties.Sdk_version != nil { |
| 1498 | return proptools.String(scopeProperties.Sdk_version) |
| 1499 | } |
| 1500 | |
Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 1501 | sdkDep := decodeSdkDep(mctx, android.SdkContext(&module.Library)) |
Paul Duffin | 12ceb46 | 2019-12-24 20:31:31 +0000 | [diff] [blame] | 1502 | if sdkDep.hasStandardLibs() { |
| 1503 | // 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] | 1504 | return apiScope.sdkVersion |
Paul Duffin | 12ceb46 | 2019-12-24 20:31:31 +0000 | [diff] [blame] | 1505 | } else { |
| 1506 | // Otherwise, use no system module. |
| 1507 | return "none" |
| 1508 | } |
| 1509 | } |
| 1510 | |
Paul Duffin | 3131025 | 2020-11-20 21:26:20 +0000 | [diff] [blame] | 1511 | func (module *SdkLibrary) distStem() string { |
| 1512 | return proptools.StringDefault(module.sdkLibraryProperties.Dist_stem, module.BaseModuleName()) |
| 1513 | } |
| 1514 | |
Colin Cross | 986b69a | 2021-06-01 13:13:40 -0700 | [diff] [blame] | 1515 | // distGroup returns the subdirectory of the dist path of the stub artifacts. |
| 1516 | func (module *SdkLibrary) distGroup() string { |
Colin Cross | 59b92bf | 2021-06-01 14:07:56 -0700 | [diff] [blame] | 1517 | return proptools.StringDefault(module.sdkLibraryProperties.Dist_group, "unknown") |
Colin Cross | 986b69a | 2021-06-01 13:13:40 -0700 | [diff] [blame] | 1518 | } |
| 1519 | |
Paul Duffin | 958806b | 2022-05-16 13:10:47 +0000 | [diff] [blame] | 1520 | func latestPrebuiltApiModuleName(name string, apiScope *apiScope) string { |
| 1521 | return PrebuiltApiModuleName(name, apiScope.name, "latest") |
| 1522 | } |
| 1523 | |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 1524 | func (module *SdkLibrary) latestApiFilegroupName(apiScope *apiScope) string { |
Paul Duffin | 958806b | 2022-05-16 13:10:47 +0000 | [diff] [blame] | 1525 | return ":" + module.latestApiModuleName(apiScope) |
| 1526 | } |
| 1527 | |
| 1528 | func (module *SdkLibrary) latestApiModuleName(apiScope *apiScope) string { |
| 1529 | return latestPrebuiltApiModuleName(module.distStem(), apiScope) |
Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 1530 | } |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1531 | |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 1532 | func (module *SdkLibrary) latestRemovedApiFilegroupName(apiScope *apiScope) string { |
Paul Duffin | 958806b | 2022-05-16 13:10:47 +0000 | [diff] [blame] | 1533 | return ":" + module.latestRemovedApiModuleName(apiScope) |
| 1534 | } |
| 1535 | |
| 1536 | func (module *SdkLibrary) latestRemovedApiModuleName(apiScope *apiScope) string { |
| 1537 | return latestPrebuiltApiModuleName(module.distStem()+"-removed", apiScope) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1538 | } |
| 1539 | |
Jaewoong Jung | 1a97ee0 | 2021-03-09 13:25:02 -0800 | [diff] [blame] | 1540 | func (module *SdkLibrary) latestIncompatibilitiesFilegroupName(apiScope *apiScope) string { |
Paul Duffin | 958806b | 2022-05-16 13:10:47 +0000 | [diff] [blame] | 1541 | return ":" + module.latestIncompatibilitiesModuleName(apiScope) |
| 1542 | } |
| 1543 | |
| 1544 | func (module *SdkLibrary) latestIncompatibilitiesModuleName(apiScope *apiScope) string { |
| 1545 | return latestPrebuiltApiModuleName(module.distStem()+"-incompatibilities", apiScope) |
Jaewoong Jung | 1a97ee0 | 2021-03-09 13:25:02 -0800 | [diff] [blame] | 1546 | } |
| 1547 | |
Jihoon Kang | 1c92c3e | 2023-03-23 17:44:51 +0000 | [diff] [blame] | 1548 | func (module *SdkLibrary) contributesToApiSurface(c android.Config) bool { |
| 1549 | _, exists := c.GetApiLibraries()[module.Name()] |
| 1550 | return exists |
| 1551 | } |
| 1552 | |
Jihoon Kang | 0c705a4 | 2023-08-02 06:44:57 +0000 | [diff] [blame] | 1553 | // The listed modules are the special java_sdk_libraries where apiScope.kind do not match the |
| 1554 | // api surface that the module contribute to. For example, the public droidstubs and java_library |
| 1555 | // do not contribute to the public api surface, but contributes to the core platform api surface. |
| 1556 | // This method returns the full api surface stub lib that |
| 1557 | // the generated java_api_library should depend on. |
| 1558 | func (module *SdkLibrary) alternativeFullApiSurfaceStubLib() string { |
| 1559 | if val, ok := apiLibraryAdditionalProperties[module.Name()]; ok { |
| 1560 | return val.FullApiSurfaceStubLib |
| 1561 | } |
| 1562 | return "" |
| 1563 | } |
| 1564 | |
| 1565 | // The listed modules' stubs contents do not match the corresponding txt files, |
| 1566 | // but require additional api contributions to generate the full stubs. |
| 1567 | // This method returns the name of the additional api contribution module |
| 1568 | // for corresponding sdk_library modules. |
| 1569 | func (module *SdkLibrary) apiLibraryAdditionalApiContribution() string { |
| 1570 | if val, ok := apiLibraryAdditionalProperties[module.Name()]; ok { |
| 1571 | return val.AdditionalApiContribution |
| 1572 | } |
| 1573 | return "" |
| 1574 | } |
| 1575 | |
Anton Hansson | 944e77d | 2020-08-19 11:40:22 +0100 | [diff] [blame] | 1576 | func childModuleVisibility(childVisibility []string) []string { |
| 1577 | if childVisibility == nil { |
| 1578 | // No child visibility set. The child will use the visibility of the sdk_library. |
| 1579 | return nil |
| 1580 | } |
| 1581 | |
| 1582 | // Prepend an override to ignore the sdk_library's visibility, and rely on the child visibility. |
| 1583 | var visibility []string |
| 1584 | visibility = append(visibility, "//visibility:override") |
| 1585 | visibility = append(visibility, childVisibility...) |
| 1586 | return visibility |
| 1587 | } |
| 1588 | |
Paul Duffin | 5df7930 | 2020-05-16 15:52:12 +0100 | [diff] [blame] | 1589 | // Creates the implementation java library |
| 1590 | func (module *SdkLibrary) createImplLibrary(mctx android.DefaultableHookContext) { |
Anton Hansson | 944e77d | 2020-08-19 11:40:22 +0100 | [diff] [blame] | 1591 | visibility := childModuleVisibility(module.sdkLibraryProperties.Impl_library_visibility) |
| 1592 | |
Paul Duffin | 5df7930 | 2020-05-16 15:52:12 +0100 | [diff] [blame] | 1593 | props := struct { |
Paul Duffin | 77590a8 | 2022-04-28 14:13:30 +0000 | [diff] [blame] | 1594 | Name *string |
| 1595 | Visibility []string |
| 1596 | Instrument bool |
| 1597 | Libs []string |
| 1598 | Static_libs []string |
| 1599 | Apex_available []string |
Paul Duffin | 5df7930 | 2020-05-16 15:52:12 +0100 | [diff] [blame] | 1600 | }{ |
| 1601 | Name: proptools.StringPtr(module.implLibraryModuleName()), |
Anton Hansson | 944e77d | 2020-08-19 11:40:22 +0100 | [diff] [blame] | 1602 | Visibility: visibility, |
Paul Duffin | 296cf33 | 2020-06-18 21:09:55 +0100 | [diff] [blame] | 1603 | // Set the instrument property to ensure it is instrumented when instrumentation is required. |
| 1604 | Instrument: true, |
Anton Hansson | 7f66efa | 2020-10-08 14:47:23 +0100 | [diff] [blame] | 1605 | // Set the impl_only libs. Note that the module's "Libs" get appended as well, via the |
| 1606 | // addition of &module.properties below. |
| 1607 | Libs: module.sdkLibraryProperties.Impl_only_libs, |
Paul Duffin | 77590a8 | 2022-04-28 14:13:30 +0000 | [diff] [blame] | 1608 | // Set the impl_only static libs. Note that the module's "static_libs" get appended as well, via the |
| 1609 | // addition of &module.properties below. |
| 1610 | Static_libs: module.sdkLibraryProperties.Impl_only_static_libs, |
| 1611 | // Pass the apex_available settings down so that the impl library can be statically |
| 1612 | // embedded within a library that is added to an APEX. Needed for updatable-media. |
| 1613 | Apex_available: module.ApexAvailable(), |
Paul Duffin | 5df7930 | 2020-05-16 15:52:12 +0100 | [diff] [blame] | 1614 | } |
| 1615 | |
| 1616 | properties := []interface{}{ |
| 1617 | &module.properties, |
| 1618 | &module.protoProperties, |
| 1619 | &module.deviceProperties, |
Liz Kammer | a7a64f3 | 2020-07-09 15:16:41 -0700 | [diff] [blame] | 1620 | &module.dexProperties, |
Paul Duffin | 5df7930 | 2020-05-16 15:52:12 +0100 | [diff] [blame] | 1621 | &module.dexpreoptProperties, |
Colin Cross | 014489c | 2020-06-02 20:09:13 -0700 | [diff] [blame] | 1622 | &module.linter.properties, |
Paul Duffin | 5df7930 | 2020-05-16 15:52:12 +0100 | [diff] [blame] | 1623 | &props, |
| 1624 | module.sdkComponentPropertiesForChildLibrary(), |
| 1625 | } |
| 1626 | mctx.CreateModule(LibraryFactory, properties...) |
| 1627 | } |
| 1628 | |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1629 | // Creates a static java library that has API stubs |
Paul Duffin | f022920 | 2020-04-29 16:47:28 +0100 | [diff] [blame] | 1630 | func (module *SdkLibrary) createStubsLibrary(mctx android.DefaultableHookContext, apiScope *apiScope) { |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1631 | props := struct { |
Dan Willemsen | 9f43597 | 2020-05-28 15:28:00 -0700 | [diff] [blame] | 1632 | Name *string |
| 1633 | Visibility []string |
| 1634 | Srcs []string |
| 1635 | Installable *bool |
| 1636 | Sdk_version *string |
| 1637 | System_modules *string |
| 1638 | Patch_module *string |
| 1639 | Libs []string |
Anton Hansson | dae54cd | 2021-04-21 16:30:10 +0100 | [diff] [blame] | 1640 | Static_libs []string |
Dan Willemsen | 9f43597 | 2020-05-28 15:28:00 -0700 | [diff] [blame] | 1641 | Compile_dex *bool |
| 1642 | Java_version *string |
| 1643 | Openjdk9 struct { |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 1644 | Srcs []string |
| 1645 | Javacflags []string |
| 1646 | } |
Anton Hansson | 5fd5d24 | 2020-03-27 19:43:19 +0000 | [diff] [blame] | 1647 | Dist struct { |
| 1648 | Targets []string |
| 1649 | Dest *string |
| 1650 | Dir *string |
| 1651 | Tag *string |
| 1652 | } |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1653 | }{} |
| 1654 | |
Jihoon Kang | 1147b31 | 2023-06-08 23:25:57 +0000 | [diff] [blame] | 1655 | props.Name = proptools.StringPtr(module.sourceStubLibraryModuleName(apiScope)) |
Jihoon Kang | 786df93 | 2023-09-07 01:18:31 +0000 | [diff] [blame] | 1656 | props.Visibility = []string{"//visibility:override", "//visibility:private"} |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1657 | // sources are generated from the droiddoc |
Paul Duffin | c3091c8 | 2020-05-08 14:16:20 +0100 | [diff] [blame] | 1658 | props.Srcs = []string{":" + module.stubsSourceModuleName(apiScope)} |
Paul Duffin | 12ceb46 | 2019-12-24 20:31:31 +0000 | [diff] [blame] | 1659 | sdkVersion := module.sdkVersionForStubsLibrary(mctx, apiScope) |
Paul Duffin | 52d398a | 2019-06-11 12:31:14 +0100 | [diff] [blame] | 1660 | props.Sdk_version = proptools.StringPtr(sdkVersion) |
Paul Duffin | a18abc2 | 2020-05-16 18:54:24 +0100 | [diff] [blame] | 1661 | props.System_modules = module.deviceProperties.System_modules |
| 1662 | props.Patch_module = module.properties.Patch_module |
Paul Duffin | 367ab91 | 2019-12-23 19:40:36 +0000 | [diff] [blame] | 1663 | props.Installable = proptools.BoolPtr(false) |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 1664 | props.Libs = module.sdkLibraryProperties.Stub_only_libs |
Mark White | 9421c4c | 2023-08-10 00:07:03 +0000 | [diff] [blame] | 1665 | props.Libs = append(props.Libs, module.scopeToProperties[apiScope].Libs...) |
Anton Hansson | dae54cd | 2021-04-21 16:30:10 +0100 | [diff] [blame] | 1666 | props.Static_libs = module.sdkLibraryProperties.Stub_only_static_libs |
Paul Duffin | e22c2ab | 2020-05-20 19:35:27 +0100 | [diff] [blame] | 1667 | // The stub-annotations library contains special versions of the annotations |
| 1668 | // with CLASS retention policy, so that they're kept. |
| 1669 | if proptools.Bool(module.sdkLibraryProperties.Annotations_enabled) { |
| 1670 | props.Libs = append(props.Libs, "stub-annotations") |
| 1671 | } |
Paul Duffin | a18abc2 | 2020-05-16 18:54:24 +0100 | [diff] [blame] | 1672 | props.Openjdk9.Srcs = module.properties.Openjdk9.Srcs |
| 1673 | props.Openjdk9.Javacflags = module.properties.Openjdk9.Javacflags |
Anton Hansson | 83509b5 | 2020-05-21 09:21:57 +0100 | [diff] [blame] | 1674 | // We compile the stubs for 1.8 in line with the main android.jar stubs, and potential |
| 1675 | // interop with older developer tools that don't support 1.9. |
| 1676 | props.Java_version = proptools.StringPtr("1.8") |
Paul Duffin | f4600f6 | 2021-05-13 22:34:45 +0100 | [diff] [blame] | 1677 | |
Paul Duffin | 859fe96 | 2020-05-15 10:20:31 +0100 | [diff] [blame] | 1678 | mctx.CreateModule(LibraryFactory, &props, module.sdkComponentPropertiesForChildLibrary()) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1679 | } |
| 1680 | |
Paul Duffin | 6d0886e | 2020-04-07 18:49:53 +0100 | [diff] [blame] | 1681 | // 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] | 1682 | // files and also updates and checks the API specification files. |
Paul Duffin | 15f34ef | 2020-07-20 18:04:44 +0100 | [diff] [blame] | 1683 | 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] | 1684 | props := struct { |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 1685 | Name *string |
Paul Duffin | 4911a89 | 2020-04-29 23:35:13 +0100 | [diff] [blame] | 1686 | Visibility []string |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 1687 | Srcs []string |
| 1688 | Installable *bool |
Paul Duffin | 52d398a | 2019-06-11 12:31:14 +0100 | [diff] [blame] | 1689 | Sdk_version *string |
Jihoon Kang | 3198f3c | 2023-01-26 08:08:52 +0000 | [diff] [blame] | 1690 | Api_surface *string |
Paul Duffin | 12ceb46 | 2019-12-24 20:31:31 +0000 | [diff] [blame] | 1691 | System_modules *string |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 1692 | Libs []string |
Paul Duffin | 6877e6d | 2020-09-25 19:59:14 +0100 | [diff] [blame] | 1693 | Output_javadoc_comments *bool |
Paul Duffin | 1151247 | 2019-02-11 15:55:17 +0000 | [diff] [blame] | 1694 | Arg_files []string |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 1695 | Args *string |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 1696 | Java_version *string |
Paul Duffin | e22c2ab | 2020-05-20 19:35:27 +0100 | [diff] [blame] | 1697 | Annotations_enabled *bool |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 1698 | Merge_annotations_dirs []string |
| 1699 | Merge_inclusion_annotations_dirs []string |
Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 1700 | Generate_stubs *bool |
Anton Hansson | e87b03d | 2020-12-21 15:29:34 +0000 | [diff] [blame] | 1701 | Previous_api *string |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 1702 | Check_api struct { |
Anton Hansson | e605615 | 2020-12-31 10:37:27 +0000 | [diff] [blame] | 1703 | Current ApiToCheck |
| 1704 | Last_released ApiToCheck |
Paul Duffin | 160fe41 | 2020-05-10 19:32:20 +0100 | [diff] [blame] | 1705 | |
| 1706 | Api_lint struct { |
| 1707 | Enabled *bool |
| 1708 | New_since *string |
| 1709 | Baseline_file *string |
| 1710 | } |
Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 1711 | } |
Sundong Ahn | 1b92c82 | 2018-05-29 11:35:17 +0900 | [diff] [blame] | 1712 | Aidl struct { |
| 1713 | Include_dirs []string |
| 1714 | Local_include_dirs []string |
| 1715 | } |
Paul Duffin | 040e906 | 2020-11-23 17:41:36 +0000 | [diff] [blame] | 1716 | Dists []android.Dist |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1717 | }{} |
| 1718 | |
Paul Duffin | 7b78b4d | 2020-04-28 14:08:32 +0100 | [diff] [blame] | 1719 | // The stubs source processing uses the same compile time classpath when extracting the |
| 1720 | // API from the implementation library as it does when compiling it. i.e. the same |
| 1721 | // * sdk version |
| 1722 | // * system_modules |
| 1723 | // * libs (static_libs/libs) |
Paul Duffin | 250e619 | 2019-06-07 10:44:37 +0100 | [diff] [blame] | 1724 | |
Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 1725 | props.Name = proptools.StringPtr(name) |
Anton Hansson | 944e77d | 2020-08-19 11:40:22 +0100 | [diff] [blame] | 1726 | props.Visibility = childModuleVisibility(module.sdkLibraryProperties.Stubs_source_visibility) |
Paul Duffin | a18abc2 | 2020-05-16 18:54:24 +0100 | [diff] [blame] | 1727 | props.Srcs = append(props.Srcs, module.properties.Srcs...) |
Anton Hansson | f8ea372 | 2021-09-16 14:24:13 +0100 | [diff] [blame] | 1728 | props.Srcs = append(props.Srcs, module.sdkLibraryProperties.Api_srcs...) |
Paul Duffin | a18abc2 | 2020-05-16 18:54:24 +0100 | [diff] [blame] | 1729 | props.Sdk_version = module.deviceProperties.Sdk_version |
Jihoon Kang | 3198f3c | 2023-01-26 08:08:52 +0000 | [diff] [blame] | 1730 | props.Api_surface = &apiScope.name |
Paul Duffin | a18abc2 | 2020-05-16 18:54:24 +0100 | [diff] [blame] | 1731 | props.System_modules = module.deviceProperties.System_modules |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1732 | props.Installable = proptools.BoolPtr(false) |
Sundong Ahn | e6f0b05 | 2018-06-05 16:46:14 +0900 | [diff] [blame] | 1733 | // A droiddoc module has only one Libs property and doesn't distinguish between |
| 1734 | // 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] | 1735 | props.Libs = module.properties.Libs |
| 1736 | props.Libs = append(props.Libs, module.properties.Static_libs...) |
Nikita Ioffe | d732da7 | 2022-11-21 12:38:25 +0000 | [diff] [blame] | 1737 | props.Libs = append(props.Libs, module.sdkLibraryProperties.Stub_only_libs...) |
Mark White | 9421c4c | 2023-08-10 00:07:03 +0000 | [diff] [blame] | 1738 | props.Libs = append(props.Libs, module.scopeToProperties[apiScope].Libs...) |
Paul Duffin | a18abc2 | 2020-05-16 18:54:24 +0100 | [diff] [blame] | 1739 | props.Aidl.Include_dirs = module.deviceProperties.Aidl.Include_dirs |
| 1740 | props.Aidl.Local_include_dirs = module.deviceProperties.Aidl.Local_include_dirs |
| 1741 | props.Java_version = module.properties.Java_version |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1742 | |
Paul Duffin | e22c2ab | 2020-05-20 19:35:27 +0100 | [diff] [blame] | 1743 | props.Annotations_enabled = module.sdkLibraryProperties.Annotations_enabled |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 1744 | props.Merge_annotations_dirs = module.sdkLibraryProperties.Merge_annotations_dirs |
| 1745 | props.Merge_inclusion_annotations_dirs = module.sdkLibraryProperties.Merge_inclusion_annotations_dirs |
| 1746 | |
Paul Duffin | 6d0886e | 2020-04-07 18:49:53 +0100 | [diff] [blame] | 1747 | droidstubsArgs := []string{} |
Paul Duffin | 235ffff | 2019-12-24 10:41:30 +0000 | [diff] [blame] | 1748 | if len(module.sdkLibraryProperties.Api_packages) != 0 { |
Paul Duffin | 6d0886e | 2020-04-07 18:49:53 +0100 | [diff] [blame] | 1749 | droidstubsArgs = append(droidstubsArgs, "--stub-packages "+strings.Join(module.sdkLibraryProperties.Api_packages, ":")) |
Paul Duffin | 235ffff | 2019-12-24 10:41:30 +0000 | [diff] [blame] | 1750 | } |
| 1751 | if len(module.sdkLibraryProperties.Hidden_api_packages) != 0 { |
Paul Duffin | 6d0886e | 2020-04-07 18:49:53 +0100 | [diff] [blame] | 1752 | droidstubsArgs = append(droidstubsArgs, |
Paul Duffin | 235ffff | 2019-12-24 10:41:30 +0000 | [diff] [blame] | 1753 | android.JoinWithPrefix(module.sdkLibraryProperties.Hidden_api_packages, " --hide-package ")) |
| 1754 | } |
Paul Duffin | 6d0886e | 2020-04-07 18:49:53 +0100 | [diff] [blame] | 1755 | droidstubsArgs = append(droidstubsArgs, module.sdkLibraryProperties.Droiddoc_options...) |
Anton Hansson | fd1c0d2 | 2023-11-02 15:18:09 +0000 | [diff] [blame] | 1756 | disabledWarnings := []string{"HiddenSuperclass"} |
| 1757 | if proptools.BoolDefault(module.sdkLibraryProperties.Api_lint.Legacy_errors_allowed, true) { |
| 1758 | disabledWarnings = append(disabledWarnings, |
| 1759 | "BroadcastBehavior", |
| 1760 | "DeprecationMismatch", |
| 1761 | "MissingPermission", |
| 1762 | "SdkConstant", |
| 1763 | "Todo", |
| 1764 | ) |
Paul Duffin | 235ffff | 2019-12-24 10:41:30 +0000 | [diff] [blame] | 1765 | } |
Paul Duffin | 6d0886e | 2020-04-07 18:49:53 +0100 | [diff] [blame] | 1766 | droidstubsArgs = append(droidstubsArgs, android.JoinWithPrefix(disabledWarnings, "--hide ")) |
Sundong Ahn | fb2721f | 2018-09-17 13:23:09 +0900 | [diff] [blame] | 1767 | |
Paul Duffin | 6877e6d | 2020-09-25 19:59:14 +0100 | [diff] [blame] | 1768 | // Output Javadoc comments for public scope. |
| 1769 | if apiScope == apiScopePublic { |
| 1770 | props.Output_javadoc_comments = proptools.BoolPtr(true) |
| 1771 | } |
| 1772 | |
Paul Duffin | 1fb487d | 2020-04-07 18:50:10 +0100 | [diff] [blame] | 1773 | // Add in scope specific arguments. |
Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 1774 | droidstubsArgs = append(droidstubsArgs, scopeSpecificDroidstubsArgs...) |
Paul Duffin | 1151247 | 2019-02-11 15:55:17 +0000 | [diff] [blame] | 1775 | props.Arg_files = module.sdkLibraryProperties.Droiddoc_option_files |
Paul Duffin | 6d0886e | 2020-04-07 18:49:53 +0100 | [diff] [blame] | 1776 | props.Args = proptools.StringPtr(strings.Join(droidstubsArgs, " ")) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1777 | |
Paul Duffin | 15f34ef | 2020-07-20 18:04:44 +0100 | [diff] [blame] | 1778 | // List of APIs identified from the provided source files are created. They are later |
| 1779 | // compared against to the not-yet-released (a.k.a current) list of APIs and to the |
| 1780 | // last-released (a.k.a numbered) list of API. |
| 1781 | currentApiFileName := apiScope.apiFilePrefix + "current.txt" |
| 1782 | removedApiFileName := apiScope.apiFilePrefix + "removed.txt" |
| 1783 | apiDir := module.getApiDir() |
| 1784 | currentApiFileName = path.Join(apiDir, currentApiFileName) |
| 1785 | removedApiFileName = path.Join(apiDir, removedApiFileName) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1786 | |
Paul Duffin | 15f34ef | 2020-07-20 18:04:44 +0100 | [diff] [blame] | 1787 | // check against the not-yet-release API |
| 1788 | props.Check_api.Current.Api_file = proptools.StringPtr(currentApiFileName) |
| 1789 | props.Check_api.Current.Removed_api_file = proptools.StringPtr(removedApiFileName) |
Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 1790 | |
Paul Duffin | 958806b | 2022-05-16 13:10:47 +0000 | [diff] [blame] | 1791 | if module.compareAgainstLatestApi(apiScope) { |
Paul Duffin | 15f34ef | 2020-07-20 18:04:44 +0100 | [diff] [blame] | 1792 | // check against the latest released API |
| 1793 | latestApiFilegroupName := proptools.StringPtr(module.latestApiFilegroupName(apiScope)) |
Anton Hansson | e87b03d | 2020-12-21 15:29:34 +0000 | [diff] [blame] | 1794 | props.Previous_api = latestApiFilegroupName |
Paul Duffin | 15f34ef | 2020-07-20 18:04:44 +0100 | [diff] [blame] | 1795 | props.Check_api.Last_released.Api_file = latestApiFilegroupName |
| 1796 | props.Check_api.Last_released.Removed_api_file = proptools.StringPtr( |
| 1797 | module.latestRemovedApiFilegroupName(apiScope)) |
Jaewoong Jung | 1a97ee0 | 2021-03-09 13:25:02 -0800 | [diff] [blame] | 1798 | props.Check_api.Last_released.Baseline_file = proptools.StringPtr( |
| 1799 | module.latestIncompatibilitiesFilegroupName(apiScope)) |
Paul Duffin | 160fe41 | 2020-05-10 19:32:20 +0100 | [diff] [blame] | 1800 | |
Paul Duffin | 15f34ef | 2020-07-20 18:04:44 +0100 | [diff] [blame] | 1801 | if proptools.Bool(module.sdkLibraryProperties.Api_lint.Enabled) { |
| 1802 | // Enable api lint. |
| 1803 | props.Check_api.Api_lint.Enabled = proptools.BoolPtr(true) |
| 1804 | props.Check_api.Api_lint.New_since = latestApiFilegroupName |
Paul Duffin | 160fe41 | 2020-05-10 19:32:20 +0100 | [diff] [blame] | 1805 | |
Paul Duffin | 15f34ef | 2020-07-20 18:04:44 +0100 | [diff] [blame] | 1806 | // If it exists then pass a lint-baseline.txt through to droidstubs. |
| 1807 | baselinePath := path.Join(apiDir, apiScope.apiFilePrefix+"lint-baseline.txt") |
| 1808 | baselinePathRelativeToRoot := path.Join(mctx.ModuleDir(), baselinePath) |
| 1809 | paths, err := mctx.GlobWithDeps(baselinePathRelativeToRoot, nil) |
| 1810 | if err != nil { |
| 1811 | mctx.ModuleErrorf("error checking for presence of %s: %s", baselinePathRelativeToRoot, err) |
| 1812 | } |
| 1813 | if len(paths) == 1 { |
| 1814 | props.Check_api.Api_lint.Baseline_file = proptools.StringPtr(baselinePath) |
| 1815 | } else if len(paths) != 0 { |
| 1816 | 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] | 1817 | } |
| 1818 | } |
Paul Duffin | 15f34ef | 2020-07-20 18:04:44 +0100 | [diff] [blame] | 1819 | } |
Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 1820 | |
Paul Duffin | 15f34ef | 2020-07-20 18:04:44 +0100 | [diff] [blame] | 1821 | if !Bool(module.sdkLibraryProperties.No_dist) { |
Paul Duffin | 040e906 | 2020-11-23 17:41:36 +0000 | [diff] [blame] | 1822 | // Dist the api txt and removed api txt artifacts for sdk builds. |
| 1823 | distDir := proptools.StringPtr(path.Join(module.apiDistPath(apiScope), "api")) |
| 1824 | for _, p := range []struct { |
| 1825 | tag string |
| 1826 | pattern string |
| 1827 | }{ |
| 1828 | {tag: ".api.txt", pattern: "%s.txt"}, |
| 1829 | {tag: ".removed-api.txt", pattern: "%s-removed.txt"}, |
| 1830 | } { |
| 1831 | props.Dists = append(props.Dists, android.Dist{ |
| 1832 | Targets: []string{"sdk", "win_sdk"}, |
| 1833 | Dir: distDir, |
| 1834 | Dest: proptools.StringPtr(fmt.Sprintf(p.pattern, module.distStem())), |
| 1835 | Tag: proptools.StringPtr(p.tag), |
| 1836 | }) |
| 1837 | } |
Anton Hansson | 5fd5d24 | 2020-03-27 19:43:19 +0000 | [diff] [blame] | 1838 | } |
| 1839 | |
Spandan Das | 2cc80ba | 2023-10-27 17:21:52 +0000 | [diff] [blame] | 1840 | mctx.CreateModule(DroidstubsFactory, &props, module.sdkComponentPropertiesForChildLibrary()).(*Droidstubs).CallHookIfAvailable(mctx) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1841 | } |
| 1842 | |
Jihoon Kang | 0c705a4 | 2023-08-02 06:44:57 +0000 | [diff] [blame] | 1843 | func (module *SdkLibrary) createApiLibrary(mctx android.DefaultableHookContext, apiScope *apiScope, alternativeFullApiSurfaceStub string) { |
Jihoon Kang | 1c92c3e | 2023-03-23 17:44:51 +0000 | [diff] [blame] | 1844 | props := struct { |
Jihoon Kang | ca198c2 | 2023-06-22 23:13:51 +0000 | [diff] [blame] | 1845 | Name *string |
| 1846 | Visibility []string |
| 1847 | Api_contributions []string |
| 1848 | Libs []string |
| 1849 | Static_libs []string |
| 1850 | Full_api_surface_stub *string |
Jihoon Kang | 4ec2487 | 2023-10-05 17:26:09 +0000 | [diff] [blame] | 1851 | System_modules *string |
Jihoon Kang | 063ec00 | 2023-06-28 01:16:23 +0000 | [diff] [blame] | 1852 | Enable_validation *bool |
Jihoon Kang | 1c92c3e | 2023-03-23 17:44:51 +0000 | [diff] [blame] | 1853 | }{} |
| 1854 | |
| 1855 | props.Name = proptools.StringPtr(module.apiLibraryModuleName(apiScope)) |
Jihoon Kang | 786df93 | 2023-09-07 01:18:31 +0000 | [diff] [blame] | 1856 | props.Visibility = []string{"//visibility:override", "//visibility:private"} |
Jihoon Kang | 1c92c3e | 2023-03-23 17:44:51 +0000 | [diff] [blame] | 1857 | |
| 1858 | apiContributions := []string{} |
| 1859 | |
| 1860 | // Api surfaces are not independent of each other, but have subset relationships, |
| 1861 | // and so does the api files. To generate from-text stubs for api surfaces other than public, |
| 1862 | // all subset api domains' api_contriubtions must be added as well. |
| 1863 | scope := apiScope |
| 1864 | for scope != nil { |
| 1865 | apiContributions = append(apiContributions, module.stubsSourceModuleName(scope)+".api.contribution") |
| 1866 | scope = scope.extends |
| 1867 | } |
Jihoon Kang | 0c705a4 | 2023-08-02 06:44:57 +0000 | [diff] [blame] | 1868 | if apiScope == apiScopePublic { |
| 1869 | additionalApiContribution := module.apiLibraryAdditionalApiContribution() |
| 1870 | if additionalApiContribution != "" { |
| 1871 | apiContributions = append(apiContributions, additionalApiContribution) |
| 1872 | } |
| 1873 | } |
Jihoon Kang | 1c92c3e | 2023-03-23 17:44:51 +0000 | [diff] [blame] | 1874 | |
| 1875 | props.Api_contributions = apiContributions |
| 1876 | props.Libs = module.properties.Libs |
| 1877 | props.Libs = append(props.Libs, module.sdkLibraryProperties.Stub_only_libs...) |
Mark White | 9421c4c | 2023-08-10 00:07:03 +0000 | [diff] [blame] | 1878 | props.Libs = append(props.Libs, module.scopeToProperties[apiScope].Libs...) |
Jihoon Kang | 1c92c3e | 2023-03-23 17:44:51 +0000 | [diff] [blame] | 1879 | props.Libs = append(props.Libs, "stub-annotations") |
| 1880 | props.Static_libs = module.sdkLibraryProperties.Stub_only_static_libs |
Jihoon Kang | e7ee256 | 2023-07-25 05:51:46 +0000 | [diff] [blame] | 1881 | props.Full_api_surface_stub = proptools.StringPtr(apiScope.kind.DefaultJavaLibraryName()) |
Jihoon Kang | 0c705a4 | 2023-08-02 06:44:57 +0000 | [diff] [blame] | 1882 | if alternativeFullApiSurfaceStub != "" { |
| 1883 | props.Full_api_surface_stub = proptools.StringPtr(alternativeFullApiSurfaceStub) |
| 1884 | } |
Jihoon Kang | 1c92c3e | 2023-03-23 17:44:51 +0000 | [diff] [blame] | 1885 | |
| 1886 | // android_module_lib_stubs_current.from-text only comprises api contributions from art, conscrypt and i18n. |
| 1887 | // Thus, replace with android_module_lib_stubs_current_full.from-text, which comprises every api domains. |
| 1888 | if apiScope.kind == android.SdkModule { |
Jihoon Kang | ca198c2 | 2023-06-22 23:13:51 +0000 | [diff] [blame] | 1889 | 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] | 1890 | } |
| 1891 | |
Jihoon Kang | d30ac8a | 2023-10-09 18:00:17 +0000 | [diff] [blame] | 1892 | // java_sdk_library modules that set sdk_version as none does not depend on other api |
| 1893 | // domains. Therefore, java_api_library created from such modules should not depend on |
| 1894 | // full_api_surface_stubs but create and compile stubs by the java_api_library module |
| 1895 | // itself. |
| 1896 | if module.SdkVersion(mctx).Kind == android.SdkNone { |
| 1897 | props.Full_api_surface_stub = nil |
| 1898 | } |
| 1899 | |
Jihoon Kang | 4ec2487 | 2023-10-05 17:26:09 +0000 | [diff] [blame] | 1900 | props.System_modules = module.deviceProperties.System_modules |
Jihoon Kang | 063ec00 | 2023-06-28 01:16:23 +0000 | [diff] [blame] | 1901 | props.Enable_validation = proptools.BoolPtr(true) |
Jihoon Kang | 4ec2487 | 2023-10-05 17:26:09 +0000 | [diff] [blame] | 1902 | |
Spandan Das | 2cc80ba | 2023-10-27 17:21:52 +0000 | [diff] [blame] | 1903 | mctx.CreateModule(ApiLibraryFactory, &props, module.sdkComponentPropertiesForChildLibrary()) |
Jihoon Kang | 1c92c3e | 2023-03-23 17:44:51 +0000 | [diff] [blame] | 1904 | } |
| 1905 | |
Jihoon Kang | 1147b31 | 2023-06-08 23:25:57 +0000 | [diff] [blame] | 1906 | func (module *SdkLibrary) createTopLevelStubsLibrary( |
| 1907 | mctx android.DefaultableHookContext, apiScope *apiScope, contributesToApiSurface bool) { |
| 1908 | props := struct { |
| 1909 | Name *string |
| 1910 | Visibility []string |
| 1911 | Sdk_version *string |
| 1912 | Static_libs []string |
| 1913 | System_modules *string |
| 1914 | Dist struct { |
| 1915 | Targets []string |
| 1916 | Dest *string |
| 1917 | Dir *string |
| 1918 | Tag *string |
| 1919 | } |
| 1920 | Compile_dex *bool |
| 1921 | }{} |
| 1922 | props.Name = proptools.StringPtr(module.stubsLibraryModuleName(apiScope)) |
| 1923 | props.Visibility = childModuleVisibility(module.sdkLibraryProperties.Stubs_library_visibility) |
| 1924 | sdkVersion := module.sdkVersionForStubsLibrary(mctx, apiScope) |
| 1925 | props.Sdk_version = proptools.StringPtr(sdkVersion) |
| 1926 | |
| 1927 | // Add the stub compiling java_library/java_api_library as static lib based on build config |
| 1928 | staticLib := module.sourceStubLibraryModuleName(apiScope) |
| 1929 | if mctx.Config().BuildFromTextStub() && contributesToApiSurface { |
| 1930 | staticLib = module.apiLibraryModuleName(apiScope) |
| 1931 | } |
| 1932 | props.Static_libs = append(props.Static_libs, staticLib) |
| 1933 | props.System_modules = module.deviceProperties.System_modules |
| 1934 | |
| 1935 | // Dist the class jar artifact for sdk builds. |
| 1936 | if !Bool(module.sdkLibraryProperties.No_dist) { |
| 1937 | props.Dist.Targets = []string{"sdk", "win_sdk"} |
| 1938 | props.Dist.Dest = proptools.StringPtr(fmt.Sprintf("%v.jar", module.distStem())) |
| 1939 | props.Dist.Dir = proptools.StringPtr(module.apiDistPath(apiScope)) |
| 1940 | props.Dist.Tag = proptools.StringPtr(".jar") |
| 1941 | } |
| 1942 | |
| 1943 | // The imports need to be compiled to dex if the java_sdk_library requests it. |
| 1944 | compileDex := module.dexProperties.Compile_dex |
| 1945 | if module.stubLibrariesCompiledForDex() { |
| 1946 | compileDex = proptools.BoolPtr(true) |
| 1947 | } |
| 1948 | props.Compile_dex = compileDex |
| 1949 | |
| 1950 | mctx.CreateModule(LibraryFactory, &props, module.sdkComponentPropertiesForChildLibrary()) |
| 1951 | } |
| 1952 | |
Paul Duffin | 958806b | 2022-05-16 13:10:47 +0000 | [diff] [blame] | 1953 | func (module *SdkLibrary) compareAgainstLatestApi(apiScope *apiScope) bool { |
| 1954 | return !(apiScope.unstable || module.sdkLibraryProperties.Unsafe_ignore_missing_latest_api) |
| 1955 | } |
| 1956 | |
Paul Duffin | ea8f808 | 2021-06-24 13:25:57 +0100 | [diff] [blame] | 1957 | // Implements android.ApexModule |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 1958 | func (module *SdkLibrary) DepIsInSameApex(mctx android.BaseModuleContext, dep android.Module) bool { |
| 1959 | depTag := mctx.OtherModuleDependencyTag(dep) |
| 1960 | if depTag == xmlPermissionsFileTag { |
| 1961 | return true |
| 1962 | } |
| 1963 | return module.Library.DepIsInSameApex(mctx, dep) |
| 1964 | } |
| 1965 | |
Paul Duffin | ea8f808 | 2021-06-24 13:25:57 +0100 | [diff] [blame] | 1966 | // Implements android.ApexModule |
| 1967 | func (module *SdkLibrary) UniqueApexVariations() bool { |
| 1968 | return module.uniqueApexVariations() |
| 1969 | } |
| 1970 | |
Jihoon Kang | 80456fd | 2023-11-15 19:22:14 +0000 | [diff] [blame] | 1971 | func (module *SdkLibrary) ContributeToApi() bool { |
| 1972 | return proptools.BoolDefault(module.sdkLibraryProperties.Contribute_to_android_api, false) |
| 1973 | } |
| 1974 | |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1975 | // Creates the xml file that publicizes the runtime library |
Paul Duffin | f022920 | 2020-04-29 16:47:28 +0100 | [diff] [blame] | 1976 | func (module *SdkLibrary) createXmlFile(mctx android.DefaultableHookContext) { |
Spandan Das | 8c9ae7e | 2023-03-03 21:20:36 +0000 | [diff] [blame] | 1977 | moduleMinApiLevel := module.Library.MinSdkVersion(mctx) |
Pedro Loureiro | c362142 | 2021-09-28 15:40:23 +0000 | [diff] [blame] | 1978 | var moduleMinApiLevelStr = moduleMinApiLevel.String() |
| 1979 | if moduleMinApiLevel == android.NoneApiLevel { |
| 1980 | moduleMinApiLevelStr = "current" |
| 1981 | } |
Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 1982 | props := struct { |
Pedro Loureiro | c362142 | 2021-09-28 15:40:23 +0000 | [diff] [blame] | 1983 | Name *string |
| 1984 | Lib_name *string |
| 1985 | Apex_available []string |
| 1986 | On_bootclasspath_since *string |
| 1987 | On_bootclasspath_before *string |
| 1988 | Min_device_sdk *string |
| 1989 | Max_device_sdk *string |
| 1990 | Sdk_library_min_api_level *string |
Jamie Garside | e570ace | 2023-11-27 12:07:36 +0000 | [diff] [blame] | 1991 | Uses_libs_dependencies []string |
Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 1992 | }{ |
Pedro Loureiro | c362142 | 2021-09-28 15:40:23 +0000 | [diff] [blame] | 1993 | Name: proptools.StringPtr(module.xmlPermissionsModuleName()), |
| 1994 | Lib_name: proptools.StringPtr(module.BaseModuleName()), |
| 1995 | Apex_available: module.ApexProperties.Apex_available, |
| 1996 | On_bootclasspath_since: module.commonSdkLibraryProperties.On_bootclasspath_since, |
| 1997 | On_bootclasspath_before: module.commonSdkLibraryProperties.On_bootclasspath_before, |
| 1998 | Min_device_sdk: module.commonSdkLibraryProperties.Min_device_sdk, |
| 1999 | Max_device_sdk: module.commonSdkLibraryProperties.Max_device_sdk, |
| 2000 | Sdk_library_min_api_level: &moduleMinApiLevelStr, |
Jamie Garside | e570ace | 2023-11-27 12:07:36 +0000 | [diff] [blame] | 2001 | Uses_libs_dependencies: module.usesLibraryProperties.Uses_libs, |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 2002 | } |
Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 2003 | |
Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 2004 | mctx.CreateModule(sdkLibraryXmlFactory, &props) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 2005 | } |
| 2006 | |
Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 2007 | func PrebuiltJars(ctx android.BaseModuleContext, baseName string, s android.SdkSpec) android.Paths { |
Jiyong Park | 54105c4 | 2021-03-31 18:17:53 +0900 | [diff] [blame] | 2008 | var ver android.ApiLevel |
Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 2009 | var kind android.SdkKind |
| 2010 | if s.UsePrebuilt(ctx) { |
Jiyong Park | 54105c4 | 2021-03-31 18:17:53 +0900 | [diff] [blame] | 2011 | ver = s.ApiLevel |
Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 2012 | kind = s.Kind |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 2013 | } else { |
Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 2014 | // We don't have prebuilt SDK for the specific sdkVersion. |
| 2015 | // Instead of breaking the build, fallback to use "system_current" |
Jiyong Park | 54105c4 | 2021-03-31 18:17:53 +0900 | [diff] [blame] | 2016 | ver = android.FutureApiLevel |
Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 2017 | kind = android.SdkSystem |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 2018 | } |
Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 2019 | |
| 2020 | dir := filepath.Join("prebuilts", "sdk", ver.String(), kind.String()) |
Paul Duffin | 5006151 | 2020-01-21 16:31:05 +0000 | [diff] [blame] | 2021 | jar := filepath.Join(dir, baseName+".jar") |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 2022 | jarPath := android.ExistentPathForSource(ctx, jar) |
Sundong Ahn | ae418ac | 2019-02-28 15:01:28 +0900 | [diff] [blame] | 2023 | if !jarPath.Valid() { |
Colin Cross | 07c8856 | 2020-01-07 09:34:44 -0800 | [diff] [blame] | 2024 | if ctx.Config().AllowMissingDependencies() { |
| 2025 | return android.Paths{android.PathForSource(ctx, jar)} |
| 2026 | } else { |
Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 2027 | 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] | 2028 | } |
Sundong Ahn | ae418ac | 2019-02-28 15:01:28 +0900 | [diff] [blame] | 2029 | return nil |
| 2030 | } |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 2031 | return android.Paths{jarPath.Path()} |
| 2032 | } |
| 2033 | |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 2034 | // 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] | 2035 | // |
| 2036 | // If either this or the other module are on the platform then this will return |
| 2037 | // false. |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 2038 | func withinSameApexesAs(ctx android.BaseModuleContext, other android.Module) bool { |
| 2039 | apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo) |
| 2040 | otherApexInfo := ctx.OtherModuleProvider(other, android.ApexInfoProvider).(android.ApexInfo) |
Jiyong Park | ab50b07 | 2021-05-12 17:13:56 +0900 | [diff] [blame] | 2041 | return len(otherApexInfo.InApexVariants) > 0 && reflect.DeepEqual(apexInfo.InApexVariants, otherApexInfo.InApexVariants) |
Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 2042 | } |
| 2043 | |
Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 2044 | 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] | 2045 | // If the client doesn't set sdk_version, but if this library prefers stubs over |
| 2046 | // the impl library, let's provide the widest API surface possible. To do so, |
| 2047 | // force override sdk_version to module_current so that the closest possible API |
| 2048 | // surface could be found in selectHeaderJarsForSdkVersion |
Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 2049 | if module.defaultsToStubs() && !sdkVersion.Specified() { |
Jiyong Park | 9231537 | 2021-04-02 08:45:46 +0900 | [diff] [blame] | 2050 | sdkVersion = android.SdkSpecFrom(ctx, "module_current") |
Jiyong Park | 932cdfe | 2020-05-28 00:19:53 +0900 | [diff] [blame] | 2051 | } |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 2052 | |
Paul Duffin | daaa332 | 2020-05-26 18:13:57 +0100 | [diff] [blame] | 2053 | // Only provide access to the implementation library if it is actually built. |
| 2054 | if module.requiresRuntimeImplementationLibrary() { |
| 2055 | // Check any special cases for java_sdk_library. |
| 2056 | // |
| 2057 | // Only allow access to the implementation library in the following condition: |
| 2058 | // * No sdk_version specified on the referencing module. |
Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 2059 | // * The referencing module is in the same apex as this. |
Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 2060 | if sdkVersion.Kind == android.SdkPrivate || withinSameApexesAs(ctx, module) { |
Paul Duffin | daaa332 | 2020-05-26 18:13:57 +0100 | [diff] [blame] | 2061 | if headerJars { |
| 2062 | return module.HeaderJars() |
| 2063 | } else { |
| 2064 | return module.ImplementationJars() |
| 2065 | } |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 2066 | } |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 2067 | } |
Paul Duffin | b05d429 | 2020-05-20 12:19:10 +0100 | [diff] [blame] | 2068 | |
Paul Duffin | 23970f4 | 2020-05-20 14:20:02 +0100 | [diff] [blame] | 2069 | return module.selectHeaderJarsForSdkVersion(ctx, sdkVersion) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 2070 | } |
| 2071 | |
Sundong Ahn | 241cd37 | 2018-07-13 16:16:44 +0900 | [diff] [blame] | 2072 | // to satisfy SdkLibraryDependency interface |
Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 2073 | func (module *SdkLibrary) SdkHeaderJars(ctx android.BaseModuleContext, sdkVersion android.SdkSpec) android.Paths { |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 2074 | return module.sdkJars(ctx, sdkVersion, true /*headerJars*/) |
| 2075 | } |
| 2076 | |
| 2077 | // to satisfy SdkLibraryDependency interface |
Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 2078 | func (module *SdkLibrary) SdkImplementationJars(ctx android.BaseModuleContext, sdkVersion android.SdkSpec) android.Paths { |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 2079 | return module.sdkJars(ctx, sdkVersion, false /*headerJars*/) |
Sundong Ahn | 241cd37 | 2018-07-13 16:16:44 +0900 | [diff] [blame] | 2080 | } |
| 2081 | |
Colin Cross | 571cccf | 2019-02-04 11:22:08 -0800 | [diff] [blame] | 2082 | var javaSdkLibrariesKey = android.NewOnceKey("javaSdkLibraries") |
| 2083 | |
Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 2084 | func javaSdkLibraries(config android.Config) *[]string { |
Colin Cross | 571cccf | 2019-02-04 11:22:08 -0800 | [diff] [blame] | 2085 | return config.Once(javaSdkLibrariesKey, func() interface{} { |
Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 2086 | return &[]string{} |
| 2087 | }).(*[]string) |
| 2088 | } |
| 2089 | |
Paul Duffin | 749f98f | 2019-12-30 17:23:46 +0000 | [diff] [blame] | 2090 | func (module *SdkLibrary) getApiDir() string { |
| 2091 | return proptools.StringDefault(module.sdkLibraryProperties.Api_dir, "api") |
| 2092 | } |
| 2093 | |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 2094 | // For a java_sdk_library module, create internal modules for stubs, docs, |
| 2095 | // runtime libs and xml file. If requested, the stubs and docs are created twice |
| 2096 | // once for public API level and once for system API level |
Paul Duffin | f022920 | 2020-04-29 16:47:28 +0100 | [diff] [blame] | 2097 | func (module *SdkLibrary) CreateInternalModules(mctx android.DefaultableHookContext) { |
| 2098 | // If the module has been disabled then don't create any child modules. |
| 2099 | if !module.Enabled() { |
| 2100 | return |
| 2101 | } |
| 2102 | |
Paul Duffin | a18abc2 | 2020-05-16 18:54:24 +0100 | [diff] [blame] | 2103 | if len(module.properties.Srcs) == 0 { |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 2104 | mctx.PropertyErrorf("srcs", "java_sdk_library must specify srcs") |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 2105 | return |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 2106 | } |
| 2107 | |
Paul Duffin | 37e0b77 | 2019-12-30 17:20:10 +0000 | [diff] [blame] | 2108 | // 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] | 2109 | // then assume it provides both system and test apis. |
Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 2110 | sdkDep := decodeSdkDep(mctx, android.SdkContext(&module.Library)) |
Paul Duffin | 37e0b77 | 2019-12-30 17:20:10 +0000 | [diff] [blame] | 2111 | hasSystemAndTestApis := sdkDep.hasStandardLibs() |
Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 2112 | module.sdkLibraryProperties.Generate_system_and_test_apis = hasSystemAndTestApis |
Paul Duffin | 4f5c1ef | 2020-11-19 14:53:43 +0000 | [diff] [blame] | 2113 | |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 2114 | missingCurrentApi := false |
Inseob Kim | 8098faa | 2019-03-18 10:19:51 +0900 | [diff] [blame] | 2115 | |
Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 2116 | generatedScopes := module.getGeneratedApiScopes(mctx) |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 2117 | |
Paul Duffin | 749f98f | 2019-12-30 17:23:46 +0000 | [diff] [blame] | 2118 | apiDir := module.getApiDir() |
Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 2119 | for _, scope := range generatedScopes { |
Inseob Kim | 8098faa | 2019-03-18 10:19:51 +0900 | [diff] [blame] | 2120 | for _, api := range []string{"current.txt", "removed.txt"} { |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 2121 | path := path.Join(mctx.ModuleDir(), apiDir, scope.apiFilePrefix+api) |
Inseob Kim | 8098faa | 2019-03-18 10:19:51 +0900 | [diff] [blame] | 2122 | p := android.ExistentPathForSource(mctx, path) |
| 2123 | if !p.Valid() { |
Colin Cross | 18f840c | 2021-05-20 17:56:54 -0700 | [diff] [blame] | 2124 | if mctx.Config().AllowMissingDependencies() { |
| 2125 | mctx.AddMissingDependencies([]string{path}) |
| 2126 | } else { |
| 2127 | mctx.ModuleErrorf("Current api file %#v doesn't exist", path) |
| 2128 | missingCurrentApi = true |
| 2129 | } |
Inseob Kim | 8098faa | 2019-03-18 10:19:51 +0900 | [diff] [blame] | 2130 | } |
| 2131 | } |
| 2132 | } |
| 2133 | |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 2134 | if missingCurrentApi { |
Inseob Kim | 8098faa | 2019-03-18 10:19:51 +0900 | [diff] [blame] | 2135 | script := "build/soong/scripts/gen-java-current-api-files.sh" |
| 2136 | p := android.ExistentPathForSource(mctx, script) |
| 2137 | |
| 2138 | if !p.Valid() { |
| 2139 | panic(fmt.Sprintf("script file %s doesn't exist", script)) |
| 2140 | } |
| 2141 | |
| 2142 | mctx.ModuleErrorf("One or more current api files are missing. "+ |
| 2143 | "You can update them by:\n"+ |
Paul Duffin | 37e0b77 | 2019-12-30 17:20:10 +0000 | [diff] [blame] | 2144 | "%s %q %s && m update-api", |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 2145 | script, filepath.Join(mctx.ModuleDir(), apiDir), |
Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 2146 | strings.Join(generatedScopes.Strings(func(s *apiScope) string { return s.apiFilePrefix }), " ")) |
Inseob Kim | 8098faa | 2019-03-18 10:19:51 +0900 | [diff] [blame] | 2147 | return |
| 2148 | } |
| 2149 | |
Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 2150 | for _, scope := range generatedScopes { |
Paul Duffin | 15f34ef | 2020-07-20 18:04:44 +0100 | [diff] [blame] | 2151 | // Use the stubs source name for legacy reasons. |
| 2152 | module.createStubsSourcesAndApi(mctx, scope, module.stubsSourceModuleName(scope), scope.droidstubsArgs) |
Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 2153 | |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 2154 | module.createStubsLibrary(mctx, scope) |
Jihoon Kang | 1c92c3e | 2023-03-23 17:44:51 +0000 | [diff] [blame] | 2155 | |
Jihoon Kang | 0c705a4 | 2023-08-02 06:44:57 +0000 | [diff] [blame] | 2156 | alternativeFullApiSurfaceStubLib := "" |
| 2157 | if scope == apiScopePublic { |
| 2158 | alternativeFullApiSurfaceStubLib = module.alternativeFullApiSurfaceStubLib() |
| 2159 | } |
| 2160 | contributesToApiSurface := module.contributesToApiSurface(mctx.Config()) || alternativeFullApiSurfaceStubLib != "" |
Jihoon Kang | 1147b31 | 2023-06-08 23:25:57 +0000 | [diff] [blame] | 2161 | if contributesToApiSurface { |
Jihoon Kang | 0c705a4 | 2023-08-02 06:44:57 +0000 | [diff] [blame] | 2162 | module.createApiLibrary(mctx, scope, alternativeFullApiSurfaceStubLib) |
Jihoon Kang | 1c92c3e | 2023-03-23 17:44:51 +0000 | [diff] [blame] | 2163 | } |
Jihoon Kang | 1147b31 | 2023-06-08 23:25:57 +0000 | [diff] [blame] | 2164 | |
| 2165 | module.createTopLevelStubsLibrary(mctx, scope, contributesToApiSurface) |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 2166 | } |
| 2167 | |
Paul Duffin | dfa131e | 2020-05-15 20:37:11 +0100 | [diff] [blame] | 2168 | if module.requiresRuntimeImplementationLibrary() { |
Paul Duffin | 5df7930 | 2020-05-16 15:52:12 +0100 | [diff] [blame] | 2169 | // Create child module to create an implementation library. |
| 2170 | // |
| 2171 | // This temporarily creates a second implementation library that can be explicitly |
| 2172 | // referenced. |
| 2173 | // |
| 2174 | // TODO(b/156618935) - update comment once only one implementation library is created. |
| 2175 | module.createImplLibrary(mctx) |
| 2176 | |
Paul Duffin | dfa131e | 2020-05-15 20:37:11 +0100 | [diff] [blame] | 2177 | // Only create an XML permissions file that declares the library as being usable |
| 2178 | // as a shared library if required. |
| 2179 | if module.sharedLibrary() { |
| 2180 | module.createXmlFile(mctx) |
| 2181 | } |
Paul Duffin | 43db9be | 2019-12-30 17:35:49 +0000 | [diff] [blame] | 2182 | |
| 2183 | // record java_sdk_library modules so that they are exported to make |
| 2184 | javaSdkLibraries := javaSdkLibraries(mctx.Config()) |
| 2185 | javaSdkLibrariesLock.Lock() |
| 2186 | defer javaSdkLibrariesLock.Unlock() |
| 2187 | *javaSdkLibraries = append(*javaSdkLibraries, module.BaseModuleName()) |
| 2188 | } |
Anton Hansson | 7f66efa | 2020-10-08 14:47:23 +0100 | [diff] [blame] | 2189 | |
Paul Duffin | 77590a8 | 2022-04-28 14:13:30 +0000 | [diff] [blame] | 2190 | // 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] | 2191 | module.properties.Libs = append(module.properties.Libs, module.sdkLibraryProperties.Impl_only_libs...) |
Paul Duffin | 77590a8 | 2022-04-28 14:13:30 +0000 | [diff] [blame] | 2192 | 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] | 2193 | } |
| 2194 | |
| 2195 | func (module *SdkLibrary) InitSdkLibraryProperties() { |
Colin Cross | ce6734e | 2020-06-15 16:09:53 -0700 | [diff] [blame] | 2196 | module.addHostAndDeviceProperties() |
| 2197 | module.AddProperties(&module.sdkLibraryProperties) |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 2198 | |
Paul Duffin | 71b33cc | 2021-06-23 11:39:47 +0100 | [diff] [blame] | 2199 | module.initSdkLibraryComponent(module) |
Paul Duffin | 859fe96 | 2020-05-15 10:20:31 +0100 | [diff] [blame] | 2200 | |
Paul Duffin | a18abc2 | 2020-05-16 18:54:24 +0100 | [diff] [blame] | 2201 | module.properties.Installable = proptools.BoolPtr(true) |
| 2202 | module.deviceProperties.IsSDKLibrary = true |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 2203 | } |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 2204 | |
Paul Duffin | dfa131e | 2020-05-15 20:37:11 +0100 | [diff] [blame] | 2205 | func (module *SdkLibrary) requiresRuntimeImplementationLibrary() bool { |
| 2206 | return !proptools.Bool(module.sdkLibraryProperties.Api_only) |
| 2207 | } |
| 2208 | |
Jiyong Park | 932cdfe | 2020-05-28 00:19:53 +0900 | [diff] [blame] | 2209 | func (module *SdkLibrary) defaultsToStubs() bool { |
| 2210 | return proptools.Bool(module.sdkLibraryProperties.Default_to_stubs) |
| 2211 | } |
| 2212 | |
Paul Duffin | 1b1e806 | 2020-05-08 13:44:43 +0100 | [diff] [blame] | 2213 | // Defines how to name the individual component modules the sdk library creates. |
| 2214 | type sdkLibraryComponentNamingScheme interface { |
| 2215 | stubsLibraryModuleName(scope *apiScope, baseName string) string |
| 2216 | |
| 2217 | stubsSourceModuleName(scope *apiScope, baseName string) string |
Jihoon Kang | 1c92c3e | 2023-03-23 17:44:51 +0000 | [diff] [blame] | 2218 | |
| 2219 | apiLibraryModuleName(scope *apiScope, baseName string) string |
Jihoon Kang | 1147b31 | 2023-06-08 23:25:57 +0000 | [diff] [blame] | 2220 | |
| 2221 | sourceStubLibraryModuleName(scope *apiScope, baseName string) string |
Paul Duffin | 1b1e806 | 2020-05-08 13:44:43 +0100 | [diff] [blame] | 2222 | } |
| 2223 | |
| 2224 | type defaultNamingScheme struct { |
| 2225 | } |
| 2226 | |
| 2227 | func (s *defaultNamingScheme) stubsLibraryModuleName(scope *apiScope, baseName string) string { |
| 2228 | return scope.stubsLibraryModuleName(baseName) |
| 2229 | } |
| 2230 | |
| 2231 | func (s *defaultNamingScheme) stubsSourceModuleName(scope *apiScope, baseName string) string { |
| 2232 | return scope.stubsSourceModuleName(baseName) |
| 2233 | } |
| 2234 | |
Jihoon Kang | 1c92c3e | 2023-03-23 17:44:51 +0000 | [diff] [blame] | 2235 | func (s *defaultNamingScheme) apiLibraryModuleName(scope *apiScope, baseName string) string { |
| 2236 | return scope.apiLibraryModuleName(baseName) |
| 2237 | } |
| 2238 | |
Jihoon Kang | 1147b31 | 2023-06-08 23:25:57 +0000 | [diff] [blame] | 2239 | func (s *defaultNamingScheme) sourceStubLibraryModuleName(scope *apiScope, baseName string) string { |
| 2240 | return scope.sourceStubLibraryModuleName(baseName) |
| 2241 | } |
| 2242 | |
Paul Duffin | 1b1e806 | 2020-05-08 13:44:43 +0100 | [diff] [blame] | 2243 | var _ sdkLibraryComponentNamingScheme = (*defaultNamingScheme)(nil) |
| 2244 | |
Jaewoong Jung | bc15e3a | 2021-03-10 17:02:43 -0800 | [diff] [blame] | 2245 | func moduleStubLinkType(name string) (stub bool, ret sdkLinkType) { |
Jihoon Kang | 1147b31 | 2023-06-08 23:25:57 +0000 | [diff] [blame] | 2246 | name = strings.TrimSuffix(name, ".from-source") |
| 2247 | |
Anton Hansson | 2d0c194 | 2020-05-25 12:20:51 +0100 | [diff] [blame] | 2248 | // This suffix-based approach is fragile and could potentially mis-trigger. |
| 2249 | // 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] | 2250 | if strings.HasSuffix(name, apiScopePublic.stubsLibraryModuleNameSuffix()) { |
| 2251 | if name == "hwbinder.stubs" || name == "libcore_private.stubs" { |
| 2252 | // Due to a previous bug, these modules were not considered stubs, so we retain that. |
| 2253 | return false, javaPlatform |
| 2254 | } |
Anton Hansson | 2d0c194 | 2020-05-25 12:20:51 +0100 | [diff] [blame] | 2255 | return true, javaSdk |
| 2256 | } |
Anton Hansson | 08f476b | 2021-04-07 15:32:19 +0100 | [diff] [blame] | 2257 | if strings.HasSuffix(name, apiScopeSystem.stubsLibraryModuleNameSuffix()) { |
Anton Hansson | 2d0c194 | 2020-05-25 12:20:51 +0100 | [diff] [blame] | 2258 | return true, javaSystem |
| 2259 | } |
Anton Hansson | 08f476b | 2021-04-07 15:32:19 +0100 | [diff] [blame] | 2260 | if strings.HasSuffix(name, apiScopeModuleLib.stubsLibraryModuleNameSuffix()) { |
Anton Hansson | 2d0c194 | 2020-05-25 12:20:51 +0100 | [diff] [blame] | 2261 | return true, javaModule |
| 2262 | } |
Anton Hansson | 08f476b | 2021-04-07 15:32:19 +0100 | [diff] [blame] | 2263 | if strings.HasSuffix(name, apiScopeTest.stubsLibraryModuleNameSuffix()) { |
Anton Hansson | 2d0c194 | 2020-05-25 12:20:51 +0100 | [diff] [blame] | 2264 | return true, javaSystem |
| 2265 | } |
Jihoon Kang | 1147b31 | 2023-06-08 23:25:57 +0000 | [diff] [blame] | 2266 | if strings.HasSuffix(name, apiScopeSystemServer.stubsLibraryModuleNameSuffix()) { |
| 2267 | return true, javaSystemServer |
| 2268 | } |
Anton Hansson | 2d0c194 | 2020-05-25 12:20:51 +0100 | [diff] [blame] | 2269 | return false, javaPlatform |
| 2270 | } |
| 2271 | |
Jaewoong Jung | 4f158ee | 2019-07-11 10:05:35 -0700 | [diff] [blame] | 2272 | // java_sdk_library is a special Java library that provides optional platform APIs to apps. |
| 2273 | // In practice, it can be viewed as a combination of several modules: 1) stubs library that clients |
| 2274 | // are linked against to, 2) droiddoc module that internally generates API stubs source files, |
| 2275 | // 3) the real runtime shared library that implements the APIs, and 4) XML file for adding |
| 2276 | // 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] | 2277 | func SdkLibraryFactory() android.Module { |
| 2278 | module := &SdkLibrary{} |
Paul Duffin | c3091c8 | 2020-05-08 14:16:20 +0100 | [diff] [blame] | 2279 | |
| 2280 | // Initialize information common between source and prebuilt. |
Paul Duffin | 71b33cc | 2021-06-23 11:39:47 +0100 | [diff] [blame] | 2281 | module.initCommon(module) |
Paul Duffin | c3091c8 | 2020-05-08 14:16:20 +0100 | [diff] [blame] | 2282 | |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 2283 | module.InitSdkLibraryProperties() |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 2284 | android.InitApexModule(module) |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 2285 | InitJavaModule(module, android.HostAndDeviceSupported) |
Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 2286 | |
| 2287 | // Initialize the map from scope to scope specific properties. |
| 2288 | scopeToProperties := make(map[*apiScope]*ApiScopeProperties) |
| 2289 | for _, scope := range allApiScopes { |
| 2290 | scopeToProperties[scope] = scope.scopeSpecificProperties(module) |
| 2291 | } |
| 2292 | module.scopeToProperties = scopeToProperties |
| 2293 | |
Paul Duffin | 4911a89 | 2020-04-29 23:35:13 +0100 | [diff] [blame] | 2294 | // Add the properties containing visibility rules so that they are checked. |
Paul Duffin | 5df7930 | 2020-05-16 15:52:12 +0100 | [diff] [blame] | 2295 | android.AddVisibilityProperty(module, "impl_library_visibility", &module.sdkLibraryProperties.Impl_library_visibility) |
Paul Duffin | 4911a89 | 2020-04-29 23:35:13 +0100 | [diff] [blame] | 2296 | android.AddVisibilityProperty(module, "stubs_library_visibility", &module.sdkLibraryProperties.Stubs_library_visibility) |
| 2297 | android.AddVisibilityProperty(module, "stubs_source_visibility", &module.sdkLibraryProperties.Stubs_source_visibility) |
| 2298 | |
Paul Duffin | 1b1e806 | 2020-05-08 13:44:43 +0100 | [diff] [blame] | 2299 | module.SetDefaultableHook(func(ctx android.DefaultableHookContext) { |
Paul Duffin | dfa131e | 2020-05-15 20:37:11 +0100 | [diff] [blame] | 2300 | // If no implementation is required then it cannot be used as a shared library |
| 2301 | // either. |
| 2302 | if !module.requiresRuntimeImplementationLibrary() { |
| 2303 | // If shared_library has been explicitly set to true then it is incompatible |
| 2304 | // with api_only: true. |
| 2305 | if proptools.Bool(module.commonSdkLibraryProperties.Shared_library) { |
| 2306 | ctx.PropertyErrorf("api_only/shared_library", "inconsistent settings, shared_library and api_only cannot both be true") |
| 2307 | } |
| 2308 | // Set shared_library: false. |
| 2309 | module.commonSdkLibraryProperties.Shared_library = proptools.BoolPtr(false) |
| 2310 | } |
| 2311 | |
Paul Duffin | 1b1e806 | 2020-05-08 13:44:43 +0100 | [diff] [blame] | 2312 | if module.initCommonAfterDefaultsApplied(ctx) { |
| 2313 | module.CreateInternalModules(ctx) |
| 2314 | } |
| 2315 | }) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 2316 | return module |
| 2317 | } |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 2318 | |
| 2319 | // |
| 2320 | // SDK library prebuilts |
| 2321 | // |
| 2322 | |
Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 2323 | // Properties associated with each api scope. |
| 2324 | type sdkLibraryScopeProperties struct { |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 2325 | Jars []string `android:"path"` |
| 2326 | |
| 2327 | Sdk_version *string |
| 2328 | |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 2329 | // List of shared java libs that this module has dependencies to |
| 2330 | Libs []string |
Paul Duffin | 3d1248c | 2020-04-09 00:10:17 +0100 | [diff] [blame] | 2331 | |
Paul Duffin | c878250 | 2020-04-29 20:45:27 +0100 | [diff] [blame] | 2332 | // The stubs source. |
Paul Duffin | 3d1248c | 2020-04-09 00:10:17 +0100 | [diff] [blame] | 2333 | Stub_srcs []string `android:"path"` |
Paul Duffin | 1fd005d | 2020-04-09 01:08:11 +0100 | [diff] [blame] | 2334 | |
| 2335 | // The current.txt |
Paul Duffin | 0f8faff | 2020-05-20 16:18:00 +0100 | [diff] [blame] | 2336 | Current_api *string `android:"path"` |
Paul Duffin | 1fd005d | 2020-04-09 01:08:11 +0100 | [diff] [blame] | 2337 | |
| 2338 | // The removed.txt |
Paul Duffin | 0f8faff | 2020-05-20 16:18:00 +0100 | [diff] [blame] | 2339 | Removed_api *string `android:"path"` |
Anton Hansson | d78eb76 | 2021-09-21 15:25:12 +0100 | [diff] [blame] | 2340 | |
| 2341 | // Annotation zip |
| 2342 | Annotations *string `android:"path"` |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 2343 | } |
| 2344 | |
Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 2345 | type sdkLibraryImportProperties struct { |
Paul Duffin | fcfd791 | 2020-01-31 17:54:30 +0000 | [diff] [blame] | 2346 | // List of shared java libs, common to all scopes, that this module has |
| 2347 | // dependencies to |
| 2348 | Libs []string |
Paul Duffin | 1267d87 | 2021-04-16 17:21:36 +0100 | [diff] [blame] | 2349 | |
| 2350 | // If set to true, compile dex files for the stubs. Defaults to false. |
| 2351 | Compile_dex *bool |
Paul Duffin | 869de14 | 2021-07-15 14:14:41 +0100 | [diff] [blame] | 2352 | |
| 2353 | // 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] | 2354 | Permitted_packages []string |
Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 2355 | } |
| 2356 | |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 2357 | type SdkLibraryImport struct { |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 2358 | android.ModuleBase |
| 2359 | android.DefaultableModuleBase |
| 2360 | prebuilt android.Prebuilt |
Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 2361 | android.ApexModuleBase |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 2362 | |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 2363 | hiddenAPI |
Jiakai Zhang | 204356f | 2021-09-09 08:12:46 +0000 | [diff] [blame] | 2364 | dexpreopter |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 2365 | |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 2366 | properties sdkLibraryImportProperties |
| 2367 | |
Paul Duffin | 46a26a8 | 2020-04-07 19:27:04 +0100 | [diff] [blame] | 2368 | // Map from api scope to the scope specific property structure. |
| 2369 | scopeProperties map[*apiScope]*sdkLibraryScopeProperties |
| 2370 | |
Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 2371 | commonToSdkLibraryAndImport |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 2372 | |
| 2373 | // The reference to the implementation library created by the source module. |
| 2374 | // Is nil if the source module does not exist. |
| 2375 | implLibraryModule *Library |
| 2376 | |
| 2377 | // The reference to the xml permissions module created by the source module. |
| 2378 | // Is nil if the source module does not exist. |
| 2379 | xmlPermissionsFileModule *sdkLibraryXml |
Paul Duffin | 3985351 | 2021-02-26 11:09:39 +0000 | [diff] [blame] | 2380 | |
Jeongik Cha | d5fe878 | 2021-07-08 01:13:11 +0900 | [diff] [blame] | 2381 | // Build path to the dex implementation jar obtained from the prebuilt_apex, if any. |
Martin Stjernholm | 8be1e6d | 2021-09-15 03:34:04 +0100 | [diff] [blame] | 2382 | dexJarFile OptionalDexJarPath |
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 | |
Jiakai Zhang | 204356f | 2021-09-09 08:12:46 +0000 | [diff] [blame] | 2595 | func (module *SdkLibraryImport) AndroidMkEntries() []android.AndroidMkEntries { |
| 2596 | // For an SDK library imported from a prebuilt APEX, we don't need a Make module for itself, as we |
| 2597 | // don't need to install it. However, we need to add its dexpreopt outputs as sub-modules, if it |
| 2598 | // is preopted. |
| 2599 | dexpreoptEntries := module.dexpreopter.AndroidMkEntriesForApex() |
| 2600 | return append(dexpreoptEntries, android.AndroidMkEntries{Disabled: true}) |
| 2601 | } |
| 2602 | |
Jiyong Park | 45bf82e | 2020-12-15 22:29:02 +0900 | [diff] [blame] | 2603 | var _ android.ApexModule = (*SdkLibraryImport)(nil) |
| 2604 | |
| 2605 | // Implements android.ApexModule |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 2606 | func (module *SdkLibraryImport) DepIsInSameApex(mctx android.BaseModuleContext, dep android.Module) bool { |
| 2607 | depTag := mctx.OtherModuleDependencyTag(dep) |
| 2608 | if depTag == xmlPermissionsFileTag { |
| 2609 | return true |
| 2610 | } |
| 2611 | |
| 2612 | // None of the other dependencies of the java_sdk_library_import are in the same apex |
| 2613 | // as the one that references this module. |
| 2614 | return false |
| 2615 | } |
| 2616 | |
Jiyong Park | 45bf82e | 2020-12-15 22:29:02 +0900 | [diff] [blame] | 2617 | // Implements android.ApexModule |
Dan Albert | c806053 | 2020-07-22 22:32:17 -0700 | [diff] [blame] | 2618 | func (module *SdkLibraryImport) ShouldSupportSdkVersion(ctx android.BaseModuleContext, |
| 2619 | sdkVersion android.ApiLevel) error { |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 2620 | // we don't check prebuilt modules for sdk_version |
| 2621 | return nil |
| 2622 | } |
| 2623 | |
Paul Duffin | ea8f808 | 2021-06-24 13:25:57 +0100 | [diff] [blame] | 2624 | // Implements android.ApexModule |
| 2625 | func (module *SdkLibraryImport) UniqueApexVariations() bool { |
| 2626 | return module.uniqueApexVariations() |
| 2627 | } |
| 2628 | |
Paul Duffin | 09817d6 | 2022-04-28 17:45:11 +0100 | [diff] [blame] | 2629 | // MinSdkVersion - Implements hiddenAPIModule |
Spandan Das | 8c9ae7e | 2023-03-03 21:20:36 +0000 | [diff] [blame] | 2630 | func (module *SdkLibraryImport) MinSdkVersion(ctx android.EarlyModuleContext) android.ApiLevel { |
| 2631 | return android.NoneApiLevel |
Paul Duffin | 09817d6 | 2022-04-28 17:45:11 +0100 | [diff] [blame] | 2632 | } |
| 2633 | |
| 2634 | var _ hiddenAPIModule = (*SdkLibraryImport)(nil) |
| 2635 | |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 2636 | func (module *SdkLibraryImport) OutputFiles(tag string) (android.Paths, error) { |
Paul Duffin | 1e940d5 | 2022-04-29 14:21:25 +0100 | [diff] [blame] | 2637 | paths, err := module.commonOutputFiles(tag) |
| 2638 | if paths != nil || err != nil { |
| 2639 | return paths, err |
| 2640 | } |
| 2641 | if module.implLibraryModule != nil { |
| 2642 | return module.implLibraryModule.OutputFiles(tag) |
| 2643 | } else { |
| 2644 | return nil, nil |
| 2645 | } |
Paul Duffin | 46dc45a | 2020-05-14 15:39:10 +0100 | [diff] [blame] | 2646 | } |
| 2647 | |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 2648 | func (module *SdkLibraryImport) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Paul Duffin | a2ae7e0 | 2020-09-11 11:55:00 +0100 | [diff] [blame] | 2649 | module.generateCommonBuildActions(ctx) |
| 2650 | |
Jeongik Cha | d5fe878 | 2021-07-08 01:13:11 +0900 | [diff] [blame] | 2651 | // Assume that source module(sdk_library) is installed in /<sdk_library partition>/framework |
| 2652 | module.installFile = android.PathForModuleInstall(ctx, "framework", module.Stem()+".jar") |
| 2653 | |
Paul Duffin | 0f8faff | 2020-05-20 16:18:00 +0100 | [diff] [blame] | 2654 | // Record the paths to the prebuilt stubs library and stubs source. |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 2655 | ctx.VisitDirectDeps(func(to android.Module) { |
| 2656 | tag := ctx.OtherModuleDependencyTag(to) |
| 2657 | |
Paul Duffin | 0f8faff | 2020-05-20 16:18:00 +0100 | [diff] [blame] | 2658 | // Extract information from any of the scope specific dependencies. |
| 2659 | if scopeTag, ok := tag.(scopeDependencyTag); ok { |
| 2660 | apiScope := scopeTag.apiScope |
| 2661 | scopePaths := module.getScopePathsCreateIfNeeded(apiScope) |
| 2662 | |
| 2663 | // Extract information from the dependency. The exact information extracted |
| 2664 | // is determined by the nature of the dependency which is determined by the tag. |
| 2665 | scopeTag.extractDepInfo(ctx, to, scopePaths) |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 2666 | } else if tag == implLibraryTag { |
| 2667 | if implLibrary, ok := to.(*Library); ok { |
| 2668 | module.implLibraryModule = implLibrary |
| 2669 | } else { |
| 2670 | ctx.ModuleErrorf("implementation library must be of type *java.Library but was %T", to) |
| 2671 | } |
| 2672 | } else if tag == xmlPermissionsFileTag { |
| 2673 | if xmlPermissionsFileModule, ok := to.(*sdkLibraryXml); ok { |
| 2674 | module.xmlPermissionsFileModule = xmlPermissionsFileModule |
| 2675 | } else { |
| 2676 | ctx.ModuleErrorf("xml permissions file module must be of type *sdkLibraryXml but was %T", to) |
| 2677 | } |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 2678 | } |
| 2679 | }) |
Paul Duffin | 0f8faff | 2020-05-20 16:18:00 +0100 | [diff] [blame] | 2680 | |
| 2681 | // Populate the scope paths with information from the properties. |
| 2682 | for apiScope, scopeProperties := range module.scopeProperties { |
| 2683 | if len(scopeProperties.Jars) == 0 { |
| 2684 | continue |
| 2685 | } |
| 2686 | |
| 2687 | paths := module.getScopePathsCreateIfNeeded(apiScope) |
Anton Hansson | d78eb76 | 2021-09-21 15:25:12 +0100 | [diff] [blame] | 2688 | paths.annotationsZip = android.OptionalPathForModuleSrc(ctx, scopeProperties.Annotations) |
Paul Duffin | 0f8faff | 2020-05-20 16:18:00 +0100 | [diff] [blame] | 2689 | paths.currentApiFilePath = android.OptionalPathForModuleSrc(ctx, scopeProperties.Current_api) |
| 2690 | paths.removedApiFilePath = android.OptionalPathForModuleSrc(ctx, scopeProperties.Removed_api) |
| 2691 | } |
Paul Duffin | 3985351 | 2021-02-26 11:09:39 +0000 | [diff] [blame] | 2692 | |
| 2693 | if ctx.Device() { |
| 2694 | // If this is a variant created for a prebuilt_apex then use the dex implementation jar |
| 2695 | // obtained from the associated deapexer module. |
| 2696 | ai := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo) |
| 2697 | if ai.ForPrebuiltApex { |
Paul Duffin | 3985351 | 2021-02-26 11:09:39 +0000 | [diff] [blame] | 2698 | // Get the path of the dex implementation jar from the `deapexer` module. |
Martin Stjernholm | 4482560 | 2021-09-17 01:44:12 +0100 | [diff] [blame] | 2699 | di := android.FindDeapexerProviderForModule(ctx) |
| 2700 | if di == nil { |
| 2701 | return // An error has been reported by FindDeapexerProviderForModule. |
| 2702 | } |
Jiakai Zhang | 81e4681 | 2023-02-08 21:56:07 +0800 | [diff] [blame] | 2703 | dexJarFileApexRootRelative := apexRootRelativePathToJavaLib(module.BaseModuleName()) |
| 2704 | if dexOutputPath := di.PrebuiltExportPath(dexJarFileApexRootRelative); dexOutputPath != nil { |
Martin Stjernholm | 8be1e6d | 2021-09-15 03:34:04 +0100 | [diff] [blame] | 2705 | dexJarFile := makeDexJarPathFromPath(dexOutputPath) |
| 2706 | module.dexJarFile = dexJarFile |
Jiakai Zhang | 204356f | 2021-09-09 08:12:46 +0000 | [diff] [blame] | 2707 | installPath := android.PathForModuleInPartitionInstall( |
Jiakai Zhang | 81e4681 | 2023-02-08 21:56:07 +0800 | [diff] [blame] | 2708 | ctx, "apex", ai.ApexVariationName, dexJarFileApexRootRelative) |
Jiakai Zhang | 204356f | 2021-09-09 08:12:46 +0000 | [diff] [blame] | 2709 | module.installFile = installPath |
Martin Stjernholm | 8be1e6d | 2021-09-15 03:34:04 +0100 | [diff] [blame] | 2710 | module.initHiddenAPI(ctx, dexJarFile, module.findScopePaths(apiScopePublic).stubsImplPath[0], nil) |
Jiakai Zhang | 204356f | 2021-09-09 08:12:46 +0000 | [diff] [blame] | 2711 | |
Jiakai Zhang | 204356f | 2021-09-09 08:12:46 +0000 | [diff] [blame] | 2712 | module.dexpreopter.installPath = module.dexpreopter.getInstallPath(ctx, installPath) |
| 2713 | module.dexpreopter.isSDKLibrary = true |
| 2714 | module.dexpreopter.uncompressedDex = shouldUncompressDex(ctx, &module.dexpreopter) |
Jiakai Zhang | 81e4681 | 2023-02-08 21:56:07 +0800 | [diff] [blame] | 2715 | |
| 2716 | if profilePath := di.PrebuiltExportPath(dexJarFileApexRootRelative + ".prof"); profilePath != nil { |
| 2717 | module.dexpreopter.inputProfilePathOnHost = profilePath |
| 2718 | } |
| 2719 | |
| 2720 | // Dexpreopting. |
Jiakai Zhang | 204356f | 2021-09-09 08:12:46 +0000 | [diff] [blame] | 2721 | module.dexpreopt(ctx, dexOutputPath) |
Paul Duffin | 3985351 | 2021-02-26 11:09:39 +0000 | [diff] [blame] | 2722 | } else { |
| 2723 | // This should never happen as a variant for a prebuilt_apex is only created if the |
| 2724 | // prebuilt_apex has been configured to export the java library dex file. |
Martin Stjernholm | 4482560 | 2021-09-17 01:44:12 +0100 | [diff] [blame] | 2725 | 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] | 2726 | } |
| 2727 | } |
| 2728 | } |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 2729 | } |
| 2730 | |
Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 2731 | 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] | 2732 | |
| 2733 | // For consistency with SdkLibrary make the implementation jar available to libraries that |
| 2734 | // are within the same APEX. |
| 2735 | implLibraryModule := module.implLibraryModule |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 2736 | if implLibraryModule != nil && withinSameApexesAs(ctx, module) { |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 2737 | if headerJars { |
| 2738 | return implLibraryModule.HeaderJars() |
| 2739 | } else { |
| 2740 | return implLibraryModule.ImplementationJars() |
| 2741 | } |
| 2742 | } |
| 2743 | |
Paul Duffin | 23970f4 | 2020-05-20 14:20:02 +0100 | [diff] [blame] | 2744 | return module.selectHeaderJarsForSdkVersion(ctx, sdkVersion) |
Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 2745 | } |
| 2746 | |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 2747 | // to satisfy SdkLibraryDependency interface |
Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 2748 | func (module *SdkLibraryImport) SdkHeaderJars(ctx android.BaseModuleContext, sdkVersion android.SdkSpec) android.Paths { |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 2749 | // This module is just a wrapper for the prebuilt stubs. |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 2750 | return module.sdkJars(ctx, sdkVersion, true) |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 2751 | } |
| 2752 | |
| 2753 | // to satisfy SdkLibraryDependency interface |
Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 2754 | func (module *SdkLibraryImport) SdkImplementationJars(ctx android.BaseModuleContext, sdkVersion android.SdkSpec) android.Paths { |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 2755 | // This module is just a wrapper for the stubs. |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 2756 | return module.sdkJars(ctx, sdkVersion, false) |
| 2757 | } |
| 2758 | |
Ulya Trafimovich | dbf3166 | 2020-12-17 12:07:54 +0000 | [diff] [blame] | 2759 | // to satisfy UsesLibraryDependency interface |
Martin Stjernholm | 8be1e6d | 2021-09-15 03:34:04 +0100 | [diff] [blame] | 2760 | func (module *SdkLibraryImport) DexJarBuildPath() OptionalDexJarPath { |
Paul Duffin | 3985351 | 2021-02-26 11:09:39 +0000 | [diff] [blame] | 2761 | // The dex implementation jar extracted from the .apex file should be used in preference to the |
| 2762 | // source. |
Martin Stjernholm | 8be1e6d | 2021-09-15 03:34:04 +0100 | [diff] [blame] | 2763 | if module.dexJarFile.IsSet() { |
Paul Duffin | 3985351 | 2021-02-26 11:09:39 +0000 | [diff] [blame] | 2764 | return module.dexJarFile |
| 2765 | } |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 2766 | if module.implLibraryModule == nil { |
Martin Stjernholm | 8be1e6d | 2021-09-15 03:34:04 +0100 | [diff] [blame] | 2767 | return makeUnsetDexJarPath() |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 2768 | } else { |
| 2769 | return module.implLibraryModule.DexJarBuildPath() |
| 2770 | } |
| 2771 | } |
| 2772 | |
Ulya Trafimovich | dbf3166 | 2020-12-17 12:07:54 +0000 | [diff] [blame] | 2773 | // to satisfy UsesLibraryDependency interface |
Ulya Trafimovich | 31e444e | 2020-08-14 17:32:16 +0100 | [diff] [blame] | 2774 | func (module *SdkLibraryImport) DexJarInstallPath() android.Path { |
Jeongik Cha | d5fe878 | 2021-07-08 01:13:11 +0900 | [diff] [blame] | 2775 | return module.installFile |
Ulya Trafimovich | 31e444e | 2020-08-14 17:32:16 +0100 | [diff] [blame] | 2776 | } |
| 2777 | |
Ulya Trafimovich | dbf3166 | 2020-12-17 12:07:54 +0000 | [diff] [blame] | 2778 | // to satisfy UsesLibraryDependency interface |
| 2779 | func (module *SdkLibraryImport) ClassLoaderContexts() dexpreopt.ClassLoaderContextMap { |
| 2780 | return nil |
| 2781 | } |
| 2782 | |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 2783 | // to satisfy apex.javaDependency interface |
| 2784 | func (module *SdkLibraryImport) JacocoReportClassesFile() android.Path { |
| 2785 | if module.implLibraryModule == nil { |
| 2786 | return nil |
| 2787 | } else { |
| 2788 | return module.implLibraryModule.JacocoReportClassesFile() |
| 2789 | } |
| 2790 | } |
| 2791 | |
| 2792 | // to satisfy apex.javaDependency interface |
Colin Cross | 08dca38 | 2020-07-21 20:31:17 -0700 | [diff] [blame] | 2793 | func (module *SdkLibraryImport) LintDepSets() LintDepSets { |
| 2794 | if module.implLibraryModule == nil { |
| 2795 | return LintDepSets{} |
| 2796 | } else { |
| 2797 | return module.implLibraryModule.LintDepSets() |
| 2798 | } |
| 2799 | } |
| 2800 | |
Spandan Das | 17854f5 | 2022-01-14 21:19:14 +0000 | [diff] [blame] | 2801 | func (module *SdkLibraryImport) GetStrictUpdatabilityLinting() bool { |
Jaewoong Jung | 476b9d6 | 2021-05-10 15:30:00 -0700 | [diff] [blame] | 2802 | if module.implLibraryModule == nil { |
| 2803 | return false |
| 2804 | } else { |
Spandan Das | 17854f5 | 2022-01-14 21:19:14 +0000 | [diff] [blame] | 2805 | return module.implLibraryModule.GetStrictUpdatabilityLinting() |
Jaewoong Jung | 476b9d6 | 2021-05-10 15:30:00 -0700 | [diff] [blame] | 2806 | } |
| 2807 | } |
| 2808 | |
Spandan Das | 17854f5 | 2022-01-14 21:19:14 +0000 | [diff] [blame] | 2809 | func (module *SdkLibraryImport) SetStrictUpdatabilityLinting(strictLinting bool) { |
Jaewoong Jung | 476b9d6 | 2021-05-10 15:30:00 -0700 | [diff] [blame] | 2810 | if module.implLibraryModule != nil { |
Spandan Das | 17854f5 | 2022-01-14 21:19:14 +0000 | [diff] [blame] | 2811 | module.implLibraryModule.SetStrictUpdatabilityLinting(strictLinting) |
Jaewoong Jung | 476b9d6 | 2021-05-10 15:30:00 -0700 | [diff] [blame] | 2812 | } |
| 2813 | } |
| 2814 | |
Colin Cross | 08dca38 | 2020-07-21 20:31:17 -0700 | [diff] [blame] | 2815 | // to satisfy apex.javaDependency interface |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 2816 | func (module *SdkLibraryImport) Stem() string { |
| 2817 | return module.BaseModuleName() |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 2818 | } |
Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 2819 | |
Paul Duffin | 44b481b | 2020-06-17 16:59:43 +0100 | [diff] [blame] | 2820 | var _ ApexDependency = (*SdkLibraryImport)(nil) |
| 2821 | |
| 2822 | // to satisfy java.ApexDependency interface |
| 2823 | func (module *SdkLibraryImport) HeaderJars() android.Paths { |
| 2824 | if module.implLibraryModule == nil { |
| 2825 | return nil |
| 2826 | } else { |
| 2827 | return module.implLibraryModule.HeaderJars() |
| 2828 | } |
| 2829 | } |
| 2830 | |
| 2831 | // to satisfy java.ApexDependency interface |
| 2832 | func (module *SdkLibraryImport) ImplementationAndResourcesJars() android.Paths { |
| 2833 | if module.implLibraryModule == nil { |
| 2834 | return nil |
| 2835 | } else { |
| 2836 | return module.implLibraryModule.ImplementationAndResourcesJars() |
| 2837 | } |
| 2838 | } |
| 2839 | |
Jiakai Zhang | 204356f | 2021-09-09 08:12:46 +0000 | [diff] [blame] | 2840 | // to satisfy java.DexpreopterInterface interface |
| 2841 | func (module *SdkLibraryImport) IsInstallable() bool { |
| 2842 | return true |
| 2843 | } |
| 2844 | |
Paul Duffin | fef5500 | 2021-06-17 14:56:05 +0100 | [diff] [blame] | 2845 | var _ android.RequiredFilesFromPrebuiltApex = (*SdkLibraryImport)(nil) |
| 2846 | |
Paul Duffin | b4bbf2c | 2021-06-17 15:59:07 +0100 | [diff] [blame] | 2847 | func (module *SdkLibraryImport) RequiredFilesFromPrebuiltApex(ctx android.BaseModuleContext) []string { |
Paul Duffin | fef5500 | 2021-06-17 14:56:05 +0100 | [diff] [blame] | 2848 | name := module.BaseModuleName() |
Jiakai Zhang | 81e4681 | 2023-02-08 21:56:07 +0800 | [diff] [blame] | 2849 | return requiredFilesFromPrebuiltApexForImport(name, &module.dexpreopter) |
Paul Duffin | fef5500 | 2021-06-17 14:56:05 +0100 | [diff] [blame] | 2850 | } |
| 2851 | |
Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 2852 | // java_sdk_library_xml |
Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 2853 | type sdkLibraryXml struct { |
| 2854 | android.ModuleBase |
| 2855 | android.DefaultableModuleBase |
| 2856 | android.ApexModuleBase |
| 2857 | |
| 2858 | properties sdkLibraryXmlProperties |
| 2859 | |
| 2860 | outputFilePath android.OutputPath |
| 2861 | installDirPath android.InstallPath |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 2862 | |
| 2863 | hideApexVariantFromMake bool |
Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 2864 | } |
| 2865 | |
| 2866 | type sdkLibraryXmlProperties struct { |
| 2867 | // canonical name of the lib |
| 2868 | Lib_name *string |
Pedro Loureiro | 9956e5e | 2021-09-07 17:21:59 +0000 | [diff] [blame] | 2869 | |
| 2870 | // Signals that this shared library is part of the bootclasspath starting |
| 2871 | // on the version indicated in this attribute. |
| 2872 | // |
| 2873 | // This will make platforms at this level and above to ignore |
| 2874 | // <uses-library> tags with this library name because the library is already |
| 2875 | // available |
| 2876 | On_bootclasspath_since *string |
| 2877 | |
| 2878 | // Signals that this shared library was part of the bootclasspath before |
| 2879 | // (but not including) the version indicated in this attribute. |
| 2880 | // |
| 2881 | // The system will automatically add a <uses-library> tag with this library to |
| 2882 | // apps that target any SDK less than the version indicated in this attribute. |
| 2883 | On_bootclasspath_before *string |
| 2884 | |
| 2885 | // Indicates that PackageManager should ignore this shared library if the |
| 2886 | // platform is below the version indicated in this attribute. |
| 2887 | // |
| 2888 | // This means that the device won't recognise this library as installed. |
| 2889 | Min_device_sdk *string |
| 2890 | |
| 2891 | // Indicates that PackageManager should ignore this shared library if the |
| 2892 | // platform is above the version indicated in this attribute. |
| 2893 | // |
| 2894 | // This means that the device won't recognise this library as installed. |
| 2895 | Max_device_sdk *string |
Pedro Loureiro | c362142 | 2021-09-28 15:40:23 +0000 | [diff] [blame] | 2896 | |
| 2897 | // The SdkLibrary's min api level as a string |
| 2898 | // |
| 2899 | // This value comes from the ApiLevel of the MinSdkVersion property. |
| 2900 | Sdk_library_min_api_level *string |
Jamie Garside | e570ace | 2023-11-27 12:07:36 +0000 | [diff] [blame] | 2901 | |
| 2902 | // Uses-libs dependencies that the shared library requires to work correctly. |
| 2903 | // |
| 2904 | // This will add dependency="foo:bar" to the <library> section. |
| 2905 | Uses_libs_dependencies []string |
Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 2906 | } |
| 2907 | |
| 2908 | // java_sdk_library_xml builds the permission xml file for a java_sdk_library. |
| 2909 | // Not to be used directly by users. java_sdk_library internally uses this. |
| 2910 | func sdkLibraryXmlFactory() android.Module { |
| 2911 | module := &sdkLibraryXml{} |
| 2912 | |
| 2913 | module.AddProperties(&module.properties) |
| 2914 | |
| 2915 | android.InitApexModule(module) |
| 2916 | android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibCommon) |
| 2917 | |
| 2918 | return module |
| 2919 | } |
| 2920 | |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 2921 | func (module *sdkLibraryXml) UniqueApexVariations() bool { |
| 2922 | // sdkLibraryXml needs a unique variation per APEX because the generated XML file contains the path to the |
| 2923 | // mounted APEX, which contains the name of the APEX. |
| 2924 | return true |
| 2925 | } |
| 2926 | |
Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 2927 | // from android.PrebuiltEtcModule |
Jooyung Han | 0703fd8 | 2020-08-26 22:11:53 +0900 | [diff] [blame] | 2928 | func (module *sdkLibraryXml) BaseDir() string { |
| 2929 | return "etc" |
| 2930 | } |
| 2931 | |
| 2932 | // from android.PrebuiltEtcModule |
Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 2933 | func (module *sdkLibraryXml) SubDir() string { |
| 2934 | return "permissions" |
| 2935 | } |
| 2936 | |
| 2937 | // from android.PrebuiltEtcModule |
| 2938 | func (module *sdkLibraryXml) OutputFile() android.OutputPath { |
| 2939 | return module.outputFilePath |
| 2940 | } |
| 2941 | |
| 2942 | // from android.ApexModule |
| 2943 | func (module *sdkLibraryXml) AvailableFor(what string) bool { |
| 2944 | return true |
| 2945 | } |
| 2946 | |
| 2947 | func (module *sdkLibraryXml) DepsMutator(ctx android.BottomUpMutatorContext) { |
| 2948 | // do nothing |
| 2949 | } |
| 2950 | |
Jiyong Park | 45bf82e | 2020-12-15 22:29:02 +0900 | [diff] [blame] | 2951 | var _ android.ApexModule = (*sdkLibraryXml)(nil) |
| 2952 | |
| 2953 | // Implements android.ApexModule |
Dan Albert | c806053 | 2020-07-22 22:32:17 -0700 | [diff] [blame] | 2954 | func (module *sdkLibraryXml) ShouldSupportSdkVersion(ctx android.BaseModuleContext, |
| 2955 | sdkVersion android.ApiLevel) error { |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 2956 | // sdkLibraryXml doesn't need to be checked separately because java_sdk_library is checked |
| 2957 | return nil |
| 2958 | } |
| 2959 | |
Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 2960 | // File path to the runtime implementation library |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 2961 | func (module *sdkLibraryXml) implPath(ctx android.ModuleContext) string { |
Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 2962 | implName := proptools.String(module.properties.Lib_name) |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 2963 | if apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo); !apexInfo.IsForPlatform() { |
Colin Cross | e07f231 | 2020-08-13 11:24:56 -0700 | [diff] [blame] | 2964 | // 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] | 2965 | // In most cases, this works fine. But when apex_name is set or override_apex is used |
| 2966 | // this can be wrong. |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 2967 | return fmt.Sprintf("/apex/%s/javalib/%s.jar", apexInfo.ApexVariationName, implName) |
Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 2968 | } |
| 2969 | partition := "system" |
| 2970 | if module.SocSpecific() { |
| 2971 | partition = "vendor" |
| 2972 | } else if module.DeviceSpecific() { |
| 2973 | partition = "odm" |
| 2974 | } else if module.ProductSpecific() { |
| 2975 | partition = "product" |
| 2976 | } else if module.SystemExtSpecific() { |
| 2977 | partition = "system_ext" |
| 2978 | } |
| 2979 | return "/" + partition + "/framework/" + implName + ".jar" |
| 2980 | } |
| 2981 | |
Pedro Loureiro | 9956e5e | 2021-09-07 17:21:59 +0000 | [diff] [blame] | 2982 | func formattedOptionalSdkLevelAttribute(ctx android.ModuleContext, attrName string, value *string) string { |
| 2983 | if value == nil { |
| 2984 | return "" |
| 2985 | } |
| 2986 | apiLevel, err := android.ApiLevelFromUser(ctx, *value) |
| 2987 | if err != nil { |
Pedro Loureiro | ba6682f | 2021-10-29 09:32:32 +0000 | [diff] [blame] | 2988 | // attributes in bp files have underscores but in the xml have dashes. |
| 2989 | ctx.PropertyErrorf(strings.ReplaceAll(attrName, "-", "_"), err.Error()) |
Pedro Loureiro | 9956e5e | 2021-09-07 17:21:59 +0000 | [diff] [blame] | 2990 | return "" |
| 2991 | } |
Pedro Loureiro | b638c62 | 2021-12-22 15:28:05 +0000 | [diff] [blame] | 2992 | if apiLevel.IsCurrent() { |
| 2993 | // passing "current" would always mean a future release, never the current (or the current in |
| 2994 | // progress) which means some conditions would never be triggered. |
| 2995 | ctx.PropertyErrorf(strings.ReplaceAll(attrName, "-", "_"), |
| 2996 | `"current" is not an allowed value for this attribute`) |
| 2997 | return "" |
| 2998 | } |
Pedro Loureiro | 4899122 | 2022-06-17 20:01:21 +0000 | [diff] [blame] | 2999 | // "safeValue" is safe because it translates finalized codenames to a string |
| 3000 | // with their SDK int. |
| 3001 | safeValue := apiLevel.String() |
| 3002 | return formattedOptionalAttribute(attrName, &safeValue) |
Pedro Loureiro | 9956e5e | 2021-09-07 17:21:59 +0000 | [diff] [blame] | 3003 | } |
| 3004 | |
| 3005 | // formats an attribute for the xml permissions file if the value is not null |
| 3006 | // returns empty string otherwise |
| 3007 | func formattedOptionalAttribute(attrName string, value *string) string { |
| 3008 | if value == nil { |
| 3009 | return "" |
| 3010 | } |
| 3011 | return fmt.Sprintf(` %s=\"%s\"\n`, attrName, *value) |
| 3012 | } |
| 3013 | |
Jamie Garside | e570ace | 2023-11-27 12:07:36 +0000 | [diff] [blame] | 3014 | func formattedDependenciesAttribute(dependencies []string) string { |
| 3015 | if dependencies == nil { |
| 3016 | return "" |
| 3017 | } |
| 3018 | return fmt.Sprintf(` dependency=\"%s\"\n`, strings.Join(dependencies, ":")) |
| 3019 | } |
| 3020 | |
Pedro Loureiro | 9956e5e | 2021-09-07 17:21:59 +0000 | [diff] [blame] | 3021 | func (module *sdkLibraryXml) permissionsContents(ctx android.ModuleContext) string { |
| 3022 | libName := proptools.String(module.properties.Lib_name) |
| 3023 | libNameAttr := formattedOptionalAttribute("name", &libName) |
| 3024 | filePath := module.implPath(ctx) |
| 3025 | filePathAttr := formattedOptionalAttribute("file", &filePath) |
Pedro Loureiro | ba6682f | 2021-10-29 09:32:32 +0000 | [diff] [blame] | 3026 | implicitFromAttr := formattedOptionalSdkLevelAttribute(ctx, "on-bootclasspath-since", module.properties.On_bootclasspath_since) |
| 3027 | implicitUntilAttr := formattedOptionalSdkLevelAttribute(ctx, "on-bootclasspath-before", module.properties.On_bootclasspath_before) |
| 3028 | minSdkAttr := formattedOptionalSdkLevelAttribute(ctx, "min-device-sdk", module.properties.Min_device_sdk) |
| 3029 | maxSdkAttr := formattedOptionalSdkLevelAttribute(ctx, "max-device-sdk", module.properties.Max_device_sdk) |
Jamie Garside | e570ace | 2023-11-27 12:07:36 +0000 | [diff] [blame] | 3030 | dependenciesAttr := formattedDependenciesAttribute(module.properties.Uses_libs_dependencies) |
Pedro Loureiro | 196d3e6 | 2021-12-22 19:53:01 +0000 | [diff] [blame] | 3031 | // <library> is understood in all android versions whereas <apex-library> is only understood from API T (and ignored before that). |
| 3032 | // 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] | 3033 | var libraryTag string |
| 3034 | if module.properties.Min_device_sdk != nil { |
Pedro Loureiro | 196d3e6 | 2021-12-22 19:53:01 +0000 | [diff] [blame] | 3035 | libraryTag = ` <apex-library\n` |
Pedro Loureiro | c362142 | 2021-09-28 15:40:23 +0000 | [diff] [blame] | 3036 | } else { |
| 3037 | libraryTag = ` <library\n` |
| 3038 | } |
Pedro Loureiro | 9956e5e | 2021-09-07 17:21:59 +0000 | [diff] [blame] | 3039 | |
| 3040 | return strings.Join([]string{ |
| 3041 | `<?xml version=\"1.0\" encoding=\"utf-8\"?>\n`, |
| 3042 | `<!-- Copyright (C) 2018 The Android Open Source Project\n`, |
| 3043 | `\n`, |
| 3044 | ` Licensed under the Apache License, Version 2.0 (the \"License\");\n`, |
| 3045 | ` you may not use this file except in compliance with the License.\n`, |
| 3046 | ` You may obtain a copy of the License at\n`, |
| 3047 | `\n`, |
| 3048 | ` http://www.apache.org/licenses/LICENSE-2.0\n`, |
| 3049 | `\n`, |
| 3050 | ` Unless required by applicable law or agreed to in writing, software\n`, |
| 3051 | ` distributed under the License is distributed on an \"AS IS\" BASIS,\n`, |
| 3052 | ` WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n`, |
| 3053 | ` See the License for the specific language governing permissions and\n`, |
| 3054 | ` limitations under the License.\n`, |
| 3055 | `-->\n`, |
| 3056 | `<permissions>\n`, |
Pedro Loureiro | c362142 | 2021-09-28 15:40:23 +0000 | [diff] [blame] | 3057 | libraryTag, |
Pedro Loureiro | 9956e5e | 2021-09-07 17:21:59 +0000 | [diff] [blame] | 3058 | libNameAttr, |
| 3059 | filePathAttr, |
| 3060 | implicitFromAttr, |
| 3061 | implicitUntilAttr, |
| 3062 | minSdkAttr, |
| 3063 | maxSdkAttr, |
Jamie Garside | e570ace | 2023-11-27 12:07:36 +0000 | [diff] [blame] | 3064 | dependenciesAttr, |
Pedro Loureiro | 9956e5e | 2021-09-07 17:21:59 +0000 | [diff] [blame] | 3065 | ` />\n`, |
| 3066 | `</permissions>\n`}, "") |
| 3067 | } |
| 3068 | |
Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 3069 | func (module *sdkLibraryXml) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 3070 | module.hideApexVariantFromMake = !ctx.Provider(android.ApexInfoProvider).(android.ApexInfo).IsForPlatform() |
| 3071 | |
Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 3072 | libName := proptools.String(module.properties.Lib_name) |
Pedro Loureiro | c362142 | 2021-09-28 15:40:23 +0000 | [diff] [blame] | 3073 | module.selfValidate(ctx) |
Pedro Loureiro | 9956e5e | 2021-09-07 17:21:59 +0000 | [diff] [blame] | 3074 | xmlContent := module.permissionsContents(ctx) |
Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 3075 | |
| 3076 | module.outputFilePath = android.PathForModuleOut(ctx, libName+".xml").OutputPath |
Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 3077 | rule := android.NewRuleBuilder(pctx, ctx) |
Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 3078 | rule.Command(). |
| 3079 | Text("/bin/bash -c \"echo -e '" + xmlContent + "'\" > "). |
| 3080 | Output(module.outputFilePath) |
| 3081 | |
Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 3082 | rule.Build("java_sdk_xml", "Permission XML") |
Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 3083 | |
| 3084 | module.installDirPath = android.PathForModuleInstall(ctx, "etc", module.SubDir()) |
| 3085 | } |
| 3086 | |
| 3087 | func (module *sdkLibraryXml) AndroidMkEntries() []android.AndroidMkEntries { |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 3088 | if module.hideApexVariantFromMake { |
satayev | 8f088b0 | 2021-12-06 11:40:46 +0000 | [diff] [blame] | 3089 | return []android.AndroidMkEntries{{ |
Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 3090 | Disabled: true, |
| 3091 | }} |
| 3092 | } |
| 3093 | |
satayev | 8f088b0 | 2021-12-06 11:40:46 +0000 | [diff] [blame] | 3094 | return []android.AndroidMkEntries{{ |
Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 3095 | Class: "ETC", |
| 3096 | OutputFile: android.OptionalPathForPath(module.outputFilePath), |
| 3097 | ExtraEntries: []android.AndroidMkExtraEntriesFunc{ |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 3098 | func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) { |
Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 3099 | entries.SetString("LOCAL_MODULE_TAGS", "optional") |
Colin Cross | c68db4b | 2021-11-11 18:59:15 -0800 | [diff] [blame] | 3100 | entries.SetString("LOCAL_MODULE_PATH", module.installDirPath.String()) |
Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 3101 | entries.SetString("LOCAL_INSTALLED_MODULE_STEM", module.outputFilePath.Base()) |
| 3102 | }, |
| 3103 | }, |
| 3104 | }} |
| 3105 | } |
Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 3106 | |
Pedro Loureiro | c362142 | 2021-09-28 15:40:23 +0000 | [diff] [blame] | 3107 | func (module *sdkLibraryXml) selfValidate(ctx android.ModuleContext) { |
| 3108 | module.validateAtLeastTAttributes(ctx) |
| 3109 | module.validateMinAndMaxDeviceSdk(ctx) |
| 3110 | module.validateMinMaxDeviceSdkAndModuleMinSdk(ctx) |
| 3111 | module.validateOnBootclasspathBeforeRequirements(ctx) |
| 3112 | } |
| 3113 | |
| 3114 | func (module *sdkLibraryXml) validateAtLeastTAttributes(ctx android.ModuleContext) { |
| 3115 | t := android.ApiLevelOrPanic(ctx, "Tiramisu") |
| 3116 | module.attrAtLeastT(ctx, t, module.properties.Min_device_sdk, "min_device_sdk") |
| 3117 | module.attrAtLeastT(ctx, t, module.properties.Max_device_sdk, "max_device_sdk") |
| 3118 | module.attrAtLeastT(ctx, t, module.properties.On_bootclasspath_before, "on_bootclasspath_before") |
| 3119 | module.attrAtLeastT(ctx, t, module.properties.On_bootclasspath_since, "on_bootclasspath_since") |
| 3120 | } |
| 3121 | |
| 3122 | func (module *sdkLibraryXml) attrAtLeastT(ctx android.ModuleContext, t android.ApiLevel, attr *string, attrName string) { |
| 3123 | if attr != nil { |
| 3124 | if level, err := android.ApiLevelFromUser(ctx, *attr); err == nil { |
| 3125 | // we will inform the user of invalid inputs when we try to write the |
| 3126 | // permissions xml file so we don't need to do it here |
| 3127 | if t.GreaterThan(level) { |
| 3128 | ctx.PropertyErrorf(attrName, "Attribute value needs to be at least T") |
| 3129 | } |
| 3130 | } |
| 3131 | } |
| 3132 | } |
| 3133 | |
| 3134 | func (module *sdkLibraryXml) validateMinAndMaxDeviceSdk(ctx android.ModuleContext) { |
| 3135 | if module.properties.Min_device_sdk != nil && module.properties.Max_device_sdk != nil { |
| 3136 | min, minErr := android.ApiLevelFromUser(ctx, *module.properties.Min_device_sdk) |
| 3137 | max, maxErr := android.ApiLevelFromUser(ctx, *module.properties.Max_device_sdk) |
| 3138 | if minErr == nil && maxErr == nil { |
| 3139 | // we will inform the user of invalid inputs when we try to write the |
| 3140 | // permissions xml file so we don't need to do it here |
| 3141 | if min.GreaterThan(max) { |
| 3142 | ctx.ModuleErrorf("min_device_sdk can't be greater than max_device_sdk") |
| 3143 | } |
| 3144 | } |
| 3145 | } |
| 3146 | } |
| 3147 | |
| 3148 | func (module *sdkLibraryXml) validateMinMaxDeviceSdkAndModuleMinSdk(ctx android.ModuleContext) { |
| 3149 | moduleMinApi := android.ApiLevelOrPanic(ctx, *module.properties.Sdk_library_min_api_level) |
| 3150 | if module.properties.Min_device_sdk != nil { |
| 3151 | api, err := android.ApiLevelFromUser(ctx, *module.properties.Min_device_sdk) |
| 3152 | if err == nil { |
| 3153 | if moduleMinApi.GreaterThan(api) { |
| 3154 | ctx.PropertyErrorf("min_device_sdk", "Can't be less than module's min sdk (%s)", moduleMinApi) |
| 3155 | } |
| 3156 | } |
| 3157 | } |
| 3158 | if module.properties.Max_device_sdk != nil { |
| 3159 | api, err := android.ApiLevelFromUser(ctx, *module.properties.Max_device_sdk) |
| 3160 | if err == nil { |
| 3161 | if moduleMinApi.GreaterThan(api) { |
| 3162 | ctx.PropertyErrorf("max_device_sdk", "Can't be less than module's min sdk (%s)", moduleMinApi) |
| 3163 | } |
| 3164 | } |
| 3165 | } |
| 3166 | } |
| 3167 | |
| 3168 | func (module *sdkLibraryXml) validateOnBootclasspathBeforeRequirements(ctx android.ModuleContext) { |
| 3169 | moduleMinApi := android.ApiLevelOrPanic(ctx, *module.properties.Sdk_library_min_api_level) |
| 3170 | if module.properties.On_bootclasspath_before != nil { |
| 3171 | t := android.ApiLevelOrPanic(ctx, "Tiramisu") |
| 3172 | // if we use the attribute, then we need to do this validation |
| 3173 | if moduleMinApi.LessThan(t) { |
| 3174 | // if minAPi is < T, then we need to have min_device_sdk (which only accepts T+) |
| 3175 | if module.properties.Min_device_sdk == nil { |
| 3176 | 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") |
| 3177 | } |
| 3178 | } |
| 3179 | } |
| 3180 | } |
| 3181 | |
Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 3182 | type sdkLibrarySdkMemberType struct { |
| 3183 | android.SdkMemberTypeBase |
| 3184 | } |
| 3185 | |
Paul Duffin | 296701e | 2021-07-14 10:29:36 +0100 | [diff] [blame] | 3186 | func (s *sdkLibrarySdkMemberType) AddDependencies(ctx android.SdkDependencyContext, dependencyTag blueprint.DependencyTag, names []string) { |
| 3187 | ctx.AddVariationDependencies(nil, dependencyTag, names...) |
Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 3188 | } |
| 3189 | |
| 3190 | func (s *sdkLibrarySdkMemberType) IsInstance(module android.Module) bool { |
| 3191 | _, ok := module.(*SdkLibrary) |
| 3192 | return ok |
| 3193 | } |
| 3194 | |
| 3195 | func (s *sdkLibrarySdkMemberType) AddPrebuiltModule(ctx android.SdkMemberContext, member android.SdkMember) android.BpModule { |
| 3196 | return ctx.SnapshotBuilder().AddPrebuiltModule(member, "java_sdk_library_import") |
| 3197 | } |
| 3198 | |
| 3199 | func (s *sdkLibrarySdkMemberType) CreateVariantPropertiesStruct() android.SdkMemberProperties { |
| 3200 | return &sdkLibrarySdkMemberProperties{} |
| 3201 | } |
| 3202 | |
Paul Duffin | 976b0e5 | 2021-04-27 23:20:26 +0100 | [diff] [blame] | 3203 | var javaSdkLibrarySdkMemberType = &sdkLibrarySdkMemberType{ |
| 3204 | android.SdkMemberTypeBase{ |
| 3205 | PropertyName: "java_sdk_libs", |
| 3206 | SupportsSdk: true, |
| 3207 | }, |
| 3208 | } |
| 3209 | |
Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 3210 | type sdkLibrarySdkMemberProperties struct { |
| 3211 | android.SdkMemberPropertiesBase |
| 3212 | |
Paul Duffin | e840995 | 2022-09-22 16:24:46 +0100 | [diff] [blame] | 3213 | // Stem name for files in the sdk snapshot. |
| 3214 | // |
| 3215 | // This is used to construct the path names of various sdk library files in the sdk snapshot to |
| 3216 | // make sure that they match the finalized versions of those files in prebuilts/sdk. |
| 3217 | // |
| 3218 | // This property is marked as keep so that it will be kept in all instances of this struct, will |
| 3219 | // not be cleared but will be copied to common structs. That is needed because this field is used |
| 3220 | // to construct many file names for other parts of this struct and so it needs to be present in |
| 3221 | // all structs. If it was not marked as keep then it would be cleared in some structs and so would |
| 3222 | // be unavailable for generating file names if there were other properties that were still set. |
| 3223 | Stem string `sdk:"keep"` |
| 3224 | |
Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 3225 | // Scope to per scope properties. |
Paul Duffin | 106a3a4 | 2022-01-27 16:39:06 +0000 | [diff] [blame] | 3226 | Scopes map[*apiScope]*scopeProperties |
Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 3227 | |
Paul Duffin | 3d1248c | 2020-04-09 00:10:17 +0100 | [diff] [blame] | 3228 | // The Java stubs source files. |
| 3229 | Stub_srcs []string |
Paul Duffin | f7a6433 | 2020-05-13 16:54:55 +0100 | [diff] [blame] | 3230 | |
| 3231 | // The naming scheme. |
| 3232 | Naming_scheme *string |
Paul Duffin | d7eb1c2 | 2020-05-26 20:57:10 +0100 | [diff] [blame] | 3233 | |
| 3234 | // True if the java_sdk_library_import is for a shared library, false |
| 3235 | // otherwise. |
| 3236 | Shared_library *bool |
Paul Duffin | a2ae7e0 | 2020-09-11 11:55:00 +0100 | [diff] [blame] | 3237 | |
Paul Duffin | 1267d87 | 2021-04-16 17:21:36 +0100 | [diff] [blame] | 3238 | // True if the stub imports should produce dex jars. |
| 3239 | Compile_dex *bool |
| 3240 | |
Paul Duffin | a2ae7e0 | 2020-09-11 11:55:00 +0100 | [diff] [blame] | 3241 | // The paths to the doctag files to add to the prebuilt. |
| 3242 | Doctag_paths android.Paths |
Paul Duffin | 869de14 | 2021-07-15 14:14:41 +0100 | [diff] [blame] | 3243 | |
| 3244 | Permitted_packages []string |
Pedro Loureiro | 9956e5e | 2021-09-07 17:21:59 +0000 | [diff] [blame] | 3245 | |
| 3246 | // Signals that this shared library is part of the bootclasspath starting |
| 3247 | // on the version indicated in this attribute. |
| 3248 | // |
| 3249 | // This will make platforms at this level and above to ignore |
| 3250 | // <uses-library> tags with this library name because the library is already |
| 3251 | // available |
| 3252 | On_bootclasspath_since *string |
| 3253 | |
| 3254 | // Signals that this shared library was part of the bootclasspath before |
| 3255 | // (but not including) the version indicated in this attribute. |
| 3256 | // |
| 3257 | // The system will automatically add a <uses-library> tag with this library to |
| 3258 | // apps that target any SDK less than the version indicated in this attribute. |
| 3259 | On_bootclasspath_before *string |
| 3260 | |
| 3261 | // Indicates that PackageManager should ignore this shared library if the |
| 3262 | // platform is below the version indicated in this attribute. |
| 3263 | // |
| 3264 | // This means that the device won't recognise this library as installed. |
| 3265 | Min_device_sdk *string |
| 3266 | |
| 3267 | // Indicates that PackageManager should ignore this shared library if the |
| 3268 | // platform is above the version indicated in this attribute. |
| 3269 | // |
| 3270 | // This means that the device won't recognise this library as installed. |
| 3271 | Max_device_sdk *string |
Jiakai Zhang | 9c4dc19 | 2023-02-09 00:09:24 +0800 | [diff] [blame] | 3272 | |
| 3273 | DexPreoptProfileGuided *bool `supported_build_releases:"UpsideDownCake+"` |
Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 3274 | } |
| 3275 | |
| 3276 | type scopeProperties struct { |
Paul Duffin | 1fd005d | 2020-04-09 01:08:11 +0100 | [diff] [blame] | 3277 | Jars android.Paths |
| 3278 | StubsSrcJar android.Path |
| 3279 | CurrentApiFile android.Path |
| 3280 | RemovedApiFile android.Path |
Paul Duffin | e7babdb | 2022-02-10 13:06:54 +0000 | [diff] [blame] | 3281 | AnnotationsZip android.Path `supported_build_releases:"Tiramisu+"` |
Paul Duffin | 1fd005d | 2020-04-09 01:08:11 +0100 | [diff] [blame] | 3282 | SdkVersion string |
Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 3283 | } |
| 3284 | |
| 3285 | func (s *sdkLibrarySdkMemberProperties) PopulateFromVariant(ctx android.SdkMemberContext, variant android.Module) { |
| 3286 | sdk := variant.(*SdkLibrary) |
| 3287 | |
Paul Duffin | e840995 | 2022-09-22 16:24:46 +0100 | [diff] [blame] | 3288 | // Copy the stem name for files in the sdk snapshot. |
| 3289 | s.Stem = sdk.distStem() |
| 3290 | |
Paul Duffin | 106a3a4 | 2022-01-27 16:39:06 +0000 | [diff] [blame] | 3291 | s.Scopes = make(map[*apiScope]*scopeProperties) |
Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 3292 | for _, apiScope := range allApiScopes { |
Paul Duffin | 803a956 | 2020-05-20 11:52:25 +0100 | [diff] [blame] | 3293 | paths := sdk.findScopePaths(apiScope) |
| 3294 | if paths == nil { |
| 3295 | continue |
| 3296 | } |
| 3297 | |
Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 3298 | jars := paths.stubsImplPath |
| 3299 | if len(jars) > 0 { |
| 3300 | properties := scopeProperties{} |
| 3301 | properties.Jars = jars |
Paul Duffin | 780c5f4 | 2020-05-12 15:52:55 +0100 | [diff] [blame] | 3302 | properties.SdkVersion = sdk.sdkVersionForStubsLibrary(ctx.SdkModuleContext(), apiScope) |
Paul Duffin | 0f8faff | 2020-05-20 16:18:00 +0100 | [diff] [blame] | 3303 | properties.StubsSrcJar = paths.stubsSrcJar.Path() |
Paul Duffin | 10269f1 | 2020-06-19 18:39:55 +0100 | [diff] [blame] | 3304 | if paths.currentApiFilePath.Valid() { |
| 3305 | properties.CurrentApiFile = paths.currentApiFilePath.Path() |
| 3306 | } |
| 3307 | if paths.removedApiFilePath.Valid() { |
| 3308 | properties.RemovedApiFile = paths.removedApiFilePath.Path() |
| 3309 | } |
Anton Hansson | d78eb76 | 2021-09-21 15:25:12 +0100 | [diff] [blame] | 3310 | // The annotations zip is only available for modules that set annotations_enabled: true. |
| 3311 | if paths.annotationsZip.Valid() { |
| 3312 | properties.AnnotationsZip = paths.annotationsZip.Path() |
| 3313 | } |
Paul Duffin | 106a3a4 | 2022-01-27 16:39:06 +0000 | [diff] [blame] | 3314 | s.Scopes[apiScope] = &properties |
Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 3315 | } |
| 3316 | } |
| 3317 | |
Paul Duffin | dfa131e | 2020-05-15 20:37:11 +0100 | [diff] [blame] | 3318 | s.Naming_scheme = sdk.commonSdkLibraryProperties.Naming_scheme |
Paul Duffin | d7eb1c2 | 2020-05-26 20:57:10 +0100 | [diff] [blame] | 3319 | s.Shared_library = proptools.BoolPtr(sdk.sharedLibrary()) |
Paul Duffin | 1267d87 | 2021-04-16 17:21:36 +0100 | [diff] [blame] | 3320 | s.Compile_dex = sdk.dexProperties.Compile_dex |
Paul Duffin | a2ae7e0 | 2020-09-11 11:55:00 +0100 | [diff] [blame] | 3321 | s.Doctag_paths = sdk.doctagPaths |
Paul Duffin | 869de14 | 2021-07-15 14:14:41 +0100 | [diff] [blame] | 3322 | s.Permitted_packages = sdk.PermittedPackagesForUpdatableBootJars() |
Pedro Loureiro | 9956e5e | 2021-09-07 17:21:59 +0000 | [diff] [blame] | 3323 | s.On_bootclasspath_since = sdk.commonSdkLibraryProperties.On_bootclasspath_since |
| 3324 | s.On_bootclasspath_before = sdk.commonSdkLibraryProperties.On_bootclasspath_before |
| 3325 | s.Min_device_sdk = sdk.commonSdkLibraryProperties.Min_device_sdk |
| 3326 | s.Max_device_sdk = sdk.commonSdkLibraryProperties.Max_device_sdk |
Jiakai Zhang | 9c4dc19 | 2023-02-09 00:09:24 +0800 | [diff] [blame] | 3327 | |
| 3328 | if sdk.dexpreopter.dexpreoptProperties.Dex_preopt_result.Profile_guided { |
| 3329 | s.DexPreoptProfileGuided = proptools.BoolPtr(true) |
| 3330 | } |
Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 3331 | } |
| 3332 | |
| 3333 | func (s *sdkLibrarySdkMemberProperties) AddToPropertySet(ctx android.SdkMemberContext, propertySet android.BpPropertySet) { |
Paul Duffin | f7a6433 | 2020-05-13 16:54:55 +0100 | [diff] [blame] | 3334 | if s.Naming_scheme != nil { |
| 3335 | propertySet.AddProperty("naming_scheme", proptools.String(s.Naming_scheme)) |
| 3336 | } |
Paul Duffin | d7eb1c2 | 2020-05-26 20:57:10 +0100 | [diff] [blame] | 3337 | if s.Shared_library != nil { |
| 3338 | propertySet.AddProperty("shared_library", *s.Shared_library) |
| 3339 | } |
Paul Duffin | 1267d87 | 2021-04-16 17:21:36 +0100 | [diff] [blame] | 3340 | if s.Compile_dex != nil { |
| 3341 | propertySet.AddProperty("compile_dex", *s.Compile_dex) |
| 3342 | } |
Paul Duffin | 869de14 | 2021-07-15 14:14:41 +0100 | [diff] [blame] | 3343 | if len(s.Permitted_packages) > 0 { |
| 3344 | propertySet.AddProperty("permitted_packages", s.Permitted_packages) |
| 3345 | } |
Jiakai Zhang | 9c4dc19 | 2023-02-09 00:09:24 +0800 | [diff] [blame] | 3346 | dexPreoptSet := propertySet.AddPropertySet("dex_preopt") |
| 3347 | if s.DexPreoptProfileGuided != nil { |
| 3348 | dexPreoptSet.AddProperty("profile_guided", proptools.Bool(s.DexPreoptProfileGuided)) |
| 3349 | } |
Paul Duffin | f7a6433 | 2020-05-13 16:54:55 +0100 | [diff] [blame] | 3350 | |
Paul Duffin | e840995 | 2022-09-22 16:24:46 +0100 | [diff] [blame] | 3351 | stem := s.Stem |
| 3352 | |
Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 3353 | for _, apiScope := range allApiScopes { |
| 3354 | if properties, ok := s.Scopes[apiScope]; ok { |
Paul Duffin | 6b836ba | 2020-05-13 19:19:49 +0100 | [diff] [blame] | 3355 | scopeSet := propertySet.AddPropertySet(apiScope.propertyName) |
Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 3356 | |
Paul Duffin | 958806b | 2022-05-16 13:10:47 +0000 | [diff] [blame] | 3357 | scopeDir := apiScope.snapshotRelativeDir() |
Paul Duffin | 3d1248c | 2020-04-09 00:10:17 +0100 | [diff] [blame] | 3358 | |
Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 3359 | var jars []string |
| 3360 | for _, p := range properties.Jars { |
Paul Duffin | e840995 | 2022-09-22 16:24:46 +0100 | [diff] [blame] | 3361 | dest := filepath.Join(scopeDir, stem+"-stubs.jar") |
Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 3362 | ctx.SnapshotBuilder().CopyToSnapshot(p, dest) |
| 3363 | jars = append(jars, dest) |
| 3364 | } |
| 3365 | scopeSet.AddProperty("jars", jars) |
| 3366 | |
Paul Duffin | 22628d5 | 2021-05-12 23:13:22 +0100 | [diff] [blame] | 3367 | if ctx.SdkModuleContext().Config().IsEnvTrue("SOONG_SDK_SNAPSHOT_USE_SRCJAR") { |
| 3368 | // Copy the stubs source jar into the snapshot zip as is. |
Paul Duffin | e840995 | 2022-09-22 16:24:46 +0100 | [diff] [blame] | 3369 | srcJarSnapshotPath := filepath.Join(scopeDir, stem+".srcjar") |
Paul Duffin | 22628d5 | 2021-05-12 23:13:22 +0100 | [diff] [blame] | 3370 | ctx.SnapshotBuilder().CopyToSnapshot(properties.StubsSrcJar, srcJarSnapshotPath) |
| 3371 | scopeSet.AddProperty("stub_srcs", []string{srcJarSnapshotPath}) |
| 3372 | } else { |
| 3373 | // Merge the stubs source jar into the snapshot zip so that when it is unpacked |
| 3374 | // the source files are also unpacked. |
Paul Duffin | e840995 | 2022-09-22 16:24:46 +0100 | [diff] [blame] | 3375 | snapshotRelativeDir := filepath.Join(scopeDir, stem+"_stub_sources") |
Paul Duffin | 22628d5 | 2021-05-12 23:13:22 +0100 | [diff] [blame] | 3376 | ctx.SnapshotBuilder().UnzipToSnapshot(properties.StubsSrcJar, snapshotRelativeDir) |
| 3377 | scopeSet.AddProperty("stub_srcs", []string{snapshotRelativeDir}) |
| 3378 | } |
Paul Duffin | 3d1248c | 2020-04-09 00:10:17 +0100 | [diff] [blame] | 3379 | |
Paul Duffin | 1fd005d | 2020-04-09 01:08:11 +0100 | [diff] [blame] | 3380 | if properties.CurrentApiFile != nil { |
Paul Duffin | e840995 | 2022-09-22 16:24:46 +0100 | [diff] [blame] | 3381 | currentApiSnapshotPath := apiScope.snapshotRelativeCurrentApiTxtPath(stem) |
Paul Duffin | 1fd005d | 2020-04-09 01:08:11 +0100 | [diff] [blame] | 3382 | ctx.SnapshotBuilder().CopyToSnapshot(properties.CurrentApiFile, currentApiSnapshotPath) |
| 3383 | scopeSet.AddProperty("current_api", currentApiSnapshotPath) |
| 3384 | } |
| 3385 | |
| 3386 | if properties.RemovedApiFile != nil { |
Paul Duffin | e840995 | 2022-09-22 16:24:46 +0100 | [diff] [blame] | 3387 | removedApiSnapshotPath := apiScope.snapshotRelativeRemovedApiTxtPath(stem) |
Paul Duffin | 3dbf9fd | 2020-06-02 13:00:02 +0100 | [diff] [blame] | 3388 | ctx.SnapshotBuilder().CopyToSnapshot(properties.RemovedApiFile, removedApiSnapshotPath) |
Paul Duffin | 1fd005d | 2020-04-09 01:08:11 +0100 | [diff] [blame] | 3389 | scopeSet.AddProperty("removed_api", removedApiSnapshotPath) |
| 3390 | } |
| 3391 | |
Anton Hansson | d78eb76 | 2021-09-21 15:25:12 +0100 | [diff] [blame] | 3392 | if properties.AnnotationsZip != nil { |
Paul Duffin | e840995 | 2022-09-22 16:24:46 +0100 | [diff] [blame] | 3393 | annotationsSnapshotPath := filepath.Join(scopeDir, stem+"_annotations.zip") |
Anton Hansson | d78eb76 | 2021-09-21 15:25:12 +0100 | [diff] [blame] | 3394 | ctx.SnapshotBuilder().CopyToSnapshot(properties.AnnotationsZip, annotationsSnapshotPath) |
| 3395 | scopeSet.AddProperty("annotations", annotationsSnapshotPath) |
| 3396 | } |
| 3397 | |
Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 3398 | if properties.SdkVersion != "" { |
| 3399 | scopeSet.AddProperty("sdk_version", properties.SdkVersion) |
| 3400 | } |
| 3401 | } |
| 3402 | } |
| 3403 | |
Paul Duffin | a2ae7e0 | 2020-09-11 11:55:00 +0100 | [diff] [blame] | 3404 | if len(s.Doctag_paths) > 0 { |
| 3405 | dests := []string{} |
| 3406 | for _, p := range s.Doctag_paths { |
| 3407 | dest := filepath.Join("doctags", p.Rel()) |
| 3408 | ctx.SnapshotBuilder().CopyToSnapshot(p, dest) |
| 3409 | dests = append(dests, dest) |
| 3410 | } |
| 3411 | propertySet.AddProperty("doctag_files", dests) |
| 3412 | } |
Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 3413 | } |