blob: 4067bd3a9e546b610680bcaf940b7d8c0241b735 [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
534 droiddocArgs := " --stub-packages " + strings.Join(module.sdkLibraryProperties.Api_packages, ":") +
535 " " + android.JoinWithPrefix(module.sdkLibraryProperties.Hidden_api_packages, " --hide-package ") +
536 " " + android.JoinWithPrefix(module.sdkLibraryProperties.Droiddoc_options, " ") +
Sundong Ahn04ef8a32019-01-14 11:36:50 +0900537 " --hide MissingPermission --hide BroadcastBehavior " +
538 "--hide HiddenSuperclass --hide DeprecationMismatch --hide UnavailableSymbol " +
539 "--hide SdkConstant --hide HiddenTypeParameter --hide Todo --hide Typo"
Sundong Ahnfb2721f2018-09-17 13:23:09 +0900540
Jiyong Parkdf130542018-04-27 16:29:21 +0900541 switch apiScope {
542 case apiScopeSystem:
Jiyong Parkc678ad32018-04-10 13:07:10 +0900543 droiddocArgs = droiddocArgs + " -showAnnotation android.annotation.SystemApi"
Jiyong Parkdf130542018-04-27 16:29:21 +0900544 case apiScopeTest:
545 droiddocArgs = droiddocArgs + " -showAnnotation android.annotation.TestApi"
Jiyong Parkc678ad32018-04-10 13:07:10 +0900546 }
Paul Duffin11512472019-02-11 15:55:17 +0000547 props.Arg_files = module.sdkLibraryProperties.Droiddoc_option_files
Jiyong Parkc678ad32018-04-10 13:07:10 +0900548 props.Args = proptools.StringPtr(droiddocArgs)
549
550 // List of APIs identified from the provided source files are created. They are later
551 // compared against to the not-yet-released (a.k.a current) list of APIs and to the
552 // last-released (a.k.a numbered) list of API.
Jiyong Parkc678ad32018-04-10 13:07:10 +0900553 currentApiFileName := "current.txt"
554 removedApiFileName := "removed.txt"
Jiyong Parkdf130542018-04-27 16:29:21 +0900555 switch apiScope {
556 case apiScopeSystem:
Jiyong Parkc678ad32018-04-10 13:07:10 +0900557 currentApiFileName = "system-" + currentApiFileName
558 removedApiFileName = "system-" + removedApiFileName
Jiyong Parkdf130542018-04-27 16:29:21 +0900559 case apiScopeTest:
560 currentApiFileName = "test-" + currentApiFileName
561 removedApiFileName = "test-" + removedApiFileName
Jiyong Parkc678ad32018-04-10 13:07:10 +0900562 }
563 currentApiFileName = path.Join("api", currentApiFileName)
564 removedApiFileName = path.Join("api", removedApiFileName)
Jiyong Park58c518b2018-05-12 22:29:12 +0900565 // TODO(jiyong): remove these three props
Jiyong Parkdf130542018-04-27 16:29:21 +0900566 props.Api_tag_name = proptools.StringPtr(module.apiTagName(apiScope))
Jiyong Parkc678ad32018-04-10 13:07:10 +0900567 props.Api_filename = proptools.StringPtr(currentApiFileName)
568 props.Removed_api_filename = proptools.StringPtr(removedApiFileName)
569
Jiyong Park58c518b2018-05-12 22:29:12 +0900570 // check against the not-yet-release API
571 props.Check_api.Current.Api_file = proptools.StringPtr(currentApiFileName)
572 props.Check_api.Current.Removed_api_file = proptools.StringPtr(removedApiFileName)
Jiyong Park58c518b2018-05-12 22:29:12 +0900573
574 // check against the latest released API
575 props.Check_api.Last_released.Api_file = proptools.StringPtr(
576 module.latestApiFilegroupName(apiScope))
577 props.Check_api.Last_released.Removed_api_file = proptools.StringPtr(
578 module.latestRemovedApiFilegroupName(apiScope))
Inseob Kim38449af2019-02-28 14:24:05 +0900579 props.Check_api.Ignore_missing_latest_api = proptools.BoolPtr(true)
Jiyong Park58c518b2018-05-12 22:29:12 +0900580
Colin Cross84dfc3d2019-09-25 11:33:01 -0700581 mctx.CreateModule(DroidstubsFactory, &props)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900582}
583
Jiyong Parkc678ad32018-04-10 13:07:10 +0900584// Creates the xml file that publicizes the runtime library
Colin Crossf8b860a2019-04-16 14:43:28 -0700585func (module *SdkLibrary) createXmlFile(mctx android.LoadHookContext) {
Jiyong Parkc678ad32018-04-10 13:07:10 +0900586 // creates a prebuilt_etc module to actually place the xml file under
587 // <partition>/etc/permissions
588 etcProps := struct {
Sundong Ahn0d7dff42019-12-04 12:53:44 +0900589 Name *string
590 Src *string
591 Sub_dir *string
592 Soc_specific *bool
593 Device_specific *bool
594 Product_specific *bool
595 System_ext_specific *bool
Jiyong Parkc678ad32018-04-10 13:07:10 +0900596 }{}
597 etcProps.Name = proptools.StringPtr(module.xmlFileName())
Jooyung Han624058e2019-12-24 18:38:06 +0900598 etcProps.Src = proptools.StringPtr(":" + module.BaseModuleName() + "{.xml}")
Jiyong Parkc678ad32018-04-10 13:07:10 +0900599 etcProps.Sub_dir = proptools.StringPtr("permissions")
600 if module.SocSpecific() {
601 etcProps.Soc_specific = proptools.BoolPtr(true)
602 } else if module.DeviceSpecific() {
603 etcProps.Device_specific = proptools.BoolPtr(true)
604 } else if module.ProductSpecific() {
605 etcProps.Product_specific = proptools.BoolPtr(true)
Sundong Ahn0d7dff42019-12-04 12:53:44 +0900606 } else if module.SystemExtSpecific() {
607 etcProps.System_ext_specific = proptools.BoolPtr(true)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900608 }
Colin Cross84dfc3d2019-09-25 11:33:01 -0700609 mctx.CreateModule(android.PrebuiltEtcFactory, &etcProps)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900610}
611
Colin Cross0ea8ba82019-06-06 14:33:29 -0700612func (module *SdkLibrary) PrebuiltJars(ctx android.BaseModuleContext, sdkVersion string) android.Paths {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900613 var api, v string
Paul Duffin52d398a2019-06-11 12:31:14 +0100614 if sdkVersion == "" || sdkVersion == "none" {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900615 api = "system"
616 v = "current"
617 } else if strings.Contains(sdkVersion, "_") {
618 t := strings.Split(sdkVersion, "_")
619 api = t[0]
620 v = t[1]
Jiyong Parkc678ad32018-04-10 13:07:10 +0900621 } else {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900622 api = "public"
623 v = sdkVersion
624 }
625 dir := filepath.Join("prebuilts", "sdk", v, api)
626 jar := filepath.Join(dir, module.BaseModuleName()+".jar")
627 jarPath := android.ExistentPathForSource(ctx, jar)
Sundong Ahnae418ac2019-02-28 15:01:28 +0900628 if !jarPath.Valid() {
629 ctx.PropertyErrorf("sdk_library", "invalid sdk version %q, %q does not exist", v, jar)
630 return nil
631 }
Sundong Ahn054b19a2018-10-19 13:46:09 +0900632 return android.Paths{jarPath.Path()}
633}
634
635// to satisfy SdkLibraryDependency interface
Colin Cross0ea8ba82019-06-06 14:33:29 -0700636func (module *SdkLibrary) SdkHeaderJars(ctx android.BaseModuleContext, sdkVersion string) android.Paths {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900637 // This module is just a wrapper for the stubs.
Colin Cross10932872019-04-18 14:27:12 -0700638 if ctx.Config().UnbundledBuildUsePrebuiltSdks() {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900639 return module.PrebuiltJars(ctx, sdkVersion)
640 } else {
641 if strings.HasPrefix(sdkVersion, "system_") {
642 return module.systemApiStubsPath
643 } else if sdkVersion == "" {
644 return module.Library.HeaderJars()
645 } else {
646 return module.publicApiStubsPath
647 }
Jiyong Parkc678ad32018-04-10 13:07:10 +0900648 }
649}
650
Sundong Ahn241cd372018-07-13 16:16:44 +0900651// to satisfy SdkLibraryDependency interface
Colin Cross0ea8ba82019-06-06 14:33:29 -0700652func (module *SdkLibrary) SdkImplementationJars(ctx android.BaseModuleContext, sdkVersion string) android.Paths {
Sundong Ahn241cd372018-07-13 16:16:44 +0900653 // This module is just a wrapper for the stubs.
Colin Cross10932872019-04-18 14:27:12 -0700654 if ctx.Config().UnbundledBuildUsePrebuiltSdks() {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900655 return module.PrebuiltJars(ctx, sdkVersion)
Sundong Ahn241cd372018-07-13 16:16:44 +0900656 } else {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900657 if strings.HasPrefix(sdkVersion, "system_") {
658 return module.systemApiStubsImplPath
659 } else if sdkVersion == "" {
660 return module.Library.ImplementationJars()
661 } else {
662 return module.publicApiStubsImplPath
663 }
Sundong Ahn241cd372018-07-13 16:16:44 +0900664 }
665}
666
Sundong Ahn80a87b32019-05-13 15:02:50 +0900667func (module *SdkLibrary) SetNoDist() {
668 module.sdkLibraryProperties.No_dist = proptools.BoolPtr(true)
669}
670
Colin Cross571cccf2019-02-04 11:22:08 -0800671var javaSdkLibrariesKey = android.NewOnceKey("javaSdkLibraries")
672
Jiyong Park82484c02018-04-23 21:41:26 +0900673func javaSdkLibraries(config android.Config) *[]string {
Colin Cross571cccf2019-02-04 11:22:08 -0800674 return config.Once(javaSdkLibrariesKey, func() interface{} {
Jiyong Park82484c02018-04-23 21:41:26 +0900675 return &[]string{}
676 }).(*[]string)
677}
678
Jiyong Parkc678ad32018-04-10 13:07:10 +0900679// For a java_sdk_library module, create internal modules for stubs, docs,
680// runtime libs and xml file. If requested, the stubs and docs are created twice
681// once for public API level and once for system API level
Colin Crossf8b860a2019-04-16 14:43:28 -0700682func (module *SdkLibrary) CreateInternalModules(mctx android.LoadHookContext) {
Inseob Kim6e93ac92019-03-21 17:43:49 +0900683 if len(module.Library.Module.properties.Srcs) == 0 {
Inseob Kimc0907f12019-02-08 21:00:45 +0900684 mctx.PropertyErrorf("srcs", "java_sdk_library must specify srcs")
Jooyung Han58f26ab2019-12-18 15:34:32 +0900685 return
Inseob Kimc0907f12019-02-08 21:00:45 +0900686 }
687
Inseob Kim6e93ac92019-03-21 17:43:49 +0900688 if len(module.sdkLibraryProperties.Api_packages) == 0 {
Inseob Kimc0907f12019-02-08 21:00:45 +0900689 mctx.PropertyErrorf("api_packages", "java_sdk_library must specify api_packages")
Jooyung Han58f26ab2019-12-18 15:34:32 +0900690 return
Inseob Kimc0907f12019-02-08 21:00:45 +0900691 }
Inseob Kim8098faa2019-03-18 10:19:51 +0900692
693 missing_current_api := false
694
695 for _, scope := range []string{"", "system-", "test-"} {
696 for _, api := range []string{"current.txt", "removed.txt"} {
697 path := path.Join(mctx.ModuleDir(), "api", scope+api)
698 p := android.ExistentPathForSource(mctx, path)
699 if !p.Valid() {
700 mctx.ModuleErrorf("Current api file %#v doesn't exist", path)
701 missing_current_api = true
702 }
703 }
704 }
705
706 if missing_current_api {
707 script := "build/soong/scripts/gen-java-current-api-files.sh"
708 p := android.ExistentPathForSource(mctx, script)
709
710 if !p.Valid() {
711 panic(fmt.Sprintf("script file %s doesn't exist", script))
712 }
713
714 mctx.ModuleErrorf("One or more current api files are missing. "+
715 "You can update them by:\n"+
716 "%s %q && m update-api", script, mctx.ModuleDir())
717 return
718 }
719
Inseob Kimc0907f12019-02-08 21:00:45 +0900720 // for public API stubs
721 module.createStubsLibrary(mctx, apiScopePublic)
722 module.createDocs(mctx, apiScopePublic)
723
Paul Duffin250e6192019-06-07 10:44:37 +0100724 sdkDep := decodeSdkDep(mctx, sdkContext(&module.Library))
725 if sdkDep.hasStandardLibs() {
Inseob Kimc0907f12019-02-08 21:00:45 +0900726 // for system API stubs
727 module.createStubsLibrary(mctx, apiScopeSystem)
728 module.createDocs(mctx, apiScopeSystem)
729
730 // for test API stubs
731 module.createStubsLibrary(mctx, apiScopeTest)
732 module.createDocs(mctx, apiScopeTest)
733
734 // for runtime
735 module.createXmlFile(mctx)
736 }
737
738 // record java_sdk_library modules so that they are exported to make
739 javaSdkLibraries := javaSdkLibraries(mctx.Config())
740 javaSdkLibrariesLock.Lock()
741 defer javaSdkLibrariesLock.Unlock()
742 *javaSdkLibraries = append(*javaSdkLibraries, module.BaseModuleName())
743}
744
745func (module *SdkLibrary) InitSdkLibraryProperties() {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900746 module.AddProperties(
747 &module.sdkLibraryProperties,
748 &module.Library.Module.properties,
749 &module.Library.Module.dexpreoptProperties,
750 &module.Library.Module.deviceProperties,
751 &module.Library.Module.protoProperties,
752 )
753
754 module.Library.Module.properties.Installable = proptools.BoolPtr(true)
755 module.Library.Module.deviceProperties.IsSDKLibrary = true
Inseob Kimc0907f12019-02-08 21:00:45 +0900756}
Sundong Ahn054b19a2018-10-19 13:46:09 +0900757
Jaewoong Jung4f158ee2019-07-11 10:05:35 -0700758// java_sdk_library is a special Java library that provides optional platform APIs to apps.
759// In practice, it can be viewed as a combination of several modules: 1) stubs library that clients
760// are linked against to, 2) droiddoc module that internally generates API stubs source files,
761// 3) the real runtime shared library that implements the APIs, and 4) XML file for adding
762// the runtime lib to the classpath at runtime if requested via <uses-library>.
Inseob Kimc0907f12019-02-08 21:00:45 +0900763func SdkLibraryFactory() android.Module {
764 module := &SdkLibrary{}
765 module.InitSdkLibraryProperties()
Jooyung Han58f26ab2019-12-18 15:34:32 +0900766 android.InitApexModule(module)
Sundong Ahn054b19a2018-10-19 13:46:09 +0900767 InitJavaModule(module, android.HostAndDeviceSupported)
Colin Crossf8b860a2019-04-16 14:43:28 -0700768 android.AddLoadHook(module, func(ctx android.LoadHookContext) { module.CreateInternalModules(ctx) })
Jiyong Parkc678ad32018-04-10 13:07:10 +0900769 return module
770}
Colin Cross79c7c262019-04-17 11:11:46 -0700771
772//
773// SDK library prebuilts
774//
775
776type sdkLibraryImportProperties struct {
777 Jars []string `android:"path"`
778
779 Sdk_version *string
780
781 Installable *bool
782
783 // List of shared java libs that this module has dependencies to
784 Libs []string
785
786 // List of files to remove from the jar file(s)
787 Exclude_files []string
788
789 // List of directories to remove from the jar file(s)
790 Exclude_dirs []string
791}
792
793type sdkLibraryImport struct {
794 android.ModuleBase
795 android.DefaultableModuleBase
796 prebuilt android.Prebuilt
797
798 properties sdkLibraryImportProperties
799
800 stubsPath android.Paths
801}
802
803var _ SdkLibraryDependency = (*sdkLibraryImport)(nil)
804
Jaewoong Jung4f158ee2019-07-11 10:05:35 -0700805// java_sdk_library_import imports a prebuilt java_sdk_library.
Colin Cross79c7c262019-04-17 11:11:46 -0700806func sdkLibraryImportFactory() android.Module {
807 module := &sdkLibraryImport{}
808
809 module.AddProperties(&module.properties)
810
811 android.InitPrebuiltModule(module, &module.properties.Jars)
812 InitJavaModule(module, android.HostAndDeviceSupported)
813
814 android.AddLoadHook(module, func(mctx android.LoadHookContext) { module.createInternalModules(mctx) })
815 return module
816}
817
818func (module *sdkLibraryImport) Prebuilt() *android.Prebuilt {
819 return &module.prebuilt
820}
821
822func (module *sdkLibraryImport) Name() string {
823 return module.prebuilt.Name(module.ModuleBase.Name())
824}
825
826func (module *sdkLibraryImport) createInternalModules(mctx android.LoadHookContext) {
827 // Creates a java import for the jar with ".stubs" suffix
828 props := struct {
Sundong Ahn0d7dff42019-12-04 12:53:44 +0900829 Name *string
830 Soc_specific *bool
831 Device_specific *bool
832 Product_specific *bool
833 System_ext_specific *bool
Colin Cross79c7c262019-04-17 11:11:46 -0700834 }{}
835
836 props.Name = proptools.StringPtr(module.BaseModuleName() + sdkStubsLibrarySuffix)
837
838 if module.SocSpecific() {
839 props.Soc_specific = proptools.BoolPtr(true)
840 } else if module.DeviceSpecific() {
841 props.Device_specific = proptools.BoolPtr(true)
842 } else if module.ProductSpecific() {
843 props.Product_specific = proptools.BoolPtr(true)
Sundong Ahn0d7dff42019-12-04 12:53:44 +0900844 } else if module.SystemExtSpecific() {
845 props.System_ext_specific = proptools.BoolPtr(true)
Colin Cross79c7c262019-04-17 11:11:46 -0700846 }
847
Colin Cross84dfc3d2019-09-25 11:33:01 -0700848 mctx.CreateModule(ImportFactory, &props, &module.properties)
Colin Cross79c7c262019-04-17 11:11:46 -0700849
850 javaSdkLibraries := javaSdkLibraries(mctx.Config())
851 javaSdkLibrariesLock.Lock()
852 defer javaSdkLibrariesLock.Unlock()
853 *javaSdkLibraries = append(*javaSdkLibraries, module.BaseModuleName())
854}
855
856func (module *sdkLibraryImport) DepsMutator(ctx android.BottomUpMutatorContext) {
857 // Add dependencies to the prebuilt stubs library
858 ctx.AddVariationDependencies(nil, publicApiStubsTag, module.BaseModuleName()+sdkStubsLibrarySuffix)
859}
860
861func (module *sdkLibraryImport) GenerateAndroidBuildActions(ctx android.ModuleContext) {
862 // Record the paths to the prebuilt stubs library.
863 ctx.VisitDirectDeps(func(to android.Module) {
864 tag := ctx.OtherModuleDependencyTag(to)
865
866 switch tag {
867 case publicApiStubsTag:
868 module.stubsPath = to.(Dependency).HeaderJars()
869 }
870 })
871}
872
873// to satisfy SdkLibraryDependency interface
Colin Cross0ea8ba82019-06-06 14:33:29 -0700874func (module *sdkLibraryImport) SdkHeaderJars(ctx android.BaseModuleContext, sdkVersion string) android.Paths {
Colin Cross79c7c262019-04-17 11:11:46 -0700875 // This module is just a wrapper for the prebuilt stubs.
876 return module.stubsPath
877}
878
879// to satisfy SdkLibraryDependency interface
Colin Cross0ea8ba82019-06-06 14:33:29 -0700880func (module *sdkLibraryImport) SdkImplementationJars(ctx android.BaseModuleContext, sdkVersion string) android.Paths {
Colin Cross79c7c262019-04-17 11:11:46 -0700881 // This module is just a wrapper for the stubs.
882 return module.stubsPath
883}