blob: ecc360896e797f01b909c90c2835f5d093fd2177 [file] [log] [blame]
Colin Cross2fe66872015-03-30 17:20:39 -07001// Copyright 2015 Google Inc. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package java
16
17// This file contains the module types for compiling Java for Android, and converts the properties
Colin Cross46c9b8b2017-06-22 16:51:17 -070018// into the flags and filenames necessary to pass to the Module. The final creation of the rules
Colin Cross2fe66872015-03-30 17:20:39 -070019// is handled in builder.go
20
21import (
Colin Crossf19b9bb2018-03-26 14:42:44 -070022 "fmt"
Colin Crossfc3674a2017-09-18 17:41:52 -070023 "path/filepath"
Colin Cross74d73e22017-08-02 11:05:49 -070024 "strconv"
Colin Cross2fe66872015-03-30 17:20:39 -070025 "strings"
26
27 "github.com/google/blueprint"
Colin Cross76b5f0c2017-08-29 16:02:06 -070028 "github.com/google/blueprint/proptools"
Colin Cross2fe66872015-03-30 17:20:39 -070029
Colin Cross635c3b02016-05-18 15:37:25 -070030 "android/soong/android"
Colin Cross3e3e72d2017-06-22 17:20:19 -070031 "android/soong/java/config"
Colin Cross303e21f2018-08-07 16:49:25 -070032 "android/soong/tradefed"
Colin Cross2fe66872015-03-30 17:20:39 -070033)
34
Colin Cross463a90e2015-06-17 14:20:06 -070035func init() {
Colin Cross89536d42017-07-07 14:35:50 -070036 android.RegisterModuleType("java_defaults", defaultsFactory)
37
Colin Cross9ae1b922018-06-26 17:59:05 -070038 android.RegisterModuleType("java_library", LibraryFactory)
Colin Cross1b16b0e2019-02-12 14:41:32 -080039 android.RegisterModuleType("java_library_static", LibraryStaticFactory)
Colin Crossf506d872017-07-19 15:53:04 -070040 android.RegisterModuleType("java_library_host", LibraryHostFactory)
41 android.RegisterModuleType("java_binary", BinaryFactory)
42 android.RegisterModuleType("java_binary_host", BinaryHostFactory)
Colin Cross05638fc2018-04-09 18:40:24 -070043 android.RegisterModuleType("java_test", TestFactory)
44 android.RegisterModuleType("java_test_host", TestHostFactory)
Colin Cross74d73e22017-08-02 11:05:49 -070045 android.RegisterModuleType("java_import", ImportFactory)
46 android.RegisterModuleType("java_import_host", ImportFactoryHost)
Colin Cross463a90e2015-06-17 14:20:06 -070047
Colin Cross798bfce2016-10-12 14:28:16 -070048 android.RegisterSingletonType("logtags", LogtagsSingleton)
Colin Cross463a90e2015-06-17 14:20:06 -070049}
50
Colin Cross2fe66872015-03-30 17:20:39 -070051// TODO:
52// Autogenerated files:
Colin Cross2fe66872015-03-30 17:20:39 -070053// Renderscript
54// Post-jar passes:
55// Proguard
Colin Cross2fe66872015-03-30 17:20:39 -070056// Rmtypedefs
Colin Cross2fe66872015-03-30 17:20:39 -070057// DroidDoc
58// Findbugs
59
Colin Cross89536d42017-07-07 14:35:50 -070060type CompilerProperties struct {
Colin Cross7d5136f2015-05-11 13:39:40 -070061 // list of source files used to compile the Java module. May be .java, .logtags, .proto,
62 // or .aidl files.
Dan Willemsen2ef08f42015-06-30 18:15:24 -070063 Srcs []string `android:"arch_variant"`
64
65 // list of source files that should not be used to build the Java module.
66 // This is most useful in the arch/multilib variants to remove non-common files
67 Exclude_srcs []string `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -070068
69 // list of directories containing Java resources
Colin Cross86a63ff2017-09-27 17:33:10 -070070 Java_resource_dirs []string `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -070071
Colin Cross86a63ff2017-09-27 17:33:10 -070072 // list of directories that should be excluded from java_resource_dirs
73 Exclude_java_resource_dirs []string `android:"arch_variant"`
Dan Willemsen2ef08f42015-06-30 18:15:24 -070074
Colin Cross0f37af02017-09-27 17:42:05 -070075 // list of files to use as Java resources
76 Java_resources []string `android:"arch_variant"`
77
Colin Crosscedd4762018-09-13 11:26:19 -070078 // list of files that should be excluded from java_resources and java_resource_dirs
Colin Cross0f37af02017-09-27 17:42:05 -070079 Exclude_java_resources []string `android:"arch_variant"`
80
Paul Duffin2fbbfb82019-02-13 12:49:33 +000081 // don't build against the default libraries (bootclasspath, ext, and framework for device
82 // targets)
Colin Cross76b5f0c2017-08-29 16:02:06 -070083 No_standard_libs *bool
Colin Cross7d5136f2015-05-11 13:39:40 -070084
Paul Duffin2fbbfb82019-02-13 12:49:33 +000085 // don't build against the framework libraries (ext, and framework for device targets)
Colin Crossfa5eb232017-10-01 20:33:03 -070086 No_framework_libs *bool
87
Colin Cross7d5136f2015-05-11 13:39:40 -070088 // list of module-specific flags that will be used for javac compiles
89 Javacflags []string `android:"arch_variant"`
90
Zoran Jovanovic8736ce22018-08-21 17:10:29 +020091 // list of module-specific flags that will be used for kotlinc compiles
92 Kotlincflags []string `android:"arch_variant"`
93
Colin Cross7d5136f2015-05-11 13:39:40 -070094 // list of of java libraries that will be in the classpath
Colin Crosse8dc34a2017-07-19 11:22:16 -070095 Libs []string `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -070096
97 // list of java libraries that will be compiled into the resulting jar
Colin Crosse8dc34a2017-07-19 11:22:16 -070098 Static_libs []string `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -070099
100 // manifest file to be included in resulting jar
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700101 Manifest *string
Colin Cross7d5136f2015-05-11 13:39:40 -0700102
Colin Cross540eff82017-06-22 17:01:52 -0700103 // if not blank, run jarjar using the specified rules file
Colin Cross975f9f72017-10-17 13:55:55 -0700104 Jarjar_rules *string `android:"arch_variant"`
Colin Cross64162712017-08-08 13:17:59 -0700105
106 // If not blank, set the java version passed to javac as -source and -target
107 Java_version *string
Colin Cross2c429dc2017-08-31 16:45:16 -0700108
Colin Cross9ae1b922018-06-26 17:59:05 -0700109 // If set to true, allow this module to be dexed and installed on devices. Has no
110 // effect on host modules, which are always considered installable.
Colin Cross2c429dc2017-08-31 16:45:16 -0700111 Installable *bool
Colin Cross32f676a2017-09-06 13:41:06 -0700112
Colin Cross0f37af02017-09-27 17:42:05 -0700113 // If set to true, include sources used to compile the module in to the final jar
114 Include_srcs *bool
115
Colin Crossbe9cdb82019-01-21 21:37:16 -0800116 // List of modules to use as annotation processors
117 Plugins []string
Colin Cross1369cdb2017-09-29 17:58:17 -0700118
Nan Zhang61eaedb2017-11-02 13:28:15 -0700119 // The number of Java source entries each Javac instance can process
120 Javac_shard_size *int64
121
Nan Zhang5f8cb422018-02-06 10:34:32 -0800122 // Add host jdk tools.jar to bootclasspath
123 Use_tools_jar *bool
124
Colin Cross1369cdb2017-09-29 17:58:17 -0700125 Openjdk9 struct {
126 // List of source files that should only be used when passing -source 1.9
127 Srcs []string
128
129 // List of javac flags that should only be used when passing -source 1.9
130 Javacflags []string
131 }
Colin Crosscb933592017-11-22 13:49:43 -0800132
Colin Cross81440082018-08-15 20:21:55 -0700133 // When compiling language level 9+ .java code in packages that are part of
134 // a system module, patch_module names the module that your sources and
135 // dependencies should be patched into. The Android runtime currently
136 // doesn't implement the JEP 261 module system so this option is only
137 // supported at compile time. It should only be needed to compile tests in
138 // packages that exist in libcore and which are inconvenient to move
139 // elsewhere.
Tobias Thiererdda713d2018-09-19 16:16:19 +0100140 Patch_module *string `android:"arch_variant"`
Colin Cross81440082018-08-15 20:21:55 -0700141
Colin Crosscb933592017-11-22 13:49:43 -0800142 Jacoco struct {
143 // List of classes to include for instrumentation with jacoco to collect coverage
144 // information at runtime when building with coverage enabled. If unset defaults to all
145 // classes.
146 // Supports '*' as the last character of an entry in the list as a wildcard match.
147 // If preceded by '.' it matches all classes in the package and subpackages, otherwise
148 // it matches classes in the package that have the class name as a prefix.
149 Include_filter []string
150
151 // List of classes to exclude from instrumentation with jacoco to collect coverage
152 // information at runtime when building with coverage enabled. Overrides classes selected
153 // by the include_filter property.
154 // Supports '*' as the last character of an entry in the list as a wildcard match.
155 // If preceded by '.' it matches all classes in the package and subpackages, otherwise
156 // it matches classes in the package that have the class name as a prefix.
157 Exclude_filter []string
158 }
159
Andreas Gampef3e5b552018-01-22 21:27:21 -0800160 Errorprone struct {
161 // List of javac flags that should only be used when running errorprone.
162 Javacflags []string
163 }
164
Colin Cross0f2ee152017-12-14 15:22:43 -0800165 Proto struct {
166 // List of extra options that will be passed to the proto generator.
167 Output_params []string
168 }
169
Colin Crosscb933592017-11-22 13:49:43 -0800170 Instrument bool `blueprint:"mutated"`
Alex Light7f004a72019-02-21 13:27:37 -0800171
172 // List of files to include in the META-INF/services folder of the resulting jar.
173 Services []string `android:"arch_variant"`
Colin Cross540eff82017-06-22 17:01:52 -0700174}
175
Colin Cross89536d42017-07-07 14:35:50 -0700176type CompilerDeviceProperties struct {
Colin Cross540eff82017-06-22 17:01:52 -0700177 // list of module-specific flags that will be used for dex compiles
178 Dxflags []string `android:"arch_variant"`
179
Colin Cross83bb3162018-06-25 15:48:06 -0700180 // if not blank, set to the version of the sdk to compile against. Defaults to compiling against the current
181 // sdk if platform_apis is not set.
Nan Zhangea568a42017-11-08 21:20:04 -0800182 Sdk_version *string
Colin Cross7d5136f2015-05-11 13:39:40 -0700183
Colin Cross83bb3162018-06-25 15:48:06 -0700184 // if not blank, set the minimum version of the sdk that the compiled artifacts will run against.
185 // Defaults to sdk_version if not set.
186 Min_sdk_version *string
187
Dan Willemsen419290a2018-10-31 15:28:47 -0700188 // if not blank, set the targetSdkVersion in the AndroidManifest.xml.
189 // Defaults to sdk_version if not set.
190 Target_sdk_version *string
191
Colin Cross6af2e492018-05-22 11:12:33 -0700192 // if true, compile against the platform APIs instead of an SDK.
193 Platform_apis *bool
194
Colin Crossebe1a512017-11-14 13:12:14 -0800195 Aidl struct {
196 // Top level directories to pass to aidl tool
197 Include_dirs []string
Colin Cross7d5136f2015-05-11 13:39:40 -0700198
Colin Crossebe1a512017-11-14 13:12:14 -0800199 // Directories rooted at the Android.bp file to pass to aidl tool
200 Local_include_dirs []string
201
202 // directories that should be added as include directories for any aidl sources of modules
203 // that depend on this module, as well as to aidl for this module.
204 Export_include_dirs []string
Martijn Coeneneab15642018-03-09 09:29:59 +0100205
206 // whether to generate traces (for systrace) for this interface
207 Generate_traces *bool
Olivier Gaillard0a4cfbc2018-07-16 23:37:03 +0100208
209 // whether to generate Binder#GetTransaction name method.
210 Generate_get_transaction_name *bool
Colin Crossebe1a512017-11-14 13:12:14 -0800211 }
Colin Cross92430102017-10-09 14:59:32 -0700212
213 // If true, export a copy of the module as a -hostdex module for host testing.
214 Hostdex *bool
Colin Cross1369cdb2017-09-29 17:58:17 -0700215
David Brazdil17ef5632018-06-27 10:27:45 +0100216 // If set to true, compile dex regardless of installable. Defaults to false.
217 Compile_dex *bool
218
Colin Cross66dbc0b2017-12-28 12:23:20 -0800219 Optimize struct {
Colin Crossae5caf52018-05-22 11:11:52 -0700220 // If false, disable all optimization. Defaults to true for android_app and android_test
221 // modules, false for java_library and java_test modules.
Colin Cross66dbc0b2017-12-28 12:23:20 -0800222 Enabled *bool
223
224 // If true, optimize for size by removing unused code. Defaults to true for apps,
225 // false for libraries and tests.
226 Shrink *bool
227
228 // If true, optimize bytecode. Defaults to false.
229 Optimize *bool
230
231 // If true, obfuscate bytecode. Defaults to false.
232 Obfuscate *bool
233
234 // If true, do not use the flag files generated by aapt that automatically keep
235 // classes referenced by the app manifest. Defaults to false.
236 No_aapt_flags *bool
237
238 // Flags to pass to proguard.
239 Proguard_flags []string
240
241 // Specifies the locations of files containing proguard flags.
242 Proguard_flags_files []string
243 }
244
Colin Cross1369cdb2017-09-29 17:58:17 -0700245 // When targeting 1.9, override the modules to use with --system
246 System_modules *string
Colin Cross5a0dcd52018-10-05 14:20:06 -0700247
248 UncompressDex bool `blueprint:"mutated"`
Colin Cross43f08db2018-11-12 10:13:39 -0800249 IsSDKLibrary bool `blueprint:"mutated"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700250}
251
Colin Cross46c9b8b2017-06-22 16:51:17 -0700252// Module contains the properties and members used by all java module types
253type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700254 android.ModuleBase
Colin Cross89536d42017-07-07 14:35:50 -0700255 android.DefaultableModuleBase
Colin Cross2fe66872015-03-30 17:20:39 -0700256
Colin Cross89536d42017-07-07 14:35:50 -0700257 properties CompilerProperties
Colin Cross6af17aa2017-09-20 12:59:05 -0700258 protoProperties android.ProtoProperties
Colin Cross89536d42017-07-07 14:35:50 -0700259 deviceProperties CompilerDeviceProperties
Colin Cross2fe66872015-03-30 17:20:39 -0700260
Colin Cross331a1212018-08-15 20:40:52 -0700261 // jar file containing header classes including static library dependencies, suitable for
262 // inserting into the bootclasspath/classpath of another compile
Nan Zhanged19fc32017-10-19 13:06:22 -0700263 headerJarFile android.Path
264
Colin Cross331a1212018-08-15 20:40:52 -0700265 // jar file containing implementation classes including static library dependencies but no
266 // resources
Nan Zhanged19fc32017-10-19 13:06:22 -0700267 implementationJarFile android.Path
Colin Cross2fe66872015-03-30 17:20:39 -0700268
Colin Cross331a1212018-08-15 20:40:52 -0700269 // jar file containing only resources including from static library dependencies
270 resourceJar android.Path
271
272 // jar file containing implementation classes and resources including static library
273 // dependencies
274 implementationAndResourcesJar android.Path
275
276 // output file containing classes.dex and resources
Colin Cross6ade34f2017-09-15 13:00:47 -0700277 dexJarFile android.Path
278
Colin Cross43f08db2018-11-12 10:13:39 -0800279 // output file that contains classes.dex if it should be in the output file
280 maybeStrippedDexJarFile android.Path
281
Colin Crosscb933592017-11-22 13:49:43 -0800282 // output file containing uninstrumented classes that will be instrumented by jacoco
283 jacocoReportClassesFile android.Path
284
Colin Cross66dbc0b2017-12-28 12:23:20 -0800285 // output file containing mapping of obfuscated names
286 proguardDictionary android.Path
287
Colin Cross331a1212018-08-15 20:40:52 -0700288 // output file of the module, which may be a classes jar or a dex jar
Colin Cross635c3b02016-05-18 15:37:25 -0700289 outputFile android.Path
Colin Crossb7a63242015-04-16 14:09:14 -0700290
Colin Cross635c3b02016-05-18 15:37:25 -0700291 exportAidlIncludeDirs android.Paths
Colin Crossc0b06f12015-04-08 13:03:43 -0700292
Colin Cross635c3b02016-05-18 15:37:25 -0700293 logtagsSrcs android.Paths
Colin Crossf05fe972015-04-10 17:45:20 -0700294
Colin Cross2fe66872015-03-30 17:20:39 -0700295 // installed file for binary dependency
Colin Cross635c3b02016-05-18 15:37:25 -0700296 installFile android.Path
Colin Cross5ab4e6d2017-11-22 16:20:45 -0800297
298 // list of .java files and srcjars that was passed to javac
299 compiledJavaSrcs android.Paths
300 compiledSrcJars android.Paths
Colin Cross66dbc0b2017-12-28 12:23:20 -0800301
302 // list of extra progurad flag files
303 extraProguardFlagFiles android.Paths
Jiyong Park1be96912018-05-28 18:02:19 +0900304
Colin Cross094054a2018-10-17 15:10:48 -0700305 // manifest file to use instead of properties.Manifest
306 overrideManifest android.OptionalPath
307
Jiyong Park1be96912018-05-28 18:02:19 +0900308 // list of SDK lib names that this java moudule is exporting
309 exportedSdkLibs []string
Brandon Lee5d45c6f2018-08-15 15:35:38 -0700310
311 // list of source files, collected from compiledJavaSrcs and compiledSrcJars
312 // filter out Exclude_srcs, will be used by android.IDEInfo struct
313 expandIDEInfoCompiledSrcs []string
Colin Cross43f08db2018-11-12 10:13:39 -0800314
Steven Morelandc4efd9c2019-01-18 11:51:25 -0800315 // expanded Jarjar_rules
316 expandJarjarRules android.Path
317
Colin Crossf24a22a2019-01-31 14:12:44 -0800318 hiddenAPI
Colin Cross43f08db2018-11-12 10:13:39 -0800319 dexpreopter
Colin Cross2fe66872015-03-30 17:20:39 -0700320}
321
Colin Cross54250902017-12-05 09:28:08 -0800322func (j *Module) Srcs() android.Paths {
Colin Cross3063b782018-08-15 11:19:12 -0700323 return android.Paths{j.outputFile}
Colin Cross54250902017-12-05 09:28:08 -0800324}
325
Jiyong Park8fd61922018-11-08 02:50:25 +0900326func (j *Module) DexJarFile() android.Path {
327 return j.dexJarFile
328}
329
Colin Cross54250902017-12-05 09:28:08 -0800330var _ android.SourceFileProducer = (*Module)(nil)
331
Colin Crossf506d872017-07-19 15:53:04 -0700332type Dependency interface {
Nan Zhanged19fc32017-10-19 13:06:22 -0700333 HeaderJars() android.Paths
334 ImplementationJars() android.Paths
Colin Cross331a1212018-08-15 20:40:52 -0700335 ResourceJars() android.Paths
336 ImplementationAndResourcesJars() android.Paths
Colin Crossf24a22a2019-01-31 14:12:44 -0800337 DexJar() android.Path
Colin Cross635c3b02016-05-18 15:37:25 -0700338 AidlIncludeDirs() android.Paths
Jiyong Park1be96912018-05-28 18:02:19 +0900339 ExportedSdkLibs() []string
Colin Cross2fe66872015-03-30 17:20:39 -0700340}
341
Jiyong Parkc678ad32018-04-10 13:07:10 +0900342type SdkLibraryDependency interface {
Colin Cross897d2ed2019-02-11 14:03:51 -0800343 SdkHeaderJars(ctx android.BaseContext, sdkVersion string) android.Paths
344 SdkImplementationJars(ctx android.BaseContext, sdkVersion string) android.Paths
Jiyong Parkc678ad32018-04-10 13:07:10 +0900345}
346
Nan Zhangb2b33de2018-02-23 11:18:47 -0800347type SrcDependency interface {
348 CompiledSrcs() android.Paths
349 CompiledSrcJars() android.Paths
350}
351
352func (j *Module) CompiledSrcs() android.Paths {
353 return j.compiledJavaSrcs
354}
355
356func (j *Module) CompiledSrcJars() android.Paths {
357 return j.compiledSrcJars
358}
359
360var _ SrcDependency = (*Module)(nil)
361
Colin Cross89536d42017-07-07 14:35:50 -0700362func InitJavaModule(module android.DefaultableModule, hod android.HostOrDeviceSupported) {
363 android.InitAndroidArchModule(module, hod, android.MultilibCommon)
364 android.InitDefaultableModule(module)
365}
366
Colin Crossbe1da472017-07-07 15:59:46 -0700367type dependencyTag struct {
368 blueprint.BaseDependencyTag
369 name string
Colin Cross2fe66872015-03-30 17:20:39 -0700370}
371
Colin Crossa4f08812018-10-02 22:03:40 -0700372type jniDependencyTag struct {
373 blueprint.BaseDependencyTag
374 target android.Target
375}
376
Colin Crossbe1da472017-07-07 15:59:46 -0700377var (
Colin Cross4b964c02018-10-15 16:18:06 -0700378 staticLibTag = dependencyTag{name: "staticlib"}
379 libTag = dependencyTag{name: "javalib"}
Colin Crossbe9cdb82019-01-21 21:37:16 -0800380 pluginTag = dependencyTag{name: "plugin"}
Colin Cross4b964c02018-10-15 16:18:06 -0700381 bootClasspathTag = dependencyTag{name: "bootclasspath"}
382 systemModulesTag = dependencyTag{name: "system modules"}
383 frameworkResTag = dependencyTag{name: "framework-res"}
384 frameworkApkTag = dependencyTag{name: "framework-apk"}
385 kotlinStdlibTag = dependencyTag{name: "kotlin-stdlib"}
Colin Crossafbb1732019-01-17 15:42:52 -0800386 kotlinAnnotationsTag = dependencyTag{name: "kotlin-annotations"}
Colin Cross4b964c02018-10-15 16:18:06 -0700387 proguardRaiseTag = dependencyTag{name: "proguard-raise"}
388 certificateTag = dependencyTag{name: "certificate"}
389 instrumentationForTag = dependencyTag{name: "instrumentation_for"}
Colin Crossbe1da472017-07-07 15:59:46 -0700390)
Colin Cross2fe66872015-03-30 17:20:39 -0700391
Colin Crossfc3674a2017-09-18 17:41:52 -0700392type sdkDep struct {
Colin Cross47ff2522017-10-02 14:22:08 -0700393 useModule, useFiles, useDefaultLibs, invalidVersion bool
394
Colin Cross86a60ae2018-05-29 14:44:55 -0700395 modules []string
Colin Cross1369cdb2017-09-29 17:58:17 -0700396 systemModules string
397
Colin Crossa97c5d32018-03-28 14:58:31 -0700398 frameworkResModule string
399
Colin Cross86a60ae2018-05-29 14:44:55 -0700400 jars android.Paths
Colin Cross1369cdb2017-09-29 17:58:17 -0700401 aidl android.Path
402}
403
Colin Crossa4f08812018-10-02 22:03:40 -0700404type jniLib struct {
405 name string
406 path android.Path
407 target android.Target
408}
409
Colin Cross3144dfc2018-01-03 15:06:47 -0800410func (j *Module) shouldInstrument(ctx android.BaseContext) bool {
411 return j.properties.Instrument && ctx.Config().IsEnvTrue("EMMA_INSTRUMENT")
412}
413
414func (j *Module) shouldInstrumentStatic(ctx android.BaseContext) bool {
415 return j.shouldInstrument(ctx) &&
416 (ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_STATIC") ||
417 ctx.Config().UnbundledBuild())
418}
419
Colin Cross83bb3162018-06-25 15:48:06 -0700420func (j *Module) sdkVersion() string {
421 return String(j.deviceProperties.Sdk_version)
422}
423
424func (j *Module) minSdkVersion() string {
425 if j.deviceProperties.Min_sdk_version != nil {
426 return *j.deviceProperties.Min_sdk_version
427 }
428 return j.sdkVersion()
429}
430
Dan Willemsen419290a2018-10-31 15:28:47 -0700431func (j *Module) targetSdkVersion() string {
432 if j.deviceProperties.Target_sdk_version != nil {
433 return *j.deviceProperties.Target_sdk_version
434 }
435 return j.sdkVersion()
436}
437
Colin Crossbe1da472017-07-07 15:59:46 -0700438func (j *Module) deps(ctx android.BottomUpMutatorContext) {
Colin Cross1369cdb2017-09-29 17:58:17 -0700439 if ctx.Device() {
Colin Crossff3ae9d2018-04-10 16:15:18 -0700440 if !Bool(j.properties.No_standard_libs) {
Colin Cross83bb3162018-06-25 15:48:06 -0700441 sdkDep := decodeSdkDep(ctx, sdkContext(j))
Colin Crossfc3674a2017-09-18 17:41:52 -0700442 if sdkDep.useDefaultLibs {
Colin Cross42d48b72018-08-29 14:10:52 -0700443 ctx.AddVariationDependencies(nil, bootClasspathTag, config.DefaultBootclasspathLibraries...)
Tobias Thierer06dd04f2018-09-11 16:21:05 +0100444 ctx.AddVariationDependencies(nil, systemModulesTag, config.DefaultSystemModules)
Colin Crossff3ae9d2018-04-10 16:15:18 -0700445 if !Bool(j.properties.No_framework_libs) {
Colin Cross42d48b72018-08-29 14:10:52 -0700446 ctx.AddVariationDependencies(nil, libTag, config.DefaultLibraries...)
Colin Crossfa5eb232017-10-01 20:33:03 -0700447 }
Colin Cross1369cdb2017-09-29 17:58:17 -0700448 } else if sdkDep.useModule {
Tobias Thierer06dd04f2018-09-11 16:21:05 +0100449 ctx.AddVariationDependencies(nil, systemModulesTag, sdkDep.systemModules)
Colin Cross42d48b72018-08-29 14:10:52 -0700450 ctx.AddVariationDependencies(nil, bootClasspathTag, sdkDep.modules...)
Colin Cross66dbc0b2017-12-28 12:23:20 -0800451 if Bool(j.deviceProperties.Optimize.Enabled) {
Colin Cross42d48b72018-08-29 14:10:52 -0700452 ctx.AddVariationDependencies(nil, proguardRaiseTag, config.DefaultBootclasspathLibraries...)
453 ctx.AddVariationDependencies(nil, proguardRaiseTag, config.DefaultLibraries...)
Colin Cross66dbc0b2017-12-28 12:23:20 -0800454 }
Colin Crossbe1da472017-07-07 15:59:46 -0700455 }
Colin Cross1369cdb2017-09-29 17:58:17 -0700456 } else if j.deviceProperties.System_modules == nil {
457 ctx.PropertyErrorf("no_standard_libs",
458 "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 +0100459 } else if *j.deviceProperties.System_modules != "none" {
Colin Cross42d48b72018-08-29 14:10:52 -0700460 ctx.AddVariationDependencies(nil, systemModulesTag, *j.deviceProperties.System_modules)
Colin Cross2fe66872015-03-30 17:20:39 -0700461 }
Mathew Inwoodebe29ce2018-09-04 14:26:19 +0100462 if (ctx.ModuleName() == "framework") || (ctx.ModuleName() == "framework-annotation-proc") {
Colin Cross42d48b72018-08-29 14:10:52 -0700463 ctx.AddVariationDependencies(nil, frameworkResTag, "framework-res")
Colin Cross5ab4e6d2017-11-22 16:20:45 -0800464 }
Nan Zhangb2b33de2018-02-23 11:18:47 -0800465 if ctx.ModuleName() == "android_stubs_current" ||
466 ctx.ModuleName() == "android_system_stubs_current" ||
Nan Zhang863f05b2018-08-07 13:41:10 -0700467 ctx.ModuleName() == "android_test_stubs_current" {
Colin Cross42d48b72018-08-29 14:10:52 -0700468 ctx.AddVariationDependencies(nil, frameworkApkTag, "framework-res")
Nan Zhangb2b33de2018-02-23 11:18:47 -0800469 }
Colin Cross2fe66872015-03-30 17:20:39 -0700470 }
Colin Cross1369cdb2017-09-29 17:58:17 -0700471
Colin Cross42d48b72018-08-29 14:10:52 -0700472 ctx.AddVariationDependencies(nil, libTag, j.properties.Libs...)
473 ctx.AddVariationDependencies(nil, staticLibTag, j.properties.Static_libs...)
Colin Crossa4f08812018-10-02 22:03:40 -0700474
Colin Crossbe9cdb82019-01-21 21:37:16 -0800475 ctx.AddFarVariationDependencies([]blueprint.Variation{
476 {Mutator: "arch", Variation: ctx.Config().BuildOsCommonVariant},
477 }, pluginTag, j.properties.Plugins...)
478
Colin Cross7f9036c2017-08-30 13:27:57 -0700479 android.ExtractSourcesDeps(ctx, j.properties.Srcs)
Nan Zhang27e284d2018-02-09 21:03:53 +0000480 android.ExtractSourcesDeps(ctx, j.properties.Exclude_srcs)
Colin Cross0f37af02017-09-27 17:42:05 -0700481 android.ExtractSourcesDeps(ctx, j.properties.Java_resources)
Colin Cross366938f2017-12-11 16:29:02 -0800482 android.ExtractSourceDeps(ctx, j.properties.Manifest)
Steven Morelandc4efd9c2019-01-18 11:51:25 -0800483 android.ExtractSourceDeps(ctx, j.properties.Jarjar_rules)
Alex Light7f004a72019-02-21 13:27:37 -0800484 android.ExtractSourcesDeps(ctx, j.properties.Services)
Colin Cross6af17aa2017-09-20 12:59:05 -0700485
486 if j.hasSrcExt(".proto") {
487 protoDeps(ctx, &j.protoProperties)
488 }
Colin Cross93e85952017-08-15 13:34:18 -0700489
490 if j.hasSrcExt(".kt") {
491 // TODO(ccross): move this to a mutator pass that can tell if generated sources contain
492 // Kotlin files
Colin Cross42d48b72018-08-29 14:10:52 -0700493 ctx.AddVariationDependencies(nil, kotlinStdlibTag, "kotlin-stdlib")
Colin Cross7788c122019-01-23 16:14:02 -0800494 if len(j.properties.Plugins) > 0 {
Colin Crossafbb1732019-01-17 15:42:52 -0800495 ctx.AddVariationDependencies(nil, kotlinAnnotationsTag, "kotlin-annotations")
496 }
Colin Cross93e85952017-08-15 13:34:18 -0700497 }
Colin Cross3144dfc2018-01-03 15:06:47 -0800498
499 if j.shouldInstrumentStatic(ctx) {
Colin Cross42d48b72018-08-29 14:10:52 -0700500 ctx.AddVariationDependencies(nil, staticLibTag, "jacocoagent")
Colin Cross3144dfc2018-01-03 15:06:47 -0800501 }
Colin Cross6af17aa2017-09-20 12:59:05 -0700502}
503
504func hasSrcExt(srcs []string, ext string) bool {
505 for _, src := range srcs {
506 if filepath.Ext(src) == ext {
507 return true
508 }
509 }
510
511 return false
512}
513
Nan Zhang61eaedb2017-11-02 13:28:15 -0700514func shardPaths(paths android.Paths, shardSize int) []android.Paths {
515 ret := make([]android.Paths, 0, (len(paths)+shardSize-1)/shardSize)
516 for len(paths) > shardSize {
517 ret = append(ret, paths[0:shardSize])
518 paths = paths[shardSize:]
519 }
520 if len(paths) > 0 {
521 ret = append(ret, paths)
522 }
523 return ret
524}
525
Colin Cross6af17aa2017-09-20 12:59:05 -0700526func (j *Module) hasSrcExt(ext string) bool {
527 return hasSrcExt(j.properties.Srcs, ext)
Colin Cross2fe66872015-03-30 17:20:39 -0700528}
529
Colin Cross46c9b8b2017-06-22 16:51:17 -0700530func (j *Module) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.OptionalPath,
Colin Cross635c3b02016-05-18 15:37:25 -0700531 aidlIncludeDirs android.Paths) []string {
Colin Crossc0b06f12015-04-08 13:03:43 -0700532
Colin Crossebe1a512017-11-14 13:12:14 -0800533 aidlIncludes := android.PathsForModuleSrc(ctx, j.deviceProperties.Aidl.Local_include_dirs)
534 aidlIncludes = append(aidlIncludes,
535 android.PathsForModuleSrc(ctx, j.deviceProperties.Aidl.Export_include_dirs)...)
536 aidlIncludes = append(aidlIncludes,
537 android.PathsForSource(ctx, j.deviceProperties.Aidl.Include_dirs)...)
Colin Crossc0b06f12015-04-08 13:03:43 -0700538
Steven Moreland36b130f2019-02-05 17:02:55 -0800539 flags := []string{}
Steven Moreland667f6882018-07-26 12:55:08 -0700540
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700541 if aidlPreprocess.Valid() {
542 flags = append(flags, "-p"+aidlPreprocess.String())
Colin Crossc0b06f12015-04-08 13:03:43 -0700543 } else {
Colin Cross635c3b02016-05-18 15:37:25 -0700544 flags = append(flags, android.JoinWithPrefix(aidlIncludeDirs.Strings(), "-I"))
Colin Crossc0b06f12015-04-08 13:03:43 -0700545 }
546
Colin Cross635c3b02016-05-18 15:37:25 -0700547 flags = append(flags, android.JoinWithPrefix(j.exportAidlIncludeDirs.Strings(), "-I"))
Colin Crossebe1a512017-11-14 13:12:14 -0800548 flags = append(flags, android.JoinWithPrefix(aidlIncludes.Strings(), "-I"))
Colin Cross635c3b02016-05-18 15:37:25 -0700549 flags = append(flags, "-I"+android.PathForModuleSrc(ctx).String())
Colin Cross32f38982018-02-22 11:47:25 -0800550 if src := android.ExistentPathForSource(ctx, ctx.ModuleDir(), "src"); src.Valid() {
Colin Crossd48633a2017-07-13 14:41:17 -0700551 flags = append(flags, "-I"+src.String())
552 }
Colin Crossc0b06f12015-04-08 13:03:43 -0700553
Martijn Coeneneab15642018-03-09 09:29:59 +0100554 if Bool(j.deviceProperties.Aidl.Generate_traces) {
555 flags = append(flags, "-t")
556 }
557
Olivier Gaillard0a4cfbc2018-07-16 23:37:03 +0100558 if Bool(j.deviceProperties.Aidl.Generate_get_transaction_name) {
559 flags = append(flags, "--transaction_names")
560 }
561
Colin Crossf03c82b2015-04-13 13:53:40 -0700562 return flags
Colin Crossc0b06f12015-04-08 13:03:43 -0700563}
564
Colin Cross32f676a2017-09-06 13:41:06 -0700565type deps struct {
Nan Zhang581fd212018-01-10 16:06:12 -0800566 classpath classpath
567 bootClasspath classpath
Colin Cross6a77c982018-06-19 22:43:34 -0700568 processorPath classpath
Colin Crossbe9cdb82019-01-21 21:37:16 -0800569 processorClasses []string
Colin Cross6ade34f2017-09-15 13:00:47 -0700570 staticJars android.Paths
Nan Zhanged19fc32017-10-19 13:06:22 -0700571 staticHeaderJars android.Paths
Colin Cross331a1212018-08-15 20:40:52 -0700572 staticResourceJars android.Paths
Colin Cross6ade34f2017-09-15 13:00:47 -0700573 aidlIncludeDirs android.Paths
Nan Zhangb2b33de2018-02-23 11:18:47 -0800574 srcs android.Paths
Colin Cross59149b62017-10-16 18:07:29 -0700575 srcJars android.Paths
Colin Cross1369cdb2017-09-29 17:58:17 -0700576 systemModules android.Path
Colin Cross6ade34f2017-09-15 13:00:47 -0700577 aidlPreprocess android.OptionalPath
Colin Cross93e85952017-08-15 13:34:18 -0700578 kotlinStdlib android.Paths
Colin Crossafbb1732019-01-17 15:42:52 -0800579 kotlinAnnotations android.Paths
Colin Crossbe9cdb82019-01-21 21:37:16 -0800580
581 disableTurbine bool
Colin Cross32f676a2017-09-06 13:41:06 -0700582}
Colin Cross2fe66872015-03-30 17:20:39 -0700583
Colin Cross54250902017-12-05 09:28:08 -0800584func checkProducesJars(ctx android.ModuleContext, dep android.SourceFileProducer) {
585 for _, f := range dep.Srcs() {
586 if f.Ext() != ".jar" {
587 ctx.ModuleErrorf("genrule %q must generate files ending with .jar to be used as a libs or static_libs dependency",
588 ctx.OtherModuleName(dep.(blueprint.Module)))
589 }
590 }
591}
592
Jiyong Park2d492942018-03-05 17:44:10 +0900593type linkType int
594
595const (
596 javaCore linkType = iota
597 javaSdk
598 javaSystem
599 javaPlatform
600)
601
Jiyong Park46f78fb2018-10-20 16:33:17 +0900602func getLinkType(m *Module, name string) (ret linkType, stubs bool) {
Colin Cross83bb3162018-06-25 15:48:06 -0700603 ver := m.sdkVersion()
Colin Crossf19b9bb2018-03-26 14:42:44 -0700604 switch {
Jiyong Park46f78fb2018-10-20 16:33:17 +0900605 case name == "core.current.stubs" || name == "core.platform.api.stubs" ||
606 name == "stub-annotations" || name == "private-stub-annotations-jar" ||
607 name == "core-lambda-stubs":
608 return javaCore, true
Neil Fuller401eeba2018-10-18 19:48:58 +0100609 case ver == "core_current":
Jiyong Park46f78fb2018-10-20 16:33:17 +0900610 return javaCore, false
611 case name == "android_system_stubs_current":
612 return javaSystem, true
613 case strings.HasPrefix(ver, "system_"):
614 return javaSystem, false
615 case name == "android_test_stubs_current":
616 return javaSystem, true
617 case strings.HasPrefix(ver, "test_"):
618 return javaPlatform, false
619 case name == "android_stubs_current":
620 return javaSdk, true
621 case ver == "current":
622 return javaSdk, false
Colin Crossf19b9bb2018-03-26 14:42:44 -0700623 case ver == "":
Jiyong Park46f78fb2018-10-20 16:33:17 +0900624 return javaPlatform, false
Colin Crossf19b9bb2018-03-26 14:42:44 -0700625 default:
626 if _, err := strconv.Atoi(ver); err != nil {
627 panic(fmt.Errorf("expected sdk_version to be a number, got %q", ver))
628 }
Jiyong Park46f78fb2018-10-20 16:33:17 +0900629 return javaSdk, false
Jiyong Park2d492942018-03-05 17:44:10 +0900630 }
631}
632
Jiyong Park750e5572018-01-31 00:20:13 +0900633func checkLinkType(ctx android.ModuleContext, from *Module, to *Library, tag dependencyTag) {
Colin Crossf19b9bb2018-03-26 14:42:44 -0700634 if ctx.Host() {
635 return
636 }
637
Jiyong Park46f78fb2018-10-20 16:33:17 +0900638 myLinkType, stubs := getLinkType(from, ctx.ModuleName())
639 if stubs {
640 return
641 }
642 otherLinkType, _ := getLinkType(&to.Module, ctx.OtherModuleName(to))
Jiyong Park2d492942018-03-05 17:44:10 +0900643 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."
644
645 switch myLinkType {
646 case javaCore:
647 if otherLinkType != javaCore {
648 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 +0900649 ctx.OtherModuleName(to))
650 }
Jiyong Park2d492942018-03-05 17:44:10 +0900651 break
652 case javaSdk:
653 if otherLinkType != javaCore && otherLinkType != javaSdk {
654 ctx.ModuleErrorf("compiles against Android API, but dependency %q is compiling against non-public Android API."+commonMessage,
655 ctx.OtherModuleName(to))
656 }
657 break
658 case javaSystem:
659 if otherLinkType == javaPlatform {
660 ctx.ModuleErrorf("compiles against system API, but dependency %q is compiling against private API."+commonMessage,
661 ctx.OtherModuleName(to))
662 }
663 break
664 case javaPlatform:
665 // no restriction on link-type
666 break
Jiyong Park750e5572018-01-31 00:20:13 +0900667 }
668}
669
Colin Cross32f676a2017-09-06 13:41:06 -0700670func (j *Module) collectDeps(ctx android.ModuleContext) deps {
671 var deps deps
Colin Crossfc3674a2017-09-18 17:41:52 -0700672
Colin Cross300f0382018-03-06 13:11:51 -0800673 if ctx.Device() {
Colin Cross83bb3162018-06-25 15:48:06 -0700674 sdkDep := decodeSdkDep(ctx, sdkContext(j))
Colin Cross300f0382018-03-06 13:11:51 -0800675 if sdkDep.invalidVersion {
Colin Cross86a60ae2018-05-29 14:44:55 -0700676 ctx.AddMissingDependencies(sdkDep.modules)
Colin Cross300f0382018-03-06 13:11:51 -0800677 } else if sdkDep.useFiles {
678 // sdkDep.jar is actually equivalent to turbine header.jar.
Colin Cross86a60ae2018-05-29 14:44:55 -0700679 deps.classpath = append(deps.classpath, sdkDep.jars...)
Colin Cross300f0382018-03-06 13:11:51 -0800680 deps.aidlIncludeDirs = append(deps.aidlIncludeDirs, sdkDep.aidl)
681 }
Colin Crossfc3674a2017-09-18 17:41:52 -0700682 }
683
Colin Crossd11fcda2017-10-23 17:59:01 -0700684 ctx.VisitDirectDeps(func(module android.Module) {
Colin Cross2fe66872015-03-30 17:20:39 -0700685 otherName := ctx.OtherModuleName(module)
Colin Crossec7a0422017-07-07 14:47:12 -0700686 tag := ctx.OtherModuleDependencyTag(module)
687
Colin Crossa4f08812018-10-02 22:03:40 -0700688 if _, ok := tag.(*jniDependencyTag); ok {
Colin Crossbd01e2a2018-10-04 15:21:03 -0700689 // Handled by AndroidApp.collectAppDeps
690 return
691 }
692 if tag == certificateTag {
693 // Handled by AndroidApp.collectAppDeps
Colin Crossa4f08812018-10-02 22:03:40 -0700694 return
695 }
696
Jiyong Park750e5572018-01-31 00:20:13 +0900697 if to, ok := module.(*Library); ok {
Colin Crossa97c5d32018-03-28 14:58:31 -0700698 switch tag {
699 case bootClasspathTag, libTag, staticLibTag:
700 checkLinkType(ctx, j, to, tag.(dependencyTag))
701 }
Jiyong Park750e5572018-01-31 00:20:13 +0900702 }
Colin Cross54250902017-12-05 09:28:08 -0800703 switch dep := module.(type) {
Colin Cross897d2ed2019-02-11 14:03:51 -0800704 case SdkLibraryDependency:
705 switch tag {
706 case libTag:
707 deps.classpath = append(deps.classpath, dep.SdkHeaderJars(ctx, j.sdkVersion())...)
708 // names of sdk libs that are directly depended are exported
709 j.exportedSdkLibs = append(j.exportedSdkLibs, otherName)
710 default:
711 ctx.ModuleErrorf("dependency on java_sdk_library %q can only be in libs", otherName)
712 }
Colin Cross54250902017-12-05 09:28:08 -0800713 case Dependency:
714 switch tag {
715 case bootClasspathTag:
716 deps.bootClasspath = append(deps.bootClasspath, dep.HeaderJars()...)
Colin Cross4b964c02018-10-15 16:18:06 -0700717 case libTag, instrumentationForTag:
Colin Cross54250902017-12-05 09:28:08 -0800718 deps.classpath = append(deps.classpath, dep.HeaderJars()...)
Jiyong Park1be96912018-05-28 18:02:19 +0900719 // sdk lib names from dependencies are re-exported
720 j.exportedSdkLibs = append(j.exportedSdkLibs, dep.ExportedSdkLibs()...)
Colin Cross54250902017-12-05 09:28:08 -0800721 case staticLibTag:
722 deps.classpath = append(deps.classpath, dep.HeaderJars()...)
723 deps.staticJars = append(deps.staticJars, dep.ImplementationJars()...)
724 deps.staticHeaderJars = append(deps.staticHeaderJars, dep.HeaderJars()...)
Colin Cross331a1212018-08-15 20:40:52 -0700725 deps.staticResourceJars = append(deps.staticResourceJars, dep.ResourceJars()...)
Jiyong Park1be96912018-05-28 18:02:19 +0900726 // sdk lib names from dependencies are re-exported
727 j.exportedSdkLibs = append(j.exportedSdkLibs, dep.ExportedSdkLibs()...)
Colin Crossbe9cdb82019-01-21 21:37:16 -0800728 case pluginTag:
729 if plugin, ok := dep.(*Plugin); ok {
730 deps.processorPath = append(deps.processorPath, dep.ImplementationAndResourcesJars()...)
731 if plugin.pluginProperties.Processor_class != nil {
732 deps.processorClasses = append(deps.processorClasses, *plugin.pluginProperties.Processor_class)
733 }
734 deps.disableTurbine = deps.disableTurbine || Bool(plugin.pluginProperties.Generates_api)
735 } else {
736 ctx.PropertyErrorf("plugins", "%q is not a java_plugin module", otherName)
737 }
Colin Cross54250902017-12-05 09:28:08 -0800738 case frameworkResTag:
Mathew Inwoodebe29ce2018-09-04 14:26:19 +0100739 if (ctx.ModuleName() == "framework") || (ctx.ModuleName() == "framework-annotation-proc") {
Colin Cross54250902017-12-05 09:28:08 -0800740 // framework.jar has a one-off dependency on the R.java and Manifest.java files
741 // generated by framework-res.apk
742 deps.srcJars = append(deps.srcJars, dep.(*AndroidApp).aaptSrcJar)
743 }
Nan Zhangb2b33de2018-02-23 11:18:47 -0800744 case frameworkApkTag:
745 if ctx.ModuleName() == "android_stubs_current" ||
746 ctx.ModuleName() == "android_system_stubs_current" ||
Nan Zhang863f05b2018-08-07 13:41:10 -0700747 ctx.ModuleName() == "android_test_stubs_current" {
Nan Zhangb2b33de2018-02-23 11:18:47 -0800748 // framework stubs.jar need to depend on framework-res.apk, in order to pull the
749 // resource files out of there for aapt.
750 //
751 // Normally the package rule runs aapt, which includes the resource,
752 // but we're not running that in our package rule so just copy in the
753 // resource files here.
Colin Cross331a1212018-08-15 20:40:52 -0700754 deps.staticResourceJars = append(deps.staticResourceJars, dep.(*AndroidApp).exportPackage)
Nan Zhangb2b33de2018-02-23 11:18:47 -0800755 }
Colin Cross54250902017-12-05 09:28:08 -0800756 case kotlinStdlibTag:
757 deps.kotlinStdlib = dep.HeaderJars()
Colin Crossafbb1732019-01-17 15:42:52 -0800758 case kotlinAnnotationsTag:
759 deps.kotlinAnnotations = dep.HeaderJars()
Colin Cross54250902017-12-05 09:28:08 -0800760 }
761
762 deps.aidlIncludeDirs = append(deps.aidlIncludeDirs, dep.AidlIncludeDirs()...)
763 case android.SourceFileProducer:
764 switch tag {
765 case libTag:
766 checkProducesJars(ctx, dep)
767 deps.classpath = append(deps.classpath, dep.Srcs()...)
768 case staticLibTag:
769 checkProducesJars(ctx, dep)
770 deps.classpath = append(deps.classpath, dep.Srcs()...)
771 deps.staticJars = append(deps.staticJars, dep.Srcs()...)
772 deps.staticHeaderJars = append(deps.staticHeaderJars, dep.Srcs()...)
773 case android.DefaultsDepTag, android.SourceDepTag:
774 // Nothing to do
Sundong Ahn054b19a2018-10-19 13:46:09 +0900775 case publicApiFileTag, systemApiFileTag, testApiFileTag:
776 // Nothing to do
Colin Cross54250902017-12-05 09:28:08 -0800777 default:
778 ctx.ModuleErrorf("dependency on genrule %q may only be in srcs, libs, or static_libs", otherName)
779 }
780 default:
Colin Crossec7a0422017-07-07 14:47:12 -0700781 switch tag {
782 case android.DefaultsDepTag, android.SourceDepTag:
Dan Willemsend6ba0d52017-09-13 15:46:47 -0700783 // Nothing to do
Colin Cross1369cdb2017-09-29 17:58:17 -0700784 case systemModulesTag:
785 if deps.systemModules != nil {
786 panic("Found two system module dependencies")
787 }
788 sm := module.(*SystemModules)
789 if sm.outputFile == nil {
790 panic("Missing directory for system module dependency")
791 }
792 deps.systemModules = sm.outputFile
Colin Crossec7a0422017-07-07 14:47:12 -0700793 default:
794 ctx.ModuleErrorf("depends on non-java module %q", otherName)
Colin Cross2fe66872015-03-30 17:20:39 -0700795 }
Colin Crossec7a0422017-07-07 14:47:12 -0700796 }
Colin Cross2fe66872015-03-30 17:20:39 -0700797 })
798
Jiyong Park1be96912018-05-28 18:02:19 +0900799 j.exportedSdkLibs = android.FirstUniqueStrings(j.exportedSdkLibs)
800
Colin Cross32f676a2017-09-06 13:41:06 -0700801 return deps
Colin Cross2fe66872015-03-30 17:20:39 -0700802}
803
Colin Cross83bb3162018-06-25 15:48:06 -0700804func getJavaVersion(ctx android.ModuleContext, javaVersion string, sdkContext sdkContext) string {
Nan Zhang357466b2018-04-17 17:38:36 -0700805 var ret string
Colin Cross98fd5742019-01-09 23:04:25 -0800806 v := sdkContext.sdkVersion()
807 // For PDK builds, use the latest SDK version instead of "current"
808 if ctx.Config().IsPdkBuild() && (v == "" || v == "current") {
809 sdkVersions := ctx.Config().Get(sdkSingletonKey).([]int)
810 latestSdkVersion := 0
811 if len(sdkVersions) > 0 {
812 latestSdkVersion = sdkVersions[len(sdkVersions)-1]
813 }
814 v = strconv.Itoa(latestSdkVersion)
815 }
816
817 sdk, err := sdkVersionToNumber(ctx, v)
Colin Cross83bb3162018-06-25 15:48:06 -0700818 if err != nil {
819 ctx.PropertyErrorf("sdk_version", "%s", err)
820 }
Nan Zhang357466b2018-04-17 17:38:36 -0700821 if javaVersion != "" {
822 ret = javaVersion
823 } else if ctx.Device() && sdk <= 23 {
824 ret = "1.7"
Jiyong Park4584a8a2018-10-03 18:05:04 +0900825 } else if ctx.Device() && sdk <= 28 || !ctx.Config().TargetOpenJDK9() {
Nan Zhang357466b2018-04-17 17:38:36 -0700826 ret = "1.8"
Colin Cross83bb3162018-06-25 15:48:06 -0700827 } else if ctx.Device() && sdkContext.sdkVersion() != "" && sdk == android.FutureApiLevel {
Nan Zhang357466b2018-04-17 17:38:36 -0700828 // TODO(ccross): once we generate stubs we should be able to use 1.9 for sdk_version: "current"
829 ret = "1.8"
830 } else {
831 ret = "1.9"
832 }
833
834 return ret
835}
836
Nan Zhanged19fc32017-10-19 13:06:22 -0700837func (j *Module) collectBuilderFlags(ctx android.ModuleContext, deps deps) javaBuilderFlags {
Colin Crossc0b06f12015-04-08 13:03:43 -0700838
Colin Crossf03c82b2015-04-13 13:53:40 -0700839 var flags javaBuilderFlags
840
Tobias Thierer06dd04f2018-09-11 16:21:05 +0100841 // javaVersion flag.
842 flags.javaVersion = getJavaVersion(ctx, String(j.properties.Java_version), sdkContext(j))
843
Nan Zhanged19fc32017-10-19 13:06:22 -0700844 // javac flags.
Colin Crossf03c82b2015-04-13 13:53:40 -0700845 javacFlags := j.properties.Javacflags
Tobias Thierer06dd04f2018-09-11 16:21:05 +0100846 if flags.javaVersion == "1.9" {
Colin Cross1369cdb2017-09-29 17:58:17 -0700847 javacFlags = append(javacFlags, j.properties.Openjdk9.Javacflags...)
Nan Zhanged19fc32017-10-19 13:06:22 -0700848 }
Colin Cross6510f912017-11-29 00:27:14 -0800849 if ctx.Config().MinimizeJavaDebugInfo() {
Colin Cross126a25c2017-10-31 13:55:34 -0700850 // Override the -g flag passed globally to remove local variable debug info to reduce
851 // disk and memory usage.
852 javacFlags = append(javacFlags, "-g:source,lines")
853 }
Colin Cross64162712017-08-08 13:17:59 -0700854
Colin Cross66548102018-06-19 22:47:35 -0700855 if ctx.Config().RunErrorProne() {
856 if config.ErrorProneClasspath == nil {
857 ctx.ModuleErrorf("cannot build with Error Prone, missing external/error_prone?")
858 }
859
860 errorProneFlags := []string{
861 "-Xplugin:ErrorProne",
862 "${config.ErrorProneChecks}",
863 }
864 errorProneFlags = append(errorProneFlags, j.properties.Errorprone.Javacflags...)
865
866 flags.errorProneExtraJavacFlags = "${config.ErrorProneFlags} " +
867 "'" + strings.Join(errorProneFlags, " ") + "'"
868 flags.errorProneProcessorPath = classpath(android.PathsForSource(ctx, config.ErrorProneClasspath))
Andreas Gampef3e5b552018-01-22 21:27:21 -0800869 }
870
Nan Zhanged19fc32017-10-19 13:06:22 -0700871 // classpath
Nan Zhang581fd212018-01-10 16:06:12 -0800872 flags.bootClasspath = append(flags.bootClasspath, deps.bootClasspath...)
873 flags.classpath = append(flags.classpath, deps.classpath...)
Colin Cross6a77c982018-06-19 22:43:34 -0700874 flags.processorPath = append(flags.processorPath, deps.processorPath...)
Colin Cross7fdd2b72018-01-02 18:14:25 -0800875
Colin Crossbe9cdb82019-01-21 21:37:16 -0800876 flags.processor = strings.Join(deps.processorClasses, ",")
877
Tobias Thierer06dd04f2018-09-11 16:21:05 +0100878 if len(flags.bootClasspath) == 0 && ctx.Host() && flags.javaVersion != "1.9" &&
Colin Cross7fdd2b72018-01-02 18:14:25 -0800879 !Bool(j.properties.No_standard_libs) &&
880 inList(flags.javaVersion, []string{"1.6", "1.7", "1.8"}) {
881 // Give host-side tools a version of OpenJDK's standard libraries
882 // close to what they're targeting. As of Dec 2017, AOSP is only
883 // bundling OpenJDK 8 and 9, so nothing < 8 is available.
884 //
885 // When building with OpenJDK 8, the following should have no
886 // effect since those jars would be available by default.
887 //
888 // When building with OpenJDK 9 but targeting a version < 1.8,
889 // putting them on the bootclasspath means that:
890 // a) code can't (accidentally) refer to OpenJDK 9 specific APIs
891 // b) references to existing APIs are not reinterpreted in an
892 // OpenJDK 9-specific way, eg. calls to subclasses of
893 // java.nio.Buffer as in http://b/70862583
894 java8Home := ctx.Config().Getenv("ANDROID_JAVA8_HOME")
895 flags.bootClasspath = append(flags.bootClasspath,
896 android.PathForSource(ctx, java8Home, "jre/lib/jce.jar"),
897 android.PathForSource(ctx, java8Home, "jre/lib/rt.jar"))
Nan Zhang5f8cb422018-02-06 10:34:32 -0800898 if Bool(j.properties.Use_tools_jar) {
899 flags.bootClasspath = append(flags.bootClasspath,
900 android.PathForSource(ctx, java8Home, "lib/tools.jar"))
901 }
Colin Cross7fdd2b72018-01-02 18:14:25 -0800902 }
903
Tobias Thierer06dd04f2018-09-11 16:21:05 +0100904 if j.properties.Patch_module != nil && flags.javaVersion == "1.9" {
Jaewoong Jung38e4fb22018-12-12 09:01:34 -0800905 // Manually specify build directory in case it is not under the repo root.
906 // (javac doesn't seem to expand into symbolc links when searching for patch-module targets, so
907 // just adding a symlink under the root doesn't help.)
908 patchPaths := ".:" + ctx.Config().BuildDir()
909 classPath := flags.classpath.FormJavaClassPath("")
910 if classPath != "" {
911 patchPaths += ":" + classPath
912 }
913 javacFlags = append(javacFlags, "--patch-module="+String(j.properties.Patch_module)+"="+patchPaths)
Colin Cross81440082018-08-15 20:21:55 -0700914 }
915
Nan Zhanged19fc32017-10-19 13:06:22 -0700916 // systemModules
Colin Cross1369cdb2017-09-29 17:58:17 -0700917 if deps.systemModules != nil {
918 flags.systemModules = append(flags.systemModules, deps.systemModules)
919 }
920
Nan Zhanged19fc32017-10-19 13:06:22 -0700921 // aidl flags.
Colin Cross32f676a2017-09-06 13:41:06 -0700922 aidlFlags := j.aidlFlags(ctx, deps.aidlPreprocess, deps.aidlIncludeDirs)
Colin Crossf03c82b2015-04-13 13:53:40 -0700923 if len(aidlFlags) > 0 {
Nan Zhanged19fc32017-10-19 13:06:22 -0700924 // optimization.
Colin Crossf03c82b2015-04-13 13:53:40 -0700925 ctx.Variable(pctx, "aidlFlags", strings.Join(aidlFlags, " "))
926 flags.aidlFlags = "$aidlFlags"
Colin Cross2fe66872015-03-30 17:20:39 -0700927 }
928
Colin Cross81440082018-08-15 20:21:55 -0700929 if len(javacFlags) > 0 {
930 // optimization.
931 ctx.Variable(pctx, "javacFlags", strings.Join(javacFlags, " "))
932 flags.javacFlags = "$javacFlags"
933 }
934
Nan Zhanged19fc32017-10-19 13:06:22 -0700935 return flags
936}
Colin Crossc0b06f12015-04-08 13:03:43 -0700937
Colin Cross3bc7ffa2017-11-22 16:19:37 -0800938func (j *Module) compile(ctx android.ModuleContext, extraSrcJars ...android.Path) {
Nan Zhanged19fc32017-10-19 13:06:22 -0700939
Colin Crossebe1a512017-11-14 13:12:14 -0800940 j.exportAidlIncludeDirs = android.PathsForModuleSrc(ctx, j.deviceProperties.Aidl.Export_include_dirs)
Nan Zhanged19fc32017-10-19 13:06:22 -0700941
942 deps := j.collectDeps(ctx)
943 flags := j.collectBuilderFlags(ctx, deps)
944
Tobias Thierer06dd04f2018-09-11 16:21:05 +0100945 if flags.javaVersion == "1.9" {
Nan Zhanged19fc32017-10-19 13:06:22 -0700946 j.properties.Srcs = append(j.properties.Srcs, j.properties.Openjdk9.Srcs...)
947 }
948 srcFiles := ctx.ExpandSources(j.properties.Srcs, j.properties.Exclude_srcs)
Colin Cross6af17aa2017-09-20 12:59:05 -0700949 if hasSrcExt(srcFiles.Strings(), ".proto") {
Colin Cross0f2ee152017-12-14 15:22:43 -0800950 flags = protoFlags(ctx, &j.properties, &j.protoProperties, flags)
Colin Cross6af17aa2017-09-20 12:59:05 -0700951 }
952
Colin Crossaf050172017-11-15 23:01:59 -0800953 srcFiles = j.genSources(ctx, srcFiles, flags)
954
955 srcJars := srcFiles.FilterByExt(".srcjar")
Colin Cross59149b62017-10-16 18:07:29 -0700956 srcJars = append(srcJars, deps.srcJars...)
Colin Cross3bc7ffa2017-11-22 16:19:37 -0800957 srcJars = append(srcJars, extraSrcJars...)
Colin Crossb7a63242015-04-16 14:09:14 -0700958
Brandon Lee5d45c6f2018-08-15 15:35:38 -0700959 // Collect source files from compiledJavaSrcs, compiledSrcJars and filter out Exclude_srcs
960 // that IDEInfo struct will use
961 j.expandIDEInfoCompiledSrcs = append(j.expandIDEInfoCompiledSrcs, srcFiles.Strings()...)
962
Steven Morelandc4efd9c2019-01-18 11:51:25 -0800963 if j.properties.Jarjar_rules != nil {
964 j.expandJarjarRules = ctx.ExpandSource(*j.properties.Jarjar_rules, "jarjar_rules")
965 }
966
Colin Cross1ee23172017-10-18 14:44:18 -0700967 jarName := ctx.ModuleName() + ".jar"
968
Przemyslaw Szczepaniak4b5fe9d2018-02-13 14:32:54 +0000969 javaSrcFiles := srcFiles.FilterByExt(".java")
970 var uniqueSrcFiles android.Paths
971 set := make(map[string]bool)
972 for _, v := range javaSrcFiles {
973 if _, found := set[v.String()]; !found {
974 set[v.String()] = true
975 uniqueSrcFiles = append(uniqueSrcFiles, v)
976 }
977 }
978
Colin Cross55f63ea2018-08-27 12:37:09 -0700979 var kotlinJars android.Paths
980
Colin Cross93e85952017-08-15 13:34:18 -0700981 if srcFiles.HasExt(".kt") {
Zoran Jovanovic8736ce22018-08-21 17:10:29 +0200982 // user defined kotlin flags.
983 kotlincFlags := j.properties.Kotlincflags
984 CheckKotlincFlags(ctx, kotlincFlags)
985
Colin Cross93e85952017-08-15 13:34:18 -0700986 // If there are kotlin files, compile them first but pass all the kotlin and java files
987 // kotlinc will use the java files to resolve types referenced by the kotlin files, but
988 // won't emit any classes for them.
Zoran Jovanovic8736ce22018-08-21 17:10:29 +0200989 kotlincFlags = append(kotlincFlags, "-no-stdlib")
Colin Cross93e85952017-08-15 13:34:18 -0700990 if ctx.Device() {
Zoran Jovanovic8736ce22018-08-21 17:10:29 +0200991 kotlincFlags = append(kotlincFlags, "-no-jdk")
992 }
993 if len(kotlincFlags) > 0 {
994 // optimization.
995 ctx.Variable(pctx, "kotlincFlags", strings.Join(kotlincFlags, " "))
996 flags.kotlincFlags += "$kotlincFlags"
Colin Cross93e85952017-08-15 13:34:18 -0700997 }
998
Przemyslaw Szczepaniak4b5fe9d2018-02-13 14:32:54 +0000999 var kotlinSrcFiles android.Paths
1000 kotlinSrcFiles = append(kotlinSrcFiles, uniqueSrcFiles...)
1001 kotlinSrcFiles = append(kotlinSrcFiles, srcFiles.FilterByExt(".kt")...)
1002
Colin Crossafbb1732019-01-17 15:42:52 -08001003 flags.classpath = append(flags.classpath, deps.kotlinStdlib...)
1004 flags.classpath = append(flags.classpath, deps.kotlinAnnotations...)
1005
1006 flags.kotlincClasspath = append(flags.kotlincClasspath, flags.bootClasspath...)
1007 flags.kotlincClasspath = append(flags.kotlincClasspath, flags.classpath...)
1008
1009 if len(flags.processorPath) > 0 {
1010 // Use kapt for annotation processing
1011 kaptSrcJar := android.PathForModuleOut(ctx, "kapt", "kapt-sources.jar")
1012 kotlinKapt(ctx, kaptSrcJar, kotlinSrcFiles, srcJars, flags)
1013 srcJars = append(srcJars, kaptSrcJar)
1014 // Disable annotation processing in javac, it's already been handled by kapt
1015 flags.processorPath = nil
Colin Cross3a3e94c2019-01-23 15:39:50 -08001016 flags.processor = ""
Colin Crossafbb1732019-01-17 15:42:52 -08001017 }
Colin Cross93e85952017-08-15 13:34:18 -07001018
Colin Cross1ee23172017-10-18 14:44:18 -07001019 kotlinJar := android.PathForModuleOut(ctx, "kotlin", jarName)
Colin Cross21fc9bb2019-01-18 15:05:09 -08001020 kotlinCompile(ctx, kotlinJar, kotlinSrcFiles, srcJars, flags)
Colin Cross93e85952017-08-15 13:34:18 -07001021 if ctx.Failed() {
1022 return
1023 }
1024
1025 // Make javac rule depend on the kotlinc rule
1026 flags.classpath = append(flags.classpath, kotlinJar)
Przemyslaw Szczepaniak66c0c402018-03-08 13:21:55 +00001027
Colin Cross93e85952017-08-15 13:34:18 -07001028 // Jar kotlin classes into the final jar after javac
Colin Cross55f63ea2018-08-27 12:37:09 -07001029 kotlinJars = append(kotlinJars, kotlinJar)
Colin Cross9b38aef2018-08-27 15:42:25 -07001030 kotlinJars = append(kotlinJars, deps.kotlinStdlib...)
Colin Cross93e85952017-08-15 13:34:18 -07001031 }
1032
Colin Cross55f63ea2018-08-27 12:37:09 -07001033 jars := append(android.Paths(nil), kotlinJars...)
1034
Colin Cross5ab4e6d2017-11-22 16:20:45 -08001035 // Store the list of .java files that was passed to javac
1036 j.compiledJavaSrcs = uniqueSrcFiles
1037 j.compiledSrcJars = srcJars
1038
Nan Zhang61eaedb2017-11-02 13:28:15 -07001039 enable_sharding := false
Colin Crossbe9cdb82019-01-21 21:37:16 -08001040 if ctx.Device() && !ctx.Config().IsEnvFalse("TURBINE_ENABLED") && !deps.disableTurbine {
Nan Zhang61eaedb2017-11-02 13:28:15 -07001041 if j.properties.Javac_shard_size != nil && *(j.properties.Javac_shard_size) > 0 {
1042 enable_sharding = true
Ashley Rosee36efcf2019-01-16 17:34:08 -05001043 // Formerly, there was a check here that prevented annotation processors
1044 // from being used when sharding was enabled, as some annotation processors
1045 // do not function correctly in sharded environments. It was removed to
1046 // allow for the use of annotation processors that do function correctly
1047 // with sharding enabled. See: b/77284273.
Nan Zhang61eaedb2017-11-02 13:28:15 -07001048 }
Colin Cross55f63ea2018-08-27 12:37:09 -07001049 j.headerJarFile = j.compileJavaHeader(ctx, uniqueSrcFiles, srcJars, deps, flags, jarName, kotlinJars)
Colin Crossf19b9bb2018-03-26 14:42:44 -07001050 if ctx.Failed() {
1051 return
Nan Zhanged19fc32017-10-19 13:06:22 -07001052 }
1053 }
Colin Cross8eadbf02017-10-24 17:46:00 -07001054 if len(uniqueSrcFiles) > 0 || len(srcJars) > 0 {
Colin Crossd6891432017-09-27 17:39:56 -07001055 var extraJarDeps android.Paths
Colin Cross66548102018-06-19 22:47:35 -07001056 if ctx.Config().RunErrorProne() {
Colin Crossc6bbef32017-08-14 14:16:06 -07001057 // If error-prone is enabled, add an additional rule to compile the java files into
1058 // a separate set of classes (so that they don't overwrite the normal ones and require
Colin Crossd6891432017-09-27 17:39:56 -07001059 // a rebuild when error-prone is turned off).
Colin Crossc6bbef32017-08-14 14:16:06 -07001060 // TODO(ccross): Once we always compile with javac9 we may be able to conditionally
1061 // enable error-prone without affecting the output class files.
Colin Cross1ee23172017-10-18 14:44:18 -07001062 errorprone := android.PathForModuleOut(ctx, "errorprone", jarName)
Nan Zhang61eaedb2017-11-02 13:28:15 -07001063 RunErrorProne(ctx, errorprone, uniqueSrcFiles, srcJars, flags)
Colin Crossc6bbef32017-08-14 14:16:06 -07001064 extraJarDeps = append(extraJarDeps, errorprone)
1065 }
1066
Nan Zhang61eaedb2017-11-02 13:28:15 -07001067 if enable_sharding {
Nan Zhang581fd212018-01-10 16:06:12 -08001068 flags.classpath = append(flags.classpath, j.headerJarFile)
Nan Zhang61eaedb2017-11-02 13:28:15 -07001069 shardSize := int(*(j.properties.Javac_shard_size))
1070 var shardSrcs []android.Paths
1071 if len(uniqueSrcFiles) > 0 {
1072 shardSrcs = shardPaths(uniqueSrcFiles, shardSize)
1073 for idx, shardSrc := range shardSrcs {
1074 classes := android.PathForModuleOut(ctx, "javac", jarName+strconv.Itoa(idx))
1075 TransformJavaToClasses(ctx, classes, idx, shardSrc, nil, flags, extraJarDeps)
1076 jars = append(jars, classes)
1077 }
1078 }
1079 if len(srcJars) > 0 {
1080 classes := android.PathForModuleOut(ctx, "javac", jarName+strconv.Itoa(len(shardSrcs)))
1081 TransformJavaToClasses(ctx, classes, len(shardSrcs), nil, srcJars, flags, extraJarDeps)
1082 jars = append(jars, classes)
1083 }
1084 } else {
1085 classes := android.PathForModuleOut(ctx, "javac", jarName)
1086 TransformJavaToClasses(ctx, classes, -1, uniqueSrcFiles, srcJars, flags, extraJarDeps)
1087 jars = append(jars, classes)
1088 }
Colin Crossd6891432017-09-27 17:39:56 -07001089 if ctx.Failed() {
1090 return
1091 }
Colin Cross2fe66872015-03-30 17:20:39 -07001092 }
1093
Colin Crosscedd4762018-09-13 11:26:19 -07001094 dirArgs, dirDeps := ResourceDirsToJarArgs(ctx, j.properties.Java_resource_dirs,
1095 j.properties.Exclude_java_resource_dirs, j.properties.Exclude_java_resources)
Colin Cross0f37af02017-09-27 17:42:05 -07001096 fileArgs, fileDeps := ResourceFilesToJarArgs(ctx, j.properties.Java_resources, j.properties.Exclude_java_resources)
1097
1098 var resArgs []string
1099 var resDeps android.Paths
1100
1101 resArgs = append(resArgs, dirArgs...)
1102 resDeps = append(resDeps, dirDeps...)
1103
1104 resArgs = append(resArgs, fileArgs...)
1105 resDeps = append(resDeps, fileDeps...)
1106
Colin Crossff3ae9d2018-04-10 16:15:18 -07001107 if Bool(j.properties.Include_srcs) {
Colin Cross23729232017-10-03 13:14:07 -07001108 srcArgs, srcDeps := SourceFilesToJarArgs(ctx, j.properties.Srcs, j.properties.Exclude_srcs)
Colin Cross0f37af02017-09-27 17:42:05 -07001109 resArgs = append(resArgs, srcArgs...)
1110 resDeps = append(resDeps, srcDeps...)
1111 }
Colin Cross40a36712017-09-27 17:41:35 -07001112
1113 if len(resArgs) > 0 {
Colin Cross1ee23172017-10-18 14:44:18 -07001114 resourceJar := android.PathForModuleOut(ctx, "res", jarName)
Colin Crosse9a275b2017-10-16 17:09:48 -07001115 TransformResourcesToJar(ctx, resourceJar, resArgs, resDeps)
Colin Cross331a1212018-08-15 20:40:52 -07001116 j.resourceJar = resourceJar
Colin Cross65bf4f22015-04-03 16:54:17 -07001117 if ctx.Failed() {
1118 return
1119 }
1120 }
1121
Colin Cross331a1212018-08-15 20:40:52 -07001122 if len(deps.staticResourceJars) > 0 {
1123 var jars android.Paths
1124 if j.resourceJar != nil {
1125 jars = append(jars, j.resourceJar)
1126 }
1127 jars = append(jars, deps.staticResourceJars...)
1128
1129 combinedJar := android.PathForModuleOut(ctx, "res-combined", jarName)
1130 TransformJarsToJar(ctx, combinedJar, "for resources", jars, android.OptionalPath{},
1131 false, nil, nil)
1132 j.resourceJar = combinedJar
1133 }
1134
Colin Cross32f676a2017-09-06 13:41:06 -07001135 jars = append(jars, deps.staticJars...)
Colin Cross331a1212018-08-15 20:40:52 -07001136 jars = append(jars, deps.staticResourceJars...)
Colin Cross0a6e0072017-08-30 14:24:55 -07001137
Colin Cross094054a2018-10-17 15:10:48 -07001138 manifest := j.overrideManifest
1139 if !manifest.Valid() && j.properties.Manifest != nil {
Colin Cross366938f2017-12-11 16:29:02 -08001140 manifest = android.OptionalPathForPath(ctx.ExpandSource(*j.properties.Manifest, "manifest"))
1141 }
Colin Cross635acc92017-09-12 22:50:46 -07001142
Alex Light7f004a72019-02-21 13:27:37 -08001143 services := ctx.ExpandSources(j.properties.Services, nil)
1144 if len(services) > 0 {
1145 servicesJar := android.PathForModuleOut(ctx, "services", jarName)
1146 var zipargs []string
1147 for _, file := range services {
1148 serviceFile := file.String()
1149 zipargs = append(zipargs, "-C", filepath.Dir(serviceFile), "-f", serviceFile)
1150 }
1151 ctx.Build(pctx, android.BuildParams{
1152 Rule: zip,
1153 Output: servicesJar,
1154 Implicits: services,
1155 Args: map[string]string{
1156 "jarArgs": "-P META-INF/services/ " + strings.Join(proptools.NinjaAndShellEscape(zipargs), " "),
1157 },
1158 })
1159 jars = append(jars, servicesJar)
1160 }
1161
Colin Cross0a6e0072017-08-30 14:24:55 -07001162 // Combine the classes built from sources, any manifests, and any static libraries into
Nan Zhanged19fc32017-10-19 13:06:22 -07001163 // classes.jar. If there is only one input jar this step will be skipped.
Colin Cross3063b782018-08-15 11:19:12 -07001164 var outputFile android.ModuleOutPath
Colin Crosse9a275b2017-10-16 17:09:48 -07001165
1166 if len(jars) == 1 && !manifest.Valid() {
Colin Cross3063b782018-08-15 11:19:12 -07001167 if moduleOutPath, ok := jars[0].(android.ModuleOutPath); ok {
1168 // Optimization: skip the combine step if there is nothing to do
1169 // TODO(ccross): this leaves any module-info.class files, but those should only come from
1170 // prebuilt dependencies until we support modules in the platform build, so there shouldn't be
1171 // any if len(jars) == 1.
1172 outputFile = moduleOutPath
1173 } else {
1174 combinedJar := android.PathForModuleOut(ctx, "combined", jarName)
1175 ctx.Build(pctx, android.BuildParams{
1176 Rule: android.Cp,
1177 Input: jars[0],
1178 Output: combinedJar,
1179 })
1180 outputFile = combinedJar
1181 }
Colin Crosse9a275b2017-10-16 17:09:48 -07001182 } else {
Colin Cross1ee23172017-10-18 14:44:18 -07001183 combinedJar := android.PathForModuleOut(ctx, "combined", jarName)
Colin Cross37f6d792018-07-12 12:28:41 -07001184 TransformJarsToJar(ctx, combinedJar, "for javac", jars, manifest,
Colin Cross9b38aef2018-08-27 15:42:25 -07001185 false, nil, nil)
Colin Crosse9a275b2017-10-16 17:09:48 -07001186 outputFile = combinedJar
1187 }
Colin Cross0a6e0072017-08-30 14:24:55 -07001188
Colin Cross331a1212018-08-15 20:40:52 -07001189 // jarjar implementation jar if necessary
Steven Morelandc4efd9c2019-01-18 11:51:25 -08001190 if j.expandJarjarRules != nil {
Colin Cross8649b262017-09-27 18:03:17 -07001191 // Transform classes.jar into classes-jarjar.jar
Colin Cross1ee23172017-10-18 14:44:18 -07001192 jarjarFile := android.PathForModuleOut(ctx, "jarjar", jarName)
Steven Morelandc4efd9c2019-01-18 11:51:25 -08001193 TransformJarJar(ctx, jarjarFile, outputFile, j.expandJarjarRules)
Colin Crosse9a275b2017-10-16 17:09:48 -07001194 outputFile = jarjarFile
Colin Cross331a1212018-08-15 20:40:52 -07001195
1196 // jarjar resource jar if necessary
1197 if j.resourceJar != nil {
1198 resourceJarJarFile := android.PathForModuleOut(ctx, "res-jarjar", jarName)
Steven Morelandc4efd9c2019-01-18 11:51:25 -08001199 TransformJarJar(ctx, resourceJarJarFile, j.resourceJar, j.expandJarjarRules)
Colin Cross331a1212018-08-15 20:40:52 -07001200 j.resourceJar = resourceJarJarFile
1201 }
1202
Colin Cross0a6e0072017-08-30 14:24:55 -07001203 if ctx.Failed() {
1204 return
1205 }
1206 }
Nan Zhanged19fc32017-10-19 13:06:22 -07001207 j.implementationJarFile = outputFile
1208 if j.headerJarFile == nil {
1209 j.headerJarFile = j.implementationJarFile
1210 }
Colin Cross2fe66872015-03-30 17:20:39 -07001211
Colin Cross6510f912017-11-29 00:27:14 -08001212 if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
Colin Crosscb933592017-11-22 13:49:43 -08001213 if inList(ctx.ModuleName(), config.InstrumentFrameworkModules) {
1214 j.properties.Instrument = true
1215 }
1216 }
1217
Colin Cross3144dfc2018-01-03 15:06:47 -08001218 if j.shouldInstrument(ctx) {
Colin Crosscb933592017-11-22 13:49:43 -08001219 outputFile = j.instrument(ctx, flags, outputFile, jarName)
1220 }
1221
Colin Cross331a1212018-08-15 20:40:52 -07001222 // merge implementation jar with resources if necessary
1223 implementationAndResourcesJar := outputFile
1224 if j.resourceJar != nil {
1225 jars := android.Paths{implementationAndResourcesJar, j.resourceJar}
1226 combinedJar := android.PathForModuleOut(ctx, "withres", jarName)
1227 TransformJarsToJar(ctx, combinedJar, "for resources", jars, android.OptionalPath{},
1228 false, nil, nil)
1229 implementationAndResourcesJar = combinedJar
1230 }
1231
1232 j.implementationAndResourcesJar = implementationAndResourcesJar
1233
Colin Cross9ae1b922018-06-26 17:59:05 -07001234 if ctx.Device() && (Bool(j.properties.Installable) || Bool(j.deviceProperties.Compile_dex)) {
Colin Cross8faf8fc2019-01-16 15:15:52 -08001235 // Dex compilation
Colin Cross3063b782018-08-15 11:19:12 -07001236 var dexOutputFile android.ModuleOutPath
David Brazdil17ef5632018-06-27 10:27:45 +01001237 dexOutputFile = j.compileDex(ctx, flags, outputFile, jarName)
Colin Cross2fe66872015-03-30 17:20:39 -07001238 if ctx.Failed() {
1239 return
1240 }
Colin Cross331a1212018-08-15 20:40:52 -07001241
Colin Cross8faf8fc2019-01-16 15:15:52 -08001242 // Hidden API CSV generation and dex encoding
Colin Crossf24a22a2019-01-31 14:12:44 -08001243 dexOutputFile = j.hiddenAPI.hiddenAPI(ctx, dexOutputFile, j.implementationJarFile,
1244 j.deviceProperties.UncompressDex)
Colin Cross8faf8fc2019-01-16 15:15:52 -08001245
Colin Cross331a1212018-08-15 20:40:52 -07001246 // merge dex jar with resources if necessary
1247 if j.resourceJar != nil {
1248 jars := android.Paths{dexOutputFile, j.resourceJar}
1249 combinedJar := android.PathForModuleOut(ctx, "dex-withres", jarName)
1250 TransformJarsToJar(ctx, combinedJar, "for dex resources", jars, android.OptionalPath{},
1251 false, nil, nil)
Nicolas Geoffrayf3438722019-01-23 15:57:21 +00001252 if j.deviceProperties.UncompressDex {
1253 combinedAlignedJar := android.PathForModuleOut(ctx, "dex-withres-aligned", jarName)
1254 TransformZipAlign(ctx, combinedAlignedJar, combinedJar)
1255 dexOutputFile = combinedAlignedJar
1256 } else {
1257 dexOutputFile = combinedJar
1258 }
Colin Cross331a1212018-08-15 20:40:52 -07001259 }
1260
1261 j.dexJarFile = dexOutputFile
1262
Colin Cross8faf8fc2019-01-16 15:15:52 -08001263 // Dexpreopting
Colin Cross43f08db2018-11-12 10:13:39 -08001264 dexOutputFile = j.dexpreopt(ctx, dexOutputFile)
1265
1266 j.maybeStrippedDexJarFile = dexOutputFile
1267
Colin Cross3063b782018-08-15 11:19:12 -07001268 outputFile = dexOutputFile
Colin Cross43f08db2018-11-12 10:13:39 -08001269
1270 if ctx.Failed() {
1271 return
1272 }
Colin Cross331a1212018-08-15 20:40:52 -07001273 } else {
1274 outputFile = implementationAndResourcesJar
Colin Cross2fe66872015-03-30 17:20:39 -07001275 }
Colin Cross331a1212018-08-15 20:40:52 -07001276
Colin Crossb7a63242015-04-16 14:09:14 -07001277 ctx.CheckbuildFile(outputFile)
Colin Cross3063b782018-08-15 11:19:12 -07001278
1279 // Save the output file with no relative path so that it doesn't end up in a subdirectory when used as a resource
1280 j.outputFile = outputFile.WithoutRel()
Colin Cross2fe66872015-03-30 17:20:39 -07001281}
1282
Zoran Jovanovic8736ce22018-08-21 17:10:29 +02001283// Check for invalid kotlinc flags. Only use this for flags explicitly passed by the user,
1284// since some of these flags may be used internally.
1285func CheckKotlincFlags(ctx android.ModuleContext, flags []string) {
1286 for _, flag := range flags {
1287 flag = strings.TrimSpace(flag)
1288
1289 if !strings.HasPrefix(flag, "-") {
1290 ctx.PropertyErrorf("kotlincflags", "Flag `%s` must start with `-`", flag)
1291 } else if strings.HasPrefix(flag, "-Xintellij-plugin-root") {
1292 ctx.PropertyErrorf("kotlincflags",
1293 "Bad flag: `%s`, only use internal compiler for consistency.", flag)
1294 } else if inList(flag, config.KotlincIllegalFlags) {
1295 ctx.PropertyErrorf("kotlincflags", "Flag `%s` already used by build system", flag)
1296 } else if flag == "-include-runtime" {
1297 ctx.PropertyErrorf("kotlincflags", "Bad flag: `%s`, do not include runtime.", flag)
1298 } else {
1299 args := strings.Split(flag, " ")
1300 if args[0] == "-kotlin-home" {
1301 ctx.PropertyErrorf("kotlincflags",
1302 "Bad flag: `%s`, kotlin home already set to default (path to kotlinc in the repo).", flag)
1303 }
1304 }
1305 }
1306}
1307
Colin Cross8eadbf02017-10-24 17:46:00 -07001308func (j *Module) compileJavaHeader(ctx android.ModuleContext, srcFiles, srcJars android.Paths,
Colin Cross55f63ea2018-08-27 12:37:09 -07001309 deps deps, flags javaBuilderFlags, jarName string, extraJars android.Paths) android.Path {
Nan Zhanged19fc32017-10-19 13:06:22 -07001310
1311 var jars android.Paths
Colin Cross8eadbf02017-10-24 17:46:00 -07001312 if len(srcFiles) > 0 || len(srcJars) > 0 {
Nan Zhanged19fc32017-10-19 13:06:22 -07001313 // Compile java sources into turbine.jar.
1314 turbineJar := android.PathForModuleOut(ctx, "turbine", jarName)
1315 TransformJavaToHeaderClasses(ctx, turbineJar, srcFiles, srcJars, flags)
1316 if ctx.Failed() {
1317 return nil
1318 }
1319 jars = append(jars, turbineJar)
1320 }
1321
Colin Cross55f63ea2018-08-27 12:37:09 -07001322 jars = append(jars, extraJars...)
1323
Nan Zhanged19fc32017-10-19 13:06:22 -07001324 // Combine any static header libraries into classes-header.jar. If there is only
1325 // one input jar this step will be skipped.
1326 var headerJar android.Path
1327 jars = append(jars, deps.staticHeaderJars...)
1328
Colin Cross5c6ecc12017-10-23 18:12:27 -07001329 // we cannot skip the combine step for now if there is only one jar
1330 // since we have to strip META-INF/TRANSITIVE dir from turbine.jar
1331 combinedJar := android.PathForModuleOut(ctx, "turbine-combined", jarName)
Colin Cross37f6d792018-07-12 12:28:41 -07001332 TransformJarsToJar(ctx, combinedJar, "for turbine", jars, android.OptionalPath{},
1333 false, nil, []string{"META-INF"})
Colin Cross5c6ecc12017-10-23 18:12:27 -07001334 headerJar = combinedJar
Nan Zhanged19fc32017-10-19 13:06:22 -07001335
Steven Morelandc4efd9c2019-01-18 11:51:25 -08001336 if j.expandJarjarRules != nil {
Nan Zhanged19fc32017-10-19 13:06:22 -07001337 // Transform classes.jar into classes-jarjar.jar
1338 jarjarFile := android.PathForModuleOut(ctx, "turbine-jarjar", jarName)
Steven Morelandc4efd9c2019-01-18 11:51:25 -08001339 TransformJarJar(ctx, jarjarFile, headerJar, j.expandJarjarRules)
Nan Zhanged19fc32017-10-19 13:06:22 -07001340 headerJar = jarjarFile
1341 if ctx.Failed() {
1342 return nil
1343 }
1344 }
1345
1346 return headerJar
1347}
1348
Colin Crosscb933592017-11-22 13:49:43 -08001349func (j *Module) instrument(ctx android.ModuleContext, flags javaBuilderFlags,
Colin Cross3063b782018-08-15 11:19:12 -07001350 classesJar android.Path, jarName string) android.ModuleOutPath {
Colin Crosscb933592017-11-22 13:49:43 -08001351
Colin Cross7a3139e2017-12-19 13:57:50 -08001352 specs := j.jacocoModuleToZipCommand(ctx)
Colin Crosscb933592017-11-22 13:49:43 -08001353
Colin Cross84c38822018-01-03 15:59:46 -08001354 jacocoReportClassesFile := android.PathForModuleOut(ctx, "jacoco-report-classes", jarName)
Colin Crosscb933592017-11-22 13:49:43 -08001355 instrumentedJar := android.PathForModuleOut(ctx, "jacoco", jarName)
1356
1357 jacocoInstrumentJar(ctx, instrumentedJar, jacocoReportClassesFile, classesJar, specs)
1358
1359 j.jacocoReportClassesFile = jacocoReportClassesFile
1360
1361 return instrumentedJar
1362}
1363
albaltai36ff7dc2018-12-25 14:35:23 +08001364var _ Dependency = (*Module)(nil)
Colin Cross2fe66872015-03-30 17:20:39 -07001365
Nan Zhanged19fc32017-10-19 13:06:22 -07001366func (j *Module) HeaderJars() android.Paths {
albaltai36ff7dc2018-12-25 14:35:23 +08001367 if j.headerJarFile == nil {
1368 return nil
1369 }
Nan Zhanged19fc32017-10-19 13:06:22 -07001370 return android.Paths{j.headerJarFile}
1371}
1372
1373func (j *Module) ImplementationJars() android.Paths {
shinwang9e4c07a2018-12-24 15:41:04 +08001374 if j.implementationJarFile == nil {
1375 return nil
1376 }
Nan Zhanged19fc32017-10-19 13:06:22 -07001377 return android.Paths{j.implementationJarFile}
Colin Cross2fe66872015-03-30 17:20:39 -07001378}
1379
Colin Crossf24a22a2019-01-31 14:12:44 -08001380func (j *Module) DexJar() android.Path {
1381 return j.dexJarFile
1382}
1383
Colin Cross331a1212018-08-15 20:40:52 -07001384func (j *Module) ResourceJars() android.Paths {
1385 if j.resourceJar == nil {
1386 return nil
1387 }
1388 return android.Paths{j.resourceJar}
1389}
1390
1391func (j *Module) ImplementationAndResourcesJars() android.Paths {
albaltai36ff7dc2018-12-25 14:35:23 +08001392 if j.implementationAndResourcesJar == nil {
1393 return nil
1394 }
Colin Cross331a1212018-08-15 20:40:52 -07001395 return android.Paths{j.implementationAndResourcesJar}
1396}
1397
Colin Cross46c9b8b2017-06-22 16:51:17 -07001398func (j *Module) AidlIncludeDirs() android.Paths {
albaltai36ff7dc2018-12-25 14:35:23 +08001399 // exportAidlIncludeDirs is type android.Paths already
Colin Crossc0b06f12015-04-08 13:03:43 -07001400 return j.exportAidlIncludeDirs
1401}
1402
Jiyong Park1be96912018-05-28 18:02:19 +09001403func (j *Module) ExportedSdkLibs() []string {
albaltai36ff7dc2018-12-25 14:35:23 +08001404 // exportedSdkLibs is type []string
Jiyong Park1be96912018-05-28 18:02:19 +09001405 return j.exportedSdkLibs
1406}
1407
Colin Cross46c9b8b2017-06-22 16:51:17 -07001408var _ logtagsProducer = (*Module)(nil)
Colin Crossf05fe972015-04-10 17:45:20 -07001409
Colin Cross46c9b8b2017-06-22 16:51:17 -07001410func (j *Module) logtags() android.Paths {
Colin Crossf05fe972015-04-10 17:45:20 -07001411 return j.logtagsSrcs
1412}
1413
Brandon Lee5d45c6f2018-08-15 15:35:38 -07001414// Collect information for opening IDE project files in java/jdeps.go.
1415func (j *Module) IDEInfo(dpInfo *android.IdeInfo) {
1416 dpInfo.Deps = append(dpInfo.Deps, j.CompilerDeps()...)
1417 dpInfo.Srcs = append(dpInfo.Srcs, j.expandIDEInfoCompiledSrcs...)
1418 dpInfo.Aidl_include_dirs = append(dpInfo.Aidl_include_dirs, j.deviceProperties.Aidl.Include_dirs...)
Steven Morelandc4efd9c2019-01-18 11:51:25 -08001419 if j.expandJarjarRules != nil {
1420 dpInfo.Jarjar_rules = append(dpInfo.Jarjar_rules, j.expandJarjarRules.String())
Brandon Lee5d45c6f2018-08-15 15:35:38 -07001421 }
1422}
1423
1424func (j *Module) CompilerDeps() []string {
1425 jdeps := []string{}
1426 jdeps = append(jdeps, j.properties.Libs...)
1427 jdeps = append(jdeps, j.properties.Static_libs...)
1428 return jdeps
1429}
1430
Colin Cross2fe66872015-03-30 17:20:39 -07001431//
1432// Java libraries (.jar file)
1433//
1434
Colin Crossf506d872017-07-19 15:53:04 -07001435type Library struct {
Colin Cross46c9b8b2017-06-22 16:51:17 -07001436 Module
Colin Cross2fe66872015-03-30 17:20:39 -07001437}
1438
Colin Cross2fc72f62018-12-21 12:59:54 -08001439func (j *Library) shouldUncompressDex(ctx android.ModuleContext) bool {
Nicolas Geoffrayfa6e9ec2019-02-12 13:12:16 +00001440 // Store uncompressed (and do not strip) dex files from boot class path jars.
1441 if inList(ctx.ModuleName(), ctx.Config().BootJars()) {
1442 return true
1443 }
1444
1445 // Store uncompressed dex files that are preopted on /system.
1446 if !j.dexpreopter.dexpreoptDisabled(ctx) && (ctx.Host() || !odexOnSystemOther(ctx, j.dexpreopter.installPath)) {
Vladimir Markoe8b00d62018-12-21 15:54:16 +00001447 return true
1448 }
Colin Cross083a2aa2019-02-06 16:37:12 -08001449 if ctx.Config().UncompressPrivAppDex() &&
1450 inList(ctx.ModuleName(), ctx.Config().ModulesLoadedByPrivilegedModules()) {
1451 return true
1452 }
1453
Colin Cross2fc72f62018-12-21 12:59:54 -08001454 return false
1455}
1456
Colin Crossf506d872017-07-19 15:53:04 -07001457func (j *Library) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross43f08db2018-11-12 10:13:39 -08001458 j.dexpreopter.installPath = android.PathForModuleInstall(ctx, "framework", ctx.ModuleName()+".jar")
1459 j.dexpreopter.isSDKLibrary = j.deviceProperties.IsSDKLibrary
Nicolas Geoffrayfa6e9ec2019-02-12 13:12:16 +00001460 j.dexpreopter.isInstallable = Bool(j.properties.Installable)
1461 j.dexpreopter.uncompressedDex = j.shouldUncompressDex(ctx)
1462 j.deviceProperties.UncompressDex = j.dexpreopter.uncompressedDex
Colin Cross46c9b8b2017-06-22 16:51:17 -07001463 j.compile(ctx)
Colin Crossb7a63242015-04-16 14:09:14 -07001464
Nicolas Geoffray4bdea392019-01-15 11:48:08 +00001465 if (Bool(j.properties.Installable) || ctx.Host()) && !android.DirectlyInAnyApex(ctx, ctx.ModuleName()) {
Colin Cross2c429dc2017-08-31 16:45:16 -07001466 j.installFile = ctx.InstallFile(android.PathForModuleInstall(ctx, "framework"),
1467 ctx.ModuleName()+".jar", j.outputFile)
1468 }
Colin Crossb7a63242015-04-16 14:09:14 -07001469}
1470
Colin Crossf506d872017-07-19 15:53:04 -07001471func (j *Library) DepsMutator(ctx android.BottomUpMutatorContext) {
Colin Cross46c9b8b2017-06-22 16:51:17 -07001472 j.deps(ctx)
1473}
1474
Colin Cross1b16b0e2019-02-12 14:41:32 -08001475// java_library builds and links sources into a `.jar` file for the device, and possibly for the host as well.
1476//
1477// By default, a java_library has a single variant that produces a `.jar` file containing `.class` files that were
1478// compiled against the device bootclasspath. This jar is not suitable for installing on a device, but can be used
1479// as a `static_libs` dependency of another module.
1480//
1481// Specifying `installable: true` will product a `.jar` file containing `classes.dex` files, suitable for installing on
1482// a device.
1483//
1484// Specifying `host_supported: true` will produce two variants, one compiled against the device bootclasspath and one
1485// compiled against the host bootclasspath.
Colin Cross9ae1b922018-06-26 17:59:05 -07001486func LibraryFactory() android.Module {
1487 module := &Library{}
Colin Cross2fe66872015-03-30 17:20:39 -07001488
Colin Cross9ae1b922018-06-26 17:59:05 -07001489 module.AddProperties(
1490 &module.Module.properties,
1491 &module.Module.deviceProperties,
Colin Cross43f08db2018-11-12 10:13:39 -08001492 &module.Module.dexpreoptProperties,
Colin Cross9ae1b922018-06-26 17:59:05 -07001493 &module.Module.protoProperties)
Colin Cross2fe66872015-03-30 17:20:39 -07001494
Colin Cross9ae1b922018-06-26 17:59:05 -07001495 InitJavaModule(module, android.HostAndDeviceSupported)
1496 return module
Colin Cross2fe66872015-03-30 17:20:39 -07001497}
1498
Colin Cross1b16b0e2019-02-12 14:41:32 -08001499// java_library_static is an obsolete alias for java_library.
1500func LibraryStaticFactory() android.Module {
1501 return LibraryFactory()
1502}
1503
1504// java_library_host builds and links sources into a `.jar` file for the host.
1505//
1506// A java_library_host has a single variant that produces a `.jar` file containing `.class` files that were
1507// compiled against the host bootclasspath.
Colin Crossf506d872017-07-19 15:53:04 -07001508func LibraryHostFactory() android.Module {
1509 module := &Library{}
Colin Cross2fe66872015-03-30 17:20:39 -07001510
Colin Cross6af17aa2017-09-20 12:59:05 -07001511 module.AddProperties(
1512 &module.Module.properties,
1513 &module.Module.protoProperties)
Colin Cross36242852017-06-23 15:06:31 -07001514
Colin Cross9ae1b922018-06-26 17:59:05 -07001515 module.Module.properties.Installable = proptools.BoolPtr(true)
1516
Colin Cross89536d42017-07-07 14:35:50 -07001517 InitJavaModule(module, android.HostSupported)
Colin Cross36242852017-06-23 15:06:31 -07001518 return module
Colin Cross2fe66872015-03-30 17:20:39 -07001519}
1520
1521//
Colin Crossb628ea52018-08-14 16:42:33 -07001522// Java Tests
Colin Cross05638fc2018-04-09 18:40:24 -07001523//
1524
1525type testProperties struct {
Colin Cross05638fc2018-04-09 18:40:24 -07001526 // list of compatibility suites (for example "cts", "vts") that the module should be
1527 // installed into.
1528 Test_suites []string `android:"arch_variant"`
Julien Despreze146e392018-08-02 15:00:46 -07001529
1530 // the name of the test configuration (for example "AndroidTest.xml") that should be
1531 // installed with the module.
1532 Test_config *string `android:"arch_variant"`
Colin Crossd96ca352018-08-10 16:06:24 -07001533
Jack He33338892018-09-19 02:21:28 -07001534 // the name of the test configuration template (for example "AndroidTestTemplate.xml") that
1535 // should be installed with the module.
1536 Test_config_template *string `android:"arch_variant"`
1537
Colin Crossd96ca352018-08-10 16:06:24 -07001538 // list of files or filegroup modules that provide data that should be installed alongside
1539 // the test
1540 Data []string
Colin Cross05638fc2018-04-09 18:40:24 -07001541}
1542
1543type Test struct {
1544 Library
1545
1546 testProperties testProperties
Colin Cross303e21f2018-08-07 16:49:25 -07001547
1548 testConfig android.Path
Colin Crossd96ca352018-08-10 16:06:24 -07001549 data android.Paths
Colin Cross303e21f2018-08-07 16:49:25 -07001550}
1551
1552func (j *Test) GenerateAndroidBuildActions(ctx android.ModuleContext) {
yangbill4f41bc22019-02-13 21:45:47 +08001553 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 -07001554 j.data = ctx.ExpandSources(j.testProperties.Data, nil)
Colin Cross303e21f2018-08-07 16:49:25 -07001555
1556 j.Library.GenerateAndroidBuildActions(ctx)
Colin Cross05638fc2018-04-09 18:40:24 -07001557}
1558
1559func (j *Test) DepsMutator(ctx android.BottomUpMutatorContext) {
1560 j.deps(ctx)
Colin Cross303e21f2018-08-07 16:49:25 -07001561 android.ExtractSourceDeps(ctx, j.testProperties.Test_config)
Jack He33338892018-09-19 02:21:28 -07001562 android.ExtractSourceDeps(ctx, j.testProperties.Test_config_template)
Colin Crossd96ca352018-08-10 16:06:24 -07001563 android.ExtractSourcesDeps(ctx, j.testProperties.Data)
Colin Cross05638fc2018-04-09 18:40:24 -07001564}
1565
Colin Cross1b16b0e2019-02-12 14:41:32 -08001566// java_test builds a and links sources into a `.jar` file for the device, and possibly for the host as well, and
1567// creates an `AndroidTest.xml` file to allow running the test with `atest` or a `TEST_MAPPING` file.
1568//
1569// By default, a java_test has a single variant that produces a `.jar` file containing `classes.dex` files that were
1570// compiled against the device bootclasspath.
1571//
1572// Specifying `host_supported: true` will produce two variants, one compiled against the device bootclasspath and one
1573// compiled against the host bootclasspath.
Colin Cross05638fc2018-04-09 18:40:24 -07001574func TestFactory() android.Module {
1575 module := &Test{}
1576
1577 module.AddProperties(
1578 &module.Module.properties,
1579 &module.Module.deviceProperties,
Colin Cross43f08db2018-11-12 10:13:39 -08001580 &module.Module.dexpreoptProperties,
Colin Cross05638fc2018-04-09 18:40:24 -07001581 &module.Module.protoProperties,
1582 &module.testProperties)
1583
Colin Cross9ae1b922018-06-26 17:59:05 -07001584 module.Module.properties.Installable = proptools.BoolPtr(true)
Colin Crosse3026872019-01-05 22:30:13 -08001585 module.Module.dexpreopter.isTest = true
Colin Cross9ae1b922018-06-26 17:59:05 -07001586
Colin Cross05638fc2018-04-09 18:40:24 -07001587 InitJavaModule(module, android.HostAndDeviceSupported)
Colin Cross05638fc2018-04-09 18:40:24 -07001588 return module
1589}
1590
Colin Cross1b16b0e2019-02-12 14:41:32 -08001591// java_test_host builds a and links sources into a `.jar` file for the host, and creates an `AndroidTest.xml` file to
1592// allow running the test with `atest` or a `TEST_MAPPING` file.
1593//
1594// A java_test_host has a single variant that produces a `.jar` file containing `.class` files that were
1595// compiled against the host bootclasspath.
Colin Cross05638fc2018-04-09 18:40:24 -07001596func TestHostFactory() android.Module {
1597 module := &Test{}
1598
1599 module.AddProperties(
1600 &module.Module.properties,
1601 &module.Module.protoProperties,
1602 &module.testProperties)
1603
Colin Cross9ae1b922018-06-26 17:59:05 -07001604 module.Module.properties.Installable = proptools.BoolPtr(true)
1605
Colin Cross05638fc2018-04-09 18:40:24 -07001606 InitJavaModule(module, android.HostSupported)
Colin Cross05638fc2018-04-09 18:40:24 -07001607 return module
1608}
1609
1610//
Colin Cross2fe66872015-03-30 17:20:39 -07001611// Java Binaries (.jar file plus wrapper script)
1612//
1613
Colin Crossf506d872017-07-19 15:53:04 -07001614type binaryProperties struct {
Colin Cross7d5136f2015-05-11 13:39:40 -07001615 // installable script to execute the resulting jar
Nan Zhangea568a42017-11-08 21:20:04 -08001616 Wrapper *string
Colin Cross094054a2018-10-17 15:10:48 -07001617
1618 // Name of the class containing main to be inserted into the manifest as Main-Class.
1619 Main_class *string
Colin Cross7d5136f2015-05-11 13:39:40 -07001620}
1621
Colin Crossf506d872017-07-19 15:53:04 -07001622type Binary struct {
1623 Library
Colin Cross2fe66872015-03-30 17:20:39 -07001624
Colin Crossf506d872017-07-19 15:53:04 -07001625 binaryProperties binaryProperties
Colin Cross10a03492017-08-10 17:09:43 -07001626
Colin Cross6b4a32d2017-12-05 13:42:45 -08001627 isWrapperVariant bool
1628
Colin Crossc3315992017-12-08 19:12:36 -08001629 wrapperFile android.Path
Colin Cross10a03492017-08-10 17:09:43 -07001630 binaryFile android.OutputPath
Colin Cross2fe66872015-03-30 17:20:39 -07001631}
1632
Alex Light24237172017-10-26 09:46:21 -07001633func (j *Binary) HostToolPath() android.OptionalPath {
1634 return android.OptionalPathForPath(j.binaryFile)
1635}
1636
Colin Crossf506d872017-07-19 15:53:04 -07001637func (j *Binary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross6b4a32d2017-12-05 13:42:45 -08001638 if ctx.Arch().ArchType == android.Common {
1639 // Compile the jar
Colin Cross094054a2018-10-17 15:10:48 -07001640 if j.binaryProperties.Main_class != nil {
1641 if j.properties.Manifest != nil {
1642 ctx.PropertyErrorf("main_class", "main_class cannot be used when manifest is set")
1643 }
1644 manifestFile := android.PathForModuleOut(ctx, "manifest.txt")
1645 GenerateMainClassManifest(ctx, manifestFile, String(j.binaryProperties.Main_class))
1646 j.overrideManifest = android.OptionalPathForPath(manifestFile)
1647 }
1648
Colin Cross6b4a32d2017-12-05 13:42:45 -08001649 j.Library.GenerateAndroidBuildActions(ctx)
Nan Zhang3c807db2017-11-03 14:53:31 -07001650 } else {
Colin Cross6b4a32d2017-12-05 13:42:45 -08001651 // Handle the binary wrapper
1652 j.isWrapperVariant = true
1653
Colin Cross366938f2017-12-11 16:29:02 -08001654 if j.binaryProperties.Wrapper != nil {
1655 j.wrapperFile = ctx.ExpandSource(*j.binaryProperties.Wrapper, "wrapper")
Colin Cross6b4a32d2017-12-05 13:42:45 -08001656 } else {
1657 j.wrapperFile = android.PathForSource(ctx, "build/soong/scripts/jar-wrapper.sh")
1658 }
1659
1660 // Depend on the installed jar so that the wrapper doesn't get executed by
1661 // another build rule before the jar has been installed.
1662 jarFile := ctx.PrimaryModule().(*Binary).installFile
1663
1664 j.binaryFile = ctx.InstallExecutable(android.PathForModuleInstall(ctx, "bin"),
1665 ctx.ModuleName(), j.wrapperFile, jarFile)
Nan Zhang3c807db2017-11-03 14:53:31 -07001666 }
Colin Cross2fe66872015-03-30 17:20:39 -07001667}
1668
Colin Crossf506d872017-07-19 15:53:04 -07001669func (j *Binary) DepsMutator(ctx android.BottomUpMutatorContext) {
Colin Cross6b4a32d2017-12-05 13:42:45 -08001670 if ctx.Arch().ArchType == android.Common {
1671 j.deps(ctx)
Colin Crossc3315992017-12-08 19:12:36 -08001672 } else {
Colin Cross366938f2017-12-11 16:29:02 -08001673 android.ExtractSourceDeps(ctx, j.binaryProperties.Wrapper)
Colin Cross6b4a32d2017-12-05 13:42:45 -08001674 }
Colin Cross46c9b8b2017-06-22 16:51:17 -07001675}
1676
Colin Cross1b16b0e2019-02-12 14:41:32 -08001677// java_binary builds a `.jar` file and a shell script that executes it for the device, and possibly for the host
1678// as well.
1679//
1680// By default, a java_binary has a single variant that produces a `.jar` file containing `classes.dex` files that were
1681// compiled against the device bootclasspath.
1682//
1683// Specifying `host_supported: true` will produce two variants, one compiled against the device bootclasspath and one
1684// compiled against the host bootclasspath.
Colin Crossf506d872017-07-19 15:53:04 -07001685func BinaryFactory() android.Module {
1686 module := &Binary{}
Colin Cross2fe66872015-03-30 17:20:39 -07001687
Colin Cross36242852017-06-23 15:06:31 -07001688 module.AddProperties(
Colin Cross540eff82017-06-22 17:01:52 -07001689 &module.Module.properties,
1690 &module.Module.deviceProperties,
Colin Cross43f08db2018-11-12 10:13:39 -08001691 &module.Module.dexpreoptProperties,
Colin Cross6af17aa2017-09-20 12:59:05 -07001692 &module.Module.protoProperties,
Colin Cross540eff82017-06-22 17:01:52 -07001693 &module.binaryProperties)
Colin Cross36242852017-06-23 15:06:31 -07001694
Colin Cross9ae1b922018-06-26 17:59:05 -07001695 module.Module.properties.Installable = proptools.BoolPtr(true)
1696
Colin Cross6b4a32d2017-12-05 13:42:45 -08001697 android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibCommonFirst)
1698 android.InitDefaultableModule(module)
Colin Cross36242852017-06-23 15:06:31 -07001699 return module
Colin Cross2fe66872015-03-30 17:20:39 -07001700}
1701
Colin Cross1b16b0e2019-02-12 14:41:32 -08001702// java_binary_host builds a `.jar` file and a shell script that executes it for the host.
1703//
1704// A java_binary_host has a single variant that produces a `.jar` file containing `.class` files that were
1705// compiled against the host bootclasspath.
Colin Crossf506d872017-07-19 15:53:04 -07001706func BinaryHostFactory() android.Module {
1707 module := &Binary{}
Colin Cross2fe66872015-03-30 17:20:39 -07001708
Colin Cross36242852017-06-23 15:06:31 -07001709 module.AddProperties(
Colin Cross540eff82017-06-22 17:01:52 -07001710 &module.Module.properties,
Colin Cross6af17aa2017-09-20 12:59:05 -07001711 &module.Module.protoProperties,
Colin Cross540eff82017-06-22 17:01:52 -07001712 &module.binaryProperties)
Colin Cross36242852017-06-23 15:06:31 -07001713
Colin Cross9ae1b922018-06-26 17:59:05 -07001714 module.Module.properties.Installable = proptools.BoolPtr(true)
1715
Colin Cross6b4a32d2017-12-05 13:42:45 -08001716 android.InitAndroidArchModule(module, android.HostSupported, android.MultilibCommonFirst)
1717 android.InitDefaultableModule(module)
Colin Cross36242852017-06-23 15:06:31 -07001718 return module
Colin Cross2fe66872015-03-30 17:20:39 -07001719}
1720
1721//
1722// Java prebuilts
1723//
1724
Colin Cross74d73e22017-08-02 11:05:49 -07001725type ImportProperties struct {
1726 Jars []string
Colin Cross461bd1a2017-10-20 13:59:18 -07001727
Nan Zhangea568a42017-11-08 21:20:04 -08001728 Sdk_version *string
Colin Cross535e2cf2017-10-20 17:57:49 -07001729
1730 Installable *bool
Jiyong Park1be96912018-05-28 18:02:19 +09001731
1732 // List of shared java libs that this module has dependencies to
1733 Libs []string
Colin Cross37f6d792018-07-12 12:28:41 -07001734
1735 // List of files to remove from the jar file(s)
1736 Exclude_files []string
1737
1738 // List of directories to remove from the jar file(s)
1739 Exclude_dirs []string
Nan Zhang4c819fb2018-08-27 18:31:46 -07001740
1741 // if set to true, run Jetifier against .jar file. Defaults to false.
1742 Jetifier_enabled *bool
Colin Cross74d73e22017-08-02 11:05:49 -07001743}
1744
1745type Import struct {
Colin Cross635c3b02016-05-18 15:37:25 -07001746 android.ModuleBase
Colin Cross48de9a42018-10-02 13:53:33 -07001747 android.DefaultableModuleBase
Colin Crossec7a0422017-07-07 14:47:12 -07001748 prebuilt android.Prebuilt
Colin Cross2fe66872015-03-30 17:20:39 -07001749
Colin Cross74d73e22017-08-02 11:05:49 -07001750 properties ImportProperties
1751
Colin Cross0a6e0072017-08-30 14:24:55 -07001752 combinedClasspathFile android.Path
Jiyong Park1be96912018-05-28 18:02:19 +09001753 exportedSdkLibs []string
Colin Cross2fe66872015-03-30 17:20:39 -07001754}
1755
Colin Cross83bb3162018-06-25 15:48:06 -07001756func (j *Import) sdkVersion() string {
1757 return String(j.properties.Sdk_version)
1758}
1759
1760func (j *Import) minSdkVersion() string {
1761 return j.sdkVersion()
1762}
1763
Colin Cross74d73e22017-08-02 11:05:49 -07001764func (j *Import) Prebuilt() *android.Prebuilt {
Colin Crossec7a0422017-07-07 14:47:12 -07001765 return &j.prebuilt
1766}
1767
Colin Cross74d73e22017-08-02 11:05:49 -07001768func (j *Import) PrebuiltSrcs() []string {
1769 return j.properties.Jars
1770}
1771
1772func (j *Import) Name() string {
Colin Cross5ea9bcc2017-07-27 15:41:32 -07001773 return j.prebuilt.Name(j.ModuleBase.Name())
1774}
1775
Colin Cross74d73e22017-08-02 11:05:49 -07001776func (j *Import) DepsMutator(ctx android.BottomUpMutatorContext) {
Colin Cross37f6d792018-07-12 12:28:41 -07001777 android.ExtractSourcesDeps(ctx, j.properties.Jars)
Colin Cross42d48b72018-08-29 14:10:52 -07001778 ctx.AddVariationDependencies(nil, libTag, j.properties.Libs...)
Colin Cross1e676be2016-10-12 14:38:15 -07001779}
1780
Colin Cross74d73e22017-08-02 11:05:49 -07001781func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross37f6d792018-07-12 12:28:41 -07001782 jars := ctx.ExpandSources(j.properties.Jars, nil)
Colin Crosse1d62a82015-04-03 16:53:05 -07001783
Nan Zhang4c819fb2018-08-27 18:31:46 -07001784 jarName := ctx.ModuleName() + ".jar"
1785 outputFile := android.PathForModuleOut(ctx, "combined", jarName)
Colin Cross37f6d792018-07-12 12:28:41 -07001786 TransformJarsToJar(ctx, outputFile, "for prebuilts", jars, android.OptionalPath{},
1787 false, j.properties.Exclude_files, j.properties.Exclude_dirs)
Nan Zhang4c819fb2018-08-27 18:31:46 -07001788 if Bool(j.properties.Jetifier_enabled) {
1789 inputFile := outputFile
1790 outputFile = android.PathForModuleOut(ctx, "jetifier", jarName)
1791 TransformJetifier(ctx, outputFile, inputFile)
1792 }
Colin Crosse9a275b2017-10-16 17:09:48 -07001793 j.combinedClasspathFile = outputFile
Jiyong Park1be96912018-05-28 18:02:19 +09001794
1795 ctx.VisitDirectDeps(func(module android.Module) {
1796 otherName := ctx.OtherModuleName(module)
1797 tag := ctx.OtherModuleDependencyTag(module)
1798
1799 switch dep := module.(type) {
1800 case Dependency:
1801 switch tag {
1802 case libTag, staticLibTag:
1803 // sdk lib names from dependencies are re-exported
1804 j.exportedSdkLibs = append(j.exportedSdkLibs, dep.ExportedSdkLibs()...)
1805 }
1806 case SdkLibraryDependency:
1807 switch tag {
1808 case libTag:
1809 // names of sdk libs that are directly depended are exported
1810 j.exportedSdkLibs = append(j.exportedSdkLibs, otherName)
1811 }
1812 }
1813 })
1814
1815 j.exportedSdkLibs = android.FirstUniqueStrings(j.exportedSdkLibs)
Nan Zhang4973ecf2018-08-10 13:42:12 -07001816 if Bool(j.properties.Installable) {
1817 ctx.InstallFile(android.PathForModuleInstall(ctx, "framework"),
1818 ctx.ModuleName()+".jar", outputFile)
1819 }
Colin Cross2fe66872015-03-30 17:20:39 -07001820}
1821
Colin Cross74d73e22017-08-02 11:05:49 -07001822var _ Dependency = (*Import)(nil)
Colin Cross2fe66872015-03-30 17:20:39 -07001823
Nan Zhanged19fc32017-10-19 13:06:22 -07001824func (j *Import) HeaderJars() android.Paths {
albaltai36ff7dc2018-12-25 14:35:23 +08001825 if j.combinedClasspathFile == nil {
1826 return nil
1827 }
Colin Cross37f6d792018-07-12 12:28:41 -07001828 return android.Paths{j.combinedClasspathFile}
Nan Zhanged19fc32017-10-19 13:06:22 -07001829}
1830
1831func (j *Import) ImplementationJars() android.Paths {
shinwang9e4c07a2018-12-24 15:41:04 +08001832 if j.combinedClasspathFile == nil {
1833 return nil
1834 }
Colin Cross37f6d792018-07-12 12:28:41 -07001835 return android.Paths{j.combinedClasspathFile}
Colin Cross2fe66872015-03-30 17:20:39 -07001836}
1837
Colin Cross331a1212018-08-15 20:40:52 -07001838func (j *Import) ResourceJars() android.Paths {
1839 return nil
1840}
1841
1842func (j *Import) ImplementationAndResourcesJars() android.Paths {
albaltai36ff7dc2018-12-25 14:35:23 +08001843 if j.combinedClasspathFile == nil {
1844 return nil
1845 }
Colin Cross331a1212018-08-15 20:40:52 -07001846 return android.Paths{j.combinedClasspathFile}
1847}
1848
Colin Crossf24a22a2019-01-31 14:12:44 -08001849func (j *Import) DexJar() android.Path {
1850 return nil
1851}
1852
Colin Cross74d73e22017-08-02 11:05:49 -07001853func (j *Import) AidlIncludeDirs() android.Paths {
Colin Crossc0b06f12015-04-08 13:03:43 -07001854 return nil
1855}
1856
Jiyong Park1be96912018-05-28 18:02:19 +09001857func (j *Import) ExportedSdkLibs() []string {
1858 return j.exportedSdkLibs
1859}
1860
albaltai36ff7dc2018-12-25 14:35:23 +08001861// Add compile time check for interface implementation
1862var _ android.IDEInfo = (*Import)(nil)
1863var _ android.IDECustomizedModuleName = (*Import)(nil)
1864
Brandon Lee5d45c6f2018-08-15 15:35:38 -07001865// Collect information for opening IDE project files in java/jdeps.go.
1866const (
1867 removedPrefix = "prebuilt_"
1868)
1869
1870func (j *Import) IDEInfo(dpInfo *android.IdeInfo) {
1871 dpInfo.Jars = append(dpInfo.Jars, j.PrebuiltSrcs()...)
1872}
1873
1874func (j *Import) IDECustomizedModuleName() string {
1875 // TODO(b/113562217): Extract the base module name from the Import name, often the Import name
1876 // has a prefix "prebuilt_". Remove the prefix explicitly if needed until we find a better
1877 // solution to get the Import name.
1878 name := j.Name()
1879 if strings.HasPrefix(name, removedPrefix) {
patricktubb640e02018-10-11 18:33:16 +08001880 name = strings.TrimPrefix(name, removedPrefix)
Brandon Lee5d45c6f2018-08-15 15:35:38 -07001881 }
1882 return name
1883}
1884
Colin Cross74d73e22017-08-02 11:05:49 -07001885var _ android.PrebuiltInterface = (*Import)(nil)
Colin Cross2fe66872015-03-30 17:20:39 -07001886
Colin Cross1b16b0e2019-02-12 14:41:32 -08001887// java_import imports one or more `.jar` files into the build graph as if they were built by a java_library module.
1888//
1889// By default, a java_import has a single variant that expects a `.jar` file containing `.class` files that were
1890// compiled against an Android classpath.
1891//
1892// Specifying `host_supported: true` will produce two variants, one for use as a dependency of device modules and one
1893// for host modules.
Colin Cross74d73e22017-08-02 11:05:49 -07001894func ImportFactory() android.Module {
1895 module := &Import{}
Colin Cross36242852017-06-23 15:06:31 -07001896
Colin Cross74d73e22017-08-02 11:05:49 -07001897 module.AddProperties(&module.properties)
1898
1899 android.InitPrebuiltModule(module, &module.properties.Jars)
Colin Cross48de9a42018-10-02 13:53:33 -07001900 InitJavaModule(module, android.HostAndDeviceSupported)
Colin Cross36242852017-06-23 15:06:31 -07001901 return module
Colin Cross2fe66872015-03-30 17:20:39 -07001902}
1903
Colin Cross1b16b0e2019-02-12 14:41:32 -08001904// java_import imports one or more `.jar` files into the build graph as if they were built by a java_library_host
1905// module.
1906//
1907// A java_import_host has a single variant that expects a `.jar` file containing `.class` files that were
1908// compiled against a host bootclasspath.
Colin Cross74d73e22017-08-02 11:05:49 -07001909func ImportFactoryHost() android.Module {
1910 module := &Import{}
1911
1912 module.AddProperties(&module.properties)
1913
1914 android.InitPrebuiltModule(module, &module.properties.Jars)
Colin Cross48de9a42018-10-02 13:53:33 -07001915 InitJavaModule(module, android.HostSupported)
Colin Cross74d73e22017-08-02 11:05:49 -07001916 return module
1917}
1918
Colin Cross89536d42017-07-07 14:35:50 -07001919//
1920// Defaults
1921//
1922type Defaults struct {
1923 android.ModuleBase
1924 android.DefaultsModuleBase
1925}
1926
1927func (*Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1928}
1929
Colin Cross1b16b0e2019-02-12 14:41:32 -08001930// java_defaults provides a set of properties that can be inherited by other java or android modules.
1931//
1932// A module can use the properties from a java_defaults module using `defaults: ["defaults_module_name"]`. Each
1933// property in the defaults module that exists in the depending module will be prepended to the depending module's
1934// value for that property.
1935//
1936// Example:
1937//
1938// java_defaults {
1939// name: "example_defaults",
1940// srcs: ["common/**/*.java"],
1941// javacflags: ["-Xlint:all"],
1942// aaptflags: ["--auto-add-overlay"],
1943// }
1944//
1945// java_library {
1946// name: "example",
1947// defaults: ["example_defaults"],
1948// srcs: ["example/**/*.java"],
1949// }
1950//
1951// is functionally identical to:
1952//
1953// java_library {
1954// name: "example",
1955// srcs: [
1956// "common/**/*.java",
1957// "example/**/*.java",
1958// ],
1959// javacflags: ["-Xlint:all"],
1960// }
Colin Cross89536d42017-07-07 14:35:50 -07001961func defaultsFactory() android.Module {
1962 return DefaultsFactory()
1963}
1964
1965func DefaultsFactory(props ...interface{}) android.Module {
1966 module := &Defaults{}
1967
1968 module.AddProperties(props...)
1969 module.AddProperties(
1970 &CompilerProperties{},
1971 &CompilerDeviceProperties{},
Colin Cross43f08db2018-11-12 10:13:39 -08001972 &DexpreoptProperties{},
Dan Willemsen6424d172018-03-08 13:27:59 -08001973 &android.ProtoProperties{},
Colin Cross48de9a42018-10-02 13:53:33 -07001974 &aaptProperties{},
1975 &androidLibraryProperties{},
1976 &appProperties{},
1977 &appTestProperties{},
1978 &ImportProperties{},
1979 &AARImportProperties{},
1980 &sdkLibraryProperties{},
Colin Cross89536d42017-07-07 14:35:50 -07001981 )
1982
1983 android.InitDefaultsModule(module)
1984
1985 return module
1986}
Nan Zhangea568a42017-11-08 21:20:04 -08001987
1988var Bool = proptools.Bool
Colin Cross38b40df2018-04-10 16:14:46 -07001989var BoolDefault = proptools.BoolDefault
Nan Zhangea568a42017-11-08 21:20:04 -08001990var String = proptools.String
Colin Cross0d0ba592018-02-20 13:33:42 -08001991var inList = android.InList