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