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