blob: c68a3d1c364e980ed62c4587d9e9bf9baba1fd64 [file] [log] [blame]
Jiyong Parkc678ad32018-04-10 13:07:10 +09001// Copyright 2018 Google Inc. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package java
16
17import (
18 "android/soong/android"
Jiyong Parkc678ad32018-04-10 13:07:10 +090019 "fmt"
Jiyong Park82484c02018-04-23 21:41:26 +090020 "io"
Jiyong Parkc678ad32018-04-10 13:07:10 +090021 "path"
Sundong Ahn054b19a2018-10-19 13:46:09 +090022 "path/filepath"
Jiyong Park82484c02018-04-23 21:41:26 +090023 "sort"
Jiyong Parkc678ad32018-04-10 13:07:10 +090024 "strings"
Jiyong Park82484c02018-04-23 21:41:26 +090025 "sync"
Jiyong Parkc678ad32018-04-10 13:07:10 +090026
Jiyong Parkc678ad32018-04-10 13:07:10 +090027 "github.com/google/blueprint/proptools"
28)
29
Jooyung Han58f26ab2019-12-18 15:34:32 +090030const (
Jiyong Parkc678ad32018-04-10 13:07:10 +090031 sdkStubsLibrarySuffix = ".stubs"
32 sdkSystemApiSuffix = ".system"
Jiyong Parkdf130542018-04-27 16:29:21 +090033 sdkTestApiSuffix = ".test"
Jiyong Parkc678ad32018-04-10 13:07:10 +090034 sdkDocsSuffix = ".docs"
Jiyong Parkc678ad32018-04-10 13:07:10 +090035 sdkXmlFileSuffix = ".xml"
Jooyung Han624058e2019-12-24 18:38:06 +090036 permissionsTemplate = `<?xml version="1.0" encoding="utf-8"?>\n` +
37 `<!-- Copyright (C) 2018 The Android Open Source Project\n` +
38 `\n` +
39 ` Licensed under the Apache License, Version 2.0 (the "License");\n` +
40 ` you may not use this file except in compliance with the License.\n` +
41 ` You may obtain a copy of the License at\n` +
42 `\n` +
43 ` http://www.apache.org/licenses/LICENSE-2.0\n` +
44 `\n` +
45 ` Unless required by applicable law or agreed to in writing, software\n` +
46 ` distributed under the License is distributed on an "AS IS" BASIS,\n` +
47 ` WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n` +
48 ` See the License for the specific language governing permissions and\n` +
49 ` limitations under the License.\n` +
50 `-->\n` +
51 `<permissions>\n` +
52 ` <library name="%s" file="%s"/>\n` +
53 `</permissions>\n`
Jiyong Parkc678ad32018-04-10 13:07:10 +090054)
55
Jiyong Parkc678ad32018-04-10 13:07:10 +090056var (
57 publicApiStubsTag = dependencyTag{name: "public"}
58 systemApiStubsTag = dependencyTag{name: "system"}
Jiyong Parkdf130542018-04-27 16:29:21 +090059 testApiStubsTag = dependencyTag{name: "test"}
Sundong Ahn20e998b2018-07-24 11:19:26 +090060 publicApiFileTag = dependencyTag{name: "publicApi"}
61 systemApiFileTag = dependencyTag{name: "systemApi"}
62 testApiFileTag = dependencyTag{name: "testApi"}
Jiyong Parkdf130542018-04-27 16:29:21 +090063)
64
65type apiScope int
66
67const (
68 apiScopePublic apiScope = iota
69 apiScopeSystem
70 apiScopeTest
Jiyong Parkc678ad32018-04-10 13:07:10 +090071)
72
Jiyong Park82484c02018-04-23 21:41:26 +090073var (
74 javaSdkLibrariesLock sync.Mutex
75)
76
Jiyong Parkc678ad32018-04-10 13:07:10 +090077// TODO: these are big features that are currently missing
Jiyong Park1be96912018-05-28 18:02:19 +090078// 1) disallowing linking to the runtime shared lib
79// 2) HTML generation
Jiyong Parkc678ad32018-04-10 13:07:10 +090080
81func init() {
Paul Duffin43dc1cc2019-12-19 11:18:54 +000082 RegisterSdkLibraryBuildComponents(android.InitRegistrationContext)
Jiyong Parkc678ad32018-04-10 13:07:10 +090083
Jiyong Park82484c02018-04-23 21:41:26 +090084 android.RegisterMakeVarsProvider(pctx, func(ctx android.MakeVarsContext) {
85 javaSdkLibraries := javaSdkLibraries(ctx.Config())
86 sort.Strings(*javaSdkLibraries)
87 ctx.Strict("JAVA_SDK_LIBRARIES", strings.Join(*javaSdkLibraries, " "))
88 })
Jiyong Parkc678ad32018-04-10 13:07:10 +090089}
90
Paul Duffin43dc1cc2019-12-19 11:18:54 +000091func RegisterSdkLibraryBuildComponents(ctx android.RegistrationContext) {
92 ctx.RegisterModuleType("java_sdk_library", SdkLibraryFactory)
93 ctx.RegisterModuleType("java_sdk_library_import", sdkLibraryImportFactory)
94}
95
Jiyong Parkc678ad32018-04-10 13:07:10 +090096type sdkLibraryProperties struct {
Sundong Ahnf043cf62018-06-25 16:04:37 +090097 // List of Java libraries that will be in the classpath when building stubs
98 Stub_only_libs []string `android:"arch_variant"`
99
Paul Duffin7a586d32019-12-30 17:09:34 +0000100 // list of package names that will be documented and publicized as API.
101 // This allows the API to be restricted to a subset of the source files provided.
102 // If this is unspecified then all the source files will be treated as being part
103 // of the API.
Jiyong Parkc678ad32018-04-10 13:07:10 +0900104 Api_packages []string
105
Jiyong Park5a2c9d72018-05-01 22:25:41 +0900106 // list of package names that must be hidden from the API
107 Hidden_api_packages []string
108
Paul Duffin749f98f2019-12-30 17:23:46 +0000109 // the relative path to the directory containing the api specification files.
110 // Defaults to "api".
111 Api_dir *string
112
Paul Duffin11512472019-02-11 15:55:17 +0000113 // local files that are used within user customized droiddoc options.
114 Droiddoc_option_files []string
115
116 // additional droiddoc options
117 // Available variables for substitution:
118 //
119 // $(location <label>): the path to the droiddoc_option_files with name <label>
Sundong Ahndd567f92018-07-31 17:19:11 +0900120 Droiddoc_options []string
121
Sundong Ahn054b19a2018-10-19 13:46:09 +0900122 // a list of top-level directories containing files to merge qualifier annotations
123 // (i.e. those intended to be included in the stubs written) from.
124 Merge_annotations_dirs []string
125
126 // a list of top-level directories containing Java stub files to merge show/hide annotations from.
127 Merge_inclusion_annotations_dirs []string
128
129 // If set to true, the path of dist files is apistubs/core. Defaults to false.
130 Core_lib *bool
131
Sundong Ahn80a87b32019-05-13 15:02:50 +0900132 // don't create dist rules.
133 No_dist *bool `blueprint:"mutated"`
134
Paul Duffin37e0b772019-12-30 17:20:10 +0000135 // indicates whether system and test apis should be managed.
136 Has_system_and_test_apis bool `blueprint:"mutated"`
137
Jiyong Parkc678ad32018-04-10 13:07:10 +0900138 // TODO: determines whether to create HTML doc or not
139 //Html_doc *bool
140}
141
Inseob Kimc0907f12019-02-08 21:00:45 +0900142type SdkLibrary struct {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900143 Library
Jiyong Parkc678ad32018-04-10 13:07:10 +0900144
Sundong Ahn054b19a2018-10-19 13:46:09 +0900145 sdkLibraryProperties sdkLibraryProperties
Jiyong Parkc678ad32018-04-10 13:07:10 +0900146
147 publicApiStubsPath android.Paths
148 systemApiStubsPath android.Paths
Jiyong Parkdf130542018-04-27 16:29:21 +0900149 testApiStubsPath android.Paths
Sundong Ahn241cd372018-07-13 16:16:44 +0900150
151 publicApiStubsImplPath android.Paths
152 systemApiStubsImplPath android.Paths
153 testApiStubsImplPath android.Paths
Sundong Ahn20e998b2018-07-24 11:19:26 +0900154
155 publicApiFilePath android.Path
156 systemApiFilePath android.Path
157 testApiFilePath android.Path
Jooyung Han58f26ab2019-12-18 15:34:32 +0900158
Jooyung Han624058e2019-12-24 18:38:06 +0900159 permissionsFile android.Path
Jiyong Parkc678ad32018-04-10 13:07:10 +0900160}
161
Inseob Kimc0907f12019-02-08 21:00:45 +0900162var _ Dependency = (*SdkLibrary)(nil)
163var _ SdkLibraryDependency = (*SdkLibrary)(nil)
Colin Cross897d2ed2019-02-11 14:03:51 -0800164
Inseob Kimc0907f12019-02-08 21:00:45 +0900165func (module *SdkLibrary) DepsMutator(ctx android.BottomUpMutatorContext) {
Jiyong Parke3ef3c82019-07-15 15:31:16 +0900166 useBuiltStubs := !ctx.Config().UnbundledBuildUsePrebuiltSdks()
Jiyong Parkc678ad32018-04-10 13:07:10 +0900167 // Add dependencies to the stubs library
Jiyong Parke3ef3c82019-07-15 15:31:16 +0900168 if useBuiltStubs {
169 ctx.AddVariationDependencies(nil, publicApiStubsTag, module.stubsName(apiScopePublic))
170 }
Colin Cross42d48b72018-08-29 14:10:52 -0700171 ctx.AddVariationDependencies(nil, publicApiFileTag, module.docsName(apiScopePublic))
Sundong Ahn054b19a2018-10-19 13:46:09 +0900172
Paul Duffin37e0b772019-12-30 17:20:10 +0000173 if module.sdkLibraryProperties.Has_system_and_test_apis {
Jiyong Parke3ef3c82019-07-15 15:31:16 +0900174 if useBuiltStubs {
175 ctx.AddVariationDependencies(nil, systemApiStubsTag, module.stubsName(apiScopeSystem))
176 ctx.AddVariationDependencies(nil, testApiStubsTag, module.stubsName(apiScopeTest))
177 }
Sundong Ahn054b19a2018-10-19 13:46:09 +0900178 ctx.AddVariationDependencies(nil, systemApiFileTag, module.docsName(apiScopeSystem))
179 ctx.AddVariationDependencies(nil, testApiFileTag, module.docsName(apiScopeTest))
Sundong Ahn054b19a2018-10-19 13:46:09 +0900180 }
181
182 module.Library.deps(ctx)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900183}
184
Inseob Kimc0907f12019-02-08 21:00:45 +0900185func (module *SdkLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900186 module.Library.GenerateAndroidBuildActions(ctx)
187
Jooyung Han624058e2019-12-24 18:38:06 +0900188 module.buildPermissionsFile(ctx)
Jooyung Han58f26ab2019-12-18 15:34:32 +0900189
Sundong Ahn57368eb2018-07-06 11:20:23 +0900190 // Record the paths to the header jars of the library (stubs and impl).
Jiyong Parkc678ad32018-04-10 13:07:10 +0900191 // When this java_sdk_library is dependened from others via "libs" property,
192 // the recorded paths will be returned depending on the link type of the caller.
193 ctx.VisitDirectDeps(func(to android.Module) {
194 otherName := ctx.OtherModuleName(to)
195 tag := ctx.OtherModuleDependencyTag(to)
196
Sundong Ahn57368eb2018-07-06 11:20:23 +0900197 if lib, ok := to.(Dependency); ok {
Jiyong Parkc678ad32018-04-10 13:07:10 +0900198 switch tag {
199 case publicApiStubsTag:
Sundong Ahn57368eb2018-07-06 11:20:23 +0900200 module.publicApiStubsPath = lib.HeaderJars()
Sundong Ahn241cd372018-07-13 16:16:44 +0900201 module.publicApiStubsImplPath = lib.ImplementationJars()
Jiyong Parkc678ad32018-04-10 13:07:10 +0900202 case systemApiStubsTag:
Sundong Ahn57368eb2018-07-06 11:20:23 +0900203 module.systemApiStubsPath = lib.HeaderJars()
Sundong Ahn241cd372018-07-13 16:16:44 +0900204 module.systemApiStubsImplPath = lib.ImplementationJars()
Jiyong Parkdf130542018-04-27 16:29:21 +0900205 case testApiStubsTag:
Sundong Ahn57368eb2018-07-06 11:20:23 +0900206 module.testApiStubsPath = lib.HeaderJars()
Sundong Ahn241cd372018-07-13 16:16:44 +0900207 module.testApiStubsImplPath = lib.ImplementationJars()
Jiyong Parkc678ad32018-04-10 13:07:10 +0900208 }
209 }
Sundong Ahn20e998b2018-07-24 11:19:26 +0900210 if doc, ok := to.(ApiFilePath); ok {
211 switch tag {
212 case publicApiFileTag:
213 module.publicApiFilePath = doc.ApiFilePath()
214 case systemApiFileTag:
215 module.systemApiFilePath = doc.ApiFilePath()
216 case testApiFileTag:
217 module.testApiFilePath = doc.ApiFilePath()
218 default:
219 ctx.ModuleErrorf("depends on module %q of unknown tag %q", otherName, tag)
220 }
221 }
Jiyong Parkc678ad32018-04-10 13:07:10 +0900222 })
223}
224
Jooyung Han624058e2019-12-24 18:38:06 +0900225func (module *SdkLibrary) buildPermissionsFile(ctx android.ModuleContext) {
226 xmlContent := fmt.Sprintf(permissionsTemplate, module.BaseModuleName(), module.implPath())
227 permissionsFile := android.PathForModuleOut(ctx, module.xmlFileName())
Jooyung Han58f26ab2019-12-18 15:34:32 +0900228
Jooyung Han624058e2019-12-24 18:38:06 +0900229 ctx.Build(pctx, android.BuildParams{
230 Rule: android.WriteFile,
231 Output: permissionsFile,
232 Description: "Generating " + module.BaseModuleName() + " permissions",
233 Args: map[string]string{
234 "content": xmlContent,
235 },
236 })
Jooyung Han58f26ab2019-12-18 15:34:32 +0900237
Jooyung Han624058e2019-12-24 18:38:06 +0900238 module.permissionsFile = permissionsFile
Jooyung Han58f26ab2019-12-18 15:34:32 +0900239}
240
Jooyung Han624058e2019-12-24 18:38:06 +0900241func (module *SdkLibrary) OutputFiles(tag string) (android.Paths, error) {
242 switch tag {
243 case ".xml":
244 return android.Paths{module.permissionsFile}, nil
245 }
246 return module.Library.OutputFiles(tag)
Jooyung Han58f26ab2019-12-18 15:34:32 +0900247}
248
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900249func (module *SdkLibrary) AndroidMkEntries() []android.AndroidMkEntries {
250 entriesList := module.Library.AndroidMkEntries()
251 entries := &entriesList[0]
Jaewoong Jungb0c127c2019-08-29 14:56:03 -0700252 entries.Required = append(entries.Required, module.xmlFileName())
Sundong Ahn054b19a2018-10-19 13:46:09 +0900253
Jaewoong Jungb0c127c2019-08-29 14:56:03 -0700254 entries.ExtraFooters = []android.AndroidMkExtraFootersFunc{
255 func(w io.Writer, name, prefix, moduleDir string, entries *android.AndroidMkEntries) {
Jaewoong Jungb0c127c2019-08-29 14:56:03 -0700256 if !Bool(module.sdkLibraryProperties.No_dist) {
257 // Create a phony module that installs the impl library, for the case when this lib is
258 // in PRODUCT_PACKAGES.
259 owner := module.ModuleBase.Owner()
260 if owner == "" {
261 if Bool(module.sdkLibraryProperties.Core_lib) {
262 owner = "core"
263 } else {
264 owner = "android"
265 }
266 }
267 // Create dist rules to install the stubs libs to the dist dir
268 if len(module.publicApiStubsPath) == 1 {
269 fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+
270 module.publicApiStubsImplPath.Strings()[0]+
271 ":"+path.Join("apistubs", owner, "public",
272 module.BaseModuleName()+".jar")+")")
273 }
274 if len(module.systemApiStubsPath) == 1 {
275 fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+
276 module.systemApiStubsImplPath.Strings()[0]+
277 ":"+path.Join("apistubs", owner, "system",
278 module.BaseModuleName()+".jar")+")")
279 }
280 if len(module.testApiStubsPath) == 1 {
281 fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+
282 module.testApiStubsImplPath.Strings()[0]+
283 ":"+path.Join("apistubs", owner, "test",
284 module.BaseModuleName()+".jar")+")")
285 }
286 if module.publicApiFilePath != nil {
287 fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+
288 module.publicApiFilePath.String()+
289 ":"+path.Join("apistubs", owner, "public", "api",
290 module.BaseModuleName()+".txt")+")")
291 }
292 if module.systemApiFilePath != nil {
293 fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+
294 module.systemApiFilePath.String()+
295 ":"+path.Join("apistubs", owner, "system", "api",
296 module.BaseModuleName()+".txt")+")")
297 }
298 if module.testApiFilePath != nil {
299 fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+
300 module.testApiFilePath.String()+
301 ":"+path.Join("apistubs", owner, "test", "api",
302 module.BaseModuleName()+".txt")+")")
Sundong Ahn80a87b32019-05-13 15:02:50 +0900303 }
Sundong Ahn4fd04bb2018-08-31 18:01:37 +0900304 }
Jaewoong Jungb0c127c2019-08-29 14:56:03 -0700305 },
Jiyong Park82484c02018-04-23 21:41:26 +0900306 }
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900307 return entriesList
Jiyong Park82484c02018-04-23 21:41:26 +0900308}
309
Jiyong Parkc678ad32018-04-10 13:07:10 +0900310// Module name of the stubs library
Inseob Kimc0907f12019-02-08 21:00:45 +0900311func (module *SdkLibrary) stubsName(apiScope apiScope) string {
Jiyong Parkc678ad32018-04-10 13:07:10 +0900312 stubsName := module.BaseModuleName() + sdkStubsLibrarySuffix
Jiyong Parkdf130542018-04-27 16:29:21 +0900313 switch apiScope {
314 case apiScopeSystem:
Jiyong Parkc678ad32018-04-10 13:07:10 +0900315 stubsName = stubsName + sdkSystemApiSuffix
Jiyong Parkdf130542018-04-27 16:29:21 +0900316 case apiScopeTest:
317 stubsName = stubsName + sdkTestApiSuffix
Jiyong Parkc678ad32018-04-10 13:07:10 +0900318 }
319 return stubsName
320}
321
322// Module name of the docs
Inseob Kimc0907f12019-02-08 21:00:45 +0900323func (module *SdkLibrary) docsName(apiScope apiScope) string {
Jiyong Parkc678ad32018-04-10 13:07:10 +0900324 docsName := module.BaseModuleName() + sdkDocsSuffix
Jiyong Parkdf130542018-04-27 16:29:21 +0900325 switch apiScope {
326 case apiScopeSystem:
Jiyong Parkc678ad32018-04-10 13:07:10 +0900327 docsName = docsName + sdkSystemApiSuffix
Jiyong Parkdf130542018-04-27 16:29:21 +0900328 case apiScopeTest:
329 docsName = docsName + sdkTestApiSuffix
Jiyong Parkc678ad32018-04-10 13:07:10 +0900330 }
331 return docsName
332}
333
334// Module name of the runtime implementation library
Inseob Kimc0907f12019-02-08 21:00:45 +0900335func (module *SdkLibrary) implName() string {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900336 return module.BaseModuleName()
Jiyong Parkc678ad32018-04-10 13:07:10 +0900337}
338
339// File path to the runtime implementation library
Inseob Kimc0907f12019-02-08 21:00:45 +0900340func (module *SdkLibrary) implPath() string {
Jooyung Han58f26ab2019-12-18 15:34:32 +0900341 if apexName := module.ApexName(); apexName != "" {
342 // TODO(b/146468504): ApexName() is only a soong module name, not apex name.
343 // In most cases, this works fine. But when apex_name is set or override_apex is used
344 // this can be wrong.
345 return fmt.Sprintf("/apex/%s/javalib/%s.jar", apexName, module.implName())
346 }
Jiyong Parkc678ad32018-04-10 13:07:10 +0900347 partition := "system"
348 if module.SocSpecific() {
349 partition = "vendor"
350 } else if module.DeviceSpecific() {
351 partition = "odm"
352 } else if module.ProductSpecific() {
353 partition = "product"
Sundong Ahn0d7dff42019-12-04 12:53:44 +0900354 } else if module.SystemExtSpecific() {
355 partition = "system_ext"
Jiyong Parkc678ad32018-04-10 13:07:10 +0900356 }
357 return "/" + partition + "/framework/" + module.implName() + ".jar"
358}
359
360// Module name of the XML file for the lib
Inseob Kimc0907f12019-02-08 21:00:45 +0900361func (module *SdkLibrary) xmlFileName() string {
Jiyong Parkc678ad32018-04-10 13:07:10 +0900362 return module.BaseModuleName() + sdkXmlFileSuffix
363}
364
365// SDK version that the stubs library is built against. Note that this is always
366// *current. Older stubs library built with a numberd SDK version is created from
367// the prebuilt jar.
Paul Duffin12ceb462019-12-24 20:31:31 +0000368func (module *SdkLibrary) sdkVersionForScope(apiScope apiScope) string {
Jiyong Parkdf130542018-04-27 16:29:21 +0900369 switch apiScope {
370 case apiScopePublic:
371 return "current"
372 case apiScopeSystem:
Jiyong Parkc678ad32018-04-10 13:07:10 +0900373 return "system_current"
Jiyong Parkdf130542018-04-27 16:29:21 +0900374 case apiScopeTest:
375 return "test_current"
376 default:
Jiyong Parkc678ad32018-04-10 13:07:10 +0900377 return "current"
378 }
379}
380
Paul Duffin12ceb462019-12-24 20:31:31 +0000381// Get the sdk version for use when compiling the stubs library.
382func (module *SdkLibrary) sdkVersionForStubsLibrary(mctx android.BaseModuleContext, apiScope apiScope) string {
383 sdkDep := decodeSdkDep(mctx, sdkContext(&module.Library))
384 if sdkDep.hasStandardLibs() {
385 // If building against a standard sdk then use the sdk version appropriate for the scope.
386 return module.sdkVersionForScope(apiScope)
387 } else {
388 // Otherwise, use no system module.
389 return "none"
390 }
391}
392
Jiyong Parkc678ad32018-04-10 13:07:10 +0900393// $(INTERNAL_PLATFORM_<apiTagName>_API_FILE) points to the generated
394// api file for the current source
395// TODO: remove this when apicheck is done in soong
Inseob Kimc0907f12019-02-08 21:00:45 +0900396func (module *SdkLibrary) apiTagName(apiScope apiScope) string {
Jiyong Parkc678ad32018-04-10 13:07:10 +0900397 apiTagName := strings.Replace(strings.ToUpper(module.BaseModuleName()), ".", "_", -1)
Jiyong Parkdf130542018-04-27 16:29:21 +0900398 switch apiScope {
399 case apiScopeSystem:
Jiyong Parkc678ad32018-04-10 13:07:10 +0900400 apiTagName = apiTagName + "_SYSTEM"
Jiyong Parkdf130542018-04-27 16:29:21 +0900401 case apiScopeTest:
402 apiTagName = apiTagName + "_TEST"
Jiyong Parkc678ad32018-04-10 13:07:10 +0900403 }
404 return apiTagName
405}
406
Inseob Kimc0907f12019-02-08 21:00:45 +0900407func (module *SdkLibrary) latestApiFilegroupName(apiScope apiScope) string {
Jiyong Park58c518b2018-05-12 22:29:12 +0900408 name := ":" + module.BaseModuleName() + ".api."
Jiyong Parkdf130542018-04-27 16:29:21 +0900409 switch apiScope {
Jiyong Park58c518b2018-05-12 22:29:12 +0900410 case apiScopePublic:
411 name = name + "public"
Jiyong Parkdf130542018-04-27 16:29:21 +0900412 case apiScopeSystem:
Jiyong Park58c518b2018-05-12 22:29:12 +0900413 name = name + "system"
Jiyong Parkdf130542018-04-27 16:29:21 +0900414 case apiScopeTest:
Jiyong Park58c518b2018-05-12 22:29:12 +0900415 name = name + "test"
Jiyong Parkc678ad32018-04-10 13:07:10 +0900416 }
Jiyong Park58c518b2018-05-12 22:29:12 +0900417 name = name + ".latest"
418 return name
419}
Jiyong Parkc678ad32018-04-10 13:07:10 +0900420
Inseob Kimc0907f12019-02-08 21:00:45 +0900421func (module *SdkLibrary) latestRemovedApiFilegroupName(apiScope apiScope) string {
Jiyong Park58c518b2018-05-12 22:29:12 +0900422 name := ":" + module.BaseModuleName() + "-removed.api."
423 switch apiScope {
424 case apiScopePublic:
425 name = name + "public"
426 case apiScopeSystem:
427 name = name + "system"
428 case apiScopeTest:
429 name = name + "test"
430 }
431 name = name + ".latest"
432 return name
Jiyong Parkc678ad32018-04-10 13:07:10 +0900433}
434
435// Creates a static java library that has API stubs
Colin Crossf8b860a2019-04-16 14:43:28 -0700436func (module *SdkLibrary) createStubsLibrary(mctx android.LoadHookContext, apiScope apiScope) {
Jiyong Parkc678ad32018-04-10 13:07:10 +0900437 props := struct {
Sundong Ahn0d7dff42019-12-04 12:53:44 +0900438 Name *string
439 Srcs []string
440 Sdk_version *string
Paul Duffin12ceb462019-12-24 20:31:31 +0000441 System_modules *string
Sundong Ahn0d7dff42019-12-04 12:53:44 +0900442 Libs []string
443 Soc_specific *bool
444 Device_specific *bool
445 Product_specific *bool
446 System_ext_specific *bool
447 Compile_dex *bool
Sundong Ahn0d7dff42019-12-04 12:53:44 +0900448 Java_version *string
449 Product_variables struct {
Jiyong Parkc678ad32018-04-10 13:07:10 +0900450 Unbundled_build struct {
451 Enabled *bool
452 }
Jiyong Park82484c02018-04-23 21:41:26 +0900453 Pdk struct {
454 Enabled *bool
455 }
Jiyong Parkc678ad32018-04-10 13:07:10 +0900456 }
Sundong Ahn054b19a2018-10-19 13:46:09 +0900457 Openjdk9 struct {
458 Srcs []string
459 Javacflags []string
460 }
Jiyong Parkc678ad32018-04-10 13:07:10 +0900461 }{}
462
Jiyong Parkdf130542018-04-27 16:29:21 +0900463 props.Name = proptools.StringPtr(module.stubsName(apiScope))
Jiyong Parkc678ad32018-04-10 13:07:10 +0900464 // sources are generated from the droiddoc
Jiyong Parkdf130542018-04-27 16:29:21 +0900465 props.Srcs = []string{":" + module.docsName(apiScope)}
Paul Duffin12ceb462019-12-24 20:31:31 +0000466 sdkVersion := module.sdkVersionForStubsLibrary(mctx, apiScope)
Paul Duffin52d398a2019-06-11 12:31:14 +0100467 props.Sdk_version = proptools.StringPtr(sdkVersion)
Paul Duffin12ceb462019-12-24 20:31:31 +0000468 props.System_modules = module.Library.Module.deviceProperties.System_modules
Sundong Ahn054b19a2018-10-19 13:46:09 +0900469 props.Libs = module.sdkLibraryProperties.Stub_only_libs
Jiyong Parkc678ad32018-04-10 13:07:10 +0900470 // Unbundled apps will use the prebult one from /prebuilts/sdk
Colin Cross10932872019-04-18 14:27:12 -0700471 if mctx.Config().UnbundledBuildUsePrebuiltSdks() {
Colin Cross2c77ceb2019-01-21 11:56:21 -0800472 props.Product_variables.Unbundled_build.Enabled = proptools.BoolPtr(false)
473 }
Jiyong Park82484c02018-04-23 21:41:26 +0900474 props.Product_variables.Pdk.Enabled = proptools.BoolPtr(false)
Sundong Ahn054b19a2018-10-19 13:46:09 +0900475 props.Openjdk9.Srcs = module.Library.Module.properties.Openjdk9.Srcs
476 props.Openjdk9.Javacflags = module.Library.Module.properties.Openjdk9.Javacflags
477 props.Java_version = module.Library.Module.properties.Java_version
478 if module.Library.Module.deviceProperties.Compile_dex != nil {
479 props.Compile_dex = module.Library.Module.deviceProperties.Compile_dex
Sundong Ahndd567f92018-07-31 17:19:11 +0900480 }
Jiyong Parkc678ad32018-04-10 13:07:10 +0900481
482 if module.SocSpecific() {
483 props.Soc_specific = proptools.BoolPtr(true)
484 } else if module.DeviceSpecific() {
485 props.Device_specific = proptools.BoolPtr(true)
486 } else if module.ProductSpecific() {
487 props.Product_specific = proptools.BoolPtr(true)
Sundong Ahn0d7dff42019-12-04 12:53:44 +0900488 } else if module.SystemExtSpecific() {
489 props.System_ext_specific = proptools.BoolPtr(true)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900490 }
491
Colin Cross84dfc3d2019-09-25 11:33:01 -0700492 mctx.CreateModule(LibraryFactory, &props)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900493}
494
495// Creates a droiddoc module that creates stubs source files from the given full source
496// files
Paul Duffinc4cea762019-12-30 17:32:47 +0000497func (module *SdkLibrary) createStubsSources(mctx android.LoadHookContext, apiScope apiScope) {
Jiyong Parkc678ad32018-04-10 13:07:10 +0900498 props := struct {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900499 Name *string
500 Srcs []string
501 Installable *bool
Paul Duffin52d398a2019-06-11 12:31:14 +0100502 Sdk_version *string
Paul Duffin12ceb462019-12-24 20:31:31 +0000503 System_modules *string
Sundong Ahn054b19a2018-10-19 13:46:09 +0900504 Libs []string
Paul Duffin11512472019-02-11 15:55:17 +0000505 Arg_files []string
Sundong Ahn054b19a2018-10-19 13:46:09 +0900506 Args *string
507 Api_tag_name *string
508 Api_filename *string
509 Removed_api_filename *string
Sundong Ahn054b19a2018-10-19 13:46:09 +0900510 Java_version *string
511 Merge_annotations_dirs []string
512 Merge_inclusion_annotations_dirs []string
513 Check_api struct {
Inseob Kim38449af2019-02-28 14:24:05 +0900514 Current ApiToCheck
515 Last_released ApiToCheck
516 Ignore_missing_latest_api *bool
Jiyong Park58c518b2018-05-12 22:29:12 +0900517 }
Sundong Ahn1b92c822018-05-29 11:35:17 +0900518 Aidl struct {
519 Include_dirs []string
520 Local_include_dirs []string
521 }
Jiyong Parkc678ad32018-04-10 13:07:10 +0900522 }{}
523
Paul Duffin250e6192019-06-07 10:44:37 +0100524 sdkDep := decodeSdkDep(mctx, sdkContext(&module.Library))
Paul Duffin12ceb462019-12-24 20:31:31 +0000525 // Use the platform API if standard libraries were requested, otherwise use
526 // no default libraries.
Paul Duffin52d398a2019-06-11 12:31:14 +0100527 sdkVersion := ""
528 if !sdkDep.hasStandardLibs() {
529 sdkVersion = "none"
530 }
Paul Duffin250e6192019-06-07 10:44:37 +0100531
Jiyong Parkdf130542018-04-27 16:29:21 +0900532 props.Name = proptools.StringPtr(module.docsName(apiScope))
Sundong Ahn054b19a2018-10-19 13:46:09 +0900533 props.Srcs = append(props.Srcs, module.Library.Module.properties.Srcs...)
Paul Duffin52d398a2019-06-11 12:31:14 +0100534 props.Sdk_version = proptools.StringPtr(sdkVersion)
Paul Duffin12ceb462019-12-24 20:31:31 +0000535 props.System_modules = module.Library.Module.deviceProperties.System_modules
Jiyong Parkc678ad32018-04-10 13:07:10 +0900536 props.Installable = proptools.BoolPtr(false)
Sundong Ahne6f0b052018-06-05 16:46:14 +0900537 // A droiddoc module has only one Libs property and doesn't distinguish between
538 // shared libs and static libs. So we need to add both of these libs to Libs property.
Sundong Ahn054b19a2018-10-19 13:46:09 +0900539 props.Libs = module.Library.Module.properties.Libs
540 props.Libs = append(props.Libs, module.Library.Module.properties.Static_libs...)
541 props.Aidl.Include_dirs = module.Library.Module.deviceProperties.Aidl.Include_dirs
542 props.Aidl.Local_include_dirs = module.Library.Module.deviceProperties.Aidl.Local_include_dirs
Sundong Ahn054b19a2018-10-19 13:46:09 +0900543 props.Java_version = module.Library.Module.properties.Java_version
Jiyong Parkc678ad32018-04-10 13:07:10 +0900544
Sundong Ahn054b19a2018-10-19 13:46:09 +0900545 props.Merge_annotations_dirs = module.sdkLibraryProperties.Merge_annotations_dirs
546 props.Merge_inclusion_annotations_dirs = module.sdkLibraryProperties.Merge_inclusion_annotations_dirs
547
Paul Duffin235ffff2019-12-24 10:41:30 +0000548 droiddocArgs := []string{}
549 if len(module.sdkLibraryProperties.Api_packages) != 0 {
550 droiddocArgs = append(droiddocArgs, "--stub-packages "+strings.Join(module.sdkLibraryProperties.Api_packages, ":"))
551 }
552 if len(module.sdkLibraryProperties.Hidden_api_packages) != 0 {
553 droiddocArgs = append(droiddocArgs,
554 android.JoinWithPrefix(module.sdkLibraryProperties.Hidden_api_packages, " --hide-package "))
555 }
556 droiddocArgs = append(droiddocArgs, module.sdkLibraryProperties.Droiddoc_options...)
557 disabledWarnings := []string{
558 "MissingPermission",
559 "BroadcastBehavior",
560 "HiddenSuperclass",
561 "DeprecationMismatch",
562 "UnavailableSymbol",
563 "SdkConstant",
564 "HiddenTypeParameter",
565 "Todo",
566 "Typo",
567 }
568 droiddocArgs = append(droiddocArgs, android.JoinWithPrefix(disabledWarnings, "--hide "))
Sundong Ahnfb2721f2018-09-17 13:23:09 +0900569
Jiyong Parkdf130542018-04-27 16:29:21 +0900570 switch apiScope {
571 case apiScopeSystem:
Paul Duffin235ffff2019-12-24 10:41:30 +0000572 droiddocArgs = append(droiddocArgs, "-showAnnotation android.annotation.SystemApi")
Jiyong Parkdf130542018-04-27 16:29:21 +0900573 case apiScopeTest:
Paul Duffin235ffff2019-12-24 10:41:30 +0000574 droiddocArgs = append(droiddocArgs, " -showAnnotation android.annotation.TestApi")
Jiyong Parkc678ad32018-04-10 13:07:10 +0900575 }
Paul Duffin11512472019-02-11 15:55:17 +0000576 props.Arg_files = module.sdkLibraryProperties.Droiddoc_option_files
Paul Duffin235ffff2019-12-24 10:41:30 +0000577 props.Args = proptools.StringPtr(strings.Join(droiddocArgs, " "))
Jiyong Parkc678ad32018-04-10 13:07:10 +0900578
579 // List of APIs identified from the provided source files are created. They are later
580 // compared against to the not-yet-released (a.k.a current) list of APIs and to the
581 // last-released (a.k.a numbered) list of API.
Jiyong Parkc678ad32018-04-10 13:07:10 +0900582 currentApiFileName := "current.txt"
583 removedApiFileName := "removed.txt"
Jiyong Parkdf130542018-04-27 16:29:21 +0900584 switch apiScope {
585 case apiScopeSystem:
Jiyong Parkc678ad32018-04-10 13:07:10 +0900586 currentApiFileName = "system-" + currentApiFileName
587 removedApiFileName = "system-" + removedApiFileName
Jiyong Parkdf130542018-04-27 16:29:21 +0900588 case apiScopeTest:
589 currentApiFileName = "test-" + currentApiFileName
590 removedApiFileName = "test-" + removedApiFileName
Jiyong Parkc678ad32018-04-10 13:07:10 +0900591 }
Paul Duffin749f98f2019-12-30 17:23:46 +0000592 apiDir := module.getApiDir()
593 currentApiFileName = path.Join(apiDir, currentApiFileName)
594 removedApiFileName = path.Join(apiDir, removedApiFileName)
Jiyong Park58c518b2018-05-12 22:29:12 +0900595 // TODO(jiyong): remove these three props
Jiyong Parkdf130542018-04-27 16:29:21 +0900596 props.Api_tag_name = proptools.StringPtr(module.apiTagName(apiScope))
Jiyong Parkc678ad32018-04-10 13:07:10 +0900597 props.Api_filename = proptools.StringPtr(currentApiFileName)
598 props.Removed_api_filename = proptools.StringPtr(removedApiFileName)
599
Jiyong Park58c518b2018-05-12 22:29:12 +0900600 // check against the not-yet-release API
601 props.Check_api.Current.Api_file = proptools.StringPtr(currentApiFileName)
602 props.Check_api.Current.Removed_api_file = proptools.StringPtr(removedApiFileName)
Jiyong Park58c518b2018-05-12 22:29:12 +0900603
604 // check against the latest released API
605 props.Check_api.Last_released.Api_file = proptools.StringPtr(
606 module.latestApiFilegroupName(apiScope))
607 props.Check_api.Last_released.Removed_api_file = proptools.StringPtr(
608 module.latestRemovedApiFilegroupName(apiScope))
Inseob Kim38449af2019-02-28 14:24:05 +0900609 props.Check_api.Ignore_missing_latest_api = proptools.BoolPtr(true)
Jiyong Park58c518b2018-05-12 22:29:12 +0900610
Colin Cross84dfc3d2019-09-25 11:33:01 -0700611 mctx.CreateModule(DroidstubsFactory, &props)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900612}
613
Jiyong Parkc678ad32018-04-10 13:07:10 +0900614// Creates the xml file that publicizes the runtime library
Colin Crossf8b860a2019-04-16 14:43:28 -0700615func (module *SdkLibrary) createXmlFile(mctx android.LoadHookContext) {
Jiyong Parkc678ad32018-04-10 13:07:10 +0900616 // creates a prebuilt_etc module to actually place the xml file under
617 // <partition>/etc/permissions
618 etcProps := struct {
Sundong Ahn0d7dff42019-12-04 12:53:44 +0900619 Name *string
620 Src *string
621 Sub_dir *string
622 Soc_specific *bool
623 Device_specific *bool
624 Product_specific *bool
625 System_ext_specific *bool
Jiyong Parkc678ad32018-04-10 13:07:10 +0900626 }{}
627 etcProps.Name = proptools.StringPtr(module.xmlFileName())
Jooyung Han624058e2019-12-24 18:38:06 +0900628 etcProps.Src = proptools.StringPtr(":" + module.BaseModuleName() + "{.xml}")
Jiyong Parkc678ad32018-04-10 13:07:10 +0900629 etcProps.Sub_dir = proptools.StringPtr("permissions")
630 if module.SocSpecific() {
631 etcProps.Soc_specific = proptools.BoolPtr(true)
632 } else if module.DeviceSpecific() {
633 etcProps.Device_specific = proptools.BoolPtr(true)
634 } else if module.ProductSpecific() {
635 etcProps.Product_specific = proptools.BoolPtr(true)
Sundong Ahn0d7dff42019-12-04 12:53:44 +0900636 } else if module.SystemExtSpecific() {
637 etcProps.System_ext_specific = proptools.BoolPtr(true)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900638 }
Colin Cross84dfc3d2019-09-25 11:33:01 -0700639 mctx.CreateModule(android.PrebuiltEtcFactory, &etcProps)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900640}
641
Colin Cross0ea8ba82019-06-06 14:33:29 -0700642func (module *SdkLibrary) PrebuiltJars(ctx android.BaseModuleContext, sdkVersion string) android.Paths {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900643 var api, v string
Paul Duffin52d398a2019-06-11 12:31:14 +0100644 if sdkVersion == "" || sdkVersion == "none" {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900645 api = "system"
646 v = "current"
647 } else if strings.Contains(sdkVersion, "_") {
648 t := strings.Split(sdkVersion, "_")
649 api = t[0]
650 v = t[1]
Jiyong Parkc678ad32018-04-10 13:07:10 +0900651 } else {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900652 api = "public"
653 v = sdkVersion
654 }
655 dir := filepath.Join("prebuilts", "sdk", v, api)
656 jar := filepath.Join(dir, module.BaseModuleName()+".jar")
657 jarPath := android.ExistentPathForSource(ctx, jar)
Sundong Ahnae418ac2019-02-28 15:01:28 +0900658 if !jarPath.Valid() {
659 ctx.PropertyErrorf("sdk_library", "invalid sdk version %q, %q does not exist", v, jar)
660 return nil
661 }
Sundong Ahn054b19a2018-10-19 13:46:09 +0900662 return android.Paths{jarPath.Path()}
663}
664
665// to satisfy SdkLibraryDependency interface
Colin Cross0ea8ba82019-06-06 14:33:29 -0700666func (module *SdkLibrary) SdkHeaderJars(ctx android.BaseModuleContext, sdkVersion string) android.Paths {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900667 // This module is just a wrapper for the stubs.
Colin Cross10932872019-04-18 14:27:12 -0700668 if ctx.Config().UnbundledBuildUsePrebuiltSdks() {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900669 return module.PrebuiltJars(ctx, sdkVersion)
670 } else {
671 if strings.HasPrefix(sdkVersion, "system_") {
672 return module.systemApiStubsPath
673 } else if sdkVersion == "" {
674 return module.Library.HeaderJars()
675 } else {
676 return module.publicApiStubsPath
677 }
Jiyong Parkc678ad32018-04-10 13:07:10 +0900678 }
679}
680
Sundong Ahn241cd372018-07-13 16:16:44 +0900681// to satisfy SdkLibraryDependency interface
Colin Cross0ea8ba82019-06-06 14:33:29 -0700682func (module *SdkLibrary) SdkImplementationJars(ctx android.BaseModuleContext, sdkVersion string) android.Paths {
Sundong Ahn241cd372018-07-13 16:16:44 +0900683 // This module is just a wrapper for the stubs.
Colin Cross10932872019-04-18 14:27:12 -0700684 if ctx.Config().UnbundledBuildUsePrebuiltSdks() {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900685 return module.PrebuiltJars(ctx, sdkVersion)
Sundong Ahn241cd372018-07-13 16:16:44 +0900686 } else {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900687 if strings.HasPrefix(sdkVersion, "system_") {
688 return module.systemApiStubsImplPath
689 } else if sdkVersion == "" {
690 return module.Library.ImplementationJars()
691 } else {
692 return module.publicApiStubsImplPath
693 }
Sundong Ahn241cd372018-07-13 16:16:44 +0900694 }
695}
696
Sundong Ahn80a87b32019-05-13 15:02:50 +0900697func (module *SdkLibrary) SetNoDist() {
698 module.sdkLibraryProperties.No_dist = proptools.BoolPtr(true)
699}
700
Colin Cross571cccf2019-02-04 11:22:08 -0800701var javaSdkLibrariesKey = android.NewOnceKey("javaSdkLibraries")
702
Jiyong Park82484c02018-04-23 21:41:26 +0900703func javaSdkLibraries(config android.Config) *[]string {
Colin Cross571cccf2019-02-04 11:22:08 -0800704 return config.Once(javaSdkLibrariesKey, func() interface{} {
Jiyong Park82484c02018-04-23 21:41:26 +0900705 return &[]string{}
706 }).(*[]string)
707}
708
Paul Duffin749f98f2019-12-30 17:23:46 +0000709func (module *SdkLibrary) getApiDir() string {
710 return proptools.StringDefault(module.sdkLibraryProperties.Api_dir, "api")
711}
712
Jiyong Parkc678ad32018-04-10 13:07:10 +0900713// For a java_sdk_library module, create internal modules for stubs, docs,
714// runtime libs and xml file. If requested, the stubs and docs are created twice
715// once for public API level and once for system API level
Colin Crossf8b860a2019-04-16 14:43:28 -0700716func (module *SdkLibrary) CreateInternalModules(mctx android.LoadHookContext) {
Inseob Kim6e93ac92019-03-21 17:43:49 +0900717 if len(module.Library.Module.properties.Srcs) == 0 {
Inseob Kimc0907f12019-02-08 21:00:45 +0900718 mctx.PropertyErrorf("srcs", "java_sdk_library must specify srcs")
Jooyung Han58f26ab2019-12-18 15:34:32 +0900719 return
Inseob Kimc0907f12019-02-08 21:00:45 +0900720 }
721
Paul Duffin37e0b772019-12-30 17:20:10 +0000722 // If this builds against standard libraries (i.e. is not part of the core libraries)
723 // then assume it provides both system and test apis. Otherwise, assume it does not and
724 // also assume it does not contribute to the dist build.
725 sdkDep := decodeSdkDep(mctx, sdkContext(&module.Library))
726 hasSystemAndTestApis := sdkDep.hasStandardLibs()
727 module.sdkLibraryProperties.Has_system_and_test_apis = hasSystemAndTestApis
728 module.sdkLibraryProperties.No_dist = proptools.BoolPtr(!hasSystemAndTestApis)
729
730 scopes := []string{""}
731 if hasSystemAndTestApis {
732 scopes = append(scopes, "system-", "test-")
733 }
734
Inseob Kim8098faa2019-03-18 10:19:51 +0900735 missing_current_api := false
736
Paul Duffin749f98f2019-12-30 17:23:46 +0000737 apiDir := module.getApiDir()
Paul Duffin37e0b772019-12-30 17:20:10 +0000738 for _, scope := range scopes {
Inseob Kim8098faa2019-03-18 10:19:51 +0900739 for _, api := range []string{"current.txt", "removed.txt"} {
Paul Duffin749f98f2019-12-30 17:23:46 +0000740 path := path.Join(mctx.ModuleDir(), apiDir, scope+api)
Inseob Kim8098faa2019-03-18 10:19:51 +0900741 p := android.ExistentPathForSource(mctx, path)
742 if !p.Valid() {
743 mctx.ModuleErrorf("Current api file %#v doesn't exist", path)
744 missing_current_api = true
745 }
746 }
747 }
748
749 if missing_current_api {
750 script := "build/soong/scripts/gen-java-current-api-files.sh"
751 p := android.ExistentPathForSource(mctx, script)
752
753 if !p.Valid() {
754 panic(fmt.Sprintf("script file %s doesn't exist", script))
755 }
756
757 mctx.ModuleErrorf("One or more current api files are missing. "+
758 "You can update them by:\n"+
Paul Duffin37e0b772019-12-30 17:20:10 +0000759 "%s %q %s && m update-api",
Paul Duffin749f98f2019-12-30 17:23:46 +0000760 script, filepath.Join(mctx.ModuleDir(), apiDir), strings.Join(scopes, " "))
Inseob Kim8098faa2019-03-18 10:19:51 +0900761 return
762 }
763
Inseob Kimc0907f12019-02-08 21:00:45 +0900764 // for public API stubs
765 module.createStubsLibrary(mctx, apiScopePublic)
Paul Duffinc4cea762019-12-30 17:32:47 +0000766 module.createStubsSources(mctx, apiScopePublic)
Inseob Kimc0907f12019-02-08 21:00:45 +0900767
Paul Duffin37e0b772019-12-30 17:20:10 +0000768 if hasSystemAndTestApis {
Inseob Kimc0907f12019-02-08 21:00:45 +0900769 // for system API stubs
770 module.createStubsLibrary(mctx, apiScopeSystem)
Paul Duffinc4cea762019-12-30 17:32:47 +0000771 module.createStubsSources(mctx, apiScopeSystem)
Inseob Kimc0907f12019-02-08 21:00:45 +0900772
773 // for test API stubs
774 module.createStubsLibrary(mctx, apiScopeTest)
Paul Duffinc4cea762019-12-30 17:32:47 +0000775 module.createStubsSources(mctx, apiScopeTest)
Inseob Kimc0907f12019-02-08 21:00:45 +0900776
777 // for runtime
778 module.createXmlFile(mctx)
779 }
780
781 // record java_sdk_library modules so that they are exported to make
782 javaSdkLibraries := javaSdkLibraries(mctx.Config())
783 javaSdkLibrariesLock.Lock()
784 defer javaSdkLibrariesLock.Unlock()
785 *javaSdkLibraries = append(*javaSdkLibraries, module.BaseModuleName())
786}
787
788func (module *SdkLibrary) InitSdkLibraryProperties() {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900789 module.AddProperties(
790 &module.sdkLibraryProperties,
791 &module.Library.Module.properties,
792 &module.Library.Module.dexpreoptProperties,
793 &module.Library.Module.deviceProperties,
794 &module.Library.Module.protoProperties,
795 )
796
797 module.Library.Module.properties.Installable = proptools.BoolPtr(true)
798 module.Library.Module.deviceProperties.IsSDKLibrary = true
Inseob Kimc0907f12019-02-08 21:00:45 +0900799}
Sundong Ahn054b19a2018-10-19 13:46:09 +0900800
Jaewoong Jung4f158ee2019-07-11 10:05:35 -0700801// java_sdk_library is a special Java library that provides optional platform APIs to apps.
802// In practice, it can be viewed as a combination of several modules: 1) stubs library that clients
803// are linked against to, 2) droiddoc module that internally generates API stubs source files,
804// 3) the real runtime shared library that implements the APIs, and 4) XML file for adding
805// the runtime lib to the classpath at runtime if requested via <uses-library>.
Inseob Kimc0907f12019-02-08 21:00:45 +0900806func SdkLibraryFactory() android.Module {
807 module := &SdkLibrary{}
808 module.InitSdkLibraryProperties()
Jooyung Han58f26ab2019-12-18 15:34:32 +0900809 android.InitApexModule(module)
Sundong Ahn054b19a2018-10-19 13:46:09 +0900810 InitJavaModule(module, android.HostAndDeviceSupported)
Colin Crossf8b860a2019-04-16 14:43:28 -0700811 android.AddLoadHook(module, func(ctx android.LoadHookContext) { module.CreateInternalModules(ctx) })
Jiyong Parkc678ad32018-04-10 13:07:10 +0900812 return module
813}
Colin Cross79c7c262019-04-17 11:11:46 -0700814
815//
816// SDK library prebuilts
817//
818
819type sdkLibraryImportProperties struct {
820 Jars []string `android:"path"`
821
822 Sdk_version *string
823
824 Installable *bool
825
826 // List of shared java libs that this module has dependencies to
827 Libs []string
828
829 // List of files to remove from the jar file(s)
830 Exclude_files []string
831
832 // List of directories to remove from the jar file(s)
833 Exclude_dirs []string
834}
835
836type sdkLibraryImport struct {
837 android.ModuleBase
838 android.DefaultableModuleBase
839 prebuilt android.Prebuilt
840
841 properties sdkLibraryImportProperties
842
843 stubsPath android.Paths
844}
845
846var _ SdkLibraryDependency = (*sdkLibraryImport)(nil)
847
Jaewoong Jung4f158ee2019-07-11 10:05:35 -0700848// java_sdk_library_import imports a prebuilt java_sdk_library.
Colin Cross79c7c262019-04-17 11:11:46 -0700849func sdkLibraryImportFactory() android.Module {
850 module := &sdkLibraryImport{}
851
852 module.AddProperties(&module.properties)
853
854 android.InitPrebuiltModule(module, &module.properties.Jars)
855 InitJavaModule(module, android.HostAndDeviceSupported)
856
857 android.AddLoadHook(module, func(mctx android.LoadHookContext) { module.createInternalModules(mctx) })
858 return module
859}
860
861func (module *sdkLibraryImport) Prebuilt() *android.Prebuilt {
862 return &module.prebuilt
863}
864
865func (module *sdkLibraryImport) Name() string {
866 return module.prebuilt.Name(module.ModuleBase.Name())
867}
868
869func (module *sdkLibraryImport) createInternalModules(mctx android.LoadHookContext) {
870 // Creates a java import for the jar with ".stubs" suffix
871 props := struct {
Sundong Ahn0d7dff42019-12-04 12:53:44 +0900872 Name *string
873 Soc_specific *bool
874 Device_specific *bool
875 Product_specific *bool
876 System_ext_specific *bool
Colin Cross79c7c262019-04-17 11:11:46 -0700877 }{}
878
879 props.Name = proptools.StringPtr(module.BaseModuleName() + sdkStubsLibrarySuffix)
880
881 if module.SocSpecific() {
882 props.Soc_specific = proptools.BoolPtr(true)
883 } else if module.DeviceSpecific() {
884 props.Device_specific = proptools.BoolPtr(true)
885 } else if module.ProductSpecific() {
886 props.Product_specific = proptools.BoolPtr(true)
Sundong Ahn0d7dff42019-12-04 12:53:44 +0900887 } else if module.SystemExtSpecific() {
888 props.System_ext_specific = proptools.BoolPtr(true)
Colin Cross79c7c262019-04-17 11:11:46 -0700889 }
890
Colin Cross84dfc3d2019-09-25 11:33:01 -0700891 mctx.CreateModule(ImportFactory, &props, &module.properties)
Colin Cross79c7c262019-04-17 11:11:46 -0700892
893 javaSdkLibraries := javaSdkLibraries(mctx.Config())
894 javaSdkLibrariesLock.Lock()
895 defer javaSdkLibrariesLock.Unlock()
896 *javaSdkLibraries = append(*javaSdkLibraries, module.BaseModuleName())
897}
898
899func (module *sdkLibraryImport) DepsMutator(ctx android.BottomUpMutatorContext) {
900 // Add dependencies to the prebuilt stubs library
901 ctx.AddVariationDependencies(nil, publicApiStubsTag, module.BaseModuleName()+sdkStubsLibrarySuffix)
902}
903
904func (module *sdkLibraryImport) GenerateAndroidBuildActions(ctx android.ModuleContext) {
905 // Record the paths to the prebuilt stubs library.
906 ctx.VisitDirectDeps(func(to android.Module) {
907 tag := ctx.OtherModuleDependencyTag(to)
908
909 switch tag {
910 case publicApiStubsTag:
911 module.stubsPath = to.(Dependency).HeaderJars()
912 }
913 })
914}
915
916// to satisfy SdkLibraryDependency interface
Colin Cross0ea8ba82019-06-06 14:33:29 -0700917func (module *sdkLibraryImport) SdkHeaderJars(ctx android.BaseModuleContext, sdkVersion string) android.Paths {
Colin Cross79c7c262019-04-17 11:11:46 -0700918 // This module is just a wrapper for the prebuilt stubs.
919 return module.stubsPath
920}
921
922// to satisfy SdkLibraryDependency interface
Colin Cross0ea8ba82019-06-06 14:33:29 -0700923func (module *sdkLibraryImport) SdkImplementationJars(ctx android.BaseModuleContext, sdkVersion string) android.Paths {
Colin Cross79c7c262019-04-17 11:11:46 -0700924 // This module is just a wrapper for the stubs.
925 return module.stubsPath
926}