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