blob: a7956fad6b7ae4ebef3f5e705123859ce022172b [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 {
Sundong Ahnf043cf62018-06-25 16:04:37 +090082 // List of Java libraries that will be in the classpath when building stubs
83 Stub_only_libs []string `android:"arch_variant"`
84
Jiyong Parkc678ad32018-04-10 13:07:10 +090085 // list of package names that will be documented and publicized as API
86 Api_packages []string
87
Jiyong Park5a2c9d72018-05-01 22:25:41 +090088 // list of package names that must be hidden from the API
89 Hidden_api_packages []string
90
Paul Duffin11512472019-02-11 15:55:17 +000091 // local files that are used within user customized droiddoc options.
92 Droiddoc_option_files []string
93
94 // additional droiddoc options
95 // Available variables for substitution:
96 //
97 // $(location <label>): the path to the droiddoc_option_files with name <label>
Sundong Ahndd567f92018-07-31 17:19:11 +090098 Droiddoc_options []string
99
Sundong Ahn054b19a2018-10-19 13:46:09 +0900100 // a list of top-level directories containing files to merge qualifier annotations
101 // (i.e. those intended to be included in the stubs written) from.
102 Merge_annotations_dirs []string
103
104 // a list of top-level directories containing Java stub files to merge show/hide annotations from.
105 Merge_inclusion_annotations_dirs []string
106
107 // If set to true, the path of dist files is apistubs/core. Defaults to false.
108 Core_lib *bool
109
Sundong Ahn80a87b32019-05-13 15:02:50 +0900110 // don't create dist rules.
111 No_dist *bool `blueprint:"mutated"`
112
Jiyong Parkc678ad32018-04-10 13:07:10 +0900113 // TODO: determines whether to create HTML doc or not
114 //Html_doc *bool
115}
116
Inseob Kimc0907f12019-02-08 21:00:45 +0900117type SdkLibrary struct {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900118 Library
Jiyong Parkc678ad32018-04-10 13:07:10 +0900119
Sundong Ahn054b19a2018-10-19 13:46:09 +0900120 sdkLibraryProperties sdkLibraryProperties
Jiyong Parkc678ad32018-04-10 13:07:10 +0900121
122 publicApiStubsPath android.Paths
123 systemApiStubsPath android.Paths
Jiyong Parkdf130542018-04-27 16:29:21 +0900124 testApiStubsPath android.Paths
Sundong Ahn241cd372018-07-13 16:16:44 +0900125
126 publicApiStubsImplPath android.Paths
127 systemApiStubsImplPath android.Paths
128 testApiStubsImplPath android.Paths
Sundong Ahn20e998b2018-07-24 11:19:26 +0900129
130 publicApiFilePath android.Path
131 systemApiFilePath android.Path
132 testApiFilePath android.Path
Jiyong Parkc678ad32018-04-10 13:07:10 +0900133}
134
Inseob Kimc0907f12019-02-08 21:00:45 +0900135var _ Dependency = (*SdkLibrary)(nil)
136var _ SdkLibraryDependency = (*SdkLibrary)(nil)
Colin Cross897d2ed2019-02-11 14:03:51 -0800137
Inseob Kimc0907f12019-02-08 21:00:45 +0900138func (module *SdkLibrary) DepsMutator(ctx android.BottomUpMutatorContext) {
Jiyong Parke3ef3c82019-07-15 15:31:16 +0900139 useBuiltStubs := !ctx.Config().UnbundledBuildUsePrebuiltSdks()
Jiyong Parkc678ad32018-04-10 13:07:10 +0900140 // Add dependencies to the stubs library
Jiyong Parke3ef3c82019-07-15 15:31:16 +0900141 if useBuiltStubs {
142 ctx.AddVariationDependencies(nil, publicApiStubsTag, module.stubsName(apiScopePublic))
143 }
Colin Cross42d48b72018-08-29 14:10:52 -0700144 ctx.AddVariationDependencies(nil, publicApiFileTag, module.docsName(apiScopePublic))
Sundong Ahn054b19a2018-10-19 13:46:09 +0900145
Paul Duffin250e6192019-06-07 10:44:37 +0100146 sdkDep := decodeSdkDep(ctx, sdkContext(&module.Library))
147 if sdkDep.hasStandardLibs() {
Jiyong Parke3ef3c82019-07-15 15:31:16 +0900148 if useBuiltStubs {
149 ctx.AddVariationDependencies(nil, systemApiStubsTag, module.stubsName(apiScopeSystem))
150 ctx.AddVariationDependencies(nil, testApiStubsTag, module.stubsName(apiScopeTest))
151 }
Sundong Ahn054b19a2018-10-19 13:46:09 +0900152 ctx.AddVariationDependencies(nil, systemApiFileTag, module.docsName(apiScopeSystem))
153 ctx.AddVariationDependencies(nil, testApiFileTag, module.docsName(apiScopeTest))
Sundong Ahn054b19a2018-10-19 13:46:09 +0900154 }
155
156 module.Library.deps(ctx)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900157}
158
Inseob Kimc0907f12019-02-08 21:00:45 +0900159func (module *SdkLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900160 module.Library.GenerateAndroidBuildActions(ctx)
161
Sundong Ahn57368eb2018-07-06 11:20:23 +0900162 // Record the paths to the header jars of the library (stubs and impl).
Jiyong Parkc678ad32018-04-10 13:07:10 +0900163 // When this java_sdk_library is dependened from others via "libs" property,
164 // the recorded paths will be returned depending on the link type of the caller.
165 ctx.VisitDirectDeps(func(to android.Module) {
166 otherName := ctx.OtherModuleName(to)
167 tag := ctx.OtherModuleDependencyTag(to)
168
Sundong Ahn57368eb2018-07-06 11:20:23 +0900169 if lib, ok := to.(Dependency); ok {
Jiyong Parkc678ad32018-04-10 13:07:10 +0900170 switch tag {
171 case publicApiStubsTag:
Sundong Ahn57368eb2018-07-06 11:20:23 +0900172 module.publicApiStubsPath = lib.HeaderJars()
Sundong Ahn241cd372018-07-13 16:16:44 +0900173 module.publicApiStubsImplPath = lib.ImplementationJars()
Jiyong Parkc678ad32018-04-10 13:07:10 +0900174 case systemApiStubsTag:
Sundong Ahn57368eb2018-07-06 11:20:23 +0900175 module.systemApiStubsPath = lib.HeaderJars()
Sundong Ahn241cd372018-07-13 16:16:44 +0900176 module.systemApiStubsImplPath = lib.ImplementationJars()
Jiyong Parkdf130542018-04-27 16:29:21 +0900177 case testApiStubsTag:
Sundong Ahn57368eb2018-07-06 11:20:23 +0900178 module.testApiStubsPath = lib.HeaderJars()
Sundong Ahn241cd372018-07-13 16:16:44 +0900179 module.testApiStubsImplPath = lib.ImplementationJars()
Jiyong Parkc678ad32018-04-10 13:07:10 +0900180 }
181 }
Sundong Ahn20e998b2018-07-24 11:19:26 +0900182 if doc, ok := to.(ApiFilePath); ok {
183 switch tag {
184 case publicApiFileTag:
185 module.publicApiFilePath = doc.ApiFilePath()
186 case systemApiFileTag:
187 module.systemApiFilePath = doc.ApiFilePath()
188 case testApiFileTag:
189 module.testApiFilePath = doc.ApiFilePath()
190 default:
191 ctx.ModuleErrorf("depends on module %q of unknown tag %q", otherName, tag)
192 }
193 }
Jiyong Parkc678ad32018-04-10 13:07:10 +0900194 })
195}
196
Jaewoong Jungb0c127c2019-08-29 14:56:03 -0700197func (module *SdkLibrary) AndroidMkEntries() android.AndroidMkEntries {
198 entries := module.Library.AndroidMkEntries()
199 entries.Required = append(entries.Required, module.xmlFileName())
Sundong Ahn054b19a2018-10-19 13:46:09 +0900200
Jaewoong Jungb0c127c2019-08-29 14:56:03 -0700201 entries.ExtraFooters = []android.AndroidMkExtraFootersFunc{
202 func(w io.Writer, name, prefix, moduleDir string, entries *android.AndroidMkEntries) {
203 module.Library.AndroidMkHostDex(w, name, entries)
204 if !Bool(module.sdkLibraryProperties.No_dist) {
205 // Create a phony module that installs the impl library, for the case when this lib is
206 // in PRODUCT_PACKAGES.
207 owner := module.ModuleBase.Owner()
208 if owner == "" {
209 if Bool(module.sdkLibraryProperties.Core_lib) {
210 owner = "core"
211 } else {
212 owner = "android"
213 }
214 }
215 // Create dist rules to install the stubs libs to the dist dir
216 if len(module.publicApiStubsPath) == 1 {
217 fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+
218 module.publicApiStubsImplPath.Strings()[0]+
219 ":"+path.Join("apistubs", owner, "public",
220 module.BaseModuleName()+".jar")+")")
221 }
222 if len(module.systemApiStubsPath) == 1 {
223 fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+
224 module.systemApiStubsImplPath.Strings()[0]+
225 ":"+path.Join("apistubs", owner, "system",
226 module.BaseModuleName()+".jar")+")")
227 }
228 if len(module.testApiStubsPath) == 1 {
229 fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+
230 module.testApiStubsImplPath.Strings()[0]+
231 ":"+path.Join("apistubs", owner, "test",
232 module.BaseModuleName()+".jar")+")")
233 }
234 if module.publicApiFilePath != nil {
235 fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+
236 module.publicApiFilePath.String()+
237 ":"+path.Join("apistubs", owner, "public", "api",
238 module.BaseModuleName()+".txt")+")")
239 }
240 if module.systemApiFilePath != nil {
241 fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+
242 module.systemApiFilePath.String()+
243 ":"+path.Join("apistubs", owner, "system", "api",
244 module.BaseModuleName()+".txt")+")")
245 }
246 if module.testApiFilePath != nil {
247 fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+
248 module.testApiFilePath.String()+
249 ":"+path.Join("apistubs", owner, "test", "api",
250 module.BaseModuleName()+".txt")+")")
Sundong Ahn80a87b32019-05-13 15:02:50 +0900251 }
Sundong Ahn4fd04bb2018-08-31 18:01:37 +0900252 }
Jaewoong Jungb0c127c2019-08-29 14:56:03 -0700253 },
Jiyong Park82484c02018-04-23 21:41:26 +0900254 }
Jaewoong Jungb0c127c2019-08-29 14:56:03 -0700255 return entries
Jiyong Park82484c02018-04-23 21:41:26 +0900256}
257
Jiyong Parkc678ad32018-04-10 13:07:10 +0900258// Module name of the stubs library
Inseob Kimc0907f12019-02-08 21:00:45 +0900259func (module *SdkLibrary) stubsName(apiScope apiScope) string {
Jiyong Parkc678ad32018-04-10 13:07:10 +0900260 stubsName := module.BaseModuleName() + sdkStubsLibrarySuffix
Jiyong Parkdf130542018-04-27 16:29:21 +0900261 switch apiScope {
262 case apiScopeSystem:
Jiyong Parkc678ad32018-04-10 13:07:10 +0900263 stubsName = stubsName + sdkSystemApiSuffix
Jiyong Parkdf130542018-04-27 16:29:21 +0900264 case apiScopeTest:
265 stubsName = stubsName + sdkTestApiSuffix
Jiyong Parkc678ad32018-04-10 13:07:10 +0900266 }
267 return stubsName
268}
269
270// Module name of the docs
Inseob Kimc0907f12019-02-08 21:00:45 +0900271func (module *SdkLibrary) docsName(apiScope apiScope) string {
Jiyong Parkc678ad32018-04-10 13:07:10 +0900272 docsName := module.BaseModuleName() + sdkDocsSuffix
Jiyong Parkdf130542018-04-27 16:29:21 +0900273 switch apiScope {
274 case apiScopeSystem:
Jiyong Parkc678ad32018-04-10 13:07:10 +0900275 docsName = docsName + sdkSystemApiSuffix
Jiyong Parkdf130542018-04-27 16:29:21 +0900276 case apiScopeTest:
277 docsName = docsName + sdkTestApiSuffix
Jiyong Parkc678ad32018-04-10 13:07:10 +0900278 }
279 return docsName
280}
281
282// Module name of the runtime implementation library
Inseob Kimc0907f12019-02-08 21:00:45 +0900283func (module *SdkLibrary) implName() string {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900284 return module.BaseModuleName()
Jiyong Parkc678ad32018-04-10 13:07:10 +0900285}
286
287// File path to the runtime implementation library
Inseob Kimc0907f12019-02-08 21:00:45 +0900288func (module *SdkLibrary) implPath() string {
Jiyong Parkc678ad32018-04-10 13:07:10 +0900289 partition := "system"
290 if module.SocSpecific() {
291 partition = "vendor"
292 } else if module.DeviceSpecific() {
293 partition = "odm"
294 } else if module.ProductSpecific() {
295 partition = "product"
Sundong Ahn0d7dff42019-12-04 12:53:44 +0900296 } else if module.SystemExtSpecific() {
297 partition = "system_ext"
Jiyong Parkc678ad32018-04-10 13:07:10 +0900298 }
299 return "/" + partition + "/framework/" + module.implName() + ".jar"
300}
301
302// Module name of the XML file for the lib
Inseob Kimc0907f12019-02-08 21:00:45 +0900303func (module *SdkLibrary) xmlFileName() string {
Jiyong Parkc678ad32018-04-10 13:07:10 +0900304 return module.BaseModuleName() + sdkXmlFileSuffix
305}
306
307// SDK version that the stubs library is built against. Note that this is always
308// *current. Older stubs library built with a numberd SDK version is created from
309// the prebuilt jar.
Inseob Kimc0907f12019-02-08 21:00:45 +0900310func (module *SdkLibrary) sdkVersion(apiScope apiScope) string {
Jiyong Parkdf130542018-04-27 16:29:21 +0900311 switch apiScope {
312 case apiScopePublic:
313 return "current"
314 case apiScopeSystem:
Jiyong Parkc678ad32018-04-10 13:07:10 +0900315 return "system_current"
Jiyong Parkdf130542018-04-27 16:29:21 +0900316 case apiScopeTest:
317 return "test_current"
318 default:
Jiyong Parkc678ad32018-04-10 13:07:10 +0900319 return "current"
320 }
321}
322
323// $(INTERNAL_PLATFORM_<apiTagName>_API_FILE) points to the generated
324// api file for the current source
325// TODO: remove this when apicheck is done in soong
Inseob Kimc0907f12019-02-08 21:00:45 +0900326func (module *SdkLibrary) apiTagName(apiScope apiScope) string {
Jiyong Parkc678ad32018-04-10 13:07:10 +0900327 apiTagName := strings.Replace(strings.ToUpper(module.BaseModuleName()), ".", "_", -1)
Jiyong Parkdf130542018-04-27 16:29:21 +0900328 switch apiScope {
329 case apiScopeSystem:
Jiyong Parkc678ad32018-04-10 13:07:10 +0900330 apiTagName = apiTagName + "_SYSTEM"
Jiyong Parkdf130542018-04-27 16:29:21 +0900331 case apiScopeTest:
332 apiTagName = apiTagName + "_TEST"
Jiyong Parkc678ad32018-04-10 13:07:10 +0900333 }
334 return apiTagName
335}
336
Inseob Kimc0907f12019-02-08 21:00:45 +0900337func (module *SdkLibrary) latestApiFilegroupName(apiScope apiScope) string {
Jiyong Park58c518b2018-05-12 22:29:12 +0900338 name := ":" + module.BaseModuleName() + ".api."
Jiyong Parkdf130542018-04-27 16:29:21 +0900339 switch apiScope {
Jiyong Park58c518b2018-05-12 22:29:12 +0900340 case apiScopePublic:
341 name = name + "public"
Jiyong Parkdf130542018-04-27 16:29:21 +0900342 case apiScopeSystem:
Jiyong Park58c518b2018-05-12 22:29:12 +0900343 name = name + "system"
Jiyong Parkdf130542018-04-27 16:29:21 +0900344 case apiScopeTest:
Jiyong Park58c518b2018-05-12 22:29:12 +0900345 name = name + "test"
Jiyong Parkc678ad32018-04-10 13:07:10 +0900346 }
Jiyong Park58c518b2018-05-12 22:29:12 +0900347 name = name + ".latest"
348 return name
349}
Jiyong Parkc678ad32018-04-10 13:07:10 +0900350
Inseob Kimc0907f12019-02-08 21:00:45 +0900351func (module *SdkLibrary) latestRemovedApiFilegroupName(apiScope apiScope) string {
Jiyong Park58c518b2018-05-12 22:29:12 +0900352 name := ":" + module.BaseModuleName() + "-removed.api."
353 switch apiScope {
354 case apiScopePublic:
355 name = name + "public"
356 case apiScopeSystem:
357 name = name + "system"
358 case apiScopeTest:
359 name = name + "test"
360 }
361 name = name + ".latest"
362 return name
Jiyong Parkc678ad32018-04-10 13:07:10 +0900363}
364
365// Creates a static java library that has API stubs
Colin Crossf8b860a2019-04-16 14:43:28 -0700366func (module *SdkLibrary) createStubsLibrary(mctx android.LoadHookContext, apiScope apiScope) {
Jiyong Parkc678ad32018-04-10 13:07:10 +0900367 props := struct {
Sundong Ahn0d7dff42019-12-04 12:53:44 +0900368 Name *string
369 Srcs []string
370 Sdk_version *string
371 Libs []string
372 Soc_specific *bool
373 Device_specific *bool
374 Product_specific *bool
375 System_ext_specific *bool
376 Compile_dex *bool
377 System_modules *string
378 Java_version *string
379 Product_variables struct {
Jiyong Parkc678ad32018-04-10 13:07:10 +0900380 Unbundled_build struct {
381 Enabled *bool
382 }
Jiyong Park82484c02018-04-23 21:41:26 +0900383 Pdk struct {
384 Enabled *bool
385 }
Jiyong Parkc678ad32018-04-10 13:07:10 +0900386 }
Sundong Ahn054b19a2018-10-19 13:46:09 +0900387 Openjdk9 struct {
388 Srcs []string
389 Javacflags []string
390 }
Jiyong Parkc678ad32018-04-10 13:07:10 +0900391 }{}
392
Paul Duffin52d398a2019-06-11 12:31:14 +0100393 sdkVersion := module.sdkVersion(apiScope)
Paul Duffin250e6192019-06-07 10:44:37 +0100394 sdkDep := decodeSdkDep(mctx, sdkContext(&module.Library))
Paul Duffin52d398a2019-06-11 12:31:14 +0100395 if !sdkDep.hasStandardLibs() {
396 sdkVersion = "none"
397 }
Paul Duffin250e6192019-06-07 10:44:37 +0100398
Jiyong Parkdf130542018-04-27 16:29:21 +0900399 props.Name = proptools.StringPtr(module.stubsName(apiScope))
Jiyong Parkc678ad32018-04-10 13:07:10 +0900400 // sources are generated from the droiddoc
Jiyong Parkdf130542018-04-27 16:29:21 +0900401 props.Srcs = []string{":" + module.docsName(apiScope)}
Paul Duffin52d398a2019-06-11 12:31:14 +0100402 props.Sdk_version = proptools.StringPtr(sdkVersion)
Sundong Ahn054b19a2018-10-19 13:46:09 +0900403 props.Libs = module.sdkLibraryProperties.Stub_only_libs
Jiyong Parkc678ad32018-04-10 13:07:10 +0900404 // Unbundled apps will use the prebult one from /prebuilts/sdk
Colin Cross10932872019-04-18 14:27:12 -0700405 if mctx.Config().UnbundledBuildUsePrebuiltSdks() {
Colin Cross2c77ceb2019-01-21 11:56:21 -0800406 props.Product_variables.Unbundled_build.Enabled = proptools.BoolPtr(false)
407 }
Jiyong Park82484c02018-04-23 21:41:26 +0900408 props.Product_variables.Pdk.Enabled = proptools.BoolPtr(false)
Sundong Ahn054b19a2018-10-19 13:46:09 +0900409 props.System_modules = module.Library.Module.deviceProperties.System_modules
410 props.Openjdk9.Srcs = module.Library.Module.properties.Openjdk9.Srcs
411 props.Openjdk9.Javacflags = module.Library.Module.properties.Openjdk9.Javacflags
412 props.Java_version = module.Library.Module.properties.Java_version
413 if module.Library.Module.deviceProperties.Compile_dex != nil {
414 props.Compile_dex = module.Library.Module.deviceProperties.Compile_dex
Sundong Ahndd567f92018-07-31 17:19:11 +0900415 }
Jiyong Parkc678ad32018-04-10 13:07:10 +0900416
417 if module.SocSpecific() {
418 props.Soc_specific = proptools.BoolPtr(true)
419 } else if module.DeviceSpecific() {
420 props.Device_specific = proptools.BoolPtr(true)
421 } else if module.ProductSpecific() {
422 props.Product_specific = proptools.BoolPtr(true)
Sundong Ahn0d7dff42019-12-04 12:53:44 +0900423 } else if module.SystemExtSpecific() {
424 props.System_ext_specific = proptools.BoolPtr(true)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900425 }
426
Colin Cross84dfc3d2019-09-25 11:33:01 -0700427 mctx.CreateModule(LibraryFactory, &props)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900428}
429
430// Creates a droiddoc module that creates stubs source files from the given full source
431// files
Colin Crossf8b860a2019-04-16 14:43:28 -0700432func (module *SdkLibrary) createDocs(mctx android.LoadHookContext, apiScope apiScope) {
Jiyong Parkc678ad32018-04-10 13:07:10 +0900433 props := struct {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900434 Name *string
435 Srcs []string
436 Installable *bool
Paul Duffin52d398a2019-06-11 12:31:14 +0100437 Sdk_version *string
Sundong Ahn054b19a2018-10-19 13:46:09 +0900438 Libs []string
Paul Duffin11512472019-02-11 15:55:17 +0000439 Arg_files []string
Sundong Ahn054b19a2018-10-19 13:46:09 +0900440 Args *string
441 Api_tag_name *string
442 Api_filename *string
443 Removed_api_filename *string
Sundong Ahn054b19a2018-10-19 13:46:09 +0900444 Java_version *string
445 Merge_annotations_dirs []string
446 Merge_inclusion_annotations_dirs []string
447 Check_api struct {
Inseob Kim38449af2019-02-28 14:24:05 +0900448 Current ApiToCheck
449 Last_released ApiToCheck
450 Ignore_missing_latest_api *bool
Jiyong Park58c518b2018-05-12 22:29:12 +0900451 }
Sundong Ahn1b92c822018-05-29 11:35:17 +0900452 Aidl struct {
453 Include_dirs []string
454 Local_include_dirs []string
455 }
Jiyong Parkc678ad32018-04-10 13:07:10 +0900456 }{}
457
Paul Duffin250e6192019-06-07 10:44:37 +0100458 sdkDep := decodeSdkDep(mctx, sdkContext(&module.Library))
Paul Duffin52d398a2019-06-11 12:31:14 +0100459 sdkVersion := ""
460 if !sdkDep.hasStandardLibs() {
461 sdkVersion = "none"
462 }
Paul Duffin250e6192019-06-07 10:44:37 +0100463
Jiyong Parkdf130542018-04-27 16:29:21 +0900464 props.Name = proptools.StringPtr(module.docsName(apiScope))
Sundong Ahn054b19a2018-10-19 13:46:09 +0900465 props.Srcs = append(props.Srcs, module.Library.Module.properties.Srcs...)
Paul Duffin52d398a2019-06-11 12:31:14 +0100466 props.Sdk_version = proptools.StringPtr(sdkVersion)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900467 props.Installable = proptools.BoolPtr(false)
Sundong Ahne6f0b052018-06-05 16:46:14 +0900468 // A droiddoc module has only one Libs property and doesn't distinguish between
469 // shared libs and static libs. So we need to add both of these libs to Libs property.
Sundong Ahn054b19a2018-10-19 13:46:09 +0900470 props.Libs = module.Library.Module.properties.Libs
471 props.Libs = append(props.Libs, module.Library.Module.properties.Static_libs...)
472 props.Aidl.Include_dirs = module.Library.Module.deviceProperties.Aidl.Include_dirs
473 props.Aidl.Local_include_dirs = module.Library.Module.deviceProperties.Aidl.Local_include_dirs
Sundong Ahn054b19a2018-10-19 13:46:09 +0900474 props.Java_version = module.Library.Module.properties.Java_version
Jiyong Parkc678ad32018-04-10 13:07:10 +0900475
Sundong Ahn054b19a2018-10-19 13:46:09 +0900476 props.Merge_annotations_dirs = module.sdkLibraryProperties.Merge_annotations_dirs
477 props.Merge_inclusion_annotations_dirs = module.sdkLibraryProperties.Merge_inclusion_annotations_dirs
478
479 droiddocArgs := " --stub-packages " + strings.Join(module.sdkLibraryProperties.Api_packages, ":") +
480 " " + android.JoinWithPrefix(module.sdkLibraryProperties.Hidden_api_packages, " --hide-package ") +
481 " " + android.JoinWithPrefix(module.sdkLibraryProperties.Droiddoc_options, " ") +
Sundong Ahn04ef8a32019-01-14 11:36:50 +0900482 " --hide MissingPermission --hide BroadcastBehavior " +
483 "--hide HiddenSuperclass --hide DeprecationMismatch --hide UnavailableSymbol " +
484 "--hide SdkConstant --hide HiddenTypeParameter --hide Todo --hide Typo"
Sundong Ahnfb2721f2018-09-17 13:23:09 +0900485
Jiyong Parkdf130542018-04-27 16:29:21 +0900486 switch apiScope {
487 case apiScopeSystem:
Jiyong Parkc678ad32018-04-10 13:07:10 +0900488 droiddocArgs = droiddocArgs + " -showAnnotation android.annotation.SystemApi"
Jiyong Parkdf130542018-04-27 16:29:21 +0900489 case apiScopeTest:
490 droiddocArgs = droiddocArgs + " -showAnnotation android.annotation.TestApi"
Jiyong Parkc678ad32018-04-10 13:07:10 +0900491 }
Paul Duffin11512472019-02-11 15:55:17 +0000492 props.Arg_files = module.sdkLibraryProperties.Droiddoc_option_files
Jiyong Parkc678ad32018-04-10 13:07:10 +0900493 props.Args = proptools.StringPtr(droiddocArgs)
494
495 // List of APIs identified from the provided source files are created. They are later
496 // compared against to the not-yet-released (a.k.a current) list of APIs and to the
497 // last-released (a.k.a numbered) list of API.
Jiyong Parkc678ad32018-04-10 13:07:10 +0900498 currentApiFileName := "current.txt"
499 removedApiFileName := "removed.txt"
Jiyong Parkdf130542018-04-27 16:29:21 +0900500 switch apiScope {
501 case apiScopeSystem:
Jiyong Parkc678ad32018-04-10 13:07:10 +0900502 currentApiFileName = "system-" + currentApiFileName
503 removedApiFileName = "system-" + removedApiFileName
Jiyong Parkdf130542018-04-27 16:29:21 +0900504 case apiScopeTest:
505 currentApiFileName = "test-" + currentApiFileName
506 removedApiFileName = "test-" + removedApiFileName
Jiyong Parkc678ad32018-04-10 13:07:10 +0900507 }
508 currentApiFileName = path.Join("api", currentApiFileName)
509 removedApiFileName = path.Join("api", removedApiFileName)
Jiyong Park58c518b2018-05-12 22:29:12 +0900510 // TODO(jiyong): remove these three props
Jiyong Parkdf130542018-04-27 16:29:21 +0900511 props.Api_tag_name = proptools.StringPtr(module.apiTagName(apiScope))
Jiyong Parkc678ad32018-04-10 13:07:10 +0900512 props.Api_filename = proptools.StringPtr(currentApiFileName)
513 props.Removed_api_filename = proptools.StringPtr(removedApiFileName)
514
Jiyong Park58c518b2018-05-12 22:29:12 +0900515 // check against the not-yet-release API
516 props.Check_api.Current.Api_file = proptools.StringPtr(currentApiFileName)
517 props.Check_api.Current.Removed_api_file = proptools.StringPtr(removedApiFileName)
Jiyong Park58c518b2018-05-12 22:29:12 +0900518
519 // check against the latest released API
520 props.Check_api.Last_released.Api_file = proptools.StringPtr(
521 module.latestApiFilegroupName(apiScope))
522 props.Check_api.Last_released.Removed_api_file = proptools.StringPtr(
523 module.latestRemovedApiFilegroupName(apiScope))
Inseob Kim38449af2019-02-28 14:24:05 +0900524 props.Check_api.Ignore_missing_latest_api = proptools.BoolPtr(true)
Jiyong Park58c518b2018-05-12 22:29:12 +0900525
Colin Cross84dfc3d2019-09-25 11:33:01 -0700526 mctx.CreateModule(DroidstubsFactory, &props)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900527}
528
Jiyong Parkc678ad32018-04-10 13:07:10 +0900529// Creates the xml file that publicizes the runtime library
Colin Crossf8b860a2019-04-16 14:43:28 -0700530func (module *SdkLibrary) createXmlFile(mctx android.LoadHookContext) {
Jiyong Parkc678ad32018-04-10 13:07:10 +0900531 template := `
532<?xml version="1.0" encoding="utf-8"?>
533<!-- Copyright (C) 2018 The Android Open Source Project
534
535 Licensed under the Apache License, Version 2.0 (the "License");
536 you may not use this file except in compliance with the License.
537 You may obtain a copy of the License at
Jiyong Park1112c4c2019-08-16 21:12:10 +0900538
Jiyong Parkc678ad32018-04-10 13:07:10 +0900539 http://www.apache.org/licenses/LICENSE-2.0
Jiyong Park1112c4c2019-08-16 21:12:10 +0900540
Jiyong Parkc678ad32018-04-10 13:07:10 +0900541 Unless required by applicable law or agreed to in writing, software
542 distributed under the License is distributed on an "AS IS" BASIS,
543 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
544 See the License for the specific language governing permissions and
545 limitations under the License.
546-->
547
548<permissions>
549 <library name="%s" file="%s"/>
550</permissions>
551`
552 // genrule to generate the xml file content from the template above
553 // TODO: preserve newlines in the generate xml file. Newlines are being squashed
554 // in the ninja file. Do we need to have an external tool for this?
555 xmlContent := fmt.Sprintf(template, module.BaseModuleName(), module.implPath())
556 genruleProps := struct {
557 Name *string
558 Cmd *string
559 Out []string
560 }{}
561 genruleProps.Name = proptools.StringPtr(module.xmlFileName() + "-gen")
562 genruleProps.Cmd = proptools.StringPtr("echo '" + xmlContent + "' > $(out)")
563 genruleProps.Out = []string{module.xmlFileName()}
Colin Cross84dfc3d2019-09-25 11:33:01 -0700564 mctx.CreateModule(genrule.GenRuleFactory, &genruleProps)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900565
566 // creates a prebuilt_etc module to actually place the xml file under
567 // <partition>/etc/permissions
568 etcProps := struct {
Sundong Ahn0d7dff42019-12-04 12:53:44 +0900569 Name *string
570 Src *string
571 Sub_dir *string
572 Soc_specific *bool
573 Device_specific *bool
574 Product_specific *bool
575 System_ext_specific *bool
Jiyong Parkc678ad32018-04-10 13:07:10 +0900576 }{}
577 etcProps.Name = proptools.StringPtr(module.xmlFileName())
Jiyong Park5a8d1be2018-04-25 22:57:34 +0900578 etcProps.Src = proptools.StringPtr(":" + module.xmlFileName() + "-gen")
Jiyong Parkc678ad32018-04-10 13:07:10 +0900579 etcProps.Sub_dir = proptools.StringPtr("permissions")
580 if module.SocSpecific() {
581 etcProps.Soc_specific = proptools.BoolPtr(true)
582 } else if module.DeviceSpecific() {
583 etcProps.Device_specific = proptools.BoolPtr(true)
584 } else if module.ProductSpecific() {
585 etcProps.Product_specific = proptools.BoolPtr(true)
Sundong Ahn0d7dff42019-12-04 12:53:44 +0900586 } else if module.SystemExtSpecific() {
587 etcProps.System_ext_specific = proptools.BoolPtr(true)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900588 }
Colin Cross84dfc3d2019-09-25 11:33:01 -0700589 mctx.CreateModule(android.PrebuiltEtcFactory, &etcProps)
Jiyong Parkc678ad32018-04-10 13:07:10 +0900590}
591
Colin Cross0ea8ba82019-06-06 14:33:29 -0700592func (module *SdkLibrary) PrebuiltJars(ctx android.BaseModuleContext, sdkVersion string) android.Paths {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900593 var api, v string
Paul Duffin52d398a2019-06-11 12:31:14 +0100594 if sdkVersion == "" || sdkVersion == "none" {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900595 api = "system"
596 v = "current"
597 } else if strings.Contains(sdkVersion, "_") {
598 t := strings.Split(sdkVersion, "_")
599 api = t[0]
600 v = t[1]
Jiyong Parkc678ad32018-04-10 13:07:10 +0900601 } else {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900602 api = "public"
603 v = sdkVersion
604 }
605 dir := filepath.Join("prebuilts", "sdk", v, api)
606 jar := filepath.Join(dir, module.BaseModuleName()+".jar")
607 jarPath := android.ExistentPathForSource(ctx, jar)
Sundong Ahnae418ac2019-02-28 15:01:28 +0900608 if !jarPath.Valid() {
609 ctx.PropertyErrorf("sdk_library", "invalid sdk version %q, %q does not exist", v, jar)
610 return nil
611 }
Sundong Ahn054b19a2018-10-19 13:46:09 +0900612 return android.Paths{jarPath.Path()}
613}
614
615// to satisfy SdkLibraryDependency interface
Colin Cross0ea8ba82019-06-06 14:33:29 -0700616func (module *SdkLibrary) SdkHeaderJars(ctx android.BaseModuleContext, sdkVersion string) android.Paths {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900617 // This module is just a wrapper for the stubs.
Colin Cross10932872019-04-18 14:27:12 -0700618 if ctx.Config().UnbundledBuildUsePrebuiltSdks() {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900619 return module.PrebuiltJars(ctx, sdkVersion)
620 } else {
621 if strings.HasPrefix(sdkVersion, "system_") {
622 return module.systemApiStubsPath
623 } else if sdkVersion == "" {
624 return module.Library.HeaderJars()
625 } else {
626 return module.publicApiStubsPath
627 }
Jiyong Parkc678ad32018-04-10 13:07:10 +0900628 }
629}
630
Sundong Ahn241cd372018-07-13 16:16:44 +0900631// to satisfy SdkLibraryDependency interface
Colin Cross0ea8ba82019-06-06 14:33:29 -0700632func (module *SdkLibrary) SdkImplementationJars(ctx android.BaseModuleContext, sdkVersion string) android.Paths {
Sundong Ahn241cd372018-07-13 16:16:44 +0900633 // This module is just a wrapper for the stubs.
Colin Cross10932872019-04-18 14:27:12 -0700634 if ctx.Config().UnbundledBuildUsePrebuiltSdks() {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900635 return module.PrebuiltJars(ctx, sdkVersion)
Sundong Ahn241cd372018-07-13 16:16:44 +0900636 } else {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900637 if strings.HasPrefix(sdkVersion, "system_") {
638 return module.systemApiStubsImplPath
639 } else if sdkVersion == "" {
640 return module.Library.ImplementationJars()
641 } else {
642 return module.publicApiStubsImplPath
643 }
Sundong Ahn241cd372018-07-13 16:16:44 +0900644 }
645}
646
Sundong Ahn80a87b32019-05-13 15:02:50 +0900647func (module *SdkLibrary) SetNoDist() {
648 module.sdkLibraryProperties.No_dist = proptools.BoolPtr(true)
649}
650
Colin Cross571cccf2019-02-04 11:22:08 -0800651var javaSdkLibrariesKey = android.NewOnceKey("javaSdkLibraries")
652
Jiyong Park82484c02018-04-23 21:41:26 +0900653func javaSdkLibraries(config android.Config) *[]string {
Colin Cross571cccf2019-02-04 11:22:08 -0800654 return config.Once(javaSdkLibrariesKey, func() interface{} {
Jiyong Park82484c02018-04-23 21:41:26 +0900655 return &[]string{}
656 }).(*[]string)
657}
658
Jiyong Parkc678ad32018-04-10 13:07:10 +0900659// For a java_sdk_library module, create internal modules for stubs, docs,
660// runtime libs and xml file. If requested, the stubs and docs are created twice
661// once for public API level and once for system API level
Colin Crossf8b860a2019-04-16 14:43:28 -0700662func (module *SdkLibrary) CreateInternalModules(mctx android.LoadHookContext) {
Inseob Kim6e93ac92019-03-21 17:43:49 +0900663 if len(module.Library.Module.properties.Srcs) == 0 {
Inseob Kimc0907f12019-02-08 21:00:45 +0900664 mctx.PropertyErrorf("srcs", "java_sdk_library must specify srcs")
665 }
666
Inseob Kim6e93ac92019-03-21 17:43:49 +0900667 if len(module.sdkLibraryProperties.Api_packages) == 0 {
Inseob Kimc0907f12019-02-08 21:00:45 +0900668 mctx.PropertyErrorf("api_packages", "java_sdk_library must specify api_packages")
669 }
Inseob Kim8098faa2019-03-18 10:19:51 +0900670
671 missing_current_api := false
672
673 for _, scope := range []string{"", "system-", "test-"} {
674 for _, api := range []string{"current.txt", "removed.txt"} {
675 path := path.Join(mctx.ModuleDir(), "api", scope+api)
676 p := android.ExistentPathForSource(mctx, path)
677 if !p.Valid() {
678 mctx.ModuleErrorf("Current api file %#v doesn't exist", path)
679 missing_current_api = true
680 }
681 }
682 }
683
684 if missing_current_api {
685 script := "build/soong/scripts/gen-java-current-api-files.sh"
686 p := android.ExistentPathForSource(mctx, script)
687
688 if !p.Valid() {
689 panic(fmt.Sprintf("script file %s doesn't exist", script))
690 }
691
692 mctx.ModuleErrorf("One or more current api files are missing. "+
693 "You can update them by:\n"+
694 "%s %q && m update-api", script, mctx.ModuleDir())
695 return
696 }
697
Inseob Kimc0907f12019-02-08 21:00:45 +0900698 // for public API stubs
699 module.createStubsLibrary(mctx, apiScopePublic)
700 module.createDocs(mctx, apiScopePublic)
701
Paul Duffin250e6192019-06-07 10:44:37 +0100702 sdkDep := decodeSdkDep(mctx, sdkContext(&module.Library))
703 if sdkDep.hasStandardLibs() {
Inseob Kimc0907f12019-02-08 21:00:45 +0900704 // for system API stubs
705 module.createStubsLibrary(mctx, apiScopeSystem)
706 module.createDocs(mctx, apiScopeSystem)
707
708 // for test API stubs
709 module.createStubsLibrary(mctx, apiScopeTest)
710 module.createDocs(mctx, apiScopeTest)
711
712 // for runtime
713 module.createXmlFile(mctx)
714 }
715
716 // record java_sdk_library modules so that they are exported to make
717 javaSdkLibraries := javaSdkLibraries(mctx.Config())
718 javaSdkLibrariesLock.Lock()
719 defer javaSdkLibrariesLock.Unlock()
720 *javaSdkLibraries = append(*javaSdkLibraries, module.BaseModuleName())
721}
722
723func (module *SdkLibrary) InitSdkLibraryProperties() {
Sundong Ahn054b19a2018-10-19 13:46:09 +0900724 module.AddProperties(
725 &module.sdkLibraryProperties,
726 &module.Library.Module.properties,
727 &module.Library.Module.dexpreoptProperties,
728 &module.Library.Module.deviceProperties,
729 &module.Library.Module.protoProperties,
730 )
731
732 module.Library.Module.properties.Installable = proptools.BoolPtr(true)
733 module.Library.Module.deviceProperties.IsSDKLibrary = true
Inseob Kimc0907f12019-02-08 21:00:45 +0900734}
Sundong Ahn054b19a2018-10-19 13:46:09 +0900735
Jaewoong Jung4f158ee2019-07-11 10:05:35 -0700736// java_sdk_library is a special Java library that provides optional platform APIs to apps.
737// In practice, it can be viewed as a combination of several modules: 1) stubs library that clients
738// are linked against to, 2) droiddoc module that internally generates API stubs source files,
739// 3) the real runtime shared library that implements the APIs, and 4) XML file for adding
740// the runtime lib to the classpath at runtime if requested via <uses-library>.
Inseob Kimc0907f12019-02-08 21:00:45 +0900741func SdkLibraryFactory() android.Module {
742 module := &SdkLibrary{}
743 module.InitSdkLibraryProperties()
Sundong Ahn054b19a2018-10-19 13:46:09 +0900744 InitJavaModule(module, android.HostAndDeviceSupported)
Colin Crossf8b860a2019-04-16 14:43:28 -0700745 android.AddLoadHook(module, func(ctx android.LoadHookContext) { module.CreateInternalModules(ctx) })
Jiyong Parkc678ad32018-04-10 13:07:10 +0900746 return module
747}
Colin Cross79c7c262019-04-17 11:11:46 -0700748
749//
750// SDK library prebuilts
751//
752
753type sdkLibraryImportProperties struct {
754 Jars []string `android:"path"`
755
756 Sdk_version *string
757
758 Installable *bool
759
760 // List of shared java libs that this module has dependencies to
761 Libs []string
762
763 // List of files to remove from the jar file(s)
764 Exclude_files []string
765
766 // List of directories to remove from the jar file(s)
767 Exclude_dirs []string
768}
769
770type sdkLibraryImport struct {
771 android.ModuleBase
772 android.DefaultableModuleBase
773 prebuilt android.Prebuilt
774
775 properties sdkLibraryImportProperties
776
777 stubsPath android.Paths
778}
779
780var _ SdkLibraryDependency = (*sdkLibraryImport)(nil)
781
Jaewoong Jung4f158ee2019-07-11 10:05:35 -0700782// java_sdk_library_import imports a prebuilt java_sdk_library.
Colin Cross79c7c262019-04-17 11:11:46 -0700783func sdkLibraryImportFactory() android.Module {
784 module := &sdkLibraryImport{}
785
786 module.AddProperties(&module.properties)
787
788 android.InitPrebuiltModule(module, &module.properties.Jars)
789 InitJavaModule(module, android.HostAndDeviceSupported)
790
791 android.AddLoadHook(module, func(mctx android.LoadHookContext) { module.createInternalModules(mctx) })
792 return module
793}
794
795func (module *sdkLibraryImport) Prebuilt() *android.Prebuilt {
796 return &module.prebuilt
797}
798
799func (module *sdkLibraryImport) Name() string {
800 return module.prebuilt.Name(module.ModuleBase.Name())
801}
802
803func (module *sdkLibraryImport) createInternalModules(mctx android.LoadHookContext) {
804 // Creates a java import for the jar with ".stubs" suffix
805 props := struct {
Sundong Ahn0d7dff42019-12-04 12:53:44 +0900806 Name *string
807 Soc_specific *bool
808 Device_specific *bool
809 Product_specific *bool
810 System_ext_specific *bool
Colin Cross79c7c262019-04-17 11:11:46 -0700811 }{}
812
813 props.Name = proptools.StringPtr(module.BaseModuleName() + sdkStubsLibrarySuffix)
814
815 if module.SocSpecific() {
816 props.Soc_specific = proptools.BoolPtr(true)
817 } else if module.DeviceSpecific() {
818 props.Device_specific = proptools.BoolPtr(true)
819 } else if module.ProductSpecific() {
820 props.Product_specific = proptools.BoolPtr(true)
Sundong Ahn0d7dff42019-12-04 12:53:44 +0900821 } else if module.SystemExtSpecific() {
822 props.System_ext_specific = proptools.BoolPtr(true)
Colin Cross79c7c262019-04-17 11:11:46 -0700823 }
824
Colin Cross84dfc3d2019-09-25 11:33:01 -0700825 mctx.CreateModule(ImportFactory, &props, &module.properties)
Colin Cross79c7c262019-04-17 11:11:46 -0700826
827 javaSdkLibraries := javaSdkLibraries(mctx.Config())
828 javaSdkLibrariesLock.Lock()
829 defer javaSdkLibrariesLock.Unlock()
830 *javaSdkLibraries = append(*javaSdkLibraries, module.BaseModuleName())
831}
832
833func (module *sdkLibraryImport) DepsMutator(ctx android.BottomUpMutatorContext) {
834 // Add dependencies to the prebuilt stubs library
835 ctx.AddVariationDependencies(nil, publicApiStubsTag, module.BaseModuleName()+sdkStubsLibrarySuffix)
836}
837
838func (module *sdkLibraryImport) GenerateAndroidBuildActions(ctx android.ModuleContext) {
839 // Record the paths to the prebuilt stubs library.
840 ctx.VisitDirectDeps(func(to android.Module) {
841 tag := ctx.OtherModuleDependencyTag(to)
842
843 switch tag {
844 case publicApiStubsTag:
845 module.stubsPath = to.(Dependency).HeaderJars()
846 }
847 })
848}
849
850// to satisfy SdkLibraryDependency interface
Colin Cross0ea8ba82019-06-06 14:33:29 -0700851func (module *sdkLibraryImport) SdkHeaderJars(ctx android.BaseModuleContext, sdkVersion string) android.Paths {
Colin Cross79c7c262019-04-17 11:11:46 -0700852 // This module is just a wrapper for the prebuilt stubs.
853 return module.stubsPath
854}
855
856// to satisfy SdkLibraryDependency interface
Colin Cross0ea8ba82019-06-06 14:33:29 -0700857func (module *sdkLibraryImport) SdkImplementationJars(ctx android.BaseModuleContext, sdkVersion string) android.Paths {
Colin Cross79c7c262019-04-17 11:11:46 -0700858 // This module is just a wrapper for the stubs.
859 return module.stubsPath
860}