blob: 56b30b2cffd0f259446640ca544a8708dd13fc6b [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
Jiyong Park1112c4c2019-08-16 21:12:10 +0900106 // list of packages to document from srcs_lib. Defaults to "android.annotation".
Sundong Ahndd567f92018-07-31 17:19:11 +0900107 Srcs_lib_whitelist_pkgs []string
108
Sundong Ahn054b19a2018-10-19 13:46:09 +0900109 // a list of top-level directories containing files to merge qualifier annotations
110 // (i.e. those intended to be included in the stubs written) from.
111 Merge_annotations_dirs []string
112
113 // a list of top-level directories containing Java stub files to merge show/hide annotations from.
114 Merge_inclusion_annotations_dirs []string
115
116 // If set to true, the path of dist files is apistubs/core. Defaults to false.
117 Core_lib *bool
118
Sundong Ahn80a87b32019-05-13 15:02:50 +0900119 // don't create dist rules.
120 No_dist *bool `blueprint:"mutated"`
121
Jiyong Parkc678ad32018-04-10 13:07:10 +0900122 // TODO: determines whether to create HTML doc or not
123 //Html_doc *bool
124}
125
Inseob Kimc0907f12019-02-08 21:00:45 +0900126type SdkLibrary struct {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900127 Library
Jiyong Parkc678ad32018-04-10 13:07:10 +0900128
Sundong Ahn054b19a2018-10-19 13:46:09 +0900129 sdkLibraryProperties sdkLibraryProperties
Jiyong Parkc678ad32018-04-10 13:07:10 +0900130
131 publicApiStubsPath android.Paths
132 systemApiStubsPath android.Paths
Jiyong Parkdf130542018-04-27 16:29:21 +0900133 testApiStubsPath android.Paths
Sundong Ahn241cd372018-07-13 16:16:44 +0900134
135 publicApiStubsImplPath android.Paths
136 systemApiStubsImplPath android.Paths
137 testApiStubsImplPath android.Paths
Sundong Ahn20e998b2018-07-24 11:19:26 +0900138
139 publicApiFilePath android.Path
140 systemApiFilePath android.Path
141 testApiFilePath android.Path
Jiyong Parkc678ad32018-04-10 13:07:10 +0900142}
143
Inseob Kimc0907f12019-02-08 21:00:45 +0900144var _ Dependency = (*SdkLibrary)(nil)
145var _ SdkLibraryDependency = (*SdkLibrary)(nil)
Colin Cross897d2ed2019-02-11 14:03:51 -0800146
Inseob Kimc0907f12019-02-08 21:00:45 +0900147func (module *SdkLibrary) DepsMutator(ctx android.BottomUpMutatorContext) {
Jiyong Parke3ef3c82019-07-15 15:31:16 +0900148 useBuiltStubs := !ctx.Config().UnbundledBuildUsePrebuiltSdks()
Jiyong Parkc678ad32018-04-10 13:07:10 +0900149 // Add dependencies to the stubs library
Jiyong Parke3ef3c82019-07-15 15:31:16 +0900150 if useBuiltStubs {
151 ctx.AddVariationDependencies(nil, publicApiStubsTag, module.stubsName(apiScopePublic))
152 }
Colin Cross42d48b72018-08-29 14:10:52 -0700153 ctx.AddVariationDependencies(nil, publicApiFileTag, module.docsName(apiScopePublic))
Sundong Ahn054b19a2018-10-19 13:46:09 +0900154
Paul Duffin250e6192019-06-07 10:44:37 +0100155 sdkDep := decodeSdkDep(ctx, sdkContext(&module.Library))
156 if sdkDep.hasStandardLibs() {
Jiyong Parke3ef3c82019-07-15 15:31:16 +0900157 if useBuiltStubs {
158 ctx.AddVariationDependencies(nil, systemApiStubsTag, module.stubsName(apiScopeSystem))
159 ctx.AddVariationDependencies(nil, testApiStubsTag, module.stubsName(apiScopeTest))
160 }
Sundong Ahn054b19a2018-10-19 13:46:09 +0900161 ctx.AddVariationDependencies(nil, systemApiFileTag, module.docsName(apiScopeSystem))
162 ctx.AddVariationDependencies(nil, testApiFileTag, module.docsName(apiScopeTest))
Sundong Ahn054b19a2018-10-19 13:46:09 +0900163 }
164
165 module.Library.deps(ctx)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900166}
167
Inseob Kimc0907f12019-02-08 21:00:45 +0900168func (module *SdkLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900169 module.Library.GenerateAndroidBuildActions(ctx)
170
Sundong Ahn57368eb2018-07-06 11:20:23 +0900171 // Record the paths to the header jars of the library (stubs and impl).
Jiyong Parkc678ad32018-04-10 13:07:10 +0900172 // When this java_sdk_library is dependened from others via "libs" property,
173 // the recorded paths will be returned depending on the link type of the caller.
174 ctx.VisitDirectDeps(func(to android.Module) {
175 otherName := ctx.OtherModuleName(to)
176 tag := ctx.OtherModuleDependencyTag(to)
177
Sundong Ahn57368eb2018-07-06 11:20:23 +0900178 if lib, ok := to.(Dependency); ok {
Jiyong Parkc678ad32018-04-10 13:07:10 +0900179 switch tag {
180 case publicApiStubsTag:
Sundong Ahn57368eb2018-07-06 11:20:23 +0900181 module.publicApiStubsPath = lib.HeaderJars()
Sundong Ahn241cd372018-07-13 16:16:44 +0900182 module.publicApiStubsImplPath = lib.ImplementationJars()
Jiyong Parkc678ad32018-04-10 13:07:10 +0900183 case systemApiStubsTag:
Sundong Ahn57368eb2018-07-06 11:20:23 +0900184 module.systemApiStubsPath = lib.HeaderJars()
Sundong Ahn241cd372018-07-13 16:16:44 +0900185 module.systemApiStubsImplPath = lib.ImplementationJars()
Jiyong Parkdf130542018-04-27 16:29:21 +0900186 case testApiStubsTag:
Sundong Ahn57368eb2018-07-06 11:20:23 +0900187 module.testApiStubsPath = lib.HeaderJars()
Sundong Ahn241cd372018-07-13 16:16:44 +0900188 module.testApiStubsImplPath = lib.ImplementationJars()
Jiyong Parkc678ad32018-04-10 13:07:10 +0900189 }
190 }
Sundong Ahn20e998b2018-07-24 11:19:26 +0900191 if doc, ok := to.(ApiFilePath); ok {
192 switch tag {
193 case publicApiFileTag:
194 module.publicApiFilePath = doc.ApiFilePath()
195 case systemApiFileTag:
196 module.systemApiFilePath = doc.ApiFilePath()
197 case testApiFileTag:
198 module.testApiFilePath = doc.ApiFilePath()
199 default:
200 ctx.ModuleErrorf("depends on module %q of unknown tag %q", otherName, tag)
201 }
202 }
Jiyong Parkc678ad32018-04-10 13:07:10 +0900203 })
204}
205
Inseob Kimc0907f12019-02-08 21:00:45 +0900206func (module *SdkLibrary) AndroidMk() android.AndroidMkData {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900207 data := module.Library.AndroidMk()
208 data.Required = append(data.Required, module.xmlFileName())
209
210 data.Custom = func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
211 android.WriteAndroidMkData(w, data)
212
213 module.Library.AndroidMkHostDex(w, name, data)
Sundong Ahn80a87b32019-05-13 15:02:50 +0900214 if !Bool(module.sdkLibraryProperties.No_dist) {
215 // Create a phony module that installs the impl library, for the case when this lib is
216 // in PRODUCT_PACKAGES.
217 owner := module.ModuleBase.Owner()
218 if owner == "" {
219 if Bool(module.sdkLibraryProperties.Core_lib) {
220 owner = "core"
221 } else {
222 owner = "android"
223 }
Sundong Ahn4fd04bb2018-08-31 18:01:37 +0900224 }
Sundong Ahn80a87b32019-05-13 15:02:50 +0900225 // Create dist rules to install the stubs libs to the dist dir
226 if len(module.publicApiStubsPath) == 1 {
227 fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+
228 module.publicApiStubsImplPath.Strings()[0]+
229 ":"+path.Join("apistubs", owner, "public",
230 module.BaseModuleName()+".jar")+")")
231 }
232 if len(module.systemApiStubsPath) == 1 {
233 fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+
234 module.systemApiStubsImplPath.Strings()[0]+
235 ":"+path.Join("apistubs", owner, "system",
236 module.BaseModuleName()+".jar")+")")
237 }
238 if len(module.testApiStubsPath) == 1 {
239 fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+
240 module.testApiStubsImplPath.Strings()[0]+
241 ":"+path.Join("apistubs", owner, "test",
242 module.BaseModuleName()+".jar")+")")
243 }
244 if module.publicApiFilePath != nil {
245 fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+
246 module.publicApiFilePath.String()+
247 ":"+path.Join("apistubs", owner, "public", "api",
248 module.BaseModuleName()+".txt")+")")
249 }
250 if module.systemApiFilePath != nil {
251 fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+
252 module.systemApiFilePath.String()+
253 ":"+path.Join("apistubs", owner, "system", "api",
254 module.BaseModuleName()+".txt")+")")
255 }
256 if module.testApiFilePath != nil {
257 fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+
258 module.testApiFilePath.String()+
259 ":"+path.Join("apistubs", owner, "test", "api",
260 module.BaseModuleName()+".txt")+")")
261 }
Sundong Ahn054b19a2018-10-19 13:46:09 +0900262 }
Jiyong Park82484c02018-04-23 21:41:26 +0900263 }
Sundong Ahn054b19a2018-10-19 13:46:09 +0900264 return data
Jiyong Park82484c02018-04-23 21:41:26 +0900265}
266
Jiyong Parkc678ad32018-04-10 13:07:10 +0900267// Module name of the stubs library
Inseob Kimc0907f12019-02-08 21:00:45 +0900268func (module *SdkLibrary) stubsName(apiScope apiScope) string {
Jiyong Parkc678ad32018-04-10 13:07:10 +0900269 stubsName := module.BaseModuleName() + sdkStubsLibrarySuffix
Jiyong Parkdf130542018-04-27 16:29:21 +0900270 switch apiScope {
271 case apiScopeSystem:
Jiyong Parkc678ad32018-04-10 13:07:10 +0900272 stubsName = stubsName + sdkSystemApiSuffix
Jiyong Parkdf130542018-04-27 16:29:21 +0900273 case apiScopeTest:
274 stubsName = stubsName + sdkTestApiSuffix
Jiyong Parkc678ad32018-04-10 13:07:10 +0900275 }
276 return stubsName
277}
278
279// Module name of the docs
Inseob Kimc0907f12019-02-08 21:00:45 +0900280func (module *SdkLibrary) docsName(apiScope apiScope) string {
Jiyong Parkc678ad32018-04-10 13:07:10 +0900281 docsName := module.BaseModuleName() + sdkDocsSuffix
Jiyong Parkdf130542018-04-27 16:29:21 +0900282 switch apiScope {
283 case apiScopeSystem:
Jiyong Parkc678ad32018-04-10 13:07:10 +0900284 docsName = docsName + sdkSystemApiSuffix
Jiyong Parkdf130542018-04-27 16:29:21 +0900285 case apiScopeTest:
286 docsName = docsName + sdkTestApiSuffix
Jiyong Parkc678ad32018-04-10 13:07:10 +0900287 }
288 return docsName
289}
290
291// Module name of the runtime implementation library
Inseob Kimc0907f12019-02-08 21:00:45 +0900292func (module *SdkLibrary) implName() string {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900293 return module.BaseModuleName()
Jiyong Parkc678ad32018-04-10 13:07:10 +0900294}
295
296// File path to the runtime implementation library
Inseob Kimc0907f12019-02-08 21:00:45 +0900297func (module *SdkLibrary) implPath() string {
Jiyong Parkc678ad32018-04-10 13:07:10 +0900298 partition := "system"
299 if module.SocSpecific() {
300 partition = "vendor"
301 } else if module.DeviceSpecific() {
302 partition = "odm"
303 } else if module.ProductSpecific() {
304 partition = "product"
305 }
306 return "/" + partition + "/framework/" + module.implName() + ".jar"
307}
308
309// Module name of the XML file for the lib
Inseob Kimc0907f12019-02-08 21:00:45 +0900310func (module *SdkLibrary) xmlFileName() string {
Jiyong Parkc678ad32018-04-10 13:07:10 +0900311 return module.BaseModuleName() + sdkXmlFileSuffix
312}
313
314// SDK version that the stubs library is built against. Note that this is always
315// *current. Older stubs library built with a numberd SDK version is created from
316// the prebuilt jar.
Inseob Kimc0907f12019-02-08 21:00:45 +0900317func (module *SdkLibrary) sdkVersion(apiScope apiScope) string {
Jiyong Parkdf130542018-04-27 16:29:21 +0900318 switch apiScope {
319 case apiScopePublic:
320 return "current"
321 case apiScopeSystem:
Jiyong Parkc678ad32018-04-10 13:07:10 +0900322 return "system_current"
Jiyong Parkdf130542018-04-27 16:29:21 +0900323 case apiScopeTest:
324 return "test_current"
325 default:
Jiyong Parkc678ad32018-04-10 13:07:10 +0900326 return "current"
327 }
328}
329
330// $(INTERNAL_PLATFORM_<apiTagName>_API_FILE) points to the generated
331// api file for the current source
332// TODO: remove this when apicheck is done in soong
Inseob Kimc0907f12019-02-08 21:00:45 +0900333func (module *SdkLibrary) apiTagName(apiScope apiScope) string {
Jiyong Parkc678ad32018-04-10 13:07:10 +0900334 apiTagName := strings.Replace(strings.ToUpper(module.BaseModuleName()), ".", "_", -1)
Jiyong Parkdf130542018-04-27 16:29:21 +0900335 switch apiScope {
336 case apiScopeSystem:
Jiyong Parkc678ad32018-04-10 13:07:10 +0900337 apiTagName = apiTagName + "_SYSTEM"
Jiyong Parkdf130542018-04-27 16:29:21 +0900338 case apiScopeTest:
339 apiTagName = apiTagName + "_TEST"
Jiyong Parkc678ad32018-04-10 13:07:10 +0900340 }
341 return apiTagName
342}
343
Inseob Kimc0907f12019-02-08 21:00:45 +0900344func (module *SdkLibrary) latestApiFilegroupName(apiScope apiScope) string {
Jiyong Park58c518b2018-05-12 22:29:12 +0900345 name := ":" + module.BaseModuleName() + ".api."
Jiyong Parkdf130542018-04-27 16:29:21 +0900346 switch apiScope {
Jiyong Park58c518b2018-05-12 22:29:12 +0900347 case apiScopePublic:
348 name = name + "public"
Jiyong Parkdf130542018-04-27 16:29:21 +0900349 case apiScopeSystem:
Jiyong Park58c518b2018-05-12 22:29:12 +0900350 name = name + "system"
Jiyong Parkdf130542018-04-27 16:29:21 +0900351 case apiScopeTest:
Jiyong Park58c518b2018-05-12 22:29:12 +0900352 name = name + "test"
Jiyong Parkc678ad32018-04-10 13:07:10 +0900353 }
Jiyong Park58c518b2018-05-12 22:29:12 +0900354 name = name + ".latest"
355 return name
356}
Jiyong Parkc678ad32018-04-10 13:07:10 +0900357
Inseob Kimc0907f12019-02-08 21:00:45 +0900358func (module *SdkLibrary) latestRemovedApiFilegroupName(apiScope apiScope) string {
Jiyong Park58c518b2018-05-12 22:29:12 +0900359 name := ":" + module.BaseModuleName() + "-removed.api."
360 switch apiScope {
361 case apiScopePublic:
362 name = name + "public"
363 case apiScopeSystem:
364 name = name + "system"
365 case apiScopeTest:
366 name = name + "test"
367 }
368 name = name + ".latest"
369 return name
Jiyong Parkc678ad32018-04-10 13:07:10 +0900370}
371
372// Creates a static java library that has API stubs
Colin Crossf8b860a2019-04-16 14:43:28 -0700373func (module *SdkLibrary) createStubsLibrary(mctx android.LoadHookContext, apiScope apiScope) {
Jiyong Parkc678ad32018-04-10 13:07:10 +0900374 props := struct {
375 Name *string
376 Srcs []string
377 Sdk_version *string
Sundong Ahnf043cf62018-06-25 16:04:37 +0900378 Libs []string
Jiyong Parkc678ad32018-04-10 13:07:10 +0900379 Soc_specific *bool
380 Device_specific *bool
381 Product_specific *bool
Sundong Ahndd567f92018-07-31 17:19:11 +0900382 Compile_dex *bool
Sundong Ahn054b19a2018-10-19 13:46:09 +0900383 System_modules *string
384 Java_version *string
Jiyong Parkc678ad32018-04-10 13:07:10 +0900385 Product_variables struct {
386 Unbundled_build struct {
387 Enabled *bool
388 }
Jiyong Park82484c02018-04-23 21:41:26 +0900389 Pdk struct {
390 Enabled *bool
391 }
Jiyong Parkc678ad32018-04-10 13:07:10 +0900392 }
Sundong Ahn054b19a2018-10-19 13:46:09 +0900393 Openjdk9 struct {
394 Srcs []string
395 Javacflags []string
396 }
Jiyong Parkc678ad32018-04-10 13:07:10 +0900397 }{}
398
Paul Duffin52d398a2019-06-11 12:31:14 +0100399 sdkVersion := module.sdkVersion(apiScope)
Paul Duffin250e6192019-06-07 10:44:37 +0100400 sdkDep := decodeSdkDep(mctx, sdkContext(&module.Library))
Paul Duffin52d398a2019-06-11 12:31:14 +0100401 if !sdkDep.hasStandardLibs() {
402 sdkVersion = "none"
403 }
Paul Duffin250e6192019-06-07 10:44:37 +0100404
Jiyong Parkdf130542018-04-27 16:29:21 +0900405 props.Name = proptools.StringPtr(module.stubsName(apiScope))
Jiyong Parkc678ad32018-04-10 13:07:10 +0900406 // sources are generated from the droiddoc
Jiyong Parkdf130542018-04-27 16:29:21 +0900407 props.Srcs = []string{":" + module.docsName(apiScope)}
Paul Duffin52d398a2019-06-11 12:31:14 +0100408 props.Sdk_version = proptools.StringPtr(sdkVersion)
Sundong Ahn054b19a2018-10-19 13:46:09 +0900409 props.Libs = module.sdkLibraryProperties.Stub_only_libs
Jiyong Parkc678ad32018-04-10 13:07:10 +0900410 // Unbundled apps will use the prebult one from /prebuilts/sdk
Colin Cross10932872019-04-18 14:27:12 -0700411 if mctx.Config().UnbundledBuildUsePrebuiltSdks() {
Colin Cross2c77ceb2019-01-21 11:56:21 -0800412 props.Product_variables.Unbundled_build.Enabled = proptools.BoolPtr(false)
413 }
Jiyong Park82484c02018-04-23 21:41:26 +0900414 props.Product_variables.Pdk.Enabled = proptools.BoolPtr(false)
Sundong Ahn054b19a2018-10-19 13:46:09 +0900415 props.System_modules = module.Library.Module.deviceProperties.System_modules
416 props.Openjdk9.Srcs = module.Library.Module.properties.Openjdk9.Srcs
417 props.Openjdk9.Javacflags = module.Library.Module.properties.Openjdk9.Javacflags
418 props.Java_version = module.Library.Module.properties.Java_version
419 if module.Library.Module.deviceProperties.Compile_dex != nil {
420 props.Compile_dex = module.Library.Module.deviceProperties.Compile_dex
Sundong Ahndd567f92018-07-31 17:19:11 +0900421 }
Jiyong Parkc678ad32018-04-10 13:07:10 +0900422
423 if module.SocSpecific() {
424 props.Soc_specific = proptools.BoolPtr(true)
425 } else if module.DeviceSpecific() {
426 props.Device_specific = proptools.BoolPtr(true)
427 } else if module.ProductSpecific() {
428 props.Product_specific = proptools.BoolPtr(true)
429 }
430
Colin Cross9ae1b922018-06-26 17:59:05 -0700431 mctx.CreateModule(android.ModuleFactoryAdaptor(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
441 Srcs_lib *string
Sundong Ahn054b19a2018-10-19 13:46:09 +0900442 Srcs_lib_whitelist_pkgs []string
Paul Duffin52d398a2019-06-11 12:31:14 +0100443 Sdk_version *string
Sundong Ahn054b19a2018-10-19 13:46:09 +0900444 Libs []string
Paul Duffin11512472019-02-11 15:55:17 +0000445 Arg_files []string
Sundong Ahn054b19a2018-10-19 13:46:09 +0900446 Args *string
447 Api_tag_name *string
448 Api_filename *string
449 Removed_api_filename *string
Sundong Ahn054b19a2018-10-19 13:46:09 +0900450 Java_version *string
451 Merge_annotations_dirs []string
452 Merge_inclusion_annotations_dirs []string
453 Check_api struct {
Inseob Kim38449af2019-02-28 14:24:05 +0900454 Current ApiToCheck
455 Last_released ApiToCheck
456 Ignore_missing_latest_api *bool
Jiyong Park58c518b2018-05-12 22:29:12 +0900457 }
Sundong Ahn1b92c822018-05-29 11:35:17 +0900458 Aidl struct {
459 Include_dirs []string
460 Local_include_dirs []string
461 }
Jiyong Parkc678ad32018-04-10 13:07:10 +0900462 }{}
463
Paul Duffin250e6192019-06-07 10:44:37 +0100464 sdkDep := decodeSdkDep(mctx, sdkContext(&module.Library))
Paul Duffin52d398a2019-06-11 12:31:14 +0100465 sdkVersion := ""
466 if !sdkDep.hasStandardLibs() {
467 sdkVersion = "none"
468 }
Paul Duffin250e6192019-06-07 10:44:37 +0100469
Jiyong Parkdf130542018-04-27 16:29:21 +0900470 props.Name = proptools.StringPtr(module.docsName(apiScope))
Sundong Ahn054b19a2018-10-19 13:46:09 +0900471 props.Srcs = append(props.Srcs, module.Library.Module.properties.Srcs...)
472 props.Srcs = append(props.Srcs, module.sdkLibraryProperties.Api_srcs...)
Paul Duffin52d398a2019-06-11 12:31:14 +0100473 props.Sdk_version = proptools.StringPtr(sdkVersion)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900474 props.Installable = proptools.BoolPtr(false)
Sundong Ahne6f0b052018-06-05 16:46:14 +0900475 // A droiddoc module has only one Libs property and doesn't distinguish between
476 // shared libs and static libs. So we need to add both of these libs to Libs property.
Sundong Ahn054b19a2018-10-19 13:46:09 +0900477 props.Libs = module.Library.Module.properties.Libs
478 props.Libs = append(props.Libs, module.Library.Module.properties.Static_libs...)
479 props.Aidl.Include_dirs = module.Library.Module.deviceProperties.Aidl.Include_dirs
480 props.Aidl.Local_include_dirs = module.Library.Module.deviceProperties.Aidl.Local_include_dirs
Sundong Ahn054b19a2018-10-19 13:46:09 +0900481 props.Java_version = module.Library.Module.properties.Java_version
Jiyong Parkc678ad32018-04-10 13:07:10 +0900482
Sundong Ahn054b19a2018-10-19 13:46:09 +0900483 props.Merge_annotations_dirs = module.sdkLibraryProperties.Merge_annotations_dirs
484 props.Merge_inclusion_annotations_dirs = module.sdkLibraryProperties.Merge_inclusion_annotations_dirs
485
486 droiddocArgs := " --stub-packages " + strings.Join(module.sdkLibraryProperties.Api_packages, ":") +
487 " " + android.JoinWithPrefix(module.sdkLibraryProperties.Hidden_api_packages, " --hide-package ") +
488 " " + android.JoinWithPrefix(module.sdkLibraryProperties.Droiddoc_options, " ") +
Sundong Ahn04ef8a32019-01-14 11:36:50 +0900489 " --hide MissingPermission --hide BroadcastBehavior " +
490 "--hide HiddenSuperclass --hide DeprecationMismatch --hide UnavailableSymbol " +
491 "--hide SdkConstant --hide HiddenTypeParameter --hide Todo --hide Typo"
Sundong Ahnfb2721f2018-09-17 13:23:09 +0900492
Jiyong Parkdf130542018-04-27 16:29:21 +0900493 switch apiScope {
494 case apiScopeSystem:
Jiyong Parkc678ad32018-04-10 13:07:10 +0900495 droiddocArgs = droiddocArgs + " -showAnnotation android.annotation.SystemApi"
Jiyong Parkdf130542018-04-27 16:29:21 +0900496 case apiScopeTest:
497 droiddocArgs = droiddocArgs + " -showAnnotation android.annotation.TestApi"
Jiyong Parkc678ad32018-04-10 13:07:10 +0900498 }
Paul Duffin11512472019-02-11 15:55:17 +0000499 props.Arg_files = module.sdkLibraryProperties.Droiddoc_option_files
Jiyong Parkc678ad32018-04-10 13:07:10 +0900500 props.Args = proptools.StringPtr(droiddocArgs)
501
502 // List of APIs identified from the provided source files are created. They are later
503 // compared against to the not-yet-released (a.k.a current) list of APIs and to the
504 // last-released (a.k.a numbered) list of API.
Jiyong Parkc678ad32018-04-10 13:07:10 +0900505 currentApiFileName := "current.txt"
506 removedApiFileName := "removed.txt"
Jiyong Parkdf130542018-04-27 16:29:21 +0900507 switch apiScope {
508 case apiScopeSystem:
Jiyong Parkc678ad32018-04-10 13:07:10 +0900509 currentApiFileName = "system-" + currentApiFileName
510 removedApiFileName = "system-" + removedApiFileName
Jiyong Parkdf130542018-04-27 16:29:21 +0900511 case apiScopeTest:
512 currentApiFileName = "test-" + currentApiFileName
513 removedApiFileName = "test-" + removedApiFileName
Jiyong Parkc678ad32018-04-10 13:07:10 +0900514 }
515 currentApiFileName = path.Join("api", currentApiFileName)
516 removedApiFileName = path.Join("api", removedApiFileName)
Jiyong Park58c518b2018-05-12 22:29:12 +0900517 // TODO(jiyong): remove these three props
Jiyong Parkdf130542018-04-27 16:29:21 +0900518 props.Api_tag_name = proptools.StringPtr(module.apiTagName(apiScope))
Jiyong Parkc678ad32018-04-10 13:07:10 +0900519 props.Api_filename = proptools.StringPtr(currentApiFileName)
520 props.Removed_api_filename = proptools.StringPtr(removedApiFileName)
521
Jiyong Park58c518b2018-05-12 22:29:12 +0900522 // check against the not-yet-release API
523 props.Check_api.Current.Api_file = proptools.StringPtr(currentApiFileName)
524 props.Check_api.Current.Removed_api_file = proptools.StringPtr(removedApiFileName)
Jiyong Park58c518b2018-05-12 22:29:12 +0900525
526 // check against the latest released API
527 props.Check_api.Last_released.Api_file = proptools.StringPtr(
528 module.latestApiFilegroupName(apiScope))
529 props.Check_api.Last_released.Removed_api_file = proptools.StringPtr(
530 module.latestRemovedApiFilegroupName(apiScope))
Inseob Kim38449af2019-02-28 14:24:05 +0900531 props.Check_api.Ignore_missing_latest_api = proptools.BoolPtr(true)
Sundong Ahn054b19a2018-10-19 13:46:09 +0900532 props.Srcs_lib = module.sdkLibraryProperties.Srcs_lib
Sundong Ahn054b19a2018-10-19 13:46:09 +0900533 props.Srcs_lib_whitelist_pkgs = module.sdkLibraryProperties.Srcs_lib_whitelist_pkgs
Jiyong Park58c518b2018-05-12 22:29:12 +0900534
Sundong Ahn04ef8a32019-01-14 11:36:50 +0900535 mctx.CreateModule(android.ModuleFactoryAdaptor(DroidstubsFactory), &props)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900536}
537
Jiyong Parkc678ad32018-04-10 13:07:10 +0900538// Creates the xml file that publicizes the runtime library
Colin Crossf8b860a2019-04-16 14:43:28 -0700539func (module *SdkLibrary) createXmlFile(mctx android.LoadHookContext) {
Jiyong Parkc678ad32018-04-10 13:07:10 +0900540 template := `
541<?xml version="1.0" encoding="utf-8"?>
542<!-- Copyright (C) 2018 The Android Open Source Project
543
544 Licensed under the Apache License, Version 2.0 (the "License");
545 you may not use this file except in compliance with the License.
546 You may obtain a copy of the License at
Jiyong Park1112c4c2019-08-16 21:12:10 +0900547
Jiyong Parkc678ad32018-04-10 13:07:10 +0900548 http://www.apache.org/licenses/LICENSE-2.0
Jiyong Park1112c4c2019-08-16 21:12:10 +0900549
Jiyong Parkc678ad32018-04-10 13:07:10 +0900550 Unless required by applicable law or agreed to in writing, software
551 distributed under the License is distributed on an "AS IS" BASIS,
552 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
553 See the License for the specific language governing permissions and
554 limitations under the License.
555-->
556
557<permissions>
558 <library name="%s" file="%s"/>
559</permissions>
560`
561 // genrule to generate the xml file content from the template above
562 // TODO: preserve newlines in the generate xml file. Newlines are being squashed
563 // in the ninja file. Do we need to have an external tool for this?
564 xmlContent := fmt.Sprintf(template, module.BaseModuleName(), module.implPath())
565 genruleProps := struct {
566 Name *string
567 Cmd *string
568 Out []string
569 }{}
570 genruleProps.Name = proptools.StringPtr(module.xmlFileName() + "-gen")
571 genruleProps.Cmd = proptools.StringPtr("echo '" + xmlContent + "' > $(out)")
572 genruleProps.Out = []string{module.xmlFileName()}
573 mctx.CreateModule(android.ModuleFactoryAdaptor(genrule.GenRuleFactory), &genruleProps)
574
575 // creates a prebuilt_etc module to actually place the xml file under
576 // <partition>/etc/permissions
577 etcProps := struct {
578 Name *string
Jiyong Park5a8d1be2018-04-25 22:57:34 +0900579 Src *string
Jiyong Parkc678ad32018-04-10 13:07:10 +0900580 Sub_dir *string
581 Soc_specific *bool
582 Device_specific *bool
583 Product_specific *bool
584 }{}
585 etcProps.Name = proptools.StringPtr(module.xmlFileName())
Jiyong Park5a8d1be2018-04-25 22:57:34 +0900586 etcProps.Src = proptools.StringPtr(":" + module.xmlFileName() + "-gen")
Jiyong Parkc678ad32018-04-10 13:07:10 +0900587 etcProps.Sub_dir = proptools.StringPtr("permissions")
588 if module.SocSpecific() {
589 etcProps.Soc_specific = proptools.BoolPtr(true)
590 } else if module.DeviceSpecific() {
591 etcProps.Device_specific = proptools.BoolPtr(true)
592 } else if module.ProductSpecific() {
593 etcProps.Product_specific = proptools.BoolPtr(true)
594 }
595 mctx.CreateModule(android.ModuleFactoryAdaptor(android.PrebuiltEtcFactory), &etcProps)
596}
597
Colin Cross0ea8ba82019-06-06 14:33:29 -0700598func (module *SdkLibrary) PrebuiltJars(ctx android.BaseModuleContext, sdkVersion string) android.Paths {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900599 var api, v string
Paul Duffin52d398a2019-06-11 12:31:14 +0100600 if sdkVersion == "" || sdkVersion == "none" {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900601 api = "system"
602 v = "current"
603 } else if strings.Contains(sdkVersion, "_") {
604 t := strings.Split(sdkVersion, "_")
605 api = t[0]
606 v = t[1]
Jiyong Parkc678ad32018-04-10 13:07:10 +0900607 } else {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900608 api = "public"
609 v = sdkVersion
610 }
611 dir := filepath.Join("prebuilts", "sdk", v, api)
612 jar := filepath.Join(dir, module.BaseModuleName()+".jar")
613 jarPath := android.ExistentPathForSource(ctx, jar)
Sundong Ahnae418ac2019-02-28 15:01:28 +0900614 if !jarPath.Valid() {
615 ctx.PropertyErrorf("sdk_library", "invalid sdk version %q, %q does not exist", v, jar)
616 return nil
617 }
Sundong Ahn054b19a2018-10-19 13:46:09 +0900618 return android.Paths{jarPath.Path()}
619}
620
621// to satisfy SdkLibraryDependency interface
Colin Cross0ea8ba82019-06-06 14:33:29 -0700622func (module *SdkLibrary) SdkHeaderJars(ctx android.BaseModuleContext, sdkVersion string) android.Paths {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900623 // This module is just a wrapper for the stubs.
Colin Cross10932872019-04-18 14:27:12 -0700624 if ctx.Config().UnbundledBuildUsePrebuiltSdks() {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900625 return module.PrebuiltJars(ctx, sdkVersion)
626 } else {
627 if strings.HasPrefix(sdkVersion, "system_") {
628 return module.systemApiStubsPath
629 } else if sdkVersion == "" {
630 return module.Library.HeaderJars()
631 } else {
632 return module.publicApiStubsPath
633 }
Jiyong Parkc678ad32018-04-10 13:07:10 +0900634 }
635}
636
Sundong Ahn241cd372018-07-13 16:16:44 +0900637// to satisfy SdkLibraryDependency interface
Colin Cross0ea8ba82019-06-06 14:33:29 -0700638func (module *SdkLibrary) SdkImplementationJars(ctx android.BaseModuleContext, sdkVersion string) android.Paths {
Sundong Ahn241cd372018-07-13 16:16:44 +0900639 // This module is just a wrapper for the stubs.
Colin Cross10932872019-04-18 14:27:12 -0700640 if ctx.Config().UnbundledBuildUsePrebuiltSdks() {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900641 return module.PrebuiltJars(ctx, sdkVersion)
Sundong Ahn241cd372018-07-13 16:16:44 +0900642 } else {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900643 if strings.HasPrefix(sdkVersion, "system_") {
644 return module.systemApiStubsImplPath
645 } else if sdkVersion == "" {
646 return module.Library.ImplementationJars()
647 } else {
648 return module.publicApiStubsImplPath
649 }
Sundong Ahn241cd372018-07-13 16:16:44 +0900650 }
651}
652
Sundong Ahn80a87b32019-05-13 15:02:50 +0900653func (module *SdkLibrary) SetNoDist() {
654 module.sdkLibraryProperties.No_dist = proptools.BoolPtr(true)
655}
656
Colin Cross571cccf2019-02-04 11:22:08 -0800657var javaSdkLibrariesKey = android.NewOnceKey("javaSdkLibraries")
658
Jiyong Park82484c02018-04-23 21:41:26 +0900659func javaSdkLibraries(config android.Config) *[]string {
Colin Cross571cccf2019-02-04 11:22:08 -0800660 return config.Once(javaSdkLibrariesKey, func() interface{} {
Jiyong Park82484c02018-04-23 21:41:26 +0900661 return &[]string{}
662 }).(*[]string)
663}
664
Jiyong Parkc678ad32018-04-10 13:07:10 +0900665// For a java_sdk_library module, create internal modules for stubs, docs,
666// runtime libs and xml file. If requested, the stubs and docs are created twice
667// once for public API level and once for system API level
Colin Crossf8b860a2019-04-16 14:43:28 -0700668func (module *SdkLibrary) CreateInternalModules(mctx android.LoadHookContext) {
Inseob Kim6e93ac92019-03-21 17:43:49 +0900669 if len(module.Library.Module.properties.Srcs) == 0 {
Inseob Kimc0907f12019-02-08 21:00:45 +0900670 mctx.PropertyErrorf("srcs", "java_sdk_library must specify srcs")
671 }
672
Inseob Kim6e93ac92019-03-21 17:43:49 +0900673 if len(module.sdkLibraryProperties.Api_packages) == 0 {
Inseob Kimc0907f12019-02-08 21:00:45 +0900674 mctx.PropertyErrorf("api_packages", "java_sdk_library must specify api_packages")
675 }
Inseob Kim8098faa2019-03-18 10:19:51 +0900676
677 missing_current_api := false
678
679 for _, scope := range []string{"", "system-", "test-"} {
680 for _, api := range []string{"current.txt", "removed.txt"} {
681 path := path.Join(mctx.ModuleDir(), "api", scope+api)
682 p := android.ExistentPathForSource(mctx, path)
683 if !p.Valid() {
684 mctx.ModuleErrorf("Current api file %#v doesn't exist", path)
685 missing_current_api = true
686 }
687 }
688 }
689
690 if missing_current_api {
691 script := "build/soong/scripts/gen-java-current-api-files.sh"
692 p := android.ExistentPathForSource(mctx, script)
693
694 if !p.Valid() {
695 panic(fmt.Sprintf("script file %s doesn't exist", script))
696 }
697
698 mctx.ModuleErrorf("One or more current api files are missing. "+
699 "You can update them by:\n"+
700 "%s %q && m update-api", script, mctx.ModuleDir())
701 return
702 }
703
Inseob Kimc0907f12019-02-08 21:00:45 +0900704 // for public API stubs
705 module.createStubsLibrary(mctx, apiScopePublic)
706 module.createDocs(mctx, apiScopePublic)
707
Paul Duffin250e6192019-06-07 10:44:37 +0100708 sdkDep := decodeSdkDep(mctx, sdkContext(&module.Library))
709 if sdkDep.hasStandardLibs() {
Inseob Kimc0907f12019-02-08 21:00:45 +0900710 // for system API stubs
711 module.createStubsLibrary(mctx, apiScopeSystem)
712 module.createDocs(mctx, apiScopeSystem)
713
714 // for test API stubs
715 module.createStubsLibrary(mctx, apiScopeTest)
716 module.createDocs(mctx, apiScopeTest)
717
718 // for runtime
719 module.createXmlFile(mctx)
720 }
721
722 // record java_sdk_library modules so that they are exported to make
723 javaSdkLibraries := javaSdkLibraries(mctx.Config())
724 javaSdkLibrariesLock.Lock()
725 defer javaSdkLibrariesLock.Unlock()
726 *javaSdkLibraries = append(*javaSdkLibraries, module.BaseModuleName())
727}
728
729func (module *SdkLibrary) InitSdkLibraryProperties() {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900730 module.AddProperties(
731 &module.sdkLibraryProperties,
732 &module.Library.Module.properties,
733 &module.Library.Module.dexpreoptProperties,
734 &module.Library.Module.deviceProperties,
735 &module.Library.Module.protoProperties,
736 )
737
738 module.Library.Module.properties.Installable = proptools.BoolPtr(true)
739 module.Library.Module.deviceProperties.IsSDKLibrary = true
Inseob Kimc0907f12019-02-08 21:00:45 +0900740}
Sundong Ahn054b19a2018-10-19 13:46:09 +0900741
Jaewoong Jung4f158ee2019-07-11 10:05:35 -0700742// java_sdk_library is a special Java library that provides optional platform APIs to apps.
743// In practice, it can be viewed as a combination of several modules: 1) stubs library that clients
744// are linked against to, 2) droiddoc module that internally generates API stubs source files,
745// 3) the real runtime shared library that implements the APIs, and 4) XML file for adding
746// the runtime lib to the classpath at runtime if requested via <uses-library>.
Inseob Kimc0907f12019-02-08 21:00:45 +0900747func SdkLibraryFactory() android.Module {
748 module := &SdkLibrary{}
749 module.InitSdkLibraryProperties()
Sundong Ahn054b19a2018-10-19 13:46:09 +0900750 InitJavaModule(module, android.HostAndDeviceSupported)
Colin Crossf8b860a2019-04-16 14:43:28 -0700751 android.AddLoadHook(module, func(ctx android.LoadHookContext) { module.CreateInternalModules(ctx) })
Jiyong Parkc678ad32018-04-10 13:07:10 +0900752 return module
753}
Colin Cross79c7c262019-04-17 11:11:46 -0700754
755//
756// SDK library prebuilts
757//
758
759type sdkLibraryImportProperties struct {
760 Jars []string `android:"path"`
761
762 Sdk_version *string
763
764 Installable *bool
765
766 // List of shared java libs that this module has dependencies to
767 Libs []string
768
769 // List of files to remove from the jar file(s)
770 Exclude_files []string
771
772 // List of directories to remove from the jar file(s)
773 Exclude_dirs []string
774}
775
776type sdkLibraryImport struct {
777 android.ModuleBase
778 android.DefaultableModuleBase
779 prebuilt android.Prebuilt
780
781 properties sdkLibraryImportProperties
782
783 stubsPath android.Paths
784}
785
786var _ SdkLibraryDependency = (*sdkLibraryImport)(nil)
787
Jaewoong Jung4f158ee2019-07-11 10:05:35 -0700788// java_sdk_library_import imports a prebuilt java_sdk_library.
Colin Cross79c7c262019-04-17 11:11:46 -0700789func sdkLibraryImportFactory() android.Module {
790 module := &sdkLibraryImport{}
791
792 module.AddProperties(&module.properties)
793
794 android.InitPrebuiltModule(module, &module.properties.Jars)
795 InitJavaModule(module, android.HostAndDeviceSupported)
796
797 android.AddLoadHook(module, func(mctx android.LoadHookContext) { module.createInternalModules(mctx) })
798 return module
799}
800
801func (module *sdkLibraryImport) Prebuilt() *android.Prebuilt {
802 return &module.prebuilt
803}
804
805func (module *sdkLibraryImport) Name() string {
806 return module.prebuilt.Name(module.ModuleBase.Name())
807}
808
809func (module *sdkLibraryImport) createInternalModules(mctx android.LoadHookContext) {
810 // Creates a java import for the jar with ".stubs" suffix
811 props := struct {
812 Name *string
813 Soc_specific *bool
814 Device_specific *bool
815 Product_specific *bool
816 }{}
817
818 props.Name = proptools.StringPtr(module.BaseModuleName() + sdkStubsLibrarySuffix)
819
820 if module.SocSpecific() {
821 props.Soc_specific = proptools.BoolPtr(true)
822 } else if module.DeviceSpecific() {
823 props.Device_specific = proptools.BoolPtr(true)
824 } else if module.ProductSpecific() {
825 props.Product_specific = proptools.BoolPtr(true)
826 }
827
828 mctx.CreateModule(android.ModuleFactoryAdaptor(ImportFactory), &props, &module.properties)
829
830 javaSdkLibraries := javaSdkLibraries(mctx.Config())
831 javaSdkLibrariesLock.Lock()
832 defer javaSdkLibrariesLock.Unlock()
833 *javaSdkLibraries = append(*javaSdkLibraries, module.BaseModuleName())
834}
835
836func (module *sdkLibraryImport) DepsMutator(ctx android.BottomUpMutatorContext) {
837 // Add dependencies to the prebuilt stubs library
838 ctx.AddVariationDependencies(nil, publicApiStubsTag, module.BaseModuleName()+sdkStubsLibrarySuffix)
839}
840
841func (module *sdkLibraryImport) GenerateAndroidBuildActions(ctx android.ModuleContext) {
842 // Record the paths to the prebuilt stubs library.
843 ctx.VisitDirectDeps(func(to android.Module) {
844 tag := ctx.OtherModuleDependencyTag(to)
845
846 switch tag {
847 case publicApiStubsTag:
848 module.stubsPath = to.(Dependency).HeaderJars()
849 }
850 })
851}
852
853// to satisfy SdkLibraryDependency interface
Colin Cross0ea8ba82019-06-06 14:33:29 -0700854func (module *sdkLibraryImport) SdkHeaderJars(ctx android.BaseModuleContext, sdkVersion string) android.Paths {
Colin Cross79c7c262019-04-17 11:11:46 -0700855 // This module is just a wrapper for the prebuilt stubs.
856 return module.stubsPath
857}
858
859// to satisfy SdkLibraryDependency interface
Colin Cross0ea8ba82019-06-06 14:33:29 -0700860func (module *sdkLibraryImport) SdkImplementationJars(ctx android.BaseModuleContext, sdkVersion string) android.Paths {
Colin Cross79c7c262019-04-17 11:11:46 -0700861 // This module is just a wrapper for the stubs.
862 return module.stubsPath
863}