blob: 52d97c9e186466e56b2b82b37554348db71850b9 [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 Cross0a6e0072017-08-30 14:24:55 -07001136
Colin Cross094054a2018-10-17 15:10:48 -07001137 manifest := j.overrideManifest
1138 if !manifest.Valid() && j.properties.Manifest != nil {
Colin Cross366938f2017-12-11 16:29:02 -08001139 manifest = android.OptionalPathForPath(ctx.ExpandSource(*j.properties.Manifest, "manifest"))
1140 }
Colin Cross635acc92017-09-12 22:50:46 -07001141
Alex Light7f004a72019-02-21 13:27:37 -08001142 services := ctx.ExpandSources(j.properties.Services, nil)
1143 if len(services) > 0 {
1144 servicesJar := android.PathForModuleOut(ctx, "services", jarName)
1145 var zipargs []string
1146 for _, file := range services {
1147 serviceFile := file.String()
1148 zipargs = append(zipargs, "-C", filepath.Dir(serviceFile), "-f", serviceFile)
1149 }
1150 ctx.Build(pctx, android.BuildParams{
1151 Rule: zip,
1152 Output: servicesJar,
1153 Implicits: services,
1154 Args: map[string]string{
Colin Cross0b9f31f2019-02-28 11:00:01 -08001155 "jarArgs": "-P META-INF/services/ " + strings.Join(proptools.NinjaAndShellEscapeList(zipargs), " "),
Alex Light7f004a72019-02-21 13:27:37 -08001156 },
1157 })
1158 jars = append(jars, servicesJar)
1159 }
1160
Colin Cross0a6e0072017-08-30 14:24:55 -07001161 // Combine the classes built from sources, any manifests, and any static libraries into
Nan Zhanged19fc32017-10-19 13:06:22 -07001162 // classes.jar. If there is only one input jar this step will be skipped.
Colin Cross3063b782018-08-15 11:19:12 -07001163 var outputFile android.ModuleOutPath
Colin Crosse9a275b2017-10-16 17:09:48 -07001164
1165 if len(jars) == 1 && !manifest.Valid() {
Colin Cross3063b782018-08-15 11:19:12 -07001166 if moduleOutPath, ok := jars[0].(android.ModuleOutPath); ok {
1167 // Optimization: skip the combine step if there is nothing to do
1168 // TODO(ccross): this leaves any module-info.class files, but those should only come from
1169 // prebuilt dependencies until we support modules in the platform build, so there shouldn't be
1170 // any if len(jars) == 1.
1171 outputFile = moduleOutPath
1172 } else {
1173 combinedJar := android.PathForModuleOut(ctx, "combined", jarName)
1174 ctx.Build(pctx, android.BuildParams{
1175 Rule: android.Cp,
1176 Input: jars[0],
1177 Output: combinedJar,
1178 })
1179 outputFile = combinedJar
1180 }
Colin Crosse9a275b2017-10-16 17:09:48 -07001181 } else {
Colin Cross1ee23172017-10-18 14:44:18 -07001182 combinedJar := android.PathForModuleOut(ctx, "combined", jarName)
Colin Cross37f6d792018-07-12 12:28:41 -07001183 TransformJarsToJar(ctx, combinedJar, "for javac", jars, manifest,
Colin Cross9b38aef2018-08-27 15:42:25 -07001184 false, nil, nil)
Colin Crosse9a275b2017-10-16 17:09:48 -07001185 outputFile = combinedJar
1186 }
Colin Cross0a6e0072017-08-30 14:24:55 -07001187
Colin Cross331a1212018-08-15 20:40:52 -07001188 // jarjar implementation jar if necessary
Steven Morelandc4efd9c2019-01-18 11:51:25 -08001189 if j.expandJarjarRules != nil {
Colin Cross8649b262017-09-27 18:03:17 -07001190 // Transform classes.jar into classes-jarjar.jar
Colin Cross1ee23172017-10-18 14:44:18 -07001191 jarjarFile := android.PathForModuleOut(ctx, "jarjar", jarName)
Steven Morelandc4efd9c2019-01-18 11:51:25 -08001192 TransformJarJar(ctx, jarjarFile, outputFile, j.expandJarjarRules)
Colin Crosse9a275b2017-10-16 17:09:48 -07001193 outputFile = jarjarFile
Colin Cross331a1212018-08-15 20:40:52 -07001194
1195 // jarjar resource jar if necessary
1196 if j.resourceJar != nil {
1197 resourceJarJarFile := android.PathForModuleOut(ctx, "res-jarjar", jarName)
Steven Morelandc4efd9c2019-01-18 11:51:25 -08001198 TransformJarJar(ctx, resourceJarJarFile, j.resourceJar, j.expandJarjarRules)
Colin Cross331a1212018-08-15 20:40:52 -07001199 j.resourceJar = resourceJarJarFile
1200 }
1201
Colin Cross0a6e0072017-08-30 14:24:55 -07001202 if ctx.Failed() {
1203 return
1204 }
1205 }
Nan Zhanged19fc32017-10-19 13:06:22 -07001206 j.implementationJarFile = outputFile
1207 if j.headerJarFile == nil {
1208 j.headerJarFile = j.implementationJarFile
1209 }
Colin Cross2fe66872015-03-30 17:20:39 -07001210
Colin Cross6510f912017-11-29 00:27:14 -08001211 if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
Colin Crosscb933592017-11-22 13:49:43 -08001212 if inList(ctx.ModuleName(), config.InstrumentFrameworkModules) {
1213 j.properties.Instrument = true
1214 }
1215 }
1216
Colin Cross3144dfc2018-01-03 15:06:47 -08001217 if j.shouldInstrument(ctx) {
Colin Crosscb933592017-11-22 13:49:43 -08001218 outputFile = j.instrument(ctx, flags, outputFile, jarName)
1219 }
1220
Colin Cross331a1212018-08-15 20:40:52 -07001221 // merge implementation jar with resources if necessary
1222 implementationAndResourcesJar := outputFile
1223 if j.resourceJar != nil {
1224 jars := android.Paths{implementationAndResourcesJar, j.resourceJar}
1225 combinedJar := android.PathForModuleOut(ctx, "withres", jarName)
1226 TransformJarsToJar(ctx, combinedJar, "for resources", jars, android.OptionalPath{},
1227 false, nil, nil)
1228 implementationAndResourcesJar = combinedJar
1229 }
1230
1231 j.implementationAndResourcesJar = implementationAndResourcesJar
1232
Colin Cross9ae1b922018-06-26 17:59:05 -07001233 if ctx.Device() && (Bool(j.properties.Installable) || Bool(j.deviceProperties.Compile_dex)) {
Colin Cross8faf8fc2019-01-16 15:15:52 -08001234 // Dex compilation
Colin Cross3063b782018-08-15 11:19:12 -07001235 var dexOutputFile android.ModuleOutPath
David Brazdil17ef5632018-06-27 10:27:45 +01001236 dexOutputFile = j.compileDex(ctx, flags, outputFile, jarName)
Colin Cross2fe66872015-03-30 17:20:39 -07001237 if ctx.Failed() {
1238 return
1239 }
Colin Cross331a1212018-08-15 20:40:52 -07001240
Colin Cross8faf8fc2019-01-16 15:15:52 -08001241 // Hidden API CSV generation and dex encoding
Colin Crossf24a22a2019-01-31 14:12:44 -08001242 dexOutputFile = j.hiddenAPI.hiddenAPI(ctx, dexOutputFile, j.implementationJarFile,
1243 j.deviceProperties.UncompressDex)
Colin Cross8faf8fc2019-01-16 15:15:52 -08001244
Colin Cross331a1212018-08-15 20:40:52 -07001245 // merge dex jar with resources if necessary
1246 if j.resourceJar != nil {
1247 jars := android.Paths{dexOutputFile, j.resourceJar}
1248 combinedJar := android.PathForModuleOut(ctx, "dex-withres", jarName)
1249 TransformJarsToJar(ctx, combinedJar, "for dex resources", jars, android.OptionalPath{},
1250 false, nil, nil)
Nicolas Geoffrayf3438722019-01-23 15:57:21 +00001251 if j.deviceProperties.UncompressDex {
1252 combinedAlignedJar := android.PathForModuleOut(ctx, "dex-withres-aligned", jarName)
1253 TransformZipAlign(ctx, combinedAlignedJar, combinedJar)
1254 dexOutputFile = combinedAlignedJar
1255 } else {
1256 dexOutputFile = combinedJar
1257 }
Colin Cross331a1212018-08-15 20:40:52 -07001258 }
1259
1260 j.dexJarFile = dexOutputFile
1261
Colin Cross8faf8fc2019-01-16 15:15:52 -08001262 // Dexpreopting
Colin Cross43f08db2018-11-12 10:13:39 -08001263 dexOutputFile = j.dexpreopt(ctx, dexOutputFile)
1264
1265 j.maybeStrippedDexJarFile = dexOutputFile
1266
Colin Cross3063b782018-08-15 11:19:12 -07001267 outputFile = dexOutputFile
Colin Cross43f08db2018-11-12 10:13:39 -08001268
1269 if ctx.Failed() {
1270 return
1271 }
Colin Cross331a1212018-08-15 20:40:52 -07001272 } else {
1273 outputFile = implementationAndResourcesJar
Colin Cross2fe66872015-03-30 17:20:39 -07001274 }
Colin Cross331a1212018-08-15 20:40:52 -07001275
Colin Crossb7a63242015-04-16 14:09:14 -07001276 ctx.CheckbuildFile(outputFile)
Colin Cross3063b782018-08-15 11:19:12 -07001277
1278 // Save the output file with no relative path so that it doesn't end up in a subdirectory when used as a resource
1279 j.outputFile = outputFile.WithoutRel()
Colin Cross2fe66872015-03-30 17:20:39 -07001280}
1281
Zoran Jovanovic8736ce22018-08-21 17:10:29 +02001282// Check for invalid kotlinc flags. Only use this for flags explicitly passed by the user,
1283// since some of these flags may be used internally.
1284func CheckKotlincFlags(ctx android.ModuleContext, flags []string) {
1285 for _, flag := range flags {
1286 flag = strings.TrimSpace(flag)
1287
1288 if !strings.HasPrefix(flag, "-") {
1289 ctx.PropertyErrorf("kotlincflags", "Flag `%s` must start with `-`", flag)
1290 } else if strings.HasPrefix(flag, "-Xintellij-plugin-root") {
1291 ctx.PropertyErrorf("kotlincflags",
1292 "Bad flag: `%s`, only use internal compiler for consistency.", flag)
1293 } else if inList(flag, config.KotlincIllegalFlags) {
1294 ctx.PropertyErrorf("kotlincflags", "Flag `%s` already used by build system", flag)
1295 } else if flag == "-include-runtime" {
1296 ctx.PropertyErrorf("kotlincflags", "Bad flag: `%s`, do not include runtime.", flag)
1297 } else {
1298 args := strings.Split(flag, " ")
1299 if args[0] == "-kotlin-home" {
1300 ctx.PropertyErrorf("kotlincflags",
1301 "Bad flag: `%s`, kotlin home already set to default (path to kotlinc in the repo).", flag)
1302 }
1303 }
1304 }
1305}
1306
Colin Cross8eadbf02017-10-24 17:46:00 -07001307func (j *Module) compileJavaHeader(ctx android.ModuleContext, srcFiles, srcJars android.Paths,
Colin Cross55f63ea2018-08-27 12:37:09 -07001308 deps deps, flags javaBuilderFlags, jarName string, extraJars android.Paths) android.Path {
Nan Zhanged19fc32017-10-19 13:06:22 -07001309
1310 var jars android.Paths
Colin Cross8eadbf02017-10-24 17:46:00 -07001311 if len(srcFiles) > 0 || len(srcJars) > 0 {
Nan Zhanged19fc32017-10-19 13:06:22 -07001312 // Compile java sources into turbine.jar.
1313 turbineJar := android.PathForModuleOut(ctx, "turbine", jarName)
1314 TransformJavaToHeaderClasses(ctx, turbineJar, srcFiles, srcJars, flags)
1315 if ctx.Failed() {
1316 return nil
1317 }
1318 jars = append(jars, turbineJar)
1319 }
1320
Colin Cross55f63ea2018-08-27 12:37:09 -07001321 jars = append(jars, extraJars...)
1322
Nan Zhanged19fc32017-10-19 13:06:22 -07001323 // Combine any static header libraries into classes-header.jar. If there is only
1324 // one input jar this step will be skipped.
1325 var headerJar android.Path
1326 jars = append(jars, deps.staticHeaderJars...)
1327
Colin Cross5c6ecc12017-10-23 18:12:27 -07001328 // we cannot skip the combine step for now if there is only one jar
1329 // since we have to strip META-INF/TRANSITIVE dir from turbine.jar
1330 combinedJar := android.PathForModuleOut(ctx, "turbine-combined", jarName)
Colin Cross37f6d792018-07-12 12:28:41 -07001331 TransformJarsToJar(ctx, combinedJar, "for turbine", jars, android.OptionalPath{},
1332 false, nil, []string{"META-INF"})
Colin Cross5c6ecc12017-10-23 18:12:27 -07001333 headerJar = combinedJar
Nan Zhanged19fc32017-10-19 13:06:22 -07001334
Steven Morelandc4efd9c2019-01-18 11:51:25 -08001335 if j.expandJarjarRules != nil {
Nan Zhanged19fc32017-10-19 13:06:22 -07001336 // Transform classes.jar into classes-jarjar.jar
1337 jarjarFile := android.PathForModuleOut(ctx, "turbine-jarjar", jarName)
Steven Morelandc4efd9c2019-01-18 11:51:25 -08001338 TransformJarJar(ctx, jarjarFile, headerJar, j.expandJarjarRules)
Nan Zhanged19fc32017-10-19 13:06:22 -07001339 headerJar = jarjarFile
1340 if ctx.Failed() {
1341 return nil
1342 }
1343 }
1344
1345 return headerJar
1346}
1347
Colin Crosscb933592017-11-22 13:49:43 -08001348func (j *Module) instrument(ctx android.ModuleContext, flags javaBuilderFlags,
Colin Cross3063b782018-08-15 11:19:12 -07001349 classesJar android.Path, jarName string) android.ModuleOutPath {
Colin Crosscb933592017-11-22 13:49:43 -08001350
Colin Cross7a3139e2017-12-19 13:57:50 -08001351 specs := j.jacocoModuleToZipCommand(ctx)
Colin Crosscb933592017-11-22 13:49:43 -08001352
Colin Cross84c38822018-01-03 15:59:46 -08001353 jacocoReportClassesFile := android.PathForModuleOut(ctx, "jacoco-report-classes", jarName)
Colin Crosscb933592017-11-22 13:49:43 -08001354 instrumentedJar := android.PathForModuleOut(ctx, "jacoco", jarName)
1355
1356 jacocoInstrumentJar(ctx, instrumentedJar, jacocoReportClassesFile, classesJar, specs)
1357
1358 j.jacocoReportClassesFile = jacocoReportClassesFile
1359
1360 return instrumentedJar
1361}
1362
albaltai36ff7dc2018-12-25 14:35:23 +08001363var _ Dependency = (*Module)(nil)
Colin Cross2fe66872015-03-30 17:20:39 -07001364
Nan Zhanged19fc32017-10-19 13:06:22 -07001365func (j *Module) HeaderJars() android.Paths {
albaltai36ff7dc2018-12-25 14:35:23 +08001366 if j.headerJarFile == nil {
1367 return nil
1368 }
Nan Zhanged19fc32017-10-19 13:06:22 -07001369 return android.Paths{j.headerJarFile}
1370}
1371
1372func (j *Module) ImplementationJars() android.Paths {
shinwang9e4c07a2018-12-24 15:41:04 +08001373 if j.implementationJarFile == nil {
1374 return nil
1375 }
Nan Zhanged19fc32017-10-19 13:06:22 -07001376 return android.Paths{j.implementationJarFile}
Colin Cross2fe66872015-03-30 17:20:39 -07001377}
1378
Colin Crossf24a22a2019-01-31 14:12:44 -08001379func (j *Module) DexJar() android.Path {
1380 return j.dexJarFile
1381}
1382
Colin Cross331a1212018-08-15 20:40:52 -07001383func (j *Module) ResourceJars() android.Paths {
1384 if j.resourceJar == nil {
1385 return nil
1386 }
1387 return android.Paths{j.resourceJar}
1388}
1389
1390func (j *Module) ImplementationAndResourcesJars() android.Paths {
albaltai36ff7dc2018-12-25 14:35:23 +08001391 if j.implementationAndResourcesJar == nil {
1392 return nil
1393 }
Colin Cross331a1212018-08-15 20:40:52 -07001394 return android.Paths{j.implementationAndResourcesJar}
1395}
1396
Colin Cross46c9b8b2017-06-22 16:51:17 -07001397func (j *Module) AidlIncludeDirs() android.Paths {
albaltai36ff7dc2018-12-25 14:35:23 +08001398 // exportAidlIncludeDirs is type android.Paths already
Colin Crossc0b06f12015-04-08 13:03:43 -07001399 return j.exportAidlIncludeDirs
1400}
1401
Jiyong Park1be96912018-05-28 18:02:19 +09001402func (j *Module) ExportedSdkLibs() []string {
albaltai36ff7dc2018-12-25 14:35:23 +08001403 // exportedSdkLibs is type []string
Jiyong Park1be96912018-05-28 18:02:19 +09001404 return j.exportedSdkLibs
1405}
1406
Colin Cross46c9b8b2017-06-22 16:51:17 -07001407var _ logtagsProducer = (*Module)(nil)
Colin Crossf05fe972015-04-10 17:45:20 -07001408
Colin Cross46c9b8b2017-06-22 16:51:17 -07001409func (j *Module) logtags() android.Paths {
Colin Crossf05fe972015-04-10 17:45:20 -07001410 return j.logtagsSrcs
1411}
1412
Brandon Lee5d45c6f2018-08-15 15:35:38 -07001413// Collect information for opening IDE project files in java/jdeps.go.
1414func (j *Module) IDEInfo(dpInfo *android.IdeInfo) {
1415 dpInfo.Deps = append(dpInfo.Deps, j.CompilerDeps()...)
1416 dpInfo.Srcs = append(dpInfo.Srcs, j.expandIDEInfoCompiledSrcs...)
1417 dpInfo.Aidl_include_dirs = append(dpInfo.Aidl_include_dirs, j.deviceProperties.Aidl.Include_dirs...)
Steven Morelandc4efd9c2019-01-18 11:51:25 -08001418 if j.expandJarjarRules != nil {
1419 dpInfo.Jarjar_rules = append(dpInfo.Jarjar_rules, j.expandJarjarRules.String())
Brandon Lee5d45c6f2018-08-15 15:35:38 -07001420 }
1421}
1422
1423func (j *Module) CompilerDeps() []string {
1424 jdeps := []string{}
1425 jdeps = append(jdeps, j.properties.Libs...)
1426 jdeps = append(jdeps, j.properties.Static_libs...)
1427 return jdeps
1428}
1429
Colin Cross2fe66872015-03-30 17:20:39 -07001430//
1431// Java libraries (.jar file)
1432//
1433
Colin Crossf506d872017-07-19 15:53:04 -07001434type Library struct {
Colin Cross46c9b8b2017-06-22 16:51:17 -07001435 Module
Colin Cross2fe66872015-03-30 17:20:39 -07001436}
1437
Colin Cross2fc72f62018-12-21 12:59:54 -08001438func (j *Library) shouldUncompressDex(ctx android.ModuleContext) bool {
Nicolas Geoffrayfa6e9ec2019-02-12 13:12:16 +00001439 // Store uncompressed (and do not strip) dex files from boot class path jars.
1440 if inList(ctx.ModuleName(), ctx.Config().BootJars()) {
1441 return true
1442 }
1443
1444 // Store uncompressed dex files that are preopted on /system.
1445 if !j.dexpreopter.dexpreoptDisabled(ctx) && (ctx.Host() || !odexOnSystemOther(ctx, j.dexpreopter.installPath)) {
Vladimir Markoe8b00d62018-12-21 15:54:16 +00001446 return true
1447 }
Colin Cross083a2aa2019-02-06 16:37:12 -08001448 if ctx.Config().UncompressPrivAppDex() &&
1449 inList(ctx.ModuleName(), ctx.Config().ModulesLoadedByPrivilegedModules()) {
1450 return true
1451 }
1452
Colin Cross2fc72f62018-12-21 12:59:54 -08001453 return false
1454}
1455
Colin Crossf506d872017-07-19 15:53:04 -07001456func (j *Library) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross43f08db2018-11-12 10:13:39 -08001457 j.dexpreopter.installPath = android.PathForModuleInstall(ctx, "framework", ctx.ModuleName()+".jar")
1458 j.dexpreopter.isSDKLibrary = j.deviceProperties.IsSDKLibrary
Nicolas Geoffrayfa6e9ec2019-02-12 13:12:16 +00001459 j.dexpreopter.isInstallable = Bool(j.properties.Installable)
1460 j.dexpreopter.uncompressedDex = j.shouldUncompressDex(ctx)
1461 j.deviceProperties.UncompressDex = j.dexpreopter.uncompressedDex
Colin Cross46c9b8b2017-06-22 16:51:17 -07001462 j.compile(ctx)
Colin Crossb7a63242015-04-16 14:09:14 -07001463
Nicolas Geoffray4bdea392019-01-15 11:48:08 +00001464 if (Bool(j.properties.Installable) || ctx.Host()) && !android.DirectlyInAnyApex(ctx, ctx.ModuleName()) {
Colin Cross2c429dc2017-08-31 16:45:16 -07001465 j.installFile = ctx.InstallFile(android.PathForModuleInstall(ctx, "framework"),
1466 ctx.ModuleName()+".jar", j.outputFile)
1467 }
Colin Crossb7a63242015-04-16 14:09:14 -07001468}
1469
Colin Crossf506d872017-07-19 15:53:04 -07001470func (j *Library) DepsMutator(ctx android.BottomUpMutatorContext) {
Colin Cross46c9b8b2017-06-22 16:51:17 -07001471 j.deps(ctx)
1472}
1473
Colin Cross1b16b0e2019-02-12 14:41:32 -08001474// java_library builds and links sources into a `.jar` file for the device, and possibly for the host as well.
1475//
1476// By default, a java_library has a single variant that produces a `.jar` file containing `.class` files that were
1477// compiled against the device bootclasspath. This jar is not suitable for installing on a device, but can be used
1478// as a `static_libs` dependency of another module.
1479//
1480// Specifying `installable: true` will product a `.jar` file containing `classes.dex` files, suitable for installing on
1481// a device.
1482//
1483// Specifying `host_supported: true` will produce two variants, one compiled against the device bootclasspath and one
1484// compiled against the host bootclasspath.
Colin Cross9ae1b922018-06-26 17:59:05 -07001485func LibraryFactory() android.Module {
1486 module := &Library{}
Colin Cross2fe66872015-03-30 17:20:39 -07001487
Colin Cross9ae1b922018-06-26 17:59:05 -07001488 module.AddProperties(
1489 &module.Module.properties,
1490 &module.Module.deviceProperties,
Colin Cross43f08db2018-11-12 10:13:39 -08001491 &module.Module.dexpreoptProperties,
Colin Cross9ae1b922018-06-26 17:59:05 -07001492 &module.Module.protoProperties)
Colin Cross2fe66872015-03-30 17:20:39 -07001493
Colin Cross9ae1b922018-06-26 17:59:05 -07001494 InitJavaModule(module, android.HostAndDeviceSupported)
1495 return module
Colin Cross2fe66872015-03-30 17:20:39 -07001496}
1497
Colin Cross1b16b0e2019-02-12 14:41:32 -08001498// java_library_static is an obsolete alias for java_library.
1499func LibraryStaticFactory() android.Module {
1500 return LibraryFactory()
1501}
1502
1503// java_library_host builds and links sources into a `.jar` file for the host.
1504//
1505// A java_library_host has a single variant that produces a `.jar` file containing `.class` files that were
1506// compiled against the host bootclasspath.
Colin Crossf506d872017-07-19 15:53:04 -07001507func LibraryHostFactory() android.Module {
1508 module := &Library{}
Colin Cross2fe66872015-03-30 17:20:39 -07001509
Colin Cross6af17aa2017-09-20 12:59:05 -07001510 module.AddProperties(
1511 &module.Module.properties,
1512 &module.Module.protoProperties)
Colin Cross36242852017-06-23 15:06:31 -07001513
Colin Cross9ae1b922018-06-26 17:59:05 -07001514 module.Module.properties.Installable = proptools.BoolPtr(true)
1515
Colin Cross89536d42017-07-07 14:35:50 -07001516 InitJavaModule(module, android.HostSupported)
Colin Cross36242852017-06-23 15:06:31 -07001517 return module
Colin Cross2fe66872015-03-30 17:20:39 -07001518}
1519
1520//
Colin Crossb628ea52018-08-14 16:42:33 -07001521// Java Tests
Colin Cross05638fc2018-04-09 18:40:24 -07001522//
1523
1524type testProperties struct {
Colin Cross05638fc2018-04-09 18:40:24 -07001525 // list of compatibility suites (for example "cts", "vts") that the module should be
1526 // installed into.
1527 Test_suites []string `android:"arch_variant"`
Julien Despreze146e392018-08-02 15:00:46 -07001528
1529 // the name of the test configuration (for example "AndroidTest.xml") that should be
1530 // installed with the module.
1531 Test_config *string `android:"arch_variant"`
Colin Crossd96ca352018-08-10 16:06:24 -07001532
Jack He33338892018-09-19 02:21:28 -07001533 // the name of the test configuration template (for example "AndroidTestTemplate.xml") that
1534 // should be installed with the module.
1535 Test_config_template *string `android:"arch_variant"`
1536
Colin Crossd96ca352018-08-10 16:06:24 -07001537 // list of files or filegroup modules that provide data that should be installed alongside
1538 // the test
1539 Data []string
Colin Cross05638fc2018-04-09 18:40:24 -07001540}
1541
1542type Test struct {
1543 Library
1544
1545 testProperties testProperties
Colin Cross303e21f2018-08-07 16:49:25 -07001546
1547 testConfig android.Path
Colin Crossd96ca352018-08-10 16:06:24 -07001548 data android.Paths
Colin Cross303e21f2018-08-07 16:49:25 -07001549}
1550
1551func (j *Test) GenerateAndroidBuildActions(ctx android.ModuleContext) {
yangbill4f41bc22019-02-13 21:45:47 +08001552 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 -07001553 j.data = ctx.ExpandSources(j.testProperties.Data, nil)
Colin Cross303e21f2018-08-07 16:49:25 -07001554
1555 j.Library.GenerateAndroidBuildActions(ctx)
Colin Cross05638fc2018-04-09 18:40:24 -07001556}
1557
1558func (j *Test) DepsMutator(ctx android.BottomUpMutatorContext) {
1559 j.deps(ctx)
Colin Cross303e21f2018-08-07 16:49:25 -07001560 android.ExtractSourceDeps(ctx, j.testProperties.Test_config)
Jack He33338892018-09-19 02:21:28 -07001561 android.ExtractSourceDeps(ctx, j.testProperties.Test_config_template)
Colin Crossd96ca352018-08-10 16:06:24 -07001562 android.ExtractSourcesDeps(ctx, j.testProperties.Data)
Colin Cross05638fc2018-04-09 18:40:24 -07001563}
1564
Colin Cross1b16b0e2019-02-12 14:41:32 -08001565// java_test builds a and links sources into a `.jar` file for the device, and possibly for the host as well, and
1566// creates an `AndroidTest.xml` file to allow running the test with `atest` or a `TEST_MAPPING` file.
1567//
1568// By default, a java_test has a single variant that produces a `.jar` file containing `classes.dex` files that were
1569// compiled against the device bootclasspath.
1570//
1571// Specifying `host_supported: true` will produce two variants, one compiled against the device bootclasspath and one
1572// compiled against the host bootclasspath.
Colin Cross05638fc2018-04-09 18:40:24 -07001573func TestFactory() android.Module {
1574 module := &Test{}
1575
1576 module.AddProperties(
1577 &module.Module.properties,
1578 &module.Module.deviceProperties,
Colin Cross43f08db2018-11-12 10:13:39 -08001579 &module.Module.dexpreoptProperties,
Colin Cross05638fc2018-04-09 18:40:24 -07001580 &module.Module.protoProperties,
1581 &module.testProperties)
1582
Colin Cross9ae1b922018-06-26 17:59:05 -07001583 module.Module.properties.Installable = proptools.BoolPtr(true)
Colin Crosse3026872019-01-05 22:30:13 -08001584 module.Module.dexpreopter.isTest = true
Colin Cross9ae1b922018-06-26 17:59:05 -07001585
Colin Cross05638fc2018-04-09 18:40:24 -07001586 InitJavaModule(module, android.HostAndDeviceSupported)
Colin Cross05638fc2018-04-09 18:40:24 -07001587 return module
1588}
1589
Colin Cross1b16b0e2019-02-12 14:41:32 -08001590// java_test_host builds a and links sources into a `.jar` file for the host, and creates an `AndroidTest.xml` file to
1591// allow running the test with `atest` or a `TEST_MAPPING` file.
1592//
1593// A java_test_host has a single variant that produces a `.jar` file containing `.class` files that were
1594// compiled against the host bootclasspath.
Colin Cross05638fc2018-04-09 18:40:24 -07001595func TestHostFactory() android.Module {
1596 module := &Test{}
1597
1598 module.AddProperties(
1599 &module.Module.properties,
1600 &module.Module.protoProperties,
1601 &module.testProperties)
1602
Colin Cross9ae1b922018-06-26 17:59:05 -07001603 module.Module.properties.Installable = proptools.BoolPtr(true)
1604
Colin Cross05638fc2018-04-09 18:40:24 -07001605 InitJavaModule(module, android.HostSupported)
Colin Cross05638fc2018-04-09 18:40:24 -07001606 return module
1607}
1608
1609//
Colin Cross2fe66872015-03-30 17:20:39 -07001610// Java Binaries (.jar file plus wrapper script)
1611//
1612
Colin Crossf506d872017-07-19 15:53:04 -07001613type binaryProperties struct {
Colin Cross7d5136f2015-05-11 13:39:40 -07001614 // installable script to execute the resulting jar
Nan Zhangea568a42017-11-08 21:20:04 -08001615 Wrapper *string
Colin Cross094054a2018-10-17 15:10:48 -07001616
1617 // Name of the class containing main to be inserted into the manifest as Main-Class.
1618 Main_class *string
Colin Cross7d5136f2015-05-11 13:39:40 -07001619}
1620
Colin Crossf506d872017-07-19 15:53:04 -07001621type Binary struct {
1622 Library
Colin Cross2fe66872015-03-30 17:20:39 -07001623
Colin Crossf506d872017-07-19 15:53:04 -07001624 binaryProperties binaryProperties
Colin Cross10a03492017-08-10 17:09:43 -07001625
Colin Cross6b4a32d2017-12-05 13:42:45 -08001626 isWrapperVariant bool
1627
Colin Crossc3315992017-12-08 19:12:36 -08001628 wrapperFile android.Path
Colin Cross10a03492017-08-10 17:09:43 -07001629 binaryFile android.OutputPath
Colin Cross2fe66872015-03-30 17:20:39 -07001630}
1631
Alex Light24237172017-10-26 09:46:21 -07001632func (j *Binary) HostToolPath() android.OptionalPath {
1633 return android.OptionalPathForPath(j.binaryFile)
1634}
1635
Colin Crossf506d872017-07-19 15:53:04 -07001636func (j *Binary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross6b4a32d2017-12-05 13:42:45 -08001637 if ctx.Arch().ArchType == android.Common {
1638 // Compile the jar
Colin Cross094054a2018-10-17 15:10:48 -07001639 if j.binaryProperties.Main_class != nil {
1640 if j.properties.Manifest != nil {
1641 ctx.PropertyErrorf("main_class", "main_class cannot be used when manifest is set")
1642 }
1643 manifestFile := android.PathForModuleOut(ctx, "manifest.txt")
1644 GenerateMainClassManifest(ctx, manifestFile, String(j.binaryProperties.Main_class))
1645 j.overrideManifest = android.OptionalPathForPath(manifestFile)
1646 }
1647
Colin Cross6b4a32d2017-12-05 13:42:45 -08001648 j.Library.GenerateAndroidBuildActions(ctx)
Nan Zhang3c807db2017-11-03 14:53:31 -07001649 } else {
Colin Cross6b4a32d2017-12-05 13:42:45 -08001650 // Handle the binary wrapper
1651 j.isWrapperVariant = true
1652
Colin Cross366938f2017-12-11 16:29:02 -08001653 if j.binaryProperties.Wrapper != nil {
1654 j.wrapperFile = ctx.ExpandSource(*j.binaryProperties.Wrapper, "wrapper")
Colin Cross6b4a32d2017-12-05 13:42:45 -08001655 } else {
1656 j.wrapperFile = android.PathForSource(ctx, "build/soong/scripts/jar-wrapper.sh")
1657 }
1658
1659 // Depend on the installed jar so that the wrapper doesn't get executed by
1660 // another build rule before the jar has been installed.
1661 jarFile := ctx.PrimaryModule().(*Binary).installFile
1662
1663 j.binaryFile = ctx.InstallExecutable(android.PathForModuleInstall(ctx, "bin"),
1664 ctx.ModuleName(), j.wrapperFile, jarFile)
Nan Zhang3c807db2017-11-03 14:53:31 -07001665 }
Colin Cross2fe66872015-03-30 17:20:39 -07001666}
1667
Colin Crossf506d872017-07-19 15:53:04 -07001668func (j *Binary) DepsMutator(ctx android.BottomUpMutatorContext) {
Colin Cross6b4a32d2017-12-05 13:42:45 -08001669 if ctx.Arch().ArchType == android.Common {
1670 j.deps(ctx)
Colin Crossc3315992017-12-08 19:12:36 -08001671 } else {
Colin Cross366938f2017-12-11 16:29:02 -08001672 android.ExtractSourceDeps(ctx, j.binaryProperties.Wrapper)
Colin Cross6b4a32d2017-12-05 13:42:45 -08001673 }
Colin Cross46c9b8b2017-06-22 16:51:17 -07001674}
1675
Colin Cross1b16b0e2019-02-12 14:41:32 -08001676// java_binary builds a `.jar` file and a shell script that executes it for the device, and possibly for the host
1677// as well.
1678//
1679// By default, a java_binary has a single variant that produces a `.jar` file containing `classes.dex` files that were
1680// compiled against the device bootclasspath.
1681//
1682// Specifying `host_supported: true` will produce two variants, one compiled against the device bootclasspath and one
1683// compiled against the host bootclasspath.
Colin Crossf506d872017-07-19 15:53:04 -07001684func BinaryFactory() android.Module {
1685 module := &Binary{}
Colin Cross2fe66872015-03-30 17:20:39 -07001686
Colin Cross36242852017-06-23 15:06:31 -07001687 module.AddProperties(
Colin Cross540eff82017-06-22 17:01:52 -07001688 &module.Module.properties,
1689 &module.Module.deviceProperties,
Colin Cross43f08db2018-11-12 10:13:39 -08001690 &module.Module.dexpreoptProperties,
Colin Cross6af17aa2017-09-20 12:59:05 -07001691 &module.Module.protoProperties,
Colin Cross540eff82017-06-22 17:01:52 -07001692 &module.binaryProperties)
Colin Cross36242852017-06-23 15:06:31 -07001693
Colin Cross9ae1b922018-06-26 17:59:05 -07001694 module.Module.properties.Installable = proptools.BoolPtr(true)
1695
Colin Cross6b4a32d2017-12-05 13:42:45 -08001696 android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibCommonFirst)
1697 android.InitDefaultableModule(module)
Colin Cross36242852017-06-23 15:06:31 -07001698 return module
Colin Cross2fe66872015-03-30 17:20:39 -07001699}
1700
Colin Cross1b16b0e2019-02-12 14:41:32 -08001701// java_binary_host builds a `.jar` file and a shell script that executes it for the host.
1702//
1703// A java_binary_host has a single variant that produces a `.jar` file containing `.class` files that were
1704// compiled against the host bootclasspath.
Colin Crossf506d872017-07-19 15:53:04 -07001705func BinaryHostFactory() android.Module {
1706 module := &Binary{}
Colin Cross2fe66872015-03-30 17:20:39 -07001707
Colin Cross36242852017-06-23 15:06:31 -07001708 module.AddProperties(
Colin Cross540eff82017-06-22 17:01:52 -07001709 &module.Module.properties,
Colin Cross6af17aa2017-09-20 12:59:05 -07001710 &module.Module.protoProperties,
Colin Cross540eff82017-06-22 17:01:52 -07001711 &module.binaryProperties)
Colin Cross36242852017-06-23 15:06:31 -07001712
Colin Cross9ae1b922018-06-26 17:59:05 -07001713 module.Module.properties.Installable = proptools.BoolPtr(true)
1714
Colin Cross6b4a32d2017-12-05 13:42:45 -08001715 android.InitAndroidArchModule(module, android.HostSupported, android.MultilibCommonFirst)
1716 android.InitDefaultableModule(module)
Colin Cross36242852017-06-23 15:06:31 -07001717 return module
Colin Cross2fe66872015-03-30 17:20:39 -07001718}
1719
1720//
1721// Java prebuilts
1722//
1723
Colin Cross74d73e22017-08-02 11:05:49 -07001724type ImportProperties struct {
1725 Jars []string
Colin Cross461bd1a2017-10-20 13:59:18 -07001726
Nan Zhangea568a42017-11-08 21:20:04 -08001727 Sdk_version *string
Colin Cross535e2cf2017-10-20 17:57:49 -07001728
1729 Installable *bool
Jiyong Park1be96912018-05-28 18:02:19 +09001730
1731 // List of shared java libs that this module has dependencies to
1732 Libs []string
Colin Cross37f6d792018-07-12 12:28:41 -07001733
1734 // List of files to remove from the jar file(s)
1735 Exclude_files []string
1736
1737 // List of directories to remove from the jar file(s)
1738 Exclude_dirs []string
Nan Zhang4c819fb2018-08-27 18:31:46 -07001739
1740 // if set to true, run Jetifier against .jar file. Defaults to false.
1741 Jetifier_enabled *bool
Colin Cross74d73e22017-08-02 11:05:49 -07001742}
1743
1744type Import struct {
Colin Cross635c3b02016-05-18 15:37:25 -07001745 android.ModuleBase
Colin Cross48de9a42018-10-02 13:53:33 -07001746 android.DefaultableModuleBase
Colin Crossec7a0422017-07-07 14:47:12 -07001747 prebuilt android.Prebuilt
Colin Cross2fe66872015-03-30 17:20:39 -07001748
Colin Cross74d73e22017-08-02 11:05:49 -07001749 properties ImportProperties
1750
Colin Cross0a6e0072017-08-30 14:24:55 -07001751 combinedClasspathFile android.Path
Jiyong Park1be96912018-05-28 18:02:19 +09001752 exportedSdkLibs []string
Colin Cross2fe66872015-03-30 17:20:39 -07001753}
1754
Colin Cross83bb3162018-06-25 15:48:06 -07001755func (j *Import) sdkVersion() string {
1756 return String(j.properties.Sdk_version)
1757}
1758
1759func (j *Import) minSdkVersion() string {
1760 return j.sdkVersion()
1761}
1762
Colin Cross74d73e22017-08-02 11:05:49 -07001763func (j *Import) Prebuilt() *android.Prebuilt {
Colin Crossec7a0422017-07-07 14:47:12 -07001764 return &j.prebuilt
1765}
1766
Colin Cross74d73e22017-08-02 11:05:49 -07001767func (j *Import) PrebuiltSrcs() []string {
1768 return j.properties.Jars
1769}
1770
1771func (j *Import) Name() string {
Colin Cross5ea9bcc2017-07-27 15:41:32 -07001772 return j.prebuilt.Name(j.ModuleBase.Name())
1773}
1774
Colin Cross74d73e22017-08-02 11:05:49 -07001775func (j *Import) DepsMutator(ctx android.BottomUpMutatorContext) {
Colin Cross37f6d792018-07-12 12:28:41 -07001776 android.ExtractSourcesDeps(ctx, j.properties.Jars)
Colin Cross42d48b72018-08-29 14:10:52 -07001777 ctx.AddVariationDependencies(nil, libTag, j.properties.Libs...)
Colin Cross1e676be2016-10-12 14:38:15 -07001778}
1779
Colin Cross74d73e22017-08-02 11:05:49 -07001780func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross37f6d792018-07-12 12:28:41 -07001781 jars := ctx.ExpandSources(j.properties.Jars, nil)
Colin Crosse1d62a82015-04-03 16:53:05 -07001782
Nan Zhang4c819fb2018-08-27 18:31:46 -07001783 jarName := ctx.ModuleName() + ".jar"
1784 outputFile := android.PathForModuleOut(ctx, "combined", jarName)
Colin Cross37f6d792018-07-12 12:28:41 -07001785 TransformJarsToJar(ctx, outputFile, "for prebuilts", jars, android.OptionalPath{},
1786 false, j.properties.Exclude_files, j.properties.Exclude_dirs)
Nan Zhang4c819fb2018-08-27 18:31:46 -07001787 if Bool(j.properties.Jetifier_enabled) {
1788 inputFile := outputFile
1789 outputFile = android.PathForModuleOut(ctx, "jetifier", jarName)
1790 TransformJetifier(ctx, outputFile, inputFile)
1791 }
Colin Crosse9a275b2017-10-16 17:09:48 -07001792 j.combinedClasspathFile = outputFile
Jiyong Park1be96912018-05-28 18:02:19 +09001793
1794 ctx.VisitDirectDeps(func(module android.Module) {
1795 otherName := ctx.OtherModuleName(module)
1796 tag := ctx.OtherModuleDependencyTag(module)
1797
1798 switch dep := module.(type) {
1799 case Dependency:
1800 switch tag {
1801 case libTag, staticLibTag:
1802 // sdk lib names from dependencies are re-exported
1803 j.exportedSdkLibs = append(j.exportedSdkLibs, dep.ExportedSdkLibs()...)
1804 }
1805 case SdkLibraryDependency:
1806 switch tag {
1807 case libTag:
1808 // names of sdk libs that are directly depended are exported
1809 j.exportedSdkLibs = append(j.exportedSdkLibs, otherName)
1810 }
1811 }
1812 })
1813
1814 j.exportedSdkLibs = android.FirstUniqueStrings(j.exportedSdkLibs)
Nan Zhang4973ecf2018-08-10 13:42:12 -07001815 if Bool(j.properties.Installable) {
1816 ctx.InstallFile(android.PathForModuleInstall(ctx, "framework"),
1817 ctx.ModuleName()+".jar", outputFile)
1818 }
Colin Cross2fe66872015-03-30 17:20:39 -07001819}
1820
Colin Cross74d73e22017-08-02 11:05:49 -07001821var _ Dependency = (*Import)(nil)
Colin Cross2fe66872015-03-30 17:20:39 -07001822
Nan Zhanged19fc32017-10-19 13:06:22 -07001823func (j *Import) HeaderJars() android.Paths {
albaltai36ff7dc2018-12-25 14:35:23 +08001824 if j.combinedClasspathFile == nil {
1825 return nil
1826 }
Colin Cross37f6d792018-07-12 12:28:41 -07001827 return android.Paths{j.combinedClasspathFile}
Nan Zhanged19fc32017-10-19 13:06:22 -07001828}
1829
1830func (j *Import) ImplementationJars() android.Paths {
shinwang9e4c07a2018-12-24 15:41:04 +08001831 if j.combinedClasspathFile == nil {
1832 return nil
1833 }
Colin Cross37f6d792018-07-12 12:28:41 -07001834 return android.Paths{j.combinedClasspathFile}
Colin Cross2fe66872015-03-30 17:20:39 -07001835}
1836
Colin Cross331a1212018-08-15 20:40:52 -07001837func (j *Import) ResourceJars() android.Paths {
1838 return nil
1839}
1840
1841func (j *Import) ImplementationAndResourcesJars() android.Paths {
albaltai36ff7dc2018-12-25 14:35:23 +08001842 if j.combinedClasspathFile == nil {
1843 return nil
1844 }
Colin Cross331a1212018-08-15 20:40:52 -07001845 return android.Paths{j.combinedClasspathFile}
1846}
1847
Colin Crossf24a22a2019-01-31 14:12:44 -08001848func (j *Import) DexJar() android.Path {
1849 return nil
1850}
1851
Colin Cross74d73e22017-08-02 11:05:49 -07001852func (j *Import) AidlIncludeDirs() android.Paths {
Colin Crossc0b06f12015-04-08 13:03:43 -07001853 return nil
1854}
1855
Jiyong Park1be96912018-05-28 18:02:19 +09001856func (j *Import) ExportedSdkLibs() []string {
1857 return j.exportedSdkLibs
1858}
1859
albaltai36ff7dc2018-12-25 14:35:23 +08001860// Add compile time check for interface implementation
1861var _ android.IDEInfo = (*Import)(nil)
1862var _ android.IDECustomizedModuleName = (*Import)(nil)
1863
Brandon Lee5d45c6f2018-08-15 15:35:38 -07001864// Collect information for opening IDE project files in java/jdeps.go.
1865const (
1866 removedPrefix = "prebuilt_"
1867)
1868
1869func (j *Import) IDEInfo(dpInfo *android.IdeInfo) {
1870 dpInfo.Jars = append(dpInfo.Jars, j.PrebuiltSrcs()...)
1871}
1872
1873func (j *Import) IDECustomizedModuleName() string {
1874 // TODO(b/113562217): Extract the base module name from the Import name, often the Import name
1875 // has a prefix "prebuilt_". Remove the prefix explicitly if needed until we find a better
1876 // solution to get the Import name.
1877 name := j.Name()
1878 if strings.HasPrefix(name, removedPrefix) {
patricktubb640e02018-10-11 18:33:16 +08001879 name = strings.TrimPrefix(name, removedPrefix)
Brandon Lee5d45c6f2018-08-15 15:35:38 -07001880 }
1881 return name
1882}
1883
Colin Cross74d73e22017-08-02 11:05:49 -07001884var _ android.PrebuiltInterface = (*Import)(nil)
Colin Cross2fe66872015-03-30 17:20:39 -07001885
Colin Cross1b16b0e2019-02-12 14:41:32 -08001886// java_import imports one or more `.jar` files into the build graph as if they were built by a java_library module.
1887//
1888// By default, a java_import has a single variant that expects a `.jar` file containing `.class` files that were
1889// compiled against an Android classpath.
1890//
1891// Specifying `host_supported: true` will produce two variants, one for use as a dependency of device modules and one
1892// for host modules.
Colin Cross74d73e22017-08-02 11:05:49 -07001893func ImportFactory() android.Module {
1894 module := &Import{}
Colin Cross36242852017-06-23 15:06:31 -07001895
Colin Cross74d73e22017-08-02 11:05:49 -07001896 module.AddProperties(&module.properties)
1897
1898 android.InitPrebuiltModule(module, &module.properties.Jars)
Colin Cross48de9a42018-10-02 13:53:33 -07001899 InitJavaModule(module, android.HostAndDeviceSupported)
Colin Cross36242852017-06-23 15:06:31 -07001900 return module
Colin Cross2fe66872015-03-30 17:20:39 -07001901}
1902
Colin Cross1b16b0e2019-02-12 14:41:32 -08001903// java_import imports one or more `.jar` files into the build graph as if they were built by a java_library_host
1904// module.
1905//
1906// A java_import_host has a single variant that expects a `.jar` file containing `.class` files that were
1907// compiled against a host bootclasspath.
Colin Cross74d73e22017-08-02 11:05:49 -07001908func ImportFactoryHost() android.Module {
1909 module := &Import{}
1910
1911 module.AddProperties(&module.properties)
1912
1913 android.InitPrebuiltModule(module, &module.properties.Jars)
Colin Cross48de9a42018-10-02 13:53:33 -07001914 InitJavaModule(module, android.HostSupported)
Colin Cross74d73e22017-08-02 11:05:49 -07001915 return module
1916}
1917
Colin Cross89536d42017-07-07 14:35:50 -07001918//
1919// Defaults
1920//
1921type Defaults struct {
1922 android.ModuleBase
1923 android.DefaultsModuleBase
1924}
1925
1926func (*Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1927}
1928
Colin Cross1b16b0e2019-02-12 14:41:32 -08001929// java_defaults provides a set of properties that can be inherited by other java or android modules.
1930//
1931// A module can use the properties from a java_defaults module using `defaults: ["defaults_module_name"]`. Each
1932// property in the defaults module that exists in the depending module will be prepended to the depending module's
1933// value for that property.
1934//
1935// Example:
1936//
1937// java_defaults {
1938// name: "example_defaults",
1939// srcs: ["common/**/*.java"],
1940// javacflags: ["-Xlint:all"],
1941// aaptflags: ["--auto-add-overlay"],
1942// }
1943//
1944// java_library {
1945// name: "example",
1946// defaults: ["example_defaults"],
1947// srcs: ["example/**/*.java"],
1948// }
1949//
1950// is functionally identical to:
1951//
1952// java_library {
1953// name: "example",
1954// srcs: [
1955// "common/**/*.java",
1956// "example/**/*.java",
1957// ],
1958// javacflags: ["-Xlint:all"],
1959// }
Colin Cross89536d42017-07-07 14:35:50 -07001960func defaultsFactory() android.Module {
1961 return DefaultsFactory()
1962}
1963
1964func DefaultsFactory(props ...interface{}) android.Module {
1965 module := &Defaults{}
1966
1967 module.AddProperties(props...)
1968 module.AddProperties(
1969 &CompilerProperties{},
1970 &CompilerDeviceProperties{},
Colin Cross43f08db2018-11-12 10:13:39 -08001971 &DexpreoptProperties{},
Dan Willemsen6424d172018-03-08 13:27:59 -08001972 &android.ProtoProperties{},
Colin Cross48de9a42018-10-02 13:53:33 -07001973 &aaptProperties{},
1974 &androidLibraryProperties{},
1975 &appProperties{},
1976 &appTestProperties{},
1977 &ImportProperties{},
1978 &AARImportProperties{},
1979 &sdkLibraryProperties{},
Colin Cross89536d42017-07-07 14:35:50 -07001980 )
1981
1982 android.InitDefaultsModule(module)
1983
1984 return module
1985}
Nan Zhangea568a42017-11-08 21:20:04 -08001986
1987var Bool = proptools.Bool
Colin Cross38b40df2018-04-10 16:14:46 -07001988var BoolDefault = proptools.BoolDefault
Nan Zhangea568a42017-11-08 21:20:04 -08001989var String = proptools.String
Colin Cross0d0ba592018-02-20 13:33:42 -08001990var inList = android.InList