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