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