blob: b4a3f296c9594ef860765f2f3fbec566122e05ff [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// java_sdk_library is to make a Java library that implements optional platform APIs to apps.
67// It is actually a wrapper of several modules: 1) stubs library that clients are linked against
68// to, 2) droiddoc module that internally generates API stubs source files, 3) the real runtime
69// shared library that implements the APIs, and 4) XML file for adding the runtime lib to the
70// classpath at runtime if requested via <uses-library>.
71//
72// TODO: these are big features that are currently missing
Jiyong Park1be96912018-05-28 18:02:19 +090073// 1) disallowing linking to the runtime shared lib
74// 2) HTML generation
Jiyong Parkc678ad32018-04-10 13:07:10 +090075
76func init() {
Inseob Kimc0907f12019-02-08 21:00:45 +090077 android.RegisterModuleType("java_sdk_library", SdkLibraryFactory)
Colin Cross79c7c262019-04-17 11:11:46 -070078 android.RegisterModuleType("java_sdk_library_import", sdkLibraryImportFactory)
Jiyong Parkc678ad32018-04-10 13:07:10 +090079
Jiyong Park82484c02018-04-23 21:41:26 +090080 android.RegisterMakeVarsProvider(pctx, func(ctx android.MakeVarsContext) {
81 javaSdkLibraries := javaSdkLibraries(ctx.Config())
82 sort.Strings(*javaSdkLibraries)
83 ctx.Strict("JAVA_SDK_LIBRARIES", strings.Join(*javaSdkLibraries, " "))
84 })
Jiyong Parkc678ad32018-04-10 13:07:10 +090085}
86
87type sdkLibraryProperties struct {
Jiyong Parkbaaf9dd2018-05-02 01:35:27 +090088 // list of optional source files that are part of API but not part of runtime library.
89 Api_srcs []string `android:"arch_variant"`
90
Sundong Ahnf043cf62018-06-25 16:04:37 +090091 // List of Java libraries that will be in the classpath when building stubs
92 Stub_only_libs []string `android:"arch_variant"`
93
Jiyong Parkc678ad32018-04-10 13:07:10 +090094 // list of package names that will be documented and publicized as API
95 Api_packages []string
96
Jiyong Park5a2c9d72018-05-01 22:25:41 +090097 // list of package names that must be hidden from the API
98 Hidden_api_packages []string
99
Paul Duffin11512472019-02-11 15:55:17 +0000100 // local files that are used within user customized droiddoc options.
101 Droiddoc_option_files []string
102
103 // additional droiddoc options
104 // Available variables for substitution:
105 //
106 // $(location <label>): the path to the droiddoc_option_files with name <label>
Sundong Ahndd567f92018-07-31 17:19:11 +0900107 Droiddoc_options []string
108
Sundong Ahnb952ba02019-01-08 16:32:12 +0900109 // the java library (in classpath) for documentation that provides java srcs and srcjars.
110 Srcs_lib *string
111
112 // the base dirs under srcs_lib will be scanned for java srcs.
113 Srcs_lib_whitelist_dirs []string
114
Sundong Ahndd567f92018-07-31 17:19:11 +0900115 // the sub dirs under srcs_lib_whitelist_dirs will be scanned for java srcs.
116 // Defaults to "android.annotation".
117 Srcs_lib_whitelist_pkgs []string
118
Sundong Ahn054b19a2018-10-19 13:46:09 +0900119 // a list of top-level directories containing files to merge qualifier annotations
120 // (i.e. those intended to be included in the stubs written) from.
121 Merge_annotations_dirs []string
122
123 // a list of top-level directories containing Java stub files to merge show/hide annotations from.
124 Merge_inclusion_annotations_dirs []string
125
126 // If set to true, the path of dist files is apistubs/core. Defaults to false.
127 Core_lib *bool
128
Sundong Ahn80a87b32019-05-13 15:02:50 +0900129 // don't create dist rules.
130 No_dist *bool `blueprint:"mutated"`
131
Jiyong Parkc678ad32018-04-10 13:07:10 +0900132 // TODO: determines whether to create HTML doc or not
133 //Html_doc *bool
134}
135
Inseob Kimc0907f12019-02-08 21:00:45 +0900136type SdkLibrary struct {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900137 Library
Jiyong Parkc678ad32018-04-10 13:07:10 +0900138
Sundong Ahn054b19a2018-10-19 13:46:09 +0900139 sdkLibraryProperties sdkLibraryProperties
Jiyong Parkc678ad32018-04-10 13:07:10 +0900140
141 publicApiStubsPath android.Paths
142 systemApiStubsPath android.Paths
Jiyong Parkdf130542018-04-27 16:29:21 +0900143 testApiStubsPath android.Paths
Sundong Ahn241cd372018-07-13 16:16:44 +0900144
145 publicApiStubsImplPath android.Paths
146 systemApiStubsImplPath android.Paths
147 testApiStubsImplPath android.Paths
Sundong Ahn20e998b2018-07-24 11:19:26 +0900148
149 publicApiFilePath android.Path
150 systemApiFilePath android.Path
151 testApiFilePath android.Path
Jiyong Parkc678ad32018-04-10 13:07:10 +0900152}
153
Inseob Kimc0907f12019-02-08 21:00:45 +0900154var _ Dependency = (*SdkLibrary)(nil)
155var _ SdkLibraryDependency = (*SdkLibrary)(nil)
Colin Cross897d2ed2019-02-11 14:03:51 -0800156
Inseob Kimc0907f12019-02-08 21:00:45 +0900157func (module *SdkLibrary) DepsMutator(ctx android.BottomUpMutatorContext) {
Jiyong Parkc678ad32018-04-10 13:07:10 +0900158 // Add dependencies to the stubs library
Colin Cross42d48b72018-08-29 14:10:52 -0700159 ctx.AddVariationDependencies(nil, publicApiStubsTag, module.stubsName(apiScopePublic))
Colin Cross42d48b72018-08-29 14:10:52 -0700160 ctx.AddVariationDependencies(nil, publicApiFileTag, module.docsName(apiScopePublic))
Sundong Ahn054b19a2018-10-19 13:46:09 +0900161
Paul Duffin250e6192019-06-07 10:44:37 +0100162 sdkDep := decodeSdkDep(ctx, sdkContext(&module.Library))
163 if sdkDep.hasStandardLibs() {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900164 ctx.AddVariationDependencies(nil, systemApiStubsTag, module.stubsName(apiScopeSystem))
165 ctx.AddVariationDependencies(nil, systemApiFileTag, module.docsName(apiScopeSystem))
166 ctx.AddVariationDependencies(nil, testApiFileTag, module.docsName(apiScopeTest))
167 ctx.AddVariationDependencies(nil, testApiStubsTag, module.stubsName(apiScopeTest))
168 }
169
170 module.Library.deps(ctx)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900171}
172
Inseob Kimc0907f12019-02-08 21:00:45 +0900173func (module *SdkLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900174 module.Library.GenerateAndroidBuildActions(ctx)
175
Sundong Ahn57368eb2018-07-06 11:20:23 +0900176 // Record the paths to the header jars of the library (stubs and impl).
Jiyong Parkc678ad32018-04-10 13:07:10 +0900177 // When this java_sdk_library is dependened from others via "libs" property,
178 // the recorded paths will be returned depending on the link type of the caller.
179 ctx.VisitDirectDeps(func(to android.Module) {
180 otherName := ctx.OtherModuleName(to)
181 tag := ctx.OtherModuleDependencyTag(to)
182
Sundong Ahn57368eb2018-07-06 11:20:23 +0900183 if lib, ok := to.(Dependency); ok {
Jiyong Parkc678ad32018-04-10 13:07:10 +0900184 switch tag {
185 case publicApiStubsTag:
Sundong Ahn57368eb2018-07-06 11:20:23 +0900186 module.publicApiStubsPath = lib.HeaderJars()
Sundong Ahn241cd372018-07-13 16:16:44 +0900187 module.publicApiStubsImplPath = lib.ImplementationJars()
Jiyong Parkc678ad32018-04-10 13:07:10 +0900188 case systemApiStubsTag:
Sundong Ahn57368eb2018-07-06 11:20:23 +0900189 module.systemApiStubsPath = lib.HeaderJars()
Sundong Ahn241cd372018-07-13 16:16:44 +0900190 module.systemApiStubsImplPath = lib.ImplementationJars()
Jiyong Parkdf130542018-04-27 16:29:21 +0900191 case testApiStubsTag:
Sundong Ahn57368eb2018-07-06 11:20:23 +0900192 module.testApiStubsPath = lib.HeaderJars()
Sundong Ahn241cd372018-07-13 16:16:44 +0900193 module.testApiStubsImplPath = lib.ImplementationJars()
Jiyong Parkc678ad32018-04-10 13:07:10 +0900194 }
195 }
Sundong Ahn20e998b2018-07-24 11:19:26 +0900196 if doc, ok := to.(ApiFilePath); ok {
197 switch tag {
198 case publicApiFileTag:
199 module.publicApiFilePath = doc.ApiFilePath()
200 case systemApiFileTag:
201 module.systemApiFilePath = doc.ApiFilePath()
202 case testApiFileTag:
203 module.testApiFilePath = doc.ApiFilePath()
204 default:
205 ctx.ModuleErrorf("depends on module %q of unknown tag %q", otherName, tag)
206 }
207 }
Jiyong Parkc678ad32018-04-10 13:07:10 +0900208 })
209}
210
Inseob Kimc0907f12019-02-08 21:00:45 +0900211func (module *SdkLibrary) AndroidMk() android.AndroidMkData {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900212 data := module.Library.AndroidMk()
213 data.Required = append(data.Required, module.xmlFileName())
214
215 data.Custom = func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
216 android.WriteAndroidMkData(w, data)
217
218 module.Library.AndroidMkHostDex(w, name, data)
Sundong Ahn80a87b32019-05-13 15:02:50 +0900219 if !Bool(module.sdkLibraryProperties.No_dist) {
220 // Create a phony module that installs the impl library, for the case when this lib is
221 // in PRODUCT_PACKAGES.
222 owner := module.ModuleBase.Owner()
223 if owner == "" {
224 if Bool(module.sdkLibraryProperties.Core_lib) {
225 owner = "core"
226 } else {
227 owner = "android"
228 }
Sundong Ahn4fd04bb2018-08-31 18:01:37 +0900229 }
Sundong Ahn80a87b32019-05-13 15:02:50 +0900230 // Create dist rules to install the stubs libs to the dist dir
231 if len(module.publicApiStubsPath) == 1 {
232 fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+
233 module.publicApiStubsImplPath.Strings()[0]+
234 ":"+path.Join("apistubs", owner, "public",
235 module.BaseModuleName()+".jar")+")")
236 }
237 if len(module.systemApiStubsPath) == 1 {
238 fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+
239 module.systemApiStubsImplPath.Strings()[0]+
240 ":"+path.Join("apistubs", owner, "system",
241 module.BaseModuleName()+".jar")+")")
242 }
243 if len(module.testApiStubsPath) == 1 {
244 fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+
245 module.testApiStubsImplPath.Strings()[0]+
246 ":"+path.Join("apistubs", owner, "test",
247 module.BaseModuleName()+".jar")+")")
248 }
249 if module.publicApiFilePath != nil {
250 fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+
251 module.publicApiFilePath.String()+
252 ":"+path.Join("apistubs", owner, "public", "api",
253 module.BaseModuleName()+".txt")+")")
254 }
255 if module.systemApiFilePath != nil {
256 fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+
257 module.systemApiFilePath.String()+
258 ":"+path.Join("apistubs", owner, "system", "api",
259 module.BaseModuleName()+".txt")+")")
260 }
261 if module.testApiFilePath != nil {
262 fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+
263 module.testApiFilePath.String()+
264 ":"+path.Join("apistubs", owner, "test", "api",
265 module.BaseModuleName()+".txt")+")")
266 }
Sundong Ahn054b19a2018-10-19 13:46:09 +0900267 }
Jiyong Park82484c02018-04-23 21:41:26 +0900268 }
Sundong Ahn054b19a2018-10-19 13:46:09 +0900269 return data
Jiyong Park82484c02018-04-23 21:41:26 +0900270}
271
Jiyong Parkc678ad32018-04-10 13:07:10 +0900272// Module name of the stubs library
Inseob Kimc0907f12019-02-08 21:00:45 +0900273func (module *SdkLibrary) stubsName(apiScope apiScope) string {
Jiyong Parkc678ad32018-04-10 13:07:10 +0900274 stubsName := module.BaseModuleName() + sdkStubsLibrarySuffix
Jiyong Parkdf130542018-04-27 16:29:21 +0900275 switch apiScope {
276 case apiScopeSystem:
Jiyong Parkc678ad32018-04-10 13:07:10 +0900277 stubsName = stubsName + sdkSystemApiSuffix
Jiyong Parkdf130542018-04-27 16:29:21 +0900278 case apiScopeTest:
279 stubsName = stubsName + sdkTestApiSuffix
Jiyong Parkc678ad32018-04-10 13:07:10 +0900280 }
281 return stubsName
282}
283
284// Module name of the docs
Inseob Kimc0907f12019-02-08 21:00:45 +0900285func (module *SdkLibrary) docsName(apiScope apiScope) string {
Jiyong Parkc678ad32018-04-10 13:07:10 +0900286 docsName := module.BaseModuleName() + sdkDocsSuffix
Jiyong Parkdf130542018-04-27 16:29:21 +0900287 switch apiScope {
288 case apiScopeSystem:
Jiyong Parkc678ad32018-04-10 13:07:10 +0900289 docsName = docsName + sdkSystemApiSuffix
Jiyong Parkdf130542018-04-27 16:29:21 +0900290 case apiScopeTest:
291 docsName = docsName + sdkTestApiSuffix
Jiyong Parkc678ad32018-04-10 13:07:10 +0900292 }
293 return docsName
294}
295
296// Module name of the runtime implementation library
Inseob Kimc0907f12019-02-08 21:00:45 +0900297func (module *SdkLibrary) implName() string {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900298 return module.BaseModuleName()
Jiyong Parkc678ad32018-04-10 13:07:10 +0900299}
300
301// File path to the runtime implementation library
Inseob Kimc0907f12019-02-08 21:00:45 +0900302func (module *SdkLibrary) implPath() string {
Jiyong Parkc678ad32018-04-10 13:07:10 +0900303 partition := "system"
304 if module.SocSpecific() {
305 partition = "vendor"
306 } else if module.DeviceSpecific() {
307 partition = "odm"
308 } else if module.ProductSpecific() {
309 partition = "product"
310 }
311 return "/" + partition + "/framework/" + module.implName() + ".jar"
312}
313
314// Module name of the XML file for the lib
Inseob Kimc0907f12019-02-08 21:00:45 +0900315func (module *SdkLibrary) xmlFileName() string {
Jiyong Parkc678ad32018-04-10 13:07:10 +0900316 return module.BaseModuleName() + sdkXmlFileSuffix
317}
318
319// SDK version that the stubs library is built against. Note that this is always
320// *current. Older stubs library built with a numberd SDK version is created from
321// the prebuilt jar.
Inseob Kimc0907f12019-02-08 21:00:45 +0900322func (module *SdkLibrary) sdkVersion(apiScope apiScope) string {
Jiyong Parkdf130542018-04-27 16:29:21 +0900323 switch apiScope {
324 case apiScopePublic:
325 return "current"
326 case apiScopeSystem:
Jiyong Parkc678ad32018-04-10 13:07:10 +0900327 return "system_current"
Jiyong Parkdf130542018-04-27 16:29:21 +0900328 case apiScopeTest:
329 return "test_current"
330 default:
Jiyong Parkc678ad32018-04-10 13:07:10 +0900331 return "current"
332 }
333}
334
335// $(INTERNAL_PLATFORM_<apiTagName>_API_FILE) points to the generated
336// api file for the current source
337// TODO: remove this when apicheck is done in soong
Inseob Kimc0907f12019-02-08 21:00:45 +0900338func (module *SdkLibrary) apiTagName(apiScope apiScope) string {
Jiyong Parkc678ad32018-04-10 13:07:10 +0900339 apiTagName := strings.Replace(strings.ToUpper(module.BaseModuleName()), ".", "_", -1)
Jiyong Parkdf130542018-04-27 16:29:21 +0900340 switch apiScope {
341 case apiScopeSystem:
Jiyong Parkc678ad32018-04-10 13:07:10 +0900342 apiTagName = apiTagName + "_SYSTEM"
Jiyong Parkdf130542018-04-27 16:29:21 +0900343 case apiScopeTest:
344 apiTagName = apiTagName + "_TEST"
Jiyong Parkc678ad32018-04-10 13:07:10 +0900345 }
346 return apiTagName
347}
348
Inseob Kimc0907f12019-02-08 21:00:45 +0900349func (module *SdkLibrary) latestApiFilegroupName(apiScope apiScope) string {
Jiyong Park58c518b2018-05-12 22:29:12 +0900350 name := ":" + module.BaseModuleName() + ".api."
Jiyong Parkdf130542018-04-27 16:29:21 +0900351 switch apiScope {
Jiyong Park58c518b2018-05-12 22:29:12 +0900352 case apiScopePublic:
353 name = name + "public"
Jiyong Parkdf130542018-04-27 16:29:21 +0900354 case apiScopeSystem:
Jiyong Park58c518b2018-05-12 22:29:12 +0900355 name = name + "system"
Jiyong Parkdf130542018-04-27 16:29:21 +0900356 case apiScopeTest:
Jiyong Park58c518b2018-05-12 22:29:12 +0900357 name = name + "test"
Jiyong Parkc678ad32018-04-10 13:07:10 +0900358 }
Jiyong Park58c518b2018-05-12 22:29:12 +0900359 name = name + ".latest"
360 return name
361}
Jiyong Parkc678ad32018-04-10 13:07:10 +0900362
Inseob Kimc0907f12019-02-08 21:00:45 +0900363func (module *SdkLibrary) latestRemovedApiFilegroupName(apiScope apiScope) string {
Jiyong Park58c518b2018-05-12 22:29:12 +0900364 name := ":" + module.BaseModuleName() + "-removed.api."
365 switch apiScope {
366 case apiScopePublic:
367 name = name + "public"
368 case apiScopeSystem:
369 name = name + "system"
370 case apiScopeTest:
371 name = name + "test"
372 }
373 name = name + ".latest"
374 return name
Jiyong Parkc678ad32018-04-10 13:07:10 +0900375}
376
377// Creates a static java library that has API stubs
Colin Crossf8b860a2019-04-16 14:43:28 -0700378func (module *SdkLibrary) createStubsLibrary(mctx android.LoadHookContext, apiScope apiScope) {
Jiyong Parkc678ad32018-04-10 13:07:10 +0900379 props := struct {
380 Name *string
381 Srcs []string
382 Sdk_version *string
Sundong Ahnf043cf62018-06-25 16:04:37 +0900383 Libs []string
Jiyong Parkc678ad32018-04-10 13:07:10 +0900384 Soc_specific *bool
385 Device_specific *bool
386 Product_specific *bool
Sundong Ahndd567f92018-07-31 17:19:11 +0900387 Compile_dex *bool
Sundong Ahn054b19a2018-10-19 13:46:09 +0900388 System_modules *string
389 Java_version *string
Jiyong Parkc678ad32018-04-10 13:07:10 +0900390 Product_variables struct {
391 Unbundled_build struct {
392 Enabled *bool
393 }
Jiyong Park82484c02018-04-23 21:41:26 +0900394 Pdk struct {
395 Enabled *bool
396 }
Jiyong Parkc678ad32018-04-10 13:07:10 +0900397 }
Sundong Ahn054b19a2018-10-19 13:46:09 +0900398 Openjdk9 struct {
399 Srcs []string
400 Javacflags []string
401 }
Jiyong Parkc678ad32018-04-10 13:07:10 +0900402 }{}
403
Paul Duffin52d398a2019-06-11 12:31:14 +0100404 sdkVersion := module.sdkVersion(apiScope)
Paul Duffin250e6192019-06-07 10:44:37 +0100405 sdkDep := decodeSdkDep(mctx, sdkContext(&module.Library))
Paul Duffin52d398a2019-06-11 12:31:14 +0100406 if !sdkDep.hasStandardLibs() {
407 sdkVersion = "none"
408 }
Paul Duffin250e6192019-06-07 10:44:37 +0100409
Jiyong Parkdf130542018-04-27 16:29:21 +0900410 props.Name = proptools.StringPtr(module.stubsName(apiScope))
Jiyong Parkc678ad32018-04-10 13:07:10 +0900411 // sources are generated from the droiddoc
Jiyong Parkdf130542018-04-27 16:29:21 +0900412 props.Srcs = []string{":" + module.docsName(apiScope)}
Paul Duffin52d398a2019-06-11 12:31:14 +0100413 props.Sdk_version = proptools.StringPtr(sdkVersion)
Sundong Ahn054b19a2018-10-19 13:46:09 +0900414 props.Libs = module.sdkLibraryProperties.Stub_only_libs
Jiyong Parkc678ad32018-04-10 13:07:10 +0900415 // Unbundled apps will use the prebult one from /prebuilts/sdk
Colin Cross10932872019-04-18 14:27:12 -0700416 if mctx.Config().UnbundledBuildUsePrebuiltSdks() {
Colin Cross2c77ceb2019-01-21 11:56:21 -0800417 props.Product_variables.Unbundled_build.Enabled = proptools.BoolPtr(false)
418 }
Jiyong Park82484c02018-04-23 21:41:26 +0900419 props.Product_variables.Pdk.Enabled = proptools.BoolPtr(false)
Sundong Ahn054b19a2018-10-19 13:46:09 +0900420 props.System_modules = module.Library.Module.deviceProperties.System_modules
421 props.Openjdk9.Srcs = module.Library.Module.properties.Openjdk9.Srcs
422 props.Openjdk9.Javacflags = module.Library.Module.properties.Openjdk9.Javacflags
423 props.Java_version = module.Library.Module.properties.Java_version
424 if module.Library.Module.deviceProperties.Compile_dex != nil {
425 props.Compile_dex = module.Library.Module.deviceProperties.Compile_dex
Sundong Ahndd567f92018-07-31 17:19:11 +0900426 }
Jiyong Parkc678ad32018-04-10 13:07:10 +0900427
428 if module.SocSpecific() {
429 props.Soc_specific = proptools.BoolPtr(true)
430 } else if module.DeviceSpecific() {
431 props.Device_specific = proptools.BoolPtr(true)
432 } else if module.ProductSpecific() {
433 props.Product_specific = proptools.BoolPtr(true)
434 }
435
Colin Cross9ae1b922018-06-26 17:59:05 -0700436 mctx.CreateModule(android.ModuleFactoryAdaptor(LibraryFactory), &props)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900437}
438
439// Creates a droiddoc module that creates stubs source files from the given full source
440// files
Colin Crossf8b860a2019-04-16 14:43:28 -0700441func (module *SdkLibrary) createDocs(mctx android.LoadHookContext, apiScope apiScope) {
Jiyong Parkc678ad32018-04-10 13:07:10 +0900442 props := struct {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900443 Name *string
444 Srcs []string
445 Installable *bool
446 Srcs_lib *string
447 Srcs_lib_whitelist_dirs []string
448 Srcs_lib_whitelist_pkgs []string
Paul Duffin52d398a2019-06-11 12:31:14 +0100449 Sdk_version *string
Sundong Ahn054b19a2018-10-19 13:46:09 +0900450 Libs []string
Paul Duffin11512472019-02-11 15:55:17 +0000451 Arg_files []string
Sundong Ahn054b19a2018-10-19 13:46:09 +0900452 Args *string
453 Api_tag_name *string
454 Api_filename *string
455 Removed_api_filename *string
Sundong Ahn054b19a2018-10-19 13:46:09 +0900456 Java_version *string
457 Merge_annotations_dirs []string
458 Merge_inclusion_annotations_dirs []string
459 Check_api struct {
Inseob Kim38449af2019-02-28 14:24:05 +0900460 Current ApiToCheck
461 Last_released ApiToCheck
462 Ignore_missing_latest_api *bool
Jiyong Park58c518b2018-05-12 22:29:12 +0900463 }
Sundong Ahn1b92c822018-05-29 11:35:17 +0900464 Aidl struct {
465 Include_dirs []string
466 Local_include_dirs []string
467 }
Jiyong Parkc678ad32018-04-10 13:07:10 +0900468 }{}
469
Paul Duffin250e6192019-06-07 10:44:37 +0100470 sdkDep := decodeSdkDep(mctx, sdkContext(&module.Library))
Paul Duffin52d398a2019-06-11 12:31:14 +0100471 sdkVersion := ""
472 if !sdkDep.hasStandardLibs() {
473 sdkVersion = "none"
474 }
Paul Duffin250e6192019-06-07 10:44:37 +0100475
Jiyong Parkdf130542018-04-27 16:29:21 +0900476 props.Name = proptools.StringPtr(module.docsName(apiScope))
Sundong Ahn054b19a2018-10-19 13:46:09 +0900477 props.Srcs = append(props.Srcs, module.Library.Module.properties.Srcs...)
478 props.Srcs = append(props.Srcs, module.sdkLibraryProperties.Api_srcs...)
Paul Duffin52d398a2019-06-11 12:31:14 +0100479 props.Sdk_version = proptools.StringPtr(sdkVersion)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900480 props.Installable = proptools.BoolPtr(false)
Sundong Ahne6f0b052018-06-05 16:46:14 +0900481 // A droiddoc module has only one Libs property and doesn't distinguish between
482 // shared libs and static libs. So we need to add both of these libs to Libs property.
Sundong Ahn054b19a2018-10-19 13:46:09 +0900483 props.Libs = module.Library.Module.properties.Libs
484 props.Libs = append(props.Libs, module.Library.Module.properties.Static_libs...)
485 props.Aidl.Include_dirs = module.Library.Module.deviceProperties.Aidl.Include_dirs
486 props.Aidl.Local_include_dirs = module.Library.Module.deviceProperties.Aidl.Local_include_dirs
Sundong Ahn054b19a2018-10-19 13:46:09 +0900487 props.Java_version = module.Library.Module.properties.Java_version
Jiyong Parkc678ad32018-04-10 13:07:10 +0900488
Sundong Ahn054b19a2018-10-19 13:46:09 +0900489 props.Merge_annotations_dirs = module.sdkLibraryProperties.Merge_annotations_dirs
490 props.Merge_inclusion_annotations_dirs = module.sdkLibraryProperties.Merge_inclusion_annotations_dirs
491
492 droiddocArgs := " --stub-packages " + strings.Join(module.sdkLibraryProperties.Api_packages, ":") +
493 " " + android.JoinWithPrefix(module.sdkLibraryProperties.Hidden_api_packages, " --hide-package ") +
494 " " + android.JoinWithPrefix(module.sdkLibraryProperties.Droiddoc_options, " ") +
Sundong Ahn04ef8a32019-01-14 11:36:50 +0900495 " --hide MissingPermission --hide BroadcastBehavior " +
496 "--hide HiddenSuperclass --hide DeprecationMismatch --hide UnavailableSymbol " +
497 "--hide SdkConstant --hide HiddenTypeParameter --hide Todo --hide Typo"
Sundong Ahnfb2721f2018-09-17 13:23:09 +0900498
Jiyong Parkdf130542018-04-27 16:29:21 +0900499 switch apiScope {
500 case apiScopeSystem:
Jiyong Parkc678ad32018-04-10 13:07:10 +0900501 droiddocArgs = droiddocArgs + " -showAnnotation android.annotation.SystemApi"
Jiyong Parkdf130542018-04-27 16:29:21 +0900502 case apiScopeTest:
503 droiddocArgs = droiddocArgs + " -showAnnotation android.annotation.TestApi"
Jiyong Parkc678ad32018-04-10 13:07:10 +0900504 }
Paul Duffin11512472019-02-11 15:55:17 +0000505 props.Arg_files = module.sdkLibraryProperties.Droiddoc_option_files
Jiyong Parkc678ad32018-04-10 13:07:10 +0900506 props.Args = proptools.StringPtr(droiddocArgs)
507
508 // List of APIs identified from the provided source files are created. They are later
509 // compared against to the not-yet-released (a.k.a current) list of APIs and to the
510 // last-released (a.k.a numbered) list of API.
Jiyong Parkc678ad32018-04-10 13:07:10 +0900511 currentApiFileName := "current.txt"
512 removedApiFileName := "removed.txt"
Jiyong Parkdf130542018-04-27 16:29:21 +0900513 switch apiScope {
514 case apiScopeSystem:
Jiyong Parkc678ad32018-04-10 13:07:10 +0900515 currentApiFileName = "system-" + currentApiFileName
516 removedApiFileName = "system-" + removedApiFileName
Jiyong Parkdf130542018-04-27 16:29:21 +0900517 case apiScopeTest:
518 currentApiFileName = "test-" + currentApiFileName
519 removedApiFileName = "test-" + removedApiFileName
Jiyong Parkc678ad32018-04-10 13:07:10 +0900520 }
521 currentApiFileName = path.Join("api", currentApiFileName)
522 removedApiFileName = path.Join("api", removedApiFileName)
Jiyong Park58c518b2018-05-12 22:29:12 +0900523 // TODO(jiyong): remove these three props
Jiyong Parkdf130542018-04-27 16:29:21 +0900524 props.Api_tag_name = proptools.StringPtr(module.apiTagName(apiScope))
Jiyong Parkc678ad32018-04-10 13:07:10 +0900525 props.Api_filename = proptools.StringPtr(currentApiFileName)
526 props.Removed_api_filename = proptools.StringPtr(removedApiFileName)
527
Jiyong Park58c518b2018-05-12 22:29:12 +0900528 // check against the not-yet-release API
529 props.Check_api.Current.Api_file = proptools.StringPtr(currentApiFileName)
530 props.Check_api.Current.Removed_api_file = proptools.StringPtr(removedApiFileName)
Jiyong Park58c518b2018-05-12 22:29:12 +0900531
532 // check against the latest released API
533 props.Check_api.Last_released.Api_file = proptools.StringPtr(
534 module.latestApiFilegroupName(apiScope))
535 props.Check_api.Last_released.Removed_api_file = proptools.StringPtr(
536 module.latestRemovedApiFilegroupName(apiScope))
Inseob Kim38449af2019-02-28 14:24:05 +0900537 props.Check_api.Ignore_missing_latest_api = proptools.BoolPtr(true)
Sundong Ahn054b19a2018-10-19 13:46:09 +0900538 props.Srcs_lib = module.sdkLibraryProperties.Srcs_lib
539 props.Srcs_lib_whitelist_dirs = module.sdkLibraryProperties.Srcs_lib_whitelist_dirs
540 props.Srcs_lib_whitelist_pkgs = module.sdkLibraryProperties.Srcs_lib_whitelist_pkgs
Jiyong Park58c518b2018-05-12 22:29:12 +0900541
Sundong Ahn04ef8a32019-01-14 11:36:50 +0900542 mctx.CreateModule(android.ModuleFactoryAdaptor(DroidstubsFactory), &props)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900543}
544
Jiyong Parkc678ad32018-04-10 13:07:10 +0900545// Creates the xml file that publicizes the runtime library
Colin Crossf8b860a2019-04-16 14:43:28 -0700546func (module *SdkLibrary) createXmlFile(mctx android.LoadHookContext) {
Jiyong Parkc678ad32018-04-10 13:07:10 +0900547 template := `
548<?xml version="1.0" encoding="utf-8"?>
549<!-- Copyright (C) 2018 The Android Open Source Project
550
551 Licensed under the Apache License, Version 2.0 (the "License");
552 you may not use this file except in compliance with the License.
553 You may obtain a copy of the License at
554
555 http://www.apache.org/licenses/LICENSE-2.0
556
557 Unless required by applicable law or agreed to in writing, software
558 distributed under the License is distributed on an "AS IS" BASIS,
559 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
560 See the License for the specific language governing permissions and
561 limitations under the License.
562-->
563
564<permissions>
565 <library name="%s" file="%s"/>
566</permissions>
567`
568 // genrule to generate the xml file content from the template above
569 // TODO: preserve newlines in the generate xml file. Newlines are being squashed
570 // in the ninja file. Do we need to have an external tool for this?
571 xmlContent := fmt.Sprintf(template, module.BaseModuleName(), module.implPath())
572 genruleProps := struct {
573 Name *string
574 Cmd *string
575 Out []string
576 }{}
577 genruleProps.Name = proptools.StringPtr(module.xmlFileName() + "-gen")
578 genruleProps.Cmd = proptools.StringPtr("echo '" + xmlContent + "' > $(out)")
579 genruleProps.Out = []string{module.xmlFileName()}
580 mctx.CreateModule(android.ModuleFactoryAdaptor(genrule.GenRuleFactory), &genruleProps)
581
582 // creates a prebuilt_etc module to actually place the xml file under
583 // <partition>/etc/permissions
584 etcProps := struct {
585 Name *string
Jiyong Park5a8d1be2018-04-25 22:57:34 +0900586 Src *string
Jiyong Parkc678ad32018-04-10 13:07:10 +0900587 Sub_dir *string
588 Soc_specific *bool
589 Device_specific *bool
590 Product_specific *bool
591 }{}
592 etcProps.Name = proptools.StringPtr(module.xmlFileName())
Jiyong Park5a8d1be2018-04-25 22:57:34 +0900593 etcProps.Src = proptools.StringPtr(":" + module.xmlFileName() + "-gen")
Jiyong Parkc678ad32018-04-10 13:07:10 +0900594 etcProps.Sub_dir = proptools.StringPtr("permissions")
595 if module.SocSpecific() {
596 etcProps.Soc_specific = proptools.BoolPtr(true)
597 } else if module.DeviceSpecific() {
598 etcProps.Device_specific = proptools.BoolPtr(true)
599 } else if module.ProductSpecific() {
600 etcProps.Product_specific = proptools.BoolPtr(true)
601 }
602 mctx.CreateModule(android.ModuleFactoryAdaptor(android.PrebuiltEtcFactory), &etcProps)
603}
604
Colin Cross0ea8ba82019-06-06 14:33:29 -0700605func (module *SdkLibrary) PrebuiltJars(ctx android.BaseModuleContext, sdkVersion string) android.Paths {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900606 var api, v string
Paul Duffin52d398a2019-06-11 12:31:14 +0100607 if sdkVersion == "" || sdkVersion == "none" {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900608 api = "system"
609 v = "current"
610 } else if strings.Contains(sdkVersion, "_") {
611 t := strings.Split(sdkVersion, "_")
612 api = t[0]
613 v = t[1]
Jiyong Parkc678ad32018-04-10 13:07:10 +0900614 } else {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900615 api = "public"
616 v = sdkVersion
617 }
618 dir := filepath.Join("prebuilts", "sdk", v, api)
619 jar := filepath.Join(dir, module.BaseModuleName()+".jar")
620 jarPath := android.ExistentPathForSource(ctx, jar)
Sundong Ahnae418ac2019-02-28 15:01:28 +0900621 if !jarPath.Valid() {
622 ctx.PropertyErrorf("sdk_library", "invalid sdk version %q, %q does not exist", v, jar)
623 return nil
624 }
Sundong Ahn054b19a2018-10-19 13:46:09 +0900625 return android.Paths{jarPath.Path()}
626}
627
628// to satisfy SdkLibraryDependency interface
Colin Cross0ea8ba82019-06-06 14:33:29 -0700629func (module *SdkLibrary) SdkHeaderJars(ctx android.BaseModuleContext, sdkVersion string) android.Paths {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900630 // This module is just a wrapper for the stubs.
Colin Cross10932872019-04-18 14:27:12 -0700631 if ctx.Config().UnbundledBuildUsePrebuiltSdks() {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900632 return module.PrebuiltJars(ctx, sdkVersion)
633 } else {
634 if strings.HasPrefix(sdkVersion, "system_") {
635 return module.systemApiStubsPath
636 } else if sdkVersion == "" {
637 return module.Library.HeaderJars()
638 } else {
639 return module.publicApiStubsPath
640 }
Jiyong Parkc678ad32018-04-10 13:07:10 +0900641 }
642}
643
Sundong Ahn241cd372018-07-13 16:16:44 +0900644// to satisfy SdkLibraryDependency interface
Colin Cross0ea8ba82019-06-06 14:33:29 -0700645func (module *SdkLibrary) SdkImplementationJars(ctx android.BaseModuleContext, sdkVersion string) android.Paths {
Sundong Ahn241cd372018-07-13 16:16:44 +0900646 // This module is just a wrapper for the stubs.
Colin Cross10932872019-04-18 14:27:12 -0700647 if ctx.Config().UnbundledBuildUsePrebuiltSdks() {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900648 return module.PrebuiltJars(ctx, sdkVersion)
Sundong Ahn241cd372018-07-13 16:16:44 +0900649 } else {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900650 if strings.HasPrefix(sdkVersion, "system_") {
651 return module.systemApiStubsImplPath
652 } else if sdkVersion == "" {
653 return module.Library.ImplementationJars()
654 } else {
655 return module.publicApiStubsImplPath
656 }
Sundong Ahn241cd372018-07-13 16:16:44 +0900657 }
658}
659
Sundong Ahn80a87b32019-05-13 15:02:50 +0900660func (module *SdkLibrary) SetNoDist() {
661 module.sdkLibraryProperties.No_dist = proptools.BoolPtr(true)
662}
663
Colin Cross571cccf2019-02-04 11:22:08 -0800664var javaSdkLibrariesKey = android.NewOnceKey("javaSdkLibraries")
665
Jiyong Park82484c02018-04-23 21:41:26 +0900666func javaSdkLibraries(config android.Config) *[]string {
Colin Cross571cccf2019-02-04 11:22:08 -0800667 return config.Once(javaSdkLibrariesKey, func() interface{} {
Jiyong Park82484c02018-04-23 21:41:26 +0900668 return &[]string{}
669 }).(*[]string)
670}
671
Jiyong Parkc678ad32018-04-10 13:07:10 +0900672// For a java_sdk_library module, create internal modules for stubs, docs,
673// runtime libs and xml file. If requested, the stubs and docs are created twice
674// once for public API level and once for system API level
Colin Crossf8b860a2019-04-16 14:43:28 -0700675func (module *SdkLibrary) CreateInternalModules(mctx android.LoadHookContext) {
Inseob Kim6e93ac92019-03-21 17:43:49 +0900676 if len(module.Library.Module.properties.Srcs) == 0 {
Inseob Kimc0907f12019-02-08 21:00:45 +0900677 mctx.PropertyErrorf("srcs", "java_sdk_library must specify srcs")
678 }
679
Inseob Kim6e93ac92019-03-21 17:43:49 +0900680 if len(module.sdkLibraryProperties.Api_packages) == 0 {
Inseob Kimc0907f12019-02-08 21:00:45 +0900681 mctx.PropertyErrorf("api_packages", "java_sdk_library must specify api_packages")
682 }
Inseob Kim8098faa2019-03-18 10:19:51 +0900683
684 missing_current_api := false
685
686 for _, scope := range []string{"", "system-", "test-"} {
687 for _, api := range []string{"current.txt", "removed.txt"} {
688 path := path.Join(mctx.ModuleDir(), "api", scope+api)
689 p := android.ExistentPathForSource(mctx, path)
690 if !p.Valid() {
691 mctx.ModuleErrorf("Current api file %#v doesn't exist", path)
692 missing_current_api = true
693 }
694 }
695 }
696
697 if missing_current_api {
698 script := "build/soong/scripts/gen-java-current-api-files.sh"
699 p := android.ExistentPathForSource(mctx, script)
700
701 if !p.Valid() {
702 panic(fmt.Sprintf("script file %s doesn't exist", script))
703 }
704
705 mctx.ModuleErrorf("One or more current api files are missing. "+
706 "You can update them by:\n"+
707 "%s %q && m update-api", script, mctx.ModuleDir())
708 return
709 }
710
Inseob Kimc0907f12019-02-08 21:00:45 +0900711 // for public API stubs
712 module.createStubsLibrary(mctx, apiScopePublic)
713 module.createDocs(mctx, apiScopePublic)
714
Paul Duffin250e6192019-06-07 10:44:37 +0100715 sdkDep := decodeSdkDep(mctx, sdkContext(&module.Library))
716 if sdkDep.hasStandardLibs() {
Inseob Kimc0907f12019-02-08 21:00:45 +0900717 // for system API stubs
718 module.createStubsLibrary(mctx, apiScopeSystem)
719 module.createDocs(mctx, apiScopeSystem)
720
721 // for test API stubs
722 module.createStubsLibrary(mctx, apiScopeTest)
723 module.createDocs(mctx, apiScopeTest)
724
725 // for runtime
726 module.createXmlFile(mctx)
727 }
728
729 // record java_sdk_library modules so that they are exported to make
730 javaSdkLibraries := javaSdkLibraries(mctx.Config())
731 javaSdkLibrariesLock.Lock()
732 defer javaSdkLibrariesLock.Unlock()
733 *javaSdkLibraries = append(*javaSdkLibraries, module.BaseModuleName())
734}
735
736func (module *SdkLibrary) InitSdkLibraryProperties() {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900737 module.AddProperties(
738 &module.sdkLibraryProperties,
739 &module.Library.Module.properties,
740 &module.Library.Module.dexpreoptProperties,
741 &module.Library.Module.deviceProperties,
742 &module.Library.Module.protoProperties,
743 )
744
745 module.Library.Module.properties.Installable = proptools.BoolPtr(true)
746 module.Library.Module.deviceProperties.IsSDKLibrary = true
Inseob Kimc0907f12019-02-08 21:00:45 +0900747}
Sundong Ahn054b19a2018-10-19 13:46:09 +0900748
Inseob Kimc0907f12019-02-08 21:00:45 +0900749func SdkLibraryFactory() android.Module {
750 module := &SdkLibrary{}
751 module.InitSdkLibraryProperties()
Sundong Ahn054b19a2018-10-19 13:46:09 +0900752 InitJavaModule(module, android.HostAndDeviceSupported)
Colin Crossf8b860a2019-04-16 14:43:28 -0700753 android.AddLoadHook(module, func(ctx android.LoadHookContext) { module.CreateInternalModules(ctx) })
Jiyong Parkc678ad32018-04-10 13:07:10 +0900754 return module
755}
Colin Cross79c7c262019-04-17 11:11:46 -0700756
757//
758// SDK library prebuilts
759//
760
761type sdkLibraryImportProperties struct {
762 Jars []string `android:"path"`
763
764 Sdk_version *string
765
766 Installable *bool
767
768 // List of shared java libs that this module has dependencies to
769 Libs []string
770
771 // List of files to remove from the jar file(s)
772 Exclude_files []string
773
774 // List of directories to remove from the jar file(s)
775 Exclude_dirs []string
776}
777
778type sdkLibraryImport struct {
779 android.ModuleBase
780 android.DefaultableModuleBase
781 prebuilt android.Prebuilt
782
783 properties sdkLibraryImportProperties
784
785 stubsPath android.Paths
786}
787
788var _ SdkLibraryDependency = (*sdkLibraryImport)(nil)
789
790func sdkLibraryImportFactory() android.Module {
791 module := &sdkLibraryImport{}
792
793 module.AddProperties(&module.properties)
794
795 android.InitPrebuiltModule(module, &module.properties.Jars)
796 InitJavaModule(module, android.HostAndDeviceSupported)
797
798 android.AddLoadHook(module, func(mctx android.LoadHookContext) { module.createInternalModules(mctx) })
799 return module
800}
801
802func (module *sdkLibraryImport) Prebuilt() *android.Prebuilt {
803 return &module.prebuilt
804}
805
806func (module *sdkLibraryImport) Name() string {
807 return module.prebuilt.Name(module.ModuleBase.Name())
808}
809
810func (module *sdkLibraryImport) createInternalModules(mctx android.LoadHookContext) {
811 // Creates a java import for the jar with ".stubs" suffix
812 props := struct {
813 Name *string
814 Soc_specific *bool
815 Device_specific *bool
816 Product_specific *bool
817 }{}
818
819 props.Name = proptools.StringPtr(module.BaseModuleName() + sdkStubsLibrarySuffix)
820
821 if module.SocSpecific() {
822 props.Soc_specific = proptools.BoolPtr(true)
823 } else if module.DeviceSpecific() {
824 props.Device_specific = proptools.BoolPtr(true)
825 } else if module.ProductSpecific() {
826 props.Product_specific = proptools.BoolPtr(true)
827 }
828
829 mctx.CreateModule(android.ModuleFactoryAdaptor(ImportFactory), &props, &module.properties)
830
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}