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