blob: 3fc18036f674e61db7a7e413aa9741ccbdc573ac [file] [log] [blame]
Jiyong Parkc678ad32018-04-10 13:07:10 +09001// 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
15package java
16
17import (
18 "android/soong/android"
Jiyong Parkc678ad32018-04-10 13:07:10 +090019 "fmt"
Jiyong Park82484c02018-04-23 21:41:26 +090020 "io"
Jiyong Parkc678ad32018-04-10 13:07:10 +090021 "path"
Sundong Ahn054b19a2018-10-19 13:46:09 +090022 "path/filepath"
Jiyong Park82484c02018-04-23 21:41:26 +090023 "sort"
Jiyong Parkc678ad32018-04-10 13:07:10 +090024 "strings"
Jiyong Park82484c02018-04-23 21:41:26 +090025 "sync"
Jiyong Parkc678ad32018-04-10 13:07:10 +090026
Jiyong Parkc678ad32018-04-10 13:07:10 +090027 "github.com/google/blueprint/proptools"
28)
29
Jooyung Han58f26ab2019-12-18 15:34:32 +090030const (
Jiyong Parkc678ad32018-04-10 13:07:10 +090031 sdkStubsLibrarySuffix = ".stubs"
32 sdkSystemApiSuffix = ".system"
Jiyong Parkdf130542018-04-27 16:29:21 +090033 sdkTestApiSuffix = ".test"
Jiyong Parkc678ad32018-04-10 13:07:10 +090034 sdkDocsSuffix = ".docs"
Jiyong Parkc678ad32018-04-10 13:07:10 +090035 sdkXmlFileSuffix = ".xml"
Jooyung Han624058e2019-12-24 18:38:06 +090036 permissionsTemplate = `<?xml version="1.0" encoding="utf-8"?>\n` +
37 `<!-- Copyright (C) 2018 The Android Open Source Project\n` +
38 `\n` +
39 ` Licensed under the Apache License, Version 2.0 (the "License");\n` +
40 ` you may not use this file except in compliance with the License.\n` +
41 ` You may obtain a copy of the License at\n` +
42 `\n` +
43 ` http://www.apache.org/licenses/LICENSE-2.0\n` +
44 `\n` +
45 ` Unless required by applicable law or agreed to in writing, software\n` +
46 ` distributed under the License is distributed on an "AS IS" BASIS,\n` +
47 ` WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n` +
48 ` See the License for the specific language governing permissions and\n` +
49 ` limitations under the License.\n` +
50 `-->\n` +
51 `<permissions>\n` +
52 ` <library name="%s" file="%s"/>\n` +
53 `</permissions>\n`
Jiyong Parkc678ad32018-04-10 13:07:10 +090054)
55
Jiyong Parkc678ad32018-04-10 13:07:10 +090056var (
57 publicApiStubsTag = dependencyTag{name: "public"}
58 systemApiStubsTag = dependencyTag{name: "system"}
Jiyong Parkdf130542018-04-27 16:29:21 +090059 testApiStubsTag = dependencyTag{name: "test"}
Sundong Ahn20e998b2018-07-24 11:19:26 +090060 publicApiFileTag = dependencyTag{name: "publicApi"}
61 systemApiFileTag = dependencyTag{name: "systemApi"}
62 testApiFileTag = dependencyTag{name: "testApi"}
Jiyong Parkdf130542018-04-27 16:29:21 +090063)
64
65type apiScope int
66
67const (
68 apiScopePublic apiScope = iota
69 apiScopeSystem
70 apiScopeTest
Jiyong Parkc678ad32018-04-10 13:07:10 +090071)
72
Jiyong Park82484c02018-04-23 21:41:26 +090073var (
74 javaSdkLibrariesLock sync.Mutex
75)
76
Jiyong Parkc678ad32018-04-10 13:07:10 +090077// TODO: these are big features that are currently missing
Jiyong Park1be96912018-05-28 18:02:19 +090078// 1) disallowing linking to the runtime shared lib
79// 2) HTML generation
Jiyong Parkc678ad32018-04-10 13:07:10 +090080
81func init() {
Paul Duffin43dc1cc2019-12-19 11:18:54 +000082 RegisterSdkLibraryBuildComponents(android.InitRegistrationContext)
Jiyong Parkc678ad32018-04-10 13:07:10 +090083
Jiyong Park82484c02018-04-23 21:41:26 +090084 android.RegisterMakeVarsProvider(pctx, func(ctx android.MakeVarsContext) {
85 javaSdkLibraries := javaSdkLibraries(ctx.Config())
86 sort.Strings(*javaSdkLibraries)
87 ctx.Strict("JAVA_SDK_LIBRARIES", strings.Join(*javaSdkLibraries, " "))
88 })
Jiyong Parkc678ad32018-04-10 13:07:10 +090089}
90
Paul Duffin43dc1cc2019-12-19 11:18:54 +000091func RegisterSdkLibraryBuildComponents(ctx android.RegistrationContext) {
92 ctx.RegisterModuleType("java_sdk_library", SdkLibraryFactory)
93 ctx.RegisterModuleType("java_sdk_library_import", sdkLibraryImportFactory)
94}
95
Jiyong Parkc678ad32018-04-10 13:07:10 +090096type sdkLibraryProperties struct {
Sundong Ahnf043cf62018-06-25 16:04:37 +090097 // List of Java libraries that will be in the classpath when building stubs
98 Stub_only_libs []string `android:"arch_variant"`
99
Paul Duffin7a586d32019-12-30 17:09:34 +0000100 // list of package names that will be documented and publicized as API.
101 // This allows the API to be restricted to a subset of the source files provided.
102 // If this is unspecified then all the source files will be treated as being part
103 // of the API.
Jiyong Parkc678ad32018-04-10 13:07:10 +0900104 Api_packages []string
105
Jiyong Park5a2c9d72018-05-01 22:25:41 +0900106 // list of package names that must be hidden from the API
107 Hidden_api_packages []string
108
Paul Duffin11512472019-02-11 15:55:17 +0000109 // local files that are used within user customized droiddoc options.
110 Droiddoc_option_files []string
111
112 // additional droiddoc options
113 // Available variables for substitution:
114 //
115 // $(location <label>): the path to the droiddoc_option_files with name <label>
Sundong Ahndd567f92018-07-31 17:19:11 +0900116 Droiddoc_options []string
117
Sundong Ahn054b19a2018-10-19 13:46:09 +0900118 // a list of top-level directories containing files to merge qualifier annotations
119 // (i.e. those intended to be included in the stubs written) from.
120 Merge_annotations_dirs []string
121
122 // a list of top-level directories containing Java stub files to merge show/hide annotations from.
123 Merge_inclusion_annotations_dirs []string
124
125 // If set to true, the path of dist files is apistubs/core. Defaults to false.
126 Core_lib *bool
127
Sundong Ahn80a87b32019-05-13 15:02:50 +0900128 // don't create dist rules.
129 No_dist *bool `blueprint:"mutated"`
130
Paul Duffin37e0b772019-12-30 17:20:10 +0000131 // indicates whether system and test apis should be managed.
132 Has_system_and_test_apis bool `blueprint:"mutated"`
133
Jiyong Parkc678ad32018-04-10 13:07:10 +0900134 // TODO: determines whether to create HTML doc or not
135 //Html_doc *bool
136}
137
Inseob Kimc0907f12019-02-08 21:00:45 +0900138type SdkLibrary struct {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900139 Library
Jiyong Parkc678ad32018-04-10 13:07:10 +0900140
Sundong Ahn054b19a2018-10-19 13:46:09 +0900141 sdkLibraryProperties sdkLibraryProperties
Jiyong Parkc678ad32018-04-10 13:07:10 +0900142
143 publicApiStubsPath android.Paths
144 systemApiStubsPath android.Paths
Jiyong Parkdf130542018-04-27 16:29:21 +0900145 testApiStubsPath android.Paths
Sundong Ahn241cd372018-07-13 16:16:44 +0900146
147 publicApiStubsImplPath android.Paths
148 systemApiStubsImplPath android.Paths
149 testApiStubsImplPath android.Paths
Sundong Ahn20e998b2018-07-24 11:19:26 +0900150
151 publicApiFilePath android.Path
152 systemApiFilePath android.Path
153 testApiFilePath android.Path
Jooyung Han58f26ab2019-12-18 15:34:32 +0900154
Jooyung Han624058e2019-12-24 18:38:06 +0900155 permissionsFile android.Path
Jiyong Parkc678ad32018-04-10 13:07:10 +0900156}
157
Inseob Kimc0907f12019-02-08 21:00:45 +0900158var _ Dependency = (*SdkLibrary)(nil)
159var _ SdkLibraryDependency = (*SdkLibrary)(nil)
Colin Cross897d2ed2019-02-11 14:03:51 -0800160
Inseob Kimc0907f12019-02-08 21:00:45 +0900161func (module *SdkLibrary) DepsMutator(ctx android.BottomUpMutatorContext) {
Jiyong Parke3ef3c82019-07-15 15:31:16 +0900162 useBuiltStubs := !ctx.Config().UnbundledBuildUsePrebuiltSdks()
Jiyong Parkc678ad32018-04-10 13:07:10 +0900163 // Add dependencies to the stubs library
Jiyong Parke3ef3c82019-07-15 15:31:16 +0900164 if useBuiltStubs {
165 ctx.AddVariationDependencies(nil, publicApiStubsTag, module.stubsName(apiScopePublic))
166 }
Colin Cross42d48b72018-08-29 14:10:52 -0700167 ctx.AddVariationDependencies(nil, publicApiFileTag, module.docsName(apiScopePublic))
Sundong Ahn054b19a2018-10-19 13:46:09 +0900168
Paul Duffin37e0b772019-12-30 17:20:10 +0000169 if module.sdkLibraryProperties.Has_system_and_test_apis {
Jiyong Parke3ef3c82019-07-15 15:31:16 +0900170 if useBuiltStubs {
171 ctx.AddVariationDependencies(nil, systemApiStubsTag, module.stubsName(apiScopeSystem))
172 ctx.AddVariationDependencies(nil, testApiStubsTag, module.stubsName(apiScopeTest))
173 }
Sundong Ahn054b19a2018-10-19 13:46:09 +0900174 ctx.AddVariationDependencies(nil, systemApiFileTag, module.docsName(apiScopeSystem))
175 ctx.AddVariationDependencies(nil, testApiFileTag, module.docsName(apiScopeTest))
Sundong Ahn054b19a2018-10-19 13:46:09 +0900176 }
177
178 module.Library.deps(ctx)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900179}
180
Inseob Kimc0907f12019-02-08 21:00:45 +0900181func (module *SdkLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900182 module.Library.GenerateAndroidBuildActions(ctx)
183
Jooyung Han624058e2019-12-24 18:38:06 +0900184 module.buildPermissionsFile(ctx)
Jooyung Han58f26ab2019-12-18 15:34:32 +0900185
Sundong Ahn57368eb2018-07-06 11:20:23 +0900186 // Record the paths to the header jars of the library (stubs and impl).
Jiyong Parkc678ad32018-04-10 13:07:10 +0900187 // When this java_sdk_library is dependened from others via "libs" property,
188 // the recorded paths will be returned depending on the link type of the caller.
189 ctx.VisitDirectDeps(func(to android.Module) {
190 otherName := ctx.OtherModuleName(to)
191 tag := ctx.OtherModuleDependencyTag(to)
192
Sundong Ahn57368eb2018-07-06 11:20:23 +0900193 if lib, ok := to.(Dependency); ok {
Jiyong Parkc678ad32018-04-10 13:07:10 +0900194 switch tag {
195 case publicApiStubsTag:
Sundong Ahn57368eb2018-07-06 11:20:23 +0900196 module.publicApiStubsPath = lib.HeaderJars()
Sundong Ahn241cd372018-07-13 16:16:44 +0900197 module.publicApiStubsImplPath = lib.ImplementationJars()
Jiyong Parkc678ad32018-04-10 13:07:10 +0900198 case systemApiStubsTag:
Sundong Ahn57368eb2018-07-06 11:20:23 +0900199 module.systemApiStubsPath = lib.HeaderJars()
Sundong Ahn241cd372018-07-13 16:16:44 +0900200 module.systemApiStubsImplPath = lib.ImplementationJars()
Jiyong Parkdf130542018-04-27 16:29:21 +0900201 case testApiStubsTag:
Sundong Ahn57368eb2018-07-06 11:20:23 +0900202 module.testApiStubsPath = lib.HeaderJars()
Sundong Ahn241cd372018-07-13 16:16:44 +0900203 module.testApiStubsImplPath = lib.ImplementationJars()
Jiyong Parkc678ad32018-04-10 13:07:10 +0900204 }
205 }
Sundong Ahn20e998b2018-07-24 11:19:26 +0900206 if doc, ok := to.(ApiFilePath); ok {
207 switch tag {
208 case publicApiFileTag:
209 module.publicApiFilePath = doc.ApiFilePath()
210 case systemApiFileTag:
211 module.systemApiFilePath = doc.ApiFilePath()
212 case testApiFileTag:
213 module.testApiFilePath = doc.ApiFilePath()
214 default:
215 ctx.ModuleErrorf("depends on module %q of unknown tag %q", otherName, tag)
216 }
217 }
Jiyong Parkc678ad32018-04-10 13:07:10 +0900218 })
219}
220
Jooyung Han624058e2019-12-24 18:38:06 +0900221func (module *SdkLibrary) buildPermissionsFile(ctx android.ModuleContext) {
222 xmlContent := fmt.Sprintf(permissionsTemplate, module.BaseModuleName(), module.implPath())
223 permissionsFile := android.PathForModuleOut(ctx, module.xmlFileName())
Jooyung Han58f26ab2019-12-18 15:34:32 +0900224
Jooyung Han624058e2019-12-24 18:38:06 +0900225 ctx.Build(pctx, android.BuildParams{
226 Rule: android.WriteFile,
227 Output: permissionsFile,
228 Description: "Generating " + module.BaseModuleName() + " permissions",
229 Args: map[string]string{
230 "content": xmlContent,
231 },
232 })
Jooyung Han58f26ab2019-12-18 15:34:32 +0900233
Jooyung Han624058e2019-12-24 18:38:06 +0900234 module.permissionsFile = permissionsFile
Jooyung Han58f26ab2019-12-18 15:34:32 +0900235}
236
Jooyung Han624058e2019-12-24 18:38:06 +0900237func (module *SdkLibrary) OutputFiles(tag string) (android.Paths, error) {
238 switch tag {
239 case ".xml":
240 return android.Paths{module.permissionsFile}, nil
241 }
242 return module.Library.OutputFiles(tag)
Jooyung Han58f26ab2019-12-18 15:34:32 +0900243}
244
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900245func (module *SdkLibrary) AndroidMkEntries() []android.AndroidMkEntries {
246 entriesList := module.Library.AndroidMkEntries()
247 entries := &entriesList[0]
Jaewoong Jungb0c127c2019-08-29 14:56:03 -0700248 entries.Required = append(entries.Required, module.xmlFileName())
Sundong Ahn054b19a2018-10-19 13:46:09 +0900249
Jaewoong Jungb0c127c2019-08-29 14:56:03 -0700250 entries.ExtraFooters = []android.AndroidMkExtraFootersFunc{
251 func(w io.Writer, name, prefix, moduleDir string, entries *android.AndroidMkEntries) {
Jaewoong Jungb0c127c2019-08-29 14:56:03 -0700252 if !Bool(module.sdkLibraryProperties.No_dist) {
253 // Create a phony module that installs the impl library, for the case when this lib is
254 // in PRODUCT_PACKAGES.
255 owner := module.ModuleBase.Owner()
256 if owner == "" {
257 if Bool(module.sdkLibraryProperties.Core_lib) {
258 owner = "core"
259 } else {
260 owner = "android"
261 }
262 }
263 // Create dist rules to install the stubs libs to the dist dir
264 if len(module.publicApiStubsPath) == 1 {
265 fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+
266 module.publicApiStubsImplPath.Strings()[0]+
267 ":"+path.Join("apistubs", owner, "public",
268 module.BaseModuleName()+".jar")+")")
269 }
270 if len(module.systemApiStubsPath) == 1 {
271 fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+
272 module.systemApiStubsImplPath.Strings()[0]+
273 ":"+path.Join("apistubs", owner, "system",
274 module.BaseModuleName()+".jar")+")")
275 }
276 if len(module.testApiStubsPath) == 1 {
277 fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+
278 module.testApiStubsImplPath.Strings()[0]+
279 ":"+path.Join("apistubs", owner, "test",
280 module.BaseModuleName()+".jar")+")")
281 }
282 if module.publicApiFilePath != nil {
283 fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+
284 module.publicApiFilePath.String()+
285 ":"+path.Join("apistubs", owner, "public", "api",
286 module.BaseModuleName()+".txt")+")")
287 }
288 if module.systemApiFilePath != nil {
289 fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+
290 module.systemApiFilePath.String()+
291 ":"+path.Join("apistubs", owner, "system", "api",
292 module.BaseModuleName()+".txt")+")")
293 }
294 if module.testApiFilePath != nil {
295 fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+
296 module.testApiFilePath.String()+
297 ":"+path.Join("apistubs", owner, "test", "api",
298 module.BaseModuleName()+".txt")+")")
Sundong Ahn80a87b32019-05-13 15:02:50 +0900299 }
Sundong Ahn4fd04bb2018-08-31 18:01:37 +0900300 }
Jaewoong Jungb0c127c2019-08-29 14:56:03 -0700301 },
Jiyong Park82484c02018-04-23 21:41:26 +0900302 }
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900303 return entriesList
Jiyong Park82484c02018-04-23 21:41:26 +0900304}
305
Jiyong Parkc678ad32018-04-10 13:07:10 +0900306// Module name of the stubs library
Inseob Kimc0907f12019-02-08 21:00:45 +0900307func (module *SdkLibrary) stubsName(apiScope apiScope) string {
Jiyong Parkc678ad32018-04-10 13:07:10 +0900308 stubsName := module.BaseModuleName() + sdkStubsLibrarySuffix
Jiyong Parkdf130542018-04-27 16:29:21 +0900309 switch apiScope {
310 case apiScopeSystem:
Jiyong Parkc678ad32018-04-10 13:07:10 +0900311 stubsName = stubsName + sdkSystemApiSuffix
Jiyong Parkdf130542018-04-27 16:29:21 +0900312 case apiScopeTest:
313 stubsName = stubsName + sdkTestApiSuffix
Jiyong Parkc678ad32018-04-10 13:07:10 +0900314 }
315 return stubsName
316}
317
318// Module name of the docs
Inseob Kimc0907f12019-02-08 21:00:45 +0900319func (module *SdkLibrary) docsName(apiScope apiScope) string {
Jiyong Parkc678ad32018-04-10 13:07:10 +0900320 docsName := module.BaseModuleName() + sdkDocsSuffix
Jiyong Parkdf130542018-04-27 16:29:21 +0900321 switch apiScope {
322 case apiScopeSystem:
Jiyong Parkc678ad32018-04-10 13:07:10 +0900323 docsName = docsName + sdkSystemApiSuffix
Jiyong Parkdf130542018-04-27 16:29:21 +0900324 case apiScopeTest:
325 docsName = docsName + sdkTestApiSuffix
Jiyong Parkc678ad32018-04-10 13:07:10 +0900326 }
327 return docsName
328}
329
330// Module name of the runtime implementation library
Inseob Kimc0907f12019-02-08 21:00:45 +0900331func (module *SdkLibrary) implName() string {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900332 return module.BaseModuleName()
Jiyong Parkc678ad32018-04-10 13:07:10 +0900333}
334
335// File path to the runtime implementation library
Inseob Kimc0907f12019-02-08 21:00:45 +0900336func (module *SdkLibrary) implPath() string {
Jooyung Han58f26ab2019-12-18 15:34:32 +0900337 if apexName := module.ApexName(); apexName != "" {
338 // TODO(b/146468504): ApexName() is only a soong module name, not apex name.
339 // In most cases, this works fine. But when apex_name is set or override_apex is used
340 // this can be wrong.
341 return fmt.Sprintf("/apex/%s/javalib/%s.jar", apexName, module.implName())
342 }
Jiyong Parkc678ad32018-04-10 13:07:10 +0900343 partition := "system"
344 if module.SocSpecific() {
345 partition = "vendor"
346 } else if module.DeviceSpecific() {
347 partition = "odm"
348 } else if module.ProductSpecific() {
349 partition = "product"
Sundong Ahn0d7dff42019-12-04 12:53:44 +0900350 } else if module.SystemExtSpecific() {
351 partition = "system_ext"
Jiyong Parkc678ad32018-04-10 13:07:10 +0900352 }
353 return "/" + partition + "/framework/" + module.implName() + ".jar"
354}
355
356// Module name of the XML file for the lib
Inseob Kimc0907f12019-02-08 21:00:45 +0900357func (module *SdkLibrary) xmlFileName() string {
Jiyong Parkc678ad32018-04-10 13:07:10 +0900358 return module.BaseModuleName() + sdkXmlFileSuffix
359}
360
361// SDK version that the stubs library is built against. Note that this is always
362// *current. Older stubs library built with a numberd SDK version is created from
363// the prebuilt jar.
Paul Duffin12ceb462019-12-24 20:31:31 +0000364func (module *SdkLibrary) sdkVersionForScope(apiScope apiScope) string {
Jiyong Parkdf130542018-04-27 16:29:21 +0900365 switch apiScope {
366 case apiScopePublic:
367 return "current"
368 case apiScopeSystem:
Jiyong Parkc678ad32018-04-10 13:07:10 +0900369 return "system_current"
Jiyong Parkdf130542018-04-27 16:29:21 +0900370 case apiScopeTest:
371 return "test_current"
372 default:
Jiyong Parkc678ad32018-04-10 13:07:10 +0900373 return "current"
374 }
375}
376
Paul Duffin12ceb462019-12-24 20:31:31 +0000377// Get the sdk version for use when compiling the stubs library.
378func (module *SdkLibrary) sdkVersionForStubsLibrary(mctx android.BaseModuleContext, apiScope apiScope) string {
379 sdkDep := decodeSdkDep(mctx, sdkContext(&module.Library))
380 if sdkDep.hasStandardLibs() {
381 // If building against a standard sdk then use the sdk version appropriate for the scope.
382 return module.sdkVersionForScope(apiScope)
383 } else {
384 // Otherwise, use no system module.
385 return "none"
386 }
387}
388
Jiyong Parkc678ad32018-04-10 13:07:10 +0900389// $(INTERNAL_PLATFORM_<apiTagName>_API_FILE) points to the generated
390// api file for the current source
391// TODO: remove this when apicheck is done in soong
Inseob Kimc0907f12019-02-08 21:00:45 +0900392func (module *SdkLibrary) apiTagName(apiScope apiScope) string {
Jiyong Parkc678ad32018-04-10 13:07:10 +0900393 apiTagName := strings.Replace(strings.ToUpper(module.BaseModuleName()), ".", "_", -1)
Jiyong Parkdf130542018-04-27 16:29:21 +0900394 switch apiScope {
395 case apiScopeSystem:
Jiyong Parkc678ad32018-04-10 13:07:10 +0900396 apiTagName = apiTagName + "_SYSTEM"
Jiyong Parkdf130542018-04-27 16:29:21 +0900397 case apiScopeTest:
398 apiTagName = apiTagName + "_TEST"
Jiyong Parkc678ad32018-04-10 13:07:10 +0900399 }
400 return apiTagName
401}
402
Inseob Kimc0907f12019-02-08 21:00:45 +0900403func (module *SdkLibrary) latestApiFilegroupName(apiScope apiScope) string {
Jiyong Park58c518b2018-05-12 22:29:12 +0900404 name := ":" + module.BaseModuleName() + ".api."
Jiyong Parkdf130542018-04-27 16:29:21 +0900405 switch apiScope {
Jiyong Park58c518b2018-05-12 22:29:12 +0900406 case apiScopePublic:
407 name = name + "public"
Jiyong Parkdf130542018-04-27 16:29:21 +0900408 case apiScopeSystem:
Jiyong Park58c518b2018-05-12 22:29:12 +0900409 name = name + "system"
Jiyong Parkdf130542018-04-27 16:29:21 +0900410 case apiScopeTest:
Jiyong Park58c518b2018-05-12 22:29:12 +0900411 name = name + "test"
Jiyong Parkc678ad32018-04-10 13:07:10 +0900412 }
Jiyong Park58c518b2018-05-12 22:29:12 +0900413 name = name + ".latest"
414 return name
415}
Jiyong Parkc678ad32018-04-10 13:07:10 +0900416
Inseob Kimc0907f12019-02-08 21:00:45 +0900417func (module *SdkLibrary) latestRemovedApiFilegroupName(apiScope apiScope) string {
Jiyong Park58c518b2018-05-12 22:29:12 +0900418 name := ":" + module.BaseModuleName() + "-removed.api."
419 switch apiScope {
420 case apiScopePublic:
421 name = name + "public"
422 case apiScopeSystem:
423 name = name + "system"
424 case apiScopeTest:
425 name = name + "test"
426 }
427 name = name + ".latest"
428 return name
Jiyong Parkc678ad32018-04-10 13:07:10 +0900429}
430
431// Creates a static java library that has API stubs
Colin Crossf8b860a2019-04-16 14:43:28 -0700432func (module *SdkLibrary) createStubsLibrary(mctx android.LoadHookContext, apiScope apiScope) {
Jiyong Parkc678ad32018-04-10 13:07:10 +0900433 props := struct {
Sundong Ahn0d7dff42019-12-04 12:53:44 +0900434 Name *string
435 Srcs []string
436 Sdk_version *string
Paul Duffin12ceb462019-12-24 20:31:31 +0000437 System_modules *string
Sundong Ahn0d7dff42019-12-04 12:53:44 +0900438 Libs []string
439 Soc_specific *bool
440 Device_specific *bool
441 Product_specific *bool
442 System_ext_specific *bool
443 Compile_dex *bool
Sundong Ahn0d7dff42019-12-04 12:53:44 +0900444 Java_version *string
445 Product_variables struct {
Jiyong Parkc678ad32018-04-10 13:07:10 +0900446 Unbundled_build struct {
447 Enabled *bool
448 }
Jiyong Park82484c02018-04-23 21:41:26 +0900449 Pdk struct {
450 Enabled *bool
451 }
Jiyong Parkc678ad32018-04-10 13:07:10 +0900452 }
Sundong Ahn054b19a2018-10-19 13:46:09 +0900453 Openjdk9 struct {
454 Srcs []string
455 Javacflags []string
456 }
Jiyong Parkc678ad32018-04-10 13:07:10 +0900457 }{}
458
Jiyong Parkdf130542018-04-27 16:29:21 +0900459 props.Name = proptools.StringPtr(module.stubsName(apiScope))
Jiyong Parkc678ad32018-04-10 13:07:10 +0900460 // sources are generated from the droiddoc
Jiyong Parkdf130542018-04-27 16:29:21 +0900461 props.Srcs = []string{":" + module.docsName(apiScope)}
Paul Duffin12ceb462019-12-24 20:31:31 +0000462 sdkVersion := module.sdkVersionForStubsLibrary(mctx, apiScope)
Paul Duffin52d398a2019-06-11 12:31:14 +0100463 props.Sdk_version = proptools.StringPtr(sdkVersion)
Paul Duffin12ceb462019-12-24 20:31:31 +0000464 props.System_modules = module.Library.Module.deviceProperties.System_modules
Sundong Ahn054b19a2018-10-19 13:46:09 +0900465 props.Libs = module.sdkLibraryProperties.Stub_only_libs
Jiyong Parkc678ad32018-04-10 13:07:10 +0900466 // Unbundled apps will use the prebult one from /prebuilts/sdk
Colin Cross10932872019-04-18 14:27:12 -0700467 if mctx.Config().UnbundledBuildUsePrebuiltSdks() {
Colin Cross2c77ceb2019-01-21 11:56:21 -0800468 props.Product_variables.Unbundled_build.Enabled = proptools.BoolPtr(false)
469 }
Jiyong Park82484c02018-04-23 21:41:26 +0900470 props.Product_variables.Pdk.Enabled = proptools.BoolPtr(false)
Sundong Ahn054b19a2018-10-19 13:46:09 +0900471 props.Openjdk9.Srcs = module.Library.Module.properties.Openjdk9.Srcs
472 props.Openjdk9.Javacflags = module.Library.Module.properties.Openjdk9.Javacflags
473 props.Java_version = module.Library.Module.properties.Java_version
474 if module.Library.Module.deviceProperties.Compile_dex != nil {
475 props.Compile_dex = module.Library.Module.deviceProperties.Compile_dex
Sundong Ahndd567f92018-07-31 17:19:11 +0900476 }
Jiyong Parkc678ad32018-04-10 13:07:10 +0900477
478 if module.SocSpecific() {
479 props.Soc_specific = proptools.BoolPtr(true)
480 } else if module.DeviceSpecific() {
481 props.Device_specific = proptools.BoolPtr(true)
482 } else if module.ProductSpecific() {
483 props.Product_specific = proptools.BoolPtr(true)
Sundong Ahn0d7dff42019-12-04 12:53:44 +0900484 } else if module.SystemExtSpecific() {
485 props.System_ext_specific = proptools.BoolPtr(true)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900486 }
487
Colin Cross84dfc3d2019-09-25 11:33:01 -0700488 mctx.CreateModule(LibraryFactory, &props)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900489}
490
491// Creates a droiddoc module that creates stubs source files from the given full source
492// files
Paul Duffinc4cea762019-12-30 17:32:47 +0000493func (module *SdkLibrary) createStubsSources(mctx android.LoadHookContext, apiScope apiScope) {
Jiyong Parkc678ad32018-04-10 13:07:10 +0900494 props := struct {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900495 Name *string
496 Srcs []string
497 Installable *bool
Paul Duffin52d398a2019-06-11 12:31:14 +0100498 Sdk_version *string
Paul Duffin12ceb462019-12-24 20:31:31 +0000499 System_modules *string
Sundong Ahn054b19a2018-10-19 13:46:09 +0900500 Libs []string
Paul Duffin11512472019-02-11 15:55:17 +0000501 Arg_files []string
Sundong Ahn054b19a2018-10-19 13:46:09 +0900502 Args *string
503 Api_tag_name *string
504 Api_filename *string
505 Removed_api_filename *string
Sundong Ahn054b19a2018-10-19 13:46:09 +0900506 Java_version *string
507 Merge_annotations_dirs []string
508 Merge_inclusion_annotations_dirs []string
509 Check_api struct {
Inseob Kim38449af2019-02-28 14:24:05 +0900510 Current ApiToCheck
511 Last_released ApiToCheck
512 Ignore_missing_latest_api *bool
Jiyong Park58c518b2018-05-12 22:29:12 +0900513 }
Sundong Ahn1b92c822018-05-29 11:35:17 +0900514 Aidl struct {
515 Include_dirs []string
516 Local_include_dirs []string
517 }
Jiyong Parkc678ad32018-04-10 13:07:10 +0900518 }{}
519
Paul Duffin250e6192019-06-07 10:44:37 +0100520 sdkDep := decodeSdkDep(mctx, sdkContext(&module.Library))
Paul Duffin12ceb462019-12-24 20:31:31 +0000521 // Use the platform API if standard libraries were requested, otherwise use
522 // no default libraries.
Paul Duffin52d398a2019-06-11 12:31:14 +0100523 sdkVersion := ""
524 if !sdkDep.hasStandardLibs() {
525 sdkVersion = "none"
526 }
Paul Duffin250e6192019-06-07 10:44:37 +0100527
Jiyong Parkdf130542018-04-27 16:29:21 +0900528 props.Name = proptools.StringPtr(module.docsName(apiScope))
Sundong Ahn054b19a2018-10-19 13:46:09 +0900529 props.Srcs = append(props.Srcs, module.Library.Module.properties.Srcs...)
Paul Duffin52d398a2019-06-11 12:31:14 +0100530 props.Sdk_version = proptools.StringPtr(sdkVersion)
Paul Duffin12ceb462019-12-24 20:31:31 +0000531 props.System_modules = module.Library.Module.deviceProperties.System_modules
Jiyong Parkc678ad32018-04-10 13:07:10 +0900532 props.Installable = proptools.BoolPtr(false)
Sundong Ahne6f0b052018-06-05 16:46:14 +0900533 // A droiddoc module has only one Libs property and doesn't distinguish between
534 // shared libs and static libs. So we need to add both of these libs to Libs property.
Sundong Ahn054b19a2018-10-19 13:46:09 +0900535 props.Libs = module.Library.Module.properties.Libs
536 props.Libs = append(props.Libs, module.Library.Module.properties.Static_libs...)
537 props.Aidl.Include_dirs = module.Library.Module.deviceProperties.Aidl.Include_dirs
538 props.Aidl.Local_include_dirs = module.Library.Module.deviceProperties.Aidl.Local_include_dirs
Sundong Ahn054b19a2018-10-19 13:46:09 +0900539 props.Java_version = module.Library.Module.properties.Java_version
Jiyong Parkc678ad32018-04-10 13:07:10 +0900540
Sundong Ahn054b19a2018-10-19 13:46:09 +0900541 props.Merge_annotations_dirs = module.sdkLibraryProperties.Merge_annotations_dirs
542 props.Merge_inclusion_annotations_dirs = module.sdkLibraryProperties.Merge_inclusion_annotations_dirs
543
Paul Duffin235ffff2019-12-24 10:41:30 +0000544 droiddocArgs := []string{}
545 if len(module.sdkLibraryProperties.Api_packages) != 0 {
546 droiddocArgs = append(droiddocArgs, "--stub-packages "+strings.Join(module.sdkLibraryProperties.Api_packages, ":"))
547 }
548 if len(module.sdkLibraryProperties.Hidden_api_packages) != 0 {
549 droiddocArgs = append(droiddocArgs,
550 android.JoinWithPrefix(module.sdkLibraryProperties.Hidden_api_packages, " --hide-package "))
551 }
552 droiddocArgs = append(droiddocArgs, module.sdkLibraryProperties.Droiddoc_options...)
553 disabledWarnings := []string{
554 "MissingPermission",
555 "BroadcastBehavior",
556 "HiddenSuperclass",
557 "DeprecationMismatch",
558 "UnavailableSymbol",
559 "SdkConstant",
560 "HiddenTypeParameter",
561 "Todo",
562 "Typo",
563 }
564 droiddocArgs = append(droiddocArgs, android.JoinWithPrefix(disabledWarnings, "--hide "))
Sundong Ahnfb2721f2018-09-17 13:23:09 +0900565
Jiyong Parkdf130542018-04-27 16:29:21 +0900566 switch apiScope {
567 case apiScopeSystem:
Paul Duffin235ffff2019-12-24 10:41:30 +0000568 droiddocArgs = append(droiddocArgs, "-showAnnotation android.annotation.SystemApi")
Jiyong Parkdf130542018-04-27 16:29:21 +0900569 case apiScopeTest:
Paul Duffin235ffff2019-12-24 10:41:30 +0000570 droiddocArgs = append(droiddocArgs, " -showAnnotation android.annotation.TestApi")
Jiyong Parkc678ad32018-04-10 13:07:10 +0900571 }
Paul Duffin11512472019-02-11 15:55:17 +0000572 props.Arg_files = module.sdkLibraryProperties.Droiddoc_option_files
Paul Duffin235ffff2019-12-24 10:41:30 +0000573 props.Args = proptools.StringPtr(strings.Join(droiddocArgs, " "))
Jiyong Parkc678ad32018-04-10 13:07:10 +0900574
575 // List of APIs identified from the provided source files are created. They are later
576 // compared against to the not-yet-released (a.k.a current) list of APIs and to the
577 // last-released (a.k.a numbered) list of API.
Jiyong Parkc678ad32018-04-10 13:07:10 +0900578 currentApiFileName := "current.txt"
579 removedApiFileName := "removed.txt"
Jiyong Parkdf130542018-04-27 16:29:21 +0900580 switch apiScope {
581 case apiScopeSystem:
Jiyong Parkc678ad32018-04-10 13:07:10 +0900582 currentApiFileName = "system-" + currentApiFileName
583 removedApiFileName = "system-" + removedApiFileName
Jiyong Parkdf130542018-04-27 16:29:21 +0900584 case apiScopeTest:
585 currentApiFileName = "test-" + currentApiFileName
586 removedApiFileName = "test-" + removedApiFileName
Jiyong Parkc678ad32018-04-10 13:07:10 +0900587 }
588 currentApiFileName = path.Join("api", currentApiFileName)
589 removedApiFileName = path.Join("api", removedApiFileName)
Jiyong Park58c518b2018-05-12 22:29:12 +0900590 // TODO(jiyong): remove these three props
Jiyong Parkdf130542018-04-27 16:29:21 +0900591 props.Api_tag_name = proptools.StringPtr(module.apiTagName(apiScope))
Jiyong Parkc678ad32018-04-10 13:07:10 +0900592 props.Api_filename = proptools.StringPtr(currentApiFileName)
593 props.Removed_api_filename = proptools.StringPtr(removedApiFileName)
594
Jiyong Park58c518b2018-05-12 22:29:12 +0900595 // check against the not-yet-release API
596 props.Check_api.Current.Api_file = proptools.StringPtr(currentApiFileName)
597 props.Check_api.Current.Removed_api_file = proptools.StringPtr(removedApiFileName)
Jiyong Park58c518b2018-05-12 22:29:12 +0900598
599 // check against the latest released API
600 props.Check_api.Last_released.Api_file = proptools.StringPtr(
601 module.latestApiFilegroupName(apiScope))
602 props.Check_api.Last_released.Removed_api_file = proptools.StringPtr(
603 module.latestRemovedApiFilegroupName(apiScope))
Inseob Kim38449af2019-02-28 14:24:05 +0900604 props.Check_api.Ignore_missing_latest_api = proptools.BoolPtr(true)
Jiyong Park58c518b2018-05-12 22:29:12 +0900605
Colin Cross84dfc3d2019-09-25 11:33:01 -0700606 mctx.CreateModule(DroidstubsFactory, &props)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900607}
608
Jiyong Parkc678ad32018-04-10 13:07:10 +0900609// Creates the xml file that publicizes the runtime library
Colin Crossf8b860a2019-04-16 14:43:28 -0700610func (module *SdkLibrary) createXmlFile(mctx android.LoadHookContext) {
Jiyong Parkc678ad32018-04-10 13:07:10 +0900611 // creates a prebuilt_etc module to actually place the xml file under
612 // <partition>/etc/permissions
613 etcProps := struct {
Sundong Ahn0d7dff42019-12-04 12:53:44 +0900614 Name *string
615 Src *string
616 Sub_dir *string
617 Soc_specific *bool
618 Device_specific *bool
619 Product_specific *bool
620 System_ext_specific *bool
Jiyong Parkc678ad32018-04-10 13:07:10 +0900621 }{}
622 etcProps.Name = proptools.StringPtr(module.xmlFileName())
Jooyung Han624058e2019-12-24 18:38:06 +0900623 etcProps.Src = proptools.StringPtr(":" + module.BaseModuleName() + "{.xml}")
Jiyong Parkc678ad32018-04-10 13:07:10 +0900624 etcProps.Sub_dir = proptools.StringPtr("permissions")
625 if module.SocSpecific() {
626 etcProps.Soc_specific = proptools.BoolPtr(true)
627 } else if module.DeviceSpecific() {
628 etcProps.Device_specific = proptools.BoolPtr(true)
629 } else if module.ProductSpecific() {
630 etcProps.Product_specific = proptools.BoolPtr(true)
Sundong Ahn0d7dff42019-12-04 12:53:44 +0900631 } else if module.SystemExtSpecific() {
632 etcProps.System_ext_specific = proptools.BoolPtr(true)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900633 }
Colin Cross84dfc3d2019-09-25 11:33:01 -0700634 mctx.CreateModule(android.PrebuiltEtcFactory, &etcProps)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900635}
636
Colin Cross0ea8ba82019-06-06 14:33:29 -0700637func (module *SdkLibrary) PrebuiltJars(ctx android.BaseModuleContext, sdkVersion string) android.Paths {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900638 var api, v string
Paul Duffin52d398a2019-06-11 12:31:14 +0100639 if sdkVersion == "" || sdkVersion == "none" {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900640 api = "system"
641 v = "current"
642 } else if strings.Contains(sdkVersion, "_") {
643 t := strings.Split(sdkVersion, "_")
644 api = t[0]
645 v = t[1]
Jiyong Parkc678ad32018-04-10 13:07:10 +0900646 } else {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900647 api = "public"
648 v = sdkVersion
649 }
650 dir := filepath.Join("prebuilts", "sdk", v, api)
651 jar := filepath.Join(dir, module.BaseModuleName()+".jar")
652 jarPath := android.ExistentPathForSource(ctx, jar)
Sundong Ahnae418ac2019-02-28 15:01:28 +0900653 if !jarPath.Valid() {
654 ctx.PropertyErrorf("sdk_library", "invalid sdk version %q, %q does not exist", v, jar)
655 return nil
656 }
Sundong Ahn054b19a2018-10-19 13:46:09 +0900657 return android.Paths{jarPath.Path()}
658}
659
660// to satisfy SdkLibraryDependency interface
Colin Cross0ea8ba82019-06-06 14:33:29 -0700661func (module *SdkLibrary) SdkHeaderJars(ctx android.BaseModuleContext, sdkVersion string) android.Paths {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900662 // This module is just a wrapper for the stubs.
Colin Cross10932872019-04-18 14:27:12 -0700663 if ctx.Config().UnbundledBuildUsePrebuiltSdks() {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900664 return module.PrebuiltJars(ctx, sdkVersion)
665 } else {
666 if strings.HasPrefix(sdkVersion, "system_") {
667 return module.systemApiStubsPath
668 } else if sdkVersion == "" {
669 return module.Library.HeaderJars()
670 } else {
671 return module.publicApiStubsPath
672 }
Jiyong Parkc678ad32018-04-10 13:07:10 +0900673 }
674}
675
Sundong Ahn241cd372018-07-13 16:16:44 +0900676// to satisfy SdkLibraryDependency interface
Colin Cross0ea8ba82019-06-06 14:33:29 -0700677func (module *SdkLibrary) SdkImplementationJars(ctx android.BaseModuleContext, sdkVersion string) android.Paths {
Sundong Ahn241cd372018-07-13 16:16:44 +0900678 // This module is just a wrapper for the stubs.
Colin Cross10932872019-04-18 14:27:12 -0700679 if ctx.Config().UnbundledBuildUsePrebuiltSdks() {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900680 return module.PrebuiltJars(ctx, sdkVersion)
Sundong Ahn241cd372018-07-13 16:16:44 +0900681 } else {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900682 if strings.HasPrefix(sdkVersion, "system_") {
683 return module.systemApiStubsImplPath
684 } else if sdkVersion == "" {
685 return module.Library.ImplementationJars()
686 } else {
687 return module.publicApiStubsImplPath
688 }
Sundong Ahn241cd372018-07-13 16:16:44 +0900689 }
690}
691
Sundong Ahn80a87b32019-05-13 15:02:50 +0900692func (module *SdkLibrary) SetNoDist() {
693 module.sdkLibraryProperties.No_dist = proptools.BoolPtr(true)
694}
695
Colin Cross571cccf2019-02-04 11:22:08 -0800696var javaSdkLibrariesKey = android.NewOnceKey("javaSdkLibraries")
697
Jiyong Park82484c02018-04-23 21:41:26 +0900698func javaSdkLibraries(config android.Config) *[]string {
Colin Cross571cccf2019-02-04 11:22:08 -0800699 return config.Once(javaSdkLibrariesKey, func() interface{} {
Jiyong Park82484c02018-04-23 21:41:26 +0900700 return &[]string{}
701 }).(*[]string)
702}
703
Jiyong Parkc678ad32018-04-10 13:07:10 +0900704// For a java_sdk_library module, create internal modules for stubs, docs,
705// runtime libs and xml file. If requested, the stubs and docs are created twice
706// once for public API level and once for system API level
Colin Crossf8b860a2019-04-16 14:43:28 -0700707func (module *SdkLibrary) CreateInternalModules(mctx android.LoadHookContext) {
Inseob Kim6e93ac92019-03-21 17:43:49 +0900708 if len(module.Library.Module.properties.Srcs) == 0 {
Inseob Kimc0907f12019-02-08 21:00:45 +0900709 mctx.PropertyErrorf("srcs", "java_sdk_library must specify srcs")
Jooyung Han58f26ab2019-12-18 15:34:32 +0900710 return
Inseob Kimc0907f12019-02-08 21:00:45 +0900711 }
712
Paul Duffin37e0b772019-12-30 17:20:10 +0000713 // If this builds against standard libraries (i.e. is not part of the core libraries)
714 // then assume it provides both system and test apis. Otherwise, assume it does not and
715 // also assume it does not contribute to the dist build.
716 sdkDep := decodeSdkDep(mctx, sdkContext(&module.Library))
717 hasSystemAndTestApis := sdkDep.hasStandardLibs()
718 module.sdkLibraryProperties.Has_system_and_test_apis = hasSystemAndTestApis
719 module.sdkLibraryProperties.No_dist = proptools.BoolPtr(!hasSystemAndTestApis)
720
721 scopes := []string{""}
722 if hasSystemAndTestApis {
723 scopes = append(scopes, "system-", "test-")
724 }
725
Inseob Kim8098faa2019-03-18 10:19:51 +0900726 missing_current_api := false
727
Paul Duffin37e0b772019-12-30 17:20:10 +0000728 for _, scope := range scopes {
Inseob Kim8098faa2019-03-18 10:19:51 +0900729 for _, api := range []string{"current.txt", "removed.txt"} {
730 path := path.Join(mctx.ModuleDir(), "api", scope+api)
731 p := android.ExistentPathForSource(mctx, path)
732 if !p.Valid() {
733 mctx.ModuleErrorf("Current api file %#v doesn't exist", path)
734 missing_current_api = true
735 }
736 }
737 }
738
739 if missing_current_api {
740 script := "build/soong/scripts/gen-java-current-api-files.sh"
741 p := android.ExistentPathForSource(mctx, script)
742
743 if !p.Valid() {
744 panic(fmt.Sprintf("script file %s doesn't exist", script))
745 }
746
747 mctx.ModuleErrorf("One or more current api files are missing. "+
748 "You can update them by:\n"+
Paul Duffin37e0b772019-12-30 17:20:10 +0000749 "%s %q %s && m update-api",
750 script, mctx.ModuleDir(), strings.Join(scopes, " "))
Inseob Kim8098faa2019-03-18 10:19:51 +0900751 return
752 }
753
Inseob Kimc0907f12019-02-08 21:00:45 +0900754 // for public API stubs
755 module.createStubsLibrary(mctx, apiScopePublic)
Paul Duffinc4cea762019-12-30 17:32:47 +0000756 module.createStubsSources(mctx, apiScopePublic)
Inseob Kimc0907f12019-02-08 21:00:45 +0900757
Paul Duffin37e0b772019-12-30 17:20:10 +0000758 if hasSystemAndTestApis {
Inseob Kimc0907f12019-02-08 21:00:45 +0900759 // for system API stubs
760 module.createStubsLibrary(mctx, apiScopeSystem)
Paul Duffinc4cea762019-12-30 17:32:47 +0000761 module.createStubsSources(mctx, apiScopeSystem)
Inseob Kimc0907f12019-02-08 21:00:45 +0900762
763 // for test API stubs
764 module.createStubsLibrary(mctx, apiScopeTest)
Paul Duffinc4cea762019-12-30 17:32:47 +0000765 module.createStubsSources(mctx, apiScopeTest)
Inseob Kimc0907f12019-02-08 21:00:45 +0900766
767 // for runtime
768 module.createXmlFile(mctx)
769 }
770
771 // record java_sdk_library modules so that they are exported to make
772 javaSdkLibraries := javaSdkLibraries(mctx.Config())
773 javaSdkLibrariesLock.Lock()
774 defer javaSdkLibrariesLock.Unlock()
775 *javaSdkLibraries = append(*javaSdkLibraries, module.BaseModuleName())
776}
777
778func (module *SdkLibrary) InitSdkLibraryProperties() {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900779 module.AddProperties(
780 &module.sdkLibraryProperties,
781 &module.Library.Module.properties,
782 &module.Library.Module.dexpreoptProperties,
783 &module.Library.Module.deviceProperties,
784 &module.Library.Module.protoProperties,
785 )
786
787 module.Library.Module.properties.Installable = proptools.BoolPtr(true)
788 module.Library.Module.deviceProperties.IsSDKLibrary = true
Inseob Kimc0907f12019-02-08 21:00:45 +0900789}
Sundong Ahn054b19a2018-10-19 13:46:09 +0900790
Jaewoong Jung4f158ee2019-07-11 10:05:35 -0700791// java_sdk_library is a special Java library that provides optional platform APIs to apps.
792// In practice, it can be viewed as a combination of several modules: 1) stubs library that clients
793// are linked against to, 2) droiddoc module that internally generates API stubs source files,
794// 3) the real runtime shared library that implements the APIs, and 4) XML file for adding
795// the runtime lib to the classpath at runtime if requested via <uses-library>.
Inseob Kimc0907f12019-02-08 21:00:45 +0900796func SdkLibraryFactory() android.Module {
797 module := &SdkLibrary{}
798 module.InitSdkLibraryProperties()
Jooyung Han58f26ab2019-12-18 15:34:32 +0900799 android.InitApexModule(module)
Sundong Ahn054b19a2018-10-19 13:46:09 +0900800 InitJavaModule(module, android.HostAndDeviceSupported)
Colin Crossf8b860a2019-04-16 14:43:28 -0700801 android.AddLoadHook(module, func(ctx android.LoadHookContext) { module.CreateInternalModules(ctx) })
Jiyong Parkc678ad32018-04-10 13:07:10 +0900802 return module
803}
Colin Cross79c7c262019-04-17 11:11:46 -0700804
805//
806// SDK library prebuilts
807//
808
809type sdkLibraryImportProperties struct {
810 Jars []string `android:"path"`
811
812 Sdk_version *string
813
814 Installable *bool
815
816 // List of shared java libs that this module has dependencies to
817 Libs []string
818
819 // List of files to remove from the jar file(s)
820 Exclude_files []string
821
822 // List of directories to remove from the jar file(s)
823 Exclude_dirs []string
824}
825
826type sdkLibraryImport struct {
827 android.ModuleBase
828 android.DefaultableModuleBase
829 prebuilt android.Prebuilt
830
831 properties sdkLibraryImportProperties
832
833 stubsPath android.Paths
834}
835
836var _ SdkLibraryDependency = (*sdkLibraryImport)(nil)
837
Jaewoong Jung4f158ee2019-07-11 10:05:35 -0700838// java_sdk_library_import imports a prebuilt java_sdk_library.
Colin Cross79c7c262019-04-17 11:11:46 -0700839func sdkLibraryImportFactory() android.Module {
840 module := &sdkLibraryImport{}
841
842 module.AddProperties(&module.properties)
843
844 android.InitPrebuiltModule(module, &module.properties.Jars)
845 InitJavaModule(module, android.HostAndDeviceSupported)
846
847 android.AddLoadHook(module, func(mctx android.LoadHookContext) { module.createInternalModules(mctx) })
848 return module
849}
850
851func (module *sdkLibraryImport) Prebuilt() *android.Prebuilt {
852 return &module.prebuilt
853}
854
855func (module *sdkLibraryImport) Name() string {
856 return module.prebuilt.Name(module.ModuleBase.Name())
857}
858
859func (module *sdkLibraryImport) createInternalModules(mctx android.LoadHookContext) {
860 // Creates a java import for the jar with ".stubs" suffix
861 props := struct {
Sundong Ahn0d7dff42019-12-04 12:53:44 +0900862 Name *string
863 Soc_specific *bool
864 Device_specific *bool
865 Product_specific *bool
866 System_ext_specific *bool
Colin Cross79c7c262019-04-17 11:11:46 -0700867 }{}
868
869 props.Name = proptools.StringPtr(module.BaseModuleName() + sdkStubsLibrarySuffix)
870
871 if module.SocSpecific() {
872 props.Soc_specific = proptools.BoolPtr(true)
873 } else if module.DeviceSpecific() {
874 props.Device_specific = proptools.BoolPtr(true)
875 } else if module.ProductSpecific() {
876 props.Product_specific = proptools.BoolPtr(true)
Sundong Ahn0d7dff42019-12-04 12:53:44 +0900877 } else if module.SystemExtSpecific() {
878 props.System_ext_specific = proptools.BoolPtr(true)
Colin Cross79c7c262019-04-17 11:11:46 -0700879 }
880
Colin Cross84dfc3d2019-09-25 11:33:01 -0700881 mctx.CreateModule(ImportFactory, &props, &module.properties)
Colin Cross79c7c262019-04-17 11:11:46 -0700882
883 javaSdkLibraries := javaSdkLibraries(mctx.Config())
884 javaSdkLibrariesLock.Lock()
885 defer javaSdkLibrariesLock.Unlock()
886 *javaSdkLibraries = append(*javaSdkLibraries, module.BaseModuleName())
887}
888
889func (module *sdkLibraryImport) DepsMutator(ctx android.BottomUpMutatorContext) {
890 // Add dependencies to the prebuilt stubs library
891 ctx.AddVariationDependencies(nil, publicApiStubsTag, module.BaseModuleName()+sdkStubsLibrarySuffix)
892}
893
894func (module *sdkLibraryImport) GenerateAndroidBuildActions(ctx android.ModuleContext) {
895 // Record the paths to the prebuilt stubs library.
896 ctx.VisitDirectDeps(func(to android.Module) {
897 tag := ctx.OtherModuleDependencyTag(to)
898
899 switch tag {
900 case publicApiStubsTag:
901 module.stubsPath = to.(Dependency).HeaderJars()
902 }
903 })
904}
905
906// to satisfy SdkLibraryDependency interface
Colin Cross0ea8ba82019-06-06 14:33:29 -0700907func (module *sdkLibraryImport) SdkHeaderJars(ctx android.BaseModuleContext, sdkVersion string) android.Paths {
Colin Cross79c7c262019-04-17 11:11:46 -0700908 // This module is just a wrapper for the prebuilt stubs.
909 return module.stubsPath
910}
911
912// to satisfy SdkLibraryDependency interface
Colin Cross0ea8ba82019-06-06 14:33:29 -0700913func (module *sdkLibraryImport) SdkImplementationJars(ctx android.BaseModuleContext, sdkVersion string) android.Paths {
Colin Cross79c7c262019-04-17 11:11:46 -0700914 // This module is just a wrapper for the stubs.
915 return module.stubsPath
916}