blob: b20f5f2442beb38fac613760aa4f414cd9011511 [file] [log] [blame]
Colin Cross2fe66872015-03-30 17:20:39 -07001// Copyright 2015 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
17// This file contains the module types for compiling Java for Android, and converts the properties
Colin Cross46c9b8b2017-06-22 16:51:17 -070018// into the flags and filenames necessary to pass to the Module. The final creation of the rules
Colin Cross2fe66872015-03-30 17:20:39 -070019// is handled in builder.go
20
21import (
Colin Crossf19b9bb2018-03-26 14:42:44 -070022 "fmt"
Colin Crossfc3674a2017-09-18 17:41:52 -070023 "path/filepath"
Colin Cross74d73e22017-08-02 11:05:49 -070024 "strconv"
Colin Cross2fe66872015-03-30 17:20:39 -070025 "strings"
Ulya Trafimovichf3ff0102019-12-03 15:39:23 +000026 "sync"
Colin Cross2fe66872015-03-30 17:20:39 -070027
28 "github.com/google/blueprint"
Colin Cross3b706fd2019-09-05 16:44:18 -070029 "github.com/google/blueprint/pathtools"
Colin Cross76b5f0c2017-08-29 16:02:06 -070030 "github.com/google/blueprint/proptools"
Colin Cross2fe66872015-03-30 17:20:39 -070031
Colin Cross635c3b02016-05-18 15:37:25 -070032 "android/soong/android"
Ulya Trafimovichf3ff0102019-12-03 15:39:23 +000033 "android/soong/dexpreopt"
Colin Cross3e3e72d2017-06-22 17:20:19 -070034 "android/soong/java/config"
Colin Cross303e21f2018-08-07 16:49:25 -070035 "android/soong/tradefed"
Colin Cross2fe66872015-03-30 17:20:39 -070036)
37
Colin Cross463a90e2015-06-17 14:20:06 -070038func init() {
Paul Duffinf9b1da02019-12-18 19:51:55 +000039 RegisterJavaBuildComponents(android.InitRegistrationContext)
Paul Duffin255f18e2019-12-13 11:22:16 +000040
41 // Register sdk member types.
Paul Duffin7b81f5e2020-01-13 21:03:22 +000042 android.RegisterSdkMemberType(javaHeaderLibsSdkMemberType)
Paul Duffin255f18e2019-12-13 11:22:16 +000043
44 android.RegisterSdkMemberType(&implLibrarySdkMemberType{
45 librarySdkMemberType{
46 android.SdkMemberTypeBase{
47 PropertyName: "java_libs",
48 },
49 },
50 })
Paul Duffin1b82e6a2019-12-03 18:06:47 +000051
52 android.RegisterSdkMemberType(&testSdkMemberType{
53 SdkMemberTypeBase: android.SdkMemberTypeBase{
54 PropertyName: "java_tests",
55 },
56 })
Ulya Trafimovichf3ff0102019-12-03 15:39:23 +000057
58 android.PostDepsMutators(RegisterPostDepsMutators)
Colin Cross463a90e2015-06-17 14:20:06 -070059}
60
Paul Duffinf9b1da02019-12-18 19:51:55 +000061func RegisterJavaBuildComponents(ctx android.RegistrationContext) {
62 ctx.RegisterModuleType("java_defaults", DefaultsFactory)
63
64 ctx.RegisterModuleType("java_library", LibraryFactory)
65 ctx.RegisterModuleType("java_library_static", LibraryStaticFactory)
66 ctx.RegisterModuleType("java_library_host", LibraryHostFactory)
67 ctx.RegisterModuleType("java_binary", BinaryFactory)
68 ctx.RegisterModuleType("java_binary_host", BinaryHostFactory)
69 ctx.RegisterModuleType("java_test", TestFactory)
70 ctx.RegisterModuleType("java_test_helper_library", TestHelperLibraryFactory)
71 ctx.RegisterModuleType("java_test_host", TestHostFactory)
Paul Duffin1b82e6a2019-12-03 18:06:47 +000072 ctx.RegisterModuleType("java_test_import", JavaTestImportFactory)
Paul Duffinf9b1da02019-12-18 19:51:55 +000073 ctx.RegisterModuleType("java_import", ImportFactory)
74 ctx.RegisterModuleType("java_import_host", ImportFactoryHost)
75 ctx.RegisterModuleType("java_device_for_host", DeviceForHostFactory)
76 ctx.RegisterModuleType("java_host_for_device", HostForDeviceFactory)
77 ctx.RegisterModuleType("dex_import", DexImportFactory)
78
79 ctx.RegisterSingletonType("logtags", LogtagsSingleton)
80 ctx.RegisterSingletonType("kythe_java_extract", kytheExtractJavaFactory)
81}
82
Ulya Trafimovichf3ff0102019-12-03 15:39:23 +000083func RegisterPostDepsMutators(ctx android.RegisterMutatorsContext) {
84 ctx.BottomUp("ordered_system_server_jars", systemServerJarsDepsMutator)
85}
86
87var (
88 dexpreoptedSystemServerJarsKey = android.NewOnceKey("dexpreoptedSystemServerJars")
89 dexpreoptedSystemServerJarsLock sync.Mutex
90)
91
92func DexpreoptedSystemServerJars(config android.Config) *[]string {
93 return config.Once(dexpreoptedSystemServerJarsKey, func() interface{} {
94 return &[]string{}
95 }).(*[]string)
96}
97
98// A PostDepsMutator pass that enforces total order on non-updatable system server jars. A total
99// order is neededed because such jars must be dexpreopted together (each jar on the list must have
100// all preceding jars in its class loader context). The total order must be compatible with the
101// partial order imposed by genuine dependencies between system server jars (which is not always
102// respected by the PRODUCT_SYSTEM_SERVER_JARS variable).
103//
104// An earlier mutator pass creates genuine dependencies, and this pass traverses the jars in that
105// order (which is partial and non-deterministic). This pass adds additional dependencies between
106// jars, making the order total and deterministic. It also constructs a global ordered list.
107func systemServerJarsDepsMutator(ctx android.BottomUpMutatorContext) {
Martin Stjernholm40f9f3c2020-01-20 18:12:23 +0000108 jars := dexpreopt.NonUpdatableSystemServerJars(ctx, dexpreopt.GetGlobalConfig(ctx))
Ulya Trafimovichf3ff0102019-12-03 15:39:23 +0000109 name := ctx.ModuleName()
110 if android.InList(name, jars) {
111 dexpreoptedSystemServerJarsLock.Lock()
112 defer dexpreoptedSystemServerJarsLock.Unlock()
113 jars := DexpreoptedSystemServerJars(ctx.Config())
114 for _, dep := range *jars {
115 ctx.AddDependency(ctx.Module(), dexpreopt.SystemServerDepTag, dep)
116 }
117 *jars = append(*jars, name)
118 }
119}
120
Jeongik Cha2cc570d2019-10-29 15:44:45 +0900121func (j *Module) checkSdkVersion(ctx android.ModuleContext) {
122 if j.SocSpecific() || j.DeviceSpecific() ||
123 (j.ProductSpecific() && ctx.Config().EnforceProductPartitionInterface()) {
124 if sc, ok := ctx.Module().(sdkContext); ok {
Jiyong Park6a927c42020-01-21 02:03:43 +0900125 if !sc.sdkVersion().specified() {
Jeongik Cha2cc570d2019-10-29 15:44:45 +0900126 ctx.PropertyErrorf("sdk_version",
127 "sdk_version must have a value when the module is located at vendor or product(only if PRODUCT_ENFORCE_PRODUCT_PARTITION_INTERFACE is set).")
128 }
129 }
130 }
131}
132
Jeongik Cha538c0d02019-07-11 15:54:27 +0900133func (j *Module) checkPlatformAPI(ctx android.ModuleContext) {
134 if sc, ok := ctx.Module().(sdkContext); ok {
135 usePlatformAPI := proptools.Bool(j.deviceProperties.Platform_apis)
Jiyong Park6a927c42020-01-21 02:03:43 +0900136 sdkVersionSpecified := sc.sdkVersion().specified()
137 if usePlatformAPI && sdkVersionSpecified {
138 ctx.PropertyErrorf("platform_apis", "platform_apis must be false when sdk_version is not empty.")
139 } else if !usePlatformAPI && !sdkVersionSpecified {
140 ctx.PropertyErrorf("platform_apis", "platform_apis must be true when sdk_version is empty.")
Jeongik Cha538c0d02019-07-11 15:54:27 +0900141 }
142
143 }
144}
145
Colin Cross2fe66872015-03-30 17:20:39 -0700146// TODO:
147// Autogenerated files:
Colin Cross2fe66872015-03-30 17:20:39 -0700148// Renderscript
149// Post-jar passes:
150// Proguard
Colin Cross2fe66872015-03-30 17:20:39 -0700151// Rmtypedefs
Colin Cross2fe66872015-03-30 17:20:39 -0700152// DroidDoc
153// Findbugs
154
Colin Cross89536d42017-07-07 14:35:50 -0700155type CompilerProperties struct {
Colin Cross7d5136f2015-05-11 13:39:40 -0700156 // list of source files used to compile the Java module. May be .java, .logtags, .proto,
157 // or .aidl files.
Colin Cross27b922f2019-03-04 22:35:41 -0800158 Srcs []string `android:"path,arch_variant"`
Dan Willemsen2ef08f42015-06-30 18:15:24 -0700159
160 // list of source files that should not be used to build the Java module.
161 // This is most useful in the arch/multilib variants to remove non-common files
Colin Cross27b922f2019-03-04 22:35:41 -0800162 Exclude_srcs []string `android:"path,arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700163
164 // list of directories containing Java resources
Colin Cross86a63ff2017-09-27 17:33:10 -0700165 Java_resource_dirs []string `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700166
Colin Cross86a63ff2017-09-27 17:33:10 -0700167 // list of directories that should be excluded from java_resource_dirs
168 Exclude_java_resource_dirs []string `android:"arch_variant"`
Dan Willemsen2ef08f42015-06-30 18:15:24 -0700169
Colin Cross0f37af02017-09-27 17:42:05 -0700170 // list of files to use as Java resources
Colin Cross27b922f2019-03-04 22:35:41 -0800171 Java_resources []string `android:"path,arch_variant"`
Colin Cross0f37af02017-09-27 17:42:05 -0700172
Colin Crosscedd4762018-09-13 11:26:19 -0700173 // list of files that should be excluded from java_resources and java_resource_dirs
Colin Cross27b922f2019-03-04 22:35:41 -0800174 Exclude_java_resources []string `android:"path,arch_variant"`
Colin Cross0f37af02017-09-27 17:42:05 -0700175
Colin Cross7d5136f2015-05-11 13:39:40 -0700176 // list of module-specific flags that will be used for javac compiles
177 Javacflags []string `android:"arch_variant"`
178
Zoran Jovanovic8736ce22018-08-21 17:10:29 +0200179 // list of module-specific flags that will be used for kotlinc compiles
180 Kotlincflags []string `android:"arch_variant"`
181
Colin Cross7d5136f2015-05-11 13:39:40 -0700182 // list of of java libraries that will be in the classpath
Colin Crosse8dc34a2017-07-19 11:22:16 -0700183 Libs []string `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700184
185 // list of java libraries that will be compiled into the resulting jar
Colin Crosse8dc34a2017-07-19 11:22:16 -0700186 Static_libs []string `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700187
188 // manifest file to be included in resulting jar
Colin Cross27b922f2019-03-04 22:35:41 -0800189 Manifest *string `android:"path"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700190
Colin Cross540eff82017-06-22 17:01:52 -0700191 // if not blank, run jarjar using the specified rules file
Colin Cross27b922f2019-03-04 22:35:41 -0800192 Jarjar_rules *string `android:"path,arch_variant"`
Colin Cross64162712017-08-08 13:17:59 -0700193
194 // If not blank, set the java version passed to javac as -source and -target
195 Java_version *string
Colin Cross2c429dc2017-08-31 16:45:16 -0700196
Colin Cross9ae1b922018-06-26 17:59:05 -0700197 // If set to true, allow this module to be dexed and installed on devices. Has no
198 // effect on host modules, which are always considered installable.
Colin Cross2c429dc2017-08-31 16:45:16 -0700199 Installable *bool
Colin Cross32f676a2017-09-06 13:41:06 -0700200
Colin Cross0f37af02017-09-27 17:42:05 -0700201 // If set to true, include sources used to compile the module in to the final jar
202 Include_srcs *bool
203
Vladimir Marko0975ee02019-04-02 10:29:55 +0100204 // If not empty, classes are restricted to the specified packages and their sub-packages.
205 // This restriction is checked after applying jarjar rules and including static libs.
206 Permitted_packages []string
207
Colin Crossbe9cdb82019-01-21 21:37:16 -0800208 // List of modules to use as annotation processors
209 Plugins []string
Colin Cross1369cdb2017-09-29 17:58:17 -0700210
Artur Satayev9cf46692019-11-26 18:08:34 +0000211 // List of modules to export to libraries that directly depend on this library as annotation processors
212 Exported_plugins []string
213
Nan Zhang61eaedb2017-11-02 13:28:15 -0700214 // The number of Java source entries each Javac instance can process
215 Javac_shard_size *int64
216
Nan Zhang5f8cb422018-02-06 10:34:32 -0800217 // Add host jdk tools.jar to bootclasspath
218 Use_tools_jar *bool
219
Colin Cross1369cdb2017-09-29 17:58:17 -0700220 Openjdk9 struct {
Colin Cross6cef4812019-10-17 14:23:50 -0700221 // List of source files that should only be used when passing -source 1.9 or higher
Colin Cross27b922f2019-03-04 22:35:41 -0800222 Srcs []string `android:"path"`
Colin Cross1369cdb2017-09-29 17:58:17 -0700223
Colin Cross6cef4812019-10-17 14:23:50 -0700224 // List of javac flags that should only be used when passing -source 1.9 or higher
Colin Cross1369cdb2017-09-29 17:58:17 -0700225 Javacflags []string
226 }
Colin Crosscb933592017-11-22 13:49:43 -0800227
Colin Cross81440082018-08-15 20:21:55 -0700228 // When compiling language level 9+ .java code in packages that are part of
229 // a system module, patch_module names the module that your sources and
230 // dependencies should be patched into. The Android runtime currently
231 // doesn't implement the JEP 261 module system so this option is only
232 // supported at compile time. It should only be needed to compile tests in
233 // packages that exist in libcore and which are inconvenient to move
234 // elsewhere.
Tobias Thiererdda713d2018-09-19 16:16:19 +0100235 Patch_module *string `android:"arch_variant"`
Colin Cross81440082018-08-15 20:21:55 -0700236
Colin Crosscb933592017-11-22 13:49:43 -0800237 Jacoco struct {
238 // List of classes to include for instrumentation with jacoco to collect coverage
239 // information at runtime when building with coverage enabled. If unset defaults to all
240 // classes.
241 // Supports '*' as the last character of an entry in the list as a wildcard match.
242 // If preceded by '.' it matches all classes in the package and subpackages, otherwise
243 // it matches classes in the package that have the class name as a prefix.
244 Include_filter []string
245
246 // List of classes to exclude from instrumentation with jacoco to collect coverage
247 // information at runtime when building with coverage enabled. Overrides classes selected
248 // by the include_filter property.
249 // Supports '*' as the last character of an entry in the list as a wildcard match.
250 // If preceded by '.' it matches all classes in the package and subpackages, otherwise
251 // it matches classes in the package that have the class name as a prefix.
252 Exclude_filter []string
253 }
254
Andreas Gampef3e5b552018-01-22 21:27:21 -0800255 Errorprone struct {
256 // List of javac flags that should only be used when running errorprone.
257 Javacflags []string
258 }
259
Colin Cross0f2ee152017-12-14 15:22:43 -0800260 Proto struct {
261 // List of extra options that will be passed to the proto generator.
262 Output_params []string
263 }
264
Colin Crosscb933592017-11-22 13:49:43 -0800265 Instrument bool `blueprint:"mutated"`
Alex Light7f004a72019-02-21 13:27:37 -0800266
267 // List of files to include in the META-INF/services folder of the resulting jar.
Colin Cross27b922f2019-03-04 22:35:41 -0800268 Services []string `android:"path,arch_variant"`
Colin Cross540eff82017-06-22 17:01:52 -0700269}
270
Colin Cross89536d42017-07-07 14:35:50 -0700271type CompilerDeviceProperties struct {
Colin Cross540eff82017-06-22 17:01:52 -0700272 // list of module-specific flags that will be used for dex compiles
273 Dxflags []string `android:"arch_variant"`
274
Jeongik Cha538c0d02019-07-11 15:54:27 +0900275 // if not blank, set to the version of the sdk to compile against.
276 // Defaults to compiling against the current platform.
Nan Zhangea568a42017-11-08 21:20:04 -0800277 Sdk_version *string
Colin Cross7d5136f2015-05-11 13:39:40 -0700278
Colin Cross83bb3162018-06-25 15:48:06 -0700279 // if not blank, set the minimum version of the sdk that the compiled artifacts will run against.
280 // Defaults to sdk_version if not set.
281 Min_sdk_version *string
282
Dan Willemsen419290a2018-10-31 15:28:47 -0700283 // if not blank, set the targetSdkVersion in the AndroidManifest.xml.
284 // Defaults to sdk_version if not set.
285 Target_sdk_version *string
286
Jeongik Cha356dac42019-08-19 14:09:52 +0900287 // Whether to compile against the platform APIs instead of an SDK.
288 // If true, then sdk_version must be empty. The value of this field
289 // is ignored when module's type isn't android_app.
Colin Cross6af2e492018-05-22 11:12:33 -0700290 Platform_apis *bool
291
Colin Crossebe1a512017-11-14 13:12:14 -0800292 Aidl struct {
293 // Top level directories to pass to aidl tool
294 Include_dirs []string
Colin Cross7d5136f2015-05-11 13:39:40 -0700295
Colin Crossebe1a512017-11-14 13:12:14 -0800296 // Directories rooted at the Android.bp file to pass to aidl tool
297 Local_include_dirs []string
298
299 // directories that should be added as include directories for any aidl sources of modules
300 // that depend on this module, as well as to aidl for this module.
301 Export_include_dirs []string
Martijn Coeneneab15642018-03-09 09:29:59 +0100302
303 // whether to generate traces (for systrace) for this interface
304 Generate_traces *bool
Olivier Gaillard0a4cfbc2018-07-16 23:37:03 +0100305
306 // whether to generate Binder#GetTransaction name method.
307 Generate_get_transaction_name *bool
Colin Crossebe1a512017-11-14 13:12:14 -0800308 }
Colin Cross92430102017-10-09 14:59:32 -0700309
310 // If true, export a copy of the module as a -hostdex module for host testing.
311 Hostdex *bool
Colin Cross1369cdb2017-09-29 17:58:17 -0700312
Colin Cross7f87f4f2019-04-24 13:41:45 -0700313 Target struct {
314 Hostdex struct {
315 // Additional required dependencies to add to -hostdex modules.
316 Required []string
317 }
318 }
319
David Brazdil17ef5632018-06-27 10:27:45 +0100320 // If set to true, compile dex regardless of installable. Defaults to false.
321 Compile_dex *bool
322
Colin Cross66dbc0b2017-12-28 12:23:20 -0800323 Optimize struct {
Colin Crossae5caf52018-05-22 11:11:52 -0700324 // If false, disable all optimization. Defaults to true for android_app and android_test
325 // modules, false for java_library and java_test modules.
Colin Cross66dbc0b2017-12-28 12:23:20 -0800326 Enabled *bool
Sasha Smundak2057f822019-04-16 17:16:58 -0700327 // True if the module containing this has it set by default.
328 EnabledByDefault bool `blueprint:"mutated"`
Colin Cross66dbc0b2017-12-28 12:23:20 -0800329
330 // If true, optimize for size by removing unused code. Defaults to true for apps,
331 // false for libraries and tests.
332 Shrink *bool
333
334 // If true, optimize bytecode. Defaults to false.
335 Optimize *bool
336
337 // If true, obfuscate bytecode. Defaults to false.
338 Obfuscate *bool
339
340 // If true, do not use the flag files generated by aapt that automatically keep
341 // classes referenced by the app manifest. Defaults to false.
342 No_aapt_flags *bool
343
344 // Flags to pass to proguard.
345 Proguard_flags []string
346
347 // Specifies the locations of files containing proguard flags.
Colin Cross27b922f2019-03-04 22:35:41 -0800348 Proguard_flags_files []string `android:"path"`
Colin Cross66dbc0b2017-12-28 12:23:20 -0800349 }
350
Paul Duffine25c6442019-10-11 13:50:28 +0100351 // When targeting 1.9 and above, override the modules to use with --system,
352 // otherwise provides defaults libraries to add to the bootclasspath.
Colin Cross1369cdb2017-09-29 17:58:17 -0700353 System_modules *string
Colin Cross5a0dcd52018-10-05 14:20:06 -0700354
Jiyong Park4c4c0242019-10-21 14:53:15 +0900355 // set the name of the output
356 Stem *string
357
Colin Cross5a0dcd52018-10-05 14:20:06 -0700358 UncompressDex bool `blueprint:"mutated"`
Colin Cross43f08db2018-11-12 10:13:39 -0800359 IsSDKLibrary bool `blueprint:"mutated"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700360}
361
Sasha Smundak2057f822019-04-16 17:16:58 -0700362func (me *CompilerDeviceProperties) EffectiveOptimizeEnabled() bool {
363 return BoolDefault(me.Optimize.Enabled, me.Optimize.EnabledByDefault)
364}
365
Colin Cross46c9b8b2017-06-22 16:51:17 -0700366// Module contains the properties and members used by all java module types
367type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700368 android.ModuleBase
Colin Cross89536d42017-07-07 14:35:50 -0700369 android.DefaultableModuleBase
Jiyong Park7f7766d2019-07-25 22:02:35 +0900370 android.ApexModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +0900371 android.SdkBase
Colin Cross2fe66872015-03-30 17:20:39 -0700372
Colin Cross89536d42017-07-07 14:35:50 -0700373 properties CompilerProperties
Colin Cross6af17aa2017-09-20 12:59:05 -0700374 protoProperties android.ProtoProperties
Colin Cross89536d42017-07-07 14:35:50 -0700375 deviceProperties CompilerDeviceProperties
Colin Cross2fe66872015-03-30 17:20:39 -0700376
Colin Cross331a1212018-08-15 20:40:52 -0700377 // jar file containing header classes including static library dependencies, suitable for
378 // inserting into the bootclasspath/classpath of another compile
Nan Zhanged19fc32017-10-19 13:06:22 -0700379 headerJarFile android.Path
380
Colin Cross331a1212018-08-15 20:40:52 -0700381 // jar file containing implementation classes including static library dependencies but no
382 // resources
Nan Zhanged19fc32017-10-19 13:06:22 -0700383 implementationJarFile android.Path
Colin Cross2fe66872015-03-30 17:20:39 -0700384
Colin Cross331a1212018-08-15 20:40:52 -0700385 // jar file containing only resources including from static library dependencies
386 resourceJar android.Path
387
Colin Cross0c4ce212019-05-03 15:28:19 -0700388 // args and dependencies to package source files into a srcjar
389 srcJarArgs []string
390 srcJarDeps android.Paths
391
Colin Cross331a1212018-08-15 20:40:52 -0700392 // jar file containing implementation classes and resources including static library
393 // dependencies
394 implementationAndResourcesJar android.Path
395
396 // output file containing classes.dex and resources
Colin Cross6ade34f2017-09-15 13:00:47 -0700397 dexJarFile android.Path
398
Colin Cross43f08db2018-11-12 10:13:39 -0800399 // output file that contains classes.dex if it should be in the output file
400 maybeStrippedDexJarFile android.Path
401
Colin Crosscb933592017-11-22 13:49:43 -0800402 // output file containing uninstrumented classes that will be instrumented by jacoco
403 jacocoReportClassesFile android.Path
404
Colin Cross66dbc0b2017-12-28 12:23:20 -0800405 // output file containing mapping of obfuscated names
406 proguardDictionary android.Path
407
Colin Cross331a1212018-08-15 20:40:52 -0700408 // output file of the module, which may be a classes jar or a dex jar
Colin Crosse560c4a2019-03-19 16:03:11 -0700409 outputFile android.Path
410 extraOutputFiles android.Paths
Colin Crossb7a63242015-04-16 14:09:14 -0700411
Colin Cross635c3b02016-05-18 15:37:25 -0700412 exportAidlIncludeDirs android.Paths
Colin Crossc0b06f12015-04-08 13:03:43 -0700413
Colin Cross635c3b02016-05-18 15:37:25 -0700414 logtagsSrcs android.Paths
Colin Crossf05fe972015-04-10 17:45:20 -0700415
Colin Cross2fe66872015-03-30 17:20:39 -0700416 // installed file for binary dependency
Colin Cross635c3b02016-05-18 15:37:25 -0700417 installFile android.Path
Colin Cross5ab4e6d2017-11-22 16:20:45 -0800418
419 // list of .java files and srcjars that was passed to javac
420 compiledJavaSrcs android.Paths
421 compiledSrcJars android.Paths
Colin Cross66dbc0b2017-12-28 12:23:20 -0800422
423 // list of extra progurad flag files
424 extraProguardFlagFiles android.Paths
Jiyong Park1be96912018-05-28 18:02:19 +0900425
Colin Cross094054a2018-10-17 15:10:48 -0700426 // manifest file to use instead of properties.Manifest
427 overrideManifest android.OptionalPath
428
Artur Satayev9cf46692019-11-26 18:08:34 +0000429 // list of SDK lib names that this java module is exporting
Jiyong Park1be96912018-05-28 18:02:19 +0900430 exportedSdkLibs []string
Brandon Lee5d45c6f2018-08-15 15:35:38 -0700431
Artur Satayev9cf46692019-11-26 18:08:34 +0000432 // list of plugins that this java module is exporting
433 exportedPluginJars android.Paths
434
435 // list of plugins that this java module is exporting
436 exportedPluginClasses []string
437
438 // list of source files, collected from srcFiles with unique java and all kt files,
patricktu242faad2019-09-24 15:41:30 +0800439 // will be used by android.IDEInfo struct
Brandon Lee5d45c6f2018-08-15 15:35:38 -0700440 expandIDEInfoCompiledSrcs []string
Colin Cross43f08db2018-11-12 10:13:39 -0800441
Steven Morelandc4efd9c2019-01-18 11:51:25 -0800442 // expanded Jarjar_rules
443 expandJarjarRules android.Path
444
Vladimir Marko0975ee02019-04-02 10:29:55 +0100445 // list of additional targets for checkbuild
446 additionalCheckedModules android.Paths
447
Colin Cross988708c2019-05-06 14:04:11 -0700448 // Extra files generated by the module type to be added as java resources.
449 extraResources android.Paths
450
Colin Crossf24a22a2019-01-31 14:12:44 -0800451 hiddenAPI
Colin Cross43f08db2018-11-12 10:13:39 -0800452 dexpreopter
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800453
454 // list of the xref extraction files
455 kytheFiles android.Paths
Colin Cross2fe66872015-03-30 17:20:39 -0700456}
457
Colin Cross41955e82019-05-29 14:40:35 -0700458func (j *Module) OutputFiles(tag string) (android.Paths, error) {
459 switch tag {
460 case "":
461 return append(android.Paths{j.outputFile}, j.extraOutputFiles...), nil
Colin Cross375ca3c2019-05-29 14:40:58 -0700462 case ".jar":
463 return android.Paths{j.implementationAndResourcesJar}, nil
Colin Cross2d975b12019-07-29 16:47:42 -0700464 case ".proguard_map":
465 return android.Paths{j.proguardDictionary}, nil
Colin Cross41955e82019-05-29 14:40:35 -0700466 default:
467 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
468 }
Colin Cross54250902017-12-05 09:28:08 -0800469}
470
Colin Cross41955e82019-05-29 14:40:35 -0700471var _ android.OutputFileProducer = (*Module)(nil)
Colin Cross54250902017-12-05 09:28:08 -0800472
Colin Crossf506d872017-07-19 15:53:04 -0700473type Dependency interface {
Nan Zhanged19fc32017-10-19 13:06:22 -0700474 HeaderJars() android.Paths
475 ImplementationJars() android.Paths
Colin Cross331a1212018-08-15 20:40:52 -0700476 ResourceJars() android.Paths
477 ImplementationAndResourcesJars() android.Paths
Colin Crossf24a22a2019-01-31 14:12:44 -0800478 DexJar() android.Path
Colin Cross635c3b02016-05-18 15:37:25 -0700479 AidlIncludeDirs() android.Paths
Jiyong Park1be96912018-05-28 18:02:19 +0900480 ExportedSdkLibs() []string
Artur Satayev9cf46692019-11-26 18:08:34 +0000481 ExportedPlugins() (android.Paths, []string)
Colin Cross0c4ce212019-05-03 15:28:19 -0700482 SrcJarArgs() ([]string, android.Paths)
Colin Crosse323f3c2019-09-17 15:34:09 -0700483 BaseModuleName() string
Jiyong Park618922e2020-01-08 13:35:43 +0900484 JacocoReportClassesFile() android.Path
Colin Cross2fe66872015-03-30 17:20:39 -0700485}
486
Jiyong Parkc678ad32018-04-10 13:07:10 +0900487type SdkLibraryDependency interface {
Jiyong Park6a927c42020-01-21 02:03:43 +0900488 SdkHeaderJars(ctx android.BaseModuleContext, sdkVersion sdkSpec) android.Paths
489 SdkImplementationJars(ctx android.BaseModuleContext, sdkVersion sdkSpec) android.Paths
Jiyong Parkc678ad32018-04-10 13:07:10 +0900490}
491
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800492type xref interface {
493 XrefJavaFiles() android.Paths
494}
495
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800496func (j *Module) XrefJavaFiles() android.Paths {
497 return j.kytheFiles
498}
499
Colin Cross89536d42017-07-07 14:35:50 -0700500func InitJavaModule(module android.DefaultableModule, hod android.HostOrDeviceSupported) {
501 android.InitAndroidArchModule(module, hod, android.MultilibCommon)
502 android.InitDefaultableModule(module)
503}
504
Colin Crossbe1da472017-07-07 15:59:46 -0700505type dependencyTag struct {
506 blueprint.BaseDependencyTag
507 name string
Colin Cross2fe66872015-03-30 17:20:39 -0700508}
509
Colin Crossa4f08812018-10-02 22:03:40 -0700510type jniDependencyTag struct {
511 blueprint.BaseDependencyTag
Colin Crossa4f08812018-10-02 22:03:40 -0700512}
513
Jiyong Park8be103b2019-11-08 15:53:48 +0900514func IsJniDepTag(depTag blueprint.DependencyTag) bool {
515 _, ok := depTag.(*jniDependencyTag)
516 return ok
517}
518
Colin Crossbe1da472017-07-07 15:59:46 -0700519var (
Colin Cross4b964c02018-10-15 16:18:06 -0700520 staticLibTag = dependencyTag{name: "staticlib"}
521 libTag = dependencyTag{name: "javalib"}
Colin Cross6cef4812019-10-17 14:23:50 -0700522 java9LibTag = dependencyTag{name: "java9lib"}
Colin Crossbe9cdb82019-01-21 21:37:16 -0800523 pluginTag = dependencyTag{name: "plugin"}
Artur Satayev9cf46692019-11-26 18:08:34 +0000524 exportedPluginTag = dependencyTag{name: "exported-plugin"}
Colin Cross4b964c02018-10-15 16:18:06 -0700525 bootClasspathTag = dependencyTag{name: "bootclasspath"}
526 systemModulesTag = dependencyTag{name: "system modules"}
527 frameworkResTag = dependencyTag{name: "framework-res"}
528 frameworkApkTag = dependencyTag{name: "framework-apk"}
529 kotlinStdlibTag = dependencyTag{name: "kotlin-stdlib"}
Colin Crossafbb1732019-01-17 15:42:52 -0800530 kotlinAnnotationsTag = dependencyTag{name: "kotlin-annotations"}
Colin Cross4b964c02018-10-15 16:18:06 -0700531 proguardRaiseTag = dependencyTag{name: "proguard-raise"}
532 certificateTag = dependencyTag{name: "certificate"}
533 instrumentationForTag = dependencyTag{name: "instrumentation_for"}
Colin Cross50ddcc42019-05-16 12:28:22 -0700534 usesLibTag = dependencyTag{name: "uses-library"}
Colin Crossbe1da472017-07-07 15:59:46 -0700535)
Colin Cross2fe66872015-03-30 17:20:39 -0700536
Jiyong Park83dc74b2020-01-14 18:38:44 +0900537func IsLibDepTag(depTag blueprint.DependencyTag) bool {
538 return depTag == libTag
539}
540
541func IsStaticLibDepTag(depTag blueprint.DependencyTag) bool {
542 return depTag == staticLibTag
543}
544
Colin Crossfc3674a2017-09-18 17:41:52 -0700545type sdkDep struct {
Colin Cross47ff2522017-10-02 14:22:08 -0700546 useModule, useFiles, useDefaultLibs, invalidVersion bool
547
Colin Cross6cef4812019-10-17 14:23:50 -0700548 // The modules that will be added to the bootclasspath when targeting 1.8 or lower
549 bootclasspath []string
Paul Duffine25c6442019-10-11 13:50:28 +0100550
551 // The default system modules to use. Will be an empty string if no system
552 // modules are to be used.
Colin Cross1369cdb2017-09-29 17:58:17 -0700553 systemModules string
554
Colin Cross6cef4812019-10-17 14:23:50 -0700555 // The modules that will be added ot the classpath when targeting 1.9 or higher
556 java9Classpath []string
557
Colin Crossa97c5d32018-03-28 14:58:31 -0700558 frameworkResModule string
559
Colin Cross86a60ae2018-05-29 14:44:55 -0700560 jars android.Paths
Colin Cross3047fa22019-04-18 10:56:44 -0700561 aidl android.OptionalPath
Paul Duffin250e6192019-06-07 10:44:37 +0100562
563 noStandardLibs, noFrameworksLibs bool
564}
565
566func (s sdkDep) hasStandardLibs() bool {
567 return !s.noStandardLibs
568}
569
570func (s sdkDep) hasFrameworkLibs() bool {
571 return !s.noStandardLibs && !s.noFrameworksLibs
Colin Cross1369cdb2017-09-29 17:58:17 -0700572}
573
Colin Crossa4f08812018-10-02 22:03:40 -0700574type jniLib struct {
575 name string
576 path android.Path
577 target android.Target
578}
579
Colin Cross0ea8ba82019-06-06 14:33:29 -0700580func (j *Module) shouldInstrument(ctx android.BaseModuleContext) bool {
Colin Cross3144dfc2018-01-03 15:06:47 -0800581 return j.properties.Instrument && ctx.Config().IsEnvTrue("EMMA_INSTRUMENT")
582}
583
Colin Cross0ea8ba82019-06-06 14:33:29 -0700584func (j *Module) shouldInstrumentStatic(ctx android.BaseModuleContext) bool {
Colin Cross3144dfc2018-01-03 15:06:47 -0800585 return j.shouldInstrument(ctx) &&
586 (ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_STATIC") ||
587 ctx.Config().UnbundledBuild())
588}
589
Jiyong Park6a927c42020-01-21 02:03:43 +0900590func (j *Module) sdkVersion() sdkSpec {
591 return sdkSpecFrom(String(j.deviceProperties.Sdk_version))
Colin Cross83bb3162018-06-25 15:48:06 -0700592}
593
Paul Duffine25c6442019-10-11 13:50:28 +0100594func (j *Module) systemModules() string {
595 return proptools.String(j.deviceProperties.System_modules)
596}
597
Jiyong Park6a927c42020-01-21 02:03:43 +0900598func (j *Module) minSdkVersion() sdkSpec {
Colin Cross83bb3162018-06-25 15:48:06 -0700599 if j.deviceProperties.Min_sdk_version != nil {
Jiyong Park6a927c42020-01-21 02:03:43 +0900600 return sdkSpecFrom(*j.deviceProperties.Min_sdk_version)
Colin Cross83bb3162018-06-25 15:48:06 -0700601 }
602 return j.sdkVersion()
603}
604
Jiyong Park6a927c42020-01-21 02:03:43 +0900605func (j *Module) targetSdkVersion() sdkSpec {
Dan Willemsen419290a2018-10-31 15:28:47 -0700606 if j.deviceProperties.Target_sdk_version != nil {
Jiyong Park6a927c42020-01-21 02:03:43 +0900607 return sdkSpecFrom(*j.deviceProperties.Target_sdk_version)
Dan Willemsen419290a2018-10-31 15:28:47 -0700608 }
609 return j.sdkVersion()
610}
611
Jiyong Parkb02bb402019-12-03 00:43:57 +0900612func (j *Module) AvailableFor(what string) bool {
613 if what == android.AvailableToPlatform && Bool(j.deviceProperties.Hostdex) {
614 // Exception: for hostdex: true libraries, the platform variant is created
615 // even if it's not marked as available to platform. In that case, the platform
616 // variant is used only for the hostdex and not installed to the device.
617 return true
618 }
619 return j.ApexModuleBase.AvailableFor(what)
620}
621
Colin Crossbe1da472017-07-07 15:59:46 -0700622func (j *Module) deps(ctx android.BottomUpMutatorContext) {
Colin Cross1369cdb2017-09-29 17:58:17 -0700623 if ctx.Device() {
Paul Duffin250e6192019-06-07 10:44:37 +0100624 sdkDep := decodeSdkDep(ctx, sdkContext(j))
Colin Cross6d8d8c62019-10-28 15:10:03 -0700625 if sdkDep.useDefaultLibs {
626 ctx.AddVariationDependencies(nil, bootClasspathTag, config.DefaultBootclasspathLibraries...)
627 ctx.AddVariationDependencies(nil, systemModulesTag, config.DefaultSystemModules)
628 if sdkDep.hasFrameworkLibs() {
629 ctx.AddVariationDependencies(nil, libTag, config.DefaultLibraries...)
Colin Crossbe1da472017-07-07 15:59:46 -0700630 }
Colin Cross6d8d8c62019-10-28 15:10:03 -0700631 } else if sdkDep.useModule {
Colin Cross6cef4812019-10-17 14:23:50 -0700632 ctx.AddVariationDependencies(nil, bootClasspathTag, sdkDep.bootclasspath...)
Paul Duffine25c6442019-10-11 13:50:28 +0100633 ctx.AddVariationDependencies(nil, systemModulesTag, sdkDep.systemModules)
Colin Cross6cef4812019-10-17 14:23:50 -0700634 ctx.AddVariationDependencies(nil, java9LibTag, sdkDep.java9Classpath...)
Colin Cross6d8d8c62019-10-28 15:10:03 -0700635 if j.deviceProperties.EffectiveOptimizeEnabled() && sdkDep.hasStandardLibs() {
636 ctx.AddVariationDependencies(nil, proguardRaiseTag, config.DefaultBootclasspathLibraries...)
637 ctx.AddVariationDependencies(nil, proguardRaiseTag, config.DefaultLibraries...)
638 }
Colin Cross2fe66872015-03-30 17:20:39 -0700639 }
Colin Cross6d8d8c62019-10-28 15:10:03 -0700640
Nan Zhangb2b33de2018-02-23 11:18:47 -0800641 if ctx.ModuleName() == "android_stubs_current" ||
642 ctx.ModuleName() == "android_system_stubs_current" ||
Nan Zhang863f05b2018-08-07 13:41:10 -0700643 ctx.ModuleName() == "android_test_stubs_current" {
Colin Cross42d48b72018-08-29 14:10:52 -0700644 ctx.AddVariationDependencies(nil, frameworkApkTag, "framework-res")
Nan Zhangb2b33de2018-02-23 11:18:47 -0800645 }
Colin Cross2fe66872015-03-30 17:20:39 -0700646 }
Colin Cross1369cdb2017-09-29 17:58:17 -0700647
Inseob Kimac1e9862019-12-09 18:15:47 +0900648 syspropPublicStubs := syspropPublicStubs(ctx.Config())
649
650 // rewriteSyspropLibs validates if a java module can link against platform's sysprop_library,
651 // and redirects dependency to public stub depending on the link type.
652 rewriteSyspropLibs := func(libs []string, prop string) []string {
653 // make a copy
654 ret := android.CopyOf(libs)
655
656 for idx, lib := range libs {
657 stub, ok := syspropPublicStubs[lib]
658
659 if !ok {
660 continue
661 }
662
663 linkType, _ := j.getLinkType(ctx.ModuleName())
Inseob Kimc5239512020-01-14 15:36:21 +0900664 // only platform modules can use internal props
665 if linkType != javaPlatform {
Inseob Kimac1e9862019-12-09 18:15:47 +0900666 ret[idx] = stub
Inseob Kimac1e9862019-12-09 18:15:47 +0900667 }
668 }
669
670 return ret
671 }
672
673 ctx.AddVariationDependencies(nil, libTag, rewriteSyspropLibs(j.properties.Libs, "libs")...)
674 ctx.AddVariationDependencies(nil, staticLibTag, rewriteSyspropLibs(j.properties.Static_libs, "static_libs")...)
Colin Crossa4f08812018-10-02 22:03:40 -0700675
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700676 ctx.AddFarVariationDependencies(ctx.Config().BuildOSCommonTarget.Variations(), pluginTag, j.properties.Plugins...)
Artur Satayev9cf46692019-11-26 18:08:34 +0000677 ctx.AddFarVariationDependencies(ctx.Config().BuildOSCommonTarget.Variations(), exportedPluginTag, j.properties.Exported_plugins...)
Colin Crossbe9cdb82019-01-21 21:37:16 -0800678
Colin Crossfe17f6f2019-03-28 19:30:56 -0700679 android.ProtoDeps(ctx, &j.protoProperties)
Colin Cross6af17aa2017-09-20 12:59:05 -0700680 if j.hasSrcExt(".proto") {
681 protoDeps(ctx, &j.protoProperties)
682 }
Colin Cross93e85952017-08-15 13:34:18 -0700683
684 if j.hasSrcExt(".kt") {
685 // TODO(ccross): move this to a mutator pass that can tell if generated sources contain
686 // Kotlin files
Colin Cross0b03d972019-05-13 11:06:25 -0700687 ctx.AddVariationDependencies(nil, kotlinStdlibTag,
688 "kotlin-stdlib", "kotlin-stdlib-jdk7", "kotlin-stdlib-jdk8")
Colin Cross7788c122019-01-23 16:14:02 -0800689 if len(j.properties.Plugins) > 0 {
Colin Crossafbb1732019-01-17 15:42:52 -0800690 ctx.AddVariationDependencies(nil, kotlinAnnotationsTag, "kotlin-annotations")
691 }
Colin Cross93e85952017-08-15 13:34:18 -0700692 }
Colin Cross3144dfc2018-01-03 15:06:47 -0800693
Ulya Trafimovich38dfa0f2020-01-07 16:37:02 +0000694 // Framework libraries need special handling in static coverage builds: they should not have
695 // static dependency on jacoco, otherwise there would be multiple conflicting definitions of
696 // the same jacoco classes coming from different bootclasspath jars.
697 if inList(ctx.ModuleName(), config.InstrumentFrameworkModules) {
698 if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
699 j.properties.Instrument = true
700 }
701 } else if j.shouldInstrumentStatic(ctx) {
Colin Cross42d48b72018-08-29 14:10:52 -0700702 ctx.AddVariationDependencies(nil, staticLibTag, "jacocoagent")
Colin Cross3144dfc2018-01-03 15:06:47 -0800703 }
Ulya Trafimovichf3ff0102019-12-03 15:39:23 +0000704
705 // services depend on com.android.location.provider, but dependency in not registered in a Blueprint file
706 if ctx.ModuleName() == "services" {
707 ctx.AddDependency(ctx.Module(), dexpreopt.SystemServerForcedDepTag, "com.android.location.provider")
708 }
Colin Cross6af17aa2017-09-20 12:59:05 -0700709}
710
711func hasSrcExt(srcs []string, ext string) bool {
712 for _, src := range srcs {
713 if filepath.Ext(src) == ext {
714 return true
715 }
716 }
717
718 return false
719}
720
721func (j *Module) hasSrcExt(ext string) bool {
722 return hasSrcExt(j.properties.Srcs, ext)
Colin Cross2fe66872015-03-30 17:20:39 -0700723}
724
Colin Cross46c9b8b2017-06-22 16:51:17 -0700725func (j *Module) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.OptionalPath,
Colin Cross3047fa22019-04-18 10:56:44 -0700726 aidlIncludeDirs android.Paths) (string, android.Paths) {
Colin Crossc0b06f12015-04-08 13:03:43 -0700727
Colin Crossebe1a512017-11-14 13:12:14 -0800728 aidlIncludes := android.PathsForModuleSrc(ctx, j.deviceProperties.Aidl.Local_include_dirs)
729 aidlIncludes = append(aidlIncludes,
730 android.PathsForModuleSrc(ctx, j.deviceProperties.Aidl.Export_include_dirs)...)
731 aidlIncludes = append(aidlIncludes,
732 android.PathsForSource(ctx, j.deviceProperties.Aidl.Include_dirs)...)
Colin Crossc0b06f12015-04-08 13:03:43 -0700733
Colin Cross3047fa22019-04-18 10:56:44 -0700734 var flags []string
735 var deps android.Paths
Steven Moreland667f6882018-07-26 12:55:08 -0700736
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700737 if aidlPreprocess.Valid() {
738 flags = append(flags, "-p"+aidlPreprocess.String())
Colin Cross3047fa22019-04-18 10:56:44 -0700739 deps = append(deps, aidlPreprocess.Path())
740 } else if len(aidlIncludeDirs) > 0 {
Colin Cross635c3b02016-05-18 15:37:25 -0700741 flags = append(flags, android.JoinWithPrefix(aidlIncludeDirs.Strings(), "-I"))
Colin Crossc0b06f12015-04-08 13:03:43 -0700742 }
743
Colin Cross3047fa22019-04-18 10:56:44 -0700744 if len(j.exportAidlIncludeDirs) > 0 {
745 flags = append(flags, android.JoinWithPrefix(j.exportAidlIncludeDirs.Strings(), "-I"))
746 }
747
748 if len(aidlIncludes) > 0 {
749 flags = append(flags, android.JoinWithPrefix(aidlIncludes.Strings(), "-I"))
750 }
751
Colin Cross635c3b02016-05-18 15:37:25 -0700752 flags = append(flags, "-I"+android.PathForModuleSrc(ctx).String())
Colin Cross32f38982018-02-22 11:47:25 -0800753 if src := android.ExistentPathForSource(ctx, ctx.ModuleDir(), "src"); src.Valid() {
Colin Crossd48633a2017-07-13 14:41:17 -0700754 flags = append(flags, "-I"+src.String())
755 }
Colin Crossc0b06f12015-04-08 13:03:43 -0700756
Martijn Coeneneab15642018-03-09 09:29:59 +0100757 if Bool(j.deviceProperties.Aidl.Generate_traces) {
758 flags = append(flags, "-t")
759 }
760
Olivier Gaillard0a4cfbc2018-07-16 23:37:03 +0100761 if Bool(j.deviceProperties.Aidl.Generate_get_transaction_name) {
762 flags = append(flags, "--transaction_names")
763 }
764
Colin Cross3047fa22019-04-18 10:56:44 -0700765 return strings.Join(flags, " "), deps
Colin Crossc0b06f12015-04-08 13:03:43 -0700766}
767
Colin Cross32f676a2017-09-06 13:41:06 -0700768type deps struct {
Nan Zhang581fd212018-01-10 16:06:12 -0800769 classpath classpath
Colin Cross6cef4812019-10-17 14:23:50 -0700770 java9Classpath classpath
Nan Zhang581fd212018-01-10 16:06:12 -0800771 bootClasspath classpath
Colin Cross6a77c982018-06-19 22:43:34 -0700772 processorPath classpath
Colin Crossbe9cdb82019-01-21 21:37:16 -0800773 processorClasses []string
Colin Cross6ade34f2017-09-15 13:00:47 -0700774 staticJars android.Paths
Nan Zhanged19fc32017-10-19 13:06:22 -0700775 staticHeaderJars android.Paths
Colin Cross331a1212018-08-15 20:40:52 -0700776 staticResourceJars android.Paths
Colin Cross6ade34f2017-09-15 13:00:47 -0700777 aidlIncludeDirs android.Paths
Nan Zhangb2b33de2018-02-23 11:18:47 -0800778 srcs android.Paths
Colin Cross59149b62017-10-16 18:07:29 -0700779 srcJars android.Paths
Colin Crossb77043e2019-07-16 13:57:13 -0700780 systemModules *systemModules
Colin Cross6ade34f2017-09-15 13:00:47 -0700781 aidlPreprocess android.OptionalPath
Colin Cross93e85952017-08-15 13:34:18 -0700782 kotlinStdlib android.Paths
Colin Crossafbb1732019-01-17 15:42:52 -0800783 kotlinAnnotations android.Paths
Colin Crossbe9cdb82019-01-21 21:37:16 -0800784
785 disableTurbine bool
Colin Cross32f676a2017-09-06 13:41:06 -0700786}
Colin Cross2fe66872015-03-30 17:20:39 -0700787
Colin Cross54250902017-12-05 09:28:08 -0800788func checkProducesJars(ctx android.ModuleContext, dep android.SourceFileProducer) {
789 for _, f := range dep.Srcs() {
790 if f.Ext() != ".jar" {
791 ctx.ModuleErrorf("genrule %q must generate files ending with .jar to be used as a libs or static_libs dependency",
792 ctx.OtherModuleName(dep.(blueprint.Module)))
793 }
794 }
795}
796
Jiyong Park2d492942018-03-05 17:44:10 +0900797type linkType int
798
799const (
Jiyong Park50146e92020-01-30 18:00:15 +0900800 // TODO(jiyong) rename these for better readability. Make the allowed
801 // and disallowed link types explicit
Jiyong Park2d492942018-03-05 17:44:10 +0900802 javaCore linkType = iota
803 javaSdk
804 javaSystem
Jiyong Park50146e92020-01-30 18:00:15 +0900805 javaModule
Jiyong Park2d492942018-03-05 17:44:10 +0900806 javaPlatform
807)
808
Jeongik Cha75b83b02019-11-01 15:28:00 +0900809type linkTypeContext interface {
810 android.Module
811 getLinkType(name string) (ret linkType, stubs bool)
812}
813
814func (m *Module) getLinkType(name string) (ret linkType, stubs bool) {
Colin Cross83bb3162018-06-25 15:48:06 -0700815 ver := m.sdkVersion()
Colin Crossf19b9bb2018-03-26 14:42:44 -0700816 switch {
Jiyong Park46f78fb2018-10-20 16:33:17 +0900817 case name == "core.current.stubs" || name == "core.platform.api.stubs" ||
818 name == "stub-annotations" || name == "private-stub-annotations-jar" ||
Pete Gillincbff3262019-05-08 15:10:06 +0100819 name == "core-lambda-stubs" || name == "core-generated-annotation-stubs":
Jiyong Park46f78fb2018-10-20 16:33:17 +0900820 return javaCore, true
Jiyong Park6a927c42020-01-21 02:03:43 +0900821 case ver.kind == sdkCore:
Jiyong Park46f78fb2018-10-20 16:33:17 +0900822 return javaCore, false
823 case name == "android_system_stubs_current":
824 return javaSystem, true
Jiyong Park6a927c42020-01-21 02:03:43 +0900825 case ver.kind == sdkSystem:
Jiyong Park46f78fb2018-10-20 16:33:17 +0900826 return javaSystem, false
827 case name == "android_test_stubs_current":
828 return javaSystem, true
Jiyong Park6a927c42020-01-21 02:03:43 +0900829 case ver.kind == sdkTest:
Jiyong Park46f78fb2018-10-20 16:33:17 +0900830 return javaPlatform, false
831 case name == "android_stubs_current":
832 return javaSdk, true
Jiyong Park6a927c42020-01-21 02:03:43 +0900833 case ver.kind == sdkPublic:
Jiyong Park46f78fb2018-10-20 16:33:17 +0900834 return javaSdk, false
Jiyong Park50146e92020-01-30 18:00:15 +0900835 case name == "android_module_lib_stubs_current":
836 return javaModule, true
837 case ver.kind == sdkModule:
838 return javaModule, false
Jiyong Park6a927c42020-01-21 02:03:43 +0900839 case ver.kind == sdkPrivate || ver.kind == sdkNone || ver.kind == sdkCorePlatform:
Jiyong Park46f78fb2018-10-20 16:33:17 +0900840 return javaPlatform, false
Jiyong Park6a927c42020-01-21 02:03:43 +0900841 case !ver.valid():
842 panic(fmt.Errorf("sdk_version is invalid. got %q", ver.raw))
Colin Crossf19b9bb2018-03-26 14:42:44 -0700843 default:
Jiyong Park46f78fb2018-10-20 16:33:17 +0900844 return javaSdk, false
Jiyong Park2d492942018-03-05 17:44:10 +0900845 }
846}
847
Jeongik Cha75b83b02019-11-01 15:28:00 +0900848func checkLinkType(ctx android.ModuleContext, from *Module, to linkTypeContext, tag dependencyTag) {
Colin Crossf19b9bb2018-03-26 14:42:44 -0700849 if ctx.Host() {
850 return
851 }
852
Jeongik Cha75b83b02019-11-01 15:28:00 +0900853 myLinkType, stubs := from.getLinkType(ctx.ModuleName())
Jiyong Park46f78fb2018-10-20 16:33:17 +0900854 if stubs {
855 return
856 }
Jeongik Cha75b83b02019-11-01 15:28:00 +0900857 otherLinkType, _ := to.getLinkType(ctx.OtherModuleName(to))
Jiyong Park2d492942018-03-05 17:44:10 +0900858 commonMessage := "Adjust sdk_version: property of the source or target module so that target module is built with the same or smaller API set than the source."
859
860 switch myLinkType {
861 case javaCore:
862 if otherLinkType != javaCore {
863 ctx.ModuleErrorf("compiles against core Java API, but dependency %q is compiling against non-core Java APIs."+commonMessage,
Jiyong Park750e5572018-01-31 00:20:13 +0900864 ctx.OtherModuleName(to))
865 }
Jiyong Park2d492942018-03-05 17:44:10 +0900866 break
867 case javaSdk:
868 if otherLinkType != javaCore && otherLinkType != javaSdk {
869 ctx.ModuleErrorf("compiles against Android API, but dependency %q is compiling against non-public Android API."+commonMessage,
870 ctx.OtherModuleName(to))
871 }
872 break
873 case javaSystem:
Jiyong Park50146e92020-01-30 18:00:15 +0900874 if otherLinkType == javaPlatform || otherLinkType == javaModule {
Jiyong Park2d492942018-03-05 17:44:10 +0900875 ctx.ModuleErrorf("compiles against system API, but dependency %q is compiling against private API."+commonMessage,
876 ctx.OtherModuleName(to))
877 }
878 break
Jiyong Park50146e92020-01-30 18:00:15 +0900879 case javaModule:
880 if otherLinkType == javaPlatform {
881 ctx.ModuleErrorf("compiles against module API, but dependency %q is compiling against private API."+commonMessage,
882 ctx.OtherModuleName(to))
883 }
884 break
Jiyong Park2d492942018-03-05 17:44:10 +0900885 case javaPlatform:
886 // no restriction on link-type
887 break
Jiyong Park750e5572018-01-31 00:20:13 +0900888 }
889}
890
Colin Cross32f676a2017-09-06 13:41:06 -0700891func (j *Module) collectDeps(ctx android.ModuleContext) deps {
892 var deps deps
Colin Crossfc3674a2017-09-18 17:41:52 -0700893
Colin Cross300f0382018-03-06 13:11:51 -0800894 if ctx.Device() {
Colin Cross83bb3162018-06-25 15:48:06 -0700895 sdkDep := decodeSdkDep(ctx, sdkContext(j))
Colin Cross300f0382018-03-06 13:11:51 -0800896 if sdkDep.invalidVersion {
Colin Cross6cef4812019-10-17 14:23:50 -0700897 ctx.AddMissingDependencies(sdkDep.bootclasspath)
898 ctx.AddMissingDependencies(sdkDep.java9Classpath)
Colin Cross300f0382018-03-06 13:11:51 -0800899 } else if sdkDep.useFiles {
900 // sdkDep.jar is actually equivalent to turbine header.jar.
Colin Cross86a60ae2018-05-29 14:44:55 -0700901 deps.classpath = append(deps.classpath, sdkDep.jars...)
Colin Cross3047fa22019-04-18 10:56:44 -0700902 deps.aidlPreprocess = sdkDep.aidl
903 } else {
904 deps.aidlPreprocess = sdkDep.aidl
Colin Cross300f0382018-03-06 13:11:51 -0800905 }
Colin Crossfc3674a2017-09-18 17:41:52 -0700906 }
907
Colin Crossd11fcda2017-10-23 17:59:01 -0700908 ctx.VisitDirectDeps(func(module android.Module) {
Colin Cross2fe66872015-03-30 17:20:39 -0700909 otherName := ctx.OtherModuleName(module)
Colin Crossec7a0422017-07-07 14:47:12 -0700910 tag := ctx.OtherModuleDependencyTag(module)
911
Colin Crossa4f08812018-10-02 22:03:40 -0700912 if _, ok := tag.(*jniDependencyTag); ok {
Colin Crossbd01e2a2018-10-04 15:21:03 -0700913 // Handled by AndroidApp.collectAppDeps
914 return
915 }
916 if tag == certificateTag {
917 // Handled by AndroidApp.collectAppDeps
Colin Crossa4f08812018-10-02 22:03:40 -0700918 return
919 }
Jeongik Cha75b83b02019-11-01 15:28:00 +0900920 switch module.(type) {
Jeongik Chae403e9e2019-12-07 00:16:24 +0900921 case *Library, *AndroidLibrary:
Jeongik Cha75b83b02019-11-01 15:28:00 +0900922 if to, ok := module.(linkTypeContext); ok {
923 switch tag {
924 case bootClasspathTag, libTag, staticLibTag:
925 checkLinkType(ctx, j, to, tag.(dependencyTag))
926 }
Colin Crossa97c5d32018-03-28 14:58:31 -0700927 }
Jiyong Park750e5572018-01-31 00:20:13 +0900928 }
Colin Cross54250902017-12-05 09:28:08 -0800929 switch dep := module.(type) {
Colin Cross897d2ed2019-02-11 14:03:51 -0800930 case SdkLibraryDependency:
931 switch tag {
932 case libTag:
933 deps.classpath = append(deps.classpath, dep.SdkHeaderJars(ctx, j.sdkVersion())...)
934 // names of sdk libs that are directly depended are exported
935 j.exportedSdkLibs = append(j.exportedSdkLibs, otherName)
Colin Cross79c7c262019-04-17 11:11:46 -0700936 case staticLibTag:
Colin Cross897d2ed2019-02-11 14:03:51 -0800937 ctx.ModuleErrorf("dependency on java_sdk_library %q can only be in libs", otherName)
938 }
Colin Cross54250902017-12-05 09:28:08 -0800939 case Dependency:
940 switch tag {
941 case bootClasspathTag:
942 deps.bootClasspath = append(deps.bootClasspath, dep.HeaderJars()...)
Colin Cross4b964c02018-10-15 16:18:06 -0700943 case libTag, instrumentationForTag:
Colin Cross54250902017-12-05 09:28:08 -0800944 deps.classpath = append(deps.classpath, dep.HeaderJars()...)
Jiyong Park1be96912018-05-28 18:02:19 +0900945 // sdk lib names from dependencies are re-exported
946 j.exportedSdkLibs = append(j.exportedSdkLibs, dep.ExportedSdkLibs()...)
Colin Cross3047fa22019-04-18 10:56:44 -0700947 deps.aidlIncludeDirs = append(deps.aidlIncludeDirs, dep.AidlIncludeDirs()...)
Artur Satayev9cf46692019-11-26 18:08:34 +0000948 pluginJars, pluginClasses := dep.ExportedPlugins()
949 addPlugins(&deps, pluginJars, pluginClasses...)
Colin Cross6cef4812019-10-17 14:23:50 -0700950 case java9LibTag:
951 deps.java9Classpath = append(deps.java9Classpath, dep.HeaderJars()...)
Colin Cross54250902017-12-05 09:28:08 -0800952 case staticLibTag:
953 deps.classpath = append(deps.classpath, dep.HeaderJars()...)
954 deps.staticJars = append(deps.staticJars, dep.ImplementationJars()...)
955 deps.staticHeaderJars = append(deps.staticHeaderJars, dep.HeaderJars()...)
Colin Cross331a1212018-08-15 20:40:52 -0700956 deps.staticResourceJars = append(deps.staticResourceJars, dep.ResourceJars()...)
Jiyong Park1be96912018-05-28 18:02:19 +0900957 // sdk lib names from dependencies are re-exported
958 j.exportedSdkLibs = append(j.exportedSdkLibs, dep.ExportedSdkLibs()...)
Colin Cross3047fa22019-04-18 10:56:44 -0700959 deps.aidlIncludeDirs = append(deps.aidlIncludeDirs, dep.AidlIncludeDirs()...)
Artur Satayev9cf46692019-11-26 18:08:34 +0000960 pluginJars, pluginClasses := dep.ExportedPlugins()
961 addPlugins(&deps, pluginJars, pluginClasses...)
Colin Crossbe9cdb82019-01-21 21:37:16 -0800962 case pluginTag:
963 if plugin, ok := dep.(*Plugin); ok {
Colin Crossbe9cdb82019-01-21 21:37:16 -0800964 if plugin.pluginProperties.Processor_class != nil {
Artur Satayev9cf46692019-11-26 18:08:34 +0000965 addPlugins(&deps, plugin.ImplementationAndResourcesJars(), *plugin.pluginProperties.Processor_class)
966 } else {
967 addPlugins(&deps, plugin.ImplementationAndResourcesJars())
Colin Crossbe9cdb82019-01-21 21:37:16 -0800968 }
969 deps.disableTurbine = deps.disableTurbine || Bool(plugin.pluginProperties.Generates_api)
970 } else {
971 ctx.PropertyErrorf("plugins", "%q is not a java_plugin module", otherName)
972 }
Artur Satayev9cf46692019-11-26 18:08:34 +0000973 case exportedPluginTag:
974 if plugin, ok := dep.(*Plugin); ok {
975 if plugin.pluginProperties.Generates_api != nil && *plugin.pluginProperties.Generates_api {
976 ctx.PropertyErrorf("exported_plugins", "Cannot export plugins with generates_api = true, found %v", otherName)
977 }
978 j.exportedPluginJars = append(j.exportedPluginJars, plugin.ImplementationAndResourcesJars()...)
979 if plugin.pluginProperties.Processor_class != nil {
980 j.exportedPluginClasses = append(j.exportedPluginClasses, *plugin.pluginProperties.Processor_class)
981 }
982 } else {
983 ctx.PropertyErrorf("exported_plugins", "%q is not a java_plugin module", otherName)
984 }
Nan Zhangb2b33de2018-02-23 11:18:47 -0800985 case frameworkApkTag:
986 if ctx.ModuleName() == "android_stubs_current" ||
987 ctx.ModuleName() == "android_system_stubs_current" ||
Nan Zhang863f05b2018-08-07 13:41:10 -0700988 ctx.ModuleName() == "android_test_stubs_current" {
Nan Zhangb2b33de2018-02-23 11:18:47 -0800989 // framework stubs.jar need to depend on framework-res.apk, in order to pull the
990 // resource files out of there for aapt.
991 //
992 // Normally the package rule runs aapt, which includes the resource,
993 // but we're not running that in our package rule so just copy in the
994 // resource files here.
Colin Cross331a1212018-08-15 20:40:52 -0700995 deps.staticResourceJars = append(deps.staticResourceJars, dep.(*AndroidApp).exportPackage)
Nan Zhangb2b33de2018-02-23 11:18:47 -0800996 }
Colin Cross54250902017-12-05 09:28:08 -0800997 case kotlinStdlibTag:
Colin Cross0b03d972019-05-13 11:06:25 -0700998 deps.kotlinStdlib = append(deps.kotlinStdlib, dep.HeaderJars()...)
Colin Crossafbb1732019-01-17 15:42:52 -0800999 case kotlinAnnotationsTag:
1000 deps.kotlinAnnotations = dep.HeaderJars()
Colin Cross54250902017-12-05 09:28:08 -08001001 }
1002
Colin Cross54250902017-12-05 09:28:08 -08001003 case android.SourceFileProducer:
1004 switch tag {
1005 case libTag:
1006 checkProducesJars(ctx, dep)
1007 deps.classpath = append(deps.classpath, dep.Srcs()...)
1008 case staticLibTag:
1009 checkProducesJars(ctx, dep)
1010 deps.classpath = append(deps.classpath, dep.Srcs()...)
1011 deps.staticJars = append(deps.staticJars, dep.Srcs()...)
1012 deps.staticHeaderJars = append(deps.staticHeaderJars, dep.Srcs()...)
Colin Cross54250902017-12-05 09:28:08 -08001013 }
1014 default:
Colin Crossec7a0422017-07-07 14:47:12 -07001015 switch tag {
Paul Duffin68289b02019-09-20 13:50:52 +01001016 case bootClasspathTag:
1017 // If a system modules dependency has been added to the bootclasspath
1018 // then add its libs to the bootclasspath.
1019 sm := module.(*SystemModules)
1020 deps.bootClasspath = append(deps.bootClasspath, sm.headerJars...)
1021
Colin Cross1369cdb2017-09-29 17:58:17 -07001022 case systemModulesTag:
1023 if deps.systemModules != nil {
1024 panic("Found two system module dependencies")
1025 }
1026 sm := module.(*SystemModules)
Dan Willemsenff60a732019-06-13 16:52:01 +00001027 if sm.outputDir == nil || len(sm.outputDeps) == 0 {
Colin Cross1369cdb2017-09-29 17:58:17 -07001028 panic("Missing directory for system module dependency")
1029 }
Colin Crossb77043e2019-07-16 13:57:13 -07001030 deps.systemModules = &systemModules{sm.outputDir, sm.outputDeps}
Colin Cross2fe66872015-03-30 17:20:39 -07001031 }
Colin Crossec7a0422017-07-07 14:47:12 -07001032 }
Colin Cross2fe66872015-03-30 17:20:39 -07001033 })
1034
Jiyong Park1be96912018-05-28 18:02:19 +09001035 j.exportedSdkLibs = android.FirstUniqueStrings(j.exportedSdkLibs)
1036
Colin Cross32f676a2017-09-06 13:41:06 -07001037 return deps
Colin Cross2fe66872015-03-30 17:20:39 -07001038}
1039
Artur Satayev9cf46692019-11-26 18:08:34 +00001040func addPlugins(deps *deps, pluginJars android.Paths, pluginClasses ...string) {
1041 deps.processorPath = append(deps.processorPath, pluginJars...)
1042 deps.processorClasses = append(deps.processorClasses, pluginClasses...)
1043}
1044
Colin Cross1e743852019-10-28 11:37:20 -07001045func getJavaVersion(ctx android.ModuleContext, javaVersion string, sdkContext sdkContext) javaVersion {
Jiyong Park6a927c42020-01-21 02:03:43 +09001046 sdk, err := sdkContext.sdkVersion().effectiveVersion(ctx)
Colin Cross83bb3162018-06-25 15:48:06 -07001047 if err != nil {
1048 ctx.PropertyErrorf("sdk_version", "%s", err)
1049 }
Nan Zhang357466b2018-04-17 17:38:36 -07001050 if javaVersion != "" {
Colin Cross1e743852019-10-28 11:37:20 -07001051 return normalizeJavaVersion(ctx, javaVersion)
Nan Zhang357466b2018-04-17 17:38:36 -07001052 } else if ctx.Device() && sdk <= 23 {
Colin Cross1e743852019-10-28 11:37:20 -07001053 return JAVA_VERSION_7
Pete Gillina1c9e9d2019-10-17 14:52:07 +01001054 } else if ctx.Device() && sdk <= 29 {
Colin Cross1e743852019-10-28 11:37:20 -07001055 return JAVA_VERSION_8
Colin Cross6cef4812019-10-17 14:23:50 -07001056 } else if ctx.Device() && ctx.Config().UnbundledBuildUsePrebuiltSdks() {
1057 // TODO(b/142896162): once we have prebuilt system modules we can use 1.9 for unbundled builds
Colin Cross1e743852019-10-28 11:37:20 -07001058 return JAVA_VERSION_8
Nan Zhang357466b2018-04-17 17:38:36 -07001059 } else {
Colin Cross1e743852019-10-28 11:37:20 -07001060 return JAVA_VERSION_9
Nan Zhang357466b2018-04-17 17:38:36 -07001061 }
Nan Zhang357466b2018-04-17 17:38:36 -07001062}
1063
Colin Cross1e743852019-10-28 11:37:20 -07001064type javaVersion int
1065
1066const (
1067 JAVA_VERSION_UNSUPPORTED = 0
1068 JAVA_VERSION_6 = 6
1069 JAVA_VERSION_7 = 7
1070 JAVA_VERSION_8 = 8
1071 JAVA_VERSION_9 = 9
1072)
1073
1074func (v javaVersion) String() string {
1075 switch v {
1076 case JAVA_VERSION_6:
1077 return "1.6"
1078 case JAVA_VERSION_7:
1079 return "1.7"
1080 case JAVA_VERSION_8:
1081 return "1.8"
1082 case JAVA_VERSION_9:
1083 return "1.9"
1084 default:
1085 return "unsupported"
1086 }
1087}
1088
1089// Returns true if javac targeting this version uses system modules instead of a bootclasspath.
1090func (v javaVersion) usesJavaModules() bool {
1091 return v >= 9
1092}
1093
1094func normalizeJavaVersion(ctx android.BaseModuleContext, javaVersion string) javaVersion {
Pete Gillin4e8b48a2019-07-12 13:16:17 +01001095 switch javaVersion {
1096 case "1.6", "6":
Colin Cross1e743852019-10-28 11:37:20 -07001097 return JAVA_VERSION_6
Pete Gillin4e8b48a2019-07-12 13:16:17 +01001098 case "1.7", "7":
Colin Cross1e743852019-10-28 11:37:20 -07001099 return JAVA_VERSION_7
Pete Gillin4e8b48a2019-07-12 13:16:17 +01001100 case "1.8", "8":
Colin Cross1e743852019-10-28 11:37:20 -07001101 return JAVA_VERSION_8
Pete Gillin4e8b48a2019-07-12 13:16:17 +01001102 case "1.9", "9":
Colin Cross1e743852019-10-28 11:37:20 -07001103 return JAVA_VERSION_9
Pete Gillin4e8b48a2019-07-12 13:16:17 +01001104 case "10", "11":
1105 ctx.PropertyErrorf("java_version", "Java language levels above 9 are not supported")
Colin Cross1e743852019-10-28 11:37:20 -07001106 return JAVA_VERSION_UNSUPPORTED
Pete Gillin4e8b48a2019-07-12 13:16:17 +01001107 default:
1108 ctx.PropertyErrorf("java_version", "Unrecognized Java language level")
Colin Cross1e743852019-10-28 11:37:20 -07001109 return JAVA_VERSION_UNSUPPORTED
Pete Gillin4e8b48a2019-07-12 13:16:17 +01001110 }
1111}
1112
Nan Zhanged19fc32017-10-19 13:06:22 -07001113func (j *Module) collectBuilderFlags(ctx android.ModuleContext, deps deps) javaBuilderFlags {
Colin Crossc0b06f12015-04-08 13:03:43 -07001114
Colin Crossf03c82b2015-04-13 13:53:40 -07001115 var flags javaBuilderFlags
1116
Tobias Thierer06dd04f2018-09-11 16:21:05 +01001117 // javaVersion flag.
1118 flags.javaVersion = getJavaVersion(ctx, String(j.properties.Java_version), sdkContext(j))
1119
Nan Zhanged19fc32017-10-19 13:06:22 -07001120 // javac flags.
Colin Crossf03c82b2015-04-13 13:53:40 -07001121 javacFlags := j.properties.Javacflags
Colin Cross1e743852019-10-28 11:37:20 -07001122 if flags.javaVersion.usesJavaModules() {
Colin Cross1369cdb2017-09-29 17:58:17 -07001123 javacFlags = append(javacFlags, j.properties.Openjdk9.Javacflags...)
Nan Zhanged19fc32017-10-19 13:06:22 -07001124 }
Colin Cross6510f912017-11-29 00:27:14 -08001125 if ctx.Config().MinimizeJavaDebugInfo() {
Colin Cross126a25c2017-10-31 13:55:34 -07001126 // Override the -g flag passed globally to remove local variable debug info to reduce
1127 // disk and memory usage.
1128 javacFlags = append(javacFlags, "-g:source,lines")
1129 }
Colin Crossc228a702019-11-06 16:18:05 -08001130 javacFlags = append(javacFlags, "-Xlint:-dep-ann")
Colin Cross64162712017-08-08 13:17:59 -07001131
Colin Cross66548102018-06-19 22:47:35 -07001132 if ctx.Config().RunErrorProne() {
1133 if config.ErrorProneClasspath == nil {
1134 ctx.ModuleErrorf("cannot build with Error Prone, missing external/error_prone?")
1135 }
1136
1137 errorProneFlags := []string{
1138 "-Xplugin:ErrorProne",
1139 "${config.ErrorProneChecks}",
1140 }
1141 errorProneFlags = append(errorProneFlags, j.properties.Errorprone.Javacflags...)
1142
1143 flags.errorProneExtraJavacFlags = "${config.ErrorProneFlags} " +
1144 "'" + strings.Join(errorProneFlags, " ") + "'"
1145 flags.errorProneProcessorPath = classpath(android.PathsForSource(ctx, config.ErrorProneClasspath))
Andreas Gampef3e5b552018-01-22 21:27:21 -08001146 }
1147
Nan Zhanged19fc32017-10-19 13:06:22 -07001148 // classpath
Nan Zhang581fd212018-01-10 16:06:12 -08001149 flags.bootClasspath = append(flags.bootClasspath, deps.bootClasspath...)
1150 flags.classpath = append(flags.classpath, deps.classpath...)
Colin Cross6cef4812019-10-17 14:23:50 -07001151 flags.java9Classpath = append(flags.java9Classpath, deps.java9Classpath...)
Colin Cross6a77c982018-06-19 22:43:34 -07001152 flags.processorPath = append(flags.processorPath, deps.processorPath...)
Colin Cross7fdd2b72018-01-02 18:14:25 -08001153
Colin Crossbe9cdb82019-01-21 21:37:16 -08001154 flags.processor = strings.Join(deps.processorClasses, ",")
1155
Colin Cross1e743852019-10-28 11:37:20 -07001156 if len(flags.bootClasspath) == 0 && ctx.Host() && !flags.javaVersion.usesJavaModules() &&
1157 decodeSdkDep(ctx, sdkContext(j)).hasStandardLibs() {
Colin Cross7fdd2b72018-01-02 18:14:25 -08001158 // Give host-side tools a version of OpenJDK's standard libraries
1159 // close to what they're targeting. As of Dec 2017, AOSP is only
1160 // bundling OpenJDK 8 and 9, so nothing < 8 is available.
1161 //
1162 // When building with OpenJDK 8, the following should have no
1163 // effect since those jars would be available by default.
1164 //
1165 // When building with OpenJDK 9 but targeting a version < 1.8,
1166 // putting them on the bootclasspath means that:
1167 // a) code can't (accidentally) refer to OpenJDK 9 specific APIs
1168 // b) references to existing APIs are not reinterpreted in an
1169 // OpenJDK 9-specific way, eg. calls to subclasses of
1170 // java.nio.Buffer as in http://b/70862583
1171 java8Home := ctx.Config().Getenv("ANDROID_JAVA8_HOME")
1172 flags.bootClasspath = append(flags.bootClasspath,
1173 android.PathForSource(ctx, java8Home, "jre/lib/jce.jar"),
1174 android.PathForSource(ctx, java8Home, "jre/lib/rt.jar"))
Nan Zhang5f8cb422018-02-06 10:34:32 -08001175 if Bool(j.properties.Use_tools_jar) {
1176 flags.bootClasspath = append(flags.bootClasspath,
1177 android.PathForSource(ctx, java8Home, "lib/tools.jar"))
1178 }
Colin Cross7fdd2b72018-01-02 18:14:25 -08001179 }
1180
Colin Cross1e743852019-10-28 11:37:20 -07001181 if j.properties.Patch_module != nil && flags.javaVersion.usesJavaModules() {
Jaewoong Jung38e4fb22018-12-12 09:01:34 -08001182 // Manually specify build directory in case it is not under the repo root.
1183 // (javac doesn't seem to expand into symbolc links when searching for patch-module targets, so
1184 // just adding a symlink under the root doesn't help.)
1185 patchPaths := ".:" + ctx.Config().BuildDir()
1186 classPath := flags.classpath.FormJavaClassPath("")
1187 if classPath != "" {
1188 patchPaths += ":" + classPath
1189 }
1190 javacFlags = append(javacFlags, "--patch-module="+String(j.properties.Patch_module)+"="+patchPaths)
Colin Cross81440082018-08-15 20:21:55 -07001191 }
1192
Nan Zhanged19fc32017-10-19 13:06:22 -07001193 // systemModules
Colin Crossb77043e2019-07-16 13:57:13 -07001194 flags.systemModules = deps.systemModules
Colin Cross1369cdb2017-09-29 17:58:17 -07001195
Nan Zhanged19fc32017-10-19 13:06:22 -07001196 // aidl flags.
Colin Cross3047fa22019-04-18 10:56:44 -07001197 flags.aidlFlags, flags.aidlDeps = j.aidlFlags(ctx, deps.aidlPreprocess, deps.aidlIncludeDirs)
Colin Cross2fe66872015-03-30 17:20:39 -07001198
Colin Cross81440082018-08-15 20:21:55 -07001199 if len(javacFlags) > 0 {
1200 // optimization.
1201 ctx.Variable(pctx, "javacFlags", strings.Join(javacFlags, " "))
1202 flags.javacFlags = "$javacFlags"
1203 }
1204
Nan Zhanged19fc32017-10-19 13:06:22 -07001205 return flags
1206}
Colin Crossc0b06f12015-04-08 13:03:43 -07001207
Jaewoong Junga24af3b2019-05-13 09:23:20 -07001208func (j *Module) compile(ctx android.ModuleContext, aaptSrcJar android.Path) {
Colin Crossebe1a512017-11-14 13:12:14 -08001209 j.exportAidlIncludeDirs = android.PathsForModuleSrc(ctx, j.deviceProperties.Aidl.Export_include_dirs)
Nan Zhanged19fc32017-10-19 13:06:22 -07001210
1211 deps := j.collectDeps(ctx)
1212 flags := j.collectBuilderFlags(ctx, deps)
1213
Colin Cross1e743852019-10-28 11:37:20 -07001214 if flags.javaVersion.usesJavaModules() {
Nan Zhanged19fc32017-10-19 13:06:22 -07001215 j.properties.Srcs = append(j.properties.Srcs, j.properties.Openjdk9.Srcs...)
1216 }
Colin Cross8a497952019-03-05 22:25:09 -08001217 srcFiles := android.PathsForModuleSrcExcludes(ctx, j.properties.Srcs, j.properties.Exclude_srcs)
Colin Cross6af17aa2017-09-20 12:59:05 -07001218 if hasSrcExt(srcFiles.Strings(), ".proto") {
Colin Cross0f2ee152017-12-14 15:22:43 -08001219 flags = protoFlags(ctx, &j.properties, &j.protoProperties, flags)
Colin Cross6af17aa2017-09-20 12:59:05 -07001220 }
1221
Colin Crossaf050172017-11-15 23:01:59 -08001222 srcFiles = j.genSources(ctx, srcFiles, flags)
1223
1224 srcJars := srcFiles.FilterByExt(".srcjar")
Colin Cross59149b62017-10-16 18:07:29 -07001225 srcJars = append(srcJars, deps.srcJars...)
Jaewoong Junga24af3b2019-05-13 09:23:20 -07001226 if aaptSrcJar != nil {
1227 srcJars = append(srcJars, aaptSrcJar)
1228 }
Colin Crossb7a63242015-04-16 14:09:14 -07001229
Steven Morelandc4efd9c2019-01-18 11:51:25 -08001230 if j.properties.Jarjar_rules != nil {
Colin Cross8a497952019-03-05 22:25:09 -08001231 j.expandJarjarRules = android.PathForModuleSrc(ctx, *j.properties.Jarjar_rules)
Steven Morelandc4efd9c2019-01-18 11:51:25 -08001232 }
1233
Colin Cross1ee23172017-10-18 14:44:18 -07001234 jarName := ctx.ModuleName() + ".jar"
1235
Przemyslaw Szczepaniak4b5fe9d2018-02-13 14:32:54 +00001236 javaSrcFiles := srcFiles.FilterByExt(".java")
1237 var uniqueSrcFiles android.Paths
1238 set := make(map[string]bool)
1239 for _, v := range javaSrcFiles {
1240 if _, found := set[v.String()]; !found {
1241 set[v.String()] = true
1242 uniqueSrcFiles = append(uniqueSrcFiles, v)
1243 }
1244 }
1245
patricktu242faad2019-09-24 15:41:30 +08001246 // Collect .java files for AIDEGen
1247 j.expandIDEInfoCompiledSrcs = append(j.expandIDEInfoCompiledSrcs, uniqueSrcFiles.Strings()...)
1248
Colin Cross55f63ea2018-08-27 12:37:09 -07001249 var kotlinJars android.Paths
1250
Colin Cross93e85952017-08-15 13:34:18 -07001251 if srcFiles.HasExt(".kt") {
Zoran Jovanovic8736ce22018-08-21 17:10:29 +02001252 // user defined kotlin flags.
1253 kotlincFlags := j.properties.Kotlincflags
1254 CheckKotlincFlags(ctx, kotlincFlags)
1255
Colin Cross93e85952017-08-15 13:34:18 -07001256 // If there are kotlin files, compile them first but pass all the kotlin and java files
1257 // kotlinc will use the java files to resolve types referenced by the kotlin files, but
1258 // won't emit any classes for them.
Zoran Jovanovic8736ce22018-08-21 17:10:29 +02001259 kotlincFlags = append(kotlincFlags, "-no-stdlib")
Colin Cross93e85952017-08-15 13:34:18 -07001260 if ctx.Device() {
Zoran Jovanovic8736ce22018-08-21 17:10:29 +02001261 kotlincFlags = append(kotlincFlags, "-no-jdk")
1262 }
1263 if len(kotlincFlags) > 0 {
1264 // optimization.
1265 ctx.Variable(pctx, "kotlincFlags", strings.Join(kotlincFlags, " "))
1266 flags.kotlincFlags += "$kotlincFlags"
Colin Cross93e85952017-08-15 13:34:18 -07001267 }
1268
Przemyslaw Szczepaniak4b5fe9d2018-02-13 14:32:54 +00001269 var kotlinSrcFiles android.Paths
1270 kotlinSrcFiles = append(kotlinSrcFiles, uniqueSrcFiles...)
1271 kotlinSrcFiles = append(kotlinSrcFiles, srcFiles.FilterByExt(".kt")...)
1272
patricktu242faad2019-09-24 15:41:30 +08001273 // Collect .kt files for AIDEGen
1274 j.expandIDEInfoCompiledSrcs = append(j.expandIDEInfoCompiledSrcs, srcFiles.FilterByExt(".kt").Strings()...)
1275
Colin Crossafbb1732019-01-17 15:42:52 -08001276 flags.classpath = append(flags.classpath, deps.kotlinStdlib...)
1277 flags.classpath = append(flags.classpath, deps.kotlinAnnotations...)
1278
1279 flags.kotlincClasspath = append(flags.kotlincClasspath, flags.bootClasspath...)
1280 flags.kotlincClasspath = append(flags.kotlincClasspath, flags.classpath...)
1281
1282 if len(flags.processorPath) > 0 {
1283 // Use kapt for annotation processing
1284 kaptSrcJar := android.PathForModuleOut(ctx, "kapt", "kapt-sources.jar")
1285 kotlinKapt(ctx, kaptSrcJar, kotlinSrcFiles, srcJars, flags)
1286 srcJars = append(srcJars, kaptSrcJar)
1287 // Disable annotation processing in javac, it's already been handled by kapt
1288 flags.processorPath = nil
Colin Cross3a3e94c2019-01-23 15:39:50 -08001289 flags.processor = ""
Colin Crossafbb1732019-01-17 15:42:52 -08001290 }
Colin Cross93e85952017-08-15 13:34:18 -07001291
Colin Cross1ee23172017-10-18 14:44:18 -07001292 kotlinJar := android.PathForModuleOut(ctx, "kotlin", jarName)
Colin Cross21fc9bb2019-01-18 15:05:09 -08001293 kotlinCompile(ctx, kotlinJar, kotlinSrcFiles, srcJars, flags)
Colin Cross93e85952017-08-15 13:34:18 -07001294 if ctx.Failed() {
1295 return
1296 }
1297
1298 // Make javac rule depend on the kotlinc rule
1299 flags.classpath = append(flags.classpath, kotlinJar)
Przemyslaw Szczepaniak66c0c402018-03-08 13:21:55 +00001300
Colin Cross93e85952017-08-15 13:34:18 -07001301 // Jar kotlin classes into the final jar after javac
Colin Cross55f63ea2018-08-27 12:37:09 -07001302 kotlinJars = append(kotlinJars, kotlinJar)
Colin Cross9b38aef2018-08-27 15:42:25 -07001303 kotlinJars = append(kotlinJars, deps.kotlinStdlib...)
Colin Cross93e85952017-08-15 13:34:18 -07001304 }
1305
Colin Cross55f63ea2018-08-27 12:37:09 -07001306 jars := append(android.Paths(nil), kotlinJars...)
1307
Colin Cross5ab4e6d2017-11-22 16:20:45 -08001308 // Store the list of .java files that was passed to javac
1309 j.compiledJavaSrcs = uniqueSrcFiles
1310 j.compiledSrcJars = srcJars
1311
Nan Zhang61eaedb2017-11-02 13:28:15 -07001312 enable_sharding := false
Colin Crossbe9cdb82019-01-21 21:37:16 -08001313 if ctx.Device() && !ctx.Config().IsEnvFalse("TURBINE_ENABLED") && !deps.disableTurbine {
Nan Zhang61eaedb2017-11-02 13:28:15 -07001314 if j.properties.Javac_shard_size != nil && *(j.properties.Javac_shard_size) > 0 {
1315 enable_sharding = true
Ashley Rosee36efcf2019-01-16 17:34:08 -05001316 // Formerly, there was a check here that prevented annotation processors
1317 // from being used when sharding was enabled, as some annotation processors
1318 // do not function correctly in sharded environments. It was removed to
1319 // allow for the use of annotation processors that do function correctly
1320 // with sharding enabled. See: b/77284273.
Nan Zhang61eaedb2017-11-02 13:28:15 -07001321 }
Colin Cross55f63ea2018-08-27 12:37:09 -07001322 j.headerJarFile = j.compileJavaHeader(ctx, uniqueSrcFiles, srcJars, deps, flags, jarName, kotlinJars)
Colin Crossf19b9bb2018-03-26 14:42:44 -07001323 if ctx.Failed() {
1324 return
Nan Zhanged19fc32017-10-19 13:06:22 -07001325 }
1326 }
Colin Cross8eadbf02017-10-24 17:46:00 -07001327 if len(uniqueSrcFiles) > 0 || len(srcJars) > 0 {
Colin Crossd6891432017-09-27 17:39:56 -07001328 var extraJarDeps android.Paths
Colin Cross66548102018-06-19 22:47:35 -07001329 if ctx.Config().RunErrorProne() {
Colin Crossc6bbef32017-08-14 14:16:06 -07001330 // If error-prone is enabled, add an additional rule to compile the java files into
1331 // a separate set of classes (so that they don't overwrite the normal ones and require
Colin Crossd6891432017-09-27 17:39:56 -07001332 // a rebuild when error-prone is turned off).
Colin Crossc6bbef32017-08-14 14:16:06 -07001333 // TODO(ccross): Once we always compile with javac9 we may be able to conditionally
1334 // enable error-prone without affecting the output class files.
Colin Cross1ee23172017-10-18 14:44:18 -07001335 errorprone := android.PathForModuleOut(ctx, "errorprone", jarName)
Nan Zhang61eaedb2017-11-02 13:28:15 -07001336 RunErrorProne(ctx, errorprone, uniqueSrcFiles, srcJars, flags)
Colin Crossc6bbef32017-08-14 14:16:06 -07001337 extraJarDeps = append(extraJarDeps, errorprone)
1338 }
1339
Nan Zhang61eaedb2017-11-02 13:28:15 -07001340 if enable_sharding {
Nan Zhang581fd212018-01-10 16:06:12 -08001341 flags.classpath = append(flags.classpath, j.headerJarFile)
Nan Zhang61eaedb2017-11-02 13:28:15 -07001342 shardSize := int(*(j.properties.Javac_shard_size))
1343 var shardSrcs []android.Paths
1344 if len(uniqueSrcFiles) > 0 {
Colin Cross0a2f7192019-09-23 14:33:09 -07001345 shardSrcs = android.ShardPaths(uniqueSrcFiles, shardSize)
Nan Zhang61eaedb2017-11-02 13:28:15 -07001346 for idx, shardSrc := range shardSrcs {
Colin Cross3b706fd2019-09-05 16:44:18 -07001347 classes := j.compileJavaClasses(ctx, jarName, idx, shardSrc,
1348 nil, flags, extraJarDeps)
Nan Zhang61eaedb2017-11-02 13:28:15 -07001349 jars = append(jars, classes)
1350 }
1351 }
1352 if len(srcJars) > 0 {
Colin Cross3b706fd2019-09-05 16:44:18 -07001353 classes := j.compileJavaClasses(ctx, jarName, len(shardSrcs),
1354 nil, srcJars, flags, extraJarDeps)
Nan Zhang61eaedb2017-11-02 13:28:15 -07001355 jars = append(jars, classes)
1356 }
1357 } else {
Colin Cross3b706fd2019-09-05 16:44:18 -07001358 classes := j.compileJavaClasses(ctx, jarName, -1, uniqueSrcFiles, srcJars, flags, extraJarDeps)
Nan Zhang61eaedb2017-11-02 13:28:15 -07001359 jars = append(jars, classes)
1360 }
Colin Crossd6891432017-09-27 17:39:56 -07001361 if ctx.Failed() {
1362 return
1363 }
Colin Cross2fe66872015-03-30 17:20:39 -07001364 }
1365
Colin Cross0c4ce212019-05-03 15:28:19 -07001366 j.srcJarArgs, j.srcJarDeps = resourcePathsToJarArgs(srcFiles), srcFiles
1367
1368 var includeSrcJar android.WritablePath
1369 if Bool(j.properties.Include_srcs) {
1370 includeSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+".srcjar")
1371 TransformResourcesToJar(ctx, includeSrcJar, j.srcJarArgs, j.srcJarDeps)
1372 }
1373
Colin Crosscedd4762018-09-13 11:26:19 -07001374 dirArgs, dirDeps := ResourceDirsToJarArgs(ctx, j.properties.Java_resource_dirs,
1375 j.properties.Exclude_java_resource_dirs, j.properties.Exclude_java_resources)
Colin Cross0f37af02017-09-27 17:42:05 -07001376 fileArgs, fileDeps := ResourceFilesToJarArgs(ctx, j.properties.Java_resources, j.properties.Exclude_java_resources)
Colin Cross988708c2019-05-06 14:04:11 -07001377 extraArgs, extraDeps := resourcePathsToJarArgs(j.extraResources), j.extraResources
Colin Cross0f37af02017-09-27 17:42:05 -07001378
1379 var resArgs []string
1380 var resDeps android.Paths
1381
1382 resArgs = append(resArgs, dirArgs...)
1383 resDeps = append(resDeps, dirDeps...)
1384
1385 resArgs = append(resArgs, fileArgs...)
1386 resDeps = append(resDeps, fileDeps...)
1387
Colin Cross988708c2019-05-06 14:04:11 -07001388 resArgs = append(resArgs, extraArgs...)
1389 resDeps = append(resDeps, extraDeps...)
1390
Colin Cross40a36712017-09-27 17:41:35 -07001391 if len(resArgs) > 0 {
Colin Cross1ee23172017-10-18 14:44:18 -07001392 resourceJar := android.PathForModuleOut(ctx, "res", jarName)
Colin Crosse9a275b2017-10-16 17:09:48 -07001393 TransformResourcesToJar(ctx, resourceJar, resArgs, resDeps)
Colin Cross331a1212018-08-15 20:40:52 -07001394 j.resourceJar = resourceJar
Colin Cross65bf4f22015-04-03 16:54:17 -07001395 if ctx.Failed() {
1396 return
1397 }
1398 }
1399
Colin Cross0c4ce212019-05-03 15:28:19 -07001400 var resourceJars android.Paths
1401 if j.resourceJar != nil {
1402 resourceJars = append(resourceJars, j.resourceJar)
1403 }
1404 if Bool(j.properties.Include_srcs) {
1405 resourceJars = append(resourceJars, includeSrcJar)
1406 }
1407 resourceJars = append(resourceJars, deps.staticResourceJars...)
Colin Cross331a1212018-08-15 20:40:52 -07001408
Colin Cross0c4ce212019-05-03 15:28:19 -07001409 if len(resourceJars) > 1 {
Colin Cross331a1212018-08-15 20:40:52 -07001410 combinedJar := android.PathForModuleOut(ctx, "res-combined", jarName)
Colin Cross0c4ce212019-05-03 15:28:19 -07001411 TransformJarsToJar(ctx, combinedJar, "for resources", resourceJars, android.OptionalPath{},
Colin Cross331a1212018-08-15 20:40:52 -07001412 false, nil, nil)
1413 j.resourceJar = combinedJar
Colin Cross0c4ce212019-05-03 15:28:19 -07001414 } else if len(resourceJars) == 1 {
1415 j.resourceJar = resourceJars[0]
Colin Cross331a1212018-08-15 20:40:52 -07001416 }
1417
Jaewoong Junga24af3b2019-05-13 09:23:20 -07001418 if len(deps.staticJars) > 0 {
1419 jars = append(jars, deps.staticJars...)
Jaewoong Junga24af3b2019-05-13 09:23:20 -07001420 }
Colin Cross0a6e0072017-08-30 14:24:55 -07001421
Colin Cross094054a2018-10-17 15:10:48 -07001422 manifest := j.overrideManifest
1423 if !manifest.Valid() && j.properties.Manifest != nil {
Colin Cross8a497952019-03-05 22:25:09 -08001424 manifest = android.OptionalPathForPath(android.PathForModuleSrc(ctx, *j.properties.Manifest))
Colin Cross366938f2017-12-11 16:29:02 -08001425 }
Colin Cross635acc92017-09-12 22:50:46 -07001426
Colin Cross8a497952019-03-05 22:25:09 -08001427 services := android.PathsForModuleSrc(ctx, j.properties.Services)
Alex Light7f004a72019-02-21 13:27:37 -08001428 if len(services) > 0 {
1429 servicesJar := android.PathForModuleOut(ctx, "services", jarName)
1430 var zipargs []string
1431 for _, file := range services {
1432 serviceFile := file.String()
1433 zipargs = append(zipargs, "-C", filepath.Dir(serviceFile), "-f", serviceFile)
1434 }
1435 ctx.Build(pctx, android.BuildParams{
1436 Rule: zip,
1437 Output: servicesJar,
1438 Implicits: services,
1439 Args: map[string]string{
Colin Cross0b9f31f2019-02-28 11:00:01 -08001440 "jarArgs": "-P META-INF/services/ " + strings.Join(proptools.NinjaAndShellEscapeList(zipargs), " "),
Alex Light7f004a72019-02-21 13:27:37 -08001441 },
1442 })
1443 jars = append(jars, servicesJar)
1444 }
1445
Colin Cross0a6e0072017-08-30 14:24:55 -07001446 // Combine the classes built from sources, any manifests, and any static libraries into
Nan Zhanged19fc32017-10-19 13:06:22 -07001447 // classes.jar. If there is only one input jar this step will be skipped.
Colin Cross3063b782018-08-15 11:19:12 -07001448 var outputFile android.ModuleOutPath
Colin Crosse9a275b2017-10-16 17:09:48 -07001449
1450 if len(jars) == 1 && !manifest.Valid() {
Colin Cross3063b782018-08-15 11:19:12 -07001451 if moduleOutPath, ok := jars[0].(android.ModuleOutPath); ok {
1452 // Optimization: skip the combine step if there is nothing to do
1453 // TODO(ccross): this leaves any module-info.class files, but those should only come from
1454 // prebuilt dependencies until we support modules in the platform build, so there shouldn't be
1455 // any if len(jars) == 1.
1456 outputFile = moduleOutPath
1457 } else {
1458 combinedJar := android.PathForModuleOut(ctx, "combined", jarName)
1459 ctx.Build(pctx, android.BuildParams{
1460 Rule: android.Cp,
1461 Input: jars[0],
1462 Output: combinedJar,
1463 })
1464 outputFile = combinedJar
1465 }
Colin Crosse9a275b2017-10-16 17:09:48 -07001466 } else {
Colin Cross1ee23172017-10-18 14:44:18 -07001467 combinedJar := android.PathForModuleOut(ctx, "combined", jarName)
Colin Cross37f6d792018-07-12 12:28:41 -07001468 TransformJarsToJar(ctx, combinedJar, "for javac", jars, manifest,
Colin Cross9b38aef2018-08-27 15:42:25 -07001469 false, nil, nil)
Colin Crosse9a275b2017-10-16 17:09:48 -07001470 outputFile = combinedJar
1471 }
Colin Cross0a6e0072017-08-30 14:24:55 -07001472
Colin Cross331a1212018-08-15 20:40:52 -07001473 // jarjar implementation jar if necessary
Steven Morelandc4efd9c2019-01-18 11:51:25 -08001474 if j.expandJarjarRules != nil {
Colin Cross8649b262017-09-27 18:03:17 -07001475 // Transform classes.jar into classes-jarjar.jar
Colin Cross1ee23172017-10-18 14:44:18 -07001476 jarjarFile := android.PathForModuleOut(ctx, "jarjar", jarName)
Steven Morelandc4efd9c2019-01-18 11:51:25 -08001477 TransformJarJar(ctx, jarjarFile, outputFile, j.expandJarjarRules)
Colin Crosse9a275b2017-10-16 17:09:48 -07001478 outputFile = jarjarFile
Colin Cross331a1212018-08-15 20:40:52 -07001479
1480 // jarjar resource jar if necessary
1481 if j.resourceJar != nil {
1482 resourceJarJarFile := android.PathForModuleOut(ctx, "res-jarjar", jarName)
Steven Morelandc4efd9c2019-01-18 11:51:25 -08001483 TransformJarJar(ctx, resourceJarJarFile, j.resourceJar, j.expandJarjarRules)
Colin Cross331a1212018-08-15 20:40:52 -07001484 j.resourceJar = resourceJarJarFile
1485 }
1486
Colin Cross0a6e0072017-08-30 14:24:55 -07001487 if ctx.Failed() {
1488 return
1489 }
1490 }
Vladimir Marko0975ee02019-04-02 10:29:55 +01001491
1492 // Check package restrictions if necessary.
1493 if len(j.properties.Permitted_packages) > 0 {
1494 // Check packages and copy to package-checked file.
1495 pkgckFile := android.PathForModuleOut(ctx, "package-check.stamp")
1496 CheckJarPackages(ctx, pkgckFile, outputFile, j.properties.Permitted_packages)
1497 j.additionalCheckedModules = append(j.additionalCheckedModules, pkgckFile)
1498
1499 if ctx.Failed() {
1500 return
1501 }
1502 }
1503
Nan Zhanged19fc32017-10-19 13:06:22 -07001504 j.implementationJarFile = outputFile
1505 if j.headerJarFile == nil {
1506 j.headerJarFile = j.implementationJarFile
1507 }
Colin Cross2fe66872015-03-30 17:20:39 -07001508
Colin Cross3144dfc2018-01-03 15:06:47 -08001509 if j.shouldInstrument(ctx) {
Colin Crosscb933592017-11-22 13:49:43 -08001510 outputFile = j.instrument(ctx, flags, outputFile, jarName)
1511 }
1512
Colin Cross331a1212018-08-15 20:40:52 -07001513 // merge implementation jar with resources if necessary
1514 implementationAndResourcesJar := outputFile
1515 if j.resourceJar != nil {
Colin Cross08a409d2019-04-29 10:22:44 -07001516 jars := android.Paths{j.resourceJar, implementationAndResourcesJar}
Colin Cross331a1212018-08-15 20:40:52 -07001517 combinedJar := android.PathForModuleOut(ctx, "withres", jarName)
Colin Cross08a409d2019-04-29 10:22:44 -07001518 TransformJarsToJar(ctx, combinedJar, "for resources", jars, manifest,
Colin Cross331a1212018-08-15 20:40:52 -07001519 false, nil, nil)
1520 implementationAndResourcesJar = combinedJar
1521 }
1522
1523 j.implementationAndResourcesJar = implementationAndResourcesJar
1524
Jiyong Park6b21c7d2020-02-11 09:16:01 +09001525 // Enable dex compilation for the APEX variants, unless it is disabled explicitly
1526 if android.DirectlyInAnyApex(ctx, ctx.ModuleName()) && !j.IsForPlatform() {
1527 if j.deviceProperties.Compile_dex == nil {
1528 j.deviceProperties.Compile_dex = proptools.BoolPtr(true)
1529 }
1530 if j.deviceProperties.Hostdex == nil {
1531 j.deviceProperties.Hostdex = proptools.BoolPtr(true)
1532 }
1533 }
1534
Jaewoong Jungc27ab662019-05-30 15:51:14 -07001535 if ctx.Device() && j.hasCode(ctx) &&
Jaewoong Junga24af3b2019-05-13 09:23:20 -07001536 (Bool(j.properties.Installable) || Bool(j.deviceProperties.Compile_dex)) {
Colin Cross8faf8fc2019-01-16 15:15:52 -08001537 // Dex compilation
Colin Cross3063b782018-08-15 11:19:12 -07001538 var dexOutputFile android.ModuleOutPath
David Brazdil17ef5632018-06-27 10:27:45 +01001539 dexOutputFile = j.compileDex(ctx, flags, outputFile, jarName)
Colin Cross2fe66872015-03-30 17:20:39 -07001540 if ctx.Failed() {
1541 return
1542 }
Colin Cross331a1212018-08-15 20:40:52 -07001543
Jiyong Park09cb6292019-07-15 15:29:23 +09001544 // Hidden API CSV generation and dex encoding
1545 dexOutputFile = j.hiddenAPI.hiddenAPI(ctx, dexOutputFile, j.implementationJarFile,
1546 j.deviceProperties.UncompressDex)
Colin Cross8faf8fc2019-01-16 15:15:52 -08001547
Colin Cross331a1212018-08-15 20:40:52 -07001548 // merge dex jar with resources if necessary
1549 if j.resourceJar != nil {
1550 jars := android.Paths{dexOutputFile, j.resourceJar}
1551 combinedJar := android.PathForModuleOut(ctx, "dex-withres", jarName)
1552 TransformJarsToJar(ctx, combinedJar, "for dex resources", jars, android.OptionalPath{},
1553 false, nil, nil)
Nicolas Geoffrayf3438722019-01-23 15:57:21 +00001554 if j.deviceProperties.UncompressDex {
1555 combinedAlignedJar := android.PathForModuleOut(ctx, "dex-withres-aligned", jarName)
1556 TransformZipAlign(ctx, combinedAlignedJar, combinedJar)
1557 dexOutputFile = combinedAlignedJar
1558 } else {
1559 dexOutputFile = combinedJar
1560 }
Colin Cross331a1212018-08-15 20:40:52 -07001561 }
1562
1563 j.dexJarFile = dexOutputFile
1564
Colin Cross8faf8fc2019-01-16 15:15:52 -08001565 // Dexpreopting
Colin Cross43f08db2018-11-12 10:13:39 -08001566 dexOutputFile = j.dexpreopt(ctx, dexOutputFile)
1567
1568 j.maybeStrippedDexJarFile = dexOutputFile
1569
Colin Cross3063b782018-08-15 11:19:12 -07001570 outputFile = dexOutputFile
Colin Cross43f08db2018-11-12 10:13:39 -08001571
1572 if ctx.Failed() {
1573 return
1574 }
Colin Cross331a1212018-08-15 20:40:52 -07001575 } else {
1576 outputFile = implementationAndResourcesJar
Colin Cross2fe66872015-03-30 17:20:39 -07001577 }
Colin Cross331a1212018-08-15 20:40:52 -07001578
Colin Crossb7a63242015-04-16 14:09:14 -07001579 ctx.CheckbuildFile(outputFile)
Colin Cross3063b782018-08-15 11:19:12 -07001580
1581 // Save the output file with no relative path so that it doesn't end up in a subdirectory when used as a resource
1582 j.outputFile = outputFile.WithoutRel()
Colin Cross2fe66872015-03-30 17:20:39 -07001583}
1584
Colin Cross3b706fd2019-09-05 16:44:18 -07001585func (j *Module) compileJavaClasses(ctx android.ModuleContext, jarName string, idx int,
1586 srcFiles, srcJars android.Paths, flags javaBuilderFlags, extraJarDeps android.Paths) android.WritablePath {
1587
1588 kzipName := pathtools.ReplaceExtension(jarName, "kzip")
1589 if idx >= 0 {
1590 kzipName = strings.TrimSuffix(jarName, filepath.Ext(jarName)) + strconv.Itoa(idx) + ".kzip"
1591 jarName += strconv.Itoa(idx)
1592 }
1593
1594 classes := android.PathForModuleOut(ctx, "javac", jarName)
1595 TransformJavaToClasses(ctx, classes, idx, srcFiles, srcJars, flags, extraJarDeps)
1596
1597 if ctx.Config().EmitXrefRules() {
1598 extractionFile := android.PathForModuleOut(ctx, kzipName)
1599 emitXrefRule(ctx, extractionFile, idx, srcFiles, srcJars, flags, extraJarDeps)
1600 j.kytheFiles = append(j.kytheFiles, extractionFile)
1601 }
1602
1603 return classes
1604}
1605
Zoran Jovanovic8736ce22018-08-21 17:10:29 +02001606// Check for invalid kotlinc flags. Only use this for flags explicitly passed by the user,
1607// since some of these flags may be used internally.
1608func CheckKotlincFlags(ctx android.ModuleContext, flags []string) {
1609 for _, flag := range flags {
1610 flag = strings.TrimSpace(flag)
1611
1612 if !strings.HasPrefix(flag, "-") {
1613 ctx.PropertyErrorf("kotlincflags", "Flag `%s` must start with `-`", flag)
1614 } else if strings.HasPrefix(flag, "-Xintellij-plugin-root") {
1615 ctx.PropertyErrorf("kotlincflags",
1616 "Bad flag: `%s`, only use internal compiler for consistency.", flag)
1617 } else if inList(flag, config.KotlincIllegalFlags) {
1618 ctx.PropertyErrorf("kotlincflags", "Flag `%s` already used by build system", flag)
1619 } else if flag == "-include-runtime" {
1620 ctx.PropertyErrorf("kotlincflags", "Bad flag: `%s`, do not include runtime.", flag)
1621 } else {
1622 args := strings.Split(flag, " ")
1623 if args[0] == "-kotlin-home" {
1624 ctx.PropertyErrorf("kotlincflags",
1625 "Bad flag: `%s`, kotlin home already set to default (path to kotlinc in the repo).", flag)
1626 }
1627 }
1628 }
1629}
1630
Colin Cross8eadbf02017-10-24 17:46:00 -07001631func (j *Module) compileJavaHeader(ctx android.ModuleContext, srcFiles, srcJars android.Paths,
Colin Cross55f63ea2018-08-27 12:37:09 -07001632 deps deps, flags javaBuilderFlags, jarName string, extraJars android.Paths) android.Path {
Nan Zhanged19fc32017-10-19 13:06:22 -07001633
1634 var jars android.Paths
Colin Cross8eadbf02017-10-24 17:46:00 -07001635 if len(srcFiles) > 0 || len(srcJars) > 0 {
Nan Zhanged19fc32017-10-19 13:06:22 -07001636 // Compile java sources into turbine.jar.
1637 turbineJar := android.PathForModuleOut(ctx, "turbine", jarName)
1638 TransformJavaToHeaderClasses(ctx, turbineJar, srcFiles, srcJars, flags)
1639 if ctx.Failed() {
1640 return nil
1641 }
1642 jars = append(jars, turbineJar)
1643 }
1644
Colin Cross55f63ea2018-08-27 12:37:09 -07001645 jars = append(jars, extraJars...)
1646
Nan Zhanged19fc32017-10-19 13:06:22 -07001647 // Combine any static header libraries into classes-header.jar. If there is only
1648 // one input jar this step will be skipped.
1649 var headerJar android.Path
1650 jars = append(jars, deps.staticHeaderJars...)
1651
Colin Cross5c6ecc12017-10-23 18:12:27 -07001652 // we cannot skip the combine step for now if there is only one jar
1653 // since we have to strip META-INF/TRANSITIVE dir from turbine.jar
1654 combinedJar := android.PathForModuleOut(ctx, "turbine-combined", jarName)
Colin Cross37f6d792018-07-12 12:28:41 -07001655 TransformJarsToJar(ctx, combinedJar, "for turbine", jars, android.OptionalPath{},
Colin Cross6c6e6cd2019-05-08 14:30:12 -07001656 false, nil, []string{"META-INF/TRANSITIVE"})
Colin Cross5c6ecc12017-10-23 18:12:27 -07001657 headerJar = combinedJar
Nan Zhanged19fc32017-10-19 13:06:22 -07001658
Steven Morelandc4efd9c2019-01-18 11:51:25 -08001659 if j.expandJarjarRules != nil {
Nan Zhanged19fc32017-10-19 13:06:22 -07001660 // Transform classes.jar into classes-jarjar.jar
1661 jarjarFile := android.PathForModuleOut(ctx, "turbine-jarjar", jarName)
Steven Morelandc4efd9c2019-01-18 11:51:25 -08001662 TransformJarJar(ctx, jarjarFile, headerJar, j.expandJarjarRules)
Nan Zhanged19fc32017-10-19 13:06:22 -07001663 headerJar = jarjarFile
1664 if ctx.Failed() {
1665 return nil
1666 }
1667 }
1668
1669 return headerJar
1670}
1671
Colin Crosscb933592017-11-22 13:49:43 -08001672func (j *Module) instrument(ctx android.ModuleContext, flags javaBuilderFlags,
Colin Cross3063b782018-08-15 11:19:12 -07001673 classesJar android.Path, jarName string) android.ModuleOutPath {
Colin Crosscb933592017-11-22 13:49:43 -08001674
Colin Cross7a3139e2017-12-19 13:57:50 -08001675 specs := j.jacocoModuleToZipCommand(ctx)
Colin Crosscb933592017-11-22 13:49:43 -08001676
Colin Cross84c38822018-01-03 15:59:46 -08001677 jacocoReportClassesFile := android.PathForModuleOut(ctx, "jacoco-report-classes", jarName)
Colin Crosscb933592017-11-22 13:49:43 -08001678 instrumentedJar := android.PathForModuleOut(ctx, "jacoco", jarName)
1679
1680 jacocoInstrumentJar(ctx, instrumentedJar, jacocoReportClassesFile, classesJar, specs)
1681
1682 j.jacocoReportClassesFile = jacocoReportClassesFile
1683
1684 return instrumentedJar
1685}
1686
albaltai36ff7dc2018-12-25 14:35:23 +08001687var _ Dependency = (*Module)(nil)
Colin Cross2fe66872015-03-30 17:20:39 -07001688
Nan Zhanged19fc32017-10-19 13:06:22 -07001689func (j *Module) HeaderJars() android.Paths {
albaltai36ff7dc2018-12-25 14:35:23 +08001690 if j.headerJarFile == nil {
1691 return nil
1692 }
Nan Zhanged19fc32017-10-19 13:06:22 -07001693 return android.Paths{j.headerJarFile}
1694}
1695
1696func (j *Module) ImplementationJars() android.Paths {
shinwang9e4c07a2018-12-24 15:41:04 +08001697 if j.implementationJarFile == nil {
1698 return nil
1699 }
Nan Zhanged19fc32017-10-19 13:06:22 -07001700 return android.Paths{j.implementationJarFile}
Colin Cross2fe66872015-03-30 17:20:39 -07001701}
1702
Colin Crossf24a22a2019-01-31 14:12:44 -08001703func (j *Module) DexJar() android.Path {
1704 return j.dexJarFile
1705}
1706
Colin Cross331a1212018-08-15 20:40:52 -07001707func (j *Module) ResourceJars() android.Paths {
1708 if j.resourceJar == nil {
1709 return nil
1710 }
1711 return android.Paths{j.resourceJar}
1712}
1713
1714func (j *Module) ImplementationAndResourcesJars() android.Paths {
albaltai36ff7dc2018-12-25 14:35:23 +08001715 if j.implementationAndResourcesJar == nil {
1716 return nil
1717 }
Colin Cross331a1212018-08-15 20:40:52 -07001718 return android.Paths{j.implementationAndResourcesJar}
1719}
1720
Colin Cross46c9b8b2017-06-22 16:51:17 -07001721func (j *Module) AidlIncludeDirs() android.Paths {
albaltai36ff7dc2018-12-25 14:35:23 +08001722 // exportAidlIncludeDirs is type android.Paths already
Colin Crossc0b06f12015-04-08 13:03:43 -07001723 return j.exportAidlIncludeDirs
1724}
1725
Jiyong Park1be96912018-05-28 18:02:19 +09001726func (j *Module) ExportedSdkLibs() []string {
albaltai36ff7dc2018-12-25 14:35:23 +08001727 // exportedSdkLibs is type []string
Jiyong Park1be96912018-05-28 18:02:19 +09001728 return j.exportedSdkLibs
1729}
1730
Artur Satayev9cf46692019-11-26 18:08:34 +00001731func (j *Module) ExportedPlugins() (android.Paths, []string) {
1732 return j.exportedPluginJars, j.exportedPluginClasses
1733}
1734
Colin Cross0c4ce212019-05-03 15:28:19 -07001735func (j *Module) SrcJarArgs() ([]string, android.Paths) {
1736 return j.srcJarArgs, j.srcJarDeps
1737}
1738
Colin Cross46c9b8b2017-06-22 16:51:17 -07001739var _ logtagsProducer = (*Module)(nil)
Colin Crossf05fe972015-04-10 17:45:20 -07001740
Colin Cross46c9b8b2017-06-22 16:51:17 -07001741func (j *Module) logtags() android.Paths {
Colin Crossf05fe972015-04-10 17:45:20 -07001742 return j.logtagsSrcs
1743}
1744
Brandon Lee5d45c6f2018-08-15 15:35:38 -07001745// Collect information for opening IDE project files in java/jdeps.go.
1746func (j *Module) IDEInfo(dpInfo *android.IdeInfo) {
1747 dpInfo.Deps = append(dpInfo.Deps, j.CompilerDeps()...)
1748 dpInfo.Srcs = append(dpInfo.Srcs, j.expandIDEInfoCompiledSrcs...)
patricktu18c82ff2019-05-10 15:48:50 +08001749 dpInfo.SrcJars = append(dpInfo.SrcJars, j.compiledSrcJars.Strings()...)
Brandon Lee5d45c6f2018-08-15 15:35:38 -07001750 dpInfo.Aidl_include_dirs = append(dpInfo.Aidl_include_dirs, j.deviceProperties.Aidl.Include_dirs...)
Steven Morelandc4efd9c2019-01-18 11:51:25 -08001751 if j.expandJarjarRules != nil {
1752 dpInfo.Jarjar_rules = append(dpInfo.Jarjar_rules, j.expandJarjarRules.String())
Brandon Lee5d45c6f2018-08-15 15:35:38 -07001753 }
1754}
1755
1756func (j *Module) CompilerDeps() []string {
1757 jdeps := []string{}
1758 jdeps = append(jdeps, j.properties.Libs...)
1759 jdeps = append(jdeps, j.properties.Static_libs...)
1760 return jdeps
1761}
1762
Jaewoong Jungc27ab662019-05-30 15:51:14 -07001763func (j *Module) hasCode(ctx android.ModuleContext) bool {
1764 srcFiles := android.PathsForModuleSrcExcludes(ctx, j.properties.Srcs, j.properties.Exclude_srcs)
1765 return len(srcFiles) > 0 || len(ctx.GetDirectDepsWithTag(staticLibTag)) > 0
1766}
1767
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09001768func (j *Module) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
1769 depTag := ctx.OtherModuleDependencyTag(dep)
Jiyong Park0f80c182020-01-31 02:49:53 +09001770 // Dependencies other than the static linkage are all considered crossing APEX boundary
1771 // Also, a dependency to an sdk member is also considered as such. This is required because
1772 // sdk members should be mutated into APEXes. Refer to sdk.sdkDepsReplaceMutator.
1773 return depTag == staticLibTag || j.IsInAnySdk()
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09001774}
1775
Jiyong Park0b238752019-10-29 11:23:10 +09001776func (j *Module) Stem() string {
1777 return proptools.StringDefault(j.deviceProperties.Stem, j.Name())
1778}
1779
Jiyong Park618922e2020-01-08 13:35:43 +09001780func (j *Module) JacocoReportClassesFile() android.Path {
1781 return j.jacocoReportClassesFile
1782}
1783
Colin Cross2fe66872015-03-30 17:20:39 -07001784//
1785// Java libraries (.jar file)
1786//
1787
Colin Crossf506d872017-07-19 15:53:04 -07001788type Library struct {
Colin Cross46c9b8b2017-06-22 16:51:17 -07001789 Module
Colin Crossf0f2e2c2019-10-15 16:36:40 -07001790
1791 InstallMixin func(ctx android.ModuleContext, installPath android.Path) (extraInstallDeps android.Paths)
Colin Cross2fe66872015-03-30 17:20:39 -07001792}
1793
Colin Cross42be7612019-02-21 18:12:14 -08001794func shouldUncompressDex(ctx android.ModuleContext, dexpreopter *dexpreopter) bool {
Ulya Trafimovichf491dde2020-01-24 12:19:45 +00001795 // Store uncompressed (and aligned) any dex files from jars in APEXes.
1796 if am, ok := ctx.Module().(android.ApexModule); ok && !am.IsForPlatform() {
1797 return true
1798 }
1799
Nicolas Geoffrayfa6e9ec2019-02-12 13:12:16 +00001800 // Store uncompressed (and do not strip) dex files from boot class path jars.
1801 if inList(ctx.ModuleName(), ctx.Config().BootJars()) {
1802 return true
1803 }
1804
1805 // Store uncompressed dex files that are preopted on /system.
Colin Cross42be7612019-02-21 18:12:14 -08001806 if !dexpreopter.dexpreoptDisabled(ctx) && (ctx.Host() || !odexOnSystemOther(ctx, dexpreopter.installPath)) {
Vladimir Markoe8b00d62018-12-21 15:54:16 +00001807 return true
1808 }
Colin Cross083a2aa2019-02-06 16:37:12 -08001809 if ctx.Config().UncompressPrivAppDex() &&
1810 inList(ctx.ModuleName(), ctx.Config().ModulesLoadedByPrivilegedModules()) {
1811 return true
1812 }
1813
Colin Cross2fc72f62018-12-21 12:59:54 -08001814 return false
1815}
1816
Colin Crossf506d872017-07-19 15:53:04 -07001817func (j *Library) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Jeongik Cha2cc570d2019-10-29 15:44:45 +09001818 j.checkSdkVersion(ctx)
Jiyong Park0b238752019-10-29 11:23:10 +09001819 j.dexpreopter.installPath = android.PathForModuleInstall(ctx, "framework", j.Stem()+".jar")
Colin Cross43f08db2018-11-12 10:13:39 -08001820 j.dexpreopter.isSDKLibrary = j.deviceProperties.IsSDKLibrary
Nicolas Geoffrayfa6e9ec2019-02-12 13:12:16 +00001821 j.dexpreopter.isInstallable = Bool(j.properties.Installable)
Colin Cross42be7612019-02-21 18:12:14 -08001822 j.dexpreopter.uncompressedDex = shouldUncompressDex(ctx, &j.dexpreopter)
Nicolas Geoffrayfa6e9ec2019-02-12 13:12:16 +00001823 j.deviceProperties.UncompressDex = j.dexpreopter.uncompressedDex
Jaewoong Junga24af3b2019-05-13 09:23:20 -07001824 j.compile(ctx, nil)
Colin Crossb7a63242015-04-16 14:09:14 -07001825
Jiyong Park7f7766d2019-07-25 22:02:35 +09001826 exclusivelyForApex := android.InAnyApex(ctx.ModuleName()) && !j.IsForPlatform()
1827 if (Bool(j.properties.Installable) || ctx.Host()) && !exclusivelyForApex {
Colin Crossf0f2e2c2019-10-15 16:36:40 -07001828 var extraInstallDeps android.Paths
1829 if j.InstallMixin != nil {
1830 extraInstallDeps = j.InstallMixin(ctx, j.outputFile)
1831 }
Colin Cross2c429dc2017-08-31 16:45:16 -07001832 j.installFile = ctx.InstallFile(android.PathForModuleInstall(ctx, "framework"),
Colin Crossf0f2e2c2019-10-15 16:36:40 -07001833 ctx.ModuleName()+".jar", j.outputFile, extraInstallDeps...)
Colin Cross2c429dc2017-08-31 16:45:16 -07001834 }
Colin Crossb7a63242015-04-16 14:09:14 -07001835}
1836
Colin Crossf506d872017-07-19 15:53:04 -07001837func (j *Library) DepsMutator(ctx android.BottomUpMutatorContext) {
Colin Cross46c9b8b2017-06-22 16:51:17 -07001838 j.deps(ctx)
1839}
1840
Paul Duffin0e0cf1d2019-11-12 19:39:25 +00001841const (
Paul Duffin1b82e6a2019-12-03 18:06:47 +00001842 aidlIncludeDir = "aidl"
1843 javaDir = "java"
1844 jarFileSuffix = ".jar"
1845 testConfigSuffix = "-AndroidTest.xml"
Paul Duffin0e0cf1d2019-11-12 19:39:25 +00001846)
1847
Paul Duffina0dbf432019-12-05 11:25:53 +00001848// path to the jar file of a java library. Relative to <sdk_root>/<api_dir>
Paul Duffin1b82e6a2019-12-03 18:06:47 +00001849func sdkSnapshotFilePathForJar(member android.SdkMember) string {
1850 return sdkSnapshotFilePathForMember(member, jarFileSuffix)
1851}
1852
1853func sdkSnapshotFilePathForMember(member android.SdkMember, suffix string) string {
1854 return filepath.Join(javaDir, member.Name()+suffix)
Paul Duffin0e0cf1d2019-11-12 19:39:25 +00001855}
1856
Paul Duffin13879572019-11-28 14:31:38 +00001857type librarySdkMemberType struct {
Paul Duffin255f18e2019-12-13 11:22:16 +00001858 android.SdkMemberTypeBase
Paul Duffin13879572019-11-28 14:31:38 +00001859}
1860
1861func (mt *librarySdkMemberType) AddDependencies(mctx android.BottomUpMutatorContext, dependencyTag blueprint.DependencyTag, names []string) {
1862 mctx.AddVariationDependencies(nil, dependencyTag, names...)
1863}
1864
1865func (mt *librarySdkMemberType) IsInstance(module android.Module) bool {
1866 _, ok := module.(*Library)
1867 return ok
1868}
1869
Paul Duffina0dbf432019-12-05 11:25:53 +00001870func (mt *librarySdkMemberType) buildSnapshot(
1871 sdkModuleContext android.ModuleContext,
1872 builder android.SnapshotBuilder,
1873 member android.SdkMember,
1874 jarToExportGetter func(j *Library) android.Path) {
1875
Paul Duffin13879572019-11-28 14:31:38 +00001876 variants := member.Variants()
1877 if len(variants) != 1 {
1878 sdkModuleContext.ModuleErrorf("sdk contains %d variants of member %q but only one is allowed", len(variants), member.Name())
1879 for _, variant := range variants {
1880 sdkModuleContext.ModuleErrorf(" %q", variant)
1881 }
1882 }
1883 variant := variants[0]
1884 j := variant.(*Library)
1885
Paul Duffina0dbf432019-12-05 11:25:53 +00001886 exportedJar := jarToExportGetter(j)
Paul Duffin1b82e6a2019-12-03 18:06:47 +00001887 snapshotRelativeJavaLibPath := sdkSnapshotFilePathForJar(member)
Paul Duffina0dbf432019-12-05 11:25:53 +00001888 builder.CopyToSnapshot(exportedJar, snapshotRelativeJavaLibPath)
Paul Duffin0e0cf1d2019-11-12 19:39:25 +00001889
1890 for _, dir := range j.AidlIncludeDirs() {
1891 // TODO(jiyong): copy parcelable declarations only
1892 aidlFiles, _ := sdkModuleContext.GlobWithDeps(dir.String()+"/**/*.aidl", nil)
1893 for _, file := range aidlFiles {
1894 builder.CopyToSnapshot(android.PathForSource(sdkModuleContext, file), filepath.Join(aidlIncludeDir, file))
1895 }
1896 }
1897
Paul Duffin9d8d6092019-12-05 18:19:29 +00001898 module := builder.AddPrebuiltModule(member, "java_import")
Paul Duffinb645ec82019-11-27 17:43:54 +00001899 module.AddProperty("jars", []string{snapshotRelativeJavaLibPath})
Paul Duffin0e0cf1d2019-11-12 19:39:25 +00001900}
1901
Paul Duffin7b81f5e2020-01-13 21:03:22 +00001902var javaHeaderLibsSdkMemberType android.SdkMemberType = &headerLibrarySdkMemberType{
1903 librarySdkMemberType{
1904 android.SdkMemberTypeBase{
1905 PropertyName: "java_header_libs",
1906 SupportsSdk: true,
1907 },
1908 },
1909}
1910
Paul Duffina0dbf432019-12-05 11:25:53 +00001911type headerLibrarySdkMemberType struct {
1912 librarySdkMemberType
1913}
1914
1915func (mt *headerLibrarySdkMemberType) BuildSnapshot(sdkModuleContext android.ModuleContext, builder android.SnapshotBuilder, member android.SdkMember) {
1916 mt.librarySdkMemberType.buildSnapshot(sdkModuleContext, builder, member, func(j *Library) android.Path {
1917 headerJars := j.HeaderJars()
1918 if len(headerJars) != 1 {
1919 panic(fmt.Errorf("there must be only one header jar from %q", j.Name()))
1920 }
1921
1922 return headerJars[0]
1923 })
1924}
1925
Paul Duffina0dbf432019-12-05 11:25:53 +00001926type implLibrarySdkMemberType struct {
1927 librarySdkMemberType
1928}
1929
1930func (mt *implLibrarySdkMemberType) BuildSnapshot(sdkModuleContext android.ModuleContext, builder android.SnapshotBuilder, member android.SdkMember) {
1931 mt.librarySdkMemberType.buildSnapshot(sdkModuleContext, builder, member, func(j *Library) android.Path {
1932 implementationJars := j.ImplementationJars()
1933 if len(implementationJars) != 1 {
1934 panic(fmt.Errorf("there must be only one implementation jar from %q", j.Name()))
1935 }
1936
1937 return implementationJars[0]
1938 })
1939}
1940
Colin Cross1b16b0e2019-02-12 14:41:32 -08001941// java_library builds and links sources into a `.jar` file for the device, and possibly for the host as well.
1942//
1943// By default, a java_library has a single variant that produces a `.jar` file containing `.class` files that were
1944// compiled against the device bootclasspath. This jar is not suitable for installing on a device, but can be used
1945// as a `static_libs` dependency of another module.
1946//
1947// Specifying `installable: true` will product a `.jar` file containing `classes.dex` files, suitable for installing on
1948// a device.
1949//
1950// Specifying `host_supported: true` will produce two variants, one compiled against the device bootclasspath and one
1951// compiled against the host bootclasspath.
Colin Cross9ae1b922018-06-26 17:59:05 -07001952func LibraryFactory() android.Module {
1953 module := &Library{}
Colin Cross2fe66872015-03-30 17:20:39 -07001954
Colin Cross9ae1b922018-06-26 17:59:05 -07001955 module.AddProperties(
1956 &module.Module.properties,
1957 &module.Module.deviceProperties,
Colin Cross43f08db2018-11-12 10:13:39 -08001958 &module.Module.dexpreoptProperties,
Colin Cross9ae1b922018-06-26 17:59:05 -07001959 &module.Module.protoProperties)
Colin Cross2fe66872015-03-30 17:20:39 -07001960
Jiyong Park7f7766d2019-07-25 22:02:35 +09001961 android.InitApexModule(module)
Jiyong Parkd1063c12019-07-17 20:08:41 +09001962 android.InitSdkAwareModule(module)
Jooyung Han18020ea2019-11-13 10:50:48 +09001963 InitJavaModule(module, android.HostAndDeviceSupported)
Colin Cross9ae1b922018-06-26 17:59:05 -07001964 return module
Colin Cross2fe66872015-03-30 17:20:39 -07001965}
1966
Colin Cross1b16b0e2019-02-12 14:41:32 -08001967// java_library_static is an obsolete alias for java_library.
1968func LibraryStaticFactory() android.Module {
1969 return LibraryFactory()
1970}
1971
1972// java_library_host builds and links sources into a `.jar` file for the host.
1973//
1974// A java_library_host has a single variant that produces a `.jar` file containing `.class` files that were
1975// compiled against the host bootclasspath.
Colin Crossf506d872017-07-19 15:53:04 -07001976func LibraryHostFactory() android.Module {
1977 module := &Library{}
Colin Cross2fe66872015-03-30 17:20:39 -07001978
Colin Cross6af17aa2017-09-20 12:59:05 -07001979 module.AddProperties(
1980 &module.Module.properties,
1981 &module.Module.protoProperties)
Colin Cross36242852017-06-23 15:06:31 -07001982
Colin Cross9ae1b922018-06-26 17:59:05 -07001983 module.Module.properties.Installable = proptools.BoolPtr(true)
1984
Jiyong Park7f7766d2019-07-25 22:02:35 +09001985 android.InitApexModule(module)
Jooyung Han18020ea2019-11-13 10:50:48 +09001986 InitJavaModule(module, android.HostSupported)
Colin Cross36242852017-06-23 15:06:31 -07001987 return module
Colin Cross2fe66872015-03-30 17:20:39 -07001988}
1989
1990//
Colin Crossb628ea52018-08-14 16:42:33 -07001991// Java Tests
Colin Cross05638fc2018-04-09 18:40:24 -07001992//
1993
1994type testProperties struct {
Colin Cross05638fc2018-04-09 18:40:24 -07001995 // list of compatibility suites (for example "cts", "vts") that the module should be
1996 // installed into.
1997 Test_suites []string `android:"arch_variant"`
Julien Despreze146e392018-08-02 15:00:46 -07001998
1999 // the name of the test configuration (for example "AndroidTest.xml") that should be
2000 // installed with the module.
Colin Cross27b922f2019-03-04 22:35:41 -08002001 Test_config *string `android:"path,arch_variant"`
Colin Crossd96ca352018-08-10 16:06:24 -07002002
Jack He33338892018-09-19 02:21:28 -07002003 // the name of the test configuration template (for example "AndroidTestTemplate.xml") that
2004 // should be installed with the module.
Colin Cross27b922f2019-03-04 22:35:41 -08002005 Test_config_template *string `android:"path,arch_variant"`
Jack He33338892018-09-19 02:21:28 -07002006
Colin Crossd96ca352018-08-10 16:06:24 -07002007 // list of files or filegroup modules that provide data that should be installed alongside
2008 // the test
Colin Cross27b922f2019-03-04 22:35:41 -08002009 Data []string `android:"path"`
Dan Shi6ffaaa82019-09-26 11:41:36 -07002010
2011 // Flag to indicate whether or not to create test config automatically. If AndroidTest.xml
2012 // doesn't exist next to the Android.bp, this attribute doesn't need to be set to true
2013 // explicitly.
2014 Auto_gen_config *bool
Colin Cross05638fc2018-04-09 18:40:24 -07002015}
2016
Paul Duffin42df1442019-03-20 12:45:53 +00002017type testHelperLibraryProperties struct {
2018 // list of compatibility suites (for example "cts", "vts") that the module should be
2019 // installed into.
2020 Test_suites []string `android:"arch_variant"`
2021}
2022
Paul Duffin1b82e6a2019-12-03 18:06:47 +00002023type prebuiltTestProperties struct {
2024 // list of compatibility suites (for example "cts", "vts") that the module should be
2025 // installed into.
2026 Test_suites []string `android:"arch_variant"`
2027
2028 // the name of the test configuration (for example "AndroidTest.xml") that should be
2029 // installed with the module.
2030 Test_config *string `android:"path,arch_variant"`
2031}
2032
Colin Cross05638fc2018-04-09 18:40:24 -07002033type Test struct {
2034 Library
2035
2036 testProperties testProperties
Colin Cross303e21f2018-08-07 16:49:25 -07002037
2038 testConfig android.Path
Colin Crossd96ca352018-08-10 16:06:24 -07002039 data android.Paths
Colin Cross303e21f2018-08-07 16:49:25 -07002040}
2041
Paul Duffin42df1442019-03-20 12:45:53 +00002042type TestHelperLibrary struct {
2043 Library
2044
2045 testHelperLibraryProperties testHelperLibraryProperties
2046}
2047
Paul Duffin1b82e6a2019-12-03 18:06:47 +00002048type JavaTestImport struct {
2049 Import
2050
2051 prebuiltTestProperties prebuiltTestProperties
2052
2053 testConfig android.Path
2054}
2055
Colin Cross303e21f2018-08-07 16:49:25 -07002056func (j *Test) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Dan Shi6ffaaa82019-09-26 11:41:36 -07002057 j.testConfig = tradefed.AutoGenJavaTestConfig(ctx, j.testProperties.Test_config, j.testProperties.Test_config_template,
2058 j.testProperties.Test_suites, j.testProperties.Auto_gen_config)
Colin Cross8a497952019-03-05 22:25:09 -08002059 j.data = android.PathsForModuleSrc(ctx, j.testProperties.Data)
Colin Cross303e21f2018-08-07 16:49:25 -07002060
2061 j.Library.GenerateAndroidBuildActions(ctx)
Colin Cross05638fc2018-04-09 18:40:24 -07002062}
2063
Paul Duffin42df1442019-03-20 12:45:53 +00002064func (j *TestHelperLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
2065 j.Library.GenerateAndroidBuildActions(ctx)
2066}
2067
Paul Duffin1b82e6a2019-12-03 18:06:47 +00002068func (j *JavaTestImport) GenerateAndroidBuildActions(ctx android.ModuleContext) {
2069 j.testConfig = tradefed.AutoGenJavaTestConfig(ctx, j.prebuiltTestProperties.Test_config, nil,
2070 j.prebuiltTestProperties.Test_suites, nil)
2071
2072 j.Import.GenerateAndroidBuildActions(ctx)
2073}
2074
2075type testSdkMemberType struct {
2076 android.SdkMemberTypeBase
2077}
2078
2079func (mt *testSdkMemberType) AddDependencies(mctx android.BottomUpMutatorContext, dependencyTag blueprint.DependencyTag, names []string) {
2080 mctx.AddVariationDependencies(nil, dependencyTag, names...)
2081}
2082
2083func (mt *testSdkMemberType) IsInstance(module android.Module) bool {
2084 _, ok := module.(*Test)
2085 return ok
2086}
2087
2088func (mt *testSdkMemberType) BuildSnapshot(sdkModuleContext android.ModuleContext, builder android.SnapshotBuilder, member android.SdkMember) {
2089 variants := member.Variants()
2090 if len(variants) != 1 {
2091 sdkModuleContext.ModuleErrorf("sdk contains %d variants of member %q but only one is allowed", len(variants), member.Name())
2092 for _, variant := range variants {
2093 sdkModuleContext.ModuleErrorf(" %q", variant)
2094 }
2095 }
2096 variant := variants[0]
2097 j := variant.(*Test)
2098
2099 implementationJars := j.ImplementationJars()
2100 if len(implementationJars) != 1 {
2101 panic(fmt.Errorf("there must be only one implementation jar from %q", j.Name()))
2102 }
2103
2104 snapshotRelativeJavaLibPath := sdkSnapshotFilePathForJar(member)
2105 builder.CopyToSnapshot(implementationJars[0], snapshotRelativeJavaLibPath)
2106
2107 snapshotRelativeTestConfigPath := sdkSnapshotFilePathForMember(member, testConfigSuffix)
2108 builder.CopyToSnapshot(j.testConfig, snapshotRelativeTestConfigPath)
2109
2110 module := builder.AddPrebuiltModule(member, "java_test_import")
2111 module.AddProperty("jars", []string{snapshotRelativeJavaLibPath})
2112 module.AddProperty("test_config", snapshotRelativeTestConfigPath)
2113}
2114
Colin Cross1b16b0e2019-02-12 14:41:32 -08002115// java_test builds a and links sources into a `.jar` file for the device, and possibly for the host as well, and
2116// creates an `AndroidTest.xml` file to allow running the test with `atest` or a `TEST_MAPPING` file.
2117//
2118// By default, a java_test has a single variant that produces a `.jar` file containing `classes.dex` files that were
2119// compiled against the device bootclasspath.
2120//
2121// Specifying `host_supported: true` will produce two variants, one compiled against the device bootclasspath and one
2122// compiled against the host bootclasspath.
Colin Cross05638fc2018-04-09 18:40:24 -07002123func TestFactory() android.Module {
2124 module := &Test{}
2125
2126 module.AddProperties(
2127 &module.Module.properties,
2128 &module.Module.deviceProperties,
Colin Cross43f08db2018-11-12 10:13:39 -08002129 &module.Module.dexpreoptProperties,
Colin Cross05638fc2018-04-09 18:40:24 -07002130 &module.Module.protoProperties,
2131 &module.testProperties)
2132
Colin Cross9ae1b922018-06-26 17:59:05 -07002133 module.Module.properties.Installable = proptools.BoolPtr(true)
Colin Crosse3026872019-01-05 22:30:13 -08002134 module.Module.dexpreopter.isTest = true
Colin Cross9ae1b922018-06-26 17:59:05 -07002135
Colin Cross05638fc2018-04-09 18:40:24 -07002136 InitJavaModule(module, android.HostAndDeviceSupported)
Colin Cross05638fc2018-04-09 18:40:24 -07002137 return module
2138}
2139
Paul Duffin42df1442019-03-20 12:45:53 +00002140// java_test_helper_library creates a java library and makes sure that it is added to the appropriate test suite.
2141func TestHelperLibraryFactory() android.Module {
2142 module := &TestHelperLibrary{}
2143
2144 module.AddProperties(
2145 &module.Module.properties,
2146 &module.Module.deviceProperties,
2147 &module.Module.dexpreoptProperties,
2148 &module.Module.protoProperties,
2149 &module.testHelperLibraryProperties)
2150
Colin Cross9a4abed2019-04-24 13:19:28 -07002151 module.Module.properties.Installable = proptools.BoolPtr(true)
2152 module.Module.dexpreopter.isTest = true
2153
Paul Duffin42df1442019-03-20 12:45:53 +00002154 InitJavaModule(module, android.HostAndDeviceSupported)
2155 return module
2156}
2157
Paul Duffin1b82e6a2019-12-03 18:06:47 +00002158// java_test_import imports one or more `.jar` files into the build graph as if they were built by a java_test module
2159// and makes sure that it is added to the appropriate test suite.
2160//
2161// By default, a java_test_import has a single variant that expects a `.jar` file containing `.class` files that were
2162// compiled against an Android classpath.
2163//
2164// Specifying `host_supported: true` will produce two variants, one for use as a dependency of device modules and one
2165// for host modules.
2166func JavaTestImportFactory() android.Module {
2167 module := &JavaTestImport{}
2168
2169 module.AddProperties(
2170 &module.Import.properties,
2171 &module.prebuiltTestProperties)
2172
2173 module.Import.properties.Installable = proptools.BoolPtr(true)
2174
2175 android.InitPrebuiltModule(module, &module.properties.Jars)
2176 android.InitApexModule(module)
2177 android.InitSdkAwareModule(module)
2178 InitJavaModule(module, android.HostAndDeviceSupported)
2179 return module
2180}
2181
Colin Cross1b16b0e2019-02-12 14:41:32 -08002182// java_test_host builds a and links sources into a `.jar` file for the host, and creates an `AndroidTest.xml` file to
2183// allow running the test with `atest` or a `TEST_MAPPING` file.
2184//
2185// A java_test_host has a single variant that produces a `.jar` file containing `.class` files that were
2186// compiled against the host bootclasspath.
Colin Cross05638fc2018-04-09 18:40:24 -07002187func TestHostFactory() android.Module {
2188 module := &Test{}
2189
2190 module.AddProperties(
2191 &module.Module.properties,
2192 &module.Module.protoProperties,
2193 &module.testProperties)
2194
Colin Cross9ae1b922018-06-26 17:59:05 -07002195 module.Module.properties.Installable = proptools.BoolPtr(true)
2196
Colin Cross05638fc2018-04-09 18:40:24 -07002197 InitJavaModule(module, android.HostSupported)
Colin Cross05638fc2018-04-09 18:40:24 -07002198 return module
2199}
2200
2201//
Colin Cross2fe66872015-03-30 17:20:39 -07002202// Java Binaries (.jar file plus wrapper script)
2203//
2204
Colin Crossf506d872017-07-19 15:53:04 -07002205type binaryProperties struct {
Colin Cross7d5136f2015-05-11 13:39:40 -07002206 // installable script to execute the resulting jar
Colin Cross27b922f2019-03-04 22:35:41 -08002207 Wrapper *string `android:"path"`
Colin Cross094054a2018-10-17 15:10:48 -07002208
2209 // Name of the class containing main to be inserted into the manifest as Main-Class.
2210 Main_class *string
Colin Cross7d5136f2015-05-11 13:39:40 -07002211}
2212
Colin Crossf506d872017-07-19 15:53:04 -07002213type Binary struct {
2214 Library
Colin Cross2fe66872015-03-30 17:20:39 -07002215
Colin Crossf506d872017-07-19 15:53:04 -07002216 binaryProperties binaryProperties
Colin Cross10a03492017-08-10 17:09:43 -07002217
Colin Cross6b4a32d2017-12-05 13:42:45 -08002218 isWrapperVariant bool
2219
Colin Crossc3315992017-12-08 19:12:36 -08002220 wrapperFile android.Path
Colin Cross70dda7e2019-10-01 22:05:35 -07002221 binaryFile android.InstallPath
Colin Cross2fe66872015-03-30 17:20:39 -07002222}
2223
Alex Light24237172017-10-26 09:46:21 -07002224func (j *Binary) HostToolPath() android.OptionalPath {
2225 return android.OptionalPathForPath(j.binaryFile)
2226}
2227
Colin Crossf506d872017-07-19 15:53:04 -07002228func (j *Binary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross6b4a32d2017-12-05 13:42:45 -08002229 if ctx.Arch().ArchType == android.Common {
2230 // Compile the jar
Colin Cross094054a2018-10-17 15:10:48 -07002231 if j.binaryProperties.Main_class != nil {
2232 if j.properties.Manifest != nil {
2233 ctx.PropertyErrorf("main_class", "main_class cannot be used when manifest is set")
2234 }
2235 manifestFile := android.PathForModuleOut(ctx, "manifest.txt")
2236 GenerateMainClassManifest(ctx, manifestFile, String(j.binaryProperties.Main_class))
2237 j.overrideManifest = android.OptionalPathForPath(manifestFile)
2238 }
2239
Colin Cross6b4a32d2017-12-05 13:42:45 -08002240 j.Library.GenerateAndroidBuildActions(ctx)
Nan Zhang3c807db2017-11-03 14:53:31 -07002241 } else {
Colin Cross6b4a32d2017-12-05 13:42:45 -08002242 // Handle the binary wrapper
2243 j.isWrapperVariant = true
2244
Colin Cross366938f2017-12-11 16:29:02 -08002245 if j.binaryProperties.Wrapper != nil {
Colin Cross8a497952019-03-05 22:25:09 -08002246 j.wrapperFile = android.PathForModuleSrc(ctx, *j.binaryProperties.Wrapper)
Colin Cross6b4a32d2017-12-05 13:42:45 -08002247 } else {
2248 j.wrapperFile = android.PathForSource(ctx, "build/soong/scripts/jar-wrapper.sh")
2249 }
2250
2251 // Depend on the installed jar so that the wrapper doesn't get executed by
2252 // another build rule before the jar has been installed.
2253 jarFile := ctx.PrimaryModule().(*Binary).installFile
2254
2255 j.binaryFile = ctx.InstallExecutable(android.PathForModuleInstall(ctx, "bin"),
2256 ctx.ModuleName(), j.wrapperFile, jarFile)
Nan Zhang3c807db2017-11-03 14:53:31 -07002257 }
Colin Cross2fe66872015-03-30 17:20:39 -07002258}
2259
Colin Crossf506d872017-07-19 15:53:04 -07002260func (j *Binary) DepsMutator(ctx android.BottomUpMutatorContext) {
Colin Cross6b4a32d2017-12-05 13:42:45 -08002261 if ctx.Arch().ArchType == android.Common {
2262 j.deps(ctx)
2263 }
Colin Cross46c9b8b2017-06-22 16:51:17 -07002264}
2265
Colin Cross1b16b0e2019-02-12 14:41:32 -08002266// java_binary builds a `.jar` file and a shell script that executes it for the device, and possibly for the host
2267// as well.
2268//
2269// By default, a java_binary has a single variant that produces a `.jar` file containing `classes.dex` files that were
2270// compiled against the device bootclasspath.
2271//
2272// Specifying `host_supported: true` will produce two variants, one compiled against the device bootclasspath and one
2273// compiled against the host bootclasspath.
Colin Crossf506d872017-07-19 15:53:04 -07002274func BinaryFactory() android.Module {
2275 module := &Binary{}
Colin Cross2fe66872015-03-30 17:20:39 -07002276
Colin Cross36242852017-06-23 15:06:31 -07002277 module.AddProperties(
Colin Cross540eff82017-06-22 17:01:52 -07002278 &module.Module.properties,
2279 &module.Module.deviceProperties,
Colin Cross43f08db2018-11-12 10:13:39 -08002280 &module.Module.dexpreoptProperties,
Colin Cross6af17aa2017-09-20 12:59:05 -07002281 &module.Module.protoProperties,
Colin Cross540eff82017-06-22 17:01:52 -07002282 &module.binaryProperties)
Colin Cross36242852017-06-23 15:06:31 -07002283
Colin Cross9ae1b922018-06-26 17:59:05 -07002284 module.Module.properties.Installable = proptools.BoolPtr(true)
2285
Colin Cross6b4a32d2017-12-05 13:42:45 -08002286 android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibCommonFirst)
2287 android.InitDefaultableModule(module)
Colin Cross36242852017-06-23 15:06:31 -07002288 return module
Colin Cross2fe66872015-03-30 17:20:39 -07002289}
2290
Colin Cross1b16b0e2019-02-12 14:41:32 -08002291// java_binary_host builds a `.jar` file and a shell script that executes it for the host.
2292//
2293// A java_binary_host has a single variant that produces a `.jar` file containing `.class` files that were
2294// compiled against the host bootclasspath.
Colin Crossf506d872017-07-19 15:53:04 -07002295func BinaryHostFactory() android.Module {
2296 module := &Binary{}
Colin Cross2fe66872015-03-30 17:20:39 -07002297
Colin Cross36242852017-06-23 15:06:31 -07002298 module.AddProperties(
Colin Cross540eff82017-06-22 17:01:52 -07002299 &module.Module.properties,
Colin Cross6af17aa2017-09-20 12:59:05 -07002300 &module.Module.protoProperties,
Colin Cross540eff82017-06-22 17:01:52 -07002301 &module.binaryProperties)
Colin Cross36242852017-06-23 15:06:31 -07002302
Colin Cross9ae1b922018-06-26 17:59:05 -07002303 module.Module.properties.Installable = proptools.BoolPtr(true)
2304
Colin Cross6b4a32d2017-12-05 13:42:45 -08002305 android.InitAndroidArchModule(module, android.HostSupported, android.MultilibCommonFirst)
2306 android.InitDefaultableModule(module)
Colin Cross36242852017-06-23 15:06:31 -07002307 return module
Colin Cross2fe66872015-03-30 17:20:39 -07002308}
2309
2310//
2311// Java prebuilts
2312//
2313
Colin Cross74d73e22017-08-02 11:05:49 -07002314type ImportProperties struct {
Colin Cross27b922f2019-03-04 22:35:41 -08002315 Jars []string `android:"path"`
Colin Cross461bd1a2017-10-20 13:59:18 -07002316
Nan Zhangea568a42017-11-08 21:20:04 -08002317 Sdk_version *string
Colin Cross535e2cf2017-10-20 17:57:49 -07002318
2319 Installable *bool
Jiyong Park1be96912018-05-28 18:02:19 +09002320
2321 // List of shared java libs that this module has dependencies to
2322 Libs []string
Colin Cross37f6d792018-07-12 12:28:41 -07002323
2324 // List of files to remove from the jar file(s)
2325 Exclude_files []string
2326
2327 // List of directories to remove from the jar file(s)
2328 Exclude_dirs []string
Nan Zhang4c819fb2018-08-27 18:31:46 -07002329
2330 // if set to true, run Jetifier against .jar file. Defaults to false.
Colin Cross1001a792019-03-21 22:21:39 -07002331 Jetifier *bool
Jiyong Park4c4c0242019-10-21 14:53:15 +09002332
2333 // set the name of the output
2334 Stem *string
Colin Cross74d73e22017-08-02 11:05:49 -07002335}
2336
2337type Import struct {
Colin Cross635c3b02016-05-18 15:37:25 -07002338 android.ModuleBase
Colin Cross48de9a42018-10-02 13:53:33 -07002339 android.DefaultableModuleBase
Jiyong Park7f7766d2019-07-25 22:02:35 +09002340 android.ApexModuleBase
Colin Crossec7a0422017-07-07 14:47:12 -07002341 prebuilt android.Prebuilt
Jiyong Parkd1063c12019-07-17 20:08:41 +09002342 android.SdkBase
Colin Cross2fe66872015-03-30 17:20:39 -07002343
Colin Cross74d73e22017-08-02 11:05:49 -07002344 properties ImportProperties
2345
Colin Cross0a6e0072017-08-30 14:24:55 -07002346 combinedClasspathFile android.Path
Jiyong Park1be96912018-05-28 18:02:19 +09002347 exportedSdkLibs []string
Colin Cross2fe66872015-03-30 17:20:39 -07002348}
2349
Jiyong Park6a927c42020-01-21 02:03:43 +09002350func (j *Import) sdkVersion() sdkSpec {
2351 return sdkSpecFrom(String(j.properties.Sdk_version))
Colin Cross83bb3162018-06-25 15:48:06 -07002352}
2353
Jiyong Park6a927c42020-01-21 02:03:43 +09002354func (j *Import) minSdkVersion() sdkSpec {
Colin Cross83bb3162018-06-25 15:48:06 -07002355 return j.sdkVersion()
2356}
2357
Colin Cross74d73e22017-08-02 11:05:49 -07002358func (j *Import) Prebuilt() *android.Prebuilt {
Colin Crossec7a0422017-07-07 14:47:12 -07002359 return &j.prebuilt
2360}
2361
Colin Cross74d73e22017-08-02 11:05:49 -07002362func (j *Import) PrebuiltSrcs() []string {
2363 return j.properties.Jars
2364}
2365
2366func (j *Import) Name() string {
Colin Cross5ea9bcc2017-07-27 15:41:32 -07002367 return j.prebuilt.Name(j.ModuleBase.Name())
2368}
2369
Jiyong Park0b238752019-10-29 11:23:10 +09002370func (j *Import) Stem() string {
2371 return proptools.StringDefault(j.properties.Stem, j.ModuleBase.Name())
2372}
2373
Jiyong Park618922e2020-01-08 13:35:43 +09002374func (a *Import) JacocoReportClassesFile() android.Path {
2375 return nil
2376}
2377
Colin Cross74d73e22017-08-02 11:05:49 -07002378func (j *Import) DepsMutator(ctx android.BottomUpMutatorContext) {
Colin Cross42d48b72018-08-29 14:10:52 -07002379 ctx.AddVariationDependencies(nil, libTag, j.properties.Libs...)
Colin Cross1e676be2016-10-12 14:38:15 -07002380}
2381
Colin Cross74d73e22017-08-02 11:05:49 -07002382func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross8a497952019-03-05 22:25:09 -08002383 jars := android.PathsForModuleSrc(ctx, j.properties.Jars)
Colin Crosse1d62a82015-04-03 16:53:05 -07002384
Jiyong Park0b238752019-10-29 11:23:10 +09002385 jarName := j.Stem() + ".jar"
Nan Zhang4c819fb2018-08-27 18:31:46 -07002386 outputFile := android.PathForModuleOut(ctx, "combined", jarName)
Colin Cross37f6d792018-07-12 12:28:41 -07002387 TransformJarsToJar(ctx, outputFile, "for prebuilts", jars, android.OptionalPath{},
2388 false, j.properties.Exclude_files, j.properties.Exclude_dirs)
Colin Cross1001a792019-03-21 22:21:39 -07002389 if Bool(j.properties.Jetifier) {
Nan Zhang4c819fb2018-08-27 18:31:46 -07002390 inputFile := outputFile
2391 outputFile = android.PathForModuleOut(ctx, "jetifier", jarName)
2392 TransformJetifier(ctx, outputFile, inputFile)
2393 }
Colin Crosse9a275b2017-10-16 17:09:48 -07002394 j.combinedClasspathFile = outputFile
Jiyong Park1be96912018-05-28 18:02:19 +09002395
2396 ctx.VisitDirectDeps(func(module android.Module) {
2397 otherName := ctx.OtherModuleName(module)
2398 tag := ctx.OtherModuleDependencyTag(module)
2399
2400 switch dep := module.(type) {
2401 case Dependency:
2402 switch tag {
2403 case libTag, staticLibTag:
2404 // sdk lib names from dependencies are re-exported
2405 j.exportedSdkLibs = append(j.exportedSdkLibs, dep.ExportedSdkLibs()...)
2406 }
2407 case SdkLibraryDependency:
2408 switch tag {
2409 case libTag:
2410 // names of sdk libs that are directly depended are exported
2411 j.exportedSdkLibs = append(j.exportedSdkLibs, otherName)
2412 }
2413 }
2414 })
2415
2416 j.exportedSdkLibs = android.FirstUniqueStrings(j.exportedSdkLibs)
Nan Zhang4973ecf2018-08-10 13:42:12 -07002417 if Bool(j.properties.Installable) {
2418 ctx.InstallFile(android.PathForModuleInstall(ctx, "framework"),
Jiyong Park4c4c0242019-10-21 14:53:15 +09002419 jarName, outputFile)
Nan Zhang4973ecf2018-08-10 13:42:12 -07002420 }
Colin Cross2fe66872015-03-30 17:20:39 -07002421}
2422
Colin Cross74d73e22017-08-02 11:05:49 -07002423var _ Dependency = (*Import)(nil)
Colin Cross2fe66872015-03-30 17:20:39 -07002424
Nan Zhanged19fc32017-10-19 13:06:22 -07002425func (j *Import) HeaderJars() android.Paths {
albaltai36ff7dc2018-12-25 14:35:23 +08002426 if j.combinedClasspathFile == nil {
2427 return nil
2428 }
Colin Cross37f6d792018-07-12 12:28:41 -07002429 return android.Paths{j.combinedClasspathFile}
Nan Zhanged19fc32017-10-19 13:06:22 -07002430}
2431
2432func (j *Import) ImplementationJars() android.Paths {
shinwang9e4c07a2018-12-24 15:41:04 +08002433 if j.combinedClasspathFile == nil {
2434 return nil
2435 }
Colin Cross37f6d792018-07-12 12:28:41 -07002436 return android.Paths{j.combinedClasspathFile}
Colin Cross2fe66872015-03-30 17:20:39 -07002437}
2438
Colin Cross331a1212018-08-15 20:40:52 -07002439func (j *Import) ResourceJars() android.Paths {
2440 return nil
2441}
2442
2443func (j *Import) ImplementationAndResourcesJars() android.Paths {
albaltai36ff7dc2018-12-25 14:35:23 +08002444 if j.combinedClasspathFile == nil {
2445 return nil
2446 }
Colin Cross331a1212018-08-15 20:40:52 -07002447 return android.Paths{j.combinedClasspathFile}
2448}
2449
Colin Crossf24a22a2019-01-31 14:12:44 -08002450func (j *Import) DexJar() android.Path {
2451 return nil
2452}
2453
Colin Cross74d73e22017-08-02 11:05:49 -07002454func (j *Import) AidlIncludeDirs() android.Paths {
Colin Crossc0b06f12015-04-08 13:03:43 -07002455 return nil
2456}
2457
Jiyong Park1be96912018-05-28 18:02:19 +09002458func (j *Import) ExportedSdkLibs() []string {
2459 return j.exportedSdkLibs
2460}
2461
Artur Satayev9cf46692019-11-26 18:08:34 +00002462func (j *Import) ExportedPlugins() (android.Paths, []string) {
2463 return nil, nil
2464}
2465
Colin Cross0c4ce212019-05-03 15:28:19 -07002466func (j *Import) SrcJarArgs() ([]string, android.Paths) {
2467 return nil, nil
2468}
2469
Jiyong Park0f80c182020-01-31 02:49:53 +09002470func (j *Import) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
2471 depTag := ctx.OtherModuleDependencyTag(dep)
2472 // dependencies other than the static linkage are all considered crossing APEX boundary
2473 // Also, a dependency to an sdk member is also considered as such. This is required because
2474 // sdk members should be mutated into APEXes. Refer to sdk.sdkDepsReplaceMutator.
2475 return depTag == staticLibTag || j.IsInAnySdk()
2476}
2477
albaltai36ff7dc2018-12-25 14:35:23 +08002478// Add compile time check for interface implementation
2479var _ android.IDEInfo = (*Import)(nil)
2480var _ android.IDECustomizedModuleName = (*Import)(nil)
2481
Brandon Lee5d45c6f2018-08-15 15:35:38 -07002482// Collect information for opening IDE project files in java/jdeps.go.
2483const (
2484 removedPrefix = "prebuilt_"
2485)
2486
2487func (j *Import) IDEInfo(dpInfo *android.IdeInfo) {
2488 dpInfo.Jars = append(dpInfo.Jars, j.PrebuiltSrcs()...)
2489}
2490
2491func (j *Import) IDECustomizedModuleName() string {
2492 // TODO(b/113562217): Extract the base module name from the Import name, often the Import name
2493 // has a prefix "prebuilt_". Remove the prefix explicitly if needed until we find a better
2494 // solution to get the Import name.
2495 name := j.Name()
2496 if strings.HasPrefix(name, removedPrefix) {
patricktubb640e02018-10-11 18:33:16 +08002497 name = strings.TrimPrefix(name, removedPrefix)
Brandon Lee5d45c6f2018-08-15 15:35:38 -07002498 }
2499 return name
2500}
2501
Colin Cross74d73e22017-08-02 11:05:49 -07002502var _ android.PrebuiltInterface = (*Import)(nil)
Colin Cross2fe66872015-03-30 17:20:39 -07002503
Colin Cross1b16b0e2019-02-12 14:41:32 -08002504// java_import imports one or more `.jar` files into the build graph as if they were built by a java_library module.
2505//
2506// By default, a java_import has a single variant that expects a `.jar` file containing `.class` files that were
2507// compiled against an Android classpath.
2508//
2509// Specifying `host_supported: true` will produce two variants, one for use as a dependency of device modules and one
2510// for host modules.
Colin Cross74d73e22017-08-02 11:05:49 -07002511func ImportFactory() android.Module {
2512 module := &Import{}
Colin Cross36242852017-06-23 15:06:31 -07002513
Colin Cross74d73e22017-08-02 11:05:49 -07002514 module.AddProperties(&module.properties)
2515
2516 android.InitPrebuiltModule(module, &module.properties.Jars)
Jiyong Park7f7766d2019-07-25 22:02:35 +09002517 android.InitApexModule(module)
Jiyong Parkd1063c12019-07-17 20:08:41 +09002518 android.InitSdkAwareModule(module)
Jooyung Han18020ea2019-11-13 10:50:48 +09002519 InitJavaModule(module, android.HostAndDeviceSupported)
Colin Cross36242852017-06-23 15:06:31 -07002520 return module
Colin Cross2fe66872015-03-30 17:20:39 -07002521}
2522
Colin Cross1b16b0e2019-02-12 14:41:32 -08002523// java_import imports one or more `.jar` files into the build graph as if they were built by a java_library_host
2524// module.
2525//
2526// A java_import_host has a single variant that expects a `.jar` file containing `.class` files that were
2527// compiled against a host bootclasspath.
Colin Cross74d73e22017-08-02 11:05:49 -07002528func ImportFactoryHost() android.Module {
2529 module := &Import{}
2530
2531 module.AddProperties(&module.properties)
2532
2533 android.InitPrebuiltModule(module, &module.properties.Jars)
Jiyong Park7f7766d2019-07-25 22:02:35 +09002534 android.InitApexModule(module)
Jooyung Han18020ea2019-11-13 10:50:48 +09002535 InitJavaModule(module, android.HostSupported)
Colin Cross74d73e22017-08-02 11:05:49 -07002536 return module
2537}
2538
Colin Cross42be7612019-02-21 18:12:14 -08002539// dex_import module
2540
2541type DexImportProperties struct {
Colin Cross5cfc70d2019-07-15 13:36:55 -07002542 Jars []string `android:"path"`
Jiyong Park4c4c0242019-10-21 14:53:15 +09002543
2544 // set the name of the output
2545 Stem *string
Colin Cross42be7612019-02-21 18:12:14 -08002546}
2547
2548type DexImport struct {
2549 android.ModuleBase
2550 android.DefaultableModuleBase
Jiyong Park7f7766d2019-07-25 22:02:35 +09002551 android.ApexModuleBase
Colin Cross42be7612019-02-21 18:12:14 -08002552 prebuilt android.Prebuilt
2553
2554 properties DexImportProperties
2555
2556 dexJarFile android.Path
2557 maybeStrippedDexJarFile android.Path
2558
2559 dexpreopter
2560}
2561
2562func (j *DexImport) Prebuilt() *android.Prebuilt {
2563 return &j.prebuilt
2564}
2565
2566func (j *DexImport) PrebuiltSrcs() []string {
2567 return j.properties.Jars
2568}
2569
2570func (j *DexImport) Name() string {
2571 return j.prebuilt.Name(j.ModuleBase.Name())
2572}
2573
Jiyong Park0b238752019-10-29 11:23:10 +09002574func (j *DexImport) Stem() string {
2575 return proptools.StringDefault(j.properties.Stem, j.ModuleBase.Name())
2576}
2577
Colin Cross42be7612019-02-21 18:12:14 -08002578func (j *DexImport) GenerateAndroidBuildActions(ctx android.ModuleContext) {
2579 if len(j.properties.Jars) != 1 {
2580 ctx.PropertyErrorf("jars", "exactly one jar must be provided")
2581 }
2582
Jiyong Park0b238752019-10-29 11:23:10 +09002583 j.dexpreopter.installPath = android.PathForModuleInstall(ctx, "framework", j.Stem()+".jar")
Colin Cross42be7612019-02-21 18:12:14 -08002584 j.dexpreopter.isInstallable = true
2585 j.dexpreopter.uncompressedDex = shouldUncompressDex(ctx, &j.dexpreopter)
2586
2587 inputJar := ctx.ExpandSource(j.properties.Jars[0], "jars")
2588 dexOutputFile := android.PathForModuleOut(ctx, ctx.ModuleName()+".jar")
2589
2590 if j.dexpreopter.uncompressedDex {
2591 rule := android.NewRuleBuilder()
2592
2593 temporary := android.PathForModuleOut(ctx, ctx.ModuleName()+".jar.unaligned")
2594 rule.Temporary(temporary)
2595
2596 // use zip2zip to uncompress classes*.dex files
2597 rule.Command().
Colin Crossee94d6a2019-07-08 17:08:34 -07002598 BuiltTool(ctx, "zip2zip").
Colin Cross42be7612019-02-21 18:12:14 -08002599 FlagWithInput("-i ", inputJar).
2600 FlagWithOutput("-o ", temporary).
2601 FlagWithArg("-0 ", "'classes*.dex'")
2602
2603 // use zipalign to align uncompressed classes*.dex files
2604 rule.Command().
Colin Crossee94d6a2019-07-08 17:08:34 -07002605 BuiltTool(ctx, "zipalign").
Colin Cross42be7612019-02-21 18:12:14 -08002606 Flag("-f").
2607 Text("4").
2608 Input(temporary).
2609 Output(dexOutputFile)
2610
2611 rule.DeleteTemporaryFiles()
2612
2613 rule.Build(pctx, ctx, "uncompress_dex", "uncompress dex")
2614 } else {
2615 ctx.Build(pctx, android.BuildParams{
2616 Rule: android.Cp,
2617 Input: inputJar,
2618 Output: dexOutputFile,
2619 })
2620 }
2621
2622 j.dexJarFile = dexOutputFile
2623
2624 dexOutputFile = j.dexpreopt(ctx, dexOutputFile)
2625
2626 j.maybeStrippedDexJarFile = dexOutputFile
2627
2628 ctx.InstallFile(android.PathForModuleInstall(ctx, "framework"),
2629 ctx.ModuleName()+".jar", dexOutputFile)
2630}
2631
2632func (j *DexImport) DexJar() android.Path {
2633 return j.dexJarFile
2634}
2635
2636// dex_import imports a `.jar` file containing classes.dex files.
2637//
2638// A dex_import module cannot be used as a dependency of a java_* or android_* module, it can only be installed
2639// to the device.
2640func DexImportFactory() android.Module {
2641 module := &DexImport{}
2642
2643 module.AddProperties(&module.properties)
2644
2645 android.InitPrebuiltModule(module, &module.properties.Jars)
Jiyong Park7f7766d2019-07-25 22:02:35 +09002646 android.InitApexModule(module)
Jooyung Han18020ea2019-11-13 10:50:48 +09002647 InitJavaModule(module, android.DeviceSupported)
Colin Cross42be7612019-02-21 18:12:14 -08002648 return module
2649}
2650
Colin Cross89536d42017-07-07 14:35:50 -07002651//
2652// Defaults
2653//
2654type Defaults struct {
2655 android.ModuleBase
2656 android.DefaultsModuleBase
Jiyong Park7f7766d2019-07-25 22:02:35 +09002657 android.ApexModuleBase
Colin Cross89536d42017-07-07 14:35:50 -07002658}
2659
Colin Cross1b16b0e2019-02-12 14:41:32 -08002660// java_defaults provides a set of properties that can be inherited by other java or android modules.
2661//
2662// A module can use the properties from a java_defaults module using `defaults: ["defaults_module_name"]`. Each
2663// property in the defaults module that exists in the depending module will be prepended to the depending module's
2664// value for that property.
2665//
2666// Example:
2667//
2668// java_defaults {
2669// name: "example_defaults",
2670// srcs: ["common/**/*.java"],
2671// javacflags: ["-Xlint:all"],
2672// aaptflags: ["--auto-add-overlay"],
2673// }
2674//
2675// java_library {
2676// name: "example",
2677// defaults: ["example_defaults"],
2678// srcs: ["example/**/*.java"],
2679// }
2680//
2681// is functionally identical to:
2682//
2683// java_library {
2684// name: "example",
2685// srcs: [
2686// "common/**/*.java",
2687// "example/**/*.java",
2688// ],
2689// javacflags: ["-Xlint:all"],
2690// }
Colin Cross89536d42017-07-07 14:35:50 -07002691func defaultsFactory() android.Module {
2692 return DefaultsFactory()
2693}
2694
Paul Duffin47357662019-12-05 14:07:14 +00002695func DefaultsFactory() android.Module {
Colin Cross89536d42017-07-07 14:35:50 -07002696 module := &Defaults{}
2697
Colin Cross89536d42017-07-07 14:35:50 -07002698 module.AddProperties(
2699 &CompilerProperties{},
2700 &CompilerDeviceProperties{},
Colin Cross43f08db2018-11-12 10:13:39 -08002701 &DexpreoptProperties{},
Dan Willemsen6424d172018-03-08 13:27:59 -08002702 &android.ProtoProperties{},
Colin Cross48de9a42018-10-02 13:53:33 -07002703 &aaptProperties{},
2704 &androidLibraryProperties{},
2705 &appProperties{},
2706 &appTestProperties{},
Jaewoong Jung525443a2019-02-28 15:35:54 -08002707 &overridableAppProperties{},
Colin Cross48de9a42018-10-02 13:53:33 -07002708 &ImportProperties{},
2709 &AARImportProperties{},
2710 &sdkLibraryProperties{},
Colin Cross42be7612019-02-21 18:12:14 -08002711 &DexImportProperties{},
Jooyung Han18020ea2019-11-13 10:50:48 +09002712 &android.ApexProperties{},
Colin Cross89536d42017-07-07 14:35:50 -07002713 )
2714
2715 android.InitDefaultsModule(module)
Colin Cross89536d42017-07-07 14:35:50 -07002716 return module
2717}
Nan Zhangea568a42017-11-08 21:20:04 -08002718
Sasha Smundak2a4549e2018-11-05 16:49:08 -08002719func kytheExtractJavaFactory() android.Singleton {
2720 return &kytheExtractJavaSingleton{}
2721}
2722
2723type kytheExtractJavaSingleton struct {
2724}
2725
2726func (ks *kytheExtractJavaSingleton) GenerateBuildActions(ctx android.SingletonContext) {
2727 var xrefTargets android.Paths
2728 ctx.VisitAllModules(func(module android.Module) {
2729 if javaModule, ok := module.(xref); ok {
2730 xrefTargets = append(xrefTargets, javaModule.XrefJavaFiles()...)
2731 }
2732 })
2733 // TODO(asmundak): perhaps emit a rule to output a warning if there were no xrefTargets
2734 if len(xrefTargets) > 0 {
2735 ctx.Build(pctx, android.BuildParams{
2736 Rule: blueprint.Phony,
2737 Output: android.PathForPhony(ctx, "xref_java"),
2738 Inputs: xrefTargets,
2739 })
2740 }
2741}
2742
Nan Zhangea568a42017-11-08 21:20:04 -08002743var Bool = proptools.Bool
Colin Cross38b40df2018-04-10 16:14:46 -07002744var BoolDefault = proptools.BoolDefault
Nan Zhangea568a42017-11-08 21:20:04 -08002745var String = proptools.String
Colin Cross0d0ba592018-02-20 13:33:42 -08002746var inList = android.InList