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