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" |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 36 | sdkDocsSuffix = ".docs" |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 37 | sdkXmlFileSuffix = ".xml" |
Jooyung Han | 624058e | 2019-12-24 18:38:06 +0900 | [diff] [blame] | 38 | permissionsTemplate = `<?xml version="1.0" encoding="utf-8"?>\n` + |
| 39 | `<!-- Copyright (C) 2018 The Android Open Source Project\n` + |
| 40 | `\n` + |
| 41 | ` Licensed under the Apache License, Version 2.0 (the "License");\n` + |
| 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` + |
| 48 | ` distributed under the License is distributed on an "AS IS" BASIS,\n` + |
| 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` + |
| 54 | ` <library name="%s" file="%s"/>\n` + |
| 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 { |
| 111 | return baseName + sdkDocsSuffix + scope.moduleSuffix |
| 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 |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 252 | |
Jooyung Han | 624058e | 2019-12-24 18:38:06 +0900 | [diff] [blame] | 253 | permissionsFile android.Path |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 254 | } |
| 255 | |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 256 | var _ Dependency = (*SdkLibrary)(nil) |
| 257 | var _ SdkLibraryDependency = (*SdkLibrary)(nil) |
Colin Cross | 897d2ed | 2019-02-11 14:03:51 -0800 | [diff] [blame] | 258 | |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 259 | func (module *SdkLibrary) getActiveApiScopes() apiScopes { |
| 260 | if module.sdkLibraryProperties.Has_system_and_test_apis { |
| 261 | return allApiScopes |
| 262 | } else { |
| 263 | return apiScopes{apiScopePublic} |
| 264 | } |
| 265 | } |
| 266 | |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 267 | func (module *SdkLibrary) DepsMutator(ctx android.BottomUpMutatorContext) { |
Jiyong Park | e3ef3c8 | 2019-07-15 15:31:16 +0900 | [diff] [blame] | 268 | useBuiltStubs := !ctx.Config().UnbundledBuildUsePrebuiltSdks() |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 269 | for _, apiScope := range module.getActiveApiScopes() { |
| 270 | // Add dependencies to the stubs library |
Jiyong Park | e3ef3c8 | 2019-07-15 15:31:16 +0900 | [diff] [blame] | 271 | if useBuiltStubs { |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 272 | ctx.AddVariationDependencies(nil, apiScope.stubsTag, module.stubsName(apiScope)) |
Jiyong Park | e3ef3c8 | 2019-07-15 15:31:16 +0900 | [diff] [blame] | 273 | } |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 274 | |
| 275 | ctx.AddVariationDependencies(nil, apiScope.apiFileTag, module.docsName(apiScope)) |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 276 | } |
| 277 | |
| 278 | module.Library.deps(ctx) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 279 | } |
| 280 | |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 281 | func (module *SdkLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Paul Duffin | 43db9be | 2019-12-30 17:35:49 +0000 | [diff] [blame] | 282 | // Don't build an implementation library if this is api only. |
| 283 | if !proptools.Bool(module.sdkLibraryProperties.Api_only) { |
| 284 | module.Library.GenerateAndroidBuildActions(ctx) |
| 285 | } |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 286 | |
Jooyung Han | 624058e | 2019-12-24 18:38:06 +0900 | [diff] [blame] | 287 | module.buildPermissionsFile(ctx) |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 288 | |
Sundong Ahn | 57368eb | 2018-07-06 11:20:23 +0900 | [diff] [blame] | 289 | // 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] | 290 | // 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] | 291 | // the recorded paths will be returned depending on the link type of the caller. |
| 292 | ctx.VisitDirectDeps(func(to android.Module) { |
| 293 | otherName := ctx.OtherModuleName(to) |
| 294 | tag := ctx.OtherModuleDependencyTag(to) |
| 295 | |
Sundong Ahn | 57368eb | 2018-07-06 11:20:23 +0900 | [diff] [blame] | 296 | if lib, ok := to.(Dependency); ok { |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 297 | if scopeTag, ok := tag.(scopeDependencyTag); ok { |
| 298 | apiScope := scopeTag.apiScope |
| 299 | scopePaths := module.getScopePaths(apiScope) |
| 300 | scopePaths.stubsHeaderPath = lib.HeaderJars() |
| 301 | scopePaths.stubsImplPath = lib.ImplementationJars() |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 302 | } |
| 303 | } |
Sundong Ahn | 20e998b | 2018-07-24 11:19:26 +0900 | [diff] [blame] | 304 | if doc, ok := to.(ApiFilePath); 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.apiFilePath = doc.ApiFilePath() |
| 309 | } else { |
Sundong Ahn | 20e998b | 2018-07-24 11:19:26 +0900 | [diff] [blame] | 310 | ctx.ModuleErrorf("depends on module %q of unknown tag %q", otherName, tag) |
| 311 | } |
| 312 | } |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 313 | }) |
| 314 | } |
| 315 | |
Jooyung Han | 624058e | 2019-12-24 18:38:06 +0900 | [diff] [blame] | 316 | func (module *SdkLibrary) buildPermissionsFile(ctx android.ModuleContext) { |
| 317 | xmlContent := fmt.Sprintf(permissionsTemplate, module.BaseModuleName(), module.implPath()) |
| 318 | permissionsFile := android.PathForModuleOut(ctx, module.xmlFileName()) |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 319 | |
Jooyung Han | 624058e | 2019-12-24 18:38:06 +0900 | [diff] [blame] | 320 | ctx.Build(pctx, android.BuildParams{ |
| 321 | Rule: android.WriteFile, |
| 322 | Output: permissionsFile, |
| 323 | Description: "Generating " + module.BaseModuleName() + " permissions", |
| 324 | Args: map[string]string{ |
| 325 | "content": xmlContent, |
| 326 | }, |
| 327 | }) |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 328 | |
Jooyung Han | 624058e | 2019-12-24 18:38:06 +0900 | [diff] [blame] | 329 | module.permissionsFile = permissionsFile |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 330 | } |
| 331 | |
Jooyung Han | 624058e | 2019-12-24 18:38:06 +0900 | [diff] [blame] | 332 | func (module *SdkLibrary) OutputFiles(tag string) (android.Paths, error) { |
| 333 | switch tag { |
| 334 | case ".xml": |
| 335 | return android.Paths{module.permissionsFile}, nil |
| 336 | } |
| 337 | return module.Library.OutputFiles(tag) |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 338 | } |
| 339 | |
Jiyong Park | 0b0e1b9 | 2019-12-03 13:24:29 +0900 | [diff] [blame] | 340 | func (module *SdkLibrary) AndroidMkEntries() []android.AndroidMkEntries { |
Paul Duffin | 43db9be | 2019-12-30 17:35:49 +0000 | [diff] [blame] | 341 | if proptools.Bool(module.sdkLibraryProperties.Api_only) { |
| 342 | return nil |
| 343 | } |
Jiyong Park | 0b0e1b9 | 2019-12-03 13:24:29 +0900 | [diff] [blame] | 344 | entriesList := module.Library.AndroidMkEntries() |
| 345 | entries := &entriesList[0] |
Jaewoong Jung | b0c127c | 2019-08-29 14:56:03 -0700 | [diff] [blame] | 346 | entries.Required = append(entries.Required, module.xmlFileName()) |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 347 | |
Jaewoong Jung | b0c127c | 2019-08-29 14:56:03 -0700 | [diff] [blame] | 348 | entries.ExtraFooters = []android.AndroidMkExtraFootersFunc{ |
| 349 | func(w io.Writer, name, prefix, moduleDir string, entries *android.AndroidMkEntries) { |
Jaewoong Jung | b0c127c | 2019-08-29 14:56:03 -0700 | [diff] [blame] | 350 | if !Bool(module.sdkLibraryProperties.No_dist) { |
| 351 | // Create a phony module that installs the impl library, for the case when this lib is |
| 352 | // in PRODUCT_PACKAGES. |
| 353 | owner := module.ModuleBase.Owner() |
| 354 | if owner == "" { |
| 355 | if Bool(module.sdkLibraryProperties.Core_lib) { |
| 356 | owner = "core" |
| 357 | } else { |
| 358 | owner = "android" |
| 359 | } |
| 360 | } |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 361 | |
| 362 | // Create dist rules to install the stubs libs and api files to the dist dir |
| 363 | for _, apiScope := range module.getActiveApiScopes() { |
| 364 | if scopePaths, ok := module.scopePaths[apiScope]; ok { |
| 365 | if len(scopePaths.stubsHeaderPath) == 1 { |
| 366 | fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+ |
| 367 | scopePaths.stubsImplPath.Strings()[0]+ |
| 368 | ":"+path.Join("apistubs", owner, apiScope.name, |
| 369 | module.BaseModuleName()+".jar")+")") |
| 370 | } |
| 371 | if scopePaths.apiFilePath != nil { |
| 372 | fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+ |
| 373 | scopePaths.apiFilePath.String()+ |
| 374 | ":"+path.Join("apistubs", owner, apiScope.name, "api", |
| 375 | module.BaseModuleName()+".txt")+")") |
| 376 | } |
| 377 | } |
Sundong Ahn | 80a87b3 | 2019-05-13 15:02:50 +0900 | [diff] [blame] | 378 | } |
Sundong Ahn | 4fd04bb | 2018-08-31 18:01:37 +0900 | [diff] [blame] | 379 | } |
Jaewoong Jung | b0c127c | 2019-08-29 14:56:03 -0700 | [diff] [blame] | 380 | }, |
Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 381 | } |
Jiyong Park | 0b0e1b9 | 2019-12-03 13:24:29 +0900 | [diff] [blame] | 382 | return entriesList |
Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 383 | } |
| 384 | |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 385 | // Module name of the stubs library |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 386 | func (module *SdkLibrary) stubsName(apiScope *apiScope) string { |
| 387 | return apiScope.stubsModuleName(module.BaseModuleName()) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 388 | } |
| 389 | |
| 390 | // Module name of the docs |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 391 | func (module *SdkLibrary) docsName(apiScope *apiScope) string { |
| 392 | return apiScope.docsModuleName(module.BaseModuleName()) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 393 | } |
| 394 | |
| 395 | // Module name of the runtime implementation library |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 396 | func (module *SdkLibrary) implName() string { |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 397 | return module.BaseModuleName() |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 398 | } |
| 399 | |
| 400 | // File path to the runtime implementation library |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 401 | func (module *SdkLibrary) implPath() string { |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 402 | if apexName := module.ApexName(); apexName != "" { |
| 403 | // TODO(b/146468504): ApexName() is only a soong module name, not apex name. |
| 404 | // In most cases, this works fine. But when apex_name is set or override_apex is used |
| 405 | // this can be wrong. |
| 406 | return fmt.Sprintf("/apex/%s/javalib/%s.jar", apexName, module.implName()) |
| 407 | } |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 408 | partition := "system" |
| 409 | if module.SocSpecific() { |
| 410 | partition = "vendor" |
| 411 | } else if module.DeviceSpecific() { |
| 412 | partition = "odm" |
| 413 | } else if module.ProductSpecific() { |
| 414 | partition = "product" |
Sundong Ahn | 0d7dff4 | 2019-12-04 12:53:44 +0900 | [diff] [blame] | 415 | } else if module.SystemExtSpecific() { |
| 416 | partition = "system_ext" |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 417 | } |
| 418 | return "/" + partition + "/framework/" + module.implName() + ".jar" |
| 419 | } |
| 420 | |
| 421 | // Module name of the XML file for the lib |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 422 | func (module *SdkLibrary) xmlFileName() string { |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 423 | return module.BaseModuleName() + sdkXmlFileSuffix |
| 424 | } |
| 425 | |
Paul Duffin | 12ceb46 | 2019-12-24 20:31:31 +0000 | [diff] [blame] | 426 | // Get the sdk version for use when compiling the stubs library. |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 427 | func (module *SdkLibrary) sdkVersionForStubsLibrary(mctx android.LoadHookContext, apiScope *apiScope) string { |
Paul Duffin | 12ceb46 | 2019-12-24 20:31:31 +0000 | [diff] [blame] | 428 | sdkDep := decodeSdkDep(mctx, sdkContext(&module.Library)) |
| 429 | if sdkDep.hasStandardLibs() { |
| 430 | // 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] | 431 | return apiScope.sdkVersion |
Paul Duffin | 12ceb46 | 2019-12-24 20:31:31 +0000 | [diff] [blame] | 432 | } else { |
| 433 | // Otherwise, use no system module. |
| 434 | return "none" |
| 435 | } |
| 436 | } |
| 437 | |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 438 | // $(INTERNAL_PLATFORM_<apiTagName>_API_FILE) points to the generated |
| 439 | // api file for the current source |
| 440 | // TODO: remove this when apicheck is done in soong |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 441 | func (module *SdkLibrary) apiTagName(apiScope *apiScope) string { |
| 442 | return strings.Replace(strings.ToUpper(module.BaseModuleName()), ".", "_", -1) + apiScope.apiFileMakeVariableSuffix |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 443 | } |
| 444 | |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 445 | func (module *SdkLibrary) latestApiFilegroupName(apiScope *apiScope) string { |
| 446 | return ":" + module.BaseModuleName() + ".api." + apiScope.name + ".latest" |
Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 447 | } |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 448 | |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 449 | func (module *SdkLibrary) latestRemovedApiFilegroupName(apiScope *apiScope) string { |
| 450 | return ":" + module.BaseModuleName() + "-removed.api." + apiScope.name + ".latest" |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 451 | } |
| 452 | |
| 453 | // Creates a static java library that has API stubs |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 454 | func (module *SdkLibrary) createStubsLibrary(mctx android.LoadHookContext, apiScope *apiScope) { |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 455 | props := struct { |
Sundong Ahn | 0d7dff4 | 2019-12-04 12:53:44 +0900 | [diff] [blame] | 456 | Name *string |
| 457 | Srcs []string |
Paul Duffin | 367ab91 | 2019-12-23 19:40:36 +0000 | [diff] [blame] | 458 | Installable *bool |
Sundong Ahn | 0d7dff4 | 2019-12-04 12:53:44 +0900 | [diff] [blame] | 459 | Sdk_version *string |
Paul Duffin | 12ceb46 | 2019-12-24 20:31:31 +0000 | [diff] [blame] | 460 | System_modules *string |
Sundong Ahn | 0d7dff4 | 2019-12-04 12:53:44 +0900 | [diff] [blame] | 461 | Libs []string |
| 462 | Soc_specific *bool |
| 463 | Device_specific *bool |
| 464 | Product_specific *bool |
| 465 | System_ext_specific *bool |
| 466 | Compile_dex *bool |
Sundong Ahn | 0d7dff4 | 2019-12-04 12:53:44 +0900 | [diff] [blame] | 467 | Java_version *string |
| 468 | Product_variables struct { |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 469 | Unbundled_build struct { |
| 470 | Enabled *bool |
| 471 | } |
Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 472 | Pdk struct { |
| 473 | Enabled *bool |
| 474 | } |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 475 | } |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 476 | Openjdk9 struct { |
| 477 | Srcs []string |
| 478 | Javacflags []string |
| 479 | } |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 480 | }{} |
| 481 | |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 482 | props.Name = proptools.StringPtr(module.stubsName(apiScope)) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 483 | // sources are generated from the droiddoc |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 484 | props.Srcs = []string{":" + module.docsName(apiScope)} |
Paul Duffin | 12ceb46 | 2019-12-24 20:31:31 +0000 | [diff] [blame] | 485 | sdkVersion := module.sdkVersionForStubsLibrary(mctx, apiScope) |
Paul Duffin | 52d398a | 2019-06-11 12:31:14 +0100 | [diff] [blame] | 486 | props.Sdk_version = proptools.StringPtr(sdkVersion) |
Paul Duffin | 12ceb46 | 2019-12-24 20:31:31 +0000 | [diff] [blame] | 487 | props.System_modules = module.Library.Module.deviceProperties.System_modules |
Paul Duffin | 367ab91 | 2019-12-23 19:40:36 +0000 | [diff] [blame] | 488 | props.Installable = proptools.BoolPtr(false) |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 489 | props.Libs = module.sdkLibraryProperties.Stub_only_libs |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 490 | // Unbundled apps will use the prebult one from /prebuilts/sdk |
Colin Cross | 1093287 | 2019-04-18 14:27:12 -0700 | [diff] [blame] | 491 | if mctx.Config().UnbundledBuildUsePrebuiltSdks() { |
Colin Cross | 2c77ceb | 2019-01-21 11:56:21 -0800 | [diff] [blame] | 492 | props.Product_variables.Unbundled_build.Enabled = proptools.BoolPtr(false) |
| 493 | } |
Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 494 | props.Product_variables.Pdk.Enabled = proptools.BoolPtr(false) |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 495 | props.Openjdk9.Srcs = module.Library.Module.properties.Openjdk9.Srcs |
| 496 | props.Openjdk9.Javacflags = module.Library.Module.properties.Openjdk9.Javacflags |
| 497 | props.Java_version = module.Library.Module.properties.Java_version |
| 498 | if module.Library.Module.deviceProperties.Compile_dex != nil { |
| 499 | props.Compile_dex = module.Library.Module.deviceProperties.Compile_dex |
Sundong Ahn | dd567f9 | 2018-07-31 17:19:11 +0900 | [diff] [blame] | 500 | } |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 501 | |
| 502 | if module.SocSpecific() { |
| 503 | props.Soc_specific = proptools.BoolPtr(true) |
| 504 | } else if module.DeviceSpecific() { |
| 505 | props.Device_specific = proptools.BoolPtr(true) |
| 506 | } else if module.ProductSpecific() { |
| 507 | props.Product_specific = proptools.BoolPtr(true) |
Sundong Ahn | 0d7dff4 | 2019-12-04 12:53:44 +0900 | [diff] [blame] | 508 | } else if module.SystemExtSpecific() { |
| 509 | props.System_ext_specific = proptools.BoolPtr(true) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 510 | } |
| 511 | |
Colin Cross | 84dfc3d | 2019-09-25 11:33:01 -0700 | [diff] [blame] | 512 | mctx.CreateModule(LibraryFactory, &props) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 513 | } |
| 514 | |
| 515 | // Creates a droiddoc module that creates stubs source files from the given full source |
| 516 | // files |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 517 | func (module *SdkLibrary) createStubsSources(mctx android.LoadHookContext, apiScope *apiScope) { |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 518 | props := struct { |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 519 | Name *string |
| 520 | Srcs []string |
| 521 | Installable *bool |
Paul Duffin | 52d398a | 2019-06-11 12:31:14 +0100 | [diff] [blame] | 522 | Sdk_version *string |
Paul Duffin | 12ceb46 | 2019-12-24 20:31:31 +0000 | [diff] [blame] | 523 | System_modules *string |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 524 | Libs []string |
Paul Duffin | 1151247 | 2019-02-11 15:55:17 +0000 | [diff] [blame] | 525 | Arg_files []string |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 526 | Args *string |
| 527 | Api_tag_name *string |
| 528 | Api_filename *string |
| 529 | Removed_api_filename *string |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 530 | Java_version *string |
| 531 | Merge_annotations_dirs []string |
| 532 | Merge_inclusion_annotations_dirs []string |
| 533 | Check_api struct { |
Inseob Kim | 38449af | 2019-02-28 14:24:05 +0900 | [diff] [blame] | 534 | Current ApiToCheck |
| 535 | Last_released ApiToCheck |
| 536 | Ignore_missing_latest_api *bool |
Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 537 | } |
Sundong Ahn | 1b92c82 | 2018-05-29 11:35:17 +0900 | [diff] [blame] | 538 | Aidl struct { |
| 539 | Include_dirs []string |
| 540 | Local_include_dirs []string |
| 541 | } |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 542 | }{} |
| 543 | |
Paul Duffin | 250e619 | 2019-06-07 10:44:37 +0100 | [diff] [blame] | 544 | sdkDep := decodeSdkDep(mctx, sdkContext(&module.Library)) |
Paul Duffin | 12ceb46 | 2019-12-24 20:31:31 +0000 | [diff] [blame] | 545 | // Use the platform API if standard libraries were requested, otherwise use |
| 546 | // no default libraries. |
Paul Duffin | 52d398a | 2019-06-11 12:31:14 +0100 | [diff] [blame] | 547 | sdkVersion := "" |
| 548 | if !sdkDep.hasStandardLibs() { |
| 549 | sdkVersion = "none" |
| 550 | } |
Paul Duffin | 250e619 | 2019-06-07 10:44:37 +0100 | [diff] [blame] | 551 | |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 552 | props.Name = proptools.StringPtr(module.docsName(apiScope)) |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 553 | props.Srcs = append(props.Srcs, module.Library.Module.properties.Srcs...) |
Paul Duffin | 52d398a | 2019-06-11 12:31:14 +0100 | [diff] [blame] | 554 | props.Sdk_version = proptools.StringPtr(sdkVersion) |
Paul Duffin | 12ceb46 | 2019-12-24 20:31:31 +0000 | [diff] [blame] | 555 | props.System_modules = module.Library.Module.deviceProperties.System_modules |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 556 | props.Installable = proptools.BoolPtr(false) |
Sundong Ahn | e6f0b05 | 2018-06-05 16:46:14 +0900 | [diff] [blame] | 557 | // A droiddoc module has only one Libs property and doesn't distinguish between |
| 558 | // 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] | 559 | props.Libs = module.Library.Module.properties.Libs |
| 560 | props.Libs = append(props.Libs, module.Library.Module.properties.Static_libs...) |
| 561 | props.Aidl.Include_dirs = module.Library.Module.deviceProperties.Aidl.Include_dirs |
| 562 | 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] | 563 | props.Java_version = module.Library.Module.properties.Java_version |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 564 | |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 565 | props.Merge_annotations_dirs = module.sdkLibraryProperties.Merge_annotations_dirs |
| 566 | props.Merge_inclusion_annotations_dirs = module.sdkLibraryProperties.Merge_inclusion_annotations_dirs |
| 567 | |
Paul Duffin | 235ffff | 2019-12-24 10:41:30 +0000 | [diff] [blame] | 568 | droiddocArgs := []string{} |
| 569 | if len(module.sdkLibraryProperties.Api_packages) != 0 { |
| 570 | droiddocArgs = append(droiddocArgs, "--stub-packages "+strings.Join(module.sdkLibraryProperties.Api_packages, ":")) |
| 571 | } |
| 572 | if len(module.sdkLibraryProperties.Hidden_api_packages) != 0 { |
| 573 | droiddocArgs = append(droiddocArgs, |
| 574 | android.JoinWithPrefix(module.sdkLibraryProperties.Hidden_api_packages, " --hide-package ")) |
| 575 | } |
| 576 | droiddocArgs = append(droiddocArgs, module.sdkLibraryProperties.Droiddoc_options...) |
| 577 | disabledWarnings := []string{ |
| 578 | "MissingPermission", |
| 579 | "BroadcastBehavior", |
| 580 | "HiddenSuperclass", |
| 581 | "DeprecationMismatch", |
| 582 | "UnavailableSymbol", |
| 583 | "SdkConstant", |
| 584 | "HiddenTypeParameter", |
| 585 | "Todo", |
| 586 | "Typo", |
| 587 | } |
| 588 | droiddocArgs = append(droiddocArgs, android.JoinWithPrefix(disabledWarnings, "--hide ")) |
Sundong Ahn | fb2721f | 2018-09-17 13:23:09 +0900 | [diff] [blame] | 589 | |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 590 | switch apiScope { |
| 591 | case apiScopeSystem: |
Paul Duffin | 235ffff | 2019-12-24 10:41:30 +0000 | [diff] [blame] | 592 | droiddocArgs = append(droiddocArgs, "-showAnnotation android.annotation.SystemApi") |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 593 | case apiScopeTest: |
Paul Duffin | 235ffff | 2019-12-24 10:41:30 +0000 | [diff] [blame] | 594 | droiddocArgs = append(droiddocArgs, " -showAnnotation android.annotation.TestApi") |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 595 | } |
Paul Duffin | 1151247 | 2019-02-11 15:55:17 +0000 | [diff] [blame] | 596 | props.Arg_files = module.sdkLibraryProperties.Droiddoc_option_files |
Paul Duffin | 235ffff | 2019-12-24 10:41:30 +0000 | [diff] [blame] | 597 | props.Args = proptools.StringPtr(strings.Join(droiddocArgs, " ")) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 598 | |
| 599 | // List of APIs identified from the provided source files are created. They are later |
| 600 | // compared against to the not-yet-released (a.k.a current) list of APIs and to the |
| 601 | // last-released (a.k.a numbered) list of API. |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 602 | currentApiFileName := apiScope.apiFilePrefix + "current.txt" |
| 603 | removedApiFileName := apiScope.apiFilePrefix + "removed.txt" |
Paul Duffin | 749f98f | 2019-12-30 17:23:46 +0000 | [diff] [blame] | 604 | apiDir := module.getApiDir() |
| 605 | currentApiFileName = path.Join(apiDir, currentApiFileName) |
| 606 | removedApiFileName = path.Join(apiDir, removedApiFileName) |
Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 607 | // TODO(jiyong): remove these three props |
Jiyong Park | df13054 | 2018-04-27 16:29:21 +0900 | [diff] [blame] | 608 | props.Api_tag_name = proptools.StringPtr(module.apiTagName(apiScope)) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 609 | props.Api_filename = proptools.StringPtr(currentApiFileName) |
| 610 | props.Removed_api_filename = proptools.StringPtr(removedApiFileName) |
| 611 | |
Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 612 | // check against the not-yet-release API |
| 613 | props.Check_api.Current.Api_file = proptools.StringPtr(currentApiFileName) |
| 614 | props.Check_api.Current.Removed_api_file = proptools.StringPtr(removedApiFileName) |
Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 615 | |
| 616 | // check against the latest released API |
| 617 | props.Check_api.Last_released.Api_file = proptools.StringPtr( |
| 618 | module.latestApiFilegroupName(apiScope)) |
| 619 | props.Check_api.Last_released.Removed_api_file = proptools.StringPtr( |
| 620 | module.latestRemovedApiFilegroupName(apiScope)) |
Inseob Kim | 38449af | 2019-02-28 14:24:05 +0900 | [diff] [blame] | 621 | props.Check_api.Ignore_missing_latest_api = proptools.BoolPtr(true) |
Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 622 | |
Colin Cross | 84dfc3d | 2019-09-25 11:33:01 -0700 | [diff] [blame] | 623 | mctx.CreateModule(DroidstubsFactory, &props) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 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) { |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 628 | // creates a prebuilt_etc module to actually place the xml file under |
| 629 | // <partition>/etc/permissions |
| 630 | etcProps := struct { |
Sundong Ahn | 0d7dff4 | 2019-12-04 12:53:44 +0900 | [diff] [blame] | 631 | Name *string |
| 632 | Src *string |
| 633 | Sub_dir *string |
| 634 | Soc_specific *bool |
| 635 | Device_specific *bool |
| 636 | Product_specific *bool |
| 637 | System_ext_specific *bool |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 638 | }{} |
| 639 | etcProps.Name = proptools.StringPtr(module.xmlFileName()) |
Jooyung Han | 624058e | 2019-12-24 18:38:06 +0900 | [diff] [blame] | 640 | etcProps.Src = proptools.StringPtr(":" + module.BaseModuleName() + "{.xml}") |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 641 | etcProps.Sub_dir = proptools.StringPtr("permissions") |
| 642 | if module.SocSpecific() { |
| 643 | etcProps.Soc_specific = proptools.BoolPtr(true) |
| 644 | } else if module.DeviceSpecific() { |
| 645 | etcProps.Device_specific = proptools.BoolPtr(true) |
| 646 | } else if module.ProductSpecific() { |
| 647 | etcProps.Product_specific = proptools.BoolPtr(true) |
Sundong Ahn | 0d7dff4 | 2019-12-04 12:53:44 +0900 | [diff] [blame] | 648 | } else if module.SystemExtSpecific() { |
| 649 | etcProps.System_ext_specific = proptools.BoolPtr(true) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 650 | } |
Colin Cross | 84dfc3d | 2019-09-25 11:33:01 -0700 | [diff] [blame] | 651 | mctx.CreateModule(android.PrebuiltEtcFactory, &etcProps) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 652 | } |
| 653 | |
Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 654 | func (module *SdkLibrary) PrebuiltJars(ctx android.BaseModuleContext, s sdkSpec) android.Paths { |
| 655 | var ver sdkVersion |
| 656 | var kind sdkKind |
| 657 | if s.usePrebuilt(ctx) { |
| 658 | ver = s.version |
| 659 | kind = s.kind |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 660 | } else { |
Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 661 | // We don't have prebuilt SDK for the specific sdkVersion. |
| 662 | // Instead of breaking the build, fallback to use "system_current" |
| 663 | ver = sdkVersionCurrent |
| 664 | kind = sdkSystem |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 665 | } |
Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 666 | |
| 667 | dir := filepath.Join("prebuilts", "sdk", ver.String(), kind.String()) |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 668 | jar := filepath.Join(dir, module.BaseModuleName()+".jar") |
| 669 | jarPath := android.ExistentPathForSource(ctx, jar) |
Sundong Ahn | ae418ac | 2019-02-28 15:01:28 +0900 | [diff] [blame] | 670 | if !jarPath.Valid() { |
Colin Cross | 07c8856 | 2020-01-07 09:34:44 -0800 | [diff] [blame] | 671 | if ctx.Config().AllowMissingDependencies() { |
| 672 | return android.Paths{android.PathForSource(ctx, jar)} |
| 673 | } else { |
Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 674 | 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] | 675 | } |
Sundong Ahn | ae418ac | 2019-02-28 15:01:28 +0900 | [diff] [blame] | 676 | return nil |
| 677 | } |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 678 | return android.Paths{jarPath.Path()} |
| 679 | } |
| 680 | |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 681 | func (module *SdkLibrary) sdkJars( |
| 682 | ctx android.BaseModuleContext, |
| 683 | sdkVersion sdkSpec, |
| 684 | headerJars bool) android.Paths { |
| 685 | |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 686 | // This module is just a wrapper for the stubs. |
Colin Cross | 1093287 | 2019-04-18 14:27:12 -0700 | [diff] [blame] | 687 | if ctx.Config().UnbundledBuildUsePrebuiltSdks() { |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 688 | return module.PrebuiltJars(ctx, sdkVersion) |
| 689 | } else { |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 690 | if !sdkVersion.specified() { |
| 691 | if headerJars { |
| 692 | return module.Library.HeaderJars() |
| 693 | } else { |
| 694 | return module.Library.ImplementationJars() |
| 695 | } |
| 696 | } |
Paul Duffin | 726d23c | 2020-01-22 16:30:37 +0000 | [diff] [blame] | 697 | var apiScope *apiScope |
Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 698 | switch sdkVersion.kind { |
| 699 | case sdkSystem: |
Paul Duffin | 726d23c | 2020-01-22 16:30:37 +0000 | [diff] [blame] | 700 | apiScope = apiScopeSystem |
| 701 | case sdkTest: |
| 702 | apiScope = apiScopeTest |
Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 703 | case sdkPrivate: |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 704 | return module.Library.HeaderJars() |
Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 705 | default: |
Paul Duffin | 726d23c | 2020-01-22 16:30:37 +0000 | [diff] [blame] | 706 | apiScope = apiScopePublic |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 707 | } |
| 708 | |
Paul Duffin | 726d23c | 2020-01-22 16:30:37 +0000 | [diff] [blame] | 709 | paths := module.getScopePaths(apiScope) |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 710 | if headerJars { |
| 711 | return paths.stubsHeaderPath |
| 712 | } else { |
| 713 | return paths.stubsImplPath |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 714 | } |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 715 | } |
| 716 | } |
| 717 | |
Sundong Ahn | 241cd37 | 2018-07-13 16:16:44 +0900 | [diff] [blame] | 718 | // to satisfy SdkLibraryDependency interface |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 719 | func (module *SdkLibrary) SdkHeaderJars(ctx android.BaseModuleContext, sdkVersion sdkSpec) android.Paths { |
| 720 | return module.sdkJars(ctx, sdkVersion, true /*headerJars*/) |
| 721 | } |
| 722 | |
| 723 | // to satisfy SdkLibraryDependency interface |
Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 724 | func (module *SdkLibrary) SdkImplementationJars(ctx android.BaseModuleContext, sdkVersion sdkSpec) android.Paths { |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 725 | return module.sdkJars(ctx, sdkVersion, false /*headerJars*/) |
Sundong Ahn | 241cd37 | 2018-07-13 16:16:44 +0900 | [diff] [blame] | 726 | } |
| 727 | |
Sundong Ahn | 80a87b3 | 2019-05-13 15:02:50 +0900 | [diff] [blame] | 728 | func (module *SdkLibrary) SetNoDist() { |
| 729 | module.sdkLibraryProperties.No_dist = proptools.BoolPtr(true) |
| 730 | } |
| 731 | |
Colin Cross | 571cccf | 2019-02-04 11:22:08 -0800 | [diff] [blame] | 732 | var javaSdkLibrariesKey = android.NewOnceKey("javaSdkLibraries") |
| 733 | |
Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 734 | func javaSdkLibraries(config android.Config) *[]string { |
Colin Cross | 571cccf | 2019-02-04 11:22:08 -0800 | [diff] [blame] | 735 | return config.Once(javaSdkLibrariesKey, func() interface{} { |
Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 736 | return &[]string{} |
| 737 | }).(*[]string) |
| 738 | } |
| 739 | |
Paul Duffin | 749f98f | 2019-12-30 17:23:46 +0000 | [diff] [blame] | 740 | func (module *SdkLibrary) getApiDir() string { |
| 741 | return proptools.StringDefault(module.sdkLibraryProperties.Api_dir, "api") |
| 742 | } |
| 743 | |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 744 | // For a java_sdk_library module, create internal modules for stubs, docs, |
| 745 | // runtime libs and xml file. If requested, the stubs and docs are created twice |
| 746 | // once for public API level and once for system API level |
Colin Cross | f8b860a | 2019-04-16 14:43:28 -0700 | [diff] [blame] | 747 | func (module *SdkLibrary) CreateInternalModules(mctx android.LoadHookContext) { |
Inseob Kim | 6e93ac9 | 2019-03-21 17:43:49 +0900 | [diff] [blame] | 748 | if len(module.Library.Module.properties.Srcs) == 0 { |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 749 | mctx.PropertyErrorf("srcs", "java_sdk_library must specify srcs") |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 750 | return |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 751 | } |
| 752 | |
Paul Duffin | 37e0b77 | 2019-12-30 17:20:10 +0000 | [diff] [blame] | 753 | // If this builds against standard libraries (i.e. is not part of the core libraries) |
| 754 | // then assume it provides both system and test apis. Otherwise, assume it does not and |
| 755 | // also assume it does not contribute to the dist build. |
| 756 | sdkDep := decodeSdkDep(mctx, sdkContext(&module.Library)) |
| 757 | hasSystemAndTestApis := sdkDep.hasStandardLibs() |
| 758 | module.sdkLibraryProperties.Has_system_and_test_apis = hasSystemAndTestApis |
| 759 | module.sdkLibraryProperties.No_dist = proptools.BoolPtr(!hasSystemAndTestApis) |
| 760 | |
Inseob Kim | 8098faa | 2019-03-18 10:19:51 +0900 | [diff] [blame] | 761 | missing_current_api := false |
| 762 | |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 763 | activeScopes := module.getActiveApiScopes() |
| 764 | |
Paul Duffin | 749f98f | 2019-12-30 17:23:46 +0000 | [diff] [blame] | 765 | apiDir := module.getApiDir() |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 766 | for _, scope := range activeScopes { |
Inseob Kim | 8098faa | 2019-03-18 10:19:51 +0900 | [diff] [blame] | 767 | for _, api := range []string{"current.txt", "removed.txt"} { |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 768 | path := path.Join(mctx.ModuleDir(), apiDir, scope.apiFilePrefix+api) |
Inseob Kim | 8098faa | 2019-03-18 10:19:51 +0900 | [diff] [blame] | 769 | p := android.ExistentPathForSource(mctx, path) |
| 770 | if !p.Valid() { |
| 771 | mctx.ModuleErrorf("Current api file %#v doesn't exist", path) |
| 772 | missing_current_api = true |
| 773 | } |
| 774 | } |
| 775 | } |
| 776 | |
| 777 | if missing_current_api { |
| 778 | script := "build/soong/scripts/gen-java-current-api-files.sh" |
| 779 | p := android.ExistentPathForSource(mctx, script) |
| 780 | |
| 781 | if !p.Valid() { |
| 782 | panic(fmt.Sprintf("script file %s doesn't exist", script)) |
| 783 | } |
| 784 | |
| 785 | mctx.ModuleErrorf("One or more current api files are missing. "+ |
| 786 | "You can update them by:\n"+ |
Paul Duffin | 37e0b77 | 2019-12-30 17:20:10 +0000 | [diff] [blame] | 787 | "%s %q %s && m update-api", |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 788 | script, filepath.Join(mctx.ModuleDir(), apiDir), |
| 789 | strings.Join(activeScopes.Strings(func(s *apiScope) string { return s.apiFilePrefix }), " ")) |
Inseob Kim | 8098faa | 2019-03-18 10:19:51 +0900 | [diff] [blame] | 790 | return |
| 791 | } |
| 792 | |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 793 | for _, scope := range activeScopes { |
| 794 | module.createStubsLibrary(mctx, scope) |
| 795 | module.createStubsSources(mctx, scope) |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 796 | } |
| 797 | |
Paul Duffin | 43db9be | 2019-12-30 17:35:49 +0000 | [diff] [blame] | 798 | if !proptools.Bool(module.sdkLibraryProperties.Api_only) { |
| 799 | // for runtime |
| 800 | module.createXmlFile(mctx) |
| 801 | |
| 802 | // record java_sdk_library modules so that they are exported to make |
| 803 | javaSdkLibraries := javaSdkLibraries(mctx.Config()) |
| 804 | javaSdkLibrariesLock.Lock() |
| 805 | defer javaSdkLibrariesLock.Unlock() |
| 806 | *javaSdkLibraries = append(*javaSdkLibraries, module.BaseModuleName()) |
| 807 | } |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 808 | } |
| 809 | |
| 810 | func (module *SdkLibrary) InitSdkLibraryProperties() { |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 811 | module.AddProperties( |
| 812 | &module.sdkLibraryProperties, |
| 813 | &module.Library.Module.properties, |
| 814 | &module.Library.Module.dexpreoptProperties, |
| 815 | &module.Library.Module.deviceProperties, |
| 816 | &module.Library.Module.protoProperties, |
| 817 | ) |
| 818 | |
| 819 | module.Library.Module.properties.Installable = proptools.BoolPtr(true) |
| 820 | module.Library.Module.deviceProperties.IsSDKLibrary = true |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 821 | } |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 822 | |
Jaewoong Jung | 4f158ee | 2019-07-11 10:05:35 -0700 | [diff] [blame] | 823 | // java_sdk_library is a special Java library that provides optional platform APIs to apps. |
| 824 | // In practice, it can be viewed as a combination of several modules: 1) stubs library that clients |
| 825 | // are linked against to, 2) droiddoc module that internally generates API stubs source files, |
| 826 | // 3) the real runtime shared library that implements the APIs, and 4) XML file for adding |
| 827 | // 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] | 828 | func SdkLibraryFactory() android.Module { |
| 829 | module := &SdkLibrary{} |
| 830 | module.InitSdkLibraryProperties() |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 831 | android.InitApexModule(module) |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 832 | InitJavaModule(module, android.HostAndDeviceSupported) |
Colin Cross | f8b860a | 2019-04-16 14:43:28 -0700 | [diff] [blame] | 833 | android.AddLoadHook(module, func(ctx android.LoadHookContext) { module.CreateInternalModules(ctx) }) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 834 | return module |
| 835 | } |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 836 | |
| 837 | // |
| 838 | // SDK library prebuilts |
| 839 | // |
| 840 | |
Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 841 | // Properties associated with each api scope. |
| 842 | type sdkLibraryScopeProperties struct { |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 843 | Jars []string `android:"path"` |
| 844 | |
| 845 | Sdk_version *string |
| 846 | |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 847 | // List of shared java libs that this module has dependencies to |
| 848 | Libs []string |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 849 | } |
| 850 | |
Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 851 | type sdkLibraryImportProperties struct { |
Paul Duffin | fcfd791 | 2020-01-31 17:54:30 +0000 | [diff] [blame^] | 852 | // List of shared java libs, common to all scopes, that this module has |
| 853 | // dependencies to |
| 854 | Libs []string |
| 855 | |
Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 856 | // Properties associated with the public api scope. |
| 857 | Public sdkLibraryScopeProperties |
| 858 | |
| 859 | // Properties associated with the system api scope. |
| 860 | System sdkLibraryScopeProperties |
| 861 | |
| 862 | // Properties associated with the test api scope. |
| 863 | Test sdkLibraryScopeProperties |
| 864 | } |
| 865 | |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 866 | type sdkLibraryImport struct { |
| 867 | android.ModuleBase |
| 868 | android.DefaultableModuleBase |
| 869 | prebuilt android.Prebuilt |
| 870 | |
| 871 | properties sdkLibraryImportProperties |
| 872 | |
Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 873 | commonToSdkLibraryAndImport |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 874 | } |
| 875 | |
| 876 | var _ SdkLibraryDependency = (*sdkLibraryImport)(nil) |
| 877 | |
Jaewoong Jung | 4f158ee | 2019-07-11 10:05:35 -0700 | [diff] [blame] | 878 | // java_sdk_library_import imports a prebuilt java_sdk_library. |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 879 | func sdkLibraryImportFactory() android.Module { |
| 880 | module := &sdkLibraryImport{} |
| 881 | |
Paul Duffin | fcfd791 | 2020-01-31 17:54:30 +0000 | [diff] [blame^] | 882 | module.AddProperties(&module.properties) |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 883 | |
Paul Duffin | fcfd791 | 2020-01-31 17:54:30 +0000 | [diff] [blame^] | 884 | android.InitPrebuiltModule(module, &[]string{}) |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 885 | InitJavaModule(module, android.HostAndDeviceSupported) |
| 886 | |
| 887 | android.AddLoadHook(module, func(mctx android.LoadHookContext) { module.createInternalModules(mctx) }) |
| 888 | return module |
| 889 | } |
| 890 | |
| 891 | func (module *sdkLibraryImport) Prebuilt() *android.Prebuilt { |
| 892 | return &module.prebuilt |
| 893 | } |
| 894 | |
| 895 | func (module *sdkLibraryImport) Name() string { |
| 896 | return module.prebuilt.Name(module.ModuleBase.Name()) |
| 897 | } |
| 898 | |
| 899 | func (module *sdkLibraryImport) createInternalModules(mctx android.LoadHookContext) { |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 900 | |
Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 901 | for apiScope, scopeProperties := range module.scopeProperties() { |
| 902 | if len(scopeProperties.Jars) == 0 { |
| 903 | continue |
| 904 | } |
| 905 | |
| 906 | // Creates a java import for the jar with ".stubs" suffix |
| 907 | props := struct { |
| 908 | Name *string |
| 909 | Soc_specific *bool |
| 910 | Device_specific *bool |
| 911 | Product_specific *bool |
| 912 | System_ext_specific *bool |
| 913 | Sdk_version *string |
| 914 | Libs []string |
| 915 | Jars []string |
| 916 | }{} |
| 917 | |
| 918 | props.Name = proptools.StringPtr(apiScope.stubsModuleName(module.BaseModuleName())) |
| 919 | props.Sdk_version = scopeProperties.Sdk_version |
Paul Duffin | fcfd791 | 2020-01-31 17:54:30 +0000 | [diff] [blame^] | 920 | // Prepend any of the libs from the legacy public properties to the libs for each of the |
| 921 | // scopes to avoid having to duplicate them in each scope. |
| 922 | props.Libs = append(module.properties.Libs, scopeProperties.Libs...) |
Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 923 | props.Jars = scopeProperties.Jars |
| 924 | |
| 925 | if module.SocSpecific() { |
| 926 | props.Soc_specific = proptools.BoolPtr(true) |
| 927 | } else if module.DeviceSpecific() { |
| 928 | props.Device_specific = proptools.BoolPtr(true) |
| 929 | } else if module.ProductSpecific() { |
| 930 | props.Product_specific = proptools.BoolPtr(true) |
| 931 | } else if module.SystemExtSpecific() { |
| 932 | props.System_ext_specific = proptools.BoolPtr(true) |
| 933 | } |
| 934 | |
| 935 | mctx.CreateModule(ImportFactory, &props) |
| 936 | } |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 937 | |
| 938 | javaSdkLibraries := javaSdkLibraries(mctx.Config()) |
| 939 | javaSdkLibrariesLock.Lock() |
| 940 | defer javaSdkLibrariesLock.Unlock() |
| 941 | *javaSdkLibraries = append(*javaSdkLibraries, module.BaseModuleName()) |
| 942 | } |
| 943 | |
Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 944 | func (module *sdkLibraryImport) scopeProperties() map[*apiScope]*sdkLibraryScopeProperties { |
| 945 | p := make(map[*apiScope]*sdkLibraryScopeProperties) |
| 946 | p[apiScopePublic] = &module.properties.Public |
| 947 | p[apiScopeSystem] = &module.properties.System |
| 948 | p[apiScopeTest] = &module.properties.Test |
| 949 | return p |
| 950 | } |
| 951 | |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 952 | func (module *sdkLibraryImport) DepsMutator(ctx android.BottomUpMutatorContext) { |
Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 953 | for apiScope, scopeProperties := range module.scopeProperties() { |
| 954 | if len(scopeProperties.Jars) == 0 { |
| 955 | continue |
| 956 | } |
| 957 | |
| 958 | // Add dependencies to the prebuilt stubs library |
| 959 | ctx.AddVariationDependencies(nil, apiScope.stubsTag, apiScope.stubsModuleName(module.BaseModuleName())) |
| 960 | } |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 961 | } |
| 962 | |
| 963 | func (module *sdkLibraryImport) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 964 | // Record the paths to the prebuilt stubs library. |
| 965 | ctx.VisitDirectDeps(func(to android.Module) { |
| 966 | tag := ctx.OtherModuleDependencyTag(to) |
| 967 | |
Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 968 | if lib, ok := to.(Dependency); ok { |
| 969 | if scopeTag, ok := tag.(scopeDependencyTag); ok { |
| 970 | apiScope := scopeTag.apiScope |
| 971 | scopePaths := module.getScopePaths(apiScope) |
| 972 | scopePaths.stubsHeaderPath = lib.HeaderJars() |
| 973 | } |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 974 | } |
| 975 | }) |
| 976 | } |
| 977 | |
Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 978 | func (module *sdkLibraryImport) sdkJars( |
| 979 | ctx android.BaseModuleContext, |
| 980 | sdkVersion sdkSpec) android.Paths { |
| 981 | |
| 982 | var apiScope *apiScope |
| 983 | switch sdkVersion.kind { |
| 984 | case sdkSystem: |
| 985 | apiScope = apiScopeSystem |
| 986 | case sdkTest: |
| 987 | apiScope = apiScopeTest |
| 988 | default: |
| 989 | apiScope = apiScopePublic |
| 990 | } |
| 991 | |
| 992 | paths := module.getScopePaths(apiScope) |
| 993 | return paths.stubsHeaderPath |
| 994 | } |
| 995 | |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 996 | // to satisfy SdkLibraryDependency interface |
Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 997 | func (module *sdkLibraryImport) SdkHeaderJars(ctx android.BaseModuleContext, sdkVersion sdkSpec) android.Paths { |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 998 | // This module is just a wrapper for the prebuilt stubs. |
Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 999 | return module.sdkJars(ctx, sdkVersion) |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 1000 | } |
| 1001 | |
| 1002 | // to satisfy SdkLibraryDependency interface |
Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 1003 | func (module *sdkLibraryImport) SdkImplementationJars(ctx android.BaseModuleContext, sdkVersion sdkSpec) android.Paths { |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 1004 | // This module is just a wrapper for the stubs. |
Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 1005 | return module.sdkJars(ctx, sdkVersion) |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 1006 | } |