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