blob: 79568131d02f87131b8f3146efa0136ea22db5ea [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() {
Paul Duffinf9b1da02019-12-18 19:51:55 +000037 RegisterJavaBuildComponents(android.InitRegistrationContext)
Paul Duffin255f18e2019-12-13 11:22:16 +000038
39 // Register sdk member types.
Paul Duffin7b81f5e2020-01-13 21:03:22 +000040 android.RegisterSdkMemberType(javaHeaderLibsSdkMemberType)
Paul Duffin255f18e2019-12-13 11:22:16 +000041
42 android.RegisterSdkMemberType(&implLibrarySdkMemberType{
43 librarySdkMemberType{
44 android.SdkMemberTypeBase{
45 PropertyName: "java_libs",
46 },
47 },
48 })
Paul Duffin1b82e6a2019-12-03 18:06:47 +000049
50 android.RegisterSdkMemberType(&testSdkMemberType{
51 SdkMemberTypeBase: android.SdkMemberTypeBase{
52 PropertyName: "java_tests",
53 },
54 })
Colin Cross463a90e2015-06-17 14:20:06 -070055}
56
Paul Duffinf9b1da02019-12-18 19:51:55 +000057func RegisterJavaBuildComponents(ctx android.RegistrationContext) {
58 ctx.RegisterModuleType("java_defaults", DefaultsFactory)
59
60 ctx.RegisterModuleType("java_library", LibraryFactory)
61 ctx.RegisterModuleType("java_library_static", LibraryStaticFactory)
62 ctx.RegisterModuleType("java_library_host", LibraryHostFactory)
63 ctx.RegisterModuleType("java_binary", BinaryFactory)
64 ctx.RegisterModuleType("java_binary_host", BinaryHostFactory)
65 ctx.RegisterModuleType("java_test", TestFactory)
66 ctx.RegisterModuleType("java_test_helper_library", TestHelperLibraryFactory)
67 ctx.RegisterModuleType("java_test_host", TestHostFactory)
Paul Duffin1b82e6a2019-12-03 18:06:47 +000068 ctx.RegisterModuleType("java_test_import", JavaTestImportFactory)
Paul Duffinf9b1da02019-12-18 19:51:55 +000069 ctx.RegisterModuleType("java_import", ImportFactory)
70 ctx.RegisterModuleType("java_import_host", ImportFactoryHost)
71 ctx.RegisterModuleType("java_device_for_host", DeviceForHostFactory)
72 ctx.RegisterModuleType("java_host_for_device", HostForDeviceFactory)
73 ctx.RegisterModuleType("dex_import", DexImportFactory)
74
Martin Stjernholm6d415272020-01-31 17:10:36 +000075 ctx.FinalDepsMutators(func(ctx android.RegisterMutatorsContext) {
76 ctx.BottomUp("dexpreopt_tool_deps", dexpreoptToolDepsMutator).Parallel()
77 })
Martin Stjernholmd90676f2020-01-11 00:37:30 +000078
Paul Duffinf9b1da02019-12-18 19:51:55 +000079 ctx.RegisterSingletonType("logtags", LogtagsSingleton)
80 ctx.RegisterSingletonType("kythe_java_extract", kytheExtractJavaFactory)
81}
82
Artur Satayeve5ac15a2020-04-08 19:09:30 +010083func (j *Module) checkSdkVersions(ctx android.ModuleContext) {
Jeongik Cha2cc570d2019-10-29 15:44:45 +090084 if j.SocSpecific() || j.DeviceSpecific() ||
85 (j.ProductSpecific() && ctx.Config().EnforceProductPartitionInterface()) {
86 if sc, ok := ctx.Module().(sdkContext); ok {
Jiyong Park6a927c42020-01-21 02:03:43 +090087 if !sc.sdkVersion().specified() {
Jeongik Cha2cc570d2019-10-29 15:44:45 +090088 ctx.PropertyErrorf("sdk_version",
89 "sdk_version must have a value when the module is located at vendor or product(only if PRODUCT_ENFORCE_PRODUCT_PARTITION_INTERFACE is set).")
90 }
91 }
92 }
Artur Satayeve5ac15a2020-04-08 19:09:30 +010093
94 ctx.VisitDirectDeps(func(module android.Module) {
95 tag := ctx.OtherModuleDependencyTag(module)
96 switch module.(type) {
97 // TODO(satayev): cover other types as well, e.g. imports
98 case *Library, *AndroidLibrary:
99 switch tag {
100 case bootClasspathTag, libTag, staticLibTag, java9LibTag:
101 checkLinkType(ctx, j, module.(linkTypeContext), tag.(dependencyTag))
102 }
103 }
104 })
Jeongik Cha2cc570d2019-10-29 15:44:45 +0900105}
106
Jeongik Cha538c0d02019-07-11 15:54:27 +0900107func (j *Module) checkPlatformAPI(ctx android.ModuleContext) {
108 if sc, ok := ctx.Module().(sdkContext); ok {
109 usePlatformAPI := proptools.Bool(j.deviceProperties.Platform_apis)
Jiyong Park6a927c42020-01-21 02:03:43 +0900110 sdkVersionSpecified := sc.sdkVersion().specified()
111 if usePlatformAPI && sdkVersionSpecified {
112 ctx.PropertyErrorf("platform_apis", "platform_apis must be false when sdk_version is not empty.")
113 } else if !usePlatformAPI && !sdkVersionSpecified {
114 ctx.PropertyErrorf("platform_apis", "platform_apis must be true when sdk_version is empty.")
Jeongik Cha538c0d02019-07-11 15:54:27 +0900115 }
116
117 }
118}
119
Colin Cross2fe66872015-03-30 17:20:39 -0700120// TODO:
121// Autogenerated files:
Colin Cross2fe66872015-03-30 17:20:39 -0700122// Renderscript
123// Post-jar passes:
124// Proguard
Colin Cross2fe66872015-03-30 17:20:39 -0700125// Rmtypedefs
Colin Cross2fe66872015-03-30 17:20:39 -0700126// DroidDoc
127// Findbugs
128
Colin Cross89536d42017-07-07 14:35:50 -0700129type CompilerProperties struct {
Colin Cross7d5136f2015-05-11 13:39:40 -0700130 // list of source files used to compile the Java module. May be .java, .logtags, .proto,
131 // or .aidl files.
Colin Cross27b922f2019-03-04 22:35:41 -0800132 Srcs []string `android:"path,arch_variant"`
Dan Willemsen2ef08f42015-06-30 18:15:24 -0700133
134 // list of source files that should not be used to build the Java module.
135 // This is most useful in the arch/multilib variants to remove non-common files
Colin Cross27b922f2019-03-04 22:35:41 -0800136 Exclude_srcs []string `android:"path,arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700137
138 // list of directories containing Java resources
Colin Cross86a63ff2017-09-27 17:33:10 -0700139 Java_resource_dirs []string `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700140
Colin Cross86a63ff2017-09-27 17:33:10 -0700141 // list of directories that should be excluded from java_resource_dirs
142 Exclude_java_resource_dirs []string `android:"arch_variant"`
Dan Willemsen2ef08f42015-06-30 18:15:24 -0700143
Colin Cross0f37af02017-09-27 17:42:05 -0700144 // list of files to use as Java resources
Colin Cross27b922f2019-03-04 22:35:41 -0800145 Java_resources []string `android:"path,arch_variant"`
Colin Cross0f37af02017-09-27 17:42:05 -0700146
Colin Crosscedd4762018-09-13 11:26:19 -0700147 // list of files that should be excluded from java_resources and java_resource_dirs
Colin Cross27b922f2019-03-04 22:35:41 -0800148 Exclude_java_resources []string `android:"path,arch_variant"`
Colin Cross0f37af02017-09-27 17:42:05 -0700149
Colin Cross7d5136f2015-05-11 13:39:40 -0700150 // list of module-specific flags that will be used for javac compiles
151 Javacflags []string `android:"arch_variant"`
152
Zoran Jovanovic8736ce22018-08-21 17:10:29 +0200153 // list of module-specific flags that will be used for kotlinc compiles
154 Kotlincflags []string `android:"arch_variant"`
155
Colin Cross7d5136f2015-05-11 13:39:40 -0700156 // list of of java libraries that will be in the classpath
Colin Crosse8dc34a2017-07-19 11:22:16 -0700157 Libs []string `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700158
159 // list of java libraries that will be compiled into the resulting jar
Colin Crosse8dc34a2017-07-19 11:22:16 -0700160 Static_libs []string `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700161
162 // manifest file to be included in resulting jar
Colin Cross27b922f2019-03-04 22:35:41 -0800163 Manifest *string `android:"path"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700164
Colin Cross540eff82017-06-22 17:01:52 -0700165 // if not blank, run jarjar using the specified rules file
Colin Cross27b922f2019-03-04 22:35:41 -0800166 Jarjar_rules *string `android:"path,arch_variant"`
Colin Cross64162712017-08-08 13:17:59 -0700167
168 // If not blank, set the java version passed to javac as -source and -target
169 Java_version *string
Colin Cross2c429dc2017-08-31 16:45:16 -0700170
Colin Cross9ae1b922018-06-26 17:59:05 -0700171 // If set to true, allow this module to be dexed and installed on devices. Has no
172 // effect on host modules, which are always considered installable.
Colin Cross2c429dc2017-08-31 16:45:16 -0700173 Installable *bool
Colin Cross32f676a2017-09-06 13:41:06 -0700174
Colin Cross0f37af02017-09-27 17:42:05 -0700175 // If set to true, include sources used to compile the module in to the final jar
176 Include_srcs *bool
177
Vladimir Marko0975ee02019-04-02 10:29:55 +0100178 // If not empty, classes are restricted to the specified packages and their sub-packages.
179 // This restriction is checked after applying jarjar rules and including static libs.
180 Permitted_packages []string
181
Colin Crossbe9cdb82019-01-21 21:37:16 -0800182 // List of modules to use as annotation processors
183 Plugins []string
Colin Cross1369cdb2017-09-29 17:58:17 -0700184
Artur Satayev9cf46692019-11-26 18:08:34 +0000185 // List of modules to export to libraries that directly depend on this library as annotation processors
186 Exported_plugins []string
187
Nan Zhang61eaedb2017-11-02 13:28:15 -0700188 // The number of Java source entries each Javac instance can process
189 Javac_shard_size *int64
190
Nan Zhang5f8cb422018-02-06 10:34:32 -0800191 // Add host jdk tools.jar to bootclasspath
192 Use_tools_jar *bool
193
Colin Cross1369cdb2017-09-29 17:58:17 -0700194 Openjdk9 struct {
Colin Cross6cef4812019-10-17 14:23:50 -0700195 // List of source files that should only be used when passing -source 1.9 or higher
Colin Cross27b922f2019-03-04 22:35:41 -0800196 Srcs []string `android:"path"`
Colin Cross1369cdb2017-09-29 17:58:17 -0700197
Colin Cross6cef4812019-10-17 14:23:50 -0700198 // List of javac flags that should only be used when passing -source 1.9 or higher
Colin Cross1369cdb2017-09-29 17:58:17 -0700199 Javacflags []string
200 }
Colin Crosscb933592017-11-22 13:49:43 -0800201
Colin Cross81440082018-08-15 20:21:55 -0700202 // When compiling language level 9+ .java code in packages that are part of
203 // a system module, patch_module names the module that your sources and
204 // dependencies should be patched into. The Android runtime currently
205 // doesn't implement the JEP 261 module system so this option is only
206 // supported at compile time. It should only be needed to compile tests in
207 // packages that exist in libcore and which are inconvenient to move
208 // elsewhere.
Tobias Thiererdda713d2018-09-19 16:16:19 +0100209 Patch_module *string `android:"arch_variant"`
Colin Cross81440082018-08-15 20:21:55 -0700210
Colin Crosscb933592017-11-22 13:49:43 -0800211 Jacoco struct {
212 // List of classes to include for instrumentation with jacoco to collect coverage
213 // information at runtime when building with coverage enabled. If unset defaults to all
214 // classes.
215 // Supports '*' as the last character of an entry in the list as a wildcard match.
216 // If preceded by '.' it matches all classes in the package and subpackages, otherwise
217 // it matches classes in the package that have the class name as a prefix.
218 Include_filter []string
219
220 // List of classes to exclude from instrumentation with jacoco to collect coverage
221 // information at runtime when building with coverage enabled. Overrides classes selected
222 // by the include_filter property.
223 // Supports '*' as the last character of an entry in the list as a wildcard match.
224 // If preceded by '.' it matches all classes in the package and subpackages, otherwise
225 // it matches classes in the package that have the class name as a prefix.
226 Exclude_filter []string
227 }
228
Andreas Gampef3e5b552018-01-22 21:27:21 -0800229 Errorprone struct {
230 // List of javac flags that should only be used when running errorprone.
231 Javacflags []string
232 }
233
Colin Cross0f2ee152017-12-14 15:22:43 -0800234 Proto struct {
235 // List of extra options that will be passed to the proto generator.
236 Output_params []string
237 }
238
Colin Crosscb933592017-11-22 13:49:43 -0800239 Instrument bool `blueprint:"mutated"`
Alex Light7f004a72019-02-21 13:27:37 -0800240
241 // List of files to include in the META-INF/services folder of the resulting jar.
Colin Cross27b922f2019-03-04 22:35:41 -0800242 Services []string `android:"path,arch_variant"`
Colin Cross540eff82017-06-22 17:01:52 -0700243}
244
Colin Cross89536d42017-07-07 14:35:50 -0700245type CompilerDeviceProperties struct {
Colin Cross540eff82017-06-22 17:01:52 -0700246 // list of module-specific flags that will be used for dex compiles
247 Dxflags []string `android:"arch_variant"`
248
Jeongik Cha538c0d02019-07-11 15:54:27 +0900249 // if not blank, set to the version of the sdk to compile against.
250 // Defaults to compiling against the current platform.
Nan Zhangea568a42017-11-08 21:20:04 -0800251 Sdk_version *string
Colin Cross7d5136f2015-05-11 13:39:40 -0700252
Colin Cross83bb3162018-06-25 15:48:06 -0700253 // if not blank, set the minimum version of the sdk that the compiled artifacts will run against.
254 // Defaults to sdk_version if not set.
255 Min_sdk_version *string
256
Dan Willemsen419290a2018-10-31 15:28:47 -0700257 // if not blank, set the targetSdkVersion in the AndroidManifest.xml.
258 // Defaults to sdk_version if not set.
259 Target_sdk_version *string
260
Jeongik Cha356dac42019-08-19 14:09:52 +0900261 // Whether to compile against the platform APIs instead of an SDK.
262 // If true, then sdk_version must be empty. The value of this field
263 // is ignored when module's type isn't android_app.
Colin Cross6af2e492018-05-22 11:12:33 -0700264 Platform_apis *bool
265
Colin Crossebe1a512017-11-14 13:12:14 -0800266 Aidl struct {
267 // Top level directories to pass to aidl tool
268 Include_dirs []string
Colin Cross7d5136f2015-05-11 13:39:40 -0700269
Colin Crossebe1a512017-11-14 13:12:14 -0800270 // Directories rooted at the Android.bp file to pass to aidl tool
271 Local_include_dirs []string
272
273 // directories that should be added as include directories for any aidl sources of modules
274 // that depend on this module, as well as to aidl for this module.
275 Export_include_dirs []string
Martijn Coeneneab15642018-03-09 09:29:59 +0100276
277 // whether to generate traces (for systrace) for this interface
278 Generate_traces *bool
Olivier Gaillard0a4cfbc2018-07-16 23:37:03 +0100279
280 // whether to generate Binder#GetTransaction name method.
281 Generate_get_transaction_name *bool
Colin Crossebe1a512017-11-14 13:12:14 -0800282 }
Colin Cross92430102017-10-09 14:59:32 -0700283
284 // If true, export a copy of the module as a -hostdex module for host testing.
285 Hostdex *bool
Colin Cross1369cdb2017-09-29 17:58:17 -0700286
Colin Cross7f87f4f2019-04-24 13:41:45 -0700287 Target struct {
288 Hostdex struct {
289 // Additional required dependencies to add to -hostdex modules.
290 Required []string
291 }
292 }
293
David Brazdil17ef5632018-06-27 10:27:45 +0100294 // If set to true, compile dex regardless of installable. Defaults to false.
295 Compile_dex *bool
296
Colin Cross66dbc0b2017-12-28 12:23:20 -0800297 Optimize struct {
Colin Crossae5caf52018-05-22 11:11:52 -0700298 // If false, disable all optimization. Defaults to true for android_app and android_test
299 // modules, false for java_library and java_test modules.
Colin Cross66dbc0b2017-12-28 12:23:20 -0800300 Enabled *bool
Sasha Smundak2057f822019-04-16 17:16:58 -0700301 // True if the module containing this has it set by default.
302 EnabledByDefault bool `blueprint:"mutated"`
Colin Cross66dbc0b2017-12-28 12:23:20 -0800303
304 // If true, optimize for size by removing unused code. Defaults to true for apps,
305 // false for libraries and tests.
306 Shrink *bool
307
308 // If true, optimize bytecode. Defaults to false.
309 Optimize *bool
310
311 // If true, obfuscate bytecode. Defaults to false.
312 Obfuscate *bool
313
314 // If true, do not use the flag files generated by aapt that automatically keep
315 // classes referenced by the app manifest. Defaults to false.
316 No_aapt_flags *bool
317
318 // Flags to pass to proguard.
319 Proguard_flags []string
320
321 // Specifies the locations of files containing proguard flags.
Colin Cross27b922f2019-03-04 22:35:41 -0800322 Proguard_flags_files []string `android:"path"`
Colin Cross66dbc0b2017-12-28 12:23:20 -0800323 }
324
Paul Duffine25c6442019-10-11 13:50:28 +0100325 // When targeting 1.9 and above, override the modules to use with --system,
326 // otherwise provides defaults libraries to add to the bootclasspath.
Colin Cross1369cdb2017-09-29 17:58:17 -0700327 System_modules *string
Colin Cross5a0dcd52018-10-05 14:20:06 -0700328
Jiyong Park4c4c0242019-10-21 14:53:15 +0900329 // set the name of the output
330 Stem *string
331
Colin Cross5a0dcd52018-10-05 14:20:06 -0700332 UncompressDex bool `blueprint:"mutated"`
Colin Cross43f08db2018-11-12 10:13:39 -0800333 IsSDKLibrary bool `blueprint:"mutated"`
Songchun Fan688de9a2020-03-24 20:32:24 -0700334
335 // If true, generate the signature file of APK Signing Scheme V4, along side the signed APK file.
336 // Defaults to false.
337 V4_signature *bool
Colin Cross7d5136f2015-05-11 13:39:40 -0700338}
339
Sasha Smundak2057f822019-04-16 17:16:58 -0700340func (me *CompilerDeviceProperties) EffectiveOptimizeEnabled() bool {
341 return BoolDefault(me.Optimize.Enabled, me.Optimize.EnabledByDefault)
342}
343
Colin Cross46c9b8b2017-06-22 16:51:17 -0700344// Module contains the properties and members used by all java module types
345type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700346 android.ModuleBase
Colin Cross89536d42017-07-07 14:35:50 -0700347 android.DefaultableModuleBase
Jiyong Park7f7766d2019-07-25 22:02:35 +0900348 android.ApexModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +0900349 android.SdkBase
Colin Cross2fe66872015-03-30 17:20:39 -0700350
Colin Cross89536d42017-07-07 14:35:50 -0700351 properties CompilerProperties
Colin Cross6af17aa2017-09-20 12:59:05 -0700352 protoProperties android.ProtoProperties
Colin Cross89536d42017-07-07 14:35:50 -0700353 deviceProperties CompilerDeviceProperties
Colin Cross2fe66872015-03-30 17:20:39 -0700354
Colin Cross331a1212018-08-15 20:40:52 -0700355 // jar file containing header classes including static library dependencies, suitable for
356 // inserting into the bootclasspath/classpath of another compile
Nan Zhanged19fc32017-10-19 13:06:22 -0700357 headerJarFile android.Path
358
Colin Cross331a1212018-08-15 20:40:52 -0700359 // jar file containing implementation classes including static library dependencies but no
360 // resources
Nan Zhanged19fc32017-10-19 13:06:22 -0700361 implementationJarFile android.Path
Colin Cross2fe66872015-03-30 17:20:39 -0700362
Colin Cross331a1212018-08-15 20:40:52 -0700363 // jar file containing only resources including from static library dependencies
364 resourceJar android.Path
365
Colin Cross0c4ce212019-05-03 15:28:19 -0700366 // args and dependencies to package source files into a srcjar
367 srcJarArgs []string
368 srcJarDeps android.Paths
369
Colin Cross331a1212018-08-15 20:40:52 -0700370 // jar file containing implementation classes and resources including static library
371 // dependencies
372 implementationAndResourcesJar android.Path
373
374 // output file containing classes.dex and resources
Colin Cross6ade34f2017-09-15 13:00:47 -0700375 dexJarFile android.Path
376
Colin Cross43f08db2018-11-12 10:13:39 -0800377 // output file that contains classes.dex if it should be in the output file
378 maybeStrippedDexJarFile android.Path
379
Colin Crosscb933592017-11-22 13:49:43 -0800380 // output file containing uninstrumented classes that will be instrumented by jacoco
381 jacocoReportClassesFile android.Path
382
Colin Cross66dbc0b2017-12-28 12:23:20 -0800383 // output file containing mapping of obfuscated names
384 proguardDictionary android.Path
385
Colin Cross331a1212018-08-15 20:40:52 -0700386 // output file of the module, which may be a classes jar or a dex jar
Colin Crosse560c4a2019-03-19 16:03:11 -0700387 outputFile android.Path
388 extraOutputFiles android.Paths
Colin Crossb7a63242015-04-16 14:09:14 -0700389
Colin Cross635c3b02016-05-18 15:37:25 -0700390 exportAidlIncludeDirs android.Paths
Colin Crossc0b06f12015-04-08 13:03:43 -0700391
Colin Cross635c3b02016-05-18 15:37:25 -0700392 logtagsSrcs android.Paths
Colin Crossf05fe972015-04-10 17:45:20 -0700393
Colin Cross2fe66872015-03-30 17:20:39 -0700394 // installed file for binary dependency
Colin Cross635c3b02016-05-18 15:37:25 -0700395 installFile android.Path
Colin Cross5ab4e6d2017-11-22 16:20:45 -0800396
397 // list of .java files and srcjars that was passed to javac
398 compiledJavaSrcs android.Paths
399 compiledSrcJars android.Paths
Colin Cross66dbc0b2017-12-28 12:23:20 -0800400
401 // list of extra progurad flag files
402 extraProguardFlagFiles android.Paths
Jiyong Park1be96912018-05-28 18:02:19 +0900403
Colin Cross094054a2018-10-17 15:10:48 -0700404 // manifest file to use instead of properties.Manifest
405 overrideManifest android.OptionalPath
406
Artur Satayev9cf46692019-11-26 18:08:34 +0000407 // list of SDK lib names that this java module is exporting
Jiyong Park1be96912018-05-28 18:02:19 +0900408 exportedSdkLibs []string
Brandon Lee5d45c6f2018-08-15 15:35:38 -0700409
Artur Satayev9cf46692019-11-26 18:08:34 +0000410 // list of plugins that this java module is exporting
411 exportedPluginJars android.Paths
412
413 // list of plugins that this java module is exporting
414 exportedPluginClasses []string
415
416 // list of source files, collected from srcFiles with unique java and all kt files,
patricktu242faad2019-09-24 15:41:30 +0800417 // will be used by android.IDEInfo struct
Brandon Lee5d45c6f2018-08-15 15:35:38 -0700418 expandIDEInfoCompiledSrcs []string
Colin Cross43f08db2018-11-12 10:13:39 -0800419
Steven Morelandc4efd9c2019-01-18 11:51:25 -0800420 // expanded Jarjar_rules
421 expandJarjarRules android.Path
422
Vladimir Marko0975ee02019-04-02 10:29:55 +0100423 // list of additional targets for checkbuild
424 additionalCheckedModules android.Paths
425
Colin Cross988708c2019-05-06 14:04:11 -0700426 // Extra files generated by the module type to be added as java resources.
427 extraResources android.Paths
428
Colin Crossf24a22a2019-01-31 14:12:44 -0800429 hiddenAPI
Colin Cross43f08db2018-11-12 10:13:39 -0800430 dexpreopter
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800431
432 // list of the xref extraction files
433 kytheFiles android.Paths
Anton Hansson1e65f942020-03-27 19:39:48 +0000434
435 distFile android.Path
Colin Cross2fe66872015-03-30 17:20:39 -0700436}
437
Colin Cross41955e82019-05-29 14:40:35 -0700438func (j *Module) OutputFiles(tag string) (android.Paths, error) {
439 switch tag {
440 case "":
441 return append(android.Paths{j.outputFile}, j.extraOutputFiles...), nil
Colin Cross375ca3c2019-05-29 14:40:58 -0700442 case ".jar":
443 return android.Paths{j.implementationAndResourcesJar}, nil
Colin Cross2d975b12019-07-29 16:47:42 -0700444 case ".proguard_map":
445 return android.Paths{j.proguardDictionary}, nil
Colin Cross41955e82019-05-29 14:40:35 -0700446 default:
447 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
448 }
Colin Cross54250902017-12-05 09:28:08 -0800449}
450
Colin Cross41955e82019-05-29 14:40:35 -0700451var _ android.OutputFileProducer = (*Module)(nil)
Colin Cross54250902017-12-05 09:28:08 -0800452
Colin Crossf506d872017-07-19 15:53:04 -0700453type Dependency interface {
Nan Zhanged19fc32017-10-19 13:06:22 -0700454 HeaderJars() android.Paths
455 ImplementationJars() android.Paths
Colin Cross331a1212018-08-15 20:40:52 -0700456 ResourceJars() android.Paths
457 ImplementationAndResourcesJars() android.Paths
Colin Crossf24a22a2019-01-31 14:12:44 -0800458 DexJar() android.Path
Colin Cross635c3b02016-05-18 15:37:25 -0700459 AidlIncludeDirs() android.Paths
Jiyong Park1be96912018-05-28 18:02:19 +0900460 ExportedSdkLibs() []string
Artur Satayev9cf46692019-11-26 18:08:34 +0000461 ExportedPlugins() (android.Paths, []string)
Colin Cross0c4ce212019-05-03 15:28:19 -0700462 SrcJarArgs() ([]string, android.Paths)
Colin Crosse323f3c2019-09-17 15:34:09 -0700463 BaseModuleName() string
Jiyong Park618922e2020-01-08 13:35:43 +0900464 JacocoReportClassesFile() android.Path
Colin Cross2fe66872015-03-30 17:20:39 -0700465}
466
Jiyong Parkc678ad32018-04-10 13:07:10 +0900467type SdkLibraryDependency interface {
Jiyong Park6a927c42020-01-21 02:03:43 +0900468 SdkHeaderJars(ctx android.BaseModuleContext, sdkVersion sdkSpec) android.Paths
469 SdkImplementationJars(ctx android.BaseModuleContext, sdkVersion sdkSpec) android.Paths
Jiyong Parkc678ad32018-04-10 13:07:10 +0900470}
471
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800472type xref interface {
473 XrefJavaFiles() android.Paths
474}
475
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800476func (j *Module) XrefJavaFiles() android.Paths {
477 return j.kytheFiles
478}
479
Colin Cross89536d42017-07-07 14:35:50 -0700480func InitJavaModule(module android.DefaultableModule, hod android.HostOrDeviceSupported) {
481 android.InitAndroidArchModule(module, hod, android.MultilibCommon)
482 android.InitDefaultableModule(module)
483}
484
Colin Crossbe1da472017-07-07 15:59:46 -0700485type dependencyTag struct {
486 blueprint.BaseDependencyTag
487 name string
Colin Cross2fe66872015-03-30 17:20:39 -0700488}
489
Colin Crossa4f08812018-10-02 22:03:40 -0700490type jniDependencyTag struct {
491 blueprint.BaseDependencyTag
Colin Crossa4f08812018-10-02 22:03:40 -0700492}
493
Jiyong Park8be103b2019-11-08 15:53:48 +0900494func IsJniDepTag(depTag blueprint.DependencyTag) bool {
495 _, ok := depTag.(*jniDependencyTag)
496 return ok
497}
498
Colin Crossbe1da472017-07-07 15:59:46 -0700499var (
Colin Cross4b964c02018-10-15 16:18:06 -0700500 staticLibTag = dependencyTag{name: "staticlib"}
501 libTag = dependencyTag{name: "javalib"}
Colin Cross6cef4812019-10-17 14:23:50 -0700502 java9LibTag = dependencyTag{name: "java9lib"}
Colin Crossbe9cdb82019-01-21 21:37:16 -0800503 pluginTag = dependencyTag{name: "plugin"}
Artur Satayev9cf46692019-11-26 18:08:34 +0000504 exportedPluginTag = dependencyTag{name: "exported-plugin"}
Colin Cross4b964c02018-10-15 16:18:06 -0700505 bootClasspathTag = dependencyTag{name: "bootclasspath"}
506 systemModulesTag = dependencyTag{name: "system modules"}
507 frameworkResTag = dependencyTag{name: "framework-res"}
508 frameworkApkTag = dependencyTag{name: "framework-apk"}
509 kotlinStdlibTag = dependencyTag{name: "kotlin-stdlib"}
Colin Crossafbb1732019-01-17 15:42:52 -0800510 kotlinAnnotationsTag = dependencyTag{name: "kotlin-annotations"}
Colin Cross4b964c02018-10-15 16:18:06 -0700511 proguardRaiseTag = dependencyTag{name: "proguard-raise"}
512 certificateTag = dependencyTag{name: "certificate"}
513 instrumentationForTag = dependencyTag{name: "instrumentation_for"}
Colin Cross50ddcc42019-05-16 12:28:22 -0700514 usesLibTag = dependencyTag{name: "uses-library"}
Colin Crossbe1da472017-07-07 15:59:46 -0700515)
Colin Cross2fe66872015-03-30 17:20:39 -0700516
Jiyong Park83dc74b2020-01-14 18:38:44 +0900517func IsLibDepTag(depTag blueprint.DependencyTag) bool {
518 return depTag == libTag
519}
520
521func IsStaticLibDepTag(depTag blueprint.DependencyTag) bool {
522 return depTag == staticLibTag
523}
524
Colin Crossfc3674a2017-09-18 17:41:52 -0700525type sdkDep struct {
Colin Cross47ff2522017-10-02 14:22:08 -0700526 useModule, useFiles, useDefaultLibs, invalidVersion bool
527
Colin Cross6cef4812019-10-17 14:23:50 -0700528 // The modules that will be added to the bootclasspath when targeting 1.8 or lower
529 bootclasspath []string
Paul Duffine25c6442019-10-11 13:50:28 +0100530
531 // The default system modules to use. Will be an empty string if no system
532 // modules are to be used.
Colin Cross1369cdb2017-09-29 17:58:17 -0700533 systemModules string
534
Colin Cross6cef4812019-10-17 14:23:50 -0700535 // The modules that will be added ot the classpath when targeting 1.9 or higher
536 java9Classpath []string
537
Colin Crossa97c5d32018-03-28 14:58:31 -0700538 frameworkResModule string
539
Colin Cross86a60ae2018-05-29 14:44:55 -0700540 jars android.Paths
Colin Cross3047fa22019-04-18 10:56:44 -0700541 aidl android.OptionalPath
Paul Duffin250e6192019-06-07 10:44:37 +0100542
543 noStandardLibs, noFrameworksLibs bool
544}
545
546func (s sdkDep) hasStandardLibs() bool {
547 return !s.noStandardLibs
548}
549
550func (s sdkDep) hasFrameworkLibs() bool {
551 return !s.noStandardLibs && !s.noFrameworksLibs
Colin Cross1369cdb2017-09-29 17:58:17 -0700552}
553
Colin Crossa4f08812018-10-02 22:03:40 -0700554type jniLib struct {
Jaewoong Jung37ca4a12020-03-26 14:01:48 -0700555 name string
556 path android.Path
557 target android.Target
558 coverageFile android.OptionalPath
Colin Crossa4f08812018-10-02 22:03:40 -0700559}
560
Colin Cross0ea8ba82019-06-06 14:33:29 -0700561func (j *Module) shouldInstrument(ctx android.BaseModuleContext) bool {
Colin Cross3144dfc2018-01-03 15:06:47 -0800562 return j.properties.Instrument && ctx.Config().IsEnvTrue("EMMA_INSTRUMENT")
563}
564
Colin Cross0ea8ba82019-06-06 14:33:29 -0700565func (j *Module) shouldInstrumentStatic(ctx android.BaseModuleContext) bool {
Colin Cross3144dfc2018-01-03 15:06:47 -0800566 return j.shouldInstrument(ctx) &&
567 (ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_STATIC") ||
568 ctx.Config().UnbundledBuild())
569}
570
Jiyong Park6a927c42020-01-21 02:03:43 +0900571func (j *Module) sdkVersion() sdkSpec {
572 return sdkSpecFrom(String(j.deviceProperties.Sdk_version))
Colin Cross83bb3162018-06-25 15:48:06 -0700573}
574
Paul Duffine25c6442019-10-11 13:50:28 +0100575func (j *Module) systemModules() string {
576 return proptools.String(j.deviceProperties.System_modules)
577}
578
Jiyong Park6a927c42020-01-21 02:03:43 +0900579func (j *Module) minSdkVersion() sdkSpec {
Colin Cross83bb3162018-06-25 15:48:06 -0700580 if j.deviceProperties.Min_sdk_version != nil {
Jiyong Park6a927c42020-01-21 02:03:43 +0900581 return sdkSpecFrom(*j.deviceProperties.Min_sdk_version)
Colin Cross83bb3162018-06-25 15:48:06 -0700582 }
583 return j.sdkVersion()
584}
585
Jiyong Park6a927c42020-01-21 02:03:43 +0900586func (j *Module) targetSdkVersion() sdkSpec {
Dan Willemsen419290a2018-10-31 15:28:47 -0700587 if j.deviceProperties.Target_sdk_version != nil {
Jiyong Park6a927c42020-01-21 02:03:43 +0900588 return sdkSpecFrom(*j.deviceProperties.Target_sdk_version)
Dan Willemsen419290a2018-10-31 15:28:47 -0700589 }
590 return j.sdkVersion()
591}
592
Jiyong Parkb02bb402019-12-03 00:43:57 +0900593func (j *Module) AvailableFor(what string) bool {
594 if what == android.AvailableToPlatform && Bool(j.deviceProperties.Hostdex) {
595 // Exception: for hostdex: true libraries, the platform variant is created
596 // even if it's not marked as available to platform. In that case, the platform
597 // variant is used only for the hostdex and not installed to the device.
598 return true
599 }
600 return j.ApexModuleBase.AvailableFor(what)
601}
602
Colin Crossbe1da472017-07-07 15:59:46 -0700603func (j *Module) deps(ctx android.BottomUpMutatorContext) {
Colin Cross1369cdb2017-09-29 17:58:17 -0700604 if ctx.Device() {
Paul Duffin250e6192019-06-07 10:44:37 +0100605 sdkDep := decodeSdkDep(ctx, sdkContext(j))
Colin Cross6d8d8c62019-10-28 15:10:03 -0700606 if sdkDep.useDefaultLibs {
607 ctx.AddVariationDependencies(nil, bootClasspathTag, config.DefaultBootclasspathLibraries...)
608 ctx.AddVariationDependencies(nil, systemModulesTag, config.DefaultSystemModules)
609 if sdkDep.hasFrameworkLibs() {
610 ctx.AddVariationDependencies(nil, libTag, config.DefaultLibraries...)
Colin Crossbe1da472017-07-07 15:59:46 -0700611 }
Colin Cross6d8d8c62019-10-28 15:10:03 -0700612 } else if sdkDep.useModule {
Colin Cross6cef4812019-10-17 14:23:50 -0700613 ctx.AddVariationDependencies(nil, bootClasspathTag, sdkDep.bootclasspath...)
Paul Duffine25c6442019-10-11 13:50:28 +0100614 ctx.AddVariationDependencies(nil, systemModulesTag, sdkDep.systemModules)
Colin Cross6cef4812019-10-17 14:23:50 -0700615 ctx.AddVariationDependencies(nil, java9LibTag, sdkDep.java9Classpath...)
Colin Cross6d8d8c62019-10-28 15:10:03 -0700616 if j.deviceProperties.EffectiveOptimizeEnabled() && sdkDep.hasStandardLibs() {
617 ctx.AddVariationDependencies(nil, proguardRaiseTag, config.DefaultBootclasspathLibraries...)
618 ctx.AddVariationDependencies(nil, proguardRaiseTag, config.DefaultLibraries...)
619 }
Colin Cross2fe66872015-03-30 17:20:39 -0700620 }
Colin Cross6d8d8c62019-10-28 15:10:03 -0700621
Nan Zhangb2b33de2018-02-23 11:18:47 -0800622 if ctx.ModuleName() == "android_stubs_current" ||
623 ctx.ModuleName() == "android_system_stubs_current" ||
Nan Zhang863f05b2018-08-07 13:41:10 -0700624 ctx.ModuleName() == "android_test_stubs_current" {
Colin Cross42d48b72018-08-29 14:10:52 -0700625 ctx.AddVariationDependencies(nil, frameworkApkTag, "framework-res")
Nan Zhangb2b33de2018-02-23 11:18:47 -0800626 }
Colin Cross2fe66872015-03-30 17:20:39 -0700627 }
Colin Cross1369cdb2017-09-29 17:58:17 -0700628
Inseob Kimac1e9862019-12-09 18:15:47 +0900629 syspropPublicStubs := syspropPublicStubs(ctx.Config())
630
631 // rewriteSyspropLibs validates if a java module can link against platform's sysprop_library,
632 // and redirects dependency to public stub depending on the link type.
633 rewriteSyspropLibs := func(libs []string, prop string) []string {
634 // make a copy
635 ret := android.CopyOf(libs)
636
637 for idx, lib := range libs {
638 stub, ok := syspropPublicStubs[lib]
639
640 if !ok {
641 continue
642 }
643
644 linkType, _ := j.getLinkType(ctx.ModuleName())
Inseob Kimc5239512020-01-14 15:36:21 +0900645 // only platform modules can use internal props
646 if linkType != javaPlatform {
Inseob Kimac1e9862019-12-09 18:15:47 +0900647 ret[idx] = stub
Inseob Kimac1e9862019-12-09 18:15:47 +0900648 }
649 }
650
651 return ret
652 }
653
654 ctx.AddVariationDependencies(nil, libTag, rewriteSyspropLibs(j.properties.Libs, "libs")...)
655 ctx.AddVariationDependencies(nil, staticLibTag, rewriteSyspropLibs(j.properties.Static_libs, "static_libs")...)
Colin Crossa4f08812018-10-02 22:03:40 -0700656
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700657 ctx.AddFarVariationDependencies(ctx.Config().BuildOSCommonTarget.Variations(), pluginTag, j.properties.Plugins...)
Artur Satayev9cf46692019-11-26 18:08:34 +0000658 ctx.AddFarVariationDependencies(ctx.Config().BuildOSCommonTarget.Variations(), exportedPluginTag, j.properties.Exported_plugins...)
Colin Crossbe9cdb82019-01-21 21:37:16 -0800659
Colin Crossfe17f6f2019-03-28 19:30:56 -0700660 android.ProtoDeps(ctx, &j.protoProperties)
Colin Cross6af17aa2017-09-20 12:59:05 -0700661 if j.hasSrcExt(".proto") {
662 protoDeps(ctx, &j.protoProperties)
663 }
Colin Cross93e85952017-08-15 13:34:18 -0700664
665 if j.hasSrcExt(".kt") {
666 // TODO(ccross): move this to a mutator pass that can tell if generated sources contain
667 // Kotlin files
Colin Cross0b03d972019-05-13 11:06:25 -0700668 ctx.AddVariationDependencies(nil, kotlinStdlibTag,
669 "kotlin-stdlib", "kotlin-stdlib-jdk7", "kotlin-stdlib-jdk8")
Colin Cross7788c122019-01-23 16:14:02 -0800670 if len(j.properties.Plugins) > 0 {
Colin Crossafbb1732019-01-17 15:42:52 -0800671 ctx.AddVariationDependencies(nil, kotlinAnnotationsTag, "kotlin-annotations")
672 }
Colin Cross93e85952017-08-15 13:34:18 -0700673 }
Colin Cross3144dfc2018-01-03 15:06:47 -0800674
Ulya Trafimovich38dfa0f2020-01-07 16:37:02 +0000675 // Framework libraries need special handling in static coverage builds: they should not have
676 // static dependency on jacoco, otherwise there would be multiple conflicting definitions of
677 // the same jacoco classes coming from different bootclasspath jars.
678 if inList(ctx.ModuleName(), config.InstrumentFrameworkModules) {
679 if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
680 j.properties.Instrument = true
681 }
682 } else if j.shouldInstrumentStatic(ctx) {
Colin Cross42d48b72018-08-29 14:10:52 -0700683 ctx.AddVariationDependencies(nil, staticLibTag, "jacocoagent")
Colin Cross3144dfc2018-01-03 15:06:47 -0800684 }
Colin Cross6af17aa2017-09-20 12:59:05 -0700685}
686
687func hasSrcExt(srcs []string, ext string) bool {
688 for _, src := range srcs {
689 if filepath.Ext(src) == ext {
690 return true
691 }
692 }
693
694 return false
695}
696
697func (j *Module) hasSrcExt(ext string) bool {
698 return hasSrcExt(j.properties.Srcs, ext)
Colin Cross2fe66872015-03-30 17:20:39 -0700699}
700
Colin Cross46c9b8b2017-06-22 16:51:17 -0700701func (j *Module) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.OptionalPath,
Colin Cross3047fa22019-04-18 10:56:44 -0700702 aidlIncludeDirs android.Paths) (string, android.Paths) {
Colin Crossc0b06f12015-04-08 13:03:43 -0700703
Colin Crossebe1a512017-11-14 13:12:14 -0800704 aidlIncludes := android.PathsForModuleSrc(ctx, j.deviceProperties.Aidl.Local_include_dirs)
705 aidlIncludes = append(aidlIncludes,
706 android.PathsForModuleSrc(ctx, j.deviceProperties.Aidl.Export_include_dirs)...)
707 aidlIncludes = append(aidlIncludes,
708 android.PathsForSource(ctx, j.deviceProperties.Aidl.Include_dirs)...)
Colin Crossc0b06f12015-04-08 13:03:43 -0700709
Colin Cross3047fa22019-04-18 10:56:44 -0700710 var flags []string
711 var deps android.Paths
Steven Moreland667f6882018-07-26 12:55:08 -0700712
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700713 if aidlPreprocess.Valid() {
714 flags = append(flags, "-p"+aidlPreprocess.String())
Colin Cross3047fa22019-04-18 10:56:44 -0700715 deps = append(deps, aidlPreprocess.Path())
716 } else if len(aidlIncludeDirs) > 0 {
Colin Cross635c3b02016-05-18 15:37:25 -0700717 flags = append(flags, android.JoinWithPrefix(aidlIncludeDirs.Strings(), "-I"))
Colin Crossc0b06f12015-04-08 13:03:43 -0700718 }
719
Colin Cross3047fa22019-04-18 10:56:44 -0700720 if len(j.exportAidlIncludeDirs) > 0 {
721 flags = append(flags, android.JoinWithPrefix(j.exportAidlIncludeDirs.Strings(), "-I"))
722 }
723
724 if len(aidlIncludes) > 0 {
725 flags = append(flags, android.JoinWithPrefix(aidlIncludes.Strings(), "-I"))
726 }
727
Colin Cross635c3b02016-05-18 15:37:25 -0700728 flags = append(flags, "-I"+android.PathForModuleSrc(ctx).String())
Colin Cross32f38982018-02-22 11:47:25 -0800729 if src := android.ExistentPathForSource(ctx, ctx.ModuleDir(), "src"); src.Valid() {
Colin Crossd48633a2017-07-13 14:41:17 -0700730 flags = append(flags, "-I"+src.String())
731 }
Colin Crossc0b06f12015-04-08 13:03:43 -0700732
Martijn Coeneneab15642018-03-09 09:29:59 +0100733 if Bool(j.deviceProperties.Aidl.Generate_traces) {
734 flags = append(flags, "-t")
735 }
736
Olivier Gaillard0a4cfbc2018-07-16 23:37:03 +0100737 if Bool(j.deviceProperties.Aidl.Generate_get_transaction_name) {
738 flags = append(flags, "--transaction_names")
739 }
740
Colin Cross3047fa22019-04-18 10:56:44 -0700741 return strings.Join(flags, " "), deps
Colin Crossc0b06f12015-04-08 13:03:43 -0700742}
743
Colin Cross32f676a2017-09-06 13:41:06 -0700744type deps struct {
Nan Zhang581fd212018-01-10 16:06:12 -0800745 classpath classpath
Colin Cross6cef4812019-10-17 14:23:50 -0700746 java9Classpath classpath
Nan Zhang581fd212018-01-10 16:06:12 -0800747 bootClasspath classpath
Colin Cross6a77c982018-06-19 22:43:34 -0700748 processorPath classpath
Colin Crossbe9cdb82019-01-21 21:37:16 -0800749 processorClasses []string
Colin Cross6ade34f2017-09-15 13:00:47 -0700750 staticJars android.Paths
Nan Zhanged19fc32017-10-19 13:06:22 -0700751 staticHeaderJars android.Paths
Colin Cross331a1212018-08-15 20:40:52 -0700752 staticResourceJars android.Paths
Colin Cross6ade34f2017-09-15 13:00:47 -0700753 aidlIncludeDirs android.Paths
Nan Zhangb2b33de2018-02-23 11:18:47 -0800754 srcs android.Paths
Colin Cross59149b62017-10-16 18:07:29 -0700755 srcJars android.Paths
Colin Crossb77043e2019-07-16 13:57:13 -0700756 systemModules *systemModules
Colin Cross6ade34f2017-09-15 13:00:47 -0700757 aidlPreprocess android.OptionalPath
Colin Cross93e85952017-08-15 13:34:18 -0700758 kotlinStdlib android.Paths
Colin Crossafbb1732019-01-17 15:42:52 -0800759 kotlinAnnotations android.Paths
Colin Crossbe9cdb82019-01-21 21:37:16 -0800760
761 disableTurbine bool
Colin Cross32f676a2017-09-06 13:41:06 -0700762}
Colin Cross2fe66872015-03-30 17:20:39 -0700763
Colin Cross54250902017-12-05 09:28:08 -0800764func checkProducesJars(ctx android.ModuleContext, dep android.SourceFileProducer) {
765 for _, f := range dep.Srcs() {
766 if f.Ext() != ".jar" {
767 ctx.ModuleErrorf("genrule %q must generate files ending with .jar to be used as a libs or static_libs dependency",
768 ctx.OtherModuleName(dep.(blueprint.Module)))
769 }
770 }
771}
772
Jiyong Park2d492942018-03-05 17:44:10 +0900773type linkType int
774
775const (
Jiyong Park50146e92020-01-30 18:00:15 +0900776 // TODO(jiyong) rename these for better readability. Make the allowed
777 // and disallowed link types explicit
Jiyong Park2d492942018-03-05 17:44:10 +0900778 javaCore linkType = iota
779 javaSdk
780 javaSystem
Jiyong Park50146e92020-01-30 18:00:15 +0900781 javaModule
Jiyong Parkaae9bd12020-02-12 04:36:43 +0900782 javaSystemServer
Jiyong Park2d492942018-03-05 17:44:10 +0900783 javaPlatform
784)
785
Jeongik Cha75b83b02019-11-01 15:28:00 +0900786type linkTypeContext interface {
787 android.Module
788 getLinkType(name string) (ret linkType, stubs bool)
789}
790
791func (m *Module) getLinkType(name string) (ret linkType, stubs bool) {
Colin Cross83bb3162018-06-25 15:48:06 -0700792 ver := m.sdkVersion()
Colin Crossf19b9bb2018-03-26 14:42:44 -0700793 switch {
Jiyong Park46f78fb2018-10-20 16:33:17 +0900794 case name == "core.current.stubs" || name == "core.platform.api.stubs" ||
795 name == "stub-annotations" || name == "private-stub-annotations-jar" ||
Pete Gillincbff3262019-05-08 15:10:06 +0100796 name == "core-lambda-stubs" || name == "core-generated-annotation-stubs":
Jiyong Park46f78fb2018-10-20 16:33:17 +0900797 return javaCore, true
Jiyong Park6a927c42020-01-21 02:03:43 +0900798 case ver.kind == sdkCore:
Jiyong Park46f78fb2018-10-20 16:33:17 +0900799 return javaCore, false
800 case name == "android_system_stubs_current":
801 return javaSystem, true
Jiyong Park6a927c42020-01-21 02:03:43 +0900802 case ver.kind == sdkSystem:
Jiyong Park46f78fb2018-10-20 16:33:17 +0900803 return javaSystem, false
804 case name == "android_test_stubs_current":
805 return javaSystem, true
Jiyong Park6a927c42020-01-21 02:03:43 +0900806 case ver.kind == sdkTest:
Jiyong Park46f78fb2018-10-20 16:33:17 +0900807 return javaPlatform, false
808 case name == "android_stubs_current":
809 return javaSdk, true
Jiyong Park6a927c42020-01-21 02:03:43 +0900810 case ver.kind == sdkPublic:
Jiyong Park46f78fb2018-10-20 16:33:17 +0900811 return javaSdk, false
Jiyong Park50146e92020-01-30 18:00:15 +0900812 case name == "android_module_lib_stubs_current":
813 return javaModule, true
814 case ver.kind == sdkModule:
815 return javaModule, false
Anton Hanssonbbd78552020-03-19 15:23:38 +0000816 case name == "android_system_server_stubs_current":
Jiyong Parkaae9bd12020-02-12 04:36:43 +0900817 return javaSystemServer, true
818 case ver.kind == sdkSystemServer:
819 return javaSystemServer, false
Jiyong Park6a927c42020-01-21 02:03:43 +0900820 case ver.kind == sdkPrivate || ver.kind == sdkNone || ver.kind == sdkCorePlatform:
Jiyong Park46f78fb2018-10-20 16:33:17 +0900821 return javaPlatform, false
Jiyong Park6a927c42020-01-21 02:03:43 +0900822 case !ver.valid():
823 panic(fmt.Errorf("sdk_version is invalid. got %q", ver.raw))
Colin Crossf19b9bb2018-03-26 14:42:44 -0700824 default:
Jiyong Park46f78fb2018-10-20 16:33:17 +0900825 return javaSdk, false
Jiyong Park2d492942018-03-05 17:44:10 +0900826 }
827}
828
Jeongik Cha75b83b02019-11-01 15:28:00 +0900829func checkLinkType(ctx android.ModuleContext, from *Module, to linkTypeContext, tag dependencyTag) {
Colin Crossf19b9bb2018-03-26 14:42:44 -0700830 if ctx.Host() {
831 return
832 }
833
Jeongik Cha75b83b02019-11-01 15:28:00 +0900834 myLinkType, stubs := from.getLinkType(ctx.ModuleName())
Jiyong Park46f78fb2018-10-20 16:33:17 +0900835 if stubs {
836 return
837 }
Jeongik Cha75b83b02019-11-01 15:28:00 +0900838 otherLinkType, _ := to.getLinkType(ctx.OtherModuleName(to))
Jiyong Park2d492942018-03-05 17:44:10 +0900839 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."
840
841 switch myLinkType {
842 case javaCore:
843 if otherLinkType != javaCore {
844 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 +0900845 ctx.OtherModuleName(to))
846 }
Jiyong Park2d492942018-03-05 17:44:10 +0900847 break
848 case javaSdk:
849 if otherLinkType != javaCore && otherLinkType != javaSdk {
850 ctx.ModuleErrorf("compiles against Android API, but dependency %q is compiling against non-public Android API."+commonMessage,
851 ctx.OtherModuleName(to))
852 }
853 break
854 case javaSystem:
Jiyong Parkaae9bd12020-02-12 04:36:43 +0900855 if otherLinkType == javaPlatform || otherLinkType == javaModule || otherLinkType == javaSystemServer {
Jiyong Park2d492942018-03-05 17:44:10 +0900856 ctx.ModuleErrorf("compiles against system API, but dependency %q is compiling against private API."+commonMessage,
857 ctx.OtherModuleName(to))
858 }
859 break
Jiyong Park50146e92020-01-30 18:00:15 +0900860 case javaModule:
Jiyong Parkaae9bd12020-02-12 04:36:43 +0900861 if otherLinkType == javaPlatform || otherLinkType == javaSystemServer {
Jiyong Park50146e92020-01-30 18:00:15 +0900862 ctx.ModuleErrorf("compiles against module API, but dependency %q is compiling against private API."+commonMessage,
863 ctx.OtherModuleName(to))
864 }
865 break
Jiyong Parkaae9bd12020-02-12 04:36:43 +0900866 case javaSystemServer:
867 if otherLinkType == javaPlatform {
868 ctx.ModuleErrorf("compiles against system server API, but dependency %q is compiling against private API."+commonMessage,
869 ctx.OtherModuleName(to))
870 }
871 break
Jiyong Park2d492942018-03-05 17:44:10 +0900872 case javaPlatform:
873 // no restriction on link-type
874 break
Jiyong Park750e5572018-01-31 00:20:13 +0900875 }
876}
877
Colin Cross32f676a2017-09-06 13:41:06 -0700878func (j *Module) collectDeps(ctx android.ModuleContext) deps {
879 var deps deps
Colin Crossfc3674a2017-09-18 17:41:52 -0700880
Colin Cross300f0382018-03-06 13:11:51 -0800881 if ctx.Device() {
Colin Cross83bb3162018-06-25 15:48:06 -0700882 sdkDep := decodeSdkDep(ctx, sdkContext(j))
Colin Cross300f0382018-03-06 13:11:51 -0800883 if sdkDep.invalidVersion {
Colin Cross6cef4812019-10-17 14:23:50 -0700884 ctx.AddMissingDependencies(sdkDep.bootclasspath)
885 ctx.AddMissingDependencies(sdkDep.java9Classpath)
Colin Cross300f0382018-03-06 13:11:51 -0800886 } else if sdkDep.useFiles {
887 // sdkDep.jar is actually equivalent to turbine header.jar.
Colin Cross86a60ae2018-05-29 14:44:55 -0700888 deps.classpath = append(deps.classpath, sdkDep.jars...)
Colin Cross3047fa22019-04-18 10:56:44 -0700889 deps.aidlPreprocess = sdkDep.aidl
890 } else {
891 deps.aidlPreprocess = sdkDep.aidl
Colin Cross300f0382018-03-06 13:11:51 -0800892 }
Colin Crossfc3674a2017-09-18 17:41:52 -0700893 }
894
Colin Crossd11fcda2017-10-23 17:59:01 -0700895 ctx.VisitDirectDeps(func(module android.Module) {
Colin Cross2fe66872015-03-30 17:20:39 -0700896 otherName := ctx.OtherModuleName(module)
Colin Crossec7a0422017-07-07 14:47:12 -0700897 tag := ctx.OtherModuleDependencyTag(module)
898
Colin Crossa4f08812018-10-02 22:03:40 -0700899 if _, ok := tag.(*jniDependencyTag); ok {
Colin Crossbd01e2a2018-10-04 15:21:03 -0700900 // Handled by AndroidApp.collectAppDeps
901 return
902 }
903 if tag == certificateTag {
904 // Handled by AndroidApp.collectAppDeps
Colin Crossa4f08812018-10-02 22:03:40 -0700905 return
906 }
Artur Satayeve5ac15a2020-04-08 19:09:30 +0100907
Colin Cross54250902017-12-05 09:28:08 -0800908 switch dep := module.(type) {
Colin Cross897d2ed2019-02-11 14:03:51 -0800909 case SdkLibraryDependency:
910 switch tag {
911 case libTag:
912 deps.classpath = append(deps.classpath, dep.SdkHeaderJars(ctx, j.sdkVersion())...)
913 // names of sdk libs that are directly depended are exported
914 j.exportedSdkLibs = append(j.exportedSdkLibs, otherName)
Colin Cross79c7c262019-04-17 11:11:46 -0700915 case staticLibTag:
Colin Cross897d2ed2019-02-11 14:03:51 -0800916 ctx.ModuleErrorf("dependency on java_sdk_library %q can only be in libs", otherName)
917 }
Colin Cross54250902017-12-05 09:28:08 -0800918 case Dependency:
919 switch tag {
920 case bootClasspathTag:
921 deps.bootClasspath = append(deps.bootClasspath, dep.HeaderJars()...)
Colin Cross4b964c02018-10-15 16:18:06 -0700922 case libTag, instrumentationForTag:
Colin Cross54250902017-12-05 09:28:08 -0800923 deps.classpath = append(deps.classpath, dep.HeaderJars()...)
Jiyong Park1be96912018-05-28 18:02:19 +0900924 // sdk lib names from dependencies are re-exported
925 j.exportedSdkLibs = append(j.exportedSdkLibs, dep.ExportedSdkLibs()...)
Colin Cross3047fa22019-04-18 10:56:44 -0700926 deps.aidlIncludeDirs = append(deps.aidlIncludeDirs, dep.AidlIncludeDirs()...)
Artur Satayev9cf46692019-11-26 18:08:34 +0000927 pluginJars, pluginClasses := dep.ExportedPlugins()
928 addPlugins(&deps, pluginJars, pluginClasses...)
Colin Cross6cef4812019-10-17 14:23:50 -0700929 case java9LibTag:
930 deps.java9Classpath = append(deps.java9Classpath, dep.HeaderJars()...)
Colin Cross54250902017-12-05 09:28:08 -0800931 case staticLibTag:
932 deps.classpath = append(deps.classpath, dep.HeaderJars()...)
933 deps.staticJars = append(deps.staticJars, dep.ImplementationJars()...)
934 deps.staticHeaderJars = append(deps.staticHeaderJars, dep.HeaderJars()...)
Colin Cross331a1212018-08-15 20:40:52 -0700935 deps.staticResourceJars = append(deps.staticResourceJars, dep.ResourceJars()...)
Jiyong Park1be96912018-05-28 18:02:19 +0900936 // sdk lib names from dependencies are re-exported
937 j.exportedSdkLibs = append(j.exportedSdkLibs, dep.ExportedSdkLibs()...)
Colin Cross3047fa22019-04-18 10:56:44 -0700938 deps.aidlIncludeDirs = append(deps.aidlIncludeDirs, dep.AidlIncludeDirs()...)
Artur Satayev9cf46692019-11-26 18:08:34 +0000939 pluginJars, pluginClasses := dep.ExportedPlugins()
940 addPlugins(&deps, pluginJars, pluginClasses...)
Colin Crossbe9cdb82019-01-21 21:37:16 -0800941 case pluginTag:
942 if plugin, ok := dep.(*Plugin); ok {
Colin Crossbe9cdb82019-01-21 21:37:16 -0800943 if plugin.pluginProperties.Processor_class != nil {
Artur Satayev9cf46692019-11-26 18:08:34 +0000944 addPlugins(&deps, plugin.ImplementationAndResourcesJars(), *plugin.pluginProperties.Processor_class)
945 } else {
946 addPlugins(&deps, plugin.ImplementationAndResourcesJars())
Colin Crossbe9cdb82019-01-21 21:37:16 -0800947 }
948 deps.disableTurbine = deps.disableTurbine || Bool(plugin.pluginProperties.Generates_api)
949 } else {
950 ctx.PropertyErrorf("plugins", "%q is not a java_plugin module", otherName)
951 }
Artur Satayev9cf46692019-11-26 18:08:34 +0000952 case exportedPluginTag:
953 if plugin, ok := dep.(*Plugin); ok {
954 if plugin.pluginProperties.Generates_api != nil && *plugin.pluginProperties.Generates_api {
955 ctx.PropertyErrorf("exported_plugins", "Cannot export plugins with generates_api = true, found %v", otherName)
956 }
957 j.exportedPluginJars = append(j.exportedPluginJars, plugin.ImplementationAndResourcesJars()...)
958 if plugin.pluginProperties.Processor_class != nil {
959 j.exportedPluginClasses = append(j.exportedPluginClasses, *plugin.pluginProperties.Processor_class)
960 }
961 } else {
962 ctx.PropertyErrorf("exported_plugins", "%q is not a java_plugin module", otherName)
963 }
Nan Zhangb2b33de2018-02-23 11:18:47 -0800964 case frameworkApkTag:
965 if ctx.ModuleName() == "android_stubs_current" ||
966 ctx.ModuleName() == "android_system_stubs_current" ||
Nan Zhang863f05b2018-08-07 13:41:10 -0700967 ctx.ModuleName() == "android_test_stubs_current" {
Nan Zhangb2b33de2018-02-23 11:18:47 -0800968 // framework stubs.jar need to depend on framework-res.apk, in order to pull the
969 // resource files out of there for aapt.
970 //
971 // Normally the package rule runs aapt, which includes the resource,
972 // but we're not running that in our package rule so just copy in the
973 // resource files here.
Colin Cross331a1212018-08-15 20:40:52 -0700974 deps.staticResourceJars = append(deps.staticResourceJars, dep.(*AndroidApp).exportPackage)
Nan Zhangb2b33de2018-02-23 11:18:47 -0800975 }
Colin Cross54250902017-12-05 09:28:08 -0800976 case kotlinStdlibTag:
Colin Cross0b03d972019-05-13 11:06:25 -0700977 deps.kotlinStdlib = append(deps.kotlinStdlib, dep.HeaderJars()...)
Colin Crossafbb1732019-01-17 15:42:52 -0800978 case kotlinAnnotationsTag:
979 deps.kotlinAnnotations = dep.HeaderJars()
Colin Cross54250902017-12-05 09:28:08 -0800980 }
981
Colin Cross54250902017-12-05 09:28:08 -0800982 case android.SourceFileProducer:
983 switch tag {
984 case libTag:
985 checkProducesJars(ctx, dep)
986 deps.classpath = append(deps.classpath, dep.Srcs()...)
987 case staticLibTag:
988 checkProducesJars(ctx, dep)
989 deps.classpath = append(deps.classpath, dep.Srcs()...)
990 deps.staticJars = append(deps.staticJars, dep.Srcs()...)
991 deps.staticHeaderJars = append(deps.staticHeaderJars, dep.Srcs()...)
Colin Cross54250902017-12-05 09:28:08 -0800992 }
993 default:
Colin Crossec7a0422017-07-07 14:47:12 -0700994 switch tag {
Paul Duffin68289b02019-09-20 13:50:52 +0100995 case bootClasspathTag:
996 // If a system modules dependency has been added to the bootclasspath
997 // then add its libs to the bootclasspath.
Paul Duffin83a2d962019-11-19 19:44:10 +0000998 sm := module.(SystemModulesProvider)
999 deps.bootClasspath = append(deps.bootClasspath, sm.HeaderJars()...)
Paul Duffin68289b02019-09-20 13:50:52 +01001000
Colin Cross1369cdb2017-09-29 17:58:17 -07001001 case systemModulesTag:
1002 if deps.systemModules != nil {
1003 panic("Found two system module dependencies")
1004 }
Paul Duffin83a2d962019-11-19 19:44:10 +00001005 sm := module.(SystemModulesProvider)
1006 outputDir, outputDeps := sm.OutputDirAndDeps()
1007 deps.systemModules = &systemModules{outputDir, outputDeps}
Colin Cross2fe66872015-03-30 17:20:39 -07001008 }
Colin Crossec7a0422017-07-07 14:47:12 -07001009 }
Colin Cross2fe66872015-03-30 17:20:39 -07001010 })
1011
Jiyong Park1be96912018-05-28 18:02:19 +09001012 j.exportedSdkLibs = android.FirstUniqueStrings(j.exportedSdkLibs)
1013
Colin Cross32f676a2017-09-06 13:41:06 -07001014 return deps
Colin Cross2fe66872015-03-30 17:20:39 -07001015}
1016
Artur Satayev9cf46692019-11-26 18:08:34 +00001017func addPlugins(deps *deps, pluginJars android.Paths, pluginClasses ...string) {
1018 deps.processorPath = append(deps.processorPath, pluginJars...)
1019 deps.processorClasses = append(deps.processorClasses, pluginClasses...)
1020}
1021
Colin Cross1e743852019-10-28 11:37:20 -07001022func getJavaVersion(ctx android.ModuleContext, javaVersion string, sdkContext sdkContext) javaVersion {
Jiyong Park6a927c42020-01-21 02:03:43 +09001023 sdk, err := sdkContext.sdkVersion().effectiveVersion(ctx)
Colin Cross83bb3162018-06-25 15:48:06 -07001024 if err != nil {
1025 ctx.PropertyErrorf("sdk_version", "%s", err)
1026 }
Nan Zhang357466b2018-04-17 17:38:36 -07001027 if javaVersion != "" {
Colin Cross1e743852019-10-28 11:37:20 -07001028 return normalizeJavaVersion(ctx, javaVersion)
Nan Zhang357466b2018-04-17 17:38:36 -07001029 } else if ctx.Device() && sdk <= 23 {
Colin Cross1e743852019-10-28 11:37:20 -07001030 return JAVA_VERSION_7
Pete Gillina1c9e9d2019-10-17 14:52:07 +01001031 } else if ctx.Device() && sdk <= 29 {
Colin Cross1e743852019-10-28 11:37:20 -07001032 return JAVA_VERSION_8
Colin Cross6cef4812019-10-17 14:23:50 -07001033 } else if ctx.Device() && ctx.Config().UnbundledBuildUsePrebuiltSdks() {
1034 // TODO(b/142896162): once we have prebuilt system modules we can use 1.9 for unbundled builds
Colin Cross1e743852019-10-28 11:37:20 -07001035 return JAVA_VERSION_8
Nan Zhang357466b2018-04-17 17:38:36 -07001036 } else {
Colin Cross1e743852019-10-28 11:37:20 -07001037 return JAVA_VERSION_9
Nan Zhang357466b2018-04-17 17:38:36 -07001038 }
Nan Zhang357466b2018-04-17 17:38:36 -07001039}
1040
Colin Cross1e743852019-10-28 11:37:20 -07001041type javaVersion int
1042
1043const (
1044 JAVA_VERSION_UNSUPPORTED = 0
1045 JAVA_VERSION_6 = 6
1046 JAVA_VERSION_7 = 7
1047 JAVA_VERSION_8 = 8
1048 JAVA_VERSION_9 = 9
1049)
1050
1051func (v javaVersion) String() string {
1052 switch v {
1053 case JAVA_VERSION_6:
1054 return "1.6"
1055 case JAVA_VERSION_7:
1056 return "1.7"
1057 case JAVA_VERSION_8:
1058 return "1.8"
1059 case JAVA_VERSION_9:
1060 return "1.9"
1061 default:
1062 return "unsupported"
1063 }
1064}
1065
1066// Returns true if javac targeting this version uses system modules instead of a bootclasspath.
1067func (v javaVersion) usesJavaModules() bool {
1068 return v >= 9
1069}
1070
1071func normalizeJavaVersion(ctx android.BaseModuleContext, javaVersion string) javaVersion {
Pete Gillin4e8b48a2019-07-12 13:16:17 +01001072 switch javaVersion {
1073 case "1.6", "6":
Colin Cross1e743852019-10-28 11:37:20 -07001074 return JAVA_VERSION_6
Pete Gillin4e8b48a2019-07-12 13:16:17 +01001075 case "1.7", "7":
Colin Cross1e743852019-10-28 11:37:20 -07001076 return JAVA_VERSION_7
Pete Gillin4e8b48a2019-07-12 13:16:17 +01001077 case "1.8", "8":
Colin Cross1e743852019-10-28 11:37:20 -07001078 return JAVA_VERSION_8
Pete Gillin4e8b48a2019-07-12 13:16:17 +01001079 case "1.9", "9":
Colin Cross1e743852019-10-28 11:37:20 -07001080 return JAVA_VERSION_9
Pete Gillin4e8b48a2019-07-12 13:16:17 +01001081 case "10", "11":
1082 ctx.PropertyErrorf("java_version", "Java language levels above 9 are not supported")
Colin Cross1e743852019-10-28 11:37:20 -07001083 return JAVA_VERSION_UNSUPPORTED
Pete Gillin4e8b48a2019-07-12 13:16:17 +01001084 default:
1085 ctx.PropertyErrorf("java_version", "Unrecognized Java language level")
Colin Cross1e743852019-10-28 11:37:20 -07001086 return JAVA_VERSION_UNSUPPORTED
Pete Gillin4e8b48a2019-07-12 13:16:17 +01001087 }
1088}
1089
Nan Zhanged19fc32017-10-19 13:06:22 -07001090func (j *Module) collectBuilderFlags(ctx android.ModuleContext, deps deps) javaBuilderFlags {
Colin Crossc0b06f12015-04-08 13:03:43 -07001091
Colin Crossf03c82b2015-04-13 13:53:40 -07001092 var flags javaBuilderFlags
1093
Tobias Thierer06dd04f2018-09-11 16:21:05 +01001094 // javaVersion flag.
1095 flags.javaVersion = getJavaVersion(ctx, String(j.properties.Java_version), sdkContext(j))
1096
Nan Zhanged19fc32017-10-19 13:06:22 -07001097 // javac flags.
Colin Crossf03c82b2015-04-13 13:53:40 -07001098 javacFlags := j.properties.Javacflags
Colin Cross1e743852019-10-28 11:37:20 -07001099 if flags.javaVersion.usesJavaModules() {
Colin Cross1369cdb2017-09-29 17:58:17 -07001100 javacFlags = append(javacFlags, j.properties.Openjdk9.Javacflags...)
Nan Zhanged19fc32017-10-19 13:06:22 -07001101 }
Colin Cross6510f912017-11-29 00:27:14 -08001102 if ctx.Config().MinimizeJavaDebugInfo() {
Colin Cross126a25c2017-10-31 13:55:34 -07001103 // Override the -g flag passed globally to remove local variable debug info to reduce
1104 // disk and memory usage.
1105 javacFlags = append(javacFlags, "-g:source,lines")
1106 }
Colin Crossc228a702019-11-06 16:18:05 -08001107 javacFlags = append(javacFlags, "-Xlint:-dep-ann")
Colin Cross64162712017-08-08 13:17:59 -07001108
Colin Cross66548102018-06-19 22:47:35 -07001109 if ctx.Config().RunErrorProne() {
1110 if config.ErrorProneClasspath == nil {
1111 ctx.ModuleErrorf("cannot build with Error Prone, missing external/error_prone?")
1112 }
1113
1114 errorProneFlags := []string{
1115 "-Xplugin:ErrorProne",
1116 "${config.ErrorProneChecks}",
1117 }
1118 errorProneFlags = append(errorProneFlags, j.properties.Errorprone.Javacflags...)
1119
1120 flags.errorProneExtraJavacFlags = "${config.ErrorProneFlags} " +
1121 "'" + strings.Join(errorProneFlags, " ") + "'"
1122 flags.errorProneProcessorPath = classpath(android.PathsForSource(ctx, config.ErrorProneClasspath))
Andreas Gampef3e5b552018-01-22 21:27:21 -08001123 }
1124
Nan Zhanged19fc32017-10-19 13:06:22 -07001125 // classpath
Nan Zhang581fd212018-01-10 16:06:12 -08001126 flags.bootClasspath = append(flags.bootClasspath, deps.bootClasspath...)
1127 flags.classpath = append(flags.classpath, deps.classpath...)
Colin Cross6cef4812019-10-17 14:23:50 -07001128 flags.java9Classpath = append(flags.java9Classpath, deps.java9Classpath...)
Colin Cross6a77c982018-06-19 22:43:34 -07001129 flags.processorPath = append(flags.processorPath, deps.processorPath...)
Colin Cross7fdd2b72018-01-02 18:14:25 -08001130
Colin Crossbe9cdb82019-01-21 21:37:16 -08001131 flags.processor = strings.Join(deps.processorClasses, ",")
1132
Colin Cross1e743852019-10-28 11:37:20 -07001133 if len(flags.bootClasspath) == 0 && ctx.Host() && !flags.javaVersion.usesJavaModules() &&
1134 decodeSdkDep(ctx, sdkContext(j)).hasStandardLibs() {
Colin Cross7fdd2b72018-01-02 18:14:25 -08001135 // Give host-side tools a version of OpenJDK's standard libraries
1136 // close to what they're targeting. As of Dec 2017, AOSP is only
1137 // bundling OpenJDK 8 and 9, so nothing < 8 is available.
1138 //
1139 // When building with OpenJDK 8, the following should have no
1140 // effect since those jars would be available by default.
1141 //
1142 // When building with OpenJDK 9 but targeting a version < 1.8,
1143 // putting them on the bootclasspath means that:
1144 // a) code can't (accidentally) refer to OpenJDK 9 specific APIs
1145 // b) references to existing APIs are not reinterpreted in an
1146 // OpenJDK 9-specific way, eg. calls to subclasses of
1147 // java.nio.Buffer as in http://b/70862583
1148 java8Home := ctx.Config().Getenv("ANDROID_JAVA8_HOME")
1149 flags.bootClasspath = append(flags.bootClasspath,
1150 android.PathForSource(ctx, java8Home, "jre/lib/jce.jar"),
1151 android.PathForSource(ctx, java8Home, "jre/lib/rt.jar"))
Nan Zhang5f8cb422018-02-06 10:34:32 -08001152 if Bool(j.properties.Use_tools_jar) {
1153 flags.bootClasspath = append(flags.bootClasspath,
1154 android.PathForSource(ctx, java8Home, "lib/tools.jar"))
1155 }
Colin Cross7fdd2b72018-01-02 18:14:25 -08001156 }
1157
Colin Cross1e743852019-10-28 11:37:20 -07001158 if j.properties.Patch_module != nil && flags.javaVersion.usesJavaModules() {
Jaewoong Jung38e4fb22018-12-12 09:01:34 -08001159 // Manually specify build directory in case it is not under the repo root.
1160 // (javac doesn't seem to expand into symbolc links when searching for patch-module targets, so
1161 // just adding a symlink under the root doesn't help.)
1162 patchPaths := ".:" + ctx.Config().BuildDir()
1163 classPath := flags.classpath.FormJavaClassPath("")
1164 if classPath != "" {
1165 patchPaths += ":" + classPath
1166 }
1167 javacFlags = append(javacFlags, "--patch-module="+String(j.properties.Patch_module)+"="+patchPaths)
Colin Cross81440082018-08-15 20:21:55 -07001168 }
1169
Nan Zhanged19fc32017-10-19 13:06:22 -07001170 // systemModules
Colin Crossb77043e2019-07-16 13:57:13 -07001171 flags.systemModules = deps.systemModules
Colin Cross1369cdb2017-09-29 17:58:17 -07001172
Nan Zhanged19fc32017-10-19 13:06:22 -07001173 // aidl flags.
Colin Cross3047fa22019-04-18 10:56:44 -07001174 flags.aidlFlags, flags.aidlDeps = j.aidlFlags(ctx, deps.aidlPreprocess, deps.aidlIncludeDirs)
Colin Cross2fe66872015-03-30 17:20:39 -07001175
Colin Cross81440082018-08-15 20:21:55 -07001176 if len(javacFlags) > 0 {
1177 // optimization.
1178 ctx.Variable(pctx, "javacFlags", strings.Join(javacFlags, " "))
1179 flags.javacFlags = "$javacFlags"
1180 }
1181
Nan Zhanged19fc32017-10-19 13:06:22 -07001182 return flags
1183}
Colin Crossc0b06f12015-04-08 13:03:43 -07001184
Jaewoong Junga24af3b2019-05-13 09:23:20 -07001185func (j *Module) compile(ctx android.ModuleContext, aaptSrcJar android.Path) {
Colin Crossebe1a512017-11-14 13:12:14 -08001186 j.exportAidlIncludeDirs = android.PathsForModuleSrc(ctx, j.deviceProperties.Aidl.Export_include_dirs)
Nan Zhanged19fc32017-10-19 13:06:22 -07001187
1188 deps := j.collectDeps(ctx)
1189 flags := j.collectBuilderFlags(ctx, deps)
1190
Colin Cross1e743852019-10-28 11:37:20 -07001191 if flags.javaVersion.usesJavaModules() {
Nan Zhanged19fc32017-10-19 13:06:22 -07001192 j.properties.Srcs = append(j.properties.Srcs, j.properties.Openjdk9.Srcs...)
1193 }
Colin Cross8a497952019-03-05 22:25:09 -08001194 srcFiles := android.PathsForModuleSrcExcludes(ctx, j.properties.Srcs, j.properties.Exclude_srcs)
Colin Cross6af17aa2017-09-20 12:59:05 -07001195 if hasSrcExt(srcFiles.Strings(), ".proto") {
Colin Cross0f2ee152017-12-14 15:22:43 -08001196 flags = protoFlags(ctx, &j.properties, &j.protoProperties, flags)
Colin Cross6af17aa2017-09-20 12:59:05 -07001197 }
1198
Colin Crossaf050172017-11-15 23:01:59 -08001199 srcFiles = j.genSources(ctx, srcFiles, flags)
1200
1201 srcJars := srcFiles.FilterByExt(".srcjar")
Colin Cross59149b62017-10-16 18:07:29 -07001202 srcJars = append(srcJars, deps.srcJars...)
Jaewoong Junga24af3b2019-05-13 09:23:20 -07001203 if aaptSrcJar != nil {
1204 srcJars = append(srcJars, aaptSrcJar)
1205 }
Colin Crossb7a63242015-04-16 14:09:14 -07001206
Steven Morelandc4efd9c2019-01-18 11:51:25 -08001207 if j.properties.Jarjar_rules != nil {
Colin Cross8a497952019-03-05 22:25:09 -08001208 j.expandJarjarRules = android.PathForModuleSrc(ctx, *j.properties.Jarjar_rules)
Steven Morelandc4efd9c2019-01-18 11:51:25 -08001209 }
1210
Colin Cross1ee23172017-10-18 14:44:18 -07001211 jarName := ctx.ModuleName() + ".jar"
1212
Przemyslaw Szczepaniak4b5fe9d2018-02-13 14:32:54 +00001213 javaSrcFiles := srcFiles.FilterByExt(".java")
1214 var uniqueSrcFiles android.Paths
1215 set := make(map[string]bool)
1216 for _, v := range javaSrcFiles {
1217 if _, found := set[v.String()]; !found {
1218 set[v.String()] = true
1219 uniqueSrcFiles = append(uniqueSrcFiles, v)
1220 }
1221 }
1222
patricktu242faad2019-09-24 15:41:30 +08001223 // Collect .java files for AIDEGen
1224 j.expandIDEInfoCompiledSrcs = append(j.expandIDEInfoCompiledSrcs, uniqueSrcFiles.Strings()...)
1225
Colin Cross55f63ea2018-08-27 12:37:09 -07001226 var kotlinJars android.Paths
1227
Colin Cross93e85952017-08-15 13:34:18 -07001228 if srcFiles.HasExt(".kt") {
Zoran Jovanovic8736ce22018-08-21 17:10:29 +02001229 // user defined kotlin flags.
1230 kotlincFlags := j.properties.Kotlincflags
1231 CheckKotlincFlags(ctx, kotlincFlags)
1232
Colin Cross93e85952017-08-15 13:34:18 -07001233 // If there are kotlin files, compile them first but pass all the kotlin and java files
1234 // kotlinc will use the java files to resolve types referenced by the kotlin files, but
1235 // won't emit any classes for them.
Zoran Jovanovic8736ce22018-08-21 17:10:29 +02001236 kotlincFlags = append(kotlincFlags, "-no-stdlib")
Colin Cross93e85952017-08-15 13:34:18 -07001237 if ctx.Device() {
Zoran Jovanovic8736ce22018-08-21 17:10:29 +02001238 kotlincFlags = append(kotlincFlags, "-no-jdk")
1239 }
1240 if len(kotlincFlags) > 0 {
1241 // optimization.
1242 ctx.Variable(pctx, "kotlincFlags", strings.Join(kotlincFlags, " "))
1243 flags.kotlincFlags += "$kotlincFlags"
Colin Cross93e85952017-08-15 13:34:18 -07001244 }
1245
Przemyslaw Szczepaniak4b5fe9d2018-02-13 14:32:54 +00001246 var kotlinSrcFiles android.Paths
1247 kotlinSrcFiles = append(kotlinSrcFiles, uniqueSrcFiles...)
1248 kotlinSrcFiles = append(kotlinSrcFiles, srcFiles.FilterByExt(".kt")...)
1249
patricktu242faad2019-09-24 15:41:30 +08001250 // Collect .kt files for AIDEGen
1251 j.expandIDEInfoCompiledSrcs = append(j.expandIDEInfoCompiledSrcs, srcFiles.FilterByExt(".kt").Strings()...)
1252
Colin Crossafbb1732019-01-17 15:42:52 -08001253 flags.classpath = append(flags.classpath, deps.kotlinStdlib...)
1254 flags.classpath = append(flags.classpath, deps.kotlinAnnotations...)
1255
1256 flags.kotlincClasspath = append(flags.kotlincClasspath, flags.bootClasspath...)
1257 flags.kotlincClasspath = append(flags.kotlincClasspath, flags.classpath...)
1258
1259 if len(flags.processorPath) > 0 {
1260 // Use kapt for annotation processing
1261 kaptSrcJar := android.PathForModuleOut(ctx, "kapt", "kapt-sources.jar")
1262 kotlinKapt(ctx, kaptSrcJar, kotlinSrcFiles, srcJars, flags)
1263 srcJars = append(srcJars, kaptSrcJar)
1264 // Disable annotation processing in javac, it's already been handled by kapt
1265 flags.processorPath = nil
Colin Cross3a3e94c2019-01-23 15:39:50 -08001266 flags.processor = ""
Colin Crossafbb1732019-01-17 15:42:52 -08001267 }
Colin Cross93e85952017-08-15 13:34:18 -07001268
Colin Cross1ee23172017-10-18 14:44:18 -07001269 kotlinJar := android.PathForModuleOut(ctx, "kotlin", jarName)
Colin Cross21fc9bb2019-01-18 15:05:09 -08001270 kotlinCompile(ctx, kotlinJar, kotlinSrcFiles, srcJars, flags)
Colin Cross93e85952017-08-15 13:34:18 -07001271 if ctx.Failed() {
1272 return
1273 }
1274
1275 // Make javac rule depend on the kotlinc rule
1276 flags.classpath = append(flags.classpath, kotlinJar)
Przemyslaw Szczepaniak66c0c402018-03-08 13:21:55 +00001277
Colin Cross93e85952017-08-15 13:34:18 -07001278 // Jar kotlin classes into the final jar after javac
Colin Cross55f63ea2018-08-27 12:37:09 -07001279 kotlinJars = append(kotlinJars, kotlinJar)
Colin Cross9b38aef2018-08-27 15:42:25 -07001280 kotlinJars = append(kotlinJars, deps.kotlinStdlib...)
Colin Cross93e85952017-08-15 13:34:18 -07001281 }
1282
Colin Cross55f63ea2018-08-27 12:37:09 -07001283 jars := append(android.Paths(nil), kotlinJars...)
1284
Colin Cross5ab4e6d2017-11-22 16:20:45 -08001285 // Store the list of .java files that was passed to javac
1286 j.compiledJavaSrcs = uniqueSrcFiles
1287 j.compiledSrcJars = srcJars
1288
Nan Zhang61eaedb2017-11-02 13:28:15 -07001289 enable_sharding := false
Colin Crossf5a66282020-02-21 08:16:41 -08001290 var headerJarFileWithoutJarjar android.Path
Colin Crossbe9cdb82019-01-21 21:37:16 -08001291 if ctx.Device() && !ctx.Config().IsEnvFalse("TURBINE_ENABLED") && !deps.disableTurbine {
Nan Zhang61eaedb2017-11-02 13:28:15 -07001292 if j.properties.Javac_shard_size != nil && *(j.properties.Javac_shard_size) > 0 {
1293 enable_sharding = true
Ashley Rosee36efcf2019-01-16 17:34:08 -05001294 // Formerly, there was a check here that prevented annotation processors
1295 // from being used when sharding was enabled, as some annotation processors
1296 // do not function correctly in sharded environments. It was removed to
1297 // allow for the use of annotation processors that do function correctly
1298 // with sharding enabled. See: b/77284273.
Nan Zhang61eaedb2017-11-02 13:28:15 -07001299 }
Colin Crossf5a66282020-02-21 08:16:41 -08001300 headerJarFileWithoutJarjar, j.headerJarFile =
1301 j.compileJavaHeader(ctx, uniqueSrcFiles, srcJars, deps, flags, jarName, kotlinJars)
Colin Crossf19b9bb2018-03-26 14:42:44 -07001302 if ctx.Failed() {
1303 return
Nan Zhanged19fc32017-10-19 13:06:22 -07001304 }
1305 }
Colin Cross8eadbf02017-10-24 17:46:00 -07001306 if len(uniqueSrcFiles) > 0 || len(srcJars) > 0 {
Colin Crossd6891432017-09-27 17:39:56 -07001307 var extraJarDeps android.Paths
Colin Cross66548102018-06-19 22:47:35 -07001308 if ctx.Config().RunErrorProne() {
Colin Crossc6bbef32017-08-14 14:16:06 -07001309 // If error-prone is enabled, add an additional rule to compile the java files into
1310 // a separate set of classes (so that they don't overwrite the normal ones and require
Colin Crossd6891432017-09-27 17:39:56 -07001311 // a rebuild when error-prone is turned off).
Colin Crossc6bbef32017-08-14 14:16:06 -07001312 // TODO(ccross): Once we always compile with javac9 we may be able to conditionally
1313 // enable error-prone without affecting the output class files.
Colin Cross1ee23172017-10-18 14:44:18 -07001314 errorprone := android.PathForModuleOut(ctx, "errorprone", jarName)
Nan Zhang61eaedb2017-11-02 13:28:15 -07001315 RunErrorProne(ctx, errorprone, uniqueSrcFiles, srcJars, flags)
Colin Crossc6bbef32017-08-14 14:16:06 -07001316 extraJarDeps = append(extraJarDeps, errorprone)
1317 }
1318
Nan Zhang61eaedb2017-11-02 13:28:15 -07001319 if enable_sharding {
Colin Crossf5a66282020-02-21 08:16:41 -08001320 flags.classpath = append(flags.classpath, headerJarFileWithoutJarjar)
Nan Zhang61eaedb2017-11-02 13:28:15 -07001321 shardSize := int(*(j.properties.Javac_shard_size))
1322 var shardSrcs []android.Paths
1323 if len(uniqueSrcFiles) > 0 {
Colin Cross0a2f7192019-09-23 14:33:09 -07001324 shardSrcs = android.ShardPaths(uniqueSrcFiles, shardSize)
Nan Zhang61eaedb2017-11-02 13:28:15 -07001325 for idx, shardSrc := range shardSrcs {
Colin Cross3b706fd2019-09-05 16:44:18 -07001326 classes := j.compileJavaClasses(ctx, jarName, idx, shardSrc,
1327 nil, flags, extraJarDeps)
Nan Zhang61eaedb2017-11-02 13:28:15 -07001328 jars = append(jars, classes)
1329 }
1330 }
1331 if len(srcJars) > 0 {
Colin Cross3b706fd2019-09-05 16:44:18 -07001332 classes := j.compileJavaClasses(ctx, jarName, len(shardSrcs),
1333 nil, srcJars, flags, extraJarDeps)
Nan Zhang61eaedb2017-11-02 13:28:15 -07001334 jars = append(jars, classes)
1335 }
1336 } else {
Colin Cross3b706fd2019-09-05 16:44:18 -07001337 classes := j.compileJavaClasses(ctx, jarName, -1, uniqueSrcFiles, srcJars, flags, extraJarDeps)
Nan Zhang61eaedb2017-11-02 13:28:15 -07001338 jars = append(jars, classes)
1339 }
Colin Crossd6891432017-09-27 17:39:56 -07001340 if ctx.Failed() {
1341 return
1342 }
Colin Cross2fe66872015-03-30 17:20:39 -07001343 }
1344
Colin Cross0c4ce212019-05-03 15:28:19 -07001345 j.srcJarArgs, j.srcJarDeps = resourcePathsToJarArgs(srcFiles), srcFiles
1346
1347 var includeSrcJar android.WritablePath
1348 if Bool(j.properties.Include_srcs) {
1349 includeSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+".srcjar")
1350 TransformResourcesToJar(ctx, includeSrcJar, j.srcJarArgs, j.srcJarDeps)
1351 }
1352
Colin Crosscedd4762018-09-13 11:26:19 -07001353 dirArgs, dirDeps := ResourceDirsToJarArgs(ctx, j.properties.Java_resource_dirs,
1354 j.properties.Exclude_java_resource_dirs, j.properties.Exclude_java_resources)
Colin Cross0f37af02017-09-27 17:42:05 -07001355 fileArgs, fileDeps := ResourceFilesToJarArgs(ctx, j.properties.Java_resources, j.properties.Exclude_java_resources)
Colin Cross988708c2019-05-06 14:04:11 -07001356 extraArgs, extraDeps := resourcePathsToJarArgs(j.extraResources), j.extraResources
Colin Cross0f37af02017-09-27 17:42:05 -07001357
1358 var resArgs []string
1359 var resDeps android.Paths
1360
1361 resArgs = append(resArgs, dirArgs...)
1362 resDeps = append(resDeps, dirDeps...)
1363
1364 resArgs = append(resArgs, fileArgs...)
1365 resDeps = append(resDeps, fileDeps...)
1366
Colin Cross988708c2019-05-06 14:04:11 -07001367 resArgs = append(resArgs, extraArgs...)
1368 resDeps = append(resDeps, extraDeps...)
1369
Colin Cross40a36712017-09-27 17:41:35 -07001370 if len(resArgs) > 0 {
Colin Cross1ee23172017-10-18 14:44:18 -07001371 resourceJar := android.PathForModuleOut(ctx, "res", jarName)
Colin Crosse9a275b2017-10-16 17:09:48 -07001372 TransformResourcesToJar(ctx, resourceJar, resArgs, resDeps)
Colin Cross331a1212018-08-15 20:40:52 -07001373 j.resourceJar = resourceJar
Colin Cross65bf4f22015-04-03 16:54:17 -07001374 if ctx.Failed() {
1375 return
1376 }
1377 }
1378
Colin Cross0c4ce212019-05-03 15:28:19 -07001379 var resourceJars android.Paths
1380 if j.resourceJar != nil {
1381 resourceJars = append(resourceJars, j.resourceJar)
1382 }
1383 if Bool(j.properties.Include_srcs) {
1384 resourceJars = append(resourceJars, includeSrcJar)
1385 }
1386 resourceJars = append(resourceJars, deps.staticResourceJars...)
Colin Cross331a1212018-08-15 20:40:52 -07001387
Colin Cross0c4ce212019-05-03 15:28:19 -07001388 if len(resourceJars) > 1 {
Colin Cross331a1212018-08-15 20:40:52 -07001389 combinedJar := android.PathForModuleOut(ctx, "res-combined", jarName)
Colin Cross0c4ce212019-05-03 15:28:19 -07001390 TransformJarsToJar(ctx, combinedJar, "for resources", resourceJars, android.OptionalPath{},
Colin Cross331a1212018-08-15 20:40:52 -07001391 false, nil, nil)
1392 j.resourceJar = combinedJar
Colin Cross0c4ce212019-05-03 15:28:19 -07001393 } else if len(resourceJars) == 1 {
1394 j.resourceJar = resourceJars[0]
Colin Cross331a1212018-08-15 20:40:52 -07001395 }
1396
Jaewoong Junga24af3b2019-05-13 09:23:20 -07001397 if len(deps.staticJars) > 0 {
1398 jars = append(jars, deps.staticJars...)
Jaewoong Junga24af3b2019-05-13 09:23:20 -07001399 }
Colin Cross0a6e0072017-08-30 14:24:55 -07001400
Colin Cross094054a2018-10-17 15:10:48 -07001401 manifest := j.overrideManifest
1402 if !manifest.Valid() && j.properties.Manifest != nil {
Colin Cross8a497952019-03-05 22:25:09 -08001403 manifest = android.OptionalPathForPath(android.PathForModuleSrc(ctx, *j.properties.Manifest))
Colin Cross366938f2017-12-11 16:29:02 -08001404 }
Colin Cross635acc92017-09-12 22:50:46 -07001405
Colin Cross8a497952019-03-05 22:25:09 -08001406 services := android.PathsForModuleSrc(ctx, j.properties.Services)
Alex Light7f004a72019-02-21 13:27:37 -08001407 if len(services) > 0 {
1408 servicesJar := android.PathForModuleOut(ctx, "services", jarName)
1409 var zipargs []string
1410 for _, file := range services {
1411 serviceFile := file.String()
1412 zipargs = append(zipargs, "-C", filepath.Dir(serviceFile), "-f", serviceFile)
1413 }
1414 ctx.Build(pctx, android.BuildParams{
1415 Rule: zip,
1416 Output: servicesJar,
1417 Implicits: services,
1418 Args: map[string]string{
Colin Cross0b9f31f2019-02-28 11:00:01 -08001419 "jarArgs": "-P META-INF/services/ " + strings.Join(proptools.NinjaAndShellEscapeList(zipargs), " "),
Alex Light7f004a72019-02-21 13:27:37 -08001420 },
1421 })
1422 jars = append(jars, servicesJar)
1423 }
1424
Colin Cross0a6e0072017-08-30 14:24:55 -07001425 // Combine the classes built from sources, any manifests, and any static libraries into
Nan Zhanged19fc32017-10-19 13:06:22 -07001426 // classes.jar. If there is only one input jar this step will be skipped.
Colin Cross3063b782018-08-15 11:19:12 -07001427 var outputFile android.ModuleOutPath
Colin Crosse9a275b2017-10-16 17:09:48 -07001428
1429 if len(jars) == 1 && !manifest.Valid() {
Colin Cross3063b782018-08-15 11:19:12 -07001430 if moduleOutPath, ok := jars[0].(android.ModuleOutPath); ok {
1431 // Optimization: skip the combine step if there is nothing to do
1432 // TODO(ccross): this leaves any module-info.class files, but those should only come from
1433 // prebuilt dependencies until we support modules in the platform build, so there shouldn't be
1434 // any if len(jars) == 1.
1435 outputFile = moduleOutPath
1436 } else {
1437 combinedJar := android.PathForModuleOut(ctx, "combined", jarName)
1438 ctx.Build(pctx, android.BuildParams{
1439 Rule: android.Cp,
1440 Input: jars[0],
1441 Output: combinedJar,
1442 })
1443 outputFile = combinedJar
1444 }
Colin Crosse9a275b2017-10-16 17:09:48 -07001445 } else {
Colin Cross1ee23172017-10-18 14:44:18 -07001446 combinedJar := android.PathForModuleOut(ctx, "combined", jarName)
Colin Cross37f6d792018-07-12 12:28:41 -07001447 TransformJarsToJar(ctx, combinedJar, "for javac", jars, manifest,
Colin Cross9b38aef2018-08-27 15:42:25 -07001448 false, nil, nil)
Colin Crosse9a275b2017-10-16 17:09:48 -07001449 outputFile = combinedJar
1450 }
Colin Cross0a6e0072017-08-30 14:24:55 -07001451
Colin Cross331a1212018-08-15 20:40:52 -07001452 // jarjar implementation jar if necessary
Steven Morelandc4efd9c2019-01-18 11:51:25 -08001453 if j.expandJarjarRules != nil {
Colin Cross8649b262017-09-27 18:03:17 -07001454 // Transform classes.jar into classes-jarjar.jar
Colin Cross1ee23172017-10-18 14:44:18 -07001455 jarjarFile := android.PathForModuleOut(ctx, "jarjar", jarName)
Steven Morelandc4efd9c2019-01-18 11:51:25 -08001456 TransformJarJar(ctx, jarjarFile, outputFile, j.expandJarjarRules)
Colin Crosse9a275b2017-10-16 17:09:48 -07001457 outputFile = jarjarFile
Colin Cross331a1212018-08-15 20:40:52 -07001458
1459 // jarjar resource jar if necessary
1460 if j.resourceJar != nil {
1461 resourceJarJarFile := android.PathForModuleOut(ctx, "res-jarjar", jarName)
Steven Morelandc4efd9c2019-01-18 11:51:25 -08001462 TransformJarJar(ctx, resourceJarJarFile, j.resourceJar, j.expandJarjarRules)
Colin Cross331a1212018-08-15 20:40:52 -07001463 j.resourceJar = resourceJarJarFile
1464 }
1465
Colin Cross0a6e0072017-08-30 14:24:55 -07001466 if ctx.Failed() {
1467 return
1468 }
1469 }
Vladimir Marko0975ee02019-04-02 10:29:55 +01001470
1471 // Check package restrictions if necessary.
1472 if len(j.properties.Permitted_packages) > 0 {
1473 // Check packages and copy to package-checked file.
1474 pkgckFile := android.PathForModuleOut(ctx, "package-check.stamp")
1475 CheckJarPackages(ctx, pkgckFile, outputFile, j.properties.Permitted_packages)
1476 j.additionalCheckedModules = append(j.additionalCheckedModules, pkgckFile)
1477
1478 if ctx.Failed() {
1479 return
1480 }
1481 }
1482
Nan Zhanged19fc32017-10-19 13:06:22 -07001483 j.implementationJarFile = outputFile
1484 if j.headerJarFile == nil {
1485 j.headerJarFile = j.implementationJarFile
1486 }
Colin Cross2fe66872015-03-30 17:20:39 -07001487
Jiyong Park28826602020-02-21 16:04:53 +09001488 // Force enable the instrumentation for java code that is built for APEXes ...
1489 // except for the jacocoagent itself (because instrumenting jacocoagent using jacocoagent
1490 // doesn't make sense)
1491 isJacocoAgent := ctx.ModuleName() == "jacocoagent"
1492 if android.DirectlyInAnyApex(ctx, ctx.ModuleName()) && !isJacocoAgent && !j.IsForPlatform() {
Jiyong Park81aaa0c2020-02-18 12:50:44 +00001493 j.properties.Instrument = true
1494 }
1495
Colin Cross3144dfc2018-01-03 15:06:47 -08001496 if j.shouldInstrument(ctx) {
Colin Crosscb933592017-11-22 13:49:43 -08001497 outputFile = j.instrument(ctx, flags, outputFile, jarName)
1498 }
1499
Colin Cross331a1212018-08-15 20:40:52 -07001500 // merge implementation jar with resources if necessary
1501 implementationAndResourcesJar := outputFile
1502 if j.resourceJar != nil {
Colin Cross08a409d2019-04-29 10:22:44 -07001503 jars := android.Paths{j.resourceJar, implementationAndResourcesJar}
Colin Cross331a1212018-08-15 20:40:52 -07001504 combinedJar := android.PathForModuleOut(ctx, "withres", jarName)
Colin Cross08a409d2019-04-29 10:22:44 -07001505 TransformJarsToJar(ctx, combinedJar, "for resources", jars, manifest,
Colin Cross331a1212018-08-15 20:40:52 -07001506 false, nil, nil)
1507 implementationAndResourcesJar = combinedJar
1508 }
1509
1510 j.implementationAndResourcesJar = implementationAndResourcesJar
1511
Jiyong Park6b21c7d2020-02-11 09:16:01 +09001512 // Enable dex compilation for the APEX variants, unless it is disabled explicitly
1513 if android.DirectlyInAnyApex(ctx, ctx.ModuleName()) && !j.IsForPlatform() {
1514 if j.deviceProperties.Compile_dex == nil {
1515 j.deviceProperties.Compile_dex = proptools.BoolPtr(true)
1516 }
1517 if j.deviceProperties.Hostdex == nil {
1518 j.deviceProperties.Hostdex = proptools.BoolPtr(true)
1519 }
1520 }
1521
Jaewoong Jungc27ab662019-05-30 15:51:14 -07001522 if ctx.Device() && j.hasCode(ctx) &&
Jaewoong Junga24af3b2019-05-13 09:23:20 -07001523 (Bool(j.properties.Installable) || Bool(j.deviceProperties.Compile_dex)) {
Colin Cross8faf8fc2019-01-16 15:15:52 -08001524 // Dex compilation
Colin Cross3063b782018-08-15 11:19:12 -07001525 var dexOutputFile android.ModuleOutPath
David Brazdil17ef5632018-06-27 10:27:45 +01001526 dexOutputFile = j.compileDex(ctx, flags, outputFile, jarName)
Colin Cross2fe66872015-03-30 17:20:39 -07001527 if ctx.Failed() {
1528 return
1529 }
Colin Cross331a1212018-08-15 20:40:52 -07001530
Jiyong Park09cb6292019-07-15 15:29:23 +09001531 // Hidden API CSV generation and dex encoding
1532 dexOutputFile = j.hiddenAPI.hiddenAPI(ctx, dexOutputFile, j.implementationJarFile,
1533 j.deviceProperties.UncompressDex)
Colin Cross8faf8fc2019-01-16 15:15:52 -08001534
Colin Cross331a1212018-08-15 20:40:52 -07001535 // merge dex jar with resources if necessary
1536 if j.resourceJar != nil {
1537 jars := android.Paths{dexOutputFile, j.resourceJar}
1538 combinedJar := android.PathForModuleOut(ctx, "dex-withres", jarName)
1539 TransformJarsToJar(ctx, combinedJar, "for dex resources", jars, android.OptionalPath{},
1540 false, nil, nil)
Nicolas Geoffrayf3438722019-01-23 15:57:21 +00001541 if j.deviceProperties.UncompressDex {
1542 combinedAlignedJar := android.PathForModuleOut(ctx, "dex-withres-aligned", jarName)
1543 TransformZipAlign(ctx, combinedAlignedJar, combinedJar)
1544 dexOutputFile = combinedAlignedJar
1545 } else {
1546 dexOutputFile = combinedJar
1547 }
Colin Cross331a1212018-08-15 20:40:52 -07001548 }
1549
1550 j.dexJarFile = dexOutputFile
1551
Colin Cross8faf8fc2019-01-16 15:15:52 -08001552 // Dexpreopting
Colin Cross43f08db2018-11-12 10:13:39 -08001553 dexOutputFile = j.dexpreopt(ctx, dexOutputFile)
1554
1555 j.maybeStrippedDexJarFile = dexOutputFile
1556
Colin Cross3063b782018-08-15 11:19:12 -07001557 outputFile = dexOutputFile
Colin Cross43f08db2018-11-12 10:13:39 -08001558
1559 if ctx.Failed() {
1560 return
1561 }
Colin Cross331a1212018-08-15 20:40:52 -07001562 } else {
1563 outputFile = implementationAndResourcesJar
Colin Cross2fe66872015-03-30 17:20:39 -07001564 }
Colin Cross331a1212018-08-15 20:40:52 -07001565
Colin Crossb7a63242015-04-16 14:09:14 -07001566 ctx.CheckbuildFile(outputFile)
Colin Cross3063b782018-08-15 11:19:12 -07001567
1568 // Save the output file with no relative path so that it doesn't end up in a subdirectory when used as a resource
1569 j.outputFile = outputFile.WithoutRel()
Colin Cross2fe66872015-03-30 17:20:39 -07001570}
1571
Colin Cross3b706fd2019-09-05 16:44:18 -07001572func (j *Module) compileJavaClasses(ctx android.ModuleContext, jarName string, idx int,
1573 srcFiles, srcJars android.Paths, flags javaBuilderFlags, extraJarDeps android.Paths) android.WritablePath {
1574
1575 kzipName := pathtools.ReplaceExtension(jarName, "kzip")
1576 if idx >= 0 {
1577 kzipName = strings.TrimSuffix(jarName, filepath.Ext(jarName)) + strconv.Itoa(idx) + ".kzip"
1578 jarName += strconv.Itoa(idx)
1579 }
1580
1581 classes := android.PathForModuleOut(ctx, "javac", jarName)
1582 TransformJavaToClasses(ctx, classes, idx, srcFiles, srcJars, flags, extraJarDeps)
1583
1584 if ctx.Config().EmitXrefRules() {
1585 extractionFile := android.PathForModuleOut(ctx, kzipName)
1586 emitXrefRule(ctx, extractionFile, idx, srcFiles, srcJars, flags, extraJarDeps)
1587 j.kytheFiles = append(j.kytheFiles, extractionFile)
1588 }
1589
1590 return classes
1591}
1592
Zoran Jovanovic8736ce22018-08-21 17:10:29 +02001593// Check for invalid kotlinc flags. Only use this for flags explicitly passed by the user,
1594// since some of these flags may be used internally.
1595func CheckKotlincFlags(ctx android.ModuleContext, flags []string) {
1596 for _, flag := range flags {
1597 flag = strings.TrimSpace(flag)
1598
1599 if !strings.HasPrefix(flag, "-") {
1600 ctx.PropertyErrorf("kotlincflags", "Flag `%s` must start with `-`", flag)
1601 } else if strings.HasPrefix(flag, "-Xintellij-plugin-root") {
1602 ctx.PropertyErrorf("kotlincflags",
1603 "Bad flag: `%s`, only use internal compiler for consistency.", flag)
1604 } else if inList(flag, config.KotlincIllegalFlags) {
1605 ctx.PropertyErrorf("kotlincflags", "Flag `%s` already used by build system", flag)
1606 } else if flag == "-include-runtime" {
1607 ctx.PropertyErrorf("kotlincflags", "Bad flag: `%s`, do not include runtime.", flag)
1608 } else {
1609 args := strings.Split(flag, " ")
1610 if args[0] == "-kotlin-home" {
1611 ctx.PropertyErrorf("kotlincflags",
1612 "Bad flag: `%s`, kotlin home already set to default (path to kotlinc in the repo).", flag)
1613 }
1614 }
1615 }
1616}
1617
Colin Cross8eadbf02017-10-24 17:46:00 -07001618func (j *Module) compileJavaHeader(ctx android.ModuleContext, srcFiles, srcJars android.Paths,
Colin Crossf5a66282020-02-21 08:16:41 -08001619 deps deps, flags javaBuilderFlags, jarName string,
1620 extraJars android.Paths) (headerJar, jarjarHeaderJar android.Path) {
Nan Zhanged19fc32017-10-19 13:06:22 -07001621
1622 var jars android.Paths
Colin Cross8eadbf02017-10-24 17:46:00 -07001623 if len(srcFiles) > 0 || len(srcJars) > 0 {
Nan Zhanged19fc32017-10-19 13:06:22 -07001624 // Compile java sources into turbine.jar.
1625 turbineJar := android.PathForModuleOut(ctx, "turbine", jarName)
1626 TransformJavaToHeaderClasses(ctx, turbineJar, srcFiles, srcJars, flags)
1627 if ctx.Failed() {
Colin Crossf5a66282020-02-21 08:16:41 -08001628 return nil, nil
Nan Zhanged19fc32017-10-19 13:06:22 -07001629 }
1630 jars = append(jars, turbineJar)
1631 }
1632
Colin Cross55f63ea2018-08-27 12:37:09 -07001633 jars = append(jars, extraJars...)
1634
Nan Zhanged19fc32017-10-19 13:06:22 -07001635 // Combine any static header libraries into classes-header.jar. If there is only
1636 // one input jar this step will be skipped.
Nan Zhanged19fc32017-10-19 13:06:22 -07001637 jars = append(jars, deps.staticHeaderJars...)
1638
Colin Cross5c6ecc12017-10-23 18:12:27 -07001639 // we cannot skip the combine step for now if there is only one jar
1640 // since we have to strip META-INF/TRANSITIVE dir from turbine.jar
1641 combinedJar := android.PathForModuleOut(ctx, "turbine-combined", jarName)
Colin Cross37f6d792018-07-12 12:28:41 -07001642 TransformJarsToJar(ctx, combinedJar, "for turbine", jars, android.OptionalPath{},
Colin Cross6c6e6cd2019-05-08 14:30:12 -07001643 false, nil, []string{"META-INF/TRANSITIVE"})
Colin Cross5c6ecc12017-10-23 18:12:27 -07001644 headerJar = combinedJar
Colin Crossf5a66282020-02-21 08:16:41 -08001645 jarjarHeaderJar = combinedJar
Nan Zhanged19fc32017-10-19 13:06:22 -07001646
Steven Morelandc4efd9c2019-01-18 11:51:25 -08001647 if j.expandJarjarRules != nil {
Nan Zhanged19fc32017-10-19 13:06:22 -07001648 // Transform classes.jar into classes-jarjar.jar
1649 jarjarFile := android.PathForModuleOut(ctx, "turbine-jarjar", jarName)
Steven Morelandc4efd9c2019-01-18 11:51:25 -08001650 TransformJarJar(ctx, jarjarFile, headerJar, j.expandJarjarRules)
Colin Crossf5a66282020-02-21 08:16:41 -08001651 jarjarHeaderJar = jarjarFile
Nan Zhanged19fc32017-10-19 13:06:22 -07001652 if ctx.Failed() {
Colin Crossf5a66282020-02-21 08:16:41 -08001653 return nil, nil
Nan Zhanged19fc32017-10-19 13:06:22 -07001654 }
1655 }
1656
Colin Crossf5a66282020-02-21 08:16:41 -08001657 return headerJar, jarjarHeaderJar
Nan Zhanged19fc32017-10-19 13:06:22 -07001658}
1659
Colin Crosscb933592017-11-22 13:49:43 -08001660func (j *Module) instrument(ctx android.ModuleContext, flags javaBuilderFlags,
Colin Cross3063b782018-08-15 11:19:12 -07001661 classesJar android.Path, jarName string) android.ModuleOutPath {
Colin Crosscb933592017-11-22 13:49:43 -08001662
Colin Cross7a3139e2017-12-19 13:57:50 -08001663 specs := j.jacocoModuleToZipCommand(ctx)
Colin Crosscb933592017-11-22 13:49:43 -08001664
Colin Cross84c38822018-01-03 15:59:46 -08001665 jacocoReportClassesFile := android.PathForModuleOut(ctx, "jacoco-report-classes", jarName)
Colin Crosscb933592017-11-22 13:49:43 -08001666 instrumentedJar := android.PathForModuleOut(ctx, "jacoco", jarName)
1667
1668 jacocoInstrumentJar(ctx, instrumentedJar, jacocoReportClassesFile, classesJar, specs)
1669
1670 j.jacocoReportClassesFile = jacocoReportClassesFile
1671
1672 return instrumentedJar
1673}
1674
albaltai36ff7dc2018-12-25 14:35:23 +08001675var _ Dependency = (*Module)(nil)
Colin Cross2fe66872015-03-30 17:20:39 -07001676
Nan Zhanged19fc32017-10-19 13:06:22 -07001677func (j *Module) HeaderJars() android.Paths {
albaltai36ff7dc2018-12-25 14:35:23 +08001678 if j.headerJarFile == nil {
1679 return nil
1680 }
Nan Zhanged19fc32017-10-19 13:06:22 -07001681 return android.Paths{j.headerJarFile}
1682}
1683
1684func (j *Module) ImplementationJars() android.Paths {
shinwang9e4c07a2018-12-24 15:41:04 +08001685 if j.implementationJarFile == nil {
1686 return nil
1687 }
Nan Zhanged19fc32017-10-19 13:06:22 -07001688 return android.Paths{j.implementationJarFile}
Colin Cross2fe66872015-03-30 17:20:39 -07001689}
1690
Colin Crossf24a22a2019-01-31 14:12:44 -08001691func (j *Module) DexJar() android.Path {
1692 return j.dexJarFile
1693}
1694
Colin Cross331a1212018-08-15 20:40:52 -07001695func (j *Module) ResourceJars() android.Paths {
1696 if j.resourceJar == nil {
1697 return nil
1698 }
1699 return android.Paths{j.resourceJar}
1700}
1701
1702func (j *Module) ImplementationAndResourcesJars() android.Paths {
albaltai36ff7dc2018-12-25 14:35:23 +08001703 if j.implementationAndResourcesJar == nil {
1704 return nil
1705 }
Colin Cross331a1212018-08-15 20:40:52 -07001706 return android.Paths{j.implementationAndResourcesJar}
1707}
1708
Colin Cross46c9b8b2017-06-22 16:51:17 -07001709func (j *Module) AidlIncludeDirs() android.Paths {
albaltai36ff7dc2018-12-25 14:35:23 +08001710 // exportAidlIncludeDirs is type android.Paths already
Colin Crossc0b06f12015-04-08 13:03:43 -07001711 return j.exportAidlIncludeDirs
1712}
1713
Jiyong Park1be96912018-05-28 18:02:19 +09001714func (j *Module) ExportedSdkLibs() []string {
albaltai36ff7dc2018-12-25 14:35:23 +08001715 // exportedSdkLibs is type []string
Jiyong Park1be96912018-05-28 18:02:19 +09001716 return j.exportedSdkLibs
1717}
1718
Artur Satayev9cf46692019-11-26 18:08:34 +00001719func (j *Module) ExportedPlugins() (android.Paths, []string) {
1720 return j.exportedPluginJars, j.exportedPluginClasses
1721}
1722
Colin Cross0c4ce212019-05-03 15:28:19 -07001723func (j *Module) SrcJarArgs() ([]string, android.Paths) {
1724 return j.srcJarArgs, j.srcJarDeps
1725}
1726
Colin Cross46c9b8b2017-06-22 16:51:17 -07001727var _ logtagsProducer = (*Module)(nil)
Colin Crossf05fe972015-04-10 17:45:20 -07001728
Colin Cross46c9b8b2017-06-22 16:51:17 -07001729func (j *Module) logtags() android.Paths {
Colin Crossf05fe972015-04-10 17:45:20 -07001730 return j.logtagsSrcs
1731}
1732
Brandon Lee5d45c6f2018-08-15 15:35:38 -07001733// Collect information for opening IDE project files in java/jdeps.go.
1734func (j *Module) IDEInfo(dpInfo *android.IdeInfo) {
1735 dpInfo.Deps = append(dpInfo.Deps, j.CompilerDeps()...)
1736 dpInfo.Srcs = append(dpInfo.Srcs, j.expandIDEInfoCompiledSrcs...)
patricktu18c82ff2019-05-10 15:48:50 +08001737 dpInfo.SrcJars = append(dpInfo.SrcJars, j.compiledSrcJars.Strings()...)
Brandon Lee5d45c6f2018-08-15 15:35:38 -07001738 dpInfo.Aidl_include_dirs = append(dpInfo.Aidl_include_dirs, j.deviceProperties.Aidl.Include_dirs...)
Steven Morelandc4efd9c2019-01-18 11:51:25 -08001739 if j.expandJarjarRules != nil {
1740 dpInfo.Jarjar_rules = append(dpInfo.Jarjar_rules, j.expandJarjarRules.String())
Brandon Lee5d45c6f2018-08-15 15:35:38 -07001741 }
1742}
1743
1744func (j *Module) CompilerDeps() []string {
1745 jdeps := []string{}
1746 jdeps = append(jdeps, j.properties.Libs...)
1747 jdeps = append(jdeps, j.properties.Static_libs...)
1748 return jdeps
1749}
1750
Jaewoong Jungc27ab662019-05-30 15:51:14 -07001751func (j *Module) hasCode(ctx android.ModuleContext) bool {
1752 srcFiles := android.PathsForModuleSrcExcludes(ctx, j.properties.Srcs, j.properties.Exclude_srcs)
1753 return len(srcFiles) > 0 || len(ctx.GetDirectDepsWithTag(staticLibTag)) > 0
1754}
1755
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09001756func (j *Module) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
Jiyong Park0f80c182020-01-31 02:49:53 +09001757 // Dependencies other than the static linkage are all considered crossing APEX boundary
Jooyung Hanb8fa86a2020-03-10 06:23:13 +09001758 if staticLibTag == ctx.OtherModuleDependencyTag(dep) {
1759 return true
1760 }
Jiyong Park0f80c182020-01-31 02:49:53 +09001761 // Also, a dependency to an sdk member is also considered as such. This is required because
1762 // sdk members should be mutated into APEXes. Refer to sdk.sdkDepsReplaceMutator.
Jooyung Hanb8fa86a2020-03-10 06:23:13 +09001763 if sa, ok := dep.(android.SdkAware); ok && sa.IsInAnySdk() {
1764 return true
1765 }
1766 return false
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09001767}
1768
Jiyong Park0b238752019-10-29 11:23:10 +09001769func (j *Module) Stem() string {
1770 return proptools.StringDefault(j.deviceProperties.Stem, j.Name())
1771}
1772
Jiyong Park618922e2020-01-08 13:35:43 +09001773func (j *Module) JacocoReportClassesFile() android.Path {
1774 return j.jacocoReportClassesFile
1775}
1776
Martin Stjernholm6d415272020-01-31 17:10:36 +00001777func (j *Module) IsInstallable() bool {
1778 return Bool(j.properties.Installable)
1779}
1780
Colin Cross2fe66872015-03-30 17:20:39 -07001781//
1782// Java libraries (.jar file)
1783//
1784
Anton Hansson1e65f942020-03-27 19:39:48 +00001785type LibraryProperties struct {
1786 Dist struct {
1787 // The tag of the output of this module that should be output.
1788 Tag *string `android:"arch_variant"`
1789 } `android:"arch_variant"`
1790}
1791
Colin Crossf506d872017-07-19 15:53:04 -07001792type Library struct {
Colin Cross46c9b8b2017-06-22 16:51:17 -07001793 Module
Colin Crossf0f2e2c2019-10-15 16:36:40 -07001794
Anton Hansson1e65f942020-03-27 19:39:48 +00001795 libraryProperties LibraryProperties
1796
Colin Crossf0f2e2c2019-10-15 16:36:40 -07001797 InstallMixin func(ctx android.ModuleContext, installPath android.Path) (extraInstallDeps android.Paths)
Colin Cross2fe66872015-03-30 17:20:39 -07001798}
1799
Colin Cross42be7612019-02-21 18:12:14 -08001800func shouldUncompressDex(ctx android.ModuleContext, dexpreopter *dexpreopter) bool {
Ulya Trafimovichf491dde2020-01-24 12:19:45 +00001801 // Store uncompressed (and aligned) any dex files from jars in APEXes.
1802 if am, ok := ctx.Module().(android.ApexModule); ok && !am.IsForPlatform() {
1803 return true
1804 }
1805
Nicolas Geoffrayfa6e9ec2019-02-12 13:12:16 +00001806 // Store uncompressed (and do not strip) dex files from boot class path jars.
1807 if inList(ctx.ModuleName(), ctx.Config().BootJars()) {
1808 return true
1809 }
1810
1811 // Store uncompressed dex files that are preopted on /system.
Colin Cross42be7612019-02-21 18:12:14 -08001812 if !dexpreopter.dexpreoptDisabled(ctx) && (ctx.Host() || !odexOnSystemOther(ctx, dexpreopter.installPath)) {
Vladimir Markoe8b00d62018-12-21 15:54:16 +00001813 return true
1814 }
Colin Cross083a2aa2019-02-06 16:37:12 -08001815 if ctx.Config().UncompressPrivAppDex() &&
1816 inList(ctx.ModuleName(), ctx.Config().ModulesLoadedByPrivilegedModules()) {
1817 return true
1818 }
1819
Colin Cross2fc72f62018-12-21 12:59:54 -08001820 return false
1821}
1822
Colin Crossf506d872017-07-19 15:53:04 -07001823func (j *Library) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Artur Satayeve5ac15a2020-04-08 19:09:30 +01001824 j.checkSdkVersions(ctx)
Jiyong Park0b238752019-10-29 11:23:10 +09001825 j.dexpreopter.installPath = android.PathForModuleInstall(ctx, "framework", j.Stem()+".jar")
Colin Cross43f08db2018-11-12 10:13:39 -08001826 j.dexpreopter.isSDKLibrary = j.deviceProperties.IsSDKLibrary
Colin Cross42be7612019-02-21 18:12:14 -08001827 j.dexpreopter.uncompressedDex = shouldUncompressDex(ctx, &j.dexpreopter)
Nicolas Geoffrayfa6e9ec2019-02-12 13:12:16 +00001828 j.deviceProperties.UncompressDex = j.dexpreopter.uncompressedDex
Jaewoong Junga24af3b2019-05-13 09:23:20 -07001829 j.compile(ctx, nil)
Colin Crossb7a63242015-04-16 14:09:14 -07001830
Jiyong Park7f7766d2019-07-25 22:02:35 +09001831 exclusivelyForApex := android.InAnyApex(ctx.ModuleName()) && !j.IsForPlatform()
1832 if (Bool(j.properties.Installable) || ctx.Host()) && !exclusivelyForApex {
Colin Crossf0f2e2c2019-10-15 16:36:40 -07001833 var extraInstallDeps android.Paths
1834 if j.InstallMixin != nil {
1835 extraInstallDeps = j.InstallMixin(ctx, j.outputFile)
1836 }
Colin Cross2c429dc2017-08-31 16:45:16 -07001837 j.installFile = ctx.InstallFile(android.PathForModuleInstall(ctx, "framework"),
Colin Crossf0f2e2c2019-10-15 16:36:40 -07001838 ctx.ModuleName()+".jar", j.outputFile, extraInstallDeps...)
Colin Cross2c429dc2017-08-31 16:45:16 -07001839 }
Anton Hansson1e65f942020-03-27 19:39:48 +00001840
1841 // Verify Dist.Tag is set to a supported output
1842 if j.libraryProperties.Dist.Tag != nil {
1843 distFiles, err := j.OutputFiles(*j.libraryProperties.Dist.Tag)
1844 if err != nil {
1845 ctx.PropertyErrorf("dist.tag", "%s", err.Error())
1846 }
1847 j.distFile = distFiles[0]
1848 }
Colin Crossb7a63242015-04-16 14:09:14 -07001849}
1850
Colin Crossf506d872017-07-19 15:53:04 -07001851func (j *Library) DepsMutator(ctx android.BottomUpMutatorContext) {
Colin Cross46c9b8b2017-06-22 16:51:17 -07001852 j.deps(ctx)
1853}
1854
Paul Duffin0e0cf1d2019-11-12 19:39:25 +00001855const (
Paul Duffin1b82e6a2019-12-03 18:06:47 +00001856 aidlIncludeDir = "aidl"
1857 javaDir = "java"
1858 jarFileSuffix = ".jar"
1859 testConfigSuffix = "-AndroidTest.xml"
Paul Duffin0e0cf1d2019-11-12 19:39:25 +00001860)
1861
Paul Duffina0dbf432019-12-05 11:25:53 +00001862// path to the jar file of a java library. Relative to <sdk_root>/<api_dir>
Paul Duffin1b82e6a2019-12-03 18:06:47 +00001863func sdkSnapshotFilePathForJar(member android.SdkMember) string {
1864 return sdkSnapshotFilePathForMember(member, jarFileSuffix)
1865}
1866
1867func sdkSnapshotFilePathForMember(member android.SdkMember, suffix string) string {
1868 return filepath.Join(javaDir, member.Name()+suffix)
Paul Duffin0e0cf1d2019-11-12 19:39:25 +00001869}
1870
Paul Duffin13879572019-11-28 14:31:38 +00001871type librarySdkMemberType struct {
Paul Duffin255f18e2019-12-13 11:22:16 +00001872 android.SdkMemberTypeBase
Paul Duffin13879572019-11-28 14:31:38 +00001873}
1874
1875func (mt *librarySdkMemberType) AddDependencies(mctx android.BottomUpMutatorContext, dependencyTag blueprint.DependencyTag, names []string) {
1876 mctx.AddVariationDependencies(nil, dependencyTag, names...)
1877}
1878
1879func (mt *librarySdkMemberType) IsInstance(module android.Module) bool {
1880 _, ok := module.(*Library)
1881 return ok
1882}
1883
Paul Duffina0dbf432019-12-05 11:25:53 +00001884func (mt *librarySdkMemberType) buildSnapshot(
1885 sdkModuleContext android.ModuleContext,
1886 builder android.SnapshotBuilder,
1887 member android.SdkMember,
1888 jarToExportGetter func(j *Library) android.Path) {
1889
Paul Duffin13879572019-11-28 14:31:38 +00001890 variants := member.Variants()
1891 if len(variants) != 1 {
1892 sdkModuleContext.ModuleErrorf("sdk contains %d variants of member %q but only one is allowed", len(variants), member.Name())
1893 for _, variant := range variants {
1894 sdkModuleContext.ModuleErrorf(" %q", variant)
1895 }
1896 }
1897 variant := variants[0]
1898 j := variant.(*Library)
1899
Paul Duffina0dbf432019-12-05 11:25:53 +00001900 exportedJar := jarToExportGetter(j)
Paul Duffin1b82e6a2019-12-03 18:06:47 +00001901 snapshotRelativeJavaLibPath := sdkSnapshotFilePathForJar(member)
Paul Duffina0dbf432019-12-05 11:25:53 +00001902 builder.CopyToSnapshot(exportedJar, snapshotRelativeJavaLibPath)
Paul Duffin0e0cf1d2019-11-12 19:39:25 +00001903
1904 for _, dir := range j.AidlIncludeDirs() {
1905 // TODO(jiyong): copy parcelable declarations only
1906 aidlFiles, _ := sdkModuleContext.GlobWithDeps(dir.String()+"/**/*.aidl", nil)
1907 for _, file := range aidlFiles {
1908 builder.CopyToSnapshot(android.PathForSource(sdkModuleContext, file), filepath.Join(aidlIncludeDir, file))
1909 }
1910 }
1911
Paul Duffin9d8d6092019-12-05 18:19:29 +00001912 module := builder.AddPrebuiltModule(member, "java_import")
Paul Duffinb645ec82019-11-27 17:43:54 +00001913 module.AddProperty("jars", []string{snapshotRelativeJavaLibPath})
Paul Duffin0e0cf1d2019-11-12 19:39:25 +00001914}
1915
Paul Duffin7b81f5e2020-01-13 21:03:22 +00001916var javaHeaderLibsSdkMemberType android.SdkMemberType = &headerLibrarySdkMemberType{
1917 librarySdkMemberType{
1918 android.SdkMemberTypeBase{
1919 PropertyName: "java_header_libs",
1920 SupportsSdk: true,
1921 },
1922 },
1923}
1924
Paul Duffina0dbf432019-12-05 11:25:53 +00001925type headerLibrarySdkMemberType struct {
1926 librarySdkMemberType
1927}
1928
1929func (mt *headerLibrarySdkMemberType) BuildSnapshot(sdkModuleContext android.ModuleContext, builder android.SnapshotBuilder, member android.SdkMember) {
1930 mt.librarySdkMemberType.buildSnapshot(sdkModuleContext, builder, member, func(j *Library) android.Path {
1931 headerJars := j.HeaderJars()
1932 if len(headerJars) != 1 {
1933 panic(fmt.Errorf("there must be only one header jar from %q", j.Name()))
1934 }
1935
1936 return headerJars[0]
1937 })
1938}
1939
Paul Duffina0dbf432019-12-05 11:25:53 +00001940type implLibrarySdkMemberType struct {
1941 librarySdkMemberType
1942}
1943
1944func (mt *implLibrarySdkMemberType) BuildSnapshot(sdkModuleContext android.ModuleContext, builder android.SnapshotBuilder, member android.SdkMember) {
1945 mt.librarySdkMemberType.buildSnapshot(sdkModuleContext, builder, member, func(j *Library) android.Path {
1946 implementationJars := j.ImplementationJars()
1947 if len(implementationJars) != 1 {
1948 panic(fmt.Errorf("there must be only one implementation jar from %q", j.Name()))
1949 }
1950
1951 return implementationJars[0]
1952 })
1953}
1954
Colin Cross1b16b0e2019-02-12 14:41:32 -08001955// java_library builds and links sources into a `.jar` file for the device, and possibly for the host as well.
1956//
1957// By default, a java_library has a single variant that produces a `.jar` file containing `.class` files that were
1958// compiled against the device bootclasspath. This jar is not suitable for installing on a device, but can be used
1959// as a `static_libs` dependency of another module.
1960//
1961// Specifying `installable: true` will product a `.jar` file containing `classes.dex` files, suitable for installing on
1962// a device.
1963//
1964// Specifying `host_supported: true` will produce two variants, one compiled against the device bootclasspath and one
1965// compiled against the host bootclasspath.
Colin Cross9ae1b922018-06-26 17:59:05 -07001966func LibraryFactory() android.Module {
1967 module := &Library{}
Colin Cross2fe66872015-03-30 17:20:39 -07001968
Colin Cross9ae1b922018-06-26 17:59:05 -07001969 module.AddProperties(
1970 &module.Module.properties,
1971 &module.Module.deviceProperties,
Colin Cross43f08db2018-11-12 10:13:39 -08001972 &module.Module.dexpreoptProperties,
Anton Hansson1e65f942020-03-27 19:39:48 +00001973 &module.Module.protoProperties,
1974 &module.libraryProperties)
Colin Cross2fe66872015-03-30 17:20:39 -07001975
Jiyong Park7f7766d2019-07-25 22:02:35 +09001976 android.InitApexModule(module)
Jiyong Parkd1063c12019-07-17 20:08:41 +09001977 android.InitSdkAwareModule(module)
Jooyung Han18020ea2019-11-13 10:50:48 +09001978 InitJavaModule(module, android.HostAndDeviceSupported)
Colin Cross9ae1b922018-06-26 17:59:05 -07001979 return module
Colin Cross2fe66872015-03-30 17:20:39 -07001980}
1981
Colin Cross1b16b0e2019-02-12 14:41:32 -08001982// java_library_static is an obsolete alias for java_library.
1983func LibraryStaticFactory() android.Module {
1984 return LibraryFactory()
1985}
1986
1987// java_library_host builds and links sources into a `.jar` file for the host.
1988//
1989// A java_library_host has a single variant that produces a `.jar` file containing `.class` files that were
1990// compiled against the host bootclasspath.
Colin Crossf506d872017-07-19 15:53:04 -07001991func LibraryHostFactory() android.Module {
1992 module := &Library{}
Colin Cross2fe66872015-03-30 17:20:39 -07001993
Colin Cross6af17aa2017-09-20 12:59:05 -07001994 module.AddProperties(
1995 &module.Module.properties,
1996 &module.Module.protoProperties)
Colin Cross36242852017-06-23 15:06:31 -07001997
Colin Cross9ae1b922018-06-26 17:59:05 -07001998 module.Module.properties.Installable = proptools.BoolPtr(true)
1999
Jiyong Park7f7766d2019-07-25 22:02:35 +09002000 android.InitApexModule(module)
Jooyung Han18020ea2019-11-13 10:50:48 +09002001 InitJavaModule(module, android.HostSupported)
Colin Cross36242852017-06-23 15:06:31 -07002002 return module
Colin Cross2fe66872015-03-30 17:20:39 -07002003}
2004
2005//
Colin Crossb628ea52018-08-14 16:42:33 -07002006// Java Tests
Colin Cross05638fc2018-04-09 18:40:24 -07002007//
2008
2009type testProperties struct {
Colin Cross05638fc2018-04-09 18:40:24 -07002010 // list of compatibility suites (for example "cts", "vts") that the module should be
2011 // installed into.
2012 Test_suites []string `android:"arch_variant"`
Julien Despreze146e392018-08-02 15:00:46 -07002013
2014 // the name of the test configuration (for example "AndroidTest.xml") that should be
2015 // installed with the module.
Colin Cross27b922f2019-03-04 22:35:41 -08002016 Test_config *string `android:"path,arch_variant"`
Colin Crossd96ca352018-08-10 16:06:24 -07002017
Jack He33338892018-09-19 02:21:28 -07002018 // the name of the test configuration template (for example "AndroidTestTemplate.xml") that
2019 // should be installed with the module.
Colin Cross27b922f2019-03-04 22:35:41 -08002020 Test_config_template *string `android:"path,arch_variant"`
Jack He33338892018-09-19 02:21:28 -07002021
Colin Crossd96ca352018-08-10 16:06:24 -07002022 // list of files or filegroup modules that provide data that should be installed alongside
2023 // the test
Colin Cross27b922f2019-03-04 22:35:41 -08002024 Data []string `android:"path"`
Dan Shi6ffaaa82019-09-26 11:41:36 -07002025
2026 // Flag to indicate whether or not to create test config automatically. If AndroidTest.xml
2027 // doesn't exist next to the Android.bp, this attribute doesn't need to be set to true
2028 // explicitly.
2029 Auto_gen_config *bool
Colin Cross05638fc2018-04-09 18:40:24 -07002030}
2031
Paul Duffin42df1442019-03-20 12:45:53 +00002032type testHelperLibraryProperties struct {
2033 // list of compatibility suites (for example "cts", "vts") that the module should be
2034 // installed into.
2035 Test_suites []string `android:"arch_variant"`
2036}
2037
Paul Duffin1b82e6a2019-12-03 18:06:47 +00002038type prebuiltTestProperties struct {
2039 // list of compatibility suites (for example "cts", "vts") that the module should be
2040 // installed into.
2041 Test_suites []string `android:"arch_variant"`
2042
2043 // the name of the test configuration (for example "AndroidTest.xml") that should be
2044 // installed with the module.
2045 Test_config *string `android:"path,arch_variant"`
2046}
2047
Colin Cross05638fc2018-04-09 18:40:24 -07002048type Test struct {
2049 Library
2050
2051 testProperties testProperties
Colin Cross303e21f2018-08-07 16:49:25 -07002052
2053 testConfig android.Path
Colin Crossd96ca352018-08-10 16:06:24 -07002054 data android.Paths
Colin Cross303e21f2018-08-07 16:49:25 -07002055}
2056
Paul Duffin42df1442019-03-20 12:45:53 +00002057type TestHelperLibrary struct {
2058 Library
2059
2060 testHelperLibraryProperties testHelperLibraryProperties
2061}
2062
Paul Duffin1b82e6a2019-12-03 18:06:47 +00002063type JavaTestImport struct {
2064 Import
2065
2066 prebuiltTestProperties prebuiltTestProperties
2067
2068 testConfig android.Path
2069}
2070
Colin Cross303e21f2018-08-07 16:49:25 -07002071func (j *Test) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Dan Shi6ffaaa82019-09-26 11:41:36 -07002072 j.testConfig = tradefed.AutoGenJavaTestConfig(ctx, j.testProperties.Test_config, j.testProperties.Test_config_template,
2073 j.testProperties.Test_suites, j.testProperties.Auto_gen_config)
Colin Cross8a497952019-03-05 22:25:09 -08002074 j.data = android.PathsForModuleSrc(ctx, j.testProperties.Data)
Colin Cross303e21f2018-08-07 16:49:25 -07002075
2076 j.Library.GenerateAndroidBuildActions(ctx)
Colin Cross05638fc2018-04-09 18:40:24 -07002077}
2078
Paul Duffin42df1442019-03-20 12:45:53 +00002079func (j *TestHelperLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
2080 j.Library.GenerateAndroidBuildActions(ctx)
2081}
2082
Paul Duffin1b82e6a2019-12-03 18:06:47 +00002083func (j *JavaTestImport) GenerateAndroidBuildActions(ctx android.ModuleContext) {
2084 j.testConfig = tradefed.AutoGenJavaTestConfig(ctx, j.prebuiltTestProperties.Test_config, nil,
2085 j.prebuiltTestProperties.Test_suites, nil)
2086
2087 j.Import.GenerateAndroidBuildActions(ctx)
2088}
2089
2090type testSdkMemberType struct {
2091 android.SdkMemberTypeBase
2092}
2093
2094func (mt *testSdkMemberType) AddDependencies(mctx android.BottomUpMutatorContext, dependencyTag blueprint.DependencyTag, names []string) {
2095 mctx.AddVariationDependencies(nil, dependencyTag, names...)
2096}
2097
2098func (mt *testSdkMemberType) IsInstance(module android.Module) bool {
2099 _, ok := module.(*Test)
2100 return ok
2101}
2102
2103func (mt *testSdkMemberType) BuildSnapshot(sdkModuleContext android.ModuleContext, builder android.SnapshotBuilder, member android.SdkMember) {
2104 variants := member.Variants()
2105 if len(variants) != 1 {
2106 sdkModuleContext.ModuleErrorf("sdk contains %d variants of member %q but only one is allowed", len(variants), member.Name())
2107 for _, variant := range variants {
2108 sdkModuleContext.ModuleErrorf(" %q", variant)
2109 }
2110 }
2111 variant := variants[0]
2112 j := variant.(*Test)
2113
2114 implementationJars := j.ImplementationJars()
2115 if len(implementationJars) != 1 {
2116 panic(fmt.Errorf("there must be only one implementation jar from %q", j.Name()))
2117 }
2118
2119 snapshotRelativeJavaLibPath := sdkSnapshotFilePathForJar(member)
2120 builder.CopyToSnapshot(implementationJars[0], snapshotRelativeJavaLibPath)
2121
2122 snapshotRelativeTestConfigPath := sdkSnapshotFilePathForMember(member, testConfigSuffix)
2123 builder.CopyToSnapshot(j.testConfig, snapshotRelativeTestConfigPath)
2124
2125 module := builder.AddPrebuiltModule(member, "java_test_import")
2126 module.AddProperty("jars", []string{snapshotRelativeJavaLibPath})
2127 module.AddProperty("test_config", snapshotRelativeTestConfigPath)
2128}
2129
Colin Cross1b16b0e2019-02-12 14:41:32 -08002130// java_test builds a and links sources into a `.jar` file for the device, and possibly for the host as well, and
2131// creates an `AndroidTest.xml` file to allow running the test with `atest` or a `TEST_MAPPING` file.
2132//
2133// By default, a java_test has a single variant that produces a `.jar` file containing `classes.dex` files that were
2134// compiled against the device bootclasspath.
2135//
2136// Specifying `host_supported: true` will produce two variants, one compiled against the device bootclasspath and one
2137// compiled against the host bootclasspath.
Colin Cross05638fc2018-04-09 18:40:24 -07002138func TestFactory() android.Module {
2139 module := &Test{}
2140
2141 module.AddProperties(
2142 &module.Module.properties,
2143 &module.Module.deviceProperties,
Colin Cross43f08db2018-11-12 10:13:39 -08002144 &module.Module.dexpreoptProperties,
Colin Cross05638fc2018-04-09 18:40:24 -07002145 &module.Module.protoProperties,
2146 &module.testProperties)
2147
Colin Cross9ae1b922018-06-26 17:59:05 -07002148 module.Module.properties.Installable = proptools.BoolPtr(true)
Colin Crosse3026872019-01-05 22:30:13 -08002149 module.Module.dexpreopter.isTest = true
Colin Cross9ae1b922018-06-26 17:59:05 -07002150
Colin Cross05638fc2018-04-09 18:40:24 -07002151 InitJavaModule(module, android.HostAndDeviceSupported)
Colin Cross05638fc2018-04-09 18:40:24 -07002152 return module
2153}
2154
Paul Duffin42df1442019-03-20 12:45:53 +00002155// java_test_helper_library creates a java library and makes sure that it is added to the appropriate test suite.
2156func TestHelperLibraryFactory() android.Module {
2157 module := &TestHelperLibrary{}
2158
2159 module.AddProperties(
2160 &module.Module.properties,
2161 &module.Module.deviceProperties,
2162 &module.Module.dexpreoptProperties,
2163 &module.Module.protoProperties,
2164 &module.testHelperLibraryProperties)
2165
Colin Cross9a4abed2019-04-24 13:19:28 -07002166 module.Module.properties.Installable = proptools.BoolPtr(true)
2167 module.Module.dexpreopter.isTest = true
2168
Paul Duffin42df1442019-03-20 12:45:53 +00002169 InitJavaModule(module, android.HostAndDeviceSupported)
2170 return module
2171}
2172
Paul Duffin1b82e6a2019-12-03 18:06:47 +00002173// java_test_import imports one or more `.jar` files into the build graph as if they were built by a java_test module
2174// and makes sure that it is added to the appropriate test suite.
2175//
2176// By default, a java_test_import has a single variant that expects a `.jar` file containing `.class` files that were
2177// compiled against an Android classpath.
2178//
2179// Specifying `host_supported: true` will produce two variants, one for use as a dependency of device modules and one
2180// for host modules.
2181func JavaTestImportFactory() android.Module {
2182 module := &JavaTestImport{}
2183
2184 module.AddProperties(
2185 &module.Import.properties,
2186 &module.prebuiltTestProperties)
2187
2188 module.Import.properties.Installable = proptools.BoolPtr(true)
2189
2190 android.InitPrebuiltModule(module, &module.properties.Jars)
2191 android.InitApexModule(module)
2192 android.InitSdkAwareModule(module)
2193 InitJavaModule(module, android.HostAndDeviceSupported)
2194 return module
2195}
2196
Colin Cross1b16b0e2019-02-12 14:41:32 -08002197// java_test_host builds a and links sources into a `.jar` file for the host, and creates an `AndroidTest.xml` file to
2198// allow running the test with `atest` or a `TEST_MAPPING` file.
2199//
2200// A java_test_host has a single variant that produces a `.jar` file containing `.class` files that were
2201// compiled against the host bootclasspath.
Colin Cross05638fc2018-04-09 18:40:24 -07002202func TestHostFactory() android.Module {
2203 module := &Test{}
2204
2205 module.AddProperties(
2206 &module.Module.properties,
2207 &module.Module.protoProperties,
2208 &module.testProperties)
2209
Colin Cross9ae1b922018-06-26 17:59:05 -07002210 module.Module.properties.Installable = proptools.BoolPtr(true)
2211
Colin Cross05638fc2018-04-09 18:40:24 -07002212 InitJavaModule(module, android.HostSupported)
Colin Cross05638fc2018-04-09 18:40:24 -07002213 return module
2214}
2215
2216//
Colin Cross2fe66872015-03-30 17:20:39 -07002217// Java Binaries (.jar file plus wrapper script)
2218//
2219
Colin Crossf506d872017-07-19 15:53:04 -07002220type binaryProperties struct {
Colin Cross7d5136f2015-05-11 13:39:40 -07002221 // installable script to execute the resulting jar
Colin Cross27b922f2019-03-04 22:35:41 -08002222 Wrapper *string `android:"path"`
Colin Cross094054a2018-10-17 15:10:48 -07002223
2224 // Name of the class containing main to be inserted into the manifest as Main-Class.
2225 Main_class *string
Colin Cross7d5136f2015-05-11 13:39:40 -07002226}
2227
Colin Crossf506d872017-07-19 15:53:04 -07002228type Binary struct {
2229 Library
Colin Cross2fe66872015-03-30 17:20:39 -07002230
Colin Crossf506d872017-07-19 15:53:04 -07002231 binaryProperties binaryProperties
Colin Cross10a03492017-08-10 17:09:43 -07002232
Colin Cross6b4a32d2017-12-05 13:42:45 -08002233 isWrapperVariant bool
2234
Colin Crossc3315992017-12-08 19:12:36 -08002235 wrapperFile android.Path
Colin Cross70dda7e2019-10-01 22:05:35 -07002236 binaryFile android.InstallPath
Colin Cross2fe66872015-03-30 17:20:39 -07002237}
2238
Alex Light24237172017-10-26 09:46:21 -07002239func (j *Binary) HostToolPath() android.OptionalPath {
2240 return android.OptionalPathForPath(j.binaryFile)
2241}
2242
Colin Crossf506d872017-07-19 15:53:04 -07002243func (j *Binary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross6b4a32d2017-12-05 13:42:45 -08002244 if ctx.Arch().ArchType == android.Common {
2245 // Compile the jar
Colin Cross094054a2018-10-17 15:10:48 -07002246 if j.binaryProperties.Main_class != nil {
2247 if j.properties.Manifest != nil {
2248 ctx.PropertyErrorf("main_class", "main_class cannot be used when manifest is set")
2249 }
2250 manifestFile := android.PathForModuleOut(ctx, "manifest.txt")
2251 GenerateMainClassManifest(ctx, manifestFile, String(j.binaryProperties.Main_class))
2252 j.overrideManifest = android.OptionalPathForPath(manifestFile)
2253 }
2254
Colin Cross6b4a32d2017-12-05 13:42:45 -08002255 j.Library.GenerateAndroidBuildActions(ctx)
Nan Zhang3c807db2017-11-03 14:53:31 -07002256 } else {
Colin Cross6b4a32d2017-12-05 13:42:45 -08002257 // Handle the binary wrapper
2258 j.isWrapperVariant = true
2259
Colin Cross366938f2017-12-11 16:29:02 -08002260 if j.binaryProperties.Wrapper != nil {
Colin Cross8a497952019-03-05 22:25:09 -08002261 j.wrapperFile = android.PathForModuleSrc(ctx, *j.binaryProperties.Wrapper)
Colin Cross6b4a32d2017-12-05 13:42:45 -08002262 } else {
2263 j.wrapperFile = android.PathForSource(ctx, "build/soong/scripts/jar-wrapper.sh")
2264 }
2265
2266 // Depend on the installed jar so that the wrapper doesn't get executed by
2267 // another build rule before the jar has been installed.
2268 jarFile := ctx.PrimaryModule().(*Binary).installFile
2269
2270 j.binaryFile = ctx.InstallExecutable(android.PathForModuleInstall(ctx, "bin"),
2271 ctx.ModuleName(), j.wrapperFile, jarFile)
Nan Zhang3c807db2017-11-03 14:53:31 -07002272 }
Colin Cross2fe66872015-03-30 17:20:39 -07002273}
2274
Colin Crossf506d872017-07-19 15:53:04 -07002275func (j *Binary) DepsMutator(ctx android.BottomUpMutatorContext) {
Colin Cross6b4a32d2017-12-05 13:42:45 -08002276 if ctx.Arch().ArchType == android.Common {
2277 j.deps(ctx)
2278 }
Colin Cross46c9b8b2017-06-22 16:51:17 -07002279}
2280
Colin Cross1b16b0e2019-02-12 14:41:32 -08002281// java_binary builds a `.jar` file and a shell script that executes it for the device, and possibly for the host
2282// as well.
2283//
2284// By default, a java_binary has a single variant that produces a `.jar` file containing `classes.dex` files that were
2285// compiled against the device bootclasspath.
2286//
2287// Specifying `host_supported: true` will produce two variants, one compiled against the device bootclasspath and one
2288// compiled against the host bootclasspath.
Colin Crossf506d872017-07-19 15:53:04 -07002289func BinaryFactory() android.Module {
2290 module := &Binary{}
Colin Cross2fe66872015-03-30 17:20:39 -07002291
Colin Cross36242852017-06-23 15:06:31 -07002292 module.AddProperties(
Colin Cross540eff82017-06-22 17:01:52 -07002293 &module.Module.properties,
2294 &module.Module.deviceProperties,
Colin Cross43f08db2018-11-12 10:13:39 -08002295 &module.Module.dexpreoptProperties,
Colin Cross6af17aa2017-09-20 12:59:05 -07002296 &module.Module.protoProperties,
Colin Cross540eff82017-06-22 17:01:52 -07002297 &module.binaryProperties)
Colin Cross36242852017-06-23 15:06:31 -07002298
Colin Cross9ae1b922018-06-26 17:59:05 -07002299 module.Module.properties.Installable = proptools.BoolPtr(true)
2300
Colin Cross6b4a32d2017-12-05 13:42:45 -08002301 android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibCommonFirst)
2302 android.InitDefaultableModule(module)
Colin Cross36242852017-06-23 15:06:31 -07002303 return module
Colin Cross2fe66872015-03-30 17:20:39 -07002304}
2305
Colin Cross1b16b0e2019-02-12 14:41:32 -08002306// java_binary_host builds a `.jar` file and a shell script that executes it for the host.
2307//
2308// A java_binary_host has a single variant that produces a `.jar` file containing `.class` files that were
2309// compiled against the host bootclasspath.
Colin Crossf506d872017-07-19 15:53:04 -07002310func BinaryHostFactory() android.Module {
2311 module := &Binary{}
Colin Cross2fe66872015-03-30 17:20:39 -07002312
Colin Cross36242852017-06-23 15:06:31 -07002313 module.AddProperties(
Colin Cross540eff82017-06-22 17:01:52 -07002314 &module.Module.properties,
Colin Cross6af17aa2017-09-20 12:59:05 -07002315 &module.Module.protoProperties,
Colin Cross540eff82017-06-22 17:01:52 -07002316 &module.binaryProperties)
Colin Cross36242852017-06-23 15:06:31 -07002317
Colin Cross9ae1b922018-06-26 17:59:05 -07002318 module.Module.properties.Installable = proptools.BoolPtr(true)
2319
Colin Cross6b4a32d2017-12-05 13:42:45 -08002320 android.InitAndroidArchModule(module, android.HostSupported, android.MultilibCommonFirst)
2321 android.InitDefaultableModule(module)
Colin Cross36242852017-06-23 15:06:31 -07002322 return module
Colin Cross2fe66872015-03-30 17:20:39 -07002323}
2324
2325//
2326// Java prebuilts
2327//
2328
Colin Cross74d73e22017-08-02 11:05:49 -07002329type ImportProperties struct {
Colin Cross27b922f2019-03-04 22:35:41 -08002330 Jars []string `android:"path"`
Colin Cross461bd1a2017-10-20 13:59:18 -07002331
Nan Zhangea568a42017-11-08 21:20:04 -08002332 Sdk_version *string
Colin Cross535e2cf2017-10-20 17:57:49 -07002333
2334 Installable *bool
Jiyong Park1be96912018-05-28 18:02:19 +09002335
2336 // List of shared java libs that this module has dependencies to
2337 Libs []string
Colin Cross37f6d792018-07-12 12:28:41 -07002338
2339 // List of files to remove from the jar file(s)
2340 Exclude_files []string
2341
2342 // List of directories to remove from the jar file(s)
2343 Exclude_dirs []string
Nan Zhang4c819fb2018-08-27 18:31:46 -07002344
2345 // if set to true, run Jetifier against .jar file. Defaults to false.
Colin Cross1001a792019-03-21 22:21:39 -07002346 Jetifier *bool
Jiyong Park4c4c0242019-10-21 14:53:15 +09002347
2348 // set the name of the output
2349 Stem *string
Colin Cross74d73e22017-08-02 11:05:49 -07002350}
2351
2352type Import struct {
Colin Cross635c3b02016-05-18 15:37:25 -07002353 android.ModuleBase
Colin Cross48de9a42018-10-02 13:53:33 -07002354 android.DefaultableModuleBase
Jiyong Park7f7766d2019-07-25 22:02:35 +09002355 android.ApexModuleBase
Colin Crossec7a0422017-07-07 14:47:12 -07002356 prebuilt android.Prebuilt
Jiyong Parkd1063c12019-07-17 20:08:41 +09002357 android.SdkBase
Colin Cross2fe66872015-03-30 17:20:39 -07002358
Colin Cross74d73e22017-08-02 11:05:49 -07002359 properties ImportProperties
2360
Colin Cross0a6e0072017-08-30 14:24:55 -07002361 combinedClasspathFile android.Path
Jiyong Park1be96912018-05-28 18:02:19 +09002362 exportedSdkLibs []string
Colin Cross2fe66872015-03-30 17:20:39 -07002363}
2364
Jiyong Park6a927c42020-01-21 02:03:43 +09002365func (j *Import) sdkVersion() sdkSpec {
2366 return sdkSpecFrom(String(j.properties.Sdk_version))
Colin Cross83bb3162018-06-25 15:48:06 -07002367}
2368
Jiyong Park6a927c42020-01-21 02:03:43 +09002369func (j *Import) minSdkVersion() sdkSpec {
Colin Cross83bb3162018-06-25 15:48:06 -07002370 return j.sdkVersion()
2371}
2372
Colin Cross74d73e22017-08-02 11:05:49 -07002373func (j *Import) Prebuilt() *android.Prebuilt {
Colin Crossec7a0422017-07-07 14:47:12 -07002374 return &j.prebuilt
2375}
2376
Colin Cross74d73e22017-08-02 11:05:49 -07002377func (j *Import) PrebuiltSrcs() []string {
2378 return j.properties.Jars
2379}
2380
2381func (j *Import) Name() string {
Colin Cross5ea9bcc2017-07-27 15:41:32 -07002382 return j.prebuilt.Name(j.ModuleBase.Name())
2383}
2384
Jiyong Park0b238752019-10-29 11:23:10 +09002385func (j *Import) Stem() string {
2386 return proptools.StringDefault(j.properties.Stem, j.ModuleBase.Name())
2387}
2388
Jiyong Park618922e2020-01-08 13:35:43 +09002389func (a *Import) JacocoReportClassesFile() android.Path {
2390 return nil
2391}
2392
Colin Cross74d73e22017-08-02 11:05:49 -07002393func (j *Import) DepsMutator(ctx android.BottomUpMutatorContext) {
Colin Cross42d48b72018-08-29 14:10:52 -07002394 ctx.AddVariationDependencies(nil, libTag, j.properties.Libs...)
Colin Cross1e676be2016-10-12 14:38:15 -07002395}
2396
Colin Cross74d73e22017-08-02 11:05:49 -07002397func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross8a497952019-03-05 22:25:09 -08002398 jars := android.PathsForModuleSrc(ctx, j.properties.Jars)
Colin Crosse1d62a82015-04-03 16:53:05 -07002399
Jiyong Park0b238752019-10-29 11:23:10 +09002400 jarName := j.Stem() + ".jar"
Nan Zhang4c819fb2018-08-27 18:31:46 -07002401 outputFile := android.PathForModuleOut(ctx, "combined", jarName)
Colin Cross37f6d792018-07-12 12:28:41 -07002402 TransformJarsToJar(ctx, outputFile, "for prebuilts", jars, android.OptionalPath{},
2403 false, j.properties.Exclude_files, j.properties.Exclude_dirs)
Colin Cross1001a792019-03-21 22:21:39 -07002404 if Bool(j.properties.Jetifier) {
Nan Zhang4c819fb2018-08-27 18:31:46 -07002405 inputFile := outputFile
2406 outputFile = android.PathForModuleOut(ctx, "jetifier", jarName)
2407 TransformJetifier(ctx, outputFile, inputFile)
2408 }
Colin Crosse9a275b2017-10-16 17:09:48 -07002409 j.combinedClasspathFile = outputFile
Jiyong Park1be96912018-05-28 18:02:19 +09002410
2411 ctx.VisitDirectDeps(func(module android.Module) {
2412 otherName := ctx.OtherModuleName(module)
2413 tag := ctx.OtherModuleDependencyTag(module)
2414
2415 switch dep := module.(type) {
2416 case Dependency:
2417 switch tag {
2418 case libTag, staticLibTag:
2419 // sdk lib names from dependencies are re-exported
2420 j.exportedSdkLibs = append(j.exportedSdkLibs, dep.ExportedSdkLibs()...)
2421 }
2422 case SdkLibraryDependency:
2423 switch tag {
2424 case libTag:
2425 // names of sdk libs that are directly depended are exported
2426 j.exportedSdkLibs = append(j.exportedSdkLibs, otherName)
2427 }
2428 }
2429 })
2430
2431 j.exportedSdkLibs = android.FirstUniqueStrings(j.exportedSdkLibs)
Nan Zhang4973ecf2018-08-10 13:42:12 -07002432 if Bool(j.properties.Installable) {
2433 ctx.InstallFile(android.PathForModuleInstall(ctx, "framework"),
Jiyong Park4c4c0242019-10-21 14:53:15 +09002434 jarName, outputFile)
Nan Zhang4973ecf2018-08-10 13:42:12 -07002435 }
Colin Cross2fe66872015-03-30 17:20:39 -07002436}
2437
Colin Cross74d73e22017-08-02 11:05:49 -07002438var _ Dependency = (*Import)(nil)
Colin Cross2fe66872015-03-30 17:20:39 -07002439
Nan Zhanged19fc32017-10-19 13:06:22 -07002440func (j *Import) HeaderJars() android.Paths {
albaltai36ff7dc2018-12-25 14:35:23 +08002441 if j.combinedClasspathFile == nil {
2442 return nil
2443 }
Colin Cross37f6d792018-07-12 12:28:41 -07002444 return android.Paths{j.combinedClasspathFile}
Nan Zhanged19fc32017-10-19 13:06:22 -07002445}
2446
2447func (j *Import) ImplementationJars() android.Paths {
shinwang9e4c07a2018-12-24 15:41:04 +08002448 if j.combinedClasspathFile == nil {
2449 return nil
2450 }
Colin Cross37f6d792018-07-12 12:28:41 -07002451 return android.Paths{j.combinedClasspathFile}
Colin Cross2fe66872015-03-30 17:20:39 -07002452}
2453
Colin Cross331a1212018-08-15 20:40:52 -07002454func (j *Import) ResourceJars() android.Paths {
2455 return nil
2456}
2457
2458func (j *Import) ImplementationAndResourcesJars() android.Paths {
albaltai36ff7dc2018-12-25 14:35:23 +08002459 if j.combinedClasspathFile == nil {
2460 return nil
2461 }
Colin Cross331a1212018-08-15 20:40:52 -07002462 return android.Paths{j.combinedClasspathFile}
2463}
2464
Colin Crossf24a22a2019-01-31 14:12:44 -08002465func (j *Import) DexJar() android.Path {
2466 return nil
2467}
2468
Colin Cross74d73e22017-08-02 11:05:49 -07002469func (j *Import) AidlIncludeDirs() android.Paths {
Colin Crossc0b06f12015-04-08 13:03:43 -07002470 return nil
2471}
2472
Jiyong Park1be96912018-05-28 18:02:19 +09002473func (j *Import) ExportedSdkLibs() []string {
2474 return j.exportedSdkLibs
2475}
2476
Artur Satayev9cf46692019-11-26 18:08:34 +00002477func (j *Import) ExportedPlugins() (android.Paths, []string) {
2478 return nil, nil
2479}
2480
Colin Cross0c4ce212019-05-03 15:28:19 -07002481func (j *Import) SrcJarArgs() ([]string, android.Paths) {
2482 return nil, nil
2483}
2484
Jiyong Park0f80c182020-01-31 02:49:53 +09002485func (j *Import) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
Jiyong Park0f80c182020-01-31 02:49:53 +09002486 // dependencies other than the static linkage are all considered crossing APEX boundary
Jooyung Hanb8fa86a2020-03-10 06:23:13 +09002487 if staticLibTag == ctx.OtherModuleDependencyTag(dep) {
2488 return true
2489 }
Jiyong Park0f80c182020-01-31 02:49:53 +09002490 // Also, a dependency to an sdk member is also considered as such. This is required because
2491 // sdk members should be mutated into APEXes. Refer to sdk.sdkDepsReplaceMutator.
Jooyung Hanb8fa86a2020-03-10 06:23:13 +09002492 if sa, ok := dep.(android.SdkAware); ok && sa.IsInAnySdk() {
2493 return true
2494 }
2495 return false
Jiyong Park0f80c182020-01-31 02:49:53 +09002496}
2497
albaltai36ff7dc2018-12-25 14:35:23 +08002498// Add compile time check for interface implementation
2499var _ android.IDEInfo = (*Import)(nil)
2500var _ android.IDECustomizedModuleName = (*Import)(nil)
2501
Brandon Lee5d45c6f2018-08-15 15:35:38 -07002502// Collect information for opening IDE project files in java/jdeps.go.
2503const (
2504 removedPrefix = "prebuilt_"
2505)
2506
2507func (j *Import) IDEInfo(dpInfo *android.IdeInfo) {
2508 dpInfo.Jars = append(dpInfo.Jars, j.PrebuiltSrcs()...)
2509}
2510
2511func (j *Import) IDECustomizedModuleName() string {
2512 // TODO(b/113562217): Extract the base module name from the Import name, often the Import name
2513 // has a prefix "prebuilt_". Remove the prefix explicitly if needed until we find a better
2514 // solution to get the Import name.
2515 name := j.Name()
2516 if strings.HasPrefix(name, removedPrefix) {
patricktubb640e02018-10-11 18:33:16 +08002517 name = strings.TrimPrefix(name, removedPrefix)
Brandon Lee5d45c6f2018-08-15 15:35:38 -07002518 }
2519 return name
2520}
2521
Colin Cross74d73e22017-08-02 11:05:49 -07002522var _ android.PrebuiltInterface = (*Import)(nil)
Colin Cross2fe66872015-03-30 17:20:39 -07002523
Colin Cross1b16b0e2019-02-12 14:41:32 -08002524// java_import imports one or more `.jar` files into the build graph as if they were built by a java_library module.
2525//
2526// By default, a java_import has a single variant that expects a `.jar` file containing `.class` files that were
2527// compiled against an Android classpath.
2528//
2529// Specifying `host_supported: true` will produce two variants, one for use as a dependency of device modules and one
2530// for host modules.
Colin Cross74d73e22017-08-02 11:05:49 -07002531func ImportFactory() android.Module {
2532 module := &Import{}
Colin Cross36242852017-06-23 15:06:31 -07002533
Colin Cross74d73e22017-08-02 11:05:49 -07002534 module.AddProperties(&module.properties)
2535
2536 android.InitPrebuiltModule(module, &module.properties.Jars)
Jiyong Park7f7766d2019-07-25 22:02:35 +09002537 android.InitApexModule(module)
Jiyong Parkd1063c12019-07-17 20:08:41 +09002538 android.InitSdkAwareModule(module)
Jooyung Han18020ea2019-11-13 10:50:48 +09002539 InitJavaModule(module, android.HostAndDeviceSupported)
Colin Cross36242852017-06-23 15:06:31 -07002540 return module
Colin Cross2fe66872015-03-30 17:20:39 -07002541}
2542
Colin Cross1b16b0e2019-02-12 14:41:32 -08002543// java_import imports one or more `.jar` files into the build graph as if they were built by a java_library_host
2544// module.
2545//
2546// A java_import_host has a single variant that expects a `.jar` file containing `.class` files that were
2547// compiled against a host bootclasspath.
Colin Cross74d73e22017-08-02 11:05:49 -07002548func ImportFactoryHost() android.Module {
2549 module := &Import{}
2550
2551 module.AddProperties(&module.properties)
2552
2553 android.InitPrebuiltModule(module, &module.properties.Jars)
Jiyong Park7f7766d2019-07-25 22:02:35 +09002554 android.InitApexModule(module)
Jooyung Han18020ea2019-11-13 10:50:48 +09002555 InitJavaModule(module, android.HostSupported)
Colin Cross74d73e22017-08-02 11:05:49 -07002556 return module
2557}
2558
Colin Cross42be7612019-02-21 18:12:14 -08002559// dex_import module
2560
2561type DexImportProperties struct {
Colin Cross5cfc70d2019-07-15 13:36:55 -07002562 Jars []string `android:"path"`
Jiyong Park4c4c0242019-10-21 14:53:15 +09002563
2564 // set the name of the output
2565 Stem *string
Colin Cross42be7612019-02-21 18:12:14 -08002566}
2567
2568type DexImport struct {
2569 android.ModuleBase
2570 android.DefaultableModuleBase
Jiyong Park7f7766d2019-07-25 22:02:35 +09002571 android.ApexModuleBase
Colin Cross42be7612019-02-21 18:12:14 -08002572 prebuilt android.Prebuilt
2573
2574 properties DexImportProperties
2575
2576 dexJarFile android.Path
2577 maybeStrippedDexJarFile android.Path
2578
2579 dexpreopter
2580}
2581
2582func (j *DexImport) Prebuilt() *android.Prebuilt {
2583 return &j.prebuilt
2584}
2585
2586func (j *DexImport) PrebuiltSrcs() []string {
2587 return j.properties.Jars
2588}
2589
2590func (j *DexImport) Name() string {
2591 return j.prebuilt.Name(j.ModuleBase.Name())
2592}
2593
Jiyong Park0b238752019-10-29 11:23:10 +09002594func (j *DexImport) Stem() string {
2595 return proptools.StringDefault(j.properties.Stem, j.ModuleBase.Name())
2596}
2597
Martin Stjernholm6d415272020-01-31 17:10:36 +00002598func (j *DexImport) IsInstallable() bool {
2599 return true
2600}
2601
Colin Cross42be7612019-02-21 18:12:14 -08002602func (j *DexImport) GenerateAndroidBuildActions(ctx android.ModuleContext) {
2603 if len(j.properties.Jars) != 1 {
2604 ctx.PropertyErrorf("jars", "exactly one jar must be provided")
2605 }
2606
Jiyong Park0b238752019-10-29 11:23:10 +09002607 j.dexpreopter.installPath = android.PathForModuleInstall(ctx, "framework", j.Stem()+".jar")
Colin Cross42be7612019-02-21 18:12:14 -08002608 j.dexpreopter.uncompressedDex = shouldUncompressDex(ctx, &j.dexpreopter)
2609
2610 inputJar := ctx.ExpandSource(j.properties.Jars[0], "jars")
2611 dexOutputFile := android.PathForModuleOut(ctx, ctx.ModuleName()+".jar")
2612
2613 if j.dexpreopter.uncompressedDex {
2614 rule := android.NewRuleBuilder()
2615
2616 temporary := android.PathForModuleOut(ctx, ctx.ModuleName()+".jar.unaligned")
2617 rule.Temporary(temporary)
2618
2619 // use zip2zip to uncompress classes*.dex files
2620 rule.Command().
Colin Crossee94d6a2019-07-08 17:08:34 -07002621 BuiltTool(ctx, "zip2zip").
Colin Cross42be7612019-02-21 18:12:14 -08002622 FlagWithInput("-i ", inputJar).
2623 FlagWithOutput("-o ", temporary).
2624 FlagWithArg("-0 ", "'classes*.dex'")
2625
2626 // use zipalign to align uncompressed classes*.dex files
2627 rule.Command().
Colin Crossee94d6a2019-07-08 17:08:34 -07002628 BuiltTool(ctx, "zipalign").
Colin Cross42be7612019-02-21 18:12:14 -08002629 Flag("-f").
2630 Text("4").
2631 Input(temporary).
2632 Output(dexOutputFile)
2633
2634 rule.DeleteTemporaryFiles()
2635
2636 rule.Build(pctx, ctx, "uncompress_dex", "uncompress dex")
2637 } else {
2638 ctx.Build(pctx, android.BuildParams{
2639 Rule: android.Cp,
2640 Input: inputJar,
2641 Output: dexOutputFile,
2642 })
2643 }
2644
2645 j.dexJarFile = dexOutputFile
2646
2647 dexOutputFile = j.dexpreopt(ctx, dexOutputFile)
2648
2649 j.maybeStrippedDexJarFile = dexOutputFile
2650
2651 ctx.InstallFile(android.PathForModuleInstall(ctx, "framework"),
2652 ctx.ModuleName()+".jar", dexOutputFile)
2653}
2654
2655func (j *DexImport) DexJar() android.Path {
2656 return j.dexJarFile
2657}
2658
2659// dex_import imports a `.jar` file containing classes.dex files.
2660//
2661// A dex_import module cannot be used as a dependency of a java_* or android_* module, it can only be installed
2662// to the device.
2663func DexImportFactory() android.Module {
2664 module := &DexImport{}
2665
2666 module.AddProperties(&module.properties)
2667
2668 android.InitPrebuiltModule(module, &module.properties.Jars)
Jiyong Park7f7766d2019-07-25 22:02:35 +09002669 android.InitApexModule(module)
Jooyung Han18020ea2019-11-13 10:50:48 +09002670 InitJavaModule(module, android.DeviceSupported)
Colin Cross42be7612019-02-21 18:12:14 -08002671 return module
2672}
2673
Colin Cross89536d42017-07-07 14:35:50 -07002674//
2675// Defaults
2676//
2677type Defaults struct {
2678 android.ModuleBase
2679 android.DefaultsModuleBase
Jiyong Park7f7766d2019-07-25 22:02:35 +09002680 android.ApexModuleBase
Colin Cross89536d42017-07-07 14:35:50 -07002681}
2682
Colin Cross1b16b0e2019-02-12 14:41:32 -08002683// java_defaults provides a set of properties that can be inherited by other java or android modules.
2684//
2685// A module can use the properties from a java_defaults module using `defaults: ["defaults_module_name"]`. Each
2686// property in the defaults module that exists in the depending module will be prepended to the depending module's
2687// value for that property.
2688//
2689// Example:
2690//
2691// java_defaults {
2692// name: "example_defaults",
2693// srcs: ["common/**/*.java"],
2694// javacflags: ["-Xlint:all"],
2695// aaptflags: ["--auto-add-overlay"],
2696// }
2697//
2698// java_library {
2699// name: "example",
2700// defaults: ["example_defaults"],
2701// srcs: ["example/**/*.java"],
2702// }
2703//
2704// is functionally identical to:
2705//
2706// java_library {
2707// name: "example",
2708// srcs: [
2709// "common/**/*.java",
2710// "example/**/*.java",
2711// ],
2712// javacflags: ["-Xlint:all"],
2713// }
Colin Cross89536d42017-07-07 14:35:50 -07002714func defaultsFactory() android.Module {
2715 return DefaultsFactory()
2716}
2717
Paul Duffin47357662019-12-05 14:07:14 +00002718func DefaultsFactory() android.Module {
Colin Cross89536d42017-07-07 14:35:50 -07002719 module := &Defaults{}
2720
Colin Cross89536d42017-07-07 14:35:50 -07002721 module.AddProperties(
2722 &CompilerProperties{},
2723 &CompilerDeviceProperties{},
Colin Cross43f08db2018-11-12 10:13:39 -08002724 &DexpreoptProperties{},
Dan Willemsen6424d172018-03-08 13:27:59 -08002725 &android.ProtoProperties{},
Colin Cross48de9a42018-10-02 13:53:33 -07002726 &aaptProperties{},
2727 &androidLibraryProperties{},
2728 &appProperties{},
2729 &appTestProperties{},
Jaewoong Jung525443a2019-02-28 15:35:54 -08002730 &overridableAppProperties{},
Colin Cross48de9a42018-10-02 13:53:33 -07002731 &ImportProperties{},
2732 &AARImportProperties{},
2733 &sdkLibraryProperties{},
Colin Cross42be7612019-02-21 18:12:14 -08002734 &DexImportProperties{},
Jooyung Han18020ea2019-11-13 10:50:48 +09002735 &android.ApexProperties{},
Colin Cross89536d42017-07-07 14:35:50 -07002736 )
2737
2738 android.InitDefaultsModule(module)
Colin Cross89536d42017-07-07 14:35:50 -07002739 return module
2740}
Nan Zhangea568a42017-11-08 21:20:04 -08002741
Sasha Smundak2a4549e2018-11-05 16:49:08 -08002742func kytheExtractJavaFactory() android.Singleton {
2743 return &kytheExtractJavaSingleton{}
2744}
2745
2746type kytheExtractJavaSingleton struct {
2747}
2748
2749func (ks *kytheExtractJavaSingleton) GenerateBuildActions(ctx android.SingletonContext) {
2750 var xrefTargets android.Paths
2751 ctx.VisitAllModules(func(module android.Module) {
2752 if javaModule, ok := module.(xref); ok {
2753 xrefTargets = append(xrefTargets, javaModule.XrefJavaFiles()...)
2754 }
2755 })
2756 // TODO(asmundak): perhaps emit a rule to output a warning if there were no xrefTargets
2757 if len(xrefTargets) > 0 {
2758 ctx.Build(pctx, android.BuildParams{
2759 Rule: blueprint.Phony,
2760 Output: android.PathForPhony(ctx, "xref_java"),
2761 Inputs: xrefTargets,
2762 })
2763 }
2764}
2765
Nan Zhangea568a42017-11-08 21:20:04 -08002766var Bool = proptools.Bool
Colin Cross38b40df2018-04-10 16:14:46 -07002767var BoolDefault = proptools.BoolDefault
Nan Zhangea568a42017-11-08 21:20:04 -08002768var String = proptools.String
Colin Cross0d0ba592018-02-20 13:33:42 -08002769var inList = android.InList