blob: 091889dbc274cda3ab26c5ce771e6df5543beecc [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
Jiyong Parkc678ad32018-04-10 13:07:10 +0900100 // list of package names that will be documented and publicized as API
101 Api_packages []string
102
Jiyong Park5a2c9d72018-05-01 22:25:41 +0900103 // list of package names that must be hidden from the API
104 Hidden_api_packages []string
105
Paul Duffin11512472019-02-11 15:55:17 +0000106 // local files that are used within user customized droiddoc options.
107 Droiddoc_option_files []string
108
109 // additional droiddoc options
110 // Available variables for substitution:
111 //
112 // $(location <label>): the path to the droiddoc_option_files with name <label>
Sundong Ahndd567f92018-07-31 17:19:11 +0900113 Droiddoc_options []string
114
Sundong Ahn054b19a2018-10-19 13:46:09 +0900115 // a list of top-level directories containing files to merge qualifier annotations
116 // (i.e. those intended to be included in the stubs written) from.
117 Merge_annotations_dirs []string
118
119 // a list of top-level directories containing Java stub files to merge show/hide annotations from.
120 Merge_inclusion_annotations_dirs []string
121
122 // If set to true, the path of dist files is apistubs/core. Defaults to false.
123 Core_lib *bool
124
Sundong Ahn80a87b32019-05-13 15:02:50 +0900125 // don't create dist rules.
126 No_dist *bool `blueprint:"mutated"`
127
Jiyong Parkc678ad32018-04-10 13:07:10 +0900128 // TODO: determines whether to create HTML doc or not
129 //Html_doc *bool
130}
131
Inseob Kimc0907f12019-02-08 21:00:45 +0900132type SdkLibrary struct {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900133 Library
Jiyong Parkc678ad32018-04-10 13:07:10 +0900134
Sundong Ahn054b19a2018-10-19 13:46:09 +0900135 sdkLibraryProperties sdkLibraryProperties
Jiyong Parkc678ad32018-04-10 13:07:10 +0900136
137 publicApiStubsPath android.Paths
138 systemApiStubsPath android.Paths
Jiyong Parkdf130542018-04-27 16:29:21 +0900139 testApiStubsPath android.Paths
Sundong Ahn241cd372018-07-13 16:16:44 +0900140
141 publicApiStubsImplPath android.Paths
142 systemApiStubsImplPath android.Paths
143 testApiStubsImplPath android.Paths
Sundong Ahn20e998b2018-07-24 11:19:26 +0900144
145 publicApiFilePath android.Path
146 systemApiFilePath android.Path
147 testApiFilePath android.Path
Jooyung Han58f26ab2019-12-18 15:34:32 +0900148
Jooyung Han624058e2019-12-24 18:38:06 +0900149 permissionsFile android.Path
Jiyong Parkc678ad32018-04-10 13:07:10 +0900150}
151
Inseob Kimc0907f12019-02-08 21:00:45 +0900152var _ Dependency = (*SdkLibrary)(nil)
153var _ SdkLibraryDependency = (*SdkLibrary)(nil)
Colin Cross897d2ed2019-02-11 14:03:51 -0800154
Inseob Kimc0907f12019-02-08 21:00:45 +0900155func (module *SdkLibrary) DepsMutator(ctx android.BottomUpMutatorContext) {
Jiyong Parke3ef3c82019-07-15 15:31:16 +0900156 useBuiltStubs := !ctx.Config().UnbundledBuildUsePrebuiltSdks()
Jiyong Parkc678ad32018-04-10 13:07:10 +0900157 // Add dependencies to the stubs library
Jiyong Parke3ef3c82019-07-15 15:31:16 +0900158 if useBuiltStubs {
159 ctx.AddVariationDependencies(nil, publicApiStubsTag, module.stubsName(apiScopePublic))
160 }
Colin Cross42d48b72018-08-29 14:10:52 -0700161 ctx.AddVariationDependencies(nil, publicApiFileTag, module.docsName(apiScopePublic))
Sundong Ahn054b19a2018-10-19 13:46:09 +0900162
Paul Duffin250e6192019-06-07 10:44:37 +0100163 sdkDep := decodeSdkDep(ctx, sdkContext(&module.Library))
164 if sdkDep.hasStandardLibs() {
Jiyong Parke3ef3c82019-07-15 15:31:16 +0900165 if useBuiltStubs {
166 ctx.AddVariationDependencies(nil, systemApiStubsTag, module.stubsName(apiScopeSystem))
167 ctx.AddVariationDependencies(nil, testApiStubsTag, module.stubsName(apiScopeTest))
168 }
Sundong Ahn054b19a2018-10-19 13:46:09 +0900169 ctx.AddVariationDependencies(nil, systemApiFileTag, module.docsName(apiScopeSystem))
170 ctx.AddVariationDependencies(nil, testApiFileTag, module.docsName(apiScopeTest))
Sundong Ahn054b19a2018-10-19 13:46:09 +0900171 }
172
173 module.Library.deps(ctx)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900174}
175
Inseob Kimc0907f12019-02-08 21:00:45 +0900176func (module *SdkLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900177 module.Library.GenerateAndroidBuildActions(ctx)
178
Jooyung Han624058e2019-12-24 18:38:06 +0900179 module.buildPermissionsFile(ctx)
Jooyung Han58f26ab2019-12-18 15:34:32 +0900180
Sundong Ahn57368eb2018-07-06 11:20:23 +0900181 // Record the paths to the header jars of the library (stubs and impl).
Jiyong Parkc678ad32018-04-10 13:07:10 +0900182 // When this java_sdk_library is dependened from others via "libs" property,
183 // the recorded paths will be returned depending on the link type of the caller.
184 ctx.VisitDirectDeps(func(to android.Module) {
185 otherName := ctx.OtherModuleName(to)
186 tag := ctx.OtherModuleDependencyTag(to)
187
Sundong Ahn57368eb2018-07-06 11:20:23 +0900188 if lib, ok := to.(Dependency); ok {
Jiyong Parkc678ad32018-04-10 13:07:10 +0900189 switch tag {
190 case publicApiStubsTag:
Sundong Ahn57368eb2018-07-06 11:20:23 +0900191 module.publicApiStubsPath = lib.HeaderJars()
Sundong Ahn241cd372018-07-13 16:16:44 +0900192 module.publicApiStubsImplPath = lib.ImplementationJars()
Jiyong Parkc678ad32018-04-10 13:07:10 +0900193 case systemApiStubsTag:
Sundong Ahn57368eb2018-07-06 11:20:23 +0900194 module.systemApiStubsPath = lib.HeaderJars()
Sundong Ahn241cd372018-07-13 16:16:44 +0900195 module.systemApiStubsImplPath = lib.ImplementationJars()
Jiyong Parkdf130542018-04-27 16:29:21 +0900196 case testApiStubsTag:
Sundong Ahn57368eb2018-07-06 11:20:23 +0900197 module.testApiStubsPath = lib.HeaderJars()
Sundong Ahn241cd372018-07-13 16:16:44 +0900198 module.testApiStubsImplPath = lib.ImplementationJars()
Jiyong Parkc678ad32018-04-10 13:07:10 +0900199 }
200 }
Sundong Ahn20e998b2018-07-24 11:19:26 +0900201 if doc, ok := to.(ApiFilePath); ok {
202 switch tag {
203 case publicApiFileTag:
204 module.publicApiFilePath = doc.ApiFilePath()
205 case systemApiFileTag:
206 module.systemApiFilePath = doc.ApiFilePath()
207 case testApiFileTag:
208 module.testApiFilePath = doc.ApiFilePath()
209 default:
210 ctx.ModuleErrorf("depends on module %q of unknown tag %q", otherName, tag)
211 }
212 }
Jiyong Parkc678ad32018-04-10 13:07:10 +0900213 })
214}
215
Jooyung Han624058e2019-12-24 18:38:06 +0900216func (module *SdkLibrary) buildPermissionsFile(ctx android.ModuleContext) {
217 xmlContent := fmt.Sprintf(permissionsTemplate, module.BaseModuleName(), module.implPath())
218 permissionsFile := android.PathForModuleOut(ctx, module.xmlFileName())
Jooyung Han58f26ab2019-12-18 15:34:32 +0900219
Jooyung Han624058e2019-12-24 18:38:06 +0900220 ctx.Build(pctx, android.BuildParams{
221 Rule: android.WriteFile,
222 Output: permissionsFile,
223 Description: "Generating " + module.BaseModuleName() + " permissions",
224 Args: map[string]string{
225 "content": xmlContent,
226 },
227 })
Jooyung Han58f26ab2019-12-18 15:34:32 +0900228
Jooyung Han624058e2019-12-24 18:38:06 +0900229 module.permissionsFile = permissionsFile
Jooyung Han58f26ab2019-12-18 15:34:32 +0900230}
231
Jooyung Han624058e2019-12-24 18:38:06 +0900232func (module *SdkLibrary) OutputFiles(tag string) (android.Paths, error) {
233 switch tag {
234 case ".xml":
235 return android.Paths{module.permissionsFile}, nil
236 }
237 return module.Library.OutputFiles(tag)
Jooyung Han58f26ab2019-12-18 15:34:32 +0900238}
239
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900240func (module *SdkLibrary) AndroidMkEntries() []android.AndroidMkEntries {
241 entriesList := module.Library.AndroidMkEntries()
242 entries := &entriesList[0]
Jaewoong Jungb0c127c2019-08-29 14:56:03 -0700243 entries.Required = append(entries.Required, module.xmlFileName())
Sundong Ahn054b19a2018-10-19 13:46:09 +0900244
Jaewoong Jungb0c127c2019-08-29 14:56:03 -0700245 entries.ExtraFooters = []android.AndroidMkExtraFootersFunc{
246 func(w io.Writer, name, prefix, moduleDir string, entries *android.AndroidMkEntries) {
Jaewoong Jungb0c127c2019-08-29 14:56:03 -0700247 if !Bool(module.sdkLibraryProperties.No_dist) {
248 // Create a phony module that installs the impl library, for the case when this lib is
249 // in PRODUCT_PACKAGES.
250 owner := module.ModuleBase.Owner()
251 if owner == "" {
252 if Bool(module.sdkLibraryProperties.Core_lib) {
253 owner = "core"
254 } else {
255 owner = "android"
256 }
257 }
258 // Create dist rules to install the stubs libs to the dist dir
259 if len(module.publicApiStubsPath) == 1 {
260 fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+
261 module.publicApiStubsImplPath.Strings()[0]+
262 ":"+path.Join("apistubs", owner, "public",
263 module.BaseModuleName()+".jar")+")")
264 }
265 if len(module.systemApiStubsPath) == 1 {
266 fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+
267 module.systemApiStubsImplPath.Strings()[0]+
268 ":"+path.Join("apistubs", owner, "system",
269 module.BaseModuleName()+".jar")+")")
270 }
271 if len(module.testApiStubsPath) == 1 {
272 fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+
273 module.testApiStubsImplPath.Strings()[0]+
274 ":"+path.Join("apistubs", owner, "test",
275 module.BaseModuleName()+".jar")+")")
276 }
277 if module.publicApiFilePath != nil {
278 fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+
279 module.publicApiFilePath.String()+
280 ":"+path.Join("apistubs", owner, "public", "api",
281 module.BaseModuleName()+".txt")+")")
282 }
283 if module.systemApiFilePath != nil {
284 fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+
285 module.systemApiFilePath.String()+
286 ":"+path.Join("apistubs", owner, "system", "api",
287 module.BaseModuleName()+".txt")+")")
288 }
289 if module.testApiFilePath != nil {
290 fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+
291 module.testApiFilePath.String()+
292 ":"+path.Join("apistubs", owner, "test", "api",
293 module.BaseModuleName()+".txt")+")")
Sundong Ahn80a87b32019-05-13 15:02:50 +0900294 }
Sundong Ahn4fd04bb2018-08-31 18:01:37 +0900295 }
Jaewoong Jungb0c127c2019-08-29 14:56:03 -0700296 },
Jiyong Park82484c02018-04-23 21:41:26 +0900297 }
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900298 return entriesList
Jiyong Park82484c02018-04-23 21:41:26 +0900299}
300
Jiyong Parkc678ad32018-04-10 13:07:10 +0900301// Module name of the stubs library
Inseob Kimc0907f12019-02-08 21:00:45 +0900302func (module *SdkLibrary) stubsName(apiScope apiScope) string {
Jiyong Parkc678ad32018-04-10 13:07:10 +0900303 stubsName := module.BaseModuleName() + sdkStubsLibrarySuffix
Jiyong Parkdf130542018-04-27 16:29:21 +0900304 switch apiScope {
305 case apiScopeSystem:
Jiyong Parkc678ad32018-04-10 13:07:10 +0900306 stubsName = stubsName + sdkSystemApiSuffix
Jiyong Parkdf130542018-04-27 16:29:21 +0900307 case apiScopeTest:
308 stubsName = stubsName + sdkTestApiSuffix
Jiyong Parkc678ad32018-04-10 13:07:10 +0900309 }
310 return stubsName
311}
312
313// Module name of the docs
Inseob Kimc0907f12019-02-08 21:00:45 +0900314func (module *SdkLibrary) docsName(apiScope apiScope) string {
Jiyong Parkc678ad32018-04-10 13:07:10 +0900315 docsName := module.BaseModuleName() + sdkDocsSuffix
Jiyong Parkdf130542018-04-27 16:29:21 +0900316 switch apiScope {
317 case apiScopeSystem:
Jiyong Parkc678ad32018-04-10 13:07:10 +0900318 docsName = docsName + sdkSystemApiSuffix
Jiyong Parkdf130542018-04-27 16:29:21 +0900319 case apiScopeTest:
320 docsName = docsName + sdkTestApiSuffix
Jiyong Parkc678ad32018-04-10 13:07:10 +0900321 }
322 return docsName
323}
324
325// Module name of the runtime implementation library
Inseob Kimc0907f12019-02-08 21:00:45 +0900326func (module *SdkLibrary) implName() string {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900327 return module.BaseModuleName()
Jiyong Parkc678ad32018-04-10 13:07:10 +0900328}
329
330// File path to the runtime implementation library
Inseob Kimc0907f12019-02-08 21:00:45 +0900331func (module *SdkLibrary) implPath() string {
Jooyung Han58f26ab2019-12-18 15:34:32 +0900332 if apexName := module.ApexName(); apexName != "" {
333 // TODO(b/146468504): ApexName() is only a soong module name, not apex name.
334 // In most cases, this works fine. But when apex_name is set or override_apex is used
335 // this can be wrong.
336 return fmt.Sprintf("/apex/%s/javalib/%s.jar", apexName, module.implName())
337 }
Jiyong Parkc678ad32018-04-10 13:07:10 +0900338 partition := "system"
339 if module.SocSpecific() {
340 partition = "vendor"
341 } else if module.DeviceSpecific() {
342 partition = "odm"
343 } else if module.ProductSpecific() {
344 partition = "product"
Sundong Ahn0d7dff42019-12-04 12:53:44 +0900345 } else if module.SystemExtSpecific() {
346 partition = "system_ext"
Jiyong Parkc678ad32018-04-10 13:07:10 +0900347 }
348 return "/" + partition + "/framework/" + module.implName() + ".jar"
349}
350
351// Module name of the XML file for the lib
Inseob Kimc0907f12019-02-08 21:00:45 +0900352func (module *SdkLibrary) xmlFileName() string {
Jiyong Parkc678ad32018-04-10 13:07:10 +0900353 return module.BaseModuleName() + sdkXmlFileSuffix
354}
355
356// SDK version that the stubs library is built against. Note that this is always
357// *current. Older stubs library built with a numberd SDK version is created from
358// the prebuilt jar.
Inseob Kimc0907f12019-02-08 21:00:45 +0900359func (module *SdkLibrary) sdkVersion(apiScope apiScope) string {
Jiyong Parkdf130542018-04-27 16:29:21 +0900360 switch apiScope {
361 case apiScopePublic:
362 return "current"
363 case apiScopeSystem:
Jiyong Parkc678ad32018-04-10 13:07:10 +0900364 return "system_current"
Jiyong Parkdf130542018-04-27 16:29:21 +0900365 case apiScopeTest:
366 return "test_current"
367 default:
Jiyong Parkc678ad32018-04-10 13:07:10 +0900368 return "current"
369 }
370}
371
372// $(INTERNAL_PLATFORM_<apiTagName>_API_FILE) points to the generated
373// api file for the current source
374// TODO: remove this when apicheck is done in soong
Inseob Kimc0907f12019-02-08 21:00:45 +0900375func (module *SdkLibrary) apiTagName(apiScope apiScope) string {
Jiyong Parkc678ad32018-04-10 13:07:10 +0900376 apiTagName := strings.Replace(strings.ToUpper(module.BaseModuleName()), ".", "_", -1)
Jiyong Parkdf130542018-04-27 16:29:21 +0900377 switch apiScope {
378 case apiScopeSystem:
Jiyong Parkc678ad32018-04-10 13:07:10 +0900379 apiTagName = apiTagName + "_SYSTEM"
Jiyong Parkdf130542018-04-27 16:29:21 +0900380 case apiScopeTest:
381 apiTagName = apiTagName + "_TEST"
Jiyong Parkc678ad32018-04-10 13:07:10 +0900382 }
383 return apiTagName
384}
385
Inseob Kimc0907f12019-02-08 21:00:45 +0900386func (module *SdkLibrary) latestApiFilegroupName(apiScope apiScope) string {
Jiyong Park58c518b2018-05-12 22:29:12 +0900387 name := ":" + module.BaseModuleName() + ".api."
Jiyong Parkdf130542018-04-27 16:29:21 +0900388 switch apiScope {
Jiyong Park58c518b2018-05-12 22:29:12 +0900389 case apiScopePublic:
390 name = name + "public"
Jiyong Parkdf130542018-04-27 16:29:21 +0900391 case apiScopeSystem:
Jiyong Park58c518b2018-05-12 22:29:12 +0900392 name = name + "system"
Jiyong Parkdf130542018-04-27 16:29:21 +0900393 case apiScopeTest:
Jiyong Park58c518b2018-05-12 22:29:12 +0900394 name = name + "test"
Jiyong Parkc678ad32018-04-10 13:07:10 +0900395 }
Jiyong Park58c518b2018-05-12 22:29:12 +0900396 name = name + ".latest"
397 return name
398}
Jiyong Parkc678ad32018-04-10 13:07:10 +0900399
Inseob Kimc0907f12019-02-08 21:00:45 +0900400func (module *SdkLibrary) latestRemovedApiFilegroupName(apiScope apiScope) string {
Jiyong Park58c518b2018-05-12 22:29:12 +0900401 name := ":" + module.BaseModuleName() + "-removed.api."
402 switch apiScope {
403 case apiScopePublic:
404 name = name + "public"
405 case apiScopeSystem:
406 name = name + "system"
407 case apiScopeTest:
408 name = name + "test"
409 }
410 name = name + ".latest"
411 return name
Jiyong Parkc678ad32018-04-10 13:07:10 +0900412}
413
414// Creates a static java library that has API stubs
Colin Crossf8b860a2019-04-16 14:43:28 -0700415func (module *SdkLibrary) createStubsLibrary(mctx android.LoadHookContext, apiScope apiScope) {
Jiyong Parkc678ad32018-04-10 13:07:10 +0900416 props := struct {
Sundong Ahn0d7dff42019-12-04 12:53:44 +0900417 Name *string
418 Srcs []string
419 Sdk_version *string
420 Libs []string
421 Soc_specific *bool
422 Device_specific *bool
423 Product_specific *bool
424 System_ext_specific *bool
425 Compile_dex *bool
426 System_modules *string
427 Java_version *string
428 Product_variables struct {
Jiyong Parkc678ad32018-04-10 13:07:10 +0900429 Unbundled_build struct {
430 Enabled *bool
431 }
Jiyong Park82484c02018-04-23 21:41:26 +0900432 Pdk struct {
433 Enabled *bool
434 }
Jiyong Parkc678ad32018-04-10 13:07:10 +0900435 }
Sundong Ahn054b19a2018-10-19 13:46:09 +0900436 Openjdk9 struct {
437 Srcs []string
438 Javacflags []string
439 }
Jiyong Parkc678ad32018-04-10 13:07:10 +0900440 }{}
441
Paul Duffin52d398a2019-06-11 12:31:14 +0100442 sdkVersion := module.sdkVersion(apiScope)
Paul Duffin250e6192019-06-07 10:44:37 +0100443 sdkDep := decodeSdkDep(mctx, sdkContext(&module.Library))
Paul Duffin52d398a2019-06-11 12:31:14 +0100444 if !sdkDep.hasStandardLibs() {
445 sdkVersion = "none"
446 }
Paul Duffin250e6192019-06-07 10:44:37 +0100447
Jiyong Parkdf130542018-04-27 16:29:21 +0900448 props.Name = proptools.StringPtr(module.stubsName(apiScope))
Jiyong Parkc678ad32018-04-10 13:07:10 +0900449 // sources are generated from the droiddoc
Jiyong Parkdf130542018-04-27 16:29:21 +0900450 props.Srcs = []string{":" + module.docsName(apiScope)}
Paul Duffin52d398a2019-06-11 12:31:14 +0100451 props.Sdk_version = proptools.StringPtr(sdkVersion)
Sundong Ahn054b19a2018-10-19 13:46:09 +0900452 props.Libs = module.sdkLibraryProperties.Stub_only_libs
Jiyong Parkc678ad32018-04-10 13:07:10 +0900453 // Unbundled apps will use the prebult one from /prebuilts/sdk
Colin Cross10932872019-04-18 14:27:12 -0700454 if mctx.Config().UnbundledBuildUsePrebuiltSdks() {
Colin Cross2c77ceb2019-01-21 11:56:21 -0800455 props.Product_variables.Unbundled_build.Enabled = proptools.BoolPtr(false)
456 }
Jiyong Park82484c02018-04-23 21:41:26 +0900457 props.Product_variables.Pdk.Enabled = proptools.BoolPtr(false)
Sundong Ahn054b19a2018-10-19 13:46:09 +0900458 props.System_modules = module.Library.Module.deviceProperties.System_modules
459 props.Openjdk9.Srcs = module.Library.Module.properties.Openjdk9.Srcs
460 props.Openjdk9.Javacflags = module.Library.Module.properties.Openjdk9.Javacflags
461 props.Java_version = module.Library.Module.properties.Java_version
462 if module.Library.Module.deviceProperties.Compile_dex != nil {
463 props.Compile_dex = module.Library.Module.deviceProperties.Compile_dex
Sundong Ahndd567f92018-07-31 17:19:11 +0900464 }
Jiyong Parkc678ad32018-04-10 13:07:10 +0900465
466 if module.SocSpecific() {
467 props.Soc_specific = proptools.BoolPtr(true)
468 } else if module.DeviceSpecific() {
469 props.Device_specific = proptools.BoolPtr(true)
470 } else if module.ProductSpecific() {
471 props.Product_specific = proptools.BoolPtr(true)
Sundong Ahn0d7dff42019-12-04 12:53:44 +0900472 } else if module.SystemExtSpecific() {
473 props.System_ext_specific = proptools.BoolPtr(true)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900474 }
475
Colin Cross84dfc3d2019-09-25 11:33:01 -0700476 mctx.CreateModule(LibraryFactory, &props)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900477}
478
479// Creates a droiddoc module that creates stubs source files from the given full source
480// files
Paul Duffinc4cea762019-12-30 17:32:47 +0000481func (module *SdkLibrary) createStubsSources(mctx android.LoadHookContext, apiScope apiScope) {
Jiyong Parkc678ad32018-04-10 13:07:10 +0900482 props := struct {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900483 Name *string
484 Srcs []string
485 Installable *bool
Paul Duffin52d398a2019-06-11 12:31:14 +0100486 Sdk_version *string
Sundong Ahn054b19a2018-10-19 13:46:09 +0900487 Libs []string
Paul Duffin11512472019-02-11 15:55:17 +0000488 Arg_files []string
Sundong Ahn054b19a2018-10-19 13:46:09 +0900489 Args *string
490 Api_tag_name *string
491 Api_filename *string
492 Removed_api_filename *string
Sundong Ahn054b19a2018-10-19 13:46:09 +0900493 Java_version *string
494 Merge_annotations_dirs []string
495 Merge_inclusion_annotations_dirs []string
496 Check_api struct {
Inseob Kim38449af2019-02-28 14:24:05 +0900497 Current ApiToCheck
498 Last_released ApiToCheck
499 Ignore_missing_latest_api *bool
Jiyong Park58c518b2018-05-12 22:29:12 +0900500 }
Sundong Ahn1b92c822018-05-29 11:35:17 +0900501 Aidl struct {
502 Include_dirs []string
503 Local_include_dirs []string
504 }
Jiyong Parkc678ad32018-04-10 13:07:10 +0900505 }{}
506
Paul Duffin250e6192019-06-07 10:44:37 +0100507 sdkDep := decodeSdkDep(mctx, sdkContext(&module.Library))
Paul Duffin52d398a2019-06-11 12:31:14 +0100508 sdkVersion := ""
509 if !sdkDep.hasStandardLibs() {
510 sdkVersion = "none"
511 }
Paul Duffin250e6192019-06-07 10:44:37 +0100512
Jiyong Parkdf130542018-04-27 16:29:21 +0900513 props.Name = proptools.StringPtr(module.docsName(apiScope))
Sundong Ahn054b19a2018-10-19 13:46:09 +0900514 props.Srcs = append(props.Srcs, module.Library.Module.properties.Srcs...)
Paul Duffin52d398a2019-06-11 12:31:14 +0100515 props.Sdk_version = proptools.StringPtr(sdkVersion)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900516 props.Installable = proptools.BoolPtr(false)
Sundong Ahne6f0b052018-06-05 16:46:14 +0900517 // A droiddoc module has only one Libs property and doesn't distinguish between
518 // shared libs and static libs. So we need to add both of these libs to Libs property.
Sundong Ahn054b19a2018-10-19 13:46:09 +0900519 props.Libs = module.Library.Module.properties.Libs
520 props.Libs = append(props.Libs, module.Library.Module.properties.Static_libs...)
521 props.Aidl.Include_dirs = module.Library.Module.deviceProperties.Aidl.Include_dirs
522 props.Aidl.Local_include_dirs = module.Library.Module.deviceProperties.Aidl.Local_include_dirs
Sundong Ahn054b19a2018-10-19 13:46:09 +0900523 props.Java_version = module.Library.Module.properties.Java_version
Jiyong Parkc678ad32018-04-10 13:07:10 +0900524
Sundong Ahn054b19a2018-10-19 13:46:09 +0900525 props.Merge_annotations_dirs = module.sdkLibraryProperties.Merge_annotations_dirs
526 props.Merge_inclusion_annotations_dirs = module.sdkLibraryProperties.Merge_inclusion_annotations_dirs
527
Paul Duffin235ffff2019-12-24 10:41:30 +0000528 droiddocArgs := []string{}
529 if len(module.sdkLibraryProperties.Api_packages) != 0 {
530 droiddocArgs = append(droiddocArgs, "--stub-packages "+strings.Join(module.sdkLibraryProperties.Api_packages, ":"))
531 }
532 if len(module.sdkLibraryProperties.Hidden_api_packages) != 0 {
533 droiddocArgs = append(droiddocArgs,
534 android.JoinWithPrefix(module.sdkLibraryProperties.Hidden_api_packages, " --hide-package "))
535 }
536 droiddocArgs = append(droiddocArgs, module.sdkLibraryProperties.Droiddoc_options...)
537 disabledWarnings := []string{
538 "MissingPermission",
539 "BroadcastBehavior",
540 "HiddenSuperclass",
541 "DeprecationMismatch",
542 "UnavailableSymbol",
543 "SdkConstant",
544 "HiddenTypeParameter",
545 "Todo",
546 "Typo",
547 }
548 droiddocArgs = append(droiddocArgs, android.JoinWithPrefix(disabledWarnings, "--hide "))
Sundong Ahnfb2721f2018-09-17 13:23:09 +0900549
Jiyong Parkdf130542018-04-27 16:29:21 +0900550 switch apiScope {
551 case apiScopeSystem:
Paul Duffin235ffff2019-12-24 10:41:30 +0000552 droiddocArgs = append(droiddocArgs, "-showAnnotation android.annotation.SystemApi")
Jiyong Parkdf130542018-04-27 16:29:21 +0900553 case apiScopeTest:
Paul Duffin235ffff2019-12-24 10:41:30 +0000554 droiddocArgs = append(droiddocArgs, " -showAnnotation android.annotation.TestApi")
Jiyong Parkc678ad32018-04-10 13:07:10 +0900555 }
Paul Duffin11512472019-02-11 15:55:17 +0000556 props.Arg_files = module.sdkLibraryProperties.Droiddoc_option_files
Paul Duffin235ffff2019-12-24 10:41:30 +0000557 props.Args = proptools.StringPtr(strings.Join(droiddocArgs, " "))
Jiyong Parkc678ad32018-04-10 13:07:10 +0900558
559 // List of APIs identified from the provided source files are created. They are later
560 // compared against to the not-yet-released (a.k.a current) list of APIs and to the
561 // last-released (a.k.a numbered) list of API.
Jiyong Parkc678ad32018-04-10 13:07:10 +0900562 currentApiFileName := "current.txt"
563 removedApiFileName := "removed.txt"
Jiyong Parkdf130542018-04-27 16:29:21 +0900564 switch apiScope {
565 case apiScopeSystem:
Jiyong Parkc678ad32018-04-10 13:07:10 +0900566 currentApiFileName = "system-" + currentApiFileName
567 removedApiFileName = "system-" + removedApiFileName
Jiyong Parkdf130542018-04-27 16:29:21 +0900568 case apiScopeTest:
569 currentApiFileName = "test-" + currentApiFileName
570 removedApiFileName = "test-" + removedApiFileName
Jiyong Parkc678ad32018-04-10 13:07:10 +0900571 }
572 currentApiFileName = path.Join("api", currentApiFileName)
573 removedApiFileName = path.Join("api", removedApiFileName)
Jiyong Park58c518b2018-05-12 22:29:12 +0900574 // TODO(jiyong): remove these three props
Jiyong Parkdf130542018-04-27 16:29:21 +0900575 props.Api_tag_name = proptools.StringPtr(module.apiTagName(apiScope))
Jiyong Parkc678ad32018-04-10 13:07:10 +0900576 props.Api_filename = proptools.StringPtr(currentApiFileName)
577 props.Removed_api_filename = proptools.StringPtr(removedApiFileName)
578
Jiyong Park58c518b2018-05-12 22:29:12 +0900579 // check against the not-yet-release API
580 props.Check_api.Current.Api_file = proptools.StringPtr(currentApiFileName)
581 props.Check_api.Current.Removed_api_file = proptools.StringPtr(removedApiFileName)
Jiyong Park58c518b2018-05-12 22:29:12 +0900582
583 // check against the latest released API
584 props.Check_api.Last_released.Api_file = proptools.StringPtr(
585 module.latestApiFilegroupName(apiScope))
586 props.Check_api.Last_released.Removed_api_file = proptools.StringPtr(
587 module.latestRemovedApiFilegroupName(apiScope))
Inseob Kim38449af2019-02-28 14:24:05 +0900588 props.Check_api.Ignore_missing_latest_api = proptools.BoolPtr(true)
Jiyong Park58c518b2018-05-12 22:29:12 +0900589
Colin Cross84dfc3d2019-09-25 11:33:01 -0700590 mctx.CreateModule(DroidstubsFactory, &props)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900591}
592
Jiyong Parkc678ad32018-04-10 13:07:10 +0900593// Creates the xml file that publicizes the runtime library
Colin Crossf8b860a2019-04-16 14:43:28 -0700594func (module *SdkLibrary) createXmlFile(mctx android.LoadHookContext) {
Jiyong Parkc678ad32018-04-10 13:07:10 +0900595 // creates a prebuilt_etc module to actually place the xml file under
596 // <partition>/etc/permissions
597 etcProps := struct {
Sundong Ahn0d7dff42019-12-04 12:53:44 +0900598 Name *string
599 Src *string
600 Sub_dir *string
601 Soc_specific *bool
602 Device_specific *bool
603 Product_specific *bool
604 System_ext_specific *bool
Jiyong Parkc678ad32018-04-10 13:07:10 +0900605 }{}
606 etcProps.Name = proptools.StringPtr(module.xmlFileName())
Jooyung Han624058e2019-12-24 18:38:06 +0900607 etcProps.Src = proptools.StringPtr(":" + module.BaseModuleName() + "{.xml}")
Jiyong Parkc678ad32018-04-10 13:07:10 +0900608 etcProps.Sub_dir = proptools.StringPtr("permissions")
609 if module.SocSpecific() {
610 etcProps.Soc_specific = proptools.BoolPtr(true)
611 } else if module.DeviceSpecific() {
612 etcProps.Device_specific = proptools.BoolPtr(true)
613 } else if module.ProductSpecific() {
614 etcProps.Product_specific = proptools.BoolPtr(true)
Sundong Ahn0d7dff42019-12-04 12:53:44 +0900615 } else if module.SystemExtSpecific() {
616 etcProps.System_ext_specific = proptools.BoolPtr(true)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900617 }
Colin Cross84dfc3d2019-09-25 11:33:01 -0700618 mctx.CreateModule(android.PrebuiltEtcFactory, &etcProps)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900619}
620
Colin Cross0ea8ba82019-06-06 14:33:29 -0700621func (module *SdkLibrary) PrebuiltJars(ctx android.BaseModuleContext, sdkVersion string) android.Paths {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900622 var api, v string
Paul Duffin52d398a2019-06-11 12:31:14 +0100623 if sdkVersion == "" || sdkVersion == "none" {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900624 api = "system"
625 v = "current"
626 } else if strings.Contains(sdkVersion, "_") {
627 t := strings.Split(sdkVersion, "_")
628 api = t[0]
629 v = t[1]
Jiyong Parkc678ad32018-04-10 13:07:10 +0900630 } else {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900631 api = "public"
632 v = sdkVersion
633 }
634 dir := filepath.Join("prebuilts", "sdk", v, api)
635 jar := filepath.Join(dir, module.BaseModuleName()+".jar")
636 jarPath := android.ExistentPathForSource(ctx, jar)
Sundong Ahnae418ac2019-02-28 15:01:28 +0900637 if !jarPath.Valid() {
638 ctx.PropertyErrorf("sdk_library", "invalid sdk version %q, %q does not exist", v, jar)
639 return nil
640 }
Sundong Ahn054b19a2018-10-19 13:46:09 +0900641 return android.Paths{jarPath.Path()}
642}
643
644// to satisfy SdkLibraryDependency interface
Colin Cross0ea8ba82019-06-06 14:33:29 -0700645func (module *SdkLibrary) SdkHeaderJars(ctx android.BaseModuleContext, sdkVersion string) android.Paths {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900646 // This module is just a wrapper for the stubs.
Colin Cross10932872019-04-18 14:27:12 -0700647 if ctx.Config().UnbundledBuildUsePrebuiltSdks() {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900648 return module.PrebuiltJars(ctx, sdkVersion)
649 } else {
650 if strings.HasPrefix(sdkVersion, "system_") {
651 return module.systemApiStubsPath
652 } else if sdkVersion == "" {
653 return module.Library.HeaderJars()
654 } else {
655 return module.publicApiStubsPath
656 }
Jiyong Parkc678ad32018-04-10 13:07:10 +0900657 }
658}
659
Sundong Ahn241cd372018-07-13 16:16:44 +0900660// to satisfy SdkLibraryDependency interface
Colin Cross0ea8ba82019-06-06 14:33:29 -0700661func (module *SdkLibrary) SdkImplementationJars(ctx android.BaseModuleContext, sdkVersion string) android.Paths {
Sundong Ahn241cd372018-07-13 16:16:44 +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)
Sundong Ahn241cd372018-07-13 16:16:44 +0900665 } else {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900666 if strings.HasPrefix(sdkVersion, "system_") {
667 return module.systemApiStubsImplPath
668 } else if sdkVersion == "" {
669 return module.Library.ImplementationJars()
670 } else {
671 return module.publicApiStubsImplPath
672 }
Sundong Ahn241cd372018-07-13 16:16:44 +0900673 }
674}
675
Sundong Ahn80a87b32019-05-13 15:02:50 +0900676func (module *SdkLibrary) SetNoDist() {
677 module.sdkLibraryProperties.No_dist = proptools.BoolPtr(true)
678}
679
Colin Cross571cccf2019-02-04 11:22:08 -0800680var javaSdkLibrariesKey = android.NewOnceKey("javaSdkLibraries")
681
Jiyong Park82484c02018-04-23 21:41:26 +0900682func javaSdkLibraries(config android.Config) *[]string {
Colin Cross571cccf2019-02-04 11:22:08 -0800683 return config.Once(javaSdkLibrariesKey, func() interface{} {
Jiyong Park82484c02018-04-23 21:41:26 +0900684 return &[]string{}
685 }).(*[]string)
686}
687
Jiyong Parkc678ad32018-04-10 13:07:10 +0900688// For a java_sdk_library module, create internal modules for stubs, docs,
689// runtime libs and xml file. If requested, the stubs and docs are created twice
690// once for public API level and once for system API level
Colin Crossf8b860a2019-04-16 14:43:28 -0700691func (module *SdkLibrary) CreateInternalModules(mctx android.LoadHookContext) {
Inseob Kim6e93ac92019-03-21 17:43:49 +0900692 if len(module.Library.Module.properties.Srcs) == 0 {
Inseob Kimc0907f12019-02-08 21:00:45 +0900693 mctx.PropertyErrorf("srcs", "java_sdk_library must specify srcs")
Jooyung Han58f26ab2019-12-18 15:34:32 +0900694 return
Inseob Kimc0907f12019-02-08 21:00:45 +0900695 }
696
Inseob Kim6e93ac92019-03-21 17:43:49 +0900697 if len(module.sdkLibraryProperties.Api_packages) == 0 {
Inseob Kimc0907f12019-02-08 21:00:45 +0900698 mctx.PropertyErrorf("api_packages", "java_sdk_library must specify api_packages")
Jooyung Han58f26ab2019-12-18 15:34:32 +0900699 return
Inseob Kimc0907f12019-02-08 21:00:45 +0900700 }
Inseob Kim8098faa2019-03-18 10:19:51 +0900701
702 missing_current_api := false
703
704 for _, scope := range []string{"", "system-", "test-"} {
705 for _, api := range []string{"current.txt", "removed.txt"} {
706 path := path.Join(mctx.ModuleDir(), "api", scope+api)
707 p := android.ExistentPathForSource(mctx, path)
708 if !p.Valid() {
709 mctx.ModuleErrorf("Current api file %#v doesn't exist", path)
710 missing_current_api = true
711 }
712 }
713 }
714
715 if missing_current_api {
716 script := "build/soong/scripts/gen-java-current-api-files.sh"
717 p := android.ExistentPathForSource(mctx, script)
718
719 if !p.Valid() {
720 panic(fmt.Sprintf("script file %s doesn't exist", script))
721 }
722
723 mctx.ModuleErrorf("One or more current api files are missing. "+
724 "You can update them by:\n"+
725 "%s %q && m update-api", script, mctx.ModuleDir())
726 return
727 }
728
Inseob Kimc0907f12019-02-08 21:00:45 +0900729 // for public API stubs
730 module.createStubsLibrary(mctx, apiScopePublic)
Paul Duffinc4cea762019-12-30 17:32:47 +0000731 module.createStubsSources(mctx, apiScopePublic)
Inseob Kimc0907f12019-02-08 21:00:45 +0900732
Paul Duffin250e6192019-06-07 10:44:37 +0100733 sdkDep := decodeSdkDep(mctx, sdkContext(&module.Library))
734 if sdkDep.hasStandardLibs() {
Inseob Kimc0907f12019-02-08 21:00:45 +0900735 // for system API stubs
736 module.createStubsLibrary(mctx, apiScopeSystem)
Paul Duffinc4cea762019-12-30 17:32:47 +0000737 module.createStubsSources(mctx, apiScopeSystem)
Inseob Kimc0907f12019-02-08 21:00:45 +0900738
739 // for test API stubs
740 module.createStubsLibrary(mctx, apiScopeTest)
Paul Duffinc4cea762019-12-30 17:32:47 +0000741 module.createStubsSources(mctx, apiScopeTest)
Inseob Kimc0907f12019-02-08 21:00:45 +0900742
743 // for runtime
744 module.createXmlFile(mctx)
745 }
746
747 // record java_sdk_library modules so that they are exported to make
748 javaSdkLibraries := javaSdkLibraries(mctx.Config())
749 javaSdkLibrariesLock.Lock()
750 defer javaSdkLibrariesLock.Unlock()
751 *javaSdkLibraries = append(*javaSdkLibraries, module.BaseModuleName())
752}
753
754func (module *SdkLibrary) InitSdkLibraryProperties() {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900755 module.AddProperties(
756 &module.sdkLibraryProperties,
757 &module.Library.Module.properties,
758 &module.Library.Module.dexpreoptProperties,
759 &module.Library.Module.deviceProperties,
760 &module.Library.Module.protoProperties,
761 )
762
763 module.Library.Module.properties.Installable = proptools.BoolPtr(true)
764 module.Library.Module.deviceProperties.IsSDKLibrary = true
Inseob Kimc0907f12019-02-08 21:00:45 +0900765}
Sundong Ahn054b19a2018-10-19 13:46:09 +0900766
Jaewoong Jung4f158ee2019-07-11 10:05:35 -0700767// java_sdk_library is a special Java library that provides optional platform APIs to apps.
768// In practice, it can be viewed as a combination of several modules: 1) stubs library that clients
769// are linked against to, 2) droiddoc module that internally generates API stubs source files,
770// 3) the real runtime shared library that implements the APIs, and 4) XML file for adding
771// the runtime lib to the classpath at runtime if requested via <uses-library>.
Inseob Kimc0907f12019-02-08 21:00:45 +0900772func SdkLibraryFactory() android.Module {
773 module := &SdkLibrary{}
774 module.InitSdkLibraryProperties()
Jooyung Han58f26ab2019-12-18 15:34:32 +0900775 android.InitApexModule(module)
Sundong Ahn054b19a2018-10-19 13:46:09 +0900776 InitJavaModule(module, android.HostAndDeviceSupported)
Colin Crossf8b860a2019-04-16 14:43:28 -0700777 android.AddLoadHook(module, func(ctx android.LoadHookContext) { module.CreateInternalModules(ctx) })
Jiyong Parkc678ad32018-04-10 13:07:10 +0900778 return module
779}
Colin Cross79c7c262019-04-17 11:11:46 -0700780
781//
782// SDK library prebuilts
783//
784
785type sdkLibraryImportProperties struct {
786 Jars []string `android:"path"`
787
788 Sdk_version *string
789
790 Installable *bool
791
792 // List of shared java libs that this module has dependencies to
793 Libs []string
794
795 // List of files to remove from the jar file(s)
796 Exclude_files []string
797
798 // List of directories to remove from the jar file(s)
799 Exclude_dirs []string
800}
801
802type sdkLibraryImport struct {
803 android.ModuleBase
804 android.DefaultableModuleBase
805 prebuilt android.Prebuilt
806
807 properties sdkLibraryImportProperties
808
809 stubsPath android.Paths
810}
811
812var _ SdkLibraryDependency = (*sdkLibraryImport)(nil)
813
Jaewoong Jung4f158ee2019-07-11 10:05:35 -0700814// java_sdk_library_import imports a prebuilt java_sdk_library.
Colin Cross79c7c262019-04-17 11:11:46 -0700815func sdkLibraryImportFactory() android.Module {
816 module := &sdkLibraryImport{}
817
818 module.AddProperties(&module.properties)
819
820 android.InitPrebuiltModule(module, &module.properties.Jars)
821 InitJavaModule(module, android.HostAndDeviceSupported)
822
823 android.AddLoadHook(module, func(mctx android.LoadHookContext) { module.createInternalModules(mctx) })
824 return module
825}
826
827func (module *sdkLibraryImport) Prebuilt() *android.Prebuilt {
828 return &module.prebuilt
829}
830
831func (module *sdkLibraryImport) Name() string {
832 return module.prebuilt.Name(module.ModuleBase.Name())
833}
834
835func (module *sdkLibraryImport) createInternalModules(mctx android.LoadHookContext) {
836 // Creates a java import for the jar with ".stubs" suffix
837 props := struct {
Sundong Ahn0d7dff42019-12-04 12:53:44 +0900838 Name *string
839 Soc_specific *bool
840 Device_specific *bool
841 Product_specific *bool
842 System_ext_specific *bool
Colin Cross79c7c262019-04-17 11:11:46 -0700843 }{}
844
845 props.Name = proptools.StringPtr(module.BaseModuleName() + sdkStubsLibrarySuffix)
846
847 if module.SocSpecific() {
848 props.Soc_specific = proptools.BoolPtr(true)
849 } else if module.DeviceSpecific() {
850 props.Device_specific = proptools.BoolPtr(true)
851 } else if module.ProductSpecific() {
852 props.Product_specific = proptools.BoolPtr(true)
Sundong Ahn0d7dff42019-12-04 12:53:44 +0900853 } else if module.SystemExtSpecific() {
854 props.System_ext_specific = proptools.BoolPtr(true)
Colin Cross79c7c262019-04-17 11:11:46 -0700855 }
856
Colin Cross84dfc3d2019-09-25 11:33:01 -0700857 mctx.CreateModule(ImportFactory, &props, &module.properties)
Colin Cross79c7c262019-04-17 11:11:46 -0700858
859 javaSdkLibraries := javaSdkLibraries(mctx.Config())
860 javaSdkLibrariesLock.Lock()
861 defer javaSdkLibrariesLock.Unlock()
862 *javaSdkLibraries = append(*javaSdkLibraries, module.BaseModuleName())
863}
864
865func (module *sdkLibraryImport) DepsMutator(ctx android.BottomUpMutatorContext) {
866 // Add dependencies to the prebuilt stubs library
867 ctx.AddVariationDependencies(nil, publicApiStubsTag, module.BaseModuleName()+sdkStubsLibrarySuffix)
868}
869
870func (module *sdkLibraryImport) GenerateAndroidBuildActions(ctx android.ModuleContext) {
871 // Record the paths to the prebuilt stubs library.
872 ctx.VisitDirectDeps(func(to android.Module) {
873 tag := ctx.OtherModuleDependencyTag(to)
874
875 switch tag {
876 case publicApiStubsTag:
877 module.stubsPath = to.(Dependency).HeaderJars()
878 }
879 })
880}
881
882// to satisfy SdkLibraryDependency interface
Colin Cross0ea8ba82019-06-06 14:33:29 -0700883func (module *sdkLibraryImport) SdkHeaderJars(ctx android.BaseModuleContext, sdkVersion string) android.Paths {
Colin Cross79c7c262019-04-17 11:11:46 -0700884 // This module is just a wrapper for the prebuilt stubs.
885 return module.stubsPath
886}
887
888// to satisfy SdkLibraryDependency interface
Colin Cross0ea8ba82019-06-06 14:33:29 -0700889func (module *sdkLibraryImport) SdkImplementationJars(ctx android.BaseModuleContext, sdkVersion string) android.Paths {
Colin Cross79c7c262019-04-17 11:11:46 -0700890 // This module is just a wrapper for the stubs.
891 return module.stubsPath
892}