blob: d38088d743ac4ef8e12d11b1ef841b80d14ecf67 [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() {
Inseob Kimc0907f12019-02-08 21:00:45 +090071 android.RegisterModuleType("java_sdk_library", SdkLibraryFactory)
Colin Cross79c7c262019-04-17 11:11:46 -070072 android.RegisterModuleType("java_sdk_library_import", sdkLibraryImportFactory)
Jiyong Parkc678ad32018-04-10 13:07:10 +090073
Jiyong Park82484c02018-04-23 21:41:26 +090074 android.RegisterMakeVarsProvider(pctx, func(ctx android.MakeVarsContext) {
75 javaSdkLibraries := javaSdkLibraries(ctx.Config())
76 sort.Strings(*javaSdkLibraries)
77 ctx.Strict("JAVA_SDK_LIBRARIES", strings.Join(*javaSdkLibraries, " "))
78 })
Jiyong Parkc678ad32018-04-10 13:07:10 +090079}
80
81type sdkLibraryProperties struct {
Jiyong Parkbaaf9dd2018-05-02 01:35:27 +090082 // list of optional source files that are part of API but not part of runtime library.
83 Api_srcs []string `android:"arch_variant"`
84
Sundong Ahnf043cf62018-06-25 16:04:37 +090085 // List of Java libraries that will be in the classpath when building stubs
86 Stub_only_libs []string `android:"arch_variant"`
87
Jiyong Parkc678ad32018-04-10 13:07:10 +090088 // list of package names that will be documented and publicized as API
89 Api_packages []string
90
Jiyong Park5a2c9d72018-05-01 22:25:41 +090091 // list of package names that must be hidden from the API
92 Hidden_api_packages []string
93
Paul Duffin11512472019-02-11 15:55:17 +000094 // local files that are used within user customized droiddoc options.
95 Droiddoc_option_files []string
96
97 // additional droiddoc options
98 // Available variables for substitution:
99 //
100 // $(location <label>): the path to the droiddoc_option_files with name <label>
Sundong Ahndd567f92018-07-31 17:19:11 +0900101 Droiddoc_options []string
102
Sundong Ahnb952ba02019-01-08 16:32:12 +0900103 // the java library (in classpath) for documentation that provides java srcs and srcjars.
104 Srcs_lib *string
105
106 // the base dirs under srcs_lib will be scanned for java srcs.
107 Srcs_lib_whitelist_dirs []string
108
Sundong Ahndd567f92018-07-31 17:19:11 +0900109 // the sub dirs under srcs_lib_whitelist_dirs will be scanned for java srcs.
110 // Defaults to "android.annotation".
111 Srcs_lib_whitelist_pkgs []string
112
Sundong Ahn054b19a2018-10-19 13:46:09 +0900113 // a list of top-level directories containing files to merge qualifier annotations
114 // (i.e. those intended to be included in the stubs written) from.
115 Merge_annotations_dirs []string
116
117 // a list of top-level directories containing Java stub files to merge show/hide annotations from.
118 Merge_inclusion_annotations_dirs []string
119
120 // If set to true, the path of dist files is apistubs/core. Defaults to false.
121 Core_lib *bool
122
Sundong Ahn80a87b32019-05-13 15:02:50 +0900123 // don't create dist rules.
124 No_dist *bool `blueprint:"mutated"`
125
Jiyong Parkc678ad32018-04-10 13:07:10 +0900126 // TODO: determines whether to create HTML doc or not
127 //Html_doc *bool
128}
129
Inseob Kimc0907f12019-02-08 21:00:45 +0900130type SdkLibrary struct {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900131 Library
Jiyong Parkc678ad32018-04-10 13:07:10 +0900132
Sundong Ahn054b19a2018-10-19 13:46:09 +0900133 sdkLibraryProperties sdkLibraryProperties
Jiyong Parkc678ad32018-04-10 13:07:10 +0900134
135 publicApiStubsPath android.Paths
136 systemApiStubsPath android.Paths
Jiyong Parkdf130542018-04-27 16:29:21 +0900137 testApiStubsPath android.Paths
Sundong Ahn241cd372018-07-13 16:16:44 +0900138
139 publicApiStubsImplPath android.Paths
140 systemApiStubsImplPath android.Paths
141 testApiStubsImplPath android.Paths
Sundong Ahn20e998b2018-07-24 11:19:26 +0900142
143 publicApiFilePath android.Path
144 systemApiFilePath android.Path
145 testApiFilePath android.Path
Jiyong Parkc678ad32018-04-10 13:07:10 +0900146}
147
Inseob Kimc0907f12019-02-08 21:00:45 +0900148var _ Dependency = (*SdkLibrary)(nil)
149var _ SdkLibraryDependency = (*SdkLibrary)(nil)
Colin Cross897d2ed2019-02-11 14:03:51 -0800150
Inseob Kimc0907f12019-02-08 21:00:45 +0900151func (module *SdkLibrary) DepsMutator(ctx android.BottomUpMutatorContext) {
Jiyong Parke3ef3c82019-07-15 15:31:16 +0900152 useBuiltStubs := !ctx.Config().UnbundledBuildUsePrebuiltSdks()
Jiyong Parkc678ad32018-04-10 13:07:10 +0900153 // Add dependencies to the stubs library
Jiyong Parke3ef3c82019-07-15 15:31:16 +0900154 if useBuiltStubs {
155 ctx.AddVariationDependencies(nil, publicApiStubsTag, module.stubsName(apiScopePublic))
156 }
Colin Cross42d48b72018-08-29 14:10:52 -0700157 ctx.AddVariationDependencies(nil, publicApiFileTag, module.docsName(apiScopePublic))
Sundong Ahn054b19a2018-10-19 13:46:09 +0900158
Paul Duffin250e6192019-06-07 10:44:37 +0100159 sdkDep := decodeSdkDep(ctx, sdkContext(&module.Library))
160 if sdkDep.hasStandardLibs() {
Jiyong Parke3ef3c82019-07-15 15:31:16 +0900161 if useBuiltStubs {
162 ctx.AddVariationDependencies(nil, systemApiStubsTag, module.stubsName(apiScopeSystem))
163 ctx.AddVariationDependencies(nil, testApiStubsTag, module.stubsName(apiScopeTest))
164 }
Sundong Ahn054b19a2018-10-19 13:46:09 +0900165 ctx.AddVariationDependencies(nil, systemApiFileTag, module.docsName(apiScopeSystem))
166 ctx.AddVariationDependencies(nil, testApiFileTag, module.docsName(apiScopeTest))
Sundong Ahn054b19a2018-10-19 13:46:09 +0900167 }
168
169 module.Library.deps(ctx)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900170}
171
Inseob Kimc0907f12019-02-08 21:00:45 +0900172func (module *SdkLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900173 module.Library.GenerateAndroidBuildActions(ctx)
174
Sundong Ahn57368eb2018-07-06 11:20:23 +0900175 // Record the paths to the header jars of the library (stubs and impl).
Jiyong Parkc678ad32018-04-10 13:07:10 +0900176 // When this java_sdk_library is dependened from others via "libs" property,
177 // the recorded paths will be returned depending on the link type of the caller.
178 ctx.VisitDirectDeps(func(to android.Module) {
179 otherName := ctx.OtherModuleName(to)
180 tag := ctx.OtherModuleDependencyTag(to)
181
Sundong Ahn57368eb2018-07-06 11:20:23 +0900182 if lib, ok := to.(Dependency); ok {
Jiyong Parkc678ad32018-04-10 13:07:10 +0900183 switch tag {
184 case publicApiStubsTag:
Sundong Ahn57368eb2018-07-06 11:20:23 +0900185 module.publicApiStubsPath = lib.HeaderJars()
Sundong Ahn241cd372018-07-13 16:16:44 +0900186 module.publicApiStubsImplPath = lib.ImplementationJars()
Jiyong Parkc678ad32018-04-10 13:07:10 +0900187 case systemApiStubsTag:
Sundong Ahn57368eb2018-07-06 11:20:23 +0900188 module.systemApiStubsPath = lib.HeaderJars()
Sundong Ahn241cd372018-07-13 16:16:44 +0900189 module.systemApiStubsImplPath = lib.ImplementationJars()
Jiyong Parkdf130542018-04-27 16:29:21 +0900190 case testApiStubsTag:
Sundong Ahn57368eb2018-07-06 11:20:23 +0900191 module.testApiStubsPath = lib.HeaderJars()
Sundong Ahn241cd372018-07-13 16:16:44 +0900192 module.testApiStubsImplPath = lib.ImplementationJars()
Jiyong Parkc678ad32018-04-10 13:07:10 +0900193 }
194 }
Sundong Ahn20e998b2018-07-24 11:19:26 +0900195 if doc, ok := to.(ApiFilePath); ok {
196 switch tag {
197 case publicApiFileTag:
198 module.publicApiFilePath = doc.ApiFilePath()
199 case systemApiFileTag:
200 module.systemApiFilePath = doc.ApiFilePath()
201 case testApiFileTag:
202 module.testApiFilePath = doc.ApiFilePath()
203 default:
204 ctx.ModuleErrorf("depends on module %q of unknown tag %q", otherName, tag)
205 }
206 }
Jiyong Parkc678ad32018-04-10 13:07:10 +0900207 })
208}
209
Inseob Kimc0907f12019-02-08 21:00:45 +0900210func (module *SdkLibrary) AndroidMk() android.AndroidMkData {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900211 data := module.Library.AndroidMk()
212 data.Required = append(data.Required, module.xmlFileName())
213
214 data.Custom = func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
215 android.WriteAndroidMkData(w, data)
216
217 module.Library.AndroidMkHostDex(w, name, data)
Sundong Ahn80a87b32019-05-13 15:02:50 +0900218 if !Bool(module.sdkLibraryProperties.No_dist) {
219 // Create a phony module that installs the impl library, for the case when this lib is
220 // in PRODUCT_PACKAGES.
221 owner := module.ModuleBase.Owner()
222 if owner == "" {
223 if Bool(module.sdkLibraryProperties.Core_lib) {
224 owner = "core"
225 } else {
226 owner = "android"
227 }
Sundong Ahn4fd04bb2018-08-31 18:01:37 +0900228 }
Sundong Ahn80a87b32019-05-13 15:02:50 +0900229 // Create dist rules to install the stubs libs to the dist dir
230 if len(module.publicApiStubsPath) == 1 {
231 fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+
232 module.publicApiStubsImplPath.Strings()[0]+
233 ":"+path.Join("apistubs", owner, "public",
234 module.BaseModuleName()+".jar")+")")
235 }
236 if len(module.systemApiStubsPath) == 1 {
237 fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+
238 module.systemApiStubsImplPath.Strings()[0]+
239 ":"+path.Join("apistubs", owner, "system",
240 module.BaseModuleName()+".jar")+")")
241 }
242 if len(module.testApiStubsPath) == 1 {
243 fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+
244 module.testApiStubsImplPath.Strings()[0]+
245 ":"+path.Join("apistubs", owner, "test",
246 module.BaseModuleName()+".jar")+")")
247 }
248 if module.publicApiFilePath != nil {
249 fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+
250 module.publicApiFilePath.String()+
251 ":"+path.Join("apistubs", owner, "public", "api",
252 module.BaseModuleName()+".txt")+")")
253 }
254 if module.systemApiFilePath != nil {
255 fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+
256 module.systemApiFilePath.String()+
257 ":"+path.Join("apistubs", owner, "system", "api",
258 module.BaseModuleName()+".txt")+")")
259 }
260 if module.testApiFilePath != nil {
261 fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+
262 module.testApiFilePath.String()+
263 ":"+path.Join("apistubs", owner, "test", "api",
264 module.BaseModuleName()+".txt")+")")
265 }
Sundong Ahn054b19a2018-10-19 13:46:09 +0900266 }
Jiyong Park82484c02018-04-23 21:41:26 +0900267 }
Sundong Ahn054b19a2018-10-19 13:46:09 +0900268 return data
Jiyong Park82484c02018-04-23 21:41:26 +0900269}
270
Jiyong Parkc678ad32018-04-10 13:07:10 +0900271// Module name of the stubs library
Inseob Kimc0907f12019-02-08 21:00:45 +0900272func (module *SdkLibrary) stubsName(apiScope apiScope) string {
Jiyong Parkc678ad32018-04-10 13:07:10 +0900273 stubsName := module.BaseModuleName() + sdkStubsLibrarySuffix
Jiyong Parkdf130542018-04-27 16:29:21 +0900274 switch apiScope {
275 case apiScopeSystem:
Jiyong Parkc678ad32018-04-10 13:07:10 +0900276 stubsName = stubsName + sdkSystemApiSuffix
Jiyong Parkdf130542018-04-27 16:29:21 +0900277 case apiScopeTest:
278 stubsName = stubsName + sdkTestApiSuffix
Jiyong Parkc678ad32018-04-10 13:07:10 +0900279 }
280 return stubsName
281}
282
283// Module name of the docs
Inseob Kimc0907f12019-02-08 21:00:45 +0900284func (module *SdkLibrary) docsName(apiScope apiScope) string {
Jiyong Parkc678ad32018-04-10 13:07:10 +0900285 docsName := module.BaseModuleName() + sdkDocsSuffix
Jiyong Parkdf130542018-04-27 16:29:21 +0900286 switch apiScope {
287 case apiScopeSystem:
Jiyong Parkc678ad32018-04-10 13:07:10 +0900288 docsName = docsName + sdkSystemApiSuffix
Jiyong Parkdf130542018-04-27 16:29:21 +0900289 case apiScopeTest:
290 docsName = docsName + sdkTestApiSuffix
Jiyong Parkc678ad32018-04-10 13:07:10 +0900291 }
292 return docsName
293}
294
295// Module name of the runtime implementation library
Inseob Kimc0907f12019-02-08 21:00:45 +0900296func (module *SdkLibrary) implName() string {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900297 return module.BaseModuleName()
Jiyong Parkc678ad32018-04-10 13:07:10 +0900298}
299
300// File path to the runtime implementation library
Inseob Kimc0907f12019-02-08 21:00:45 +0900301func (module *SdkLibrary) implPath() string {
Jiyong Parkc678ad32018-04-10 13:07:10 +0900302 partition := "system"
303 if module.SocSpecific() {
304 partition = "vendor"
305 } else if module.DeviceSpecific() {
306 partition = "odm"
307 } else if module.ProductSpecific() {
308 partition = "product"
309 }
310 return "/" + partition + "/framework/" + module.implName() + ".jar"
311}
312
313// Module name of the XML file for the lib
Inseob Kimc0907f12019-02-08 21:00:45 +0900314func (module *SdkLibrary) xmlFileName() string {
Jiyong Parkc678ad32018-04-10 13:07:10 +0900315 return module.BaseModuleName() + sdkXmlFileSuffix
316}
317
318// SDK version that the stubs library is built against. Note that this is always
319// *current. Older stubs library built with a numberd SDK version is created from
320// the prebuilt jar.
Inseob Kimc0907f12019-02-08 21:00:45 +0900321func (module *SdkLibrary) sdkVersion(apiScope apiScope) string {
Jiyong Parkdf130542018-04-27 16:29:21 +0900322 switch apiScope {
323 case apiScopePublic:
324 return "current"
325 case apiScopeSystem:
Jiyong Parkc678ad32018-04-10 13:07:10 +0900326 return "system_current"
Jiyong Parkdf130542018-04-27 16:29:21 +0900327 case apiScopeTest:
328 return "test_current"
329 default:
Jiyong Parkc678ad32018-04-10 13:07:10 +0900330 return "current"
331 }
332}
333
334// $(INTERNAL_PLATFORM_<apiTagName>_API_FILE) points to the generated
335// api file for the current source
336// TODO: remove this when apicheck is done in soong
Inseob Kimc0907f12019-02-08 21:00:45 +0900337func (module *SdkLibrary) apiTagName(apiScope apiScope) string {
Jiyong Parkc678ad32018-04-10 13:07:10 +0900338 apiTagName := strings.Replace(strings.ToUpper(module.BaseModuleName()), ".", "_", -1)
Jiyong Parkdf130542018-04-27 16:29:21 +0900339 switch apiScope {
340 case apiScopeSystem:
Jiyong Parkc678ad32018-04-10 13:07:10 +0900341 apiTagName = apiTagName + "_SYSTEM"
Jiyong Parkdf130542018-04-27 16:29:21 +0900342 case apiScopeTest:
343 apiTagName = apiTagName + "_TEST"
Jiyong Parkc678ad32018-04-10 13:07:10 +0900344 }
345 return apiTagName
346}
347
Inseob Kimc0907f12019-02-08 21:00:45 +0900348func (module *SdkLibrary) latestApiFilegroupName(apiScope apiScope) string {
Jiyong Park58c518b2018-05-12 22:29:12 +0900349 name := ":" + module.BaseModuleName() + ".api."
Jiyong Parkdf130542018-04-27 16:29:21 +0900350 switch apiScope {
Jiyong Park58c518b2018-05-12 22:29:12 +0900351 case apiScopePublic:
352 name = name + "public"
Jiyong Parkdf130542018-04-27 16:29:21 +0900353 case apiScopeSystem:
Jiyong Park58c518b2018-05-12 22:29:12 +0900354 name = name + "system"
Jiyong Parkdf130542018-04-27 16:29:21 +0900355 case apiScopeTest:
Jiyong Park58c518b2018-05-12 22:29:12 +0900356 name = name + "test"
Jiyong Parkc678ad32018-04-10 13:07:10 +0900357 }
Jiyong Park58c518b2018-05-12 22:29:12 +0900358 name = name + ".latest"
359 return name
360}
Jiyong Parkc678ad32018-04-10 13:07:10 +0900361
Inseob Kimc0907f12019-02-08 21:00:45 +0900362func (module *SdkLibrary) latestRemovedApiFilegroupName(apiScope apiScope) string {
Jiyong Park58c518b2018-05-12 22:29:12 +0900363 name := ":" + module.BaseModuleName() + "-removed.api."
364 switch apiScope {
365 case apiScopePublic:
366 name = name + "public"
367 case apiScopeSystem:
368 name = name + "system"
369 case apiScopeTest:
370 name = name + "test"
371 }
372 name = name + ".latest"
373 return name
Jiyong Parkc678ad32018-04-10 13:07:10 +0900374}
375
376// Creates a static java library that has API stubs
Colin Crossf8b860a2019-04-16 14:43:28 -0700377func (module *SdkLibrary) createStubsLibrary(mctx android.LoadHookContext, apiScope apiScope) {
Jiyong Parkc678ad32018-04-10 13:07:10 +0900378 props := struct {
379 Name *string
380 Srcs []string
381 Sdk_version *string
Sundong Ahnf043cf62018-06-25 16:04:37 +0900382 Libs []string
Jiyong Parkc678ad32018-04-10 13:07:10 +0900383 Soc_specific *bool
384 Device_specific *bool
385 Product_specific *bool
Sundong Ahndd567f92018-07-31 17:19:11 +0900386 Compile_dex *bool
Sundong Ahn054b19a2018-10-19 13:46:09 +0900387 System_modules *string
388 Java_version *string
Jiyong Parkc678ad32018-04-10 13:07:10 +0900389 Product_variables struct {
390 Unbundled_build struct {
391 Enabled *bool
392 }
Jiyong Park82484c02018-04-23 21:41:26 +0900393 Pdk struct {
394 Enabled *bool
395 }
Jiyong Parkc678ad32018-04-10 13:07:10 +0900396 }
Sundong Ahn054b19a2018-10-19 13:46:09 +0900397 Openjdk9 struct {
398 Srcs []string
399 Javacflags []string
400 }
Jiyong Parkc678ad32018-04-10 13:07:10 +0900401 }{}
402
Paul Duffin52d398a2019-06-11 12:31:14 +0100403 sdkVersion := module.sdkVersion(apiScope)
Paul Duffin250e6192019-06-07 10:44:37 +0100404 sdkDep := decodeSdkDep(mctx, sdkContext(&module.Library))
Paul Duffin52d398a2019-06-11 12:31:14 +0100405 if !sdkDep.hasStandardLibs() {
406 sdkVersion = "none"
407 }
Paul Duffin250e6192019-06-07 10:44:37 +0100408
Jiyong Parkdf130542018-04-27 16:29:21 +0900409 props.Name = proptools.StringPtr(module.stubsName(apiScope))
Jiyong Parkc678ad32018-04-10 13:07:10 +0900410 // sources are generated from the droiddoc
Jiyong Parkdf130542018-04-27 16:29:21 +0900411 props.Srcs = []string{":" + module.docsName(apiScope)}
Paul Duffin52d398a2019-06-11 12:31:14 +0100412 props.Sdk_version = proptools.StringPtr(sdkVersion)
Sundong Ahn054b19a2018-10-19 13:46:09 +0900413 props.Libs = module.sdkLibraryProperties.Stub_only_libs
Jiyong Parkc678ad32018-04-10 13:07:10 +0900414 // Unbundled apps will use the prebult one from /prebuilts/sdk
Colin Cross10932872019-04-18 14:27:12 -0700415 if mctx.Config().UnbundledBuildUsePrebuiltSdks() {
Colin Cross2c77ceb2019-01-21 11:56:21 -0800416 props.Product_variables.Unbundled_build.Enabled = proptools.BoolPtr(false)
417 }
Jiyong Park82484c02018-04-23 21:41:26 +0900418 props.Product_variables.Pdk.Enabled = proptools.BoolPtr(false)
Sundong Ahn054b19a2018-10-19 13:46:09 +0900419 props.System_modules = module.Library.Module.deviceProperties.System_modules
420 props.Openjdk9.Srcs = module.Library.Module.properties.Openjdk9.Srcs
421 props.Openjdk9.Javacflags = module.Library.Module.properties.Openjdk9.Javacflags
422 props.Java_version = module.Library.Module.properties.Java_version
423 if module.Library.Module.deviceProperties.Compile_dex != nil {
424 props.Compile_dex = module.Library.Module.deviceProperties.Compile_dex
Sundong Ahndd567f92018-07-31 17:19:11 +0900425 }
Jiyong Parkc678ad32018-04-10 13:07:10 +0900426
427 if module.SocSpecific() {
428 props.Soc_specific = proptools.BoolPtr(true)
429 } else if module.DeviceSpecific() {
430 props.Device_specific = proptools.BoolPtr(true)
431 } else if module.ProductSpecific() {
432 props.Product_specific = proptools.BoolPtr(true)
433 }
434
Colin Cross9ae1b922018-06-26 17:59:05 -0700435 mctx.CreateModule(android.ModuleFactoryAdaptor(LibraryFactory), &props)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900436}
437
438// Creates a droiddoc module that creates stubs source files from the given full source
439// files
Colin Crossf8b860a2019-04-16 14:43:28 -0700440func (module *SdkLibrary) createDocs(mctx android.LoadHookContext, apiScope apiScope) {
Jiyong Parkc678ad32018-04-10 13:07:10 +0900441 props := struct {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900442 Name *string
443 Srcs []string
444 Installable *bool
445 Srcs_lib *string
446 Srcs_lib_whitelist_dirs []string
447 Srcs_lib_whitelist_pkgs []string
Paul Duffin52d398a2019-06-11 12:31:14 +0100448 Sdk_version *string
Sundong Ahn054b19a2018-10-19 13:46:09 +0900449 Libs []string
Paul Duffin11512472019-02-11 15:55:17 +0000450 Arg_files []string
Sundong Ahn054b19a2018-10-19 13:46:09 +0900451 Args *string
452 Api_tag_name *string
453 Api_filename *string
454 Removed_api_filename *string
Sundong Ahn054b19a2018-10-19 13:46:09 +0900455 Java_version *string
456 Merge_annotations_dirs []string
457 Merge_inclusion_annotations_dirs []string
458 Check_api struct {
Inseob Kim38449af2019-02-28 14:24:05 +0900459 Current ApiToCheck
460 Last_released ApiToCheck
461 Ignore_missing_latest_api *bool
Jiyong Park58c518b2018-05-12 22:29:12 +0900462 }
Sundong Ahn1b92c822018-05-29 11:35:17 +0900463 Aidl struct {
464 Include_dirs []string
465 Local_include_dirs []string
466 }
Jiyong Parkc678ad32018-04-10 13:07:10 +0900467 }{}
468
Paul Duffin250e6192019-06-07 10:44:37 +0100469 sdkDep := decodeSdkDep(mctx, sdkContext(&module.Library))
Paul Duffin52d398a2019-06-11 12:31:14 +0100470 sdkVersion := ""
471 if !sdkDep.hasStandardLibs() {
472 sdkVersion = "none"
473 }
Paul Duffin250e6192019-06-07 10:44:37 +0100474
Jiyong Parkdf130542018-04-27 16:29:21 +0900475 props.Name = proptools.StringPtr(module.docsName(apiScope))
Sundong Ahn054b19a2018-10-19 13:46:09 +0900476 props.Srcs = append(props.Srcs, module.Library.Module.properties.Srcs...)
477 props.Srcs = append(props.Srcs, module.sdkLibraryProperties.Api_srcs...)
Paul Duffin52d398a2019-06-11 12:31:14 +0100478 props.Sdk_version = proptools.StringPtr(sdkVersion)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900479 props.Installable = proptools.BoolPtr(false)
Sundong Ahne6f0b052018-06-05 16:46:14 +0900480 // A droiddoc module has only one Libs property and doesn't distinguish between
481 // shared libs and static libs. So we need to add both of these libs to Libs property.
Sundong Ahn054b19a2018-10-19 13:46:09 +0900482 props.Libs = module.Library.Module.properties.Libs
483 props.Libs = append(props.Libs, module.Library.Module.properties.Static_libs...)
484 props.Aidl.Include_dirs = module.Library.Module.deviceProperties.Aidl.Include_dirs
485 props.Aidl.Local_include_dirs = module.Library.Module.deviceProperties.Aidl.Local_include_dirs
Sundong Ahn054b19a2018-10-19 13:46:09 +0900486 props.Java_version = module.Library.Module.properties.Java_version
Jiyong Parkc678ad32018-04-10 13:07:10 +0900487
Sundong Ahn054b19a2018-10-19 13:46:09 +0900488 props.Merge_annotations_dirs = module.sdkLibraryProperties.Merge_annotations_dirs
489 props.Merge_inclusion_annotations_dirs = module.sdkLibraryProperties.Merge_inclusion_annotations_dirs
490
491 droiddocArgs := " --stub-packages " + strings.Join(module.sdkLibraryProperties.Api_packages, ":") +
492 " " + android.JoinWithPrefix(module.sdkLibraryProperties.Hidden_api_packages, " --hide-package ") +
493 " " + android.JoinWithPrefix(module.sdkLibraryProperties.Droiddoc_options, " ") +
Sundong Ahn04ef8a32019-01-14 11:36:50 +0900494 " --hide MissingPermission --hide BroadcastBehavior " +
495 "--hide HiddenSuperclass --hide DeprecationMismatch --hide UnavailableSymbol " +
496 "--hide SdkConstant --hide HiddenTypeParameter --hide Todo --hide Typo"
Sundong Ahnfb2721f2018-09-17 13:23:09 +0900497
Jiyong Parkdf130542018-04-27 16:29:21 +0900498 switch apiScope {
499 case apiScopeSystem:
Jiyong Parkc678ad32018-04-10 13:07:10 +0900500 droiddocArgs = droiddocArgs + " -showAnnotation android.annotation.SystemApi"
Jiyong Parkdf130542018-04-27 16:29:21 +0900501 case apiScopeTest:
502 droiddocArgs = droiddocArgs + " -showAnnotation android.annotation.TestApi"
Jiyong Parkc678ad32018-04-10 13:07:10 +0900503 }
Paul Duffin11512472019-02-11 15:55:17 +0000504 props.Arg_files = module.sdkLibraryProperties.Droiddoc_option_files
Jiyong Parkc678ad32018-04-10 13:07:10 +0900505 props.Args = proptools.StringPtr(droiddocArgs)
506
507 // List of APIs identified from the provided source files are created. They are later
508 // compared against to the not-yet-released (a.k.a current) list of APIs and to the
509 // last-released (a.k.a numbered) list of API.
Jiyong Parkc678ad32018-04-10 13:07:10 +0900510 currentApiFileName := "current.txt"
511 removedApiFileName := "removed.txt"
Jiyong Parkdf130542018-04-27 16:29:21 +0900512 switch apiScope {
513 case apiScopeSystem:
Jiyong Parkc678ad32018-04-10 13:07:10 +0900514 currentApiFileName = "system-" + currentApiFileName
515 removedApiFileName = "system-" + removedApiFileName
Jiyong Parkdf130542018-04-27 16:29:21 +0900516 case apiScopeTest:
517 currentApiFileName = "test-" + currentApiFileName
518 removedApiFileName = "test-" + removedApiFileName
Jiyong Parkc678ad32018-04-10 13:07:10 +0900519 }
520 currentApiFileName = path.Join("api", currentApiFileName)
521 removedApiFileName = path.Join("api", removedApiFileName)
Jiyong Park58c518b2018-05-12 22:29:12 +0900522 // TODO(jiyong): remove these three props
Jiyong Parkdf130542018-04-27 16:29:21 +0900523 props.Api_tag_name = proptools.StringPtr(module.apiTagName(apiScope))
Jiyong Parkc678ad32018-04-10 13:07:10 +0900524 props.Api_filename = proptools.StringPtr(currentApiFileName)
525 props.Removed_api_filename = proptools.StringPtr(removedApiFileName)
526
Jiyong Park58c518b2018-05-12 22:29:12 +0900527 // check against the not-yet-release API
528 props.Check_api.Current.Api_file = proptools.StringPtr(currentApiFileName)
529 props.Check_api.Current.Removed_api_file = proptools.StringPtr(removedApiFileName)
Jiyong Park58c518b2018-05-12 22:29:12 +0900530
531 // check against the latest released API
532 props.Check_api.Last_released.Api_file = proptools.StringPtr(
533 module.latestApiFilegroupName(apiScope))
534 props.Check_api.Last_released.Removed_api_file = proptools.StringPtr(
535 module.latestRemovedApiFilegroupName(apiScope))
Inseob Kim38449af2019-02-28 14:24:05 +0900536 props.Check_api.Ignore_missing_latest_api = proptools.BoolPtr(true)
Sundong Ahn054b19a2018-10-19 13:46:09 +0900537 props.Srcs_lib = module.sdkLibraryProperties.Srcs_lib
538 props.Srcs_lib_whitelist_dirs = module.sdkLibraryProperties.Srcs_lib_whitelist_dirs
539 props.Srcs_lib_whitelist_pkgs = module.sdkLibraryProperties.Srcs_lib_whitelist_pkgs
Jiyong Park58c518b2018-05-12 22:29:12 +0900540
Sundong Ahn04ef8a32019-01-14 11:36:50 +0900541 mctx.CreateModule(android.ModuleFactoryAdaptor(DroidstubsFactory), &props)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900542}
543
Jiyong Parkc678ad32018-04-10 13:07:10 +0900544// Creates the xml file that publicizes the runtime library
Colin Crossf8b860a2019-04-16 14:43:28 -0700545func (module *SdkLibrary) createXmlFile(mctx android.LoadHookContext) {
Jiyong Parkc678ad32018-04-10 13:07:10 +0900546 template := `
547<?xml version="1.0" encoding="utf-8"?>
548<!-- Copyright (C) 2018 The Android Open Source Project
549
550 Licensed under the Apache License, Version 2.0 (the "License");
551 you may not use this file except in compliance with the License.
552 You may obtain a copy of the License at
553
554 http://www.apache.org/licenses/LICENSE-2.0
555
556 Unless required by applicable law or agreed to in writing, software
557 distributed under the License is distributed on an "AS IS" BASIS,
558 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
559 See the License for the specific language governing permissions and
560 limitations under the License.
561-->
562
563<permissions>
564 <library name="%s" file="%s"/>
565</permissions>
566`
567 // genrule to generate the xml file content from the template above
568 // TODO: preserve newlines in the generate xml file. Newlines are being squashed
569 // in the ninja file. Do we need to have an external tool for this?
570 xmlContent := fmt.Sprintf(template, module.BaseModuleName(), module.implPath())
571 genruleProps := struct {
572 Name *string
573 Cmd *string
574 Out []string
575 }{}
576 genruleProps.Name = proptools.StringPtr(module.xmlFileName() + "-gen")
577 genruleProps.Cmd = proptools.StringPtr("echo '" + xmlContent + "' > $(out)")
578 genruleProps.Out = []string{module.xmlFileName()}
579 mctx.CreateModule(android.ModuleFactoryAdaptor(genrule.GenRuleFactory), &genruleProps)
580
581 // creates a prebuilt_etc module to actually place the xml file under
582 // <partition>/etc/permissions
583 etcProps := struct {
584 Name *string
Jiyong Park5a8d1be2018-04-25 22:57:34 +0900585 Src *string
Jiyong Parkc678ad32018-04-10 13:07:10 +0900586 Sub_dir *string
587 Soc_specific *bool
588 Device_specific *bool
589 Product_specific *bool
590 }{}
591 etcProps.Name = proptools.StringPtr(module.xmlFileName())
Jiyong Park5a8d1be2018-04-25 22:57:34 +0900592 etcProps.Src = proptools.StringPtr(":" + module.xmlFileName() + "-gen")
Jiyong Parkc678ad32018-04-10 13:07:10 +0900593 etcProps.Sub_dir = proptools.StringPtr("permissions")
594 if module.SocSpecific() {
595 etcProps.Soc_specific = proptools.BoolPtr(true)
596 } else if module.DeviceSpecific() {
597 etcProps.Device_specific = proptools.BoolPtr(true)
598 } else if module.ProductSpecific() {
599 etcProps.Product_specific = proptools.BoolPtr(true)
600 }
601 mctx.CreateModule(android.ModuleFactoryAdaptor(android.PrebuiltEtcFactory), &etcProps)
602}
603
Colin Cross0ea8ba82019-06-06 14:33:29 -0700604func (module *SdkLibrary) PrebuiltJars(ctx android.BaseModuleContext, sdkVersion string) android.Paths {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900605 var api, v string
Paul Duffin52d398a2019-06-11 12:31:14 +0100606 if sdkVersion == "" || sdkVersion == "none" {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900607 api = "system"
608 v = "current"
609 } else if strings.Contains(sdkVersion, "_") {
610 t := strings.Split(sdkVersion, "_")
611 api = t[0]
612 v = t[1]
Jiyong Parkc678ad32018-04-10 13:07:10 +0900613 } else {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900614 api = "public"
615 v = sdkVersion
616 }
617 dir := filepath.Join("prebuilts", "sdk", v, api)
618 jar := filepath.Join(dir, module.BaseModuleName()+".jar")
619 jarPath := android.ExistentPathForSource(ctx, jar)
Sundong Ahnae418ac2019-02-28 15:01:28 +0900620 if !jarPath.Valid() {
621 ctx.PropertyErrorf("sdk_library", "invalid sdk version %q, %q does not exist", v, jar)
622 return nil
623 }
Sundong Ahn054b19a2018-10-19 13:46:09 +0900624 return android.Paths{jarPath.Path()}
625}
626
627// to satisfy SdkLibraryDependency interface
Colin Cross0ea8ba82019-06-06 14:33:29 -0700628func (module *SdkLibrary) SdkHeaderJars(ctx android.BaseModuleContext, sdkVersion string) android.Paths {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900629 // This module is just a wrapper for the stubs.
Colin Cross10932872019-04-18 14:27:12 -0700630 if ctx.Config().UnbundledBuildUsePrebuiltSdks() {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900631 return module.PrebuiltJars(ctx, sdkVersion)
632 } else {
633 if strings.HasPrefix(sdkVersion, "system_") {
634 return module.systemApiStubsPath
635 } else if sdkVersion == "" {
636 return module.Library.HeaderJars()
637 } else {
638 return module.publicApiStubsPath
639 }
Jiyong Parkc678ad32018-04-10 13:07:10 +0900640 }
641}
642
Sundong Ahn241cd372018-07-13 16:16:44 +0900643// to satisfy SdkLibraryDependency interface
Colin Cross0ea8ba82019-06-06 14:33:29 -0700644func (module *SdkLibrary) SdkImplementationJars(ctx android.BaseModuleContext, sdkVersion string) android.Paths {
Sundong Ahn241cd372018-07-13 16:16:44 +0900645 // This module is just a wrapper for the stubs.
Colin Cross10932872019-04-18 14:27:12 -0700646 if ctx.Config().UnbundledBuildUsePrebuiltSdks() {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900647 return module.PrebuiltJars(ctx, sdkVersion)
Sundong Ahn241cd372018-07-13 16:16:44 +0900648 } else {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900649 if strings.HasPrefix(sdkVersion, "system_") {
650 return module.systemApiStubsImplPath
651 } else if sdkVersion == "" {
652 return module.Library.ImplementationJars()
653 } else {
654 return module.publicApiStubsImplPath
655 }
Sundong Ahn241cd372018-07-13 16:16:44 +0900656 }
657}
658
Sundong Ahn80a87b32019-05-13 15:02:50 +0900659func (module *SdkLibrary) SetNoDist() {
660 module.sdkLibraryProperties.No_dist = proptools.BoolPtr(true)
661}
662
Colin Cross571cccf2019-02-04 11:22:08 -0800663var javaSdkLibrariesKey = android.NewOnceKey("javaSdkLibraries")
664
Jiyong Park82484c02018-04-23 21:41:26 +0900665func javaSdkLibraries(config android.Config) *[]string {
Colin Cross571cccf2019-02-04 11:22:08 -0800666 return config.Once(javaSdkLibrariesKey, func() interface{} {
Jiyong Park82484c02018-04-23 21:41:26 +0900667 return &[]string{}
668 }).(*[]string)
669}
670
Jiyong Parkc678ad32018-04-10 13:07:10 +0900671// For a java_sdk_library module, create internal modules for stubs, docs,
672// runtime libs and xml file. If requested, the stubs and docs are created twice
673// once for public API level and once for system API level
Colin Crossf8b860a2019-04-16 14:43:28 -0700674func (module *SdkLibrary) CreateInternalModules(mctx android.LoadHookContext) {
Inseob Kim6e93ac92019-03-21 17:43:49 +0900675 if len(module.Library.Module.properties.Srcs) == 0 {
Inseob Kimc0907f12019-02-08 21:00:45 +0900676 mctx.PropertyErrorf("srcs", "java_sdk_library must specify srcs")
677 }
678
Inseob Kim6e93ac92019-03-21 17:43:49 +0900679 if len(module.sdkLibraryProperties.Api_packages) == 0 {
Inseob Kimc0907f12019-02-08 21:00:45 +0900680 mctx.PropertyErrorf("api_packages", "java_sdk_library must specify api_packages")
681 }
Inseob Kim8098faa2019-03-18 10:19:51 +0900682
683 missing_current_api := false
684
685 for _, scope := range []string{"", "system-", "test-"} {
686 for _, api := range []string{"current.txt", "removed.txt"} {
687 path := path.Join(mctx.ModuleDir(), "api", scope+api)
688 p := android.ExistentPathForSource(mctx, path)
689 if !p.Valid() {
690 mctx.ModuleErrorf("Current api file %#v doesn't exist", path)
691 missing_current_api = true
692 }
693 }
694 }
695
696 if missing_current_api {
697 script := "build/soong/scripts/gen-java-current-api-files.sh"
698 p := android.ExistentPathForSource(mctx, script)
699
700 if !p.Valid() {
701 panic(fmt.Sprintf("script file %s doesn't exist", script))
702 }
703
704 mctx.ModuleErrorf("One or more current api files are missing. "+
705 "You can update them by:\n"+
706 "%s %q && m update-api", script, mctx.ModuleDir())
707 return
708 }
709
Inseob Kimc0907f12019-02-08 21:00:45 +0900710 // for public API stubs
711 module.createStubsLibrary(mctx, apiScopePublic)
712 module.createDocs(mctx, apiScopePublic)
713
Paul Duffin250e6192019-06-07 10:44:37 +0100714 sdkDep := decodeSdkDep(mctx, sdkContext(&module.Library))
715 if sdkDep.hasStandardLibs() {
Inseob Kimc0907f12019-02-08 21:00:45 +0900716 // for system API stubs
717 module.createStubsLibrary(mctx, apiScopeSystem)
718 module.createDocs(mctx, apiScopeSystem)
719
720 // for test API stubs
721 module.createStubsLibrary(mctx, apiScopeTest)
722 module.createDocs(mctx, apiScopeTest)
723
724 // for runtime
725 module.createXmlFile(mctx)
726 }
727
728 // record java_sdk_library modules so that they are exported to make
729 javaSdkLibraries := javaSdkLibraries(mctx.Config())
730 javaSdkLibrariesLock.Lock()
731 defer javaSdkLibrariesLock.Unlock()
732 *javaSdkLibraries = append(*javaSdkLibraries, module.BaseModuleName())
733}
734
735func (module *SdkLibrary) InitSdkLibraryProperties() {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900736 module.AddProperties(
737 &module.sdkLibraryProperties,
738 &module.Library.Module.properties,
739 &module.Library.Module.dexpreoptProperties,
740 &module.Library.Module.deviceProperties,
741 &module.Library.Module.protoProperties,
742 )
743
744 module.Library.Module.properties.Installable = proptools.BoolPtr(true)
745 module.Library.Module.deviceProperties.IsSDKLibrary = true
Inseob Kimc0907f12019-02-08 21:00:45 +0900746}
Sundong Ahn054b19a2018-10-19 13:46:09 +0900747
Jaewoong Jung4f158ee2019-07-11 10:05:35 -0700748// java_sdk_library is a special Java library that provides optional platform APIs to apps.
749// In practice, it can be viewed as a combination of several modules: 1) stubs library that clients
750// are linked against to, 2) droiddoc module that internally generates API stubs source files,
751// 3) the real runtime shared library that implements the APIs, and 4) XML file for adding
752// the runtime lib to the classpath at runtime if requested via <uses-library>.
Inseob Kimc0907f12019-02-08 21:00:45 +0900753func SdkLibraryFactory() android.Module {
754 module := &SdkLibrary{}
755 module.InitSdkLibraryProperties()
Sundong Ahn054b19a2018-10-19 13:46:09 +0900756 InitJavaModule(module, android.HostAndDeviceSupported)
Colin Crossf8b860a2019-04-16 14:43:28 -0700757 android.AddLoadHook(module, func(ctx android.LoadHookContext) { module.CreateInternalModules(ctx) })
Jiyong Parkc678ad32018-04-10 13:07:10 +0900758 return module
759}
Colin Cross79c7c262019-04-17 11:11:46 -0700760
761//
762// SDK library prebuilts
763//
764
765type sdkLibraryImportProperties struct {
766 Jars []string `android:"path"`
767
768 Sdk_version *string
769
770 Installable *bool
771
772 // List of shared java libs that this module has dependencies to
773 Libs []string
774
775 // List of files to remove from the jar file(s)
776 Exclude_files []string
777
778 // List of directories to remove from the jar file(s)
779 Exclude_dirs []string
780}
781
782type sdkLibraryImport struct {
783 android.ModuleBase
784 android.DefaultableModuleBase
785 prebuilt android.Prebuilt
786
787 properties sdkLibraryImportProperties
788
789 stubsPath android.Paths
790}
791
792var _ SdkLibraryDependency = (*sdkLibraryImport)(nil)
793
Jaewoong Jung4f158ee2019-07-11 10:05:35 -0700794// java_sdk_library_import imports a prebuilt java_sdk_library.
Colin Cross79c7c262019-04-17 11:11:46 -0700795func sdkLibraryImportFactory() android.Module {
796 module := &sdkLibraryImport{}
797
798 module.AddProperties(&module.properties)
799
800 android.InitPrebuiltModule(module, &module.properties.Jars)
801 InitJavaModule(module, android.HostAndDeviceSupported)
802
803 android.AddLoadHook(module, func(mctx android.LoadHookContext) { module.createInternalModules(mctx) })
804 return module
805}
806
807func (module *sdkLibraryImport) Prebuilt() *android.Prebuilt {
808 return &module.prebuilt
809}
810
811func (module *sdkLibraryImport) Name() string {
812 return module.prebuilt.Name(module.ModuleBase.Name())
813}
814
815func (module *sdkLibraryImport) createInternalModules(mctx android.LoadHookContext) {
816 // Creates a java import for the jar with ".stubs" suffix
817 props := struct {
818 Name *string
819 Soc_specific *bool
820 Device_specific *bool
821 Product_specific *bool
822 }{}
823
824 props.Name = proptools.StringPtr(module.BaseModuleName() + sdkStubsLibrarySuffix)
825
826 if module.SocSpecific() {
827 props.Soc_specific = proptools.BoolPtr(true)
828 } else if module.DeviceSpecific() {
829 props.Device_specific = proptools.BoolPtr(true)
830 } else if module.ProductSpecific() {
831 props.Product_specific = proptools.BoolPtr(true)
832 }
833
834 mctx.CreateModule(android.ModuleFactoryAdaptor(ImportFactory), &props, &module.properties)
835
836 javaSdkLibraries := javaSdkLibraries(mctx.Config())
837 javaSdkLibrariesLock.Lock()
838 defer javaSdkLibrariesLock.Unlock()
839 *javaSdkLibraries = append(*javaSdkLibraries, module.BaseModuleName())
840}
841
842func (module *sdkLibraryImport) DepsMutator(ctx android.BottomUpMutatorContext) {
843 // Add dependencies to the prebuilt stubs library
844 ctx.AddVariationDependencies(nil, publicApiStubsTag, module.BaseModuleName()+sdkStubsLibrarySuffix)
845}
846
847func (module *sdkLibraryImport) GenerateAndroidBuildActions(ctx android.ModuleContext) {
848 // Record the paths to the prebuilt stubs library.
849 ctx.VisitDirectDeps(func(to android.Module) {
850 tag := ctx.OtherModuleDependencyTag(to)
851
852 switch tag {
853 case publicApiStubsTag:
854 module.stubsPath = to.(Dependency).HeaderJars()
855 }
856 })
857}
858
859// to satisfy SdkLibraryDependency interface
Colin Cross0ea8ba82019-06-06 14:33:29 -0700860func (module *sdkLibraryImport) SdkHeaderJars(ctx android.BaseModuleContext, sdkVersion string) android.Paths {
Colin Cross79c7c262019-04-17 11:11:46 -0700861 // This module is just a wrapper for the prebuilt stubs.
862 return module.stubsPath
863}
864
865// to satisfy SdkLibraryDependency interface
Colin Cross0ea8ba82019-06-06 14:33:29 -0700866func (module *sdkLibraryImport) SdkImplementationJars(ctx android.BaseModuleContext, sdkVersion string) android.Paths {
Colin Cross79c7c262019-04-17 11:11:46 -0700867 // This module is just a wrapper for the stubs.
868 return module.stubsPath
869}