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