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