blob: a26474f0274d525f4409db56850d8dc21f31c8b7 [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
27 "github.com/google/blueprint"
28 "github.com/google/blueprint/proptools"
29)
30
Jooyung Han58f26ab2019-12-18 15:34:32 +090031const (
Jiyong Parkc678ad32018-04-10 13:07:10 +090032 sdkStubsLibrarySuffix = ".stubs"
33 sdkSystemApiSuffix = ".system"
Jiyong Parkdf130542018-04-27 16:29:21 +090034 sdkTestApiSuffix = ".test"
Jiyong Parkc678ad32018-04-10 13:07:10 +090035 sdkDocsSuffix = ".docs"
Jiyong Parkc678ad32018-04-10 13:07:10 +090036 sdkXmlFileSuffix = ".xml"
Jooyung Han624058e2019-12-24 18:38:06 +090037 permissionsTemplate = `<?xml version="1.0" encoding="utf-8"?>\n` +
38 `<!-- Copyright (C) 2018 The Android Open Source Project\n` +
39 `\n` +
40 ` Licensed under the Apache License, Version 2.0 (the "License");\n` +
41 ` you may not use this file except in compliance with the License.\n` +
42 ` You may obtain a copy of the License at\n` +
43 `\n` +
44 ` http://www.apache.org/licenses/LICENSE-2.0\n` +
45 `\n` +
46 ` Unless required by applicable law or agreed to in writing, software\n` +
47 ` distributed under the License is distributed on an "AS IS" BASIS,\n` +
48 ` WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n` +
49 ` See the License for the specific language governing permissions and\n` +
50 ` limitations under the License.\n` +
51 `-->\n` +
52 `<permissions>\n` +
53 ` <library name="%s" file="%s"/>\n` +
54 `</permissions>\n`
Jiyong Parkc678ad32018-04-10 13:07:10 +090055)
56
57type stubsLibraryDependencyTag struct {
58 blueprint.BaseDependencyTag
59 name string
60}
61
62var (
63 publicApiStubsTag = dependencyTag{name: "public"}
64 systemApiStubsTag = dependencyTag{name: "system"}
Jiyong Parkdf130542018-04-27 16:29:21 +090065 testApiStubsTag = dependencyTag{name: "test"}
Sundong Ahn20e998b2018-07-24 11:19:26 +090066 publicApiFileTag = dependencyTag{name: "publicApi"}
67 systemApiFileTag = dependencyTag{name: "systemApi"}
68 testApiFileTag = dependencyTag{name: "testApi"}
Jiyong Parkdf130542018-04-27 16:29:21 +090069)
70
71type apiScope int
72
73const (
74 apiScopePublic apiScope = iota
75 apiScopeSystem
76 apiScopeTest
Jiyong Parkc678ad32018-04-10 13:07:10 +090077)
78
Jiyong Park82484c02018-04-23 21:41:26 +090079var (
80 javaSdkLibrariesLock sync.Mutex
81)
82
Jiyong Parkc678ad32018-04-10 13:07:10 +090083// TODO: these are big features that are currently missing
Jiyong Park1be96912018-05-28 18:02:19 +090084// 1) disallowing linking to the runtime shared lib
85// 2) HTML generation
Jiyong Parkc678ad32018-04-10 13:07:10 +090086
87func init() {
Paul Duffin43dc1cc2019-12-19 11:18:54 +000088 RegisterSdkLibraryBuildComponents(android.InitRegistrationContext)
Jiyong Parkc678ad32018-04-10 13:07:10 +090089
Jiyong Park82484c02018-04-23 21:41:26 +090090 android.RegisterMakeVarsProvider(pctx, func(ctx android.MakeVarsContext) {
91 javaSdkLibraries := javaSdkLibraries(ctx.Config())
92 sort.Strings(*javaSdkLibraries)
93 ctx.Strict("JAVA_SDK_LIBRARIES", strings.Join(*javaSdkLibraries, " "))
94 })
Jiyong Parkc678ad32018-04-10 13:07:10 +090095}
96
Paul Duffin43dc1cc2019-12-19 11:18:54 +000097func RegisterSdkLibraryBuildComponents(ctx android.RegistrationContext) {
98 ctx.RegisterModuleType("java_sdk_library", SdkLibraryFactory)
99 ctx.RegisterModuleType("java_sdk_library_import", sdkLibraryImportFactory)
100}
101
Jiyong Parkc678ad32018-04-10 13:07:10 +0900102type sdkLibraryProperties struct {
Sundong Ahnf043cf62018-06-25 16:04:37 +0900103 // List of Java libraries that will be in the classpath when building stubs
104 Stub_only_libs []string `android:"arch_variant"`
105
Jiyong Parkc678ad32018-04-10 13:07:10 +0900106 // list of package names that will be documented and publicized as API
107 Api_packages []string
108
Jiyong Park5a2c9d72018-05-01 22:25:41 +0900109 // list of package names that must be hidden from the API
110 Hidden_api_packages []string
111
Paul Duffin11512472019-02-11 15:55:17 +0000112 // local files that are used within user customized droiddoc options.
113 Droiddoc_option_files []string
114
115 // additional droiddoc options
116 // Available variables for substitution:
117 //
118 // $(location <label>): the path to the droiddoc_option_files with name <label>
Sundong Ahndd567f92018-07-31 17:19:11 +0900119 Droiddoc_options []string
120
Sundong Ahn054b19a2018-10-19 13:46:09 +0900121 // a list of top-level directories containing files to merge qualifier annotations
122 // (i.e. those intended to be included in the stubs written) from.
123 Merge_annotations_dirs []string
124
125 // a list of top-level directories containing Java stub files to merge show/hide annotations from.
126 Merge_inclusion_annotations_dirs []string
127
128 // If set to true, the path of dist files is apistubs/core. Defaults to false.
129 Core_lib *bool
130
Sundong Ahn80a87b32019-05-13 15:02:50 +0900131 // don't create dist rules.
132 No_dist *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 Duffin250e6192019-06-07 10:44:37 +0100169 sdkDep := decodeSdkDep(ctx, sdkContext(&module.Library))
170 if sdkDep.hasStandardLibs() {
Jiyong Parke3ef3c82019-07-15 15:31:16 +0900171 if useBuiltStubs {
172 ctx.AddVariationDependencies(nil, systemApiStubsTag, module.stubsName(apiScopeSystem))
173 ctx.AddVariationDependencies(nil, testApiStubsTag, module.stubsName(apiScopeTest))
174 }
Sundong Ahn054b19a2018-10-19 13:46:09 +0900175 ctx.AddVariationDependencies(nil, systemApiFileTag, module.docsName(apiScopeSystem))
176 ctx.AddVariationDependencies(nil, testApiFileTag, module.docsName(apiScopeTest))
Sundong Ahn054b19a2018-10-19 13:46:09 +0900177 }
178
179 module.Library.deps(ctx)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900180}
181
Inseob Kimc0907f12019-02-08 21:00:45 +0900182func (module *SdkLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900183 module.Library.GenerateAndroidBuildActions(ctx)
184
Jooyung Han624058e2019-12-24 18:38:06 +0900185 module.buildPermissionsFile(ctx)
Jooyung Han58f26ab2019-12-18 15:34:32 +0900186
Sundong Ahn57368eb2018-07-06 11:20:23 +0900187 // Record the paths to the header jars of the library (stubs and impl).
Jiyong Parkc678ad32018-04-10 13:07:10 +0900188 // When this java_sdk_library is dependened from others via "libs" property,
189 // the recorded paths will be returned depending on the link type of the caller.
190 ctx.VisitDirectDeps(func(to android.Module) {
191 otherName := ctx.OtherModuleName(to)
192 tag := ctx.OtherModuleDependencyTag(to)
193
Sundong Ahn57368eb2018-07-06 11:20:23 +0900194 if lib, ok := to.(Dependency); ok {
Jiyong Parkc678ad32018-04-10 13:07:10 +0900195 switch tag {
196 case publicApiStubsTag:
Sundong Ahn57368eb2018-07-06 11:20:23 +0900197 module.publicApiStubsPath = lib.HeaderJars()
Sundong Ahn241cd372018-07-13 16:16:44 +0900198 module.publicApiStubsImplPath = lib.ImplementationJars()
Jiyong Parkc678ad32018-04-10 13:07:10 +0900199 case systemApiStubsTag:
Sundong Ahn57368eb2018-07-06 11:20:23 +0900200 module.systemApiStubsPath = lib.HeaderJars()
Sundong Ahn241cd372018-07-13 16:16:44 +0900201 module.systemApiStubsImplPath = lib.ImplementationJars()
Jiyong Parkdf130542018-04-27 16:29:21 +0900202 case testApiStubsTag:
Sundong Ahn57368eb2018-07-06 11:20:23 +0900203 module.testApiStubsPath = lib.HeaderJars()
Sundong Ahn241cd372018-07-13 16:16:44 +0900204 module.testApiStubsImplPath = lib.ImplementationJars()
Jiyong Parkc678ad32018-04-10 13:07:10 +0900205 }
206 }
Sundong Ahn20e998b2018-07-24 11:19:26 +0900207 if doc, ok := to.(ApiFilePath); ok {
208 switch tag {
209 case publicApiFileTag:
210 module.publicApiFilePath = doc.ApiFilePath()
211 case systemApiFileTag:
212 module.systemApiFilePath = doc.ApiFilePath()
213 case testApiFileTag:
214 module.testApiFilePath = doc.ApiFilePath()
215 default:
216 ctx.ModuleErrorf("depends on module %q of unknown tag %q", otherName, tag)
217 }
218 }
Jiyong Parkc678ad32018-04-10 13:07:10 +0900219 })
220}
221
Jooyung Han624058e2019-12-24 18:38:06 +0900222func (module *SdkLibrary) buildPermissionsFile(ctx android.ModuleContext) {
223 xmlContent := fmt.Sprintf(permissionsTemplate, module.BaseModuleName(), module.implPath())
224 permissionsFile := android.PathForModuleOut(ctx, module.xmlFileName())
Jooyung Han58f26ab2019-12-18 15:34:32 +0900225
Jooyung Han624058e2019-12-24 18:38:06 +0900226 ctx.Build(pctx, android.BuildParams{
227 Rule: android.WriteFile,
228 Output: permissionsFile,
229 Description: "Generating " + module.BaseModuleName() + " permissions",
230 Args: map[string]string{
231 "content": xmlContent,
232 },
233 })
Jooyung Han58f26ab2019-12-18 15:34:32 +0900234
Jooyung Han624058e2019-12-24 18:38:06 +0900235 module.permissionsFile = permissionsFile
Jooyung Han58f26ab2019-12-18 15:34:32 +0900236}
237
Jooyung Han624058e2019-12-24 18:38:06 +0900238func (module *SdkLibrary) OutputFiles(tag string) (android.Paths, error) {
239 switch tag {
240 case ".xml":
241 return android.Paths{module.permissionsFile}, nil
242 }
243 return module.Library.OutputFiles(tag)
Jooyung Han58f26ab2019-12-18 15:34:32 +0900244}
245
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900246func (module *SdkLibrary) AndroidMkEntries() []android.AndroidMkEntries {
247 entriesList := module.Library.AndroidMkEntries()
248 entries := &entriesList[0]
Jaewoong Jungb0c127c2019-08-29 14:56:03 -0700249 entries.Required = append(entries.Required, module.xmlFileName())
Sundong Ahn054b19a2018-10-19 13:46:09 +0900250
Jaewoong Jungb0c127c2019-08-29 14:56:03 -0700251 entries.ExtraFooters = []android.AndroidMkExtraFootersFunc{
252 func(w io.Writer, name, prefix, moduleDir string, entries *android.AndroidMkEntries) {
Jaewoong Jungb0c127c2019-08-29 14:56:03 -0700253 if !Bool(module.sdkLibraryProperties.No_dist) {
254 // Create a phony module that installs the impl library, for the case when this lib is
255 // in PRODUCT_PACKAGES.
256 owner := module.ModuleBase.Owner()
257 if owner == "" {
258 if Bool(module.sdkLibraryProperties.Core_lib) {
259 owner = "core"
260 } else {
261 owner = "android"
262 }
263 }
264 // Create dist rules to install the stubs libs to the dist dir
265 if len(module.publicApiStubsPath) == 1 {
266 fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+
267 module.publicApiStubsImplPath.Strings()[0]+
268 ":"+path.Join("apistubs", owner, "public",
269 module.BaseModuleName()+".jar")+")")
270 }
271 if len(module.systemApiStubsPath) == 1 {
272 fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+
273 module.systemApiStubsImplPath.Strings()[0]+
274 ":"+path.Join("apistubs", owner, "system",
275 module.BaseModuleName()+".jar")+")")
276 }
277 if len(module.testApiStubsPath) == 1 {
278 fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+
279 module.testApiStubsImplPath.Strings()[0]+
280 ":"+path.Join("apistubs", owner, "test",
281 module.BaseModuleName()+".jar")+")")
282 }
283 if module.publicApiFilePath != nil {
284 fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+
285 module.publicApiFilePath.String()+
286 ":"+path.Join("apistubs", owner, "public", "api",
287 module.BaseModuleName()+".txt")+")")
288 }
289 if module.systemApiFilePath != nil {
290 fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+
291 module.systemApiFilePath.String()+
292 ":"+path.Join("apistubs", owner, "system", "api",
293 module.BaseModuleName()+".txt")+")")
294 }
295 if module.testApiFilePath != nil {
296 fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+
297 module.testApiFilePath.String()+
298 ":"+path.Join("apistubs", owner, "test", "api",
299 module.BaseModuleName()+".txt")+")")
Sundong Ahn80a87b32019-05-13 15:02:50 +0900300 }
Sundong Ahn4fd04bb2018-08-31 18:01:37 +0900301 }
Jaewoong Jungb0c127c2019-08-29 14:56:03 -0700302 },
Jiyong Park82484c02018-04-23 21:41:26 +0900303 }
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900304 return entriesList
Jiyong Park82484c02018-04-23 21:41:26 +0900305}
306
Jiyong Parkc678ad32018-04-10 13:07:10 +0900307// Module name of the stubs library
Inseob Kimc0907f12019-02-08 21:00:45 +0900308func (module *SdkLibrary) stubsName(apiScope apiScope) string {
Jiyong Parkc678ad32018-04-10 13:07:10 +0900309 stubsName := module.BaseModuleName() + sdkStubsLibrarySuffix
Jiyong Parkdf130542018-04-27 16:29:21 +0900310 switch apiScope {
311 case apiScopeSystem:
Jiyong Parkc678ad32018-04-10 13:07:10 +0900312 stubsName = stubsName + sdkSystemApiSuffix
Jiyong Parkdf130542018-04-27 16:29:21 +0900313 case apiScopeTest:
314 stubsName = stubsName + sdkTestApiSuffix
Jiyong Parkc678ad32018-04-10 13:07:10 +0900315 }
316 return stubsName
317}
318
319// Module name of the docs
Inseob Kimc0907f12019-02-08 21:00:45 +0900320func (module *SdkLibrary) docsName(apiScope apiScope) string {
Jiyong Parkc678ad32018-04-10 13:07:10 +0900321 docsName := module.BaseModuleName() + sdkDocsSuffix
Jiyong Parkdf130542018-04-27 16:29:21 +0900322 switch apiScope {
323 case apiScopeSystem:
Jiyong Parkc678ad32018-04-10 13:07:10 +0900324 docsName = docsName + sdkSystemApiSuffix
Jiyong Parkdf130542018-04-27 16:29:21 +0900325 case apiScopeTest:
326 docsName = docsName + sdkTestApiSuffix
Jiyong Parkc678ad32018-04-10 13:07:10 +0900327 }
328 return docsName
329}
330
331// Module name of the runtime implementation library
Inseob Kimc0907f12019-02-08 21:00:45 +0900332func (module *SdkLibrary) implName() string {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900333 return module.BaseModuleName()
Jiyong Parkc678ad32018-04-10 13:07:10 +0900334}
335
336// File path to the runtime implementation library
Inseob Kimc0907f12019-02-08 21:00:45 +0900337func (module *SdkLibrary) implPath() string {
Jooyung Han58f26ab2019-12-18 15:34:32 +0900338 if apexName := module.ApexName(); apexName != "" {
339 // TODO(b/146468504): ApexName() is only a soong module name, not apex name.
340 // In most cases, this works fine. But when apex_name is set or override_apex is used
341 // this can be wrong.
342 return fmt.Sprintf("/apex/%s/javalib/%s.jar", apexName, module.implName())
343 }
Jiyong Parkc678ad32018-04-10 13:07:10 +0900344 partition := "system"
345 if module.SocSpecific() {
346 partition = "vendor"
347 } else if module.DeviceSpecific() {
348 partition = "odm"
349 } else if module.ProductSpecific() {
350 partition = "product"
Sundong Ahn0d7dff42019-12-04 12:53:44 +0900351 } else if module.SystemExtSpecific() {
352 partition = "system_ext"
Jiyong Parkc678ad32018-04-10 13:07:10 +0900353 }
354 return "/" + partition + "/framework/" + module.implName() + ".jar"
355}
356
357// Module name of the XML file for the lib
Inseob Kimc0907f12019-02-08 21:00:45 +0900358func (module *SdkLibrary) xmlFileName() string {
Jiyong Parkc678ad32018-04-10 13:07:10 +0900359 return module.BaseModuleName() + sdkXmlFileSuffix
360}
361
362// SDK version that the stubs library is built against. Note that this is always
363// *current. Older stubs library built with a numberd SDK version is created from
364// the prebuilt jar.
Inseob Kimc0907f12019-02-08 21:00:45 +0900365func (module *SdkLibrary) sdkVersion(apiScope apiScope) string {
Jiyong Parkdf130542018-04-27 16:29:21 +0900366 switch apiScope {
367 case apiScopePublic:
368 return "current"
369 case apiScopeSystem:
Jiyong Parkc678ad32018-04-10 13:07:10 +0900370 return "system_current"
Jiyong Parkdf130542018-04-27 16:29:21 +0900371 case apiScopeTest:
372 return "test_current"
373 default:
Jiyong Parkc678ad32018-04-10 13:07:10 +0900374 return "current"
375 }
376}
377
378// $(INTERNAL_PLATFORM_<apiTagName>_API_FILE) points to the generated
379// api file for the current source
380// TODO: remove this when apicheck is done in soong
Inseob Kimc0907f12019-02-08 21:00:45 +0900381func (module *SdkLibrary) apiTagName(apiScope apiScope) string {
Jiyong Parkc678ad32018-04-10 13:07:10 +0900382 apiTagName := strings.Replace(strings.ToUpper(module.BaseModuleName()), ".", "_", -1)
Jiyong Parkdf130542018-04-27 16:29:21 +0900383 switch apiScope {
384 case apiScopeSystem:
Jiyong Parkc678ad32018-04-10 13:07:10 +0900385 apiTagName = apiTagName + "_SYSTEM"
Jiyong Parkdf130542018-04-27 16:29:21 +0900386 case apiScopeTest:
387 apiTagName = apiTagName + "_TEST"
Jiyong Parkc678ad32018-04-10 13:07:10 +0900388 }
389 return apiTagName
390}
391
Inseob Kimc0907f12019-02-08 21:00:45 +0900392func (module *SdkLibrary) latestApiFilegroupName(apiScope apiScope) string {
Jiyong Park58c518b2018-05-12 22:29:12 +0900393 name := ":" + module.BaseModuleName() + ".api."
Jiyong Parkdf130542018-04-27 16:29:21 +0900394 switch apiScope {
Jiyong Park58c518b2018-05-12 22:29:12 +0900395 case apiScopePublic:
396 name = name + "public"
Jiyong Parkdf130542018-04-27 16:29:21 +0900397 case apiScopeSystem:
Jiyong Park58c518b2018-05-12 22:29:12 +0900398 name = name + "system"
Jiyong Parkdf130542018-04-27 16:29:21 +0900399 case apiScopeTest:
Jiyong Park58c518b2018-05-12 22:29:12 +0900400 name = name + "test"
Jiyong Parkc678ad32018-04-10 13:07:10 +0900401 }
Jiyong Park58c518b2018-05-12 22:29:12 +0900402 name = name + ".latest"
403 return name
404}
Jiyong Parkc678ad32018-04-10 13:07:10 +0900405
Inseob Kimc0907f12019-02-08 21:00:45 +0900406func (module *SdkLibrary) latestRemovedApiFilegroupName(apiScope apiScope) string {
Jiyong Park58c518b2018-05-12 22:29:12 +0900407 name := ":" + module.BaseModuleName() + "-removed.api."
408 switch apiScope {
409 case apiScopePublic:
410 name = name + "public"
411 case apiScopeSystem:
412 name = name + "system"
413 case apiScopeTest:
414 name = name + "test"
415 }
416 name = name + ".latest"
417 return name
Jiyong Parkc678ad32018-04-10 13:07:10 +0900418}
419
420// Creates a static java library that has API stubs
Colin Crossf8b860a2019-04-16 14:43:28 -0700421func (module *SdkLibrary) createStubsLibrary(mctx android.LoadHookContext, apiScope apiScope) {
Jiyong Parkc678ad32018-04-10 13:07:10 +0900422 props := struct {
Sundong Ahn0d7dff42019-12-04 12:53:44 +0900423 Name *string
424 Srcs []string
425 Sdk_version *string
426 Libs []string
427 Soc_specific *bool
428 Device_specific *bool
429 Product_specific *bool
430 System_ext_specific *bool
431 Compile_dex *bool
432 System_modules *string
433 Java_version *string
434 Product_variables struct {
Jiyong Parkc678ad32018-04-10 13:07:10 +0900435 Unbundled_build struct {
436 Enabled *bool
437 }
Jiyong Park82484c02018-04-23 21:41:26 +0900438 Pdk struct {
439 Enabled *bool
440 }
Jiyong Parkc678ad32018-04-10 13:07:10 +0900441 }
Sundong Ahn054b19a2018-10-19 13:46:09 +0900442 Openjdk9 struct {
443 Srcs []string
444 Javacflags []string
445 }
Jiyong Parkc678ad32018-04-10 13:07:10 +0900446 }{}
447
Paul Duffin52d398a2019-06-11 12:31:14 +0100448 sdkVersion := module.sdkVersion(apiScope)
Paul Duffin250e6192019-06-07 10:44:37 +0100449 sdkDep := decodeSdkDep(mctx, sdkContext(&module.Library))
Paul Duffin52d398a2019-06-11 12:31:14 +0100450 if !sdkDep.hasStandardLibs() {
451 sdkVersion = "none"
452 }
Paul Duffin250e6192019-06-07 10:44:37 +0100453
Jiyong Parkdf130542018-04-27 16:29:21 +0900454 props.Name = proptools.StringPtr(module.stubsName(apiScope))
Jiyong Parkc678ad32018-04-10 13:07:10 +0900455 // sources are generated from the droiddoc
Jiyong Parkdf130542018-04-27 16:29:21 +0900456 props.Srcs = []string{":" + module.docsName(apiScope)}
Paul Duffin52d398a2019-06-11 12:31:14 +0100457 props.Sdk_version = proptools.StringPtr(sdkVersion)
Sundong Ahn054b19a2018-10-19 13:46:09 +0900458 props.Libs = module.sdkLibraryProperties.Stub_only_libs
Jiyong Parkc678ad32018-04-10 13:07:10 +0900459 // Unbundled apps will use the prebult one from /prebuilts/sdk
Colin Cross10932872019-04-18 14:27:12 -0700460 if mctx.Config().UnbundledBuildUsePrebuiltSdks() {
Colin Cross2c77ceb2019-01-21 11:56:21 -0800461 props.Product_variables.Unbundled_build.Enabled = proptools.BoolPtr(false)
462 }
Jiyong Park82484c02018-04-23 21:41:26 +0900463 props.Product_variables.Pdk.Enabled = proptools.BoolPtr(false)
Sundong Ahn054b19a2018-10-19 13:46:09 +0900464 props.System_modules = module.Library.Module.deviceProperties.System_modules
465 props.Openjdk9.Srcs = module.Library.Module.properties.Openjdk9.Srcs
466 props.Openjdk9.Javacflags = module.Library.Module.properties.Openjdk9.Javacflags
467 props.Java_version = module.Library.Module.properties.Java_version
468 if module.Library.Module.deviceProperties.Compile_dex != nil {
469 props.Compile_dex = module.Library.Module.deviceProperties.Compile_dex
Sundong Ahndd567f92018-07-31 17:19:11 +0900470 }
Jiyong Parkc678ad32018-04-10 13:07:10 +0900471
472 if module.SocSpecific() {
473 props.Soc_specific = proptools.BoolPtr(true)
474 } else if module.DeviceSpecific() {
475 props.Device_specific = proptools.BoolPtr(true)
476 } else if module.ProductSpecific() {
477 props.Product_specific = proptools.BoolPtr(true)
Sundong Ahn0d7dff42019-12-04 12:53:44 +0900478 } else if module.SystemExtSpecific() {
479 props.System_ext_specific = proptools.BoolPtr(true)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900480 }
481
Colin Cross84dfc3d2019-09-25 11:33:01 -0700482 mctx.CreateModule(LibraryFactory, &props)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900483}
484
485// Creates a droiddoc module that creates stubs source files from the given full source
486// files
Colin Crossf8b860a2019-04-16 14:43:28 -0700487func (module *SdkLibrary) createDocs(mctx android.LoadHookContext, apiScope apiScope) {
Jiyong Parkc678ad32018-04-10 13:07:10 +0900488 props := struct {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900489 Name *string
490 Srcs []string
491 Installable *bool
Paul Duffin52d398a2019-06-11 12:31:14 +0100492 Sdk_version *string
Sundong Ahn054b19a2018-10-19 13:46:09 +0900493 Libs []string
Paul Duffin11512472019-02-11 15:55:17 +0000494 Arg_files []string
Sundong Ahn054b19a2018-10-19 13:46:09 +0900495 Args *string
496 Api_tag_name *string
497 Api_filename *string
498 Removed_api_filename *string
Sundong Ahn054b19a2018-10-19 13:46:09 +0900499 Java_version *string
500 Merge_annotations_dirs []string
501 Merge_inclusion_annotations_dirs []string
502 Check_api struct {
Inseob Kim38449af2019-02-28 14:24:05 +0900503 Current ApiToCheck
504 Last_released ApiToCheck
505 Ignore_missing_latest_api *bool
Jiyong Park58c518b2018-05-12 22:29:12 +0900506 }
Sundong Ahn1b92c822018-05-29 11:35:17 +0900507 Aidl struct {
508 Include_dirs []string
509 Local_include_dirs []string
510 }
Jiyong Parkc678ad32018-04-10 13:07:10 +0900511 }{}
512
Paul Duffin250e6192019-06-07 10:44:37 +0100513 sdkDep := decodeSdkDep(mctx, sdkContext(&module.Library))
Paul Duffin52d398a2019-06-11 12:31:14 +0100514 sdkVersion := ""
515 if !sdkDep.hasStandardLibs() {
516 sdkVersion = "none"
517 }
Paul Duffin250e6192019-06-07 10:44:37 +0100518
Jiyong Parkdf130542018-04-27 16:29:21 +0900519 props.Name = proptools.StringPtr(module.docsName(apiScope))
Sundong Ahn054b19a2018-10-19 13:46:09 +0900520 props.Srcs = append(props.Srcs, module.Library.Module.properties.Srcs...)
Paul Duffin52d398a2019-06-11 12:31:14 +0100521 props.Sdk_version = proptools.StringPtr(sdkVersion)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900522 props.Installable = proptools.BoolPtr(false)
Sundong Ahne6f0b052018-06-05 16:46:14 +0900523 // A droiddoc module has only one Libs property and doesn't distinguish between
524 // shared libs and static libs. So we need to add both of these libs to Libs property.
Sundong Ahn054b19a2018-10-19 13:46:09 +0900525 props.Libs = module.Library.Module.properties.Libs
526 props.Libs = append(props.Libs, module.Library.Module.properties.Static_libs...)
527 props.Aidl.Include_dirs = module.Library.Module.deviceProperties.Aidl.Include_dirs
528 props.Aidl.Local_include_dirs = module.Library.Module.deviceProperties.Aidl.Local_include_dirs
Sundong Ahn054b19a2018-10-19 13:46:09 +0900529 props.Java_version = module.Library.Module.properties.Java_version
Jiyong Parkc678ad32018-04-10 13:07:10 +0900530
Sundong Ahn054b19a2018-10-19 13:46:09 +0900531 props.Merge_annotations_dirs = module.sdkLibraryProperties.Merge_annotations_dirs
532 props.Merge_inclusion_annotations_dirs = module.sdkLibraryProperties.Merge_inclusion_annotations_dirs
533
Paul Duffin235ffff2019-12-24 10:41:30 +0000534 droiddocArgs := []string{}
535 if len(module.sdkLibraryProperties.Api_packages) != 0 {
536 droiddocArgs = append(droiddocArgs, "--stub-packages "+strings.Join(module.sdkLibraryProperties.Api_packages, ":"))
537 }
538 if len(module.sdkLibraryProperties.Hidden_api_packages) != 0 {
539 droiddocArgs = append(droiddocArgs,
540 android.JoinWithPrefix(module.sdkLibraryProperties.Hidden_api_packages, " --hide-package "))
541 }
542 droiddocArgs = append(droiddocArgs, module.sdkLibraryProperties.Droiddoc_options...)
543 disabledWarnings := []string{
544 "MissingPermission",
545 "BroadcastBehavior",
546 "HiddenSuperclass",
547 "DeprecationMismatch",
548 "UnavailableSymbol",
549 "SdkConstant",
550 "HiddenTypeParameter",
551 "Todo",
552 "Typo",
553 }
554 droiddocArgs = append(droiddocArgs, android.JoinWithPrefix(disabledWarnings, "--hide "))
Sundong Ahnfb2721f2018-09-17 13:23:09 +0900555
Jiyong Parkdf130542018-04-27 16:29:21 +0900556 switch apiScope {
557 case apiScopeSystem:
Paul Duffin235ffff2019-12-24 10:41:30 +0000558 droiddocArgs = append(droiddocArgs, "-showAnnotation android.annotation.SystemApi")
Jiyong Parkdf130542018-04-27 16:29:21 +0900559 case apiScopeTest:
Paul Duffin235ffff2019-12-24 10:41:30 +0000560 droiddocArgs = append(droiddocArgs, " -showAnnotation android.annotation.TestApi")
Jiyong Parkc678ad32018-04-10 13:07:10 +0900561 }
Paul Duffin11512472019-02-11 15:55:17 +0000562 props.Arg_files = module.sdkLibraryProperties.Droiddoc_option_files
Paul Duffin235ffff2019-12-24 10:41:30 +0000563 props.Args = proptools.StringPtr(strings.Join(droiddocArgs, " "))
Jiyong Parkc678ad32018-04-10 13:07:10 +0900564
565 // List of APIs identified from the provided source files are created. They are later
566 // compared against to the not-yet-released (a.k.a current) list of APIs and to the
567 // last-released (a.k.a numbered) list of API.
Jiyong Parkc678ad32018-04-10 13:07:10 +0900568 currentApiFileName := "current.txt"
569 removedApiFileName := "removed.txt"
Jiyong Parkdf130542018-04-27 16:29:21 +0900570 switch apiScope {
571 case apiScopeSystem:
Jiyong Parkc678ad32018-04-10 13:07:10 +0900572 currentApiFileName = "system-" + currentApiFileName
573 removedApiFileName = "system-" + removedApiFileName
Jiyong Parkdf130542018-04-27 16:29:21 +0900574 case apiScopeTest:
575 currentApiFileName = "test-" + currentApiFileName
576 removedApiFileName = "test-" + removedApiFileName
Jiyong Parkc678ad32018-04-10 13:07:10 +0900577 }
578 currentApiFileName = path.Join("api", currentApiFileName)
579 removedApiFileName = path.Join("api", removedApiFileName)
Jiyong Park58c518b2018-05-12 22:29:12 +0900580 // TODO(jiyong): remove these three props
Jiyong Parkdf130542018-04-27 16:29:21 +0900581 props.Api_tag_name = proptools.StringPtr(module.apiTagName(apiScope))
Jiyong Parkc678ad32018-04-10 13:07:10 +0900582 props.Api_filename = proptools.StringPtr(currentApiFileName)
583 props.Removed_api_filename = proptools.StringPtr(removedApiFileName)
584
Jiyong Park58c518b2018-05-12 22:29:12 +0900585 // check against the not-yet-release API
586 props.Check_api.Current.Api_file = proptools.StringPtr(currentApiFileName)
587 props.Check_api.Current.Removed_api_file = proptools.StringPtr(removedApiFileName)
Jiyong Park58c518b2018-05-12 22:29:12 +0900588
589 // check against the latest released API
590 props.Check_api.Last_released.Api_file = proptools.StringPtr(
591 module.latestApiFilegroupName(apiScope))
592 props.Check_api.Last_released.Removed_api_file = proptools.StringPtr(
593 module.latestRemovedApiFilegroupName(apiScope))
Inseob Kim38449af2019-02-28 14:24:05 +0900594 props.Check_api.Ignore_missing_latest_api = proptools.BoolPtr(true)
Jiyong Park58c518b2018-05-12 22:29:12 +0900595
Colin Cross84dfc3d2019-09-25 11:33:01 -0700596 mctx.CreateModule(DroidstubsFactory, &props)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900597}
598
Jiyong Parkc678ad32018-04-10 13:07:10 +0900599// Creates the xml file that publicizes the runtime library
Colin Crossf8b860a2019-04-16 14:43:28 -0700600func (module *SdkLibrary) createXmlFile(mctx android.LoadHookContext) {
Jiyong Parkc678ad32018-04-10 13:07:10 +0900601 // creates a prebuilt_etc module to actually place the xml file under
602 // <partition>/etc/permissions
603 etcProps := struct {
Sundong Ahn0d7dff42019-12-04 12:53:44 +0900604 Name *string
605 Src *string
606 Sub_dir *string
607 Soc_specific *bool
608 Device_specific *bool
609 Product_specific *bool
610 System_ext_specific *bool
Jiyong Parkc678ad32018-04-10 13:07:10 +0900611 }{}
612 etcProps.Name = proptools.StringPtr(module.xmlFileName())
Jooyung Han624058e2019-12-24 18:38:06 +0900613 etcProps.Src = proptools.StringPtr(":" + module.BaseModuleName() + "{.xml}")
Jiyong Parkc678ad32018-04-10 13:07:10 +0900614 etcProps.Sub_dir = proptools.StringPtr("permissions")
615 if module.SocSpecific() {
616 etcProps.Soc_specific = proptools.BoolPtr(true)
617 } else if module.DeviceSpecific() {
618 etcProps.Device_specific = proptools.BoolPtr(true)
619 } else if module.ProductSpecific() {
620 etcProps.Product_specific = proptools.BoolPtr(true)
Sundong Ahn0d7dff42019-12-04 12:53:44 +0900621 } else if module.SystemExtSpecific() {
622 etcProps.System_ext_specific = proptools.BoolPtr(true)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900623 }
Colin Cross84dfc3d2019-09-25 11:33:01 -0700624 mctx.CreateModule(android.PrebuiltEtcFactory, &etcProps)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900625}
626
Colin Cross0ea8ba82019-06-06 14:33:29 -0700627func (module *SdkLibrary) PrebuiltJars(ctx android.BaseModuleContext, sdkVersion string) android.Paths {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900628 var api, v string
Paul Duffin52d398a2019-06-11 12:31:14 +0100629 if sdkVersion == "" || sdkVersion == "none" {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900630 api = "system"
631 v = "current"
632 } else if strings.Contains(sdkVersion, "_") {
633 t := strings.Split(sdkVersion, "_")
634 api = t[0]
635 v = t[1]
Jiyong Parkc678ad32018-04-10 13:07:10 +0900636 } else {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900637 api = "public"
638 v = sdkVersion
639 }
640 dir := filepath.Join("prebuilts", "sdk", v, api)
641 jar := filepath.Join(dir, module.BaseModuleName()+".jar")
642 jarPath := android.ExistentPathForSource(ctx, jar)
Sundong Ahnae418ac2019-02-28 15:01:28 +0900643 if !jarPath.Valid() {
644 ctx.PropertyErrorf("sdk_library", "invalid sdk version %q, %q does not exist", v, jar)
645 return nil
646 }
Sundong Ahn054b19a2018-10-19 13:46:09 +0900647 return android.Paths{jarPath.Path()}
648}
649
650// to satisfy SdkLibraryDependency interface
Colin Cross0ea8ba82019-06-06 14:33:29 -0700651func (module *SdkLibrary) SdkHeaderJars(ctx android.BaseModuleContext, sdkVersion string) android.Paths {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900652 // This module is just a wrapper for the stubs.
Colin Cross10932872019-04-18 14:27:12 -0700653 if ctx.Config().UnbundledBuildUsePrebuiltSdks() {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900654 return module.PrebuiltJars(ctx, sdkVersion)
655 } else {
656 if strings.HasPrefix(sdkVersion, "system_") {
657 return module.systemApiStubsPath
658 } else if sdkVersion == "" {
659 return module.Library.HeaderJars()
660 } else {
661 return module.publicApiStubsPath
662 }
Jiyong Parkc678ad32018-04-10 13:07:10 +0900663 }
664}
665
Sundong Ahn241cd372018-07-13 16:16:44 +0900666// to satisfy SdkLibraryDependency interface
Colin Cross0ea8ba82019-06-06 14:33:29 -0700667func (module *SdkLibrary) SdkImplementationJars(ctx android.BaseModuleContext, sdkVersion string) android.Paths {
Sundong Ahn241cd372018-07-13 16:16:44 +0900668 // This module is just a wrapper for the stubs.
Colin Cross10932872019-04-18 14:27:12 -0700669 if ctx.Config().UnbundledBuildUsePrebuiltSdks() {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900670 return module.PrebuiltJars(ctx, sdkVersion)
Sundong Ahn241cd372018-07-13 16:16:44 +0900671 } else {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900672 if strings.HasPrefix(sdkVersion, "system_") {
673 return module.systemApiStubsImplPath
674 } else if sdkVersion == "" {
675 return module.Library.ImplementationJars()
676 } else {
677 return module.publicApiStubsImplPath
678 }
Sundong Ahn241cd372018-07-13 16:16:44 +0900679 }
680}
681
Sundong Ahn80a87b32019-05-13 15:02:50 +0900682func (module *SdkLibrary) SetNoDist() {
683 module.sdkLibraryProperties.No_dist = proptools.BoolPtr(true)
684}
685
Colin Cross571cccf2019-02-04 11:22:08 -0800686var javaSdkLibrariesKey = android.NewOnceKey("javaSdkLibraries")
687
Jiyong Park82484c02018-04-23 21:41:26 +0900688func javaSdkLibraries(config android.Config) *[]string {
Colin Cross571cccf2019-02-04 11:22:08 -0800689 return config.Once(javaSdkLibrariesKey, func() interface{} {
Jiyong Park82484c02018-04-23 21:41:26 +0900690 return &[]string{}
691 }).(*[]string)
692}
693
Jiyong Parkc678ad32018-04-10 13:07:10 +0900694// For a java_sdk_library module, create internal modules for stubs, docs,
695// runtime libs and xml file. If requested, the stubs and docs are created twice
696// once for public API level and once for system API level
Colin Crossf8b860a2019-04-16 14:43:28 -0700697func (module *SdkLibrary) CreateInternalModules(mctx android.LoadHookContext) {
Inseob Kim6e93ac92019-03-21 17:43:49 +0900698 if len(module.Library.Module.properties.Srcs) == 0 {
Inseob Kimc0907f12019-02-08 21:00:45 +0900699 mctx.PropertyErrorf("srcs", "java_sdk_library must specify srcs")
Jooyung Han58f26ab2019-12-18 15:34:32 +0900700 return
Inseob Kimc0907f12019-02-08 21:00:45 +0900701 }
702
Inseob Kim6e93ac92019-03-21 17:43:49 +0900703 if len(module.sdkLibraryProperties.Api_packages) == 0 {
Inseob Kimc0907f12019-02-08 21:00:45 +0900704 mctx.PropertyErrorf("api_packages", "java_sdk_library must specify api_packages")
Jooyung Han58f26ab2019-12-18 15:34:32 +0900705 return
Inseob Kimc0907f12019-02-08 21:00:45 +0900706 }
Inseob Kim8098faa2019-03-18 10:19:51 +0900707
708 missing_current_api := false
709
710 for _, scope := range []string{"", "system-", "test-"} {
711 for _, api := range []string{"current.txt", "removed.txt"} {
712 path := path.Join(mctx.ModuleDir(), "api", scope+api)
713 p := android.ExistentPathForSource(mctx, path)
714 if !p.Valid() {
715 mctx.ModuleErrorf("Current api file %#v doesn't exist", path)
716 missing_current_api = true
717 }
718 }
719 }
720
721 if missing_current_api {
722 script := "build/soong/scripts/gen-java-current-api-files.sh"
723 p := android.ExistentPathForSource(mctx, script)
724
725 if !p.Valid() {
726 panic(fmt.Sprintf("script file %s doesn't exist", script))
727 }
728
729 mctx.ModuleErrorf("One or more current api files are missing. "+
730 "You can update them by:\n"+
731 "%s %q && m update-api", script, mctx.ModuleDir())
732 return
733 }
734
Inseob Kimc0907f12019-02-08 21:00:45 +0900735 // for public API stubs
736 module.createStubsLibrary(mctx, apiScopePublic)
737 module.createDocs(mctx, apiScopePublic)
738
Paul Duffin250e6192019-06-07 10:44:37 +0100739 sdkDep := decodeSdkDep(mctx, sdkContext(&module.Library))
740 if sdkDep.hasStandardLibs() {
Inseob Kimc0907f12019-02-08 21:00:45 +0900741 // for system API stubs
742 module.createStubsLibrary(mctx, apiScopeSystem)
743 module.createDocs(mctx, apiScopeSystem)
744
745 // for test API stubs
746 module.createStubsLibrary(mctx, apiScopeTest)
747 module.createDocs(mctx, apiScopeTest)
748
749 // for runtime
750 module.createXmlFile(mctx)
751 }
752
753 // record java_sdk_library modules so that they are exported to make
754 javaSdkLibraries := javaSdkLibraries(mctx.Config())
755 javaSdkLibrariesLock.Lock()
756 defer javaSdkLibrariesLock.Unlock()
757 *javaSdkLibraries = append(*javaSdkLibraries, module.BaseModuleName())
758}
759
760func (module *SdkLibrary) InitSdkLibraryProperties() {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900761 module.AddProperties(
762 &module.sdkLibraryProperties,
763 &module.Library.Module.properties,
764 &module.Library.Module.dexpreoptProperties,
765 &module.Library.Module.deviceProperties,
766 &module.Library.Module.protoProperties,
767 )
768
769 module.Library.Module.properties.Installable = proptools.BoolPtr(true)
770 module.Library.Module.deviceProperties.IsSDKLibrary = true
Inseob Kimc0907f12019-02-08 21:00:45 +0900771}
Sundong Ahn054b19a2018-10-19 13:46:09 +0900772
Jaewoong Jung4f158ee2019-07-11 10:05:35 -0700773// java_sdk_library is a special Java library that provides optional platform APIs to apps.
774// In practice, it can be viewed as a combination of several modules: 1) stubs library that clients
775// are linked against to, 2) droiddoc module that internally generates API stubs source files,
776// 3) the real runtime shared library that implements the APIs, and 4) XML file for adding
777// the runtime lib to the classpath at runtime if requested via <uses-library>.
Inseob Kimc0907f12019-02-08 21:00:45 +0900778func SdkLibraryFactory() android.Module {
779 module := &SdkLibrary{}
780 module.InitSdkLibraryProperties()
Jooyung Han58f26ab2019-12-18 15:34:32 +0900781 android.InitApexModule(module)
Sundong Ahn054b19a2018-10-19 13:46:09 +0900782 InitJavaModule(module, android.HostAndDeviceSupported)
Colin Crossf8b860a2019-04-16 14:43:28 -0700783 android.AddLoadHook(module, func(ctx android.LoadHookContext) { module.CreateInternalModules(ctx) })
Jiyong Parkc678ad32018-04-10 13:07:10 +0900784 return module
785}
Colin Cross79c7c262019-04-17 11:11:46 -0700786
787//
788// SDK library prebuilts
789//
790
791type sdkLibraryImportProperties struct {
792 Jars []string `android:"path"`
793
794 Sdk_version *string
795
796 Installable *bool
797
798 // List of shared java libs that this module has dependencies to
799 Libs []string
800
801 // List of files to remove from the jar file(s)
802 Exclude_files []string
803
804 // List of directories to remove from the jar file(s)
805 Exclude_dirs []string
806}
807
808type sdkLibraryImport struct {
809 android.ModuleBase
810 android.DefaultableModuleBase
811 prebuilt android.Prebuilt
812
813 properties sdkLibraryImportProperties
814
815 stubsPath android.Paths
816}
817
818var _ SdkLibraryDependency = (*sdkLibraryImport)(nil)
819
Jaewoong Jung4f158ee2019-07-11 10:05:35 -0700820// java_sdk_library_import imports a prebuilt java_sdk_library.
Colin Cross79c7c262019-04-17 11:11:46 -0700821func sdkLibraryImportFactory() android.Module {
822 module := &sdkLibraryImport{}
823
824 module.AddProperties(&module.properties)
825
826 android.InitPrebuiltModule(module, &module.properties.Jars)
827 InitJavaModule(module, android.HostAndDeviceSupported)
828
829 android.AddLoadHook(module, func(mctx android.LoadHookContext) { module.createInternalModules(mctx) })
830 return module
831}
832
833func (module *sdkLibraryImport) Prebuilt() *android.Prebuilt {
834 return &module.prebuilt
835}
836
837func (module *sdkLibraryImport) Name() string {
838 return module.prebuilt.Name(module.ModuleBase.Name())
839}
840
841func (module *sdkLibraryImport) createInternalModules(mctx android.LoadHookContext) {
842 // Creates a java import for the jar with ".stubs" suffix
843 props := struct {
Sundong Ahn0d7dff42019-12-04 12:53:44 +0900844 Name *string
845 Soc_specific *bool
846 Device_specific *bool
847 Product_specific *bool
848 System_ext_specific *bool
Colin Cross79c7c262019-04-17 11:11:46 -0700849 }{}
850
851 props.Name = proptools.StringPtr(module.BaseModuleName() + sdkStubsLibrarySuffix)
852
853 if module.SocSpecific() {
854 props.Soc_specific = proptools.BoolPtr(true)
855 } else if module.DeviceSpecific() {
856 props.Device_specific = proptools.BoolPtr(true)
857 } else if module.ProductSpecific() {
858 props.Product_specific = proptools.BoolPtr(true)
Sundong Ahn0d7dff42019-12-04 12:53:44 +0900859 } else if module.SystemExtSpecific() {
860 props.System_ext_specific = proptools.BoolPtr(true)
Colin Cross79c7c262019-04-17 11:11:46 -0700861 }
862
Colin Cross84dfc3d2019-09-25 11:33:01 -0700863 mctx.CreateModule(ImportFactory, &props, &module.properties)
Colin Cross79c7c262019-04-17 11:11:46 -0700864
865 javaSdkLibraries := javaSdkLibraries(mctx.Config())
866 javaSdkLibrariesLock.Lock()
867 defer javaSdkLibrariesLock.Unlock()
868 *javaSdkLibraries = append(*javaSdkLibraries, module.BaseModuleName())
869}
870
871func (module *sdkLibraryImport) DepsMutator(ctx android.BottomUpMutatorContext) {
872 // Add dependencies to the prebuilt stubs library
873 ctx.AddVariationDependencies(nil, publicApiStubsTag, module.BaseModuleName()+sdkStubsLibrarySuffix)
874}
875
876func (module *sdkLibraryImport) GenerateAndroidBuildActions(ctx android.ModuleContext) {
877 // Record the paths to the prebuilt stubs library.
878 ctx.VisitDirectDeps(func(to android.Module) {
879 tag := ctx.OtherModuleDependencyTag(to)
880
881 switch tag {
882 case publicApiStubsTag:
883 module.stubsPath = to.(Dependency).HeaderJars()
884 }
885 })
886}
887
888// to satisfy SdkLibraryDependency interface
Colin Cross0ea8ba82019-06-06 14:33:29 -0700889func (module *sdkLibraryImport) SdkHeaderJars(ctx android.BaseModuleContext, sdkVersion string) android.Paths {
Colin Cross79c7c262019-04-17 11:11:46 -0700890 // This module is just a wrapper for the prebuilt stubs.
891 return module.stubsPath
892}
893
894// to satisfy SdkLibraryDependency interface
Colin Cross0ea8ba82019-06-06 14:33:29 -0700895func (module *sdkLibraryImport) SdkImplementationJars(ctx android.BaseModuleContext, sdkVersion string) android.Paths {
Colin Cross79c7c262019-04-17 11:11:46 -0700896 // This module is just a wrapper for the stubs.
897 return module.stubsPath
898}