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