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