blob: 67c052f9525f884af724efc9066db34fff489c48 [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"
19 "android/soong/genrule"
20 "fmt"
Jiyong Park82484c02018-04-23 21:41:26 +090021 "io"
Jiyong Parkc678ad32018-04-10 13:07:10 +090022 "path"
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
31var (
32 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"
36 sdkImplLibrarySuffix = ".impl"
37 sdkXmlFileSuffix = ".xml"
38)
39
40type stubsLibraryDependencyTag struct {
41 blueprint.BaseDependencyTag
42 name string
43}
44
45var (
46 publicApiStubsTag = dependencyTag{name: "public"}
47 systemApiStubsTag = dependencyTag{name: "system"}
Jiyong Parkdf130542018-04-27 16:29:21 +090048 testApiStubsTag = dependencyTag{name: "test"}
49)
50
51type apiScope int
52
53const (
54 apiScopePublic apiScope = iota
55 apiScopeSystem
56 apiScopeTest
Jiyong Parkc678ad32018-04-10 13:07:10 +090057)
58
Jiyong Park82484c02018-04-23 21:41:26 +090059var (
60 javaSdkLibrariesLock sync.Mutex
61)
62
Jiyong Parkc678ad32018-04-10 13:07:10 +090063// java_sdk_library is to make a Java library that implements optional platform APIs to apps.
64// It is actually a wrapper of several modules: 1) stubs library that clients are linked against
65// to, 2) droiddoc module that internally generates API stubs source files, 3) the real runtime
66// shared library that implements the APIs, and 4) XML file for adding the runtime lib to the
67// classpath at runtime if requested via <uses-library>.
68//
69// TODO: these are big features that are currently missing
70// 1) check for API consistency
71// 2) install stubs libs as the dist artifacts
72// 3) ensuring that apps have appropriate <uses-library> tag
73// 4) disallowing linking to the runtime shared lib
74// 5) HTML generation
75
76func init() {
77 android.RegisterModuleType("java_sdk_library", sdkLibraryFactory)
78
79 android.PreArchMutators(func(ctx android.RegisterMutatorsContext) {
80 ctx.TopDown("java_sdk_library", sdkLibraryMutator).Parallel()
81 })
Jiyong Park82484c02018-04-23 21:41:26 +090082
83 android.RegisterMakeVarsProvider(pctx, func(ctx android.MakeVarsContext) {
84 javaSdkLibraries := javaSdkLibraries(ctx.Config())
85 sort.Strings(*javaSdkLibraries)
86 ctx.Strict("JAVA_SDK_LIBRARIES", strings.Join(*javaSdkLibraries, " "))
87 })
Jiyong Parkc678ad32018-04-10 13:07:10 +090088}
89
90type sdkLibraryProperties struct {
91 // list of source files used to compile the Java module. May be .java, .logtags, .proto,
92 // or .aidl files.
93 Srcs []string `android:"arch_variant"`
94
95 // list of of java libraries that will be in the classpath
96 Libs []string `android:"arch_variant"`
97
98 // list of java libraries that will be compiled into the resulting runtime jar.
99 // These libraries are not compiled into the stubs jar.
100 Static_libs []string `android:"arch_variant"`
101
102 // list of package names that will be documented and publicized as API
103 Api_packages []string
104
Jiyong Park5a2c9d72018-05-01 22:25:41 +0900105 // list of package names that must be hidden from the API
106 Hidden_api_packages []string
107
Jiyong Parkc678ad32018-04-10 13:07:10 +0900108 // TODO: determines whether to create HTML doc or not
109 //Html_doc *bool
110}
111
112type sdkLibrary struct {
113 android.ModuleBase
114 android.DefaultableModuleBase
115
Jiyong Park441a47d2018-05-01 23:33:08 +0900116 properties sdkLibraryProperties
117 deviceProperties CompilerDeviceProperties
Jiyong Parkc678ad32018-04-10 13:07:10 +0900118
119 publicApiStubsPath android.Paths
120 systemApiStubsPath android.Paths
Jiyong Parkdf130542018-04-27 16:29:21 +0900121 testApiStubsPath android.Paths
Jiyong Parkc678ad32018-04-10 13:07:10 +0900122}
123
124func (module *sdkLibrary) DepsMutator(ctx android.BottomUpMutatorContext) {
125 // Add dependencies to the stubs library
Jiyong Parkdf130542018-04-27 16:29:21 +0900126 ctx.AddDependency(ctx.Module(), publicApiStubsTag, module.stubsName(apiScopePublic))
127 ctx.AddDependency(ctx.Module(), systemApiStubsTag, module.stubsName(apiScopeSystem))
128 ctx.AddDependency(ctx.Module(), testApiStubsTag, module.stubsName(apiScopeTest))
Jiyong Parkc678ad32018-04-10 13:07:10 +0900129}
130
131func (module *sdkLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
132 // Record the paths to the header jars of the stubs library.
133 // When this java_sdk_library is dependened from others via "libs" property,
134 // the recorded paths will be returned depending on the link type of the caller.
135 ctx.VisitDirectDeps(func(to android.Module) {
136 otherName := ctx.OtherModuleName(to)
137 tag := ctx.OtherModuleDependencyTag(to)
138
139 if stubs, ok := to.(Dependency); ok {
140 switch tag {
141 case publicApiStubsTag:
142 module.publicApiStubsPath = stubs.HeaderJars()
143 case systemApiStubsTag:
144 module.systemApiStubsPath = stubs.HeaderJars()
Jiyong Parkdf130542018-04-27 16:29:21 +0900145 case testApiStubsTag:
146 module.testApiStubsPath = stubs.HeaderJars()
Jiyong Parkc678ad32018-04-10 13:07:10 +0900147 default:
148 ctx.ModuleErrorf("depends on module %q of unknown tag %q", otherName, tag)
149 }
150 }
151 })
152}
153
Jiyong Park82484c02018-04-23 21:41:26 +0900154func (module *sdkLibrary) AndroidMk() android.AndroidMkData {
155 // Create a phony module that installs the impl library, for the case when this lib is
156 // in PRODUCT_PACKAGES.
157 return android.AndroidMkData{
158 Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
159 fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)")
160 fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir)
161 fmt.Fprintln(w, "LOCAL_MODULE :=", name)
162 fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES := "+module.implName())
163 fmt.Fprintln(w, "include $(BUILD_PHONY_PACKAGE)")
164 },
165 }
166}
167
Jiyong Parkc678ad32018-04-10 13:07:10 +0900168// Module name of the stubs library
Jiyong Parkdf130542018-04-27 16:29:21 +0900169func (module *sdkLibrary) stubsName(apiScope apiScope) string {
Jiyong Parkc678ad32018-04-10 13:07:10 +0900170 stubsName := module.BaseModuleName() + sdkStubsLibrarySuffix
Jiyong Parkdf130542018-04-27 16:29:21 +0900171 switch apiScope {
172 case apiScopeSystem:
Jiyong Parkc678ad32018-04-10 13:07:10 +0900173 stubsName = stubsName + sdkSystemApiSuffix
Jiyong Parkdf130542018-04-27 16:29:21 +0900174 case apiScopeTest:
175 stubsName = stubsName + sdkTestApiSuffix
Jiyong Parkc678ad32018-04-10 13:07:10 +0900176 }
177 return stubsName
178}
179
180// Module name of the docs
Jiyong Parkdf130542018-04-27 16:29:21 +0900181func (module *sdkLibrary) docsName(apiScope apiScope) string {
Jiyong Parkc678ad32018-04-10 13:07:10 +0900182 docsName := module.BaseModuleName() + sdkDocsSuffix
Jiyong Parkdf130542018-04-27 16:29:21 +0900183 switch apiScope {
184 case apiScopeSystem:
Jiyong Parkc678ad32018-04-10 13:07:10 +0900185 docsName = docsName + sdkSystemApiSuffix
Jiyong Parkdf130542018-04-27 16:29:21 +0900186 case apiScopeTest:
187 docsName = docsName + sdkTestApiSuffix
Jiyong Parkc678ad32018-04-10 13:07:10 +0900188 }
189 return docsName
190}
191
192// Module name of the runtime implementation library
193func (module *sdkLibrary) implName() string {
194 return module.BaseModuleName() + sdkImplLibrarySuffix
195}
196
197// File path to the runtime implementation library
198func (module *sdkLibrary) implPath() string {
199 partition := "system"
200 if module.SocSpecific() {
201 partition = "vendor"
202 } else if module.DeviceSpecific() {
203 partition = "odm"
204 } else if module.ProductSpecific() {
205 partition = "product"
206 }
207 return "/" + partition + "/framework/" + module.implName() + ".jar"
208}
209
210// Module name of the XML file for the lib
211func (module *sdkLibrary) xmlFileName() string {
212 return module.BaseModuleName() + sdkXmlFileSuffix
213}
214
215// SDK version that the stubs library is built against. Note that this is always
216// *current. Older stubs library built with a numberd SDK version is created from
217// the prebuilt jar.
Jiyong Parkdf130542018-04-27 16:29:21 +0900218func (module *sdkLibrary) sdkVersion(apiScope apiScope) string {
219 switch apiScope {
220 case apiScopePublic:
221 return "current"
222 case apiScopeSystem:
Jiyong Parkc678ad32018-04-10 13:07:10 +0900223 return "system_current"
Jiyong Parkdf130542018-04-27 16:29:21 +0900224 case apiScopeTest:
225 return "test_current"
226 default:
Jiyong Parkc678ad32018-04-10 13:07:10 +0900227 return "current"
228 }
229}
230
231// $(INTERNAL_PLATFORM_<apiTagName>_API_FILE) points to the generated
232// api file for the current source
233// TODO: remove this when apicheck is done in soong
Jiyong Parkdf130542018-04-27 16:29:21 +0900234func (module *sdkLibrary) apiTagName(apiScope apiScope) string {
Jiyong Parkc678ad32018-04-10 13:07:10 +0900235 apiTagName := strings.Replace(strings.ToUpper(module.BaseModuleName()), ".", "_", -1)
Jiyong Parkdf130542018-04-27 16:29:21 +0900236 switch apiScope {
237 case apiScopeSystem:
Jiyong Parkc678ad32018-04-10 13:07:10 +0900238 apiTagName = apiTagName + "_SYSTEM"
Jiyong Parkdf130542018-04-27 16:29:21 +0900239 case apiScopeTest:
240 apiTagName = apiTagName + "_TEST"
Jiyong Parkc678ad32018-04-10 13:07:10 +0900241 }
242 return apiTagName
243}
244
245// returns the path (relative to this module) to the API txt file. Files are located
246// ./<api_dir>/<api_level>.txt where <api_level> is either current, system-current, removed,
247// or system-removed.
Jiyong Parkdf130542018-04-27 16:29:21 +0900248func (module *sdkLibrary) apiFilePath(apiLevel string, apiScope apiScope) string {
Jiyong Parkc678ad32018-04-10 13:07:10 +0900249 apiDir := "api"
250 apiFile := apiLevel
Jiyong Parkdf130542018-04-27 16:29:21 +0900251 switch apiScope {
252 case apiScopeSystem:
Jiyong Parkc678ad32018-04-10 13:07:10 +0900253 apiFile = "system-" + apiFile
Jiyong Parkdf130542018-04-27 16:29:21 +0900254 case apiScopeTest:
255 apiFile = "test-" + apiFile
Jiyong Parkc678ad32018-04-10 13:07:10 +0900256 }
257 apiFile = apiFile + ".txt"
258
259 return path.Join(apiDir, apiFile)
260}
261
262// Creates a static java library that has API stubs
Jiyong Parkdf130542018-04-27 16:29:21 +0900263func (module *sdkLibrary) createStubsLibrary(mctx android.TopDownMutatorContext, apiScope apiScope) {
Jiyong Parkc678ad32018-04-10 13:07:10 +0900264 props := struct {
265 Name *string
266 Srcs []string
267 Sdk_version *string
268 Soc_specific *bool
269 Device_specific *bool
270 Product_specific *bool
271 Product_variables struct {
272 Unbundled_build struct {
273 Enabled *bool
274 }
Jiyong Park82484c02018-04-23 21:41:26 +0900275 Pdk struct {
276 Enabled *bool
277 }
Jiyong Parkc678ad32018-04-10 13:07:10 +0900278 }
279 }{}
280
Jiyong Parkdf130542018-04-27 16:29:21 +0900281 props.Name = proptools.StringPtr(module.stubsName(apiScope))
Jiyong Parkc678ad32018-04-10 13:07:10 +0900282 // sources are generated from the droiddoc
Jiyong Parkdf130542018-04-27 16:29:21 +0900283 props.Srcs = []string{":" + module.docsName(apiScope)}
284 props.Sdk_version = proptools.StringPtr(module.sdkVersion(apiScope))
Jiyong Parkc678ad32018-04-10 13:07:10 +0900285 // Unbundled apps will use the prebult one from /prebuilts/sdk
286 props.Product_variables.Unbundled_build.Enabled = proptools.BoolPtr(false)
Jiyong Park82484c02018-04-23 21:41:26 +0900287 props.Product_variables.Pdk.Enabled = proptools.BoolPtr(false)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900288
289 if module.SocSpecific() {
290 props.Soc_specific = proptools.BoolPtr(true)
291 } else if module.DeviceSpecific() {
292 props.Device_specific = proptools.BoolPtr(true)
293 } else if module.ProductSpecific() {
294 props.Product_specific = proptools.BoolPtr(true)
295 }
296
297 mctx.CreateModule(android.ModuleFactoryAdaptor(LibraryFactory(false)), &props)
298}
299
300// Creates a droiddoc module that creates stubs source files from the given full source
301// files
Jiyong Parkdf130542018-04-27 16:29:21 +0900302func (module *sdkLibrary) createDocs(mctx android.TopDownMutatorContext, apiScope apiScope) {
Jiyong Parkc678ad32018-04-10 13:07:10 +0900303 props := struct {
304 Name *string
305 Srcs []string
306 Custom_template *string
307 Installable *bool
308 Srcs_lib *string
309 Srcs_lib_whitelist_dirs []string
310 Srcs_lib_whitelist_pkgs []string
311 Libs []string
312 Args *string
313 Api_tag_name *string
314 Api_filename *string
315 Removed_api_filename *string
316 }{}
317
Jiyong Parkdf130542018-04-27 16:29:21 +0900318 props.Name = proptools.StringPtr(module.docsName(apiScope))
Jiyong Parkc678ad32018-04-10 13:07:10 +0900319 props.Srcs = module.properties.Srcs
320 props.Custom_template = proptools.StringPtr("droiddoc-templates-sdk")
321 props.Installable = proptools.BoolPtr(false)
322 props.Libs = module.properties.Libs
323
324 droiddocArgs := " -hide 110 -hide 111 -hide 113 -hide 121 -hide 125 -hide 126 -hide 127 -hide 128" +
325 " -stubpackages " + strings.Join(module.properties.Api_packages, ":") +
Jiyong Park5a2c9d72018-05-01 22:25:41 +0900326 " " + android.JoinWithPrefix(module.properties.Hidden_api_packages, "-hidePackage ") +
Jiyong Parkc678ad32018-04-10 13:07:10 +0900327 " -nodocs"
Jiyong Parkdf130542018-04-27 16:29:21 +0900328 switch apiScope {
329 case apiScopeSystem:
Jiyong Parkc678ad32018-04-10 13:07:10 +0900330 droiddocArgs = droiddocArgs + " -showAnnotation android.annotation.SystemApi"
Jiyong Parkdf130542018-04-27 16:29:21 +0900331 case apiScopeTest:
332 droiddocArgs = droiddocArgs + " -showAnnotation android.annotation.TestApi"
Jiyong Parkc678ad32018-04-10 13:07:10 +0900333 }
334 props.Args = proptools.StringPtr(droiddocArgs)
335
336 // List of APIs identified from the provided source files are created. They are later
337 // compared against to the not-yet-released (a.k.a current) list of APIs and to the
338 // last-released (a.k.a numbered) list of API.
339 // TODO: If any incompatible change is detected, break the build
340 currentApiFileName := "current.txt"
341 removedApiFileName := "removed.txt"
Jiyong Parkdf130542018-04-27 16:29:21 +0900342 switch apiScope {
343 case apiScopeSystem:
Jiyong Parkc678ad32018-04-10 13:07:10 +0900344 currentApiFileName = "system-" + currentApiFileName
345 removedApiFileName = "system-" + removedApiFileName
Jiyong Parkdf130542018-04-27 16:29:21 +0900346 case apiScopeTest:
347 currentApiFileName = "test-" + currentApiFileName
348 removedApiFileName = "test-" + removedApiFileName
Jiyong Parkc678ad32018-04-10 13:07:10 +0900349 }
350 currentApiFileName = path.Join("api", currentApiFileName)
351 removedApiFileName = path.Join("api", removedApiFileName)
Jiyong Parkdf130542018-04-27 16:29:21 +0900352 props.Api_tag_name = proptools.StringPtr(module.apiTagName(apiScope))
Jiyong Parkc678ad32018-04-10 13:07:10 +0900353 // Note: the exact names of these two are not important because they are always
354 // referenced by the make variable $(INTERNAL_PLATFORM_<TAG_NAME>_API_FILE)
355 props.Api_filename = proptools.StringPtr(currentApiFileName)
356 props.Removed_api_filename = proptools.StringPtr(removedApiFileName)
357
Jiyong Park82484c02018-04-23 21:41:26 +0900358 // Include the part of the framework source. This is required for the case when
359 // API class is extending from the framework class. In that case, doclava needs
360 // to know whether the base class is hidden or not. Since that information is
361 // encoded as @hide string in the comment, we need source files for the classes,
362 // not the compiled ones. Also there are rare cases where part of SDK library is
363 // implemented in the framework (e.g. org.apache.http.legacy). In that case,
364 // we need framework source to make API stubs, though the sources are not
365 // required to build the runtime library.
Jiyong Parkc678ad32018-04-10 13:07:10 +0900366 props.Srcs_lib = proptools.StringPtr("framework")
367 props.Srcs_lib_whitelist_dirs = []string{"core/java"}
Jiyong Park82484c02018-04-23 21:41:26 +0900368 props.Srcs_lib_whitelist_pkgs = module.properties.Api_packages
369 // Add android.annotation package to give access to the framework-defined
370 // annotations such as SystemApi, NonNull, etc.
371 props.Srcs_lib_whitelist_pkgs = append(props.Srcs_lib_whitelist_pkgs, "android.annotation")
372 // These libs are required by doclava to parse the framework sources add via
373 // Src_lib and Src_lib_whitelist_* properties just above.
Jiyong Parkc678ad32018-04-10 13:07:10 +0900374 // If we don't add them to the classpath, errors messages are generated by doclava,
375 // though they don't break the build.
Jiyong Park82484c02018-04-23 21:41:26 +0900376 props.Libs = append(props.Libs, "conscrypt", "bouncycastle", "okhttp", "framework")
Jiyong Parkc678ad32018-04-10 13:07:10 +0900377
378 mctx.CreateModule(android.ModuleFactoryAdaptor(DroiddocFactory), &props)
379}
380
381// Creates the runtime library. This is not directly linkable from other modules.
382func (module *sdkLibrary) createImplLibrary(mctx android.TopDownMutatorContext) {
383 props := struct {
384 Name *string
385 Srcs []string
386 Libs []string
387 Static_libs []string
388 Soc_specific *bool
389 Device_specific *bool
390 Product_specific *bool
391 Required []string
392 }{}
393
394 props.Name = proptools.StringPtr(module.implName())
395 props.Srcs = module.properties.Srcs
396 props.Libs = module.properties.Libs
397 props.Static_libs = module.properties.Static_libs
398 // XML file is installed along with the impl lib
399 props.Required = []string{module.xmlFileName()}
400
401 if module.SocSpecific() {
402 props.Soc_specific = proptools.BoolPtr(true)
403 } else if module.DeviceSpecific() {
404 props.Device_specific = proptools.BoolPtr(true)
405 } else if module.ProductSpecific() {
406 props.Product_specific = proptools.BoolPtr(true)
407 }
408
Jiyong Park441a47d2018-05-01 23:33:08 +0900409 mctx.CreateModule(android.ModuleFactoryAdaptor(LibraryFactory(true)), &props, &module.deviceProperties)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900410}
411
412// Creates the xml file that publicizes the runtime library
413func (module *sdkLibrary) createXmlFile(mctx android.TopDownMutatorContext) {
414 template := `
415<?xml version="1.0" encoding="utf-8"?>
416<!-- Copyright (C) 2018 The Android Open Source Project
417
418 Licensed under the Apache License, Version 2.0 (the "License");
419 you may not use this file except in compliance with the License.
420 You may obtain a copy of the License at
421
422 http://www.apache.org/licenses/LICENSE-2.0
423
424 Unless required by applicable law or agreed to in writing, software
425 distributed under the License is distributed on an "AS IS" BASIS,
426 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
427 See the License for the specific language governing permissions and
428 limitations under the License.
429-->
430
431<permissions>
432 <library name="%s" file="%s"/>
433</permissions>
434`
435 // genrule to generate the xml file content from the template above
436 // TODO: preserve newlines in the generate xml file. Newlines are being squashed
437 // in the ninja file. Do we need to have an external tool for this?
438 xmlContent := fmt.Sprintf(template, module.BaseModuleName(), module.implPath())
439 genruleProps := struct {
440 Name *string
441 Cmd *string
442 Out []string
443 }{}
444 genruleProps.Name = proptools.StringPtr(module.xmlFileName() + "-gen")
445 genruleProps.Cmd = proptools.StringPtr("echo '" + xmlContent + "' > $(out)")
446 genruleProps.Out = []string{module.xmlFileName()}
447 mctx.CreateModule(android.ModuleFactoryAdaptor(genrule.GenRuleFactory), &genruleProps)
448
449 // creates a prebuilt_etc module to actually place the xml file under
450 // <partition>/etc/permissions
451 etcProps := struct {
452 Name *string
Jiyong Park5a8d1be2018-04-25 22:57:34 +0900453 Src *string
Jiyong Parkc678ad32018-04-10 13:07:10 +0900454 Sub_dir *string
455 Soc_specific *bool
456 Device_specific *bool
457 Product_specific *bool
458 }{}
459 etcProps.Name = proptools.StringPtr(module.xmlFileName())
Jiyong Park5a8d1be2018-04-25 22:57:34 +0900460 etcProps.Src = proptools.StringPtr(":" + module.xmlFileName() + "-gen")
Jiyong Parkc678ad32018-04-10 13:07:10 +0900461 etcProps.Sub_dir = proptools.StringPtr("permissions")
462 if module.SocSpecific() {
463 etcProps.Soc_specific = proptools.BoolPtr(true)
464 } else if module.DeviceSpecific() {
465 etcProps.Device_specific = proptools.BoolPtr(true)
466 } else if module.ProductSpecific() {
467 etcProps.Product_specific = proptools.BoolPtr(true)
468 }
469 mctx.CreateModule(android.ModuleFactoryAdaptor(android.PrebuiltEtcFactory), &etcProps)
470}
471
472// to satisfy SdkLibraryDependency interface
473func (module *sdkLibrary) HeaderJars(linkType linkType) android.Paths {
474 // This module is just a wrapper for the stubs.
475 if linkType == javaSystem || linkType == javaPlatform {
476 return module.systemApiStubsPath
477 } else {
478 return module.publicApiStubsPath
479 }
480}
481
Jiyong Park82484c02018-04-23 21:41:26 +0900482func javaSdkLibraries(config android.Config) *[]string {
483 return config.Once("javaSdkLibraries", func() interface{} {
484 return &[]string{}
485 }).(*[]string)
486}
487
Jiyong Parkc678ad32018-04-10 13:07:10 +0900488// For a java_sdk_library module, create internal modules for stubs, docs,
489// runtime libs and xml file. If requested, the stubs and docs are created twice
490// once for public API level and once for system API level
491func sdkLibraryMutator(mctx android.TopDownMutatorContext) {
492 if module, ok := mctx.Module().(*sdkLibrary); ok {
Anton Hansson8959e142018-04-25 11:56:13 +0100493 if module.properties.Srcs == nil {
494 mctx.PropertyErrorf("srcs", "java_sdk_library must specify srcs")
495 }
496 if module.properties.Api_packages == nil {
497 mctx.PropertyErrorf("api_packages", "java_sdk_library must specify api_packages")
498 }
499
Jiyong Parkc678ad32018-04-10 13:07:10 +0900500 // for public API stubs
Jiyong Parkdf130542018-04-27 16:29:21 +0900501 module.createStubsLibrary(mctx, apiScopePublic)
502 module.createDocs(mctx, apiScopePublic)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900503
504 // for system API stubs
Jiyong Parkdf130542018-04-27 16:29:21 +0900505 module.createStubsLibrary(mctx, apiScopeSystem)
506 module.createDocs(mctx, apiScopeSystem)
507
508 // for test API stubs
509 module.createStubsLibrary(mctx, apiScopeTest)
510 module.createDocs(mctx, apiScopeTest)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900511
512 // for runtime
513 module.createXmlFile(mctx)
514 module.createImplLibrary(mctx)
Jiyong Park82484c02018-04-23 21:41:26 +0900515
516 // record java_sdk_library modules so that they are exported to make
517 javaSdkLibraries := javaSdkLibraries(mctx.Config())
518 javaSdkLibrariesLock.Lock()
519 defer javaSdkLibrariesLock.Unlock()
520 *javaSdkLibraries = append(*javaSdkLibraries, module.BaseModuleName())
Jiyong Parkc678ad32018-04-10 13:07:10 +0900521 }
522}
523
524func sdkLibraryFactory() android.Module {
525 module := &sdkLibrary{}
526 module.AddProperties(&module.properties)
Jiyong Park441a47d2018-05-01 23:33:08 +0900527 module.AddProperties(&module.deviceProperties)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900528 android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibCommon)
529 android.InitDefaultableModule(module)
530 return module
531}