blob: 9f68c42b59c19164375c3a669abd9ce2250f3237 [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 Cross3b706fd2019-09-05 16:44:18 -070028 "github.com/google/blueprint/pathtools"
Colin Cross76b5f0c2017-08-29 16:02:06 -070029 "github.com/google/blueprint/proptools"
Colin Cross2fe66872015-03-30 17:20:39 -070030
Colin Cross635c3b02016-05-18 15:37:25 -070031 "android/soong/android"
Colin Cross3e3e72d2017-06-22 17:20:19 -070032 "android/soong/java/config"
Colin Cross303e21f2018-08-07 16:49:25 -070033 "android/soong/tradefed"
Colin Cross2fe66872015-03-30 17:20:39 -070034)
35
Colin Cross463a90e2015-06-17 14:20:06 -070036func init() {
Colin Cross89536d42017-07-07 14:35:50 -070037 android.RegisterModuleType("java_defaults", defaultsFactory)
38
Colin Cross9ae1b922018-06-26 17:59:05 -070039 android.RegisterModuleType("java_library", LibraryFactory)
Colin Cross1b16b0e2019-02-12 14:41:32 -080040 android.RegisterModuleType("java_library_static", LibraryStaticFactory)
Colin Crossf506d872017-07-19 15:53:04 -070041 android.RegisterModuleType("java_library_host", LibraryHostFactory)
42 android.RegisterModuleType("java_binary", BinaryFactory)
43 android.RegisterModuleType("java_binary_host", BinaryHostFactory)
Colin Cross05638fc2018-04-09 18:40:24 -070044 android.RegisterModuleType("java_test", TestFactory)
Paul Duffin42df1442019-03-20 12:45:53 +000045 android.RegisterModuleType("java_test_helper_library", TestHelperLibraryFactory)
Colin Cross05638fc2018-04-09 18:40:24 -070046 android.RegisterModuleType("java_test_host", TestHostFactory)
Colin Cross74d73e22017-08-02 11:05:49 -070047 android.RegisterModuleType("java_import", ImportFactory)
48 android.RegisterModuleType("java_import_host", ImportFactoryHost)
Colin Cross3d7c9822019-03-01 13:46:24 -080049 android.RegisterModuleType("java_device_for_host", DeviceForHostFactory)
50 android.RegisterModuleType("java_host_for_device", HostForDeviceFactory)
Colin Cross42be7612019-02-21 18:12:14 -080051 android.RegisterModuleType("dex_import", DexImportFactory)
Colin Cross463a90e2015-06-17 14:20:06 -070052
Colin Cross798bfce2016-10-12 14:28:16 -070053 android.RegisterSingletonType("logtags", LogtagsSingleton)
Sasha Smundak2a4549e2018-11-05 16:49:08 -080054 android.RegisterSingletonType("kythe_java_extract", kytheExtractJavaFactory)
Colin Cross463a90e2015-06-17 14:20:06 -070055}
56
Jeongik Cha2cc570d2019-10-29 15:44:45 +090057func (j *Module) checkSdkVersion(ctx android.ModuleContext) {
58 if j.SocSpecific() || j.DeviceSpecific() ||
59 (j.ProductSpecific() && ctx.Config().EnforceProductPartitionInterface()) {
60 if sc, ok := ctx.Module().(sdkContext); ok {
61 if sc.sdkVersion() == "" {
62 ctx.PropertyErrorf("sdk_version",
63 "sdk_version must have a value when the module is located at vendor or product(only if PRODUCT_ENFORCE_PRODUCT_PARTITION_INTERFACE is set).")
64 }
65 }
66 }
67}
68
Jeongik Cha538c0d02019-07-11 15:54:27 +090069func (j *Module) checkPlatformAPI(ctx android.ModuleContext) {
70 if sc, ok := ctx.Module().(sdkContext); ok {
71 usePlatformAPI := proptools.Bool(j.deviceProperties.Platform_apis)
72 if usePlatformAPI != (sc.sdkVersion() == "") {
73 if usePlatformAPI {
74 ctx.PropertyErrorf("platform_apis", "platform_apis must be false when sdk_version is not empty.")
75 } else {
76 ctx.PropertyErrorf("platform_apis", "platform_apis must be true when sdk_version is empty.")
77 }
78 }
79
80 }
81}
82
Colin Cross2fe66872015-03-30 17:20:39 -070083// TODO:
84// Autogenerated files:
Colin Cross2fe66872015-03-30 17:20:39 -070085// Renderscript
86// Post-jar passes:
87// Proguard
Colin Cross2fe66872015-03-30 17:20:39 -070088// Rmtypedefs
Colin Cross2fe66872015-03-30 17:20:39 -070089// DroidDoc
90// Findbugs
91
Colin Cross89536d42017-07-07 14:35:50 -070092type CompilerProperties struct {
Colin Cross7d5136f2015-05-11 13:39:40 -070093 // list of source files used to compile the Java module. May be .java, .logtags, .proto,
94 // or .aidl files.
Colin Cross27b922f2019-03-04 22:35:41 -080095 Srcs []string `android:"path,arch_variant"`
Dan Willemsen2ef08f42015-06-30 18:15:24 -070096
97 // list of source files that should not be used to build the Java module.
98 // This is most useful in the arch/multilib variants to remove non-common files
Colin Cross27b922f2019-03-04 22:35:41 -080099 Exclude_srcs []string `android:"path,arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700100
101 // list of directories containing Java resources
Colin Cross86a63ff2017-09-27 17:33:10 -0700102 Java_resource_dirs []string `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700103
Colin Cross86a63ff2017-09-27 17:33:10 -0700104 // list of directories that should be excluded from java_resource_dirs
105 Exclude_java_resource_dirs []string `android:"arch_variant"`
Dan Willemsen2ef08f42015-06-30 18:15:24 -0700106
Colin Cross0f37af02017-09-27 17:42:05 -0700107 // list of files to use as Java resources
Colin Cross27b922f2019-03-04 22:35:41 -0800108 Java_resources []string `android:"path,arch_variant"`
Colin Cross0f37af02017-09-27 17:42:05 -0700109
Colin Crosscedd4762018-09-13 11:26:19 -0700110 // list of files that should be excluded from java_resources and java_resource_dirs
Colin Cross27b922f2019-03-04 22:35:41 -0800111 Exclude_java_resources []string `android:"path,arch_variant"`
Colin Cross0f37af02017-09-27 17:42:05 -0700112
Colin Cross7d5136f2015-05-11 13:39:40 -0700113 // list of module-specific flags that will be used for javac compiles
114 Javacflags []string `android:"arch_variant"`
115
Zoran Jovanovic8736ce22018-08-21 17:10:29 +0200116 // list of module-specific flags that will be used for kotlinc compiles
117 Kotlincflags []string `android:"arch_variant"`
118
Colin Cross7d5136f2015-05-11 13:39:40 -0700119 // list of of java libraries that will be in the classpath
Colin Crosse8dc34a2017-07-19 11:22:16 -0700120 Libs []string `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700121
122 // list of java libraries that will be compiled into the resulting jar
Colin Crosse8dc34a2017-07-19 11:22:16 -0700123 Static_libs []string `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700124
125 // manifest file to be included in resulting jar
Colin Cross27b922f2019-03-04 22:35:41 -0800126 Manifest *string `android:"path"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700127
Colin Cross540eff82017-06-22 17:01:52 -0700128 // if not blank, run jarjar using the specified rules file
Colin Cross27b922f2019-03-04 22:35:41 -0800129 Jarjar_rules *string `android:"path,arch_variant"`
Colin Cross64162712017-08-08 13:17:59 -0700130
131 // If not blank, set the java version passed to javac as -source and -target
132 Java_version *string
Colin Cross2c429dc2017-08-31 16:45:16 -0700133
Colin Cross9ae1b922018-06-26 17:59:05 -0700134 // If set to true, allow this module to be dexed and installed on devices. Has no
135 // effect on host modules, which are always considered installable.
Colin Cross2c429dc2017-08-31 16:45:16 -0700136 Installable *bool
Colin Cross32f676a2017-09-06 13:41:06 -0700137
Colin Cross0f37af02017-09-27 17:42:05 -0700138 // If set to true, include sources used to compile the module in to the final jar
139 Include_srcs *bool
140
Vladimir Marko0975ee02019-04-02 10:29:55 +0100141 // If not empty, classes are restricted to the specified packages and their sub-packages.
142 // This restriction is checked after applying jarjar rules and including static libs.
143 Permitted_packages []string
144
Colin Crossbe9cdb82019-01-21 21:37:16 -0800145 // List of modules to use as annotation processors
146 Plugins []string
Colin Cross1369cdb2017-09-29 17:58:17 -0700147
Nan Zhang61eaedb2017-11-02 13:28:15 -0700148 // The number of Java source entries each Javac instance can process
149 Javac_shard_size *int64
150
Nan Zhang5f8cb422018-02-06 10:34:32 -0800151 // Add host jdk tools.jar to bootclasspath
152 Use_tools_jar *bool
153
Colin Cross1369cdb2017-09-29 17:58:17 -0700154 Openjdk9 struct {
Colin Cross6cef4812019-10-17 14:23:50 -0700155 // List of source files that should only be used when passing -source 1.9 or higher
Colin Cross27b922f2019-03-04 22:35:41 -0800156 Srcs []string `android:"path"`
Colin Cross1369cdb2017-09-29 17:58:17 -0700157
Colin Cross6cef4812019-10-17 14:23:50 -0700158 // List of javac flags that should only be used when passing -source 1.9 or higher
Colin Cross1369cdb2017-09-29 17:58:17 -0700159 Javacflags []string
160 }
Colin Crosscb933592017-11-22 13:49:43 -0800161
Colin Cross81440082018-08-15 20:21:55 -0700162 // When compiling language level 9+ .java code in packages that are part of
163 // a system module, patch_module names the module that your sources and
164 // dependencies should be patched into. The Android runtime currently
165 // doesn't implement the JEP 261 module system so this option is only
166 // supported at compile time. It should only be needed to compile tests in
167 // packages that exist in libcore and which are inconvenient to move
168 // elsewhere.
Tobias Thiererdda713d2018-09-19 16:16:19 +0100169 Patch_module *string `android:"arch_variant"`
Colin Cross81440082018-08-15 20:21:55 -0700170
Colin Crosscb933592017-11-22 13:49:43 -0800171 Jacoco struct {
172 // List of classes to include for instrumentation with jacoco to collect coverage
173 // information at runtime when building with coverage enabled. If unset defaults to all
174 // classes.
175 // Supports '*' as the last character of an entry in the list as a wildcard match.
176 // If preceded by '.' it matches all classes in the package and subpackages, otherwise
177 // it matches classes in the package that have the class name as a prefix.
178 Include_filter []string
179
180 // List of classes to exclude from instrumentation with jacoco to collect coverage
181 // information at runtime when building with coverage enabled. Overrides classes selected
182 // by the include_filter property.
183 // Supports '*' as the last character of an entry in the list as a wildcard match.
184 // If preceded by '.' it matches all classes in the package and subpackages, otherwise
185 // it matches classes in the package that have the class name as a prefix.
186 Exclude_filter []string
187 }
188
Andreas Gampef3e5b552018-01-22 21:27:21 -0800189 Errorprone struct {
190 // List of javac flags that should only be used when running errorprone.
191 Javacflags []string
192 }
193
Colin Cross0f2ee152017-12-14 15:22:43 -0800194 Proto struct {
195 // List of extra options that will be passed to the proto generator.
196 Output_params []string
197 }
198
Colin Crosscb933592017-11-22 13:49:43 -0800199 Instrument bool `blueprint:"mutated"`
Alex Light7f004a72019-02-21 13:27:37 -0800200
201 // List of files to include in the META-INF/services folder of the resulting jar.
Colin Cross27b922f2019-03-04 22:35:41 -0800202 Services []string `android:"path,arch_variant"`
Colin Cross540eff82017-06-22 17:01:52 -0700203}
204
Colin Cross89536d42017-07-07 14:35:50 -0700205type CompilerDeviceProperties struct {
Colin Cross540eff82017-06-22 17:01:52 -0700206 // list of module-specific flags that will be used for dex compiles
207 Dxflags []string `android:"arch_variant"`
208
Jeongik Cha538c0d02019-07-11 15:54:27 +0900209 // if not blank, set to the version of the sdk to compile against.
210 // Defaults to compiling against the current platform.
Nan Zhangea568a42017-11-08 21:20:04 -0800211 Sdk_version *string
Colin Cross7d5136f2015-05-11 13:39:40 -0700212
Colin Cross83bb3162018-06-25 15:48:06 -0700213 // if not blank, set the minimum version of the sdk that the compiled artifacts will run against.
214 // Defaults to sdk_version if not set.
215 Min_sdk_version *string
216
Dan Willemsen419290a2018-10-31 15:28:47 -0700217 // if not blank, set the targetSdkVersion in the AndroidManifest.xml.
218 // Defaults to sdk_version if not set.
219 Target_sdk_version *string
220
Jeongik Cha356dac42019-08-19 14:09:52 +0900221 // Whether to compile against the platform APIs instead of an SDK.
222 // If true, then sdk_version must be empty. The value of this field
223 // is ignored when module's type isn't android_app.
Colin Cross6af2e492018-05-22 11:12:33 -0700224 Platform_apis *bool
225
Colin Crossebe1a512017-11-14 13:12:14 -0800226 Aidl struct {
227 // Top level directories to pass to aidl tool
228 Include_dirs []string
Colin Cross7d5136f2015-05-11 13:39:40 -0700229
Colin Crossebe1a512017-11-14 13:12:14 -0800230 // Directories rooted at the Android.bp file to pass to aidl tool
231 Local_include_dirs []string
232
233 // directories that should be added as include directories for any aidl sources of modules
234 // that depend on this module, as well as to aidl for this module.
235 Export_include_dirs []string
Martijn Coeneneab15642018-03-09 09:29:59 +0100236
237 // whether to generate traces (for systrace) for this interface
238 Generate_traces *bool
Olivier Gaillard0a4cfbc2018-07-16 23:37:03 +0100239
240 // whether to generate Binder#GetTransaction name method.
241 Generate_get_transaction_name *bool
Colin Crossebe1a512017-11-14 13:12:14 -0800242 }
Colin Cross92430102017-10-09 14:59:32 -0700243
244 // If true, export a copy of the module as a -hostdex module for host testing.
245 Hostdex *bool
Colin Cross1369cdb2017-09-29 17:58:17 -0700246
Colin Cross7f87f4f2019-04-24 13:41:45 -0700247 Target struct {
248 Hostdex struct {
249 // Additional required dependencies to add to -hostdex modules.
250 Required []string
251 }
252 }
253
David Brazdil17ef5632018-06-27 10:27:45 +0100254 // If set to true, compile dex regardless of installable. Defaults to false.
255 Compile_dex *bool
256
Colin Cross66dbc0b2017-12-28 12:23:20 -0800257 Optimize struct {
Colin Crossae5caf52018-05-22 11:11:52 -0700258 // If false, disable all optimization. Defaults to true for android_app and android_test
259 // modules, false for java_library and java_test modules.
Colin Cross66dbc0b2017-12-28 12:23:20 -0800260 Enabled *bool
Sasha Smundak2057f822019-04-16 17:16:58 -0700261 // True if the module containing this has it set by default.
262 EnabledByDefault bool `blueprint:"mutated"`
Colin Cross66dbc0b2017-12-28 12:23:20 -0800263
264 // If true, optimize for size by removing unused code. Defaults to true for apps,
265 // false for libraries and tests.
266 Shrink *bool
267
268 // If true, optimize bytecode. Defaults to false.
269 Optimize *bool
270
271 // If true, obfuscate bytecode. Defaults to false.
272 Obfuscate *bool
273
274 // If true, do not use the flag files generated by aapt that automatically keep
275 // classes referenced by the app manifest. Defaults to false.
276 No_aapt_flags *bool
277
278 // Flags to pass to proguard.
279 Proguard_flags []string
280
281 // Specifies the locations of files containing proguard flags.
Colin Cross27b922f2019-03-04 22:35:41 -0800282 Proguard_flags_files []string `android:"path"`
Colin Cross66dbc0b2017-12-28 12:23:20 -0800283 }
284
Paul Duffine25c6442019-10-11 13:50:28 +0100285 // When targeting 1.9 and above, override the modules to use with --system,
286 // otherwise provides defaults libraries to add to the bootclasspath.
Colin Cross1369cdb2017-09-29 17:58:17 -0700287 System_modules *string
Colin Cross5a0dcd52018-10-05 14:20:06 -0700288
Jiyong Park4c4c0242019-10-21 14:53:15 +0900289 // set the name of the output
290 Stem *string
291
Colin Cross5a0dcd52018-10-05 14:20:06 -0700292 UncompressDex bool `blueprint:"mutated"`
Colin Cross43f08db2018-11-12 10:13:39 -0800293 IsSDKLibrary bool `blueprint:"mutated"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700294}
295
Sasha Smundak2057f822019-04-16 17:16:58 -0700296func (me *CompilerDeviceProperties) EffectiveOptimizeEnabled() bool {
297 return BoolDefault(me.Optimize.Enabled, me.Optimize.EnabledByDefault)
298}
299
Colin Cross46c9b8b2017-06-22 16:51:17 -0700300// Module contains the properties and members used by all java module types
301type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700302 android.ModuleBase
Colin Cross89536d42017-07-07 14:35:50 -0700303 android.DefaultableModuleBase
Jiyong Park7f7766d2019-07-25 22:02:35 +0900304 android.ApexModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +0900305 android.SdkBase
Colin Cross2fe66872015-03-30 17:20:39 -0700306
Colin Cross89536d42017-07-07 14:35:50 -0700307 properties CompilerProperties
Colin Cross6af17aa2017-09-20 12:59:05 -0700308 protoProperties android.ProtoProperties
Colin Cross89536d42017-07-07 14:35:50 -0700309 deviceProperties CompilerDeviceProperties
Colin Cross2fe66872015-03-30 17:20:39 -0700310
Colin Cross331a1212018-08-15 20:40:52 -0700311 // jar file containing header classes including static library dependencies, suitable for
312 // inserting into the bootclasspath/classpath of another compile
Nan Zhanged19fc32017-10-19 13:06:22 -0700313 headerJarFile android.Path
314
Colin Cross331a1212018-08-15 20:40:52 -0700315 // jar file containing implementation classes including static library dependencies but no
316 // resources
Nan Zhanged19fc32017-10-19 13:06:22 -0700317 implementationJarFile android.Path
Colin Cross2fe66872015-03-30 17:20:39 -0700318
Colin Cross331a1212018-08-15 20:40:52 -0700319 // jar file containing only resources including from static library dependencies
320 resourceJar android.Path
321
Colin Cross0c4ce212019-05-03 15:28:19 -0700322 // args and dependencies to package source files into a srcjar
323 srcJarArgs []string
324 srcJarDeps android.Paths
325
Colin Cross331a1212018-08-15 20:40:52 -0700326 // jar file containing implementation classes and resources including static library
327 // dependencies
328 implementationAndResourcesJar android.Path
329
330 // output file containing classes.dex and resources
Colin Cross6ade34f2017-09-15 13:00:47 -0700331 dexJarFile android.Path
332
Colin Cross43f08db2018-11-12 10:13:39 -0800333 // output file that contains classes.dex if it should be in the output file
334 maybeStrippedDexJarFile android.Path
335
Colin Crosscb933592017-11-22 13:49:43 -0800336 // output file containing uninstrumented classes that will be instrumented by jacoco
337 jacocoReportClassesFile android.Path
338
Colin Cross66dbc0b2017-12-28 12:23:20 -0800339 // output file containing mapping of obfuscated names
340 proguardDictionary android.Path
341
Colin Cross331a1212018-08-15 20:40:52 -0700342 // output file of the module, which may be a classes jar or a dex jar
Colin Crosse560c4a2019-03-19 16:03:11 -0700343 outputFile android.Path
344 extraOutputFiles android.Paths
Colin Crossb7a63242015-04-16 14:09:14 -0700345
Colin Cross635c3b02016-05-18 15:37:25 -0700346 exportAidlIncludeDirs android.Paths
Colin Crossc0b06f12015-04-08 13:03:43 -0700347
Colin Cross635c3b02016-05-18 15:37:25 -0700348 logtagsSrcs android.Paths
Colin Crossf05fe972015-04-10 17:45:20 -0700349
Colin Cross2fe66872015-03-30 17:20:39 -0700350 // installed file for binary dependency
Colin Cross635c3b02016-05-18 15:37:25 -0700351 installFile android.Path
Colin Cross5ab4e6d2017-11-22 16:20:45 -0800352
353 // list of .java files and srcjars that was passed to javac
354 compiledJavaSrcs android.Paths
355 compiledSrcJars android.Paths
Colin Cross66dbc0b2017-12-28 12:23:20 -0800356
357 // list of extra progurad flag files
358 extraProguardFlagFiles android.Paths
Jiyong Park1be96912018-05-28 18:02:19 +0900359
Colin Cross094054a2018-10-17 15:10:48 -0700360 // manifest file to use instead of properties.Manifest
361 overrideManifest android.OptionalPath
362
Jiyong Park1be96912018-05-28 18:02:19 +0900363 // list of SDK lib names that this java moudule is exporting
364 exportedSdkLibs []string
Brandon Lee5d45c6f2018-08-15 15:35:38 -0700365
patricktu242faad2019-09-24 15:41:30 +0800366 // list of source files, collected from srcFiles with uniqie java and all kt files,
367 // will be used by android.IDEInfo struct
Brandon Lee5d45c6f2018-08-15 15:35:38 -0700368 expandIDEInfoCompiledSrcs []string
Colin Cross43f08db2018-11-12 10:13:39 -0800369
Steven Morelandc4efd9c2019-01-18 11:51:25 -0800370 // expanded Jarjar_rules
371 expandJarjarRules android.Path
372
Vladimir Marko0975ee02019-04-02 10:29:55 +0100373 // list of additional targets for checkbuild
374 additionalCheckedModules android.Paths
375
Colin Cross988708c2019-05-06 14:04:11 -0700376 // Extra files generated by the module type to be added as java resources.
377 extraResources android.Paths
378
Colin Crossf24a22a2019-01-31 14:12:44 -0800379 hiddenAPI
Colin Cross43f08db2018-11-12 10:13:39 -0800380 dexpreopter
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800381
382 // list of the xref extraction files
383 kytheFiles android.Paths
Colin Cross2fe66872015-03-30 17:20:39 -0700384}
385
Colin Cross41955e82019-05-29 14:40:35 -0700386func (j *Module) OutputFiles(tag string) (android.Paths, error) {
387 switch tag {
388 case "":
389 return append(android.Paths{j.outputFile}, j.extraOutputFiles...), nil
Colin Cross375ca3c2019-05-29 14:40:58 -0700390 case ".jar":
391 return android.Paths{j.implementationAndResourcesJar}, nil
Colin Cross2d975b12019-07-29 16:47:42 -0700392 case ".proguard_map":
393 return android.Paths{j.proguardDictionary}, nil
Colin Cross41955e82019-05-29 14:40:35 -0700394 default:
395 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
396 }
Colin Cross54250902017-12-05 09:28:08 -0800397}
398
Jiyong Park8fd61922018-11-08 02:50:25 +0900399func (j *Module) DexJarFile() android.Path {
400 return j.dexJarFile
401}
402
Colin Cross41955e82019-05-29 14:40:35 -0700403var _ android.OutputFileProducer = (*Module)(nil)
Colin Cross54250902017-12-05 09:28:08 -0800404
Colin Crossf506d872017-07-19 15:53:04 -0700405type Dependency interface {
Nan Zhanged19fc32017-10-19 13:06:22 -0700406 HeaderJars() android.Paths
407 ImplementationJars() android.Paths
Colin Cross331a1212018-08-15 20:40:52 -0700408 ResourceJars() android.Paths
409 ImplementationAndResourcesJars() android.Paths
Colin Crossf24a22a2019-01-31 14:12:44 -0800410 DexJar() android.Path
Colin Cross635c3b02016-05-18 15:37:25 -0700411 AidlIncludeDirs() android.Paths
Jiyong Park1be96912018-05-28 18:02:19 +0900412 ExportedSdkLibs() []string
Colin Cross0c4ce212019-05-03 15:28:19 -0700413 SrcJarArgs() ([]string, android.Paths)
Colin Crosse323f3c2019-09-17 15:34:09 -0700414 BaseModuleName() string
Colin Cross2fe66872015-03-30 17:20:39 -0700415}
416
Jiyong Parkc678ad32018-04-10 13:07:10 +0900417type SdkLibraryDependency interface {
Colin Cross0ea8ba82019-06-06 14:33:29 -0700418 SdkHeaderJars(ctx android.BaseModuleContext, sdkVersion string) android.Paths
419 SdkImplementationJars(ctx android.BaseModuleContext, sdkVersion string) android.Paths
Jiyong Parkc678ad32018-04-10 13:07:10 +0900420}
421
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800422type xref interface {
423 XrefJavaFiles() android.Paths
424}
425
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800426func (j *Module) XrefJavaFiles() android.Paths {
427 return j.kytheFiles
428}
429
Colin Cross89536d42017-07-07 14:35:50 -0700430func InitJavaModule(module android.DefaultableModule, hod android.HostOrDeviceSupported) {
431 android.InitAndroidArchModule(module, hod, android.MultilibCommon)
432 android.InitDefaultableModule(module)
433}
434
Colin Crossbe1da472017-07-07 15:59:46 -0700435type dependencyTag struct {
436 blueprint.BaseDependencyTag
437 name string
Colin Cross2fe66872015-03-30 17:20:39 -0700438}
439
Colin Crossa4f08812018-10-02 22:03:40 -0700440type jniDependencyTag struct {
441 blueprint.BaseDependencyTag
442 target android.Target
443}
444
Jiyong Park8be103b2019-11-08 15:53:48 +0900445func IsJniDepTag(depTag blueprint.DependencyTag) bool {
446 _, ok := depTag.(*jniDependencyTag)
447 return ok
448}
449
Colin Crossbe1da472017-07-07 15:59:46 -0700450var (
Colin Cross4b964c02018-10-15 16:18:06 -0700451 staticLibTag = dependencyTag{name: "staticlib"}
452 libTag = dependencyTag{name: "javalib"}
Colin Cross6cef4812019-10-17 14:23:50 -0700453 java9LibTag = dependencyTag{name: "java9lib"}
Colin Crossbe9cdb82019-01-21 21:37:16 -0800454 pluginTag = dependencyTag{name: "plugin"}
Colin Cross4b964c02018-10-15 16:18:06 -0700455 bootClasspathTag = dependencyTag{name: "bootclasspath"}
456 systemModulesTag = dependencyTag{name: "system modules"}
457 frameworkResTag = dependencyTag{name: "framework-res"}
458 frameworkApkTag = dependencyTag{name: "framework-apk"}
459 kotlinStdlibTag = dependencyTag{name: "kotlin-stdlib"}
Colin Crossafbb1732019-01-17 15:42:52 -0800460 kotlinAnnotationsTag = dependencyTag{name: "kotlin-annotations"}
Colin Cross4b964c02018-10-15 16:18:06 -0700461 proguardRaiseTag = dependencyTag{name: "proguard-raise"}
462 certificateTag = dependencyTag{name: "certificate"}
463 instrumentationForTag = dependencyTag{name: "instrumentation_for"}
Colin Cross50ddcc42019-05-16 12:28:22 -0700464 usesLibTag = dependencyTag{name: "uses-library"}
Colin Crossbe1da472017-07-07 15:59:46 -0700465)
Colin Cross2fe66872015-03-30 17:20:39 -0700466
Colin Crossfc3674a2017-09-18 17:41:52 -0700467type sdkDep struct {
Colin Cross47ff2522017-10-02 14:22:08 -0700468 useModule, useFiles, useDefaultLibs, invalidVersion bool
469
Colin Cross6cef4812019-10-17 14:23:50 -0700470 // The modules that will be added to the bootclasspath when targeting 1.8 or lower
471 bootclasspath []string
Paul Duffine25c6442019-10-11 13:50:28 +0100472
473 // The default system modules to use. Will be an empty string if no system
474 // modules are to be used.
Colin Cross1369cdb2017-09-29 17:58:17 -0700475 systemModules string
476
Colin Cross6cef4812019-10-17 14:23:50 -0700477 // The modules that will be added ot the classpath when targeting 1.9 or higher
478 java9Classpath []string
479
Colin Crossa97c5d32018-03-28 14:58:31 -0700480 frameworkResModule string
481
Colin Cross86a60ae2018-05-29 14:44:55 -0700482 jars android.Paths
Colin Cross3047fa22019-04-18 10:56:44 -0700483 aidl android.OptionalPath
Paul Duffin250e6192019-06-07 10:44:37 +0100484
485 noStandardLibs, noFrameworksLibs bool
486}
487
488func (s sdkDep) hasStandardLibs() bool {
489 return !s.noStandardLibs
490}
491
492func (s sdkDep) hasFrameworkLibs() bool {
493 return !s.noStandardLibs && !s.noFrameworksLibs
Colin Cross1369cdb2017-09-29 17:58:17 -0700494}
495
Colin Crossa4f08812018-10-02 22:03:40 -0700496type jniLib struct {
497 name string
498 path android.Path
499 target android.Target
500}
501
Colin Cross0ea8ba82019-06-06 14:33:29 -0700502func (j *Module) shouldInstrument(ctx android.BaseModuleContext) bool {
Colin Cross3144dfc2018-01-03 15:06:47 -0800503 return j.properties.Instrument && ctx.Config().IsEnvTrue("EMMA_INSTRUMENT")
504}
505
Colin Cross0ea8ba82019-06-06 14:33:29 -0700506func (j *Module) shouldInstrumentStatic(ctx android.BaseModuleContext) bool {
Colin Cross3144dfc2018-01-03 15:06:47 -0800507 return j.shouldInstrument(ctx) &&
508 (ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_STATIC") ||
509 ctx.Config().UnbundledBuild())
510}
511
Colin Cross83bb3162018-06-25 15:48:06 -0700512func (j *Module) sdkVersion() string {
Jeongik Cha2cc570d2019-10-29 15:44:45 +0900513 return String(j.deviceProperties.Sdk_version)
Colin Cross83bb3162018-06-25 15:48:06 -0700514}
515
Paul Duffine25c6442019-10-11 13:50:28 +0100516func (j *Module) systemModules() string {
517 return proptools.String(j.deviceProperties.System_modules)
518}
519
Colin Cross83bb3162018-06-25 15:48:06 -0700520func (j *Module) minSdkVersion() string {
521 if j.deviceProperties.Min_sdk_version != nil {
522 return *j.deviceProperties.Min_sdk_version
523 }
524 return j.sdkVersion()
525}
526
Dan Willemsen419290a2018-10-31 15:28:47 -0700527func (j *Module) targetSdkVersion() string {
528 if j.deviceProperties.Target_sdk_version != nil {
529 return *j.deviceProperties.Target_sdk_version
530 }
531 return j.sdkVersion()
532}
533
Colin Crossbe1da472017-07-07 15:59:46 -0700534func (j *Module) deps(ctx android.BottomUpMutatorContext) {
Colin Cross1369cdb2017-09-29 17:58:17 -0700535 if ctx.Device() {
Paul Duffin250e6192019-06-07 10:44:37 +0100536 sdkDep := decodeSdkDep(ctx, sdkContext(j))
Colin Cross6d8d8c62019-10-28 15:10:03 -0700537 if sdkDep.useDefaultLibs {
538 ctx.AddVariationDependencies(nil, bootClasspathTag, config.DefaultBootclasspathLibraries...)
539 ctx.AddVariationDependencies(nil, systemModulesTag, config.DefaultSystemModules)
540 if sdkDep.hasFrameworkLibs() {
541 ctx.AddVariationDependencies(nil, libTag, config.DefaultLibraries...)
Colin Crossbe1da472017-07-07 15:59:46 -0700542 }
Colin Cross6d8d8c62019-10-28 15:10:03 -0700543 } else if sdkDep.useModule {
Colin Cross6cef4812019-10-17 14:23:50 -0700544 ctx.AddVariationDependencies(nil, bootClasspathTag, sdkDep.bootclasspath...)
Paul Duffine25c6442019-10-11 13:50:28 +0100545 ctx.AddVariationDependencies(nil, systemModulesTag, sdkDep.systemModules)
Colin Cross6cef4812019-10-17 14:23:50 -0700546 ctx.AddVariationDependencies(nil, java9LibTag, sdkDep.java9Classpath...)
Colin Cross6d8d8c62019-10-28 15:10:03 -0700547 if j.deviceProperties.EffectiveOptimizeEnabled() && sdkDep.hasStandardLibs() {
548 ctx.AddVariationDependencies(nil, proguardRaiseTag, config.DefaultBootclasspathLibraries...)
549 ctx.AddVariationDependencies(nil, proguardRaiseTag, config.DefaultLibraries...)
550 }
Colin Cross2fe66872015-03-30 17:20:39 -0700551 }
Colin Cross6d8d8c62019-10-28 15:10:03 -0700552
Nan Zhangb2b33de2018-02-23 11:18:47 -0800553 if ctx.ModuleName() == "android_stubs_current" ||
554 ctx.ModuleName() == "android_system_stubs_current" ||
Nan Zhang863f05b2018-08-07 13:41:10 -0700555 ctx.ModuleName() == "android_test_stubs_current" {
Colin Cross42d48b72018-08-29 14:10:52 -0700556 ctx.AddVariationDependencies(nil, frameworkApkTag, "framework-res")
Nan Zhangb2b33de2018-02-23 11:18:47 -0800557 }
Colin Cross2fe66872015-03-30 17:20:39 -0700558 }
Colin Cross1369cdb2017-09-29 17:58:17 -0700559
Colin Cross42d48b72018-08-29 14:10:52 -0700560 ctx.AddVariationDependencies(nil, libTag, j.properties.Libs...)
561 ctx.AddVariationDependencies(nil, staticLibTag, j.properties.Static_libs...)
Colin Crossa4f08812018-10-02 22:03:40 -0700562
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700563 ctx.AddFarVariationDependencies(ctx.Config().BuildOSCommonTarget.Variations(), pluginTag, j.properties.Plugins...)
Colin Crossbe9cdb82019-01-21 21:37:16 -0800564
Colin Crossfe17f6f2019-03-28 19:30:56 -0700565 android.ProtoDeps(ctx, &j.protoProperties)
Colin Cross6af17aa2017-09-20 12:59:05 -0700566 if j.hasSrcExt(".proto") {
567 protoDeps(ctx, &j.protoProperties)
568 }
Colin Cross93e85952017-08-15 13:34:18 -0700569
570 if j.hasSrcExt(".kt") {
571 // TODO(ccross): move this to a mutator pass that can tell if generated sources contain
572 // Kotlin files
Colin Cross0b03d972019-05-13 11:06:25 -0700573 ctx.AddVariationDependencies(nil, kotlinStdlibTag,
574 "kotlin-stdlib", "kotlin-stdlib-jdk7", "kotlin-stdlib-jdk8")
Colin Cross7788c122019-01-23 16:14:02 -0800575 if len(j.properties.Plugins) > 0 {
Colin Crossafbb1732019-01-17 15:42:52 -0800576 ctx.AddVariationDependencies(nil, kotlinAnnotationsTag, "kotlin-annotations")
577 }
Colin Cross93e85952017-08-15 13:34:18 -0700578 }
Colin Cross3144dfc2018-01-03 15:06:47 -0800579
580 if j.shouldInstrumentStatic(ctx) {
Colin Cross42d48b72018-08-29 14:10:52 -0700581 ctx.AddVariationDependencies(nil, staticLibTag, "jacocoagent")
Colin Cross3144dfc2018-01-03 15:06:47 -0800582 }
Colin Cross6af17aa2017-09-20 12:59:05 -0700583}
584
585func hasSrcExt(srcs []string, ext string) bool {
586 for _, src := range srcs {
587 if filepath.Ext(src) == ext {
588 return true
589 }
590 }
591
592 return false
593}
594
595func (j *Module) hasSrcExt(ext string) bool {
596 return hasSrcExt(j.properties.Srcs, ext)
Colin Cross2fe66872015-03-30 17:20:39 -0700597}
598
Colin Cross46c9b8b2017-06-22 16:51:17 -0700599func (j *Module) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.OptionalPath,
Colin Cross3047fa22019-04-18 10:56:44 -0700600 aidlIncludeDirs android.Paths) (string, android.Paths) {
Colin Crossc0b06f12015-04-08 13:03:43 -0700601
Colin Crossebe1a512017-11-14 13:12:14 -0800602 aidlIncludes := android.PathsForModuleSrc(ctx, j.deviceProperties.Aidl.Local_include_dirs)
603 aidlIncludes = append(aidlIncludes,
604 android.PathsForModuleSrc(ctx, j.deviceProperties.Aidl.Export_include_dirs)...)
605 aidlIncludes = append(aidlIncludes,
606 android.PathsForSource(ctx, j.deviceProperties.Aidl.Include_dirs)...)
Colin Crossc0b06f12015-04-08 13:03:43 -0700607
Colin Cross3047fa22019-04-18 10:56:44 -0700608 var flags []string
609 var deps android.Paths
Steven Moreland667f6882018-07-26 12:55:08 -0700610
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700611 if aidlPreprocess.Valid() {
612 flags = append(flags, "-p"+aidlPreprocess.String())
Colin Cross3047fa22019-04-18 10:56:44 -0700613 deps = append(deps, aidlPreprocess.Path())
614 } else if len(aidlIncludeDirs) > 0 {
Colin Cross635c3b02016-05-18 15:37:25 -0700615 flags = append(flags, android.JoinWithPrefix(aidlIncludeDirs.Strings(), "-I"))
Colin Crossc0b06f12015-04-08 13:03:43 -0700616 }
617
Colin Cross3047fa22019-04-18 10:56:44 -0700618 if len(j.exportAidlIncludeDirs) > 0 {
619 flags = append(flags, android.JoinWithPrefix(j.exportAidlIncludeDirs.Strings(), "-I"))
620 }
621
622 if len(aidlIncludes) > 0 {
623 flags = append(flags, android.JoinWithPrefix(aidlIncludes.Strings(), "-I"))
624 }
625
Colin Cross635c3b02016-05-18 15:37:25 -0700626 flags = append(flags, "-I"+android.PathForModuleSrc(ctx).String())
Colin Cross32f38982018-02-22 11:47:25 -0800627 if src := android.ExistentPathForSource(ctx, ctx.ModuleDir(), "src"); src.Valid() {
Colin Crossd48633a2017-07-13 14:41:17 -0700628 flags = append(flags, "-I"+src.String())
629 }
Colin Crossc0b06f12015-04-08 13:03:43 -0700630
Martijn Coeneneab15642018-03-09 09:29:59 +0100631 if Bool(j.deviceProperties.Aidl.Generate_traces) {
632 flags = append(flags, "-t")
633 }
634
Olivier Gaillard0a4cfbc2018-07-16 23:37:03 +0100635 if Bool(j.deviceProperties.Aidl.Generate_get_transaction_name) {
636 flags = append(flags, "--transaction_names")
637 }
638
Colin Cross3047fa22019-04-18 10:56:44 -0700639 return strings.Join(flags, " "), deps
Colin Crossc0b06f12015-04-08 13:03:43 -0700640}
641
Colin Cross32f676a2017-09-06 13:41:06 -0700642type deps struct {
Nan Zhang581fd212018-01-10 16:06:12 -0800643 classpath classpath
Colin Cross6cef4812019-10-17 14:23:50 -0700644 java9Classpath classpath
Nan Zhang581fd212018-01-10 16:06:12 -0800645 bootClasspath classpath
Colin Cross6a77c982018-06-19 22:43:34 -0700646 processorPath classpath
Colin Crossbe9cdb82019-01-21 21:37:16 -0800647 processorClasses []string
Colin Cross6ade34f2017-09-15 13:00:47 -0700648 staticJars android.Paths
Nan Zhanged19fc32017-10-19 13:06:22 -0700649 staticHeaderJars android.Paths
Colin Cross331a1212018-08-15 20:40:52 -0700650 staticResourceJars android.Paths
Colin Cross6ade34f2017-09-15 13:00:47 -0700651 aidlIncludeDirs android.Paths
Nan Zhangb2b33de2018-02-23 11:18:47 -0800652 srcs android.Paths
Colin Cross59149b62017-10-16 18:07:29 -0700653 srcJars android.Paths
Colin Crossb77043e2019-07-16 13:57:13 -0700654 systemModules *systemModules
Colin Cross6ade34f2017-09-15 13:00:47 -0700655 aidlPreprocess android.OptionalPath
Colin Cross93e85952017-08-15 13:34:18 -0700656 kotlinStdlib android.Paths
Colin Crossafbb1732019-01-17 15:42:52 -0800657 kotlinAnnotations android.Paths
Colin Crossbe9cdb82019-01-21 21:37:16 -0800658
659 disableTurbine bool
Colin Cross32f676a2017-09-06 13:41:06 -0700660}
Colin Cross2fe66872015-03-30 17:20:39 -0700661
Colin Cross54250902017-12-05 09:28:08 -0800662func checkProducesJars(ctx android.ModuleContext, dep android.SourceFileProducer) {
663 for _, f := range dep.Srcs() {
664 if f.Ext() != ".jar" {
665 ctx.ModuleErrorf("genrule %q must generate files ending with .jar to be used as a libs or static_libs dependency",
666 ctx.OtherModuleName(dep.(blueprint.Module)))
667 }
668 }
669}
670
Jiyong Park2d492942018-03-05 17:44:10 +0900671type linkType int
672
673const (
674 javaCore linkType = iota
675 javaSdk
676 javaSystem
677 javaPlatform
678)
679
Jiyong Park46f78fb2018-10-20 16:33:17 +0900680func getLinkType(m *Module, name string) (ret linkType, stubs bool) {
Colin Cross83bb3162018-06-25 15:48:06 -0700681 ver := m.sdkVersion()
Colin Crossf19b9bb2018-03-26 14:42:44 -0700682 switch {
Jiyong Park46f78fb2018-10-20 16:33:17 +0900683 case name == "core.current.stubs" || name == "core.platform.api.stubs" ||
684 name == "stub-annotations" || name == "private-stub-annotations-jar" ||
Pete Gillincbff3262019-05-08 15:10:06 +0100685 name == "core-lambda-stubs" || name == "core-generated-annotation-stubs":
Jiyong Park46f78fb2018-10-20 16:33:17 +0900686 return javaCore, true
Neil Fuller401eeba2018-10-18 19:48:58 +0100687 case ver == "core_current":
Jiyong Park46f78fb2018-10-20 16:33:17 +0900688 return javaCore, false
689 case name == "android_system_stubs_current":
690 return javaSystem, true
691 case strings.HasPrefix(ver, "system_"):
692 return javaSystem, false
693 case name == "android_test_stubs_current":
694 return javaSystem, true
695 case strings.HasPrefix(ver, "test_"):
696 return javaPlatform, false
697 case name == "android_stubs_current":
698 return javaSdk, true
699 case ver == "current":
700 return javaSdk, false
Paul Duffin50c217c2019-06-12 13:25:22 +0100701 case ver == "" || ver == "none" || ver == "core_platform":
Jiyong Park46f78fb2018-10-20 16:33:17 +0900702 return javaPlatform, false
Colin Crossf19b9bb2018-03-26 14:42:44 -0700703 default:
704 if _, err := strconv.Atoi(ver); err != nil {
705 panic(fmt.Errorf("expected sdk_version to be a number, got %q", ver))
706 }
Jiyong Park46f78fb2018-10-20 16:33:17 +0900707 return javaSdk, false
Jiyong Park2d492942018-03-05 17:44:10 +0900708 }
709}
710
Jiyong Park750e5572018-01-31 00:20:13 +0900711func checkLinkType(ctx android.ModuleContext, from *Module, to *Library, tag dependencyTag) {
Colin Crossf19b9bb2018-03-26 14:42:44 -0700712 if ctx.Host() {
713 return
714 }
715
Jiyong Park46f78fb2018-10-20 16:33:17 +0900716 myLinkType, stubs := getLinkType(from, ctx.ModuleName())
717 if stubs {
718 return
719 }
720 otherLinkType, _ := getLinkType(&to.Module, ctx.OtherModuleName(to))
Jiyong Park2d492942018-03-05 17:44:10 +0900721 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."
722
723 switch myLinkType {
724 case javaCore:
725 if otherLinkType != javaCore {
726 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 +0900727 ctx.OtherModuleName(to))
728 }
Jiyong Park2d492942018-03-05 17:44:10 +0900729 break
730 case javaSdk:
731 if otherLinkType != javaCore && otherLinkType != javaSdk {
732 ctx.ModuleErrorf("compiles against Android API, but dependency %q is compiling against non-public Android API."+commonMessage,
733 ctx.OtherModuleName(to))
734 }
735 break
736 case javaSystem:
737 if otherLinkType == javaPlatform {
738 ctx.ModuleErrorf("compiles against system API, but dependency %q is compiling against private API."+commonMessage,
739 ctx.OtherModuleName(to))
740 }
741 break
742 case javaPlatform:
743 // no restriction on link-type
744 break
Jiyong Park750e5572018-01-31 00:20:13 +0900745 }
746}
747
Colin Cross32f676a2017-09-06 13:41:06 -0700748func (j *Module) collectDeps(ctx android.ModuleContext) deps {
749 var deps deps
Colin Crossfc3674a2017-09-18 17:41:52 -0700750
Colin Cross300f0382018-03-06 13:11:51 -0800751 if ctx.Device() {
Colin Cross83bb3162018-06-25 15:48:06 -0700752 sdkDep := decodeSdkDep(ctx, sdkContext(j))
Colin Cross300f0382018-03-06 13:11:51 -0800753 if sdkDep.invalidVersion {
Colin Cross6cef4812019-10-17 14:23:50 -0700754 ctx.AddMissingDependencies(sdkDep.bootclasspath)
755 ctx.AddMissingDependencies(sdkDep.java9Classpath)
Colin Cross300f0382018-03-06 13:11:51 -0800756 } else if sdkDep.useFiles {
757 // sdkDep.jar is actually equivalent to turbine header.jar.
Colin Cross86a60ae2018-05-29 14:44:55 -0700758 deps.classpath = append(deps.classpath, sdkDep.jars...)
Colin Cross3047fa22019-04-18 10:56:44 -0700759 deps.aidlPreprocess = sdkDep.aidl
760 } else {
761 deps.aidlPreprocess = sdkDep.aidl
Colin Cross300f0382018-03-06 13:11:51 -0800762 }
Colin Crossfc3674a2017-09-18 17:41:52 -0700763 }
764
Colin Crossd11fcda2017-10-23 17:59:01 -0700765 ctx.VisitDirectDeps(func(module android.Module) {
Colin Cross2fe66872015-03-30 17:20:39 -0700766 otherName := ctx.OtherModuleName(module)
Colin Crossec7a0422017-07-07 14:47:12 -0700767 tag := ctx.OtherModuleDependencyTag(module)
768
Colin Crossa4f08812018-10-02 22:03:40 -0700769 if _, ok := tag.(*jniDependencyTag); ok {
Colin Crossbd01e2a2018-10-04 15:21:03 -0700770 // Handled by AndroidApp.collectAppDeps
771 return
772 }
773 if tag == certificateTag {
774 // Handled by AndroidApp.collectAppDeps
Colin Crossa4f08812018-10-02 22:03:40 -0700775 return
776 }
777
Jiyong Park750e5572018-01-31 00:20:13 +0900778 if to, ok := module.(*Library); ok {
Colin Crossa97c5d32018-03-28 14:58:31 -0700779 switch tag {
780 case bootClasspathTag, libTag, staticLibTag:
781 checkLinkType(ctx, j, to, tag.(dependencyTag))
782 }
Jiyong Park750e5572018-01-31 00:20:13 +0900783 }
Colin Cross54250902017-12-05 09:28:08 -0800784 switch dep := module.(type) {
Colin Cross897d2ed2019-02-11 14:03:51 -0800785 case SdkLibraryDependency:
786 switch tag {
787 case libTag:
788 deps.classpath = append(deps.classpath, dep.SdkHeaderJars(ctx, j.sdkVersion())...)
789 // names of sdk libs that are directly depended are exported
790 j.exportedSdkLibs = append(j.exportedSdkLibs, otherName)
Colin Cross79c7c262019-04-17 11:11:46 -0700791 case staticLibTag:
Colin Cross897d2ed2019-02-11 14:03:51 -0800792 ctx.ModuleErrorf("dependency on java_sdk_library %q can only be in libs", otherName)
793 }
Colin Cross54250902017-12-05 09:28:08 -0800794 case Dependency:
795 switch tag {
796 case bootClasspathTag:
797 deps.bootClasspath = append(deps.bootClasspath, dep.HeaderJars()...)
Colin Cross4b964c02018-10-15 16:18:06 -0700798 case libTag, instrumentationForTag:
Colin Cross54250902017-12-05 09:28:08 -0800799 deps.classpath = append(deps.classpath, dep.HeaderJars()...)
Jiyong Park1be96912018-05-28 18:02:19 +0900800 // sdk lib names from dependencies are re-exported
801 j.exportedSdkLibs = append(j.exportedSdkLibs, dep.ExportedSdkLibs()...)
Colin Cross3047fa22019-04-18 10:56:44 -0700802 deps.aidlIncludeDirs = append(deps.aidlIncludeDirs, dep.AidlIncludeDirs()...)
Colin Cross6cef4812019-10-17 14:23:50 -0700803 case java9LibTag:
804 deps.java9Classpath = append(deps.java9Classpath, dep.HeaderJars()...)
Colin Cross54250902017-12-05 09:28:08 -0800805 case staticLibTag:
806 deps.classpath = append(deps.classpath, dep.HeaderJars()...)
807 deps.staticJars = append(deps.staticJars, dep.ImplementationJars()...)
808 deps.staticHeaderJars = append(deps.staticHeaderJars, dep.HeaderJars()...)
Colin Cross331a1212018-08-15 20:40:52 -0700809 deps.staticResourceJars = append(deps.staticResourceJars, dep.ResourceJars()...)
Jiyong Park1be96912018-05-28 18:02:19 +0900810 // sdk lib names from dependencies are re-exported
811 j.exportedSdkLibs = append(j.exportedSdkLibs, dep.ExportedSdkLibs()...)
Colin Cross3047fa22019-04-18 10:56:44 -0700812 deps.aidlIncludeDirs = append(deps.aidlIncludeDirs, dep.AidlIncludeDirs()...)
Colin Crossbe9cdb82019-01-21 21:37:16 -0800813 case pluginTag:
814 if plugin, ok := dep.(*Plugin); ok {
815 deps.processorPath = append(deps.processorPath, dep.ImplementationAndResourcesJars()...)
816 if plugin.pluginProperties.Processor_class != nil {
817 deps.processorClasses = append(deps.processorClasses, *plugin.pluginProperties.Processor_class)
818 }
819 deps.disableTurbine = deps.disableTurbine || Bool(plugin.pluginProperties.Generates_api)
820 } else {
821 ctx.PropertyErrorf("plugins", "%q is not a java_plugin module", otherName)
822 }
Nan Zhangb2b33de2018-02-23 11:18:47 -0800823 case frameworkApkTag:
824 if ctx.ModuleName() == "android_stubs_current" ||
825 ctx.ModuleName() == "android_system_stubs_current" ||
Nan Zhang863f05b2018-08-07 13:41:10 -0700826 ctx.ModuleName() == "android_test_stubs_current" {
Nan Zhangb2b33de2018-02-23 11:18:47 -0800827 // framework stubs.jar need to depend on framework-res.apk, in order to pull the
828 // resource files out of there for aapt.
829 //
830 // Normally the package rule runs aapt, which includes the resource,
831 // but we're not running that in our package rule so just copy in the
832 // resource files here.
Colin Cross331a1212018-08-15 20:40:52 -0700833 deps.staticResourceJars = append(deps.staticResourceJars, dep.(*AndroidApp).exportPackage)
Nan Zhangb2b33de2018-02-23 11:18:47 -0800834 }
Colin Cross54250902017-12-05 09:28:08 -0800835 case kotlinStdlibTag:
Colin Cross0b03d972019-05-13 11:06:25 -0700836 deps.kotlinStdlib = append(deps.kotlinStdlib, dep.HeaderJars()...)
Colin Crossafbb1732019-01-17 15:42:52 -0800837 case kotlinAnnotationsTag:
838 deps.kotlinAnnotations = dep.HeaderJars()
Colin Cross54250902017-12-05 09:28:08 -0800839 }
840
Colin Cross54250902017-12-05 09:28:08 -0800841 case android.SourceFileProducer:
842 switch tag {
843 case libTag:
844 checkProducesJars(ctx, dep)
845 deps.classpath = append(deps.classpath, dep.Srcs()...)
846 case staticLibTag:
847 checkProducesJars(ctx, dep)
848 deps.classpath = append(deps.classpath, dep.Srcs()...)
849 deps.staticJars = append(deps.staticJars, dep.Srcs()...)
850 deps.staticHeaderJars = append(deps.staticHeaderJars, dep.Srcs()...)
Colin Cross54250902017-12-05 09:28:08 -0800851 }
852 default:
Colin Crossec7a0422017-07-07 14:47:12 -0700853 switch tag {
Paul Duffin68289b02019-09-20 13:50:52 +0100854 case bootClasspathTag:
855 // If a system modules dependency has been added to the bootclasspath
856 // then add its libs to the bootclasspath.
857 sm := module.(*SystemModules)
858 deps.bootClasspath = append(deps.bootClasspath, sm.headerJars...)
859
Colin Cross1369cdb2017-09-29 17:58:17 -0700860 case systemModulesTag:
861 if deps.systemModules != nil {
862 panic("Found two system module dependencies")
863 }
864 sm := module.(*SystemModules)
Dan Willemsenff60a732019-06-13 16:52:01 +0000865 if sm.outputDir == nil || len(sm.outputDeps) == 0 {
Colin Cross1369cdb2017-09-29 17:58:17 -0700866 panic("Missing directory for system module dependency")
867 }
Colin Crossb77043e2019-07-16 13:57:13 -0700868 deps.systemModules = &systemModules{sm.outputDir, sm.outputDeps}
Colin Cross2fe66872015-03-30 17:20:39 -0700869 }
Colin Crossec7a0422017-07-07 14:47:12 -0700870 }
Colin Cross2fe66872015-03-30 17:20:39 -0700871 })
872
Jiyong Park1be96912018-05-28 18:02:19 +0900873 j.exportedSdkLibs = android.FirstUniqueStrings(j.exportedSdkLibs)
874
Colin Cross32f676a2017-09-06 13:41:06 -0700875 return deps
Colin Cross2fe66872015-03-30 17:20:39 -0700876}
877
Colin Cross1e743852019-10-28 11:37:20 -0700878func getJavaVersion(ctx android.ModuleContext, javaVersion string, sdkContext sdkContext) javaVersion {
Colin Cross98fd5742019-01-09 23:04:25 -0800879 v := sdkContext.sdkVersion()
880 // For PDK builds, use the latest SDK version instead of "current"
Paul Duffin50c217c2019-06-12 13:25:22 +0100881 if ctx.Config().IsPdkBuild() &&
882 (v == "" || v == "none" || v == "core_platform" || v == "current") {
Colin Cross3047fa22019-04-18 10:56:44 -0700883 sdkVersions := ctx.Config().Get(sdkVersionsKey).([]int)
Colin Cross98fd5742019-01-09 23:04:25 -0800884 latestSdkVersion := 0
885 if len(sdkVersions) > 0 {
886 latestSdkVersion = sdkVersions[len(sdkVersions)-1]
887 }
888 v = strconv.Itoa(latestSdkVersion)
889 }
890
891 sdk, err := sdkVersionToNumber(ctx, v)
Colin Cross83bb3162018-06-25 15:48:06 -0700892 if err != nil {
893 ctx.PropertyErrorf("sdk_version", "%s", err)
894 }
Nan Zhang357466b2018-04-17 17:38:36 -0700895 if javaVersion != "" {
Colin Cross1e743852019-10-28 11:37:20 -0700896 return normalizeJavaVersion(ctx, javaVersion)
Nan Zhang357466b2018-04-17 17:38:36 -0700897 } else if ctx.Device() && sdk <= 23 {
Colin Cross1e743852019-10-28 11:37:20 -0700898 return JAVA_VERSION_7
Pete Gillina1c9e9d2019-10-17 14:52:07 +0100899 } else if ctx.Device() && sdk <= 29 {
Colin Cross1e743852019-10-28 11:37:20 -0700900 return JAVA_VERSION_8
Colin Cross6cef4812019-10-17 14:23:50 -0700901 } else if ctx.Device() && ctx.Config().UnbundledBuildUsePrebuiltSdks() {
902 // TODO(b/142896162): once we have prebuilt system modules we can use 1.9 for unbundled builds
Colin Cross1e743852019-10-28 11:37:20 -0700903 return JAVA_VERSION_8
Nan Zhang357466b2018-04-17 17:38:36 -0700904 } else {
Colin Cross1e743852019-10-28 11:37:20 -0700905 return JAVA_VERSION_9
Nan Zhang357466b2018-04-17 17:38:36 -0700906 }
Nan Zhang357466b2018-04-17 17:38:36 -0700907}
908
Colin Cross1e743852019-10-28 11:37:20 -0700909type javaVersion int
910
911const (
912 JAVA_VERSION_UNSUPPORTED = 0
913 JAVA_VERSION_6 = 6
914 JAVA_VERSION_7 = 7
915 JAVA_VERSION_8 = 8
916 JAVA_VERSION_9 = 9
917)
918
919func (v javaVersion) String() string {
920 switch v {
921 case JAVA_VERSION_6:
922 return "1.6"
923 case JAVA_VERSION_7:
924 return "1.7"
925 case JAVA_VERSION_8:
926 return "1.8"
927 case JAVA_VERSION_9:
928 return "1.9"
929 default:
930 return "unsupported"
931 }
932}
933
934// Returns true if javac targeting this version uses system modules instead of a bootclasspath.
935func (v javaVersion) usesJavaModules() bool {
936 return v >= 9
937}
938
939func normalizeJavaVersion(ctx android.BaseModuleContext, javaVersion string) javaVersion {
Pete Gillin4e8b48a2019-07-12 13:16:17 +0100940 switch javaVersion {
941 case "1.6", "6":
Colin Cross1e743852019-10-28 11:37:20 -0700942 return JAVA_VERSION_6
Pete Gillin4e8b48a2019-07-12 13:16:17 +0100943 case "1.7", "7":
Colin Cross1e743852019-10-28 11:37:20 -0700944 return JAVA_VERSION_7
Pete Gillin4e8b48a2019-07-12 13:16:17 +0100945 case "1.8", "8":
Colin Cross1e743852019-10-28 11:37:20 -0700946 return JAVA_VERSION_8
Pete Gillin4e8b48a2019-07-12 13:16:17 +0100947 case "1.9", "9":
Colin Cross1e743852019-10-28 11:37:20 -0700948 return JAVA_VERSION_9
Pete Gillin4e8b48a2019-07-12 13:16:17 +0100949 case "10", "11":
950 ctx.PropertyErrorf("java_version", "Java language levels above 9 are not supported")
Colin Cross1e743852019-10-28 11:37:20 -0700951 return JAVA_VERSION_UNSUPPORTED
Pete Gillin4e8b48a2019-07-12 13:16:17 +0100952 default:
953 ctx.PropertyErrorf("java_version", "Unrecognized Java language level")
Colin Cross1e743852019-10-28 11:37:20 -0700954 return JAVA_VERSION_UNSUPPORTED
Pete Gillin4e8b48a2019-07-12 13:16:17 +0100955 }
956}
957
Nan Zhanged19fc32017-10-19 13:06:22 -0700958func (j *Module) collectBuilderFlags(ctx android.ModuleContext, deps deps) javaBuilderFlags {
Colin Crossc0b06f12015-04-08 13:03:43 -0700959
Colin Crossf03c82b2015-04-13 13:53:40 -0700960 var flags javaBuilderFlags
961
Tobias Thierer06dd04f2018-09-11 16:21:05 +0100962 // javaVersion flag.
963 flags.javaVersion = getJavaVersion(ctx, String(j.properties.Java_version), sdkContext(j))
964
Nan Zhanged19fc32017-10-19 13:06:22 -0700965 // javac flags.
Colin Crossf03c82b2015-04-13 13:53:40 -0700966 javacFlags := j.properties.Javacflags
Colin Cross1e743852019-10-28 11:37:20 -0700967 if flags.javaVersion.usesJavaModules() {
Colin Cross1369cdb2017-09-29 17:58:17 -0700968 javacFlags = append(javacFlags, j.properties.Openjdk9.Javacflags...)
Nan Zhanged19fc32017-10-19 13:06:22 -0700969 }
Colin Cross6510f912017-11-29 00:27:14 -0800970 if ctx.Config().MinimizeJavaDebugInfo() {
Colin Cross126a25c2017-10-31 13:55:34 -0700971 // Override the -g flag passed globally to remove local variable debug info to reduce
972 // disk and memory usage.
973 javacFlags = append(javacFlags, "-g:source,lines")
974 }
Colin Crossc228a702019-11-06 16:18:05 -0800975 javacFlags = append(javacFlags, "-Xlint:-dep-ann")
Colin Cross64162712017-08-08 13:17:59 -0700976
Colin Cross66548102018-06-19 22:47:35 -0700977 if ctx.Config().RunErrorProne() {
978 if config.ErrorProneClasspath == nil {
979 ctx.ModuleErrorf("cannot build with Error Prone, missing external/error_prone?")
980 }
981
982 errorProneFlags := []string{
983 "-Xplugin:ErrorProne",
984 "${config.ErrorProneChecks}",
985 }
986 errorProneFlags = append(errorProneFlags, j.properties.Errorprone.Javacflags...)
987
988 flags.errorProneExtraJavacFlags = "${config.ErrorProneFlags} " +
989 "'" + strings.Join(errorProneFlags, " ") + "'"
990 flags.errorProneProcessorPath = classpath(android.PathsForSource(ctx, config.ErrorProneClasspath))
Andreas Gampef3e5b552018-01-22 21:27:21 -0800991 }
992
Nan Zhanged19fc32017-10-19 13:06:22 -0700993 // classpath
Nan Zhang581fd212018-01-10 16:06:12 -0800994 flags.bootClasspath = append(flags.bootClasspath, deps.bootClasspath...)
995 flags.classpath = append(flags.classpath, deps.classpath...)
Colin Cross6cef4812019-10-17 14:23:50 -0700996 flags.java9Classpath = append(flags.java9Classpath, deps.java9Classpath...)
Colin Cross6a77c982018-06-19 22:43:34 -0700997 flags.processorPath = append(flags.processorPath, deps.processorPath...)
Colin Cross7fdd2b72018-01-02 18:14:25 -0800998
Colin Crossbe9cdb82019-01-21 21:37:16 -0800999 flags.processor = strings.Join(deps.processorClasses, ",")
1000
Colin Cross1e743852019-10-28 11:37:20 -07001001 if len(flags.bootClasspath) == 0 && ctx.Host() && !flags.javaVersion.usesJavaModules() &&
1002 decodeSdkDep(ctx, sdkContext(j)).hasStandardLibs() {
Colin Cross7fdd2b72018-01-02 18:14:25 -08001003 // Give host-side tools a version of OpenJDK's standard libraries
1004 // close to what they're targeting. As of Dec 2017, AOSP is only
1005 // bundling OpenJDK 8 and 9, so nothing < 8 is available.
1006 //
1007 // When building with OpenJDK 8, the following should have no
1008 // effect since those jars would be available by default.
1009 //
1010 // When building with OpenJDK 9 but targeting a version < 1.8,
1011 // putting them on the bootclasspath means that:
1012 // a) code can't (accidentally) refer to OpenJDK 9 specific APIs
1013 // b) references to existing APIs are not reinterpreted in an
1014 // OpenJDK 9-specific way, eg. calls to subclasses of
1015 // java.nio.Buffer as in http://b/70862583
1016 java8Home := ctx.Config().Getenv("ANDROID_JAVA8_HOME")
1017 flags.bootClasspath = append(flags.bootClasspath,
1018 android.PathForSource(ctx, java8Home, "jre/lib/jce.jar"),
1019 android.PathForSource(ctx, java8Home, "jre/lib/rt.jar"))
Nan Zhang5f8cb422018-02-06 10:34:32 -08001020 if Bool(j.properties.Use_tools_jar) {
1021 flags.bootClasspath = append(flags.bootClasspath,
1022 android.PathForSource(ctx, java8Home, "lib/tools.jar"))
1023 }
Colin Cross7fdd2b72018-01-02 18:14:25 -08001024 }
1025
Colin Cross1e743852019-10-28 11:37:20 -07001026 if j.properties.Patch_module != nil && flags.javaVersion.usesJavaModules() {
Jaewoong Jung38e4fb22018-12-12 09:01:34 -08001027 // Manually specify build directory in case it is not under the repo root.
1028 // (javac doesn't seem to expand into symbolc links when searching for patch-module targets, so
1029 // just adding a symlink under the root doesn't help.)
1030 patchPaths := ".:" + ctx.Config().BuildDir()
1031 classPath := flags.classpath.FormJavaClassPath("")
1032 if classPath != "" {
1033 patchPaths += ":" + classPath
1034 }
1035 javacFlags = append(javacFlags, "--patch-module="+String(j.properties.Patch_module)+"="+patchPaths)
Colin Cross81440082018-08-15 20:21:55 -07001036 }
1037
Nan Zhanged19fc32017-10-19 13:06:22 -07001038 // systemModules
Colin Crossb77043e2019-07-16 13:57:13 -07001039 flags.systemModules = deps.systemModules
Colin Cross1369cdb2017-09-29 17:58:17 -07001040
Nan Zhanged19fc32017-10-19 13:06:22 -07001041 // aidl flags.
Colin Cross3047fa22019-04-18 10:56:44 -07001042 flags.aidlFlags, flags.aidlDeps = j.aidlFlags(ctx, deps.aidlPreprocess, deps.aidlIncludeDirs)
Colin Cross2fe66872015-03-30 17:20:39 -07001043
Colin Cross81440082018-08-15 20:21:55 -07001044 if len(javacFlags) > 0 {
1045 // optimization.
1046 ctx.Variable(pctx, "javacFlags", strings.Join(javacFlags, " "))
1047 flags.javacFlags = "$javacFlags"
1048 }
1049
Nan Zhanged19fc32017-10-19 13:06:22 -07001050 return flags
1051}
Colin Crossc0b06f12015-04-08 13:03:43 -07001052
Jaewoong Junga24af3b2019-05-13 09:23:20 -07001053func (j *Module) compile(ctx android.ModuleContext, aaptSrcJar android.Path) {
Colin Crossebe1a512017-11-14 13:12:14 -08001054 j.exportAidlIncludeDirs = android.PathsForModuleSrc(ctx, j.deviceProperties.Aidl.Export_include_dirs)
Nan Zhanged19fc32017-10-19 13:06:22 -07001055
1056 deps := j.collectDeps(ctx)
1057 flags := j.collectBuilderFlags(ctx, deps)
1058
Colin Cross1e743852019-10-28 11:37:20 -07001059 if flags.javaVersion.usesJavaModules() {
Nan Zhanged19fc32017-10-19 13:06:22 -07001060 j.properties.Srcs = append(j.properties.Srcs, j.properties.Openjdk9.Srcs...)
1061 }
Colin Cross8a497952019-03-05 22:25:09 -08001062 srcFiles := android.PathsForModuleSrcExcludes(ctx, j.properties.Srcs, j.properties.Exclude_srcs)
Colin Cross6af17aa2017-09-20 12:59:05 -07001063 if hasSrcExt(srcFiles.Strings(), ".proto") {
Colin Cross0f2ee152017-12-14 15:22:43 -08001064 flags = protoFlags(ctx, &j.properties, &j.protoProperties, flags)
Colin Cross6af17aa2017-09-20 12:59:05 -07001065 }
1066
Colin Crossaf050172017-11-15 23:01:59 -08001067 srcFiles = j.genSources(ctx, srcFiles, flags)
1068
1069 srcJars := srcFiles.FilterByExt(".srcjar")
Colin Cross59149b62017-10-16 18:07:29 -07001070 srcJars = append(srcJars, deps.srcJars...)
Jaewoong Junga24af3b2019-05-13 09:23:20 -07001071 if aaptSrcJar != nil {
1072 srcJars = append(srcJars, aaptSrcJar)
1073 }
Colin Crossb7a63242015-04-16 14:09:14 -07001074
Steven Morelandc4efd9c2019-01-18 11:51:25 -08001075 if j.properties.Jarjar_rules != nil {
Colin Cross8a497952019-03-05 22:25:09 -08001076 j.expandJarjarRules = android.PathForModuleSrc(ctx, *j.properties.Jarjar_rules)
Steven Morelandc4efd9c2019-01-18 11:51:25 -08001077 }
1078
Colin Cross1ee23172017-10-18 14:44:18 -07001079 jarName := ctx.ModuleName() + ".jar"
1080
Przemyslaw Szczepaniak4b5fe9d2018-02-13 14:32:54 +00001081 javaSrcFiles := srcFiles.FilterByExt(".java")
1082 var uniqueSrcFiles android.Paths
1083 set := make(map[string]bool)
1084 for _, v := range javaSrcFiles {
1085 if _, found := set[v.String()]; !found {
1086 set[v.String()] = true
1087 uniqueSrcFiles = append(uniqueSrcFiles, v)
1088 }
1089 }
1090
patricktu242faad2019-09-24 15:41:30 +08001091 // Collect .java files for AIDEGen
1092 j.expandIDEInfoCompiledSrcs = append(j.expandIDEInfoCompiledSrcs, uniqueSrcFiles.Strings()...)
1093
Colin Cross55f63ea2018-08-27 12:37:09 -07001094 var kotlinJars android.Paths
1095
Colin Cross93e85952017-08-15 13:34:18 -07001096 if srcFiles.HasExt(".kt") {
Zoran Jovanovic8736ce22018-08-21 17:10:29 +02001097 // user defined kotlin flags.
1098 kotlincFlags := j.properties.Kotlincflags
1099 CheckKotlincFlags(ctx, kotlincFlags)
1100
Colin Cross93e85952017-08-15 13:34:18 -07001101 // If there are kotlin files, compile them first but pass all the kotlin and java files
1102 // kotlinc will use the java files to resolve types referenced by the kotlin files, but
1103 // won't emit any classes for them.
Zoran Jovanovic8736ce22018-08-21 17:10:29 +02001104 kotlincFlags = append(kotlincFlags, "-no-stdlib")
Colin Cross93e85952017-08-15 13:34:18 -07001105 if ctx.Device() {
Zoran Jovanovic8736ce22018-08-21 17:10:29 +02001106 kotlincFlags = append(kotlincFlags, "-no-jdk")
1107 }
1108 if len(kotlincFlags) > 0 {
1109 // optimization.
1110 ctx.Variable(pctx, "kotlincFlags", strings.Join(kotlincFlags, " "))
1111 flags.kotlincFlags += "$kotlincFlags"
Colin Cross93e85952017-08-15 13:34:18 -07001112 }
1113
Przemyslaw Szczepaniak4b5fe9d2018-02-13 14:32:54 +00001114 var kotlinSrcFiles android.Paths
1115 kotlinSrcFiles = append(kotlinSrcFiles, uniqueSrcFiles...)
1116 kotlinSrcFiles = append(kotlinSrcFiles, srcFiles.FilterByExt(".kt")...)
1117
patricktu242faad2019-09-24 15:41:30 +08001118 // Collect .kt files for AIDEGen
1119 j.expandIDEInfoCompiledSrcs = append(j.expandIDEInfoCompiledSrcs, srcFiles.FilterByExt(".kt").Strings()...)
1120
Colin Crossafbb1732019-01-17 15:42:52 -08001121 flags.classpath = append(flags.classpath, deps.kotlinStdlib...)
1122 flags.classpath = append(flags.classpath, deps.kotlinAnnotations...)
1123
1124 flags.kotlincClasspath = append(flags.kotlincClasspath, flags.bootClasspath...)
1125 flags.kotlincClasspath = append(flags.kotlincClasspath, flags.classpath...)
1126
1127 if len(flags.processorPath) > 0 {
1128 // Use kapt for annotation processing
1129 kaptSrcJar := android.PathForModuleOut(ctx, "kapt", "kapt-sources.jar")
1130 kotlinKapt(ctx, kaptSrcJar, kotlinSrcFiles, srcJars, flags)
1131 srcJars = append(srcJars, kaptSrcJar)
1132 // Disable annotation processing in javac, it's already been handled by kapt
1133 flags.processorPath = nil
Colin Cross3a3e94c2019-01-23 15:39:50 -08001134 flags.processor = ""
Colin Crossafbb1732019-01-17 15:42:52 -08001135 }
Colin Cross93e85952017-08-15 13:34:18 -07001136
Colin Cross1ee23172017-10-18 14:44:18 -07001137 kotlinJar := android.PathForModuleOut(ctx, "kotlin", jarName)
Colin Cross21fc9bb2019-01-18 15:05:09 -08001138 kotlinCompile(ctx, kotlinJar, kotlinSrcFiles, srcJars, flags)
Colin Cross93e85952017-08-15 13:34:18 -07001139 if ctx.Failed() {
1140 return
1141 }
1142
1143 // Make javac rule depend on the kotlinc rule
1144 flags.classpath = append(flags.classpath, kotlinJar)
Przemyslaw Szczepaniak66c0c402018-03-08 13:21:55 +00001145
Colin Cross93e85952017-08-15 13:34:18 -07001146 // Jar kotlin classes into the final jar after javac
Colin Cross55f63ea2018-08-27 12:37:09 -07001147 kotlinJars = append(kotlinJars, kotlinJar)
Colin Cross9b38aef2018-08-27 15:42:25 -07001148 kotlinJars = append(kotlinJars, deps.kotlinStdlib...)
Colin Cross93e85952017-08-15 13:34:18 -07001149 }
1150
Colin Cross55f63ea2018-08-27 12:37:09 -07001151 jars := append(android.Paths(nil), kotlinJars...)
1152
Colin Cross5ab4e6d2017-11-22 16:20:45 -08001153 // Store the list of .java files that was passed to javac
1154 j.compiledJavaSrcs = uniqueSrcFiles
1155 j.compiledSrcJars = srcJars
1156
Nan Zhang61eaedb2017-11-02 13:28:15 -07001157 enable_sharding := false
Colin Crossbe9cdb82019-01-21 21:37:16 -08001158 if ctx.Device() && !ctx.Config().IsEnvFalse("TURBINE_ENABLED") && !deps.disableTurbine {
Nan Zhang61eaedb2017-11-02 13:28:15 -07001159 if j.properties.Javac_shard_size != nil && *(j.properties.Javac_shard_size) > 0 {
1160 enable_sharding = true
Ashley Rosee36efcf2019-01-16 17:34:08 -05001161 // Formerly, there was a check here that prevented annotation processors
1162 // from being used when sharding was enabled, as some annotation processors
1163 // do not function correctly in sharded environments. It was removed to
1164 // allow for the use of annotation processors that do function correctly
1165 // with sharding enabled. See: b/77284273.
Nan Zhang61eaedb2017-11-02 13:28:15 -07001166 }
Colin Cross55f63ea2018-08-27 12:37:09 -07001167 j.headerJarFile = j.compileJavaHeader(ctx, uniqueSrcFiles, srcJars, deps, flags, jarName, kotlinJars)
Colin Crossf19b9bb2018-03-26 14:42:44 -07001168 if ctx.Failed() {
1169 return
Nan Zhanged19fc32017-10-19 13:06:22 -07001170 }
1171 }
Colin Cross8eadbf02017-10-24 17:46:00 -07001172 if len(uniqueSrcFiles) > 0 || len(srcJars) > 0 {
Colin Crossd6891432017-09-27 17:39:56 -07001173 var extraJarDeps android.Paths
Colin Cross66548102018-06-19 22:47:35 -07001174 if ctx.Config().RunErrorProne() {
Colin Crossc6bbef32017-08-14 14:16:06 -07001175 // If error-prone is enabled, add an additional rule to compile the java files into
1176 // a separate set of classes (so that they don't overwrite the normal ones and require
Colin Crossd6891432017-09-27 17:39:56 -07001177 // a rebuild when error-prone is turned off).
Colin Crossc6bbef32017-08-14 14:16:06 -07001178 // TODO(ccross): Once we always compile with javac9 we may be able to conditionally
1179 // enable error-prone without affecting the output class files.
Colin Cross1ee23172017-10-18 14:44:18 -07001180 errorprone := android.PathForModuleOut(ctx, "errorprone", jarName)
Nan Zhang61eaedb2017-11-02 13:28:15 -07001181 RunErrorProne(ctx, errorprone, uniqueSrcFiles, srcJars, flags)
Colin Crossc6bbef32017-08-14 14:16:06 -07001182 extraJarDeps = append(extraJarDeps, errorprone)
1183 }
1184
Nan Zhang61eaedb2017-11-02 13:28:15 -07001185 if enable_sharding {
Nan Zhang581fd212018-01-10 16:06:12 -08001186 flags.classpath = append(flags.classpath, j.headerJarFile)
Nan Zhang61eaedb2017-11-02 13:28:15 -07001187 shardSize := int(*(j.properties.Javac_shard_size))
1188 var shardSrcs []android.Paths
1189 if len(uniqueSrcFiles) > 0 {
Colin Cross0a2f7192019-09-23 14:33:09 -07001190 shardSrcs = android.ShardPaths(uniqueSrcFiles, shardSize)
Nan Zhang61eaedb2017-11-02 13:28:15 -07001191 for idx, shardSrc := range shardSrcs {
Colin Cross3b706fd2019-09-05 16:44:18 -07001192 classes := j.compileJavaClasses(ctx, jarName, idx, shardSrc,
1193 nil, flags, extraJarDeps)
Nan Zhang61eaedb2017-11-02 13:28:15 -07001194 jars = append(jars, classes)
1195 }
1196 }
1197 if len(srcJars) > 0 {
Colin Cross3b706fd2019-09-05 16:44:18 -07001198 classes := j.compileJavaClasses(ctx, jarName, len(shardSrcs),
1199 nil, srcJars, flags, extraJarDeps)
Nan Zhang61eaedb2017-11-02 13:28:15 -07001200 jars = append(jars, classes)
1201 }
1202 } else {
Colin Cross3b706fd2019-09-05 16:44:18 -07001203 classes := j.compileJavaClasses(ctx, jarName, -1, uniqueSrcFiles, srcJars, flags, extraJarDeps)
Nan Zhang61eaedb2017-11-02 13:28:15 -07001204 jars = append(jars, classes)
1205 }
Colin Crossd6891432017-09-27 17:39:56 -07001206 if ctx.Failed() {
1207 return
1208 }
Colin Cross2fe66872015-03-30 17:20:39 -07001209 }
1210
Colin Cross0c4ce212019-05-03 15:28:19 -07001211 j.srcJarArgs, j.srcJarDeps = resourcePathsToJarArgs(srcFiles), srcFiles
1212
1213 var includeSrcJar android.WritablePath
1214 if Bool(j.properties.Include_srcs) {
1215 includeSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+".srcjar")
1216 TransformResourcesToJar(ctx, includeSrcJar, j.srcJarArgs, j.srcJarDeps)
1217 }
1218
Colin Crosscedd4762018-09-13 11:26:19 -07001219 dirArgs, dirDeps := ResourceDirsToJarArgs(ctx, j.properties.Java_resource_dirs,
1220 j.properties.Exclude_java_resource_dirs, j.properties.Exclude_java_resources)
Colin Cross0f37af02017-09-27 17:42:05 -07001221 fileArgs, fileDeps := ResourceFilesToJarArgs(ctx, j.properties.Java_resources, j.properties.Exclude_java_resources)
Colin Cross988708c2019-05-06 14:04:11 -07001222 extraArgs, extraDeps := resourcePathsToJarArgs(j.extraResources), j.extraResources
Colin Cross0f37af02017-09-27 17:42:05 -07001223
1224 var resArgs []string
1225 var resDeps android.Paths
1226
1227 resArgs = append(resArgs, dirArgs...)
1228 resDeps = append(resDeps, dirDeps...)
1229
1230 resArgs = append(resArgs, fileArgs...)
1231 resDeps = append(resDeps, fileDeps...)
1232
Colin Cross988708c2019-05-06 14:04:11 -07001233 resArgs = append(resArgs, extraArgs...)
1234 resDeps = append(resDeps, extraDeps...)
1235
Colin Cross40a36712017-09-27 17:41:35 -07001236 if len(resArgs) > 0 {
Colin Cross1ee23172017-10-18 14:44:18 -07001237 resourceJar := android.PathForModuleOut(ctx, "res", jarName)
Colin Crosse9a275b2017-10-16 17:09:48 -07001238 TransformResourcesToJar(ctx, resourceJar, resArgs, resDeps)
Colin Cross331a1212018-08-15 20:40:52 -07001239 j.resourceJar = resourceJar
Colin Cross65bf4f22015-04-03 16:54:17 -07001240 if ctx.Failed() {
1241 return
1242 }
1243 }
1244
Colin Cross0c4ce212019-05-03 15:28:19 -07001245 var resourceJars android.Paths
1246 if j.resourceJar != nil {
1247 resourceJars = append(resourceJars, j.resourceJar)
1248 }
1249 if Bool(j.properties.Include_srcs) {
1250 resourceJars = append(resourceJars, includeSrcJar)
1251 }
1252 resourceJars = append(resourceJars, deps.staticResourceJars...)
Colin Cross331a1212018-08-15 20:40:52 -07001253
Colin Cross0c4ce212019-05-03 15:28:19 -07001254 if len(resourceJars) > 1 {
Colin Cross331a1212018-08-15 20:40:52 -07001255 combinedJar := android.PathForModuleOut(ctx, "res-combined", jarName)
Colin Cross0c4ce212019-05-03 15:28:19 -07001256 TransformJarsToJar(ctx, combinedJar, "for resources", resourceJars, android.OptionalPath{},
Colin Cross331a1212018-08-15 20:40:52 -07001257 false, nil, nil)
1258 j.resourceJar = combinedJar
Colin Cross0c4ce212019-05-03 15:28:19 -07001259 } else if len(resourceJars) == 1 {
1260 j.resourceJar = resourceJars[0]
Colin Cross331a1212018-08-15 20:40:52 -07001261 }
1262
Jaewoong Junga24af3b2019-05-13 09:23:20 -07001263 if len(deps.staticJars) > 0 {
1264 jars = append(jars, deps.staticJars...)
Jaewoong Junga24af3b2019-05-13 09:23:20 -07001265 }
Colin Cross0a6e0072017-08-30 14:24:55 -07001266
Colin Cross094054a2018-10-17 15:10:48 -07001267 manifest := j.overrideManifest
1268 if !manifest.Valid() && j.properties.Manifest != nil {
Colin Cross8a497952019-03-05 22:25:09 -08001269 manifest = android.OptionalPathForPath(android.PathForModuleSrc(ctx, *j.properties.Manifest))
Colin Cross366938f2017-12-11 16:29:02 -08001270 }
Colin Cross635acc92017-09-12 22:50:46 -07001271
Colin Cross8a497952019-03-05 22:25:09 -08001272 services := android.PathsForModuleSrc(ctx, j.properties.Services)
Alex Light7f004a72019-02-21 13:27:37 -08001273 if len(services) > 0 {
1274 servicesJar := android.PathForModuleOut(ctx, "services", jarName)
1275 var zipargs []string
1276 for _, file := range services {
1277 serviceFile := file.String()
1278 zipargs = append(zipargs, "-C", filepath.Dir(serviceFile), "-f", serviceFile)
1279 }
1280 ctx.Build(pctx, android.BuildParams{
1281 Rule: zip,
1282 Output: servicesJar,
1283 Implicits: services,
1284 Args: map[string]string{
Colin Cross0b9f31f2019-02-28 11:00:01 -08001285 "jarArgs": "-P META-INF/services/ " + strings.Join(proptools.NinjaAndShellEscapeList(zipargs), " "),
Alex Light7f004a72019-02-21 13:27:37 -08001286 },
1287 })
1288 jars = append(jars, servicesJar)
1289 }
1290
Colin Cross0a6e0072017-08-30 14:24:55 -07001291 // Combine the classes built from sources, any manifests, and any static libraries into
Nan Zhanged19fc32017-10-19 13:06:22 -07001292 // classes.jar. If there is only one input jar this step will be skipped.
Colin Cross3063b782018-08-15 11:19:12 -07001293 var outputFile android.ModuleOutPath
Colin Crosse9a275b2017-10-16 17:09:48 -07001294
1295 if len(jars) == 1 && !manifest.Valid() {
Colin Cross3063b782018-08-15 11:19:12 -07001296 if moduleOutPath, ok := jars[0].(android.ModuleOutPath); ok {
1297 // Optimization: skip the combine step if there is nothing to do
1298 // TODO(ccross): this leaves any module-info.class files, but those should only come from
1299 // prebuilt dependencies until we support modules in the platform build, so there shouldn't be
1300 // any if len(jars) == 1.
1301 outputFile = moduleOutPath
1302 } else {
1303 combinedJar := android.PathForModuleOut(ctx, "combined", jarName)
1304 ctx.Build(pctx, android.BuildParams{
1305 Rule: android.Cp,
1306 Input: jars[0],
1307 Output: combinedJar,
1308 })
1309 outputFile = combinedJar
1310 }
Colin Crosse9a275b2017-10-16 17:09:48 -07001311 } else {
Colin Cross1ee23172017-10-18 14:44:18 -07001312 combinedJar := android.PathForModuleOut(ctx, "combined", jarName)
Colin Cross37f6d792018-07-12 12:28:41 -07001313 TransformJarsToJar(ctx, combinedJar, "for javac", jars, manifest,
Colin Cross9b38aef2018-08-27 15:42:25 -07001314 false, nil, nil)
Colin Crosse9a275b2017-10-16 17:09:48 -07001315 outputFile = combinedJar
1316 }
Colin Cross0a6e0072017-08-30 14:24:55 -07001317
Colin Cross331a1212018-08-15 20:40:52 -07001318 // jarjar implementation jar if necessary
Steven Morelandc4efd9c2019-01-18 11:51:25 -08001319 if j.expandJarjarRules != nil {
Colin Cross8649b262017-09-27 18:03:17 -07001320 // Transform classes.jar into classes-jarjar.jar
Colin Cross1ee23172017-10-18 14:44:18 -07001321 jarjarFile := android.PathForModuleOut(ctx, "jarjar", jarName)
Steven Morelandc4efd9c2019-01-18 11:51:25 -08001322 TransformJarJar(ctx, jarjarFile, outputFile, j.expandJarjarRules)
Colin Crosse9a275b2017-10-16 17:09:48 -07001323 outputFile = jarjarFile
Colin Cross331a1212018-08-15 20:40:52 -07001324
1325 // jarjar resource jar if necessary
1326 if j.resourceJar != nil {
1327 resourceJarJarFile := android.PathForModuleOut(ctx, "res-jarjar", jarName)
Steven Morelandc4efd9c2019-01-18 11:51:25 -08001328 TransformJarJar(ctx, resourceJarJarFile, j.resourceJar, j.expandJarjarRules)
Colin Cross331a1212018-08-15 20:40:52 -07001329 j.resourceJar = resourceJarJarFile
1330 }
1331
Colin Cross0a6e0072017-08-30 14:24:55 -07001332 if ctx.Failed() {
1333 return
1334 }
1335 }
Vladimir Marko0975ee02019-04-02 10:29:55 +01001336
1337 // Check package restrictions if necessary.
1338 if len(j.properties.Permitted_packages) > 0 {
1339 // Check packages and copy to package-checked file.
1340 pkgckFile := android.PathForModuleOut(ctx, "package-check.stamp")
1341 CheckJarPackages(ctx, pkgckFile, outputFile, j.properties.Permitted_packages)
1342 j.additionalCheckedModules = append(j.additionalCheckedModules, pkgckFile)
1343
1344 if ctx.Failed() {
1345 return
1346 }
1347 }
1348
Nan Zhanged19fc32017-10-19 13:06:22 -07001349 j.implementationJarFile = outputFile
1350 if j.headerJarFile == nil {
1351 j.headerJarFile = j.implementationJarFile
1352 }
Colin Cross2fe66872015-03-30 17:20:39 -07001353
Colin Cross6510f912017-11-29 00:27:14 -08001354 if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
Colin Crosscb933592017-11-22 13:49:43 -08001355 if inList(ctx.ModuleName(), config.InstrumentFrameworkModules) {
1356 j.properties.Instrument = true
1357 }
1358 }
1359
Colin Cross3144dfc2018-01-03 15:06:47 -08001360 if j.shouldInstrument(ctx) {
Colin Crosscb933592017-11-22 13:49:43 -08001361 outputFile = j.instrument(ctx, flags, outputFile, jarName)
1362 }
1363
Colin Cross331a1212018-08-15 20:40:52 -07001364 // merge implementation jar with resources if necessary
1365 implementationAndResourcesJar := outputFile
1366 if j.resourceJar != nil {
Colin Cross08a409d2019-04-29 10:22:44 -07001367 jars := android.Paths{j.resourceJar, implementationAndResourcesJar}
Colin Cross331a1212018-08-15 20:40:52 -07001368 combinedJar := android.PathForModuleOut(ctx, "withres", jarName)
Colin Cross08a409d2019-04-29 10:22:44 -07001369 TransformJarsToJar(ctx, combinedJar, "for resources", jars, manifest,
Colin Cross331a1212018-08-15 20:40:52 -07001370 false, nil, nil)
1371 implementationAndResourcesJar = combinedJar
1372 }
1373
1374 j.implementationAndResourcesJar = implementationAndResourcesJar
1375
Jaewoong Jungc27ab662019-05-30 15:51:14 -07001376 if ctx.Device() && j.hasCode(ctx) &&
Jaewoong Junga24af3b2019-05-13 09:23:20 -07001377 (Bool(j.properties.Installable) || Bool(j.deviceProperties.Compile_dex)) {
Colin Cross8faf8fc2019-01-16 15:15:52 -08001378 // Dex compilation
Colin Cross3063b782018-08-15 11:19:12 -07001379 var dexOutputFile android.ModuleOutPath
David Brazdil17ef5632018-06-27 10:27:45 +01001380 dexOutputFile = j.compileDex(ctx, flags, outputFile, jarName)
Colin Cross2fe66872015-03-30 17:20:39 -07001381 if ctx.Failed() {
1382 return
1383 }
Colin Cross331a1212018-08-15 20:40:52 -07001384
Jiyong Park09cb6292019-07-15 15:29:23 +09001385 // Hidden API CSV generation and dex encoding
1386 dexOutputFile = j.hiddenAPI.hiddenAPI(ctx, dexOutputFile, j.implementationJarFile,
1387 j.deviceProperties.UncompressDex)
Colin Cross8faf8fc2019-01-16 15:15:52 -08001388
Colin Cross331a1212018-08-15 20:40:52 -07001389 // merge dex jar with resources if necessary
1390 if j.resourceJar != nil {
1391 jars := android.Paths{dexOutputFile, j.resourceJar}
1392 combinedJar := android.PathForModuleOut(ctx, "dex-withres", jarName)
1393 TransformJarsToJar(ctx, combinedJar, "for dex resources", jars, android.OptionalPath{},
1394 false, nil, nil)
Nicolas Geoffrayf3438722019-01-23 15:57:21 +00001395 if j.deviceProperties.UncompressDex {
1396 combinedAlignedJar := android.PathForModuleOut(ctx, "dex-withres-aligned", jarName)
1397 TransformZipAlign(ctx, combinedAlignedJar, combinedJar)
1398 dexOutputFile = combinedAlignedJar
1399 } else {
1400 dexOutputFile = combinedJar
1401 }
Colin Cross331a1212018-08-15 20:40:52 -07001402 }
1403
1404 j.dexJarFile = dexOutputFile
1405
Colin Cross8faf8fc2019-01-16 15:15:52 -08001406 // Dexpreopting
Colin Cross43f08db2018-11-12 10:13:39 -08001407 dexOutputFile = j.dexpreopt(ctx, dexOutputFile)
1408
1409 j.maybeStrippedDexJarFile = dexOutputFile
1410
Colin Cross3063b782018-08-15 11:19:12 -07001411 outputFile = dexOutputFile
Colin Cross43f08db2018-11-12 10:13:39 -08001412
1413 if ctx.Failed() {
1414 return
1415 }
Colin Cross331a1212018-08-15 20:40:52 -07001416 } else {
1417 outputFile = implementationAndResourcesJar
Colin Cross2fe66872015-03-30 17:20:39 -07001418 }
Colin Cross331a1212018-08-15 20:40:52 -07001419
Colin Crossb7a63242015-04-16 14:09:14 -07001420 ctx.CheckbuildFile(outputFile)
Colin Cross3063b782018-08-15 11:19:12 -07001421
1422 // Save the output file with no relative path so that it doesn't end up in a subdirectory when used as a resource
1423 j.outputFile = outputFile.WithoutRel()
Colin Cross2fe66872015-03-30 17:20:39 -07001424}
1425
Colin Cross3b706fd2019-09-05 16:44:18 -07001426func (j *Module) compileJavaClasses(ctx android.ModuleContext, jarName string, idx int,
1427 srcFiles, srcJars android.Paths, flags javaBuilderFlags, extraJarDeps android.Paths) android.WritablePath {
1428
1429 kzipName := pathtools.ReplaceExtension(jarName, "kzip")
1430 if idx >= 0 {
1431 kzipName = strings.TrimSuffix(jarName, filepath.Ext(jarName)) + strconv.Itoa(idx) + ".kzip"
1432 jarName += strconv.Itoa(idx)
1433 }
1434
1435 classes := android.PathForModuleOut(ctx, "javac", jarName)
1436 TransformJavaToClasses(ctx, classes, idx, srcFiles, srcJars, flags, extraJarDeps)
1437
1438 if ctx.Config().EmitXrefRules() {
1439 extractionFile := android.PathForModuleOut(ctx, kzipName)
1440 emitXrefRule(ctx, extractionFile, idx, srcFiles, srcJars, flags, extraJarDeps)
1441 j.kytheFiles = append(j.kytheFiles, extractionFile)
1442 }
1443
1444 return classes
1445}
1446
Zoran Jovanovic8736ce22018-08-21 17:10:29 +02001447// Check for invalid kotlinc flags. Only use this for flags explicitly passed by the user,
1448// since some of these flags may be used internally.
1449func CheckKotlincFlags(ctx android.ModuleContext, flags []string) {
1450 for _, flag := range flags {
1451 flag = strings.TrimSpace(flag)
1452
1453 if !strings.HasPrefix(flag, "-") {
1454 ctx.PropertyErrorf("kotlincflags", "Flag `%s` must start with `-`", flag)
1455 } else if strings.HasPrefix(flag, "-Xintellij-plugin-root") {
1456 ctx.PropertyErrorf("kotlincflags",
1457 "Bad flag: `%s`, only use internal compiler for consistency.", flag)
1458 } else if inList(flag, config.KotlincIllegalFlags) {
1459 ctx.PropertyErrorf("kotlincflags", "Flag `%s` already used by build system", flag)
1460 } else if flag == "-include-runtime" {
1461 ctx.PropertyErrorf("kotlincflags", "Bad flag: `%s`, do not include runtime.", flag)
1462 } else {
1463 args := strings.Split(flag, " ")
1464 if args[0] == "-kotlin-home" {
1465 ctx.PropertyErrorf("kotlincflags",
1466 "Bad flag: `%s`, kotlin home already set to default (path to kotlinc in the repo).", flag)
1467 }
1468 }
1469 }
1470}
1471
Colin Cross8eadbf02017-10-24 17:46:00 -07001472func (j *Module) compileJavaHeader(ctx android.ModuleContext, srcFiles, srcJars android.Paths,
Colin Cross55f63ea2018-08-27 12:37:09 -07001473 deps deps, flags javaBuilderFlags, jarName string, extraJars android.Paths) android.Path {
Nan Zhanged19fc32017-10-19 13:06:22 -07001474
1475 var jars android.Paths
Colin Cross8eadbf02017-10-24 17:46:00 -07001476 if len(srcFiles) > 0 || len(srcJars) > 0 {
Nan Zhanged19fc32017-10-19 13:06:22 -07001477 // Compile java sources into turbine.jar.
1478 turbineJar := android.PathForModuleOut(ctx, "turbine", jarName)
1479 TransformJavaToHeaderClasses(ctx, turbineJar, srcFiles, srcJars, flags)
1480 if ctx.Failed() {
1481 return nil
1482 }
1483 jars = append(jars, turbineJar)
1484 }
1485
Colin Cross55f63ea2018-08-27 12:37:09 -07001486 jars = append(jars, extraJars...)
1487
Nan Zhanged19fc32017-10-19 13:06:22 -07001488 // Combine any static header libraries into classes-header.jar. If there is only
1489 // one input jar this step will be skipped.
1490 var headerJar android.Path
1491 jars = append(jars, deps.staticHeaderJars...)
1492
Colin Cross5c6ecc12017-10-23 18:12:27 -07001493 // we cannot skip the combine step for now if there is only one jar
1494 // since we have to strip META-INF/TRANSITIVE dir from turbine.jar
1495 combinedJar := android.PathForModuleOut(ctx, "turbine-combined", jarName)
Colin Cross37f6d792018-07-12 12:28:41 -07001496 TransformJarsToJar(ctx, combinedJar, "for turbine", jars, android.OptionalPath{},
Colin Cross6c6e6cd2019-05-08 14:30:12 -07001497 false, nil, []string{"META-INF/TRANSITIVE"})
Colin Cross5c6ecc12017-10-23 18:12:27 -07001498 headerJar = combinedJar
Nan Zhanged19fc32017-10-19 13:06:22 -07001499
Steven Morelandc4efd9c2019-01-18 11:51:25 -08001500 if j.expandJarjarRules != nil {
Nan Zhanged19fc32017-10-19 13:06:22 -07001501 // Transform classes.jar into classes-jarjar.jar
1502 jarjarFile := android.PathForModuleOut(ctx, "turbine-jarjar", jarName)
Steven Morelandc4efd9c2019-01-18 11:51:25 -08001503 TransformJarJar(ctx, jarjarFile, headerJar, j.expandJarjarRules)
Nan Zhanged19fc32017-10-19 13:06:22 -07001504 headerJar = jarjarFile
1505 if ctx.Failed() {
1506 return nil
1507 }
1508 }
1509
1510 return headerJar
1511}
1512
Colin Crosscb933592017-11-22 13:49:43 -08001513func (j *Module) instrument(ctx android.ModuleContext, flags javaBuilderFlags,
Colin Cross3063b782018-08-15 11:19:12 -07001514 classesJar android.Path, jarName string) android.ModuleOutPath {
Colin Crosscb933592017-11-22 13:49:43 -08001515
Colin Cross7a3139e2017-12-19 13:57:50 -08001516 specs := j.jacocoModuleToZipCommand(ctx)
Colin Crosscb933592017-11-22 13:49:43 -08001517
Colin Cross84c38822018-01-03 15:59:46 -08001518 jacocoReportClassesFile := android.PathForModuleOut(ctx, "jacoco-report-classes", jarName)
Colin Crosscb933592017-11-22 13:49:43 -08001519 instrumentedJar := android.PathForModuleOut(ctx, "jacoco", jarName)
1520
1521 jacocoInstrumentJar(ctx, instrumentedJar, jacocoReportClassesFile, classesJar, specs)
1522
1523 j.jacocoReportClassesFile = jacocoReportClassesFile
1524
1525 return instrumentedJar
1526}
1527
albaltai36ff7dc2018-12-25 14:35:23 +08001528var _ Dependency = (*Module)(nil)
Colin Cross2fe66872015-03-30 17:20:39 -07001529
Nan Zhanged19fc32017-10-19 13:06:22 -07001530func (j *Module) HeaderJars() android.Paths {
albaltai36ff7dc2018-12-25 14:35:23 +08001531 if j.headerJarFile == nil {
1532 return nil
1533 }
Nan Zhanged19fc32017-10-19 13:06:22 -07001534 return android.Paths{j.headerJarFile}
1535}
1536
1537func (j *Module) ImplementationJars() android.Paths {
shinwang9e4c07a2018-12-24 15:41:04 +08001538 if j.implementationJarFile == nil {
1539 return nil
1540 }
Nan Zhanged19fc32017-10-19 13:06:22 -07001541 return android.Paths{j.implementationJarFile}
Colin Cross2fe66872015-03-30 17:20:39 -07001542}
1543
Colin Crossf24a22a2019-01-31 14:12:44 -08001544func (j *Module) DexJar() android.Path {
1545 return j.dexJarFile
1546}
1547
Colin Cross331a1212018-08-15 20:40:52 -07001548func (j *Module) ResourceJars() android.Paths {
1549 if j.resourceJar == nil {
1550 return nil
1551 }
1552 return android.Paths{j.resourceJar}
1553}
1554
1555func (j *Module) ImplementationAndResourcesJars() android.Paths {
albaltai36ff7dc2018-12-25 14:35:23 +08001556 if j.implementationAndResourcesJar == nil {
1557 return nil
1558 }
Colin Cross331a1212018-08-15 20:40:52 -07001559 return android.Paths{j.implementationAndResourcesJar}
1560}
1561
Colin Cross46c9b8b2017-06-22 16:51:17 -07001562func (j *Module) AidlIncludeDirs() android.Paths {
albaltai36ff7dc2018-12-25 14:35:23 +08001563 // exportAidlIncludeDirs is type android.Paths already
Colin Crossc0b06f12015-04-08 13:03:43 -07001564 return j.exportAidlIncludeDirs
1565}
1566
Jiyong Park1be96912018-05-28 18:02:19 +09001567func (j *Module) ExportedSdkLibs() []string {
albaltai36ff7dc2018-12-25 14:35:23 +08001568 // exportedSdkLibs is type []string
Jiyong Park1be96912018-05-28 18:02:19 +09001569 return j.exportedSdkLibs
1570}
1571
Colin Cross0c4ce212019-05-03 15:28:19 -07001572func (j *Module) SrcJarArgs() ([]string, android.Paths) {
1573 return j.srcJarArgs, j.srcJarDeps
1574}
1575
Colin Cross46c9b8b2017-06-22 16:51:17 -07001576var _ logtagsProducer = (*Module)(nil)
Colin Crossf05fe972015-04-10 17:45:20 -07001577
Colin Cross46c9b8b2017-06-22 16:51:17 -07001578func (j *Module) logtags() android.Paths {
Colin Crossf05fe972015-04-10 17:45:20 -07001579 return j.logtagsSrcs
1580}
1581
Brandon Lee5d45c6f2018-08-15 15:35:38 -07001582// Collect information for opening IDE project files in java/jdeps.go.
1583func (j *Module) IDEInfo(dpInfo *android.IdeInfo) {
1584 dpInfo.Deps = append(dpInfo.Deps, j.CompilerDeps()...)
1585 dpInfo.Srcs = append(dpInfo.Srcs, j.expandIDEInfoCompiledSrcs...)
patricktu18c82ff2019-05-10 15:48:50 +08001586 dpInfo.SrcJars = append(dpInfo.SrcJars, j.compiledSrcJars.Strings()...)
Brandon Lee5d45c6f2018-08-15 15:35:38 -07001587 dpInfo.Aidl_include_dirs = append(dpInfo.Aidl_include_dirs, j.deviceProperties.Aidl.Include_dirs...)
Steven Morelandc4efd9c2019-01-18 11:51:25 -08001588 if j.expandJarjarRules != nil {
1589 dpInfo.Jarjar_rules = append(dpInfo.Jarjar_rules, j.expandJarjarRules.String())
Brandon Lee5d45c6f2018-08-15 15:35:38 -07001590 }
1591}
1592
1593func (j *Module) CompilerDeps() []string {
1594 jdeps := []string{}
1595 jdeps = append(jdeps, j.properties.Libs...)
1596 jdeps = append(jdeps, j.properties.Static_libs...)
1597 return jdeps
1598}
1599
Jaewoong Jungc27ab662019-05-30 15:51:14 -07001600func (j *Module) hasCode(ctx android.ModuleContext) bool {
1601 srcFiles := android.PathsForModuleSrcExcludes(ctx, j.properties.Srcs, j.properties.Exclude_srcs)
1602 return len(srcFiles) > 0 || len(ctx.GetDirectDepsWithTag(staticLibTag)) > 0
1603}
1604
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09001605func (j *Module) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
1606 depTag := ctx.OtherModuleDependencyTag(dep)
1607 // dependencies other than the static linkage are all considered crossing APEX boundary
1608 return depTag == staticLibTag
1609}
1610
Jiyong Park0b238752019-10-29 11:23:10 +09001611func (j *Module) Stem() string {
1612 return proptools.StringDefault(j.deviceProperties.Stem, j.Name())
1613}
1614
Colin Cross2fe66872015-03-30 17:20:39 -07001615//
1616// Java libraries (.jar file)
1617//
1618
Colin Crossf506d872017-07-19 15:53:04 -07001619type Library struct {
Colin Cross46c9b8b2017-06-22 16:51:17 -07001620 Module
Colin Crossf0f2e2c2019-10-15 16:36:40 -07001621
1622 InstallMixin func(ctx android.ModuleContext, installPath android.Path) (extraInstallDeps android.Paths)
Colin Cross2fe66872015-03-30 17:20:39 -07001623}
1624
Colin Cross42be7612019-02-21 18:12:14 -08001625func shouldUncompressDex(ctx android.ModuleContext, dexpreopter *dexpreopter) bool {
Nicolas Geoffrayfa6e9ec2019-02-12 13:12:16 +00001626 // Store uncompressed (and do not strip) dex files from boot class path jars.
1627 if inList(ctx.ModuleName(), ctx.Config().BootJars()) {
1628 return true
1629 }
1630
1631 // Store uncompressed dex files that are preopted on /system.
Colin Cross42be7612019-02-21 18:12:14 -08001632 if !dexpreopter.dexpreoptDisabled(ctx) && (ctx.Host() || !odexOnSystemOther(ctx, dexpreopter.installPath)) {
Vladimir Markoe8b00d62018-12-21 15:54:16 +00001633 return true
1634 }
Colin Cross083a2aa2019-02-06 16:37:12 -08001635 if ctx.Config().UncompressPrivAppDex() &&
1636 inList(ctx.ModuleName(), ctx.Config().ModulesLoadedByPrivilegedModules()) {
1637 return true
1638 }
1639
Colin Cross2fc72f62018-12-21 12:59:54 -08001640 return false
1641}
1642
Colin Crossf506d872017-07-19 15:53:04 -07001643func (j *Library) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Jeongik Cha2cc570d2019-10-29 15:44:45 +09001644 j.checkSdkVersion(ctx)
Jiyong Park0b238752019-10-29 11:23:10 +09001645 j.dexpreopter.installPath = android.PathForModuleInstall(ctx, "framework", j.Stem()+".jar")
Colin Cross43f08db2018-11-12 10:13:39 -08001646 j.dexpreopter.isSDKLibrary = j.deviceProperties.IsSDKLibrary
Nicolas Geoffrayfa6e9ec2019-02-12 13:12:16 +00001647 j.dexpreopter.isInstallable = Bool(j.properties.Installable)
Colin Cross42be7612019-02-21 18:12:14 -08001648 j.dexpreopter.uncompressedDex = shouldUncompressDex(ctx, &j.dexpreopter)
Nicolas Geoffrayfa6e9ec2019-02-12 13:12:16 +00001649 j.deviceProperties.UncompressDex = j.dexpreopter.uncompressedDex
Jaewoong Junga24af3b2019-05-13 09:23:20 -07001650 j.compile(ctx, nil)
Colin Crossb7a63242015-04-16 14:09:14 -07001651
Jiyong Park7f7766d2019-07-25 22:02:35 +09001652 exclusivelyForApex := android.InAnyApex(ctx.ModuleName()) && !j.IsForPlatform()
1653 if (Bool(j.properties.Installable) || ctx.Host()) && !exclusivelyForApex {
Colin Crossf0f2e2c2019-10-15 16:36:40 -07001654 var extraInstallDeps android.Paths
1655 if j.InstallMixin != nil {
1656 extraInstallDeps = j.InstallMixin(ctx, j.outputFile)
1657 }
Colin Cross2c429dc2017-08-31 16:45:16 -07001658 j.installFile = ctx.InstallFile(android.PathForModuleInstall(ctx, "framework"),
Colin Crossf0f2e2c2019-10-15 16:36:40 -07001659 ctx.ModuleName()+".jar", j.outputFile, extraInstallDeps...)
Colin Cross2c429dc2017-08-31 16:45:16 -07001660 }
Colin Crossb7a63242015-04-16 14:09:14 -07001661}
1662
Colin Crossf506d872017-07-19 15:53:04 -07001663func (j *Library) DepsMutator(ctx android.BottomUpMutatorContext) {
Colin Cross46c9b8b2017-06-22 16:51:17 -07001664 j.deps(ctx)
1665}
1666
Colin Cross1b16b0e2019-02-12 14:41:32 -08001667// java_library builds and links sources into a `.jar` file for the device, and possibly for the host as well.
1668//
1669// By default, a java_library has a single variant that produces a `.jar` file containing `.class` files that were
1670// compiled against the device bootclasspath. This jar is not suitable for installing on a device, but can be used
1671// as a `static_libs` dependency of another module.
1672//
1673// Specifying `installable: true` will product a `.jar` file containing `classes.dex` files, suitable for installing on
1674// a device.
1675//
1676// Specifying `host_supported: true` will produce two variants, one compiled against the device bootclasspath and one
1677// compiled against the host bootclasspath.
Colin Cross9ae1b922018-06-26 17:59:05 -07001678func LibraryFactory() android.Module {
1679 module := &Library{}
Colin Cross2fe66872015-03-30 17:20:39 -07001680
Colin Cross9ae1b922018-06-26 17:59:05 -07001681 module.AddProperties(
1682 &module.Module.properties,
1683 &module.Module.deviceProperties,
Colin Cross43f08db2018-11-12 10:13:39 -08001684 &module.Module.dexpreoptProperties,
Colin Cross9ae1b922018-06-26 17:59:05 -07001685 &module.Module.protoProperties)
Colin Cross2fe66872015-03-30 17:20:39 -07001686
Jiyong Park7f7766d2019-07-25 22:02:35 +09001687 android.InitApexModule(module)
Jiyong Parkd1063c12019-07-17 20:08:41 +09001688 android.InitSdkAwareModule(module)
Jooyung Han18020ea2019-11-13 10:50:48 +09001689 InitJavaModule(module, android.HostAndDeviceSupported)
Colin Cross9ae1b922018-06-26 17:59:05 -07001690 return module
Colin Cross2fe66872015-03-30 17:20:39 -07001691}
1692
Colin Cross1b16b0e2019-02-12 14:41:32 -08001693// java_library_static is an obsolete alias for java_library.
1694func LibraryStaticFactory() android.Module {
1695 return LibraryFactory()
1696}
1697
1698// java_library_host builds and links sources into a `.jar` file for the host.
1699//
1700// A java_library_host has a single variant that produces a `.jar` file containing `.class` files that were
1701// compiled against the host bootclasspath.
Colin Crossf506d872017-07-19 15:53:04 -07001702func LibraryHostFactory() android.Module {
1703 module := &Library{}
Colin Cross2fe66872015-03-30 17:20:39 -07001704
Colin Cross6af17aa2017-09-20 12:59:05 -07001705 module.AddProperties(
1706 &module.Module.properties,
1707 &module.Module.protoProperties)
Colin Cross36242852017-06-23 15:06:31 -07001708
Colin Cross9ae1b922018-06-26 17:59:05 -07001709 module.Module.properties.Installable = proptools.BoolPtr(true)
1710
Jiyong Park7f7766d2019-07-25 22:02:35 +09001711 android.InitApexModule(module)
Jooyung Han18020ea2019-11-13 10:50:48 +09001712 InitJavaModule(module, android.HostSupported)
Colin Cross36242852017-06-23 15:06:31 -07001713 return module
Colin Cross2fe66872015-03-30 17:20:39 -07001714}
1715
1716//
Colin Crossb628ea52018-08-14 16:42:33 -07001717// Java Tests
Colin Cross05638fc2018-04-09 18:40:24 -07001718//
1719
1720type testProperties struct {
Colin Cross05638fc2018-04-09 18:40:24 -07001721 // list of compatibility suites (for example "cts", "vts") that the module should be
1722 // installed into.
1723 Test_suites []string `android:"arch_variant"`
Julien Despreze146e392018-08-02 15:00:46 -07001724
1725 // the name of the test configuration (for example "AndroidTest.xml") that should be
1726 // installed with the module.
Colin Cross27b922f2019-03-04 22:35:41 -08001727 Test_config *string `android:"path,arch_variant"`
Colin Crossd96ca352018-08-10 16:06:24 -07001728
Jack He33338892018-09-19 02:21:28 -07001729 // the name of the test configuration template (for example "AndroidTestTemplate.xml") that
1730 // should be installed with the module.
Colin Cross27b922f2019-03-04 22:35:41 -08001731 Test_config_template *string `android:"path,arch_variant"`
Jack He33338892018-09-19 02:21:28 -07001732
Colin Crossd96ca352018-08-10 16:06:24 -07001733 // list of files or filegroup modules that provide data that should be installed alongside
1734 // the test
Colin Cross27b922f2019-03-04 22:35:41 -08001735 Data []string `android:"path"`
Dan Shi6ffaaa82019-09-26 11:41:36 -07001736
1737 // Flag to indicate whether or not to create test config automatically. If AndroidTest.xml
1738 // doesn't exist next to the Android.bp, this attribute doesn't need to be set to true
1739 // explicitly.
1740 Auto_gen_config *bool
Colin Cross05638fc2018-04-09 18:40:24 -07001741}
1742
Paul Duffin42df1442019-03-20 12:45:53 +00001743type testHelperLibraryProperties struct {
1744 // list of compatibility suites (for example "cts", "vts") that the module should be
1745 // installed into.
1746 Test_suites []string `android:"arch_variant"`
1747}
1748
Colin Cross05638fc2018-04-09 18:40:24 -07001749type Test struct {
1750 Library
1751
1752 testProperties testProperties
Colin Cross303e21f2018-08-07 16:49:25 -07001753
1754 testConfig android.Path
Colin Crossd96ca352018-08-10 16:06:24 -07001755 data android.Paths
Colin Cross303e21f2018-08-07 16:49:25 -07001756}
1757
Paul Duffin42df1442019-03-20 12:45:53 +00001758type TestHelperLibrary struct {
1759 Library
1760
1761 testHelperLibraryProperties testHelperLibraryProperties
1762}
1763
Colin Cross303e21f2018-08-07 16:49:25 -07001764func (j *Test) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Dan Shi6ffaaa82019-09-26 11:41:36 -07001765 j.testConfig = tradefed.AutoGenJavaTestConfig(ctx, j.testProperties.Test_config, j.testProperties.Test_config_template,
1766 j.testProperties.Test_suites, j.testProperties.Auto_gen_config)
Colin Cross8a497952019-03-05 22:25:09 -08001767 j.data = android.PathsForModuleSrc(ctx, j.testProperties.Data)
Colin Cross303e21f2018-08-07 16:49:25 -07001768
1769 j.Library.GenerateAndroidBuildActions(ctx)
Colin Cross05638fc2018-04-09 18:40:24 -07001770}
1771
Paul Duffin42df1442019-03-20 12:45:53 +00001772func (j *TestHelperLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1773 j.Library.GenerateAndroidBuildActions(ctx)
1774}
1775
Colin Cross1b16b0e2019-02-12 14:41:32 -08001776// java_test builds a and links sources into a `.jar` file for the device, and possibly for the host as well, and
1777// creates an `AndroidTest.xml` file to allow running the test with `atest` or a `TEST_MAPPING` file.
1778//
1779// By default, a java_test has a single variant that produces a `.jar` file containing `classes.dex` files that were
1780// compiled against the device bootclasspath.
1781//
1782// Specifying `host_supported: true` will produce two variants, one compiled against the device bootclasspath and one
1783// compiled against the host bootclasspath.
Colin Cross05638fc2018-04-09 18:40:24 -07001784func TestFactory() android.Module {
1785 module := &Test{}
1786
1787 module.AddProperties(
1788 &module.Module.properties,
1789 &module.Module.deviceProperties,
Colin Cross43f08db2018-11-12 10:13:39 -08001790 &module.Module.dexpreoptProperties,
Colin Cross05638fc2018-04-09 18:40:24 -07001791 &module.Module.protoProperties,
1792 &module.testProperties)
1793
Colin Cross9ae1b922018-06-26 17:59:05 -07001794 module.Module.properties.Installable = proptools.BoolPtr(true)
Colin Crosse3026872019-01-05 22:30:13 -08001795 module.Module.dexpreopter.isTest = true
Colin Cross9ae1b922018-06-26 17:59:05 -07001796
Colin Cross05638fc2018-04-09 18:40:24 -07001797 InitJavaModule(module, android.HostAndDeviceSupported)
Colin Cross05638fc2018-04-09 18:40:24 -07001798 return module
1799}
1800
Paul Duffin42df1442019-03-20 12:45:53 +00001801// java_test_helper_library creates a java library and makes sure that it is added to the appropriate test suite.
1802func TestHelperLibraryFactory() android.Module {
1803 module := &TestHelperLibrary{}
1804
1805 module.AddProperties(
1806 &module.Module.properties,
1807 &module.Module.deviceProperties,
1808 &module.Module.dexpreoptProperties,
1809 &module.Module.protoProperties,
1810 &module.testHelperLibraryProperties)
1811
Colin Cross9a4abed2019-04-24 13:19:28 -07001812 module.Module.properties.Installable = proptools.BoolPtr(true)
1813 module.Module.dexpreopter.isTest = true
1814
Paul Duffin42df1442019-03-20 12:45:53 +00001815 InitJavaModule(module, android.HostAndDeviceSupported)
1816 return module
1817}
1818
Colin Cross1b16b0e2019-02-12 14:41:32 -08001819// java_test_host builds a and links sources into a `.jar` file for the host, and creates an `AndroidTest.xml` file to
1820// allow running the test with `atest` or a `TEST_MAPPING` file.
1821//
1822// A java_test_host has a single variant that produces a `.jar` file containing `.class` files that were
1823// compiled against the host bootclasspath.
Colin Cross05638fc2018-04-09 18:40:24 -07001824func TestHostFactory() android.Module {
1825 module := &Test{}
1826
1827 module.AddProperties(
1828 &module.Module.properties,
1829 &module.Module.protoProperties,
1830 &module.testProperties)
1831
Colin Cross9ae1b922018-06-26 17:59:05 -07001832 module.Module.properties.Installable = proptools.BoolPtr(true)
1833
Colin Cross05638fc2018-04-09 18:40:24 -07001834 InitJavaModule(module, android.HostSupported)
Colin Cross05638fc2018-04-09 18:40:24 -07001835 return module
1836}
1837
1838//
Colin Cross2fe66872015-03-30 17:20:39 -07001839// Java Binaries (.jar file plus wrapper script)
1840//
1841
Colin Crossf506d872017-07-19 15:53:04 -07001842type binaryProperties struct {
Colin Cross7d5136f2015-05-11 13:39:40 -07001843 // installable script to execute the resulting jar
Colin Cross27b922f2019-03-04 22:35:41 -08001844 Wrapper *string `android:"path"`
Colin Cross094054a2018-10-17 15:10:48 -07001845
1846 // Name of the class containing main to be inserted into the manifest as Main-Class.
1847 Main_class *string
Colin Cross7d5136f2015-05-11 13:39:40 -07001848}
1849
Colin Crossf506d872017-07-19 15:53:04 -07001850type Binary struct {
1851 Library
Colin Cross2fe66872015-03-30 17:20:39 -07001852
Colin Crossf506d872017-07-19 15:53:04 -07001853 binaryProperties binaryProperties
Colin Cross10a03492017-08-10 17:09:43 -07001854
Colin Cross6b4a32d2017-12-05 13:42:45 -08001855 isWrapperVariant bool
1856
Colin Crossc3315992017-12-08 19:12:36 -08001857 wrapperFile android.Path
Colin Cross70dda7e2019-10-01 22:05:35 -07001858 binaryFile android.InstallPath
Colin Cross2fe66872015-03-30 17:20:39 -07001859}
1860
Alex Light24237172017-10-26 09:46:21 -07001861func (j *Binary) HostToolPath() android.OptionalPath {
1862 return android.OptionalPathForPath(j.binaryFile)
1863}
1864
Colin Crossf506d872017-07-19 15:53:04 -07001865func (j *Binary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross6b4a32d2017-12-05 13:42:45 -08001866 if ctx.Arch().ArchType == android.Common {
1867 // Compile the jar
Colin Cross094054a2018-10-17 15:10:48 -07001868 if j.binaryProperties.Main_class != nil {
1869 if j.properties.Manifest != nil {
1870 ctx.PropertyErrorf("main_class", "main_class cannot be used when manifest is set")
1871 }
1872 manifestFile := android.PathForModuleOut(ctx, "manifest.txt")
1873 GenerateMainClassManifest(ctx, manifestFile, String(j.binaryProperties.Main_class))
1874 j.overrideManifest = android.OptionalPathForPath(manifestFile)
1875 }
1876
Colin Cross6b4a32d2017-12-05 13:42:45 -08001877 j.Library.GenerateAndroidBuildActions(ctx)
Nan Zhang3c807db2017-11-03 14:53:31 -07001878 } else {
Colin Cross6b4a32d2017-12-05 13:42:45 -08001879 // Handle the binary wrapper
1880 j.isWrapperVariant = true
1881
Colin Cross366938f2017-12-11 16:29:02 -08001882 if j.binaryProperties.Wrapper != nil {
Colin Cross8a497952019-03-05 22:25:09 -08001883 j.wrapperFile = android.PathForModuleSrc(ctx, *j.binaryProperties.Wrapper)
Colin Cross6b4a32d2017-12-05 13:42:45 -08001884 } else {
1885 j.wrapperFile = android.PathForSource(ctx, "build/soong/scripts/jar-wrapper.sh")
1886 }
1887
1888 // Depend on the installed jar so that the wrapper doesn't get executed by
1889 // another build rule before the jar has been installed.
1890 jarFile := ctx.PrimaryModule().(*Binary).installFile
1891
1892 j.binaryFile = ctx.InstallExecutable(android.PathForModuleInstall(ctx, "bin"),
1893 ctx.ModuleName(), j.wrapperFile, jarFile)
Nan Zhang3c807db2017-11-03 14:53:31 -07001894 }
Colin Cross2fe66872015-03-30 17:20:39 -07001895}
1896
Colin Crossf506d872017-07-19 15:53:04 -07001897func (j *Binary) DepsMutator(ctx android.BottomUpMutatorContext) {
Colin Cross6b4a32d2017-12-05 13:42:45 -08001898 if ctx.Arch().ArchType == android.Common {
1899 j.deps(ctx)
1900 }
Colin Cross46c9b8b2017-06-22 16:51:17 -07001901}
1902
Colin Cross1b16b0e2019-02-12 14:41:32 -08001903// java_binary builds a `.jar` file and a shell script that executes it for the device, and possibly for the host
1904// as well.
1905//
1906// By default, a java_binary has a single variant that produces a `.jar` file containing `classes.dex` files that were
1907// compiled against the device bootclasspath.
1908//
1909// Specifying `host_supported: true` will produce two variants, one compiled against the device bootclasspath and one
1910// compiled against the host bootclasspath.
Colin Crossf506d872017-07-19 15:53:04 -07001911func BinaryFactory() android.Module {
1912 module := &Binary{}
Colin Cross2fe66872015-03-30 17:20:39 -07001913
Colin Cross36242852017-06-23 15:06:31 -07001914 module.AddProperties(
Colin Cross540eff82017-06-22 17:01:52 -07001915 &module.Module.properties,
1916 &module.Module.deviceProperties,
Colin Cross43f08db2018-11-12 10:13:39 -08001917 &module.Module.dexpreoptProperties,
Colin Cross6af17aa2017-09-20 12:59:05 -07001918 &module.Module.protoProperties,
Colin Cross540eff82017-06-22 17:01:52 -07001919 &module.binaryProperties)
Colin Cross36242852017-06-23 15:06:31 -07001920
Colin Cross9ae1b922018-06-26 17:59:05 -07001921 module.Module.properties.Installable = proptools.BoolPtr(true)
1922
Colin Cross6b4a32d2017-12-05 13:42:45 -08001923 android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibCommonFirst)
1924 android.InitDefaultableModule(module)
Colin Cross36242852017-06-23 15:06:31 -07001925 return module
Colin Cross2fe66872015-03-30 17:20:39 -07001926}
1927
Colin Cross1b16b0e2019-02-12 14:41:32 -08001928// java_binary_host builds a `.jar` file and a shell script that executes it for the host.
1929//
1930// A java_binary_host has a single variant that produces a `.jar` file containing `.class` files that were
1931// compiled against the host bootclasspath.
Colin Crossf506d872017-07-19 15:53:04 -07001932func BinaryHostFactory() android.Module {
1933 module := &Binary{}
Colin Cross2fe66872015-03-30 17:20:39 -07001934
Colin Cross36242852017-06-23 15:06:31 -07001935 module.AddProperties(
Colin Cross540eff82017-06-22 17:01:52 -07001936 &module.Module.properties,
Colin Cross6af17aa2017-09-20 12:59:05 -07001937 &module.Module.protoProperties,
Colin Cross540eff82017-06-22 17:01:52 -07001938 &module.binaryProperties)
Colin Cross36242852017-06-23 15:06:31 -07001939
Colin Cross9ae1b922018-06-26 17:59:05 -07001940 module.Module.properties.Installable = proptools.BoolPtr(true)
1941
Colin Cross6b4a32d2017-12-05 13:42:45 -08001942 android.InitAndroidArchModule(module, android.HostSupported, android.MultilibCommonFirst)
1943 android.InitDefaultableModule(module)
Colin Cross36242852017-06-23 15:06:31 -07001944 return module
Colin Cross2fe66872015-03-30 17:20:39 -07001945}
1946
1947//
1948// Java prebuilts
1949//
1950
Colin Cross74d73e22017-08-02 11:05:49 -07001951type ImportProperties struct {
Colin Cross27b922f2019-03-04 22:35:41 -08001952 Jars []string `android:"path"`
Colin Cross461bd1a2017-10-20 13:59:18 -07001953
Nan Zhangea568a42017-11-08 21:20:04 -08001954 Sdk_version *string
Colin Cross535e2cf2017-10-20 17:57:49 -07001955
1956 Installable *bool
Jiyong Park1be96912018-05-28 18:02:19 +09001957
1958 // List of shared java libs that this module has dependencies to
1959 Libs []string
Colin Cross37f6d792018-07-12 12:28:41 -07001960
1961 // List of files to remove from the jar file(s)
1962 Exclude_files []string
1963
1964 // List of directories to remove from the jar file(s)
1965 Exclude_dirs []string
Nan Zhang4c819fb2018-08-27 18:31:46 -07001966
1967 // if set to true, run Jetifier against .jar file. Defaults to false.
Colin Cross1001a792019-03-21 22:21:39 -07001968 Jetifier *bool
Jiyong Park4c4c0242019-10-21 14:53:15 +09001969
1970 // set the name of the output
1971 Stem *string
Colin Cross74d73e22017-08-02 11:05:49 -07001972}
1973
1974type Import struct {
Colin Cross635c3b02016-05-18 15:37:25 -07001975 android.ModuleBase
Colin Cross48de9a42018-10-02 13:53:33 -07001976 android.DefaultableModuleBase
Jiyong Park7f7766d2019-07-25 22:02:35 +09001977 android.ApexModuleBase
Colin Crossec7a0422017-07-07 14:47:12 -07001978 prebuilt android.Prebuilt
Jiyong Parkd1063c12019-07-17 20:08:41 +09001979 android.SdkBase
Colin Cross2fe66872015-03-30 17:20:39 -07001980
Colin Cross74d73e22017-08-02 11:05:49 -07001981 properties ImportProperties
1982
Colin Cross0a6e0072017-08-30 14:24:55 -07001983 combinedClasspathFile android.Path
Jiyong Park1be96912018-05-28 18:02:19 +09001984 exportedSdkLibs []string
Colin Cross2fe66872015-03-30 17:20:39 -07001985}
1986
Colin Cross83bb3162018-06-25 15:48:06 -07001987func (j *Import) sdkVersion() string {
Jeongik Cha2cc570d2019-10-29 15:44:45 +09001988 return String(j.properties.Sdk_version)
Colin Cross83bb3162018-06-25 15:48:06 -07001989}
1990
1991func (j *Import) minSdkVersion() string {
1992 return j.sdkVersion()
1993}
1994
Colin Cross74d73e22017-08-02 11:05:49 -07001995func (j *Import) Prebuilt() *android.Prebuilt {
Colin Crossec7a0422017-07-07 14:47:12 -07001996 return &j.prebuilt
1997}
1998
Colin Cross74d73e22017-08-02 11:05:49 -07001999func (j *Import) PrebuiltSrcs() []string {
2000 return j.properties.Jars
2001}
2002
2003func (j *Import) Name() string {
Colin Cross5ea9bcc2017-07-27 15:41:32 -07002004 return j.prebuilt.Name(j.ModuleBase.Name())
2005}
2006
Jiyong Park0b238752019-10-29 11:23:10 +09002007func (j *Import) Stem() string {
2008 return proptools.StringDefault(j.properties.Stem, j.ModuleBase.Name())
2009}
2010
Colin Cross74d73e22017-08-02 11:05:49 -07002011func (j *Import) DepsMutator(ctx android.BottomUpMutatorContext) {
Colin Cross42d48b72018-08-29 14:10:52 -07002012 ctx.AddVariationDependencies(nil, libTag, j.properties.Libs...)
Colin Cross1e676be2016-10-12 14:38:15 -07002013}
2014
Colin Cross74d73e22017-08-02 11:05:49 -07002015func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross8a497952019-03-05 22:25:09 -08002016 jars := android.PathsForModuleSrc(ctx, j.properties.Jars)
Colin Crosse1d62a82015-04-03 16:53:05 -07002017
Jiyong Park0b238752019-10-29 11:23:10 +09002018 jarName := j.Stem() + ".jar"
Nan Zhang4c819fb2018-08-27 18:31:46 -07002019 outputFile := android.PathForModuleOut(ctx, "combined", jarName)
Colin Cross37f6d792018-07-12 12:28:41 -07002020 TransformJarsToJar(ctx, outputFile, "for prebuilts", jars, android.OptionalPath{},
2021 false, j.properties.Exclude_files, j.properties.Exclude_dirs)
Colin Cross1001a792019-03-21 22:21:39 -07002022 if Bool(j.properties.Jetifier) {
Nan Zhang4c819fb2018-08-27 18:31:46 -07002023 inputFile := outputFile
2024 outputFile = android.PathForModuleOut(ctx, "jetifier", jarName)
2025 TransformJetifier(ctx, outputFile, inputFile)
2026 }
Colin Crosse9a275b2017-10-16 17:09:48 -07002027 j.combinedClasspathFile = outputFile
Jiyong Park1be96912018-05-28 18:02:19 +09002028
2029 ctx.VisitDirectDeps(func(module android.Module) {
2030 otherName := ctx.OtherModuleName(module)
2031 tag := ctx.OtherModuleDependencyTag(module)
2032
2033 switch dep := module.(type) {
2034 case Dependency:
2035 switch tag {
2036 case libTag, staticLibTag:
2037 // sdk lib names from dependencies are re-exported
2038 j.exportedSdkLibs = append(j.exportedSdkLibs, dep.ExportedSdkLibs()...)
2039 }
2040 case SdkLibraryDependency:
2041 switch tag {
2042 case libTag:
2043 // names of sdk libs that are directly depended are exported
2044 j.exportedSdkLibs = append(j.exportedSdkLibs, otherName)
2045 }
2046 }
2047 })
2048
2049 j.exportedSdkLibs = android.FirstUniqueStrings(j.exportedSdkLibs)
Nan Zhang4973ecf2018-08-10 13:42:12 -07002050 if Bool(j.properties.Installable) {
2051 ctx.InstallFile(android.PathForModuleInstall(ctx, "framework"),
Jiyong Park4c4c0242019-10-21 14:53:15 +09002052 jarName, outputFile)
Nan Zhang4973ecf2018-08-10 13:42:12 -07002053 }
Colin Cross2fe66872015-03-30 17:20:39 -07002054}
2055
Colin Cross74d73e22017-08-02 11:05:49 -07002056var _ Dependency = (*Import)(nil)
Colin Cross2fe66872015-03-30 17:20:39 -07002057
Nan Zhanged19fc32017-10-19 13:06:22 -07002058func (j *Import) HeaderJars() android.Paths {
albaltai36ff7dc2018-12-25 14:35:23 +08002059 if j.combinedClasspathFile == nil {
2060 return nil
2061 }
Colin Cross37f6d792018-07-12 12:28:41 -07002062 return android.Paths{j.combinedClasspathFile}
Nan Zhanged19fc32017-10-19 13:06:22 -07002063}
2064
2065func (j *Import) ImplementationJars() android.Paths {
shinwang9e4c07a2018-12-24 15:41:04 +08002066 if j.combinedClasspathFile == nil {
2067 return nil
2068 }
Colin Cross37f6d792018-07-12 12:28:41 -07002069 return android.Paths{j.combinedClasspathFile}
Colin Cross2fe66872015-03-30 17:20:39 -07002070}
2071
Colin Cross331a1212018-08-15 20:40:52 -07002072func (j *Import) ResourceJars() android.Paths {
2073 return nil
2074}
2075
2076func (j *Import) ImplementationAndResourcesJars() android.Paths {
albaltai36ff7dc2018-12-25 14:35:23 +08002077 if j.combinedClasspathFile == nil {
2078 return nil
2079 }
Colin Cross331a1212018-08-15 20:40:52 -07002080 return android.Paths{j.combinedClasspathFile}
2081}
2082
Colin Crossf24a22a2019-01-31 14:12:44 -08002083func (j *Import) DexJar() android.Path {
2084 return nil
2085}
2086
Colin Cross74d73e22017-08-02 11:05:49 -07002087func (j *Import) AidlIncludeDirs() android.Paths {
Colin Crossc0b06f12015-04-08 13:03:43 -07002088 return nil
2089}
2090
Jiyong Park1be96912018-05-28 18:02:19 +09002091func (j *Import) ExportedSdkLibs() []string {
2092 return j.exportedSdkLibs
2093}
2094
Colin Cross0c4ce212019-05-03 15:28:19 -07002095func (j *Import) SrcJarArgs() ([]string, android.Paths) {
2096 return nil, nil
2097}
2098
albaltai36ff7dc2018-12-25 14:35:23 +08002099// Add compile time check for interface implementation
2100var _ android.IDEInfo = (*Import)(nil)
2101var _ android.IDECustomizedModuleName = (*Import)(nil)
2102
Brandon Lee5d45c6f2018-08-15 15:35:38 -07002103// Collect information for opening IDE project files in java/jdeps.go.
2104const (
2105 removedPrefix = "prebuilt_"
2106)
2107
2108func (j *Import) IDEInfo(dpInfo *android.IdeInfo) {
2109 dpInfo.Jars = append(dpInfo.Jars, j.PrebuiltSrcs()...)
2110}
2111
2112func (j *Import) IDECustomizedModuleName() string {
2113 // TODO(b/113562217): Extract the base module name from the Import name, often the Import name
2114 // has a prefix "prebuilt_". Remove the prefix explicitly if needed until we find a better
2115 // solution to get the Import name.
2116 name := j.Name()
2117 if strings.HasPrefix(name, removedPrefix) {
patricktubb640e02018-10-11 18:33:16 +08002118 name = strings.TrimPrefix(name, removedPrefix)
Brandon Lee5d45c6f2018-08-15 15:35:38 -07002119 }
2120 return name
2121}
2122
Colin Cross74d73e22017-08-02 11:05:49 -07002123var _ android.PrebuiltInterface = (*Import)(nil)
Colin Cross2fe66872015-03-30 17:20:39 -07002124
Colin Cross1b16b0e2019-02-12 14:41:32 -08002125// java_import imports one or more `.jar` files into the build graph as if they were built by a java_library module.
2126//
2127// By default, a java_import has a single variant that expects a `.jar` file containing `.class` files that were
2128// compiled against an Android classpath.
2129//
2130// Specifying `host_supported: true` will produce two variants, one for use as a dependency of device modules and one
2131// for host modules.
Colin Cross74d73e22017-08-02 11:05:49 -07002132func ImportFactory() android.Module {
2133 module := &Import{}
Colin Cross36242852017-06-23 15:06:31 -07002134
Colin Cross74d73e22017-08-02 11:05:49 -07002135 module.AddProperties(&module.properties)
2136
2137 android.InitPrebuiltModule(module, &module.properties.Jars)
Jiyong Park7f7766d2019-07-25 22:02:35 +09002138 android.InitApexModule(module)
Jiyong Parkd1063c12019-07-17 20:08:41 +09002139 android.InitSdkAwareModule(module)
Jooyung Han18020ea2019-11-13 10:50:48 +09002140 InitJavaModule(module, android.HostAndDeviceSupported)
Colin Cross36242852017-06-23 15:06:31 -07002141 return module
Colin Cross2fe66872015-03-30 17:20:39 -07002142}
2143
Colin Cross1b16b0e2019-02-12 14:41:32 -08002144// java_import imports one or more `.jar` files into the build graph as if they were built by a java_library_host
2145// module.
2146//
2147// A java_import_host has a single variant that expects a `.jar` file containing `.class` files that were
2148// compiled against a host bootclasspath.
Colin Cross74d73e22017-08-02 11:05:49 -07002149func ImportFactoryHost() android.Module {
2150 module := &Import{}
2151
2152 module.AddProperties(&module.properties)
2153
2154 android.InitPrebuiltModule(module, &module.properties.Jars)
Jiyong Park7f7766d2019-07-25 22:02:35 +09002155 android.InitApexModule(module)
Jooyung Han18020ea2019-11-13 10:50:48 +09002156 InitJavaModule(module, android.HostSupported)
Colin Cross74d73e22017-08-02 11:05:49 -07002157 return module
2158}
2159
Colin Cross42be7612019-02-21 18:12:14 -08002160// dex_import module
2161
2162type DexImportProperties struct {
Colin Cross5cfc70d2019-07-15 13:36:55 -07002163 Jars []string `android:"path"`
Jiyong Park4c4c0242019-10-21 14:53:15 +09002164
2165 // set the name of the output
2166 Stem *string
Colin Cross42be7612019-02-21 18:12:14 -08002167}
2168
2169type DexImport struct {
2170 android.ModuleBase
2171 android.DefaultableModuleBase
Jiyong Park7f7766d2019-07-25 22:02:35 +09002172 android.ApexModuleBase
Colin Cross42be7612019-02-21 18:12:14 -08002173 prebuilt android.Prebuilt
2174
2175 properties DexImportProperties
2176
2177 dexJarFile android.Path
2178 maybeStrippedDexJarFile android.Path
2179
2180 dexpreopter
2181}
2182
2183func (j *DexImport) Prebuilt() *android.Prebuilt {
2184 return &j.prebuilt
2185}
2186
2187func (j *DexImport) PrebuiltSrcs() []string {
2188 return j.properties.Jars
2189}
2190
2191func (j *DexImport) Name() string {
2192 return j.prebuilt.Name(j.ModuleBase.Name())
2193}
2194
Jiyong Park0b238752019-10-29 11:23:10 +09002195func (j *DexImport) Stem() string {
2196 return proptools.StringDefault(j.properties.Stem, j.ModuleBase.Name())
2197}
2198
Colin Cross42be7612019-02-21 18:12:14 -08002199func (j *DexImport) GenerateAndroidBuildActions(ctx android.ModuleContext) {
2200 if len(j.properties.Jars) != 1 {
2201 ctx.PropertyErrorf("jars", "exactly one jar must be provided")
2202 }
2203
Jiyong Park0b238752019-10-29 11:23:10 +09002204 j.dexpreopter.installPath = android.PathForModuleInstall(ctx, "framework", j.Stem()+".jar")
Colin Cross42be7612019-02-21 18:12:14 -08002205 j.dexpreopter.isInstallable = true
2206 j.dexpreopter.uncompressedDex = shouldUncompressDex(ctx, &j.dexpreopter)
2207
2208 inputJar := ctx.ExpandSource(j.properties.Jars[0], "jars")
2209 dexOutputFile := android.PathForModuleOut(ctx, ctx.ModuleName()+".jar")
2210
2211 if j.dexpreopter.uncompressedDex {
2212 rule := android.NewRuleBuilder()
2213
2214 temporary := android.PathForModuleOut(ctx, ctx.ModuleName()+".jar.unaligned")
2215 rule.Temporary(temporary)
2216
2217 // use zip2zip to uncompress classes*.dex files
2218 rule.Command().
Colin Crossee94d6a2019-07-08 17:08:34 -07002219 BuiltTool(ctx, "zip2zip").
Colin Cross42be7612019-02-21 18:12:14 -08002220 FlagWithInput("-i ", inputJar).
2221 FlagWithOutput("-o ", temporary).
2222 FlagWithArg("-0 ", "'classes*.dex'")
2223
2224 // use zipalign to align uncompressed classes*.dex files
2225 rule.Command().
Colin Crossee94d6a2019-07-08 17:08:34 -07002226 BuiltTool(ctx, "zipalign").
Colin Cross42be7612019-02-21 18:12:14 -08002227 Flag("-f").
2228 Text("4").
2229 Input(temporary).
2230 Output(dexOutputFile)
2231
2232 rule.DeleteTemporaryFiles()
2233
2234 rule.Build(pctx, ctx, "uncompress_dex", "uncompress dex")
2235 } else {
2236 ctx.Build(pctx, android.BuildParams{
2237 Rule: android.Cp,
2238 Input: inputJar,
2239 Output: dexOutputFile,
2240 })
2241 }
2242
2243 j.dexJarFile = dexOutputFile
2244
2245 dexOutputFile = j.dexpreopt(ctx, dexOutputFile)
2246
2247 j.maybeStrippedDexJarFile = dexOutputFile
2248
2249 ctx.InstallFile(android.PathForModuleInstall(ctx, "framework"),
2250 ctx.ModuleName()+".jar", dexOutputFile)
2251}
2252
2253func (j *DexImport) DexJar() android.Path {
2254 return j.dexJarFile
2255}
2256
2257// dex_import imports a `.jar` file containing classes.dex files.
2258//
2259// A dex_import module cannot be used as a dependency of a java_* or android_* module, it can only be installed
2260// to the device.
2261func DexImportFactory() android.Module {
2262 module := &DexImport{}
2263
2264 module.AddProperties(&module.properties)
2265
2266 android.InitPrebuiltModule(module, &module.properties.Jars)
Jiyong Park7f7766d2019-07-25 22:02:35 +09002267 android.InitApexModule(module)
Jooyung Han18020ea2019-11-13 10:50:48 +09002268 InitJavaModule(module, android.DeviceSupported)
Colin Cross42be7612019-02-21 18:12:14 -08002269 return module
2270}
2271
Colin Cross89536d42017-07-07 14:35:50 -07002272//
2273// Defaults
2274//
2275type Defaults struct {
2276 android.ModuleBase
2277 android.DefaultsModuleBase
Jiyong Park7f7766d2019-07-25 22:02:35 +09002278 android.ApexModuleBase
Colin Cross89536d42017-07-07 14:35:50 -07002279}
2280
Colin Cross1b16b0e2019-02-12 14:41:32 -08002281// java_defaults provides a set of properties that can be inherited by other java or android modules.
2282//
2283// A module can use the properties from a java_defaults module using `defaults: ["defaults_module_name"]`. Each
2284// property in the defaults module that exists in the depending module will be prepended to the depending module's
2285// value for that property.
2286//
2287// Example:
2288//
2289// java_defaults {
2290// name: "example_defaults",
2291// srcs: ["common/**/*.java"],
2292// javacflags: ["-Xlint:all"],
2293// aaptflags: ["--auto-add-overlay"],
2294// }
2295//
2296// java_library {
2297// name: "example",
2298// defaults: ["example_defaults"],
2299// srcs: ["example/**/*.java"],
2300// }
2301//
2302// is functionally identical to:
2303//
2304// java_library {
2305// name: "example",
2306// srcs: [
2307// "common/**/*.java",
2308// "example/**/*.java",
2309// ],
2310// javacflags: ["-Xlint:all"],
2311// }
Colin Cross89536d42017-07-07 14:35:50 -07002312func defaultsFactory() android.Module {
2313 return DefaultsFactory()
2314}
2315
2316func DefaultsFactory(props ...interface{}) android.Module {
2317 module := &Defaults{}
2318
2319 module.AddProperties(props...)
2320 module.AddProperties(
2321 &CompilerProperties{},
2322 &CompilerDeviceProperties{},
Colin Cross43f08db2018-11-12 10:13:39 -08002323 &DexpreoptProperties{},
Dan Willemsen6424d172018-03-08 13:27:59 -08002324 &android.ProtoProperties{},
Colin Cross48de9a42018-10-02 13:53:33 -07002325 &aaptProperties{},
2326 &androidLibraryProperties{},
2327 &appProperties{},
2328 &appTestProperties{},
Jaewoong Jung525443a2019-02-28 15:35:54 -08002329 &overridableAppProperties{},
Colin Cross48de9a42018-10-02 13:53:33 -07002330 &ImportProperties{},
2331 &AARImportProperties{},
2332 &sdkLibraryProperties{},
Colin Cross42be7612019-02-21 18:12:14 -08002333 &DexImportProperties{},
Jooyung Han18020ea2019-11-13 10:50:48 +09002334 &android.ApexProperties{},
Colin Cross89536d42017-07-07 14:35:50 -07002335 )
2336
2337 android.InitDefaultsModule(module)
Colin Cross89536d42017-07-07 14:35:50 -07002338 return module
2339}
Nan Zhangea568a42017-11-08 21:20:04 -08002340
Sasha Smundak2a4549e2018-11-05 16:49:08 -08002341func kytheExtractJavaFactory() android.Singleton {
2342 return &kytheExtractJavaSingleton{}
2343}
2344
2345type kytheExtractJavaSingleton struct {
2346}
2347
2348func (ks *kytheExtractJavaSingleton) GenerateBuildActions(ctx android.SingletonContext) {
2349 var xrefTargets android.Paths
2350 ctx.VisitAllModules(func(module android.Module) {
2351 if javaModule, ok := module.(xref); ok {
2352 xrefTargets = append(xrefTargets, javaModule.XrefJavaFiles()...)
2353 }
2354 })
2355 // TODO(asmundak): perhaps emit a rule to output a warning if there were no xrefTargets
2356 if len(xrefTargets) > 0 {
2357 ctx.Build(pctx, android.BuildParams{
2358 Rule: blueprint.Phony,
2359 Output: android.PathForPhony(ctx, "xref_java"),
2360 Inputs: xrefTargets,
2361 })
2362 }
2363}
2364
Nan Zhangea568a42017-11-08 21:20:04 -08002365var Bool = proptools.Bool
Colin Cross38b40df2018-04-10 16:14:46 -07002366var BoolDefault = proptools.BoolDefault
Nan Zhangea568a42017-11-08 21:20:04 -08002367var String = proptools.String
Colin Cross0d0ba592018-02-20 13:33:42 -08002368var inList = android.InList