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