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" |
Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 22 | "sort" |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 23 | "strings" |
Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 24 | "sync" |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 25 | |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 26 | "github.com/google/blueprint" |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 27 | "github.com/google/blueprint/proptools" |
Paul Duffin | 46a26a8 | 2020-04-07 19:27:04 +0100 | [diff] [blame] | 28 | |
| 29 | "android/soong/android" |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 30 | ) |
| 31 | |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 32 | const ( |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 33 | sdkStubsLibrarySuffix = ".stubs" |
| 34 | sdkSystemApiSuffix = ".system" |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 35 | sdkTestApiSuffix = ".test" |
Paul Duffin | 91b883d | 2020-02-11 13:05:28 +0000 | [diff] [blame] | 36 | sdkStubsSourceSuffix = ".stubs.source" |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 37 | sdkXmlFileSuffix = ".xml" |
Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 38 | permissionsTemplate = `<?xml version=\"1.0\" encoding=\"utf-8\"?>\n` + |
Jooyung Han | 624058e | 2019-12-24 18:38:06 +0900 | [diff] [blame] | 39 | `<!-- Copyright (C) 2018 The Android Open Source Project\n` + |
| 40 | `\n` + |
Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 41 | ` Licensed under the Apache License, Version 2.0 (the \"License\");\n` + |
Jooyung Han | 624058e | 2019-12-24 18:38:06 +0900 | [diff] [blame] | 42 | ` you may not use this file except in compliance with the License.\n` + |
| 43 | ` You may obtain a copy of the License at\n` + |
| 44 | `\n` + |
| 45 | ` http://www.apache.org/licenses/LICENSE-2.0\n` + |
| 46 | `\n` + |
| 47 | ` Unless required by applicable law or agreed to in writing, software\n` + |
Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 48 | ` distributed under the License is distributed on an \"AS IS\" BASIS,\n` + |
Jooyung Han | 624058e | 2019-12-24 18:38:06 +0900 | [diff] [blame] | 49 | ` WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n` + |
| 50 | ` See the License for the specific language governing permissions and\n` + |
| 51 | ` limitations under the License.\n` + |
| 52 | `-->\n` + |
| 53 | `<permissions>\n` + |
Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 54 | ` <library name=\"%s\" file=\"%s\"/>\n` + |
Jooyung Han | 624058e | 2019-12-24 18:38:06 +0900 | [diff] [blame] | 55 | `</permissions>\n` |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 56 | ) |
| 57 | |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 58 | // A tag to associated a dependency with a specific api scope. |
| 59 | type scopeDependencyTag struct { |
| 60 | blueprint.BaseDependencyTag |
| 61 | name string |
| 62 | apiScope *apiScope |
| 63 | } |
| 64 | |
| 65 | // Provides information about an api scope, e.g. public, system, test. |
| 66 | type apiScope struct { |
| 67 | // The name of the api scope, e.g. public, system, test |
| 68 | name string |
| 69 | |
Paul Duffin | 97b53b8 | 2020-05-05 14:40:52 +0100 | [diff] [blame] | 70 | // The api scope that this scope extends. |
| 71 | extends *apiScope |
| 72 | |
Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 73 | // The legacy enabled status for a specific scope can be dependent on other |
| 74 | // properties that have been specified on the library so it is provided by |
| 75 | // a function that can determine the status by examining those properties. |
| 76 | legacyEnabledStatus func(module *SdkLibrary) bool |
| 77 | |
| 78 | // The default enabled status for non-legacy behavior, which is triggered by |
| 79 | // explicitly enabling at least one api scope. |
| 80 | defaultEnabledStatus bool |
| 81 | |
| 82 | // Gets a pointer to the scope specific properties. |
| 83 | scopeSpecificProperties func(module *SdkLibrary) *ApiScopeProperties |
| 84 | |
Paul Duffin | 46a26a8 | 2020-04-07 19:27:04 +0100 | [diff] [blame] | 85 | // The name of the field in the dynamically created structure. |
| 86 | fieldName string |
| 87 | |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 88 | // The tag to use to depend on the stubs library module. |
| 89 | stubsTag scopeDependencyTag |
| 90 | |
| 91 | // The tag to use to depend on the stubs |
| 92 | apiFileTag scopeDependencyTag |
| 93 | |
| 94 | // The scope specific prefix to add to the api file base of "current.txt" or "removed.txt". |
| 95 | apiFilePrefix string |
| 96 | |
| 97 | // The scope specific prefix to add to the sdk library module name to construct a scope specific |
| 98 | // module name. |
| 99 | moduleSuffix string |
| 100 | |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 101 | // SDK version that the stubs library is built against. Note that this is always |
| 102 | // *current. Older stubs library built with a numbered SDK version is created from |
| 103 | // the prebuilt jar. |
| 104 | sdkVersion string |
Paul Duffin | 1fb487d | 2020-04-07 18:50:10 +0100 | [diff] [blame] | 105 | |
| 106 | // Extra arguments to pass to droidstubs for this scope. |
| 107 | droidstubsArgs []string |
Anton Hansson | 6478ac1 | 2020-05-02 11:19:36 +0100 | [diff] [blame] | 108 | |
| 109 | // Whether the api scope can be treated as unstable, and should skip compat checks. |
| 110 | unstable bool |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | // Initialize a scope, creating and adding appropriate dependency tags |
| 114 | func initApiScope(scope *apiScope) *apiScope { |
Paul Duffin | 46a26a8 | 2020-04-07 19:27:04 +0100 | [diff] [blame] | 115 | scope.fieldName = proptools.FieldNameForProperty(scope.name) |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 116 | scope.stubsTag = scopeDependencyTag{ |
| 117 | name: scope.name + "-stubs", |
| 118 | apiScope: scope, |
| 119 | } |
| 120 | scope.apiFileTag = scopeDependencyTag{ |
| 121 | name: scope.name + "-api", |
| 122 | apiScope: scope, |
| 123 | } |
| 124 | return scope |
| 125 | } |
| 126 | |
| 127 | func (scope *apiScope) stubsModuleName(baseName string) string { |
| 128 | return baseName + sdkStubsLibrarySuffix + scope.moduleSuffix |
| 129 | } |
| 130 | |
| 131 | func (scope *apiScope) docsModuleName(baseName string) string { |
Paul Duffin | 91b883d | 2020-02-11 13:05:28 +0000 | [diff] [blame] | 132 | return baseName + sdkStubsSourceSuffix + scope.moduleSuffix |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 133 | } |
| 134 | |
Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 135 | func (scope *apiScope) String() string { |
| 136 | return scope.name |
| 137 | } |
| 138 | |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 139 | type apiScopes []*apiScope |
| 140 | |
| 141 | func (scopes apiScopes) Strings(accessor func(*apiScope) string) []string { |
| 142 | var list []string |
| 143 | for _, scope := range scopes { |
| 144 | list = append(list, accessor(scope)) |
| 145 | } |
| 146 | return list |
| 147 | } |
| 148 | |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 149 | var ( |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 150 | apiScopePublic = initApiScope(&apiScope{ |
Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 151 | name: "public", |
| 152 | |
| 153 | // Public scope is enabled by default for both legacy and non-legacy modes. |
| 154 | legacyEnabledStatus: func(module *SdkLibrary) bool { |
| 155 | return true |
| 156 | }, |
| 157 | defaultEnabledStatus: true, |
| 158 | |
| 159 | scopeSpecificProperties: func(module *SdkLibrary) *ApiScopeProperties { |
| 160 | return &module.sdkLibraryProperties.Public |
| 161 | }, |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 162 | sdkVersion: "current", |
| 163 | }) |
| 164 | apiScopeSystem = initApiScope(&apiScope{ |
Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 165 | name: "system", |
| 166 | extends: apiScopePublic, |
| 167 | legacyEnabledStatus: (*SdkLibrary).generateTestAndSystemScopesByDefault, |
| 168 | scopeSpecificProperties: func(module *SdkLibrary) *ApiScopeProperties { |
| 169 | return &module.sdkLibraryProperties.System |
| 170 | }, |
Anton Hansson | 6affb1f | 2020-04-28 16:47:41 +0100 | [diff] [blame] | 171 | apiFilePrefix: "system-", |
| 172 | moduleSuffix: sdkSystemApiSuffix, |
| 173 | sdkVersion: "system_current", |
| 174 | droidstubsArgs: []string{"-showAnnotation android.annotation.SystemApi"}, |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 175 | }) |
| 176 | apiScopeTest = initApiScope(&apiScope{ |
Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 177 | name: "test", |
| 178 | extends: apiScopePublic, |
| 179 | legacyEnabledStatus: (*SdkLibrary).generateTestAndSystemScopesByDefault, |
| 180 | scopeSpecificProperties: func(module *SdkLibrary) *ApiScopeProperties { |
| 181 | return &module.sdkLibraryProperties.Test |
| 182 | }, |
Anton Hansson | 6affb1f | 2020-04-28 16:47:41 +0100 | [diff] [blame] | 183 | apiFilePrefix: "test-", |
| 184 | moduleSuffix: sdkTestApiSuffix, |
| 185 | sdkVersion: "test_current", |
| 186 | droidstubsArgs: []string{"-showAnnotation android.annotation.TestApi"}, |
Anton Hansson | 6478ac1 | 2020-05-02 11:19:36 +0100 | [diff] [blame] | 187 | unstable: true, |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 188 | }) |
Paul Duffin | 8f265b9 | 2020-04-28 14:13:56 +0100 | [diff] [blame] | 189 | apiScopeModuleLib = initApiScope(&apiScope{ |
| 190 | name: "module_lib", |
| 191 | extends: apiScopeSystem, |
| 192 | // Module_lib scope is disabled by default in legacy mode. |
| 193 | // |
| 194 | // Enabling this would break existing usages. |
| 195 | legacyEnabledStatus: func(module *SdkLibrary) bool { |
| 196 | return false |
| 197 | }, |
| 198 | scopeSpecificProperties: func(module *SdkLibrary) *ApiScopeProperties { |
| 199 | return &module.sdkLibraryProperties.Module_lib |
| 200 | }, |
| 201 | apiFilePrefix: "module-lib-", |
| 202 | moduleSuffix: ".module_lib", |
| 203 | sdkVersion: "module_current", |
| 204 | droidstubsArgs: []string{ |
| 205 | "--show-annotation android.annotation.SystemApi\\(client=android.annotation.SystemApi.Client.MODULE_LIBRARIES\\)", |
| 206 | }, |
| 207 | }) |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 208 | allApiScopes = apiScopes{ |
| 209 | apiScopePublic, |
| 210 | apiScopeSystem, |
| 211 | apiScopeTest, |
Paul Duffin | 8f265b9 | 2020-04-28 14:13:56 +0100 | [diff] [blame] | 212 | apiScopeModuleLib, |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 213 | } |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 214 | ) |
| 215 | |
Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 216 | var ( |
| 217 | javaSdkLibrariesLock sync.Mutex |
| 218 | ) |
| 219 | |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 220 | // TODO: these are big features that are currently missing |
Jiyong Park | 1be9691 | 2018-05-28 18:02:19 +0900 | [diff] [blame] | 221 | // 1) disallowing linking to the runtime shared lib |
| 222 | // 2) HTML generation |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 223 | |
| 224 | func init() { |
Paul Duffin | 43dc1cc | 2019-12-19 11:18:54 +0000 | [diff] [blame] | 225 | RegisterSdkLibraryBuildComponents(android.InitRegistrationContext) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 226 | |
Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 227 | android.RegisterMakeVarsProvider(pctx, func(ctx android.MakeVarsContext) { |
| 228 | javaSdkLibraries := javaSdkLibraries(ctx.Config()) |
| 229 | sort.Strings(*javaSdkLibraries) |
| 230 | ctx.Strict("JAVA_SDK_LIBRARIES", strings.Join(*javaSdkLibraries, " ")) |
| 231 | }) |
Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 232 | |
| 233 | // Register sdk member types. |
| 234 | android.RegisterSdkMemberType(&sdkLibrarySdkMemberType{ |
| 235 | android.SdkMemberTypeBase{ |
| 236 | PropertyName: "java_sdk_libs", |
| 237 | SupportsSdk: true, |
| 238 | }, |
| 239 | }) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 240 | } |
| 241 | |
Paul Duffin | 43dc1cc | 2019-12-19 11:18:54 +0000 | [diff] [blame] | 242 | func RegisterSdkLibraryBuildComponents(ctx android.RegistrationContext) { |
| 243 | ctx.RegisterModuleType("java_sdk_library", SdkLibraryFactory) |
| 244 | ctx.RegisterModuleType("java_sdk_library_import", sdkLibraryImportFactory) |
| 245 | } |
| 246 | |
Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 247 | // Properties associated with each api scope. |
| 248 | type ApiScopeProperties struct { |
| 249 | // Indicates whether the api surface is generated. |
| 250 | // |
| 251 | // If this is set for any scope then all scopes must explicitly specify if they |
| 252 | // are enabled. This is to prevent new usages from depending on legacy behavior. |
| 253 | // |
| 254 | // Otherwise, if this is not set for any scope then the default behavior is |
| 255 | // scope specific so please refer to the scope specific property documentation. |
| 256 | Enabled *bool |
| 257 | } |
| 258 | |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 259 | type sdkLibraryProperties struct { |
Paul Duffin | 4911a89 | 2020-04-29 23:35:13 +0100 | [diff] [blame] | 260 | // Visibility for stubs library modules. If not specified then defaults to the |
| 261 | // visibility property. |
| 262 | Stubs_library_visibility []string |
| 263 | |
| 264 | // Visibility for stubs source modules. If not specified then defaults to the |
| 265 | // visibility property. |
| 266 | Stubs_source_visibility []string |
| 267 | |
Sundong Ahn | f043cf6 | 2018-06-25 16:04:37 +0900 | [diff] [blame] | 268 | // List of Java libraries that will be in the classpath when building stubs |
| 269 | Stub_only_libs []string `android:"arch_variant"` |
| 270 | |
Paul Duffin | 7a586d3 | 2019-12-30 17:09:34 +0000 | [diff] [blame] | 271 | // list of package names that will be documented and publicized as API. |
| 272 | // This allows the API to be restricted to a subset of the source files provided. |
| 273 | // If this is unspecified then all the source files will be treated as being part |
| 274 | // of the API. |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 275 | Api_packages []string |
| 276 | |
Jiyong Park | 5a2c9d7 | 2018-05-01 22:25:41 +0900 | [diff] [blame] | 277 | // list of package names that must be hidden from the API |
| 278 | Hidden_api_packages []string |
| 279 | |
Paul Duffin | 749f98f | 2019-12-30 17:23:46 +0000 | [diff] [blame] | 280 | // the relative path to the directory containing the api specification files. |
| 281 | // Defaults to "api". |
| 282 | Api_dir *string |
| 283 | |
Paul Duffin | 43db9be | 2019-12-30 17:35:49 +0000 | [diff] [blame] | 284 | // If set to true there is no runtime library. |
| 285 | Api_only *bool |
| 286 | |
Paul Duffin | 1151247 | 2019-02-11 15:55:17 +0000 | [diff] [blame] | 287 | // local files that are used within user customized droiddoc options. |
| 288 | Droiddoc_option_files []string |
| 289 | |
| 290 | // additional droiddoc options |
| 291 | // Available variables for substitution: |
| 292 | // |
| 293 | // $(location <label>): the path to the droiddoc_option_files with name <label> |
Sundong Ahn | dd567f9 | 2018-07-31 17:19:11 +0900 | [diff] [blame] | 294 | Droiddoc_options []string |
| 295 | |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 296 | // a list of top-level directories containing files to merge qualifier annotations |
| 297 | // (i.e. those intended to be included in the stubs written) from. |
| 298 | Merge_annotations_dirs []string |
| 299 | |
| 300 | // a list of top-level directories containing Java stub files to merge show/hide annotations from. |
| 301 | Merge_inclusion_annotations_dirs []string |
| 302 | |
| 303 | // If set to true, the path of dist files is apistubs/core. Defaults to false. |
| 304 | Core_lib *bool |
| 305 | |
Sundong Ahn | 80a87b3 | 2019-05-13 15:02:50 +0900 | [diff] [blame] | 306 | // don't create dist rules. |
| 307 | No_dist *bool `blueprint:"mutated"` |
| 308 | |
Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 309 | // indicates whether system and test apis should be generated. |
| 310 | Generate_system_and_test_apis bool `blueprint:"mutated"` |
| 311 | |
| 312 | // The properties specific to the public api scope |
| 313 | // |
| 314 | // Unless explicitly specified by using public.enabled the public api scope is |
| 315 | // enabled by default in both legacy and non-legacy mode. |
| 316 | Public ApiScopeProperties |
| 317 | |
| 318 | // The properties specific to the system api scope |
| 319 | // |
| 320 | // In legacy mode the system api scope is enabled by default when sdk_version |
| 321 | // is set to something other than "none". |
| 322 | // |
| 323 | // In non-legacy mode the system api scope is disabled by default. |
| 324 | System ApiScopeProperties |
| 325 | |
| 326 | // The properties specific to the test api scope |
| 327 | // |
| 328 | // In legacy mode the test api scope is enabled by default when sdk_version |
| 329 | // is set to something other than "none". |
| 330 | // |
| 331 | // In non-legacy mode the test api scope is disabled by default. |
| 332 | Test ApiScopeProperties |
Paul Duffin | 37e0b77 | 2019-12-30 17:20:10 +0000 | [diff] [blame] | 333 | |
Paul Duffin | 8f265b9 | 2020-04-28 14:13:56 +0100 | [diff] [blame] | 334 | // The properties specific to the module_lib api scope |
| 335 | // |
| 336 | // Unless explicitly specified by using test.enabled the module_lib api scope is |
| 337 | // disabled by default. |
| 338 | Module_lib ApiScopeProperties |
| 339 | |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 340 | // TODO: determines whether to create HTML doc or not |
| 341 | //Html_doc *bool |
| 342 | } |
| 343 | |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 344 | type scopePaths struct { |
Paul Duffin | 1fd005d | 2020-04-09 01:08:11 +0100 | [diff] [blame] | 345 | stubsHeaderPath android.Paths |
| 346 | stubsImplPath android.Paths |
| 347 | currentApiFilePath android.Path |
| 348 | removedApiFilePath android.Path |
| 349 | stubsSrcJar android.Path |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 350 | } |
| 351 | |
Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 352 | // Common code between sdk library and sdk library import |
| 353 | type commonToSdkLibraryAndImport struct { |
| 354 | scopePaths map[*apiScope]*scopePaths |
| 355 | } |
| 356 | |
| 357 | func (c *commonToSdkLibraryAndImport) getScopePaths(scope *apiScope) *scopePaths { |
| 358 | if c.scopePaths == nil { |
| 359 | c.scopePaths = make(map[*apiScope]*scopePaths) |
| 360 | } |
| 361 | paths := c.scopePaths[scope] |
| 362 | if paths == nil { |
| 363 | paths = &scopePaths{} |
| 364 | c.scopePaths[scope] = paths |
| 365 | } |
| 366 | |
| 367 | return paths |
| 368 | } |
| 369 | |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 370 | type SdkLibrary struct { |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 371 | Library |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 372 | |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 373 | sdkLibraryProperties sdkLibraryProperties |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 374 | |
Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 375 | // Map from api scope to the scope specific property structure. |
| 376 | scopeToProperties map[*apiScope]*ApiScopeProperties |
| 377 | |
Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 378 | commonToSdkLibraryAndImport |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 379 | } |
| 380 | |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 381 | var _ Dependency = (*SdkLibrary)(nil) |
| 382 | var _ SdkLibraryDependency = (*SdkLibrary)(nil) |
Colin Cross | 897d2ed | 2019-02-11 14:03:51 -0800 | [diff] [blame] | 383 | |
Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 384 | func (module *SdkLibrary) generateTestAndSystemScopesByDefault() bool { |
| 385 | return module.sdkLibraryProperties.Generate_system_and_test_apis |
| 386 | } |
| 387 | |
| 388 | func (module *SdkLibrary) getGeneratedApiScopes(ctx android.EarlyModuleContext) apiScopes { |
| 389 | // Check to see if any scopes have been explicitly enabled. If any have then all |
| 390 | // must be. |
| 391 | anyScopesExplicitlyEnabled := false |
| 392 | for _, scope := range allApiScopes { |
| 393 | scopeProperties := module.scopeToProperties[scope] |
| 394 | if scopeProperties.Enabled != nil { |
| 395 | anyScopesExplicitlyEnabled = true |
| 396 | break |
| 397 | } |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 398 | } |
Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 399 | |
| 400 | var generatedScopes apiScopes |
| 401 | enabledScopes := make(map[*apiScope]struct{}) |
| 402 | for _, scope := range allApiScopes { |
| 403 | scopeProperties := module.scopeToProperties[scope] |
| 404 | // If any scopes are explicitly enabled then ignore the legacy enabled status. |
| 405 | // This is to ensure that any new usages of this module type do not rely on legacy |
| 406 | // behaviour. |
| 407 | defaultEnabledStatus := false |
| 408 | if anyScopesExplicitlyEnabled { |
| 409 | defaultEnabledStatus = scope.defaultEnabledStatus |
| 410 | } else { |
| 411 | defaultEnabledStatus = scope.legacyEnabledStatus(module) |
| 412 | } |
| 413 | enabled := proptools.BoolDefault(scopeProperties.Enabled, defaultEnabledStatus) |
| 414 | if enabled { |
| 415 | enabledScopes[scope] = struct{}{} |
| 416 | generatedScopes = append(generatedScopes, scope) |
| 417 | } |
| 418 | } |
| 419 | |
| 420 | // Now check to make sure that any scope that is extended by an enabled scope is also |
| 421 | // enabled. |
| 422 | for _, scope := range allApiScopes { |
| 423 | if _, ok := enabledScopes[scope]; ok { |
| 424 | extends := scope.extends |
| 425 | if extends != nil { |
| 426 | if _, ok := enabledScopes[extends]; !ok { |
| 427 | ctx.ModuleErrorf("enabled api scope %q depends on disabled scope %q", scope, extends) |
| 428 | } |
| 429 | } |
| 430 | } |
| 431 | } |
| 432 | |
| 433 | return generatedScopes |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 434 | } |
| 435 | |
Paul Duffin | e74ac73 | 2020-02-06 13:51:46 +0000 | [diff] [blame] | 436 | var xmlPermissionsFileTag = dependencyTag{name: "xml-permissions-file"} |
| 437 | |
Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 438 | func IsXmlPermissionsFileDepTag(depTag blueprint.DependencyTag) bool { |
| 439 | if dt, ok := depTag.(dependencyTag); ok { |
| 440 | return dt == xmlPermissionsFileTag |
| 441 | } |
| 442 | return false |
| 443 | } |
| 444 | |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 445 | func (module *SdkLibrary) DepsMutator(ctx android.BottomUpMutatorContext) { |
Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 446 | for _, apiScope := range module.getGeneratedApiScopes(ctx) { |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 447 | // Add dependencies to the stubs library |
Paul Duffin | 5006151 | 2020-01-21 16:31:05 +0000 | [diff] [blame] | 448 | ctx.AddVariationDependencies(nil, apiScope.stubsTag, module.stubsName(apiScope)) |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 449 | |
Paul Duffin | 5006151 | 2020-01-21 16:31:05 +0000 | [diff] [blame] | 450 | // And the api file |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 451 | ctx.AddVariationDependencies(nil, apiScope.apiFileTag, module.docsName(apiScope)) |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 452 | } |
| 453 | |
Paul Duffin | e74ac73 | 2020-02-06 13:51:46 +0000 | [diff] [blame] | 454 | if !proptools.Bool(module.sdkLibraryProperties.Api_only) { |
| 455 | // Add dependency to the rule for generating the xml permissions file |
Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 456 | ctx.AddDependency(module, xmlPermissionsFileTag, module.xmlFileName()) |
Paul Duffin | e74ac73 | 2020-02-06 13:51:46 +0000 | [diff] [blame] | 457 | } |
| 458 | |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 459 | module.Library.deps(ctx) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 460 | } |
| 461 | |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 462 | func (module *SdkLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Paul Duffin | 43db9be | 2019-12-30 17:35:49 +0000 | [diff] [blame] | 463 | // Don't build an implementation library if this is api only. |
| 464 | if !proptools.Bool(module.sdkLibraryProperties.Api_only) { |
| 465 | module.Library.GenerateAndroidBuildActions(ctx) |
| 466 | } |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 467 | |
Sundong Ahn | 57368eb | 2018-07-06 11:20:23 +0900 | [diff] [blame] | 468 | // 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] | 469 | // 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] | 470 | // the recorded paths will be returned depending on the link type of the caller. |
| 471 | ctx.VisitDirectDeps(func(to android.Module) { |
| 472 | otherName := ctx.OtherModuleName(to) |
| 473 | tag := ctx.OtherModuleDependencyTag(to) |
| 474 | |
Sundong Ahn | 57368eb | 2018-07-06 11:20:23 +0900 | [diff] [blame] | 475 | if lib, ok := to.(Dependency); ok { |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 476 | if scopeTag, ok := tag.(scopeDependencyTag); ok { |
| 477 | apiScope := scopeTag.apiScope |
| 478 | scopePaths := module.getScopePaths(apiScope) |
| 479 | scopePaths.stubsHeaderPath = lib.HeaderJars() |
| 480 | scopePaths.stubsImplPath = lib.ImplementationJars() |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 481 | } |
| 482 | } |
Paul Duffin | 3d1248c | 2020-04-09 00:10:17 +0100 | [diff] [blame] | 483 | if doc, ok := to.(ApiStubsProvider); ok { |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 484 | if scopeTag, ok := tag.(scopeDependencyTag); ok { |
| 485 | apiScope := scopeTag.apiScope |
| 486 | scopePaths := module.getScopePaths(apiScope) |
Paul Duffin | 1fd005d | 2020-04-09 01:08:11 +0100 | [diff] [blame] | 487 | scopePaths.currentApiFilePath = doc.ApiFilePath() |
| 488 | scopePaths.removedApiFilePath = doc.RemovedApiFilePath() |
Paul Duffin | 3d1248c | 2020-04-09 00:10:17 +0100 | [diff] [blame] | 489 | scopePaths.stubsSrcJar = doc.StubsSrcJar() |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 490 | } else { |
Sundong Ahn | 20e998b | 2018-07-24 11:19:26 +0900 | [diff] [blame] | 491 | ctx.ModuleErrorf("depends on module %q of unknown tag %q", otherName, tag) |
| 492 | } |
| 493 | } |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 494 | }) |
| 495 | } |
| 496 | |
Jiyong Park | 0b0e1b9 | 2019-12-03 13:24:29 +0900 | [diff] [blame] | 497 | func (module *SdkLibrary) AndroidMkEntries() []android.AndroidMkEntries { |
Paul Duffin | 43db9be | 2019-12-30 17:35:49 +0000 | [diff] [blame] | 498 | if proptools.Bool(module.sdkLibraryProperties.Api_only) { |
| 499 | return nil |
| 500 | } |
Jiyong Park | 0b0e1b9 | 2019-12-03 13:24:29 +0900 | [diff] [blame] | 501 | entriesList := module.Library.AndroidMkEntries() |
| 502 | entries := &entriesList[0] |
Jaewoong Jung | b0c127c | 2019-08-29 14:56:03 -0700 | [diff] [blame] | 503 | entries.Required = append(entries.Required, module.xmlFileName()) |
Jiyong Park | 0b0e1b9 | 2019-12-03 13:24:29 +0900 | [diff] [blame] | 504 | return entriesList |
Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 505 | } |
| 506 | |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 507 | // Module name of the stubs library |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 508 | func (module *SdkLibrary) stubsName(apiScope *apiScope) string { |
| 509 | return apiScope.stubsModuleName(module.BaseModuleName()) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 510 | } |
| 511 | |
| 512 | // Module name of the docs |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 513 | func (module *SdkLibrary) docsName(apiScope *apiScope) string { |
| 514 | return apiScope.docsModuleName(module.BaseModuleName()) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 515 | } |
| 516 | |
| 517 | // Module name of the runtime implementation library |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 518 | func (module *SdkLibrary) implName() string { |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 519 | return module.BaseModuleName() |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 520 | } |
| 521 | |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 522 | // Module name of the XML file for the lib |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 523 | func (module *SdkLibrary) xmlFileName() string { |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 524 | return module.BaseModuleName() + sdkXmlFileSuffix |
| 525 | } |
| 526 | |
Anton Hansson | 5fd5d24 | 2020-03-27 19:43:19 +0000 | [diff] [blame] | 527 | // The dist path of the stub artifacts |
| 528 | func (module *SdkLibrary) apiDistPath(apiScope *apiScope) string { |
| 529 | if module.ModuleBase.Owner() != "" { |
| 530 | return path.Join("apistubs", module.ModuleBase.Owner(), apiScope.name) |
| 531 | } else if Bool(module.sdkLibraryProperties.Core_lib) { |
| 532 | return path.Join("apistubs", "core", apiScope.name) |
| 533 | } else { |
| 534 | return path.Join("apistubs", "android", apiScope.name) |
| 535 | } |
| 536 | } |
| 537 | |
Paul Duffin | 12ceb46 | 2019-12-24 20:31:31 +0000 | [diff] [blame] | 538 | // Get the sdk version for use when compiling the stubs library. |
Paul Duffin | f022920 | 2020-04-29 16:47:28 +0100 | [diff] [blame] | 539 | func (module *SdkLibrary) sdkVersionForStubsLibrary(mctx android.DefaultableHookContext, apiScope *apiScope) string { |
Paul Duffin | 12ceb46 | 2019-12-24 20:31:31 +0000 | [diff] [blame] | 540 | sdkDep := decodeSdkDep(mctx, sdkContext(&module.Library)) |
| 541 | if sdkDep.hasStandardLibs() { |
| 542 | // 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] | 543 | return apiScope.sdkVersion |
Paul Duffin | 12ceb46 | 2019-12-24 20:31:31 +0000 | [diff] [blame] | 544 | } else { |
| 545 | // Otherwise, use no system module. |
| 546 | return "none" |
| 547 | } |
| 548 | } |
| 549 | |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 550 | func (module *SdkLibrary) latestApiFilegroupName(apiScope *apiScope) string { |
| 551 | return ":" + module.BaseModuleName() + ".api." + apiScope.name + ".latest" |
Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 552 | } |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 553 | |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 554 | func (module *SdkLibrary) latestRemovedApiFilegroupName(apiScope *apiScope) string { |
| 555 | return ":" + module.BaseModuleName() + "-removed.api." + apiScope.name + ".latest" |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 556 | } |
| 557 | |
| 558 | // Creates a static java library that has API stubs |
Paul Duffin | f022920 | 2020-04-29 16:47:28 +0100 | [diff] [blame] | 559 | func (module *SdkLibrary) createStubsLibrary(mctx android.DefaultableHookContext, apiScope *apiScope) { |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 560 | props := struct { |
Sundong Ahn | 0d7dff4 | 2019-12-04 12:53:44 +0900 | [diff] [blame] | 561 | Name *string |
Paul Duffin | 4911a89 | 2020-04-29 23:35:13 +0100 | [diff] [blame] | 562 | Visibility []string |
Sundong Ahn | 0d7dff4 | 2019-12-04 12:53:44 +0900 | [diff] [blame] | 563 | Srcs []string |
Paul Duffin | 367ab91 | 2019-12-23 19:40:36 +0000 | [diff] [blame] | 564 | Installable *bool |
Sundong Ahn | 0d7dff4 | 2019-12-04 12:53:44 +0900 | [diff] [blame] | 565 | Sdk_version *string |
Paul Duffin | 12ceb46 | 2019-12-24 20:31:31 +0000 | [diff] [blame] | 566 | System_modules *string |
Paul Duffin | ab8da5d | 2020-02-07 16:12:04 +0000 | [diff] [blame] | 567 | Patch_module *string |
Sundong Ahn | 0d7dff4 | 2019-12-04 12:53:44 +0900 | [diff] [blame] | 568 | Libs []string |
| 569 | Soc_specific *bool |
| 570 | Device_specific *bool |
| 571 | Product_specific *bool |
| 572 | System_ext_specific *bool |
| 573 | Compile_dex *bool |
Sundong Ahn | 0d7dff4 | 2019-12-04 12:53:44 +0900 | [diff] [blame] | 574 | Java_version *string |
| 575 | Product_variables struct { |
Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 576 | Pdk struct { |
| 577 | Enabled *bool |
| 578 | } |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 579 | } |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 580 | Openjdk9 struct { |
| 581 | Srcs []string |
| 582 | Javacflags []string |
| 583 | } |
Anton Hansson | 5fd5d24 | 2020-03-27 19:43:19 +0000 | [diff] [blame] | 584 | Dist struct { |
| 585 | Targets []string |
| 586 | Dest *string |
| 587 | Dir *string |
| 588 | Tag *string |
| 589 | } |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 590 | }{} |
| 591 | |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 592 | props.Name = proptools.StringPtr(module.stubsName(apiScope)) |
Paul Duffin | 4911a89 | 2020-04-29 23:35:13 +0100 | [diff] [blame] | 593 | |
| 594 | // If stubs_library_visibility is not set then the created module will use the |
| 595 | // visibility of this module. |
| 596 | visibility := module.sdkLibraryProperties.Stubs_library_visibility |
| 597 | props.Visibility = visibility |
| 598 | |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 599 | // sources are generated from the droiddoc |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 600 | props.Srcs = []string{":" + module.docsName(apiScope)} |
Paul Duffin | 12ceb46 | 2019-12-24 20:31:31 +0000 | [diff] [blame] | 601 | sdkVersion := module.sdkVersionForStubsLibrary(mctx, apiScope) |
Paul Duffin | 52d398a | 2019-06-11 12:31:14 +0100 | [diff] [blame] | 602 | props.Sdk_version = proptools.StringPtr(sdkVersion) |
Paul Duffin | 12ceb46 | 2019-12-24 20:31:31 +0000 | [diff] [blame] | 603 | props.System_modules = module.Library.Module.deviceProperties.System_modules |
Paul Duffin | ab8da5d | 2020-02-07 16:12:04 +0000 | [diff] [blame] | 604 | props.Patch_module = module.Library.Module.properties.Patch_module |
Paul Duffin | 367ab91 | 2019-12-23 19:40:36 +0000 | [diff] [blame] | 605 | props.Installable = proptools.BoolPtr(false) |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 606 | props.Libs = module.sdkLibraryProperties.Stub_only_libs |
Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 607 | props.Product_variables.Pdk.Enabled = proptools.BoolPtr(false) |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 608 | props.Openjdk9.Srcs = module.Library.Module.properties.Openjdk9.Srcs |
| 609 | props.Openjdk9.Javacflags = module.Library.Module.properties.Openjdk9.Javacflags |
| 610 | props.Java_version = module.Library.Module.properties.Java_version |
| 611 | if module.Library.Module.deviceProperties.Compile_dex != nil { |
| 612 | props.Compile_dex = module.Library.Module.deviceProperties.Compile_dex |
Sundong Ahn | dd567f9 | 2018-07-31 17:19:11 +0900 | [diff] [blame] | 613 | } |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 614 | |
| 615 | if module.SocSpecific() { |
| 616 | props.Soc_specific = proptools.BoolPtr(true) |
| 617 | } else if module.DeviceSpecific() { |
| 618 | props.Device_specific = proptools.BoolPtr(true) |
| 619 | } else if module.ProductSpecific() { |
| 620 | props.Product_specific = proptools.BoolPtr(true) |
Sundong Ahn | 0d7dff4 | 2019-12-04 12:53:44 +0900 | [diff] [blame] | 621 | } else if module.SystemExtSpecific() { |
| 622 | props.System_ext_specific = proptools.BoolPtr(true) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 623 | } |
Anton Hansson | 5fd5d24 | 2020-03-27 19:43:19 +0000 | [diff] [blame] | 624 | // Dist the class jar artifact for sdk builds. |
| 625 | if !Bool(module.sdkLibraryProperties.No_dist) { |
| 626 | props.Dist.Targets = []string{"sdk", "win_sdk"} |
| 627 | props.Dist.Dest = proptools.StringPtr(fmt.Sprintf("%v.jar", module.BaseModuleName())) |
| 628 | props.Dist.Dir = proptools.StringPtr(module.apiDistPath(apiScope)) |
| 629 | props.Dist.Tag = proptools.StringPtr(".jar") |
| 630 | } |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 631 | |
Colin Cross | 84dfc3d | 2019-09-25 11:33:01 -0700 | [diff] [blame] | 632 | mctx.CreateModule(LibraryFactory, &props) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 633 | } |
| 634 | |
Paul Duffin | 6d0886e | 2020-04-07 18:49:53 +0100 | [diff] [blame] | 635 | // Creates a droidstubs module that creates stubs source files from the given full source |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 636 | // files |
Paul Duffin | f022920 | 2020-04-29 16:47:28 +0100 | [diff] [blame] | 637 | func (module *SdkLibrary) createStubsSources(mctx android.DefaultableHookContext, apiScope *apiScope) { |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 638 | props := struct { |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 639 | Name *string |
Paul Duffin | 4911a89 | 2020-04-29 23:35:13 +0100 | [diff] [blame] | 640 | Visibility []string |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 641 | Srcs []string |
| 642 | Installable *bool |
Paul Duffin | 52d398a | 2019-06-11 12:31:14 +0100 | [diff] [blame] | 643 | Sdk_version *string |
Paul Duffin | 12ceb46 | 2019-12-24 20:31:31 +0000 | [diff] [blame] | 644 | System_modules *string |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 645 | Libs []string |
Paul Duffin | 1151247 | 2019-02-11 15:55:17 +0000 | [diff] [blame] | 646 | Arg_files []string |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 647 | Args *string |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 648 | Java_version *string |
| 649 | Merge_annotations_dirs []string |
| 650 | Merge_inclusion_annotations_dirs []string |
| 651 | Check_api struct { |
Inseob Kim | 38449af | 2019-02-28 14:24:05 +0900 | [diff] [blame] | 652 | Current ApiToCheck |
| 653 | Last_released ApiToCheck |
| 654 | Ignore_missing_latest_api *bool |
Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 655 | } |
Sundong Ahn | 1b92c82 | 2018-05-29 11:35:17 +0900 | [diff] [blame] | 656 | Aidl struct { |
| 657 | Include_dirs []string |
| 658 | Local_include_dirs []string |
| 659 | } |
Anton Hansson | 5fd5d24 | 2020-03-27 19:43:19 +0000 | [diff] [blame] | 660 | Dist struct { |
| 661 | Targets []string |
| 662 | Dest *string |
| 663 | Dir *string |
| 664 | } |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 665 | }{} |
| 666 | |
Paul Duffin | 7b78b4d | 2020-04-28 14:08:32 +0100 | [diff] [blame] | 667 | // The stubs source processing uses the same compile time classpath when extracting the |
| 668 | // API from the implementation library as it does when compiling it. i.e. the same |
| 669 | // * sdk version |
| 670 | // * system_modules |
| 671 | // * libs (static_libs/libs) |
Paul Duffin | 250e619 | 2019-06-07 10:44:37 +0100 | [diff] [blame] | 672 | |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 673 | props.Name = proptools.StringPtr(module.docsName(apiScope)) |
Paul Duffin | 4911a89 | 2020-04-29 23:35:13 +0100 | [diff] [blame] | 674 | |
| 675 | // If stubs_source_visibility is not set then the created module will use the |
| 676 | // visibility of this module. |
| 677 | visibility := module.sdkLibraryProperties.Stubs_source_visibility |
| 678 | props.Visibility = visibility |
| 679 | |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 680 | props.Srcs = append(props.Srcs, module.Library.Module.properties.Srcs...) |
Paul Duffin | 7b78b4d | 2020-04-28 14:08:32 +0100 | [diff] [blame] | 681 | props.Sdk_version = module.Library.Module.deviceProperties.Sdk_version |
Paul Duffin | 12ceb46 | 2019-12-24 20:31:31 +0000 | [diff] [blame] | 682 | props.System_modules = module.Library.Module.deviceProperties.System_modules |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 683 | props.Installable = proptools.BoolPtr(false) |
Sundong Ahn | e6f0b05 | 2018-06-05 16:46:14 +0900 | [diff] [blame] | 684 | // A droiddoc module has only one Libs property and doesn't distinguish between |
| 685 | // shared libs and static libs. So we need to add both of these libs to Libs property. |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 686 | props.Libs = module.Library.Module.properties.Libs |
| 687 | props.Libs = append(props.Libs, module.Library.Module.properties.Static_libs...) |
| 688 | props.Aidl.Include_dirs = module.Library.Module.deviceProperties.Aidl.Include_dirs |
| 689 | props.Aidl.Local_include_dirs = module.Library.Module.deviceProperties.Aidl.Local_include_dirs |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 690 | props.Java_version = module.Library.Module.properties.Java_version |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 691 | |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 692 | props.Merge_annotations_dirs = module.sdkLibraryProperties.Merge_annotations_dirs |
| 693 | props.Merge_inclusion_annotations_dirs = module.sdkLibraryProperties.Merge_inclusion_annotations_dirs |
| 694 | |
Paul Duffin | 6d0886e | 2020-04-07 18:49:53 +0100 | [diff] [blame] | 695 | droidstubsArgs := []string{} |
Paul Duffin | 235ffff | 2019-12-24 10:41:30 +0000 | [diff] [blame] | 696 | if len(module.sdkLibraryProperties.Api_packages) != 0 { |
Paul Duffin | 6d0886e | 2020-04-07 18:49:53 +0100 | [diff] [blame] | 697 | droidstubsArgs = append(droidstubsArgs, "--stub-packages "+strings.Join(module.sdkLibraryProperties.Api_packages, ":")) |
Paul Duffin | 235ffff | 2019-12-24 10:41:30 +0000 | [diff] [blame] | 698 | } |
| 699 | if len(module.sdkLibraryProperties.Hidden_api_packages) != 0 { |
Paul Duffin | 6d0886e | 2020-04-07 18:49:53 +0100 | [diff] [blame] | 700 | droidstubsArgs = append(droidstubsArgs, |
Paul Duffin | 235ffff | 2019-12-24 10:41:30 +0000 | [diff] [blame] | 701 | android.JoinWithPrefix(module.sdkLibraryProperties.Hidden_api_packages, " --hide-package ")) |
| 702 | } |
Paul Duffin | 6d0886e | 2020-04-07 18:49:53 +0100 | [diff] [blame] | 703 | droidstubsArgs = append(droidstubsArgs, module.sdkLibraryProperties.Droiddoc_options...) |
Paul Duffin | 235ffff | 2019-12-24 10:41:30 +0000 | [diff] [blame] | 704 | disabledWarnings := []string{ |
| 705 | "MissingPermission", |
| 706 | "BroadcastBehavior", |
| 707 | "HiddenSuperclass", |
| 708 | "DeprecationMismatch", |
| 709 | "UnavailableSymbol", |
| 710 | "SdkConstant", |
| 711 | "HiddenTypeParameter", |
| 712 | "Todo", |
| 713 | "Typo", |
| 714 | } |
Paul Duffin | 6d0886e | 2020-04-07 18:49:53 +0100 | [diff] [blame] | 715 | droidstubsArgs = append(droidstubsArgs, android.JoinWithPrefix(disabledWarnings, "--hide ")) |
Sundong Ahn | fb2721f | 2018-09-17 13:23:09 +0900 | [diff] [blame] | 716 | |
Paul Duffin | 1fb487d | 2020-04-07 18:50:10 +0100 | [diff] [blame] | 717 | // Add in scope specific arguments. |
| 718 | droidstubsArgs = append(droidstubsArgs, apiScope.droidstubsArgs...) |
Paul Duffin | 1151247 | 2019-02-11 15:55:17 +0000 | [diff] [blame] | 719 | props.Arg_files = module.sdkLibraryProperties.Droiddoc_option_files |
Paul Duffin | 6d0886e | 2020-04-07 18:49:53 +0100 | [diff] [blame] | 720 | props.Args = proptools.StringPtr(strings.Join(droidstubsArgs, " ")) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 721 | |
| 722 | // List of APIs identified from the provided source files are created. They are later |
| 723 | // compared against to the not-yet-released (a.k.a current) list of APIs and to the |
| 724 | // last-released (a.k.a numbered) list of API. |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 725 | currentApiFileName := apiScope.apiFilePrefix + "current.txt" |
| 726 | removedApiFileName := apiScope.apiFilePrefix + "removed.txt" |
Paul Duffin | 749f98f | 2019-12-30 17:23:46 +0000 | [diff] [blame] | 727 | apiDir := module.getApiDir() |
| 728 | currentApiFileName = path.Join(apiDir, currentApiFileName) |
| 729 | removedApiFileName = path.Join(apiDir, removedApiFileName) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 730 | |
Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 731 | // check against the not-yet-release API |
| 732 | props.Check_api.Current.Api_file = proptools.StringPtr(currentApiFileName) |
| 733 | props.Check_api.Current.Removed_api_file = proptools.StringPtr(removedApiFileName) |
Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 734 | |
Anton Hansson | 6478ac1 | 2020-05-02 11:19:36 +0100 | [diff] [blame] | 735 | if !apiScope.unstable { |
| 736 | // check against the latest released API |
| 737 | props.Check_api.Last_released.Api_file = proptools.StringPtr( |
| 738 | module.latestApiFilegroupName(apiScope)) |
| 739 | props.Check_api.Last_released.Removed_api_file = proptools.StringPtr( |
| 740 | module.latestRemovedApiFilegroupName(apiScope)) |
| 741 | props.Check_api.Ignore_missing_latest_api = proptools.BoolPtr(true) |
| 742 | } |
Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 743 | |
Anton Hansson | 5fd5d24 | 2020-03-27 19:43:19 +0000 | [diff] [blame] | 744 | // Dist the api txt artifact for sdk builds. |
| 745 | if !Bool(module.sdkLibraryProperties.No_dist) { |
| 746 | props.Dist.Targets = []string{"sdk", "win_sdk"} |
| 747 | props.Dist.Dest = proptools.StringPtr(fmt.Sprintf("%v.txt", module.BaseModuleName())) |
| 748 | props.Dist.Dir = proptools.StringPtr(path.Join(module.apiDistPath(apiScope), "api")) |
| 749 | } |
| 750 | |
Colin Cross | 84dfc3d | 2019-09-25 11:33:01 -0700 | [diff] [blame] | 751 | mctx.CreateModule(DroidstubsFactory, &props) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 752 | } |
| 753 | |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 754 | func (module *SdkLibrary) DepIsInSameApex(mctx android.BaseModuleContext, dep android.Module) bool { |
| 755 | depTag := mctx.OtherModuleDependencyTag(dep) |
| 756 | if depTag == xmlPermissionsFileTag { |
| 757 | return true |
| 758 | } |
| 759 | return module.Library.DepIsInSameApex(mctx, dep) |
| 760 | } |
| 761 | |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 762 | // Creates the xml file that publicizes the runtime library |
Paul Duffin | f022920 | 2020-04-29 16:47:28 +0100 | [diff] [blame] | 763 | func (module *SdkLibrary) createXmlFile(mctx android.DefaultableHookContext) { |
Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 764 | props := struct { |
Sundong Ahn | 0d7dff4 | 2019-12-04 12:53:44 +0900 | [diff] [blame] | 765 | Name *string |
Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 766 | Lib_name *string |
Sundong Ahn | 0d7dff4 | 2019-12-04 12:53:44 +0900 | [diff] [blame] | 767 | Soc_specific *bool |
| 768 | Device_specific *bool |
| 769 | Product_specific *bool |
| 770 | System_ext_specific *bool |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 771 | Apex_available []string |
Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 772 | }{ |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 773 | Name: proptools.StringPtr(module.xmlFileName()), |
| 774 | Lib_name: proptools.StringPtr(module.BaseModuleName()), |
| 775 | Apex_available: module.ApexProperties.Apex_available, |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 776 | } |
Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 777 | |
| 778 | if module.SocSpecific() { |
| 779 | props.Soc_specific = proptools.BoolPtr(true) |
| 780 | } else if module.DeviceSpecific() { |
| 781 | props.Device_specific = proptools.BoolPtr(true) |
| 782 | } else if module.ProductSpecific() { |
| 783 | props.Product_specific = proptools.BoolPtr(true) |
| 784 | } else if module.SystemExtSpecific() { |
| 785 | props.System_ext_specific = proptools.BoolPtr(true) |
| 786 | } |
| 787 | |
| 788 | mctx.CreateModule(sdkLibraryXmlFactory, &props) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 789 | } |
| 790 | |
Paul Duffin | 5006151 | 2020-01-21 16:31:05 +0000 | [diff] [blame] | 791 | func PrebuiltJars(ctx android.BaseModuleContext, baseName string, s sdkSpec) android.Paths { |
Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 792 | var ver sdkVersion |
| 793 | var kind sdkKind |
| 794 | if s.usePrebuilt(ctx) { |
| 795 | ver = s.version |
| 796 | kind = s.kind |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 797 | } else { |
Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 798 | // We don't have prebuilt SDK for the specific sdkVersion. |
| 799 | // Instead of breaking the build, fallback to use "system_current" |
| 800 | ver = sdkVersionCurrent |
| 801 | kind = sdkSystem |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 802 | } |
Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 803 | |
| 804 | dir := filepath.Join("prebuilts", "sdk", ver.String(), kind.String()) |
Paul Duffin | 5006151 | 2020-01-21 16:31:05 +0000 | [diff] [blame] | 805 | jar := filepath.Join(dir, baseName+".jar") |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 806 | jarPath := android.ExistentPathForSource(ctx, jar) |
Sundong Ahn | ae418ac | 2019-02-28 15:01:28 +0900 | [diff] [blame] | 807 | if !jarPath.Valid() { |
Colin Cross | 07c8856 | 2020-01-07 09:34:44 -0800 | [diff] [blame] | 808 | if ctx.Config().AllowMissingDependencies() { |
| 809 | return android.Paths{android.PathForSource(ctx, jar)} |
| 810 | } else { |
Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 811 | 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] | 812 | } |
Sundong Ahn | ae418ac | 2019-02-28 15:01:28 +0900 | [diff] [blame] | 813 | return nil |
| 814 | } |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 815 | return android.Paths{jarPath.Path()} |
| 816 | } |
| 817 | |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 818 | func (module *SdkLibrary) sdkJars( |
| 819 | ctx android.BaseModuleContext, |
| 820 | sdkVersion sdkSpec, |
| 821 | headerJars bool) android.Paths { |
| 822 | |
Paul Duffin | 5006151 | 2020-01-21 16:31:05 +0000 | [diff] [blame] | 823 | // If a specific numeric version has been requested then use prebuilt versions of the sdk. |
| 824 | if sdkVersion.version.isNumbered() { |
| 825 | return PrebuiltJars(ctx, module.BaseModuleName(), sdkVersion) |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 826 | } else { |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 827 | if !sdkVersion.specified() { |
| 828 | if headerJars { |
| 829 | return module.Library.HeaderJars() |
| 830 | } else { |
| 831 | return module.Library.ImplementationJars() |
| 832 | } |
| 833 | } |
Paul Duffin | 726d23c | 2020-01-22 16:30:37 +0000 | [diff] [blame] | 834 | var apiScope *apiScope |
Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 835 | switch sdkVersion.kind { |
| 836 | case sdkSystem: |
Paul Duffin | 726d23c | 2020-01-22 16:30:37 +0000 | [diff] [blame] | 837 | apiScope = apiScopeSystem |
| 838 | case sdkTest: |
| 839 | apiScope = apiScopeTest |
Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 840 | case sdkPrivate: |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 841 | return module.Library.HeaderJars() |
Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 842 | default: |
Paul Duffin | 726d23c | 2020-01-22 16:30:37 +0000 | [diff] [blame] | 843 | apiScope = apiScopePublic |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 844 | } |
| 845 | |
Paul Duffin | 726d23c | 2020-01-22 16:30:37 +0000 | [diff] [blame] | 846 | paths := module.getScopePaths(apiScope) |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 847 | if headerJars { |
| 848 | return paths.stubsHeaderPath |
| 849 | } else { |
| 850 | return paths.stubsImplPath |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 851 | } |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 852 | } |
| 853 | } |
| 854 | |
Sundong Ahn | 241cd37 | 2018-07-13 16:16:44 +0900 | [diff] [blame] | 855 | // to satisfy SdkLibraryDependency interface |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 856 | func (module *SdkLibrary) SdkHeaderJars(ctx android.BaseModuleContext, sdkVersion sdkSpec) android.Paths { |
| 857 | return module.sdkJars(ctx, sdkVersion, true /*headerJars*/) |
| 858 | } |
| 859 | |
| 860 | // to satisfy SdkLibraryDependency interface |
Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 861 | func (module *SdkLibrary) SdkImplementationJars(ctx android.BaseModuleContext, sdkVersion sdkSpec) android.Paths { |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 862 | return module.sdkJars(ctx, sdkVersion, false /*headerJars*/) |
Sundong Ahn | 241cd37 | 2018-07-13 16:16:44 +0900 | [diff] [blame] | 863 | } |
| 864 | |
Sundong Ahn | 80a87b3 | 2019-05-13 15:02:50 +0900 | [diff] [blame] | 865 | func (module *SdkLibrary) SetNoDist() { |
| 866 | module.sdkLibraryProperties.No_dist = proptools.BoolPtr(true) |
| 867 | } |
| 868 | |
Colin Cross | 571cccf | 2019-02-04 11:22:08 -0800 | [diff] [blame] | 869 | var javaSdkLibrariesKey = android.NewOnceKey("javaSdkLibraries") |
| 870 | |
Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 871 | func javaSdkLibraries(config android.Config) *[]string { |
Colin Cross | 571cccf | 2019-02-04 11:22:08 -0800 | [diff] [blame] | 872 | return config.Once(javaSdkLibrariesKey, func() interface{} { |
Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 873 | return &[]string{} |
| 874 | }).(*[]string) |
| 875 | } |
| 876 | |
Paul Duffin | 749f98f | 2019-12-30 17:23:46 +0000 | [diff] [blame] | 877 | func (module *SdkLibrary) getApiDir() string { |
| 878 | return proptools.StringDefault(module.sdkLibraryProperties.Api_dir, "api") |
| 879 | } |
| 880 | |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 881 | // For a java_sdk_library module, create internal modules for stubs, docs, |
| 882 | // runtime libs and xml file. If requested, the stubs and docs are created twice |
| 883 | // once for public API level and once for system API level |
Paul Duffin | f022920 | 2020-04-29 16:47:28 +0100 | [diff] [blame] | 884 | func (module *SdkLibrary) CreateInternalModules(mctx android.DefaultableHookContext) { |
| 885 | // If the module has been disabled then don't create any child modules. |
| 886 | if !module.Enabled() { |
| 887 | return |
| 888 | } |
| 889 | |
Inseob Kim | 6e93ac9 | 2019-03-21 17:43:49 +0900 | [diff] [blame] | 890 | if len(module.Library.Module.properties.Srcs) == 0 { |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 891 | mctx.PropertyErrorf("srcs", "java_sdk_library must specify srcs") |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 892 | return |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 893 | } |
| 894 | |
Paul Duffin | 37e0b77 | 2019-12-30 17:20:10 +0000 | [diff] [blame] | 895 | // If this builds against standard libraries (i.e. is not part of the core libraries) |
| 896 | // then assume it provides both system and test apis. Otherwise, assume it does not and |
| 897 | // also assume it does not contribute to the dist build. |
| 898 | sdkDep := decodeSdkDep(mctx, sdkContext(&module.Library)) |
| 899 | hasSystemAndTestApis := sdkDep.hasStandardLibs() |
Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 900 | module.sdkLibraryProperties.Generate_system_and_test_apis = hasSystemAndTestApis |
Paul Duffin | 37e0b77 | 2019-12-30 17:20:10 +0000 | [diff] [blame] | 901 | module.sdkLibraryProperties.No_dist = proptools.BoolPtr(!hasSystemAndTestApis) |
| 902 | |
Inseob Kim | 8098faa | 2019-03-18 10:19:51 +0900 | [diff] [blame] | 903 | missing_current_api := false |
| 904 | |
Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 905 | generatedScopes := module.getGeneratedApiScopes(mctx) |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 906 | |
Paul Duffin | 749f98f | 2019-12-30 17:23:46 +0000 | [diff] [blame] | 907 | apiDir := module.getApiDir() |
Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 908 | for _, scope := range generatedScopes { |
Inseob Kim | 8098faa | 2019-03-18 10:19:51 +0900 | [diff] [blame] | 909 | for _, api := range []string{"current.txt", "removed.txt"} { |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 910 | path := path.Join(mctx.ModuleDir(), apiDir, scope.apiFilePrefix+api) |
Inseob Kim | 8098faa | 2019-03-18 10:19:51 +0900 | [diff] [blame] | 911 | p := android.ExistentPathForSource(mctx, path) |
| 912 | if !p.Valid() { |
| 913 | mctx.ModuleErrorf("Current api file %#v doesn't exist", path) |
| 914 | missing_current_api = true |
| 915 | } |
| 916 | } |
| 917 | } |
| 918 | |
| 919 | if missing_current_api { |
| 920 | script := "build/soong/scripts/gen-java-current-api-files.sh" |
| 921 | p := android.ExistentPathForSource(mctx, script) |
| 922 | |
| 923 | if !p.Valid() { |
| 924 | panic(fmt.Sprintf("script file %s doesn't exist", script)) |
| 925 | } |
| 926 | |
| 927 | mctx.ModuleErrorf("One or more current api files are missing. "+ |
| 928 | "You can update them by:\n"+ |
Paul Duffin | 37e0b77 | 2019-12-30 17:20:10 +0000 | [diff] [blame] | 929 | "%s %q %s && m update-api", |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 930 | script, filepath.Join(mctx.ModuleDir(), apiDir), |
Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 931 | strings.Join(generatedScopes.Strings(func(s *apiScope) string { return s.apiFilePrefix }), " ")) |
Inseob Kim | 8098faa | 2019-03-18 10:19:51 +0900 | [diff] [blame] | 932 | return |
| 933 | } |
| 934 | |
Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 935 | for _, scope := range generatedScopes { |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 936 | module.createStubsLibrary(mctx, scope) |
| 937 | module.createStubsSources(mctx, scope) |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 938 | } |
| 939 | |
Paul Duffin | 43db9be | 2019-12-30 17:35:49 +0000 | [diff] [blame] | 940 | if !proptools.Bool(module.sdkLibraryProperties.Api_only) { |
| 941 | // for runtime |
| 942 | module.createXmlFile(mctx) |
| 943 | |
| 944 | // record java_sdk_library modules so that they are exported to make |
| 945 | javaSdkLibraries := javaSdkLibraries(mctx.Config()) |
| 946 | javaSdkLibrariesLock.Lock() |
| 947 | defer javaSdkLibrariesLock.Unlock() |
| 948 | *javaSdkLibraries = append(*javaSdkLibraries, module.BaseModuleName()) |
| 949 | } |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 950 | } |
| 951 | |
| 952 | func (module *SdkLibrary) InitSdkLibraryProperties() { |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 953 | module.AddProperties( |
| 954 | &module.sdkLibraryProperties, |
| 955 | &module.Library.Module.properties, |
| 956 | &module.Library.Module.dexpreoptProperties, |
| 957 | &module.Library.Module.deviceProperties, |
| 958 | &module.Library.Module.protoProperties, |
| 959 | ) |
| 960 | |
| 961 | module.Library.Module.properties.Installable = proptools.BoolPtr(true) |
| 962 | module.Library.Module.deviceProperties.IsSDKLibrary = true |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 963 | } |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 964 | |
Jaewoong Jung | 4f158ee | 2019-07-11 10:05:35 -0700 | [diff] [blame] | 965 | // java_sdk_library is a special Java library that provides optional platform APIs to apps. |
| 966 | // In practice, it can be viewed as a combination of several modules: 1) stubs library that clients |
| 967 | // are linked against to, 2) droiddoc module that internally generates API stubs source files, |
| 968 | // 3) the real runtime shared library that implements the APIs, and 4) XML file for adding |
| 969 | // 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] | 970 | func SdkLibraryFactory() android.Module { |
| 971 | module := &SdkLibrary{} |
| 972 | module.InitSdkLibraryProperties() |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 973 | android.InitApexModule(module) |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 974 | InitJavaModule(module, android.HostAndDeviceSupported) |
Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 975 | |
| 976 | // Initialize the map from scope to scope specific properties. |
| 977 | scopeToProperties := make(map[*apiScope]*ApiScopeProperties) |
| 978 | for _, scope := range allApiScopes { |
| 979 | scopeToProperties[scope] = scope.scopeSpecificProperties(module) |
| 980 | } |
| 981 | module.scopeToProperties = scopeToProperties |
| 982 | |
Paul Duffin | 4911a89 | 2020-04-29 23:35:13 +0100 | [diff] [blame] | 983 | // Add the properties containing visibility rules so that they are checked. |
| 984 | android.AddVisibilityProperty(module, "stubs_library_visibility", &module.sdkLibraryProperties.Stubs_library_visibility) |
| 985 | android.AddVisibilityProperty(module, "stubs_source_visibility", &module.sdkLibraryProperties.Stubs_source_visibility) |
| 986 | |
Paul Duffin | f022920 | 2020-04-29 16:47:28 +0100 | [diff] [blame] | 987 | module.SetDefaultableHook(func(ctx android.DefaultableHookContext) { module.CreateInternalModules(ctx) }) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 988 | return module |
| 989 | } |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 990 | |
| 991 | // |
| 992 | // SDK library prebuilts |
| 993 | // |
| 994 | |
Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 995 | // Properties associated with each api scope. |
| 996 | type sdkLibraryScopeProperties struct { |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 997 | Jars []string `android:"path"` |
| 998 | |
| 999 | Sdk_version *string |
| 1000 | |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 1001 | // List of shared java libs that this module has dependencies to |
| 1002 | Libs []string |
Paul Duffin | 3d1248c | 2020-04-09 00:10:17 +0100 | [diff] [blame] | 1003 | |
| 1004 | // The stub sources. |
| 1005 | Stub_srcs []string `android:"path"` |
Paul Duffin | 1fd005d | 2020-04-09 01:08:11 +0100 | [diff] [blame] | 1006 | |
| 1007 | // The current.txt |
| 1008 | Current_api string `android:"path"` |
| 1009 | |
| 1010 | // The removed.txt |
| 1011 | Removed_api string `android:"path"` |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 1012 | } |
| 1013 | |
Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 1014 | type sdkLibraryImportProperties struct { |
Paul Duffin | fcfd791 | 2020-01-31 17:54:30 +0000 | [diff] [blame] | 1015 | // List of shared java libs, common to all scopes, that this module has |
| 1016 | // dependencies to |
| 1017 | Libs []string |
Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 1018 | } |
| 1019 | |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 1020 | type sdkLibraryImport struct { |
| 1021 | android.ModuleBase |
| 1022 | android.DefaultableModuleBase |
| 1023 | prebuilt android.Prebuilt |
Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 1024 | android.ApexModuleBase |
| 1025 | android.SdkBase |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 1026 | |
| 1027 | properties sdkLibraryImportProperties |
| 1028 | |
Paul Duffin | 46a26a8 | 2020-04-07 19:27:04 +0100 | [diff] [blame] | 1029 | // Map from api scope to the scope specific property structure. |
| 1030 | scopeProperties map[*apiScope]*sdkLibraryScopeProperties |
| 1031 | |
Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 1032 | commonToSdkLibraryAndImport |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 1033 | } |
| 1034 | |
| 1035 | var _ SdkLibraryDependency = (*sdkLibraryImport)(nil) |
| 1036 | |
Paul Duffin | 46a26a8 | 2020-04-07 19:27:04 +0100 | [diff] [blame] | 1037 | // The type of a structure that contains a field of type sdkLibraryScopeProperties |
| 1038 | // for each apiscope in allApiScopes, e.g. something like: |
| 1039 | // struct { |
| 1040 | // Public sdkLibraryScopeProperties |
| 1041 | // System sdkLibraryScopeProperties |
| 1042 | // ... |
| 1043 | // } |
| 1044 | var allScopeStructType = createAllScopePropertiesStructType() |
| 1045 | |
| 1046 | // Dynamically create a structure type for each apiscope in allApiScopes. |
| 1047 | func createAllScopePropertiesStructType() reflect.Type { |
| 1048 | var fields []reflect.StructField |
| 1049 | for _, apiScope := range allApiScopes { |
| 1050 | field := reflect.StructField{ |
| 1051 | Name: apiScope.fieldName, |
| 1052 | Type: reflect.TypeOf(sdkLibraryScopeProperties{}), |
| 1053 | } |
| 1054 | fields = append(fields, field) |
| 1055 | } |
| 1056 | |
| 1057 | return reflect.StructOf(fields) |
| 1058 | } |
| 1059 | |
| 1060 | // Create an instance of the scope specific structure type and return a map |
| 1061 | // from apiscope to a pointer to each scope specific field. |
| 1062 | func createPropertiesInstance() (interface{}, map[*apiScope]*sdkLibraryScopeProperties) { |
| 1063 | allScopePropertiesPtr := reflect.New(allScopeStructType) |
| 1064 | allScopePropertiesStruct := allScopePropertiesPtr.Elem() |
| 1065 | scopeProperties := make(map[*apiScope]*sdkLibraryScopeProperties) |
| 1066 | |
| 1067 | for _, apiScope := range allApiScopes { |
| 1068 | field := allScopePropertiesStruct.FieldByName(apiScope.fieldName) |
| 1069 | scopeProperties[apiScope] = field.Addr().Interface().(*sdkLibraryScopeProperties) |
| 1070 | } |
| 1071 | |
| 1072 | return allScopePropertiesPtr.Interface(), scopeProperties |
| 1073 | } |
| 1074 | |
Jaewoong Jung | 4f158ee | 2019-07-11 10:05:35 -0700 | [diff] [blame] | 1075 | // java_sdk_library_import imports a prebuilt java_sdk_library. |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 1076 | func sdkLibraryImportFactory() android.Module { |
| 1077 | module := &sdkLibraryImport{} |
| 1078 | |
Paul Duffin | 46a26a8 | 2020-04-07 19:27:04 +0100 | [diff] [blame] | 1079 | allScopeProperties, scopeToProperties := createPropertiesInstance() |
| 1080 | module.scopeProperties = scopeToProperties |
| 1081 | module.AddProperties(&module.properties, allScopeProperties) |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 1082 | |
Paul Duffin | 0bdcb27 | 2020-02-06 15:24:57 +0000 | [diff] [blame] | 1083 | android.InitPrebuiltModule(module, &[]string{""}) |
Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 1084 | android.InitApexModule(module) |
| 1085 | android.InitSdkAwareModule(module) |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 1086 | InitJavaModule(module, android.HostAndDeviceSupported) |
| 1087 | |
Paul Duffin | 6e7ecbf | 2020-05-08 15:01:19 +0100 | [diff] [blame^] | 1088 | module.SetDefaultableHook(func(mctx android.DefaultableHookContext) { module.createInternalModules(mctx) }) |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 1089 | return module |
| 1090 | } |
| 1091 | |
| 1092 | func (module *sdkLibraryImport) Prebuilt() *android.Prebuilt { |
| 1093 | return &module.prebuilt |
| 1094 | } |
| 1095 | |
| 1096 | func (module *sdkLibraryImport) Name() string { |
| 1097 | return module.prebuilt.Name(module.ModuleBase.Name()) |
| 1098 | } |
| 1099 | |
Paul Duffin | 6e7ecbf | 2020-05-08 15:01:19 +0100 | [diff] [blame^] | 1100 | func (module *sdkLibraryImport) createInternalModules(mctx android.DefaultableHookContext) { |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 1101 | |
Paul Duffin | 5006151 | 2020-01-21 16:31:05 +0000 | [diff] [blame] | 1102 | // If the build is configured to use prebuilts then force this to be preferred. |
| 1103 | if mctx.Config().UnbundledBuildUsePrebuiltSdks() { |
| 1104 | module.prebuilt.ForcePrefer() |
| 1105 | } |
| 1106 | |
Paul Duffin | 46a26a8 | 2020-04-07 19:27:04 +0100 | [diff] [blame] | 1107 | for apiScope, scopeProperties := range module.scopeProperties { |
Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 1108 | if len(scopeProperties.Jars) == 0 { |
| 1109 | continue |
| 1110 | } |
| 1111 | |
Paul Duffin | bbb546b | 2020-04-09 00:07:11 +0100 | [diff] [blame] | 1112 | module.createJavaImportForStubs(mctx, apiScope, scopeProperties) |
Paul Duffin | 3d1248c | 2020-04-09 00:10:17 +0100 | [diff] [blame] | 1113 | |
| 1114 | module.createPrebuiltStubsSources(mctx, apiScope, scopeProperties) |
Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 1115 | } |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 1116 | |
| 1117 | javaSdkLibraries := javaSdkLibraries(mctx.Config()) |
| 1118 | javaSdkLibrariesLock.Lock() |
| 1119 | defer javaSdkLibrariesLock.Unlock() |
| 1120 | *javaSdkLibraries = append(*javaSdkLibraries, module.BaseModuleName()) |
| 1121 | } |
| 1122 | |
Paul Duffin | 6e7ecbf | 2020-05-08 15:01:19 +0100 | [diff] [blame^] | 1123 | func (module *sdkLibraryImport) createJavaImportForStubs(mctx android.DefaultableHookContext, apiScope *apiScope, scopeProperties *sdkLibraryScopeProperties) { |
Paul Duffin | bbb546b | 2020-04-09 00:07:11 +0100 | [diff] [blame] | 1124 | // Creates a java import for the jar with ".stubs" suffix |
| 1125 | props := struct { |
| 1126 | Name *string |
| 1127 | Soc_specific *bool |
| 1128 | Device_specific *bool |
| 1129 | Product_specific *bool |
| 1130 | System_ext_specific *bool |
| 1131 | Sdk_version *string |
| 1132 | Libs []string |
| 1133 | Jars []string |
| 1134 | Prefer *bool |
| 1135 | }{} |
| 1136 | props.Name = proptools.StringPtr(apiScope.stubsModuleName(module.BaseModuleName())) |
| 1137 | props.Sdk_version = scopeProperties.Sdk_version |
| 1138 | // Prepend any of the libs from the legacy public properties to the libs for each of the |
| 1139 | // scopes to avoid having to duplicate them in each scope. |
| 1140 | props.Libs = append(module.properties.Libs, scopeProperties.Libs...) |
| 1141 | props.Jars = scopeProperties.Jars |
| 1142 | if module.SocSpecific() { |
| 1143 | props.Soc_specific = proptools.BoolPtr(true) |
| 1144 | } else if module.DeviceSpecific() { |
| 1145 | props.Device_specific = proptools.BoolPtr(true) |
| 1146 | } else if module.ProductSpecific() { |
| 1147 | props.Product_specific = proptools.BoolPtr(true) |
| 1148 | } else if module.SystemExtSpecific() { |
| 1149 | props.System_ext_specific = proptools.BoolPtr(true) |
| 1150 | } |
| 1151 | // If the build should use prebuilt sdks then set prefer to true on the stubs library. |
| 1152 | // That will cause the prebuilt version of the stubs to override the source version. |
| 1153 | if mctx.Config().UnbundledBuildUsePrebuiltSdks() { |
| 1154 | props.Prefer = proptools.BoolPtr(true) |
| 1155 | } |
| 1156 | mctx.CreateModule(ImportFactory, &props) |
| 1157 | } |
| 1158 | |
Paul Duffin | 6e7ecbf | 2020-05-08 15:01:19 +0100 | [diff] [blame^] | 1159 | func (module *sdkLibraryImport) createPrebuiltStubsSources(mctx android.DefaultableHookContext, apiScope *apiScope, scopeProperties *sdkLibraryScopeProperties) { |
Paul Duffin | 3d1248c | 2020-04-09 00:10:17 +0100 | [diff] [blame] | 1160 | props := struct { |
| 1161 | Name *string |
| 1162 | Srcs []string |
| 1163 | }{} |
| 1164 | props.Name = proptools.StringPtr(apiScope.docsModuleName(module.BaseModuleName())) |
| 1165 | props.Srcs = scopeProperties.Stub_srcs |
| 1166 | mctx.CreateModule(PrebuiltStubsSourcesFactory, &props) |
| 1167 | } |
| 1168 | |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 1169 | func (module *sdkLibraryImport) DepsMutator(ctx android.BottomUpMutatorContext) { |
Paul Duffin | 46a26a8 | 2020-04-07 19:27:04 +0100 | [diff] [blame] | 1170 | for apiScope, scopeProperties := range module.scopeProperties { |
Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 1171 | if len(scopeProperties.Jars) == 0 { |
| 1172 | continue |
| 1173 | } |
| 1174 | |
| 1175 | // Add dependencies to the prebuilt stubs library |
| 1176 | ctx.AddVariationDependencies(nil, apiScope.stubsTag, apiScope.stubsModuleName(module.BaseModuleName())) |
| 1177 | } |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 1178 | } |
| 1179 | |
| 1180 | func (module *sdkLibraryImport) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 1181 | // Record the paths to the prebuilt stubs library. |
| 1182 | ctx.VisitDirectDeps(func(to android.Module) { |
| 1183 | tag := ctx.OtherModuleDependencyTag(to) |
| 1184 | |
Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 1185 | if lib, ok := to.(Dependency); ok { |
| 1186 | if scopeTag, ok := tag.(scopeDependencyTag); ok { |
| 1187 | apiScope := scopeTag.apiScope |
| 1188 | scopePaths := module.getScopePaths(apiScope) |
| 1189 | scopePaths.stubsHeaderPath = lib.HeaderJars() |
| 1190 | } |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 1191 | } |
| 1192 | }) |
| 1193 | } |
| 1194 | |
Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 1195 | func (module *sdkLibraryImport) sdkJars( |
| 1196 | ctx android.BaseModuleContext, |
| 1197 | sdkVersion sdkSpec) android.Paths { |
| 1198 | |
Paul Duffin | 5006151 | 2020-01-21 16:31:05 +0000 | [diff] [blame] | 1199 | // If a specific numeric version has been requested then use prebuilt versions of the sdk. |
| 1200 | if sdkVersion.version.isNumbered() { |
| 1201 | return PrebuiltJars(ctx, module.BaseModuleName(), sdkVersion) |
| 1202 | } |
| 1203 | |
Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 1204 | var apiScope *apiScope |
| 1205 | switch sdkVersion.kind { |
| 1206 | case sdkSystem: |
| 1207 | apiScope = apiScopeSystem |
| 1208 | case sdkTest: |
| 1209 | apiScope = apiScopeTest |
| 1210 | default: |
| 1211 | apiScope = apiScopePublic |
| 1212 | } |
| 1213 | |
| 1214 | paths := module.getScopePaths(apiScope) |
| 1215 | return paths.stubsHeaderPath |
| 1216 | } |
| 1217 | |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 1218 | // to satisfy SdkLibraryDependency interface |
Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 1219 | func (module *sdkLibraryImport) SdkHeaderJars(ctx android.BaseModuleContext, sdkVersion sdkSpec) android.Paths { |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 1220 | // This module is just a wrapper for the prebuilt stubs. |
Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 1221 | return module.sdkJars(ctx, sdkVersion) |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 1222 | } |
| 1223 | |
| 1224 | // to satisfy SdkLibraryDependency interface |
Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 1225 | func (module *sdkLibraryImport) SdkImplementationJars(ctx android.BaseModuleContext, sdkVersion sdkSpec) android.Paths { |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 1226 | // This module is just a wrapper for the stubs. |
Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 1227 | return module.sdkJars(ctx, sdkVersion) |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 1228 | } |
Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 1229 | |
| 1230 | // |
| 1231 | // java_sdk_library_xml |
| 1232 | // |
| 1233 | type sdkLibraryXml struct { |
| 1234 | android.ModuleBase |
| 1235 | android.DefaultableModuleBase |
| 1236 | android.ApexModuleBase |
| 1237 | |
| 1238 | properties sdkLibraryXmlProperties |
| 1239 | |
| 1240 | outputFilePath android.OutputPath |
| 1241 | installDirPath android.InstallPath |
| 1242 | } |
| 1243 | |
| 1244 | type sdkLibraryXmlProperties struct { |
| 1245 | // canonical name of the lib |
| 1246 | Lib_name *string |
| 1247 | } |
| 1248 | |
| 1249 | // java_sdk_library_xml builds the permission xml file for a java_sdk_library. |
| 1250 | // Not to be used directly by users. java_sdk_library internally uses this. |
| 1251 | func sdkLibraryXmlFactory() android.Module { |
| 1252 | module := &sdkLibraryXml{} |
| 1253 | |
| 1254 | module.AddProperties(&module.properties) |
| 1255 | |
| 1256 | android.InitApexModule(module) |
| 1257 | android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibCommon) |
| 1258 | |
| 1259 | return module |
| 1260 | } |
| 1261 | |
| 1262 | // from android.PrebuiltEtcModule |
| 1263 | func (module *sdkLibraryXml) SubDir() string { |
| 1264 | return "permissions" |
| 1265 | } |
| 1266 | |
| 1267 | // from android.PrebuiltEtcModule |
| 1268 | func (module *sdkLibraryXml) OutputFile() android.OutputPath { |
| 1269 | return module.outputFilePath |
| 1270 | } |
| 1271 | |
| 1272 | // from android.ApexModule |
| 1273 | func (module *sdkLibraryXml) AvailableFor(what string) bool { |
| 1274 | return true |
| 1275 | } |
| 1276 | |
| 1277 | func (module *sdkLibraryXml) DepsMutator(ctx android.BottomUpMutatorContext) { |
| 1278 | // do nothing |
| 1279 | } |
| 1280 | |
| 1281 | // File path to the runtime implementation library |
| 1282 | func (module *sdkLibraryXml) implPath() string { |
| 1283 | implName := proptools.String(module.properties.Lib_name) |
| 1284 | if apexName := module.ApexName(); apexName != "" { |
| 1285 | // TODO(b/146468504): ApexName() is only a soong module name, not apex name. |
| 1286 | // In most cases, this works fine. But when apex_name is set or override_apex is used |
| 1287 | // this can be wrong. |
| 1288 | return fmt.Sprintf("/apex/%s/javalib/%s.jar", apexName, implName) |
| 1289 | } |
| 1290 | partition := "system" |
| 1291 | if module.SocSpecific() { |
| 1292 | partition = "vendor" |
| 1293 | } else if module.DeviceSpecific() { |
| 1294 | partition = "odm" |
| 1295 | } else if module.ProductSpecific() { |
| 1296 | partition = "product" |
| 1297 | } else if module.SystemExtSpecific() { |
| 1298 | partition = "system_ext" |
| 1299 | } |
| 1300 | return "/" + partition + "/framework/" + implName + ".jar" |
| 1301 | } |
| 1302 | |
| 1303 | func (module *sdkLibraryXml) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 1304 | libName := proptools.String(module.properties.Lib_name) |
| 1305 | xmlContent := fmt.Sprintf(permissionsTemplate, libName, module.implPath()) |
| 1306 | |
| 1307 | module.outputFilePath = android.PathForModuleOut(ctx, libName+".xml").OutputPath |
| 1308 | rule := android.NewRuleBuilder() |
| 1309 | rule.Command(). |
| 1310 | Text("/bin/bash -c \"echo -e '" + xmlContent + "'\" > "). |
| 1311 | Output(module.outputFilePath) |
| 1312 | |
| 1313 | rule.Build(pctx, ctx, "java_sdk_xml", "Permission XML") |
| 1314 | |
| 1315 | module.installDirPath = android.PathForModuleInstall(ctx, "etc", module.SubDir()) |
| 1316 | } |
| 1317 | |
| 1318 | func (module *sdkLibraryXml) AndroidMkEntries() []android.AndroidMkEntries { |
| 1319 | if !module.IsForPlatform() { |
| 1320 | return []android.AndroidMkEntries{android.AndroidMkEntries{ |
| 1321 | Disabled: true, |
| 1322 | }} |
| 1323 | } |
| 1324 | |
| 1325 | return []android.AndroidMkEntries{android.AndroidMkEntries{ |
| 1326 | Class: "ETC", |
| 1327 | OutputFile: android.OptionalPathForPath(module.outputFilePath), |
| 1328 | ExtraEntries: []android.AndroidMkExtraEntriesFunc{ |
| 1329 | func(entries *android.AndroidMkEntries) { |
| 1330 | entries.SetString("LOCAL_MODULE_TAGS", "optional") |
| 1331 | entries.SetString("LOCAL_MODULE_PATH", module.installDirPath.ToMakePath().String()) |
| 1332 | entries.SetString("LOCAL_INSTALLED_MODULE_STEM", module.outputFilePath.Base()) |
| 1333 | }, |
| 1334 | }, |
| 1335 | }} |
| 1336 | } |
Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 1337 | |
| 1338 | type sdkLibrarySdkMemberType struct { |
| 1339 | android.SdkMemberTypeBase |
| 1340 | } |
| 1341 | |
| 1342 | func (s *sdkLibrarySdkMemberType) AddDependencies(mctx android.BottomUpMutatorContext, dependencyTag blueprint.DependencyTag, names []string) { |
| 1343 | mctx.AddVariationDependencies(nil, dependencyTag, names...) |
| 1344 | } |
| 1345 | |
| 1346 | func (s *sdkLibrarySdkMemberType) IsInstance(module android.Module) bool { |
| 1347 | _, ok := module.(*SdkLibrary) |
| 1348 | return ok |
| 1349 | } |
| 1350 | |
| 1351 | func (s *sdkLibrarySdkMemberType) AddPrebuiltModule(ctx android.SdkMemberContext, member android.SdkMember) android.BpModule { |
| 1352 | return ctx.SnapshotBuilder().AddPrebuiltModule(member, "java_sdk_library_import") |
| 1353 | } |
| 1354 | |
| 1355 | func (s *sdkLibrarySdkMemberType) CreateVariantPropertiesStruct() android.SdkMemberProperties { |
| 1356 | return &sdkLibrarySdkMemberProperties{} |
| 1357 | } |
| 1358 | |
| 1359 | type sdkLibrarySdkMemberProperties struct { |
| 1360 | android.SdkMemberPropertiesBase |
| 1361 | |
| 1362 | // Scope to per scope properties. |
| 1363 | Scopes map[*apiScope]scopeProperties |
| 1364 | |
| 1365 | // Additional libraries that the exported stubs libraries depend upon. |
| 1366 | Libs []string |
Paul Duffin | 3d1248c | 2020-04-09 00:10:17 +0100 | [diff] [blame] | 1367 | |
| 1368 | // The Java stubs source files. |
| 1369 | Stub_srcs []string |
Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 1370 | } |
| 1371 | |
| 1372 | type scopeProperties struct { |
Paul Duffin | 1fd005d | 2020-04-09 01:08:11 +0100 | [diff] [blame] | 1373 | Jars android.Paths |
| 1374 | StubsSrcJar android.Path |
| 1375 | CurrentApiFile android.Path |
| 1376 | RemovedApiFile android.Path |
| 1377 | SdkVersion string |
Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 1378 | } |
| 1379 | |
| 1380 | func (s *sdkLibrarySdkMemberProperties) PopulateFromVariant(ctx android.SdkMemberContext, variant android.Module) { |
| 1381 | sdk := variant.(*SdkLibrary) |
| 1382 | |
| 1383 | s.Scopes = make(map[*apiScope]scopeProperties) |
| 1384 | for _, apiScope := range allApiScopes { |
| 1385 | paths := sdk.getScopePaths(apiScope) |
| 1386 | jars := paths.stubsImplPath |
| 1387 | if len(jars) > 0 { |
| 1388 | properties := scopeProperties{} |
| 1389 | properties.Jars = jars |
| 1390 | properties.SdkVersion = apiScope.sdkVersion |
Paul Duffin | 3d1248c | 2020-04-09 00:10:17 +0100 | [diff] [blame] | 1391 | properties.StubsSrcJar = paths.stubsSrcJar |
Paul Duffin | 1fd005d | 2020-04-09 01:08:11 +0100 | [diff] [blame] | 1392 | properties.CurrentApiFile = paths.currentApiFilePath |
| 1393 | properties.RemovedApiFile = paths.removedApiFilePath |
Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 1394 | s.Scopes[apiScope] = properties |
| 1395 | } |
| 1396 | } |
| 1397 | |
| 1398 | s.Libs = sdk.properties.Libs |
| 1399 | } |
| 1400 | |
| 1401 | func (s *sdkLibrarySdkMemberProperties) AddToPropertySet(ctx android.SdkMemberContext, propertySet android.BpPropertySet) { |
| 1402 | for _, apiScope := range allApiScopes { |
| 1403 | if properties, ok := s.Scopes[apiScope]; ok { |
| 1404 | scopeSet := propertySet.AddPropertySet(apiScope.name) |
| 1405 | |
Paul Duffin | 3d1248c | 2020-04-09 00:10:17 +0100 | [diff] [blame] | 1406 | scopeDir := filepath.Join("sdk_library", s.OsPrefix(), apiScope.name) |
| 1407 | |
Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 1408 | var jars []string |
| 1409 | for _, p := range properties.Jars { |
Paul Duffin | 3d1248c | 2020-04-09 00:10:17 +0100 | [diff] [blame] | 1410 | dest := filepath.Join(scopeDir, ctx.Name()+"-stubs.jar") |
Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 1411 | ctx.SnapshotBuilder().CopyToSnapshot(p, dest) |
| 1412 | jars = append(jars, dest) |
| 1413 | } |
| 1414 | scopeSet.AddProperty("jars", jars) |
| 1415 | |
Paul Duffin | 3d1248c | 2020-04-09 00:10:17 +0100 | [diff] [blame] | 1416 | // Merge the stubs source jar into the snapshot zip so that when it is unpacked |
| 1417 | // the source files are also unpacked. |
| 1418 | snapshotRelativeDir := filepath.Join(scopeDir, ctx.Name()+"_stub_sources") |
| 1419 | ctx.SnapshotBuilder().UnzipToSnapshot(properties.StubsSrcJar, snapshotRelativeDir) |
| 1420 | scopeSet.AddProperty("stub_srcs", []string{snapshotRelativeDir}) |
| 1421 | |
Paul Duffin | 1fd005d | 2020-04-09 01:08:11 +0100 | [diff] [blame] | 1422 | if properties.CurrentApiFile != nil { |
| 1423 | currentApiSnapshotPath := filepath.Join(scopeDir, ctx.Name()+".txt") |
| 1424 | ctx.SnapshotBuilder().CopyToSnapshot(properties.CurrentApiFile, currentApiSnapshotPath) |
| 1425 | scopeSet.AddProperty("current_api", currentApiSnapshotPath) |
| 1426 | } |
| 1427 | |
| 1428 | if properties.RemovedApiFile != nil { |
| 1429 | removedApiSnapshotPath := filepath.Join(scopeDir, ctx.Name()+"-removed.txt") |
| 1430 | ctx.SnapshotBuilder().CopyToSnapshot(properties.CurrentApiFile, removedApiSnapshotPath) |
| 1431 | scopeSet.AddProperty("removed_api", removedApiSnapshotPath) |
| 1432 | } |
| 1433 | |
Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 1434 | if properties.SdkVersion != "" { |
| 1435 | scopeSet.AddProperty("sdk_version", properties.SdkVersion) |
| 1436 | } |
| 1437 | } |
| 1438 | } |
| 1439 | |
| 1440 | if len(s.Libs) > 0 { |
| 1441 | propertySet.AddPropertyWithTag("libs", s.Libs, ctx.SnapshotBuilder().SdkMemberReferencePropertyTag(false)) |
| 1442 | } |
| 1443 | } |