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