blob: f088d8647bd08c7dfa579622d11568545ff9f45b [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 Crosse560c4a2019-03-19 16:03:11 -0700291 outputFile android.Path
292 extraOutputFiles android.Paths
Colin Crossb7a63242015-04-16 14:09:14 -0700293
Colin Cross635c3b02016-05-18 15:37:25 -0700294 exportAidlIncludeDirs android.Paths
Colin Crossc0b06f12015-04-08 13:03:43 -0700295
Colin Cross635c3b02016-05-18 15:37:25 -0700296 logtagsSrcs android.Paths
Colin Crossf05fe972015-04-10 17:45:20 -0700297
Colin Cross2fe66872015-03-30 17:20:39 -0700298 // installed file for binary dependency
Colin Cross635c3b02016-05-18 15:37:25 -0700299 installFile android.Path
Colin Cross5ab4e6d2017-11-22 16:20:45 -0800300
301 // list of .java files and srcjars that was passed to javac
302 compiledJavaSrcs android.Paths
303 compiledSrcJars android.Paths
Colin Cross66dbc0b2017-12-28 12:23:20 -0800304
305 // list of extra progurad flag files
306 extraProguardFlagFiles android.Paths
Jiyong Park1be96912018-05-28 18:02:19 +0900307
Colin Cross094054a2018-10-17 15:10:48 -0700308 // manifest file to use instead of properties.Manifest
309 overrideManifest android.OptionalPath
310
Jiyong Park1be96912018-05-28 18:02:19 +0900311 // list of SDK lib names that this java moudule is exporting
312 exportedSdkLibs []string
Brandon Lee5d45c6f2018-08-15 15:35:38 -0700313
314 // list of source files, collected from compiledJavaSrcs and compiledSrcJars
315 // filter out Exclude_srcs, will be used by android.IDEInfo struct
316 expandIDEInfoCompiledSrcs []string
Colin Cross43f08db2018-11-12 10:13:39 -0800317
Steven Morelandc4efd9c2019-01-18 11:51:25 -0800318 // expanded Jarjar_rules
319 expandJarjarRules android.Path
320
Colin Crossf24a22a2019-01-31 14:12:44 -0800321 hiddenAPI
Colin Cross43f08db2018-11-12 10:13:39 -0800322 dexpreopter
Colin Cross2fe66872015-03-30 17:20:39 -0700323}
324
Colin Cross54250902017-12-05 09:28:08 -0800325func (j *Module) Srcs() android.Paths {
Colin Crosse560c4a2019-03-19 16:03:11 -0700326 return append(android.Paths{j.outputFile}, j.extraOutputFiles...)
Colin Cross54250902017-12-05 09:28:08 -0800327}
328
Jiyong Park8fd61922018-11-08 02:50:25 +0900329func (j *Module) DexJarFile() android.Path {
330 return j.dexJarFile
331}
332
Colin Cross54250902017-12-05 09:28:08 -0800333var _ android.SourceFileProducer = (*Module)(nil)
334
Colin Crossf506d872017-07-19 15:53:04 -0700335type Dependency interface {
Nan Zhanged19fc32017-10-19 13:06:22 -0700336 HeaderJars() android.Paths
337 ImplementationJars() android.Paths
Colin Cross331a1212018-08-15 20:40:52 -0700338 ResourceJars() android.Paths
339 ImplementationAndResourcesJars() android.Paths
Colin Crossf24a22a2019-01-31 14:12:44 -0800340 DexJar() android.Path
Colin Cross635c3b02016-05-18 15:37:25 -0700341 AidlIncludeDirs() android.Paths
Jiyong Park1be96912018-05-28 18:02:19 +0900342 ExportedSdkLibs() []string
Colin Cross2fe66872015-03-30 17:20:39 -0700343}
344
Jiyong Parkc678ad32018-04-10 13:07:10 +0900345type SdkLibraryDependency interface {
Colin Cross897d2ed2019-02-11 14:03:51 -0800346 SdkHeaderJars(ctx android.BaseContext, sdkVersion string) android.Paths
347 SdkImplementationJars(ctx android.BaseContext, sdkVersion string) android.Paths
Jiyong Parkc678ad32018-04-10 13:07:10 +0900348}
349
Nan Zhangb2b33de2018-02-23 11:18:47 -0800350type SrcDependency interface {
351 CompiledSrcs() android.Paths
352 CompiledSrcJars() android.Paths
353}
354
355func (j *Module) CompiledSrcs() android.Paths {
356 return j.compiledJavaSrcs
357}
358
359func (j *Module) CompiledSrcJars() android.Paths {
360 return j.compiledSrcJars
361}
362
363var _ SrcDependency = (*Module)(nil)
364
Colin Cross89536d42017-07-07 14:35:50 -0700365func InitJavaModule(module android.DefaultableModule, hod android.HostOrDeviceSupported) {
366 android.InitAndroidArchModule(module, hod, android.MultilibCommon)
367 android.InitDefaultableModule(module)
368}
369
Colin Crossbe1da472017-07-07 15:59:46 -0700370type dependencyTag struct {
371 blueprint.BaseDependencyTag
372 name string
Colin Cross2fe66872015-03-30 17:20:39 -0700373}
374
Colin Crossa4f08812018-10-02 22:03:40 -0700375type jniDependencyTag struct {
376 blueprint.BaseDependencyTag
377 target android.Target
378}
379
Colin Crossbe1da472017-07-07 15:59:46 -0700380var (
Colin Cross4b964c02018-10-15 16:18:06 -0700381 staticLibTag = dependencyTag{name: "staticlib"}
382 libTag = dependencyTag{name: "javalib"}
Colin Crossbe9cdb82019-01-21 21:37:16 -0800383 pluginTag = dependencyTag{name: "plugin"}
Colin Cross4b964c02018-10-15 16:18:06 -0700384 bootClasspathTag = dependencyTag{name: "bootclasspath"}
385 systemModulesTag = dependencyTag{name: "system modules"}
386 frameworkResTag = dependencyTag{name: "framework-res"}
387 frameworkApkTag = dependencyTag{name: "framework-apk"}
388 kotlinStdlibTag = dependencyTag{name: "kotlin-stdlib"}
Colin Crossafbb1732019-01-17 15:42:52 -0800389 kotlinAnnotationsTag = dependencyTag{name: "kotlin-annotations"}
Colin Cross4b964c02018-10-15 16:18:06 -0700390 proguardRaiseTag = dependencyTag{name: "proguard-raise"}
391 certificateTag = dependencyTag{name: "certificate"}
392 instrumentationForTag = dependencyTag{name: "instrumentation_for"}
Colin Crossbe1da472017-07-07 15:59:46 -0700393)
Colin Cross2fe66872015-03-30 17:20:39 -0700394
Colin Crossfc3674a2017-09-18 17:41:52 -0700395type sdkDep struct {
Colin Cross47ff2522017-10-02 14:22:08 -0700396 useModule, useFiles, useDefaultLibs, invalidVersion bool
397
Colin Cross86a60ae2018-05-29 14:44:55 -0700398 modules []string
Colin Cross1369cdb2017-09-29 17:58:17 -0700399 systemModules string
400
Colin Crossa97c5d32018-03-28 14:58:31 -0700401 frameworkResModule string
402
Colin Cross86a60ae2018-05-29 14:44:55 -0700403 jars android.Paths
Colin Cross1369cdb2017-09-29 17:58:17 -0700404 aidl android.Path
405}
406
Colin Crossa4f08812018-10-02 22:03:40 -0700407type jniLib struct {
408 name string
409 path android.Path
410 target android.Target
411}
412
Colin Cross3144dfc2018-01-03 15:06:47 -0800413func (j *Module) shouldInstrument(ctx android.BaseContext) bool {
414 return j.properties.Instrument && ctx.Config().IsEnvTrue("EMMA_INSTRUMENT")
415}
416
417func (j *Module) shouldInstrumentStatic(ctx android.BaseContext) bool {
418 return j.shouldInstrument(ctx) &&
419 (ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_STATIC") ||
420 ctx.Config().UnbundledBuild())
421}
422
Colin Cross83bb3162018-06-25 15:48:06 -0700423func (j *Module) sdkVersion() string {
424 return String(j.deviceProperties.Sdk_version)
425}
426
427func (j *Module) minSdkVersion() string {
428 if j.deviceProperties.Min_sdk_version != nil {
429 return *j.deviceProperties.Min_sdk_version
430 }
431 return j.sdkVersion()
432}
433
Dan Willemsen419290a2018-10-31 15:28:47 -0700434func (j *Module) targetSdkVersion() string {
435 if j.deviceProperties.Target_sdk_version != nil {
436 return *j.deviceProperties.Target_sdk_version
437 }
438 return j.sdkVersion()
439}
440
Colin Crossbe1da472017-07-07 15:59:46 -0700441func (j *Module) deps(ctx android.BottomUpMutatorContext) {
Colin Cross1369cdb2017-09-29 17:58:17 -0700442 if ctx.Device() {
Colin Crossff3ae9d2018-04-10 16:15:18 -0700443 if !Bool(j.properties.No_standard_libs) {
Colin Cross83bb3162018-06-25 15:48:06 -0700444 sdkDep := decodeSdkDep(ctx, sdkContext(j))
Colin Crossfc3674a2017-09-18 17:41:52 -0700445 if sdkDep.useDefaultLibs {
Colin Cross42d48b72018-08-29 14:10:52 -0700446 ctx.AddVariationDependencies(nil, bootClasspathTag, config.DefaultBootclasspathLibraries...)
Tobias Thierer06dd04f2018-09-11 16:21:05 +0100447 ctx.AddVariationDependencies(nil, systemModulesTag, config.DefaultSystemModules)
Colin Crossff3ae9d2018-04-10 16:15:18 -0700448 if !Bool(j.properties.No_framework_libs) {
Colin Cross42d48b72018-08-29 14:10:52 -0700449 ctx.AddVariationDependencies(nil, libTag, config.DefaultLibraries...)
Colin Crossfa5eb232017-10-01 20:33:03 -0700450 }
Colin Cross1369cdb2017-09-29 17:58:17 -0700451 } else if sdkDep.useModule {
Tobias Thierer06dd04f2018-09-11 16:21:05 +0100452 ctx.AddVariationDependencies(nil, systemModulesTag, sdkDep.systemModules)
Colin Cross42d48b72018-08-29 14:10:52 -0700453 ctx.AddVariationDependencies(nil, bootClasspathTag, sdkDep.modules...)
Colin Cross66dbc0b2017-12-28 12:23:20 -0800454 if Bool(j.deviceProperties.Optimize.Enabled) {
Colin Cross42d48b72018-08-29 14:10:52 -0700455 ctx.AddVariationDependencies(nil, proguardRaiseTag, config.DefaultBootclasspathLibraries...)
456 ctx.AddVariationDependencies(nil, proguardRaiseTag, config.DefaultLibraries...)
Colin Cross66dbc0b2017-12-28 12:23:20 -0800457 }
Colin Crossbe1da472017-07-07 15:59:46 -0700458 }
Colin Cross1369cdb2017-09-29 17:58:17 -0700459 } else if j.deviceProperties.System_modules == nil {
460 ctx.PropertyErrorf("no_standard_libs",
461 "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 +0100462 } else if *j.deviceProperties.System_modules != "none" {
Colin Cross42d48b72018-08-29 14:10:52 -0700463 ctx.AddVariationDependencies(nil, systemModulesTag, *j.deviceProperties.System_modules)
Colin Cross2fe66872015-03-30 17:20:39 -0700464 }
Mathew Inwoodebe29ce2018-09-04 14:26:19 +0100465 if (ctx.ModuleName() == "framework") || (ctx.ModuleName() == "framework-annotation-proc") {
Colin Cross42d48b72018-08-29 14:10:52 -0700466 ctx.AddVariationDependencies(nil, frameworkResTag, "framework-res")
Colin Cross5ab4e6d2017-11-22 16:20:45 -0800467 }
Nan Zhangb2b33de2018-02-23 11:18:47 -0800468 if ctx.ModuleName() == "android_stubs_current" ||
469 ctx.ModuleName() == "android_system_stubs_current" ||
Nan Zhang863f05b2018-08-07 13:41:10 -0700470 ctx.ModuleName() == "android_test_stubs_current" {
Colin Cross42d48b72018-08-29 14:10:52 -0700471 ctx.AddVariationDependencies(nil, frameworkApkTag, "framework-res")
Nan Zhangb2b33de2018-02-23 11:18:47 -0800472 }
Colin Cross2fe66872015-03-30 17:20:39 -0700473 }
Colin Cross1369cdb2017-09-29 17:58:17 -0700474
Colin Cross42d48b72018-08-29 14:10:52 -0700475 ctx.AddVariationDependencies(nil, libTag, j.properties.Libs...)
476 ctx.AddVariationDependencies(nil, staticLibTag, j.properties.Static_libs...)
Colin Crossa4f08812018-10-02 22:03:40 -0700477
Colin Crossbe9cdb82019-01-21 21:37:16 -0800478 ctx.AddFarVariationDependencies([]blueprint.Variation{
479 {Mutator: "arch", Variation: ctx.Config().BuildOsCommonVariant},
480 }, pluginTag, j.properties.Plugins...)
481
Colin Cross6af17aa2017-09-20 12:59:05 -0700482 if j.hasSrcExt(".proto") {
483 protoDeps(ctx, &j.protoProperties)
484 }
Colin Cross93e85952017-08-15 13:34:18 -0700485
486 if j.hasSrcExt(".kt") {
487 // TODO(ccross): move this to a mutator pass that can tell if generated sources contain
488 // Kotlin files
Colin Cross42d48b72018-08-29 14:10:52 -0700489 ctx.AddVariationDependencies(nil, kotlinStdlibTag, "kotlin-stdlib")
Colin Cross7788c122019-01-23 16:14:02 -0800490 if len(j.properties.Plugins) > 0 {
Colin Crossafbb1732019-01-17 15:42:52 -0800491 ctx.AddVariationDependencies(nil, kotlinAnnotationsTag, "kotlin-annotations")
492 }
Colin Cross93e85952017-08-15 13:34:18 -0700493 }
Colin Cross3144dfc2018-01-03 15:06:47 -0800494
495 if j.shouldInstrumentStatic(ctx) {
Colin Cross42d48b72018-08-29 14:10:52 -0700496 ctx.AddVariationDependencies(nil, staticLibTag, "jacocoagent")
Colin Cross3144dfc2018-01-03 15:06:47 -0800497 }
Colin Cross6af17aa2017-09-20 12:59:05 -0700498}
499
500func hasSrcExt(srcs []string, ext string) bool {
501 for _, src := range srcs {
502 if filepath.Ext(src) == ext {
503 return true
504 }
505 }
506
507 return false
508}
509
Nan Zhang61eaedb2017-11-02 13:28:15 -0700510func shardPaths(paths android.Paths, shardSize int) []android.Paths {
511 ret := make([]android.Paths, 0, (len(paths)+shardSize-1)/shardSize)
512 for len(paths) > shardSize {
513 ret = append(ret, paths[0:shardSize])
514 paths = paths[shardSize:]
515 }
516 if len(paths) > 0 {
517 ret = append(ret, paths)
518 }
519 return ret
520}
521
Colin Cross6af17aa2017-09-20 12:59:05 -0700522func (j *Module) hasSrcExt(ext string) bool {
523 return hasSrcExt(j.properties.Srcs, ext)
Colin Cross2fe66872015-03-30 17:20:39 -0700524}
525
Colin Cross46c9b8b2017-06-22 16:51:17 -0700526func (j *Module) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.OptionalPath,
Colin Cross635c3b02016-05-18 15:37:25 -0700527 aidlIncludeDirs android.Paths) []string {
Colin Crossc0b06f12015-04-08 13:03:43 -0700528
Colin Crossebe1a512017-11-14 13:12:14 -0800529 aidlIncludes := android.PathsForModuleSrc(ctx, j.deviceProperties.Aidl.Local_include_dirs)
530 aidlIncludes = append(aidlIncludes,
531 android.PathsForModuleSrc(ctx, j.deviceProperties.Aidl.Export_include_dirs)...)
532 aidlIncludes = append(aidlIncludes,
533 android.PathsForSource(ctx, j.deviceProperties.Aidl.Include_dirs)...)
Colin Crossc0b06f12015-04-08 13:03:43 -0700534
Steven Moreland36b130f2019-02-05 17:02:55 -0800535 flags := []string{}
Steven Moreland667f6882018-07-26 12:55:08 -0700536
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700537 if aidlPreprocess.Valid() {
538 flags = append(flags, "-p"+aidlPreprocess.String())
Colin Crossc0b06f12015-04-08 13:03:43 -0700539 } else {
Colin Cross635c3b02016-05-18 15:37:25 -0700540 flags = append(flags, android.JoinWithPrefix(aidlIncludeDirs.Strings(), "-I"))
Colin Crossc0b06f12015-04-08 13:03:43 -0700541 }
542
Colin Cross635c3b02016-05-18 15:37:25 -0700543 flags = append(flags, android.JoinWithPrefix(j.exportAidlIncludeDirs.Strings(), "-I"))
Colin Crossebe1a512017-11-14 13:12:14 -0800544 flags = append(flags, android.JoinWithPrefix(aidlIncludes.Strings(), "-I"))
Colin Cross635c3b02016-05-18 15:37:25 -0700545 flags = append(flags, "-I"+android.PathForModuleSrc(ctx).String())
Colin Cross32f38982018-02-22 11:47:25 -0800546 if src := android.ExistentPathForSource(ctx, ctx.ModuleDir(), "src"); src.Valid() {
Colin Crossd48633a2017-07-13 14:41:17 -0700547 flags = append(flags, "-I"+src.String())
548 }
Colin Crossc0b06f12015-04-08 13:03:43 -0700549
Martijn Coeneneab15642018-03-09 09:29:59 +0100550 if Bool(j.deviceProperties.Aidl.Generate_traces) {
551 flags = append(flags, "-t")
552 }
553
Olivier Gaillard0a4cfbc2018-07-16 23:37:03 +0100554 if Bool(j.deviceProperties.Aidl.Generate_get_transaction_name) {
555 flags = append(flags, "--transaction_names")
556 }
557
Colin Crossf03c82b2015-04-13 13:53:40 -0700558 return flags
Colin Crossc0b06f12015-04-08 13:03:43 -0700559}
560
Colin Cross32f676a2017-09-06 13:41:06 -0700561type deps struct {
Nan Zhang581fd212018-01-10 16:06:12 -0800562 classpath classpath
563 bootClasspath classpath
Colin Cross6a77c982018-06-19 22:43:34 -0700564 processorPath classpath
Colin Crossbe9cdb82019-01-21 21:37:16 -0800565 processorClasses []string
Colin Cross6ade34f2017-09-15 13:00:47 -0700566 staticJars android.Paths
Nan Zhanged19fc32017-10-19 13:06:22 -0700567 staticHeaderJars android.Paths
Colin Cross331a1212018-08-15 20:40:52 -0700568 staticResourceJars android.Paths
Colin Cross6ade34f2017-09-15 13:00:47 -0700569 aidlIncludeDirs android.Paths
Nan Zhangb2b33de2018-02-23 11:18:47 -0800570 srcs android.Paths
Colin Cross59149b62017-10-16 18:07:29 -0700571 srcJars android.Paths
Colin Cross1369cdb2017-09-29 17:58:17 -0700572 systemModules android.Path
Colin Cross6ade34f2017-09-15 13:00:47 -0700573 aidlPreprocess android.OptionalPath
Colin Cross93e85952017-08-15 13:34:18 -0700574 kotlinStdlib android.Paths
Colin Crossafbb1732019-01-17 15:42:52 -0800575 kotlinAnnotations android.Paths
Colin Crossbe9cdb82019-01-21 21:37:16 -0800576
577 disableTurbine bool
Colin Cross32f676a2017-09-06 13:41:06 -0700578}
Colin Cross2fe66872015-03-30 17:20:39 -0700579
Colin Cross54250902017-12-05 09:28:08 -0800580func checkProducesJars(ctx android.ModuleContext, dep android.SourceFileProducer) {
581 for _, f := range dep.Srcs() {
582 if f.Ext() != ".jar" {
583 ctx.ModuleErrorf("genrule %q must generate files ending with .jar to be used as a libs or static_libs dependency",
584 ctx.OtherModuleName(dep.(blueprint.Module)))
585 }
586 }
587}
588
Jiyong Park2d492942018-03-05 17:44:10 +0900589type linkType int
590
591const (
592 javaCore linkType = iota
593 javaSdk
594 javaSystem
595 javaPlatform
596)
597
Jiyong Park46f78fb2018-10-20 16:33:17 +0900598func getLinkType(m *Module, name string) (ret linkType, stubs bool) {
Colin Cross83bb3162018-06-25 15:48:06 -0700599 ver := m.sdkVersion()
Colin Crossf19b9bb2018-03-26 14:42:44 -0700600 switch {
Jiyong Park46f78fb2018-10-20 16:33:17 +0900601 case name == "core.current.stubs" || name == "core.platform.api.stubs" ||
602 name == "stub-annotations" || name == "private-stub-annotations-jar" ||
603 name == "core-lambda-stubs":
604 return javaCore, true
Neil Fuller401eeba2018-10-18 19:48:58 +0100605 case ver == "core_current":
Jiyong Park46f78fb2018-10-20 16:33:17 +0900606 return javaCore, false
607 case name == "android_system_stubs_current":
608 return javaSystem, true
609 case strings.HasPrefix(ver, "system_"):
610 return javaSystem, false
611 case name == "android_test_stubs_current":
612 return javaSystem, true
613 case strings.HasPrefix(ver, "test_"):
614 return javaPlatform, false
615 case name == "android_stubs_current":
616 return javaSdk, true
617 case ver == "current":
618 return javaSdk, false
Colin Crossf19b9bb2018-03-26 14:42:44 -0700619 case ver == "":
Jiyong Park46f78fb2018-10-20 16:33:17 +0900620 return javaPlatform, false
Colin Crossf19b9bb2018-03-26 14:42:44 -0700621 default:
622 if _, err := strconv.Atoi(ver); err != nil {
623 panic(fmt.Errorf("expected sdk_version to be a number, got %q", ver))
624 }
Jiyong Park46f78fb2018-10-20 16:33:17 +0900625 return javaSdk, false
Jiyong Park2d492942018-03-05 17:44:10 +0900626 }
627}
628
Jiyong Park750e5572018-01-31 00:20:13 +0900629func checkLinkType(ctx android.ModuleContext, from *Module, to *Library, tag dependencyTag) {
Colin Crossf19b9bb2018-03-26 14:42:44 -0700630 if ctx.Host() {
631 return
632 }
633
Jiyong Park46f78fb2018-10-20 16:33:17 +0900634 myLinkType, stubs := getLinkType(from, ctx.ModuleName())
635 if stubs {
636 return
637 }
638 otherLinkType, _ := getLinkType(&to.Module, ctx.OtherModuleName(to))
Jiyong Park2d492942018-03-05 17:44:10 +0900639 commonMessage := "Adjust sdk_version: property of the source or target module so that target module is built with the same or smaller API set than the source."
640
641 switch myLinkType {
642 case javaCore:
643 if otherLinkType != javaCore {
644 ctx.ModuleErrorf("compiles against core Java API, but dependency %q is compiling against non-core Java APIs."+commonMessage,
Jiyong Park750e5572018-01-31 00:20:13 +0900645 ctx.OtherModuleName(to))
646 }
Jiyong Park2d492942018-03-05 17:44:10 +0900647 break
648 case javaSdk:
649 if otherLinkType != javaCore && otherLinkType != javaSdk {
650 ctx.ModuleErrorf("compiles against Android API, but dependency %q is compiling against non-public Android API."+commonMessage,
651 ctx.OtherModuleName(to))
652 }
653 break
654 case javaSystem:
655 if otherLinkType == javaPlatform {
656 ctx.ModuleErrorf("compiles against system API, but dependency %q is compiling against private API."+commonMessage,
657 ctx.OtherModuleName(to))
658 }
659 break
660 case javaPlatform:
661 // no restriction on link-type
662 break
Jiyong Park750e5572018-01-31 00:20:13 +0900663 }
664}
665
Colin Cross32f676a2017-09-06 13:41:06 -0700666func (j *Module) collectDeps(ctx android.ModuleContext) deps {
667 var deps deps
Colin Crossfc3674a2017-09-18 17:41:52 -0700668
Colin Cross300f0382018-03-06 13:11:51 -0800669 if ctx.Device() {
Colin Cross83bb3162018-06-25 15:48:06 -0700670 sdkDep := decodeSdkDep(ctx, sdkContext(j))
Colin Cross300f0382018-03-06 13:11:51 -0800671 if sdkDep.invalidVersion {
Colin Cross86a60ae2018-05-29 14:44:55 -0700672 ctx.AddMissingDependencies(sdkDep.modules)
Colin Cross300f0382018-03-06 13:11:51 -0800673 } else if sdkDep.useFiles {
674 // sdkDep.jar is actually equivalent to turbine header.jar.
Colin Cross86a60ae2018-05-29 14:44:55 -0700675 deps.classpath = append(deps.classpath, sdkDep.jars...)
Colin Cross300f0382018-03-06 13:11:51 -0800676 deps.aidlIncludeDirs = append(deps.aidlIncludeDirs, sdkDep.aidl)
677 }
Colin Crossfc3674a2017-09-18 17:41:52 -0700678 }
679
Colin Crossd11fcda2017-10-23 17:59:01 -0700680 ctx.VisitDirectDeps(func(module android.Module) {
Colin Cross2fe66872015-03-30 17:20:39 -0700681 otherName := ctx.OtherModuleName(module)
Colin Crossec7a0422017-07-07 14:47:12 -0700682 tag := ctx.OtherModuleDependencyTag(module)
683
Colin Crossa4f08812018-10-02 22:03:40 -0700684 if _, ok := tag.(*jniDependencyTag); ok {
Colin Crossbd01e2a2018-10-04 15:21:03 -0700685 // Handled by AndroidApp.collectAppDeps
686 return
687 }
688 if tag == certificateTag {
689 // Handled by AndroidApp.collectAppDeps
Colin Crossa4f08812018-10-02 22:03:40 -0700690 return
691 }
692
Jiyong Park750e5572018-01-31 00:20:13 +0900693 if to, ok := module.(*Library); ok {
Colin Crossa97c5d32018-03-28 14:58:31 -0700694 switch tag {
695 case bootClasspathTag, libTag, staticLibTag:
696 checkLinkType(ctx, j, to, tag.(dependencyTag))
697 }
Jiyong Park750e5572018-01-31 00:20:13 +0900698 }
Colin Cross54250902017-12-05 09:28:08 -0800699 switch dep := module.(type) {
Colin Cross897d2ed2019-02-11 14:03:51 -0800700 case SdkLibraryDependency:
701 switch tag {
702 case libTag:
703 deps.classpath = append(deps.classpath, dep.SdkHeaderJars(ctx, j.sdkVersion())...)
704 // names of sdk libs that are directly depended are exported
705 j.exportedSdkLibs = append(j.exportedSdkLibs, otherName)
706 default:
707 ctx.ModuleErrorf("dependency on java_sdk_library %q can only be in libs", otherName)
708 }
Colin Cross54250902017-12-05 09:28:08 -0800709 case Dependency:
710 switch tag {
711 case bootClasspathTag:
712 deps.bootClasspath = append(deps.bootClasspath, dep.HeaderJars()...)
Colin Cross4b964c02018-10-15 16:18:06 -0700713 case libTag, instrumentationForTag:
Colin Cross54250902017-12-05 09:28:08 -0800714 deps.classpath = append(deps.classpath, dep.HeaderJars()...)
Jiyong Park1be96912018-05-28 18:02:19 +0900715 // sdk lib names from dependencies are re-exported
716 j.exportedSdkLibs = append(j.exportedSdkLibs, dep.ExportedSdkLibs()...)
Colin Cross54250902017-12-05 09:28:08 -0800717 case staticLibTag:
718 deps.classpath = append(deps.classpath, dep.HeaderJars()...)
719 deps.staticJars = append(deps.staticJars, dep.ImplementationJars()...)
720 deps.staticHeaderJars = append(deps.staticHeaderJars, dep.HeaderJars()...)
Colin Cross331a1212018-08-15 20:40:52 -0700721 deps.staticResourceJars = append(deps.staticResourceJars, dep.ResourceJars()...)
Jiyong Park1be96912018-05-28 18:02:19 +0900722 // sdk lib names from dependencies are re-exported
723 j.exportedSdkLibs = append(j.exportedSdkLibs, dep.ExportedSdkLibs()...)
Colin Crossbe9cdb82019-01-21 21:37:16 -0800724 case pluginTag:
725 if plugin, ok := dep.(*Plugin); ok {
726 deps.processorPath = append(deps.processorPath, dep.ImplementationAndResourcesJars()...)
727 if plugin.pluginProperties.Processor_class != nil {
728 deps.processorClasses = append(deps.processorClasses, *plugin.pluginProperties.Processor_class)
729 }
730 deps.disableTurbine = deps.disableTurbine || Bool(plugin.pluginProperties.Generates_api)
731 } else {
732 ctx.PropertyErrorf("plugins", "%q is not a java_plugin module", otherName)
733 }
Colin Cross54250902017-12-05 09:28:08 -0800734 case frameworkResTag:
Mathew Inwoodebe29ce2018-09-04 14:26:19 +0100735 if (ctx.ModuleName() == "framework") || (ctx.ModuleName() == "framework-annotation-proc") {
Colin Cross54250902017-12-05 09:28:08 -0800736 // framework.jar has a one-off dependency on the R.java and Manifest.java files
737 // generated by framework-res.apk
738 deps.srcJars = append(deps.srcJars, dep.(*AndroidApp).aaptSrcJar)
739 }
Nan Zhangb2b33de2018-02-23 11:18:47 -0800740 case frameworkApkTag:
741 if ctx.ModuleName() == "android_stubs_current" ||
742 ctx.ModuleName() == "android_system_stubs_current" ||
Nan Zhang863f05b2018-08-07 13:41:10 -0700743 ctx.ModuleName() == "android_test_stubs_current" {
Nan Zhangb2b33de2018-02-23 11:18:47 -0800744 // framework stubs.jar need to depend on framework-res.apk, in order to pull the
745 // resource files out of there for aapt.
746 //
747 // Normally the package rule runs aapt, which includes the resource,
748 // but we're not running that in our package rule so just copy in the
749 // resource files here.
Colin Cross331a1212018-08-15 20:40:52 -0700750 deps.staticResourceJars = append(deps.staticResourceJars, dep.(*AndroidApp).exportPackage)
Nan Zhangb2b33de2018-02-23 11:18:47 -0800751 }
Colin Cross54250902017-12-05 09:28:08 -0800752 case kotlinStdlibTag:
753 deps.kotlinStdlib = dep.HeaderJars()
Colin Crossafbb1732019-01-17 15:42:52 -0800754 case kotlinAnnotationsTag:
755 deps.kotlinAnnotations = dep.HeaderJars()
Colin Cross54250902017-12-05 09:28:08 -0800756 }
757
758 deps.aidlIncludeDirs = append(deps.aidlIncludeDirs, dep.AidlIncludeDirs()...)
759 case android.SourceFileProducer:
760 switch tag {
761 case libTag:
762 checkProducesJars(ctx, dep)
763 deps.classpath = append(deps.classpath, dep.Srcs()...)
764 case staticLibTag:
765 checkProducesJars(ctx, dep)
766 deps.classpath = append(deps.classpath, dep.Srcs()...)
767 deps.staticJars = append(deps.staticJars, dep.Srcs()...)
768 deps.staticHeaderJars = append(deps.staticHeaderJars, dep.Srcs()...)
769 case android.DefaultsDepTag, android.SourceDepTag:
770 // Nothing to do
Sundong Ahn054b19a2018-10-19 13:46:09 +0900771 case publicApiFileTag, systemApiFileTag, testApiFileTag:
772 // Nothing to do
Colin Cross54250902017-12-05 09:28:08 -0800773 default:
774 ctx.ModuleErrorf("dependency on genrule %q may only be in srcs, libs, or static_libs", otherName)
775 }
776 default:
Colin Crossec7a0422017-07-07 14:47:12 -0700777 switch tag {
778 case android.DefaultsDepTag, android.SourceDepTag:
Dan Willemsend6ba0d52017-09-13 15:46:47 -0700779 // Nothing to do
Colin Cross1369cdb2017-09-29 17:58:17 -0700780 case systemModulesTag:
781 if deps.systemModules != nil {
782 panic("Found two system module dependencies")
783 }
784 sm := module.(*SystemModules)
785 if sm.outputFile == nil {
786 panic("Missing directory for system module dependency")
787 }
788 deps.systemModules = sm.outputFile
Colin Crossec7a0422017-07-07 14:47:12 -0700789 default:
790 ctx.ModuleErrorf("depends on non-java module %q", otherName)
Colin Cross2fe66872015-03-30 17:20:39 -0700791 }
Colin Crossec7a0422017-07-07 14:47:12 -0700792 }
Colin Cross2fe66872015-03-30 17:20:39 -0700793 })
794
Jiyong Park1be96912018-05-28 18:02:19 +0900795 j.exportedSdkLibs = android.FirstUniqueStrings(j.exportedSdkLibs)
796
Colin Cross32f676a2017-09-06 13:41:06 -0700797 return deps
Colin Cross2fe66872015-03-30 17:20:39 -0700798}
799
Colin Cross83bb3162018-06-25 15:48:06 -0700800func getJavaVersion(ctx android.ModuleContext, javaVersion string, sdkContext sdkContext) string {
Nan Zhang357466b2018-04-17 17:38:36 -0700801 var ret string
Colin Cross98fd5742019-01-09 23:04:25 -0800802 v := sdkContext.sdkVersion()
803 // For PDK builds, use the latest SDK version instead of "current"
804 if ctx.Config().IsPdkBuild() && (v == "" || v == "current") {
805 sdkVersions := ctx.Config().Get(sdkSingletonKey).([]int)
806 latestSdkVersion := 0
807 if len(sdkVersions) > 0 {
808 latestSdkVersion = sdkVersions[len(sdkVersions)-1]
809 }
810 v = strconv.Itoa(latestSdkVersion)
811 }
812
813 sdk, err := sdkVersionToNumber(ctx, v)
Colin Cross83bb3162018-06-25 15:48:06 -0700814 if err != nil {
815 ctx.PropertyErrorf("sdk_version", "%s", err)
816 }
Nan Zhang357466b2018-04-17 17:38:36 -0700817 if javaVersion != "" {
818 ret = javaVersion
819 } else if ctx.Device() && sdk <= 23 {
820 ret = "1.7"
Jiyong Park4584a8a2018-10-03 18:05:04 +0900821 } else if ctx.Device() && sdk <= 28 || !ctx.Config().TargetOpenJDK9() {
Nan Zhang357466b2018-04-17 17:38:36 -0700822 ret = "1.8"
Colin Cross83bb3162018-06-25 15:48:06 -0700823 } else if ctx.Device() && sdkContext.sdkVersion() != "" && sdk == android.FutureApiLevel {
Nan Zhang357466b2018-04-17 17:38:36 -0700824 // TODO(ccross): once we generate stubs we should be able to use 1.9 for sdk_version: "current"
825 ret = "1.8"
826 } else {
827 ret = "1.9"
828 }
829
830 return ret
831}
832
Nan Zhanged19fc32017-10-19 13:06:22 -0700833func (j *Module) collectBuilderFlags(ctx android.ModuleContext, deps deps) javaBuilderFlags {
Colin Crossc0b06f12015-04-08 13:03:43 -0700834
Colin Crossf03c82b2015-04-13 13:53:40 -0700835 var flags javaBuilderFlags
836
Tobias Thierer06dd04f2018-09-11 16:21:05 +0100837 // javaVersion flag.
838 flags.javaVersion = getJavaVersion(ctx, String(j.properties.Java_version), sdkContext(j))
839
Nan Zhanged19fc32017-10-19 13:06:22 -0700840 // javac flags.
Colin Crossf03c82b2015-04-13 13:53:40 -0700841 javacFlags := j.properties.Javacflags
Tobias Thierer06dd04f2018-09-11 16:21:05 +0100842 if flags.javaVersion == "1.9" {
Colin Cross1369cdb2017-09-29 17:58:17 -0700843 javacFlags = append(javacFlags, j.properties.Openjdk9.Javacflags...)
Nan Zhanged19fc32017-10-19 13:06:22 -0700844 }
Colin Cross6510f912017-11-29 00:27:14 -0800845 if ctx.Config().MinimizeJavaDebugInfo() {
Colin Cross126a25c2017-10-31 13:55:34 -0700846 // Override the -g flag passed globally to remove local variable debug info to reduce
847 // disk and memory usage.
848 javacFlags = append(javacFlags, "-g:source,lines")
849 }
Colin Cross64162712017-08-08 13:17:59 -0700850
Colin Cross66548102018-06-19 22:47:35 -0700851 if ctx.Config().RunErrorProne() {
852 if config.ErrorProneClasspath == nil {
853 ctx.ModuleErrorf("cannot build with Error Prone, missing external/error_prone?")
854 }
855
856 errorProneFlags := []string{
857 "-Xplugin:ErrorProne",
858 "${config.ErrorProneChecks}",
859 }
860 errorProneFlags = append(errorProneFlags, j.properties.Errorprone.Javacflags...)
861
862 flags.errorProneExtraJavacFlags = "${config.ErrorProneFlags} " +
863 "'" + strings.Join(errorProneFlags, " ") + "'"
864 flags.errorProneProcessorPath = classpath(android.PathsForSource(ctx, config.ErrorProneClasspath))
Andreas Gampef3e5b552018-01-22 21:27:21 -0800865 }
866
Nan Zhanged19fc32017-10-19 13:06:22 -0700867 // classpath
Nan Zhang581fd212018-01-10 16:06:12 -0800868 flags.bootClasspath = append(flags.bootClasspath, deps.bootClasspath...)
869 flags.classpath = append(flags.classpath, deps.classpath...)
Colin Cross6a77c982018-06-19 22:43:34 -0700870 flags.processorPath = append(flags.processorPath, deps.processorPath...)
Colin Cross7fdd2b72018-01-02 18:14:25 -0800871
Colin Crossbe9cdb82019-01-21 21:37:16 -0800872 flags.processor = strings.Join(deps.processorClasses, ",")
873
Tobias Thierer06dd04f2018-09-11 16:21:05 +0100874 if len(flags.bootClasspath) == 0 && ctx.Host() && flags.javaVersion != "1.9" &&
Colin Cross7fdd2b72018-01-02 18:14:25 -0800875 !Bool(j.properties.No_standard_libs) &&
876 inList(flags.javaVersion, []string{"1.6", "1.7", "1.8"}) {
877 // Give host-side tools a version of OpenJDK's standard libraries
878 // close to what they're targeting. As of Dec 2017, AOSP is only
879 // bundling OpenJDK 8 and 9, so nothing < 8 is available.
880 //
881 // When building with OpenJDK 8, the following should have no
882 // effect since those jars would be available by default.
883 //
884 // When building with OpenJDK 9 but targeting a version < 1.8,
885 // putting them on the bootclasspath means that:
886 // a) code can't (accidentally) refer to OpenJDK 9 specific APIs
887 // b) references to existing APIs are not reinterpreted in an
888 // OpenJDK 9-specific way, eg. calls to subclasses of
889 // java.nio.Buffer as in http://b/70862583
890 java8Home := ctx.Config().Getenv("ANDROID_JAVA8_HOME")
891 flags.bootClasspath = append(flags.bootClasspath,
892 android.PathForSource(ctx, java8Home, "jre/lib/jce.jar"),
893 android.PathForSource(ctx, java8Home, "jre/lib/rt.jar"))
Nan Zhang5f8cb422018-02-06 10:34:32 -0800894 if Bool(j.properties.Use_tools_jar) {
895 flags.bootClasspath = append(flags.bootClasspath,
896 android.PathForSource(ctx, java8Home, "lib/tools.jar"))
897 }
Colin Cross7fdd2b72018-01-02 18:14:25 -0800898 }
899
Tobias Thierer06dd04f2018-09-11 16:21:05 +0100900 if j.properties.Patch_module != nil && flags.javaVersion == "1.9" {
Jaewoong Jung38e4fb22018-12-12 09:01:34 -0800901 // Manually specify build directory in case it is not under the repo root.
902 // (javac doesn't seem to expand into symbolc links when searching for patch-module targets, so
903 // just adding a symlink under the root doesn't help.)
904 patchPaths := ".:" + ctx.Config().BuildDir()
905 classPath := flags.classpath.FormJavaClassPath("")
906 if classPath != "" {
907 patchPaths += ":" + classPath
908 }
909 javacFlags = append(javacFlags, "--patch-module="+String(j.properties.Patch_module)+"="+patchPaths)
Colin Cross81440082018-08-15 20:21:55 -0700910 }
911
Nan Zhanged19fc32017-10-19 13:06:22 -0700912 // systemModules
Colin Cross1369cdb2017-09-29 17:58:17 -0700913 if deps.systemModules != nil {
914 flags.systemModules = append(flags.systemModules, deps.systemModules)
915 }
916
Nan Zhanged19fc32017-10-19 13:06:22 -0700917 // aidl flags.
Colin Cross32f676a2017-09-06 13:41:06 -0700918 aidlFlags := j.aidlFlags(ctx, deps.aidlPreprocess, deps.aidlIncludeDirs)
Colin Crossf03c82b2015-04-13 13:53:40 -0700919 if len(aidlFlags) > 0 {
Nan Zhanged19fc32017-10-19 13:06:22 -0700920 // optimization.
Colin Crossf03c82b2015-04-13 13:53:40 -0700921 ctx.Variable(pctx, "aidlFlags", strings.Join(aidlFlags, " "))
922 flags.aidlFlags = "$aidlFlags"
Colin Cross2fe66872015-03-30 17:20:39 -0700923 }
924
Colin Cross81440082018-08-15 20:21:55 -0700925 if len(javacFlags) > 0 {
926 // optimization.
927 ctx.Variable(pctx, "javacFlags", strings.Join(javacFlags, " "))
928 flags.javacFlags = "$javacFlags"
929 }
930
Nan Zhanged19fc32017-10-19 13:06:22 -0700931 return flags
932}
Colin Crossc0b06f12015-04-08 13:03:43 -0700933
Colin Cross3bc7ffa2017-11-22 16:19:37 -0800934func (j *Module) compile(ctx android.ModuleContext, extraSrcJars ...android.Path) {
Nan Zhanged19fc32017-10-19 13:06:22 -0700935
Colin Crossebe1a512017-11-14 13:12:14 -0800936 j.exportAidlIncludeDirs = android.PathsForModuleSrc(ctx, j.deviceProperties.Aidl.Export_include_dirs)
Nan Zhanged19fc32017-10-19 13:06:22 -0700937
938 deps := j.collectDeps(ctx)
939 flags := j.collectBuilderFlags(ctx, deps)
940
Tobias Thierer06dd04f2018-09-11 16:21:05 +0100941 if flags.javaVersion == "1.9" {
Nan Zhanged19fc32017-10-19 13:06:22 -0700942 j.properties.Srcs = append(j.properties.Srcs, j.properties.Openjdk9.Srcs...)
943 }
944 srcFiles := ctx.ExpandSources(j.properties.Srcs, j.properties.Exclude_srcs)
Colin Cross6af17aa2017-09-20 12:59:05 -0700945 if hasSrcExt(srcFiles.Strings(), ".proto") {
Colin Cross0f2ee152017-12-14 15:22:43 -0800946 flags = protoFlags(ctx, &j.properties, &j.protoProperties, flags)
Colin Cross6af17aa2017-09-20 12:59:05 -0700947 }
948
Colin Crossaf050172017-11-15 23:01:59 -0800949 srcFiles = j.genSources(ctx, srcFiles, flags)
950
951 srcJars := srcFiles.FilterByExt(".srcjar")
Colin Cross59149b62017-10-16 18:07:29 -0700952 srcJars = append(srcJars, deps.srcJars...)
Colin Cross3bc7ffa2017-11-22 16:19:37 -0800953 srcJars = append(srcJars, extraSrcJars...)
Colin Crossb7a63242015-04-16 14:09:14 -0700954
Brandon Lee5d45c6f2018-08-15 15:35:38 -0700955 // Collect source files from compiledJavaSrcs, compiledSrcJars and filter out Exclude_srcs
956 // that IDEInfo struct will use
957 j.expandIDEInfoCompiledSrcs = append(j.expandIDEInfoCompiledSrcs, srcFiles.Strings()...)
958
Steven Morelandc4efd9c2019-01-18 11:51:25 -0800959 if j.properties.Jarjar_rules != nil {
960 j.expandJarjarRules = ctx.ExpandSource(*j.properties.Jarjar_rules, "jarjar_rules")
961 }
962
Colin Cross1ee23172017-10-18 14:44:18 -0700963 jarName := ctx.ModuleName() + ".jar"
964
Przemyslaw Szczepaniak4b5fe9d2018-02-13 14:32:54 +0000965 javaSrcFiles := srcFiles.FilterByExt(".java")
966 var uniqueSrcFiles android.Paths
967 set := make(map[string]bool)
968 for _, v := range javaSrcFiles {
969 if _, found := set[v.String()]; !found {
970 set[v.String()] = true
971 uniqueSrcFiles = append(uniqueSrcFiles, v)
972 }
973 }
974
Colin Cross55f63ea2018-08-27 12:37:09 -0700975 var kotlinJars android.Paths
976
Colin Cross93e85952017-08-15 13:34:18 -0700977 if srcFiles.HasExt(".kt") {
Zoran Jovanovic8736ce22018-08-21 17:10:29 +0200978 // user defined kotlin flags.
979 kotlincFlags := j.properties.Kotlincflags
980 CheckKotlincFlags(ctx, kotlincFlags)
981
Colin Cross93e85952017-08-15 13:34:18 -0700982 // If there are kotlin files, compile them first but pass all the kotlin and java files
983 // kotlinc will use the java files to resolve types referenced by the kotlin files, but
984 // won't emit any classes for them.
Zoran Jovanovic8736ce22018-08-21 17:10:29 +0200985 kotlincFlags = append(kotlincFlags, "-no-stdlib")
Colin Cross93e85952017-08-15 13:34:18 -0700986 if ctx.Device() {
Zoran Jovanovic8736ce22018-08-21 17:10:29 +0200987 kotlincFlags = append(kotlincFlags, "-no-jdk")
988 }
989 if len(kotlincFlags) > 0 {
990 // optimization.
991 ctx.Variable(pctx, "kotlincFlags", strings.Join(kotlincFlags, " "))
992 flags.kotlincFlags += "$kotlincFlags"
Colin Cross93e85952017-08-15 13:34:18 -0700993 }
994
Przemyslaw Szczepaniak4b5fe9d2018-02-13 14:32:54 +0000995 var kotlinSrcFiles android.Paths
996 kotlinSrcFiles = append(kotlinSrcFiles, uniqueSrcFiles...)
997 kotlinSrcFiles = append(kotlinSrcFiles, srcFiles.FilterByExt(".kt")...)
998
Colin Crossafbb1732019-01-17 15:42:52 -0800999 flags.classpath = append(flags.classpath, deps.kotlinStdlib...)
1000 flags.classpath = append(flags.classpath, deps.kotlinAnnotations...)
1001
1002 flags.kotlincClasspath = append(flags.kotlincClasspath, flags.bootClasspath...)
1003 flags.kotlincClasspath = append(flags.kotlincClasspath, flags.classpath...)
1004
1005 if len(flags.processorPath) > 0 {
1006 // Use kapt for annotation processing
1007 kaptSrcJar := android.PathForModuleOut(ctx, "kapt", "kapt-sources.jar")
1008 kotlinKapt(ctx, kaptSrcJar, kotlinSrcFiles, srcJars, flags)
1009 srcJars = append(srcJars, kaptSrcJar)
1010 // Disable annotation processing in javac, it's already been handled by kapt
1011 flags.processorPath = nil
Colin Cross3a3e94c2019-01-23 15:39:50 -08001012 flags.processor = ""
Colin Crossafbb1732019-01-17 15:42:52 -08001013 }
Colin Cross93e85952017-08-15 13:34:18 -07001014
Colin Cross1ee23172017-10-18 14:44:18 -07001015 kotlinJar := android.PathForModuleOut(ctx, "kotlin", jarName)
Colin Cross21fc9bb2019-01-18 15:05:09 -08001016 kotlinCompile(ctx, kotlinJar, kotlinSrcFiles, srcJars, flags)
Colin Cross93e85952017-08-15 13:34:18 -07001017 if ctx.Failed() {
1018 return
1019 }
1020
1021 // Make javac rule depend on the kotlinc rule
1022 flags.classpath = append(flags.classpath, kotlinJar)
Przemyslaw Szczepaniak66c0c402018-03-08 13:21:55 +00001023
Colin Cross93e85952017-08-15 13:34:18 -07001024 // Jar kotlin classes into the final jar after javac
Colin Cross55f63ea2018-08-27 12:37:09 -07001025 kotlinJars = append(kotlinJars, kotlinJar)
Colin Cross9b38aef2018-08-27 15:42:25 -07001026 kotlinJars = append(kotlinJars, deps.kotlinStdlib...)
Colin Cross93e85952017-08-15 13:34:18 -07001027 }
1028
Colin Cross55f63ea2018-08-27 12:37:09 -07001029 jars := append(android.Paths(nil), kotlinJars...)
1030
Colin Cross5ab4e6d2017-11-22 16:20:45 -08001031 // Store the list of .java files that was passed to javac
1032 j.compiledJavaSrcs = uniqueSrcFiles
1033 j.compiledSrcJars = srcJars
1034
Nan Zhang61eaedb2017-11-02 13:28:15 -07001035 enable_sharding := false
Colin Crossbe9cdb82019-01-21 21:37:16 -08001036 if ctx.Device() && !ctx.Config().IsEnvFalse("TURBINE_ENABLED") && !deps.disableTurbine {
Nan Zhang61eaedb2017-11-02 13:28:15 -07001037 if j.properties.Javac_shard_size != nil && *(j.properties.Javac_shard_size) > 0 {
1038 enable_sharding = true
Ashley Rosee36efcf2019-01-16 17:34:08 -05001039 // Formerly, there was a check here that prevented annotation processors
1040 // from being used when sharding was enabled, as some annotation processors
1041 // do not function correctly in sharded environments. It was removed to
1042 // allow for the use of annotation processors that do function correctly
1043 // with sharding enabled. See: b/77284273.
Nan Zhang61eaedb2017-11-02 13:28:15 -07001044 }
Colin Cross55f63ea2018-08-27 12:37:09 -07001045 j.headerJarFile = j.compileJavaHeader(ctx, uniqueSrcFiles, srcJars, deps, flags, jarName, kotlinJars)
Colin Crossf19b9bb2018-03-26 14:42:44 -07001046 if ctx.Failed() {
1047 return
Nan Zhanged19fc32017-10-19 13:06:22 -07001048 }
1049 }
Colin Cross8eadbf02017-10-24 17:46:00 -07001050 if len(uniqueSrcFiles) > 0 || len(srcJars) > 0 {
Colin Crossd6891432017-09-27 17:39:56 -07001051 var extraJarDeps android.Paths
Colin Cross66548102018-06-19 22:47:35 -07001052 if ctx.Config().RunErrorProne() {
Colin Crossc6bbef32017-08-14 14:16:06 -07001053 // If error-prone is enabled, add an additional rule to compile the java files into
1054 // a separate set of classes (so that they don't overwrite the normal ones and require
Colin Crossd6891432017-09-27 17:39:56 -07001055 // a rebuild when error-prone is turned off).
Colin Crossc6bbef32017-08-14 14:16:06 -07001056 // TODO(ccross): Once we always compile with javac9 we may be able to conditionally
1057 // enable error-prone without affecting the output class files.
Colin Cross1ee23172017-10-18 14:44:18 -07001058 errorprone := android.PathForModuleOut(ctx, "errorprone", jarName)
Nan Zhang61eaedb2017-11-02 13:28:15 -07001059 RunErrorProne(ctx, errorprone, uniqueSrcFiles, srcJars, flags)
Colin Crossc6bbef32017-08-14 14:16:06 -07001060 extraJarDeps = append(extraJarDeps, errorprone)
1061 }
1062
Nan Zhang61eaedb2017-11-02 13:28:15 -07001063 if enable_sharding {
Nan Zhang581fd212018-01-10 16:06:12 -08001064 flags.classpath = append(flags.classpath, j.headerJarFile)
Nan Zhang61eaedb2017-11-02 13:28:15 -07001065 shardSize := int(*(j.properties.Javac_shard_size))
1066 var shardSrcs []android.Paths
1067 if len(uniqueSrcFiles) > 0 {
1068 shardSrcs = shardPaths(uniqueSrcFiles, shardSize)
1069 for idx, shardSrc := range shardSrcs {
1070 classes := android.PathForModuleOut(ctx, "javac", jarName+strconv.Itoa(idx))
1071 TransformJavaToClasses(ctx, classes, idx, shardSrc, nil, flags, extraJarDeps)
1072 jars = append(jars, classes)
1073 }
1074 }
1075 if len(srcJars) > 0 {
1076 classes := android.PathForModuleOut(ctx, "javac", jarName+strconv.Itoa(len(shardSrcs)))
1077 TransformJavaToClasses(ctx, classes, len(shardSrcs), nil, srcJars, flags, extraJarDeps)
1078 jars = append(jars, classes)
1079 }
1080 } else {
1081 classes := android.PathForModuleOut(ctx, "javac", jarName)
1082 TransformJavaToClasses(ctx, classes, -1, uniqueSrcFiles, srcJars, flags, extraJarDeps)
1083 jars = append(jars, classes)
1084 }
Colin Crossd6891432017-09-27 17:39:56 -07001085 if ctx.Failed() {
1086 return
1087 }
Colin Cross2fe66872015-03-30 17:20:39 -07001088 }
1089
Colin Crosscedd4762018-09-13 11:26:19 -07001090 dirArgs, dirDeps := ResourceDirsToJarArgs(ctx, j.properties.Java_resource_dirs,
1091 j.properties.Exclude_java_resource_dirs, j.properties.Exclude_java_resources)
Colin Cross0f37af02017-09-27 17:42:05 -07001092 fileArgs, fileDeps := ResourceFilesToJarArgs(ctx, j.properties.Java_resources, j.properties.Exclude_java_resources)
1093
1094 var resArgs []string
1095 var resDeps android.Paths
1096
1097 resArgs = append(resArgs, dirArgs...)
1098 resDeps = append(resDeps, dirDeps...)
1099
1100 resArgs = append(resArgs, fileArgs...)
1101 resDeps = append(resDeps, fileDeps...)
1102
Colin Crossff3ae9d2018-04-10 16:15:18 -07001103 if Bool(j.properties.Include_srcs) {
Colin Cross23729232017-10-03 13:14:07 -07001104 srcArgs, srcDeps := SourceFilesToJarArgs(ctx, j.properties.Srcs, j.properties.Exclude_srcs)
Colin Cross0f37af02017-09-27 17:42:05 -07001105 resArgs = append(resArgs, srcArgs...)
1106 resDeps = append(resDeps, srcDeps...)
1107 }
Colin Cross40a36712017-09-27 17:41:35 -07001108
1109 if len(resArgs) > 0 {
Colin Cross1ee23172017-10-18 14:44:18 -07001110 resourceJar := android.PathForModuleOut(ctx, "res", jarName)
Colin Crosse9a275b2017-10-16 17:09:48 -07001111 TransformResourcesToJar(ctx, resourceJar, resArgs, resDeps)
Colin Cross331a1212018-08-15 20:40:52 -07001112 j.resourceJar = resourceJar
Colin Cross65bf4f22015-04-03 16:54:17 -07001113 if ctx.Failed() {
1114 return
1115 }
1116 }
1117
Colin Cross331a1212018-08-15 20:40:52 -07001118 if len(deps.staticResourceJars) > 0 {
1119 var jars android.Paths
1120 if j.resourceJar != nil {
1121 jars = append(jars, j.resourceJar)
1122 }
1123 jars = append(jars, deps.staticResourceJars...)
1124
1125 combinedJar := android.PathForModuleOut(ctx, "res-combined", jarName)
1126 TransformJarsToJar(ctx, combinedJar, "for resources", jars, android.OptionalPath{},
1127 false, nil, nil)
1128 j.resourceJar = combinedJar
1129 }
1130
Colin Cross32f676a2017-09-06 13:41:06 -07001131 jars = append(jars, deps.staticJars...)
Colin Cross0a6e0072017-08-30 14:24:55 -07001132
Colin Cross094054a2018-10-17 15:10:48 -07001133 manifest := j.overrideManifest
1134 if !manifest.Valid() && j.properties.Manifest != nil {
Colin Cross366938f2017-12-11 16:29:02 -08001135 manifest = android.OptionalPathForPath(ctx.ExpandSource(*j.properties.Manifest, "manifest"))
1136 }
Colin Cross635acc92017-09-12 22:50:46 -07001137
Alex Light7f004a72019-02-21 13:27:37 -08001138 services := ctx.ExpandSources(j.properties.Services, nil)
1139 if len(services) > 0 {
1140 servicesJar := android.PathForModuleOut(ctx, "services", jarName)
1141 var zipargs []string
1142 for _, file := range services {
1143 serviceFile := file.String()
1144 zipargs = append(zipargs, "-C", filepath.Dir(serviceFile), "-f", serviceFile)
1145 }
1146 ctx.Build(pctx, android.BuildParams{
1147 Rule: zip,
1148 Output: servicesJar,
1149 Implicits: services,
1150 Args: map[string]string{
Colin Cross0b9f31f2019-02-28 11:00:01 -08001151 "jarArgs": "-P META-INF/services/ " + strings.Join(proptools.NinjaAndShellEscapeList(zipargs), " "),
Alex Light7f004a72019-02-21 13:27:37 -08001152 },
1153 })
1154 jars = append(jars, servicesJar)
1155 }
1156
Colin Cross0a6e0072017-08-30 14:24:55 -07001157 // Combine the classes built from sources, any manifests, and any static libraries into
Nan Zhanged19fc32017-10-19 13:06:22 -07001158 // classes.jar. If there is only one input jar this step will be skipped.
Colin Cross3063b782018-08-15 11:19:12 -07001159 var outputFile android.ModuleOutPath
Colin Crosse9a275b2017-10-16 17:09:48 -07001160
1161 if len(jars) == 1 && !manifest.Valid() {
Colin Cross3063b782018-08-15 11:19:12 -07001162 if moduleOutPath, ok := jars[0].(android.ModuleOutPath); ok {
1163 // Optimization: skip the combine step if there is nothing to do
1164 // TODO(ccross): this leaves any module-info.class files, but those should only come from
1165 // prebuilt dependencies until we support modules in the platform build, so there shouldn't be
1166 // any if len(jars) == 1.
1167 outputFile = moduleOutPath
1168 } else {
1169 combinedJar := android.PathForModuleOut(ctx, "combined", jarName)
1170 ctx.Build(pctx, android.BuildParams{
1171 Rule: android.Cp,
1172 Input: jars[0],
1173 Output: combinedJar,
1174 })
1175 outputFile = combinedJar
1176 }
Colin Crosse9a275b2017-10-16 17:09:48 -07001177 } else {
Colin Cross1ee23172017-10-18 14:44:18 -07001178 combinedJar := android.PathForModuleOut(ctx, "combined", jarName)
Colin Cross37f6d792018-07-12 12:28:41 -07001179 TransformJarsToJar(ctx, combinedJar, "for javac", jars, manifest,
Colin Cross9b38aef2018-08-27 15:42:25 -07001180 false, nil, nil)
Colin Crosse9a275b2017-10-16 17:09:48 -07001181 outputFile = combinedJar
1182 }
Colin Cross0a6e0072017-08-30 14:24:55 -07001183
Colin Cross331a1212018-08-15 20:40:52 -07001184 // jarjar implementation jar if necessary
Steven Morelandc4efd9c2019-01-18 11:51:25 -08001185 if j.expandJarjarRules != nil {
Colin Cross8649b262017-09-27 18:03:17 -07001186 // Transform classes.jar into classes-jarjar.jar
Colin Cross1ee23172017-10-18 14:44:18 -07001187 jarjarFile := android.PathForModuleOut(ctx, "jarjar", jarName)
Steven Morelandc4efd9c2019-01-18 11:51:25 -08001188 TransformJarJar(ctx, jarjarFile, outputFile, j.expandJarjarRules)
Colin Crosse9a275b2017-10-16 17:09:48 -07001189 outputFile = jarjarFile
Colin Cross331a1212018-08-15 20:40:52 -07001190
1191 // jarjar resource jar if necessary
1192 if j.resourceJar != nil {
1193 resourceJarJarFile := android.PathForModuleOut(ctx, "res-jarjar", jarName)
Steven Morelandc4efd9c2019-01-18 11:51:25 -08001194 TransformJarJar(ctx, resourceJarJarFile, j.resourceJar, j.expandJarjarRules)
Colin Cross331a1212018-08-15 20:40:52 -07001195 j.resourceJar = resourceJarJarFile
1196 }
1197
Colin Cross0a6e0072017-08-30 14:24:55 -07001198 if ctx.Failed() {
1199 return
1200 }
1201 }
Nan Zhanged19fc32017-10-19 13:06:22 -07001202 j.implementationJarFile = outputFile
1203 if j.headerJarFile == nil {
1204 j.headerJarFile = j.implementationJarFile
1205 }
Colin Cross2fe66872015-03-30 17:20:39 -07001206
Colin Cross6510f912017-11-29 00:27:14 -08001207 if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
Colin Crosscb933592017-11-22 13:49:43 -08001208 if inList(ctx.ModuleName(), config.InstrumentFrameworkModules) {
1209 j.properties.Instrument = true
1210 }
1211 }
1212
Colin Cross3144dfc2018-01-03 15:06:47 -08001213 if j.shouldInstrument(ctx) {
Colin Crosscb933592017-11-22 13:49:43 -08001214 outputFile = j.instrument(ctx, flags, outputFile, jarName)
1215 }
1216
Colin Cross331a1212018-08-15 20:40:52 -07001217 // merge implementation jar with resources if necessary
1218 implementationAndResourcesJar := outputFile
1219 if j.resourceJar != nil {
1220 jars := android.Paths{implementationAndResourcesJar, j.resourceJar}
1221 combinedJar := android.PathForModuleOut(ctx, "withres", jarName)
1222 TransformJarsToJar(ctx, combinedJar, "for resources", jars, android.OptionalPath{},
1223 false, nil, nil)
1224 implementationAndResourcesJar = combinedJar
1225 }
1226
1227 j.implementationAndResourcesJar = implementationAndResourcesJar
1228
Colin Cross9ae1b922018-06-26 17:59:05 -07001229 if ctx.Device() && (Bool(j.properties.Installable) || Bool(j.deviceProperties.Compile_dex)) {
Colin Cross8faf8fc2019-01-16 15:15:52 -08001230 // Dex compilation
Colin Cross3063b782018-08-15 11:19:12 -07001231 var dexOutputFile android.ModuleOutPath
David Brazdil17ef5632018-06-27 10:27:45 +01001232 dexOutputFile = j.compileDex(ctx, flags, outputFile, jarName)
Colin Cross2fe66872015-03-30 17:20:39 -07001233 if ctx.Failed() {
1234 return
1235 }
Colin Cross331a1212018-08-15 20:40:52 -07001236
Colin Cross8faf8fc2019-01-16 15:15:52 -08001237 // Hidden API CSV generation and dex encoding
Colin Crossf24a22a2019-01-31 14:12:44 -08001238 dexOutputFile = j.hiddenAPI.hiddenAPI(ctx, dexOutputFile, j.implementationJarFile,
1239 j.deviceProperties.UncompressDex)
Colin Cross8faf8fc2019-01-16 15:15:52 -08001240
Colin Cross331a1212018-08-15 20:40:52 -07001241 // merge dex jar with resources if necessary
1242 if j.resourceJar != nil {
1243 jars := android.Paths{dexOutputFile, j.resourceJar}
1244 combinedJar := android.PathForModuleOut(ctx, "dex-withres", jarName)
1245 TransformJarsToJar(ctx, combinedJar, "for dex resources", jars, android.OptionalPath{},
1246 false, nil, nil)
Nicolas Geoffrayf3438722019-01-23 15:57:21 +00001247 if j.deviceProperties.UncompressDex {
1248 combinedAlignedJar := android.PathForModuleOut(ctx, "dex-withres-aligned", jarName)
1249 TransformZipAlign(ctx, combinedAlignedJar, combinedJar)
1250 dexOutputFile = combinedAlignedJar
1251 } else {
1252 dexOutputFile = combinedJar
1253 }
Colin Cross331a1212018-08-15 20:40:52 -07001254 }
1255
1256 j.dexJarFile = dexOutputFile
1257
Colin Cross8faf8fc2019-01-16 15:15:52 -08001258 // Dexpreopting
Colin Cross43f08db2018-11-12 10:13:39 -08001259 dexOutputFile = j.dexpreopt(ctx, dexOutputFile)
1260
1261 j.maybeStrippedDexJarFile = dexOutputFile
1262
Colin Cross3063b782018-08-15 11:19:12 -07001263 outputFile = dexOutputFile
Colin Cross43f08db2018-11-12 10:13:39 -08001264
1265 if ctx.Failed() {
1266 return
1267 }
Colin Cross331a1212018-08-15 20:40:52 -07001268 } else {
1269 outputFile = implementationAndResourcesJar
Colin Cross2fe66872015-03-30 17:20:39 -07001270 }
Colin Cross331a1212018-08-15 20:40:52 -07001271
Colin Crossb7a63242015-04-16 14:09:14 -07001272 ctx.CheckbuildFile(outputFile)
Colin Cross3063b782018-08-15 11:19:12 -07001273
1274 // Save the output file with no relative path so that it doesn't end up in a subdirectory when used as a resource
1275 j.outputFile = outputFile.WithoutRel()
Colin Cross2fe66872015-03-30 17:20:39 -07001276}
1277
Zoran Jovanovic8736ce22018-08-21 17:10:29 +02001278// Check for invalid kotlinc flags. Only use this for flags explicitly passed by the user,
1279// since some of these flags may be used internally.
1280func CheckKotlincFlags(ctx android.ModuleContext, flags []string) {
1281 for _, flag := range flags {
1282 flag = strings.TrimSpace(flag)
1283
1284 if !strings.HasPrefix(flag, "-") {
1285 ctx.PropertyErrorf("kotlincflags", "Flag `%s` must start with `-`", flag)
1286 } else if strings.HasPrefix(flag, "-Xintellij-plugin-root") {
1287 ctx.PropertyErrorf("kotlincflags",
1288 "Bad flag: `%s`, only use internal compiler for consistency.", flag)
1289 } else if inList(flag, config.KotlincIllegalFlags) {
1290 ctx.PropertyErrorf("kotlincflags", "Flag `%s` already used by build system", flag)
1291 } else if flag == "-include-runtime" {
1292 ctx.PropertyErrorf("kotlincflags", "Bad flag: `%s`, do not include runtime.", flag)
1293 } else {
1294 args := strings.Split(flag, " ")
1295 if args[0] == "-kotlin-home" {
1296 ctx.PropertyErrorf("kotlincflags",
1297 "Bad flag: `%s`, kotlin home already set to default (path to kotlinc in the repo).", flag)
1298 }
1299 }
1300 }
1301}
1302
Colin Cross8eadbf02017-10-24 17:46:00 -07001303func (j *Module) compileJavaHeader(ctx android.ModuleContext, srcFiles, srcJars android.Paths,
Colin Cross55f63ea2018-08-27 12:37:09 -07001304 deps deps, flags javaBuilderFlags, jarName string, extraJars android.Paths) android.Path {
Nan Zhanged19fc32017-10-19 13:06:22 -07001305
1306 var jars android.Paths
Colin Cross8eadbf02017-10-24 17:46:00 -07001307 if len(srcFiles) > 0 || len(srcJars) > 0 {
Nan Zhanged19fc32017-10-19 13:06:22 -07001308 // Compile java sources into turbine.jar.
1309 turbineJar := android.PathForModuleOut(ctx, "turbine", jarName)
1310 TransformJavaToHeaderClasses(ctx, turbineJar, srcFiles, srcJars, flags)
1311 if ctx.Failed() {
1312 return nil
1313 }
1314 jars = append(jars, turbineJar)
1315 }
1316
Colin Cross55f63ea2018-08-27 12:37:09 -07001317 jars = append(jars, extraJars...)
1318
Nan Zhanged19fc32017-10-19 13:06:22 -07001319 // Combine any static header libraries into classes-header.jar. If there is only
1320 // one input jar this step will be skipped.
1321 var headerJar android.Path
1322 jars = append(jars, deps.staticHeaderJars...)
1323
Colin Cross5c6ecc12017-10-23 18:12:27 -07001324 // we cannot skip the combine step for now if there is only one jar
1325 // since we have to strip META-INF/TRANSITIVE dir from turbine.jar
1326 combinedJar := android.PathForModuleOut(ctx, "turbine-combined", jarName)
Colin Cross37f6d792018-07-12 12:28:41 -07001327 TransformJarsToJar(ctx, combinedJar, "for turbine", jars, android.OptionalPath{},
1328 false, nil, []string{"META-INF"})
Colin Cross5c6ecc12017-10-23 18:12:27 -07001329 headerJar = combinedJar
Nan Zhanged19fc32017-10-19 13:06:22 -07001330
Steven Morelandc4efd9c2019-01-18 11:51:25 -08001331 if j.expandJarjarRules != nil {
Nan Zhanged19fc32017-10-19 13:06:22 -07001332 // Transform classes.jar into classes-jarjar.jar
1333 jarjarFile := android.PathForModuleOut(ctx, "turbine-jarjar", jarName)
Steven Morelandc4efd9c2019-01-18 11:51:25 -08001334 TransformJarJar(ctx, jarjarFile, headerJar, j.expandJarjarRules)
Nan Zhanged19fc32017-10-19 13:06:22 -07001335 headerJar = jarjarFile
1336 if ctx.Failed() {
1337 return nil
1338 }
1339 }
1340
1341 return headerJar
1342}
1343
Colin Crosscb933592017-11-22 13:49:43 -08001344func (j *Module) instrument(ctx android.ModuleContext, flags javaBuilderFlags,
Colin Cross3063b782018-08-15 11:19:12 -07001345 classesJar android.Path, jarName string) android.ModuleOutPath {
Colin Crosscb933592017-11-22 13:49:43 -08001346
Colin Cross7a3139e2017-12-19 13:57:50 -08001347 specs := j.jacocoModuleToZipCommand(ctx)
Colin Crosscb933592017-11-22 13:49:43 -08001348
Colin Cross84c38822018-01-03 15:59:46 -08001349 jacocoReportClassesFile := android.PathForModuleOut(ctx, "jacoco-report-classes", jarName)
Colin Crosscb933592017-11-22 13:49:43 -08001350 instrumentedJar := android.PathForModuleOut(ctx, "jacoco", jarName)
1351
1352 jacocoInstrumentJar(ctx, instrumentedJar, jacocoReportClassesFile, classesJar, specs)
1353
1354 j.jacocoReportClassesFile = jacocoReportClassesFile
1355
1356 return instrumentedJar
1357}
1358
albaltai36ff7dc2018-12-25 14:35:23 +08001359var _ Dependency = (*Module)(nil)
Colin Cross2fe66872015-03-30 17:20:39 -07001360
Nan Zhanged19fc32017-10-19 13:06:22 -07001361func (j *Module) HeaderJars() android.Paths {
albaltai36ff7dc2018-12-25 14:35:23 +08001362 if j.headerJarFile == nil {
1363 return nil
1364 }
Nan Zhanged19fc32017-10-19 13:06:22 -07001365 return android.Paths{j.headerJarFile}
1366}
1367
1368func (j *Module) ImplementationJars() android.Paths {
shinwang9e4c07a2018-12-24 15:41:04 +08001369 if j.implementationJarFile == nil {
1370 return nil
1371 }
Nan Zhanged19fc32017-10-19 13:06:22 -07001372 return android.Paths{j.implementationJarFile}
Colin Cross2fe66872015-03-30 17:20:39 -07001373}
1374
Colin Crossf24a22a2019-01-31 14:12:44 -08001375func (j *Module) DexJar() android.Path {
1376 return j.dexJarFile
1377}
1378
Colin Cross331a1212018-08-15 20:40:52 -07001379func (j *Module) ResourceJars() android.Paths {
1380 if j.resourceJar == nil {
1381 return nil
1382 }
1383 return android.Paths{j.resourceJar}
1384}
1385
1386func (j *Module) ImplementationAndResourcesJars() android.Paths {
albaltai36ff7dc2018-12-25 14:35:23 +08001387 if j.implementationAndResourcesJar == nil {
1388 return nil
1389 }
Colin Cross331a1212018-08-15 20:40:52 -07001390 return android.Paths{j.implementationAndResourcesJar}
1391}
1392
Colin Cross46c9b8b2017-06-22 16:51:17 -07001393func (j *Module) AidlIncludeDirs() android.Paths {
albaltai36ff7dc2018-12-25 14:35:23 +08001394 // exportAidlIncludeDirs is type android.Paths already
Colin Crossc0b06f12015-04-08 13:03:43 -07001395 return j.exportAidlIncludeDirs
1396}
1397
Jiyong Park1be96912018-05-28 18:02:19 +09001398func (j *Module) ExportedSdkLibs() []string {
albaltai36ff7dc2018-12-25 14:35:23 +08001399 // exportedSdkLibs is type []string
Jiyong Park1be96912018-05-28 18:02:19 +09001400 return j.exportedSdkLibs
1401}
1402
Colin Cross46c9b8b2017-06-22 16:51:17 -07001403var _ logtagsProducer = (*Module)(nil)
Colin Crossf05fe972015-04-10 17:45:20 -07001404
Colin Cross46c9b8b2017-06-22 16:51:17 -07001405func (j *Module) logtags() android.Paths {
Colin Crossf05fe972015-04-10 17:45:20 -07001406 return j.logtagsSrcs
1407}
1408
Brandon Lee5d45c6f2018-08-15 15:35:38 -07001409// Collect information for opening IDE project files in java/jdeps.go.
1410func (j *Module) IDEInfo(dpInfo *android.IdeInfo) {
1411 dpInfo.Deps = append(dpInfo.Deps, j.CompilerDeps()...)
1412 dpInfo.Srcs = append(dpInfo.Srcs, j.expandIDEInfoCompiledSrcs...)
1413 dpInfo.Aidl_include_dirs = append(dpInfo.Aidl_include_dirs, j.deviceProperties.Aidl.Include_dirs...)
Steven Morelandc4efd9c2019-01-18 11:51:25 -08001414 if j.expandJarjarRules != nil {
1415 dpInfo.Jarjar_rules = append(dpInfo.Jarjar_rules, j.expandJarjarRules.String())
Brandon Lee5d45c6f2018-08-15 15:35:38 -07001416 }
1417}
1418
1419func (j *Module) CompilerDeps() []string {
1420 jdeps := []string{}
1421 jdeps = append(jdeps, j.properties.Libs...)
1422 jdeps = append(jdeps, j.properties.Static_libs...)
1423 return jdeps
1424}
1425
Colin Cross2fe66872015-03-30 17:20:39 -07001426//
1427// Java libraries (.jar file)
1428//
1429
Colin Crossf506d872017-07-19 15:53:04 -07001430type Library struct {
Colin Cross46c9b8b2017-06-22 16:51:17 -07001431 Module
Colin Cross2fe66872015-03-30 17:20:39 -07001432}
1433
Colin Cross2fc72f62018-12-21 12:59:54 -08001434func (j *Library) shouldUncompressDex(ctx android.ModuleContext) bool {
Nicolas Geoffrayfa6e9ec2019-02-12 13:12:16 +00001435 // Store uncompressed (and do not strip) dex files from boot class path jars.
1436 if inList(ctx.ModuleName(), ctx.Config().BootJars()) {
1437 return true
1438 }
1439
1440 // Store uncompressed dex files that are preopted on /system.
1441 if !j.dexpreopter.dexpreoptDisabled(ctx) && (ctx.Host() || !odexOnSystemOther(ctx, j.dexpreopter.installPath)) {
Vladimir Markoe8b00d62018-12-21 15:54:16 +00001442 return true
1443 }
Colin Cross083a2aa2019-02-06 16:37:12 -08001444 if ctx.Config().UncompressPrivAppDex() &&
1445 inList(ctx.ModuleName(), ctx.Config().ModulesLoadedByPrivilegedModules()) {
1446 return true
1447 }
1448
Colin Cross2fc72f62018-12-21 12:59:54 -08001449 return false
1450}
1451
Colin Crossf506d872017-07-19 15:53:04 -07001452func (j *Library) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross43f08db2018-11-12 10:13:39 -08001453 j.dexpreopter.installPath = android.PathForModuleInstall(ctx, "framework", ctx.ModuleName()+".jar")
1454 j.dexpreopter.isSDKLibrary = j.deviceProperties.IsSDKLibrary
Nicolas Geoffrayfa6e9ec2019-02-12 13:12:16 +00001455 j.dexpreopter.isInstallable = Bool(j.properties.Installable)
1456 j.dexpreopter.uncompressedDex = j.shouldUncompressDex(ctx)
1457 j.deviceProperties.UncompressDex = j.dexpreopter.uncompressedDex
Colin Cross46c9b8b2017-06-22 16:51:17 -07001458 j.compile(ctx)
Colin Crossb7a63242015-04-16 14:09:14 -07001459
Nicolas Geoffray4bdea392019-01-15 11:48:08 +00001460 if (Bool(j.properties.Installable) || ctx.Host()) && !android.DirectlyInAnyApex(ctx, ctx.ModuleName()) {
Colin Cross2c429dc2017-08-31 16:45:16 -07001461 j.installFile = ctx.InstallFile(android.PathForModuleInstall(ctx, "framework"),
1462 ctx.ModuleName()+".jar", j.outputFile)
1463 }
Colin Crossb7a63242015-04-16 14:09:14 -07001464}
1465
Colin Crossf506d872017-07-19 15:53:04 -07001466func (j *Library) DepsMutator(ctx android.BottomUpMutatorContext) {
Colin Cross46c9b8b2017-06-22 16:51:17 -07001467 j.deps(ctx)
1468}
1469
Colin Cross1b16b0e2019-02-12 14:41:32 -08001470// java_library builds and links sources into a `.jar` file for the device, and possibly for the host as well.
1471//
1472// By default, a java_library has a single variant that produces a `.jar` file containing `.class` files that were
1473// compiled against the device bootclasspath. This jar is not suitable for installing on a device, but can be used
1474// as a `static_libs` dependency of another module.
1475//
1476// Specifying `installable: true` will product a `.jar` file containing `classes.dex` files, suitable for installing on
1477// a device.
1478//
1479// Specifying `host_supported: true` will produce two variants, one compiled against the device bootclasspath and one
1480// compiled against the host bootclasspath.
Colin Cross9ae1b922018-06-26 17:59:05 -07001481func LibraryFactory() android.Module {
1482 module := &Library{}
Colin Cross2fe66872015-03-30 17:20:39 -07001483
Colin Cross9ae1b922018-06-26 17:59:05 -07001484 module.AddProperties(
1485 &module.Module.properties,
1486 &module.Module.deviceProperties,
Colin Cross43f08db2018-11-12 10:13:39 -08001487 &module.Module.dexpreoptProperties,
Colin Cross9ae1b922018-06-26 17:59:05 -07001488 &module.Module.protoProperties)
Colin Cross2fe66872015-03-30 17:20:39 -07001489
Colin Cross9ae1b922018-06-26 17:59:05 -07001490 InitJavaModule(module, android.HostAndDeviceSupported)
1491 return module
Colin Cross2fe66872015-03-30 17:20:39 -07001492}
1493
Colin Cross1b16b0e2019-02-12 14:41:32 -08001494// java_library_static is an obsolete alias for java_library.
1495func LibraryStaticFactory() android.Module {
1496 return LibraryFactory()
1497}
1498
1499// java_library_host builds and links sources into a `.jar` file for the host.
1500//
1501// A java_library_host has a single variant that produces a `.jar` file containing `.class` files that were
1502// compiled against the host bootclasspath.
Colin Crossf506d872017-07-19 15:53:04 -07001503func LibraryHostFactory() android.Module {
1504 module := &Library{}
Colin Cross2fe66872015-03-30 17:20:39 -07001505
Colin Cross6af17aa2017-09-20 12:59:05 -07001506 module.AddProperties(
1507 &module.Module.properties,
1508 &module.Module.protoProperties)
Colin Cross36242852017-06-23 15:06:31 -07001509
Colin Cross9ae1b922018-06-26 17:59:05 -07001510 module.Module.properties.Installable = proptools.BoolPtr(true)
1511
Colin Cross89536d42017-07-07 14:35:50 -07001512 InitJavaModule(module, android.HostSupported)
Colin Cross36242852017-06-23 15:06:31 -07001513 return module
Colin Cross2fe66872015-03-30 17:20:39 -07001514}
1515
1516//
Colin Crossb628ea52018-08-14 16:42:33 -07001517// Java Tests
Colin Cross05638fc2018-04-09 18:40:24 -07001518//
1519
1520type testProperties struct {
Colin Cross05638fc2018-04-09 18:40:24 -07001521 // list of compatibility suites (for example "cts", "vts") that the module should be
1522 // installed into.
1523 Test_suites []string `android:"arch_variant"`
Julien Despreze146e392018-08-02 15:00:46 -07001524
1525 // the name of the test configuration (for example "AndroidTest.xml") that should be
1526 // installed with the module.
Colin Cross27b922f2019-03-04 22:35:41 -08001527 Test_config *string `android:"path,arch_variant"`
Colin Crossd96ca352018-08-10 16:06:24 -07001528
Jack He33338892018-09-19 02:21:28 -07001529 // the name of the test configuration template (for example "AndroidTestTemplate.xml") that
1530 // should be installed with the module.
Colin Cross27b922f2019-03-04 22:35:41 -08001531 Test_config_template *string `android:"path,arch_variant"`
Jack He33338892018-09-19 02:21:28 -07001532
Colin Crossd96ca352018-08-10 16:06:24 -07001533 // list of files or filegroup modules that provide data that should be installed alongside
1534 // the test
Colin Cross27b922f2019-03-04 22:35:41 -08001535 Data []string `android:"path"`
Colin Cross05638fc2018-04-09 18:40:24 -07001536}
1537
1538type Test struct {
1539 Library
1540
1541 testProperties testProperties
Colin Cross303e21f2018-08-07 16:49:25 -07001542
1543 testConfig android.Path
Colin Crossd96ca352018-08-10 16:06:24 -07001544 data android.Paths
Colin Cross303e21f2018-08-07 16:49:25 -07001545}
1546
1547func (j *Test) GenerateAndroidBuildActions(ctx android.ModuleContext) {
yangbill4f41bc22019-02-13 21:45:47 +08001548 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 -07001549 j.data = ctx.ExpandSources(j.testProperties.Data, nil)
Colin Cross303e21f2018-08-07 16:49:25 -07001550
1551 j.Library.GenerateAndroidBuildActions(ctx)
Colin Cross05638fc2018-04-09 18:40:24 -07001552}
1553
Colin Cross1b16b0e2019-02-12 14:41:32 -08001554// java_test builds a and links sources into a `.jar` file for the device, and possibly for the host as well, and
1555// creates an `AndroidTest.xml` file to allow running the test with `atest` or a `TEST_MAPPING` file.
1556//
1557// By default, a java_test has a single variant that produces a `.jar` file containing `classes.dex` files that were
1558// compiled against the device bootclasspath.
1559//
1560// Specifying `host_supported: true` will produce two variants, one compiled against the device bootclasspath and one
1561// compiled against the host bootclasspath.
Colin Cross05638fc2018-04-09 18:40:24 -07001562func TestFactory() android.Module {
1563 module := &Test{}
1564
1565 module.AddProperties(
1566 &module.Module.properties,
1567 &module.Module.deviceProperties,
Colin Cross43f08db2018-11-12 10:13:39 -08001568 &module.Module.dexpreoptProperties,
Colin Cross05638fc2018-04-09 18:40:24 -07001569 &module.Module.protoProperties,
1570 &module.testProperties)
1571
Colin Cross9ae1b922018-06-26 17:59:05 -07001572 module.Module.properties.Installable = proptools.BoolPtr(true)
Colin Crosse3026872019-01-05 22:30:13 -08001573 module.Module.dexpreopter.isTest = true
Colin Cross9ae1b922018-06-26 17:59:05 -07001574
Colin Cross05638fc2018-04-09 18:40:24 -07001575 InitJavaModule(module, android.HostAndDeviceSupported)
Colin Cross05638fc2018-04-09 18:40:24 -07001576 return module
1577}
1578
Colin Cross1b16b0e2019-02-12 14:41:32 -08001579// java_test_host builds a and links sources into a `.jar` file for the host, and creates an `AndroidTest.xml` file to
1580// allow running the test with `atest` or a `TEST_MAPPING` file.
1581//
1582// A java_test_host has a single variant that produces a `.jar` file containing `.class` files that were
1583// compiled against the host bootclasspath.
Colin Cross05638fc2018-04-09 18:40:24 -07001584func TestHostFactory() android.Module {
1585 module := &Test{}
1586
1587 module.AddProperties(
1588 &module.Module.properties,
1589 &module.Module.protoProperties,
1590 &module.testProperties)
1591
Colin Cross9ae1b922018-06-26 17:59:05 -07001592 module.Module.properties.Installable = proptools.BoolPtr(true)
1593
Colin Cross05638fc2018-04-09 18:40:24 -07001594 InitJavaModule(module, android.HostSupported)
Colin Cross05638fc2018-04-09 18:40:24 -07001595 return module
1596}
1597
1598//
Colin Cross2fe66872015-03-30 17:20:39 -07001599// Java Binaries (.jar file plus wrapper script)
1600//
1601
Colin Crossf506d872017-07-19 15:53:04 -07001602type binaryProperties struct {
Colin Cross7d5136f2015-05-11 13:39:40 -07001603 // installable script to execute the resulting jar
Colin Cross27b922f2019-03-04 22:35:41 -08001604 Wrapper *string `android:"path"`
Colin Cross094054a2018-10-17 15:10:48 -07001605
1606 // Name of the class containing main to be inserted into the manifest as Main-Class.
1607 Main_class *string
Colin Cross7d5136f2015-05-11 13:39:40 -07001608}
1609
Colin Crossf506d872017-07-19 15:53:04 -07001610type Binary struct {
1611 Library
Colin Cross2fe66872015-03-30 17:20:39 -07001612
Colin Crossf506d872017-07-19 15:53:04 -07001613 binaryProperties binaryProperties
Colin Cross10a03492017-08-10 17:09:43 -07001614
Colin Cross6b4a32d2017-12-05 13:42:45 -08001615 isWrapperVariant bool
1616
Colin Crossc3315992017-12-08 19:12:36 -08001617 wrapperFile android.Path
Colin Cross10a03492017-08-10 17:09:43 -07001618 binaryFile android.OutputPath
Colin Cross2fe66872015-03-30 17:20:39 -07001619}
1620
Alex Light24237172017-10-26 09:46:21 -07001621func (j *Binary) HostToolPath() android.OptionalPath {
1622 return android.OptionalPathForPath(j.binaryFile)
1623}
1624
Colin Crossf506d872017-07-19 15:53:04 -07001625func (j *Binary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross6b4a32d2017-12-05 13:42:45 -08001626 if ctx.Arch().ArchType == android.Common {
1627 // Compile the jar
Colin Cross094054a2018-10-17 15:10:48 -07001628 if j.binaryProperties.Main_class != nil {
1629 if j.properties.Manifest != nil {
1630 ctx.PropertyErrorf("main_class", "main_class cannot be used when manifest is set")
1631 }
1632 manifestFile := android.PathForModuleOut(ctx, "manifest.txt")
1633 GenerateMainClassManifest(ctx, manifestFile, String(j.binaryProperties.Main_class))
1634 j.overrideManifest = android.OptionalPathForPath(manifestFile)
1635 }
1636
Colin Cross6b4a32d2017-12-05 13:42:45 -08001637 j.Library.GenerateAndroidBuildActions(ctx)
Nan Zhang3c807db2017-11-03 14:53:31 -07001638 } else {
Colin Cross6b4a32d2017-12-05 13:42:45 -08001639 // Handle the binary wrapper
1640 j.isWrapperVariant = true
1641
Colin Cross366938f2017-12-11 16:29:02 -08001642 if j.binaryProperties.Wrapper != nil {
1643 j.wrapperFile = ctx.ExpandSource(*j.binaryProperties.Wrapper, "wrapper")
Colin Cross6b4a32d2017-12-05 13:42:45 -08001644 } else {
1645 j.wrapperFile = android.PathForSource(ctx, "build/soong/scripts/jar-wrapper.sh")
1646 }
1647
1648 // Depend on the installed jar so that the wrapper doesn't get executed by
1649 // another build rule before the jar has been installed.
1650 jarFile := ctx.PrimaryModule().(*Binary).installFile
1651
1652 j.binaryFile = ctx.InstallExecutable(android.PathForModuleInstall(ctx, "bin"),
1653 ctx.ModuleName(), j.wrapperFile, jarFile)
Nan Zhang3c807db2017-11-03 14:53:31 -07001654 }
Colin Cross2fe66872015-03-30 17:20:39 -07001655}
1656
Colin Crossf506d872017-07-19 15:53:04 -07001657func (j *Binary) DepsMutator(ctx android.BottomUpMutatorContext) {
Colin Cross6b4a32d2017-12-05 13:42:45 -08001658 if ctx.Arch().ArchType == android.Common {
1659 j.deps(ctx)
1660 }
Colin Cross46c9b8b2017-06-22 16:51:17 -07001661}
1662
Colin Cross1b16b0e2019-02-12 14:41:32 -08001663// java_binary builds a `.jar` file and a shell script that executes it for the device, and possibly for the host
1664// as well.
1665//
1666// By default, a java_binary has a single variant that produces a `.jar` file containing `classes.dex` files that were
1667// compiled against the device bootclasspath.
1668//
1669// Specifying `host_supported: true` will produce two variants, one compiled against the device bootclasspath and one
1670// compiled against the host bootclasspath.
Colin Crossf506d872017-07-19 15:53:04 -07001671func BinaryFactory() android.Module {
1672 module := &Binary{}
Colin Cross2fe66872015-03-30 17:20:39 -07001673
Colin Cross36242852017-06-23 15:06:31 -07001674 module.AddProperties(
Colin Cross540eff82017-06-22 17:01:52 -07001675 &module.Module.properties,
1676 &module.Module.deviceProperties,
Colin Cross43f08db2018-11-12 10:13:39 -08001677 &module.Module.dexpreoptProperties,
Colin Cross6af17aa2017-09-20 12:59:05 -07001678 &module.Module.protoProperties,
Colin Cross540eff82017-06-22 17:01:52 -07001679 &module.binaryProperties)
Colin Cross36242852017-06-23 15:06:31 -07001680
Colin Cross9ae1b922018-06-26 17:59:05 -07001681 module.Module.properties.Installable = proptools.BoolPtr(true)
1682
Colin Cross6b4a32d2017-12-05 13:42:45 -08001683 android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibCommonFirst)
1684 android.InitDefaultableModule(module)
Colin Cross36242852017-06-23 15:06:31 -07001685 return module
Colin Cross2fe66872015-03-30 17:20:39 -07001686}
1687
Colin Cross1b16b0e2019-02-12 14:41:32 -08001688// java_binary_host builds a `.jar` file and a shell script that executes it for the host.
1689//
1690// A java_binary_host has a single variant that produces a `.jar` file containing `.class` files that were
1691// compiled against the host bootclasspath.
Colin Crossf506d872017-07-19 15:53:04 -07001692func BinaryHostFactory() android.Module {
1693 module := &Binary{}
Colin Cross2fe66872015-03-30 17:20:39 -07001694
Colin Cross36242852017-06-23 15:06:31 -07001695 module.AddProperties(
Colin Cross540eff82017-06-22 17:01:52 -07001696 &module.Module.properties,
Colin Cross6af17aa2017-09-20 12:59:05 -07001697 &module.Module.protoProperties,
Colin Cross540eff82017-06-22 17:01:52 -07001698 &module.binaryProperties)
Colin Cross36242852017-06-23 15:06:31 -07001699
Colin Cross9ae1b922018-06-26 17:59:05 -07001700 module.Module.properties.Installable = proptools.BoolPtr(true)
1701
Colin Cross6b4a32d2017-12-05 13:42:45 -08001702 android.InitAndroidArchModule(module, android.HostSupported, android.MultilibCommonFirst)
1703 android.InitDefaultableModule(module)
Colin Cross36242852017-06-23 15:06:31 -07001704 return module
Colin Cross2fe66872015-03-30 17:20:39 -07001705}
1706
1707//
1708// Java prebuilts
1709//
1710
Colin Cross74d73e22017-08-02 11:05:49 -07001711type ImportProperties struct {
Colin Cross27b922f2019-03-04 22:35:41 -08001712 Jars []string `android:"path"`
Colin Cross461bd1a2017-10-20 13:59:18 -07001713
Nan Zhangea568a42017-11-08 21:20:04 -08001714 Sdk_version *string
Colin Cross535e2cf2017-10-20 17:57:49 -07001715
1716 Installable *bool
Jiyong Park1be96912018-05-28 18:02:19 +09001717
1718 // List of shared java libs that this module has dependencies to
1719 Libs []string
Colin Cross37f6d792018-07-12 12:28:41 -07001720
1721 // List of files to remove from the jar file(s)
1722 Exclude_files []string
1723
1724 // List of directories to remove from the jar file(s)
1725 Exclude_dirs []string
Nan Zhang4c819fb2018-08-27 18:31:46 -07001726
1727 // if set to true, run Jetifier against .jar file. Defaults to false.
1728 Jetifier_enabled *bool
Colin Cross74d73e22017-08-02 11:05:49 -07001729}
1730
1731type Import struct {
Colin Cross635c3b02016-05-18 15:37:25 -07001732 android.ModuleBase
Colin Cross48de9a42018-10-02 13:53:33 -07001733 android.DefaultableModuleBase
Colin Crossec7a0422017-07-07 14:47:12 -07001734 prebuilt android.Prebuilt
Colin Cross2fe66872015-03-30 17:20:39 -07001735
Colin Cross74d73e22017-08-02 11:05:49 -07001736 properties ImportProperties
1737
Colin Cross0a6e0072017-08-30 14:24:55 -07001738 combinedClasspathFile android.Path
Jiyong Park1be96912018-05-28 18:02:19 +09001739 exportedSdkLibs []string
Colin Cross2fe66872015-03-30 17:20:39 -07001740}
1741
Colin Cross83bb3162018-06-25 15:48:06 -07001742func (j *Import) sdkVersion() string {
1743 return String(j.properties.Sdk_version)
1744}
1745
1746func (j *Import) minSdkVersion() string {
1747 return j.sdkVersion()
1748}
1749
Colin Cross74d73e22017-08-02 11:05:49 -07001750func (j *Import) Prebuilt() *android.Prebuilt {
Colin Crossec7a0422017-07-07 14:47:12 -07001751 return &j.prebuilt
1752}
1753
Colin Cross74d73e22017-08-02 11:05:49 -07001754func (j *Import) PrebuiltSrcs() []string {
1755 return j.properties.Jars
1756}
1757
1758func (j *Import) Name() string {
Colin Cross5ea9bcc2017-07-27 15:41:32 -07001759 return j.prebuilt.Name(j.ModuleBase.Name())
1760}
1761
Colin Cross74d73e22017-08-02 11:05:49 -07001762func (j *Import) DepsMutator(ctx android.BottomUpMutatorContext) {
Colin Cross42d48b72018-08-29 14:10:52 -07001763 ctx.AddVariationDependencies(nil, libTag, j.properties.Libs...)
Colin Cross1e676be2016-10-12 14:38:15 -07001764}
1765
Colin Cross74d73e22017-08-02 11:05:49 -07001766func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross37f6d792018-07-12 12:28:41 -07001767 jars := ctx.ExpandSources(j.properties.Jars, nil)
Colin Crosse1d62a82015-04-03 16:53:05 -07001768
Nan Zhang4c819fb2018-08-27 18:31:46 -07001769 jarName := ctx.ModuleName() + ".jar"
1770 outputFile := android.PathForModuleOut(ctx, "combined", jarName)
Colin Cross37f6d792018-07-12 12:28:41 -07001771 TransformJarsToJar(ctx, outputFile, "for prebuilts", jars, android.OptionalPath{},
1772 false, j.properties.Exclude_files, j.properties.Exclude_dirs)
Nan Zhang4c819fb2018-08-27 18:31:46 -07001773 if Bool(j.properties.Jetifier_enabled) {
1774 inputFile := outputFile
1775 outputFile = android.PathForModuleOut(ctx, "jetifier", jarName)
1776 TransformJetifier(ctx, outputFile, inputFile)
1777 }
Colin Crosse9a275b2017-10-16 17:09:48 -07001778 j.combinedClasspathFile = outputFile
Jiyong Park1be96912018-05-28 18:02:19 +09001779
1780 ctx.VisitDirectDeps(func(module android.Module) {
1781 otherName := ctx.OtherModuleName(module)
1782 tag := ctx.OtherModuleDependencyTag(module)
1783
1784 switch dep := module.(type) {
1785 case Dependency:
1786 switch tag {
1787 case libTag, staticLibTag:
1788 // sdk lib names from dependencies are re-exported
1789 j.exportedSdkLibs = append(j.exportedSdkLibs, dep.ExportedSdkLibs()...)
1790 }
1791 case SdkLibraryDependency:
1792 switch tag {
1793 case libTag:
1794 // names of sdk libs that are directly depended are exported
1795 j.exportedSdkLibs = append(j.exportedSdkLibs, otherName)
1796 }
1797 }
1798 })
1799
1800 j.exportedSdkLibs = android.FirstUniqueStrings(j.exportedSdkLibs)
Nan Zhang4973ecf2018-08-10 13:42:12 -07001801 if Bool(j.properties.Installable) {
1802 ctx.InstallFile(android.PathForModuleInstall(ctx, "framework"),
1803 ctx.ModuleName()+".jar", outputFile)
1804 }
Colin Cross2fe66872015-03-30 17:20:39 -07001805}
1806
Colin Cross74d73e22017-08-02 11:05:49 -07001807var _ Dependency = (*Import)(nil)
Colin Cross2fe66872015-03-30 17:20:39 -07001808
Nan Zhanged19fc32017-10-19 13:06:22 -07001809func (j *Import) HeaderJars() android.Paths {
albaltai36ff7dc2018-12-25 14:35:23 +08001810 if j.combinedClasspathFile == nil {
1811 return nil
1812 }
Colin Cross37f6d792018-07-12 12:28:41 -07001813 return android.Paths{j.combinedClasspathFile}
Nan Zhanged19fc32017-10-19 13:06:22 -07001814}
1815
1816func (j *Import) ImplementationJars() android.Paths {
shinwang9e4c07a2018-12-24 15:41:04 +08001817 if j.combinedClasspathFile == nil {
1818 return nil
1819 }
Colin Cross37f6d792018-07-12 12:28:41 -07001820 return android.Paths{j.combinedClasspathFile}
Colin Cross2fe66872015-03-30 17:20:39 -07001821}
1822
Colin Cross331a1212018-08-15 20:40:52 -07001823func (j *Import) ResourceJars() android.Paths {
1824 return nil
1825}
1826
1827func (j *Import) ImplementationAndResourcesJars() android.Paths {
albaltai36ff7dc2018-12-25 14:35:23 +08001828 if j.combinedClasspathFile == nil {
1829 return nil
1830 }
Colin Cross331a1212018-08-15 20:40:52 -07001831 return android.Paths{j.combinedClasspathFile}
1832}
1833
Colin Crossf24a22a2019-01-31 14:12:44 -08001834func (j *Import) DexJar() android.Path {
1835 return nil
1836}
1837
Colin Cross74d73e22017-08-02 11:05:49 -07001838func (j *Import) AidlIncludeDirs() android.Paths {
Colin Crossc0b06f12015-04-08 13:03:43 -07001839 return nil
1840}
1841
Jiyong Park1be96912018-05-28 18:02:19 +09001842func (j *Import) ExportedSdkLibs() []string {
1843 return j.exportedSdkLibs
1844}
1845
albaltai36ff7dc2018-12-25 14:35:23 +08001846// Add compile time check for interface implementation
1847var _ android.IDEInfo = (*Import)(nil)
1848var _ android.IDECustomizedModuleName = (*Import)(nil)
1849
Brandon Lee5d45c6f2018-08-15 15:35:38 -07001850// Collect information for opening IDE project files in java/jdeps.go.
1851const (
1852 removedPrefix = "prebuilt_"
1853)
1854
1855func (j *Import) IDEInfo(dpInfo *android.IdeInfo) {
1856 dpInfo.Jars = append(dpInfo.Jars, j.PrebuiltSrcs()...)
1857}
1858
1859func (j *Import) IDECustomizedModuleName() string {
1860 // TODO(b/113562217): Extract the base module name from the Import name, often the Import name
1861 // has a prefix "prebuilt_". Remove the prefix explicitly if needed until we find a better
1862 // solution to get the Import name.
1863 name := j.Name()
1864 if strings.HasPrefix(name, removedPrefix) {
patricktubb640e02018-10-11 18:33:16 +08001865 name = strings.TrimPrefix(name, removedPrefix)
Brandon Lee5d45c6f2018-08-15 15:35:38 -07001866 }
1867 return name
1868}
1869
Colin Cross74d73e22017-08-02 11:05:49 -07001870var _ android.PrebuiltInterface = (*Import)(nil)
Colin Cross2fe66872015-03-30 17:20:39 -07001871
Colin Cross1b16b0e2019-02-12 14:41:32 -08001872// java_import imports one or more `.jar` files into the build graph as if they were built by a java_library module.
1873//
1874// By default, a java_import has a single variant that expects a `.jar` file containing `.class` files that were
1875// compiled against an Android classpath.
1876//
1877// Specifying `host_supported: true` will produce two variants, one for use as a dependency of device modules and one
1878// for host modules.
Colin Cross74d73e22017-08-02 11:05:49 -07001879func ImportFactory() android.Module {
1880 module := &Import{}
Colin Cross36242852017-06-23 15:06:31 -07001881
Colin Cross74d73e22017-08-02 11:05:49 -07001882 module.AddProperties(&module.properties)
1883
1884 android.InitPrebuiltModule(module, &module.properties.Jars)
Colin Cross48de9a42018-10-02 13:53:33 -07001885 InitJavaModule(module, android.HostAndDeviceSupported)
Colin Cross36242852017-06-23 15:06:31 -07001886 return module
Colin Cross2fe66872015-03-30 17:20:39 -07001887}
1888
Colin Cross1b16b0e2019-02-12 14:41:32 -08001889// java_import imports one or more `.jar` files into the build graph as if they were built by a java_library_host
1890// module.
1891//
1892// A java_import_host has a single variant that expects a `.jar` file containing `.class` files that were
1893// compiled against a host bootclasspath.
Colin Cross74d73e22017-08-02 11:05:49 -07001894func ImportFactoryHost() android.Module {
1895 module := &Import{}
1896
1897 module.AddProperties(&module.properties)
1898
1899 android.InitPrebuiltModule(module, &module.properties.Jars)
Colin Cross48de9a42018-10-02 13:53:33 -07001900 InitJavaModule(module, android.HostSupported)
Colin Cross74d73e22017-08-02 11:05:49 -07001901 return module
1902}
1903
Colin Cross89536d42017-07-07 14:35:50 -07001904//
1905// Defaults
1906//
1907type Defaults struct {
1908 android.ModuleBase
1909 android.DefaultsModuleBase
1910}
1911
1912func (*Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1913}
1914
Colin Cross1b16b0e2019-02-12 14:41:32 -08001915// java_defaults provides a set of properties that can be inherited by other java or android modules.
1916//
1917// A module can use the properties from a java_defaults module using `defaults: ["defaults_module_name"]`. Each
1918// property in the defaults module that exists in the depending module will be prepended to the depending module's
1919// value for that property.
1920//
1921// Example:
1922//
1923// java_defaults {
1924// name: "example_defaults",
1925// srcs: ["common/**/*.java"],
1926// javacflags: ["-Xlint:all"],
1927// aaptflags: ["--auto-add-overlay"],
1928// }
1929//
1930// java_library {
1931// name: "example",
1932// defaults: ["example_defaults"],
1933// srcs: ["example/**/*.java"],
1934// }
1935//
1936// is functionally identical to:
1937//
1938// java_library {
1939// name: "example",
1940// srcs: [
1941// "common/**/*.java",
1942// "example/**/*.java",
1943// ],
1944// javacflags: ["-Xlint:all"],
1945// }
Colin Cross89536d42017-07-07 14:35:50 -07001946func defaultsFactory() android.Module {
1947 return DefaultsFactory()
1948}
1949
1950func DefaultsFactory(props ...interface{}) android.Module {
1951 module := &Defaults{}
1952
1953 module.AddProperties(props...)
1954 module.AddProperties(
1955 &CompilerProperties{},
1956 &CompilerDeviceProperties{},
Colin Cross43f08db2018-11-12 10:13:39 -08001957 &DexpreoptProperties{},
Dan Willemsen6424d172018-03-08 13:27:59 -08001958 &android.ProtoProperties{},
Colin Cross48de9a42018-10-02 13:53:33 -07001959 &aaptProperties{},
1960 &androidLibraryProperties{},
1961 &appProperties{},
1962 &appTestProperties{},
1963 &ImportProperties{},
1964 &AARImportProperties{},
1965 &sdkLibraryProperties{},
Colin Cross89536d42017-07-07 14:35:50 -07001966 )
1967
1968 android.InitDefaultsModule(module)
1969
1970 return module
1971}
Nan Zhangea568a42017-11-08 21:20:04 -08001972
1973var Bool = proptools.Bool
Colin Cross38b40df2018-04-10 16:14:46 -07001974var BoolDefault = proptools.BoolDefault
Nan Zhangea568a42017-11-08 21:20:04 -08001975var String = proptools.String
Colin Cross0d0ba592018-02-20 13:33:42 -08001976var inList = android.InList