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