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