blob: 3501174672e8fd30706efaf70d94889ccc67a58f [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"
26
27 "github.com/google/blueprint"
Colin Cross76b5f0c2017-08-29 16:02:06 -070028 "github.com/google/blueprint/proptools"
Colin Cross2fe66872015-03-30 17:20:39 -070029
Colin Cross635c3b02016-05-18 15:37:25 -070030 "android/soong/android"
Colin Cross3e3e72d2017-06-22 17:20:19 -070031 "android/soong/java/config"
Colin Cross303e21f2018-08-07 16:49:25 -070032 "android/soong/tradefed"
Colin Cross2fe66872015-03-30 17:20:39 -070033)
34
Colin Cross463a90e2015-06-17 14:20:06 -070035func init() {
Colin Cross89536d42017-07-07 14:35:50 -070036 android.RegisterModuleType("java_defaults", defaultsFactory)
37
Colin Cross9ae1b922018-06-26 17:59:05 -070038 android.RegisterModuleType("java_library", LibraryFactory)
Colin Cross1b16b0e2019-02-12 14:41:32 -080039 android.RegisterModuleType("java_library_static", LibraryStaticFactory)
Colin Crossf506d872017-07-19 15:53:04 -070040 android.RegisterModuleType("java_library_host", LibraryHostFactory)
41 android.RegisterModuleType("java_binary", BinaryFactory)
42 android.RegisterModuleType("java_binary_host", BinaryHostFactory)
Colin Cross05638fc2018-04-09 18:40:24 -070043 android.RegisterModuleType("java_test", TestFactory)
44 android.RegisterModuleType("java_test_host", TestHostFactory)
Colin Cross74d73e22017-08-02 11:05:49 -070045 android.RegisterModuleType("java_import", ImportFactory)
46 android.RegisterModuleType("java_import_host", ImportFactoryHost)
Colin Cross463a90e2015-06-17 14:20:06 -070047
Colin Cross798bfce2016-10-12 14:28:16 -070048 android.RegisterSingletonType("logtags", LogtagsSingleton)
Colin Cross463a90e2015-06-17 14:20:06 -070049}
50
Colin Cross2fe66872015-03-30 17:20:39 -070051// TODO:
52// Autogenerated files:
Colin Cross2fe66872015-03-30 17:20:39 -070053// Renderscript
54// Post-jar passes:
55// Proguard
Colin Cross2fe66872015-03-30 17:20:39 -070056// Rmtypedefs
Colin Cross2fe66872015-03-30 17:20:39 -070057// DroidDoc
58// Findbugs
59
Colin Cross89536d42017-07-07 14:35:50 -070060type CompilerProperties struct {
Colin Cross7d5136f2015-05-11 13:39:40 -070061 // list of source files used to compile the Java module. May be .java, .logtags, .proto,
62 // or .aidl files.
Dan Willemsen2ef08f42015-06-30 18:15:24 -070063 Srcs []string `android:"arch_variant"`
64
65 // list of source files that should not be used to build the Java module.
66 // This is most useful in the arch/multilib variants to remove non-common files
67 Exclude_srcs []string `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -070068
69 // list of directories containing Java resources
Colin Cross86a63ff2017-09-27 17:33:10 -070070 Java_resource_dirs []string `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -070071
Colin Cross86a63ff2017-09-27 17:33:10 -070072 // list of directories that should be excluded from java_resource_dirs
73 Exclude_java_resource_dirs []string `android:"arch_variant"`
Dan Willemsen2ef08f42015-06-30 18:15:24 -070074
Colin Cross0f37af02017-09-27 17:42:05 -070075 // list of files to use as Java resources
76 Java_resources []string `android:"arch_variant"`
77
Colin Crosscedd4762018-09-13 11:26:19 -070078 // list of files that should be excluded from java_resources and java_resource_dirs
Colin Cross0f37af02017-09-27 17:42:05 -070079 Exclude_java_resources []string `android:"arch_variant"`
80
Paul Duffin2fbbfb82019-02-13 12:49:33 +000081 // don't build against the default libraries (bootclasspath, ext, and framework for device
82 // targets)
Colin Cross76b5f0c2017-08-29 16:02:06 -070083 No_standard_libs *bool
Colin Cross7d5136f2015-05-11 13:39:40 -070084
Paul Duffin2fbbfb82019-02-13 12:49:33 +000085 // don't build against the framework libraries (ext, and framework for device targets)
Colin Crossfa5eb232017-10-01 20:33:03 -070086 No_framework_libs *bool
87
Colin Cross7d5136f2015-05-11 13:39:40 -070088 // list of module-specific flags that will be used for javac compiles
89 Javacflags []string `android:"arch_variant"`
90
Zoran Jovanovic8736ce22018-08-21 17:10:29 +020091 // list of module-specific flags that will be used for kotlinc compiles
92 Kotlincflags []string `android:"arch_variant"`
93
Colin Cross7d5136f2015-05-11 13:39:40 -070094 // list of of java libraries that will be in the classpath
Colin Crosse8dc34a2017-07-19 11:22:16 -070095 Libs []string `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -070096
97 // list of java libraries that will be compiled into the resulting jar
Colin Crosse8dc34a2017-07-19 11:22:16 -070098 Static_libs []string `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -070099
100 // manifest file to be included in resulting jar
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700101 Manifest *string
Colin Cross7d5136f2015-05-11 13:39:40 -0700102
Colin Cross540eff82017-06-22 17:01:52 -0700103 // if not blank, run jarjar using the specified rules file
Colin Cross975f9f72017-10-17 13:55:55 -0700104 Jarjar_rules *string `android:"arch_variant"`
Colin Cross64162712017-08-08 13:17:59 -0700105
106 // If not blank, set the java version passed to javac as -source and -target
107 Java_version *string
Colin Cross2c429dc2017-08-31 16:45:16 -0700108
Colin Cross9ae1b922018-06-26 17:59:05 -0700109 // If set to true, allow this module to be dexed and installed on devices. Has no
110 // effect on host modules, which are always considered installable.
Colin Cross2c429dc2017-08-31 16:45:16 -0700111 Installable *bool
Colin Cross32f676a2017-09-06 13:41:06 -0700112
Colin Cross0f37af02017-09-27 17:42:05 -0700113 // If set to true, include sources used to compile the module in to the final jar
114 Include_srcs *bool
115
Colin Crossbe9cdb82019-01-21 21:37:16 -0800116 // List of modules to use as annotation processors
117 Plugins []string
Colin Cross1369cdb2017-09-29 17:58:17 -0700118
Nan Zhang61eaedb2017-11-02 13:28:15 -0700119 // The number of Java source entries each Javac instance can process
120 Javac_shard_size *int64
121
Nan Zhang5f8cb422018-02-06 10:34:32 -0800122 // Add host jdk tools.jar to bootclasspath
123 Use_tools_jar *bool
124
Colin Cross1369cdb2017-09-29 17:58:17 -0700125 Openjdk9 struct {
126 // List of source files that should only be used when passing -source 1.9
127 Srcs []string
128
129 // List of javac flags that should only be used when passing -source 1.9
130 Javacflags []string
131 }
Colin Crosscb933592017-11-22 13:49:43 -0800132
Colin Cross81440082018-08-15 20:21:55 -0700133 // When compiling language level 9+ .java code in packages that are part of
134 // a system module, patch_module names the module that your sources and
135 // dependencies should be patched into. The Android runtime currently
136 // doesn't implement the JEP 261 module system so this option is only
137 // supported at compile time. It should only be needed to compile tests in
138 // packages that exist in libcore and which are inconvenient to move
139 // elsewhere.
Tobias Thiererdda713d2018-09-19 16:16:19 +0100140 Patch_module *string `android:"arch_variant"`
Colin Cross81440082018-08-15 20:21:55 -0700141
Colin Crosscb933592017-11-22 13:49:43 -0800142 Jacoco struct {
143 // List of classes to include for instrumentation with jacoco to collect coverage
144 // information at runtime when building with coverage enabled. If unset defaults to all
145 // classes.
146 // Supports '*' as the last character of an entry in the list as a wildcard match.
147 // If preceded by '.' it matches all classes in the package and subpackages, otherwise
148 // it matches classes in the package that have the class name as a prefix.
149 Include_filter []string
150
151 // List of classes to exclude from instrumentation with jacoco to collect coverage
152 // information at runtime when building with coverage enabled. Overrides classes selected
153 // by the include_filter property.
154 // Supports '*' as the last character of an entry in the list as a wildcard match.
155 // If preceded by '.' it matches all classes in the package and subpackages, otherwise
156 // it matches classes in the package that have the class name as a prefix.
157 Exclude_filter []string
158 }
159
Andreas Gampef3e5b552018-01-22 21:27:21 -0800160 Errorprone struct {
161 // List of javac flags that should only be used when running errorprone.
162 Javacflags []string
163 }
164
Colin Cross0f2ee152017-12-14 15:22:43 -0800165 Proto struct {
166 // List of extra options that will be passed to the proto generator.
167 Output_params []string
168 }
169
Colin Crosscb933592017-11-22 13:49:43 -0800170 Instrument bool `blueprint:"mutated"`
Colin Cross540eff82017-06-22 17:01:52 -0700171}
172
Colin Cross89536d42017-07-07 14:35:50 -0700173type CompilerDeviceProperties struct {
Colin Cross540eff82017-06-22 17:01:52 -0700174 // list of module-specific flags that will be used for dex compiles
175 Dxflags []string `android:"arch_variant"`
176
Colin Cross83bb3162018-06-25 15:48:06 -0700177 // if not blank, set to the version of the sdk to compile against. Defaults to compiling against the current
178 // sdk if platform_apis is not set.
Nan Zhangea568a42017-11-08 21:20:04 -0800179 Sdk_version *string
Colin Cross7d5136f2015-05-11 13:39:40 -0700180
Colin Cross83bb3162018-06-25 15:48:06 -0700181 // if not blank, set the minimum version of the sdk that the compiled artifacts will run against.
182 // Defaults to sdk_version if not set.
183 Min_sdk_version *string
184
Dan Willemsen419290a2018-10-31 15:28:47 -0700185 // if not blank, set the targetSdkVersion in the AndroidManifest.xml.
186 // Defaults to sdk_version if not set.
187 Target_sdk_version *string
188
Colin Cross6af2e492018-05-22 11:12:33 -0700189 // if true, compile against the platform APIs instead of an SDK.
190 Platform_apis *bool
191
Colin Crossebe1a512017-11-14 13:12:14 -0800192 Aidl struct {
193 // Top level directories to pass to aidl tool
194 Include_dirs []string
Colin Cross7d5136f2015-05-11 13:39:40 -0700195
Colin Crossebe1a512017-11-14 13:12:14 -0800196 // Directories rooted at the Android.bp file to pass to aidl tool
197 Local_include_dirs []string
198
199 // directories that should be added as include directories for any aidl sources of modules
200 // that depend on this module, as well as to aidl for this module.
201 Export_include_dirs []string
Martijn Coeneneab15642018-03-09 09:29:59 +0100202
203 // whether to generate traces (for systrace) for this interface
204 Generate_traces *bool
Olivier Gaillard0a4cfbc2018-07-16 23:37:03 +0100205
206 // whether to generate Binder#GetTransaction name method.
207 Generate_get_transaction_name *bool
Colin Crossebe1a512017-11-14 13:12:14 -0800208 }
Colin Cross92430102017-10-09 14:59:32 -0700209
210 // If true, export a copy of the module as a -hostdex module for host testing.
211 Hostdex *bool
Colin Cross1369cdb2017-09-29 17:58:17 -0700212
David Brazdil17ef5632018-06-27 10:27:45 +0100213 // If set to true, compile dex regardless of installable. Defaults to false.
214 Compile_dex *bool
215
Colin Cross66dbc0b2017-12-28 12:23:20 -0800216 Optimize struct {
Colin Crossae5caf52018-05-22 11:11:52 -0700217 // If false, disable all optimization. Defaults to true for android_app and android_test
218 // modules, false for java_library and java_test modules.
Colin Cross66dbc0b2017-12-28 12:23:20 -0800219 Enabled *bool
220
221 // If true, optimize for size by removing unused code. Defaults to true for apps,
222 // false for libraries and tests.
223 Shrink *bool
224
225 // If true, optimize bytecode. Defaults to false.
226 Optimize *bool
227
228 // If true, obfuscate bytecode. Defaults to false.
229 Obfuscate *bool
230
231 // If true, do not use the flag files generated by aapt that automatically keep
232 // classes referenced by the app manifest. Defaults to false.
233 No_aapt_flags *bool
234
235 // Flags to pass to proguard.
236 Proguard_flags []string
237
238 // Specifies the locations of files containing proguard flags.
239 Proguard_flags_files []string
240 }
241
Colin Cross1369cdb2017-09-29 17:58:17 -0700242 // When targeting 1.9, override the modules to use with --system
243 System_modules *string
Colin Cross5a0dcd52018-10-05 14:20:06 -0700244
245 UncompressDex bool `blueprint:"mutated"`
Colin Cross43f08db2018-11-12 10:13:39 -0800246 IsSDKLibrary bool `blueprint:"mutated"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700247}
248
Colin Cross46c9b8b2017-06-22 16:51:17 -0700249// Module contains the properties and members used by all java module types
250type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700251 android.ModuleBase
Colin Cross89536d42017-07-07 14:35:50 -0700252 android.DefaultableModuleBase
Colin Cross2fe66872015-03-30 17:20:39 -0700253
Colin Cross89536d42017-07-07 14:35:50 -0700254 properties CompilerProperties
Colin Cross6af17aa2017-09-20 12:59:05 -0700255 protoProperties android.ProtoProperties
Colin Cross89536d42017-07-07 14:35:50 -0700256 deviceProperties CompilerDeviceProperties
Colin Cross2fe66872015-03-30 17:20:39 -0700257
Colin Cross331a1212018-08-15 20:40:52 -0700258 // jar file containing header classes including static library dependencies, suitable for
259 // inserting into the bootclasspath/classpath of another compile
Nan Zhanged19fc32017-10-19 13:06:22 -0700260 headerJarFile android.Path
261
Colin Cross331a1212018-08-15 20:40:52 -0700262 // jar file containing implementation classes including static library dependencies but no
263 // resources
Nan Zhanged19fc32017-10-19 13:06:22 -0700264 implementationJarFile android.Path
Colin Cross2fe66872015-03-30 17:20:39 -0700265
Colin Cross331a1212018-08-15 20:40:52 -0700266 // jar file containing only resources including from static library dependencies
267 resourceJar android.Path
268
269 // jar file containing implementation classes and resources including static library
270 // dependencies
271 implementationAndResourcesJar android.Path
272
273 // output file containing classes.dex and resources
Colin Cross6ade34f2017-09-15 13:00:47 -0700274 dexJarFile android.Path
275
Colin Cross43f08db2018-11-12 10:13:39 -0800276 // output file that contains classes.dex if it should be in the output file
277 maybeStrippedDexJarFile android.Path
278
Colin Crosscb933592017-11-22 13:49:43 -0800279 // output file containing uninstrumented classes that will be instrumented by jacoco
280 jacocoReportClassesFile android.Path
281
Colin Cross66dbc0b2017-12-28 12:23:20 -0800282 // output file containing mapping of obfuscated names
283 proguardDictionary android.Path
284
Colin Cross331a1212018-08-15 20:40:52 -0700285 // output file of the module, which may be a classes jar or a dex jar
Colin Cross635c3b02016-05-18 15:37:25 -0700286 outputFile android.Path
Colin Crossb7a63242015-04-16 14:09:14 -0700287
Colin Cross635c3b02016-05-18 15:37:25 -0700288 exportAidlIncludeDirs android.Paths
Colin Crossc0b06f12015-04-08 13:03:43 -0700289
Colin Cross635c3b02016-05-18 15:37:25 -0700290 logtagsSrcs android.Paths
Colin Crossf05fe972015-04-10 17:45:20 -0700291
Colin Cross2fe66872015-03-30 17:20:39 -0700292 // installed file for binary dependency
Colin Cross635c3b02016-05-18 15:37:25 -0700293 installFile android.Path
Colin Cross5ab4e6d2017-11-22 16:20:45 -0800294
295 // list of .java files and srcjars that was passed to javac
296 compiledJavaSrcs android.Paths
297 compiledSrcJars android.Paths
Colin Cross66dbc0b2017-12-28 12:23:20 -0800298
299 // list of extra progurad flag files
300 extraProguardFlagFiles android.Paths
Jiyong Park1be96912018-05-28 18:02:19 +0900301
Colin Cross094054a2018-10-17 15:10:48 -0700302 // manifest file to use instead of properties.Manifest
303 overrideManifest android.OptionalPath
304
Jiyong Park1be96912018-05-28 18:02:19 +0900305 // list of SDK lib names that this java moudule is exporting
306 exportedSdkLibs []string
Brandon Lee5d45c6f2018-08-15 15:35:38 -0700307
308 // list of source files, collected from compiledJavaSrcs and compiledSrcJars
309 // filter out Exclude_srcs, will be used by android.IDEInfo struct
310 expandIDEInfoCompiledSrcs []string
Colin Cross43f08db2018-11-12 10:13:39 -0800311
Steven Morelandc4efd9c2019-01-18 11:51:25 -0800312 // expanded Jarjar_rules
313 expandJarjarRules android.Path
314
Colin Crossf24a22a2019-01-31 14:12:44 -0800315 hiddenAPI
Colin Cross43f08db2018-11-12 10:13:39 -0800316 dexpreopter
Colin Cross2fe66872015-03-30 17:20:39 -0700317}
318
Colin Cross54250902017-12-05 09:28:08 -0800319func (j *Module) Srcs() android.Paths {
Colin Cross3063b782018-08-15 11:19:12 -0700320 return android.Paths{j.outputFile}
Colin Cross54250902017-12-05 09:28:08 -0800321}
322
Jiyong Park8fd61922018-11-08 02:50:25 +0900323func (j *Module) DexJarFile() android.Path {
324 return j.dexJarFile
325}
326
Colin Cross54250902017-12-05 09:28:08 -0800327var _ android.SourceFileProducer = (*Module)(nil)
328
Colin Crossf506d872017-07-19 15:53:04 -0700329type Dependency interface {
Nan Zhanged19fc32017-10-19 13:06:22 -0700330 HeaderJars() android.Paths
331 ImplementationJars() android.Paths
Colin Cross331a1212018-08-15 20:40:52 -0700332 ResourceJars() android.Paths
333 ImplementationAndResourcesJars() android.Paths
Colin Crossf24a22a2019-01-31 14:12:44 -0800334 DexJar() android.Path
Colin Cross635c3b02016-05-18 15:37:25 -0700335 AidlIncludeDirs() android.Paths
Jiyong Park1be96912018-05-28 18:02:19 +0900336 ExportedSdkLibs() []string
Colin Cross2fe66872015-03-30 17:20:39 -0700337}
338
Jiyong Parkc678ad32018-04-10 13:07:10 +0900339type SdkLibraryDependency interface {
Colin Cross897d2ed2019-02-11 14:03:51 -0800340 SdkHeaderJars(ctx android.BaseContext, sdkVersion string) android.Paths
341 SdkImplementationJars(ctx android.BaseContext, sdkVersion string) android.Paths
Jiyong Parkc678ad32018-04-10 13:07:10 +0900342}
343
Nan Zhangb2b33de2018-02-23 11:18:47 -0800344type SrcDependency interface {
345 CompiledSrcs() android.Paths
346 CompiledSrcJars() android.Paths
347}
348
349func (j *Module) CompiledSrcs() android.Paths {
350 return j.compiledJavaSrcs
351}
352
353func (j *Module) CompiledSrcJars() android.Paths {
354 return j.compiledSrcJars
355}
356
357var _ SrcDependency = (*Module)(nil)
358
Colin Cross89536d42017-07-07 14:35:50 -0700359func InitJavaModule(module android.DefaultableModule, hod android.HostOrDeviceSupported) {
360 android.InitAndroidArchModule(module, hod, android.MultilibCommon)
361 android.InitDefaultableModule(module)
362}
363
Colin Crossbe1da472017-07-07 15:59:46 -0700364type dependencyTag struct {
365 blueprint.BaseDependencyTag
366 name string
Colin Cross2fe66872015-03-30 17:20:39 -0700367}
368
Colin Crossa4f08812018-10-02 22:03:40 -0700369type jniDependencyTag struct {
370 blueprint.BaseDependencyTag
371 target android.Target
372}
373
Colin Crossbe1da472017-07-07 15:59:46 -0700374var (
Colin Cross4b964c02018-10-15 16:18:06 -0700375 staticLibTag = dependencyTag{name: "staticlib"}
376 libTag = dependencyTag{name: "javalib"}
Colin Crossbe9cdb82019-01-21 21:37:16 -0800377 pluginTag = dependencyTag{name: "plugin"}
Colin Cross4b964c02018-10-15 16:18:06 -0700378 bootClasspathTag = dependencyTag{name: "bootclasspath"}
379 systemModulesTag = dependencyTag{name: "system modules"}
380 frameworkResTag = dependencyTag{name: "framework-res"}
381 frameworkApkTag = dependencyTag{name: "framework-apk"}
382 kotlinStdlibTag = dependencyTag{name: "kotlin-stdlib"}
Colin Crossafbb1732019-01-17 15:42:52 -0800383 kotlinAnnotationsTag = dependencyTag{name: "kotlin-annotations"}
Colin Cross4b964c02018-10-15 16:18:06 -0700384 proguardRaiseTag = dependencyTag{name: "proguard-raise"}
385 certificateTag = dependencyTag{name: "certificate"}
386 instrumentationForTag = dependencyTag{name: "instrumentation_for"}
Colin Crossbe1da472017-07-07 15:59:46 -0700387)
Colin Cross2fe66872015-03-30 17:20:39 -0700388
Colin Crossfc3674a2017-09-18 17:41:52 -0700389type sdkDep struct {
Colin Cross47ff2522017-10-02 14:22:08 -0700390 useModule, useFiles, useDefaultLibs, invalidVersion bool
391
Colin Cross86a60ae2018-05-29 14:44:55 -0700392 modules []string
Colin Cross1369cdb2017-09-29 17:58:17 -0700393 systemModules string
394
Colin Crossa97c5d32018-03-28 14:58:31 -0700395 frameworkResModule string
396
Colin Cross86a60ae2018-05-29 14:44:55 -0700397 jars android.Paths
Colin Cross1369cdb2017-09-29 17:58:17 -0700398 aidl android.Path
399}
400
Colin Crossa4f08812018-10-02 22:03:40 -0700401type jniLib struct {
402 name string
403 path android.Path
404 target android.Target
405}
406
Colin Cross3144dfc2018-01-03 15:06:47 -0800407func (j *Module) shouldInstrument(ctx android.BaseContext) bool {
408 return j.properties.Instrument && ctx.Config().IsEnvTrue("EMMA_INSTRUMENT")
409}
410
411func (j *Module) shouldInstrumentStatic(ctx android.BaseContext) bool {
412 return j.shouldInstrument(ctx) &&
413 (ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_STATIC") ||
414 ctx.Config().UnbundledBuild())
415}
416
Colin Cross83bb3162018-06-25 15:48:06 -0700417func (j *Module) sdkVersion() string {
418 return String(j.deviceProperties.Sdk_version)
419}
420
421func (j *Module) minSdkVersion() string {
422 if j.deviceProperties.Min_sdk_version != nil {
423 return *j.deviceProperties.Min_sdk_version
424 }
425 return j.sdkVersion()
426}
427
Dan Willemsen419290a2018-10-31 15:28:47 -0700428func (j *Module) targetSdkVersion() string {
429 if j.deviceProperties.Target_sdk_version != nil {
430 return *j.deviceProperties.Target_sdk_version
431 }
432 return j.sdkVersion()
433}
434
Colin Crossbe1da472017-07-07 15:59:46 -0700435func (j *Module) deps(ctx android.BottomUpMutatorContext) {
Colin Cross1369cdb2017-09-29 17:58:17 -0700436 if ctx.Device() {
Colin Crossff3ae9d2018-04-10 16:15:18 -0700437 if !Bool(j.properties.No_standard_libs) {
Colin Cross83bb3162018-06-25 15:48:06 -0700438 sdkDep := decodeSdkDep(ctx, sdkContext(j))
Colin Crossfc3674a2017-09-18 17:41:52 -0700439 if sdkDep.useDefaultLibs {
Colin Cross42d48b72018-08-29 14:10:52 -0700440 ctx.AddVariationDependencies(nil, bootClasspathTag, config.DefaultBootclasspathLibraries...)
Tobias Thierer06dd04f2018-09-11 16:21:05 +0100441 ctx.AddVariationDependencies(nil, systemModulesTag, config.DefaultSystemModules)
Colin Crossff3ae9d2018-04-10 16:15:18 -0700442 if !Bool(j.properties.No_framework_libs) {
Colin Cross42d48b72018-08-29 14:10:52 -0700443 ctx.AddVariationDependencies(nil, libTag, config.DefaultLibraries...)
Colin Crossfa5eb232017-10-01 20:33:03 -0700444 }
Colin Cross1369cdb2017-09-29 17:58:17 -0700445 } else if sdkDep.useModule {
Tobias Thierer06dd04f2018-09-11 16:21:05 +0100446 ctx.AddVariationDependencies(nil, systemModulesTag, sdkDep.systemModules)
Colin Cross42d48b72018-08-29 14:10:52 -0700447 ctx.AddVariationDependencies(nil, bootClasspathTag, sdkDep.modules...)
Colin Cross66dbc0b2017-12-28 12:23:20 -0800448 if Bool(j.deviceProperties.Optimize.Enabled) {
Colin Cross42d48b72018-08-29 14:10:52 -0700449 ctx.AddVariationDependencies(nil, proguardRaiseTag, config.DefaultBootclasspathLibraries...)
450 ctx.AddVariationDependencies(nil, proguardRaiseTag, config.DefaultLibraries...)
Colin Cross66dbc0b2017-12-28 12:23:20 -0800451 }
Colin Crossbe1da472017-07-07 15:59:46 -0700452 }
Colin Cross1369cdb2017-09-29 17:58:17 -0700453 } else if j.deviceProperties.System_modules == nil {
454 ctx.PropertyErrorf("no_standard_libs",
455 "system_modules is required to be set when no_standard_libs is true, did you mean no_framework_libs?")
Tobias Thierer06dd04f2018-09-11 16:21:05 +0100456 } else if *j.deviceProperties.System_modules != "none" {
Colin Cross42d48b72018-08-29 14:10:52 -0700457 ctx.AddVariationDependencies(nil, systemModulesTag, *j.deviceProperties.System_modules)
Colin Cross2fe66872015-03-30 17:20:39 -0700458 }
Mathew Inwoodebe29ce2018-09-04 14:26:19 +0100459 if (ctx.ModuleName() == "framework") || (ctx.ModuleName() == "framework-annotation-proc") {
Colin Cross42d48b72018-08-29 14:10:52 -0700460 ctx.AddVariationDependencies(nil, frameworkResTag, "framework-res")
Colin Cross5ab4e6d2017-11-22 16:20:45 -0800461 }
Nan Zhangb2b33de2018-02-23 11:18:47 -0800462 if ctx.ModuleName() == "android_stubs_current" ||
463 ctx.ModuleName() == "android_system_stubs_current" ||
Nan Zhang863f05b2018-08-07 13:41:10 -0700464 ctx.ModuleName() == "android_test_stubs_current" {
Colin Cross42d48b72018-08-29 14:10:52 -0700465 ctx.AddVariationDependencies(nil, frameworkApkTag, "framework-res")
Nan Zhangb2b33de2018-02-23 11:18:47 -0800466 }
Colin Cross2fe66872015-03-30 17:20:39 -0700467 }
Colin Cross1369cdb2017-09-29 17:58:17 -0700468
Colin Cross42d48b72018-08-29 14:10:52 -0700469 ctx.AddVariationDependencies(nil, libTag, j.properties.Libs...)
470 ctx.AddVariationDependencies(nil, staticLibTag, j.properties.Static_libs...)
Colin Crossa4f08812018-10-02 22:03:40 -0700471
Colin Crossbe9cdb82019-01-21 21:37:16 -0800472 ctx.AddFarVariationDependencies([]blueprint.Variation{
473 {Mutator: "arch", Variation: ctx.Config().BuildOsCommonVariant},
474 }, pluginTag, j.properties.Plugins...)
475
Colin Cross7f9036c2017-08-30 13:27:57 -0700476 android.ExtractSourcesDeps(ctx, j.properties.Srcs)
Nan Zhang27e284d2018-02-09 21:03:53 +0000477 android.ExtractSourcesDeps(ctx, j.properties.Exclude_srcs)
Colin Cross0f37af02017-09-27 17:42:05 -0700478 android.ExtractSourcesDeps(ctx, j.properties.Java_resources)
Colin Cross366938f2017-12-11 16:29:02 -0800479 android.ExtractSourceDeps(ctx, j.properties.Manifest)
Steven Morelandc4efd9c2019-01-18 11:51:25 -0800480 android.ExtractSourceDeps(ctx, j.properties.Jarjar_rules)
Colin Cross6af17aa2017-09-20 12:59:05 -0700481
482 if j.hasSrcExt(".proto") {
483 protoDeps(ctx, &j.protoProperties)
484 }
Colin Cross93e85952017-08-15 13:34:18 -0700485
486 if j.hasSrcExt(".kt") {
487 // TODO(ccross): move this to a mutator pass that can tell if generated sources contain
488 // Kotlin files
Colin Cross42d48b72018-08-29 14:10:52 -0700489 ctx.AddVariationDependencies(nil, kotlinStdlibTag, "kotlin-stdlib")
Colin Cross7788c122019-01-23 16:14:02 -0800490 if len(j.properties.Plugins) > 0 {
Colin Crossafbb1732019-01-17 15:42:52 -0800491 ctx.AddVariationDependencies(nil, kotlinAnnotationsTag, "kotlin-annotations")
492 }
Colin Cross93e85952017-08-15 13:34:18 -0700493 }
Colin Cross3144dfc2018-01-03 15:06:47 -0800494
495 if j.shouldInstrumentStatic(ctx) {
Colin Cross42d48b72018-08-29 14:10:52 -0700496 ctx.AddVariationDependencies(nil, staticLibTag, "jacocoagent")
Colin Cross3144dfc2018-01-03 15:06:47 -0800497 }
Colin Cross6af17aa2017-09-20 12:59:05 -0700498}
499
500func hasSrcExt(srcs []string, ext string) bool {
501 for _, src := range srcs {
502 if filepath.Ext(src) == ext {
503 return true
504 }
505 }
506
507 return false
508}
509
Nan Zhang61eaedb2017-11-02 13:28:15 -0700510func shardPaths(paths android.Paths, shardSize int) []android.Paths {
511 ret := make([]android.Paths, 0, (len(paths)+shardSize-1)/shardSize)
512 for len(paths) > shardSize {
513 ret = append(ret, paths[0:shardSize])
514 paths = paths[shardSize:]
515 }
516 if len(paths) > 0 {
517 ret = append(ret, paths)
518 }
519 return ret
520}
521
Colin Cross6af17aa2017-09-20 12:59:05 -0700522func (j *Module) hasSrcExt(ext string) bool {
523 return hasSrcExt(j.properties.Srcs, ext)
Colin Cross2fe66872015-03-30 17:20:39 -0700524}
525
Colin Cross46c9b8b2017-06-22 16:51:17 -0700526func (j *Module) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.OptionalPath,
Colin Cross635c3b02016-05-18 15:37:25 -0700527 aidlIncludeDirs android.Paths) []string {
Colin Crossc0b06f12015-04-08 13:03:43 -0700528
Colin Crossebe1a512017-11-14 13:12:14 -0800529 aidlIncludes := android.PathsForModuleSrc(ctx, j.deviceProperties.Aidl.Local_include_dirs)
530 aidlIncludes = append(aidlIncludes,
531 android.PathsForModuleSrc(ctx, j.deviceProperties.Aidl.Export_include_dirs)...)
532 aidlIncludes = append(aidlIncludes,
533 android.PathsForSource(ctx, j.deviceProperties.Aidl.Include_dirs)...)
Colin Crossc0b06f12015-04-08 13:03:43 -0700534
Steven Moreland36b130f2019-02-05 17:02:55 -0800535 flags := []string{}
Steven Moreland667f6882018-07-26 12:55:08 -0700536
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700537 if aidlPreprocess.Valid() {
538 flags = append(flags, "-p"+aidlPreprocess.String())
Colin Crossc0b06f12015-04-08 13:03:43 -0700539 } else {
Colin Cross635c3b02016-05-18 15:37:25 -0700540 flags = append(flags, android.JoinWithPrefix(aidlIncludeDirs.Strings(), "-I"))
Colin Crossc0b06f12015-04-08 13:03:43 -0700541 }
542
Colin Cross635c3b02016-05-18 15:37:25 -0700543 flags = append(flags, android.JoinWithPrefix(j.exportAidlIncludeDirs.Strings(), "-I"))
Colin Crossebe1a512017-11-14 13:12:14 -0800544 flags = append(flags, android.JoinWithPrefix(aidlIncludes.Strings(), "-I"))
Colin Cross635c3b02016-05-18 15:37:25 -0700545 flags = append(flags, "-I"+android.PathForModuleSrc(ctx).String())
Colin Cross32f38982018-02-22 11:47:25 -0800546 if src := android.ExistentPathForSource(ctx, ctx.ModuleDir(), "src"); src.Valid() {
Colin Crossd48633a2017-07-13 14:41:17 -0700547 flags = append(flags, "-I"+src.String())
548 }
Colin Crossc0b06f12015-04-08 13:03:43 -0700549
Martijn Coeneneab15642018-03-09 09:29:59 +0100550 if Bool(j.deviceProperties.Aidl.Generate_traces) {
551 flags = append(flags, "-t")
552 }
553
Olivier Gaillard0a4cfbc2018-07-16 23:37:03 +0100554 if Bool(j.deviceProperties.Aidl.Generate_get_transaction_name) {
555 flags = append(flags, "--transaction_names")
556 }
557
Colin Crossf03c82b2015-04-13 13:53:40 -0700558 return flags
Colin Crossc0b06f12015-04-08 13:03:43 -0700559}
560
Colin Cross32f676a2017-09-06 13:41:06 -0700561type deps struct {
Nan Zhang581fd212018-01-10 16:06:12 -0800562 classpath classpath
563 bootClasspath classpath
Colin Cross6a77c982018-06-19 22:43:34 -0700564 processorPath classpath
Colin Crossbe9cdb82019-01-21 21:37:16 -0800565 processorClasses []string
Colin Cross6ade34f2017-09-15 13:00:47 -0700566 staticJars android.Paths
Nan Zhanged19fc32017-10-19 13:06:22 -0700567 staticHeaderJars android.Paths
Colin Cross331a1212018-08-15 20:40:52 -0700568 staticResourceJars android.Paths
Colin Cross6ade34f2017-09-15 13:00:47 -0700569 aidlIncludeDirs android.Paths
Nan Zhangb2b33de2018-02-23 11:18:47 -0800570 srcs android.Paths
Colin Cross59149b62017-10-16 18:07:29 -0700571 srcJars android.Paths
Colin Cross1369cdb2017-09-29 17:58:17 -0700572 systemModules android.Path
Colin Cross6ade34f2017-09-15 13:00:47 -0700573 aidlPreprocess android.OptionalPath
Colin Cross93e85952017-08-15 13:34:18 -0700574 kotlinStdlib android.Paths
Colin Crossafbb1732019-01-17 15:42:52 -0800575 kotlinAnnotations android.Paths
Colin Crossbe9cdb82019-01-21 21:37:16 -0800576
577 disableTurbine bool
Colin Cross32f676a2017-09-06 13:41:06 -0700578}
Colin Cross2fe66872015-03-30 17:20:39 -0700579
Colin Cross54250902017-12-05 09:28:08 -0800580func checkProducesJars(ctx android.ModuleContext, dep android.SourceFileProducer) {
581 for _, f := range dep.Srcs() {
582 if f.Ext() != ".jar" {
583 ctx.ModuleErrorf("genrule %q must generate files ending with .jar to be used as a libs or static_libs dependency",
584 ctx.OtherModuleName(dep.(blueprint.Module)))
585 }
586 }
587}
588
Jiyong Park2d492942018-03-05 17:44:10 +0900589type linkType int
590
591const (
592 javaCore linkType = iota
593 javaSdk
594 javaSystem
595 javaPlatform
596)
597
Jiyong Park46f78fb2018-10-20 16:33:17 +0900598func getLinkType(m *Module, name string) (ret linkType, stubs bool) {
Colin Cross83bb3162018-06-25 15:48:06 -0700599 ver := m.sdkVersion()
Colin Crossf19b9bb2018-03-26 14:42:44 -0700600 switch {
Jiyong Park46f78fb2018-10-20 16:33:17 +0900601 case name == "core.current.stubs" || name == "core.platform.api.stubs" ||
602 name == "stub-annotations" || name == "private-stub-annotations-jar" ||
603 name == "core-lambda-stubs":
604 return javaCore, true
Neil Fuller401eeba2018-10-18 19:48:58 +0100605 case ver == "core_current":
Jiyong Park46f78fb2018-10-20 16:33:17 +0900606 return javaCore, false
607 case name == "android_system_stubs_current":
608 return javaSystem, true
609 case strings.HasPrefix(ver, "system_"):
610 return javaSystem, false
611 case name == "android_test_stubs_current":
612 return javaSystem, true
613 case strings.HasPrefix(ver, "test_"):
614 return javaPlatform, false
615 case name == "android_stubs_current":
616 return javaSdk, true
617 case ver == "current":
618 return javaSdk, false
Colin Crossf19b9bb2018-03-26 14:42:44 -0700619 case ver == "":
Jiyong Park46f78fb2018-10-20 16:33:17 +0900620 return javaPlatform, false
Colin Crossf19b9bb2018-03-26 14:42:44 -0700621 default:
622 if _, err := strconv.Atoi(ver); err != nil {
623 panic(fmt.Errorf("expected sdk_version to be a number, got %q", ver))
624 }
Jiyong Park46f78fb2018-10-20 16:33:17 +0900625 return javaSdk, false
Jiyong Park2d492942018-03-05 17:44:10 +0900626 }
627}
628
Jiyong Park750e5572018-01-31 00:20:13 +0900629func checkLinkType(ctx android.ModuleContext, from *Module, to *Library, tag dependencyTag) {
Colin Crossf19b9bb2018-03-26 14:42:44 -0700630 if ctx.Host() {
631 return
632 }
633
Jiyong Park46f78fb2018-10-20 16:33:17 +0900634 myLinkType, stubs := getLinkType(from, ctx.ModuleName())
635 if stubs {
636 return
637 }
638 otherLinkType, _ := getLinkType(&to.Module, ctx.OtherModuleName(to))
Jiyong Park2d492942018-03-05 17:44:10 +0900639 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."
640
641 switch myLinkType {
642 case javaCore:
643 if otherLinkType != javaCore {
644 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 +0900645 ctx.OtherModuleName(to))
646 }
Jiyong Park2d492942018-03-05 17:44:10 +0900647 break
648 case javaSdk:
649 if otherLinkType != javaCore && otherLinkType != javaSdk {
650 ctx.ModuleErrorf("compiles against Android API, but dependency %q is compiling against non-public Android API."+commonMessage,
651 ctx.OtherModuleName(to))
652 }
653 break
654 case javaSystem:
655 if otherLinkType == javaPlatform {
656 ctx.ModuleErrorf("compiles against system API, but dependency %q is compiling against private API."+commonMessage,
657 ctx.OtherModuleName(to))
658 }
659 break
660 case javaPlatform:
661 // no restriction on link-type
662 break
Jiyong Park750e5572018-01-31 00:20:13 +0900663 }
664}
665
Colin Cross32f676a2017-09-06 13:41:06 -0700666func (j *Module) collectDeps(ctx android.ModuleContext) deps {
667 var deps deps
Colin Crossfc3674a2017-09-18 17:41:52 -0700668
Colin Cross300f0382018-03-06 13:11:51 -0800669 if ctx.Device() {
Colin Cross83bb3162018-06-25 15:48:06 -0700670 sdkDep := decodeSdkDep(ctx, sdkContext(j))
Colin Cross300f0382018-03-06 13:11:51 -0800671 if sdkDep.invalidVersion {
Colin Cross86a60ae2018-05-29 14:44:55 -0700672 ctx.AddMissingDependencies(sdkDep.modules)
Colin Cross300f0382018-03-06 13:11:51 -0800673 } else if sdkDep.useFiles {
674 // sdkDep.jar is actually equivalent to turbine header.jar.
Colin Cross86a60ae2018-05-29 14:44:55 -0700675 deps.classpath = append(deps.classpath, sdkDep.jars...)
Colin Cross300f0382018-03-06 13:11:51 -0800676 deps.aidlIncludeDirs = append(deps.aidlIncludeDirs, sdkDep.aidl)
677 }
Colin Crossfc3674a2017-09-18 17:41:52 -0700678 }
679
Colin Crossd11fcda2017-10-23 17:59:01 -0700680 ctx.VisitDirectDeps(func(module android.Module) {
Colin Cross2fe66872015-03-30 17:20:39 -0700681 otherName := ctx.OtherModuleName(module)
Colin Crossec7a0422017-07-07 14:47:12 -0700682 tag := ctx.OtherModuleDependencyTag(module)
683
Colin Crossa4f08812018-10-02 22:03:40 -0700684 if _, ok := tag.(*jniDependencyTag); ok {
Colin Crossbd01e2a2018-10-04 15:21:03 -0700685 // Handled by AndroidApp.collectAppDeps
686 return
687 }
688 if tag == certificateTag {
689 // Handled by AndroidApp.collectAppDeps
Colin Crossa4f08812018-10-02 22:03:40 -0700690 return
691 }
692
Jiyong Park750e5572018-01-31 00:20:13 +0900693 if to, ok := module.(*Library); ok {
Colin Crossa97c5d32018-03-28 14:58:31 -0700694 switch tag {
695 case bootClasspathTag, libTag, staticLibTag:
696 checkLinkType(ctx, j, to, tag.(dependencyTag))
697 }
Jiyong Park750e5572018-01-31 00:20:13 +0900698 }
Colin Cross54250902017-12-05 09:28:08 -0800699 switch dep := module.(type) {
Colin Cross897d2ed2019-02-11 14:03:51 -0800700 case SdkLibraryDependency:
701 switch tag {
702 case libTag:
703 deps.classpath = append(deps.classpath, dep.SdkHeaderJars(ctx, j.sdkVersion())...)
704 // names of sdk libs that are directly depended are exported
705 j.exportedSdkLibs = append(j.exportedSdkLibs, otherName)
706 default:
707 ctx.ModuleErrorf("dependency on java_sdk_library %q can only be in libs", otherName)
708 }
Colin Cross54250902017-12-05 09:28:08 -0800709 case Dependency:
710 switch tag {
711 case bootClasspathTag:
712 deps.bootClasspath = append(deps.bootClasspath, dep.HeaderJars()...)
Colin Cross4b964c02018-10-15 16:18:06 -0700713 case libTag, instrumentationForTag:
Colin Cross54250902017-12-05 09:28:08 -0800714 deps.classpath = append(deps.classpath, dep.HeaderJars()...)
Jiyong Park1be96912018-05-28 18:02:19 +0900715 // sdk lib names from dependencies are re-exported
716 j.exportedSdkLibs = append(j.exportedSdkLibs, dep.ExportedSdkLibs()...)
Colin Cross54250902017-12-05 09:28:08 -0800717 case staticLibTag:
718 deps.classpath = append(deps.classpath, dep.HeaderJars()...)
719 deps.staticJars = append(deps.staticJars, dep.ImplementationJars()...)
720 deps.staticHeaderJars = append(deps.staticHeaderJars, dep.HeaderJars()...)
Colin Cross331a1212018-08-15 20:40:52 -0700721 deps.staticResourceJars = append(deps.staticResourceJars, dep.ResourceJars()...)
Jiyong Park1be96912018-05-28 18:02:19 +0900722 // sdk lib names from dependencies are re-exported
723 j.exportedSdkLibs = append(j.exportedSdkLibs, dep.ExportedSdkLibs()...)
Colin Crossbe9cdb82019-01-21 21:37:16 -0800724 case pluginTag:
725 if plugin, ok := dep.(*Plugin); ok {
726 deps.processorPath = append(deps.processorPath, dep.ImplementationAndResourcesJars()...)
727 if plugin.pluginProperties.Processor_class != nil {
728 deps.processorClasses = append(deps.processorClasses, *plugin.pluginProperties.Processor_class)
729 }
730 deps.disableTurbine = deps.disableTurbine || Bool(plugin.pluginProperties.Generates_api)
731 } else {
732 ctx.PropertyErrorf("plugins", "%q is not a java_plugin module", otherName)
733 }
Colin Cross54250902017-12-05 09:28:08 -0800734 case frameworkResTag:
Mathew Inwoodebe29ce2018-09-04 14:26:19 +0100735 if (ctx.ModuleName() == "framework") || (ctx.ModuleName() == "framework-annotation-proc") {
Colin Cross54250902017-12-05 09:28:08 -0800736 // framework.jar has a one-off dependency on the R.java and Manifest.java files
737 // generated by framework-res.apk
738 deps.srcJars = append(deps.srcJars, dep.(*AndroidApp).aaptSrcJar)
739 }
Nan Zhangb2b33de2018-02-23 11:18:47 -0800740 case frameworkApkTag:
741 if ctx.ModuleName() == "android_stubs_current" ||
742 ctx.ModuleName() == "android_system_stubs_current" ||
Nan Zhang863f05b2018-08-07 13:41:10 -0700743 ctx.ModuleName() == "android_test_stubs_current" {
Nan Zhangb2b33de2018-02-23 11:18:47 -0800744 // framework stubs.jar need to depend on framework-res.apk, in order to pull the
745 // resource files out of there for aapt.
746 //
747 // Normally the package rule runs aapt, which includes the resource,
748 // but we're not running that in our package rule so just copy in the
749 // resource files here.
Colin Cross331a1212018-08-15 20:40:52 -0700750 deps.staticResourceJars = append(deps.staticResourceJars, dep.(*AndroidApp).exportPackage)
Nan Zhangb2b33de2018-02-23 11:18:47 -0800751 }
Colin Cross54250902017-12-05 09:28:08 -0800752 case kotlinStdlibTag:
753 deps.kotlinStdlib = dep.HeaderJars()
Colin Crossafbb1732019-01-17 15:42:52 -0800754 case kotlinAnnotationsTag:
755 deps.kotlinAnnotations = dep.HeaderJars()
Colin Cross54250902017-12-05 09:28:08 -0800756 }
757
758 deps.aidlIncludeDirs = append(deps.aidlIncludeDirs, dep.AidlIncludeDirs()...)
759 case android.SourceFileProducer:
760 switch tag {
761 case libTag:
762 checkProducesJars(ctx, dep)
763 deps.classpath = append(deps.classpath, dep.Srcs()...)
764 case staticLibTag:
765 checkProducesJars(ctx, dep)
766 deps.classpath = append(deps.classpath, dep.Srcs()...)
767 deps.staticJars = append(deps.staticJars, dep.Srcs()...)
768 deps.staticHeaderJars = append(deps.staticHeaderJars, dep.Srcs()...)
769 case android.DefaultsDepTag, android.SourceDepTag:
770 // Nothing to do
Sundong Ahn054b19a2018-10-19 13:46:09 +0900771 case publicApiFileTag, systemApiFileTag, testApiFileTag:
772 // Nothing to do
Colin Cross54250902017-12-05 09:28:08 -0800773 default:
774 ctx.ModuleErrorf("dependency on genrule %q may only be in srcs, libs, or static_libs", otherName)
775 }
776 default:
Colin Crossec7a0422017-07-07 14:47:12 -0700777 switch tag {
778 case android.DefaultsDepTag, android.SourceDepTag:
Dan Willemsend6ba0d52017-09-13 15:46:47 -0700779 // Nothing to do
Colin Cross1369cdb2017-09-29 17:58:17 -0700780 case systemModulesTag:
781 if deps.systemModules != nil {
782 panic("Found two system module dependencies")
783 }
784 sm := module.(*SystemModules)
785 if sm.outputFile == nil {
786 panic("Missing directory for system module dependency")
787 }
788 deps.systemModules = sm.outputFile
Colin Crossec7a0422017-07-07 14:47:12 -0700789 default:
790 ctx.ModuleErrorf("depends on non-java module %q", otherName)
Colin Cross2fe66872015-03-30 17:20:39 -0700791 }
Colin Crossec7a0422017-07-07 14:47:12 -0700792 }
Colin Cross2fe66872015-03-30 17:20:39 -0700793 })
794
Jiyong Park1be96912018-05-28 18:02:19 +0900795 j.exportedSdkLibs = android.FirstUniqueStrings(j.exportedSdkLibs)
796
Colin Cross32f676a2017-09-06 13:41:06 -0700797 return deps
Colin Cross2fe66872015-03-30 17:20:39 -0700798}
799
Colin Cross83bb3162018-06-25 15:48:06 -0700800func getJavaVersion(ctx android.ModuleContext, javaVersion string, sdkContext sdkContext) string {
Nan Zhang357466b2018-04-17 17:38:36 -0700801 var ret string
Colin Cross98fd5742019-01-09 23:04:25 -0800802 v := sdkContext.sdkVersion()
803 // For PDK builds, use the latest SDK version instead of "current"
804 if ctx.Config().IsPdkBuild() && (v == "" || v == "current") {
805 sdkVersions := ctx.Config().Get(sdkSingletonKey).([]int)
806 latestSdkVersion := 0
807 if len(sdkVersions) > 0 {
808 latestSdkVersion = sdkVersions[len(sdkVersions)-1]
809 }
810 v = strconv.Itoa(latestSdkVersion)
811 }
812
813 sdk, err := sdkVersionToNumber(ctx, v)
Colin Cross83bb3162018-06-25 15:48:06 -0700814 if err != nil {
815 ctx.PropertyErrorf("sdk_version", "%s", err)
816 }
Nan Zhang357466b2018-04-17 17:38:36 -0700817 if javaVersion != "" {
818 ret = javaVersion
819 } else if ctx.Device() && sdk <= 23 {
820 ret = "1.7"
Jiyong Park4584a8a2018-10-03 18:05:04 +0900821 } else if ctx.Device() && sdk <= 28 || !ctx.Config().TargetOpenJDK9() {
Nan Zhang357466b2018-04-17 17:38:36 -0700822 ret = "1.8"
Colin Cross83bb3162018-06-25 15:48:06 -0700823 } else if ctx.Device() && sdkContext.sdkVersion() != "" && sdk == android.FutureApiLevel {
Nan Zhang357466b2018-04-17 17:38:36 -0700824 // TODO(ccross): once we generate stubs we should be able to use 1.9 for sdk_version: "current"
825 ret = "1.8"
826 } else {
827 ret = "1.9"
828 }
829
830 return ret
831}
832
Nan Zhanged19fc32017-10-19 13:06:22 -0700833func (j *Module) collectBuilderFlags(ctx android.ModuleContext, deps deps) javaBuilderFlags {
Colin Crossc0b06f12015-04-08 13:03:43 -0700834
Colin Crossf03c82b2015-04-13 13:53:40 -0700835 var flags javaBuilderFlags
836
Tobias Thierer06dd04f2018-09-11 16:21:05 +0100837 // javaVersion flag.
838 flags.javaVersion = getJavaVersion(ctx, String(j.properties.Java_version), sdkContext(j))
839
Nan Zhanged19fc32017-10-19 13:06:22 -0700840 // javac flags.
Colin Crossf03c82b2015-04-13 13:53:40 -0700841 javacFlags := j.properties.Javacflags
Tobias Thierer06dd04f2018-09-11 16:21:05 +0100842 if flags.javaVersion == "1.9" {
Colin Cross1369cdb2017-09-29 17:58:17 -0700843 javacFlags = append(javacFlags, j.properties.Openjdk9.Javacflags...)
Nan Zhanged19fc32017-10-19 13:06:22 -0700844 }
Colin Cross6510f912017-11-29 00:27:14 -0800845 if ctx.Config().MinimizeJavaDebugInfo() {
Colin Cross126a25c2017-10-31 13:55:34 -0700846 // Override the -g flag passed globally to remove local variable debug info to reduce
847 // disk and memory usage.
848 javacFlags = append(javacFlags, "-g:source,lines")
849 }
Colin Cross64162712017-08-08 13:17:59 -0700850
Colin Cross66548102018-06-19 22:47:35 -0700851 if ctx.Config().RunErrorProne() {
852 if config.ErrorProneClasspath == nil {
853 ctx.ModuleErrorf("cannot build with Error Prone, missing external/error_prone?")
854 }
855
856 errorProneFlags := []string{
857 "-Xplugin:ErrorProne",
858 "${config.ErrorProneChecks}",
859 }
860 errorProneFlags = append(errorProneFlags, j.properties.Errorprone.Javacflags...)
861
862 flags.errorProneExtraJavacFlags = "${config.ErrorProneFlags} " +
863 "'" + strings.Join(errorProneFlags, " ") + "'"
864 flags.errorProneProcessorPath = classpath(android.PathsForSource(ctx, config.ErrorProneClasspath))
Andreas Gampef3e5b552018-01-22 21:27:21 -0800865 }
866
Nan Zhanged19fc32017-10-19 13:06:22 -0700867 // classpath
Nan Zhang581fd212018-01-10 16:06:12 -0800868 flags.bootClasspath = append(flags.bootClasspath, deps.bootClasspath...)
869 flags.classpath = append(flags.classpath, deps.classpath...)
Colin Cross6a77c982018-06-19 22:43:34 -0700870 flags.processorPath = append(flags.processorPath, deps.processorPath...)
Colin Cross7fdd2b72018-01-02 18:14:25 -0800871
Colin Crossbe9cdb82019-01-21 21:37:16 -0800872 flags.processor = strings.Join(deps.processorClasses, ",")
873
Tobias Thierer06dd04f2018-09-11 16:21:05 +0100874 if len(flags.bootClasspath) == 0 && ctx.Host() && flags.javaVersion != "1.9" &&
Colin Cross7fdd2b72018-01-02 18:14:25 -0800875 !Bool(j.properties.No_standard_libs) &&
876 inList(flags.javaVersion, []string{"1.6", "1.7", "1.8"}) {
877 // Give host-side tools a version of OpenJDK's standard libraries
878 // close to what they're targeting. As of Dec 2017, AOSP is only
879 // bundling OpenJDK 8 and 9, so nothing < 8 is available.
880 //
881 // When building with OpenJDK 8, the following should have no
882 // effect since those jars would be available by default.
883 //
884 // When building with OpenJDK 9 but targeting a version < 1.8,
885 // putting them on the bootclasspath means that:
886 // a) code can't (accidentally) refer to OpenJDK 9 specific APIs
887 // b) references to existing APIs are not reinterpreted in an
888 // OpenJDK 9-specific way, eg. calls to subclasses of
889 // java.nio.Buffer as in http://b/70862583
890 java8Home := ctx.Config().Getenv("ANDROID_JAVA8_HOME")
891 flags.bootClasspath = append(flags.bootClasspath,
892 android.PathForSource(ctx, java8Home, "jre/lib/jce.jar"),
893 android.PathForSource(ctx, java8Home, "jre/lib/rt.jar"))
Nan Zhang5f8cb422018-02-06 10:34:32 -0800894 if Bool(j.properties.Use_tools_jar) {
895 flags.bootClasspath = append(flags.bootClasspath,
896 android.PathForSource(ctx, java8Home, "lib/tools.jar"))
897 }
Colin Cross7fdd2b72018-01-02 18:14:25 -0800898 }
899
Tobias Thierer06dd04f2018-09-11 16:21:05 +0100900 if j.properties.Patch_module != nil && flags.javaVersion == "1.9" {
Jaewoong Jung38e4fb22018-12-12 09:01:34 -0800901 // Manually specify build directory in case it is not under the repo root.
902 // (javac doesn't seem to expand into symbolc links when searching for patch-module targets, so
903 // just adding a symlink under the root doesn't help.)
904 patchPaths := ".:" + ctx.Config().BuildDir()
905 classPath := flags.classpath.FormJavaClassPath("")
906 if classPath != "" {
907 patchPaths += ":" + classPath
908 }
909 javacFlags = append(javacFlags, "--patch-module="+String(j.properties.Patch_module)+"="+patchPaths)
Colin Cross81440082018-08-15 20:21:55 -0700910 }
911
Nan Zhanged19fc32017-10-19 13:06:22 -0700912 // systemModules
Colin Cross1369cdb2017-09-29 17:58:17 -0700913 if deps.systemModules != nil {
914 flags.systemModules = append(flags.systemModules, deps.systemModules)
915 }
916
Nan Zhanged19fc32017-10-19 13:06:22 -0700917 // aidl flags.
Colin Cross32f676a2017-09-06 13:41:06 -0700918 aidlFlags := j.aidlFlags(ctx, deps.aidlPreprocess, deps.aidlIncludeDirs)
Colin Crossf03c82b2015-04-13 13:53:40 -0700919 if len(aidlFlags) > 0 {
Nan Zhanged19fc32017-10-19 13:06:22 -0700920 // optimization.
Colin Crossf03c82b2015-04-13 13:53:40 -0700921 ctx.Variable(pctx, "aidlFlags", strings.Join(aidlFlags, " "))
922 flags.aidlFlags = "$aidlFlags"
Colin Cross2fe66872015-03-30 17:20:39 -0700923 }
924
Colin Cross81440082018-08-15 20:21:55 -0700925 if len(javacFlags) > 0 {
926 // optimization.
927 ctx.Variable(pctx, "javacFlags", strings.Join(javacFlags, " "))
928 flags.javacFlags = "$javacFlags"
929 }
930
Nan Zhanged19fc32017-10-19 13:06:22 -0700931 return flags
932}
Colin Crossc0b06f12015-04-08 13:03:43 -0700933
Colin Cross3bc7ffa2017-11-22 16:19:37 -0800934func (j *Module) compile(ctx android.ModuleContext, extraSrcJars ...android.Path) {
Nan Zhanged19fc32017-10-19 13:06:22 -0700935
Colin Crossebe1a512017-11-14 13:12:14 -0800936 j.exportAidlIncludeDirs = android.PathsForModuleSrc(ctx, j.deviceProperties.Aidl.Export_include_dirs)
Nan Zhanged19fc32017-10-19 13:06:22 -0700937
938 deps := j.collectDeps(ctx)
939 flags := j.collectBuilderFlags(ctx, deps)
940
Tobias Thierer06dd04f2018-09-11 16:21:05 +0100941 if flags.javaVersion == "1.9" {
Nan Zhanged19fc32017-10-19 13:06:22 -0700942 j.properties.Srcs = append(j.properties.Srcs, j.properties.Openjdk9.Srcs...)
943 }
944 srcFiles := ctx.ExpandSources(j.properties.Srcs, j.properties.Exclude_srcs)
Colin Cross6af17aa2017-09-20 12:59:05 -0700945 if hasSrcExt(srcFiles.Strings(), ".proto") {
Colin Cross0f2ee152017-12-14 15:22:43 -0800946 flags = protoFlags(ctx, &j.properties, &j.protoProperties, flags)
Colin Cross6af17aa2017-09-20 12:59:05 -0700947 }
948
Colin Crossaf050172017-11-15 23:01:59 -0800949 srcFiles = j.genSources(ctx, srcFiles, flags)
950
951 srcJars := srcFiles.FilterByExt(".srcjar")
Colin Cross59149b62017-10-16 18:07:29 -0700952 srcJars = append(srcJars, deps.srcJars...)
Colin Cross3bc7ffa2017-11-22 16:19:37 -0800953 srcJars = append(srcJars, extraSrcJars...)
Colin Crossb7a63242015-04-16 14:09:14 -0700954
Brandon Lee5d45c6f2018-08-15 15:35:38 -0700955 // Collect source files from compiledJavaSrcs, compiledSrcJars and filter out Exclude_srcs
956 // that IDEInfo struct will use
957 j.expandIDEInfoCompiledSrcs = append(j.expandIDEInfoCompiledSrcs, srcFiles.Strings()...)
958
Steven Morelandc4efd9c2019-01-18 11:51:25 -0800959 if j.properties.Jarjar_rules != nil {
960 j.expandJarjarRules = ctx.ExpandSource(*j.properties.Jarjar_rules, "jarjar_rules")
961 }
962
Colin Cross1ee23172017-10-18 14:44:18 -0700963 jarName := ctx.ModuleName() + ".jar"
964
Przemyslaw Szczepaniak4b5fe9d2018-02-13 14:32:54 +0000965 javaSrcFiles := srcFiles.FilterByExt(".java")
966 var uniqueSrcFiles android.Paths
967 set := make(map[string]bool)
968 for _, v := range javaSrcFiles {
969 if _, found := set[v.String()]; !found {
970 set[v.String()] = true
971 uniqueSrcFiles = append(uniqueSrcFiles, v)
972 }
973 }
974
Colin Cross55f63ea2018-08-27 12:37:09 -0700975 var kotlinJars android.Paths
976
Colin Cross93e85952017-08-15 13:34:18 -0700977 if srcFiles.HasExt(".kt") {
Zoran Jovanovic8736ce22018-08-21 17:10:29 +0200978 // user defined kotlin flags.
979 kotlincFlags := j.properties.Kotlincflags
980 CheckKotlincFlags(ctx, kotlincFlags)
981
Colin Cross93e85952017-08-15 13:34:18 -0700982 // If there are kotlin files, compile them first but pass all the kotlin and java files
983 // kotlinc will use the java files to resolve types referenced by the kotlin files, but
984 // won't emit any classes for them.
Zoran Jovanovic8736ce22018-08-21 17:10:29 +0200985 kotlincFlags = append(kotlincFlags, "-no-stdlib")
Colin Cross93e85952017-08-15 13:34:18 -0700986 if ctx.Device() {
Zoran Jovanovic8736ce22018-08-21 17:10:29 +0200987 kotlincFlags = append(kotlincFlags, "-no-jdk")
988 }
989 if len(kotlincFlags) > 0 {
990 // optimization.
991 ctx.Variable(pctx, "kotlincFlags", strings.Join(kotlincFlags, " "))
992 flags.kotlincFlags += "$kotlincFlags"
Colin Cross93e85952017-08-15 13:34:18 -0700993 }
994
Przemyslaw Szczepaniak4b5fe9d2018-02-13 14:32:54 +0000995 var kotlinSrcFiles android.Paths
996 kotlinSrcFiles = append(kotlinSrcFiles, uniqueSrcFiles...)
997 kotlinSrcFiles = append(kotlinSrcFiles, srcFiles.FilterByExt(".kt")...)
998
Colin Crossafbb1732019-01-17 15:42:52 -0800999 flags.classpath = append(flags.classpath, deps.kotlinStdlib...)
1000 flags.classpath = append(flags.classpath, deps.kotlinAnnotations...)
1001
1002 flags.kotlincClasspath = append(flags.kotlincClasspath, flags.bootClasspath...)
1003 flags.kotlincClasspath = append(flags.kotlincClasspath, flags.classpath...)
1004
1005 if len(flags.processorPath) > 0 {
1006 // Use kapt for annotation processing
1007 kaptSrcJar := android.PathForModuleOut(ctx, "kapt", "kapt-sources.jar")
1008 kotlinKapt(ctx, kaptSrcJar, kotlinSrcFiles, srcJars, flags)
1009 srcJars = append(srcJars, kaptSrcJar)
1010 // Disable annotation processing in javac, it's already been handled by kapt
1011 flags.processorPath = nil
Colin Cross3a3e94c2019-01-23 15:39:50 -08001012 flags.processor = ""
Colin Crossafbb1732019-01-17 15:42:52 -08001013 }
Colin Cross93e85952017-08-15 13:34:18 -07001014
Colin Cross1ee23172017-10-18 14:44:18 -07001015 kotlinJar := android.PathForModuleOut(ctx, "kotlin", jarName)
Colin Cross21fc9bb2019-01-18 15:05:09 -08001016 kotlinCompile(ctx, kotlinJar, kotlinSrcFiles, srcJars, flags)
Colin Cross93e85952017-08-15 13:34:18 -07001017 if ctx.Failed() {
1018 return
1019 }
1020
1021 // Make javac rule depend on the kotlinc rule
1022 flags.classpath = append(flags.classpath, kotlinJar)
Przemyslaw Szczepaniak66c0c402018-03-08 13:21:55 +00001023
Colin Cross93e85952017-08-15 13:34:18 -07001024 // Jar kotlin classes into the final jar after javac
Colin Cross55f63ea2018-08-27 12:37:09 -07001025 kotlinJars = append(kotlinJars, kotlinJar)
Colin Cross9b38aef2018-08-27 15:42:25 -07001026 kotlinJars = append(kotlinJars, deps.kotlinStdlib...)
Colin Cross93e85952017-08-15 13:34:18 -07001027 }
1028
Colin Cross55f63ea2018-08-27 12:37:09 -07001029 jars := append(android.Paths(nil), kotlinJars...)
1030
Colin Cross5ab4e6d2017-11-22 16:20:45 -08001031 // Store the list of .java files that was passed to javac
1032 j.compiledJavaSrcs = uniqueSrcFiles
1033 j.compiledSrcJars = srcJars
1034
Nan Zhang61eaedb2017-11-02 13:28:15 -07001035 enable_sharding := false
Colin Crossbe9cdb82019-01-21 21:37:16 -08001036 if ctx.Device() && !ctx.Config().IsEnvFalse("TURBINE_ENABLED") && !deps.disableTurbine {
Nan Zhang61eaedb2017-11-02 13:28:15 -07001037 if j.properties.Javac_shard_size != nil && *(j.properties.Javac_shard_size) > 0 {
1038 enable_sharding = true
Ashley Rosee36efcf2019-01-16 17:34:08 -05001039 // Formerly, there was a check here that prevented annotation processors
1040 // from being used when sharding was enabled, as some annotation processors
1041 // do not function correctly in sharded environments. It was removed to
1042 // allow for the use of annotation processors that do function correctly
1043 // with sharding enabled. See: b/77284273.
Nan Zhang61eaedb2017-11-02 13:28:15 -07001044 }
Colin Cross55f63ea2018-08-27 12:37:09 -07001045 j.headerJarFile = j.compileJavaHeader(ctx, uniqueSrcFiles, srcJars, deps, flags, jarName, kotlinJars)
Colin Crossf19b9bb2018-03-26 14:42:44 -07001046 if ctx.Failed() {
1047 return
Nan Zhanged19fc32017-10-19 13:06:22 -07001048 }
1049 }
Colin Cross8eadbf02017-10-24 17:46:00 -07001050 if len(uniqueSrcFiles) > 0 || len(srcJars) > 0 {
Colin Crossd6891432017-09-27 17:39:56 -07001051 var extraJarDeps android.Paths
Colin Cross66548102018-06-19 22:47:35 -07001052 if ctx.Config().RunErrorProne() {
Colin Crossc6bbef32017-08-14 14:16:06 -07001053 // If error-prone is enabled, add an additional rule to compile the java files into
1054 // a separate set of classes (so that they don't overwrite the normal ones and require
Colin Crossd6891432017-09-27 17:39:56 -07001055 // a rebuild when error-prone is turned off).
Colin Crossc6bbef32017-08-14 14:16:06 -07001056 // TODO(ccross): Once we always compile with javac9 we may be able to conditionally
1057 // enable error-prone without affecting the output class files.
Colin Cross1ee23172017-10-18 14:44:18 -07001058 errorprone := android.PathForModuleOut(ctx, "errorprone", jarName)
Nan Zhang61eaedb2017-11-02 13:28:15 -07001059 RunErrorProne(ctx, errorprone, uniqueSrcFiles, srcJars, flags)
Colin Crossc6bbef32017-08-14 14:16:06 -07001060 extraJarDeps = append(extraJarDeps, errorprone)
1061 }
1062
Nan Zhang61eaedb2017-11-02 13:28:15 -07001063 if enable_sharding {
Nan Zhang581fd212018-01-10 16:06:12 -08001064 flags.classpath = append(flags.classpath, j.headerJarFile)
Nan Zhang61eaedb2017-11-02 13:28:15 -07001065 shardSize := int(*(j.properties.Javac_shard_size))
1066 var shardSrcs []android.Paths
1067 if len(uniqueSrcFiles) > 0 {
1068 shardSrcs = shardPaths(uniqueSrcFiles, shardSize)
1069 for idx, shardSrc := range shardSrcs {
1070 classes := android.PathForModuleOut(ctx, "javac", jarName+strconv.Itoa(idx))
1071 TransformJavaToClasses(ctx, classes, idx, shardSrc, nil, flags, extraJarDeps)
1072 jars = append(jars, classes)
1073 }
1074 }
1075 if len(srcJars) > 0 {
1076 classes := android.PathForModuleOut(ctx, "javac", jarName+strconv.Itoa(len(shardSrcs)))
1077 TransformJavaToClasses(ctx, classes, len(shardSrcs), nil, srcJars, flags, extraJarDeps)
1078 jars = append(jars, classes)
1079 }
1080 } else {
1081 classes := android.PathForModuleOut(ctx, "javac", jarName)
1082 TransformJavaToClasses(ctx, classes, -1, uniqueSrcFiles, srcJars, flags, extraJarDeps)
1083 jars = append(jars, classes)
1084 }
Colin Crossd6891432017-09-27 17:39:56 -07001085 if ctx.Failed() {
1086 return
1087 }
Colin Cross2fe66872015-03-30 17:20:39 -07001088 }
1089
Colin Crosscedd4762018-09-13 11:26:19 -07001090 dirArgs, dirDeps := ResourceDirsToJarArgs(ctx, j.properties.Java_resource_dirs,
1091 j.properties.Exclude_java_resource_dirs, j.properties.Exclude_java_resources)
Colin Cross0f37af02017-09-27 17:42:05 -07001092 fileArgs, fileDeps := ResourceFilesToJarArgs(ctx, j.properties.Java_resources, j.properties.Exclude_java_resources)
1093
1094 var resArgs []string
1095 var resDeps android.Paths
1096
1097 resArgs = append(resArgs, dirArgs...)
1098 resDeps = append(resDeps, dirDeps...)
1099
1100 resArgs = append(resArgs, fileArgs...)
1101 resDeps = append(resDeps, fileDeps...)
1102
Colin Crossff3ae9d2018-04-10 16:15:18 -07001103 if Bool(j.properties.Include_srcs) {
Colin Cross23729232017-10-03 13:14:07 -07001104 srcArgs, srcDeps := SourceFilesToJarArgs(ctx, j.properties.Srcs, j.properties.Exclude_srcs)
Colin Cross0f37af02017-09-27 17:42:05 -07001105 resArgs = append(resArgs, srcArgs...)
1106 resDeps = append(resDeps, srcDeps...)
1107 }
Colin Cross40a36712017-09-27 17:41:35 -07001108
1109 if len(resArgs) > 0 {
Colin Cross1ee23172017-10-18 14:44:18 -07001110 resourceJar := android.PathForModuleOut(ctx, "res", jarName)
Colin Crosse9a275b2017-10-16 17:09:48 -07001111 TransformResourcesToJar(ctx, resourceJar, resArgs, resDeps)
Colin Cross331a1212018-08-15 20:40:52 -07001112 j.resourceJar = resourceJar
Colin Cross65bf4f22015-04-03 16:54:17 -07001113 if ctx.Failed() {
1114 return
1115 }
1116 }
1117
Colin Cross331a1212018-08-15 20:40:52 -07001118 if len(deps.staticResourceJars) > 0 {
1119 var jars android.Paths
1120 if j.resourceJar != nil {
1121 jars = append(jars, j.resourceJar)
1122 }
1123 jars = append(jars, deps.staticResourceJars...)
1124
1125 combinedJar := android.PathForModuleOut(ctx, "res-combined", jarName)
1126 TransformJarsToJar(ctx, combinedJar, "for resources", jars, android.OptionalPath{},
1127 false, nil, nil)
1128 j.resourceJar = combinedJar
1129 }
1130
Colin Cross32f676a2017-09-06 13:41:06 -07001131 jars = append(jars, deps.staticJars...)
Colin Cross331a1212018-08-15 20:40:52 -07001132 jars = append(jars, deps.staticResourceJars...)
Colin Cross0a6e0072017-08-30 14:24:55 -07001133
Colin Cross094054a2018-10-17 15:10:48 -07001134 manifest := j.overrideManifest
1135 if !manifest.Valid() && j.properties.Manifest != nil {
Colin Cross366938f2017-12-11 16:29:02 -08001136 manifest = android.OptionalPathForPath(ctx.ExpandSource(*j.properties.Manifest, "manifest"))
1137 }
Colin Cross635acc92017-09-12 22:50:46 -07001138
Colin Cross0a6e0072017-08-30 14:24:55 -07001139 // Combine the classes built from sources, any manifests, and any static libraries into
Nan Zhanged19fc32017-10-19 13:06:22 -07001140 // classes.jar. If there is only one input jar this step will be skipped.
Colin Cross3063b782018-08-15 11:19:12 -07001141 var outputFile android.ModuleOutPath
Colin Crosse9a275b2017-10-16 17:09:48 -07001142
1143 if len(jars) == 1 && !manifest.Valid() {
Colin Cross3063b782018-08-15 11:19:12 -07001144 if moduleOutPath, ok := jars[0].(android.ModuleOutPath); ok {
1145 // Optimization: skip the combine step if there is nothing to do
1146 // TODO(ccross): this leaves any module-info.class files, but those should only come from
1147 // prebuilt dependencies until we support modules in the platform build, so there shouldn't be
1148 // any if len(jars) == 1.
1149 outputFile = moduleOutPath
1150 } else {
1151 combinedJar := android.PathForModuleOut(ctx, "combined", jarName)
1152 ctx.Build(pctx, android.BuildParams{
1153 Rule: android.Cp,
1154 Input: jars[0],
1155 Output: combinedJar,
1156 })
1157 outputFile = combinedJar
1158 }
Colin Crosse9a275b2017-10-16 17:09:48 -07001159 } else {
Colin Cross1ee23172017-10-18 14:44:18 -07001160 combinedJar := android.PathForModuleOut(ctx, "combined", jarName)
Colin Cross37f6d792018-07-12 12:28:41 -07001161 TransformJarsToJar(ctx, combinedJar, "for javac", jars, manifest,
Colin Cross9b38aef2018-08-27 15:42:25 -07001162 false, nil, nil)
Colin Crosse9a275b2017-10-16 17:09:48 -07001163 outputFile = combinedJar
1164 }
Colin Cross0a6e0072017-08-30 14:24:55 -07001165
Colin Cross331a1212018-08-15 20:40:52 -07001166 // jarjar implementation jar if necessary
Steven Morelandc4efd9c2019-01-18 11:51:25 -08001167 if j.expandJarjarRules != nil {
Colin Cross8649b262017-09-27 18:03:17 -07001168 // Transform classes.jar into classes-jarjar.jar
Colin Cross1ee23172017-10-18 14:44:18 -07001169 jarjarFile := android.PathForModuleOut(ctx, "jarjar", jarName)
Steven Morelandc4efd9c2019-01-18 11:51:25 -08001170 TransformJarJar(ctx, jarjarFile, outputFile, j.expandJarjarRules)
Colin Crosse9a275b2017-10-16 17:09:48 -07001171 outputFile = jarjarFile
Colin Cross331a1212018-08-15 20:40:52 -07001172
1173 // jarjar resource jar if necessary
1174 if j.resourceJar != nil {
1175 resourceJarJarFile := android.PathForModuleOut(ctx, "res-jarjar", jarName)
Steven Morelandc4efd9c2019-01-18 11:51:25 -08001176 TransformJarJar(ctx, resourceJarJarFile, j.resourceJar, j.expandJarjarRules)
Colin Cross331a1212018-08-15 20:40:52 -07001177 j.resourceJar = resourceJarJarFile
1178 }
1179
Colin Cross0a6e0072017-08-30 14:24:55 -07001180 if ctx.Failed() {
1181 return
1182 }
1183 }
Nan Zhanged19fc32017-10-19 13:06:22 -07001184 j.implementationJarFile = outputFile
1185 if j.headerJarFile == nil {
1186 j.headerJarFile = j.implementationJarFile
1187 }
Colin Cross2fe66872015-03-30 17:20:39 -07001188
Colin Cross6510f912017-11-29 00:27:14 -08001189 if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
Colin Crosscb933592017-11-22 13:49:43 -08001190 if inList(ctx.ModuleName(), config.InstrumentFrameworkModules) {
1191 j.properties.Instrument = true
1192 }
1193 }
1194
Colin Cross3144dfc2018-01-03 15:06:47 -08001195 if j.shouldInstrument(ctx) {
Colin Crosscb933592017-11-22 13:49:43 -08001196 outputFile = j.instrument(ctx, flags, outputFile, jarName)
1197 }
1198
Colin Cross331a1212018-08-15 20:40:52 -07001199 // merge implementation jar with resources if necessary
1200 implementationAndResourcesJar := outputFile
1201 if j.resourceJar != nil {
1202 jars := android.Paths{implementationAndResourcesJar, j.resourceJar}
1203 combinedJar := android.PathForModuleOut(ctx, "withres", jarName)
1204 TransformJarsToJar(ctx, combinedJar, "for resources", jars, android.OptionalPath{},
1205 false, nil, nil)
1206 implementationAndResourcesJar = combinedJar
1207 }
1208
1209 j.implementationAndResourcesJar = implementationAndResourcesJar
1210
Colin Cross9ae1b922018-06-26 17:59:05 -07001211 if ctx.Device() && (Bool(j.properties.Installable) || Bool(j.deviceProperties.Compile_dex)) {
Colin Cross8faf8fc2019-01-16 15:15:52 -08001212 // Dex compilation
Colin Cross3063b782018-08-15 11:19:12 -07001213 var dexOutputFile android.ModuleOutPath
David Brazdil17ef5632018-06-27 10:27:45 +01001214 dexOutputFile = j.compileDex(ctx, flags, outputFile, jarName)
Colin Cross2fe66872015-03-30 17:20:39 -07001215 if ctx.Failed() {
1216 return
1217 }
Colin Cross331a1212018-08-15 20:40:52 -07001218
Colin Cross8faf8fc2019-01-16 15:15:52 -08001219 // Hidden API CSV generation and dex encoding
Colin Crossf24a22a2019-01-31 14:12:44 -08001220 dexOutputFile = j.hiddenAPI.hiddenAPI(ctx, dexOutputFile, j.implementationJarFile,
1221 j.deviceProperties.UncompressDex)
Colin Cross8faf8fc2019-01-16 15:15:52 -08001222
Colin Cross331a1212018-08-15 20:40:52 -07001223 // merge dex jar with resources if necessary
1224 if j.resourceJar != nil {
1225 jars := android.Paths{dexOutputFile, j.resourceJar}
1226 combinedJar := android.PathForModuleOut(ctx, "dex-withres", jarName)
1227 TransformJarsToJar(ctx, combinedJar, "for dex resources", jars, android.OptionalPath{},
1228 false, nil, nil)
Nicolas Geoffrayf3438722019-01-23 15:57:21 +00001229 if j.deviceProperties.UncompressDex {
1230 combinedAlignedJar := android.PathForModuleOut(ctx, "dex-withres-aligned", jarName)
1231 TransformZipAlign(ctx, combinedAlignedJar, combinedJar)
1232 dexOutputFile = combinedAlignedJar
1233 } else {
1234 dexOutputFile = combinedJar
1235 }
Colin Cross331a1212018-08-15 20:40:52 -07001236 }
1237
1238 j.dexJarFile = dexOutputFile
1239
Colin Cross8faf8fc2019-01-16 15:15:52 -08001240 // Dexpreopting
Colin Cross43f08db2018-11-12 10:13:39 -08001241 dexOutputFile = j.dexpreopt(ctx, dexOutputFile)
1242
1243 j.maybeStrippedDexJarFile = dexOutputFile
1244
Colin Cross3063b782018-08-15 11:19:12 -07001245 outputFile = dexOutputFile
Colin Cross43f08db2018-11-12 10:13:39 -08001246
1247 if ctx.Failed() {
1248 return
1249 }
Colin Cross331a1212018-08-15 20:40:52 -07001250 } else {
1251 outputFile = implementationAndResourcesJar
Colin Cross2fe66872015-03-30 17:20:39 -07001252 }
Colin Cross331a1212018-08-15 20:40:52 -07001253
Colin Crossb7a63242015-04-16 14:09:14 -07001254 ctx.CheckbuildFile(outputFile)
Colin Cross3063b782018-08-15 11:19:12 -07001255
1256 // Save the output file with no relative path so that it doesn't end up in a subdirectory when used as a resource
1257 j.outputFile = outputFile.WithoutRel()
Colin Cross2fe66872015-03-30 17:20:39 -07001258}
1259
Zoran Jovanovic8736ce22018-08-21 17:10:29 +02001260// Check for invalid kotlinc flags. Only use this for flags explicitly passed by the user,
1261// since some of these flags may be used internally.
1262func CheckKotlincFlags(ctx android.ModuleContext, flags []string) {
1263 for _, flag := range flags {
1264 flag = strings.TrimSpace(flag)
1265
1266 if !strings.HasPrefix(flag, "-") {
1267 ctx.PropertyErrorf("kotlincflags", "Flag `%s` must start with `-`", flag)
1268 } else if strings.HasPrefix(flag, "-Xintellij-plugin-root") {
1269 ctx.PropertyErrorf("kotlincflags",
1270 "Bad flag: `%s`, only use internal compiler for consistency.", flag)
1271 } else if inList(flag, config.KotlincIllegalFlags) {
1272 ctx.PropertyErrorf("kotlincflags", "Flag `%s` already used by build system", flag)
1273 } else if flag == "-include-runtime" {
1274 ctx.PropertyErrorf("kotlincflags", "Bad flag: `%s`, do not include runtime.", flag)
1275 } else {
1276 args := strings.Split(flag, " ")
1277 if args[0] == "-kotlin-home" {
1278 ctx.PropertyErrorf("kotlincflags",
1279 "Bad flag: `%s`, kotlin home already set to default (path to kotlinc in the repo).", flag)
1280 }
1281 }
1282 }
1283}
1284
Colin Cross8eadbf02017-10-24 17:46:00 -07001285func (j *Module) compileJavaHeader(ctx android.ModuleContext, srcFiles, srcJars android.Paths,
Colin Cross55f63ea2018-08-27 12:37:09 -07001286 deps deps, flags javaBuilderFlags, jarName string, extraJars android.Paths) android.Path {
Nan Zhanged19fc32017-10-19 13:06:22 -07001287
1288 var jars android.Paths
Colin Cross8eadbf02017-10-24 17:46:00 -07001289 if len(srcFiles) > 0 || len(srcJars) > 0 {
Nan Zhanged19fc32017-10-19 13:06:22 -07001290 // Compile java sources into turbine.jar.
1291 turbineJar := android.PathForModuleOut(ctx, "turbine", jarName)
1292 TransformJavaToHeaderClasses(ctx, turbineJar, srcFiles, srcJars, flags)
1293 if ctx.Failed() {
1294 return nil
1295 }
1296 jars = append(jars, turbineJar)
1297 }
1298
Colin Cross55f63ea2018-08-27 12:37:09 -07001299 jars = append(jars, extraJars...)
1300
Nan Zhanged19fc32017-10-19 13:06:22 -07001301 // Combine any static header libraries into classes-header.jar. If there is only
1302 // one input jar this step will be skipped.
1303 var headerJar android.Path
1304 jars = append(jars, deps.staticHeaderJars...)
1305
Colin Cross5c6ecc12017-10-23 18:12:27 -07001306 // we cannot skip the combine step for now if there is only one jar
1307 // since we have to strip META-INF/TRANSITIVE dir from turbine.jar
1308 combinedJar := android.PathForModuleOut(ctx, "turbine-combined", jarName)
Colin Cross37f6d792018-07-12 12:28:41 -07001309 TransformJarsToJar(ctx, combinedJar, "for turbine", jars, android.OptionalPath{},
1310 false, nil, []string{"META-INF"})
Colin Cross5c6ecc12017-10-23 18:12:27 -07001311 headerJar = combinedJar
Nan Zhanged19fc32017-10-19 13:06:22 -07001312
Steven Morelandc4efd9c2019-01-18 11:51:25 -08001313 if j.expandJarjarRules != nil {
Nan Zhanged19fc32017-10-19 13:06:22 -07001314 // Transform classes.jar into classes-jarjar.jar
1315 jarjarFile := android.PathForModuleOut(ctx, "turbine-jarjar", jarName)
Steven Morelandc4efd9c2019-01-18 11:51:25 -08001316 TransformJarJar(ctx, jarjarFile, headerJar, j.expandJarjarRules)
Nan Zhanged19fc32017-10-19 13:06:22 -07001317 headerJar = jarjarFile
1318 if ctx.Failed() {
1319 return nil
1320 }
1321 }
1322
1323 return headerJar
1324}
1325
Colin Crosscb933592017-11-22 13:49:43 -08001326func (j *Module) instrument(ctx android.ModuleContext, flags javaBuilderFlags,
Colin Cross3063b782018-08-15 11:19:12 -07001327 classesJar android.Path, jarName string) android.ModuleOutPath {
Colin Crosscb933592017-11-22 13:49:43 -08001328
Colin Cross7a3139e2017-12-19 13:57:50 -08001329 specs := j.jacocoModuleToZipCommand(ctx)
Colin Crosscb933592017-11-22 13:49:43 -08001330
Colin Cross84c38822018-01-03 15:59:46 -08001331 jacocoReportClassesFile := android.PathForModuleOut(ctx, "jacoco-report-classes", jarName)
Colin Crosscb933592017-11-22 13:49:43 -08001332 instrumentedJar := android.PathForModuleOut(ctx, "jacoco", jarName)
1333
1334 jacocoInstrumentJar(ctx, instrumentedJar, jacocoReportClassesFile, classesJar, specs)
1335
1336 j.jacocoReportClassesFile = jacocoReportClassesFile
1337
1338 return instrumentedJar
1339}
1340
albaltai36ff7dc2018-12-25 14:35:23 +08001341var _ Dependency = (*Module)(nil)
Colin Cross2fe66872015-03-30 17:20:39 -07001342
Nan Zhanged19fc32017-10-19 13:06:22 -07001343func (j *Module) HeaderJars() android.Paths {
albaltai36ff7dc2018-12-25 14:35:23 +08001344 if j.headerJarFile == nil {
1345 return nil
1346 }
Nan Zhanged19fc32017-10-19 13:06:22 -07001347 return android.Paths{j.headerJarFile}
1348}
1349
1350func (j *Module) ImplementationJars() android.Paths {
shinwang9e4c07a2018-12-24 15:41:04 +08001351 if j.implementationJarFile == nil {
1352 return nil
1353 }
Nan Zhanged19fc32017-10-19 13:06:22 -07001354 return android.Paths{j.implementationJarFile}
Colin Cross2fe66872015-03-30 17:20:39 -07001355}
1356
Colin Crossf24a22a2019-01-31 14:12:44 -08001357func (j *Module) DexJar() android.Path {
1358 return j.dexJarFile
1359}
1360
Colin Cross331a1212018-08-15 20:40:52 -07001361func (j *Module) ResourceJars() android.Paths {
1362 if j.resourceJar == nil {
1363 return nil
1364 }
1365 return android.Paths{j.resourceJar}
1366}
1367
1368func (j *Module) ImplementationAndResourcesJars() android.Paths {
albaltai36ff7dc2018-12-25 14:35:23 +08001369 if j.implementationAndResourcesJar == nil {
1370 return nil
1371 }
Colin Cross331a1212018-08-15 20:40:52 -07001372 return android.Paths{j.implementationAndResourcesJar}
1373}
1374
Colin Cross46c9b8b2017-06-22 16:51:17 -07001375func (j *Module) AidlIncludeDirs() android.Paths {
albaltai36ff7dc2018-12-25 14:35:23 +08001376 // exportAidlIncludeDirs is type android.Paths already
Colin Crossc0b06f12015-04-08 13:03:43 -07001377 return j.exportAidlIncludeDirs
1378}
1379
Jiyong Park1be96912018-05-28 18:02:19 +09001380func (j *Module) ExportedSdkLibs() []string {
albaltai36ff7dc2018-12-25 14:35:23 +08001381 // exportedSdkLibs is type []string
Jiyong Park1be96912018-05-28 18:02:19 +09001382 return j.exportedSdkLibs
1383}
1384
Colin Cross46c9b8b2017-06-22 16:51:17 -07001385var _ logtagsProducer = (*Module)(nil)
Colin Crossf05fe972015-04-10 17:45:20 -07001386
Colin Cross46c9b8b2017-06-22 16:51:17 -07001387func (j *Module) logtags() android.Paths {
Colin Crossf05fe972015-04-10 17:45:20 -07001388 return j.logtagsSrcs
1389}
1390
Brandon Lee5d45c6f2018-08-15 15:35:38 -07001391// Collect information for opening IDE project files in java/jdeps.go.
1392func (j *Module) IDEInfo(dpInfo *android.IdeInfo) {
1393 dpInfo.Deps = append(dpInfo.Deps, j.CompilerDeps()...)
1394 dpInfo.Srcs = append(dpInfo.Srcs, j.expandIDEInfoCompiledSrcs...)
1395 dpInfo.Aidl_include_dirs = append(dpInfo.Aidl_include_dirs, j.deviceProperties.Aidl.Include_dirs...)
Steven Morelandc4efd9c2019-01-18 11:51:25 -08001396 if j.expandJarjarRules != nil {
1397 dpInfo.Jarjar_rules = append(dpInfo.Jarjar_rules, j.expandJarjarRules.String())
Brandon Lee5d45c6f2018-08-15 15:35:38 -07001398 }
1399}
1400
1401func (j *Module) CompilerDeps() []string {
1402 jdeps := []string{}
1403 jdeps = append(jdeps, j.properties.Libs...)
1404 jdeps = append(jdeps, j.properties.Static_libs...)
1405 return jdeps
1406}
1407
Colin Cross2fe66872015-03-30 17:20:39 -07001408//
1409// Java libraries (.jar file)
1410//
1411
Colin Crossf506d872017-07-19 15:53:04 -07001412type Library struct {
Colin Cross46c9b8b2017-06-22 16:51:17 -07001413 Module
Colin Cross2fe66872015-03-30 17:20:39 -07001414}
1415
Colin Cross2fc72f62018-12-21 12:59:54 -08001416func (j *Library) shouldUncompressDex(ctx android.ModuleContext) bool {
Nicolas Geoffrayfa6e9ec2019-02-12 13:12:16 +00001417 // Store uncompressed (and do not strip) dex files from boot class path jars.
1418 if inList(ctx.ModuleName(), ctx.Config().BootJars()) {
1419 return true
1420 }
1421
1422 // Store uncompressed dex files that are preopted on /system.
1423 if !j.dexpreopter.dexpreoptDisabled(ctx) && (ctx.Host() || !odexOnSystemOther(ctx, j.dexpreopter.installPath)) {
Vladimir Markoe8b00d62018-12-21 15:54:16 +00001424 return true
1425 }
Colin Cross083a2aa2019-02-06 16:37:12 -08001426 if ctx.Config().UncompressPrivAppDex() &&
1427 inList(ctx.ModuleName(), ctx.Config().ModulesLoadedByPrivilegedModules()) {
1428 return true
1429 }
1430
Colin Cross2fc72f62018-12-21 12:59:54 -08001431 return false
1432}
1433
Colin Crossf506d872017-07-19 15:53:04 -07001434func (j *Library) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross43f08db2018-11-12 10:13:39 -08001435 j.dexpreopter.installPath = android.PathForModuleInstall(ctx, "framework", ctx.ModuleName()+".jar")
1436 j.dexpreopter.isSDKLibrary = j.deviceProperties.IsSDKLibrary
Nicolas Geoffrayfa6e9ec2019-02-12 13:12:16 +00001437 j.dexpreopter.isInstallable = Bool(j.properties.Installable)
1438 j.dexpreopter.uncompressedDex = j.shouldUncompressDex(ctx)
1439 j.deviceProperties.UncompressDex = j.dexpreopter.uncompressedDex
Colin Cross46c9b8b2017-06-22 16:51:17 -07001440 j.compile(ctx)
Colin Crossb7a63242015-04-16 14:09:14 -07001441
Nicolas Geoffray4bdea392019-01-15 11:48:08 +00001442 if (Bool(j.properties.Installable) || ctx.Host()) && !android.DirectlyInAnyApex(ctx, ctx.ModuleName()) {
Colin Cross2c429dc2017-08-31 16:45:16 -07001443 j.installFile = ctx.InstallFile(android.PathForModuleInstall(ctx, "framework"),
1444 ctx.ModuleName()+".jar", j.outputFile)
1445 }
Colin Crossb7a63242015-04-16 14:09:14 -07001446}
1447
Colin Crossf506d872017-07-19 15:53:04 -07001448func (j *Library) DepsMutator(ctx android.BottomUpMutatorContext) {
Colin Cross46c9b8b2017-06-22 16:51:17 -07001449 j.deps(ctx)
1450}
1451
Colin Cross1b16b0e2019-02-12 14:41:32 -08001452// java_library builds and links sources into a `.jar` file for the device, and possibly for the host as well.
1453//
1454// By default, a java_library has a single variant that produces a `.jar` file containing `.class` files that were
1455// compiled against the device bootclasspath. This jar is not suitable for installing on a device, but can be used
1456// as a `static_libs` dependency of another module.
1457//
1458// Specifying `installable: true` will product a `.jar` file containing `classes.dex` files, suitable for installing on
1459// a device.
1460//
1461// Specifying `host_supported: true` will produce two variants, one compiled against the device bootclasspath and one
1462// compiled against the host bootclasspath.
Colin Cross9ae1b922018-06-26 17:59:05 -07001463func LibraryFactory() android.Module {
1464 module := &Library{}
Colin Cross2fe66872015-03-30 17:20:39 -07001465
Colin Cross9ae1b922018-06-26 17:59:05 -07001466 module.AddProperties(
1467 &module.Module.properties,
1468 &module.Module.deviceProperties,
Colin Cross43f08db2018-11-12 10:13:39 -08001469 &module.Module.dexpreoptProperties,
Colin Cross9ae1b922018-06-26 17:59:05 -07001470 &module.Module.protoProperties)
Colin Cross2fe66872015-03-30 17:20:39 -07001471
Colin Cross9ae1b922018-06-26 17:59:05 -07001472 InitJavaModule(module, android.HostAndDeviceSupported)
1473 return module
Colin Cross2fe66872015-03-30 17:20:39 -07001474}
1475
Colin Cross1b16b0e2019-02-12 14:41:32 -08001476// java_library_static is an obsolete alias for java_library.
1477func LibraryStaticFactory() android.Module {
1478 return LibraryFactory()
1479}
1480
1481// java_library_host builds and links sources into a `.jar` file for the host.
1482//
1483// A java_library_host has a single variant that produces a `.jar` file containing `.class` files that were
1484// compiled against the host bootclasspath.
Colin Crossf506d872017-07-19 15:53:04 -07001485func LibraryHostFactory() android.Module {
1486 module := &Library{}
Colin Cross2fe66872015-03-30 17:20:39 -07001487
Colin Cross6af17aa2017-09-20 12:59:05 -07001488 module.AddProperties(
1489 &module.Module.properties,
1490 &module.Module.protoProperties)
Colin Cross36242852017-06-23 15:06:31 -07001491
Colin Cross9ae1b922018-06-26 17:59:05 -07001492 module.Module.properties.Installable = proptools.BoolPtr(true)
1493
Colin Cross89536d42017-07-07 14:35:50 -07001494 InitJavaModule(module, android.HostSupported)
Colin Cross36242852017-06-23 15:06:31 -07001495 return module
Colin Cross2fe66872015-03-30 17:20:39 -07001496}
1497
1498//
Colin Crossb628ea52018-08-14 16:42:33 -07001499// Java Tests
Colin Cross05638fc2018-04-09 18:40:24 -07001500//
1501
1502type testProperties struct {
Colin Cross05638fc2018-04-09 18:40:24 -07001503 // list of compatibility suites (for example "cts", "vts") that the module should be
1504 // installed into.
1505 Test_suites []string `android:"arch_variant"`
Julien Despreze146e392018-08-02 15:00:46 -07001506
1507 // the name of the test configuration (for example "AndroidTest.xml") that should be
1508 // installed with the module.
1509 Test_config *string `android:"arch_variant"`
Colin Crossd96ca352018-08-10 16:06:24 -07001510
Jack He33338892018-09-19 02:21:28 -07001511 // the name of the test configuration template (for example "AndroidTestTemplate.xml") that
1512 // should be installed with the module.
1513 Test_config_template *string `android:"arch_variant"`
1514
Colin Crossd96ca352018-08-10 16:06:24 -07001515 // list of files or filegroup modules that provide data that should be installed alongside
1516 // the test
1517 Data []string
Colin Cross05638fc2018-04-09 18:40:24 -07001518}
1519
1520type Test struct {
1521 Library
1522
1523 testProperties testProperties
Colin Cross303e21f2018-08-07 16:49:25 -07001524
1525 testConfig android.Path
Colin Crossd96ca352018-08-10 16:06:24 -07001526 data android.Paths
Colin Cross303e21f2018-08-07 16:49:25 -07001527}
1528
1529func (j *Test) GenerateAndroidBuildActions(ctx android.ModuleContext) {
yangbill4f41bc22019-02-13 21:45:47 +08001530 j.testConfig = tradefed.AutoGenJavaTestConfig(ctx, j.testProperties.Test_config, j.testProperties.Test_config_template, j.testProperties.Test_suites)
Colin Crossd96ca352018-08-10 16:06:24 -07001531 j.data = ctx.ExpandSources(j.testProperties.Data, nil)
Colin Cross303e21f2018-08-07 16:49:25 -07001532
1533 j.Library.GenerateAndroidBuildActions(ctx)
Colin Cross05638fc2018-04-09 18:40:24 -07001534}
1535
1536func (j *Test) DepsMutator(ctx android.BottomUpMutatorContext) {
1537 j.deps(ctx)
Colin Cross303e21f2018-08-07 16:49:25 -07001538 android.ExtractSourceDeps(ctx, j.testProperties.Test_config)
Jack He33338892018-09-19 02:21:28 -07001539 android.ExtractSourceDeps(ctx, j.testProperties.Test_config_template)
Colin Crossd96ca352018-08-10 16:06:24 -07001540 android.ExtractSourcesDeps(ctx, j.testProperties.Data)
Colin Cross05638fc2018-04-09 18:40:24 -07001541}
1542
Colin Cross1b16b0e2019-02-12 14:41:32 -08001543// java_test builds a and links sources into a `.jar` file for the device, and possibly for the host as well, and
1544// creates an `AndroidTest.xml` file to allow running the test with `atest` or a `TEST_MAPPING` file.
1545//
1546// By default, a java_test has a single variant that produces a `.jar` file containing `classes.dex` files that were
1547// compiled against the device bootclasspath.
1548//
1549// Specifying `host_supported: true` will produce two variants, one compiled against the device bootclasspath and one
1550// compiled against the host bootclasspath.
Colin Cross05638fc2018-04-09 18:40:24 -07001551func TestFactory() android.Module {
1552 module := &Test{}
1553
1554 module.AddProperties(
1555 &module.Module.properties,
1556 &module.Module.deviceProperties,
Colin Cross43f08db2018-11-12 10:13:39 -08001557 &module.Module.dexpreoptProperties,
Colin Cross05638fc2018-04-09 18:40:24 -07001558 &module.Module.protoProperties,
1559 &module.testProperties)
1560
Colin Cross9ae1b922018-06-26 17:59:05 -07001561 module.Module.properties.Installable = proptools.BoolPtr(true)
Colin Crosse3026872019-01-05 22:30:13 -08001562 module.Module.dexpreopter.isTest = true
Colin Cross9ae1b922018-06-26 17:59:05 -07001563
Colin Cross05638fc2018-04-09 18:40:24 -07001564 InitJavaModule(module, android.HostAndDeviceSupported)
Colin Cross05638fc2018-04-09 18:40:24 -07001565 return module
1566}
1567
Colin Cross1b16b0e2019-02-12 14:41:32 -08001568// java_test_host builds a and links sources into a `.jar` file for the host, and creates an `AndroidTest.xml` file to
1569// allow running the test with `atest` or a `TEST_MAPPING` file.
1570//
1571// A java_test_host has a single variant that produces a `.jar` file containing `.class` files that were
1572// compiled against the host bootclasspath.
Colin Cross05638fc2018-04-09 18:40:24 -07001573func TestHostFactory() android.Module {
1574 module := &Test{}
1575
1576 module.AddProperties(
1577 &module.Module.properties,
1578 &module.Module.protoProperties,
1579 &module.testProperties)
1580
Colin Cross9ae1b922018-06-26 17:59:05 -07001581 module.Module.properties.Installable = proptools.BoolPtr(true)
1582
Colin Cross05638fc2018-04-09 18:40:24 -07001583 InitJavaModule(module, android.HostSupported)
Colin Cross05638fc2018-04-09 18:40:24 -07001584 return module
1585}
1586
1587//
Colin Cross2fe66872015-03-30 17:20:39 -07001588// Java Binaries (.jar file plus wrapper script)
1589//
1590
Colin Crossf506d872017-07-19 15:53:04 -07001591type binaryProperties struct {
Colin Cross7d5136f2015-05-11 13:39:40 -07001592 // installable script to execute the resulting jar
Nan Zhangea568a42017-11-08 21:20:04 -08001593 Wrapper *string
Colin Cross094054a2018-10-17 15:10:48 -07001594
1595 // Name of the class containing main to be inserted into the manifest as Main-Class.
1596 Main_class *string
Colin Cross7d5136f2015-05-11 13:39:40 -07001597}
1598
Colin Crossf506d872017-07-19 15:53:04 -07001599type Binary struct {
1600 Library
Colin Cross2fe66872015-03-30 17:20:39 -07001601
Colin Crossf506d872017-07-19 15:53:04 -07001602 binaryProperties binaryProperties
Colin Cross10a03492017-08-10 17:09:43 -07001603
Colin Cross6b4a32d2017-12-05 13:42:45 -08001604 isWrapperVariant bool
1605
Colin Crossc3315992017-12-08 19:12:36 -08001606 wrapperFile android.Path
Colin Cross10a03492017-08-10 17:09:43 -07001607 binaryFile android.OutputPath
Colin Cross2fe66872015-03-30 17:20:39 -07001608}
1609
Alex Light24237172017-10-26 09:46:21 -07001610func (j *Binary) HostToolPath() android.OptionalPath {
1611 return android.OptionalPathForPath(j.binaryFile)
1612}
1613
Colin Crossf506d872017-07-19 15:53:04 -07001614func (j *Binary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross6b4a32d2017-12-05 13:42:45 -08001615 if ctx.Arch().ArchType == android.Common {
1616 // Compile the jar
Colin Cross094054a2018-10-17 15:10:48 -07001617 if j.binaryProperties.Main_class != nil {
1618 if j.properties.Manifest != nil {
1619 ctx.PropertyErrorf("main_class", "main_class cannot be used when manifest is set")
1620 }
1621 manifestFile := android.PathForModuleOut(ctx, "manifest.txt")
1622 GenerateMainClassManifest(ctx, manifestFile, String(j.binaryProperties.Main_class))
1623 j.overrideManifest = android.OptionalPathForPath(manifestFile)
1624 }
1625
Colin Cross6b4a32d2017-12-05 13:42:45 -08001626 j.Library.GenerateAndroidBuildActions(ctx)
Nan Zhang3c807db2017-11-03 14:53:31 -07001627 } else {
Colin Cross6b4a32d2017-12-05 13:42:45 -08001628 // Handle the binary wrapper
1629 j.isWrapperVariant = true
1630
Colin Cross366938f2017-12-11 16:29:02 -08001631 if j.binaryProperties.Wrapper != nil {
1632 j.wrapperFile = ctx.ExpandSource(*j.binaryProperties.Wrapper, "wrapper")
Colin Cross6b4a32d2017-12-05 13:42:45 -08001633 } else {
1634 j.wrapperFile = android.PathForSource(ctx, "build/soong/scripts/jar-wrapper.sh")
1635 }
1636
1637 // Depend on the installed jar so that the wrapper doesn't get executed by
1638 // another build rule before the jar has been installed.
1639 jarFile := ctx.PrimaryModule().(*Binary).installFile
1640
1641 j.binaryFile = ctx.InstallExecutable(android.PathForModuleInstall(ctx, "bin"),
1642 ctx.ModuleName(), j.wrapperFile, jarFile)
Nan Zhang3c807db2017-11-03 14:53:31 -07001643 }
Colin Cross2fe66872015-03-30 17:20:39 -07001644}
1645
Colin Crossf506d872017-07-19 15:53:04 -07001646func (j *Binary) DepsMutator(ctx android.BottomUpMutatorContext) {
Colin Cross6b4a32d2017-12-05 13:42:45 -08001647 if ctx.Arch().ArchType == android.Common {
1648 j.deps(ctx)
Colin Crossc3315992017-12-08 19:12:36 -08001649 } else {
Colin Cross366938f2017-12-11 16:29:02 -08001650 android.ExtractSourceDeps(ctx, j.binaryProperties.Wrapper)
Colin Cross6b4a32d2017-12-05 13:42:45 -08001651 }
Colin Cross46c9b8b2017-06-22 16:51:17 -07001652}
1653
Colin Cross1b16b0e2019-02-12 14:41:32 -08001654// java_binary builds a `.jar` file and a shell script that executes it for the device, and possibly for the host
1655// as well.
1656//
1657// By default, a java_binary has a single variant that produces a `.jar` file containing `classes.dex` files that were
1658// compiled against the device bootclasspath.
1659//
1660// Specifying `host_supported: true` will produce two variants, one compiled against the device bootclasspath and one
1661// compiled against the host bootclasspath.
Colin Crossf506d872017-07-19 15:53:04 -07001662func BinaryFactory() android.Module {
1663 module := &Binary{}
Colin Cross2fe66872015-03-30 17:20:39 -07001664
Colin Cross36242852017-06-23 15:06:31 -07001665 module.AddProperties(
Colin Cross540eff82017-06-22 17:01:52 -07001666 &module.Module.properties,
1667 &module.Module.deviceProperties,
Colin Cross43f08db2018-11-12 10:13:39 -08001668 &module.Module.dexpreoptProperties,
Colin Cross6af17aa2017-09-20 12:59:05 -07001669 &module.Module.protoProperties,
Colin Cross540eff82017-06-22 17:01:52 -07001670 &module.binaryProperties)
Colin Cross36242852017-06-23 15:06:31 -07001671
Colin Cross9ae1b922018-06-26 17:59:05 -07001672 module.Module.properties.Installable = proptools.BoolPtr(true)
1673
Colin Cross6b4a32d2017-12-05 13:42:45 -08001674 android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibCommonFirst)
1675 android.InitDefaultableModule(module)
Colin Cross36242852017-06-23 15:06:31 -07001676 return module
Colin Cross2fe66872015-03-30 17:20:39 -07001677}
1678
Colin Cross1b16b0e2019-02-12 14:41:32 -08001679// java_binary_host builds a `.jar` file and a shell script that executes it for the host.
1680//
1681// A java_binary_host has a single variant that produces a `.jar` file containing `.class` files that were
1682// compiled against the host bootclasspath.
Colin Crossf506d872017-07-19 15:53:04 -07001683func BinaryHostFactory() android.Module {
1684 module := &Binary{}
Colin Cross2fe66872015-03-30 17:20:39 -07001685
Colin Cross36242852017-06-23 15:06:31 -07001686 module.AddProperties(
Colin Cross540eff82017-06-22 17:01:52 -07001687 &module.Module.properties,
Colin Cross6af17aa2017-09-20 12:59:05 -07001688 &module.Module.protoProperties,
Colin Cross540eff82017-06-22 17:01:52 -07001689 &module.binaryProperties)
Colin Cross36242852017-06-23 15:06:31 -07001690
Colin Cross9ae1b922018-06-26 17:59:05 -07001691 module.Module.properties.Installable = proptools.BoolPtr(true)
1692
Colin Cross6b4a32d2017-12-05 13:42:45 -08001693 android.InitAndroidArchModule(module, android.HostSupported, android.MultilibCommonFirst)
1694 android.InitDefaultableModule(module)
Colin Cross36242852017-06-23 15:06:31 -07001695 return module
Colin Cross2fe66872015-03-30 17:20:39 -07001696}
1697
1698//
1699// Java prebuilts
1700//
1701
Colin Cross74d73e22017-08-02 11:05:49 -07001702type ImportProperties struct {
1703 Jars []string
Colin Cross461bd1a2017-10-20 13:59:18 -07001704
Nan Zhangea568a42017-11-08 21:20:04 -08001705 Sdk_version *string
Colin Cross535e2cf2017-10-20 17:57:49 -07001706
1707 Installable *bool
Jiyong Park1be96912018-05-28 18:02:19 +09001708
1709 // List of shared java libs that this module has dependencies to
1710 Libs []string
Colin Cross37f6d792018-07-12 12:28:41 -07001711
1712 // List of files to remove from the jar file(s)
1713 Exclude_files []string
1714
1715 // List of directories to remove from the jar file(s)
1716 Exclude_dirs []string
Nan Zhang4c819fb2018-08-27 18:31:46 -07001717
1718 // if set to true, run Jetifier against .jar file. Defaults to false.
1719 Jetifier_enabled *bool
Colin Cross74d73e22017-08-02 11:05:49 -07001720}
1721
1722type Import struct {
Colin Cross635c3b02016-05-18 15:37:25 -07001723 android.ModuleBase
Colin Cross48de9a42018-10-02 13:53:33 -07001724 android.DefaultableModuleBase
Colin Crossec7a0422017-07-07 14:47:12 -07001725 prebuilt android.Prebuilt
Colin Cross2fe66872015-03-30 17:20:39 -07001726
Colin Cross74d73e22017-08-02 11:05:49 -07001727 properties ImportProperties
1728
Colin Cross0a6e0072017-08-30 14:24:55 -07001729 combinedClasspathFile android.Path
Jiyong Park1be96912018-05-28 18:02:19 +09001730 exportedSdkLibs []string
Colin Cross2fe66872015-03-30 17:20:39 -07001731}
1732
Colin Cross83bb3162018-06-25 15:48:06 -07001733func (j *Import) sdkVersion() string {
1734 return String(j.properties.Sdk_version)
1735}
1736
1737func (j *Import) minSdkVersion() string {
1738 return j.sdkVersion()
1739}
1740
Colin Cross74d73e22017-08-02 11:05:49 -07001741func (j *Import) Prebuilt() *android.Prebuilt {
Colin Crossec7a0422017-07-07 14:47:12 -07001742 return &j.prebuilt
1743}
1744
Colin Cross74d73e22017-08-02 11:05:49 -07001745func (j *Import) PrebuiltSrcs() []string {
1746 return j.properties.Jars
1747}
1748
1749func (j *Import) Name() string {
Colin Cross5ea9bcc2017-07-27 15:41:32 -07001750 return j.prebuilt.Name(j.ModuleBase.Name())
1751}
1752
Colin Cross74d73e22017-08-02 11:05:49 -07001753func (j *Import) DepsMutator(ctx android.BottomUpMutatorContext) {
Colin Cross37f6d792018-07-12 12:28:41 -07001754 android.ExtractSourcesDeps(ctx, j.properties.Jars)
Colin Cross42d48b72018-08-29 14:10:52 -07001755 ctx.AddVariationDependencies(nil, libTag, j.properties.Libs...)
Colin Cross1e676be2016-10-12 14:38:15 -07001756}
1757
Colin Cross74d73e22017-08-02 11:05:49 -07001758func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross37f6d792018-07-12 12:28:41 -07001759 jars := ctx.ExpandSources(j.properties.Jars, nil)
Colin Crosse1d62a82015-04-03 16:53:05 -07001760
Nan Zhang4c819fb2018-08-27 18:31:46 -07001761 jarName := ctx.ModuleName() + ".jar"
1762 outputFile := android.PathForModuleOut(ctx, "combined", jarName)
Colin Cross37f6d792018-07-12 12:28:41 -07001763 TransformJarsToJar(ctx, outputFile, "for prebuilts", jars, android.OptionalPath{},
1764 false, j.properties.Exclude_files, j.properties.Exclude_dirs)
Nan Zhang4c819fb2018-08-27 18:31:46 -07001765 if Bool(j.properties.Jetifier_enabled) {
1766 inputFile := outputFile
1767 outputFile = android.PathForModuleOut(ctx, "jetifier", jarName)
1768 TransformJetifier(ctx, outputFile, inputFile)
1769 }
Colin Crosse9a275b2017-10-16 17:09:48 -07001770 j.combinedClasspathFile = outputFile
Jiyong Park1be96912018-05-28 18:02:19 +09001771
1772 ctx.VisitDirectDeps(func(module android.Module) {
1773 otherName := ctx.OtherModuleName(module)
1774 tag := ctx.OtherModuleDependencyTag(module)
1775
1776 switch dep := module.(type) {
1777 case Dependency:
1778 switch tag {
1779 case libTag, staticLibTag:
1780 // sdk lib names from dependencies are re-exported
1781 j.exportedSdkLibs = append(j.exportedSdkLibs, dep.ExportedSdkLibs()...)
1782 }
1783 case SdkLibraryDependency:
1784 switch tag {
1785 case libTag:
1786 // names of sdk libs that are directly depended are exported
1787 j.exportedSdkLibs = append(j.exportedSdkLibs, otherName)
1788 }
1789 }
1790 })
1791
1792 j.exportedSdkLibs = android.FirstUniqueStrings(j.exportedSdkLibs)
Nan Zhang4973ecf2018-08-10 13:42:12 -07001793 if Bool(j.properties.Installable) {
1794 ctx.InstallFile(android.PathForModuleInstall(ctx, "framework"),
1795 ctx.ModuleName()+".jar", outputFile)
1796 }
Colin Cross2fe66872015-03-30 17:20:39 -07001797}
1798
Colin Cross74d73e22017-08-02 11:05:49 -07001799var _ Dependency = (*Import)(nil)
Colin Cross2fe66872015-03-30 17:20:39 -07001800
Nan Zhanged19fc32017-10-19 13:06:22 -07001801func (j *Import) HeaderJars() android.Paths {
albaltai36ff7dc2018-12-25 14:35:23 +08001802 if j.combinedClasspathFile == nil {
1803 return nil
1804 }
Colin Cross37f6d792018-07-12 12:28:41 -07001805 return android.Paths{j.combinedClasspathFile}
Nan Zhanged19fc32017-10-19 13:06:22 -07001806}
1807
1808func (j *Import) ImplementationJars() android.Paths {
shinwang9e4c07a2018-12-24 15:41:04 +08001809 if j.combinedClasspathFile == nil {
1810 return nil
1811 }
Colin Cross37f6d792018-07-12 12:28:41 -07001812 return android.Paths{j.combinedClasspathFile}
Colin Cross2fe66872015-03-30 17:20:39 -07001813}
1814
Colin Cross331a1212018-08-15 20:40:52 -07001815func (j *Import) ResourceJars() android.Paths {
1816 return nil
1817}
1818
1819func (j *Import) ImplementationAndResourcesJars() android.Paths {
albaltai36ff7dc2018-12-25 14:35:23 +08001820 if j.combinedClasspathFile == nil {
1821 return nil
1822 }
Colin Cross331a1212018-08-15 20:40:52 -07001823 return android.Paths{j.combinedClasspathFile}
1824}
1825
Colin Crossf24a22a2019-01-31 14:12:44 -08001826func (j *Import) DexJar() android.Path {
1827 return nil
1828}
1829
Colin Cross74d73e22017-08-02 11:05:49 -07001830func (j *Import) AidlIncludeDirs() android.Paths {
Colin Crossc0b06f12015-04-08 13:03:43 -07001831 return nil
1832}
1833
Jiyong Park1be96912018-05-28 18:02:19 +09001834func (j *Import) ExportedSdkLibs() []string {
1835 return j.exportedSdkLibs
1836}
1837
albaltai36ff7dc2018-12-25 14:35:23 +08001838// Add compile time check for interface implementation
1839var _ android.IDEInfo = (*Import)(nil)
1840var _ android.IDECustomizedModuleName = (*Import)(nil)
1841
Brandon Lee5d45c6f2018-08-15 15:35:38 -07001842// Collect information for opening IDE project files in java/jdeps.go.
1843const (
1844 removedPrefix = "prebuilt_"
1845)
1846
1847func (j *Import) IDEInfo(dpInfo *android.IdeInfo) {
1848 dpInfo.Jars = append(dpInfo.Jars, j.PrebuiltSrcs()...)
1849}
1850
1851func (j *Import) IDECustomizedModuleName() string {
1852 // TODO(b/113562217): Extract the base module name from the Import name, often the Import name
1853 // has a prefix "prebuilt_". Remove the prefix explicitly if needed until we find a better
1854 // solution to get the Import name.
1855 name := j.Name()
1856 if strings.HasPrefix(name, removedPrefix) {
patricktubb640e02018-10-11 18:33:16 +08001857 name = strings.TrimPrefix(name, removedPrefix)
Brandon Lee5d45c6f2018-08-15 15:35:38 -07001858 }
1859 return name
1860}
1861
Colin Cross74d73e22017-08-02 11:05:49 -07001862var _ android.PrebuiltInterface = (*Import)(nil)
Colin Cross2fe66872015-03-30 17:20:39 -07001863
Colin Cross1b16b0e2019-02-12 14:41:32 -08001864// java_import imports one or more `.jar` files into the build graph as if they were built by a java_library module.
1865//
1866// By default, a java_import has a single variant that expects a `.jar` file containing `.class` files that were
1867// compiled against an Android classpath.
1868//
1869// Specifying `host_supported: true` will produce two variants, one for use as a dependency of device modules and one
1870// for host modules.
Colin Cross74d73e22017-08-02 11:05:49 -07001871func ImportFactory() android.Module {
1872 module := &Import{}
Colin Cross36242852017-06-23 15:06:31 -07001873
Colin Cross74d73e22017-08-02 11:05:49 -07001874 module.AddProperties(&module.properties)
1875
1876 android.InitPrebuiltModule(module, &module.properties.Jars)
Colin Cross48de9a42018-10-02 13:53:33 -07001877 InitJavaModule(module, android.HostAndDeviceSupported)
Colin Cross36242852017-06-23 15:06:31 -07001878 return module
Colin Cross2fe66872015-03-30 17:20:39 -07001879}
1880
Colin Cross1b16b0e2019-02-12 14:41:32 -08001881// java_import imports one or more `.jar` files into the build graph as if they were built by a java_library_host
1882// module.
1883//
1884// A java_import_host has a single variant that expects a `.jar` file containing `.class` files that were
1885// compiled against a host bootclasspath.
Colin Cross74d73e22017-08-02 11:05:49 -07001886func ImportFactoryHost() android.Module {
1887 module := &Import{}
1888
1889 module.AddProperties(&module.properties)
1890
1891 android.InitPrebuiltModule(module, &module.properties.Jars)
Colin Cross48de9a42018-10-02 13:53:33 -07001892 InitJavaModule(module, android.HostSupported)
Colin Cross74d73e22017-08-02 11:05:49 -07001893 return module
1894}
1895
Colin Cross89536d42017-07-07 14:35:50 -07001896//
1897// Defaults
1898//
1899type Defaults struct {
1900 android.ModuleBase
1901 android.DefaultsModuleBase
1902}
1903
1904func (*Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1905}
1906
Colin Cross1b16b0e2019-02-12 14:41:32 -08001907// java_defaults provides a set of properties that can be inherited by other java or android modules.
1908//
1909// A module can use the properties from a java_defaults module using `defaults: ["defaults_module_name"]`. Each
1910// property in the defaults module that exists in the depending module will be prepended to the depending module's
1911// value for that property.
1912//
1913// Example:
1914//
1915// java_defaults {
1916// name: "example_defaults",
1917// srcs: ["common/**/*.java"],
1918// javacflags: ["-Xlint:all"],
1919// aaptflags: ["--auto-add-overlay"],
1920// }
1921//
1922// java_library {
1923// name: "example",
1924// defaults: ["example_defaults"],
1925// srcs: ["example/**/*.java"],
1926// }
1927//
1928// is functionally identical to:
1929//
1930// java_library {
1931// name: "example",
1932// srcs: [
1933// "common/**/*.java",
1934// "example/**/*.java",
1935// ],
1936// javacflags: ["-Xlint:all"],
1937// }
Colin Cross89536d42017-07-07 14:35:50 -07001938func defaultsFactory() android.Module {
1939 return DefaultsFactory()
1940}
1941
1942func DefaultsFactory(props ...interface{}) android.Module {
1943 module := &Defaults{}
1944
1945 module.AddProperties(props...)
1946 module.AddProperties(
1947 &CompilerProperties{},
1948 &CompilerDeviceProperties{},
Colin Cross43f08db2018-11-12 10:13:39 -08001949 &DexpreoptProperties{},
Dan Willemsen6424d172018-03-08 13:27:59 -08001950 &android.ProtoProperties{},
Colin Cross48de9a42018-10-02 13:53:33 -07001951 &aaptProperties{},
1952 &androidLibraryProperties{},
1953 &appProperties{},
1954 &appTestProperties{},
1955 &ImportProperties{},
1956 &AARImportProperties{},
1957 &sdkLibraryProperties{},
Colin Cross89536d42017-07-07 14:35:50 -07001958 )
1959
1960 android.InitDefaultsModule(module)
1961
1962 return module
1963}
Nan Zhangea568a42017-11-08 21:20:04 -08001964
1965var Bool = proptools.Bool
Colin Cross38b40df2018-04-10 16:14:46 -07001966var BoolDefault = proptools.BoolDefault
Nan Zhangea568a42017-11-08 21:20:04 -08001967var String = proptools.String
Colin Cross0d0ba592018-02-20 13:33:42 -08001968var inList = android.InList