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