blob: 9aa75b2fc846d13d280125ce383c2d188da638d0 [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 Cha538c0d02019-07-11 15:54:27 +090057func (j *Module) checkPlatformAPI(ctx android.ModuleContext) {
58 if sc, ok := ctx.Module().(sdkContext); ok {
59 usePlatformAPI := proptools.Bool(j.deviceProperties.Platform_apis)
60 if usePlatformAPI != (sc.sdkVersion() == "") {
61 if usePlatformAPI {
62 ctx.PropertyErrorf("platform_apis", "platform_apis must be false when sdk_version is not empty.")
63 } else {
64 ctx.PropertyErrorf("platform_apis", "platform_apis must be true when sdk_version is empty.")
65 }
66 }
67
68 }
69}
70
Colin Cross2fe66872015-03-30 17:20:39 -070071// TODO:
72// Autogenerated files:
Colin Cross2fe66872015-03-30 17:20:39 -070073// Renderscript
74// Post-jar passes:
75// Proguard
Colin Cross2fe66872015-03-30 17:20:39 -070076// Rmtypedefs
Colin Cross2fe66872015-03-30 17:20:39 -070077// DroidDoc
78// Findbugs
79
Colin Cross89536d42017-07-07 14:35:50 -070080type CompilerProperties struct {
Colin Cross7d5136f2015-05-11 13:39:40 -070081 // list of source files used to compile the Java module. May be .java, .logtags, .proto,
82 // or .aidl files.
Colin Cross27b922f2019-03-04 22:35:41 -080083 Srcs []string `android:"path,arch_variant"`
Dan Willemsen2ef08f42015-06-30 18:15:24 -070084
85 // list of source files that should not be used to build the Java module.
86 // This is most useful in the arch/multilib variants to remove non-common files
Colin Cross27b922f2019-03-04 22:35:41 -080087 Exclude_srcs []string `android:"path,arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -070088
89 // list of directories containing Java resources
Colin Cross86a63ff2017-09-27 17:33:10 -070090 Java_resource_dirs []string `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -070091
Colin Cross86a63ff2017-09-27 17:33:10 -070092 // list of directories that should be excluded from java_resource_dirs
93 Exclude_java_resource_dirs []string `android:"arch_variant"`
Dan Willemsen2ef08f42015-06-30 18:15:24 -070094
Colin Cross0f37af02017-09-27 17:42:05 -070095 // list of files to use as Java resources
Colin Cross27b922f2019-03-04 22:35:41 -080096 Java_resources []string `android:"path,arch_variant"`
Colin Cross0f37af02017-09-27 17:42:05 -070097
Colin Crosscedd4762018-09-13 11:26:19 -070098 // list of files that should be excluded from java_resources and java_resource_dirs
Colin Cross27b922f2019-03-04 22:35:41 -080099 Exclude_java_resources []string `android:"path,arch_variant"`
Colin Cross0f37af02017-09-27 17:42:05 -0700100
Colin Cross7d5136f2015-05-11 13:39:40 -0700101 // list of module-specific flags that will be used for javac compiles
102 Javacflags []string `android:"arch_variant"`
103
Zoran Jovanovic8736ce22018-08-21 17:10:29 +0200104 // list of module-specific flags that will be used for kotlinc compiles
105 Kotlincflags []string `android:"arch_variant"`
106
Colin Cross7d5136f2015-05-11 13:39:40 -0700107 // list of of java libraries that will be in the classpath
Colin Crosse8dc34a2017-07-19 11:22:16 -0700108 Libs []string `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700109
110 // list of java libraries that will be compiled into the resulting jar
Colin Crosse8dc34a2017-07-19 11:22:16 -0700111 Static_libs []string `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700112
113 // manifest file to be included in resulting jar
Colin Cross27b922f2019-03-04 22:35:41 -0800114 Manifest *string `android:"path"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700115
Colin Cross540eff82017-06-22 17:01:52 -0700116 // if not blank, run jarjar using the specified rules file
Colin Cross27b922f2019-03-04 22:35:41 -0800117 Jarjar_rules *string `android:"path,arch_variant"`
Colin Cross64162712017-08-08 13:17:59 -0700118
119 // If not blank, set the java version passed to javac as -source and -target
120 Java_version *string
Colin Cross2c429dc2017-08-31 16:45:16 -0700121
Colin Cross9ae1b922018-06-26 17:59:05 -0700122 // If set to true, allow this module to be dexed and installed on devices. Has no
123 // effect on host modules, which are always considered installable.
Colin Cross2c429dc2017-08-31 16:45:16 -0700124 Installable *bool
Colin Cross32f676a2017-09-06 13:41:06 -0700125
Colin Cross0f37af02017-09-27 17:42:05 -0700126 // If set to true, include sources used to compile the module in to the final jar
127 Include_srcs *bool
128
Vladimir Marko0975ee02019-04-02 10:29:55 +0100129 // If not empty, classes are restricted to the specified packages and their sub-packages.
130 // This restriction is checked after applying jarjar rules and including static libs.
131 Permitted_packages []string
132
Colin Crossbe9cdb82019-01-21 21:37:16 -0800133 // List of modules to use as annotation processors
134 Plugins []string
Colin Cross1369cdb2017-09-29 17:58:17 -0700135
Nan Zhang61eaedb2017-11-02 13:28:15 -0700136 // The number of Java source entries each Javac instance can process
137 Javac_shard_size *int64
138
Nan Zhang5f8cb422018-02-06 10:34:32 -0800139 // Add host jdk tools.jar to bootclasspath
140 Use_tools_jar *bool
141
Colin Cross1369cdb2017-09-29 17:58:17 -0700142 Openjdk9 struct {
143 // List of source files that should only be used when passing -source 1.9
Colin Cross27b922f2019-03-04 22:35:41 -0800144 Srcs []string `android:"path"`
Colin Cross1369cdb2017-09-29 17:58:17 -0700145
146 // List of javac flags that should only be used when passing -source 1.9
147 Javacflags []string
148 }
Colin Crosscb933592017-11-22 13:49:43 -0800149
Colin Cross81440082018-08-15 20:21:55 -0700150 // When compiling language level 9+ .java code in packages that are part of
151 // a system module, patch_module names the module that your sources and
152 // dependencies should be patched into. The Android runtime currently
153 // doesn't implement the JEP 261 module system so this option is only
154 // supported at compile time. It should only be needed to compile tests in
155 // packages that exist in libcore and which are inconvenient to move
156 // elsewhere.
Tobias Thiererdda713d2018-09-19 16:16:19 +0100157 Patch_module *string `android:"arch_variant"`
Colin Cross81440082018-08-15 20:21:55 -0700158
Colin Crosscb933592017-11-22 13:49:43 -0800159 Jacoco struct {
160 // List of classes to include for instrumentation with jacoco to collect coverage
161 // information at runtime when building with coverage enabled. If unset defaults to all
162 // classes.
163 // Supports '*' as the last character of an entry in the list as a wildcard match.
164 // If preceded by '.' it matches all classes in the package and subpackages, otherwise
165 // it matches classes in the package that have the class name as a prefix.
166 Include_filter []string
167
168 // List of classes to exclude from instrumentation with jacoco to collect coverage
169 // information at runtime when building with coverage enabled. Overrides classes selected
170 // by the include_filter property.
171 // Supports '*' as the last character of an entry in the list as a wildcard match.
172 // If preceded by '.' it matches all classes in the package and subpackages, otherwise
173 // it matches classes in the package that have the class name as a prefix.
174 Exclude_filter []string
175 }
176
Andreas Gampef3e5b552018-01-22 21:27:21 -0800177 Errorprone struct {
178 // List of javac flags that should only be used when running errorprone.
179 Javacflags []string
180 }
181
Colin Cross0f2ee152017-12-14 15:22:43 -0800182 Proto struct {
183 // List of extra options that will be passed to the proto generator.
184 Output_params []string
185 }
186
Colin Crosscb933592017-11-22 13:49:43 -0800187 Instrument bool `blueprint:"mutated"`
Alex Light7f004a72019-02-21 13:27:37 -0800188
189 // List of files to include in the META-INF/services folder of the resulting jar.
Colin Cross27b922f2019-03-04 22:35:41 -0800190 Services []string `android:"path,arch_variant"`
Colin Cross540eff82017-06-22 17:01:52 -0700191}
192
Colin Cross89536d42017-07-07 14:35:50 -0700193type CompilerDeviceProperties struct {
Colin Cross540eff82017-06-22 17:01:52 -0700194 // list of module-specific flags that will be used for dex compiles
195 Dxflags []string `android:"arch_variant"`
196
Jeongik Cha538c0d02019-07-11 15:54:27 +0900197 // if not blank, set to the version of the sdk to compile against.
198 // Defaults to compiling against the current platform.
Nan Zhangea568a42017-11-08 21:20:04 -0800199 Sdk_version *string
Colin Cross7d5136f2015-05-11 13:39:40 -0700200
Colin Cross83bb3162018-06-25 15:48:06 -0700201 // if not blank, set the minimum version of the sdk that the compiled artifacts will run against.
202 // Defaults to sdk_version if not set.
203 Min_sdk_version *string
204
Dan Willemsen419290a2018-10-31 15:28:47 -0700205 // if not blank, set the targetSdkVersion in the AndroidManifest.xml.
206 // Defaults to sdk_version if not set.
207 Target_sdk_version *string
208
Jeongik Cha356dac42019-08-19 14:09:52 +0900209 // Whether to compile against the platform APIs instead of an SDK.
210 // If true, then sdk_version must be empty. The value of this field
211 // is ignored when module's type isn't android_app.
Colin Cross6af2e492018-05-22 11:12:33 -0700212 Platform_apis *bool
213
Colin Crossebe1a512017-11-14 13:12:14 -0800214 Aidl struct {
215 // Top level directories to pass to aidl tool
216 Include_dirs []string
Colin Cross7d5136f2015-05-11 13:39:40 -0700217
Colin Crossebe1a512017-11-14 13:12:14 -0800218 // Directories rooted at the Android.bp file to pass to aidl tool
219 Local_include_dirs []string
220
221 // directories that should be added as include directories for any aidl sources of modules
222 // that depend on this module, as well as to aidl for this module.
223 Export_include_dirs []string
Martijn Coeneneab15642018-03-09 09:29:59 +0100224
225 // whether to generate traces (for systrace) for this interface
226 Generate_traces *bool
Olivier Gaillard0a4cfbc2018-07-16 23:37:03 +0100227
228 // whether to generate Binder#GetTransaction name method.
229 Generate_get_transaction_name *bool
Colin Crossebe1a512017-11-14 13:12:14 -0800230 }
Colin Cross92430102017-10-09 14:59:32 -0700231
232 // If true, export a copy of the module as a -hostdex module for host testing.
233 Hostdex *bool
Colin Cross1369cdb2017-09-29 17:58:17 -0700234
Colin Cross7f87f4f2019-04-24 13:41:45 -0700235 Target struct {
236 Hostdex struct {
237 // Additional required dependencies to add to -hostdex modules.
238 Required []string
239 }
240 }
241
David Brazdil17ef5632018-06-27 10:27:45 +0100242 // If set to true, compile dex regardless of installable. Defaults to false.
243 Compile_dex *bool
244
Colin Cross66dbc0b2017-12-28 12:23:20 -0800245 Optimize struct {
Colin Crossae5caf52018-05-22 11:11:52 -0700246 // If false, disable all optimization. Defaults to true for android_app and android_test
247 // modules, false for java_library and java_test modules.
Colin Cross66dbc0b2017-12-28 12:23:20 -0800248 Enabled *bool
Sasha Smundak2057f822019-04-16 17:16:58 -0700249 // True if the module containing this has it set by default.
250 EnabledByDefault bool `blueprint:"mutated"`
Colin Cross66dbc0b2017-12-28 12:23:20 -0800251
252 // If true, optimize for size by removing unused code. Defaults to true for apps,
253 // false for libraries and tests.
254 Shrink *bool
255
256 // If true, optimize bytecode. Defaults to false.
257 Optimize *bool
258
259 // If true, obfuscate bytecode. Defaults to false.
260 Obfuscate *bool
261
262 // If true, do not use the flag files generated by aapt that automatically keep
263 // classes referenced by the app manifest. Defaults to false.
264 No_aapt_flags *bool
265
266 // Flags to pass to proguard.
267 Proguard_flags []string
268
269 // Specifies the locations of files containing proguard flags.
Colin Cross27b922f2019-03-04 22:35:41 -0800270 Proguard_flags_files []string `android:"path"`
Colin Cross66dbc0b2017-12-28 12:23:20 -0800271 }
272
Paul Duffine25c6442019-10-11 13:50:28 +0100273 // When targeting 1.9 and above, override the modules to use with --system,
274 // otherwise provides defaults libraries to add to the bootclasspath.
Colin Cross1369cdb2017-09-29 17:58:17 -0700275 System_modules *string
Colin Cross5a0dcd52018-10-05 14:20:06 -0700276
Jiyong Park4c4c0242019-10-21 14:53:15 +0900277 // set the name of the output
278 Stem *string
279
Colin Cross5a0dcd52018-10-05 14:20:06 -0700280 UncompressDex bool `blueprint:"mutated"`
Colin Cross43f08db2018-11-12 10:13:39 -0800281 IsSDKLibrary bool `blueprint:"mutated"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700282}
283
Sasha Smundak2057f822019-04-16 17:16:58 -0700284func (me *CompilerDeviceProperties) EffectiveOptimizeEnabled() bool {
285 return BoolDefault(me.Optimize.Enabled, me.Optimize.EnabledByDefault)
286}
287
Colin Cross46c9b8b2017-06-22 16:51:17 -0700288// Module contains the properties and members used by all java module types
289type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700290 android.ModuleBase
Colin Cross89536d42017-07-07 14:35:50 -0700291 android.DefaultableModuleBase
Jiyong Park7f7766d2019-07-25 22:02:35 +0900292 android.ApexModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +0900293 android.SdkBase
Colin Cross2fe66872015-03-30 17:20:39 -0700294
Colin Cross89536d42017-07-07 14:35:50 -0700295 properties CompilerProperties
Colin Cross6af17aa2017-09-20 12:59:05 -0700296 protoProperties android.ProtoProperties
Colin Cross89536d42017-07-07 14:35:50 -0700297 deviceProperties CompilerDeviceProperties
Colin Cross2fe66872015-03-30 17:20:39 -0700298
Colin Cross331a1212018-08-15 20:40:52 -0700299 // jar file containing header classes including static library dependencies, suitable for
300 // inserting into the bootclasspath/classpath of another compile
Nan Zhanged19fc32017-10-19 13:06:22 -0700301 headerJarFile android.Path
302
Colin Cross331a1212018-08-15 20:40:52 -0700303 // jar file containing implementation classes including static library dependencies but no
304 // resources
Nan Zhanged19fc32017-10-19 13:06:22 -0700305 implementationJarFile android.Path
Colin Cross2fe66872015-03-30 17:20:39 -0700306
Colin Cross331a1212018-08-15 20:40:52 -0700307 // jar file containing only resources including from static library dependencies
308 resourceJar android.Path
309
Colin Cross0c4ce212019-05-03 15:28:19 -0700310 // args and dependencies to package source files into a srcjar
311 srcJarArgs []string
312 srcJarDeps android.Paths
313
Colin Cross331a1212018-08-15 20:40:52 -0700314 // jar file containing implementation classes and resources including static library
315 // dependencies
316 implementationAndResourcesJar android.Path
317
318 // output file containing classes.dex and resources
Colin Cross6ade34f2017-09-15 13:00:47 -0700319 dexJarFile android.Path
320
Colin Cross43f08db2018-11-12 10:13:39 -0800321 // output file that contains classes.dex if it should be in the output file
322 maybeStrippedDexJarFile android.Path
323
Colin Crosscb933592017-11-22 13:49:43 -0800324 // output file containing uninstrumented classes that will be instrumented by jacoco
325 jacocoReportClassesFile android.Path
326
Colin Cross66dbc0b2017-12-28 12:23:20 -0800327 // output file containing mapping of obfuscated names
328 proguardDictionary android.Path
329
Colin Cross331a1212018-08-15 20:40:52 -0700330 // output file of the module, which may be a classes jar or a dex jar
Colin Crosse560c4a2019-03-19 16:03:11 -0700331 outputFile android.Path
332 extraOutputFiles android.Paths
Colin Crossb7a63242015-04-16 14:09:14 -0700333
Colin Cross635c3b02016-05-18 15:37:25 -0700334 exportAidlIncludeDirs android.Paths
Colin Crossc0b06f12015-04-08 13:03:43 -0700335
Colin Cross635c3b02016-05-18 15:37:25 -0700336 logtagsSrcs android.Paths
Colin Crossf05fe972015-04-10 17:45:20 -0700337
Colin Cross2fe66872015-03-30 17:20:39 -0700338 // installed file for binary dependency
Colin Cross635c3b02016-05-18 15:37:25 -0700339 installFile android.Path
Colin Cross5ab4e6d2017-11-22 16:20:45 -0800340
341 // list of .java files and srcjars that was passed to javac
342 compiledJavaSrcs android.Paths
343 compiledSrcJars android.Paths
Colin Cross66dbc0b2017-12-28 12:23:20 -0800344
345 // list of extra progurad flag files
346 extraProguardFlagFiles android.Paths
Jiyong Park1be96912018-05-28 18:02:19 +0900347
Colin Cross094054a2018-10-17 15:10:48 -0700348 // manifest file to use instead of properties.Manifest
349 overrideManifest android.OptionalPath
350
Jiyong Park1be96912018-05-28 18:02:19 +0900351 // list of SDK lib names that this java moudule is exporting
352 exportedSdkLibs []string
Brandon Lee5d45c6f2018-08-15 15:35:38 -0700353
patricktu242faad2019-09-24 15:41:30 +0800354 // list of source files, collected from srcFiles with uniqie java and all kt files,
355 // will be used by android.IDEInfo struct
Brandon Lee5d45c6f2018-08-15 15:35:38 -0700356 expandIDEInfoCompiledSrcs []string
Colin Cross43f08db2018-11-12 10:13:39 -0800357
Steven Morelandc4efd9c2019-01-18 11:51:25 -0800358 // expanded Jarjar_rules
359 expandJarjarRules android.Path
360
Vladimir Marko0975ee02019-04-02 10:29:55 +0100361 // list of additional targets for checkbuild
362 additionalCheckedModules android.Paths
363
Colin Cross988708c2019-05-06 14:04:11 -0700364 // Extra files generated by the module type to be added as java resources.
365 extraResources android.Paths
366
Colin Crossf24a22a2019-01-31 14:12:44 -0800367 hiddenAPI
Colin Cross43f08db2018-11-12 10:13:39 -0800368 dexpreopter
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800369
370 // list of the xref extraction files
371 kytheFiles android.Paths
Colin Cross2fe66872015-03-30 17:20:39 -0700372}
373
Colin Cross41955e82019-05-29 14:40:35 -0700374func (j *Module) OutputFiles(tag string) (android.Paths, error) {
375 switch tag {
376 case "":
377 return append(android.Paths{j.outputFile}, j.extraOutputFiles...), nil
Colin Cross375ca3c2019-05-29 14:40:58 -0700378 case ".jar":
379 return android.Paths{j.implementationAndResourcesJar}, nil
Colin Cross2d975b12019-07-29 16:47:42 -0700380 case ".proguard_map":
381 return android.Paths{j.proguardDictionary}, nil
Colin Cross41955e82019-05-29 14:40:35 -0700382 default:
383 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
384 }
Colin Cross54250902017-12-05 09:28:08 -0800385}
386
Jiyong Park8fd61922018-11-08 02:50:25 +0900387func (j *Module) DexJarFile() android.Path {
388 return j.dexJarFile
389}
390
Colin Cross41955e82019-05-29 14:40:35 -0700391var _ android.OutputFileProducer = (*Module)(nil)
Colin Cross54250902017-12-05 09:28:08 -0800392
Colin Crossf506d872017-07-19 15:53:04 -0700393type Dependency interface {
Nan Zhanged19fc32017-10-19 13:06:22 -0700394 HeaderJars() android.Paths
395 ImplementationJars() android.Paths
Colin Cross331a1212018-08-15 20:40:52 -0700396 ResourceJars() android.Paths
397 ImplementationAndResourcesJars() android.Paths
Colin Crossf24a22a2019-01-31 14:12:44 -0800398 DexJar() android.Path
Colin Cross635c3b02016-05-18 15:37:25 -0700399 AidlIncludeDirs() android.Paths
Jiyong Park1be96912018-05-28 18:02:19 +0900400 ExportedSdkLibs() []string
Colin Cross0c4ce212019-05-03 15:28:19 -0700401 SrcJarArgs() ([]string, android.Paths)
Colin Crosse323f3c2019-09-17 15:34:09 -0700402 BaseModuleName() string
Colin Cross2fe66872015-03-30 17:20:39 -0700403}
404
Jiyong Parkc678ad32018-04-10 13:07:10 +0900405type SdkLibraryDependency interface {
Colin Cross0ea8ba82019-06-06 14:33:29 -0700406 SdkHeaderJars(ctx android.BaseModuleContext, sdkVersion string) android.Paths
407 SdkImplementationJars(ctx android.BaseModuleContext, sdkVersion string) android.Paths
Jiyong Parkc678ad32018-04-10 13:07:10 +0900408}
409
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800410type xref interface {
411 XrefJavaFiles() android.Paths
412}
413
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800414func (j *Module) XrefJavaFiles() android.Paths {
415 return j.kytheFiles
416}
417
Colin Cross89536d42017-07-07 14:35:50 -0700418func InitJavaModule(module android.DefaultableModule, hod android.HostOrDeviceSupported) {
419 android.InitAndroidArchModule(module, hod, android.MultilibCommon)
420 android.InitDefaultableModule(module)
421}
422
Colin Crossbe1da472017-07-07 15:59:46 -0700423type dependencyTag struct {
424 blueprint.BaseDependencyTag
425 name string
Colin Cross2fe66872015-03-30 17:20:39 -0700426}
427
Colin Crossa4f08812018-10-02 22:03:40 -0700428type jniDependencyTag struct {
429 blueprint.BaseDependencyTag
430 target android.Target
431}
432
Colin Crossbe1da472017-07-07 15:59:46 -0700433var (
Colin Cross4b964c02018-10-15 16:18:06 -0700434 staticLibTag = dependencyTag{name: "staticlib"}
435 libTag = dependencyTag{name: "javalib"}
Colin Crossbe9cdb82019-01-21 21:37:16 -0800436 pluginTag = dependencyTag{name: "plugin"}
Colin Cross4b964c02018-10-15 16:18:06 -0700437 bootClasspathTag = dependencyTag{name: "bootclasspath"}
438 systemModulesTag = dependencyTag{name: "system modules"}
439 frameworkResTag = dependencyTag{name: "framework-res"}
440 frameworkApkTag = dependencyTag{name: "framework-apk"}
441 kotlinStdlibTag = dependencyTag{name: "kotlin-stdlib"}
Colin Crossafbb1732019-01-17 15:42:52 -0800442 kotlinAnnotationsTag = dependencyTag{name: "kotlin-annotations"}
Colin Cross4b964c02018-10-15 16:18:06 -0700443 proguardRaiseTag = dependencyTag{name: "proguard-raise"}
444 certificateTag = dependencyTag{name: "certificate"}
445 instrumentationForTag = dependencyTag{name: "instrumentation_for"}
Colin Cross50ddcc42019-05-16 12:28:22 -0700446 usesLibTag = dependencyTag{name: "uses-library"}
Colin Crossbe1da472017-07-07 15:59:46 -0700447)
Colin Cross2fe66872015-03-30 17:20:39 -0700448
Jeongik Cha6bd33c12019-06-25 16:26:18 +0900449func defaultSdkVersion(ctx checkVendorModuleContext) string {
450 if ctx.SocSpecific() || ctx.DeviceSpecific() {
451 return "system_current"
452 }
453 return ""
454}
455
456type checkVendorModuleContext interface {
457 SocSpecific() bool
458 DeviceSpecific() bool
459}
460
Colin Crossfc3674a2017-09-18 17:41:52 -0700461type sdkDep struct {
Colin Cross47ff2522017-10-02 14:22:08 -0700462 useModule, useFiles, useDefaultLibs, invalidVersion bool
463
Paul Duffine25c6442019-10-11 13:50:28 +0100464 modules []string
465
466 // The default system modules to use. Will be an empty string if no system
467 // modules are to be used.
Colin Cross1369cdb2017-09-29 17:58:17 -0700468 systemModules string
469
Colin Crossa97c5d32018-03-28 14:58:31 -0700470 frameworkResModule string
471
Colin Cross86a60ae2018-05-29 14:44:55 -0700472 jars android.Paths
Colin Cross3047fa22019-04-18 10:56:44 -0700473 aidl android.OptionalPath
Paul Duffin250e6192019-06-07 10:44:37 +0100474
475 noStandardLibs, noFrameworksLibs bool
476}
477
478func (s sdkDep) hasStandardLibs() bool {
479 return !s.noStandardLibs
480}
481
482func (s sdkDep) hasFrameworkLibs() bool {
483 return !s.noStandardLibs && !s.noFrameworksLibs
Colin Cross1369cdb2017-09-29 17:58:17 -0700484}
485
Colin Crossa4f08812018-10-02 22:03:40 -0700486type jniLib struct {
487 name string
488 path android.Path
489 target android.Target
490}
491
Colin Cross0ea8ba82019-06-06 14:33:29 -0700492func (j *Module) shouldInstrument(ctx android.BaseModuleContext) bool {
Colin Cross3144dfc2018-01-03 15:06:47 -0800493 return j.properties.Instrument && ctx.Config().IsEnvTrue("EMMA_INSTRUMENT")
494}
495
Colin Cross0ea8ba82019-06-06 14:33:29 -0700496func (j *Module) shouldInstrumentStatic(ctx android.BaseModuleContext) bool {
Colin Cross3144dfc2018-01-03 15:06:47 -0800497 return j.shouldInstrument(ctx) &&
498 (ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_STATIC") ||
499 ctx.Config().UnbundledBuild())
500}
501
Colin Cross83bb3162018-06-25 15:48:06 -0700502func (j *Module) sdkVersion() string {
Jeongik Cha6bd33c12019-06-25 16:26:18 +0900503 return proptools.StringDefault(j.deviceProperties.Sdk_version, defaultSdkVersion(j))
Colin Cross83bb3162018-06-25 15:48:06 -0700504}
505
Paul Duffine25c6442019-10-11 13:50:28 +0100506func (j *Module) systemModules() string {
507 return proptools.String(j.deviceProperties.System_modules)
508}
509
Colin Cross83bb3162018-06-25 15:48:06 -0700510func (j *Module) minSdkVersion() string {
511 if j.deviceProperties.Min_sdk_version != nil {
512 return *j.deviceProperties.Min_sdk_version
513 }
514 return j.sdkVersion()
515}
516
Dan Willemsen419290a2018-10-31 15:28:47 -0700517func (j *Module) targetSdkVersion() string {
518 if j.deviceProperties.Target_sdk_version != nil {
519 return *j.deviceProperties.Target_sdk_version
520 }
521 return j.sdkVersion()
522}
523
Colin Crossbe1da472017-07-07 15:59:46 -0700524func (j *Module) deps(ctx android.BottomUpMutatorContext) {
Colin Cross1369cdb2017-09-29 17:58:17 -0700525 if ctx.Device() {
Paul Duffin250e6192019-06-07 10:44:37 +0100526 sdkDep := decodeSdkDep(ctx, sdkContext(j))
527 if sdkDep.hasStandardLibs() {
Colin Crossfc3674a2017-09-18 17:41:52 -0700528 if sdkDep.useDefaultLibs {
Colin Cross42d48b72018-08-29 14:10:52 -0700529 ctx.AddVariationDependencies(nil, bootClasspathTag, config.DefaultBootclasspathLibraries...)
Tobias Thierer06dd04f2018-09-11 16:21:05 +0100530 ctx.AddVariationDependencies(nil, systemModulesTag, config.DefaultSystemModules)
Paul Duffin250e6192019-06-07 10:44:37 +0100531 if sdkDep.hasFrameworkLibs() {
Colin Cross42d48b72018-08-29 14:10:52 -0700532 ctx.AddVariationDependencies(nil, libTag, config.DefaultLibraries...)
Colin Crossfa5eb232017-10-01 20:33:03 -0700533 }
Colin Cross1369cdb2017-09-29 17:58:17 -0700534 } else if sdkDep.useModule {
Tobias Thierer06dd04f2018-09-11 16:21:05 +0100535 ctx.AddVariationDependencies(nil, systemModulesTag, sdkDep.systemModules)
Colin Cross42d48b72018-08-29 14:10:52 -0700536 ctx.AddVariationDependencies(nil, bootClasspathTag, sdkDep.modules...)
Sasha Smundak2057f822019-04-16 17:16:58 -0700537 if j.deviceProperties.EffectiveOptimizeEnabled() {
Colin Cross42d48b72018-08-29 14:10:52 -0700538 ctx.AddVariationDependencies(nil, proguardRaiseTag, config.DefaultBootclasspathLibraries...)
539 ctx.AddVariationDependencies(nil, proguardRaiseTag, config.DefaultLibraries...)
Colin Cross66dbc0b2017-12-28 12:23:20 -0800540 }
Colin Crossbe1da472017-07-07 15:59:46 -0700541 }
Paul Duffine25c6442019-10-11 13:50:28 +0100542 } else if sdkDep.systemModules != "" {
Paul Duffin68289b02019-09-20 13:50:52 +0100543 // Add the system modules to both the system modules and bootclasspath.
Paul Duffine25c6442019-10-11 13:50:28 +0100544 ctx.AddVariationDependencies(nil, systemModulesTag, sdkDep.systemModules)
545 ctx.AddVariationDependencies(nil, bootClasspathTag, sdkDep.systemModules)
Colin Cross2fe66872015-03-30 17:20:39 -0700546 }
Nan Zhangb2b33de2018-02-23 11:18:47 -0800547 if ctx.ModuleName() == "android_stubs_current" ||
548 ctx.ModuleName() == "android_system_stubs_current" ||
Nan Zhang863f05b2018-08-07 13:41:10 -0700549 ctx.ModuleName() == "android_test_stubs_current" {
Colin Cross42d48b72018-08-29 14:10:52 -0700550 ctx.AddVariationDependencies(nil, frameworkApkTag, "framework-res")
Nan Zhangb2b33de2018-02-23 11:18:47 -0800551 }
Colin Cross2fe66872015-03-30 17:20:39 -0700552 }
Colin Cross1369cdb2017-09-29 17:58:17 -0700553
Colin Cross42d48b72018-08-29 14:10:52 -0700554 ctx.AddVariationDependencies(nil, libTag, j.properties.Libs...)
555 ctx.AddVariationDependencies(nil, staticLibTag, j.properties.Static_libs...)
Colin Crossa4f08812018-10-02 22:03:40 -0700556
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700557 ctx.AddFarVariationDependencies(ctx.Config().BuildOSCommonTarget.Variations(), pluginTag, j.properties.Plugins...)
Colin Crossbe9cdb82019-01-21 21:37:16 -0800558
Colin Crossfe17f6f2019-03-28 19:30:56 -0700559 android.ProtoDeps(ctx, &j.protoProperties)
Colin Cross6af17aa2017-09-20 12:59:05 -0700560 if j.hasSrcExt(".proto") {
561 protoDeps(ctx, &j.protoProperties)
562 }
Colin Cross93e85952017-08-15 13:34:18 -0700563
564 if j.hasSrcExt(".kt") {
565 // TODO(ccross): move this to a mutator pass that can tell if generated sources contain
566 // Kotlin files
Colin Cross0b03d972019-05-13 11:06:25 -0700567 ctx.AddVariationDependencies(nil, kotlinStdlibTag,
568 "kotlin-stdlib", "kotlin-stdlib-jdk7", "kotlin-stdlib-jdk8")
Colin Cross7788c122019-01-23 16:14:02 -0800569 if len(j.properties.Plugins) > 0 {
Colin Crossafbb1732019-01-17 15:42:52 -0800570 ctx.AddVariationDependencies(nil, kotlinAnnotationsTag, "kotlin-annotations")
571 }
Colin Cross93e85952017-08-15 13:34:18 -0700572 }
Colin Cross3144dfc2018-01-03 15:06:47 -0800573
574 if j.shouldInstrumentStatic(ctx) {
Colin Cross42d48b72018-08-29 14:10:52 -0700575 ctx.AddVariationDependencies(nil, staticLibTag, "jacocoagent")
Colin Cross3144dfc2018-01-03 15:06:47 -0800576 }
Colin Cross6af17aa2017-09-20 12:59:05 -0700577}
578
579func hasSrcExt(srcs []string, ext string) bool {
580 for _, src := range srcs {
581 if filepath.Ext(src) == ext {
582 return true
583 }
584 }
585
586 return false
587}
588
589func (j *Module) hasSrcExt(ext string) bool {
590 return hasSrcExt(j.properties.Srcs, ext)
Colin Cross2fe66872015-03-30 17:20:39 -0700591}
592
Colin Cross46c9b8b2017-06-22 16:51:17 -0700593func (j *Module) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.OptionalPath,
Colin Cross3047fa22019-04-18 10:56:44 -0700594 aidlIncludeDirs android.Paths) (string, android.Paths) {
Colin Crossc0b06f12015-04-08 13:03:43 -0700595
Colin Crossebe1a512017-11-14 13:12:14 -0800596 aidlIncludes := android.PathsForModuleSrc(ctx, j.deviceProperties.Aidl.Local_include_dirs)
597 aidlIncludes = append(aidlIncludes,
598 android.PathsForModuleSrc(ctx, j.deviceProperties.Aidl.Export_include_dirs)...)
599 aidlIncludes = append(aidlIncludes,
600 android.PathsForSource(ctx, j.deviceProperties.Aidl.Include_dirs)...)
Colin Crossc0b06f12015-04-08 13:03:43 -0700601
Colin Cross3047fa22019-04-18 10:56:44 -0700602 var flags []string
603 var deps android.Paths
Steven Moreland667f6882018-07-26 12:55:08 -0700604
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700605 if aidlPreprocess.Valid() {
606 flags = append(flags, "-p"+aidlPreprocess.String())
Colin Cross3047fa22019-04-18 10:56:44 -0700607 deps = append(deps, aidlPreprocess.Path())
608 } else if len(aidlIncludeDirs) > 0 {
Colin Cross635c3b02016-05-18 15:37:25 -0700609 flags = append(flags, android.JoinWithPrefix(aidlIncludeDirs.Strings(), "-I"))
Colin Crossc0b06f12015-04-08 13:03:43 -0700610 }
611
Colin Cross3047fa22019-04-18 10:56:44 -0700612 if len(j.exportAidlIncludeDirs) > 0 {
613 flags = append(flags, android.JoinWithPrefix(j.exportAidlIncludeDirs.Strings(), "-I"))
614 }
615
616 if len(aidlIncludes) > 0 {
617 flags = append(flags, android.JoinWithPrefix(aidlIncludes.Strings(), "-I"))
618 }
619
Colin Cross635c3b02016-05-18 15:37:25 -0700620 flags = append(flags, "-I"+android.PathForModuleSrc(ctx).String())
Colin Cross32f38982018-02-22 11:47:25 -0800621 if src := android.ExistentPathForSource(ctx, ctx.ModuleDir(), "src"); src.Valid() {
Colin Crossd48633a2017-07-13 14:41:17 -0700622 flags = append(flags, "-I"+src.String())
623 }
Colin Crossc0b06f12015-04-08 13:03:43 -0700624
Martijn Coeneneab15642018-03-09 09:29:59 +0100625 if Bool(j.deviceProperties.Aidl.Generate_traces) {
626 flags = append(flags, "-t")
627 }
628
Olivier Gaillard0a4cfbc2018-07-16 23:37:03 +0100629 if Bool(j.deviceProperties.Aidl.Generate_get_transaction_name) {
630 flags = append(flags, "--transaction_names")
631 }
632
Colin Cross3047fa22019-04-18 10:56:44 -0700633 return strings.Join(flags, " "), deps
Colin Crossc0b06f12015-04-08 13:03:43 -0700634}
635
Colin Cross32f676a2017-09-06 13:41:06 -0700636type deps struct {
Nan Zhang581fd212018-01-10 16:06:12 -0800637 classpath classpath
638 bootClasspath classpath
Colin Cross6a77c982018-06-19 22:43:34 -0700639 processorPath classpath
Colin Crossbe9cdb82019-01-21 21:37:16 -0800640 processorClasses []string
Colin Cross6ade34f2017-09-15 13:00:47 -0700641 staticJars android.Paths
Nan Zhanged19fc32017-10-19 13:06:22 -0700642 staticHeaderJars android.Paths
Colin Cross331a1212018-08-15 20:40:52 -0700643 staticResourceJars android.Paths
Colin Cross6ade34f2017-09-15 13:00:47 -0700644 aidlIncludeDirs android.Paths
Nan Zhangb2b33de2018-02-23 11:18:47 -0800645 srcs android.Paths
Colin Cross59149b62017-10-16 18:07:29 -0700646 srcJars android.Paths
Colin Crossb77043e2019-07-16 13:57:13 -0700647 systemModules *systemModules
Colin Cross6ade34f2017-09-15 13:00:47 -0700648 aidlPreprocess android.OptionalPath
Colin Cross93e85952017-08-15 13:34:18 -0700649 kotlinStdlib android.Paths
Colin Crossafbb1732019-01-17 15:42:52 -0800650 kotlinAnnotations android.Paths
Colin Crossbe9cdb82019-01-21 21:37:16 -0800651
652 disableTurbine bool
Colin Cross32f676a2017-09-06 13:41:06 -0700653}
Colin Cross2fe66872015-03-30 17:20:39 -0700654
Colin Cross54250902017-12-05 09:28:08 -0800655func checkProducesJars(ctx android.ModuleContext, dep android.SourceFileProducer) {
656 for _, f := range dep.Srcs() {
657 if f.Ext() != ".jar" {
658 ctx.ModuleErrorf("genrule %q must generate files ending with .jar to be used as a libs or static_libs dependency",
659 ctx.OtherModuleName(dep.(blueprint.Module)))
660 }
661 }
662}
663
Jiyong Park2d492942018-03-05 17:44:10 +0900664type linkType int
665
666const (
667 javaCore linkType = iota
668 javaSdk
669 javaSystem
670 javaPlatform
671)
672
Jiyong Park46f78fb2018-10-20 16:33:17 +0900673func getLinkType(m *Module, name string) (ret linkType, stubs bool) {
Colin Cross83bb3162018-06-25 15:48:06 -0700674 ver := m.sdkVersion()
Colin Crossf19b9bb2018-03-26 14:42:44 -0700675 switch {
Jiyong Park46f78fb2018-10-20 16:33:17 +0900676 case name == "core.current.stubs" || name == "core.platform.api.stubs" ||
677 name == "stub-annotations" || name == "private-stub-annotations-jar" ||
Pete Gillincbff3262019-05-08 15:10:06 +0100678 name == "core-lambda-stubs" || name == "core-generated-annotation-stubs":
Jiyong Park46f78fb2018-10-20 16:33:17 +0900679 return javaCore, true
Neil Fuller401eeba2018-10-18 19:48:58 +0100680 case ver == "core_current":
Jiyong Park46f78fb2018-10-20 16:33:17 +0900681 return javaCore, false
682 case name == "android_system_stubs_current":
683 return javaSystem, true
684 case strings.HasPrefix(ver, "system_"):
685 return javaSystem, false
686 case name == "android_test_stubs_current":
687 return javaSystem, true
688 case strings.HasPrefix(ver, "test_"):
689 return javaPlatform, false
690 case name == "android_stubs_current":
691 return javaSdk, true
692 case ver == "current":
693 return javaSdk, false
Paul Duffin50c217c2019-06-12 13:25:22 +0100694 case ver == "" || ver == "none" || ver == "core_platform":
Jiyong Park46f78fb2018-10-20 16:33:17 +0900695 return javaPlatform, false
Colin Crossf19b9bb2018-03-26 14:42:44 -0700696 default:
697 if _, err := strconv.Atoi(ver); err != nil {
698 panic(fmt.Errorf("expected sdk_version to be a number, got %q", ver))
699 }
Jiyong Park46f78fb2018-10-20 16:33:17 +0900700 return javaSdk, false
Jiyong Park2d492942018-03-05 17:44:10 +0900701 }
702}
703
Jiyong Park750e5572018-01-31 00:20:13 +0900704func checkLinkType(ctx android.ModuleContext, from *Module, to *Library, tag dependencyTag) {
Colin Crossf19b9bb2018-03-26 14:42:44 -0700705 if ctx.Host() {
706 return
707 }
708
Jiyong Park46f78fb2018-10-20 16:33:17 +0900709 myLinkType, stubs := getLinkType(from, ctx.ModuleName())
710 if stubs {
711 return
712 }
713 otherLinkType, _ := getLinkType(&to.Module, ctx.OtherModuleName(to))
Jiyong Park2d492942018-03-05 17:44:10 +0900714 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."
715
716 switch myLinkType {
717 case javaCore:
718 if otherLinkType != javaCore {
719 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 +0900720 ctx.OtherModuleName(to))
721 }
Jiyong Park2d492942018-03-05 17:44:10 +0900722 break
723 case javaSdk:
724 if otherLinkType != javaCore && otherLinkType != javaSdk {
725 ctx.ModuleErrorf("compiles against Android API, but dependency %q is compiling against non-public Android API."+commonMessage,
726 ctx.OtherModuleName(to))
727 }
728 break
729 case javaSystem:
730 if otherLinkType == javaPlatform {
731 ctx.ModuleErrorf("compiles against system API, but dependency %q is compiling against private API."+commonMessage,
732 ctx.OtherModuleName(to))
733 }
734 break
735 case javaPlatform:
736 // no restriction on link-type
737 break
Jiyong Park750e5572018-01-31 00:20:13 +0900738 }
739}
740
Colin Cross32f676a2017-09-06 13:41:06 -0700741func (j *Module) collectDeps(ctx android.ModuleContext) deps {
742 var deps deps
Colin Crossfc3674a2017-09-18 17:41:52 -0700743
Colin Cross300f0382018-03-06 13:11:51 -0800744 if ctx.Device() {
Colin Cross83bb3162018-06-25 15:48:06 -0700745 sdkDep := decodeSdkDep(ctx, sdkContext(j))
Colin Cross300f0382018-03-06 13:11:51 -0800746 if sdkDep.invalidVersion {
Colin Cross86a60ae2018-05-29 14:44:55 -0700747 ctx.AddMissingDependencies(sdkDep.modules)
Colin Cross300f0382018-03-06 13:11:51 -0800748 } else if sdkDep.useFiles {
749 // sdkDep.jar is actually equivalent to turbine header.jar.
Colin Cross86a60ae2018-05-29 14:44:55 -0700750 deps.classpath = append(deps.classpath, sdkDep.jars...)
Colin Cross3047fa22019-04-18 10:56:44 -0700751 deps.aidlPreprocess = sdkDep.aidl
752 } else {
753 deps.aidlPreprocess = sdkDep.aidl
Colin Cross300f0382018-03-06 13:11:51 -0800754 }
Colin Crossfc3674a2017-09-18 17:41:52 -0700755 }
756
Colin Crossd11fcda2017-10-23 17:59:01 -0700757 ctx.VisitDirectDeps(func(module android.Module) {
Colin Cross2fe66872015-03-30 17:20:39 -0700758 otherName := ctx.OtherModuleName(module)
Colin Crossec7a0422017-07-07 14:47:12 -0700759 tag := ctx.OtherModuleDependencyTag(module)
760
Colin Crossa4f08812018-10-02 22:03:40 -0700761 if _, ok := tag.(*jniDependencyTag); ok {
Colin Crossbd01e2a2018-10-04 15:21:03 -0700762 // Handled by AndroidApp.collectAppDeps
763 return
764 }
765 if tag == certificateTag {
766 // Handled by AndroidApp.collectAppDeps
Colin Crossa4f08812018-10-02 22:03:40 -0700767 return
768 }
769
Jiyong Park750e5572018-01-31 00:20:13 +0900770 if to, ok := module.(*Library); ok {
Colin Crossa97c5d32018-03-28 14:58:31 -0700771 switch tag {
772 case bootClasspathTag, libTag, staticLibTag:
773 checkLinkType(ctx, j, to, tag.(dependencyTag))
774 }
Jiyong Park750e5572018-01-31 00:20:13 +0900775 }
Colin Cross54250902017-12-05 09:28:08 -0800776 switch dep := module.(type) {
Colin Cross897d2ed2019-02-11 14:03:51 -0800777 case SdkLibraryDependency:
778 switch tag {
779 case libTag:
780 deps.classpath = append(deps.classpath, dep.SdkHeaderJars(ctx, j.sdkVersion())...)
781 // names of sdk libs that are directly depended are exported
782 j.exportedSdkLibs = append(j.exportedSdkLibs, otherName)
Colin Cross79c7c262019-04-17 11:11:46 -0700783 case staticLibTag:
Colin Cross897d2ed2019-02-11 14:03:51 -0800784 ctx.ModuleErrorf("dependency on java_sdk_library %q can only be in libs", otherName)
785 }
Colin Cross54250902017-12-05 09:28:08 -0800786 case Dependency:
787 switch tag {
788 case bootClasspathTag:
789 deps.bootClasspath = append(deps.bootClasspath, dep.HeaderJars()...)
Colin Cross4b964c02018-10-15 16:18:06 -0700790 case libTag, instrumentationForTag:
Colin Cross54250902017-12-05 09:28:08 -0800791 deps.classpath = append(deps.classpath, dep.HeaderJars()...)
Jiyong Park1be96912018-05-28 18:02:19 +0900792 // sdk lib names from dependencies are re-exported
793 j.exportedSdkLibs = append(j.exportedSdkLibs, dep.ExportedSdkLibs()...)
Colin Cross3047fa22019-04-18 10:56:44 -0700794 deps.aidlIncludeDirs = append(deps.aidlIncludeDirs, dep.AidlIncludeDirs()...)
Colin Cross54250902017-12-05 09:28:08 -0800795 case staticLibTag:
796 deps.classpath = append(deps.classpath, dep.HeaderJars()...)
797 deps.staticJars = append(deps.staticJars, dep.ImplementationJars()...)
798 deps.staticHeaderJars = append(deps.staticHeaderJars, dep.HeaderJars()...)
Colin Cross331a1212018-08-15 20:40:52 -0700799 deps.staticResourceJars = append(deps.staticResourceJars, dep.ResourceJars()...)
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 Crossbe9cdb82019-01-21 21:37:16 -0800803 case pluginTag:
804 if plugin, ok := dep.(*Plugin); ok {
805 deps.processorPath = append(deps.processorPath, dep.ImplementationAndResourcesJars()...)
806 if plugin.pluginProperties.Processor_class != nil {
807 deps.processorClasses = append(deps.processorClasses, *plugin.pluginProperties.Processor_class)
808 }
809 deps.disableTurbine = deps.disableTurbine || Bool(plugin.pluginProperties.Generates_api)
810 } else {
811 ctx.PropertyErrorf("plugins", "%q is not a java_plugin module", otherName)
812 }
Nan Zhangb2b33de2018-02-23 11:18:47 -0800813 case frameworkApkTag:
814 if ctx.ModuleName() == "android_stubs_current" ||
815 ctx.ModuleName() == "android_system_stubs_current" ||
Nan Zhang863f05b2018-08-07 13:41:10 -0700816 ctx.ModuleName() == "android_test_stubs_current" {
Nan Zhangb2b33de2018-02-23 11:18:47 -0800817 // framework stubs.jar need to depend on framework-res.apk, in order to pull the
818 // resource files out of there for aapt.
819 //
820 // Normally the package rule runs aapt, which includes the resource,
821 // but we're not running that in our package rule so just copy in the
822 // resource files here.
Colin Cross331a1212018-08-15 20:40:52 -0700823 deps.staticResourceJars = append(deps.staticResourceJars, dep.(*AndroidApp).exportPackage)
Nan Zhangb2b33de2018-02-23 11:18:47 -0800824 }
Colin Cross54250902017-12-05 09:28:08 -0800825 case kotlinStdlibTag:
Colin Cross0b03d972019-05-13 11:06:25 -0700826 deps.kotlinStdlib = append(deps.kotlinStdlib, dep.HeaderJars()...)
Colin Crossafbb1732019-01-17 15:42:52 -0800827 case kotlinAnnotationsTag:
828 deps.kotlinAnnotations = dep.HeaderJars()
Colin Cross54250902017-12-05 09:28:08 -0800829 }
830
Colin Cross54250902017-12-05 09:28:08 -0800831 case android.SourceFileProducer:
832 switch tag {
833 case libTag:
834 checkProducesJars(ctx, dep)
835 deps.classpath = append(deps.classpath, dep.Srcs()...)
836 case staticLibTag:
837 checkProducesJars(ctx, dep)
838 deps.classpath = append(deps.classpath, dep.Srcs()...)
839 deps.staticJars = append(deps.staticJars, dep.Srcs()...)
840 deps.staticHeaderJars = append(deps.staticHeaderJars, dep.Srcs()...)
Colin Cross54250902017-12-05 09:28:08 -0800841 }
842 default:
Colin Crossec7a0422017-07-07 14:47:12 -0700843 switch tag {
Paul Duffin68289b02019-09-20 13:50:52 +0100844 case bootClasspathTag:
845 // If a system modules dependency has been added to the bootclasspath
846 // then add its libs to the bootclasspath.
847 sm := module.(*SystemModules)
848 deps.bootClasspath = append(deps.bootClasspath, sm.headerJars...)
849
Colin Cross1369cdb2017-09-29 17:58:17 -0700850 case systemModulesTag:
851 if deps.systemModules != nil {
852 panic("Found two system module dependencies")
853 }
854 sm := module.(*SystemModules)
Dan Willemsenff60a732019-06-13 16:52:01 +0000855 if sm.outputDir == nil || len(sm.outputDeps) == 0 {
Colin Cross1369cdb2017-09-29 17:58:17 -0700856 panic("Missing directory for system module dependency")
857 }
Colin Crossb77043e2019-07-16 13:57:13 -0700858 deps.systemModules = &systemModules{sm.outputDir, sm.outputDeps}
Colin Cross2fe66872015-03-30 17:20:39 -0700859 }
Colin Crossec7a0422017-07-07 14:47:12 -0700860 }
Colin Cross2fe66872015-03-30 17:20:39 -0700861 })
862
Jiyong Park1be96912018-05-28 18:02:19 +0900863 j.exportedSdkLibs = android.FirstUniqueStrings(j.exportedSdkLibs)
864
Colin Cross32f676a2017-09-06 13:41:06 -0700865 return deps
Colin Cross2fe66872015-03-30 17:20:39 -0700866}
867
Colin Cross1e743852019-10-28 11:37:20 -0700868func getJavaVersion(ctx android.ModuleContext, javaVersion string, sdkContext sdkContext) javaVersion {
Colin Cross98fd5742019-01-09 23:04:25 -0800869 v := sdkContext.sdkVersion()
870 // For PDK builds, use the latest SDK version instead of "current"
Paul Duffin50c217c2019-06-12 13:25:22 +0100871 if ctx.Config().IsPdkBuild() &&
872 (v == "" || v == "none" || v == "core_platform" || v == "current") {
Colin Cross3047fa22019-04-18 10:56:44 -0700873 sdkVersions := ctx.Config().Get(sdkVersionsKey).([]int)
Colin Cross98fd5742019-01-09 23:04:25 -0800874 latestSdkVersion := 0
875 if len(sdkVersions) > 0 {
876 latestSdkVersion = sdkVersions[len(sdkVersions)-1]
877 }
878 v = strconv.Itoa(latestSdkVersion)
879 }
880
881 sdk, err := sdkVersionToNumber(ctx, v)
Colin Cross83bb3162018-06-25 15:48:06 -0700882 if err != nil {
883 ctx.PropertyErrorf("sdk_version", "%s", err)
884 }
Nan Zhang357466b2018-04-17 17:38:36 -0700885 if javaVersion != "" {
Colin Cross1e743852019-10-28 11:37:20 -0700886 return normalizeJavaVersion(ctx, javaVersion)
Nan Zhang357466b2018-04-17 17:38:36 -0700887 } else if ctx.Device() && sdk <= 23 {
Colin Cross1e743852019-10-28 11:37:20 -0700888 return JAVA_VERSION_7
Pete Gillina1c9e9d2019-10-17 14:52:07 +0100889 } else if ctx.Device() && sdk <= 29 {
Colin Cross1e743852019-10-28 11:37:20 -0700890 return JAVA_VERSION_8
Paul Duffin50c217c2019-06-12 13:25:22 +0100891 } else if ctx.Device() &&
892 sdkContext.sdkVersion() != "" &&
893 sdkContext.sdkVersion() != "none" &&
894 sdkContext.sdkVersion() != "core_platform" &&
895 sdk == android.FutureApiLevel {
Nan Zhang357466b2018-04-17 17:38:36 -0700896 // TODO(ccross): once we generate stubs we should be able to use 1.9 for sdk_version: "current"
Colin Cross1e743852019-10-28 11:37:20 -0700897 return JAVA_VERSION_8
Nan Zhang357466b2018-04-17 17:38:36 -0700898 } else {
Colin Cross1e743852019-10-28 11:37:20 -0700899 return JAVA_VERSION_9
Nan Zhang357466b2018-04-17 17:38:36 -0700900 }
Nan Zhang357466b2018-04-17 17:38:36 -0700901}
902
Colin Cross1e743852019-10-28 11:37:20 -0700903type javaVersion int
904
905const (
906 JAVA_VERSION_UNSUPPORTED = 0
907 JAVA_VERSION_6 = 6
908 JAVA_VERSION_7 = 7
909 JAVA_VERSION_8 = 8
910 JAVA_VERSION_9 = 9
911)
912
913func (v javaVersion) String() string {
914 switch v {
915 case JAVA_VERSION_6:
916 return "1.6"
917 case JAVA_VERSION_7:
918 return "1.7"
919 case JAVA_VERSION_8:
920 return "1.8"
921 case JAVA_VERSION_9:
922 return "1.9"
923 default:
924 return "unsupported"
925 }
926}
927
928// Returns true if javac targeting this version uses system modules instead of a bootclasspath.
929func (v javaVersion) usesJavaModules() bool {
930 return v >= 9
931}
932
933func normalizeJavaVersion(ctx android.BaseModuleContext, javaVersion string) javaVersion {
Pete Gillin4e8b48a2019-07-12 13:16:17 +0100934 switch javaVersion {
935 case "1.6", "6":
Colin Cross1e743852019-10-28 11:37:20 -0700936 return JAVA_VERSION_6
Pete Gillin4e8b48a2019-07-12 13:16:17 +0100937 case "1.7", "7":
Colin Cross1e743852019-10-28 11:37:20 -0700938 return JAVA_VERSION_7
Pete Gillin4e8b48a2019-07-12 13:16:17 +0100939 case "1.8", "8":
Colin Cross1e743852019-10-28 11:37:20 -0700940 return JAVA_VERSION_8
Pete Gillin4e8b48a2019-07-12 13:16:17 +0100941 case "1.9", "9":
Colin Cross1e743852019-10-28 11:37:20 -0700942 return JAVA_VERSION_9
Pete Gillin4e8b48a2019-07-12 13:16:17 +0100943 case "10", "11":
944 ctx.PropertyErrorf("java_version", "Java language levels above 9 are not supported")
Colin Cross1e743852019-10-28 11:37:20 -0700945 return JAVA_VERSION_UNSUPPORTED
Pete Gillin4e8b48a2019-07-12 13:16:17 +0100946 default:
947 ctx.PropertyErrorf("java_version", "Unrecognized Java language level")
Colin Cross1e743852019-10-28 11:37:20 -0700948 return JAVA_VERSION_UNSUPPORTED
Pete Gillin4e8b48a2019-07-12 13:16:17 +0100949 }
950}
951
Nan Zhanged19fc32017-10-19 13:06:22 -0700952func (j *Module) collectBuilderFlags(ctx android.ModuleContext, deps deps) javaBuilderFlags {
Colin Crossc0b06f12015-04-08 13:03:43 -0700953
Colin Crossf03c82b2015-04-13 13:53:40 -0700954 var flags javaBuilderFlags
955
Tobias Thierer06dd04f2018-09-11 16:21:05 +0100956 // javaVersion flag.
957 flags.javaVersion = getJavaVersion(ctx, String(j.properties.Java_version), sdkContext(j))
958
Nan Zhanged19fc32017-10-19 13:06:22 -0700959 // javac flags.
Colin Crossf03c82b2015-04-13 13:53:40 -0700960 javacFlags := j.properties.Javacflags
Colin Cross1e743852019-10-28 11:37:20 -0700961 if flags.javaVersion.usesJavaModules() {
Colin Cross1369cdb2017-09-29 17:58:17 -0700962 javacFlags = append(javacFlags, j.properties.Openjdk9.Javacflags...)
Nan Zhanged19fc32017-10-19 13:06:22 -0700963 }
Colin Cross6510f912017-11-29 00:27:14 -0800964 if ctx.Config().MinimizeJavaDebugInfo() {
Colin Cross126a25c2017-10-31 13:55:34 -0700965 // Override the -g flag passed globally to remove local variable debug info to reduce
966 // disk and memory usage.
967 javacFlags = append(javacFlags, "-g:source,lines")
968 }
Colin Cross64162712017-08-08 13:17:59 -0700969
Colin Cross66548102018-06-19 22:47:35 -0700970 if ctx.Config().RunErrorProne() {
971 if config.ErrorProneClasspath == nil {
972 ctx.ModuleErrorf("cannot build with Error Prone, missing external/error_prone?")
973 }
974
975 errorProneFlags := []string{
976 "-Xplugin:ErrorProne",
977 "${config.ErrorProneChecks}",
978 }
979 errorProneFlags = append(errorProneFlags, j.properties.Errorprone.Javacflags...)
980
981 flags.errorProneExtraJavacFlags = "${config.ErrorProneFlags} " +
982 "'" + strings.Join(errorProneFlags, " ") + "'"
983 flags.errorProneProcessorPath = classpath(android.PathsForSource(ctx, config.ErrorProneClasspath))
Andreas Gampef3e5b552018-01-22 21:27:21 -0800984 }
985
Nan Zhanged19fc32017-10-19 13:06:22 -0700986 // classpath
Nan Zhang581fd212018-01-10 16:06:12 -0800987 flags.bootClasspath = append(flags.bootClasspath, deps.bootClasspath...)
988 flags.classpath = append(flags.classpath, deps.classpath...)
Colin Cross6a77c982018-06-19 22:43:34 -0700989 flags.processorPath = append(flags.processorPath, deps.processorPath...)
Colin Cross7fdd2b72018-01-02 18:14:25 -0800990
Colin Crossbe9cdb82019-01-21 21:37:16 -0800991 flags.processor = strings.Join(deps.processorClasses, ",")
992
Colin Cross1e743852019-10-28 11:37:20 -0700993 if len(flags.bootClasspath) == 0 && ctx.Host() && !flags.javaVersion.usesJavaModules() &&
994 decodeSdkDep(ctx, sdkContext(j)).hasStandardLibs() {
Colin Cross7fdd2b72018-01-02 18:14:25 -0800995 // Give host-side tools a version of OpenJDK's standard libraries
996 // close to what they're targeting. As of Dec 2017, AOSP is only
997 // bundling OpenJDK 8 and 9, so nothing < 8 is available.
998 //
999 // When building with OpenJDK 8, the following should have no
1000 // effect since those jars would be available by default.
1001 //
1002 // When building with OpenJDK 9 but targeting a version < 1.8,
1003 // putting them on the bootclasspath means that:
1004 // a) code can't (accidentally) refer to OpenJDK 9 specific APIs
1005 // b) references to existing APIs are not reinterpreted in an
1006 // OpenJDK 9-specific way, eg. calls to subclasses of
1007 // java.nio.Buffer as in http://b/70862583
1008 java8Home := ctx.Config().Getenv("ANDROID_JAVA8_HOME")
1009 flags.bootClasspath = append(flags.bootClasspath,
1010 android.PathForSource(ctx, java8Home, "jre/lib/jce.jar"),
1011 android.PathForSource(ctx, java8Home, "jre/lib/rt.jar"))
Nan Zhang5f8cb422018-02-06 10:34:32 -08001012 if Bool(j.properties.Use_tools_jar) {
1013 flags.bootClasspath = append(flags.bootClasspath,
1014 android.PathForSource(ctx, java8Home, "lib/tools.jar"))
1015 }
Colin Cross7fdd2b72018-01-02 18:14:25 -08001016 }
1017
Colin Cross1e743852019-10-28 11:37:20 -07001018 if j.properties.Patch_module != nil && flags.javaVersion.usesJavaModules() {
Jaewoong Jung38e4fb22018-12-12 09:01:34 -08001019 // Manually specify build directory in case it is not under the repo root.
1020 // (javac doesn't seem to expand into symbolc links when searching for patch-module targets, so
1021 // just adding a symlink under the root doesn't help.)
1022 patchPaths := ".:" + ctx.Config().BuildDir()
1023 classPath := flags.classpath.FormJavaClassPath("")
1024 if classPath != "" {
1025 patchPaths += ":" + classPath
1026 }
1027 javacFlags = append(javacFlags, "--patch-module="+String(j.properties.Patch_module)+"="+patchPaths)
Colin Cross81440082018-08-15 20:21:55 -07001028 }
1029
Nan Zhanged19fc32017-10-19 13:06:22 -07001030 // systemModules
Colin Crossb77043e2019-07-16 13:57:13 -07001031 flags.systemModules = deps.systemModules
Colin Cross1369cdb2017-09-29 17:58:17 -07001032
Nan Zhanged19fc32017-10-19 13:06:22 -07001033 // aidl flags.
Colin Cross3047fa22019-04-18 10:56:44 -07001034 flags.aidlFlags, flags.aidlDeps = j.aidlFlags(ctx, deps.aidlPreprocess, deps.aidlIncludeDirs)
Colin Cross2fe66872015-03-30 17:20:39 -07001035
Colin Cross81440082018-08-15 20:21:55 -07001036 if len(javacFlags) > 0 {
1037 // optimization.
1038 ctx.Variable(pctx, "javacFlags", strings.Join(javacFlags, " "))
1039 flags.javacFlags = "$javacFlags"
1040 }
1041
Nan Zhanged19fc32017-10-19 13:06:22 -07001042 return flags
1043}
Colin Crossc0b06f12015-04-08 13:03:43 -07001044
Jaewoong Junga24af3b2019-05-13 09:23:20 -07001045func (j *Module) compile(ctx android.ModuleContext, aaptSrcJar android.Path) {
Colin Crossebe1a512017-11-14 13:12:14 -08001046 j.exportAidlIncludeDirs = android.PathsForModuleSrc(ctx, j.deviceProperties.Aidl.Export_include_dirs)
Nan Zhanged19fc32017-10-19 13:06:22 -07001047
1048 deps := j.collectDeps(ctx)
1049 flags := j.collectBuilderFlags(ctx, deps)
1050
Colin Cross1e743852019-10-28 11:37:20 -07001051 if flags.javaVersion.usesJavaModules() {
Nan Zhanged19fc32017-10-19 13:06:22 -07001052 j.properties.Srcs = append(j.properties.Srcs, j.properties.Openjdk9.Srcs...)
1053 }
Colin Cross8a497952019-03-05 22:25:09 -08001054 srcFiles := android.PathsForModuleSrcExcludes(ctx, j.properties.Srcs, j.properties.Exclude_srcs)
Colin Cross6af17aa2017-09-20 12:59:05 -07001055 if hasSrcExt(srcFiles.Strings(), ".proto") {
Colin Cross0f2ee152017-12-14 15:22:43 -08001056 flags = protoFlags(ctx, &j.properties, &j.protoProperties, flags)
Colin Cross6af17aa2017-09-20 12:59:05 -07001057 }
1058
Colin Crossaf050172017-11-15 23:01:59 -08001059 srcFiles = j.genSources(ctx, srcFiles, flags)
1060
1061 srcJars := srcFiles.FilterByExt(".srcjar")
Colin Cross59149b62017-10-16 18:07:29 -07001062 srcJars = append(srcJars, deps.srcJars...)
Jaewoong Junga24af3b2019-05-13 09:23:20 -07001063 if aaptSrcJar != nil {
1064 srcJars = append(srcJars, aaptSrcJar)
1065 }
Colin Crossb7a63242015-04-16 14:09:14 -07001066
Steven Morelandc4efd9c2019-01-18 11:51:25 -08001067 if j.properties.Jarjar_rules != nil {
Colin Cross8a497952019-03-05 22:25:09 -08001068 j.expandJarjarRules = android.PathForModuleSrc(ctx, *j.properties.Jarjar_rules)
Steven Morelandc4efd9c2019-01-18 11:51:25 -08001069 }
1070
Colin Cross1ee23172017-10-18 14:44:18 -07001071 jarName := ctx.ModuleName() + ".jar"
1072
Przemyslaw Szczepaniak4b5fe9d2018-02-13 14:32:54 +00001073 javaSrcFiles := srcFiles.FilterByExt(".java")
1074 var uniqueSrcFiles android.Paths
1075 set := make(map[string]bool)
1076 for _, v := range javaSrcFiles {
1077 if _, found := set[v.String()]; !found {
1078 set[v.String()] = true
1079 uniqueSrcFiles = append(uniqueSrcFiles, v)
1080 }
1081 }
1082
patricktu242faad2019-09-24 15:41:30 +08001083 // Collect .java files for AIDEGen
1084 j.expandIDEInfoCompiledSrcs = append(j.expandIDEInfoCompiledSrcs, uniqueSrcFiles.Strings()...)
1085
Colin Cross55f63ea2018-08-27 12:37:09 -07001086 var kotlinJars android.Paths
1087
Colin Cross93e85952017-08-15 13:34:18 -07001088 if srcFiles.HasExt(".kt") {
Zoran Jovanovic8736ce22018-08-21 17:10:29 +02001089 // user defined kotlin flags.
1090 kotlincFlags := j.properties.Kotlincflags
1091 CheckKotlincFlags(ctx, kotlincFlags)
1092
Colin Cross93e85952017-08-15 13:34:18 -07001093 // If there are kotlin files, compile them first but pass all the kotlin and java files
1094 // kotlinc will use the java files to resolve types referenced by the kotlin files, but
1095 // won't emit any classes for them.
Zoran Jovanovic8736ce22018-08-21 17:10:29 +02001096 kotlincFlags = append(kotlincFlags, "-no-stdlib")
Colin Cross93e85952017-08-15 13:34:18 -07001097 if ctx.Device() {
Zoran Jovanovic8736ce22018-08-21 17:10:29 +02001098 kotlincFlags = append(kotlincFlags, "-no-jdk")
1099 }
1100 if len(kotlincFlags) > 0 {
1101 // optimization.
1102 ctx.Variable(pctx, "kotlincFlags", strings.Join(kotlincFlags, " "))
1103 flags.kotlincFlags += "$kotlincFlags"
Colin Cross93e85952017-08-15 13:34:18 -07001104 }
1105
Przemyslaw Szczepaniak4b5fe9d2018-02-13 14:32:54 +00001106 var kotlinSrcFiles android.Paths
1107 kotlinSrcFiles = append(kotlinSrcFiles, uniqueSrcFiles...)
1108 kotlinSrcFiles = append(kotlinSrcFiles, srcFiles.FilterByExt(".kt")...)
1109
patricktu242faad2019-09-24 15:41:30 +08001110 // Collect .kt files for AIDEGen
1111 j.expandIDEInfoCompiledSrcs = append(j.expandIDEInfoCompiledSrcs, srcFiles.FilterByExt(".kt").Strings()...)
1112
Colin Crossafbb1732019-01-17 15:42:52 -08001113 flags.classpath = append(flags.classpath, deps.kotlinStdlib...)
1114 flags.classpath = append(flags.classpath, deps.kotlinAnnotations...)
1115
1116 flags.kotlincClasspath = append(flags.kotlincClasspath, flags.bootClasspath...)
1117 flags.kotlincClasspath = append(flags.kotlincClasspath, flags.classpath...)
1118
1119 if len(flags.processorPath) > 0 {
1120 // Use kapt for annotation processing
1121 kaptSrcJar := android.PathForModuleOut(ctx, "kapt", "kapt-sources.jar")
1122 kotlinKapt(ctx, kaptSrcJar, kotlinSrcFiles, srcJars, flags)
1123 srcJars = append(srcJars, kaptSrcJar)
1124 // Disable annotation processing in javac, it's already been handled by kapt
1125 flags.processorPath = nil
Colin Cross3a3e94c2019-01-23 15:39:50 -08001126 flags.processor = ""
Colin Crossafbb1732019-01-17 15:42:52 -08001127 }
Colin Cross93e85952017-08-15 13:34:18 -07001128
Colin Cross1ee23172017-10-18 14:44:18 -07001129 kotlinJar := android.PathForModuleOut(ctx, "kotlin", jarName)
Colin Cross21fc9bb2019-01-18 15:05:09 -08001130 kotlinCompile(ctx, kotlinJar, kotlinSrcFiles, srcJars, flags)
Colin Cross93e85952017-08-15 13:34:18 -07001131 if ctx.Failed() {
1132 return
1133 }
1134
1135 // Make javac rule depend on the kotlinc rule
1136 flags.classpath = append(flags.classpath, kotlinJar)
Przemyslaw Szczepaniak66c0c402018-03-08 13:21:55 +00001137
Colin Cross93e85952017-08-15 13:34:18 -07001138 // Jar kotlin classes into the final jar after javac
Colin Cross55f63ea2018-08-27 12:37:09 -07001139 kotlinJars = append(kotlinJars, kotlinJar)
Colin Cross9b38aef2018-08-27 15:42:25 -07001140 kotlinJars = append(kotlinJars, deps.kotlinStdlib...)
Colin Cross93e85952017-08-15 13:34:18 -07001141 }
1142
Colin Cross55f63ea2018-08-27 12:37:09 -07001143 jars := append(android.Paths(nil), kotlinJars...)
1144
Colin Cross5ab4e6d2017-11-22 16:20:45 -08001145 // Store the list of .java files that was passed to javac
1146 j.compiledJavaSrcs = uniqueSrcFiles
1147 j.compiledSrcJars = srcJars
1148
Nan Zhang61eaedb2017-11-02 13:28:15 -07001149 enable_sharding := false
Colin Crossbe9cdb82019-01-21 21:37:16 -08001150 if ctx.Device() && !ctx.Config().IsEnvFalse("TURBINE_ENABLED") && !deps.disableTurbine {
Nan Zhang61eaedb2017-11-02 13:28:15 -07001151 if j.properties.Javac_shard_size != nil && *(j.properties.Javac_shard_size) > 0 {
1152 enable_sharding = true
Ashley Rosee36efcf2019-01-16 17:34:08 -05001153 // Formerly, there was a check here that prevented annotation processors
1154 // from being used when sharding was enabled, as some annotation processors
1155 // do not function correctly in sharded environments. It was removed to
1156 // allow for the use of annotation processors that do function correctly
1157 // with sharding enabled. See: b/77284273.
Nan Zhang61eaedb2017-11-02 13:28:15 -07001158 }
Colin Cross55f63ea2018-08-27 12:37:09 -07001159 j.headerJarFile = j.compileJavaHeader(ctx, uniqueSrcFiles, srcJars, deps, flags, jarName, kotlinJars)
Colin Crossf19b9bb2018-03-26 14:42:44 -07001160 if ctx.Failed() {
1161 return
Nan Zhanged19fc32017-10-19 13:06:22 -07001162 }
1163 }
Colin Cross8eadbf02017-10-24 17:46:00 -07001164 if len(uniqueSrcFiles) > 0 || len(srcJars) > 0 {
Colin Crossd6891432017-09-27 17:39:56 -07001165 var extraJarDeps android.Paths
Colin Cross66548102018-06-19 22:47:35 -07001166 if ctx.Config().RunErrorProne() {
Colin Crossc6bbef32017-08-14 14:16:06 -07001167 // If error-prone is enabled, add an additional rule to compile the java files into
1168 // a separate set of classes (so that they don't overwrite the normal ones and require
Colin Crossd6891432017-09-27 17:39:56 -07001169 // a rebuild when error-prone is turned off).
Colin Crossc6bbef32017-08-14 14:16:06 -07001170 // TODO(ccross): Once we always compile with javac9 we may be able to conditionally
1171 // enable error-prone without affecting the output class files.
Colin Cross1ee23172017-10-18 14:44:18 -07001172 errorprone := android.PathForModuleOut(ctx, "errorprone", jarName)
Nan Zhang61eaedb2017-11-02 13:28:15 -07001173 RunErrorProne(ctx, errorprone, uniqueSrcFiles, srcJars, flags)
Colin Crossc6bbef32017-08-14 14:16:06 -07001174 extraJarDeps = append(extraJarDeps, errorprone)
1175 }
1176
Nan Zhang61eaedb2017-11-02 13:28:15 -07001177 if enable_sharding {
Nan Zhang581fd212018-01-10 16:06:12 -08001178 flags.classpath = append(flags.classpath, j.headerJarFile)
Nan Zhang61eaedb2017-11-02 13:28:15 -07001179 shardSize := int(*(j.properties.Javac_shard_size))
1180 var shardSrcs []android.Paths
1181 if len(uniqueSrcFiles) > 0 {
Colin Cross0a2f7192019-09-23 14:33:09 -07001182 shardSrcs = android.ShardPaths(uniqueSrcFiles, shardSize)
Nan Zhang61eaedb2017-11-02 13:28:15 -07001183 for idx, shardSrc := range shardSrcs {
Colin Cross3b706fd2019-09-05 16:44:18 -07001184 classes := j.compileJavaClasses(ctx, jarName, idx, shardSrc,
1185 nil, flags, extraJarDeps)
Nan Zhang61eaedb2017-11-02 13:28:15 -07001186 jars = append(jars, classes)
1187 }
1188 }
1189 if len(srcJars) > 0 {
Colin Cross3b706fd2019-09-05 16:44:18 -07001190 classes := j.compileJavaClasses(ctx, jarName, len(shardSrcs),
1191 nil, srcJars, flags, extraJarDeps)
Nan Zhang61eaedb2017-11-02 13:28:15 -07001192 jars = append(jars, classes)
1193 }
1194 } else {
Colin Cross3b706fd2019-09-05 16:44:18 -07001195 classes := j.compileJavaClasses(ctx, jarName, -1, uniqueSrcFiles, srcJars, flags, extraJarDeps)
Nan Zhang61eaedb2017-11-02 13:28:15 -07001196 jars = append(jars, classes)
1197 }
Colin Crossd6891432017-09-27 17:39:56 -07001198 if ctx.Failed() {
1199 return
1200 }
Colin Cross2fe66872015-03-30 17:20:39 -07001201 }
1202
Colin Cross0c4ce212019-05-03 15:28:19 -07001203 j.srcJarArgs, j.srcJarDeps = resourcePathsToJarArgs(srcFiles), srcFiles
1204
1205 var includeSrcJar android.WritablePath
1206 if Bool(j.properties.Include_srcs) {
1207 includeSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+".srcjar")
1208 TransformResourcesToJar(ctx, includeSrcJar, j.srcJarArgs, j.srcJarDeps)
1209 }
1210
Colin Crosscedd4762018-09-13 11:26:19 -07001211 dirArgs, dirDeps := ResourceDirsToJarArgs(ctx, j.properties.Java_resource_dirs,
1212 j.properties.Exclude_java_resource_dirs, j.properties.Exclude_java_resources)
Colin Cross0f37af02017-09-27 17:42:05 -07001213 fileArgs, fileDeps := ResourceFilesToJarArgs(ctx, j.properties.Java_resources, j.properties.Exclude_java_resources)
Colin Cross988708c2019-05-06 14:04:11 -07001214 extraArgs, extraDeps := resourcePathsToJarArgs(j.extraResources), j.extraResources
Colin Cross0f37af02017-09-27 17:42:05 -07001215
1216 var resArgs []string
1217 var resDeps android.Paths
1218
1219 resArgs = append(resArgs, dirArgs...)
1220 resDeps = append(resDeps, dirDeps...)
1221
1222 resArgs = append(resArgs, fileArgs...)
1223 resDeps = append(resDeps, fileDeps...)
1224
Colin Cross988708c2019-05-06 14:04:11 -07001225 resArgs = append(resArgs, extraArgs...)
1226 resDeps = append(resDeps, extraDeps...)
1227
Colin Cross40a36712017-09-27 17:41:35 -07001228 if len(resArgs) > 0 {
Colin Cross1ee23172017-10-18 14:44:18 -07001229 resourceJar := android.PathForModuleOut(ctx, "res", jarName)
Colin Crosse9a275b2017-10-16 17:09:48 -07001230 TransformResourcesToJar(ctx, resourceJar, resArgs, resDeps)
Colin Cross331a1212018-08-15 20:40:52 -07001231 j.resourceJar = resourceJar
Colin Cross65bf4f22015-04-03 16:54:17 -07001232 if ctx.Failed() {
1233 return
1234 }
1235 }
1236
Colin Cross0c4ce212019-05-03 15:28:19 -07001237 var resourceJars android.Paths
1238 if j.resourceJar != nil {
1239 resourceJars = append(resourceJars, j.resourceJar)
1240 }
1241 if Bool(j.properties.Include_srcs) {
1242 resourceJars = append(resourceJars, includeSrcJar)
1243 }
1244 resourceJars = append(resourceJars, deps.staticResourceJars...)
Colin Cross331a1212018-08-15 20:40:52 -07001245
Colin Cross0c4ce212019-05-03 15:28:19 -07001246 if len(resourceJars) > 1 {
Colin Cross331a1212018-08-15 20:40:52 -07001247 combinedJar := android.PathForModuleOut(ctx, "res-combined", jarName)
Colin Cross0c4ce212019-05-03 15:28:19 -07001248 TransformJarsToJar(ctx, combinedJar, "for resources", resourceJars, android.OptionalPath{},
Colin Cross331a1212018-08-15 20:40:52 -07001249 false, nil, nil)
1250 j.resourceJar = combinedJar
Colin Cross0c4ce212019-05-03 15:28:19 -07001251 } else if len(resourceJars) == 1 {
1252 j.resourceJar = resourceJars[0]
Colin Cross331a1212018-08-15 20:40:52 -07001253 }
1254
Jaewoong Junga24af3b2019-05-13 09:23:20 -07001255 if len(deps.staticJars) > 0 {
1256 jars = append(jars, deps.staticJars...)
Jaewoong Junga24af3b2019-05-13 09:23:20 -07001257 }
Colin Cross0a6e0072017-08-30 14:24:55 -07001258
Colin Cross094054a2018-10-17 15:10:48 -07001259 manifest := j.overrideManifest
1260 if !manifest.Valid() && j.properties.Manifest != nil {
Colin Cross8a497952019-03-05 22:25:09 -08001261 manifest = android.OptionalPathForPath(android.PathForModuleSrc(ctx, *j.properties.Manifest))
Colin Cross366938f2017-12-11 16:29:02 -08001262 }
Colin Cross635acc92017-09-12 22:50:46 -07001263
Colin Cross8a497952019-03-05 22:25:09 -08001264 services := android.PathsForModuleSrc(ctx, j.properties.Services)
Alex Light7f004a72019-02-21 13:27:37 -08001265 if len(services) > 0 {
1266 servicesJar := android.PathForModuleOut(ctx, "services", jarName)
1267 var zipargs []string
1268 for _, file := range services {
1269 serviceFile := file.String()
1270 zipargs = append(zipargs, "-C", filepath.Dir(serviceFile), "-f", serviceFile)
1271 }
1272 ctx.Build(pctx, android.BuildParams{
1273 Rule: zip,
1274 Output: servicesJar,
1275 Implicits: services,
1276 Args: map[string]string{
Colin Cross0b9f31f2019-02-28 11:00:01 -08001277 "jarArgs": "-P META-INF/services/ " + strings.Join(proptools.NinjaAndShellEscapeList(zipargs), " "),
Alex Light7f004a72019-02-21 13:27:37 -08001278 },
1279 })
1280 jars = append(jars, servicesJar)
1281 }
1282
Colin Cross0a6e0072017-08-30 14:24:55 -07001283 // Combine the classes built from sources, any manifests, and any static libraries into
Nan Zhanged19fc32017-10-19 13:06:22 -07001284 // classes.jar. If there is only one input jar this step will be skipped.
Colin Cross3063b782018-08-15 11:19:12 -07001285 var outputFile android.ModuleOutPath
Colin Crosse9a275b2017-10-16 17:09:48 -07001286
1287 if len(jars) == 1 && !manifest.Valid() {
Colin Cross3063b782018-08-15 11:19:12 -07001288 if moduleOutPath, ok := jars[0].(android.ModuleOutPath); ok {
1289 // Optimization: skip the combine step if there is nothing to do
1290 // TODO(ccross): this leaves any module-info.class files, but those should only come from
1291 // prebuilt dependencies until we support modules in the platform build, so there shouldn't be
1292 // any if len(jars) == 1.
1293 outputFile = moduleOutPath
1294 } else {
1295 combinedJar := android.PathForModuleOut(ctx, "combined", jarName)
1296 ctx.Build(pctx, android.BuildParams{
1297 Rule: android.Cp,
1298 Input: jars[0],
1299 Output: combinedJar,
1300 })
1301 outputFile = combinedJar
1302 }
Colin Crosse9a275b2017-10-16 17:09:48 -07001303 } else {
Colin Cross1ee23172017-10-18 14:44:18 -07001304 combinedJar := android.PathForModuleOut(ctx, "combined", jarName)
Colin Cross37f6d792018-07-12 12:28:41 -07001305 TransformJarsToJar(ctx, combinedJar, "for javac", jars, manifest,
Colin Cross9b38aef2018-08-27 15:42:25 -07001306 false, nil, nil)
Colin Crosse9a275b2017-10-16 17:09:48 -07001307 outputFile = combinedJar
1308 }
Colin Cross0a6e0072017-08-30 14:24:55 -07001309
Colin Cross331a1212018-08-15 20:40:52 -07001310 // jarjar implementation jar if necessary
Steven Morelandc4efd9c2019-01-18 11:51:25 -08001311 if j.expandJarjarRules != nil {
Colin Cross8649b262017-09-27 18:03:17 -07001312 // Transform classes.jar into classes-jarjar.jar
Colin Cross1ee23172017-10-18 14:44:18 -07001313 jarjarFile := android.PathForModuleOut(ctx, "jarjar", jarName)
Steven Morelandc4efd9c2019-01-18 11:51:25 -08001314 TransformJarJar(ctx, jarjarFile, outputFile, j.expandJarjarRules)
Colin Crosse9a275b2017-10-16 17:09:48 -07001315 outputFile = jarjarFile
Colin Cross331a1212018-08-15 20:40:52 -07001316
1317 // jarjar resource jar if necessary
1318 if j.resourceJar != nil {
1319 resourceJarJarFile := android.PathForModuleOut(ctx, "res-jarjar", jarName)
Steven Morelandc4efd9c2019-01-18 11:51:25 -08001320 TransformJarJar(ctx, resourceJarJarFile, j.resourceJar, j.expandJarjarRules)
Colin Cross331a1212018-08-15 20:40:52 -07001321 j.resourceJar = resourceJarJarFile
1322 }
1323
Colin Cross0a6e0072017-08-30 14:24:55 -07001324 if ctx.Failed() {
1325 return
1326 }
1327 }
Vladimir Marko0975ee02019-04-02 10:29:55 +01001328
1329 // Check package restrictions if necessary.
1330 if len(j.properties.Permitted_packages) > 0 {
1331 // Check packages and copy to package-checked file.
1332 pkgckFile := android.PathForModuleOut(ctx, "package-check.stamp")
1333 CheckJarPackages(ctx, pkgckFile, outputFile, j.properties.Permitted_packages)
1334 j.additionalCheckedModules = append(j.additionalCheckedModules, pkgckFile)
1335
1336 if ctx.Failed() {
1337 return
1338 }
1339 }
1340
Nan Zhanged19fc32017-10-19 13:06:22 -07001341 j.implementationJarFile = outputFile
1342 if j.headerJarFile == nil {
1343 j.headerJarFile = j.implementationJarFile
1344 }
Colin Cross2fe66872015-03-30 17:20:39 -07001345
Colin Cross6510f912017-11-29 00:27:14 -08001346 if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
Colin Crosscb933592017-11-22 13:49:43 -08001347 if inList(ctx.ModuleName(), config.InstrumentFrameworkModules) {
1348 j.properties.Instrument = true
1349 }
1350 }
1351
Colin Cross3144dfc2018-01-03 15:06:47 -08001352 if j.shouldInstrument(ctx) {
Colin Crosscb933592017-11-22 13:49:43 -08001353 outputFile = j.instrument(ctx, flags, outputFile, jarName)
1354 }
1355
Colin Cross331a1212018-08-15 20:40:52 -07001356 // merge implementation jar with resources if necessary
1357 implementationAndResourcesJar := outputFile
1358 if j.resourceJar != nil {
Colin Cross08a409d2019-04-29 10:22:44 -07001359 jars := android.Paths{j.resourceJar, implementationAndResourcesJar}
Colin Cross331a1212018-08-15 20:40:52 -07001360 combinedJar := android.PathForModuleOut(ctx, "withres", jarName)
Colin Cross08a409d2019-04-29 10:22:44 -07001361 TransformJarsToJar(ctx, combinedJar, "for resources", jars, manifest,
Colin Cross331a1212018-08-15 20:40:52 -07001362 false, nil, nil)
1363 implementationAndResourcesJar = combinedJar
1364 }
1365
1366 j.implementationAndResourcesJar = implementationAndResourcesJar
1367
Jaewoong Jungc27ab662019-05-30 15:51:14 -07001368 if ctx.Device() && j.hasCode(ctx) &&
Jaewoong Junga24af3b2019-05-13 09:23:20 -07001369 (Bool(j.properties.Installable) || Bool(j.deviceProperties.Compile_dex)) {
Colin Cross8faf8fc2019-01-16 15:15:52 -08001370 // Dex compilation
Colin Cross3063b782018-08-15 11:19:12 -07001371 var dexOutputFile android.ModuleOutPath
David Brazdil17ef5632018-06-27 10:27:45 +01001372 dexOutputFile = j.compileDex(ctx, flags, outputFile, jarName)
Colin Cross2fe66872015-03-30 17:20:39 -07001373 if ctx.Failed() {
1374 return
1375 }
Colin Cross331a1212018-08-15 20:40:52 -07001376
Jiyong Park09cb6292019-07-15 15:29:23 +09001377 // Hidden API CSV generation and dex encoding
1378 dexOutputFile = j.hiddenAPI.hiddenAPI(ctx, dexOutputFile, j.implementationJarFile,
1379 j.deviceProperties.UncompressDex)
Colin Cross8faf8fc2019-01-16 15:15:52 -08001380
Colin Cross331a1212018-08-15 20:40:52 -07001381 // merge dex jar with resources if necessary
1382 if j.resourceJar != nil {
1383 jars := android.Paths{dexOutputFile, j.resourceJar}
1384 combinedJar := android.PathForModuleOut(ctx, "dex-withres", jarName)
1385 TransformJarsToJar(ctx, combinedJar, "for dex resources", jars, android.OptionalPath{},
1386 false, nil, nil)
Nicolas Geoffrayf3438722019-01-23 15:57:21 +00001387 if j.deviceProperties.UncompressDex {
1388 combinedAlignedJar := android.PathForModuleOut(ctx, "dex-withres-aligned", jarName)
1389 TransformZipAlign(ctx, combinedAlignedJar, combinedJar)
1390 dexOutputFile = combinedAlignedJar
1391 } else {
1392 dexOutputFile = combinedJar
1393 }
Colin Cross331a1212018-08-15 20:40:52 -07001394 }
1395
1396 j.dexJarFile = dexOutputFile
1397
Colin Cross8faf8fc2019-01-16 15:15:52 -08001398 // Dexpreopting
Colin Cross43f08db2018-11-12 10:13:39 -08001399 dexOutputFile = j.dexpreopt(ctx, dexOutputFile)
1400
1401 j.maybeStrippedDexJarFile = dexOutputFile
1402
Colin Cross3063b782018-08-15 11:19:12 -07001403 outputFile = dexOutputFile
Colin Cross43f08db2018-11-12 10:13:39 -08001404
1405 if ctx.Failed() {
1406 return
1407 }
Colin Cross331a1212018-08-15 20:40:52 -07001408 } else {
1409 outputFile = implementationAndResourcesJar
Colin Cross2fe66872015-03-30 17:20:39 -07001410 }
Colin Cross331a1212018-08-15 20:40:52 -07001411
Colin Crossb7a63242015-04-16 14:09:14 -07001412 ctx.CheckbuildFile(outputFile)
Colin Cross3063b782018-08-15 11:19:12 -07001413
1414 // Save the output file with no relative path so that it doesn't end up in a subdirectory when used as a resource
1415 j.outputFile = outputFile.WithoutRel()
Colin Cross2fe66872015-03-30 17:20:39 -07001416}
1417
Colin Cross3b706fd2019-09-05 16:44:18 -07001418func (j *Module) compileJavaClasses(ctx android.ModuleContext, jarName string, idx int,
1419 srcFiles, srcJars android.Paths, flags javaBuilderFlags, extraJarDeps android.Paths) android.WritablePath {
1420
1421 kzipName := pathtools.ReplaceExtension(jarName, "kzip")
1422 if idx >= 0 {
1423 kzipName = strings.TrimSuffix(jarName, filepath.Ext(jarName)) + strconv.Itoa(idx) + ".kzip"
1424 jarName += strconv.Itoa(idx)
1425 }
1426
1427 classes := android.PathForModuleOut(ctx, "javac", jarName)
1428 TransformJavaToClasses(ctx, classes, idx, srcFiles, srcJars, flags, extraJarDeps)
1429
1430 if ctx.Config().EmitXrefRules() {
1431 extractionFile := android.PathForModuleOut(ctx, kzipName)
1432 emitXrefRule(ctx, extractionFile, idx, srcFiles, srcJars, flags, extraJarDeps)
1433 j.kytheFiles = append(j.kytheFiles, extractionFile)
1434 }
1435
1436 return classes
1437}
1438
Zoran Jovanovic8736ce22018-08-21 17:10:29 +02001439// Check for invalid kotlinc flags. Only use this for flags explicitly passed by the user,
1440// since some of these flags may be used internally.
1441func CheckKotlincFlags(ctx android.ModuleContext, flags []string) {
1442 for _, flag := range flags {
1443 flag = strings.TrimSpace(flag)
1444
1445 if !strings.HasPrefix(flag, "-") {
1446 ctx.PropertyErrorf("kotlincflags", "Flag `%s` must start with `-`", flag)
1447 } else if strings.HasPrefix(flag, "-Xintellij-plugin-root") {
1448 ctx.PropertyErrorf("kotlincflags",
1449 "Bad flag: `%s`, only use internal compiler for consistency.", flag)
1450 } else if inList(flag, config.KotlincIllegalFlags) {
1451 ctx.PropertyErrorf("kotlincflags", "Flag `%s` already used by build system", flag)
1452 } else if flag == "-include-runtime" {
1453 ctx.PropertyErrorf("kotlincflags", "Bad flag: `%s`, do not include runtime.", flag)
1454 } else {
1455 args := strings.Split(flag, " ")
1456 if args[0] == "-kotlin-home" {
1457 ctx.PropertyErrorf("kotlincflags",
1458 "Bad flag: `%s`, kotlin home already set to default (path to kotlinc in the repo).", flag)
1459 }
1460 }
1461 }
1462}
1463
Colin Cross8eadbf02017-10-24 17:46:00 -07001464func (j *Module) compileJavaHeader(ctx android.ModuleContext, srcFiles, srcJars android.Paths,
Colin Cross55f63ea2018-08-27 12:37:09 -07001465 deps deps, flags javaBuilderFlags, jarName string, extraJars android.Paths) android.Path {
Nan Zhanged19fc32017-10-19 13:06:22 -07001466
1467 var jars android.Paths
Colin Cross8eadbf02017-10-24 17:46:00 -07001468 if len(srcFiles) > 0 || len(srcJars) > 0 {
Nan Zhanged19fc32017-10-19 13:06:22 -07001469 // Compile java sources into turbine.jar.
1470 turbineJar := android.PathForModuleOut(ctx, "turbine", jarName)
1471 TransformJavaToHeaderClasses(ctx, turbineJar, srcFiles, srcJars, flags)
1472 if ctx.Failed() {
1473 return nil
1474 }
1475 jars = append(jars, turbineJar)
1476 }
1477
Colin Cross55f63ea2018-08-27 12:37:09 -07001478 jars = append(jars, extraJars...)
1479
Nan Zhanged19fc32017-10-19 13:06:22 -07001480 // Combine any static header libraries into classes-header.jar. If there is only
1481 // one input jar this step will be skipped.
1482 var headerJar android.Path
1483 jars = append(jars, deps.staticHeaderJars...)
1484
Colin Cross5c6ecc12017-10-23 18:12:27 -07001485 // we cannot skip the combine step for now if there is only one jar
1486 // since we have to strip META-INF/TRANSITIVE dir from turbine.jar
1487 combinedJar := android.PathForModuleOut(ctx, "turbine-combined", jarName)
Colin Cross37f6d792018-07-12 12:28:41 -07001488 TransformJarsToJar(ctx, combinedJar, "for turbine", jars, android.OptionalPath{},
Colin Cross6c6e6cd2019-05-08 14:30:12 -07001489 false, nil, []string{"META-INF/TRANSITIVE"})
Colin Cross5c6ecc12017-10-23 18:12:27 -07001490 headerJar = combinedJar
Nan Zhanged19fc32017-10-19 13:06:22 -07001491
Steven Morelandc4efd9c2019-01-18 11:51:25 -08001492 if j.expandJarjarRules != nil {
Nan Zhanged19fc32017-10-19 13:06:22 -07001493 // Transform classes.jar into classes-jarjar.jar
1494 jarjarFile := android.PathForModuleOut(ctx, "turbine-jarjar", jarName)
Steven Morelandc4efd9c2019-01-18 11:51:25 -08001495 TransformJarJar(ctx, jarjarFile, headerJar, j.expandJarjarRules)
Nan Zhanged19fc32017-10-19 13:06:22 -07001496 headerJar = jarjarFile
1497 if ctx.Failed() {
1498 return nil
1499 }
1500 }
1501
1502 return headerJar
1503}
1504
Colin Crosscb933592017-11-22 13:49:43 -08001505func (j *Module) instrument(ctx android.ModuleContext, flags javaBuilderFlags,
Colin Cross3063b782018-08-15 11:19:12 -07001506 classesJar android.Path, jarName string) android.ModuleOutPath {
Colin Crosscb933592017-11-22 13:49:43 -08001507
Colin Cross7a3139e2017-12-19 13:57:50 -08001508 specs := j.jacocoModuleToZipCommand(ctx)
Colin Crosscb933592017-11-22 13:49:43 -08001509
Colin Cross84c38822018-01-03 15:59:46 -08001510 jacocoReportClassesFile := android.PathForModuleOut(ctx, "jacoco-report-classes", jarName)
Colin Crosscb933592017-11-22 13:49:43 -08001511 instrumentedJar := android.PathForModuleOut(ctx, "jacoco", jarName)
1512
1513 jacocoInstrumentJar(ctx, instrumentedJar, jacocoReportClassesFile, classesJar, specs)
1514
1515 j.jacocoReportClassesFile = jacocoReportClassesFile
1516
1517 return instrumentedJar
1518}
1519
albaltai36ff7dc2018-12-25 14:35:23 +08001520var _ Dependency = (*Module)(nil)
Colin Cross2fe66872015-03-30 17:20:39 -07001521
Nan Zhanged19fc32017-10-19 13:06:22 -07001522func (j *Module) HeaderJars() android.Paths {
albaltai36ff7dc2018-12-25 14:35:23 +08001523 if j.headerJarFile == nil {
1524 return nil
1525 }
Nan Zhanged19fc32017-10-19 13:06:22 -07001526 return android.Paths{j.headerJarFile}
1527}
1528
1529func (j *Module) ImplementationJars() android.Paths {
shinwang9e4c07a2018-12-24 15:41:04 +08001530 if j.implementationJarFile == nil {
1531 return nil
1532 }
Nan Zhanged19fc32017-10-19 13:06:22 -07001533 return android.Paths{j.implementationJarFile}
Colin Cross2fe66872015-03-30 17:20:39 -07001534}
1535
Colin Crossf24a22a2019-01-31 14:12:44 -08001536func (j *Module) DexJar() android.Path {
1537 return j.dexJarFile
1538}
1539
Colin Cross331a1212018-08-15 20:40:52 -07001540func (j *Module) ResourceJars() android.Paths {
1541 if j.resourceJar == nil {
1542 return nil
1543 }
1544 return android.Paths{j.resourceJar}
1545}
1546
1547func (j *Module) ImplementationAndResourcesJars() android.Paths {
albaltai36ff7dc2018-12-25 14:35:23 +08001548 if j.implementationAndResourcesJar == nil {
1549 return nil
1550 }
Colin Cross331a1212018-08-15 20:40:52 -07001551 return android.Paths{j.implementationAndResourcesJar}
1552}
1553
Colin Cross46c9b8b2017-06-22 16:51:17 -07001554func (j *Module) AidlIncludeDirs() android.Paths {
albaltai36ff7dc2018-12-25 14:35:23 +08001555 // exportAidlIncludeDirs is type android.Paths already
Colin Crossc0b06f12015-04-08 13:03:43 -07001556 return j.exportAidlIncludeDirs
1557}
1558
Jiyong Park1be96912018-05-28 18:02:19 +09001559func (j *Module) ExportedSdkLibs() []string {
albaltai36ff7dc2018-12-25 14:35:23 +08001560 // exportedSdkLibs is type []string
Jiyong Park1be96912018-05-28 18:02:19 +09001561 return j.exportedSdkLibs
1562}
1563
Colin Cross0c4ce212019-05-03 15:28:19 -07001564func (j *Module) SrcJarArgs() ([]string, android.Paths) {
1565 return j.srcJarArgs, j.srcJarDeps
1566}
1567
Colin Cross46c9b8b2017-06-22 16:51:17 -07001568var _ logtagsProducer = (*Module)(nil)
Colin Crossf05fe972015-04-10 17:45:20 -07001569
Colin Cross46c9b8b2017-06-22 16:51:17 -07001570func (j *Module) logtags() android.Paths {
Colin Crossf05fe972015-04-10 17:45:20 -07001571 return j.logtagsSrcs
1572}
1573
Brandon Lee5d45c6f2018-08-15 15:35:38 -07001574// Collect information for opening IDE project files in java/jdeps.go.
1575func (j *Module) IDEInfo(dpInfo *android.IdeInfo) {
1576 dpInfo.Deps = append(dpInfo.Deps, j.CompilerDeps()...)
1577 dpInfo.Srcs = append(dpInfo.Srcs, j.expandIDEInfoCompiledSrcs...)
patricktu18c82ff2019-05-10 15:48:50 +08001578 dpInfo.SrcJars = append(dpInfo.SrcJars, j.compiledSrcJars.Strings()...)
Brandon Lee5d45c6f2018-08-15 15:35:38 -07001579 dpInfo.Aidl_include_dirs = append(dpInfo.Aidl_include_dirs, j.deviceProperties.Aidl.Include_dirs...)
Steven Morelandc4efd9c2019-01-18 11:51:25 -08001580 if j.expandJarjarRules != nil {
1581 dpInfo.Jarjar_rules = append(dpInfo.Jarjar_rules, j.expandJarjarRules.String())
Brandon Lee5d45c6f2018-08-15 15:35:38 -07001582 }
1583}
1584
1585func (j *Module) CompilerDeps() []string {
1586 jdeps := []string{}
1587 jdeps = append(jdeps, j.properties.Libs...)
1588 jdeps = append(jdeps, j.properties.Static_libs...)
1589 return jdeps
1590}
1591
Jaewoong Jungc27ab662019-05-30 15:51:14 -07001592func (j *Module) hasCode(ctx android.ModuleContext) bool {
1593 srcFiles := android.PathsForModuleSrcExcludes(ctx, j.properties.Srcs, j.properties.Exclude_srcs)
1594 return len(srcFiles) > 0 || len(ctx.GetDirectDepsWithTag(staticLibTag)) > 0
1595}
1596
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09001597func (j *Module) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
1598 depTag := ctx.OtherModuleDependencyTag(dep)
1599 // dependencies other than the static linkage are all considered crossing APEX boundary
1600 return depTag == staticLibTag
1601}
1602
Colin Cross2fe66872015-03-30 17:20:39 -07001603//
1604// Java libraries (.jar file)
1605//
1606
Colin Crossf506d872017-07-19 15:53:04 -07001607type Library struct {
Colin Cross46c9b8b2017-06-22 16:51:17 -07001608 Module
Colin Crossf0f2e2c2019-10-15 16:36:40 -07001609
1610 InstallMixin func(ctx android.ModuleContext, installPath android.Path) (extraInstallDeps android.Paths)
Colin Cross2fe66872015-03-30 17:20:39 -07001611}
1612
Colin Cross42be7612019-02-21 18:12:14 -08001613func shouldUncompressDex(ctx android.ModuleContext, dexpreopter *dexpreopter) bool {
Nicolas Geoffrayfa6e9ec2019-02-12 13:12:16 +00001614 // Store uncompressed (and do not strip) dex files from boot class path jars.
1615 if inList(ctx.ModuleName(), ctx.Config().BootJars()) {
1616 return true
1617 }
1618
1619 // Store uncompressed dex files that are preopted on /system.
Colin Cross42be7612019-02-21 18:12:14 -08001620 if !dexpreopter.dexpreoptDisabled(ctx) && (ctx.Host() || !odexOnSystemOther(ctx, dexpreopter.installPath)) {
Vladimir Markoe8b00d62018-12-21 15:54:16 +00001621 return true
1622 }
Colin Cross083a2aa2019-02-06 16:37:12 -08001623 if ctx.Config().UncompressPrivAppDex() &&
1624 inList(ctx.ModuleName(), ctx.Config().ModulesLoadedByPrivilegedModules()) {
1625 return true
1626 }
1627
Colin Cross2fc72f62018-12-21 12:59:54 -08001628 return false
1629}
1630
Colin Crossf506d872017-07-19 15:53:04 -07001631func (j *Library) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Jiyong Park4c4c0242019-10-21 14:53:15 +09001632 j.dexpreopter.installPath = android.PathForModuleInstall(ctx, "framework",
1633 proptools.StringDefault(j.deviceProperties.Stem, ctx.ModuleName())+".jar")
Colin Cross43f08db2018-11-12 10:13:39 -08001634 j.dexpreopter.isSDKLibrary = j.deviceProperties.IsSDKLibrary
Nicolas Geoffrayfa6e9ec2019-02-12 13:12:16 +00001635 j.dexpreopter.isInstallable = Bool(j.properties.Installable)
Colin Cross42be7612019-02-21 18:12:14 -08001636 j.dexpreopter.uncompressedDex = shouldUncompressDex(ctx, &j.dexpreopter)
Nicolas Geoffrayfa6e9ec2019-02-12 13:12:16 +00001637 j.deviceProperties.UncompressDex = j.dexpreopter.uncompressedDex
Jaewoong Junga24af3b2019-05-13 09:23:20 -07001638 j.compile(ctx, nil)
Colin Crossb7a63242015-04-16 14:09:14 -07001639
Jiyong Park7f7766d2019-07-25 22:02:35 +09001640 exclusivelyForApex := android.InAnyApex(ctx.ModuleName()) && !j.IsForPlatform()
1641 if (Bool(j.properties.Installable) || ctx.Host()) && !exclusivelyForApex {
Colin Crossf0f2e2c2019-10-15 16:36:40 -07001642 var extraInstallDeps android.Paths
1643 if j.InstallMixin != nil {
1644 extraInstallDeps = j.InstallMixin(ctx, j.outputFile)
1645 }
Colin Cross2c429dc2017-08-31 16:45:16 -07001646 j.installFile = ctx.InstallFile(android.PathForModuleInstall(ctx, "framework"),
Colin Crossf0f2e2c2019-10-15 16:36:40 -07001647 ctx.ModuleName()+".jar", j.outputFile, extraInstallDeps...)
Colin Cross2c429dc2017-08-31 16:45:16 -07001648 }
Colin Crossb7a63242015-04-16 14:09:14 -07001649}
1650
Colin Crossf506d872017-07-19 15:53:04 -07001651func (j *Library) DepsMutator(ctx android.BottomUpMutatorContext) {
Colin Cross46c9b8b2017-06-22 16:51:17 -07001652 j.deps(ctx)
1653}
1654
Colin Cross1b16b0e2019-02-12 14:41:32 -08001655// java_library builds and links sources into a `.jar` file for the device, and possibly for the host as well.
1656//
1657// By default, a java_library has a single variant that produces a `.jar` file containing `.class` files that were
1658// compiled against the device bootclasspath. This jar is not suitable for installing on a device, but can be used
1659// as a `static_libs` dependency of another module.
1660//
1661// Specifying `installable: true` will product a `.jar` file containing `classes.dex` files, suitable for installing on
1662// a device.
1663//
1664// Specifying `host_supported: true` will produce two variants, one compiled against the device bootclasspath and one
1665// compiled against the host bootclasspath.
Colin Cross9ae1b922018-06-26 17:59:05 -07001666func LibraryFactory() android.Module {
1667 module := &Library{}
Colin Cross2fe66872015-03-30 17:20:39 -07001668
Colin Cross9ae1b922018-06-26 17:59:05 -07001669 module.AddProperties(
1670 &module.Module.properties,
1671 &module.Module.deviceProperties,
Colin Cross43f08db2018-11-12 10:13:39 -08001672 &module.Module.dexpreoptProperties,
Colin Cross9ae1b922018-06-26 17:59:05 -07001673 &module.Module.protoProperties)
Colin Cross2fe66872015-03-30 17:20:39 -07001674
Colin Cross9ae1b922018-06-26 17:59:05 -07001675 InitJavaModule(module, android.HostAndDeviceSupported)
Jiyong Park7f7766d2019-07-25 22:02:35 +09001676 android.InitApexModule(module)
Jiyong Parkd1063c12019-07-17 20:08:41 +09001677 android.InitSdkAwareModule(module)
Colin Cross9ae1b922018-06-26 17:59:05 -07001678 return module
Colin Cross2fe66872015-03-30 17:20:39 -07001679}
1680
Colin Cross1b16b0e2019-02-12 14:41:32 -08001681// java_library_static is an obsolete alias for java_library.
1682func LibraryStaticFactory() android.Module {
1683 return LibraryFactory()
1684}
1685
1686// java_library_host builds and links sources into a `.jar` file for the host.
1687//
1688// A java_library_host has a single variant that produces a `.jar` file containing `.class` files that were
1689// compiled against the host bootclasspath.
Colin Crossf506d872017-07-19 15:53:04 -07001690func LibraryHostFactory() android.Module {
1691 module := &Library{}
Colin Cross2fe66872015-03-30 17:20:39 -07001692
Colin Cross6af17aa2017-09-20 12:59:05 -07001693 module.AddProperties(
1694 &module.Module.properties,
1695 &module.Module.protoProperties)
Colin Cross36242852017-06-23 15:06:31 -07001696
Colin Cross9ae1b922018-06-26 17:59:05 -07001697 module.Module.properties.Installable = proptools.BoolPtr(true)
1698
Colin Cross89536d42017-07-07 14:35:50 -07001699 InitJavaModule(module, android.HostSupported)
Jiyong Park7f7766d2019-07-25 22:02:35 +09001700 android.InitApexModule(module)
Colin Cross36242852017-06-23 15:06:31 -07001701 return module
Colin Cross2fe66872015-03-30 17:20:39 -07001702}
1703
1704//
Colin Crossb628ea52018-08-14 16:42:33 -07001705// Java Tests
Colin Cross05638fc2018-04-09 18:40:24 -07001706//
1707
1708type testProperties struct {
Colin Cross05638fc2018-04-09 18:40:24 -07001709 // list of compatibility suites (for example "cts", "vts") that the module should be
1710 // installed into.
1711 Test_suites []string `android:"arch_variant"`
Julien Despreze146e392018-08-02 15:00:46 -07001712
1713 // the name of the test configuration (for example "AndroidTest.xml") that should be
1714 // installed with the module.
Colin Cross27b922f2019-03-04 22:35:41 -08001715 Test_config *string `android:"path,arch_variant"`
Colin Crossd96ca352018-08-10 16:06:24 -07001716
Jack He33338892018-09-19 02:21:28 -07001717 // the name of the test configuration template (for example "AndroidTestTemplate.xml") that
1718 // should be installed with the module.
Colin Cross27b922f2019-03-04 22:35:41 -08001719 Test_config_template *string `android:"path,arch_variant"`
Jack He33338892018-09-19 02:21:28 -07001720
Colin Crossd96ca352018-08-10 16:06:24 -07001721 // list of files or filegroup modules that provide data that should be installed alongside
1722 // the test
Colin Cross27b922f2019-03-04 22:35:41 -08001723 Data []string `android:"path"`
Dan Shi6ffaaa82019-09-26 11:41:36 -07001724
1725 // Flag to indicate whether or not to create test config automatically. If AndroidTest.xml
1726 // doesn't exist next to the Android.bp, this attribute doesn't need to be set to true
1727 // explicitly.
1728 Auto_gen_config *bool
Colin Cross05638fc2018-04-09 18:40:24 -07001729}
1730
Paul Duffin42df1442019-03-20 12:45:53 +00001731type testHelperLibraryProperties struct {
1732 // list of compatibility suites (for example "cts", "vts") that the module should be
1733 // installed into.
1734 Test_suites []string `android:"arch_variant"`
1735}
1736
Colin Cross05638fc2018-04-09 18:40:24 -07001737type Test struct {
1738 Library
1739
1740 testProperties testProperties
Colin Cross303e21f2018-08-07 16:49:25 -07001741
1742 testConfig android.Path
Colin Crossd96ca352018-08-10 16:06:24 -07001743 data android.Paths
Colin Cross303e21f2018-08-07 16:49:25 -07001744}
1745
Paul Duffin42df1442019-03-20 12:45:53 +00001746type TestHelperLibrary struct {
1747 Library
1748
1749 testHelperLibraryProperties testHelperLibraryProperties
1750}
1751
Colin Cross303e21f2018-08-07 16:49:25 -07001752func (j *Test) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Dan Shi6ffaaa82019-09-26 11:41:36 -07001753 j.testConfig = tradefed.AutoGenJavaTestConfig(ctx, j.testProperties.Test_config, j.testProperties.Test_config_template,
1754 j.testProperties.Test_suites, j.testProperties.Auto_gen_config)
Colin Cross8a497952019-03-05 22:25:09 -08001755 j.data = android.PathsForModuleSrc(ctx, j.testProperties.Data)
Colin Cross303e21f2018-08-07 16:49:25 -07001756
1757 j.Library.GenerateAndroidBuildActions(ctx)
Colin Cross05638fc2018-04-09 18:40:24 -07001758}
1759
Paul Duffin42df1442019-03-20 12:45:53 +00001760func (j *TestHelperLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1761 j.Library.GenerateAndroidBuildActions(ctx)
1762}
1763
Colin Cross1b16b0e2019-02-12 14:41:32 -08001764// java_test builds a and links sources into a `.jar` file for the device, and possibly for the host as well, and
1765// creates an `AndroidTest.xml` file to allow running the test with `atest` or a `TEST_MAPPING` file.
1766//
1767// By default, a java_test has a single variant that produces a `.jar` file containing `classes.dex` files that were
1768// compiled against the device bootclasspath.
1769//
1770// Specifying `host_supported: true` will produce two variants, one compiled against the device bootclasspath and one
1771// compiled against the host bootclasspath.
Colin Cross05638fc2018-04-09 18:40:24 -07001772func TestFactory() android.Module {
1773 module := &Test{}
1774
1775 module.AddProperties(
1776 &module.Module.properties,
1777 &module.Module.deviceProperties,
Colin Cross43f08db2018-11-12 10:13:39 -08001778 &module.Module.dexpreoptProperties,
Colin Cross05638fc2018-04-09 18:40:24 -07001779 &module.Module.protoProperties,
1780 &module.testProperties)
1781
Colin Cross9ae1b922018-06-26 17:59:05 -07001782 module.Module.properties.Installable = proptools.BoolPtr(true)
Colin Crosse3026872019-01-05 22:30:13 -08001783 module.Module.dexpreopter.isTest = true
Colin Cross9ae1b922018-06-26 17:59:05 -07001784
Colin Cross05638fc2018-04-09 18:40:24 -07001785 InitJavaModule(module, android.HostAndDeviceSupported)
Colin Cross05638fc2018-04-09 18:40:24 -07001786 return module
1787}
1788
Paul Duffin42df1442019-03-20 12:45:53 +00001789// java_test_helper_library creates a java library and makes sure that it is added to the appropriate test suite.
1790func TestHelperLibraryFactory() android.Module {
1791 module := &TestHelperLibrary{}
1792
1793 module.AddProperties(
1794 &module.Module.properties,
1795 &module.Module.deviceProperties,
1796 &module.Module.dexpreoptProperties,
1797 &module.Module.protoProperties,
1798 &module.testHelperLibraryProperties)
1799
Colin Cross9a4abed2019-04-24 13:19:28 -07001800 module.Module.properties.Installable = proptools.BoolPtr(true)
1801 module.Module.dexpreopter.isTest = true
1802
Paul Duffin42df1442019-03-20 12:45:53 +00001803 InitJavaModule(module, android.HostAndDeviceSupported)
1804 return module
1805}
1806
Colin Cross1b16b0e2019-02-12 14:41:32 -08001807// java_test_host builds a and links sources into a `.jar` file for the host, and creates an `AndroidTest.xml` file to
1808// allow running the test with `atest` or a `TEST_MAPPING` file.
1809//
1810// A java_test_host has a single variant that produces a `.jar` file containing `.class` files that were
1811// compiled against the host bootclasspath.
Colin Cross05638fc2018-04-09 18:40:24 -07001812func TestHostFactory() android.Module {
1813 module := &Test{}
1814
1815 module.AddProperties(
1816 &module.Module.properties,
1817 &module.Module.protoProperties,
1818 &module.testProperties)
1819
Colin Cross9ae1b922018-06-26 17:59:05 -07001820 module.Module.properties.Installable = proptools.BoolPtr(true)
1821
Colin Cross05638fc2018-04-09 18:40:24 -07001822 InitJavaModule(module, android.HostSupported)
Colin Cross05638fc2018-04-09 18:40:24 -07001823 return module
1824}
1825
1826//
Colin Cross2fe66872015-03-30 17:20:39 -07001827// Java Binaries (.jar file plus wrapper script)
1828//
1829
Colin Crossf506d872017-07-19 15:53:04 -07001830type binaryProperties struct {
Colin Cross7d5136f2015-05-11 13:39:40 -07001831 // installable script to execute the resulting jar
Colin Cross27b922f2019-03-04 22:35:41 -08001832 Wrapper *string `android:"path"`
Colin Cross094054a2018-10-17 15:10:48 -07001833
1834 // Name of the class containing main to be inserted into the manifest as Main-Class.
1835 Main_class *string
Colin Cross7d5136f2015-05-11 13:39:40 -07001836}
1837
Colin Crossf506d872017-07-19 15:53:04 -07001838type Binary struct {
1839 Library
Colin Cross2fe66872015-03-30 17:20:39 -07001840
Colin Crossf506d872017-07-19 15:53:04 -07001841 binaryProperties binaryProperties
Colin Cross10a03492017-08-10 17:09:43 -07001842
Colin Cross6b4a32d2017-12-05 13:42:45 -08001843 isWrapperVariant bool
1844
Colin Crossc3315992017-12-08 19:12:36 -08001845 wrapperFile android.Path
Colin Cross70dda7e2019-10-01 22:05:35 -07001846 binaryFile android.InstallPath
Colin Cross2fe66872015-03-30 17:20:39 -07001847}
1848
Alex Light24237172017-10-26 09:46:21 -07001849func (j *Binary) HostToolPath() android.OptionalPath {
1850 return android.OptionalPathForPath(j.binaryFile)
1851}
1852
Colin Crossf506d872017-07-19 15:53:04 -07001853func (j *Binary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross6b4a32d2017-12-05 13:42:45 -08001854 if ctx.Arch().ArchType == android.Common {
1855 // Compile the jar
Colin Cross094054a2018-10-17 15:10:48 -07001856 if j.binaryProperties.Main_class != nil {
1857 if j.properties.Manifest != nil {
1858 ctx.PropertyErrorf("main_class", "main_class cannot be used when manifest is set")
1859 }
1860 manifestFile := android.PathForModuleOut(ctx, "manifest.txt")
1861 GenerateMainClassManifest(ctx, manifestFile, String(j.binaryProperties.Main_class))
1862 j.overrideManifest = android.OptionalPathForPath(manifestFile)
1863 }
1864
Colin Cross6b4a32d2017-12-05 13:42:45 -08001865 j.Library.GenerateAndroidBuildActions(ctx)
Nan Zhang3c807db2017-11-03 14:53:31 -07001866 } else {
Colin Cross6b4a32d2017-12-05 13:42:45 -08001867 // Handle the binary wrapper
1868 j.isWrapperVariant = true
1869
Colin Cross366938f2017-12-11 16:29:02 -08001870 if j.binaryProperties.Wrapper != nil {
Colin Cross8a497952019-03-05 22:25:09 -08001871 j.wrapperFile = android.PathForModuleSrc(ctx, *j.binaryProperties.Wrapper)
Colin Cross6b4a32d2017-12-05 13:42:45 -08001872 } else {
1873 j.wrapperFile = android.PathForSource(ctx, "build/soong/scripts/jar-wrapper.sh")
1874 }
1875
1876 // Depend on the installed jar so that the wrapper doesn't get executed by
1877 // another build rule before the jar has been installed.
1878 jarFile := ctx.PrimaryModule().(*Binary).installFile
1879
1880 j.binaryFile = ctx.InstallExecutable(android.PathForModuleInstall(ctx, "bin"),
1881 ctx.ModuleName(), j.wrapperFile, jarFile)
Nan Zhang3c807db2017-11-03 14:53:31 -07001882 }
Colin Cross2fe66872015-03-30 17:20:39 -07001883}
1884
Colin Crossf506d872017-07-19 15:53:04 -07001885func (j *Binary) DepsMutator(ctx android.BottomUpMutatorContext) {
Colin Cross6b4a32d2017-12-05 13:42:45 -08001886 if ctx.Arch().ArchType == android.Common {
1887 j.deps(ctx)
1888 }
Colin Cross46c9b8b2017-06-22 16:51:17 -07001889}
1890
Colin Cross1b16b0e2019-02-12 14:41:32 -08001891// java_binary builds a `.jar` file and a shell script that executes it for the device, and possibly for the host
1892// as well.
1893//
1894// By default, a java_binary has a single variant that produces a `.jar` file containing `classes.dex` files that were
1895// compiled against the device bootclasspath.
1896//
1897// Specifying `host_supported: true` will produce two variants, one compiled against the device bootclasspath and one
1898// compiled against the host bootclasspath.
Colin Crossf506d872017-07-19 15:53:04 -07001899func BinaryFactory() android.Module {
1900 module := &Binary{}
Colin Cross2fe66872015-03-30 17:20:39 -07001901
Colin Cross36242852017-06-23 15:06:31 -07001902 module.AddProperties(
Colin Cross540eff82017-06-22 17:01:52 -07001903 &module.Module.properties,
1904 &module.Module.deviceProperties,
Colin Cross43f08db2018-11-12 10:13:39 -08001905 &module.Module.dexpreoptProperties,
Colin Cross6af17aa2017-09-20 12:59:05 -07001906 &module.Module.protoProperties,
Colin Cross540eff82017-06-22 17:01:52 -07001907 &module.binaryProperties)
Colin Cross36242852017-06-23 15:06:31 -07001908
Colin Cross9ae1b922018-06-26 17:59:05 -07001909 module.Module.properties.Installable = proptools.BoolPtr(true)
1910
Colin Cross6b4a32d2017-12-05 13:42:45 -08001911 android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibCommonFirst)
1912 android.InitDefaultableModule(module)
Colin Cross36242852017-06-23 15:06:31 -07001913 return module
Colin Cross2fe66872015-03-30 17:20:39 -07001914}
1915
Colin Cross1b16b0e2019-02-12 14:41:32 -08001916// java_binary_host builds a `.jar` file and a shell script that executes it for the host.
1917//
1918// A java_binary_host has a single variant that produces a `.jar` file containing `.class` files that were
1919// compiled against the host bootclasspath.
Colin Crossf506d872017-07-19 15:53:04 -07001920func BinaryHostFactory() android.Module {
1921 module := &Binary{}
Colin Cross2fe66872015-03-30 17:20:39 -07001922
Colin Cross36242852017-06-23 15:06:31 -07001923 module.AddProperties(
Colin Cross540eff82017-06-22 17:01:52 -07001924 &module.Module.properties,
Colin Cross6af17aa2017-09-20 12:59:05 -07001925 &module.Module.protoProperties,
Colin Cross540eff82017-06-22 17:01:52 -07001926 &module.binaryProperties)
Colin Cross36242852017-06-23 15:06:31 -07001927
Colin Cross9ae1b922018-06-26 17:59:05 -07001928 module.Module.properties.Installable = proptools.BoolPtr(true)
1929
Colin Cross6b4a32d2017-12-05 13:42:45 -08001930 android.InitAndroidArchModule(module, android.HostSupported, android.MultilibCommonFirst)
1931 android.InitDefaultableModule(module)
Colin Cross36242852017-06-23 15:06:31 -07001932 return module
Colin Cross2fe66872015-03-30 17:20:39 -07001933}
1934
1935//
1936// Java prebuilts
1937//
1938
Colin Cross74d73e22017-08-02 11:05:49 -07001939type ImportProperties struct {
Colin Cross27b922f2019-03-04 22:35:41 -08001940 Jars []string `android:"path"`
Colin Cross461bd1a2017-10-20 13:59:18 -07001941
Nan Zhangea568a42017-11-08 21:20:04 -08001942 Sdk_version *string
Colin Cross535e2cf2017-10-20 17:57:49 -07001943
1944 Installable *bool
Jiyong Park1be96912018-05-28 18:02:19 +09001945
1946 // List of shared java libs that this module has dependencies to
1947 Libs []string
Colin Cross37f6d792018-07-12 12:28:41 -07001948
1949 // List of files to remove from the jar file(s)
1950 Exclude_files []string
1951
1952 // List of directories to remove from the jar file(s)
1953 Exclude_dirs []string
Nan Zhang4c819fb2018-08-27 18:31:46 -07001954
1955 // if set to true, run Jetifier against .jar file. Defaults to false.
Colin Cross1001a792019-03-21 22:21:39 -07001956 Jetifier *bool
Jiyong Park4c4c0242019-10-21 14:53:15 +09001957
1958 // set the name of the output
1959 Stem *string
Colin Cross74d73e22017-08-02 11:05:49 -07001960}
1961
1962type Import struct {
Colin Cross635c3b02016-05-18 15:37:25 -07001963 android.ModuleBase
Colin Cross48de9a42018-10-02 13:53:33 -07001964 android.DefaultableModuleBase
Jiyong Park7f7766d2019-07-25 22:02:35 +09001965 android.ApexModuleBase
Colin Crossec7a0422017-07-07 14:47:12 -07001966 prebuilt android.Prebuilt
Jiyong Parkd1063c12019-07-17 20:08:41 +09001967 android.SdkBase
Colin Cross2fe66872015-03-30 17:20:39 -07001968
Colin Cross74d73e22017-08-02 11:05:49 -07001969 properties ImportProperties
1970
Colin Cross0a6e0072017-08-30 14:24:55 -07001971 combinedClasspathFile android.Path
Jiyong Park1be96912018-05-28 18:02:19 +09001972 exportedSdkLibs []string
Colin Cross2fe66872015-03-30 17:20:39 -07001973}
1974
Colin Cross83bb3162018-06-25 15:48:06 -07001975func (j *Import) sdkVersion() string {
Jeongik Cha6bd33c12019-06-25 16:26:18 +09001976 return proptools.StringDefault(j.properties.Sdk_version, defaultSdkVersion(j))
Colin Cross83bb3162018-06-25 15:48:06 -07001977}
1978
1979func (j *Import) minSdkVersion() string {
1980 return j.sdkVersion()
1981}
1982
Colin Cross74d73e22017-08-02 11:05:49 -07001983func (j *Import) Prebuilt() *android.Prebuilt {
Colin Crossec7a0422017-07-07 14:47:12 -07001984 return &j.prebuilt
1985}
1986
Colin Cross74d73e22017-08-02 11:05:49 -07001987func (j *Import) PrebuiltSrcs() []string {
1988 return j.properties.Jars
1989}
1990
1991func (j *Import) Name() string {
Colin Cross5ea9bcc2017-07-27 15:41:32 -07001992 return j.prebuilt.Name(j.ModuleBase.Name())
1993}
1994
Colin Cross74d73e22017-08-02 11:05:49 -07001995func (j *Import) DepsMutator(ctx android.BottomUpMutatorContext) {
Colin Cross42d48b72018-08-29 14:10:52 -07001996 ctx.AddVariationDependencies(nil, libTag, j.properties.Libs...)
Colin Cross1e676be2016-10-12 14:38:15 -07001997}
1998
Colin Cross74d73e22017-08-02 11:05:49 -07001999func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross8a497952019-03-05 22:25:09 -08002000 jars := android.PathsForModuleSrc(ctx, j.properties.Jars)
Colin Crosse1d62a82015-04-03 16:53:05 -07002001
Jiyong Park4c4c0242019-10-21 14:53:15 +09002002 jarName := proptools.StringDefault(j.properties.Stem, ctx.ModuleName()) + ".jar"
Nan Zhang4c819fb2018-08-27 18:31:46 -07002003 outputFile := android.PathForModuleOut(ctx, "combined", jarName)
Colin Cross37f6d792018-07-12 12:28:41 -07002004 TransformJarsToJar(ctx, outputFile, "for prebuilts", jars, android.OptionalPath{},
2005 false, j.properties.Exclude_files, j.properties.Exclude_dirs)
Colin Cross1001a792019-03-21 22:21:39 -07002006 if Bool(j.properties.Jetifier) {
Nan Zhang4c819fb2018-08-27 18:31:46 -07002007 inputFile := outputFile
2008 outputFile = android.PathForModuleOut(ctx, "jetifier", jarName)
2009 TransformJetifier(ctx, outputFile, inputFile)
2010 }
Colin Crosse9a275b2017-10-16 17:09:48 -07002011 j.combinedClasspathFile = outputFile
Jiyong Park1be96912018-05-28 18:02:19 +09002012
2013 ctx.VisitDirectDeps(func(module android.Module) {
2014 otherName := ctx.OtherModuleName(module)
2015 tag := ctx.OtherModuleDependencyTag(module)
2016
2017 switch dep := module.(type) {
2018 case Dependency:
2019 switch tag {
2020 case libTag, staticLibTag:
2021 // sdk lib names from dependencies are re-exported
2022 j.exportedSdkLibs = append(j.exportedSdkLibs, dep.ExportedSdkLibs()...)
2023 }
2024 case SdkLibraryDependency:
2025 switch tag {
2026 case libTag:
2027 // names of sdk libs that are directly depended are exported
2028 j.exportedSdkLibs = append(j.exportedSdkLibs, otherName)
2029 }
2030 }
2031 })
2032
2033 j.exportedSdkLibs = android.FirstUniqueStrings(j.exportedSdkLibs)
Nan Zhang4973ecf2018-08-10 13:42:12 -07002034 if Bool(j.properties.Installable) {
2035 ctx.InstallFile(android.PathForModuleInstall(ctx, "framework"),
Jiyong Park4c4c0242019-10-21 14:53:15 +09002036 jarName, outputFile)
Nan Zhang4973ecf2018-08-10 13:42:12 -07002037 }
Colin Cross2fe66872015-03-30 17:20:39 -07002038}
2039
Colin Cross74d73e22017-08-02 11:05:49 -07002040var _ Dependency = (*Import)(nil)
Colin Cross2fe66872015-03-30 17:20:39 -07002041
Nan Zhanged19fc32017-10-19 13:06:22 -07002042func (j *Import) HeaderJars() android.Paths {
albaltai36ff7dc2018-12-25 14:35:23 +08002043 if j.combinedClasspathFile == nil {
2044 return nil
2045 }
Colin Cross37f6d792018-07-12 12:28:41 -07002046 return android.Paths{j.combinedClasspathFile}
Nan Zhanged19fc32017-10-19 13:06:22 -07002047}
2048
2049func (j *Import) ImplementationJars() android.Paths {
shinwang9e4c07a2018-12-24 15:41:04 +08002050 if j.combinedClasspathFile == nil {
2051 return nil
2052 }
Colin Cross37f6d792018-07-12 12:28:41 -07002053 return android.Paths{j.combinedClasspathFile}
Colin Cross2fe66872015-03-30 17:20:39 -07002054}
2055
Colin Cross331a1212018-08-15 20:40:52 -07002056func (j *Import) ResourceJars() android.Paths {
2057 return nil
2058}
2059
2060func (j *Import) ImplementationAndResourcesJars() android.Paths {
albaltai36ff7dc2018-12-25 14:35:23 +08002061 if j.combinedClasspathFile == nil {
2062 return nil
2063 }
Colin Cross331a1212018-08-15 20:40:52 -07002064 return android.Paths{j.combinedClasspathFile}
2065}
2066
Colin Crossf24a22a2019-01-31 14:12:44 -08002067func (j *Import) DexJar() android.Path {
2068 return nil
2069}
2070
Colin Cross74d73e22017-08-02 11:05:49 -07002071func (j *Import) AidlIncludeDirs() android.Paths {
Colin Crossc0b06f12015-04-08 13:03:43 -07002072 return nil
2073}
2074
Jiyong Park1be96912018-05-28 18:02:19 +09002075func (j *Import) ExportedSdkLibs() []string {
2076 return j.exportedSdkLibs
2077}
2078
Colin Cross0c4ce212019-05-03 15:28:19 -07002079func (j *Import) SrcJarArgs() ([]string, android.Paths) {
2080 return nil, nil
2081}
2082
albaltai36ff7dc2018-12-25 14:35:23 +08002083// Add compile time check for interface implementation
2084var _ android.IDEInfo = (*Import)(nil)
2085var _ android.IDECustomizedModuleName = (*Import)(nil)
2086
Brandon Lee5d45c6f2018-08-15 15:35:38 -07002087// Collect information for opening IDE project files in java/jdeps.go.
2088const (
2089 removedPrefix = "prebuilt_"
2090)
2091
2092func (j *Import) IDEInfo(dpInfo *android.IdeInfo) {
2093 dpInfo.Jars = append(dpInfo.Jars, j.PrebuiltSrcs()...)
2094}
2095
2096func (j *Import) IDECustomizedModuleName() string {
2097 // TODO(b/113562217): Extract the base module name from the Import name, often the Import name
2098 // has a prefix "prebuilt_". Remove the prefix explicitly if needed until we find a better
2099 // solution to get the Import name.
2100 name := j.Name()
2101 if strings.HasPrefix(name, removedPrefix) {
patricktubb640e02018-10-11 18:33:16 +08002102 name = strings.TrimPrefix(name, removedPrefix)
Brandon Lee5d45c6f2018-08-15 15:35:38 -07002103 }
2104 return name
2105}
2106
Colin Cross74d73e22017-08-02 11:05:49 -07002107var _ android.PrebuiltInterface = (*Import)(nil)
Colin Cross2fe66872015-03-30 17:20:39 -07002108
Colin Cross1b16b0e2019-02-12 14:41:32 -08002109// java_import imports one or more `.jar` files into the build graph as if they were built by a java_library module.
2110//
2111// By default, a java_import has a single variant that expects a `.jar` file containing `.class` files that were
2112// compiled against an Android classpath.
2113//
2114// Specifying `host_supported: true` will produce two variants, one for use as a dependency of device modules and one
2115// for host modules.
Colin Cross74d73e22017-08-02 11:05:49 -07002116func ImportFactory() android.Module {
2117 module := &Import{}
Colin Cross36242852017-06-23 15:06:31 -07002118
Colin Cross74d73e22017-08-02 11:05:49 -07002119 module.AddProperties(&module.properties)
2120
2121 android.InitPrebuiltModule(module, &module.properties.Jars)
Colin Cross48de9a42018-10-02 13:53:33 -07002122 InitJavaModule(module, android.HostAndDeviceSupported)
Jiyong Park7f7766d2019-07-25 22:02:35 +09002123 android.InitApexModule(module)
Jiyong Parkd1063c12019-07-17 20:08:41 +09002124 android.InitSdkAwareModule(module)
Colin Cross36242852017-06-23 15:06:31 -07002125 return module
Colin Cross2fe66872015-03-30 17:20:39 -07002126}
2127
Colin Cross1b16b0e2019-02-12 14:41:32 -08002128// java_import imports one or more `.jar` files into the build graph as if they were built by a java_library_host
2129// module.
2130//
2131// A java_import_host has a single variant that expects a `.jar` file containing `.class` files that were
2132// compiled against a host bootclasspath.
Colin Cross74d73e22017-08-02 11:05:49 -07002133func ImportFactoryHost() android.Module {
2134 module := &Import{}
2135
2136 module.AddProperties(&module.properties)
2137
2138 android.InitPrebuiltModule(module, &module.properties.Jars)
Colin Cross48de9a42018-10-02 13:53:33 -07002139 InitJavaModule(module, android.HostSupported)
Jiyong Park7f7766d2019-07-25 22:02:35 +09002140 android.InitApexModule(module)
Colin Cross74d73e22017-08-02 11:05:49 -07002141 return module
2142}
2143
Colin Cross42be7612019-02-21 18:12:14 -08002144// dex_import module
2145
2146type DexImportProperties struct {
Colin Cross5cfc70d2019-07-15 13:36:55 -07002147 Jars []string `android:"path"`
Jiyong Park4c4c0242019-10-21 14:53:15 +09002148
2149 // set the name of the output
2150 Stem *string
Colin Cross42be7612019-02-21 18:12:14 -08002151}
2152
2153type DexImport struct {
2154 android.ModuleBase
2155 android.DefaultableModuleBase
Jiyong Park7f7766d2019-07-25 22:02:35 +09002156 android.ApexModuleBase
Colin Cross42be7612019-02-21 18:12:14 -08002157 prebuilt android.Prebuilt
2158
2159 properties DexImportProperties
2160
2161 dexJarFile android.Path
2162 maybeStrippedDexJarFile android.Path
2163
2164 dexpreopter
2165}
2166
2167func (j *DexImport) Prebuilt() *android.Prebuilt {
2168 return &j.prebuilt
2169}
2170
2171func (j *DexImport) PrebuiltSrcs() []string {
2172 return j.properties.Jars
2173}
2174
2175func (j *DexImport) Name() string {
2176 return j.prebuilt.Name(j.ModuleBase.Name())
2177}
2178
Colin Cross42be7612019-02-21 18:12:14 -08002179func (j *DexImport) GenerateAndroidBuildActions(ctx android.ModuleContext) {
2180 if len(j.properties.Jars) != 1 {
2181 ctx.PropertyErrorf("jars", "exactly one jar must be provided")
2182 }
2183
Jiyong Park4c4c0242019-10-21 14:53:15 +09002184 j.dexpreopter.installPath = android.PathForModuleInstall(ctx, "framework",
2185 proptools.StringDefault(j.properties.Stem, ctx.ModuleName())+".jar")
Colin Cross42be7612019-02-21 18:12:14 -08002186 j.dexpreopter.isInstallable = true
2187 j.dexpreopter.uncompressedDex = shouldUncompressDex(ctx, &j.dexpreopter)
2188
2189 inputJar := ctx.ExpandSource(j.properties.Jars[0], "jars")
2190 dexOutputFile := android.PathForModuleOut(ctx, ctx.ModuleName()+".jar")
2191
2192 if j.dexpreopter.uncompressedDex {
2193 rule := android.NewRuleBuilder()
2194
2195 temporary := android.PathForModuleOut(ctx, ctx.ModuleName()+".jar.unaligned")
2196 rule.Temporary(temporary)
2197
2198 // use zip2zip to uncompress classes*.dex files
2199 rule.Command().
Colin Crossee94d6a2019-07-08 17:08:34 -07002200 BuiltTool(ctx, "zip2zip").
Colin Cross42be7612019-02-21 18:12:14 -08002201 FlagWithInput("-i ", inputJar).
2202 FlagWithOutput("-o ", temporary).
2203 FlagWithArg("-0 ", "'classes*.dex'")
2204
2205 // use zipalign to align uncompressed classes*.dex files
2206 rule.Command().
Colin Crossee94d6a2019-07-08 17:08:34 -07002207 BuiltTool(ctx, "zipalign").
Colin Cross42be7612019-02-21 18:12:14 -08002208 Flag("-f").
2209 Text("4").
2210 Input(temporary).
2211 Output(dexOutputFile)
2212
2213 rule.DeleteTemporaryFiles()
2214
2215 rule.Build(pctx, ctx, "uncompress_dex", "uncompress dex")
2216 } else {
2217 ctx.Build(pctx, android.BuildParams{
2218 Rule: android.Cp,
2219 Input: inputJar,
2220 Output: dexOutputFile,
2221 })
2222 }
2223
2224 j.dexJarFile = dexOutputFile
2225
2226 dexOutputFile = j.dexpreopt(ctx, dexOutputFile)
2227
2228 j.maybeStrippedDexJarFile = dexOutputFile
2229
2230 ctx.InstallFile(android.PathForModuleInstall(ctx, "framework"),
2231 ctx.ModuleName()+".jar", dexOutputFile)
2232}
2233
2234func (j *DexImport) DexJar() android.Path {
2235 return j.dexJarFile
2236}
2237
2238// dex_import imports a `.jar` file containing classes.dex files.
2239//
2240// A dex_import module cannot be used as a dependency of a java_* or android_* module, it can only be installed
2241// to the device.
2242func DexImportFactory() android.Module {
2243 module := &DexImport{}
2244
2245 module.AddProperties(&module.properties)
2246
2247 android.InitPrebuiltModule(module, &module.properties.Jars)
2248 InitJavaModule(module, android.DeviceSupported)
Jiyong Park7f7766d2019-07-25 22:02:35 +09002249 android.InitApexModule(module)
Colin Cross42be7612019-02-21 18:12:14 -08002250 return module
2251}
2252
Colin Cross89536d42017-07-07 14:35:50 -07002253//
2254// Defaults
2255//
2256type Defaults struct {
2257 android.ModuleBase
2258 android.DefaultsModuleBase
Jiyong Park7f7766d2019-07-25 22:02:35 +09002259 android.ApexModuleBase
Colin Cross89536d42017-07-07 14:35:50 -07002260}
2261
Colin Cross1b16b0e2019-02-12 14:41:32 -08002262// java_defaults provides a set of properties that can be inherited by other java or android modules.
2263//
2264// A module can use the properties from a java_defaults module using `defaults: ["defaults_module_name"]`. Each
2265// property in the defaults module that exists in the depending module will be prepended to the depending module's
2266// value for that property.
2267//
2268// Example:
2269//
2270// java_defaults {
2271// name: "example_defaults",
2272// srcs: ["common/**/*.java"],
2273// javacflags: ["-Xlint:all"],
2274// aaptflags: ["--auto-add-overlay"],
2275// }
2276//
2277// java_library {
2278// name: "example",
2279// defaults: ["example_defaults"],
2280// srcs: ["example/**/*.java"],
2281// }
2282//
2283// is functionally identical to:
2284//
2285// java_library {
2286// name: "example",
2287// srcs: [
2288// "common/**/*.java",
2289// "example/**/*.java",
2290// ],
2291// javacflags: ["-Xlint:all"],
2292// }
Colin Cross89536d42017-07-07 14:35:50 -07002293func defaultsFactory() android.Module {
2294 return DefaultsFactory()
2295}
2296
2297func DefaultsFactory(props ...interface{}) android.Module {
2298 module := &Defaults{}
2299
2300 module.AddProperties(props...)
2301 module.AddProperties(
2302 &CompilerProperties{},
2303 &CompilerDeviceProperties{},
Colin Cross43f08db2018-11-12 10:13:39 -08002304 &DexpreoptProperties{},
Dan Willemsen6424d172018-03-08 13:27:59 -08002305 &android.ProtoProperties{},
Colin Cross48de9a42018-10-02 13:53:33 -07002306 &aaptProperties{},
2307 &androidLibraryProperties{},
2308 &appProperties{},
2309 &appTestProperties{},
Jaewoong Jung525443a2019-02-28 15:35:54 -08002310 &overridableAppProperties{},
Colin Cross48de9a42018-10-02 13:53:33 -07002311 &ImportProperties{},
2312 &AARImportProperties{},
2313 &sdkLibraryProperties{},
Colin Cross42be7612019-02-21 18:12:14 -08002314 &DexImportProperties{},
Colin Cross89536d42017-07-07 14:35:50 -07002315 )
2316
2317 android.InitDefaultsModule(module)
Jiyong Park7f7766d2019-07-25 22:02:35 +09002318 android.InitApexModule(module)
Colin Cross89536d42017-07-07 14:35:50 -07002319 return module
2320}
Nan Zhangea568a42017-11-08 21:20:04 -08002321
Sasha Smundak2a4549e2018-11-05 16:49:08 -08002322func kytheExtractJavaFactory() android.Singleton {
2323 return &kytheExtractJavaSingleton{}
2324}
2325
2326type kytheExtractJavaSingleton struct {
2327}
2328
2329func (ks *kytheExtractJavaSingleton) GenerateBuildActions(ctx android.SingletonContext) {
2330 var xrefTargets android.Paths
2331 ctx.VisitAllModules(func(module android.Module) {
2332 if javaModule, ok := module.(xref); ok {
2333 xrefTargets = append(xrefTargets, javaModule.XrefJavaFiles()...)
2334 }
2335 })
2336 // TODO(asmundak): perhaps emit a rule to output a warning if there were no xrefTargets
2337 if len(xrefTargets) > 0 {
2338 ctx.Build(pctx, android.BuildParams{
2339 Rule: blueprint.Phony,
2340 Output: android.PathForPhony(ctx, "xref_java"),
2341 Inputs: xrefTargets,
2342 })
2343 }
2344}
2345
Nan Zhangea568a42017-11-08 21:20:04 -08002346var Bool = proptools.Bool
Colin Cross38b40df2018-04-10 16:14:46 -07002347var BoolDefault = proptools.BoolDefault
Nan Zhangea568a42017-11-08 21:20:04 -08002348var String = proptools.String
Colin Cross0d0ba592018-02-20 13:33:42 -08002349var inList = android.InList