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