blob: dcd6dbe937d8e3be6e3470d88341c53d27ad535d [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 Cross3d7c9822019-03-01 13:46:24 -080047 android.RegisterModuleType("java_device_for_host", DeviceForHostFactory)
48 android.RegisterModuleType("java_host_for_device", HostForDeviceFactory)
Colin Cross463a90e2015-06-17 14:20:06 -070049
Colin Cross798bfce2016-10-12 14:28:16 -070050 android.RegisterSingletonType("logtags", LogtagsSingleton)
Colin Cross463a90e2015-06-17 14:20:06 -070051}
52
Colin Cross2fe66872015-03-30 17:20:39 -070053// TODO:
54// Autogenerated files:
Colin Cross2fe66872015-03-30 17:20:39 -070055// Renderscript
56// Post-jar passes:
57// Proguard
Colin Cross2fe66872015-03-30 17:20:39 -070058// Rmtypedefs
Colin Cross2fe66872015-03-30 17:20:39 -070059// DroidDoc
60// Findbugs
61
Colin Cross89536d42017-07-07 14:35:50 -070062type CompilerProperties struct {
Colin Cross7d5136f2015-05-11 13:39:40 -070063 // list of source files used to compile the Java module. May be .java, .logtags, .proto,
64 // or .aidl files.
Colin Cross27b922f2019-03-04 22:35:41 -080065 Srcs []string `android:"path,arch_variant"`
Dan Willemsen2ef08f42015-06-30 18:15:24 -070066
67 // list of source files that should not be used to build the Java module.
68 // This is most useful in the arch/multilib variants to remove non-common files
Colin Cross27b922f2019-03-04 22:35:41 -080069 Exclude_srcs []string `android:"path,arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -070070
71 // list of directories containing Java resources
Colin Cross86a63ff2017-09-27 17:33:10 -070072 Java_resource_dirs []string `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -070073
Colin Cross86a63ff2017-09-27 17:33:10 -070074 // list of directories that should be excluded from java_resource_dirs
75 Exclude_java_resource_dirs []string `android:"arch_variant"`
Dan Willemsen2ef08f42015-06-30 18:15:24 -070076
Colin Cross0f37af02017-09-27 17:42:05 -070077 // list of files to use as Java resources
Colin Cross27b922f2019-03-04 22:35:41 -080078 Java_resources []string `android:"path,arch_variant"`
Colin Cross0f37af02017-09-27 17:42:05 -070079
Colin Crosscedd4762018-09-13 11:26:19 -070080 // list of files that should be excluded from java_resources and java_resource_dirs
Colin Cross27b922f2019-03-04 22:35:41 -080081 Exclude_java_resources []string `android:"path,arch_variant"`
Colin Cross0f37af02017-09-27 17:42:05 -070082
Paul Duffin2fbbfb82019-02-13 12:49:33 +000083 // don't build against the default libraries (bootclasspath, ext, and framework for device
84 // targets)
Colin Cross76b5f0c2017-08-29 16:02:06 -070085 No_standard_libs *bool
Colin Cross7d5136f2015-05-11 13:39:40 -070086
Paul Duffin2fbbfb82019-02-13 12:49:33 +000087 // don't build against the framework libraries (ext, and framework for device targets)
Colin Crossfa5eb232017-10-01 20:33:03 -070088 No_framework_libs *bool
89
Colin Cross7d5136f2015-05-11 13:39:40 -070090 // list of module-specific flags that will be used for javac compiles
91 Javacflags []string `android:"arch_variant"`
92
Zoran Jovanovic8736ce22018-08-21 17:10:29 +020093 // list of module-specific flags that will be used for kotlinc compiles
94 Kotlincflags []string `android:"arch_variant"`
95
Colin Cross7d5136f2015-05-11 13:39:40 -070096 // list of of java libraries that will be in the classpath
Colin Crosse8dc34a2017-07-19 11:22:16 -070097 Libs []string `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -070098
99 // list of java libraries that will be compiled into the resulting jar
Colin Crosse8dc34a2017-07-19 11:22:16 -0700100 Static_libs []string `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700101
102 // manifest file to be included in resulting jar
Colin Cross27b922f2019-03-04 22:35:41 -0800103 Manifest *string `android:"path"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700104
Colin Cross540eff82017-06-22 17:01:52 -0700105 // if not blank, run jarjar using the specified rules file
Colin Cross27b922f2019-03-04 22:35:41 -0800106 Jarjar_rules *string `android:"path,arch_variant"`
Colin Cross64162712017-08-08 13:17:59 -0700107
108 // If not blank, set the java version passed to javac as -source and -target
109 Java_version *string
Colin Cross2c429dc2017-08-31 16:45:16 -0700110
Colin Cross9ae1b922018-06-26 17:59:05 -0700111 // If set to true, allow this module to be dexed and installed on devices. Has no
112 // effect on host modules, which are always considered installable.
Colin Cross2c429dc2017-08-31 16:45:16 -0700113 Installable *bool
Colin Cross32f676a2017-09-06 13:41:06 -0700114
Colin Cross0f37af02017-09-27 17:42:05 -0700115 // If set to true, include sources used to compile the module in to the final jar
116 Include_srcs *bool
117
Colin Crossbe9cdb82019-01-21 21:37:16 -0800118 // List of modules to use as annotation processors
119 Plugins []string
Colin Cross1369cdb2017-09-29 17:58:17 -0700120
Nan Zhang61eaedb2017-11-02 13:28:15 -0700121 // The number of Java source entries each Javac instance can process
122 Javac_shard_size *int64
123
Nan Zhang5f8cb422018-02-06 10:34:32 -0800124 // Add host jdk tools.jar to bootclasspath
125 Use_tools_jar *bool
126
Colin Cross1369cdb2017-09-29 17:58:17 -0700127 Openjdk9 struct {
128 // List of source files that should only be used when passing -source 1.9
Colin Cross27b922f2019-03-04 22:35:41 -0800129 Srcs []string `android:"path"`
Colin Cross1369cdb2017-09-29 17:58:17 -0700130
131 // List of javac flags that should only be used when passing -source 1.9
132 Javacflags []string
133 }
Colin Crosscb933592017-11-22 13:49:43 -0800134
Colin Cross81440082018-08-15 20:21:55 -0700135 // When compiling language level 9+ .java code in packages that are part of
136 // a system module, patch_module names the module that your sources and
137 // dependencies should be patched into. The Android runtime currently
138 // doesn't implement the JEP 261 module system so this option is only
139 // supported at compile time. It should only be needed to compile tests in
140 // packages that exist in libcore and which are inconvenient to move
141 // elsewhere.
Tobias Thiererdda713d2018-09-19 16:16:19 +0100142 Patch_module *string `android:"arch_variant"`
Colin Cross81440082018-08-15 20:21:55 -0700143
Colin Crosscb933592017-11-22 13:49:43 -0800144 Jacoco struct {
145 // List of classes to include for instrumentation with jacoco to collect coverage
146 // information at runtime when building with coverage enabled. If unset defaults to all
147 // classes.
148 // Supports '*' as the last character of an entry in the list as a wildcard match.
149 // If preceded by '.' it matches all classes in the package and subpackages, otherwise
150 // it matches classes in the package that have the class name as a prefix.
151 Include_filter []string
152
153 // List of classes to exclude from instrumentation with jacoco to collect coverage
154 // information at runtime when building with coverage enabled. Overrides classes selected
155 // by the include_filter property.
156 // Supports '*' as the last character of an entry in the list as a wildcard match.
157 // If preceded by '.' it matches all classes in the package and subpackages, otherwise
158 // it matches classes in the package that have the class name as a prefix.
159 Exclude_filter []string
160 }
161
Andreas Gampef3e5b552018-01-22 21:27:21 -0800162 Errorprone struct {
163 // List of javac flags that should only be used when running errorprone.
164 Javacflags []string
165 }
166
Colin Cross0f2ee152017-12-14 15:22:43 -0800167 Proto struct {
168 // List of extra options that will be passed to the proto generator.
169 Output_params []string
170 }
171
Colin Crosscb933592017-11-22 13:49:43 -0800172 Instrument bool `blueprint:"mutated"`
Alex Light7f004a72019-02-21 13:27:37 -0800173
174 // List of files to include in the META-INF/services folder of the resulting jar.
Colin Cross27b922f2019-03-04 22:35:41 -0800175 Services []string `android:"path,arch_variant"`
Colin Cross540eff82017-06-22 17:01:52 -0700176}
177
Colin Cross89536d42017-07-07 14:35:50 -0700178type CompilerDeviceProperties struct {
Colin Cross540eff82017-06-22 17:01:52 -0700179 // list of module-specific flags that will be used for dex compiles
180 Dxflags []string `android:"arch_variant"`
181
Colin Cross83bb3162018-06-25 15:48:06 -0700182 // if not blank, set to the version of the sdk to compile against. Defaults to compiling against the current
183 // sdk if platform_apis is not set.
Nan Zhangea568a42017-11-08 21:20:04 -0800184 Sdk_version *string
Colin Cross7d5136f2015-05-11 13:39:40 -0700185
Colin Cross83bb3162018-06-25 15:48:06 -0700186 // if not blank, set the minimum version of the sdk that the compiled artifacts will run against.
187 // Defaults to sdk_version if not set.
188 Min_sdk_version *string
189
Dan Willemsen419290a2018-10-31 15:28:47 -0700190 // if not blank, set the targetSdkVersion in the AndroidManifest.xml.
191 // Defaults to sdk_version if not set.
192 Target_sdk_version *string
193
Colin Cross6af2e492018-05-22 11:12:33 -0700194 // if true, compile against the platform APIs instead of an SDK.
195 Platform_apis *bool
196
Colin Crossebe1a512017-11-14 13:12:14 -0800197 Aidl struct {
198 // Top level directories to pass to aidl tool
199 Include_dirs []string
Colin Cross7d5136f2015-05-11 13:39:40 -0700200
Colin Crossebe1a512017-11-14 13:12:14 -0800201 // Directories rooted at the Android.bp file to pass to aidl tool
202 Local_include_dirs []string
203
204 // directories that should be added as include directories for any aidl sources of modules
205 // that depend on this module, as well as to aidl for this module.
206 Export_include_dirs []string
Martijn Coeneneab15642018-03-09 09:29:59 +0100207
208 // whether to generate traces (for systrace) for this interface
209 Generate_traces *bool
Olivier Gaillard0a4cfbc2018-07-16 23:37:03 +0100210
211 // whether to generate Binder#GetTransaction name method.
212 Generate_get_transaction_name *bool
Colin Crossebe1a512017-11-14 13:12:14 -0800213 }
Colin Cross92430102017-10-09 14:59:32 -0700214
215 // If true, export a copy of the module as a -hostdex module for host testing.
216 Hostdex *bool
Colin Cross1369cdb2017-09-29 17:58:17 -0700217
David Brazdil17ef5632018-06-27 10:27:45 +0100218 // If set to true, compile dex regardless of installable. Defaults to false.
219 Compile_dex *bool
220
Colin Cross66dbc0b2017-12-28 12:23:20 -0800221 Optimize struct {
Colin Crossae5caf52018-05-22 11:11:52 -0700222 // If false, disable all optimization. Defaults to true for android_app and android_test
223 // modules, false for java_library and java_test modules.
Colin Cross66dbc0b2017-12-28 12:23:20 -0800224 Enabled *bool
225
226 // If true, optimize for size by removing unused code. Defaults to true for apps,
227 // false for libraries and tests.
228 Shrink *bool
229
230 // If true, optimize bytecode. Defaults to false.
231 Optimize *bool
232
233 // If true, obfuscate bytecode. Defaults to false.
234 Obfuscate *bool
235
236 // If true, do not use the flag files generated by aapt that automatically keep
237 // classes referenced by the app manifest. Defaults to false.
238 No_aapt_flags *bool
239
240 // Flags to pass to proguard.
241 Proguard_flags []string
242
243 // Specifies the locations of files containing proguard flags.
Colin Cross27b922f2019-03-04 22:35:41 -0800244 Proguard_flags_files []string `android:"path"`
Colin Cross66dbc0b2017-12-28 12:23:20 -0800245 }
246
Colin Cross1369cdb2017-09-29 17:58:17 -0700247 // When targeting 1.9, override the modules to use with --system
248 System_modules *string
Colin Cross5a0dcd52018-10-05 14:20:06 -0700249
250 UncompressDex bool `blueprint:"mutated"`
Colin Cross43f08db2018-11-12 10:13:39 -0800251 IsSDKLibrary bool `blueprint:"mutated"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700252}
253
Colin Cross46c9b8b2017-06-22 16:51:17 -0700254// Module contains the properties and members used by all java module types
255type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700256 android.ModuleBase
Colin Cross89536d42017-07-07 14:35:50 -0700257 android.DefaultableModuleBase
Colin Cross2fe66872015-03-30 17:20:39 -0700258
Colin Cross89536d42017-07-07 14:35:50 -0700259 properties CompilerProperties
Colin Cross6af17aa2017-09-20 12:59:05 -0700260 protoProperties android.ProtoProperties
Colin Cross89536d42017-07-07 14:35:50 -0700261 deviceProperties CompilerDeviceProperties
Colin Cross2fe66872015-03-30 17:20:39 -0700262
Colin Cross331a1212018-08-15 20:40:52 -0700263 // jar file containing header classes including static library dependencies, suitable for
264 // inserting into the bootclasspath/classpath of another compile
Nan Zhanged19fc32017-10-19 13:06:22 -0700265 headerJarFile android.Path
266
Colin Cross331a1212018-08-15 20:40:52 -0700267 // jar file containing implementation classes including static library dependencies but no
268 // resources
Nan Zhanged19fc32017-10-19 13:06:22 -0700269 implementationJarFile android.Path
Colin Cross2fe66872015-03-30 17:20:39 -0700270
Colin Cross331a1212018-08-15 20:40:52 -0700271 // jar file containing only resources including from static library dependencies
272 resourceJar android.Path
273
274 // jar file containing implementation classes and resources including static library
275 // dependencies
276 implementationAndResourcesJar android.Path
277
278 // output file containing classes.dex and resources
Colin Cross6ade34f2017-09-15 13:00:47 -0700279 dexJarFile android.Path
280
Colin Cross43f08db2018-11-12 10:13:39 -0800281 // output file that contains classes.dex if it should be in the output file
282 maybeStrippedDexJarFile android.Path
283
Colin Crosscb933592017-11-22 13:49:43 -0800284 // output file containing uninstrumented classes that will be instrumented by jacoco
285 jacocoReportClassesFile android.Path
286
Colin Cross66dbc0b2017-12-28 12:23:20 -0800287 // output file containing mapping of obfuscated names
288 proguardDictionary android.Path
289
Colin Cross331a1212018-08-15 20:40:52 -0700290 // output file of the module, which may be a classes jar or a dex jar
Colin Cross635c3b02016-05-18 15:37:25 -0700291 outputFile android.Path
Colin Crossb7a63242015-04-16 14:09:14 -0700292
Colin Cross635c3b02016-05-18 15:37:25 -0700293 exportAidlIncludeDirs android.Paths
Colin Crossc0b06f12015-04-08 13:03:43 -0700294
Colin Cross635c3b02016-05-18 15:37:25 -0700295 logtagsSrcs android.Paths
Colin Crossf05fe972015-04-10 17:45:20 -0700296
Colin Cross2fe66872015-03-30 17:20:39 -0700297 // installed file for binary dependency
Colin Cross635c3b02016-05-18 15:37:25 -0700298 installFile android.Path
Colin Cross5ab4e6d2017-11-22 16:20:45 -0800299
300 // list of .java files and srcjars that was passed to javac
301 compiledJavaSrcs android.Paths
302 compiledSrcJars android.Paths
Colin Cross66dbc0b2017-12-28 12:23:20 -0800303
304 // list of extra progurad flag files
305 extraProguardFlagFiles android.Paths
Jiyong Park1be96912018-05-28 18:02:19 +0900306
Colin Cross094054a2018-10-17 15:10:48 -0700307 // manifest file to use instead of properties.Manifest
308 overrideManifest android.OptionalPath
309
Jiyong Park1be96912018-05-28 18:02:19 +0900310 // list of SDK lib names that this java moudule is exporting
311 exportedSdkLibs []string
Brandon Lee5d45c6f2018-08-15 15:35:38 -0700312
313 // list of source files, collected from compiledJavaSrcs and compiledSrcJars
314 // filter out Exclude_srcs, will be used by android.IDEInfo struct
315 expandIDEInfoCompiledSrcs []string
Colin Cross43f08db2018-11-12 10:13:39 -0800316
Steven Morelandc4efd9c2019-01-18 11:51:25 -0800317 // expanded Jarjar_rules
318 expandJarjarRules android.Path
319
Colin Crossf24a22a2019-01-31 14:12:44 -0800320 hiddenAPI
Colin Cross43f08db2018-11-12 10:13:39 -0800321 dexpreopter
Colin Cross2fe66872015-03-30 17:20:39 -0700322}
323
Colin Cross54250902017-12-05 09:28:08 -0800324func (j *Module) Srcs() android.Paths {
Colin Cross3063b782018-08-15 11:19:12 -0700325 return android.Paths{j.outputFile}
Colin Cross54250902017-12-05 09:28:08 -0800326}
327
Jiyong Park8fd61922018-11-08 02:50:25 +0900328func (j *Module) DexJarFile() android.Path {
329 return j.dexJarFile
330}
331
Colin Cross54250902017-12-05 09:28:08 -0800332var _ android.SourceFileProducer = (*Module)(nil)
333
Colin Crossf506d872017-07-19 15:53:04 -0700334type Dependency interface {
Nan Zhanged19fc32017-10-19 13:06:22 -0700335 HeaderJars() android.Paths
336 ImplementationJars() android.Paths
Colin Cross331a1212018-08-15 20:40:52 -0700337 ResourceJars() android.Paths
338 ImplementationAndResourcesJars() android.Paths
Colin Crossf24a22a2019-01-31 14:12:44 -0800339 DexJar() android.Path
Colin Cross635c3b02016-05-18 15:37:25 -0700340 AidlIncludeDirs() android.Paths
Jiyong Park1be96912018-05-28 18:02:19 +0900341 ExportedSdkLibs() []string
Colin Cross2fe66872015-03-30 17:20:39 -0700342}
343
Jiyong Parkc678ad32018-04-10 13:07:10 +0900344type SdkLibraryDependency interface {
Colin Cross897d2ed2019-02-11 14:03:51 -0800345 SdkHeaderJars(ctx android.BaseContext, sdkVersion string) android.Paths
346 SdkImplementationJars(ctx android.BaseContext, sdkVersion string) android.Paths
Jiyong Parkc678ad32018-04-10 13:07:10 +0900347}
348
Nan Zhangb2b33de2018-02-23 11:18:47 -0800349type SrcDependency interface {
350 CompiledSrcs() android.Paths
351 CompiledSrcJars() android.Paths
352}
353
354func (j *Module) CompiledSrcs() android.Paths {
355 return j.compiledJavaSrcs
356}
357
358func (j *Module) CompiledSrcJars() android.Paths {
359 return j.compiledSrcJars
360}
361
362var _ SrcDependency = (*Module)(nil)
363
Colin Cross89536d42017-07-07 14:35:50 -0700364func InitJavaModule(module android.DefaultableModule, hod android.HostOrDeviceSupported) {
365 android.InitAndroidArchModule(module, hod, android.MultilibCommon)
366 android.InitDefaultableModule(module)
367}
368
Colin Crossbe1da472017-07-07 15:59:46 -0700369type dependencyTag struct {
370 blueprint.BaseDependencyTag
371 name string
Colin Cross2fe66872015-03-30 17:20:39 -0700372}
373
Colin Crossa4f08812018-10-02 22:03:40 -0700374type jniDependencyTag struct {
375 blueprint.BaseDependencyTag
376 target android.Target
377}
378
Colin Crossbe1da472017-07-07 15:59:46 -0700379var (
Colin Cross4b964c02018-10-15 16:18:06 -0700380 staticLibTag = dependencyTag{name: "staticlib"}
381 libTag = dependencyTag{name: "javalib"}
Colin Crossbe9cdb82019-01-21 21:37:16 -0800382 pluginTag = dependencyTag{name: "plugin"}
Colin Cross4b964c02018-10-15 16:18:06 -0700383 bootClasspathTag = dependencyTag{name: "bootclasspath"}
384 systemModulesTag = dependencyTag{name: "system modules"}
385 frameworkResTag = dependencyTag{name: "framework-res"}
386 frameworkApkTag = dependencyTag{name: "framework-apk"}
387 kotlinStdlibTag = dependencyTag{name: "kotlin-stdlib"}
Colin Crossafbb1732019-01-17 15:42:52 -0800388 kotlinAnnotationsTag = dependencyTag{name: "kotlin-annotations"}
Colin Cross4b964c02018-10-15 16:18:06 -0700389 proguardRaiseTag = dependencyTag{name: "proguard-raise"}
390 certificateTag = dependencyTag{name: "certificate"}
391 instrumentationForTag = dependencyTag{name: "instrumentation_for"}
Colin Crossbe1da472017-07-07 15:59:46 -0700392)
Colin Cross2fe66872015-03-30 17:20:39 -0700393
Colin Crossfc3674a2017-09-18 17:41:52 -0700394type sdkDep struct {
Colin Cross47ff2522017-10-02 14:22:08 -0700395 useModule, useFiles, useDefaultLibs, invalidVersion bool
396
Colin Cross86a60ae2018-05-29 14:44:55 -0700397 modules []string
Colin Cross1369cdb2017-09-29 17:58:17 -0700398 systemModules string
399
Colin Crossa97c5d32018-03-28 14:58:31 -0700400 frameworkResModule string
401
Colin Cross86a60ae2018-05-29 14:44:55 -0700402 jars android.Paths
Colin Cross1369cdb2017-09-29 17:58:17 -0700403 aidl android.Path
404}
405
Colin Crossa4f08812018-10-02 22:03:40 -0700406type jniLib struct {
407 name string
408 path android.Path
409 target android.Target
410}
411
Colin Cross3144dfc2018-01-03 15:06:47 -0800412func (j *Module) shouldInstrument(ctx android.BaseContext) bool {
413 return j.properties.Instrument && ctx.Config().IsEnvTrue("EMMA_INSTRUMENT")
414}
415
416func (j *Module) shouldInstrumentStatic(ctx android.BaseContext) bool {
417 return j.shouldInstrument(ctx) &&
418 (ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_STATIC") ||
419 ctx.Config().UnbundledBuild())
420}
421
Colin Cross83bb3162018-06-25 15:48:06 -0700422func (j *Module) sdkVersion() string {
423 return String(j.deviceProperties.Sdk_version)
424}
425
426func (j *Module) minSdkVersion() string {
427 if j.deviceProperties.Min_sdk_version != nil {
428 return *j.deviceProperties.Min_sdk_version
429 }
430 return j.sdkVersion()
431}
432
Dan Willemsen419290a2018-10-31 15:28:47 -0700433func (j *Module) targetSdkVersion() string {
434 if j.deviceProperties.Target_sdk_version != nil {
435 return *j.deviceProperties.Target_sdk_version
436 }
437 return j.sdkVersion()
438}
439
Colin Crossbe1da472017-07-07 15:59:46 -0700440func (j *Module) deps(ctx android.BottomUpMutatorContext) {
Colin Cross1369cdb2017-09-29 17:58:17 -0700441 if ctx.Device() {
Colin Crossff3ae9d2018-04-10 16:15:18 -0700442 if !Bool(j.properties.No_standard_libs) {
Colin Cross83bb3162018-06-25 15:48:06 -0700443 sdkDep := decodeSdkDep(ctx, sdkContext(j))
Colin Crossfc3674a2017-09-18 17:41:52 -0700444 if sdkDep.useDefaultLibs {
Colin Cross42d48b72018-08-29 14:10:52 -0700445 ctx.AddVariationDependencies(nil, bootClasspathTag, config.DefaultBootclasspathLibraries...)
Tobias Thierer06dd04f2018-09-11 16:21:05 +0100446 ctx.AddVariationDependencies(nil, systemModulesTag, config.DefaultSystemModules)
Colin Crossff3ae9d2018-04-10 16:15:18 -0700447 if !Bool(j.properties.No_framework_libs) {
Colin Cross42d48b72018-08-29 14:10:52 -0700448 ctx.AddVariationDependencies(nil, libTag, config.DefaultLibraries...)
Colin Crossfa5eb232017-10-01 20:33:03 -0700449 }
Colin Cross1369cdb2017-09-29 17:58:17 -0700450 } else if sdkDep.useModule {
Tobias Thierer06dd04f2018-09-11 16:21:05 +0100451 ctx.AddVariationDependencies(nil, systemModulesTag, sdkDep.systemModules)
Colin Cross42d48b72018-08-29 14:10:52 -0700452 ctx.AddVariationDependencies(nil, bootClasspathTag, sdkDep.modules...)
Colin Cross66dbc0b2017-12-28 12:23:20 -0800453 if Bool(j.deviceProperties.Optimize.Enabled) {
Colin Cross42d48b72018-08-29 14:10:52 -0700454 ctx.AddVariationDependencies(nil, proguardRaiseTag, config.DefaultBootclasspathLibraries...)
455 ctx.AddVariationDependencies(nil, proguardRaiseTag, config.DefaultLibraries...)
Colin Cross66dbc0b2017-12-28 12:23:20 -0800456 }
Colin Crossbe1da472017-07-07 15:59:46 -0700457 }
Colin Cross1369cdb2017-09-29 17:58:17 -0700458 } else if j.deviceProperties.System_modules == nil {
459 ctx.PropertyErrorf("no_standard_libs",
460 "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 +0100461 } else if *j.deviceProperties.System_modules != "none" {
Colin Cross42d48b72018-08-29 14:10:52 -0700462 ctx.AddVariationDependencies(nil, systemModulesTag, *j.deviceProperties.System_modules)
Colin Cross2fe66872015-03-30 17:20:39 -0700463 }
Mathew Inwoodebe29ce2018-09-04 14:26:19 +0100464 if (ctx.ModuleName() == "framework") || (ctx.ModuleName() == "framework-annotation-proc") {
Colin Cross42d48b72018-08-29 14:10:52 -0700465 ctx.AddVariationDependencies(nil, frameworkResTag, "framework-res")
Colin Cross5ab4e6d2017-11-22 16:20:45 -0800466 }
Nan Zhangb2b33de2018-02-23 11:18:47 -0800467 if ctx.ModuleName() == "android_stubs_current" ||
468 ctx.ModuleName() == "android_system_stubs_current" ||
Nan Zhang863f05b2018-08-07 13:41:10 -0700469 ctx.ModuleName() == "android_test_stubs_current" {
Colin Cross42d48b72018-08-29 14:10:52 -0700470 ctx.AddVariationDependencies(nil, frameworkApkTag, "framework-res")
Nan Zhangb2b33de2018-02-23 11:18:47 -0800471 }
Colin Cross2fe66872015-03-30 17:20:39 -0700472 }
Colin Cross1369cdb2017-09-29 17:58:17 -0700473
Colin Cross42d48b72018-08-29 14:10:52 -0700474 ctx.AddVariationDependencies(nil, libTag, j.properties.Libs...)
475 ctx.AddVariationDependencies(nil, staticLibTag, j.properties.Static_libs...)
Colin Crossa4f08812018-10-02 22:03:40 -0700476
Colin Crossbe9cdb82019-01-21 21:37:16 -0800477 ctx.AddFarVariationDependencies([]blueprint.Variation{
478 {Mutator: "arch", Variation: ctx.Config().BuildOsCommonVariant},
479 }, pluginTag, j.properties.Plugins...)
480
Colin Cross6af17aa2017-09-20 12:59:05 -0700481 if j.hasSrcExt(".proto") {
482 protoDeps(ctx, &j.protoProperties)
483 }
Colin Cross93e85952017-08-15 13:34:18 -0700484
485 if j.hasSrcExt(".kt") {
486 // TODO(ccross): move this to a mutator pass that can tell if generated sources contain
487 // Kotlin files
Colin Cross42d48b72018-08-29 14:10:52 -0700488 ctx.AddVariationDependencies(nil, kotlinStdlibTag, "kotlin-stdlib")
Colin Cross7788c122019-01-23 16:14:02 -0800489 if len(j.properties.Plugins) > 0 {
Colin Crossafbb1732019-01-17 15:42:52 -0800490 ctx.AddVariationDependencies(nil, kotlinAnnotationsTag, "kotlin-annotations")
491 }
Colin Cross93e85952017-08-15 13:34:18 -0700492 }
Colin Cross3144dfc2018-01-03 15:06:47 -0800493
494 if j.shouldInstrumentStatic(ctx) {
Colin Cross42d48b72018-08-29 14:10:52 -0700495 ctx.AddVariationDependencies(nil, staticLibTag, "jacocoagent")
Colin Cross3144dfc2018-01-03 15:06:47 -0800496 }
Colin Cross6af17aa2017-09-20 12:59:05 -0700497}
498
499func hasSrcExt(srcs []string, ext string) bool {
500 for _, src := range srcs {
501 if filepath.Ext(src) == ext {
502 return true
503 }
504 }
505
506 return false
507}
508
Nan Zhang61eaedb2017-11-02 13:28:15 -0700509func shardPaths(paths android.Paths, shardSize int) []android.Paths {
510 ret := make([]android.Paths, 0, (len(paths)+shardSize-1)/shardSize)
511 for len(paths) > shardSize {
512 ret = append(ret, paths[0:shardSize])
513 paths = paths[shardSize:]
514 }
515 if len(paths) > 0 {
516 ret = append(ret, paths)
517 }
518 return ret
519}
520
Colin Cross6af17aa2017-09-20 12:59:05 -0700521func (j *Module) hasSrcExt(ext string) bool {
522 return hasSrcExt(j.properties.Srcs, ext)
Colin Cross2fe66872015-03-30 17:20:39 -0700523}
524
Colin Cross46c9b8b2017-06-22 16:51:17 -0700525func (j *Module) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.OptionalPath,
Colin Cross635c3b02016-05-18 15:37:25 -0700526 aidlIncludeDirs android.Paths) []string {
Colin Crossc0b06f12015-04-08 13:03:43 -0700527
Colin Crossebe1a512017-11-14 13:12:14 -0800528 aidlIncludes := android.PathsForModuleSrc(ctx, j.deviceProperties.Aidl.Local_include_dirs)
529 aidlIncludes = append(aidlIncludes,
530 android.PathsForModuleSrc(ctx, j.deviceProperties.Aidl.Export_include_dirs)...)
531 aidlIncludes = append(aidlIncludes,
532 android.PathsForSource(ctx, j.deviceProperties.Aidl.Include_dirs)...)
Colin Crossc0b06f12015-04-08 13:03:43 -0700533
Steven Moreland36b130f2019-02-05 17:02:55 -0800534 flags := []string{}
Steven Moreland667f6882018-07-26 12:55:08 -0700535
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700536 if aidlPreprocess.Valid() {
537 flags = append(flags, "-p"+aidlPreprocess.String())
Colin Crossc0b06f12015-04-08 13:03:43 -0700538 } else {
Colin Cross635c3b02016-05-18 15:37:25 -0700539 flags = append(flags, android.JoinWithPrefix(aidlIncludeDirs.Strings(), "-I"))
Colin Crossc0b06f12015-04-08 13:03:43 -0700540 }
541
Colin Cross635c3b02016-05-18 15:37:25 -0700542 flags = append(flags, android.JoinWithPrefix(j.exportAidlIncludeDirs.Strings(), "-I"))
Colin Crossebe1a512017-11-14 13:12:14 -0800543 flags = append(flags, android.JoinWithPrefix(aidlIncludes.Strings(), "-I"))
Colin Cross635c3b02016-05-18 15:37:25 -0700544 flags = append(flags, "-I"+android.PathForModuleSrc(ctx).String())
Colin Cross32f38982018-02-22 11:47:25 -0800545 if src := android.ExistentPathForSource(ctx, ctx.ModuleDir(), "src"); src.Valid() {
Colin Crossd48633a2017-07-13 14:41:17 -0700546 flags = append(flags, "-I"+src.String())
547 }
Colin Crossc0b06f12015-04-08 13:03:43 -0700548
Martijn Coeneneab15642018-03-09 09:29:59 +0100549 if Bool(j.deviceProperties.Aidl.Generate_traces) {
550 flags = append(flags, "-t")
551 }
552
Olivier Gaillard0a4cfbc2018-07-16 23:37:03 +0100553 if Bool(j.deviceProperties.Aidl.Generate_get_transaction_name) {
554 flags = append(flags, "--transaction_names")
555 }
556
Colin Crossf03c82b2015-04-13 13:53:40 -0700557 return flags
Colin Crossc0b06f12015-04-08 13:03:43 -0700558}
559
Colin Cross32f676a2017-09-06 13:41:06 -0700560type deps struct {
Nan Zhang581fd212018-01-10 16:06:12 -0800561 classpath classpath
562 bootClasspath classpath
Colin Cross6a77c982018-06-19 22:43:34 -0700563 processorPath classpath
Colin Crossbe9cdb82019-01-21 21:37:16 -0800564 processorClasses []string
Colin Cross6ade34f2017-09-15 13:00:47 -0700565 staticJars android.Paths
Nan Zhanged19fc32017-10-19 13:06:22 -0700566 staticHeaderJars android.Paths
Colin Cross331a1212018-08-15 20:40:52 -0700567 staticResourceJars android.Paths
Colin Cross6ade34f2017-09-15 13:00:47 -0700568 aidlIncludeDirs android.Paths
Nan Zhangb2b33de2018-02-23 11:18:47 -0800569 srcs android.Paths
Colin Cross59149b62017-10-16 18:07:29 -0700570 srcJars android.Paths
Colin Cross1369cdb2017-09-29 17:58:17 -0700571 systemModules android.Path
Colin Cross6ade34f2017-09-15 13:00:47 -0700572 aidlPreprocess android.OptionalPath
Colin Cross93e85952017-08-15 13:34:18 -0700573 kotlinStdlib android.Paths
Colin Crossafbb1732019-01-17 15:42:52 -0800574 kotlinAnnotations android.Paths
Colin Crossbe9cdb82019-01-21 21:37:16 -0800575
576 disableTurbine bool
Colin Cross32f676a2017-09-06 13:41:06 -0700577}
Colin Cross2fe66872015-03-30 17:20:39 -0700578
Colin Cross54250902017-12-05 09:28:08 -0800579func checkProducesJars(ctx android.ModuleContext, dep android.SourceFileProducer) {
580 for _, f := range dep.Srcs() {
581 if f.Ext() != ".jar" {
582 ctx.ModuleErrorf("genrule %q must generate files ending with .jar to be used as a libs or static_libs dependency",
583 ctx.OtherModuleName(dep.(blueprint.Module)))
584 }
585 }
586}
587
Jiyong Park2d492942018-03-05 17:44:10 +0900588type linkType int
589
590const (
591 javaCore linkType = iota
592 javaSdk
593 javaSystem
594 javaPlatform
595)
596
Jiyong Park46f78fb2018-10-20 16:33:17 +0900597func getLinkType(m *Module, name string) (ret linkType, stubs bool) {
Colin Cross83bb3162018-06-25 15:48:06 -0700598 ver := m.sdkVersion()
Colin Crossf19b9bb2018-03-26 14:42:44 -0700599 switch {
Jiyong Park46f78fb2018-10-20 16:33:17 +0900600 case name == "core.current.stubs" || name == "core.platform.api.stubs" ||
601 name == "stub-annotations" || name == "private-stub-annotations-jar" ||
602 name == "core-lambda-stubs":
603 return javaCore, true
Neil Fuller401eeba2018-10-18 19:48:58 +0100604 case ver == "core_current":
Jiyong Park46f78fb2018-10-20 16:33:17 +0900605 return javaCore, false
606 case name == "android_system_stubs_current":
607 return javaSystem, true
608 case strings.HasPrefix(ver, "system_"):
609 return javaSystem, false
610 case name == "android_test_stubs_current":
611 return javaSystem, true
612 case strings.HasPrefix(ver, "test_"):
613 return javaPlatform, false
614 case name == "android_stubs_current":
615 return javaSdk, true
616 case ver == "current":
617 return javaSdk, false
Colin Crossf19b9bb2018-03-26 14:42:44 -0700618 case ver == "":
Jiyong Park46f78fb2018-10-20 16:33:17 +0900619 return javaPlatform, false
Colin Crossf19b9bb2018-03-26 14:42:44 -0700620 default:
621 if _, err := strconv.Atoi(ver); err != nil {
622 panic(fmt.Errorf("expected sdk_version to be a number, got %q", ver))
623 }
Jiyong Park46f78fb2018-10-20 16:33:17 +0900624 return javaSdk, false
Jiyong Park2d492942018-03-05 17:44:10 +0900625 }
626}
627
Jiyong Park750e5572018-01-31 00:20:13 +0900628func checkLinkType(ctx android.ModuleContext, from *Module, to *Library, tag dependencyTag) {
Colin Crossf19b9bb2018-03-26 14:42:44 -0700629 if ctx.Host() {
630 return
631 }
632
Jiyong Park46f78fb2018-10-20 16:33:17 +0900633 myLinkType, stubs := getLinkType(from, ctx.ModuleName())
634 if stubs {
635 return
636 }
637 otherLinkType, _ := getLinkType(&to.Module, ctx.OtherModuleName(to))
Jiyong Park2d492942018-03-05 17:44:10 +0900638 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."
639
640 switch myLinkType {
641 case javaCore:
642 if otherLinkType != javaCore {
643 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 +0900644 ctx.OtherModuleName(to))
645 }
Jiyong Park2d492942018-03-05 17:44:10 +0900646 break
647 case javaSdk:
648 if otherLinkType != javaCore && otherLinkType != javaSdk {
649 ctx.ModuleErrorf("compiles against Android API, but dependency %q is compiling against non-public Android API."+commonMessage,
650 ctx.OtherModuleName(to))
651 }
652 break
653 case javaSystem:
654 if otherLinkType == javaPlatform {
655 ctx.ModuleErrorf("compiles against system API, but dependency %q is compiling against private API."+commonMessage,
656 ctx.OtherModuleName(to))
657 }
658 break
659 case javaPlatform:
660 // no restriction on link-type
661 break
Jiyong Park750e5572018-01-31 00:20:13 +0900662 }
663}
664
Colin Cross32f676a2017-09-06 13:41:06 -0700665func (j *Module) collectDeps(ctx android.ModuleContext) deps {
666 var deps deps
Colin Crossfc3674a2017-09-18 17:41:52 -0700667
Colin Cross300f0382018-03-06 13:11:51 -0800668 if ctx.Device() {
Colin Cross83bb3162018-06-25 15:48:06 -0700669 sdkDep := decodeSdkDep(ctx, sdkContext(j))
Colin Cross300f0382018-03-06 13:11:51 -0800670 if sdkDep.invalidVersion {
Colin Cross86a60ae2018-05-29 14:44:55 -0700671 ctx.AddMissingDependencies(sdkDep.modules)
Colin Cross300f0382018-03-06 13:11:51 -0800672 } else if sdkDep.useFiles {
673 // sdkDep.jar is actually equivalent to turbine header.jar.
Colin Cross86a60ae2018-05-29 14:44:55 -0700674 deps.classpath = append(deps.classpath, sdkDep.jars...)
Colin Cross300f0382018-03-06 13:11:51 -0800675 deps.aidlIncludeDirs = append(deps.aidlIncludeDirs, sdkDep.aidl)
676 }
Colin Crossfc3674a2017-09-18 17:41:52 -0700677 }
678
Colin Crossd11fcda2017-10-23 17:59:01 -0700679 ctx.VisitDirectDeps(func(module android.Module) {
Colin Cross2fe66872015-03-30 17:20:39 -0700680 otherName := ctx.OtherModuleName(module)
Colin Crossec7a0422017-07-07 14:47:12 -0700681 tag := ctx.OtherModuleDependencyTag(module)
682
Colin Crossa4f08812018-10-02 22:03:40 -0700683 if _, ok := tag.(*jniDependencyTag); ok {
Colin Crossbd01e2a2018-10-04 15:21:03 -0700684 // Handled by AndroidApp.collectAppDeps
685 return
686 }
687 if tag == certificateTag {
688 // Handled by AndroidApp.collectAppDeps
Colin Crossa4f08812018-10-02 22:03:40 -0700689 return
690 }
691
Jiyong Park750e5572018-01-31 00:20:13 +0900692 if to, ok := module.(*Library); ok {
Colin Crossa97c5d32018-03-28 14:58:31 -0700693 switch tag {
694 case bootClasspathTag, libTag, staticLibTag:
695 checkLinkType(ctx, j, to, tag.(dependencyTag))
696 }
Jiyong Park750e5572018-01-31 00:20:13 +0900697 }
Colin Cross54250902017-12-05 09:28:08 -0800698 switch dep := module.(type) {
Colin Cross897d2ed2019-02-11 14:03:51 -0800699 case SdkLibraryDependency:
700 switch tag {
701 case libTag:
702 deps.classpath = append(deps.classpath, dep.SdkHeaderJars(ctx, j.sdkVersion())...)
703 // names of sdk libs that are directly depended are exported
704 j.exportedSdkLibs = append(j.exportedSdkLibs, otherName)
705 default:
706 ctx.ModuleErrorf("dependency on java_sdk_library %q can only be in libs", otherName)
707 }
Colin Cross54250902017-12-05 09:28:08 -0800708 case Dependency:
709 switch tag {
710 case bootClasspathTag:
711 deps.bootClasspath = append(deps.bootClasspath, dep.HeaderJars()...)
Colin Cross4b964c02018-10-15 16:18:06 -0700712 case libTag, instrumentationForTag:
Colin Cross54250902017-12-05 09:28:08 -0800713 deps.classpath = append(deps.classpath, dep.HeaderJars()...)
Jiyong Park1be96912018-05-28 18:02:19 +0900714 // sdk lib names from dependencies are re-exported
715 j.exportedSdkLibs = append(j.exportedSdkLibs, dep.ExportedSdkLibs()...)
Colin Cross54250902017-12-05 09:28:08 -0800716 case staticLibTag:
717 deps.classpath = append(deps.classpath, dep.HeaderJars()...)
718 deps.staticJars = append(deps.staticJars, dep.ImplementationJars()...)
719 deps.staticHeaderJars = append(deps.staticHeaderJars, dep.HeaderJars()...)
Colin Cross331a1212018-08-15 20:40:52 -0700720 deps.staticResourceJars = append(deps.staticResourceJars, dep.ResourceJars()...)
Jiyong Park1be96912018-05-28 18:02:19 +0900721 // sdk lib names from dependencies are re-exported
722 j.exportedSdkLibs = append(j.exportedSdkLibs, dep.ExportedSdkLibs()...)
Colin Crossbe9cdb82019-01-21 21:37:16 -0800723 case pluginTag:
724 if plugin, ok := dep.(*Plugin); ok {
725 deps.processorPath = append(deps.processorPath, dep.ImplementationAndResourcesJars()...)
726 if plugin.pluginProperties.Processor_class != nil {
727 deps.processorClasses = append(deps.processorClasses, *plugin.pluginProperties.Processor_class)
728 }
729 deps.disableTurbine = deps.disableTurbine || Bool(plugin.pluginProperties.Generates_api)
730 } else {
731 ctx.PropertyErrorf("plugins", "%q is not a java_plugin module", otherName)
732 }
Colin Cross54250902017-12-05 09:28:08 -0800733 case frameworkResTag:
Mathew Inwoodebe29ce2018-09-04 14:26:19 +0100734 if (ctx.ModuleName() == "framework") || (ctx.ModuleName() == "framework-annotation-proc") {
Colin Cross54250902017-12-05 09:28:08 -0800735 // framework.jar has a one-off dependency on the R.java and Manifest.java files
736 // generated by framework-res.apk
737 deps.srcJars = append(deps.srcJars, dep.(*AndroidApp).aaptSrcJar)
738 }
Nan Zhangb2b33de2018-02-23 11:18:47 -0800739 case frameworkApkTag:
740 if ctx.ModuleName() == "android_stubs_current" ||
741 ctx.ModuleName() == "android_system_stubs_current" ||
Nan Zhang863f05b2018-08-07 13:41:10 -0700742 ctx.ModuleName() == "android_test_stubs_current" {
Nan Zhangb2b33de2018-02-23 11:18:47 -0800743 // framework stubs.jar need to depend on framework-res.apk, in order to pull the
744 // resource files out of there for aapt.
745 //
746 // Normally the package rule runs aapt, which includes the resource,
747 // but we're not running that in our package rule so just copy in the
748 // resource files here.
Colin Cross331a1212018-08-15 20:40:52 -0700749 deps.staticResourceJars = append(deps.staticResourceJars, dep.(*AndroidApp).exportPackage)
Nan Zhangb2b33de2018-02-23 11:18:47 -0800750 }
Colin Cross54250902017-12-05 09:28:08 -0800751 case kotlinStdlibTag:
752 deps.kotlinStdlib = dep.HeaderJars()
Colin Crossafbb1732019-01-17 15:42:52 -0800753 case kotlinAnnotationsTag:
754 deps.kotlinAnnotations = dep.HeaderJars()
Colin Cross54250902017-12-05 09:28:08 -0800755 }
756
757 deps.aidlIncludeDirs = append(deps.aidlIncludeDirs, dep.AidlIncludeDirs()...)
758 case android.SourceFileProducer:
759 switch tag {
760 case libTag:
761 checkProducesJars(ctx, dep)
762 deps.classpath = append(deps.classpath, dep.Srcs()...)
763 case staticLibTag:
764 checkProducesJars(ctx, dep)
765 deps.classpath = append(deps.classpath, dep.Srcs()...)
766 deps.staticJars = append(deps.staticJars, dep.Srcs()...)
767 deps.staticHeaderJars = append(deps.staticHeaderJars, dep.Srcs()...)
768 case android.DefaultsDepTag, android.SourceDepTag:
769 // Nothing to do
Sundong Ahn054b19a2018-10-19 13:46:09 +0900770 case publicApiFileTag, systemApiFileTag, testApiFileTag:
771 // Nothing to do
Colin Cross54250902017-12-05 09:28:08 -0800772 default:
773 ctx.ModuleErrorf("dependency on genrule %q may only be in srcs, libs, or static_libs", otherName)
774 }
775 default:
Colin Crossec7a0422017-07-07 14:47:12 -0700776 switch tag {
777 case android.DefaultsDepTag, android.SourceDepTag:
Dan Willemsend6ba0d52017-09-13 15:46:47 -0700778 // Nothing to do
Colin Cross1369cdb2017-09-29 17:58:17 -0700779 case systemModulesTag:
780 if deps.systemModules != nil {
781 panic("Found two system module dependencies")
782 }
783 sm := module.(*SystemModules)
784 if sm.outputFile == nil {
785 panic("Missing directory for system module dependency")
786 }
787 deps.systemModules = sm.outputFile
Colin Crossec7a0422017-07-07 14:47:12 -0700788 default:
789 ctx.ModuleErrorf("depends on non-java module %q", otherName)
Colin Cross2fe66872015-03-30 17:20:39 -0700790 }
Colin Crossec7a0422017-07-07 14:47:12 -0700791 }
Colin Cross2fe66872015-03-30 17:20:39 -0700792 })
793
Jiyong Park1be96912018-05-28 18:02:19 +0900794 j.exportedSdkLibs = android.FirstUniqueStrings(j.exportedSdkLibs)
795
Colin Cross32f676a2017-09-06 13:41:06 -0700796 return deps
Colin Cross2fe66872015-03-30 17:20:39 -0700797}
798
Colin Cross83bb3162018-06-25 15:48:06 -0700799func getJavaVersion(ctx android.ModuleContext, javaVersion string, sdkContext sdkContext) string {
Nan Zhang357466b2018-04-17 17:38:36 -0700800 var ret string
Colin Cross98fd5742019-01-09 23:04:25 -0800801 v := sdkContext.sdkVersion()
802 // For PDK builds, use the latest SDK version instead of "current"
803 if ctx.Config().IsPdkBuild() && (v == "" || v == "current") {
804 sdkVersions := ctx.Config().Get(sdkSingletonKey).([]int)
805 latestSdkVersion := 0
806 if len(sdkVersions) > 0 {
807 latestSdkVersion = sdkVersions[len(sdkVersions)-1]
808 }
809 v = strconv.Itoa(latestSdkVersion)
810 }
811
812 sdk, err := sdkVersionToNumber(ctx, v)
Colin Cross83bb3162018-06-25 15:48:06 -0700813 if err != nil {
814 ctx.PropertyErrorf("sdk_version", "%s", err)
815 }
Nan Zhang357466b2018-04-17 17:38:36 -0700816 if javaVersion != "" {
817 ret = javaVersion
818 } else if ctx.Device() && sdk <= 23 {
819 ret = "1.7"
Jiyong Park4584a8a2018-10-03 18:05:04 +0900820 } else if ctx.Device() && sdk <= 28 || !ctx.Config().TargetOpenJDK9() {
Nan Zhang357466b2018-04-17 17:38:36 -0700821 ret = "1.8"
Colin Cross83bb3162018-06-25 15:48:06 -0700822 } else if ctx.Device() && sdkContext.sdkVersion() != "" && sdk == android.FutureApiLevel {
Nan Zhang357466b2018-04-17 17:38:36 -0700823 // TODO(ccross): once we generate stubs we should be able to use 1.9 for sdk_version: "current"
824 ret = "1.8"
825 } else {
826 ret = "1.9"
827 }
828
829 return ret
830}
831
Nan Zhanged19fc32017-10-19 13:06:22 -0700832func (j *Module) collectBuilderFlags(ctx android.ModuleContext, deps deps) javaBuilderFlags {
Colin Crossc0b06f12015-04-08 13:03:43 -0700833
Colin Crossf03c82b2015-04-13 13:53:40 -0700834 var flags javaBuilderFlags
835
Tobias Thierer06dd04f2018-09-11 16:21:05 +0100836 // javaVersion flag.
837 flags.javaVersion = getJavaVersion(ctx, String(j.properties.Java_version), sdkContext(j))
838
Nan Zhanged19fc32017-10-19 13:06:22 -0700839 // javac flags.
Colin Crossf03c82b2015-04-13 13:53:40 -0700840 javacFlags := j.properties.Javacflags
Tobias Thierer06dd04f2018-09-11 16:21:05 +0100841 if flags.javaVersion == "1.9" {
Colin Cross1369cdb2017-09-29 17:58:17 -0700842 javacFlags = append(javacFlags, j.properties.Openjdk9.Javacflags...)
Nan Zhanged19fc32017-10-19 13:06:22 -0700843 }
Colin Cross6510f912017-11-29 00:27:14 -0800844 if ctx.Config().MinimizeJavaDebugInfo() {
Colin Cross126a25c2017-10-31 13:55:34 -0700845 // Override the -g flag passed globally to remove local variable debug info to reduce
846 // disk and memory usage.
847 javacFlags = append(javacFlags, "-g:source,lines")
848 }
Colin Cross64162712017-08-08 13:17:59 -0700849
Colin Cross66548102018-06-19 22:47:35 -0700850 if ctx.Config().RunErrorProne() {
851 if config.ErrorProneClasspath == nil {
852 ctx.ModuleErrorf("cannot build with Error Prone, missing external/error_prone?")
853 }
854
855 errorProneFlags := []string{
856 "-Xplugin:ErrorProne",
857 "${config.ErrorProneChecks}",
858 }
859 errorProneFlags = append(errorProneFlags, j.properties.Errorprone.Javacflags...)
860
861 flags.errorProneExtraJavacFlags = "${config.ErrorProneFlags} " +
862 "'" + strings.Join(errorProneFlags, " ") + "'"
863 flags.errorProneProcessorPath = classpath(android.PathsForSource(ctx, config.ErrorProneClasspath))
Andreas Gampef3e5b552018-01-22 21:27:21 -0800864 }
865
Nan Zhanged19fc32017-10-19 13:06:22 -0700866 // classpath
Nan Zhang581fd212018-01-10 16:06:12 -0800867 flags.bootClasspath = append(flags.bootClasspath, deps.bootClasspath...)
868 flags.classpath = append(flags.classpath, deps.classpath...)
Colin Cross6a77c982018-06-19 22:43:34 -0700869 flags.processorPath = append(flags.processorPath, deps.processorPath...)
Colin Cross7fdd2b72018-01-02 18:14:25 -0800870
Colin Crossbe9cdb82019-01-21 21:37:16 -0800871 flags.processor = strings.Join(deps.processorClasses, ",")
872
Tobias Thierer06dd04f2018-09-11 16:21:05 +0100873 if len(flags.bootClasspath) == 0 && ctx.Host() && flags.javaVersion != "1.9" &&
Colin Cross7fdd2b72018-01-02 18:14:25 -0800874 !Bool(j.properties.No_standard_libs) &&
875 inList(flags.javaVersion, []string{"1.6", "1.7", "1.8"}) {
876 // Give host-side tools a version of OpenJDK's standard libraries
877 // close to what they're targeting. As of Dec 2017, AOSP is only
878 // bundling OpenJDK 8 and 9, so nothing < 8 is available.
879 //
880 // When building with OpenJDK 8, the following should have no
881 // effect since those jars would be available by default.
882 //
883 // When building with OpenJDK 9 but targeting a version < 1.8,
884 // putting them on the bootclasspath means that:
885 // a) code can't (accidentally) refer to OpenJDK 9 specific APIs
886 // b) references to existing APIs are not reinterpreted in an
887 // OpenJDK 9-specific way, eg. calls to subclasses of
888 // java.nio.Buffer as in http://b/70862583
889 java8Home := ctx.Config().Getenv("ANDROID_JAVA8_HOME")
890 flags.bootClasspath = append(flags.bootClasspath,
891 android.PathForSource(ctx, java8Home, "jre/lib/jce.jar"),
892 android.PathForSource(ctx, java8Home, "jre/lib/rt.jar"))
Nan Zhang5f8cb422018-02-06 10:34:32 -0800893 if Bool(j.properties.Use_tools_jar) {
894 flags.bootClasspath = append(flags.bootClasspath,
895 android.PathForSource(ctx, java8Home, "lib/tools.jar"))
896 }
Colin Cross7fdd2b72018-01-02 18:14:25 -0800897 }
898
Tobias Thierer06dd04f2018-09-11 16:21:05 +0100899 if j.properties.Patch_module != nil && flags.javaVersion == "1.9" {
Jaewoong Jung38e4fb22018-12-12 09:01:34 -0800900 // Manually specify build directory in case it is not under the repo root.
901 // (javac doesn't seem to expand into symbolc links when searching for patch-module targets, so
902 // just adding a symlink under the root doesn't help.)
903 patchPaths := ".:" + ctx.Config().BuildDir()
904 classPath := flags.classpath.FormJavaClassPath("")
905 if classPath != "" {
906 patchPaths += ":" + classPath
907 }
908 javacFlags = append(javacFlags, "--patch-module="+String(j.properties.Patch_module)+"="+patchPaths)
Colin Cross81440082018-08-15 20:21:55 -0700909 }
910
Nan Zhanged19fc32017-10-19 13:06:22 -0700911 // systemModules
Colin Cross1369cdb2017-09-29 17:58:17 -0700912 if deps.systemModules != nil {
913 flags.systemModules = append(flags.systemModules, deps.systemModules)
914 }
915
Nan Zhanged19fc32017-10-19 13:06:22 -0700916 // aidl flags.
Colin Cross32f676a2017-09-06 13:41:06 -0700917 aidlFlags := j.aidlFlags(ctx, deps.aidlPreprocess, deps.aidlIncludeDirs)
Colin Crossf03c82b2015-04-13 13:53:40 -0700918 if len(aidlFlags) > 0 {
Nan Zhanged19fc32017-10-19 13:06:22 -0700919 // optimization.
Colin Crossf03c82b2015-04-13 13:53:40 -0700920 ctx.Variable(pctx, "aidlFlags", strings.Join(aidlFlags, " "))
921 flags.aidlFlags = "$aidlFlags"
Colin Cross2fe66872015-03-30 17:20:39 -0700922 }
923
Colin Cross81440082018-08-15 20:21:55 -0700924 if len(javacFlags) > 0 {
925 // optimization.
926 ctx.Variable(pctx, "javacFlags", strings.Join(javacFlags, " "))
927 flags.javacFlags = "$javacFlags"
928 }
929
Nan Zhanged19fc32017-10-19 13:06:22 -0700930 return flags
931}
Colin Crossc0b06f12015-04-08 13:03:43 -0700932
Colin Cross3bc7ffa2017-11-22 16:19:37 -0800933func (j *Module) compile(ctx android.ModuleContext, extraSrcJars ...android.Path) {
Nan Zhanged19fc32017-10-19 13:06:22 -0700934
Colin Crossebe1a512017-11-14 13:12:14 -0800935 j.exportAidlIncludeDirs = android.PathsForModuleSrc(ctx, j.deviceProperties.Aidl.Export_include_dirs)
Nan Zhanged19fc32017-10-19 13:06:22 -0700936
937 deps := j.collectDeps(ctx)
938 flags := j.collectBuilderFlags(ctx, deps)
939
Tobias Thierer06dd04f2018-09-11 16:21:05 +0100940 if flags.javaVersion == "1.9" {
Nan Zhanged19fc32017-10-19 13:06:22 -0700941 j.properties.Srcs = append(j.properties.Srcs, j.properties.Openjdk9.Srcs...)
942 }
943 srcFiles := ctx.ExpandSources(j.properties.Srcs, j.properties.Exclude_srcs)
Colin Cross6af17aa2017-09-20 12:59:05 -0700944 if hasSrcExt(srcFiles.Strings(), ".proto") {
Colin Cross0f2ee152017-12-14 15:22:43 -0800945 flags = protoFlags(ctx, &j.properties, &j.protoProperties, flags)
Colin Cross6af17aa2017-09-20 12:59:05 -0700946 }
947
Colin Crossaf050172017-11-15 23:01:59 -0800948 srcFiles = j.genSources(ctx, srcFiles, flags)
949
950 srcJars := srcFiles.FilterByExt(".srcjar")
Colin Cross59149b62017-10-16 18:07:29 -0700951 srcJars = append(srcJars, deps.srcJars...)
Colin Cross3bc7ffa2017-11-22 16:19:37 -0800952 srcJars = append(srcJars, extraSrcJars...)
Colin Crossb7a63242015-04-16 14:09:14 -0700953
Brandon Lee5d45c6f2018-08-15 15:35:38 -0700954 // Collect source files from compiledJavaSrcs, compiledSrcJars and filter out Exclude_srcs
955 // that IDEInfo struct will use
956 j.expandIDEInfoCompiledSrcs = append(j.expandIDEInfoCompiledSrcs, srcFiles.Strings()...)
957
Steven Morelandc4efd9c2019-01-18 11:51:25 -0800958 if j.properties.Jarjar_rules != nil {
959 j.expandJarjarRules = ctx.ExpandSource(*j.properties.Jarjar_rules, "jarjar_rules")
960 }
961
Colin Cross1ee23172017-10-18 14:44:18 -0700962 jarName := ctx.ModuleName() + ".jar"
963
Przemyslaw Szczepaniak4b5fe9d2018-02-13 14:32:54 +0000964 javaSrcFiles := srcFiles.FilterByExt(".java")
965 var uniqueSrcFiles android.Paths
966 set := make(map[string]bool)
967 for _, v := range javaSrcFiles {
968 if _, found := set[v.String()]; !found {
969 set[v.String()] = true
970 uniqueSrcFiles = append(uniqueSrcFiles, v)
971 }
972 }
973
Colin Cross55f63ea2018-08-27 12:37:09 -0700974 var kotlinJars android.Paths
975
Colin Cross93e85952017-08-15 13:34:18 -0700976 if srcFiles.HasExt(".kt") {
Zoran Jovanovic8736ce22018-08-21 17:10:29 +0200977 // user defined kotlin flags.
978 kotlincFlags := j.properties.Kotlincflags
979 CheckKotlincFlags(ctx, kotlincFlags)
980
Colin Cross93e85952017-08-15 13:34:18 -0700981 // If there are kotlin files, compile them first but pass all the kotlin and java files
982 // kotlinc will use the java files to resolve types referenced by the kotlin files, but
983 // won't emit any classes for them.
Zoran Jovanovic8736ce22018-08-21 17:10:29 +0200984 kotlincFlags = append(kotlincFlags, "-no-stdlib")
Colin Cross93e85952017-08-15 13:34:18 -0700985 if ctx.Device() {
Zoran Jovanovic8736ce22018-08-21 17:10:29 +0200986 kotlincFlags = append(kotlincFlags, "-no-jdk")
987 }
988 if len(kotlincFlags) > 0 {
989 // optimization.
990 ctx.Variable(pctx, "kotlincFlags", strings.Join(kotlincFlags, " "))
991 flags.kotlincFlags += "$kotlincFlags"
Colin Cross93e85952017-08-15 13:34:18 -0700992 }
993
Przemyslaw Szczepaniak4b5fe9d2018-02-13 14:32:54 +0000994 var kotlinSrcFiles android.Paths
995 kotlinSrcFiles = append(kotlinSrcFiles, uniqueSrcFiles...)
996 kotlinSrcFiles = append(kotlinSrcFiles, srcFiles.FilterByExt(".kt")...)
997
Colin Crossafbb1732019-01-17 15:42:52 -0800998 flags.classpath = append(flags.classpath, deps.kotlinStdlib...)
999 flags.classpath = append(flags.classpath, deps.kotlinAnnotations...)
1000
1001 flags.kotlincClasspath = append(flags.kotlincClasspath, flags.bootClasspath...)
1002 flags.kotlincClasspath = append(flags.kotlincClasspath, flags.classpath...)
1003
1004 if len(flags.processorPath) > 0 {
1005 // Use kapt for annotation processing
1006 kaptSrcJar := android.PathForModuleOut(ctx, "kapt", "kapt-sources.jar")
1007 kotlinKapt(ctx, kaptSrcJar, kotlinSrcFiles, srcJars, flags)
1008 srcJars = append(srcJars, kaptSrcJar)
1009 // Disable annotation processing in javac, it's already been handled by kapt
1010 flags.processorPath = nil
Colin Cross3a3e94c2019-01-23 15:39:50 -08001011 flags.processor = ""
Colin Crossafbb1732019-01-17 15:42:52 -08001012 }
Colin Cross93e85952017-08-15 13:34:18 -07001013
Colin Cross1ee23172017-10-18 14:44:18 -07001014 kotlinJar := android.PathForModuleOut(ctx, "kotlin", jarName)
Colin Cross21fc9bb2019-01-18 15:05:09 -08001015 kotlinCompile(ctx, kotlinJar, kotlinSrcFiles, srcJars, flags)
Colin Cross93e85952017-08-15 13:34:18 -07001016 if ctx.Failed() {
1017 return
1018 }
1019
1020 // Make javac rule depend on the kotlinc rule
1021 flags.classpath = append(flags.classpath, kotlinJar)
Przemyslaw Szczepaniak66c0c402018-03-08 13:21:55 +00001022
Colin Cross93e85952017-08-15 13:34:18 -07001023 // Jar kotlin classes into the final jar after javac
Colin Cross55f63ea2018-08-27 12:37:09 -07001024 kotlinJars = append(kotlinJars, kotlinJar)
Colin Cross9b38aef2018-08-27 15:42:25 -07001025 kotlinJars = append(kotlinJars, deps.kotlinStdlib...)
Colin Cross93e85952017-08-15 13:34:18 -07001026 }
1027
Colin Cross55f63ea2018-08-27 12:37:09 -07001028 jars := append(android.Paths(nil), kotlinJars...)
1029
Colin Cross5ab4e6d2017-11-22 16:20:45 -08001030 // Store the list of .java files that was passed to javac
1031 j.compiledJavaSrcs = uniqueSrcFiles
1032 j.compiledSrcJars = srcJars
1033
Nan Zhang61eaedb2017-11-02 13:28:15 -07001034 enable_sharding := false
Colin Crossbe9cdb82019-01-21 21:37:16 -08001035 if ctx.Device() && !ctx.Config().IsEnvFalse("TURBINE_ENABLED") && !deps.disableTurbine {
Nan Zhang61eaedb2017-11-02 13:28:15 -07001036 if j.properties.Javac_shard_size != nil && *(j.properties.Javac_shard_size) > 0 {
1037 enable_sharding = true
Ashley Rosee36efcf2019-01-16 17:34:08 -05001038 // Formerly, there was a check here that prevented annotation processors
1039 // from being used when sharding was enabled, as some annotation processors
1040 // do not function correctly in sharded environments. It was removed to
1041 // allow for the use of annotation processors that do function correctly
1042 // with sharding enabled. See: b/77284273.
Nan Zhang61eaedb2017-11-02 13:28:15 -07001043 }
Colin Cross55f63ea2018-08-27 12:37:09 -07001044 j.headerJarFile = j.compileJavaHeader(ctx, uniqueSrcFiles, srcJars, deps, flags, jarName, kotlinJars)
Colin Crossf19b9bb2018-03-26 14:42:44 -07001045 if ctx.Failed() {
1046 return
Nan Zhanged19fc32017-10-19 13:06:22 -07001047 }
1048 }
Colin Cross8eadbf02017-10-24 17:46:00 -07001049 if len(uniqueSrcFiles) > 0 || len(srcJars) > 0 {
Colin Crossd6891432017-09-27 17:39:56 -07001050 var extraJarDeps android.Paths
Colin Cross66548102018-06-19 22:47:35 -07001051 if ctx.Config().RunErrorProne() {
Colin Crossc6bbef32017-08-14 14:16:06 -07001052 // If error-prone is enabled, add an additional rule to compile the java files into
1053 // a separate set of classes (so that they don't overwrite the normal ones and require
Colin Crossd6891432017-09-27 17:39:56 -07001054 // a rebuild when error-prone is turned off).
Colin Crossc6bbef32017-08-14 14:16:06 -07001055 // TODO(ccross): Once we always compile with javac9 we may be able to conditionally
1056 // enable error-prone without affecting the output class files.
Colin Cross1ee23172017-10-18 14:44:18 -07001057 errorprone := android.PathForModuleOut(ctx, "errorprone", jarName)
Nan Zhang61eaedb2017-11-02 13:28:15 -07001058 RunErrorProne(ctx, errorprone, uniqueSrcFiles, srcJars, flags)
Colin Crossc6bbef32017-08-14 14:16:06 -07001059 extraJarDeps = append(extraJarDeps, errorprone)
1060 }
1061
Nan Zhang61eaedb2017-11-02 13:28:15 -07001062 if enable_sharding {
Nan Zhang581fd212018-01-10 16:06:12 -08001063 flags.classpath = append(flags.classpath, j.headerJarFile)
Nan Zhang61eaedb2017-11-02 13:28:15 -07001064 shardSize := int(*(j.properties.Javac_shard_size))
1065 var shardSrcs []android.Paths
1066 if len(uniqueSrcFiles) > 0 {
1067 shardSrcs = shardPaths(uniqueSrcFiles, shardSize)
1068 for idx, shardSrc := range shardSrcs {
1069 classes := android.PathForModuleOut(ctx, "javac", jarName+strconv.Itoa(idx))
1070 TransformJavaToClasses(ctx, classes, idx, shardSrc, nil, flags, extraJarDeps)
1071 jars = append(jars, classes)
1072 }
1073 }
1074 if len(srcJars) > 0 {
1075 classes := android.PathForModuleOut(ctx, "javac", jarName+strconv.Itoa(len(shardSrcs)))
1076 TransformJavaToClasses(ctx, classes, len(shardSrcs), nil, srcJars, flags, extraJarDeps)
1077 jars = append(jars, classes)
1078 }
1079 } else {
1080 classes := android.PathForModuleOut(ctx, "javac", jarName)
1081 TransformJavaToClasses(ctx, classes, -1, uniqueSrcFiles, srcJars, flags, extraJarDeps)
1082 jars = append(jars, classes)
1083 }
Colin Crossd6891432017-09-27 17:39:56 -07001084 if ctx.Failed() {
1085 return
1086 }
Colin Cross2fe66872015-03-30 17:20:39 -07001087 }
1088
Colin Crosscedd4762018-09-13 11:26:19 -07001089 dirArgs, dirDeps := ResourceDirsToJarArgs(ctx, j.properties.Java_resource_dirs,
1090 j.properties.Exclude_java_resource_dirs, j.properties.Exclude_java_resources)
Colin Cross0f37af02017-09-27 17:42:05 -07001091 fileArgs, fileDeps := ResourceFilesToJarArgs(ctx, j.properties.Java_resources, j.properties.Exclude_java_resources)
1092
1093 var resArgs []string
1094 var resDeps android.Paths
1095
1096 resArgs = append(resArgs, dirArgs...)
1097 resDeps = append(resDeps, dirDeps...)
1098
1099 resArgs = append(resArgs, fileArgs...)
1100 resDeps = append(resDeps, fileDeps...)
1101
Colin Crossff3ae9d2018-04-10 16:15:18 -07001102 if Bool(j.properties.Include_srcs) {
Colin Cross23729232017-10-03 13:14:07 -07001103 srcArgs, srcDeps := SourceFilesToJarArgs(ctx, j.properties.Srcs, j.properties.Exclude_srcs)
Colin Cross0f37af02017-09-27 17:42:05 -07001104 resArgs = append(resArgs, srcArgs...)
1105 resDeps = append(resDeps, srcDeps...)
1106 }
Colin Cross40a36712017-09-27 17:41:35 -07001107
1108 if len(resArgs) > 0 {
Colin Cross1ee23172017-10-18 14:44:18 -07001109 resourceJar := android.PathForModuleOut(ctx, "res", jarName)
Colin Crosse9a275b2017-10-16 17:09:48 -07001110 TransformResourcesToJar(ctx, resourceJar, resArgs, resDeps)
Colin Cross331a1212018-08-15 20:40:52 -07001111 j.resourceJar = resourceJar
Colin Cross65bf4f22015-04-03 16:54:17 -07001112 if ctx.Failed() {
1113 return
1114 }
1115 }
1116
Colin Cross331a1212018-08-15 20:40:52 -07001117 if len(deps.staticResourceJars) > 0 {
1118 var jars android.Paths
1119 if j.resourceJar != nil {
1120 jars = append(jars, j.resourceJar)
1121 }
1122 jars = append(jars, deps.staticResourceJars...)
1123
1124 combinedJar := android.PathForModuleOut(ctx, "res-combined", jarName)
1125 TransformJarsToJar(ctx, combinedJar, "for resources", jars, android.OptionalPath{},
1126 false, nil, nil)
1127 j.resourceJar = combinedJar
1128 }
1129
Colin Cross32f676a2017-09-06 13:41:06 -07001130 jars = append(jars, deps.staticJars...)
Colin Cross0a6e0072017-08-30 14:24:55 -07001131
Colin Cross094054a2018-10-17 15:10:48 -07001132 manifest := j.overrideManifest
1133 if !manifest.Valid() && j.properties.Manifest != nil {
Colin Cross366938f2017-12-11 16:29:02 -08001134 manifest = android.OptionalPathForPath(ctx.ExpandSource(*j.properties.Manifest, "manifest"))
1135 }
Colin Cross635acc92017-09-12 22:50:46 -07001136
Alex Light7f004a72019-02-21 13:27:37 -08001137 services := ctx.ExpandSources(j.properties.Services, nil)
1138 if len(services) > 0 {
1139 servicesJar := android.PathForModuleOut(ctx, "services", jarName)
1140 var zipargs []string
1141 for _, file := range services {
1142 serviceFile := file.String()
1143 zipargs = append(zipargs, "-C", filepath.Dir(serviceFile), "-f", serviceFile)
1144 }
1145 ctx.Build(pctx, android.BuildParams{
1146 Rule: zip,
1147 Output: servicesJar,
1148 Implicits: services,
1149 Args: map[string]string{
Colin Cross0b9f31f2019-02-28 11:00:01 -08001150 "jarArgs": "-P META-INF/services/ " + strings.Join(proptools.NinjaAndShellEscapeList(zipargs), " "),
Alex Light7f004a72019-02-21 13:27:37 -08001151 },
1152 })
1153 jars = append(jars, servicesJar)
1154 }
1155
Colin Cross0a6e0072017-08-30 14:24:55 -07001156 // Combine the classes built from sources, any manifests, and any static libraries into
Nan Zhanged19fc32017-10-19 13:06:22 -07001157 // classes.jar. If there is only one input jar this step will be skipped.
Colin Cross3063b782018-08-15 11:19:12 -07001158 var outputFile android.ModuleOutPath
Colin Crosse9a275b2017-10-16 17:09:48 -07001159
1160 if len(jars) == 1 && !manifest.Valid() {
Colin Cross3063b782018-08-15 11:19:12 -07001161 if moduleOutPath, ok := jars[0].(android.ModuleOutPath); ok {
1162 // Optimization: skip the combine step if there is nothing to do
1163 // TODO(ccross): this leaves any module-info.class files, but those should only come from
1164 // prebuilt dependencies until we support modules in the platform build, so there shouldn't be
1165 // any if len(jars) == 1.
1166 outputFile = moduleOutPath
1167 } else {
1168 combinedJar := android.PathForModuleOut(ctx, "combined", jarName)
1169 ctx.Build(pctx, android.BuildParams{
1170 Rule: android.Cp,
1171 Input: jars[0],
1172 Output: combinedJar,
1173 })
1174 outputFile = combinedJar
1175 }
Colin Crosse9a275b2017-10-16 17:09:48 -07001176 } else {
Colin Cross1ee23172017-10-18 14:44:18 -07001177 combinedJar := android.PathForModuleOut(ctx, "combined", jarName)
Colin Cross37f6d792018-07-12 12:28:41 -07001178 TransformJarsToJar(ctx, combinedJar, "for javac", jars, manifest,
Colin Cross9b38aef2018-08-27 15:42:25 -07001179 false, nil, nil)
Colin Crosse9a275b2017-10-16 17:09:48 -07001180 outputFile = combinedJar
1181 }
Colin Cross0a6e0072017-08-30 14:24:55 -07001182
Colin Cross331a1212018-08-15 20:40:52 -07001183 // jarjar implementation jar if necessary
Steven Morelandc4efd9c2019-01-18 11:51:25 -08001184 if j.expandJarjarRules != nil {
Colin Cross8649b262017-09-27 18:03:17 -07001185 // Transform classes.jar into classes-jarjar.jar
Colin Cross1ee23172017-10-18 14:44:18 -07001186 jarjarFile := android.PathForModuleOut(ctx, "jarjar", jarName)
Steven Morelandc4efd9c2019-01-18 11:51:25 -08001187 TransformJarJar(ctx, jarjarFile, outputFile, j.expandJarjarRules)
Colin Crosse9a275b2017-10-16 17:09:48 -07001188 outputFile = jarjarFile
Colin Cross331a1212018-08-15 20:40:52 -07001189
1190 // jarjar resource jar if necessary
1191 if j.resourceJar != nil {
1192 resourceJarJarFile := android.PathForModuleOut(ctx, "res-jarjar", jarName)
Steven Morelandc4efd9c2019-01-18 11:51:25 -08001193 TransformJarJar(ctx, resourceJarJarFile, j.resourceJar, j.expandJarjarRules)
Colin Cross331a1212018-08-15 20:40:52 -07001194 j.resourceJar = resourceJarJarFile
1195 }
1196
Colin Cross0a6e0072017-08-30 14:24:55 -07001197 if ctx.Failed() {
1198 return
1199 }
1200 }
Nan Zhanged19fc32017-10-19 13:06:22 -07001201 j.implementationJarFile = outputFile
1202 if j.headerJarFile == nil {
1203 j.headerJarFile = j.implementationJarFile
1204 }
Colin Cross2fe66872015-03-30 17:20:39 -07001205
Colin Cross6510f912017-11-29 00:27:14 -08001206 if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
Colin Crosscb933592017-11-22 13:49:43 -08001207 if inList(ctx.ModuleName(), config.InstrumentFrameworkModules) {
1208 j.properties.Instrument = true
1209 }
1210 }
1211
Colin Cross3144dfc2018-01-03 15:06:47 -08001212 if j.shouldInstrument(ctx) {
Colin Crosscb933592017-11-22 13:49:43 -08001213 outputFile = j.instrument(ctx, flags, outputFile, jarName)
1214 }
1215
Colin Cross331a1212018-08-15 20:40:52 -07001216 // merge implementation jar with resources if necessary
1217 implementationAndResourcesJar := outputFile
1218 if j.resourceJar != nil {
1219 jars := android.Paths{implementationAndResourcesJar, j.resourceJar}
1220 combinedJar := android.PathForModuleOut(ctx, "withres", jarName)
1221 TransformJarsToJar(ctx, combinedJar, "for resources", jars, android.OptionalPath{},
1222 false, nil, nil)
1223 implementationAndResourcesJar = combinedJar
1224 }
1225
1226 j.implementationAndResourcesJar = implementationAndResourcesJar
1227
Colin Cross9ae1b922018-06-26 17:59:05 -07001228 if ctx.Device() && (Bool(j.properties.Installable) || Bool(j.deviceProperties.Compile_dex)) {
Colin Cross8faf8fc2019-01-16 15:15:52 -08001229 // Dex compilation
Colin Cross3063b782018-08-15 11:19:12 -07001230 var dexOutputFile android.ModuleOutPath
David Brazdil17ef5632018-06-27 10:27:45 +01001231 dexOutputFile = j.compileDex(ctx, flags, outputFile, jarName)
Colin Cross2fe66872015-03-30 17:20:39 -07001232 if ctx.Failed() {
1233 return
1234 }
Colin Cross331a1212018-08-15 20:40:52 -07001235
Colin Cross8faf8fc2019-01-16 15:15:52 -08001236 // Hidden API CSV generation and dex encoding
Colin Crossf24a22a2019-01-31 14:12:44 -08001237 dexOutputFile = j.hiddenAPI.hiddenAPI(ctx, dexOutputFile, j.implementationJarFile,
1238 j.deviceProperties.UncompressDex)
Colin Cross8faf8fc2019-01-16 15:15:52 -08001239
Colin Cross331a1212018-08-15 20:40:52 -07001240 // merge dex jar with resources if necessary
1241 if j.resourceJar != nil {
1242 jars := android.Paths{dexOutputFile, j.resourceJar}
1243 combinedJar := android.PathForModuleOut(ctx, "dex-withres", jarName)
1244 TransformJarsToJar(ctx, combinedJar, "for dex resources", jars, android.OptionalPath{},
1245 false, nil, nil)
Nicolas Geoffrayf3438722019-01-23 15:57:21 +00001246 if j.deviceProperties.UncompressDex {
1247 combinedAlignedJar := android.PathForModuleOut(ctx, "dex-withres-aligned", jarName)
1248 TransformZipAlign(ctx, combinedAlignedJar, combinedJar)
1249 dexOutputFile = combinedAlignedJar
1250 } else {
1251 dexOutputFile = combinedJar
1252 }
Colin Cross331a1212018-08-15 20:40:52 -07001253 }
1254
1255 j.dexJarFile = dexOutputFile
1256
Colin Cross8faf8fc2019-01-16 15:15:52 -08001257 // Dexpreopting
Colin Cross43f08db2018-11-12 10:13:39 -08001258 dexOutputFile = j.dexpreopt(ctx, dexOutputFile)
1259
1260 j.maybeStrippedDexJarFile = dexOutputFile
1261
Colin Cross3063b782018-08-15 11:19:12 -07001262 outputFile = dexOutputFile
Colin Cross43f08db2018-11-12 10:13:39 -08001263
1264 if ctx.Failed() {
1265 return
1266 }
Colin Cross331a1212018-08-15 20:40:52 -07001267 } else {
1268 outputFile = implementationAndResourcesJar
Colin Cross2fe66872015-03-30 17:20:39 -07001269 }
Colin Cross331a1212018-08-15 20:40:52 -07001270
Colin Crossb7a63242015-04-16 14:09:14 -07001271 ctx.CheckbuildFile(outputFile)
Colin Cross3063b782018-08-15 11:19:12 -07001272
1273 // Save the output file with no relative path so that it doesn't end up in a subdirectory when used as a resource
1274 j.outputFile = outputFile.WithoutRel()
Colin Cross2fe66872015-03-30 17:20:39 -07001275}
1276
Zoran Jovanovic8736ce22018-08-21 17:10:29 +02001277// Check for invalid kotlinc flags. Only use this for flags explicitly passed by the user,
1278// since some of these flags may be used internally.
1279func CheckKotlincFlags(ctx android.ModuleContext, flags []string) {
1280 for _, flag := range flags {
1281 flag = strings.TrimSpace(flag)
1282
1283 if !strings.HasPrefix(flag, "-") {
1284 ctx.PropertyErrorf("kotlincflags", "Flag `%s` must start with `-`", flag)
1285 } else if strings.HasPrefix(flag, "-Xintellij-plugin-root") {
1286 ctx.PropertyErrorf("kotlincflags",
1287 "Bad flag: `%s`, only use internal compiler for consistency.", flag)
1288 } else if inList(flag, config.KotlincIllegalFlags) {
1289 ctx.PropertyErrorf("kotlincflags", "Flag `%s` already used by build system", flag)
1290 } else if flag == "-include-runtime" {
1291 ctx.PropertyErrorf("kotlincflags", "Bad flag: `%s`, do not include runtime.", flag)
1292 } else {
1293 args := strings.Split(flag, " ")
1294 if args[0] == "-kotlin-home" {
1295 ctx.PropertyErrorf("kotlincflags",
1296 "Bad flag: `%s`, kotlin home already set to default (path to kotlinc in the repo).", flag)
1297 }
1298 }
1299 }
1300}
1301
Colin Cross8eadbf02017-10-24 17:46:00 -07001302func (j *Module) compileJavaHeader(ctx android.ModuleContext, srcFiles, srcJars android.Paths,
Colin Cross55f63ea2018-08-27 12:37:09 -07001303 deps deps, flags javaBuilderFlags, jarName string, extraJars android.Paths) android.Path {
Nan Zhanged19fc32017-10-19 13:06:22 -07001304
1305 var jars android.Paths
Colin Cross8eadbf02017-10-24 17:46:00 -07001306 if len(srcFiles) > 0 || len(srcJars) > 0 {
Nan Zhanged19fc32017-10-19 13:06:22 -07001307 // Compile java sources into turbine.jar.
1308 turbineJar := android.PathForModuleOut(ctx, "turbine", jarName)
1309 TransformJavaToHeaderClasses(ctx, turbineJar, srcFiles, srcJars, flags)
1310 if ctx.Failed() {
1311 return nil
1312 }
1313 jars = append(jars, turbineJar)
1314 }
1315
Colin Cross55f63ea2018-08-27 12:37:09 -07001316 jars = append(jars, extraJars...)
1317
Nan Zhanged19fc32017-10-19 13:06:22 -07001318 // Combine any static header libraries into classes-header.jar. If there is only
1319 // one input jar this step will be skipped.
1320 var headerJar android.Path
1321 jars = append(jars, deps.staticHeaderJars...)
1322
Colin Cross5c6ecc12017-10-23 18:12:27 -07001323 // we cannot skip the combine step for now if there is only one jar
1324 // since we have to strip META-INF/TRANSITIVE dir from turbine.jar
1325 combinedJar := android.PathForModuleOut(ctx, "turbine-combined", jarName)
Colin Cross37f6d792018-07-12 12:28:41 -07001326 TransformJarsToJar(ctx, combinedJar, "for turbine", jars, android.OptionalPath{},
1327 false, nil, []string{"META-INF"})
Colin Cross5c6ecc12017-10-23 18:12:27 -07001328 headerJar = combinedJar
Nan Zhanged19fc32017-10-19 13:06:22 -07001329
Steven Morelandc4efd9c2019-01-18 11:51:25 -08001330 if j.expandJarjarRules != nil {
Nan Zhanged19fc32017-10-19 13:06:22 -07001331 // Transform classes.jar into classes-jarjar.jar
1332 jarjarFile := android.PathForModuleOut(ctx, "turbine-jarjar", jarName)
Steven Morelandc4efd9c2019-01-18 11:51:25 -08001333 TransformJarJar(ctx, jarjarFile, headerJar, j.expandJarjarRules)
Nan Zhanged19fc32017-10-19 13:06:22 -07001334 headerJar = jarjarFile
1335 if ctx.Failed() {
1336 return nil
1337 }
1338 }
1339
1340 return headerJar
1341}
1342
Colin Crosscb933592017-11-22 13:49:43 -08001343func (j *Module) instrument(ctx android.ModuleContext, flags javaBuilderFlags,
Colin Cross3063b782018-08-15 11:19:12 -07001344 classesJar android.Path, jarName string) android.ModuleOutPath {
Colin Crosscb933592017-11-22 13:49:43 -08001345
Colin Cross7a3139e2017-12-19 13:57:50 -08001346 specs := j.jacocoModuleToZipCommand(ctx)
Colin Crosscb933592017-11-22 13:49:43 -08001347
Colin Cross84c38822018-01-03 15:59:46 -08001348 jacocoReportClassesFile := android.PathForModuleOut(ctx, "jacoco-report-classes", jarName)
Colin Crosscb933592017-11-22 13:49:43 -08001349 instrumentedJar := android.PathForModuleOut(ctx, "jacoco", jarName)
1350
1351 jacocoInstrumentJar(ctx, instrumentedJar, jacocoReportClassesFile, classesJar, specs)
1352
1353 j.jacocoReportClassesFile = jacocoReportClassesFile
1354
1355 return instrumentedJar
1356}
1357
albaltai36ff7dc2018-12-25 14:35:23 +08001358var _ Dependency = (*Module)(nil)
Colin Cross2fe66872015-03-30 17:20:39 -07001359
Nan Zhanged19fc32017-10-19 13:06:22 -07001360func (j *Module) HeaderJars() android.Paths {
albaltai36ff7dc2018-12-25 14:35:23 +08001361 if j.headerJarFile == nil {
1362 return nil
1363 }
Nan Zhanged19fc32017-10-19 13:06:22 -07001364 return android.Paths{j.headerJarFile}
1365}
1366
1367func (j *Module) ImplementationJars() android.Paths {
shinwang9e4c07a2018-12-24 15:41:04 +08001368 if j.implementationJarFile == nil {
1369 return nil
1370 }
Nan Zhanged19fc32017-10-19 13:06:22 -07001371 return android.Paths{j.implementationJarFile}
Colin Cross2fe66872015-03-30 17:20:39 -07001372}
1373
Colin Crossf24a22a2019-01-31 14:12:44 -08001374func (j *Module) DexJar() android.Path {
1375 return j.dexJarFile
1376}
1377
Colin Cross331a1212018-08-15 20:40:52 -07001378func (j *Module) ResourceJars() android.Paths {
1379 if j.resourceJar == nil {
1380 return nil
1381 }
1382 return android.Paths{j.resourceJar}
1383}
1384
1385func (j *Module) ImplementationAndResourcesJars() android.Paths {
albaltai36ff7dc2018-12-25 14:35:23 +08001386 if j.implementationAndResourcesJar == nil {
1387 return nil
1388 }
Colin Cross331a1212018-08-15 20:40:52 -07001389 return android.Paths{j.implementationAndResourcesJar}
1390}
1391
Colin Cross46c9b8b2017-06-22 16:51:17 -07001392func (j *Module) AidlIncludeDirs() android.Paths {
albaltai36ff7dc2018-12-25 14:35:23 +08001393 // exportAidlIncludeDirs is type android.Paths already
Colin Crossc0b06f12015-04-08 13:03:43 -07001394 return j.exportAidlIncludeDirs
1395}
1396
Jiyong Park1be96912018-05-28 18:02:19 +09001397func (j *Module) ExportedSdkLibs() []string {
albaltai36ff7dc2018-12-25 14:35:23 +08001398 // exportedSdkLibs is type []string
Jiyong Park1be96912018-05-28 18:02:19 +09001399 return j.exportedSdkLibs
1400}
1401
Colin Cross46c9b8b2017-06-22 16:51:17 -07001402var _ logtagsProducer = (*Module)(nil)
Colin Crossf05fe972015-04-10 17:45:20 -07001403
Colin Cross46c9b8b2017-06-22 16:51:17 -07001404func (j *Module) logtags() android.Paths {
Colin Crossf05fe972015-04-10 17:45:20 -07001405 return j.logtagsSrcs
1406}
1407
Brandon Lee5d45c6f2018-08-15 15:35:38 -07001408// Collect information for opening IDE project files in java/jdeps.go.
1409func (j *Module) IDEInfo(dpInfo *android.IdeInfo) {
1410 dpInfo.Deps = append(dpInfo.Deps, j.CompilerDeps()...)
1411 dpInfo.Srcs = append(dpInfo.Srcs, j.expandIDEInfoCompiledSrcs...)
1412 dpInfo.Aidl_include_dirs = append(dpInfo.Aidl_include_dirs, j.deviceProperties.Aidl.Include_dirs...)
Steven Morelandc4efd9c2019-01-18 11:51:25 -08001413 if j.expandJarjarRules != nil {
1414 dpInfo.Jarjar_rules = append(dpInfo.Jarjar_rules, j.expandJarjarRules.String())
Brandon Lee5d45c6f2018-08-15 15:35:38 -07001415 }
1416}
1417
1418func (j *Module) CompilerDeps() []string {
1419 jdeps := []string{}
1420 jdeps = append(jdeps, j.properties.Libs...)
1421 jdeps = append(jdeps, j.properties.Static_libs...)
1422 return jdeps
1423}
1424
Colin Cross2fe66872015-03-30 17:20:39 -07001425//
1426// Java libraries (.jar file)
1427//
1428
Colin Crossf506d872017-07-19 15:53:04 -07001429type Library struct {
Colin Cross46c9b8b2017-06-22 16:51:17 -07001430 Module
Colin Cross2fe66872015-03-30 17:20:39 -07001431}
1432
Colin Cross2fc72f62018-12-21 12:59:54 -08001433func (j *Library) shouldUncompressDex(ctx android.ModuleContext) bool {
Nicolas Geoffrayfa6e9ec2019-02-12 13:12:16 +00001434 // Store uncompressed (and do not strip) dex files from boot class path jars.
1435 if inList(ctx.ModuleName(), ctx.Config().BootJars()) {
1436 return true
1437 }
1438
1439 // Store uncompressed dex files that are preopted on /system.
1440 if !j.dexpreopter.dexpreoptDisabled(ctx) && (ctx.Host() || !odexOnSystemOther(ctx, j.dexpreopter.installPath)) {
Vladimir Markoe8b00d62018-12-21 15:54:16 +00001441 return true
1442 }
Colin Cross083a2aa2019-02-06 16:37:12 -08001443 if ctx.Config().UncompressPrivAppDex() &&
1444 inList(ctx.ModuleName(), ctx.Config().ModulesLoadedByPrivilegedModules()) {
1445 return true
1446 }
1447
Colin Cross2fc72f62018-12-21 12:59:54 -08001448 return false
1449}
1450
Colin Crossf506d872017-07-19 15:53:04 -07001451func (j *Library) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross43f08db2018-11-12 10:13:39 -08001452 j.dexpreopter.installPath = android.PathForModuleInstall(ctx, "framework", ctx.ModuleName()+".jar")
1453 j.dexpreopter.isSDKLibrary = j.deviceProperties.IsSDKLibrary
Nicolas Geoffrayfa6e9ec2019-02-12 13:12:16 +00001454 j.dexpreopter.isInstallable = Bool(j.properties.Installable)
1455 j.dexpreopter.uncompressedDex = j.shouldUncompressDex(ctx)
1456 j.deviceProperties.UncompressDex = j.dexpreopter.uncompressedDex
Colin Cross46c9b8b2017-06-22 16:51:17 -07001457 j.compile(ctx)
Colin Crossb7a63242015-04-16 14:09:14 -07001458
Nicolas Geoffray4bdea392019-01-15 11:48:08 +00001459 if (Bool(j.properties.Installable) || ctx.Host()) && !android.DirectlyInAnyApex(ctx, ctx.ModuleName()) {
Colin Cross2c429dc2017-08-31 16:45:16 -07001460 j.installFile = ctx.InstallFile(android.PathForModuleInstall(ctx, "framework"),
1461 ctx.ModuleName()+".jar", j.outputFile)
1462 }
Colin Crossb7a63242015-04-16 14:09:14 -07001463}
1464
Colin Crossf506d872017-07-19 15:53:04 -07001465func (j *Library) DepsMutator(ctx android.BottomUpMutatorContext) {
Colin Cross46c9b8b2017-06-22 16:51:17 -07001466 j.deps(ctx)
1467}
1468
Colin Cross1b16b0e2019-02-12 14:41:32 -08001469// java_library builds and links sources into a `.jar` file for the device, and possibly for the host as well.
1470//
1471// By default, a java_library has a single variant that produces a `.jar` file containing `.class` files that were
1472// compiled against the device bootclasspath. This jar is not suitable for installing on a device, but can be used
1473// as a `static_libs` dependency of another module.
1474//
1475// Specifying `installable: true` will product a `.jar` file containing `classes.dex` files, suitable for installing on
1476// a device.
1477//
1478// Specifying `host_supported: true` will produce two variants, one compiled against the device bootclasspath and one
1479// compiled against the host bootclasspath.
Colin Cross9ae1b922018-06-26 17:59:05 -07001480func LibraryFactory() android.Module {
1481 module := &Library{}
Colin Cross2fe66872015-03-30 17:20:39 -07001482
Colin Cross9ae1b922018-06-26 17:59:05 -07001483 module.AddProperties(
1484 &module.Module.properties,
1485 &module.Module.deviceProperties,
Colin Cross43f08db2018-11-12 10:13:39 -08001486 &module.Module.dexpreoptProperties,
Colin Cross9ae1b922018-06-26 17:59:05 -07001487 &module.Module.protoProperties)
Colin Cross2fe66872015-03-30 17:20:39 -07001488
Colin Cross9ae1b922018-06-26 17:59:05 -07001489 InitJavaModule(module, android.HostAndDeviceSupported)
1490 return module
Colin Cross2fe66872015-03-30 17:20:39 -07001491}
1492
Colin Cross1b16b0e2019-02-12 14:41:32 -08001493// java_library_static is an obsolete alias for java_library.
1494func LibraryStaticFactory() android.Module {
1495 return LibraryFactory()
1496}
1497
1498// java_library_host builds and links sources into a `.jar` file for the host.
1499//
1500// A java_library_host has a single variant that produces a `.jar` file containing `.class` files that were
1501// compiled against the host bootclasspath.
Colin Crossf506d872017-07-19 15:53:04 -07001502func LibraryHostFactory() android.Module {
1503 module := &Library{}
Colin Cross2fe66872015-03-30 17:20:39 -07001504
Colin Cross6af17aa2017-09-20 12:59:05 -07001505 module.AddProperties(
1506 &module.Module.properties,
1507 &module.Module.protoProperties)
Colin Cross36242852017-06-23 15:06:31 -07001508
Colin Cross9ae1b922018-06-26 17:59:05 -07001509 module.Module.properties.Installable = proptools.BoolPtr(true)
1510
Colin Cross89536d42017-07-07 14:35:50 -07001511 InitJavaModule(module, android.HostSupported)
Colin Cross36242852017-06-23 15:06:31 -07001512 return module
Colin Cross2fe66872015-03-30 17:20:39 -07001513}
1514
1515//
Colin Crossb628ea52018-08-14 16:42:33 -07001516// Java Tests
Colin Cross05638fc2018-04-09 18:40:24 -07001517//
1518
1519type testProperties struct {
Colin Cross05638fc2018-04-09 18:40:24 -07001520 // list of compatibility suites (for example "cts", "vts") that the module should be
1521 // installed into.
1522 Test_suites []string `android:"arch_variant"`
Julien Despreze146e392018-08-02 15:00:46 -07001523
1524 // the name of the test configuration (for example "AndroidTest.xml") that should be
1525 // installed with the module.
Colin Cross27b922f2019-03-04 22:35:41 -08001526 Test_config *string `android:"path,arch_variant"`
Colin Crossd96ca352018-08-10 16:06:24 -07001527
Jack He33338892018-09-19 02:21:28 -07001528 // the name of the test configuration template (for example "AndroidTestTemplate.xml") that
1529 // should be installed with the module.
Colin Cross27b922f2019-03-04 22:35:41 -08001530 Test_config_template *string `android:"path,arch_variant"`
Jack He33338892018-09-19 02:21:28 -07001531
Colin Crossd96ca352018-08-10 16:06:24 -07001532 // list of files or filegroup modules that provide data that should be installed alongside
1533 // the test
Colin Cross27b922f2019-03-04 22:35:41 -08001534 Data []string `android:"path"`
Colin Cross05638fc2018-04-09 18:40:24 -07001535}
1536
1537type Test struct {
1538 Library
1539
1540 testProperties testProperties
Colin Cross303e21f2018-08-07 16:49:25 -07001541
1542 testConfig android.Path
Colin Crossd96ca352018-08-10 16:06:24 -07001543 data android.Paths
Colin Cross303e21f2018-08-07 16:49:25 -07001544}
1545
1546func (j *Test) GenerateAndroidBuildActions(ctx android.ModuleContext) {
yangbill4f41bc22019-02-13 21:45:47 +08001547 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 -07001548 j.data = ctx.ExpandSources(j.testProperties.Data, nil)
Colin Cross303e21f2018-08-07 16:49:25 -07001549
1550 j.Library.GenerateAndroidBuildActions(ctx)
Colin Cross05638fc2018-04-09 18:40:24 -07001551}
1552
Colin Cross1b16b0e2019-02-12 14:41:32 -08001553// java_test builds a and links sources into a `.jar` file for the device, and possibly for the host as well, and
1554// creates an `AndroidTest.xml` file to allow running the test with `atest` or a `TEST_MAPPING` file.
1555//
1556// By default, a java_test has a single variant that produces a `.jar` file containing `classes.dex` files that were
1557// compiled against the device bootclasspath.
1558//
1559// Specifying `host_supported: true` will produce two variants, one compiled against the device bootclasspath and one
1560// compiled against the host bootclasspath.
Colin Cross05638fc2018-04-09 18:40:24 -07001561func TestFactory() android.Module {
1562 module := &Test{}
1563
1564 module.AddProperties(
1565 &module.Module.properties,
1566 &module.Module.deviceProperties,
Colin Cross43f08db2018-11-12 10:13:39 -08001567 &module.Module.dexpreoptProperties,
Colin Cross05638fc2018-04-09 18:40:24 -07001568 &module.Module.protoProperties,
1569 &module.testProperties)
1570
Colin Cross9ae1b922018-06-26 17:59:05 -07001571 module.Module.properties.Installable = proptools.BoolPtr(true)
Colin Crosse3026872019-01-05 22:30:13 -08001572 module.Module.dexpreopter.isTest = true
Colin Cross9ae1b922018-06-26 17:59:05 -07001573
Colin Cross05638fc2018-04-09 18:40:24 -07001574 InitJavaModule(module, android.HostAndDeviceSupported)
Colin Cross05638fc2018-04-09 18:40:24 -07001575 return module
1576}
1577
Colin Cross1b16b0e2019-02-12 14:41:32 -08001578// java_test_host builds a and links sources into a `.jar` file for the host, and creates an `AndroidTest.xml` file to
1579// allow running the test with `atest` or a `TEST_MAPPING` file.
1580//
1581// A java_test_host has a single variant that produces a `.jar` file containing `.class` files that were
1582// compiled against the host bootclasspath.
Colin Cross05638fc2018-04-09 18:40:24 -07001583func TestHostFactory() android.Module {
1584 module := &Test{}
1585
1586 module.AddProperties(
1587 &module.Module.properties,
1588 &module.Module.protoProperties,
1589 &module.testProperties)
1590
Colin Cross9ae1b922018-06-26 17:59:05 -07001591 module.Module.properties.Installable = proptools.BoolPtr(true)
1592
Colin Cross05638fc2018-04-09 18:40:24 -07001593 InitJavaModule(module, android.HostSupported)
Colin Cross05638fc2018-04-09 18:40:24 -07001594 return module
1595}
1596
1597//
Colin Cross2fe66872015-03-30 17:20:39 -07001598// Java Binaries (.jar file plus wrapper script)
1599//
1600
Colin Crossf506d872017-07-19 15:53:04 -07001601type binaryProperties struct {
Colin Cross7d5136f2015-05-11 13:39:40 -07001602 // installable script to execute the resulting jar
Colin Cross27b922f2019-03-04 22:35:41 -08001603 Wrapper *string `android:"path"`
Colin Cross094054a2018-10-17 15:10:48 -07001604
1605 // Name of the class containing main to be inserted into the manifest as Main-Class.
1606 Main_class *string
Colin Cross7d5136f2015-05-11 13:39:40 -07001607}
1608
Colin Crossf506d872017-07-19 15:53:04 -07001609type Binary struct {
1610 Library
Colin Cross2fe66872015-03-30 17:20:39 -07001611
Colin Crossf506d872017-07-19 15:53:04 -07001612 binaryProperties binaryProperties
Colin Cross10a03492017-08-10 17:09:43 -07001613
Colin Cross6b4a32d2017-12-05 13:42:45 -08001614 isWrapperVariant bool
1615
Colin Crossc3315992017-12-08 19:12:36 -08001616 wrapperFile android.Path
Colin Cross10a03492017-08-10 17:09:43 -07001617 binaryFile android.OutputPath
Colin Cross2fe66872015-03-30 17:20:39 -07001618}
1619
Alex Light24237172017-10-26 09:46:21 -07001620func (j *Binary) HostToolPath() android.OptionalPath {
1621 return android.OptionalPathForPath(j.binaryFile)
1622}
1623
Colin Crossf506d872017-07-19 15:53:04 -07001624func (j *Binary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross6b4a32d2017-12-05 13:42:45 -08001625 if ctx.Arch().ArchType == android.Common {
1626 // Compile the jar
Colin Cross094054a2018-10-17 15:10:48 -07001627 if j.binaryProperties.Main_class != nil {
1628 if j.properties.Manifest != nil {
1629 ctx.PropertyErrorf("main_class", "main_class cannot be used when manifest is set")
1630 }
1631 manifestFile := android.PathForModuleOut(ctx, "manifest.txt")
1632 GenerateMainClassManifest(ctx, manifestFile, String(j.binaryProperties.Main_class))
1633 j.overrideManifest = android.OptionalPathForPath(manifestFile)
1634 }
1635
Colin Cross6b4a32d2017-12-05 13:42:45 -08001636 j.Library.GenerateAndroidBuildActions(ctx)
Nan Zhang3c807db2017-11-03 14:53:31 -07001637 } else {
Colin Cross6b4a32d2017-12-05 13:42:45 -08001638 // Handle the binary wrapper
1639 j.isWrapperVariant = true
1640
Colin Cross366938f2017-12-11 16:29:02 -08001641 if j.binaryProperties.Wrapper != nil {
1642 j.wrapperFile = ctx.ExpandSource(*j.binaryProperties.Wrapper, "wrapper")
Colin Cross6b4a32d2017-12-05 13:42:45 -08001643 } else {
1644 j.wrapperFile = android.PathForSource(ctx, "build/soong/scripts/jar-wrapper.sh")
1645 }
1646
1647 // Depend on the installed jar so that the wrapper doesn't get executed by
1648 // another build rule before the jar has been installed.
1649 jarFile := ctx.PrimaryModule().(*Binary).installFile
1650
1651 j.binaryFile = ctx.InstallExecutable(android.PathForModuleInstall(ctx, "bin"),
1652 ctx.ModuleName(), j.wrapperFile, jarFile)
Nan Zhang3c807db2017-11-03 14:53:31 -07001653 }
Colin Cross2fe66872015-03-30 17:20:39 -07001654}
1655
Colin Crossf506d872017-07-19 15:53:04 -07001656func (j *Binary) DepsMutator(ctx android.BottomUpMutatorContext) {
Colin Cross6b4a32d2017-12-05 13:42:45 -08001657 if ctx.Arch().ArchType == android.Common {
1658 j.deps(ctx)
1659 }
Colin Cross46c9b8b2017-06-22 16:51:17 -07001660}
1661
Colin Cross1b16b0e2019-02-12 14:41:32 -08001662// java_binary builds a `.jar` file and a shell script that executes it for the device, and possibly for the host
1663// as well.
1664//
1665// By default, a java_binary has a single variant that produces a `.jar` file containing `classes.dex` files that were
1666// compiled against the device bootclasspath.
1667//
1668// Specifying `host_supported: true` will produce two variants, one compiled against the device bootclasspath and one
1669// compiled against the host bootclasspath.
Colin Crossf506d872017-07-19 15:53:04 -07001670func BinaryFactory() android.Module {
1671 module := &Binary{}
Colin Cross2fe66872015-03-30 17:20:39 -07001672
Colin Cross36242852017-06-23 15:06:31 -07001673 module.AddProperties(
Colin Cross540eff82017-06-22 17:01:52 -07001674 &module.Module.properties,
1675 &module.Module.deviceProperties,
Colin Cross43f08db2018-11-12 10:13:39 -08001676 &module.Module.dexpreoptProperties,
Colin Cross6af17aa2017-09-20 12:59:05 -07001677 &module.Module.protoProperties,
Colin Cross540eff82017-06-22 17:01:52 -07001678 &module.binaryProperties)
Colin Cross36242852017-06-23 15:06:31 -07001679
Colin Cross9ae1b922018-06-26 17:59:05 -07001680 module.Module.properties.Installable = proptools.BoolPtr(true)
1681
Colin Cross6b4a32d2017-12-05 13:42:45 -08001682 android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibCommonFirst)
1683 android.InitDefaultableModule(module)
Colin Cross36242852017-06-23 15:06:31 -07001684 return module
Colin Cross2fe66872015-03-30 17:20:39 -07001685}
1686
Colin Cross1b16b0e2019-02-12 14:41:32 -08001687// java_binary_host builds a `.jar` file and a shell script that executes it for the host.
1688//
1689// A java_binary_host has a single variant that produces a `.jar` file containing `.class` files that were
1690// compiled against the host bootclasspath.
Colin Crossf506d872017-07-19 15:53:04 -07001691func BinaryHostFactory() android.Module {
1692 module := &Binary{}
Colin Cross2fe66872015-03-30 17:20:39 -07001693
Colin Cross36242852017-06-23 15:06:31 -07001694 module.AddProperties(
Colin Cross540eff82017-06-22 17:01:52 -07001695 &module.Module.properties,
Colin Cross6af17aa2017-09-20 12:59:05 -07001696 &module.Module.protoProperties,
Colin Cross540eff82017-06-22 17:01:52 -07001697 &module.binaryProperties)
Colin Cross36242852017-06-23 15:06:31 -07001698
Colin Cross9ae1b922018-06-26 17:59:05 -07001699 module.Module.properties.Installable = proptools.BoolPtr(true)
1700
Colin Cross6b4a32d2017-12-05 13:42:45 -08001701 android.InitAndroidArchModule(module, android.HostSupported, android.MultilibCommonFirst)
1702 android.InitDefaultableModule(module)
Colin Cross36242852017-06-23 15:06:31 -07001703 return module
Colin Cross2fe66872015-03-30 17:20:39 -07001704}
1705
1706//
1707// Java prebuilts
1708//
1709
Colin Cross74d73e22017-08-02 11:05:49 -07001710type ImportProperties struct {
Colin Cross27b922f2019-03-04 22:35:41 -08001711 Jars []string `android:"path"`
Colin Cross461bd1a2017-10-20 13:59:18 -07001712
Nan Zhangea568a42017-11-08 21:20:04 -08001713 Sdk_version *string
Colin Cross535e2cf2017-10-20 17:57:49 -07001714
1715 Installable *bool
Jiyong Park1be96912018-05-28 18:02:19 +09001716
1717 // List of shared java libs that this module has dependencies to
1718 Libs []string
Colin Cross37f6d792018-07-12 12:28:41 -07001719
1720 // List of files to remove from the jar file(s)
1721 Exclude_files []string
1722
1723 // List of directories to remove from the jar file(s)
1724 Exclude_dirs []string
Nan Zhang4c819fb2018-08-27 18:31:46 -07001725
1726 // if set to true, run Jetifier against .jar file. Defaults to false.
1727 Jetifier_enabled *bool
Colin Cross74d73e22017-08-02 11:05:49 -07001728}
1729
1730type Import struct {
Colin Cross635c3b02016-05-18 15:37:25 -07001731 android.ModuleBase
Colin Cross48de9a42018-10-02 13:53:33 -07001732 android.DefaultableModuleBase
Colin Crossec7a0422017-07-07 14:47:12 -07001733 prebuilt android.Prebuilt
Colin Cross2fe66872015-03-30 17:20:39 -07001734
Colin Cross74d73e22017-08-02 11:05:49 -07001735 properties ImportProperties
1736
Colin Cross0a6e0072017-08-30 14:24:55 -07001737 combinedClasspathFile android.Path
Jiyong Park1be96912018-05-28 18:02:19 +09001738 exportedSdkLibs []string
Colin Cross2fe66872015-03-30 17:20:39 -07001739}
1740
Colin Cross83bb3162018-06-25 15:48:06 -07001741func (j *Import) sdkVersion() string {
1742 return String(j.properties.Sdk_version)
1743}
1744
1745func (j *Import) minSdkVersion() string {
1746 return j.sdkVersion()
1747}
1748
Colin Cross74d73e22017-08-02 11:05:49 -07001749func (j *Import) Prebuilt() *android.Prebuilt {
Colin Crossec7a0422017-07-07 14:47:12 -07001750 return &j.prebuilt
1751}
1752
Colin Cross74d73e22017-08-02 11:05:49 -07001753func (j *Import) PrebuiltSrcs() []string {
1754 return j.properties.Jars
1755}
1756
1757func (j *Import) Name() string {
Colin Cross5ea9bcc2017-07-27 15:41:32 -07001758 return j.prebuilt.Name(j.ModuleBase.Name())
1759}
1760
Colin Cross74d73e22017-08-02 11:05:49 -07001761func (j *Import) DepsMutator(ctx android.BottomUpMutatorContext) {
Colin Cross42d48b72018-08-29 14:10:52 -07001762 ctx.AddVariationDependencies(nil, libTag, j.properties.Libs...)
Colin Cross1e676be2016-10-12 14:38:15 -07001763}
1764
Colin Cross74d73e22017-08-02 11:05:49 -07001765func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross37f6d792018-07-12 12:28:41 -07001766 jars := ctx.ExpandSources(j.properties.Jars, nil)
Colin Crosse1d62a82015-04-03 16:53:05 -07001767
Nan Zhang4c819fb2018-08-27 18:31:46 -07001768 jarName := ctx.ModuleName() + ".jar"
1769 outputFile := android.PathForModuleOut(ctx, "combined", jarName)
Colin Cross37f6d792018-07-12 12:28:41 -07001770 TransformJarsToJar(ctx, outputFile, "for prebuilts", jars, android.OptionalPath{},
1771 false, j.properties.Exclude_files, j.properties.Exclude_dirs)
Nan Zhang4c819fb2018-08-27 18:31:46 -07001772 if Bool(j.properties.Jetifier_enabled) {
1773 inputFile := outputFile
1774 outputFile = android.PathForModuleOut(ctx, "jetifier", jarName)
1775 TransformJetifier(ctx, outputFile, inputFile)
1776 }
Colin Crosse9a275b2017-10-16 17:09:48 -07001777 j.combinedClasspathFile = outputFile
Jiyong Park1be96912018-05-28 18:02:19 +09001778
1779 ctx.VisitDirectDeps(func(module android.Module) {
1780 otherName := ctx.OtherModuleName(module)
1781 tag := ctx.OtherModuleDependencyTag(module)
1782
1783 switch dep := module.(type) {
1784 case Dependency:
1785 switch tag {
1786 case libTag, staticLibTag:
1787 // sdk lib names from dependencies are re-exported
1788 j.exportedSdkLibs = append(j.exportedSdkLibs, dep.ExportedSdkLibs()...)
1789 }
1790 case SdkLibraryDependency:
1791 switch tag {
1792 case libTag:
1793 // names of sdk libs that are directly depended are exported
1794 j.exportedSdkLibs = append(j.exportedSdkLibs, otherName)
1795 }
1796 }
1797 })
1798
1799 j.exportedSdkLibs = android.FirstUniqueStrings(j.exportedSdkLibs)
Nan Zhang4973ecf2018-08-10 13:42:12 -07001800 if Bool(j.properties.Installable) {
1801 ctx.InstallFile(android.PathForModuleInstall(ctx, "framework"),
1802 ctx.ModuleName()+".jar", outputFile)
1803 }
Colin Cross2fe66872015-03-30 17:20:39 -07001804}
1805
Colin Cross74d73e22017-08-02 11:05:49 -07001806var _ Dependency = (*Import)(nil)
Colin Cross2fe66872015-03-30 17:20:39 -07001807
Nan Zhanged19fc32017-10-19 13:06:22 -07001808func (j *Import) HeaderJars() android.Paths {
albaltai36ff7dc2018-12-25 14:35:23 +08001809 if j.combinedClasspathFile == nil {
1810 return nil
1811 }
Colin Cross37f6d792018-07-12 12:28:41 -07001812 return android.Paths{j.combinedClasspathFile}
Nan Zhanged19fc32017-10-19 13:06:22 -07001813}
1814
1815func (j *Import) ImplementationJars() android.Paths {
shinwang9e4c07a2018-12-24 15:41:04 +08001816 if j.combinedClasspathFile == nil {
1817 return nil
1818 }
Colin Cross37f6d792018-07-12 12:28:41 -07001819 return android.Paths{j.combinedClasspathFile}
Colin Cross2fe66872015-03-30 17:20:39 -07001820}
1821
Colin Cross331a1212018-08-15 20:40:52 -07001822func (j *Import) ResourceJars() android.Paths {
1823 return nil
1824}
1825
1826func (j *Import) ImplementationAndResourcesJars() android.Paths {
albaltai36ff7dc2018-12-25 14:35:23 +08001827 if j.combinedClasspathFile == nil {
1828 return nil
1829 }
Colin Cross331a1212018-08-15 20:40:52 -07001830 return android.Paths{j.combinedClasspathFile}
1831}
1832
Colin Crossf24a22a2019-01-31 14:12:44 -08001833func (j *Import) DexJar() android.Path {
1834 return nil
1835}
1836
Colin Cross74d73e22017-08-02 11:05:49 -07001837func (j *Import) AidlIncludeDirs() android.Paths {
Colin Crossc0b06f12015-04-08 13:03:43 -07001838 return nil
1839}
1840
Jiyong Park1be96912018-05-28 18:02:19 +09001841func (j *Import) ExportedSdkLibs() []string {
1842 return j.exportedSdkLibs
1843}
1844
albaltai36ff7dc2018-12-25 14:35:23 +08001845// Add compile time check for interface implementation
1846var _ android.IDEInfo = (*Import)(nil)
1847var _ android.IDECustomizedModuleName = (*Import)(nil)
1848
Brandon Lee5d45c6f2018-08-15 15:35:38 -07001849// Collect information for opening IDE project files in java/jdeps.go.
1850const (
1851 removedPrefix = "prebuilt_"
1852)
1853
1854func (j *Import) IDEInfo(dpInfo *android.IdeInfo) {
1855 dpInfo.Jars = append(dpInfo.Jars, j.PrebuiltSrcs()...)
1856}
1857
1858func (j *Import) IDECustomizedModuleName() string {
1859 // TODO(b/113562217): Extract the base module name from the Import name, often the Import name
1860 // has a prefix "prebuilt_". Remove the prefix explicitly if needed until we find a better
1861 // solution to get the Import name.
1862 name := j.Name()
1863 if strings.HasPrefix(name, removedPrefix) {
patricktubb640e02018-10-11 18:33:16 +08001864 name = strings.TrimPrefix(name, removedPrefix)
Brandon Lee5d45c6f2018-08-15 15:35:38 -07001865 }
1866 return name
1867}
1868
Colin Cross74d73e22017-08-02 11:05:49 -07001869var _ android.PrebuiltInterface = (*Import)(nil)
Colin Cross2fe66872015-03-30 17:20:39 -07001870
Colin Cross1b16b0e2019-02-12 14:41:32 -08001871// java_import imports one or more `.jar` files into the build graph as if they were built by a java_library module.
1872//
1873// By default, a java_import has a single variant that expects a `.jar` file containing `.class` files that were
1874// compiled against an Android classpath.
1875//
1876// Specifying `host_supported: true` will produce two variants, one for use as a dependency of device modules and one
1877// for host modules.
Colin Cross74d73e22017-08-02 11:05:49 -07001878func ImportFactory() android.Module {
1879 module := &Import{}
Colin Cross36242852017-06-23 15:06:31 -07001880
Colin Cross74d73e22017-08-02 11:05:49 -07001881 module.AddProperties(&module.properties)
1882
1883 android.InitPrebuiltModule(module, &module.properties.Jars)
Colin Cross48de9a42018-10-02 13:53:33 -07001884 InitJavaModule(module, android.HostAndDeviceSupported)
Colin Cross36242852017-06-23 15:06:31 -07001885 return module
Colin Cross2fe66872015-03-30 17:20:39 -07001886}
1887
Colin Cross1b16b0e2019-02-12 14:41:32 -08001888// java_import imports one or more `.jar` files into the build graph as if they were built by a java_library_host
1889// module.
1890//
1891// A java_import_host has a single variant that expects a `.jar` file containing `.class` files that were
1892// compiled against a host bootclasspath.
Colin Cross74d73e22017-08-02 11:05:49 -07001893func ImportFactoryHost() android.Module {
1894 module := &Import{}
1895
1896 module.AddProperties(&module.properties)
1897
1898 android.InitPrebuiltModule(module, &module.properties.Jars)
Colin Cross48de9a42018-10-02 13:53:33 -07001899 InitJavaModule(module, android.HostSupported)
Colin Cross74d73e22017-08-02 11:05:49 -07001900 return module
1901}
1902
Colin Cross89536d42017-07-07 14:35:50 -07001903//
1904// Defaults
1905//
1906type Defaults struct {
1907 android.ModuleBase
1908 android.DefaultsModuleBase
1909}
1910
1911func (*Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1912}
1913
Colin Cross1b16b0e2019-02-12 14:41:32 -08001914// java_defaults provides a set of properties that can be inherited by other java or android modules.
1915//
1916// A module can use the properties from a java_defaults module using `defaults: ["defaults_module_name"]`. Each
1917// property in the defaults module that exists in the depending module will be prepended to the depending module's
1918// value for that property.
1919//
1920// Example:
1921//
1922// java_defaults {
1923// name: "example_defaults",
1924// srcs: ["common/**/*.java"],
1925// javacflags: ["-Xlint:all"],
1926// aaptflags: ["--auto-add-overlay"],
1927// }
1928//
1929// java_library {
1930// name: "example",
1931// defaults: ["example_defaults"],
1932// srcs: ["example/**/*.java"],
1933// }
1934//
1935// is functionally identical to:
1936//
1937// java_library {
1938// name: "example",
1939// srcs: [
1940// "common/**/*.java",
1941// "example/**/*.java",
1942// ],
1943// javacflags: ["-Xlint:all"],
1944// }
Colin Cross89536d42017-07-07 14:35:50 -07001945func defaultsFactory() android.Module {
1946 return DefaultsFactory()
1947}
1948
1949func DefaultsFactory(props ...interface{}) android.Module {
1950 module := &Defaults{}
1951
1952 module.AddProperties(props...)
1953 module.AddProperties(
1954 &CompilerProperties{},
1955 &CompilerDeviceProperties{},
Colin Cross43f08db2018-11-12 10:13:39 -08001956 &DexpreoptProperties{},
Dan Willemsen6424d172018-03-08 13:27:59 -08001957 &android.ProtoProperties{},
Colin Cross48de9a42018-10-02 13:53:33 -07001958 &aaptProperties{},
1959 &androidLibraryProperties{},
1960 &appProperties{},
1961 &appTestProperties{},
1962 &ImportProperties{},
1963 &AARImportProperties{},
1964 &sdkLibraryProperties{},
Colin Cross89536d42017-07-07 14:35:50 -07001965 )
1966
1967 android.InitDefaultsModule(module)
1968
1969 return module
1970}
Nan Zhangea568a42017-11-08 21:20:04 -08001971
1972var Bool = proptools.Bool
Colin Cross38b40df2018-04-10 16:14:46 -07001973var BoolDefault = proptools.BoolDefault
Nan Zhangea568a42017-11-08 21:20:04 -08001974var String = proptools.String
Colin Cross0d0ba592018-02-20 13:33:42 -08001975var inList = android.InList