blob: 3bac8f6f002e45720f005bda81ceb473fc2f3c04 [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"}
Sundong Ahn57368eb2018-07-06 11:20:23 +090049 implLibTag = dependencyTag{name: "platform"}
Jiyong Parkdf130542018-04-27 16:29:21 +090050)
51
52type apiScope int
53
54const (
55 apiScopePublic apiScope = iota
56 apiScopeSystem
57 apiScopeTest
Jiyong Parkc678ad32018-04-10 13:07:10 +090058)
59
Jiyong Park82484c02018-04-23 21:41:26 +090060var (
61 javaSdkLibrariesLock sync.Mutex
62)
63
Jiyong Parkc678ad32018-04-10 13:07:10 +090064// java_sdk_library is to make a Java library that implements optional platform APIs to apps.
65// It is actually a wrapper of several modules: 1) stubs library that clients are linked against
66// to, 2) droiddoc module that internally generates API stubs source files, 3) the real runtime
67// shared library that implements the APIs, and 4) XML file for adding the runtime lib to the
68// classpath at runtime if requested via <uses-library>.
69//
70// TODO: these are big features that are currently missing
Jiyong Park1be96912018-05-28 18:02:19 +090071// 1) disallowing linking to the runtime shared lib
72// 2) HTML generation
Jiyong Parkc678ad32018-04-10 13:07:10 +090073
74func init() {
75 android.RegisterModuleType("java_sdk_library", sdkLibraryFactory)
76
77 android.PreArchMutators(func(ctx android.RegisterMutatorsContext) {
78 ctx.TopDown("java_sdk_library", sdkLibraryMutator).Parallel()
79 })
Jiyong Park82484c02018-04-23 21:41:26 +090080
81 android.RegisterMakeVarsProvider(pctx, func(ctx android.MakeVarsContext) {
82 javaSdkLibraries := javaSdkLibraries(ctx.Config())
83 sort.Strings(*javaSdkLibraries)
84 ctx.Strict("JAVA_SDK_LIBRARIES", strings.Join(*javaSdkLibraries, " "))
85 })
Jiyong Parkc678ad32018-04-10 13:07:10 +090086}
87
88type sdkLibraryProperties struct {
89 // list of source files used to compile the Java module. May be .java, .logtags, .proto,
90 // or .aidl files.
91 Srcs []string `android:"arch_variant"`
92
Jiyong Parkbaaf9dd2018-05-02 01:35:27 +090093 // list of optional source files that are part of API but not part of runtime library.
94 Api_srcs []string `android:"arch_variant"`
95
Jiyong Parkc678ad32018-04-10 13:07:10 +090096 // list of of java libraries that will be in the classpath
97 Libs []string `android:"arch_variant"`
98
99 // list of java libraries that will be compiled into the resulting runtime jar.
100 // These libraries are not compiled into the stubs jar.
101 Static_libs []string `android:"arch_variant"`
102
Sundong Ahnf043cf62018-06-25 16:04:37 +0900103 // List of Java libraries that will be in the classpath when building stubs
104 Stub_only_libs []string `android:"arch_variant"`
105
Jiyong Parkc678ad32018-04-10 13:07:10 +0900106 // list of package names that will be documented and publicized as API
107 Api_packages []string
108
Jiyong Park5a2c9d72018-05-01 22:25:41 +0900109 // list of package names that must be hidden from the API
110 Hidden_api_packages []string
111
Jiyong Parkb5b709f2018-06-15 10:38:59 +0900112 Errorprone struct {
113 // List of javac flags that should only be used when running errorprone.
114 Javacflags []string
115 }
116
Jiyong Parkc678ad32018-04-10 13:07:10 +0900117 // TODO: determines whether to create HTML doc or not
118 //Html_doc *bool
119}
120
121type sdkLibrary struct {
122 android.ModuleBase
123 android.DefaultableModuleBase
124
Jiyong Park441a47d2018-05-01 23:33:08 +0900125 properties sdkLibraryProperties
126 deviceProperties CompilerDeviceProperties
Jiyong Parkc678ad32018-04-10 13:07:10 +0900127
128 publicApiStubsPath android.Paths
129 systemApiStubsPath android.Paths
Jiyong Parkdf130542018-04-27 16:29:21 +0900130 testApiStubsPath android.Paths
Sundong Ahn57368eb2018-07-06 11:20:23 +0900131 implLibPath android.Paths
Sundong Ahn241cd372018-07-13 16:16:44 +0900132
133 publicApiStubsImplPath android.Paths
134 systemApiStubsImplPath android.Paths
135 testApiStubsImplPath android.Paths
136 implLibImplPath android.Paths
Jiyong Parkc678ad32018-04-10 13:07:10 +0900137}
138
139func (module *sdkLibrary) DepsMutator(ctx android.BottomUpMutatorContext) {
140 // Add dependencies to the stubs library
Jiyong Parkdf130542018-04-27 16:29:21 +0900141 ctx.AddDependency(ctx.Module(), publicApiStubsTag, module.stubsName(apiScopePublic))
142 ctx.AddDependency(ctx.Module(), systemApiStubsTag, module.stubsName(apiScopeSystem))
143 ctx.AddDependency(ctx.Module(), testApiStubsTag, module.stubsName(apiScopeTest))
Sundong Ahn57368eb2018-07-06 11:20:23 +0900144 ctx.AddDependency(ctx.Module(), implLibTag, module.implName())
Jiyong Parkc678ad32018-04-10 13:07:10 +0900145}
146
147func (module *sdkLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Sundong Ahn57368eb2018-07-06 11:20:23 +0900148 // Record the paths to the header jars of the library (stubs and impl).
Jiyong Parkc678ad32018-04-10 13:07:10 +0900149 // When this java_sdk_library is dependened from others via "libs" property,
150 // the recorded paths will be returned depending on the link type of the caller.
151 ctx.VisitDirectDeps(func(to android.Module) {
152 otherName := ctx.OtherModuleName(to)
153 tag := ctx.OtherModuleDependencyTag(to)
154
Sundong Ahn57368eb2018-07-06 11:20:23 +0900155 if lib, ok := to.(Dependency); ok {
Jiyong Parkc678ad32018-04-10 13:07:10 +0900156 switch tag {
157 case publicApiStubsTag:
Sundong Ahn57368eb2018-07-06 11:20:23 +0900158 module.publicApiStubsPath = lib.HeaderJars()
Sundong Ahn241cd372018-07-13 16:16:44 +0900159 module.publicApiStubsImplPath = lib.ImplementationJars()
Jiyong Parkc678ad32018-04-10 13:07:10 +0900160 case systemApiStubsTag:
Sundong Ahn57368eb2018-07-06 11:20:23 +0900161 module.systemApiStubsPath = lib.HeaderJars()
Sundong Ahn241cd372018-07-13 16:16:44 +0900162 module.systemApiStubsImplPath = lib.ImplementationJars()
Jiyong Parkdf130542018-04-27 16:29:21 +0900163 case testApiStubsTag:
Sundong Ahn57368eb2018-07-06 11:20:23 +0900164 module.testApiStubsPath = lib.HeaderJars()
Sundong Ahn241cd372018-07-13 16:16:44 +0900165 module.testApiStubsImplPath = lib.ImplementationJars()
Sundong Ahn57368eb2018-07-06 11:20:23 +0900166 case implLibTag:
167 module.implLibPath = lib.HeaderJars()
Sundong Ahn241cd372018-07-13 16:16:44 +0900168 module.implLibImplPath = lib.ImplementationJars()
Jiyong Parkc678ad32018-04-10 13:07:10 +0900169 default:
170 ctx.ModuleErrorf("depends on module %q of unknown tag %q", otherName, tag)
171 }
172 }
173 })
174}
175
Jiyong Park82484c02018-04-23 21:41:26 +0900176func (module *sdkLibrary) AndroidMk() android.AndroidMkData {
Jiyong Park82484c02018-04-23 21:41:26 +0900177 return android.AndroidMkData{
178 Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
Jiyong Park90078382018-05-02 19:30:15 +0900179 // Create a phony module that installs the impl library, for the case when this lib is
180 // in PRODUCT_PACKAGES.
Jiyong Park82484c02018-04-23 21:41:26 +0900181 fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)")
182 fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir)
183 fmt.Fprintln(w, "LOCAL_MODULE :=", name)
184 fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES := "+module.implName())
185 fmt.Fprintln(w, "include $(BUILD_PHONY_PACKAGE)")
Jiyong Park90078382018-05-02 19:30:15 +0900186 // Create dist rules to install the stubs libs to the dist dir
Jiyong Parkb674a522018-05-06 07:53:02 +0900187 if len(module.publicApiStubsPath) == 1 {
188 fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+
189 module.publicApiStubsPath.Strings()[0]+
190 ":"+path.Join("apistubs", "public", module.BaseModuleName()+".jar")+")")
191 }
192 if len(module.systemApiStubsPath) == 1 {
193 fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+
194 module.systemApiStubsPath.Strings()[0]+
195 ":"+path.Join("apistubs", "system", module.BaseModuleName()+".jar")+")")
196 }
197 if len(module.testApiStubsPath) == 1 {
198 fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+
199 module.testApiStubsPath.Strings()[0]+
200 ":"+path.Join("apistubs", "test", module.BaseModuleName()+".jar")+")")
201 }
Jiyong Park82484c02018-04-23 21:41:26 +0900202 },
203 }
204}
205
Jiyong Parkc678ad32018-04-10 13:07:10 +0900206// Module name of the stubs library
Jiyong Parkdf130542018-04-27 16:29:21 +0900207func (module *sdkLibrary) stubsName(apiScope apiScope) string {
Jiyong Parkc678ad32018-04-10 13:07:10 +0900208 stubsName := module.BaseModuleName() + sdkStubsLibrarySuffix
Jiyong Parkdf130542018-04-27 16:29:21 +0900209 switch apiScope {
210 case apiScopeSystem:
Jiyong Parkc678ad32018-04-10 13:07:10 +0900211 stubsName = stubsName + sdkSystemApiSuffix
Jiyong Parkdf130542018-04-27 16:29:21 +0900212 case apiScopeTest:
213 stubsName = stubsName + sdkTestApiSuffix
Jiyong Parkc678ad32018-04-10 13:07:10 +0900214 }
215 return stubsName
216}
217
218// Module name of the docs
Jiyong Parkdf130542018-04-27 16:29:21 +0900219func (module *sdkLibrary) docsName(apiScope apiScope) string {
Jiyong Parkc678ad32018-04-10 13:07:10 +0900220 docsName := module.BaseModuleName() + sdkDocsSuffix
Jiyong Parkdf130542018-04-27 16:29:21 +0900221 switch apiScope {
222 case apiScopeSystem:
Jiyong Parkc678ad32018-04-10 13:07:10 +0900223 docsName = docsName + sdkSystemApiSuffix
Jiyong Parkdf130542018-04-27 16:29:21 +0900224 case apiScopeTest:
225 docsName = docsName + sdkTestApiSuffix
Jiyong Parkc678ad32018-04-10 13:07:10 +0900226 }
227 return docsName
228}
229
230// Module name of the runtime implementation library
231func (module *sdkLibrary) implName() string {
232 return module.BaseModuleName() + sdkImplLibrarySuffix
233}
234
235// File path to the runtime implementation library
236func (module *sdkLibrary) implPath() string {
237 partition := "system"
238 if module.SocSpecific() {
239 partition = "vendor"
240 } else if module.DeviceSpecific() {
241 partition = "odm"
242 } else if module.ProductSpecific() {
243 partition = "product"
244 }
245 return "/" + partition + "/framework/" + module.implName() + ".jar"
246}
247
248// Module name of the XML file for the lib
249func (module *sdkLibrary) xmlFileName() string {
250 return module.BaseModuleName() + sdkXmlFileSuffix
251}
252
253// SDK version that the stubs library is built against. Note that this is always
254// *current. Older stubs library built with a numberd SDK version is created from
255// the prebuilt jar.
Jiyong Parkdf130542018-04-27 16:29:21 +0900256func (module *sdkLibrary) sdkVersion(apiScope apiScope) string {
257 switch apiScope {
258 case apiScopePublic:
259 return "current"
260 case apiScopeSystem:
Jiyong Parkc678ad32018-04-10 13:07:10 +0900261 return "system_current"
Jiyong Parkdf130542018-04-27 16:29:21 +0900262 case apiScopeTest:
263 return "test_current"
264 default:
Jiyong Parkc678ad32018-04-10 13:07:10 +0900265 return "current"
266 }
267}
268
269// $(INTERNAL_PLATFORM_<apiTagName>_API_FILE) points to the generated
270// api file for the current source
271// TODO: remove this when apicheck is done in soong
Jiyong Parkdf130542018-04-27 16:29:21 +0900272func (module *sdkLibrary) apiTagName(apiScope apiScope) string {
Jiyong Parkc678ad32018-04-10 13:07:10 +0900273 apiTagName := strings.Replace(strings.ToUpper(module.BaseModuleName()), ".", "_", -1)
Jiyong Parkdf130542018-04-27 16:29:21 +0900274 switch apiScope {
275 case apiScopeSystem:
Jiyong Parkc678ad32018-04-10 13:07:10 +0900276 apiTagName = apiTagName + "_SYSTEM"
Jiyong Parkdf130542018-04-27 16:29:21 +0900277 case apiScopeTest:
278 apiTagName = apiTagName + "_TEST"
Jiyong Parkc678ad32018-04-10 13:07:10 +0900279 }
280 return apiTagName
281}
282
Jiyong Park58c518b2018-05-12 22:29:12 +0900283func (module *sdkLibrary) latestApiFilegroupName(apiScope apiScope) string {
284 name := ":" + module.BaseModuleName() + ".api."
Jiyong Parkdf130542018-04-27 16:29:21 +0900285 switch apiScope {
Jiyong Park58c518b2018-05-12 22:29:12 +0900286 case apiScopePublic:
287 name = name + "public"
Jiyong Parkdf130542018-04-27 16:29:21 +0900288 case apiScopeSystem:
Jiyong Park58c518b2018-05-12 22:29:12 +0900289 name = name + "system"
Jiyong Parkdf130542018-04-27 16:29:21 +0900290 case apiScopeTest:
Jiyong Park58c518b2018-05-12 22:29:12 +0900291 name = name + "test"
Jiyong Parkc678ad32018-04-10 13:07:10 +0900292 }
Jiyong Park58c518b2018-05-12 22:29:12 +0900293 name = name + ".latest"
294 return name
295}
Jiyong Parkc678ad32018-04-10 13:07:10 +0900296
Jiyong Park58c518b2018-05-12 22:29:12 +0900297func (module *sdkLibrary) latestRemovedApiFilegroupName(apiScope apiScope) string {
298 name := ":" + module.BaseModuleName() + "-removed.api."
299 switch apiScope {
300 case apiScopePublic:
301 name = name + "public"
302 case apiScopeSystem:
303 name = name + "system"
304 case apiScopeTest:
305 name = name + "test"
306 }
307 name = name + ".latest"
308 return name
Jiyong Parkc678ad32018-04-10 13:07:10 +0900309}
310
311// Creates a static java library that has API stubs
Jiyong Parkdf130542018-04-27 16:29:21 +0900312func (module *sdkLibrary) createStubsLibrary(mctx android.TopDownMutatorContext, apiScope apiScope) {
Jiyong Parkc678ad32018-04-10 13:07:10 +0900313 props := struct {
314 Name *string
315 Srcs []string
316 Sdk_version *string
Sundong Ahnf043cf62018-06-25 16:04:37 +0900317 Libs []string
Jiyong Parkc678ad32018-04-10 13:07:10 +0900318 Soc_specific *bool
319 Device_specific *bool
320 Product_specific *bool
321 Product_variables struct {
322 Unbundled_build struct {
323 Enabled *bool
324 }
Jiyong Park82484c02018-04-23 21:41:26 +0900325 Pdk struct {
326 Enabled *bool
327 }
Jiyong Parkc678ad32018-04-10 13:07:10 +0900328 }
329 }{}
330
Jiyong Parkdf130542018-04-27 16:29:21 +0900331 props.Name = proptools.StringPtr(module.stubsName(apiScope))
Jiyong Parkc678ad32018-04-10 13:07:10 +0900332 // sources are generated from the droiddoc
Jiyong Parkdf130542018-04-27 16:29:21 +0900333 props.Srcs = []string{":" + module.docsName(apiScope)}
334 props.Sdk_version = proptools.StringPtr(module.sdkVersion(apiScope))
Sundong Ahnf043cf62018-06-25 16:04:37 +0900335 props.Libs = module.properties.Stub_only_libs
Jiyong Parkc678ad32018-04-10 13:07:10 +0900336 // Unbundled apps will use the prebult one from /prebuilts/sdk
337 props.Product_variables.Unbundled_build.Enabled = proptools.BoolPtr(false)
Jiyong Park82484c02018-04-23 21:41:26 +0900338 props.Product_variables.Pdk.Enabled = proptools.BoolPtr(false)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900339
340 if module.SocSpecific() {
341 props.Soc_specific = proptools.BoolPtr(true)
342 } else if module.DeviceSpecific() {
343 props.Device_specific = proptools.BoolPtr(true)
344 } else if module.ProductSpecific() {
345 props.Product_specific = proptools.BoolPtr(true)
346 }
347
Colin Cross9ae1b922018-06-26 17:59:05 -0700348 mctx.CreateModule(android.ModuleFactoryAdaptor(LibraryFactory), &props)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900349}
350
351// Creates a droiddoc module that creates stubs source files from the given full source
352// files
Jiyong Parkdf130542018-04-27 16:29:21 +0900353func (module *sdkLibrary) createDocs(mctx android.TopDownMutatorContext, apiScope apiScope) {
Jiyong Parkc678ad32018-04-10 13:07:10 +0900354 props := struct {
355 Name *string
356 Srcs []string
357 Custom_template *string
358 Installable *bool
359 Srcs_lib *string
360 Srcs_lib_whitelist_dirs []string
361 Srcs_lib_whitelist_pkgs []string
362 Libs []string
363 Args *string
364 Api_tag_name *string
365 Api_filename *string
366 Removed_api_filename *string
Jiyong Park58c518b2018-05-12 22:29:12 +0900367 Check_api struct {
368 Current ApiToCheck
369 Last_released ApiToCheck
370 }
Sundong Ahn1b92c822018-05-29 11:35:17 +0900371 Aidl struct {
372 Include_dirs []string
373 Local_include_dirs []string
374 }
Jiyong Parkc678ad32018-04-10 13:07:10 +0900375 }{}
376
Jiyong Parkdf130542018-04-27 16:29:21 +0900377 props.Name = proptools.StringPtr(module.docsName(apiScope))
Jiyong Parkbaaf9dd2018-05-02 01:35:27 +0900378 props.Srcs = append(props.Srcs, module.properties.Srcs...)
379 props.Srcs = append(props.Srcs, module.properties.Api_srcs...)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900380 props.Custom_template = proptools.StringPtr("droiddoc-templates-sdk")
381 props.Installable = proptools.BoolPtr(false)
Sundong Ahne6f0b052018-06-05 16:46:14 +0900382 // A droiddoc module has only one Libs property and doesn't distinguish between
383 // shared libs and static libs. So we need to add both of these libs to Libs property.
Jiyong Parkc678ad32018-04-10 13:07:10 +0900384 props.Libs = module.properties.Libs
Sundong Ahne6f0b052018-06-05 16:46:14 +0900385 props.Libs = append(props.Libs, module.properties.Static_libs...)
Sundong Ahn1b92c822018-05-29 11:35:17 +0900386 props.Aidl.Include_dirs = module.deviceProperties.Aidl.Include_dirs
387 props.Aidl.Local_include_dirs = module.deviceProperties.Aidl.Local_include_dirs
Jiyong Parkc678ad32018-04-10 13:07:10 +0900388
389 droiddocArgs := " -hide 110 -hide 111 -hide 113 -hide 121 -hide 125 -hide 126 -hide 127 -hide 128" +
390 " -stubpackages " + strings.Join(module.properties.Api_packages, ":") +
Jiyong Park5a2c9d72018-05-01 22:25:41 +0900391 " " + android.JoinWithPrefix(module.properties.Hidden_api_packages, "-hidePackage ") +
Jiyong Parkc678ad32018-04-10 13:07:10 +0900392 " -nodocs"
Jiyong Parkdf130542018-04-27 16:29:21 +0900393 switch apiScope {
394 case apiScopeSystem:
Jiyong Parkc678ad32018-04-10 13:07:10 +0900395 droiddocArgs = droiddocArgs + " -showAnnotation android.annotation.SystemApi"
Jiyong Parkdf130542018-04-27 16:29:21 +0900396 case apiScopeTest:
397 droiddocArgs = droiddocArgs + " -showAnnotation android.annotation.TestApi"
Jiyong Parkc678ad32018-04-10 13:07:10 +0900398 }
399 props.Args = proptools.StringPtr(droiddocArgs)
400
401 // List of APIs identified from the provided source files are created. They are later
402 // compared against to the not-yet-released (a.k.a current) list of APIs and to the
403 // last-released (a.k.a numbered) list of API.
Jiyong Parkc678ad32018-04-10 13:07:10 +0900404 currentApiFileName := "current.txt"
405 removedApiFileName := "removed.txt"
Jiyong Parkdf130542018-04-27 16:29:21 +0900406 switch apiScope {
407 case apiScopeSystem:
Jiyong Parkc678ad32018-04-10 13:07:10 +0900408 currentApiFileName = "system-" + currentApiFileName
409 removedApiFileName = "system-" + removedApiFileName
Jiyong Parkdf130542018-04-27 16:29:21 +0900410 case apiScopeTest:
411 currentApiFileName = "test-" + currentApiFileName
412 removedApiFileName = "test-" + removedApiFileName
Jiyong Parkc678ad32018-04-10 13:07:10 +0900413 }
414 currentApiFileName = path.Join("api", currentApiFileName)
415 removedApiFileName = path.Join("api", removedApiFileName)
Jiyong Park58c518b2018-05-12 22:29:12 +0900416 // TODO(jiyong): remove these three props
Jiyong Parkdf130542018-04-27 16:29:21 +0900417 props.Api_tag_name = proptools.StringPtr(module.apiTagName(apiScope))
Jiyong Parkc678ad32018-04-10 13:07:10 +0900418 props.Api_filename = proptools.StringPtr(currentApiFileName)
419 props.Removed_api_filename = proptools.StringPtr(removedApiFileName)
420
Jiyong Park58c518b2018-05-12 22:29:12 +0900421 // check against the not-yet-release API
422 props.Check_api.Current.Api_file = proptools.StringPtr(currentApiFileName)
423 props.Check_api.Current.Removed_api_file = proptools.StringPtr(removedApiFileName)
424 // any change is reported as error
425 props.Check_api.Current.Args = proptools.StringPtr("-error 2 -error 3 -error 4 -error 5 " +
426 "-error 6 -error 7 -error 8 -error 9 -error 10 -error 11 -error 12 -error 13 " +
427 "-error 14 -error 15 -error 16 -error 17 -error 18 -error 19 -error 20 " +
428 "-error 21 -error 23 -error 24 -error 25 -error 26 -error 27")
429
430 // check against the latest released API
431 props.Check_api.Last_released.Api_file = proptools.StringPtr(
432 module.latestApiFilegroupName(apiScope))
433 props.Check_api.Last_released.Removed_api_file = proptools.StringPtr(
434 module.latestRemovedApiFilegroupName(apiScope))
435 // backward incompatible changes are reported as error
436 props.Check_api.Last_released.Args = proptools.StringPtr("-hide 2 -hide 3 -hide 4 -hide 5 " +
437 "-hide 6 -hide 24 -hide 25 -hide 26 -hide 27 " +
438 "-error 7 -error 8 -error 9 -error 10 -error 11 -error 12 -error 13 -error 14 " +
439 "-error 15 -error 16 -error 17 -error 18")
440
Jiyong Park82484c02018-04-23 21:41:26 +0900441 // Include the part of the framework source. This is required for the case when
442 // API class is extending from the framework class. In that case, doclava needs
443 // to know whether the base class is hidden or not. Since that information is
444 // encoded as @hide string in the comment, we need source files for the classes,
Jiyong Parkbaaf9dd2018-05-02 01:35:27 +0900445 // not the compiled ones.
Jiyong Parkc678ad32018-04-10 13:07:10 +0900446 props.Srcs_lib = proptools.StringPtr("framework")
447 props.Srcs_lib_whitelist_dirs = []string{"core/java"}
Jiyong Park82484c02018-04-23 21:41:26 +0900448 // Add android.annotation package to give access to the framework-defined
449 // annotations such as SystemApi, NonNull, etc.
Jiyong Parkbaaf9dd2018-05-02 01:35:27 +0900450 props.Srcs_lib_whitelist_pkgs = []string{"android.annotation"}
Jiyong Park82484c02018-04-23 21:41:26 +0900451 // These libs are required by doclava to parse the framework sources add via
452 // Src_lib and Src_lib_whitelist_* properties just above.
Jiyong Parkc678ad32018-04-10 13:07:10 +0900453 // If we don't add them to the classpath, errors messages are generated by doclava,
454 // though they don't break the build.
Jiyong Park82484c02018-04-23 21:41:26 +0900455 props.Libs = append(props.Libs, "conscrypt", "bouncycastle", "okhttp", "framework")
Jiyong Parkc678ad32018-04-10 13:07:10 +0900456
457 mctx.CreateModule(android.ModuleFactoryAdaptor(DroiddocFactory), &props)
458}
459
460// Creates the runtime library. This is not directly linkable from other modules.
461func (module *sdkLibrary) createImplLibrary(mctx android.TopDownMutatorContext) {
462 props := struct {
463 Name *string
464 Srcs []string
465 Libs []string
466 Static_libs []string
467 Soc_specific *bool
468 Device_specific *bool
469 Product_specific *bool
Colin Cross9ae1b922018-06-26 17:59:05 -0700470 Installable *bool
Jiyong Parkc678ad32018-04-10 13:07:10 +0900471 Required []string
Jiyong Parkb5b709f2018-06-15 10:38:59 +0900472 Errorprone struct {
473 Javacflags []string
474 }
Jiyong Parkc678ad32018-04-10 13:07:10 +0900475 }{}
476
477 props.Name = proptools.StringPtr(module.implName())
478 props.Srcs = module.properties.Srcs
479 props.Libs = module.properties.Libs
480 props.Static_libs = module.properties.Static_libs
Colin Cross9ae1b922018-06-26 17:59:05 -0700481 props.Installable = proptools.BoolPtr(true)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900482 // XML file is installed along with the impl lib
483 props.Required = []string{module.xmlFileName()}
Jiyong Parkb5b709f2018-06-15 10:38:59 +0900484 props.Errorprone.Javacflags = module.properties.Errorprone.Javacflags
Jiyong Parkc678ad32018-04-10 13:07:10 +0900485
486 if module.SocSpecific() {
487 props.Soc_specific = proptools.BoolPtr(true)
488 } else if module.DeviceSpecific() {
489 props.Device_specific = proptools.BoolPtr(true)
490 } else if module.ProductSpecific() {
491 props.Product_specific = proptools.BoolPtr(true)
492 }
493
Colin Cross9ae1b922018-06-26 17:59:05 -0700494 mctx.CreateModule(android.ModuleFactoryAdaptor(LibraryFactory), &props, &module.deviceProperties)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900495}
496
497// Creates the xml file that publicizes the runtime library
498func (module *sdkLibrary) createXmlFile(mctx android.TopDownMutatorContext) {
499 template := `
500<?xml version="1.0" encoding="utf-8"?>
501<!-- Copyright (C) 2018 The Android Open Source Project
502
503 Licensed under the Apache License, Version 2.0 (the "License");
504 you may not use this file except in compliance with the License.
505 You may obtain a copy of the License at
506
507 http://www.apache.org/licenses/LICENSE-2.0
508
509 Unless required by applicable law or agreed to in writing, software
510 distributed under the License is distributed on an "AS IS" BASIS,
511 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
512 See the License for the specific language governing permissions and
513 limitations under the License.
514-->
515
516<permissions>
517 <library name="%s" file="%s"/>
518</permissions>
519`
520 // genrule to generate the xml file content from the template above
521 // TODO: preserve newlines in the generate xml file. Newlines are being squashed
522 // in the ninja file. Do we need to have an external tool for this?
523 xmlContent := fmt.Sprintf(template, module.BaseModuleName(), module.implPath())
524 genruleProps := struct {
525 Name *string
526 Cmd *string
527 Out []string
528 }{}
529 genruleProps.Name = proptools.StringPtr(module.xmlFileName() + "-gen")
530 genruleProps.Cmd = proptools.StringPtr("echo '" + xmlContent + "' > $(out)")
531 genruleProps.Out = []string{module.xmlFileName()}
532 mctx.CreateModule(android.ModuleFactoryAdaptor(genrule.GenRuleFactory), &genruleProps)
533
534 // creates a prebuilt_etc module to actually place the xml file under
535 // <partition>/etc/permissions
536 etcProps := struct {
537 Name *string
Jiyong Park5a8d1be2018-04-25 22:57:34 +0900538 Src *string
Jiyong Parkc678ad32018-04-10 13:07:10 +0900539 Sub_dir *string
540 Soc_specific *bool
541 Device_specific *bool
542 Product_specific *bool
543 }{}
544 etcProps.Name = proptools.StringPtr(module.xmlFileName())
Jiyong Park5a8d1be2018-04-25 22:57:34 +0900545 etcProps.Src = proptools.StringPtr(":" + module.xmlFileName() + "-gen")
Jiyong Parkc678ad32018-04-10 13:07:10 +0900546 etcProps.Sub_dir = proptools.StringPtr("permissions")
547 if module.SocSpecific() {
548 etcProps.Soc_specific = proptools.BoolPtr(true)
549 } else if module.DeviceSpecific() {
550 etcProps.Device_specific = proptools.BoolPtr(true)
551 } else if module.ProductSpecific() {
552 etcProps.Product_specific = proptools.BoolPtr(true)
553 }
554 mctx.CreateModule(android.ModuleFactoryAdaptor(android.PrebuiltEtcFactory), &etcProps)
555}
556
557// to satisfy SdkLibraryDependency interface
558func (module *sdkLibrary) HeaderJars(linkType linkType) android.Paths {
559 // This module is just a wrapper for the stubs.
Sundong Ahn57368eb2018-07-06 11:20:23 +0900560 if linkType == javaSystem {
Jiyong Parkc678ad32018-04-10 13:07:10 +0900561 return module.systemApiStubsPath
Sundong Ahn57368eb2018-07-06 11:20:23 +0900562 } else if linkType == javaPlatform {
563 return module.implLibPath
Jiyong Parkc678ad32018-04-10 13:07:10 +0900564 } else {
565 return module.publicApiStubsPath
566 }
567}
568
Sundong Ahn241cd372018-07-13 16:16:44 +0900569// to satisfy SdkLibraryDependency interface
570func (module *sdkLibrary) ImplementationJars(linkType linkType) android.Paths {
571 // This module is just a wrapper for the stubs.
572 if linkType == javaSystem {
573 return module.systemApiStubsImplPath
574 } else if linkType == javaPlatform {
575 return module.implLibImplPath
576 } else {
577 return module.publicApiStubsImplPath
578 }
579}
580
Jiyong Park82484c02018-04-23 21:41:26 +0900581func javaSdkLibraries(config android.Config) *[]string {
582 return config.Once("javaSdkLibraries", func() interface{} {
583 return &[]string{}
584 }).(*[]string)
585}
586
Jiyong Parkc678ad32018-04-10 13:07:10 +0900587// For a java_sdk_library module, create internal modules for stubs, docs,
588// runtime libs and xml file. If requested, the stubs and docs are created twice
589// once for public API level and once for system API level
590func sdkLibraryMutator(mctx android.TopDownMutatorContext) {
591 if module, ok := mctx.Module().(*sdkLibrary); ok {
Anton Hansson8959e142018-04-25 11:56:13 +0100592 if module.properties.Srcs == nil {
593 mctx.PropertyErrorf("srcs", "java_sdk_library must specify srcs")
594 }
595 if module.properties.Api_packages == nil {
596 mctx.PropertyErrorf("api_packages", "java_sdk_library must specify api_packages")
597 }
598
Jiyong Parkc678ad32018-04-10 13:07:10 +0900599 // for public API stubs
Jiyong Parkdf130542018-04-27 16:29:21 +0900600 module.createStubsLibrary(mctx, apiScopePublic)
601 module.createDocs(mctx, apiScopePublic)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900602
603 // for system API stubs
Jiyong Parkdf130542018-04-27 16:29:21 +0900604 module.createStubsLibrary(mctx, apiScopeSystem)
605 module.createDocs(mctx, apiScopeSystem)
606
607 // for test API stubs
608 module.createStubsLibrary(mctx, apiScopeTest)
609 module.createDocs(mctx, apiScopeTest)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900610
611 // for runtime
612 module.createXmlFile(mctx)
613 module.createImplLibrary(mctx)
Jiyong Park82484c02018-04-23 21:41:26 +0900614
615 // record java_sdk_library modules so that they are exported to make
616 javaSdkLibraries := javaSdkLibraries(mctx.Config())
617 javaSdkLibrariesLock.Lock()
618 defer javaSdkLibrariesLock.Unlock()
619 *javaSdkLibraries = append(*javaSdkLibraries, module.BaseModuleName())
Jiyong Parkc678ad32018-04-10 13:07:10 +0900620 }
621}
622
623func sdkLibraryFactory() android.Module {
624 module := &sdkLibrary{}
625 module.AddProperties(&module.properties)
Jiyong Park441a47d2018-05-01 23:33:08 +0900626 module.AddProperties(&module.deviceProperties)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900627 android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibCommon)
628 android.InitDefaultableModule(module)
629 return module
630}