blob: 32b2d1ac21c6d42ec548a467f7b229c44ef0c87b [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"
Sundong Ahn054b19a2018-10-19 13:46:09 +090023 "path/filepath"
Jiyong Park82484c02018-04-23 21:41:26 +090024 "sort"
Jiyong Parkc678ad32018-04-10 13:07:10 +090025 "strings"
Jiyong Park82484c02018-04-23 21:41:26 +090026 "sync"
Jiyong Parkc678ad32018-04-10 13:07:10 +090027
28 "github.com/google/blueprint"
29 "github.com/google/blueprint/proptools"
30)
31
32var (
33 sdkStubsLibrarySuffix = ".stubs"
34 sdkSystemApiSuffix = ".system"
Jiyong Parkdf130542018-04-27 16:29:21 +090035 sdkTestApiSuffix = ".test"
Jiyong Parkc678ad32018-04-10 13:07:10 +090036 sdkDocsSuffix = ".docs"
Jiyong Parkc678ad32018-04-10 13:07:10 +090037 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 Ahn20e998b2018-07-24 11:19:26 +090049 publicApiFileTag = dependencyTag{name: "publicApi"}
50 systemApiFileTag = dependencyTag{name: "systemApi"}
51 testApiFileTag = dependencyTag{name: "testApi"}
Jiyong Parkdf130542018-04-27 16:29:21 +090052)
53
54type apiScope int
55
56const (
57 apiScopePublic apiScope = iota
58 apiScopeSystem
59 apiScopeTest
Jiyong Parkc678ad32018-04-10 13:07:10 +090060)
61
Jiyong Park82484c02018-04-23 21:41:26 +090062var (
63 javaSdkLibrariesLock sync.Mutex
64)
65
Jiyong Parkc678ad32018-04-10 13:07:10 +090066// TODO: these are big features that are currently missing
Jiyong Park1be96912018-05-28 18:02:19 +090067// 1) disallowing linking to the runtime shared lib
68// 2) HTML generation
Jiyong Parkc678ad32018-04-10 13:07:10 +090069
70func init() {
Paul Duffin43dc1cc2019-12-19 11:18:54 +000071 RegisterSdkLibraryBuildComponents(android.InitRegistrationContext)
Jiyong Parkc678ad32018-04-10 13:07:10 +090072
Jiyong Park82484c02018-04-23 21:41:26 +090073 android.RegisterMakeVarsProvider(pctx, func(ctx android.MakeVarsContext) {
74 javaSdkLibraries := javaSdkLibraries(ctx.Config())
75 sort.Strings(*javaSdkLibraries)
76 ctx.Strict("JAVA_SDK_LIBRARIES", strings.Join(*javaSdkLibraries, " "))
77 })
Jiyong Parkc678ad32018-04-10 13:07:10 +090078}
79
Paul Duffin43dc1cc2019-12-19 11:18:54 +000080func RegisterSdkLibraryBuildComponents(ctx android.RegistrationContext) {
81 ctx.RegisterModuleType("java_sdk_library", SdkLibraryFactory)
82 ctx.RegisterModuleType("java_sdk_library_import", sdkLibraryImportFactory)
83}
84
Jiyong Parkc678ad32018-04-10 13:07:10 +090085type sdkLibraryProperties struct {
Sundong Ahnf043cf62018-06-25 16:04:37 +090086 // List of Java libraries that will be in the classpath when building stubs
87 Stub_only_libs []string `android:"arch_variant"`
88
Jiyong Parkc678ad32018-04-10 13:07:10 +090089 // list of package names that will be documented and publicized as API
90 Api_packages []string
91
Jiyong Park5a2c9d72018-05-01 22:25:41 +090092 // list of package names that must be hidden from the API
93 Hidden_api_packages []string
94
Paul Duffin11512472019-02-11 15:55:17 +000095 // local files that are used within user customized droiddoc options.
96 Droiddoc_option_files []string
97
98 // additional droiddoc options
99 // Available variables for substitution:
100 //
101 // $(location <label>): the path to the droiddoc_option_files with name <label>
Sundong Ahndd567f92018-07-31 17:19:11 +0900102 Droiddoc_options []string
103
Sundong Ahn054b19a2018-10-19 13:46:09 +0900104 // a list of top-level directories containing files to merge qualifier annotations
105 // (i.e. those intended to be included in the stubs written) from.
106 Merge_annotations_dirs []string
107
108 // a list of top-level directories containing Java stub files to merge show/hide annotations from.
109 Merge_inclusion_annotations_dirs []string
110
111 // If set to true, the path of dist files is apistubs/core. Defaults to false.
112 Core_lib *bool
113
Sundong Ahn80a87b32019-05-13 15:02:50 +0900114 // don't create dist rules.
115 No_dist *bool `blueprint:"mutated"`
116
Jiyong Parkc678ad32018-04-10 13:07:10 +0900117 // TODO: determines whether to create HTML doc or not
118 //Html_doc *bool
119}
120
Inseob Kimc0907f12019-02-08 21:00:45 +0900121type SdkLibrary struct {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900122 Library
Jiyong Parkc678ad32018-04-10 13:07:10 +0900123
Sundong Ahn054b19a2018-10-19 13:46:09 +0900124 sdkLibraryProperties sdkLibraryProperties
Jiyong Parkc678ad32018-04-10 13:07:10 +0900125
126 publicApiStubsPath android.Paths
127 systemApiStubsPath android.Paths
Jiyong Parkdf130542018-04-27 16:29:21 +0900128 testApiStubsPath android.Paths
Sundong Ahn241cd372018-07-13 16:16:44 +0900129
130 publicApiStubsImplPath android.Paths
131 systemApiStubsImplPath android.Paths
132 testApiStubsImplPath android.Paths
Sundong Ahn20e998b2018-07-24 11:19:26 +0900133
134 publicApiFilePath android.Path
135 systemApiFilePath android.Path
136 testApiFilePath android.Path
Jiyong Parkc678ad32018-04-10 13:07:10 +0900137}
138
Inseob Kimc0907f12019-02-08 21:00:45 +0900139var _ Dependency = (*SdkLibrary)(nil)
140var _ SdkLibraryDependency = (*SdkLibrary)(nil)
Colin Cross897d2ed2019-02-11 14:03:51 -0800141
Inseob Kimc0907f12019-02-08 21:00:45 +0900142func (module *SdkLibrary) DepsMutator(ctx android.BottomUpMutatorContext) {
Jiyong Parke3ef3c82019-07-15 15:31:16 +0900143 useBuiltStubs := !ctx.Config().UnbundledBuildUsePrebuiltSdks()
Jiyong Parkc678ad32018-04-10 13:07:10 +0900144 // Add dependencies to the stubs library
Jiyong Parke3ef3c82019-07-15 15:31:16 +0900145 if useBuiltStubs {
146 ctx.AddVariationDependencies(nil, publicApiStubsTag, module.stubsName(apiScopePublic))
147 }
Colin Cross42d48b72018-08-29 14:10:52 -0700148 ctx.AddVariationDependencies(nil, publicApiFileTag, module.docsName(apiScopePublic))
Sundong Ahn054b19a2018-10-19 13:46:09 +0900149
Paul Duffin250e6192019-06-07 10:44:37 +0100150 sdkDep := decodeSdkDep(ctx, sdkContext(&module.Library))
151 if sdkDep.hasStandardLibs() {
Jiyong Parke3ef3c82019-07-15 15:31:16 +0900152 if useBuiltStubs {
153 ctx.AddVariationDependencies(nil, systemApiStubsTag, module.stubsName(apiScopeSystem))
154 ctx.AddVariationDependencies(nil, testApiStubsTag, module.stubsName(apiScopeTest))
155 }
Sundong Ahn054b19a2018-10-19 13:46:09 +0900156 ctx.AddVariationDependencies(nil, systemApiFileTag, module.docsName(apiScopeSystem))
157 ctx.AddVariationDependencies(nil, testApiFileTag, module.docsName(apiScopeTest))
Sundong Ahn054b19a2018-10-19 13:46:09 +0900158 }
159
160 module.Library.deps(ctx)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900161}
162
Inseob Kimc0907f12019-02-08 21:00:45 +0900163func (module *SdkLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900164 module.Library.GenerateAndroidBuildActions(ctx)
165
Sundong Ahn57368eb2018-07-06 11:20:23 +0900166 // Record the paths to the header jars of the library (stubs and impl).
Jiyong Parkc678ad32018-04-10 13:07:10 +0900167 // When this java_sdk_library is dependened from others via "libs" property,
168 // the recorded paths will be returned depending on the link type of the caller.
169 ctx.VisitDirectDeps(func(to android.Module) {
170 otherName := ctx.OtherModuleName(to)
171 tag := ctx.OtherModuleDependencyTag(to)
172
Sundong Ahn57368eb2018-07-06 11:20:23 +0900173 if lib, ok := to.(Dependency); ok {
Jiyong Parkc678ad32018-04-10 13:07:10 +0900174 switch tag {
175 case publicApiStubsTag:
Sundong Ahn57368eb2018-07-06 11:20:23 +0900176 module.publicApiStubsPath = lib.HeaderJars()
Sundong Ahn241cd372018-07-13 16:16:44 +0900177 module.publicApiStubsImplPath = lib.ImplementationJars()
Jiyong Parkc678ad32018-04-10 13:07:10 +0900178 case systemApiStubsTag:
Sundong Ahn57368eb2018-07-06 11:20:23 +0900179 module.systemApiStubsPath = lib.HeaderJars()
Sundong Ahn241cd372018-07-13 16:16:44 +0900180 module.systemApiStubsImplPath = lib.ImplementationJars()
Jiyong Parkdf130542018-04-27 16:29:21 +0900181 case testApiStubsTag:
Sundong Ahn57368eb2018-07-06 11:20:23 +0900182 module.testApiStubsPath = lib.HeaderJars()
Sundong Ahn241cd372018-07-13 16:16:44 +0900183 module.testApiStubsImplPath = lib.ImplementationJars()
Jiyong Parkc678ad32018-04-10 13:07:10 +0900184 }
185 }
Sundong Ahn20e998b2018-07-24 11:19:26 +0900186 if doc, ok := to.(ApiFilePath); ok {
187 switch tag {
188 case publicApiFileTag:
189 module.publicApiFilePath = doc.ApiFilePath()
190 case systemApiFileTag:
191 module.systemApiFilePath = doc.ApiFilePath()
192 case testApiFileTag:
193 module.testApiFilePath = doc.ApiFilePath()
194 default:
195 ctx.ModuleErrorf("depends on module %q of unknown tag %q", otherName, tag)
196 }
197 }
Jiyong Parkc678ad32018-04-10 13:07:10 +0900198 })
199}
200
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900201func (module *SdkLibrary) AndroidMkEntries() []android.AndroidMkEntries {
202 entriesList := module.Library.AndroidMkEntries()
203 entries := &entriesList[0]
Jaewoong Jungb0c127c2019-08-29 14:56:03 -0700204 entries.Required = append(entries.Required, module.xmlFileName())
Sundong Ahn054b19a2018-10-19 13:46:09 +0900205
Jaewoong Jungb0c127c2019-08-29 14:56:03 -0700206 entries.ExtraFooters = []android.AndroidMkExtraFootersFunc{
207 func(w io.Writer, name, prefix, moduleDir string, entries *android.AndroidMkEntries) {
Jaewoong Jungb0c127c2019-08-29 14:56:03 -0700208 if !Bool(module.sdkLibraryProperties.No_dist) {
209 // Create a phony module that installs the impl library, for the case when this lib is
210 // in PRODUCT_PACKAGES.
211 owner := module.ModuleBase.Owner()
212 if owner == "" {
213 if Bool(module.sdkLibraryProperties.Core_lib) {
214 owner = "core"
215 } else {
216 owner = "android"
217 }
218 }
219 // Create dist rules to install the stubs libs to the dist dir
220 if len(module.publicApiStubsPath) == 1 {
221 fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+
222 module.publicApiStubsImplPath.Strings()[0]+
223 ":"+path.Join("apistubs", owner, "public",
224 module.BaseModuleName()+".jar")+")")
225 }
226 if len(module.systemApiStubsPath) == 1 {
227 fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+
228 module.systemApiStubsImplPath.Strings()[0]+
229 ":"+path.Join("apistubs", owner, "system",
230 module.BaseModuleName()+".jar")+")")
231 }
232 if len(module.testApiStubsPath) == 1 {
233 fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+
234 module.testApiStubsImplPath.Strings()[0]+
235 ":"+path.Join("apistubs", owner, "test",
236 module.BaseModuleName()+".jar")+")")
237 }
238 if module.publicApiFilePath != nil {
239 fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+
240 module.publicApiFilePath.String()+
241 ":"+path.Join("apistubs", owner, "public", "api",
242 module.BaseModuleName()+".txt")+")")
243 }
244 if module.systemApiFilePath != nil {
245 fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+
246 module.systemApiFilePath.String()+
247 ":"+path.Join("apistubs", owner, "system", "api",
248 module.BaseModuleName()+".txt")+")")
249 }
250 if module.testApiFilePath != nil {
251 fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+
252 module.testApiFilePath.String()+
253 ":"+path.Join("apistubs", owner, "test", "api",
254 module.BaseModuleName()+".txt")+")")
Sundong Ahn80a87b32019-05-13 15:02:50 +0900255 }
Sundong Ahn4fd04bb2018-08-31 18:01:37 +0900256 }
Jaewoong Jungb0c127c2019-08-29 14:56:03 -0700257 },
Jiyong Park82484c02018-04-23 21:41:26 +0900258 }
Jiyong Park0b0e1b92019-12-03 13:24:29 +0900259 return entriesList
Jiyong Park82484c02018-04-23 21:41:26 +0900260}
261
Jiyong Parkc678ad32018-04-10 13:07:10 +0900262// Module name of the stubs library
Inseob Kimc0907f12019-02-08 21:00:45 +0900263func (module *SdkLibrary) stubsName(apiScope apiScope) string {
Jiyong Parkc678ad32018-04-10 13:07:10 +0900264 stubsName := module.BaseModuleName() + sdkStubsLibrarySuffix
Jiyong Parkdf130542018-04-27 16:29:21 +0900265 switch apiScope {
266 case apiScopeSystem:
Jiyong Parkc678ad32018-04-10 13:07:10 +0900267 stubsName = stubsName + sdkSystemApiSuffix
Jiyong Parkdf130542018-04-27 16:29:21 +0900268 case apiScopeTest:
269 stubsName = stubsName + sdkTestApiSuffix
Jiyong Parkc678ad32018-04-10 13:07:10 +0900270 }
271 return stubsName
272}
273
274// Module name of the docs
Inseob Kimc0907f12019-02-08 21:00:45 +0900275func (module *SdkLibrary) docsName(apiScope apiScope) string {
Jiyong Parkc678ad32018-04-10 13:07:10 +0900276 docsName := module.BaseModuleName() + sdkDocsSuffix
Jiyong Parkdf130542018-04-27 16:29:21 +0900277 switch apiScope {
278 case apiScopeSystem:
Jiyong Parkc678ad32018-04-10 13:07:10 +0900279 docsName = docsName + sdkSystemApiSuffix
Jiyong Parkdf130542018-04-27 16:29:21 +0900280 case apiScopeTest:
281 docsName = docsName + sdkTestApiSuffix
Jiyong Parkc678ad32018-04-10 13:07:10 +0900282 }
283 return docsName
284}
285
286// Module name of the runtime implementation library
Inseob Kimc0907f12019-02-08 21:00:45 +0900287func (module *SdkLibrary) implName() string {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900288 return module.BaseModuleName()
Jiyong Parkc678ad32018-04-10 13:07:10 +0900289}
290
291// File path to the runtime implementation library
Inseob Kimc0907f12019-02-08 21:00:45 +0900292func (module *SdkLibrary) implPath() string {
Jiyong Parkc678ad32018-04-10 13:07:10 +0900293 partition := "system"
294 if module.SocSpecific() {
295 partition = "vendor"
296 } else if module.DeviceSpecific() {
297 partition = "odm"
298 } else if module.ProductSpecific() {
299 partition = "product"
Sundong Ahn0d7dff42019-12-04 12:53:44 +0900300 } else if module.SystemExtSpecific() {
301 partition = "system_ext"
Jiyong Parkc678ad32018-04-10 13:07:10 +0900302 }
303 return "/" + partition + "/framework/" + module.implName() + ".jar"
304}
305
306// Module name of the XML file for the lib
Inseob Kimc0907f12019-02-08 21:00:45 +0900307func (module *SdkLibrary) xmlFileName() string {
Jiyong Parkc678ad32018-04-10 13:07:10 +0900308 return module.BaseModuleName() + sdkXmlFileSuffix
309}
310
311// SDK version that the stubs library is built against. Note that this is always
312// *current. Older stubs library built with a numberd SDK version is created from
313// the prebuilt jar.
Inseob Kimc0907f12019-02-08 21:00:45 +0900314func (module *SdkLibrary) sdkVersion(apiScope apiScope) string {
Jiyong Parkdf130542018-04-27 16:29:21 +0900315 switch apiScope {
316 case apiScopePublic:
317 return "current"
318 case apiScopeSystem:
Jiyong Parkc678ad32018-04-10 13:07:10 +0900319 return "system_current"
Jiyong Parkdf130542018-04-27 16:29:21 +0900320 case apiScopeTest:
321 return "test_current"
322 default:
Jiyong Parkc678ad32018-04-10 13:07:10 +0900323 return "current"
324 }
325}
326
327// $(INTERNAL_PLATFORM_<apiTagName>_API_FILE) points to the generated
328// api file for the current source
329// TODO: remove this when apicheck is done in soong
Inseob Kimc0907f12019-02-08 21:00:45 +0900330func (module *SdkLibrary) apiTagName(apiScope apiScope) string {
Jiyong Parkc678ad32018-04-10 13:07:10 +0900331 apiTagName := strings.Replace(strings.ToUpper(module.BaseModuleName()), ".", "_", -1)
Jiyong Parkdf130542018-04-27 16:29:21 +0900332 switch apiScope {
333 case apiScopeSystem:
Jiyong Parkc678ad32018-04-10 13:07:10 +0900334 apiTagName = apiTagName + "_SYSTEM"
Jiyong Parkdf130542018-04-27 16:29:21 +0900335 case apiScopeTest:
336 apiTagName = apiTagName + "_TEST"
Jiyong Parkc678ad32018-04-10 13:07:10 +0900337 }
338 return apiTagName
339}
340
Inseob Kimc0907f12019-02-08 21:00:45 +0900341func (module *SdkLibrary) latestApiFilegroupName(apiScope apiScope) string {
Jiyong Park58c518b2018-05-12 22:29:12 +0900342 name := ":" + module.BaseModuleName() + ".api."
Jiyong Parkdf130542018-04-27 16:29:21 +0900343 switch apiScope {
Jiyong Park58c518b2018-05-12 22:29:12 +0900344 case apiScopePublic:
345 name = name + "public"
Jiyong Parkdf130542018-04-27 16:29:21 +0900346 case apiScopeSystem:
Jiyong Park58c518b2018-05-12 22:29:12 +0900347 name = name + "system"
Jiyong Parkdf130542018-04-27 16:29:21 +0900348 case apiScopeTest:
Jiyong Park58c518b2018-05-12 22:29:12 +0900349 name = name + "test"
Jiyong Parkc678ad32018-04-10 13:07:10 +0900350 }
Jiyong Park58c518b2018-05-12 22:29:12 +0900351 name = name + ".latest"
352 return name
353}
Jiyong Parkc678ad32018-04-10 13:07:10 +0900354
Inseob Kimc0907f12019-02-08 21:00:45 +0900355func (module *SdkLibrary) latestRemovedApiFilegroupName(apiScope apiScope) string {
Jiyong Park58c518b2018-05-12 22:29:12 +0900356 name := ":" + module.BaseModuleName() + "-removed.api."
357 switch apiScope {
358 case apiScopePublic:
359 name = name + "public"
360 case apiScopeSystem:
361 name = name + "system"
362 case apiScopeTest:
363 name = name + "test"
364 }
365 name = name + ".latest"
366 return name
Jiyong Parkc678ad32018-04-10 13:07:10 +0900367}
368
369// Creates a static java library that has API stubs
Colin Crossf8b860a2019-04-16 14:43:28 -0700370func (module *SdkLibrary) createStubsLibrary(mctx android.LoadHookContext, apiScope apiScope) {
Jiyong Parkc678ad32018-04-10 13:07:10 +0900371 props := struct {
Sundong Ahn0d7dff42019-12-04 12:53:44 +0900372 Name *string
373 Srcs []string
374 Sdk_version *string
375 Libs []string
376 Soc_specific *bool
377 Device_specific *bool
378 Product_specific *bool
379 System_ext_specific *bool
380 Compile_dex *bool
381 System_modules *string
382 Java_version *string
383 Product_variables struct {
Jiyong Parkc678ad32018-04-10 13:07:10 +0900384 Unbundled_build struct {
385 Enabled *bool
386 }
Jiyong Park82484c02018-04-23 21:41:26 +0900387 Pdk struct {
388 Enabled *bool
389 }
Jiyong Parkc678ad32018-04-10 13:07:10 +0900390 }
Sundong Ahn054b19a2018-10-19 13:46:09 +0900391 Openjdk9 struct {
392 Srcs []string
393 Javacflags []string
394 }
Jiyong Parkc678ad32018-04-10 13:07:10 +0900395 }{}
396
Paul Duffin52d398a2019-06-11 12:31:14 +0100397 sdkVersion := module.sdkVersion(apiScope)
Paul Duffin250e6192019-06-07 10:44:37 +0100398 sdkDep := decodeSdkDep(mctx, sdkContext(&module.Library))
Paul Duffin52d398a2019-06-11 12:31:14 +0100399 if !sdkDep.hasStandardLibs() {
400 sdkVersion = "none"
401 }
Paul Duffin250e6192019-06-07 10:44:37 +0100402
Jiyong Parkdf130542018-04-27 16:29:21 +0900403 props.Name = proptools.StringPtr(module.stubsName(apiScope))
Jiyong Parkc678ad32018-04-10 13:07:10 +0900404 // sources are generated from the droiddoc
Jiyong Parkdf130542018-04-27 16:29:21 +0900405 props.Srcs = []string{":" + module.docsName(apiScope)}
Paul Duffin52d398a2019-06-11 12:31:14 +0100406 props.Sdk_version = proptools.StringPtr(sdkVersion)
Sundong Ahn054b19a2018-10-19 13:46:09 +0900407 props.Libs = module.sdkLibraryProperties.Stub_only_libs
Jiyong Parkc678ad32018-04-10 13:07:10 +0900408 // Unbundled apps will use the prebult one from /prebuilts/sdk
Colin Cross10932872019-04-18 14:27:12 -0700409 if mctx.Config().UnbundledBuildUsePrebuiltSdks() {
Colin Cross2c77ceb2019-01-21 11:56:21 -0800410 props.Product_variables.Unbundled_build.Enabled = proptools.BoolPtr(false)
411 }
Jiyong Park82484c02018-04-23 21:41:26 +0900412 props.Product_variables.Pdk.Enabled = proptools.BoolPtr(false)
Sundong Ahn054b19a2018-10-19 13:46:09 +0900413 props.System_modules = module.Library.Module.deviceProperties.System_modules
414 props.Openjdk9.Srcs = module.Library.Module.properties.Openjdk9.Srcs
415 props.Openjdk9.Javacflags = module.Library.Module.properties.Openjdk9.Javacflags
416 props.Java_version = module.Library.Module.properties.Java_version
417 if module.Library.Module.deviceProperties.Compile_dex != nil {
418 props.Compile_dex = module.Library.Module.deviceProperties.Compile_dex
Sundong Ahndd567f92018-07-31 17:19:11 +0900419 }
Jiyong Parkc678ad32018-04-10 13:07:10 +0900420
421 if module.SocSpecific() {
422 props.Soc_specific = proptools.BoolPtr(true)
423 } else if module.DeviceSpecific() {
424 props.Device_specific = proptools.BoolPtr(true)
425 } else if module.ProductSpecific() {
426 props.Product_specific = proptools.BoolPtr(true)
Sundong Ahn0d7dff42019-12-04 12:53:44 +0900427 } else if module.SystemExtSpecific() {
428 props.System_ext_specific = proptools.BoolPtr(true)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900429 }
430
Colin Cross84dfc3d2019-09-25 11:33:01 -0700431 mctx.CreateModule(LibraryFactory, &props)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900432}
433
434// Creates a droiddoc module that creates stubs source files from the given full source
435// files
Colin Crossf8b860a2019-04-16 14:43:28 -0700436func (module *SdkLibrary) createDocs(mctx android.LoadHookContext, apiScope apiScope) {
Jiyong Parkc678ad32018-04-10 13:07:10 +0900437 props := struct {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900438 Name *string
439 Srcs []string
440 Installable *bool
Paul Duffin52d398a2019-06-11 12:31:14 +0100441 Sdk_version *string
Sundong Ahn054b19a2018-10-19 13:46:09 +0900442 Libs []string
Paul Duffin11512472019-02-11 15:55:17 +0000443 Arg_files []string
Sundong Ahn054b19a2018-10-19 13:46:09 +0900444 Args *string
445 Api_tag_name *string
446 Api_filename *string
447 Removed_api_filename *string
Sundong Ahn054b19a2018-10-19 13:46:09 +0900448 Java_version *string
449 Merge_annotations_dirs []string
450 Merge_inclusion_annotations_dirs []string
451 Check_api struct {
Inseob Kim38449af2019-02-28 14:24:05 +0900452 Current ApiToCheck
453 Last_released ApiToCheck
454 Ignore_missing_latest_api *bool
Jiyong Park58c518b2018-05-12 22:29:12 +0900455 }
Sundong Ahn1b92c822018-05-29 11:35:17 +0900456 Aidl struct {
457 Include_dirs []string
458 Local_include_dirs []string
459 }
Jiyong Parkc678ad32018-04-10 13:07:10 +0900460 }{}
461
Paul Duffin250e6192019-06-07 10:44:37 +0100462 sdkDep := decodeSdkDep(mctx, sdkContext(&module.Library))
Paul Duffin52d398a2019-06-11 12:31:14 +0100463 sdkVersion := ""
464 if !sdkDep.hasStandardLibs() {
465 sdkVersion = "none"
466 }
Paul Duffin250e6192019-06-07 10:44:37 +0100467
Jiyong Parkdf130542018-04-27 16:29:21 +0900468 props.Name = proptools.StringPtr(module.docsName(apiScope))
Sundong Ahn054b19a2018-10-19 13:46:09 +0900469 props.Srcs = append(props.Srcs, module.Library.Module.properties.Srcs...)
Paul Duffin52d398a2019-06-11 12:31:14 +0100470 props.Sdk_version = proptools.StringPtr(sdkVersion)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900471 props.Installable = proptools.BoolPtr(false)
Sundong Ahne6f0b052018-06-05 16:46:14 +0900472 // A droiddoc module has only one Libs property and doesn't distinguish between
473 // shared libs and static libs. So we need to add both of these libs to Libs property.
Sundong Ahn054b19a2018-10-19 13:46:09 +0900474 props.Libs = module.Library.Module.properties.Libs
475 props.Libs = append(props.Libs, module.Library.Module.properties.Static_libs...)
476 props.Aidl.Include_dirs = module.Library.Module.deviceProperties.Aidl.Include_dirs
477 props.Aidl.Local_include_dirs = module.Library.Module.deviceProperties.Aidl.Local_include_dirs
Sundong Ahn054b19a2018-10-19 13:46:09 +0900478 props.Java_version = module.Library.Module.properties.Java_version
Jiyong Parkc678ad32018-04-10 13:07:10 +0900479
Sundong Ahn054b19a2018-10-19 13:46:09 +0900480 props.Merge_annotations_dirs = module.sdkLibraryProperties.Merge_annotations_dirs
481 props.Merge_inclusion_annotations_dirs = module.sdkLibraryProperties.Merge_inclusion_annotations_dirs
482
483 droiddocArgs := " --stub-packages " + strings.Join(module.sdkLibraryProperties.Api_packages, ":") +
484 " " + android.JoinWithPrefix(module.sdkLibraryProperties.Hidden_api_packages, " --hide-package ") +
485 " " + android.JoinWithPrefix(module.sdkLibraryProperties.Droiddoc_options, " ") +
Sundong Ahn04ef8a32019-01-14 11:36:50 +0900486 " --hide MissingPermission --hide BroadcastBehavior " +
487 "--hide HiddenSuperclass --hide DeprecationMismatch --hide UnavailableSymbol " +
488 "--hide SdkConstant --hide HiddenTypeParameter --hide Todo --hide Typo"
Sundong Ahnfb2721f2018-09-17 13:23:09 +0900489
Jiyong Parkdf130542018-04-27 16:29:21 +0900490 switch apiScope {
491 case apiScopeSystem:
Jiyong Parkc678ad32018-04-10 13:07:10 +0900492 droiddocArgs = droiddocArgs + " -showAnnotation android.annotation.SystemApi"
Jiyong Parkdf130542018-04-27 16:29:21 +0900493 case apiScopeTest:
494 droiddocArgs = droiddocArgs + " -showAnnotation android.annotation.TestApi"
Jiyong Parkc678ad32018-04-10 13:07:10 +0900495 }
Paul Duffin11512472019-02-11 15:55:17 +0000496 props.Arg_files = module.sdkLibraryProperties.Droiddoc_option_files
Jiyong Parkc678ad32018-04-10 13:07:10 +0900497 props.Args = proptools.StringPtr(droiddocArgs)
498
499 // List of APIs identified from the provided source files are created. They are later
500 // compared against to the not-yet-released (a.k.a current) list of APIs and to the
501 // last-released (a.k.a numbered) list of API.
Jiyong Parkc678ad32018-04-10 13:07:10 +0900502 currentApiFileName := "current.txt"
503 removedApiFileName := "removed.txt"
Jiyong Parkdf130542018-04-27 16:29:21 +0900504 switch apiScope {
505 case apiScopeSystem:
Jiyong Parkc678ad32018-04-10 13:07:10 +0900506 currentApiFileName = "system-" + currentApiFileName
507 removedApiFileName = "system-" + removedApiFileName
Jiyong Parkdf130542018-04-27 16:29:21 +0900508 case apiScopeTest:
509 currentApiFileName = "test-" + currentApiFileName
510 removedApiFileName = "test-" + removedApiFileName
Jiyong Parkc678ad32018-04-10 13:07:10 +0900511 }
512 currentApiFileName = path.Join("api", currentApiFileName)
513 removedApiFileName = path.Join("api", removedApiFileName)
Jiyong Park58c518b2018-05-12 22:29:12 +0900514 // TODO(jiyong): remove these three props
Jiyong Parkdf130542018-04-27 16:29:21 +0900515 props.Api_tag_name = proptools.StringPtr(module.apiTagName(apiScope))
Jiyong Parkc678ad32018-04-10 13:07:10 +0900516 props.Api_filename = proptools.StringPtr(currentApiFileName)
517 props.Removed_api_filename = proptools.StringPtr(removedApiFileName)
518
Jiyong Park58c518b2018-05-12 22:29:12 +0900519 // check against the not-yet-release API
520 props.Check_api.Current.Api_file = proptools.StringPtr(currentApiFileName)
521 props.Check_api.Current.Removed_api_file = proptools.StringPtr(removedApiFileName)
Jiyong Park58c518b2018-05-12 22:29:12 +0900522
523 // check against the latest released API
524 props.Check_api.Last_released.Api_file = proptools.StringPtr(
525 module.latestApiFilegroupName(apiScope))
526 props.Check_api.Last_released.Removed_api_file = proptools.StringPtr(
527 module.latestRemovedApiFilegroupName(apiScope))
Inseob Kim38449af2019-02-28 14:24:05 +0900528 props.Check_api.Ignore_missing_latest_api = proptools.BoolPtr(true)
Jiyong Park58c518b2018-05-12 22:29:12 +0900529
Colin Cross84dfc3d2019-09-25 11:33:01 -0700530 mctx.CreateModule(DroidstubsFactory, &props)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900531}
532
Jiyong Parkc678ad32018-04-10 13:07:10 +0900533// Creates the xml file that publicizes the runtime library
Colin Crossf8b860a2019-04-16 14:43:28 -0700534func (module *SdkLibrary) createXmlFile(mctx android.LoadHookContext) {
Jiyong Parkc678ad32018-04-10 13:07:10 +0900535 template := `
536<?xml version="1.0" encoding="utf-8"?>
537<!-- Copyright (C) 2018 The Android Open Source Project
538
539 Licensed under the Apache License, Version 2.0 (the "License");
540 you may not use this file except in compliance with the License.
541 You may obtain a copy of the License at
Jiyong Park1112c4c2019-08-16 21:12:10 +0900542
Jiyong Parkc678ad32018-04-10 13:07:10 +0900543 http://www.apache.org/licenses/LICENSE-2.0
Jiyong Park1112c4c2019-08-16 21:12:10 +0900544
Jiyong Parkc678ad32018-04-10 13:07:10 +0900545 Unless required by applicable law or agreed to in writing, software
546 distributed under the License is distributed on an "AS IS" BASIS,
547 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
548 See the License for the specific language governing permissions and
549 limitations under the License.
550-->
551
552<permissions>
553 <library name="%s" file="%s"/>
554</permissions>
555`
556 // genrule to generate the xml file content from the template above
557 // TODO: preserve newlines in the generate xml file. Newlines are being squashed
558 // in the ninja file. Do we need to have an external tool for this?
559 xmlContent := fmt.Sprintf(template, module.BaseModuleName(), module.implPath())
560 genruleProps := struct {
561 Name *string
562 Cmd *string
563 Out []string
564 }{}
565 genruleProps.Name = proptools.StringPtr(module.xmlFileName() + "-gen")
566 genruleProps.Cmd = proptools.StringPtr("echo '" + xmlContent + "' > $(out)")
567 genruleProps.Out = []string{module.xmlFileName()}
Colin Cross84dfc3d2019-09-25 11:33:01 -0700568 mctx.CreateModule(genrule.GenRuleFactory, &genruleProps)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900569
570 // creates a prebuilt_etc module to actually place the xml file under
571 // <partition>/etc/permissions
572 etcProps := struct {
Sundong Ahn0d7dff42019-12-04 12:53:44 +0900573 Name *string
574 Src *string
575 Sub_dir *string
576 Soc_specific *bool
577 Device_specific *bool
578 Product_specific *bool
579 System_ext_specific *bool
Jiyong Parkc678ad32018-04-10 13:07:10 +0900580 }{}
581 etcProps.Name = proptools.StringPtr(module.xmlFileName())
Jiyong Park5a8d1be2018-04-25 22:57:34 +0900582 etcProps.Src = proptools.StringPtr(":" + module.xmlFileName() + "-gen")
Jiyong Parkc678ad32018-04-10 13:07:10 +0900583 etcProps.Sub_dir = proptools.StringPtr("permissions")
584 if module.SocSpecific() {
585 etcProps.Soc_specific = proptools.BoolPtr(true)
586 } else if module.DeviceSpecific() {
587 etcProps.Device_specific = proptools.BoolPtr(true)
588 } else if module.ProductSpecific() {
589 etcProps.Product_specific = proptools.BoolPtr(true)
Sundong Ahn0d7dff42019-12-04 12:53:44 +0900590 } else if module.SystemExtSpecific() {
591 etcProps.System_ext_specific = proptools.BoolPtr(true)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900592 }
Colin Cross84dfc3d2019-09-25 11:33:01 -0700593 mctx.CreateModule(android.PrebuiltEtcFactory, &etcProps)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900594}
595
Colin Cross0ea8ba82019-06-06 14:33:29 -0700596func (module *SdkLibrary) PrebuiltJars(ctx android.BaseModuleContext, sdkVersion string) android.Paths {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900597 var api, v string
Paul Duffin52d398a2019-06-11 12:31:14 +0100598 if sdkVersion == "" || sdkVersion == "none" {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900599 api = "system"
600 v = "current"
601 } else if strings.Contains(sdkVersion, "_") {
602 t := strings.Split(sdkVersion, "_")
603 api = t[0]
604 v = t[1]
Jiyong Parkc678ad32018-04-10 13:07:10 +0900605 } else {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900606 api = "public"
607 v = sdkVersion
608 }
609 dir := filepath.Join("prebuilts", "sdk", v, api)
610 jar := filepath.Join(dir, module.BaseModuleName()+".jar")
611 jarPath := android.ExistentPathForSource(ctx, jar)
Sundong Ahnae418ac2019-02-28 15:01:28 +0900612 if !jarPath.Valid() {
613 ctx.PropertyErrorf("sdk_library", "invalid sdk version %q, %q does not exist", v, jar)
614 return nil
615 }
Sundong Ahn054b19a2018-10-19 13:46:09 +0900616 return android.Paths{jarPath.Path()}
617}
618
619// to satisfy SdkLibraryDependency interface
Colin Cross0ea8ba82019-06-06 14:33:29 -0700620func (module *SdkLibrary) SdkHeaderJars(ctx android.BaseModuleContext, sdkVersion string) android.Paths {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900621 // This module is just a wrapper for the stubs.
Colin Cross10932872019-04-18 14:27:12 -0700622 if ctx.Config().UnbundledBuildUsePrebuiltSdks() {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900623 return module.PrebuiltJars(ctx, sdkVersion)
624 } else {
625 if strings.HasPrefix(sdkVersion, "system_") {
626 return module.systemApiStubsPath
627 } else if sdkVersion == "" {
628 return module.Library.HeaderJars()
629 } else {
630 return module.publicApiStubsPath
631 }
Jiyong Parkc678ad32018-04-10 13:07:10 +0900632 }
633}
634
Sundong Ahn241cd372018-07-13 16:16:44 +0900635// to satisfy SdkLibraryDependency interface
Colin Cross0ea8ba82019-06-06 14:33:29 -0700636func (module *SdkLibrary) SdkImplementationJars(ctx android.BaseModuleContext, sdkVersion string) android.Paths {
Sundong Ahn241cd372018-07-13 16:16:44 +0900637 // This module is just a wrapper for the stubs.
Colin Cross10932872019-04-18 14:27:12 -0700638 if ctx.Config().UnbundledBuildUsePrebuiltSdks() {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900639 return module.PrebuiltJars(ctx, sdkVersion)
Sundong Ahn241cd372018-07-13 16:16:44 +0900640 } else {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900641 if strings.HasPrefix(sdkVersion, "system_") {
642 return module.systemApiStubsImplPath
643 } else if sdkVersion == "" {
644 return module.Library.ImplementationJars()
645 } else {
646 return module.publicApiStubsImplPath
647 }
Sundong Ahn241cd372018-07-13 16:16:44 +0900648 }
649}
650
Sundong Ahn80a87b32019-05-13 15:02:50 +0900651func (module *SdkLibrary) SetNoDist() {
652 module.sdkLibraryProperties.No_dist = proptools.BoolPtr(true)
653}
654
Colin Cross571cccf2019-02-04 11:22:08 -0800655var javaSdkLibrariesKey = android.NewOnceKey("javaSdkLibraries")
656
Jiyong Park82484c02018-04-23 21:41:26 +0900657func javaSdkLibraries(config android.Config) *[]string {
Colin Cross571cccf2019-02-04 11:22:08 -0800658 return config.Once(javaSdkLibrariesKey, func() interface{} {
Jiyong Park82484c02018-04-23 21:41:26 +0900659 return &[]string{}
660 }).(*[]string)
661}
662
Jiyong Parkc678ad32018-04-10 13:07:10 +0900663// For a java_sdk_library module, create internal modules for stubs, docs,
664// runtime libs and xml file. If requested, the stubs and docs are created twice
665// once for public API level and once for system API level
Colin Crossf8b860a2019-04-16 14:43:28 -0700666func (module *SdkLibrary) CreateInternalModules(mctx android.LoadHookContext) {
Inseob Kim6e93ac92019-03-21 17:43:49 +0900667 if len(module.Library.Module.properties.Srcs) == 0 {
Inseob Kimc0907f12019-02-08 21:00:45 +0900668 mctx.PropertyErrorf("srcs", "java_sdk_library must specify srcs")
669 }
670
Inseob Kim6e93ac92019-03-21 17:43:49 +0900671 if len(module.sdkLibraryProperties.Api_packages) == 0 {
Inseob Kimc0907f12019-02-08 21:00:45 +0900672 mctx.PropertyErrorf("api_packages", "java_sdk_library must specify api_packages")
673 }
Inseob Kim8098faa2019-03-18 10:19:51 +0900674
675 missing_current_api := false
676
677 for _, scope := range []string{"", "system-", "test-"} {
678 for _, api := range []string{"current.txt", "removed.txt"} {
679 path := path.Join(mctx.ModuleDir(), "api", scope+api)
680 p := android.ExistentPathForSource(mctx, path)
681 if !p.Valid() {
682 mctx.ModuleErrorf("Current api file %#v doesn't exist", path)
683 missing_current_api = true
684 }
685 }
686 }
687
688 if missing_current_api {
689 script := "build/soong/scripts/gen-java-current-api-files.sh"
690 p := android.ExistentPathForSource(mctx, script)
691
692 if !p.Valid() {
693 panic(fmt.Sprintf("script file %s doesn't exist", script))
694 }
695
696 mctx.ModuleErrorf("One or more current api files are missing. "+
697 "You can update them by:\n"+
698 "%s %q && m update-api", script, mctx.ModuleDir())
699 return
700 }
701
Inseob Kimc0907f12019-02-08 21:00:45 +0900702 // for public API stubs
703 module.createStubsLibrary(mctx, apiScopePublic)
704 module.createDocs(mctx, apiScopePublic)
705
Paul Duffin250e6192019-06-07 10:44:37 +0100706 sdkDep := decodeSdkDep(mctx, sdkContext(&module.Library))
707 if sdkDep.hasStandardLibs() {
Inseob Kimc0907f12019-02-08 21:00:45 +0900708 // for system API stubs
709 module.createStubsLibrary(mctx, apiScopeSystem)
710 module.createDocs(mctx, apiScopeSystem)
711
712 // for test API stubs
713 module.createStubsLibrary(mctx, apiScopeTest)
714 module.createDocs(mctx, apiScopeTest)
715
716 // for runtime
717 module.createXmlFile(mctx)
718 }
719
720 // record java_sdk_library modules so that they are exported to make
721 javaSdkLibraries := javaSdkLibraries(mctx.Config())
722 javaSdkLibrariesLock.Lock()
723 defer javaSdkLibrariesLock.Unlock()
724 *javaSdkLibraries = append(*javaSdkLibraries, module.BaseModuleName())
725}
726
727func (module *SdkLibrary) InitSdkLibraryProperties() {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900728 module.AddProperties(
729 &module.sdkLibraryProperties,
730 &module.Library.Module.properties,
731 &module.Library.Module.dexpreoptProperties,
732 &module.Library.Module.deviceProperties,
733 &module.Library.Module.protoProperties,
734 )
735
736 module.Library.Module.properties.Installable = proptools.BoolPtr(true)
737 module.Library.Module.deviceProperties.IsSDKLibrary = true
Inseob Kimc0907f12019-02-08 21:00:45 +0900738}
Sundong Ahn054b19a2018-10-19 13:46:09 +0900739
Jaewoong Jung4f158ee2019-07-11 10:05:35 -0700740// java_sdk_library is a special Java library that provides optional platform APIs to apps.
741// In practice, it can be viewed as a combination of several modules: 1) stubs library that clients
742// are linked against to, 2) droiddoc module that internally generates API stubs source files,
743// 3) the real runtime shared library that implements the APIs, and 4) XML file for adding
744// the runtime lib to the classpath at runtime if requested via <uses-library>.
Inseob Kimc0907f12019-02-08 21:00:45 +0900745func SdkLibraryFactory() android.Module {
746 module := &SdkLibrary{}
747 module.InitSdkLibraryProperties()
Sundong Ahn054b19a2018-10-19 13:46:09 +0900748 InitJavaModule(module, android.HostAndDeviceSupported)
Colin Crossf8b860a2019-04-16 14:43:28 -0700749 android.AddLoadHook(module, func(ctx android.LoadHookContext) { module.CreateInternalModules(ctx) })
Jiyong Parkc678ad32018-04-10 13:07:10 +0900750 return module
751}
Colin Cross79c7c262019-04-17 11:11:46 -0700752
753//
754// SDK library prebuilts
755//
756
757type sdkLibraryImportProperties struct {
758 Jars []string `android:"path"`
759
760 Sdk_version *string
761
762 Installable *bool
763
764 // List of shared java libs that this module has dependencies to
765 Libs []string
766
767 // List of files to remove from the jar file(s)
768 Exclude_files []string
769
770 // List of directories to remove from the jar file(s)
771 Exclude_dirs []string
772}
773
774type sdkLibraryImport struct {
775 android.ModuleBase
776 android.DefaultableModuleBase
777 prebuilt android.Prebuilt
778
779 properties sdkLibraryImportProperties
780
781 stubsPath android.Paths
782}
783
784var _ SdkLibraryDependency = (*sdkLibraryImport)(nil)
785
Jaewoong Jung4f158ee2019-07-11 10:05:35 -0700786// java_sdk_library_import imports a prebuilt java_sdk_library.
Colin Cross79c7c262019-04-17 11:11:46 -0700787func sdkLibraryImportFactory() android.Module {
788 module := &sdkLibraryImport{}
789
790 module.AddProperties(&module.properties)
791
792 android.InitPrebuiltModule(module, &module.properties.Jars)
793 InitJavaModule(module, android.HostAndDeviceSupported)
794
795 android.AddLoadHook(module, func(mctx android.LoadHookContext) { module.createInternalModules(mctx) })
796 return module
797}
798
799func (module *sdkLibraryImport) Prebuilt() *android.Prebuilt {
800 return &module.prebuilt
801}
802
803func (module *sdkLibraryImport) Name() string {
804 return module.prebuilt.Name(module.ModuleBase.Name())
805}
806
807func (module *sdkLibraryImport) createInternalModules(mctx android.LoadHookContext) {
808 // Creates a java import for the jar with ".stubs" suffix
809 props := struct {
Sundong Ahn0d7dff42019-12-04 12:53:44 +0900810 Name *string
811 Soc_specific *bool
812 Device_specific *bool
813 Product_specific *bool
814 System_ext_specific *bool
Colin Cross79c7c262019-04-17 11:11:46 -0700815 }{}
816
817 props.Name = proptools.StringPtr(module.BaseModuleName() + sdkStubsLibrarySuffix)
818
819 if module.SocSpecific() {
820 props.Soc_specific = proptools.BoolPtr(true)
821 } else if module.DeviceSpecific() {
822 props.Device_specific = proptools.BoolPtr(true)
823 } else if module.ProductSpecific() {
824 props.Product_specific = proptools.BoolPtr(true)
Sundong Ahn0d7dff42019-12-04 12:53:44 +0900825 } else if module.SystemExtSpecific() {
826 props.System_ext_specific = proptools.BoolPtr(true)
Colin Cross79c7c262019-04-17 11:11:46 -0700827 }
828
Colin Cross84dfc3d2019-09-25 11:33:01 -0700829 mctx.CreateModule(ImportFactory, &props, &module.properties)
Colin Cross79c7c262019-04-17 11:11:46 -0700830
831 javaSdkLibraries := javaSdkLibraries(mctx.Config())
832 javaSdkLibrariesLock.Lock()
833 defer javaSdkLibrariesLock.Unlock()
834 *javaSdkLibraries = append(*javaSdkLibraries, module.BaseModuleName())
835}
836
837func (module *sdkLibraryImport) DepsMutator(ctx android.BottomUpMutatorContext) {
838 // Add dependencies to the prebuilt stubs library
839 ctx.AddVariationDependencies(nil, publicApiStubsTag, module.BaseModuleName()+sdkStubsLibrarySuffix)
840}
841
842func (module *sdkLibraryImport) GenerateAndroidBuildActions(ctx android.ModuleContext) {
843 // Record the paths to the prebuilt stubs library.
844 ctx.VisitDirectDeps(func(to android.Module) {
845 tag := ctx.OtherModuleDependencyTag(to)
846
847 switch tag {
848 case publicApiStubsTag:
849 module.stubsPath = to.(Dependency).HeaderJars()
850 }
851 })
852}
853
854// to satisfy SdkLibraryDependency interface
Colin Cross0ea8ba82019-06-06 14:33:29 -0700855func (module *sdkLibraryImport) SdkHeaderJars(ctx android.BaseModuleContext, sdkVersion string) android.Paths {
Colin Cross79c7c262019-04-17 11:11:46 -0700856 // This module is just a wrapper for the prebuilt stubs.
857 return module.stubsPath
858}
859
860// to satisfy SdkLibraryDependency interface
Colin Cross0ea8ba82019-06-06 14:33:29 -0700861func (module *sdkLibraryImport) SdkImplementationJars(ctx android.BaseModuleContext, sdkVersion string) android.Paths {
Colin Cross79c7c262019-04-17 11:11:46 -0700862 // This module is just a wrapper for the stubs.
863 return module.stubsPath
864}