blob: ceedd8971ce3320a378be2e273cf30c5dd3a223b [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"
Ulya Trafimovichf3ff0102019-12-03 15:39:23 +000026 "sync"
Colin Cross2fe66872015-03-30 17:20:39 -070027
28 "github.com/google/blueprint"
Colin Cross3b706fd2019-09-05 16:44:18 -070029 "github.com/google/blueprint/pathtools"
Colin Cross76b5f0c2017-08-29 16:02:06 -070030 "github.com/google/blueprint/proptools"
Colin Cross2fe66872015-03-30 17:20:39 -070031
Colin Cross635c3b02016-05-18 15:37:25 -070032 "android/soong/android"
Ulya Trafimovichf3ff0102019-12-03 15:39:23 +000033 "android/soong/dexpreopt"
Colin Cross3e3e72d2017-06-22 17:20:19 -070034 "android/soong/java/config"
Colin Cross303e21f2018-08-07 16:49:25 -070035 "android/soong/tradefed"
Colin Cross2fe66872015-03-30 17:20:39 -070036)
37
Colin Cross463a90e2015-06-17 14:20:06 -070038func init() {
Paul Duffinf9b1da02019-12-18 19:51:55 +000039 RegisterJavaBuildComponents(android.InitRegistrationContext)
Paul Duffin255f18e2019-12-13 11:22:16 +000040
41 // Register sdk member types.
Paul Duffin7b81f5e2020-01-13 21:03:22 +000042 android.RegisterSdkMemberType(javaHeaderLibsSdkMemberType)
Paul Duffin255f18e2019-12-13 11:22:16 +000043
44 android.RegisterSdkMemberType(&implLibrarySdkMemberType{
45 librarySdkMemberType{
46 android.SdkMemberTypeBase{
47 PropertyName: "java_libs",
48 },
49 },
50 })
Paul Duffin1b82e6a2019-12-03 18:06:47 +000051
52 android.RegisterSdkMemberType(&testSdkMemberType{
53 SdkMemberTypeBase: android.SdkMemberTypeBase{
54 PropertyName: "java_tests",
55 },
56 })
Ulya Trafimovichf3ff0102019-12-03 15:39:23 +000057
58 android.PostDepsMutators(RegisterPostDepsMutators)
Colin Cross463a90e2015-06-17 14:20:06 -070059}
60
Paul Duffinf9b1da02019-12-18 19:51:55 +000061func RegisterJavaBuildComponents(ctx android.RegistrationContext) {
62 ctx.RegisterModuleType("java_defaults", DefaultsFactory)
63
64 ctx.RegisterModuleType("java_library", LibraryFactory)
65 ctx.RegisterModuleType("java_library_static", LibraryStaticFactory)
66 ctx.RegisterModuleType("java_library_host", LibraryHostFactory)
67 ctx.RegisterModuleType("java_binary", BinaryFactory)
68 ctx.RegisterModuleType("java_binary_host", BinaryHostFactory)
69 ctx.RegisterModuleType("java_test", TestFactory)
70 ctx.RegisterModuleType("java_test_helper_library", TestHelperLibraryFactory)
71 ctx.RegisterModuleType("java_test_host", TestHostFactory)
Paul Duffin1b82e6a2019-12-03 18:06:47 +000072 ctx.RegisterModuleType("java_test_import", JavaTestImportFactory)
Paul Duffinf9b1da02019-12-18 19:51:55 +000073 ctx.RegisterModuleType("java_import", ImportFactory)
74 ctx.RegisterModuleType("java_import_host", ImportFactoryHost)
75 ctx.RegisterModuleType("java_device_for_host", DeviceForHostFactory)
76 ctx.RegisterModuleType("java_host_for_device", HostForDeviceFactory)
77 ctx.RegisterModuleType("dex_import", DexImportFactory)
78
Martin Stjernholm6d415272020-01-31 17:10:36 +000079 ctx.FinalDepsMutators(func(ctx android.RegisterMutatorsContext) {
80 ctx.BottomUp("dexpreopt_tool_deps", dexpreoptToolDepsMutator).Parallel()
81 })
Martin Stjernholmd90676f2020-01-11 00:37:30 +000082
Paul Duffinf9b1da02019-12-18 19:51:55 +000083 ctx.RegisterSingletonType("logtags", LogtagsSingleton)
84 ctx.RegisterSingletonType("kythe_java_extract", kytheExtractJavaFactory)
85}
86
Ulya Trafimovichf3ff0102019-12-03 15:39:23 +000087func RegisterPostDepsMutators(ctx android.RegisterMutatorsContext) {
88 ctx.BottomUp("ordered_system_server_jars", systemServerJarsDepsMutator)
89}
90
91var (
92 dexpreoptedSystemServerJarsKey = android.NewOnceKey("dexpreoptedSystemServerJars")
93 dexpreoptedSystemServerJarsLock sync.Mutex
94)
95
96func DexpreoptedSystemServerJars(config android.Config) *[]string {
97 return config.Once(dexpreoptedSystemServerJarsKey, func() interface{} {
98 return &[]string{}
99 }).(*[]string)
100}
101
102// A PostDepsMutator pass that enforces total order on non-updatable system server jars. A total
103// order is neededed because such jars must be dexpreopted together (each jar on the list must have
104// all preceding jars in its class loader context). The total order must be compatible with the
105// partial order imposed by genuine dependencies between system server jars (which is not always
106// respected by the PRODUCT_SYSTEM_SERVER_JARS variable).
107//
108// An earlier mutator pass creates genuine dependencies, and this pass traverses the jars in that
109// order (which is partial and non-deterministic). This pass adds additional dependencies between
110// jars, making the order total and deterministic. It also constructs a global ordered list.
111func systemServerJarsDepsMutator(ctx android.BottomUpMutatorContext) {
Martin Stjernholm40f9f3c2020-01-20 18:12:23 +0000112 jars := dexpreopt.NonUpdatableSystemServerJars(ctx, dexpreopt.GetGlobalConfig(ctx))
Ulya Trafimovichf3ff0102019-12-03 15:39:23 +0000113 name := ctx.ModuleName()
114 if android.InList(name, jars) {
115 dexpreoptedSystemServerJarsLock.Lock()
116 defer dexpreoptedSystemServerJarsLock.Unlock()
117 jars := DexpreoptedSystemServerJars(ctx.Config())
118 for _, dep := range *jars {
119 ctx.AddDependency(ctx.Module(), dexpreopt.SystemServerDepTag, dep)
120 }
121 *jars = append(*jars, name)
122 }
123}
124
Jeongik Cha2cc570d2019-10-29 15:44:45 +0900125func (j *Module) checkSdkVersion(ctx android.ModuleContext) {
126 if j.SocSpecific() || j.DeviceSpecific() ||
127 (j.ProductSpecific() && ctx.Config().EnforceProductPartitionInterface()) {
128 if sc, ok := ctx.Module().(sdkContext); ok {
Jiyong Park6a927c42020-01-21 02:03:43 +0900129 if !sc.sdkVersion().specified() {
Jeongik Cha2cc570d2019-10-29 15:44:45 +0900130 ctx.PropertyErrorf("sdk_version",
131 "sdk_version must have a value when the module is located at vendor or product(only if PRODUCT_ENFORCE_PRODUCT_PARTITION_INTERFACE is set).")
132 }
133 }
134 }
135}
136
Jeongik Cha538c0d02019-07-11 15:54:27 +0900137func (j *Module) checkPlatformAPI(ctx android.ModuleContext) {
138 if sc, ok := ctx.Module().(sdkContext); ok {
139 usePlatformAPI := proptools.Bool(j.deviceProperties.Platform_apis)
Jiyong Park6a927c42020-01-21 02:03:43 +0900140 sdkVersionSpecified := sc.sdkVersion().specified()
141 if usePlatformAPI && sdkVersionSpecified {
142 ctx.PropertyErrorf("platform_apis", "platform_apis must be false when sdk_version is not empty.")
143 } else if !usePlatformAPI && !sdkVersionSpecified {
144 ctx.PropertyErrorf("platform_apis", "platform_apis must be true when sdk_version is empty.")
Jeongik Cha538c0d02019-07-11 15:54:27 +0900145 }
146
147 }
148}
149
Colin Cross2fe66872015-03-30 17:20:39 -0700150// TODO:
151// Autogenerated files:
Colin Cross2fe66872015-03-30 17:20:39 -0700152// Renderscript
153// Post-jar passes:
154// Proguard
Colin Cross2fe66872015-03-30 17:20:39 -0700155// Rmtypedefs
Colin Cross2fe66872015-03-30 17:20:39 -0700156// DroidDoc
157// Findbugs
158
Colin Cross89536d42017-07-07 14:35:50 -0700159type CompilerProperties struct {
Colin Cross7d5136f2015-05-11 13:39:40 -0700160 // list of source files used to compile the Java module. May be .java, .logtags, .proto,
161 // or .aidl files.
Colin Cross27b922f2019-03-04 22:35:41 -0800162 Srcs []string `android:"path,arch_variant"`
Dan Willemsen2ef08f42015-06-30 18:15:24 -0700163
164 // list of source files that should not be used to build the Java module.
165 // This is most useful in the arch/multilib variants to remove non-common files
Colin Cross27b922f2019-03-04 22:35:41 -0800166 Exclude_srcs []string `android:"path,arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700167
168 // list of directories containing Java resources
Colin Cross86a63ff2017-09-27 17:33:10 -0700169 Java_resource_dirs []string `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700170
Colin Cross86a63ff2017-09-27 17:33:10 -0700171 // list of directories that should be excluded from java_resource_dirs
172 Exclude_java_resource_dirs []string `android:"arch_variant"`
Dan Willemsen2ef08f42015-06-30 18:15:24 -0700173
Colin Cross0f37af02017-09-27 17:42:05 -0700174 // list of files to use as Java resources
Colin Cross27b922f2019-03-04 22:35:41 -0800175 Java_resources []string `android:"path,arch_variant"`
Colin Cross0f37af02017-09-27 17:42:05 -0700176
Colin Crosscedd4762018-09-13 11:26:19 -0700177 // list of files that should be excluded from java_resources and java_resource_dirs
Colin Cross27b922f2019-03-04 22:35:41 -0800178 Exclude_java_resources []string `android:"path,arch_variant"`
Colin Cross0f37af02017-09-27 17:42:05 -0700179
Colin Cross7d5136f2015-05-11 13:39:40 -0700180 // list of module-specific flags that will be used for javac compiles
181 Javacflags []string `android:"arch_variant"`
182
Zoran Jovanovic8736ce22018-08-21 17:10:29 +0200183 // list of module-specific flags that will be used for kotlinc compiles
184 Kotlincflags []string `android:"arch_variant"`
185
Colin Cross7d5136f2015-05-11 13:39:40 -0700186 // list of of java libraries that will be in the classpath
Colin Crosse8dc34a2017-07-19 11:22:16 -0700187 Libs []string `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700188
189 // list of java libraries that will be compiled into the resulting jar
Colin Crosse8dc34a2017-07-19 11:22:16 -0700190 Static_libs []string `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700191
192 // manifest file to be included in resulting jar
Colin Cross27b922f2019-03-04 22:35:41 -0800193 Manifest *string `android:"path"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700194
Colin Cross540eff82017-06-22 17:01:52 -0700195 // if not blank, run jarjar using the specified rules file
Colin Cross27b922f2019-03-04 22:35:41 -0800196 Jarjar_rules *string `android:"path,arch_variant"`
Colin Cross64162712017-08-08 13:17:59 -0700197
198 // If not blank, set the java version passed to javac as -source and -target
199 Java_version *string
Colin Cross2c429dc2017-08-31 16:45:16 -0700200
Colin Cross9ae1b922018-06-26 17:59:05 -0700201 // If set to true, allow this module to be dexed and installed on devices. Has no
202 // effect on host modules, which are always considered installable.
Colin Cross2c429dc2017-08-31 16:45:16 -0700203 Installable *bool
Colin Cross32f676a2017-09-06 13:41:06 -0700204
Colin Cross0f37af02017-09-27 17:42:05 -0700205 // If set to true, include sources used to compile the module in to the final jar
206 Include_srcs *bool
207
Vladimir Marko0975ee02019-04-02 10:29:55 +0100208 // If not empty, classes are restricted to the specified packages and their sub-packages.
209 // This restriction is checked after applying jarjar rules and including static libs.
210 Permitted_packages []string
211
Colin Crossbe9cdb82019-01-21 21:37:16 -0800212 // List of modules to use as annotation processors
213 Plugins []string
Colin Cross1369cdb2017-09-29 17:58:17 -0700214
Artur Satayev9cf46692019-11-26 18:08:34 +0000215 // List of modules to export to libraries that directly depend on this library as annotation processors
216 Exported_plugins []string
217
Nan Zhang61eaedb2017-11-02 13:28:15 -0700218 // The number of Java source entries each Javac instance can process
219 Javac_shard_size *int64
220
Nan Zhang5f8cb422018-02-06 10:34:32 -0800221 // Add host jdk tools.jar to bootclasspath
222 Use_tools_jar *bool
223
Colin Cross1369cdb2017-09-29 17:58:17 -0700224 Openjdk9 struct {
Colin Cross6cef4812019-10-17 14:23:50 -0700225 // List of source files that should only be used when passing -source 1.9 or higher
Colin Cross27b922f2019-03-04 22:35:41 -0800226 Srcs []string `android:"path"`
Colin Cross1369cdb2017-09-29 17:58:17 -0700227
Colin Cross6cef4812019-10-17 14:23:50 -0700228 // List of javac flags that should only be used when passing -source 1.9 or higher
Colin Cross1369cdb2017-09-29 17:58:17 -0700229 Javacflags []string
230 }
Colin Crosscb933592017-11-22 13:49:43 -0800231
Colin Cross81440082018-08-15 20:21:55 -0700232 // When compiling language level 9+ .java code in packages that are part of
233 // a system module, patch_module names the module that your sources and
234 // dependencies should be patched into. The Android runtime currently
235 // doesn't implement the JEP 261 module system so this option is only
236 // supported at compile time. It should only be needed to compile tests in
237 // packages that exist in libcore and which are inconvenient to move
238 // elsewhere.
Tobias Thiererdda713d2018-09-19 16:16:19 +0100239 Patch_module *string `android:"arch_variant"`
Colin Cross81440082018-08-15 20:21:55 -0700240
Colin Crosscb933592017-11-22 13:49:43 -0800241 Jacoco struct {
242 // List of classes to include for instrumentation with jacoco to collect coverage
243 // information at runtime when building with coverage enabled. If unset defaults to all
244 // classes.
245 // Supports '*' as the last character of an entry in the list as a wildcard match.
246 // If preceded by '.' it matches all classes in the package and subpackages, otherwise
247 // it matches classes in the package that have the class name as a prefix.
248 Include_filter []string
249
250 // List of classes to exclude from instrumentation with jacoco to collect coverage
251 // information at runtime when building with coverage enabled. Overrides classes selected
252 // by the include_filter property.
253 // Supports '*' as the last character of an entry in the list as a wildcard match.
254 // If preceded by '.' it matches all classes in the package and subpackages, otherwise
255 // it matches classes in the package that have the class name as a prefix.
256 Exclude_filter []string
257 }
258
Andreas Gampef3e5b552018-01-22 21:27:21 -0800259 Errorprone struct {
260 // List of javac flags that should only be used when running errorprone.
261 Javacflags []string
262 }
263
Colin Cross0f2ee152017-12-14 15:22:43 -0800264 Proto struct {
265 // List of extra options that will be passed to the proto generator.
266 Output_params []string
267 }
268
Colin Crosscb933592017-11-22 13:49:43 -0800269 Instrument bool `blueprint:"mutated"`
Alex Light7f004a72019-02-21 13:27:37 -0800270
271 // List of files to include in the META-INF/services folder of the resulting jar.
Colin Cross27b922f2019-03-04 22:35:41 -0800272 Services []string `android:"path,arch_variant"`
Colin Cross540eff82017-06-22 17:01:52 -0700273}
274
Colin Cross89536d42017-07-07 14:35:50 -0700275type CompilerDeviceProperties struct {
Colin Cross540eff82017-06-22 17:01:52 -0700276 // list of module-specific flags that will be used for dex compiles
277 Dxflags []string `android:"arch_variant"`
278
Jeongik Cha538c0d02019-07-11 15:54:27 +0900279 // if not blank, set to the version of the sdk to compile against.
280 // Defaults to compiling against the current platform.
Nan Zhangea568a42017-11-08 21:20:04 -0800281 Sdk_version *string
Colin Cross7d5136f2015-05-11 13:39:40 -0700282
Colin Cross83bb3162018-06-25 15:48:06 -0700283 // if not blank, set the minimum version of the sdk that the compiled artifacts will run against.
284 // Defaults to sdk_version if not set.
285 Min_sdk_version *string
286
Dan Willemsen419290a2018-10-31 15:28:47 -0700287 // if not blank, set the targetSdkVersion in the AndroidManifest.xml.
288 // Defaults to sdk_version if not set.
289 Target_sdk_version *string
290
Jeongik Cha356dac42019-08-19 14:09:52 +0900291 // Whether to compile against the platform APIs instead of an SDK.
292 // If true, then sdk_version must be empty. The value of this field
293 // is ignored when module's type isn't android_app.
Colin Cross6af2e492018-05-22 11:12:33 -0700294 Platform_apis *bool
295
Colin Crossebe1a512017-11-14 13:12:14 -0800296 Aidl struct {
297 // Top level directories to pass to aidl tool
298 Include_dirs []string
Colin Cross7d5136f2015-05-11 13:39:40 -0700299
Colin Crossebe1a512017-11-14 13:12:14 -0800300 // Directories rooted at the Android.bp file to pass to aidl tool
301 Local_include_dirs []string
302
303 // directories that should be added as include directories for any aidl sources of modules
304 // that depend on this module, as well as to aidl for this module.
305 Export_include_dirs []string
Martijn Coeneneab15642018-03-09 09:29:59 +0100306
307 // whether to generate traces (for systrace) for this interface
308 Generate_traces *bool
Olivier Gaillard0a4cfbc2018-07-16 23:37:03 +0100309
310 // whether to generate Binder#GetTransaction name method.
311 Generate_get_transaction_name *bool
Colin Crossebe1a512017-11-14 13:12:14 -0800312 }
Colin Cross92430102017-10-09 14:59:32 -0700313
314 // If true, export a copy of the module as a -hostdex module for host testing.
315 Hostdex *bool
Colin Cross1369cdb2017-09-29 17:58:17 -0700316
Colin Cross7f87f4f2019-04-24 13:41:45 -0700317 Target struct {
318 Hostdex struct {
319 // Additional required dependencies to add to -hostdex modules.
320 Required []string
321 }
322 }
323
David Brazdil17ef5632018-06-27 10:27:45 +0100324 // If set to true, compile dex regardless of installable. Defaults to false.
325 Compile_dex *bool
326
Colin Cross66dbc0b2017-12-28 12:23:20 -0800327 Optimize struct {
Colin Crossae5caf52018-05-22 11:11:52 -0700328 // If false, disable all optimization. Defaults to true for android_app and android_test
329 // modules, false for java_library and java_test modules.
Colin Cross66dbc0b2017-12-28 12:23:20 -0800330 Enabled *bool
Sasha Smundak2057f822019-04-16 17:16:58 -0700331 // True if the module containing this has it set by default.
332 EnabledByDefault bool `blueprint:"mutated"`
Colin Cross66dbc0b2017-12-28 12:23:20 -0800333
334 // If true, optimize for size by removing unused code. Defaults to true for apps,
335 // false for libraries and tests.
336 Shrink *bool
337
338 // If true, optimize bytecode. Defaults to false.
339 Optimize *bool
340
341 // If true, obfuscate bytecode. Defaults to false.
342 Obfuscate *bool
343
344 // If true, do not use the flag files generated by aapt that automatically keep
345 // classes referenced by the app manifest. Defaults to false.
346 No_aapt_flags *bool
347
348 // Flags to pass to proguard.
349 Proguard_flags []string
350
351 // Specifies the locations of files containing proguard flags.
Colin Cross27b922f2019-03-04 22:35:41 -0800352 Proguard_flags_files []string `android:"path"`
Colin Cross66dbc0b2017-12-28 12:23:20 -0800353 }
354
Paul Duffine25c6442019-10-11 13:50:28 +0100355 // When targeting 1.9 and above, override the modules to use with --system,
356 // otherwise provides defaults libraries to add to the bootclasspath.
Colin Cross1369cdb2017-09-29 17:58:17 -0700357 System_modules *string
Colin Cross5a0dcd52018-10-05 14:20:06 -0700358
Jiyong Park4c4c0242019-10-21 14:53:15 +0900359 // set the name of the output
360 Stem *string
361
Colin Cross5a0dcd52018-10-05 14:20:06 -0700362 UncompressDex bool `blueprint:"mutated"`
Colin Cross43f08db2018-11-12 10:13:39 -0800363 IsSDKLibrary bool `blueprint:"mutated"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700364}
365
Sasha Smundak2057f822019-04-16 17:16:58 -0700366func (me *CompilerDeviceProperties) EffectiveOptimizeEnabled() bool {
367 return BoolDefault(me.Optimize.Enabled, me.Optimize.EnabledByDefault)
368}
369
Colin Cross46c9b8b2017-06-22 16:51:17 -0700370// Module contains the properties and members used by all java module types
371type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700372 android.ModuleBase
Colin Cross89536d42017-07-07 14:35:50 -0700373 android.DefaultableModuleBase
Jiyong Park7f7766d2019-07-25 22:02:35 +0900374 android.ApexModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +0900375 android.SdkBase
Colin Cross2fe66872015-03-30 17:20:39 -0700376
Colin Cross89536d42017-07-07 14:35:50 -0700377 properties CompilerProperties
Colin Cross6af17aa2017-09-20 12:59:05 -0700378 protoProperties android.ProtoProperties
Colin Cross89536d42017-07-07 14:35:50 -0700379 deviceProperties CompilerDeviceProperties
Colin Cross2fe66872015-03-30 17:20:39 -0700380
Colin Cross331a1212018-08-15 20:40:52 -0700381 // jar file containing header classes including static library dependencies, suitable for
382 // inserting into the bootclasspath/classpath of another compile
Nan Zhanged19fc32017-10-19 13:06:22 -0700383 headerJarFile android.Path
384
Colin Cross331a1212018-08-15 20:40:52 -0700385 // jar file containing implementation classes including static library dependencies but no
386 // resources
Nan Zhanged19fc32017-10-19 13:06:22 -0700387 implementationJarFile android.Path
Colin Cross2fe66872015-03-30 17:20:39 -0700388
Colin Cross331a1212018-08-15 20:40:52 -0700389 // jar file containing only resources including from static library dependencies
390 resourceJar android.Path
391
Colin Cross0c4ce212019-05-03 15:28:19 -0700392 // args and dependencies to package source files into a srcjar
393 srcJarArgs []string
394 srcJarDeps android.Paths
395
Colin Cross331a1212018-08-15 20:40:52 -0700396 // jar file containing implementation classes and resources including static library
397 // dependencies
398 implementationAndResourcesJar android.Path
399
400 // output file containing classes.dex and resources
Colin Cross6ade34f2017-09-15 13:00:47 -0700401 dexJarFile android.Path
402
Colin Cross43f08db2018-11-12 10:13:39 -0800403 // output file that contains classes.dex if it should be in the output file
404 maybeStrippedDexJarFile android.Path
405
Colin Crosscb933592017-11-22 13:49:43 -0800406 // output file containing uninstrumented classes that will be instrumented by jacoco
407 jacocoReportClassesFile android.Path
408
Colin Cross66dbc0b2017-12-28 12:23:20 -0800409 // output file containing mapping of obfuscated names
410 proguardDictionary android.Path
411
Colin Cross331a1212018-08-15 20:40:52 -0700412 // output file of the module, which may be a classes jar or a dex jar
Colin Crosse560c4a2019-03-19 16:03:11 -0700413 outputFile android.Path
414 extraOutputFiles android.Paths
Colin Crossb7a63242015-04-16 14:09:14 -0700415
Colin Cross635c3b02016-05-18 15:37:25 -0700416 exportAidlIncludeDirs android.Paths
Colin Crossc0b06f12015-04-08 13:03:43 -0700417
Colin Cross635c3b02016-05-18 15:37:25 -0700418 logtagsSrcs android.Paths
Colin Crossf05fe972015-04-10 17:45:20 -0700419
Colin Cross2fe66872015-03-30 17:20:39 -0700420 // installed file for binary dependency
Colin Cross635c3b02016-05-18 15:37:25 -0700421 installFile android.Path
Colin Cross5ab4e6d2017-11-22 16:20:45 -0800422
423 // list of .java files and srcjars that was passed to javac
424 compiledJavaSrcs android.Paths
425 compiledSrcJars android.Paths
Colin Cross66dbc0b2017-12-28 12:23:20 -0800426
427 // list of extra progurad flag files
428 extraProguardFlagFiles android.Paths
Jiyong Park1be96912018-05-28 18:02:19 +0900429
Colin Cross094054a2018-10-17 15:10:48 -0700430 // manifest file to use instead of properties.Manifest
431 overrideManifest android.OptionalPath
432
Artur Satayev9cf46692019-11-26 18:08:34 +0000433 // list of SDK lib names that this java module is exporting
Jiyong Park1be96912018-05-28 18:02:19 +0900434 exportedSdkLibs []string
Brandon Lee5d45c6f2018-08-15 15:35:38 -0700435
Artur Satayev9cf46692019-11-26 18:08:34 +0000436 // list of plugins that this java module is exporting
437 exportedPluginJars android.Paths
438
439 // list of plugins that this java module is exporting
440 exportedPluginClasses []string
441
442 // list of source files, collected from srcFiles with unique java and all kt files,
patricktu242faad2019-09-24 15:41:30 +0800443 // will be used by android.IDEInfo struct
Brandon Lee5d45c6f2018-08-15 15:35:38 -0700444 expandIDEInfoCompiledSrcs []string
Colin Cross43f08db2018-11-12 10:13:39 -0800445
Steven Morelandc4efd9c2019-01-18 11:51:25 -0800446 // expanded Jarjar_rules
447 expandJarjarRules android.Path
448
Vladimir Marko0975ee02019-04-02 10:29:55 +0100449 // list of additional targets for checkbuild
450 additionalCheckedModules android.Paths
451
Colin Cross988708c2019-05-06 14:04:11 -0700452 // Extra files generated by the module type to be added as java resources.
453 extraResources android.Paths
454
Colin Crossf24a22a2019-01-31 14:12:44 -0800455 hiddenAPI
Colin Cross43f08db2018-11-12 10:13:39 -0800456 dexpreopter
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800457
458 // list of the xref extraction files
459 kytheFiles android.Paths
Colin Cross2fe66872015-03-30 17:20:39 -0700460}
461
Colin Cross41955e82019-05-29 14:40:35 -0700462func (j *Module) OutputFiles(tag string) (android.Paths, error) {
463 switch tag {
464 case "":
465 return append(android.Paths{j.outputFile}, j.extraOutputFiles...), nil
Colin Cross375ca3c2019-05-29 14:40:58 -0700466 case ".jar":
467 return android.Paths{j.implementationAndResourcesJar}, nil
Colin Cross2d975b12019-07-29 16:47:42 -0700468 case ".proguard_map":
469 return android.Paths{j.proguardDictionary}, nil
Colin Cross41955e82019-05-29 14:40:35 -0700470 default:
471 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
472 }
Colin Cross54250902017-12-05 09:28:08 -0800473}
474
Colin Cross41955e82019-05-29 14:40:35 -0700475var _ android.OutputFileProducer = (*Module)(nil)
Colin Cross54250902017-12-05 09:28:08 -0800476
Colin Crossf506d872017-07-19 15:53:04 -0700477type Dependency interface {
Nan Zhanged19fc32017-10-19 13:06:22 -0700478 HeaderJars() android.Paths
479 ImplementationJars() android.Paths
Colin Cross331a1212018-08-15 20:40:52 -0700480 ResourceJars() android.Paths
481 ImplementationAndResourcesJars() android.Paths
Colin Crossf24a22a2019-01-31 14:12:44 -0800482 DexJar() android.Path
Colin Cross635c3b02016-05-18 15:37:25 -0700483 AidlIncludeDirs() android.Paths
Jiyong Park1be96912018-05-28 18:02:19 +0900484 ExportedSdkLibs() []string
Artur Satayev9cf46692019-11-26 18:08:34 +0000485 ExportedPlugins() (android.Paths, []string)
Colin Cross0c4ce212019-05-03 15:28:19 -0700486 SrcJarArgs() ([]string, android.Paths)
Colin Crosse323f3c2019-09-17 15:34:09 -0700487 BaseModuleName() string
Jiyong Park618922e2020-01-08 13:35:43 +0900488 JacocoReportClassesFile() android.Path
Colin Cross2fe66872015-03-30 17:20:39 -0700489}
490
Jiyong Parkc678ad32018-04-10 13:07:10 +0900491type SdkLibraryDependency interface {
Jiyong Park6a927c42020-01-21 02:03:43 +0900492 SdkHeaderJars(ctx android.BaseModuleContext, sdkVersion sdkSpec) android.Paths
493 SdkImplementationJars(ctx android.BaseModuleContext, sdkVersion sdkSpec) android.Paths
Jiyong Parkc678ad32018-04-10 13:07:10 +0900494}
495
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800496type xref interface {
497 XrefJavaFiles() android.Paths
498}
499
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800500func (j *Module) XrefJavaFiles() android.Paths {
501 return j.kytheFiles
502}
503
Colin Cross89536d42017-07-07 14:35:50 -0700504func InitJavaModule(module android.DefaultableModule, hod android.HostOrDeviceSupported) {
505 android.InitAndroidArchModule(module, hod, android.MultilibCommon)
506 android.InitDefaultableModule(module)
507}
508
Colin Crossbe1da472017-07-07 15:59:46 -0700509type dependencyTag struct {
510 blueprint.BaseDependencyTag
511 name string
Colin Cross2fe66872015-03-30 17:20:39 -0700512}
513
Colin Crossa4f08812018-10-02 22:03:40 -0700514type jniDependencyTag struct {
515 blueprint.BaseDependencyTag
Colin Crossa4f08812018-10-02 22:03:40 -0700516}
517
Jiyong Park8be103b2019-11-08 15:53:48 +0900518func IsJniDepTag(depTag blueprint.DependencyTag) bool {
519 _, ok := depTag.(*jniDependencyTag)
520 return ok
521}
522
Colin Crossbe1da472017-07-07 15:59:46 -0700523var (
Colin Cross4b964c02018-10-15 16:18:06 -0700524 staticLibTag = dependencyTag{name: "staticlib"}
525 libTag = dependencyTag{name: "javalib"}
Colin Cross6cef4812019-10-17 14:23:50 -0700526 java9LibTag = dependencyTag{name: "java9lib"}
Colin Crossbe9cdb82019-01-21 21:37:16 -0800527 pluginTag = dependencyTag{name: "plugin"}
Artur Satayev9cf46692019-11-26 18:08:34 +0000528 exportedPluginTag = dependencyTag{name: "exported-plugin"}
Colin Cross4b964c02018-10-15 16:18:06 -0700529 bootClasspathTag = dependencyTag{name: "bootclasspath"}
530 systemModulesTag = dependencyTag{name: "system modules"}
531 frameworkResTag = dependencyTag{name: "framework-res"}
532 frameworkApkTag = dependencyTag{name: "framework-apk"}
533 kotlinStdlibTag = dependencyTag{name: "kotlin-stdlib"}
Colin Crossafbb1732019-01-17 15:42:52 -0800534 kotlinAnnotationsTag = dependencyTag{name: "kotlin-annotations"}
Colin Cross4b964c02018-10-15 16:18:06 -0700535 proguardRaiseTag = dependencyTag{name: "proguard-raise"}
536 certificateTag = dependencyTag{name: "certificate"}
537 instrumentationForTag = dependencyTag{name: "instrumentation_for"}
Colin Cross50ddcc42019-05-16 12:28:22 -0700538 usesLibTag = dependencyTag{name: "uses-library"}
Colin Crossbe1da472017-07-07 15:59:46 -0700539)
Colin Cross2fe66872015-03-30 17:20:39 -0700540
Jiyong Park83dc74b2020-01-14 18:38:44 +0900541func IsLibDepTag(depTag blueprint.DependencyTag) bool {
542 return depTag == libTag
543}
544
545func IsStaticLibDepTag(depTag blueprint.DependencyTag) bool {
546 return depTag == staticLibTag
547}
548
Colin Crossfc3674a2017-09-18 17:41:52 -0700549type sdkDep struct {
Colin Cross47ff2522017-10-02 14:22:08 -0700550 useModule, useFiles, useDefaultLibs, invalidVersion bool
551
Colin Cross6cef4812019-10-17 14:23:50 -0700552 // The modules that will be added to the bootclasspath when targeting 1.8 or lower
553 bootclasspath []string
Paul Duffine25c6442019-10-11 13:50:28 +0100554
555 // The default system modules to use. Will be an empty string if no system
556 // modules are to be used.
Colin Cross1369cdb2017-09-29 17:58:17 -0700557 systemModules string
558
Colin Cross6cef4812019-10-17 14:23:50 -0700559 // The modules that will be added ot the classpath when targeting 1.9 or higher
560 java9Classpath []string
561
Colin Crossa97c5d32018-03-28 14:58:31 -0700562 frameworkResModule string
563
Colin Cross86a60ae2018-05-29 14:44:55 -0700564 jars android.Paths
Colin Cross3047fa22019-04-18 10:56:44 -0700565 aidl android.OptionalPath
Paul Duffin250e6192019-06-07 10:44:37 +0100566
567 noStandardLibs, noFrameworksLibs bool
568}
569
570func (s sdkDep) hasStandardLibs() bool {
571 return !s.noStandardLibs
572}
573
574func (s sdkDep) hasFrameworkLibs() bool {
575 return !s.noStandardLibs && !s.noFrameworksLibs
Colin Cross1369cdb2017-09-29 17:58:17 -0700576}
577
Colin Crossa4f08812018-10-02 22:03:40 -0700578type jniLib struct {
579 name string
580 path android.Path
581 target android.Target
582}
583
Colin Cross0ea8ba82019-06-06 14:33:29 -0700584func (j *Module) shouldInstrument(ctx android.BaseModuleContext) bool {
Colin Cross3144dfc2018-01-03 15:06:47 -0800585 return j.properties.Instrument && ctx.Config().IsEnvTrue("EMMA_INSTRUMENT")
586}
587
Colin Cross0ea8ba82019-06-06 14:33:29 -0700588func (j *Module) shouldInstrumentStatic(ctx android.BaseModuleContext) bool {
Colin Cross3144dfc2018-01-03 15:06:47 -0800589 return j.shouldInstrument(ctx) &&
590 (ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_STATIC") ||
591 ctx.Config().UnbundledBuild())
592}
593
Jiyong Park6a927c42020-01-21 02:03:43 +0900594func (j *Module) sdkVersion() sdkSpec {
595 return sdkSpecFrom(String(j.deviceProperties.Sdk_version))
Colin Cross83bb3162018-06-25 15:48:06 -0700596}
597
Paul Duffine25c6442019-10-11 13:50:28 +0100598func (j *Module) systemModules() string {
599 return proptools.String(j.deviceProperties.System_modules)
600}
601
Jiyong Park6a927c42020-01-21 02:03:43 +0900602func (j *Module) minSdkVersion() sdkSpec {
Colin Cross83bb3162018-06-25 15:48:06 -0700603 if j.deviceProperties.Min_sdk_version != nil {
Jiyong Park6a927c42020-01-21 02:03:43 +0900604 return sdkSpecFrom(*j.deviceProperties.Min_sdk_version)
Colin Cross83bb3162018-06-25 15:48:06 -0700605 }
606 return j.sdkVersion()
607}
608
Jiyong Park6a927c42020-01-21 02:03:43 +0900609func (j *Module) targetSdkVersion() sdkSpec {
Dan Willemsen419290a2018-10-31 15:28:47 -0700610 if j.deviceProperties.Target_sdk_version != nil {
Jiyong Park6a927c42020-01-21 02:03:43 +0900611 return sdkSpecFrom(*j.deviceProperties.Target_sdk_version)
Dan Willemsen419290a2018-10-31 15:28:47 -0700612 }
613 return j.sdkVersion()
614}
615
Jiyong Parkb02bb402019-12-03 00:43:57 +0900616func (j *Module) AvailableFor(what string) bool {
617 if what == android.AvailableToPlatform && Bool(j.deviceProperties.Hostdex) {
618 // Exception: for hostdex: true libraries, the platform variant is created
619 // even if it's not marked as available to platform. In that case, the platform
620 // variant is used only for the hostdex and not installed to the device.
621 return true
622 }
623 return j.ApexModuleBase.AvailableFor(what)
624}
625
Colin Crossbe1da472017-07-07 15:59:46 -0700626func (j *Module) deps(ctx android.BottomUpMutatorContext) {
Colin Cross1369cdb2017-09-29 17:58:17 -0700627 if ctx.Device() {
Paul Duffin250e6192019-06-07 10:44:37 +0100628 sdkDep := decodeSdkDep(ctx, sdkContext(j))
Colin Cross6d8d8c62019-10-28 15:10:03 -0700629 if sdkDep.useDefaultLibs {
630 ctx.AddVariationDependencies(nil, bootClasspathTag, config.DefaultBootclasspathLibraries...)
631 ctx.AddVariationDependencies(nil, systemModulesTag, config.DefaultSystemModules)
632 if sdkDep.hasFrameworkLibs() {
633 ctx.AddVariationDependencies(nil, libTag, config.DefaultLibraries...)
Colin Crossbe1da472017-07-07 15:59:46 -0700634 }
Colin Cross6d8d8c62019-10-28 15:10:03 -0700635 } else if sdkDep.useModule {
Colin Cross6cef4812019-10-17 14:23:50 -0700636 ctx.AddVariationDependencies(nil, bootClasspathTag, sdkDep.bootclasspath...)
Paul Duffine25c6442019-10-11 13:50:28 +0100637 ctx.AddVariationDependencies(nil, systemModulesTag, sdkDep.systemModules)
Colin Cross6cef4812019-10-17 14:23:50 -0700638 ctx.AddVariationDependencies(nil, java9LibTag, sdkDep.java9Classpath...)
Colin Cross6d8d8c62019-10-28 15:10:03 -0700639 if j.deviceProperties.EffectiveOptimizeEnabled() && sdkDep.hasStandardLibs() {
640 ctx.AddVariationDependencies(nil, proguardRaiseTag, config.DefaultBootclasspathLibraries...)
641 ctx.AddVariationDependencies(nil, proguardRaiseTag, config.DefaultLibraries...)
642 }
Colin Cross2fe66872015-03-30 17:20:39 -0700643 }
Colin Cross6d8d8c62019-10-28 15:10:03 -0700644
Nan Zhangb2b33de2018-02-23 11:18:47 -0800645 if ctx.ModuleName() == "android_stubs_current" ||
646 ctx.ModuleName() == "android_system_stubs_current" ||
Nan Zhang863f05b2018-08-07 13:41:10 -0700647 ctx.ModuleName() == "android_test_stubs_current" {
Colin Cross42d48b72018-08-29 14:10:52 -0700648 ctx.AddVariationDependencies(nil, frameworkApkTag, "framework-res")
Nan Zhangb2b33de2018-02-23 11:18:47 -0800649 }
Colin Cross2fe66872015-03-30 17:20:39 -0700650 }
Colin Cross1369cdb2017-09-29 17:58:17 -0700651
Inseob Kimac1e9862019-12-09 18:15:47 +0900652 syspropPublicStubs := syspropPublicStubs(ctx.Config())
653
654 // rewriteSyspropLibs validates if a java module can link against platform's sysprop_library,
655 // and redirects dependency to public stub depending on the link type.
656 rewriteSyspropLibs := func(libs []string, prop string) []string {
657 // make a copy
658 ret := android.CopyOf(libs)
659
660 for idx, lib := range libs {
661 stub, ok := syspropPublicStubs[lib]
662
663 if !ok {
664 continue
665 }
666
667 linkType, _ := j.getLinkType(ctx.ModuleName())
Inseob Kimc5239512020-01-14 15:36:21 +0900668 // only platform modules can use internal props
669 if linkType != javaPlatform {
Inseob Kimac1e9862019-12-09 18:15:47 +0900670 ret[idx] = stub
Inseob Kimac1e9862019-12-09 18:15:47 +0900671 }
672 }
673
674 return ret
675 }
676
677 ctx.AddVariationDependencies(nil, libTag, rewriteSyspropLibs(j.properties.Libs, "libs")...)
678 ctx.AddVariationDependencies(nil, staticLibTag, rewriteSyspropLibs(j.properties.Static_libs, "static_libs")...)
Colin Crossa4f08812018-10-02 22:03:40 -0700679
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700680 ctx.AddFarVariationDependencies(ctx.Config().BuildOSCommonTarget.Variations(), pluginTag, j.properties.Plugins...)
Artur Satayev9cf46692019-11-26 18:08:34 +0000681 ctx.AddFarVariationDependencies(ctx.Config().BuildOSCommonTarget.Variations(), exportedPluginTag, j.properties.Exported_plugins...)
Colin Crossbe9cdb82019-01-21 21:37:16 -0800682
Colin Crossfe17f6f2019-03-28 19:30:56 -0700683 android.ProtoDeps(ctx, &j.protoProperties)
Colin Cross6af17aa2017-09-20 12:59:05 -0700684 if j.hasSrcExt(".proto") {
685 protoDeps(ctx, &j.protoProperties)
686 }
Colin Cross93e85952017-08-15 13:34:18 -0700687
688 if j.hasSrcExt(".kt") {
689 // TODO(ccross): move this to a mutator pass that can tell if generated sources contain
690 // Kotlin files
Colin Cross0b03d972019-05-13 11:06:25 -0700691 ctx.AddVariationDependencies(nil, kotlinStdlibTag,
692 "kotlin-stdlib", "kotlin-stdlib-jdk7", "kotlin-stdlib-jdk8")
Colin Cross7788c122019-01-23 16:14:02 -0800693 if len(j.properties.Plugins) > 0 {
Colin Crossafbb1732019-01-17 15:42:52 -0800694 ctx.AddVariationDependencies(nil, kotlinAnnotationsTag, "kotlin-annotations")
695 }
Colin Cross93e85952017-08-15 13:34:18 -0700696 }
Colin Cross3144dfc2018-01-03 15:06:47 -0800697
Ulya Trafimovich38dfa0f2020-01-07 16:37:02 +0000698 // Framework libraries need special handling in static coverage builds: they should not have
699 // static dependency on jacoco, otherwise there would be multiple conflicting definitions of
700 // the same jacoco classes coming from different bootclasspath jars.
701 if inList(ctx.ModuleName(), config.InstrumentFrameworkModules) {
702 if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
703 j.properties.Instrument = true
704 }
705 } else if j.shouldInstrumentStatic(ctx) {
Colin Cross42d48b72018-08-29 14:10:52 -0700706 ctx.AddVariationDependencies(nil, staticLibTag, "jacocoagent")
Colin Cross3144dfc2018-01-03 15:06:47 -0800707 }
Ulya Trafimovichf3ff0102019-12-03 15:39:23 +0000708
709 // services depend on com.android.location.provider, but dependency in not registered in a Blueprint file
710 if ctx.ModuleName() == "services" {
711 ctx.AddDependency(ctx.Module(), dexpreopt.SystemServerForcedDepTag, "com.android.location.provider")
712 }
Colin Cross6af17aa2017-09-20 12:59:05 -0700713}
714
715func hasSrcExt(srcs []string, ext string) bool {
716 for _, src := range srcs {
717 if filepath.Ext(src) == ext {
718 return true
719 }
720 }
721
722 return false
723}
724
725func (j *Module) hasSrcExt(ext string) bool {
726 return hasSrcExt(j.properties.Srcs, ext)
Colin Cross2fe66872015-03-30 17:20:39 -0700727}
728
Colin Cross46c9b8b2017-06-22 16:51:17 -0700729func (j *Module) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.OptionalPath,
Colin Cross3047fa22019-04-18 10:56:44 -0700730 aidlIncludeDirs android.Paths) (string, android.Paths) {
Colin Crossc0b06f12015-04-08 13:03:43 -0700731
Colin Crossebe1a512017-11-14 13:12:14 -0800732 aidlIncludes := android.PathsForModuleSrc(ctx, j.deviceProperties.Aidl.Local_include_dirs)
733 aidlIncludes = append(aidlIncludes,
734 android.PathsForModuleSrc(ctx, j.deviceProperties.Aidl.Export_include_dirs)...)
735 aidlIncludes = append(aidlIncludes,
736 android.PathsForSource(ctx, j.deviceProperties.Aidl.Include_dirs)...)
Colin Crossc0b06f12015-04-08 13:03:43 -0700737
Colin Cross3047fa22019-04-18 10:56:44 -0700738 var flags []string
739 var deps android.Paths
Steven Moreland667f6882018-07-26 12:55:08 -0700740
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700741 if aidlPreprocess.Valid() {
742 flags = append(flags, "-p"+aidlPreprocess.String())
Colin Cross3047fa22019-04-18 10:56:44 -0700743 deps = append(deps, aidlPreprocess.Path())
744 } else if len(aidlIncludeDirs) > 0 {
Colin Cross635c3b02016-05-18 15:37:25 -0700745 flags = append(flags, android.JoinWithPrefix(aidlIncludeDirs.Strings(), "-I"))
Colin Crossc0b06f12015-04-08 13:03:43 -0700746 }
747
Colin Cross3047fa22019-04-18 10:56:44 -0700748 if len(j.exportAidlIncludeDirs) > 0 {
749 flags = append(flags, android.JoinWithPrefix(j.exportAidlIncludeDirs.Strings(), "-I"))
750 }
751
752 if len(aidlIncludes) > 0 {
753 flags = append(flags, android.JoinWithPrefix(aidlIncludes.Strings(), "-I"))
754 }
755
Colin Cross635c3b02016-05-18 15:37:25 -0700756 flags = append(flags, "-I"+android.PathForModuleSrc(ctx).String())
Colin Cross32f38982018-02-22 11:47:25 -0800757 if src := android.ExistentPathForSource(ctx, ctx.ModuleDir(), "src"); src.Valid() {
Colin Crossd48633a2017-07-13 14:41:17 -0700758 flags = append(flags, "-I"+src.String())
759 }
Colin Crossc0b06f12015-04-08 13:03:43 -0700760
Martijn Coeneneab15642018-03-09 09:29:59 +0100761 if Bool(j.deviceProperties.Aidl.Generate_traces) {
762 flags = append(flags, "-t")
763 }
764
Olivier Gaillard0a4cfbc2018-07-16 23:37:03 +0100765 if Bool(j.deviceProperties.Aidl.Generate_get_transaction_name) {
766 flags = append(flags, "--transaction_names")
767 }
768
Colin Cross3047fa22019-04-18 10:56:44 -0700769 return strings.Join(flags, " "), deps
Colin Crossc0b06f12015-04-08 13:03:43 -0700770}
771
Colin Cross32f676a2017-09-06 13:41:06 -0700772type deps struct {
Nan Zhang581fd212018-01-10 16:06:12 -0800773 classpath classpath
Colin Cross6cef4812019-10-17 14:23:50 -0700774 java9Classpath classpath
Nan Zhang581fd212018-01-10 16:06:12 -0800775 bootClasspath classpath
Colin Cross6a77c982018-06-19 22:43:34 -0700776 processorPath classpath
Colin Crossbe9cdb82019-01-21 21:37:16 -0800777 processorClasses []string
Colin Cross6ade34f2017-09-15 13:00:47 -0700778 staticJars android.Paths
Nan Zhanged19fc32017-10-19 13:06:22 -0700779 staticHeaderJars android.Paths
Colin Cross331a1212018-08-15 20:40:52 -0700780 staticResourceJars android.Paths
Colin Cross6ade34f2017-09-15 13:00:47 -0700781 aidlIncludeDirs android.Paths
Nan Zhangb2b33de2018-02-23 11:18:47 -0800782 srcs android.Paths
Colin Cross59149b62017-10-16 18:07:29 -0700783 srcJars android.Paths
Colin Crossb77043e2019-07-16 13:57:13 -0700784 systemModules *systemModules
Colin Cross6ade34f2017-09-15 13:00:47 -0700785 aidlPreprocess android.OptionalPath
Colin Cross93e85952017-08-15 13:34:18 -0700786 kotlinStdlib android.Paths
Colin Crossafbb1732019-01-17 15:42:52 -0800787 kotlinAnnotations android.Paths
Colin Crossbe9cdb82019-01-21 21:37:16 -0800788
789 disableTurbine bool
Colin Cross32f676a2017-09-06 13:41:06 -0700790}
Colin Cross2fe66872015-03-30 17:20:39 -0700791
Colin Cross54250902017-12-05 09:28:08 -0800792func checkProducesJars(ctx android.ModuleContext, dep android.SourceFileProducer) {
793 for _, f := range dep.Srcs() {
794 if f.Ext() != ".jar" {
795 ctx.ModuleErrorf("genrule %q must generate files ending with .jar to be used as a libs or static_libs dependency",
796 ctx.OtherModuleName(dep.(blueprint.Module)))
797 }
798 }
799}
800
Jiyong Park2d492942018-03-05 17:44:10 +0900801type linkType int
802
803const (
Jiyong Park50146e92020-01-30 18:00:15 +0900804 // TODO(jiyong) rename these for better readability. Make the allowed
805 // and disallowed link types explicit
Jiyong Park2d492942018-03-05 17:44:10 +0900806 javaCore linkType = iota
807 javaSdk
808 javaSystem
Jiyong Park50146e92020-01-30 18:00:15 +0900809 javaModule
Jiyong Park2d492942018-03-05 17:44:10 +0900810 javaPlatform
811)
812
Jeongik Cha75b83b02019-11-01 15:28:00 +0900813type linkTypeContext interface {
814 android.Module
815 getLinkType(name string) (ret linkType, stubs bool)
816}
817
818func (m *Module) getLinkType(name string) (ret linkType, stubs bool) {
Colin Cross83bb3162018-06-25 15:48:06 -0700819 ver := m.sdkVersion()
Colin Crossf19b9bb2018-03-26 14:42:44 -0700820 switch {
Jiyong Park46f78fb2018-10-20 16:33:17 +0900821 case name == "core.current.stubs" || name == "core.platform.api.stubs" ||
822 name == "stub-annotations" || name == "private-stub-annotations-jar" ||
Pete Gillincbff3262019-05-08 15:10:06 +0100823 name == "core-lambda-stubs" || name == "core-generated-annotation-stubs":
Jiyong Park46f78fb2018-10-20 16:33:17 +0900824 return javaCore, true
Jiyong Park6a927c42020-01-21 02:03:43 +0900825 case ver.kind == sdkCore:
Jiyong Park46f78fb2018-10-20 16:33:17 +0900826 return javaCore, false
827 case name == "android_system_stubs_current":
828 return javaSystem, true
Jiyong Park6a927c42020-01-21 02:03:43 +0900829 case ver.kind == sdkSystem:
Jiyong Park46f78fb2018-10-20 16:33:17 +0900830 return javaSystem, false
831 case name == "android_test_stubs_current":
832 return javaSystem, true
Jiyong Park6a927c42020-01-21 02:03:43 +0900833 case ver.kind == sdkTest:
Jiyong Park46f78fb2018-10-20 16:33:17 +0900834 return javaPlatform, false
835 case name == "android_stubs_current":
836 return javaSdk, true
Jiyong Park6a927c42020-01-21 02:03:43 +0900837 case ver.kind == sdkPublic:
Jiyong Park46f78fb2018-10-20 16:33:17 +0900838 return javaSdk, false
Jiyong Park50146e92020-01-30 18:00:15 +0900839 case name == "android_module_lib_stubs_current":
840 return javaModule, true
841 case ver.kind == sdkModule:
842 return javaModule, false
Jiyong Park6a927c42020-01-21 02:03:43 +0900843 case ver.kind == sdkPrivate || ver.kind == sdkNone || ver.kind == sdkCorePlatform:
Jiyong Park46f78fb2018-10-20 16:33:17 +0900844 return javaPlatform, false
Jiyong Park6a927c42020-01-21 02:03:43 +0900845 case !ver.valid():
846 panic(fmt.Errorf("sdk_version is invalid. got %q", ver.raw))
Colin Crossf19b9bb2018-03-26 14:42:44 -0700847 default:
Jiyong Park46f78fb2018-10-20 16:33:17 +0900848 return javaSdk, false
Jiyong Park2d492942018-03-05 17:44:10 +0900849 }
850}
851
Jeongik Cha75b83b02019-11-01 15:28:00 +0900852func checkLinkType(ctx android.ModuleContext, from *Module, to linkTypeContext, tag dependencyTag) {
Colin Crossf19b9bb2018-03-26 14:42:44 -0700853 if ctx.Host() {
854 return
855 }
856
Jeongik Cha75b83b02019-11-01 15:28:00 +0900857 myLinkType, stubs := from.getLinkType(ctx.ModuleName())
Jiyong Park46f78fb2018-10-20 16:33:17 +0900858 if stubs {
859 return
860 }
Jeongik Cha75b83b02019-11-01 15:28:00 +0900861 otherLinkType, _ := to.getLinkType(ctx.OtherModuleName(to))
Jiyong Park2d492942018-03-05 17:44:10 +0900862 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."
863
864 switch myLinkType {
865 case javaCore:
866 if otherLinkType != javaCore {
867 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 +0900868 ctx.OtherModuleName(to))
869 }
Jiyong Park2d492942018-03-05 17:44:10 +0900870 break
871 case javaSdk:
872 if otherLinkType != javaCore && otherLinkType != javaSdk {
873 ctx.ModuleErrorf("compiles against Android API, but dependency %q is compiling against non-public Android API."+commonMessage,
874 ctx.OtherModuleName(to))
875 }
876 break
877 case javaSystem:
Jiyong Park50146e92020-01-30 18:00:15 +0900878 if otherLinkType == javaPlatform || otherLinkType == javaModule {
Jiyong Park2d492942018-03-05 17:44:10 +0900879 ctx.ModuleErrorf("compiles against system API, but dependency %q is compiling against private API."+commonMessage,
880 ctx.OtherModuleName(to))
881 }
882 break
Jiyong Park50146e92020-01-30 18:00:15 +0900883 case javaModule:
884 if otherLinkType == javaPlatform {
885 ctx.ModuleErrorf("compiles against module API, but dependency %q is compiling against private API."+commonMessage,
886 ctx.OtherModuleName(to))
887 }
888 break
Jiyong Park2d492942018-03-05 17:44:10 +0900889 case javaPlatform:
890 // no restriction on link-type
891 break
Jiyong Park750e5572018-01-31 00:20:13 +0900892 }
893}
894
Colin Cross32f676a2017-09-06 13:41:06 -0700895func (j *Module) collectDeps(ctx android.ModuleContext) deps {
896 var deps deps
Colin Crossfc3674a2017-09-18 17:41:52 -0700897
Colin Cross300f0382018-03-06 13:11:51 -0800898 if ctx.Device() {
Colin Cross83bb3162018-06-25 15:48:06 -0700899 sdkDep := decodeSdkDep(ctx, sdkContext(j))
Colin Cross300f0382018-03-06 13:11:51 -0800900 if sdkDep.invalidVersion {
Colin Cross6cef4812019-10-17 14:23:50 -0700901 ctx.AddMissingDependencies(sdkDep.bootclasspath)
902 ctx.AddMissingDependencies(sdkDep.java9Classpath)
Colin Cross300f0382018-03-06 13:11:51 -0800903 } else if sdkDep.useFiles {
904 // sdkDep.jar is actually equivalent to turbine header.jar.
Colin Cross86a60ae2018-05-29 14:44:55 -0700905 deps.classpath = append(deps.classpath, sdkDep.jars...)
Colin Cross3047fa22019-04-18 10:56:44 -0700906 deps.aidlPreprocess = sdkDep.aidl
907 } else {
908 deps.aidlPreprocess = sdkDep.aidl
Colin Cross300f0382018-03-06 13:11:51 -0800909 }
Colin Crossfc3674a2017-09-18 17:41:52 -0700910 }
911
Colin Crossd11fcda2017-10-23 17:59:01 -0700912 ctx.VisitDirectDeps(func(module android.Module) {
Colin Cross2fe66872015-03-30 17:20:39 -0700913 otherName := ctx.OtherModuleName(module)
Colin Crossec7a0422017-07-07 14:47:12 -0700914 tag := ctx.OtherModuleDependencyTag(module)
915
Colin Crossa4f08812018-10-02 22:03:40 -0700916 if _, ok := tag.(*jniDependencyTag); ok {
Colin Crossbd01e2a2018-10-04 15:21:03 -0700917 // Handled by AndroidApp.collectAppDeps
918 return
919 }
920 if tag == certificateTag {
921 // Handled by AndroidApp.collectAppDeps
Colin Crossa4f08812018-10-02 22:03:40 -0700922 return
923 }
Jeongik Cha75b83b02019-11-01 15:28:00 +0900924 switch module.(type) {
Jeongik Chae403e9e2019-12-07 00:16:24 +0900925 case *Library, *AndroidLibrary:
Jeongik Cha75b83b02019-11-01 15:28:00 +0900926 if to, ok := module.(linkTypeContext); ok {
927 switch tag {
928 case bootClasspathTag, libTag, staticLibTag:
929 checkLinkType(ctx, j, to, tag.(dependencyTag))
930 }
Colin Crossa97c5d32018-03-28 14:58:31 -0700931 }
Jiyong Park750e5572018-01-31 00:20:13 +0900932 }
Colin Cross54250902017-12-05 09:28:08 -0800933 switch dep := module.(type) {
Colin Cross897d2ed2019-02-11 14:03:51 -0800934 case SdkLibraryDependency:
935 switch tag {
936 case libTag:
937 deps.classpath = append(deps.classpath, dep.SdkHeaderJars(ctx, j.sdkVersion())...)
938 // names of sdk libs that are directly depended are exported
939 j.exportedSdkLibs = append(j.exportedSdkLibs, otherName)
Colin Cross79c7c262019-04-17 11:11:46 -0700940 case staticLibTag:
Colin Cross897d2ed2019-02-11 14:03:51 -0800941 ctx.ModuleErrorf("dependency on java_sdk_library %q can only be in libs", otherName)
942 }
Colin Cross54250902017-12-05 09:28:08 -0800943 case Dependency:
944 switch tag {
945 case bootClasspathTag:
946 deps.bootClasspath = append(deps.bootClasspath, dep.HeaderJars()...)
Colin Cross4b964c02018-10-15 16:18:06 -0700947 case libTag, instrumentationForTag:
Colin Cross54250902017-12-05 09:28:08 -0800948 deps.classpath = append(deps.classpath, dep.HeaderJars()...)
Jiyong Park1be96912018-05-28 18:02:19 +0900949 // sdk lib names from dependencies are re-exported
950 j.exportedSdkLibs = append(j.exportedSdkLibs, dep.ExportedSdkLibs()...)
Colin Cross3047fa22019-04-18 10:56:44 -0700951 deps.aidlIncludeDirs = append(deps.aidlIncludeDirs, dep.AidlIncludeDirs()...)
Artur Satayev9cf46692019-11-26 18:08:34 +0000952 pluginJars, pluginClasses := dep.ExportedPlugins()
953 addPlugins(&deps, pluginJars, pluginClasses...)
Colin Cross6cef4812019-10-17 14:23:50 -0700954 case java9LibTag:
955 deps.java9Classpath = append(deps.java9Classpath, dep.HeaderJars()...)
Colin Cross54250902017-12-05 09:28:08 -0800956 case staticLibTag:
957 deps.classpath = append(deps.classpath, dep.HeaderJars()...)
958 deps.staticJars = append(deps.staticJars, dep.ImplementationJars()...)
959 deps.staticHeaderJars = append(deps.staticHeaderJars, dep.HeaderJars()...)
Colin Cross331a1212018-08-15 20:40:52 -0700960 deps.staticResourceJars = append(deps.staticResourceJars, dep.ResourceJars()...)
Jiyong Park1be96912018-05-28 18:02:19 +0900961 // sdk lib names from dependencies are re-exported
962 j.exportedSdkLibs = append(j.exportedSdkLibs, dep.ExportedSdkLibs()...)
Colin Cross3047fa22019-04-18 10:56:44 -0700963 deps.aidlIncludeDirs = append(deps.aidlIncludeDirs, dep.AidlIncludeDirs()...)
Artur Satayev9cf46692019-11-26 18:08:34 +0000964 pluginJars, pluginClasses := dep.ExportedPlugins()
965 addPlugins(&deps, pluginJars, pluginClasses...)
Colin Crossbe9cdb82019-01-21 21:37:16 -0800966 case pluginTag:
967 if plugin, ok := dep.(*Plugin); ok {
Colin Crossbe9cdb82019-01-21 21:37:16 -0800968 if plugin.pluginProperties.Processor_class != nil {
Artur Satayev9cf46692019-11-26 18:08:34 +0000969 addPlugins(&deps, plugin.ImplementationAndResourcesJars(), *plugin.pluginProperties.Processor_class)
970 } else {
971 addPlugins(&deps, plugin.ImplementationAndResourcesJars())
Colin Crossbe9cdb82019-01-21 21:37:16 -0800972 }
973 deps.disableTurbine = deps.disableTurbine || Bool(plugin.pluginProperties.Generates_api)
974 } else {
975 ctx.PropertyErrorf("plugins", "%q is not a java_plugin module", otherName)
976 }
Artur Satayev9cf46692019-11-26 18:08:34 +0000977 case exportedPluginTag:
978 if plugin, ok := dep.(*Plugin); ok {
979 if plugin.pluginProperties.Generates_api != nil && *plugin.pluginProperties.Generates_api {
980 ctx.PropertyErrorf("exported_plugins", "Cannot export plugins with generates_api = true, found %v", otherName)
981 }
982 j.exportedPluginJars = append(j.exportedPluginJars, plugin.ImplementationAndResourcesJars()...)
983 if plugin.pluginProperties.Processor_class != nil {
984 j.exportedPluginClasses = append(j.exportedPluginClasses, *plugin.pluginProperties.Processor_class)
985 }
986 } else {
987 ctx.PropertyErrorf("exported_plugins", "%q is not a java_plugin module", otherName)
988 }
Nan Zhangb2b33de2018-02-23 11:18:47 -0800989 case frameworkApkTag:
990 if ctx.ModuleName() == "android_stubs_current" ||
991 ctx.ModuleName() == "android_system_stubs_current" ||
Nan Zhang863f05b2018-08-07 13:41:10 -0700992 ctx.ModuleName() == "android_test_stubs_current" {
Nan Zhangb2b33de2018-02-23 11:18:47 -0800993 // framework stubs.jar need to depend on framework-res.apk, in order to pull the
994 // resource files out of there for aapt.
995 //
996 // Normally the package rule runs aapt, which includes the resource,
997 // but we're not running that in our package rule so just copy in the
998 // resource files here.
Colin Cross331a1212018-08-15 20:40:52 -0700999 deps.staticResourceJars = append(deps.staticResourceJars, dep.(*AndroidApp).exportPackage)
Nan Zhangb2b33de2018-02-23 11:18:47 -08001000 }
Colin Cross54250902017-12-05 09:28:08 -08001001 case kotlinStdlibTag:
Colin Cross0b03d972019-05-13 11:06:25 -07001002 deps.kotlinStdlib = append(deps.kotlinStdlib, dep.HeaderJars()...)
Colin Crossafbb1732019-01-17 15:42:52 -08001003 case kotlinAnnotationsTag:
1004 deps.kotlinAnnotations = dep.HeaderJars()
Colin Cross54250902017-12-05 09:28:08 -08001005 }
1006
Colin Cross54250902017-12-05 09:28:08 -08001007 case android.SourceFileProducer:
1008 switch tag {
1009 case libTag:
1010 checkProducesJars(ctx, dep)
1011 deps.classpath = append(deps.classpath, dep.Srcs()...)
1012 case staticLibTag:
1013 checkProducesJars(ctx, dep)
1014 deps.classpath = append(deps.classpath, dep.Srcs()...)
1015 deps.staticJars = append(deps.staticJars, dep.Srcs()...)
1016 deps.staticHeaderJars = append(deps.staticHeaderJars, dep.Srcs()...)
Colin Cross54250902017-12-05 09:28:08 -08001017 }
1018 default:
Colin Crossec7a0422017-07-07 14:47:12 -07001019 switch tag {
Paul Duffin68289b02019-09-20 13:50:52 +01001020 case bootClasspathTag:
1021 // If a system modules dependency has been added to the bootclasspath
1022 // then add its libs to the bootclasspath.
1023 sm := module.(*SystemModules)
1024 deps.bootClasspath = append(deps.bootClasspath, sm.headerJars...)
1025
Colin Cross1369cdb2017-09-29 17:58:17 -07001026 case systemModulesTag:
1027 if deps.systemModules != nil {
1028 panic("Found two system module dependencies")
1029 }
1030 sm := module.(*SystemModules)
Dan Willemsenff60a732019-06-13 16:52:01 +00001031 if sm.outputDir == nil || len(sm.outputDeps) == 0 {
Colin Cross1369cdb2017-09-29 17:58:17 -07001032 panic("Missing directory for system module dependency")
1033 }
Colin Crossb77043e2019-07-16 13:57:13 -07001034 deps.systemModules = &systemModules{sm.outputDir, sm.outputDeps}
Colin Cross2fe66872015-03-30 17:20:39 -07001035 }
Colin Crossec7a0422017-07-07 14:47:12 -07001036 }
Colin Cross2fe66872015-03-30 17:20:39 -07001037 })
1038
Jiyong Park1be96912018-05-28 18:02:19 +09001039 j.exportedSdkLibs = android.FirstUniqueStrings(j.exportedSdkLibs)
1040
Colin Cross32f676a2017-09-06 13:41:06 -07001041 return deps
Colin Cross2fe66872015-03-30 17:20:39 -07001042}
1043
Artur Satayev9cf46692019-11-26 18:08:34 +00001044func addPlugins(deps *deps, pluginJars android.Paths, pluginClasses ...string) {
1045 deps.processorPath = append(deps.processorPath, pluginJars...)
1046 deps.processorClasses = append(deps.processorClasses, pluginClasses...)
1047}
1048
Colin Cross1e743852019-10-28 11:37:20 -07001049func getJavaVersion(ctx android.ModuleContext, javaVersion string, sdkContext sdkContext) javaVersion {
Jiyong Park6a927c42020-01-21 02:03:43 +09001050 sdk, err := sdkContext.sdkVersion().effectiveVersion(ctx)
Colin Cross83bb3162018-06-25 15:48:06 -07001051 if err != nil {
1052 ctx.PropertyErrorf("sdk_version", "%s", err)
1053 }
Nan Zhang357466b2018-04-17 17:38:36 -07001054 if javaVersion != "" {
Colin Cross1e743852019-10-28 11:37:20 -07001055 return normalizeJavaVersion(ctx, javaVersion)
Nan Zhang357466b2018-04-17 17:38:36 -07001056 } else if ctx.Device() && sdk <= 23 {
Colin Cross1e743852019-10-28 11:37:20 -07001057 return JAVA_VERSION_7
Pete Gillina1c9e9d2019-10-17 14:52:07 +01001058 } else if ctx.Device() && sdk <= 29 {
Colin Cross1e743852019-10-28 11:37:20 -07001059 return JAVA_VERSION_8
Colin Cross6cef4812019-10-17 14:23:50 -07001060 } else if ctx.Device() && ctx.Config().UnbundledBuildUsePrebuiltSdks() {
1061 // TODO(b/142896162): once we have prebuilt system modules we can use 1.9 for unbundled builds
Colin Cross1e743852019-10-28 11:37:20 -07001062 return JAVA_VERSION_8
Nan Zhang357466b2018-04-17 17:38:36 -07001063 } else {
Colin Cross1e743852019-10-28 11:37:20 -07001064 return JAVA_VERSION_9
Nan Zhang357466b2018-04-17 17:38:36 -07001065 }
Nan Zhang357466b2018-04-17 17:38:36 -07001066}
1067
Colin Cross1e743852019-10-28 11:37:20 -07001068type javaVersion int
1069
1070const (
1071 JAVA_VERSION_UNSUPPORTED = 0
1072 JAVA_VERSION_6 = 6
1073 JAVA_VERSION_7 = 7
1074 JAVA_VERSION_8 = 8
1075 JAVA_VERSION_9 = 9
1076)
1077
1078func (v javaVersion) String() string {
1079 switch v {
1080 case JAVA_VERSION_6:
1081 return "1.6"
1082 case JAVA_VERSION_7:
1083 return "1.7"
1084 case JAVA_VERSION_8:
1085 return "1.8"
1086 case JAVA_VERSION_9:
1087 return "1.9"
1088 default:
1089 return "unsupported"
1090 }
1091}
1092
1093// Returns true if javac targeting this version uses system modules instead of a bootclasspath.
1094func (v javaVersion) usesJavaModules() bool {
1095 return v >= 9
1096}
1097
1098func normalizeJavaVersion(ctx android.BaseModuleContext, javaVersion string) javaVersion {
Pete Gillin4e8b48a2019-07-12 13:16:17 +01001099 switch javaVersion {
1100 case "1.6", "6":
Colin Cross1e743852019-10-28 11:37:20 -07001101 return JAVA_VERSION_6
Pete Gillin4e8b48a2019-07-12 13:16:17 +01001102 case "1.7", "7":
Colin Cross1e743852019-10-28 11:37:20 -07001103 return JAVA_VERSION_7
Pete Gillin4e8b48a2019-07-12 13:16:17 +01001104 case "1.8", "8":
Colin Cross1e743852019-10-28 11:37:20 -07001105 return JAVA_VERSION_8
Pete Gillin4e8b48a2019-07-12 13:16:17 +01001106 case "1.9", "9":
Colin Cross1e743852019-10-28 11:37:20 -07001107 return JAVA_VERSION_9
Pete Gillin4e8b48a2019-07-12 13:16:17 +01001108 case "10", "11":
1109 ctx.PropertyErrorf("java_version", "Java language levels above 9 are not supported")
Colin Cross1e743852019-10-28 11:37:20 -07001110 return JAVA_VERSION_UNSUPPORTED
Pete Gillin4e8b48a2019-07-12 13:16:17 +01001111 default:
1112 ctx.PropertyErrorf("java_version", "Unrecognized Java language level")
Colin Cross1e743852019-10-28 11:37:20 -07001113 return JAVA_VERSION_UNSUPPORTED
Pete Gillin4e8b48a2019-07-12 13:16:17 +01001114 }
1115}
1116
Nan Zhanged19fc32017-10-19 13:06:22 -07001117func (j *Module) collectBuilderFlags(ctx android.ModuleContext, deps deps) javaBuilderFlags {
Colin Crossc0b06f12015-04-08 13:03:43 -07001118
Colin Crossf03c82b2015-04-13 13:53:40 -07001119 var flags javaBuilderFlags
1120
Tobias Thierer06dd04f2018-09-11 16:21:05 +01001121 // javaVersion flag.
1122 flags.javaVersion = getJavaVersion(ctx, String(j.properties.Java_version), sdkContext(j))
1123
Nan Zhanged19fc32017-10-19 13:06:22 -07001124 // javac flags.
Colin Crossf03c82b2015-04-13 13:53:40 -07001125 javacFlags := j.properties.Javacflags
Colin Cross1e743852019-10-28 11:37:20 -07001126 if flags.javaVersion.usesJavaModules() {
Colin Cross1369cdb2017-09-29 17:58:17 -07001127 javacFlags = append(javacFlags, j.properties.Openjdk9.Javacflags...)
Nan Zhanged19fc32017-10-19 13:06:22 -07001128 }
Colin Cross6510f912017-11-29 00:27:14 -08001129 if ctx.Config().MinimizeJavaDebugInfo() {
Colin Cross126a25c2017-10-31 13:55:34 -07001130 // Override the -g flag passed globally to remove local variable debug info to reduce
1131 // disk and memory usage.
1132 javacFlags = append(javacFlags, "-g:source,lines")
1133 }
Colin Crossc228a702019-11-06 16:18:05 -08001134 javacFlags = append(javacFlags, "-Xlint:-dep-ann")
Colin Cross64162712017-08-08 13:17:59 -07001135
Colin Cross66548102018-06-19 22:47:35 -07001136 if ctx.Config().RunErrorProne() {
1137 if config.ErrorProneClasspath == nil {
1138 ctx.ModuleErrorf("cannot build with Error Prone, missing external/error_prone?")
1139 }
1140
1141 errorProneFlags := []string{
1142 "-Xplugin:ErrorProne",
1143 "${config.ErrorProneChecks}",
1144 }
1145 errorProneFlags = append(errorProneFlags, j.properties.Errorprone.Javacflags...)
1146
1147 flags.errorProneExtraJavacFlags = "${config.ErrorProneFlags} " +
1148 "'" + strings.Join(errorProneFlags, " ") + "'"
1149 flags.errorProneProcessorPath = classpath(android.PathsForSource(ctx, config.ErrorProneClasspath))
Andreas Gampef3e5b552018-01-22 21:27:21 -08001150 }
1151
Nan Zhanged19fc32017-10-19 13:06:22 -07001152 // classpath
Nan Zhang581fd212018-01-10 16:06:12 -08001153 flags.bootClasspath = append(flags.bootClasspath, deps.bootClasspath...)
1154 flags.classpath = append(flags.classpath, deps.classpath...)
Colin Cross6cef4812019-10-17 14:23:50 -07001155 flags.java9Classpath = append(flags.java9Classpath, deps.java9Classpath...)
Colin Cross6a77c982018-06-19 22:43:34 -07001156 flags.processorPath = append(flags.processorPath, deps.processorPath...)
Colin Cross7fdd2b72018-01-02 18:14:25 -08001157
Colin Crossbe9cdb82019-01-21 21:37:16 -08001158 flags.processor = strings.Join(deps.processorClasses, ",")
1159
Colin Cross1e743852019-10-28 11:37:20 -07001160 if len(flags.bootClasspath) == 0 && ctx.Host() && !flags.javaVersion.usesJavaModules() &&
1161 decodeSdkDep(ctx, sdkContext(j)).hasStandardLibs() {
Colin Cross7fdd2b72018-01-02 18:14:25 -08001162 // Give host-side tools a version of OpenJDK's standard libraries
1163 // close to what they're targeting. As of Dec 2017, AOSP is only
1164 // bundling OpenJDK 8 and 9, so nothing < 8 is available.
1165 //
1166 // When building with OpenJDK 8, the following should have no
1167 // effect since those jars would be available by default.
1168 //
1169 // When building with OpenJDK 9 but targeting a version < 1.8,
1170 // putting them on the bootclasspath means that:
1171 // a) code can't (accidentally) refer to OpenJDK 9 specific APIs
1172 // b) references to existing APIs are not reinterpreted in an
1173 // OpenJDK 9-specific way, eg. calls to subclasses of
1174 // java.nio.Buffer as in http://b/70862583
1175 java8Home := ctx.Config().Getenv("ANDROID_JAVA8_HOME")
1176 flags.bootClasspath = append(flags.bootClasspath,
1177 android.PathForSource(ctx, java8Home, "jre/lib/jce.jar"),
1178 android.PathForSource(ctx, java8Home, "jre/lib/rt.jar"))
Nan Zhang5f8cb422018-02-06 10:34:32 -08001179 if Bool(j.properties.Use_tools_jar) {
1180 flags.bootClasspath = append(flags.bootClasspath,
1181 android.PathForSource(ctx, java8Home, "lib/tools.jar"))
1182 }
Colin Cross7fdd2b72018-01-02 18:14:25 -08001183 }
1184
Colin Cross1e743852019-10-28 11:37:20 -07001185 if j.properties.Patch_module != nil && flags.javaVersion.usesJavaModules() {
Jaewoong Jung38e4fb22018-12-12 09:01:34 -08001186 // Manually specify build directory in case it is not under the repo root.
1187 // (javac doesn't seem to expand into symbolc links when searching for patch-module targets, so
1188 // just adding a symlink under the root doesn't help.)
1189 patchPaths := ".:" + ctx.Config().BuildDir()
1190 classPath := flags.classpath.FormJavaClassPath("")
1191 if classPath != "" {
1192 patchPaths += ":" + classPath
1193 }
1194 javacFlags = append(javacFlags, "--patch-module="+String(j.properties.Patch_module)+"="+patchPaths)
Colin Cross81440082018-08-15 20:21:55 -07001195 }
1196
Nan Zhanged19fc32017-10-19 13:06:22 -07001197 // systemModules
Colin Crossb77043e2019-07-16 13:57:13 -07001198 flags.systemModules = deps.systemModules
Colin Cross1369cdb2017-09-29 17:58:17 -07001199
Nan Zhanged19fc32017-10-19 13:06:22 -07001200 // aidl flags.
Colin Cross3047fa22019-04-18 10:56:44 -07001201 flags.aidlFlags, flags.aidlDeps = j.aidlFlags(ctx, deps.aidlPreprocess, deps.aidlIncludeDirs)
Colin Cross2fe66872015-03-30 17:20:39 -07001202
Colin Cross81440082018-08-15 20:21:55 -07001203 if len(javacFlags) > 0 {
1204 // optimization.
1205 ctx.Variable(pctx, "javacFlags", strings.Join(javacFlags, " "))
1206 flags.javacFlags = "$javacFlags"
1207 }
1208
Nan Zhanged19fc32017-10-19 13:06:22 -07001209 return flags
1210}
Colin Crossc0b06f12015-04-08 13:03:43 -07001211
Jaewoong Junga24af3b2019-05-13 09:23:20 -07001212func (j *Module) compile(ctx android.ModuleContext, aaptSrcJar android.Path) {
Colin Crossebe1a512017-11-14 13:12:14 -08001213 j.exportAidlIncludeDirs = android.PathsForModuleSrc(ctx, j.deviceProperties.Aidl.Export_include_dirs)
Nan Zhanged19fc32017-10-19 13:06:22 -07001214
1215 deps := j.collectDeps(ctx)
1216 flags := j.collectBuilderFlags(ctx, deps)
1217
Colin Cross1e743852019-10-28 11:37:20 -07001218 if flags.javaVersion.usesJavaModules() {
Nan Zhanged19fc32017-10-19 13:06:22 -07001219 j.properties.Srcs = append(j.properties.Srcs, j.properties.Openjdk9.Srcs...)
1220 }
Colin Cross8a497952019-03-05 22:25:09 -08001221 srcFiles := android.PathsForModuleSrcExcludes(ctx, j.properties.Srcs, j.properties.Exclude_srcs)
Colin Cross6af17aa2017-09-20 12:59:05 -07001222 if hasSrcExt(srcFiles.Strings(), ".proto") {
Colin Cross0f2ee152017-12-14 15:22:43 -08001223 flags = protoFlags(ctx, &j.properties, &j.protoProperties, flags)
Colin Cross6af17aa2017-09-20 12:59:05 -07001224 }
1225
Colin Crossaf050172017-11-15 23:01:59 -08001226 srcFiles = j.genSources(ctx, srcFiles, flags)
1227
1228 srcJars := srcFiles.FilterByExt(".srcjar")
Colin Cross59149b62017-10-16 18:07:29 -07001229 srcJars = append(srcJars, deps.srcJars...)
Jaewoong Junga24af3b2019-05-13 09:23:20 -07001230 if aaptSrcJar != nil {
1231 srcJars = append(srcJars, aaptSrcJar)
1232 }
Colin Crossb7a63242015-04-16 14:09:14 -07001233
Steven Morelandc4efd9c2019-01-18 11:51:25 -08001234 if j.properties.Jarjar_rules != nil {
Colin Cross8a497952019-03-05 22:25:09 -08001235 j.expandJarjarRules = android.PathForModuleSrc(ctx, *j.properties.Jarjar_rules)
Steven Morelandc4efd9c2019-01-18 11:51:25 -08001236 }
1237
Colin Cross1ee23172017-10-18 14:44:18 -07001238 jarName := ctx.ModuleName() + ".jar"
1239
Przemyslaw Szczepaniak4b5fe9d2018-02-13 14:32:54 +00001240 javaSrcFiles := srcFiles.FilterByExt(".java")
1241 var uniqueSrcFiles android.Paths
1242 set := make(map[string]bool)
1243 for _, v := range javaSrcFiles {
1244 if _, found := set[v.String()]; !found {
1245 set[v.String()] = true
1246 uniqueSrcFiles = append(uniqueSrcFiles, v)
1247 }
1248 }
1249
patricktu242faad2019-09-24 15:41:30 +08001250 // Collect .java files for AIDEGen
1251 j.expandIDEInfoCompiledSrcs = append(j.expandIDEInfoCompiledSrcs, uniqueSrcFiles.Strings()...)
1252
Colin Cross55f63ea2018-08-27 12:37:09 -07001253 var kotlinJars android.Paths
1254
Colin Cross93e85952017-08-15 13:34:18 -07001255 if srcFiles.HasExt(".kt") {
Zoran Jovanovic8736ce22018-08-21 17:10:29 +02001256 // user defined kotlin flags.
1257 kotlincFlags := j.properties.Kotlincflags
1258 CheckKotlincFlags(ctx, kotlincFlags)
1259
Colin Cross93e85952017-08-15 13:34:18 -07001260 // If there are kotlin files, compile them first but pass all the kotlin and java files
1261 // kotlinc will use the java files to resolve types referenced by the kotlin files, but
1262 // won't emit any classes for them.
Zoran Jovanovic8736ce22018-08-21 17:10:29 +02001263 kotlincFlags = append(kotlincFlags, "-no-stdlib")
Colin Cross93e85952017-08-15 13:34:18 -07001264 if ctx.Device() {
Zoran Jovanovic8736ce22018-08-21 17:10:29 +02001265 kotlincFlags = append(kotlincFlags, "-no-jdk")
1266 }
1267 if len(kotlincFlags) > 0 {
1268 // optimization.
1269 ctx.Variable(pctx, "kotlincFlags", strings.Join(kotlincFlags, " "))
1270 flags.kotlincFlags += "$kotlincFlags"
Colin Cross93e85952017-08-15 13:34:18 -07001271 }
1272
Przemyslaw Szczepaniak4b5fe9d2018-02-13 14:32:54 +00001273 var kotlinSrcFiles android.Paths
1274 kotlinSrcFiles = append(kotlinSrcFiles, uniqueSrcFiles...)
1275 kotlinSrcFiles = append(kotlinSrcFiles, srcFiles.FilterByExt(".kt")...)
1276
patricktu242faad2019-09-24 15:41:30 +08001277 // Collect .kt files for AIDEGen
1278 j.expandIDEInfoCompiledSrcs = append(j.expandIDEInfoCompiledSrcs, srcFiles.FilterByExt(".kt").Strings()...)
1279
Colin Crossafbb1732019-01-17 15:42:52 -08001280 flags.classpath = append(flags.classpath, deps.kotlinStdlib...)
1281 flags.classpath = append(flags.classpath, deps.kotlinAnnotations...)
1282
1283 flags.kotlincClasspath = append(flags.kotlincClasspath, flags.bootClasspath...)
1284 flags.kotlincClasspath = append(flags.kotlincClasspath, flags.classpath...)
1285
1286 if len(flags.processorPath) > 0 {
1287 // Use kapt for annotation processing
1288 kaptSrcJar := android.PathForModuleOut(ctx, "kapt", "kapt-sources.jar")
1289 kotlinKapt(ctx, kaptSrcJar, kotlinSrcFiles, srcJars, flags)
1290 srcJars = append(srcJars, kaptSrcJar)
1291 // Disable annotation processing in javac, it's already been handled by kapt
1292 flags.processorPath = nil
Colin Cross3a3e94c2019-01-23 15:39:50 -08001293 flags.processor = ""
Colin Crossafbb1732019-01-17 15:42:52 -08001294 }
Colin Cross93e85952017-08-15 13:34:18 -07001295
Colin Cross1ee23172017-10-18 14:44:18 -07001296 kotlinJar := android.PathForModuleOut(ctx, "kotlin", jarName)
Colin Cross21fc9bb2019-01-18 15:05:09 -08001297 kotlinCompile(ctx, kotlinJar, kotlinSrcFiles, srcJars, flags)
Colin Cross93e85952017-08-15 13:34:18 -07001298 if ctx.Failed() {
1299 return
1300 }
1301
1302 // Make javac rule depend on the kotlinc rule
1303 flags.classpath = append(flags.classpath, kotlinJar)
Przemyslaw Szczepaniak66c0c402018-03-08 13:21:55 +00001304
Colin Cross93e85952017-08-15 13:34:18 -07001305 // Jar kotlin classes into the final jar after javac
Colin Cross55f63ea2018-08-27 12:37:09 -07001306 kotlinJars = append(kotlinJars, kotlinJar)
Colin Cross9b38aef2018-08-27 15:42:25 -07001307 kotlinJars = append(kotlinJars, deps.kotlinStdlib...)
Colin Cross93e85952017-08-15 13:34:18 -07001308 }
1309
Colin Cross55f63ea2018-08-27 12:37:09 -07001310 jars := append(android.Paths(nil), kotlinJars...)
1311
Colin Cross5ab4e6d2017-11-22 16:20:45 -08001312 // Store the list of .java files that was passed to javac
1313 j.compiledJavaSrcs = uniqueSrcFiles
1314 j.compiledSrcJars = srcJars
1315
Nan Zhang61eaedb2017-11-02 13:28:15 -07001316 enable_sharding := false
Colin Crossbe9cdb82019-01-21 21:37:16 -08001317 if ctx.Device() && !ctx.Config().IsEnvFalse("TURBINE_ENABLED") && !deps.disableTurbine {
Nan Zhang61eaedb2017-11-02 13:28:15 -07001318 if j.properties.Javac_shard_size != nil && *(j.properties.Javac_shard_size) > 0 {
1319 enable_sharding = true
Ashley Rosee36efcf2019-01-16 17:34:08 -05001320 // Formerly, there was a check here that prevented annotation processors
1321 // from being used when sharding was enabled, as some annotation processors
1322 // do not function correctly in sharded environments. It was removed to
1323 // allow for the use of annotation processors that do function correctly
1324 // with sharding enabled. See: b/77284273.
Nan Zhang61eaedb2017-11-02 13:28:15 -07001325 }
Colin Cross55f63ea2018-08-27 12:37:09 -07001326 j.headerJarFile = j.compileJavaHeader(ctx, uniqueSrcFiles, srcJars, deps, flags, jarName, kotlinJars)
Colin Crossf19b9bb2018-03-26 14:42:44 -07001327 if ctx.Failed() {
1328 return
Nan Zhanged19fc32017-10-19 13:06:22 -07001329 }
1330 }
Colin Cross8eadbf02017-10-24 17:46:00 -07001331 if len(uniqueSrcFiles) > 0 || len(srcJars) > 0 {
Colin Crossd6891432017-09-27 17:39:56 -07001332 var extraJarDeps android.Paths
Colin Cross66548102018-06-19 22:47:35 -07001333 if ctx.Config().RunErrorProne() {
Colin Crossc6bbef32017-08-14 14:16:06 -07001334 // If error-prone is enabled, add an additional rule to compile the java files into
1335 // a separate set of classes (so that they don't overwrite the normal ones and require
Colin Crossd6891432017-09-27 17:39:56 -07001336 // a rebuild when error-prone is turned off).
Colin Crossc6bbef32017-08-14 14:16:06 -07001337 // TODO(ccross): Once we always compile with javac9 we may be able to conditionally
1338 // enable error-prone without affecting the output class files.
Colin Cross1ee23172017-10-18 14:44:18 -07001339 errorprone := android.PathForModuleOut(ctx, "errorprone", jarName)
Nan Zhang61eaedb2017-11-02 13:28:15 -07001340 RunErrorProne(ctx, errorprone, uniqueSrcFiles, srcJars, flags)
Colin Crossc6bbef32017-08-14 14:16:06 -07001341 extraJarDeps = append(extraJarDeps, errorprone)
1342 }
1343
Nan Zhang61eaedb2017-11-02 13:28:15 -07001344 if enable_sharding {
Nan Zhang581fd212018-01-10 16:06:12 -08001345 flags.classpath = append(flags.classpath, j.headerJarFile)
Nan Zhang61eaedb2017-11-02 13:28:15 -07001346 shardSize := int(*(j.properties.Javac_shard_size))
1347 var shardSrcs []android.Paths
1348 if len(uniqueSrcFiles) > 0 {
Colin Cross0a2f7192019-09-23 14:33:09 -07001349 shardSrcs = android.ShardPaths(uniqueSrcFiles, shardSize)
Nan Zhang61eaedb2017-11-02 13:28:15 -07001350 for idx, shardSrc := range shardSrcs {
Colin Cross3b706fd2019-09-05 16:44:18 -07001351 classes := j.compileJavaClasses(ctx, jarName, idx, shardSrc,
1352 nil, flags, extraJarDeps)
Nan Zhang61eaedb2017-11-02 13:28:15 -07001353 jars = append(jars, classes)
1354 }
1355 }
1356 if len(srcJars) > 0 {
Colin Cross3b706fd2019-09-05 16:44:18 -07001357 classes := j.compileJavaClasses(ctx, jarName, len(shardSrcs),
1358 nil, srcJars, flags, extraJarDeps)
Nan Zhang61eaedb2017-11-02 13:28:15 -07001359 jars = append(jars, classes)
1360 }
1361 } else {
Colin Cross3b706fd2019-09-05 16:44:18 -07001362 classes := j.compileJavaClasses(ctx, jarName, -1, uniqueSrcFiles, srcJars, flags, extraJarDeps)
Nan Zhang61eaedb2017-11-02 13:28:15 -07001363 jars = append(jars, classes)
1364 }
Colin Crossd6891432017-09-27 17:39:56 -07001365 if ctx.Failed() {
1366 return
1367 }
Colin Cross2fe66872015-03-30 17:20:39 -07001368 }
1369
Colin Cross0c4ce212019-05-03 15:28:19 -07001370 j.srcJarArgs, j.srcJarDeps = resourcePathsToJarArgs(srcFiles), srcFiles
1371
1372 var includeSrcJar android.WritablePath
1373 if Bool(j.properties.Include_srcs) {
1374 includeSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+".srcjar")
1375 TransformResourcesToJar(ctx, includeSrcJar, j.srcJarArgs, j.srcJarDeps)
1376 }
1377
Colin Crosscedd4762018-09-13 11:26:19 -07001378 dirArgs, dirDeps := ResourceDirsToJarArgs(ctx, j.properties.Java_resource_dirs,
1379 j.properties.Exclude_java_resource_dirs, j.properties.Exclude_java_resources)
Colin Cross0f37af02017-09-27 17:42:05 -07001380 fileArgs, fileDeps := ResourceFilesToJarArgs(ctx, j.properties.Java_resources, j.properties.Exclude_java_resources)
Colin Cross988708c2019-05-06 14:04:11 -07001381 extraArgs, extraDeps := resourcePathsToJarArgs(j.extraResources), j.extraResources
Colin Cross0f37af02017-09-27 17:42:05 -07001382
1383 var resArgs []string
1384 var resDeps android.Paths
1385
1386 resArgs = append(resArgs, dirArgs...)
1387 resDeps = append(resDeps, dirDeps...)
1388
1389 resArgs = append(resArgs, fileArgs...)
1390 resDeps = append(resDeps, fileDeps...)
1391
Colin Cross988708c2019-05-06 14:04:11 -07001392 resArgs = append(resArgs, extraArgs...)
1393 resDeps = append(resDeps, extraDeps...)
1394
Colin Cross40a36712017-09-27 17:41:35 -07001395 if len(resArgs) > 0 {
Colin Cross1ee23172017-10-18 14:44:18 -07001396 resourceJar := android.PathForModuleOut(ctx, "res", jarName)
Colin Crosse9a275b2017-10-16 17:09:48 -07001397 TransformResourcesToJar(ctx, resourceJar, resArgs, resDeps)
Colin Cross331a1212018-08-15 20:40:52 -07001398 j.resourceJar = resourceJar
Colin Cross65bf4f22015-04-03 16:54:17 -07001399 if ctx.Failed() {
1400 return
1401 }
1402 }
1403
Colin Cross0c4ce212019-05-03 15:28:19 -07001404 var resourceJars android.Paths
1405 if j.resourceJar != nil {
1406 resourceJars = append(resourceJars, j.resourceJar)
1407 }
1408 if Bool(j.properties.Include_srcs) {
1409 resourceJars = append(resourceJars, includeSrcJar)
1410 }
1411 resourceJars = append(resourceJars, deps.staticResourceJars...)
Colin Cross331a1212018-08-15 20:40:52 -07001412
Colin Cross0c4ce212019-05-03 15:28:19 -07001413 if len(resourceJars) > 1 {
Colin Cross331a1212018-08-15 20:40:52 -07001414 combinedJar := android.PathForModuleOut(ctx, "res-combined", jarName)
Colin Cross0c4ce212019-05-03 15:28:19 -07001415 TransformJarsToJar(ctx, combinedJar, "for resources", resourceJars, android.OptionalPath{},
Colin Cross331a1212018-08-15 20:40:52 -07001416 false, nil, nil)
1417 j.resourceJar = combinedJar
Colin Cross0c4ce212019-05-03 15:28:19 -07001418 } else if len(resourceJars) == 1 {
1419 j.resourceJar = resourceJars[0]
Colin Cross331a1212018-08-15 20:40:52 -07001420 }
1421
Jaewoong Junga24af3b2019-05-13 09:23:20 -07001422 if len(deps.staticJars) > 0 {
1423 jars = append(jars, deps.staticJars...)
Jaewoong Junga24af3b2019-05-13 09:23:20 -07001424 }
Colin Cross0a6e0072017-08-30 14:24:55 -07001425
Colin Cross094054a2018-10-17 15:10:48 -07001426 manifest := j.overrideManifest
1427 if !manifest.Valid() && j.properties.Manifest != nil {
Colin Cross8a497952019-03-05 22:25:09 -08001428 manifest = android.OptionalPathForPath(android.PathForModuleSrc(ctx, *j.properties.Manifest))
Colin Cross366938f2017-12-11 16:29:02 -08001429 }
Colin Cross635acc92017-09-12 22:50:46 -07001430
Colin Cross8a497952019-03-05 22:25:09 -08001431 services := android.PathsForModuleSrc(ctx, j.properties.Services)
Alex Light7f004a72019-02-21 13:27:37 -08001432 if len(services) > 0 {
1433 servicesJar := android.PathForModuleOut(ctx, "services", jarName)
1434 var zipargs []string
1435 for _, file := range services {
1436 serviceFile := file.String()
1437 zipargs = append(zipargs, "-C", filepath.Dir(serviceFile), "-f", serviceFile)
1438 }
1439 ctx.Build(pctx, android.BuildParams{
1440 Rule: zip,
1441 Output: servicesJar,
1442 Implicits: services,
1443 Args: map[string]string{
Colin Cross0b9f31f2019-02-28 11:00:01 -08001444 "jarArgs": "-P META-INF/services/ " + strings.Join(proptools.NinjaAndShellEscapeList(zipargs), " "),
Alex Light7f004a72019-02-21 13:27:37 -08001445 },
1446 })
1447 jars = append(jars, servicesJar)
1448 }
1449
Colin Cross0a6e0072017-08-30 14:24:55 -07001450 // Combine the classes built from sources, any manifests, and any static libraries into
Nan Zhanged19fc32017-10-19 13:06:22 -07001451 // classes.jar. If there is only one input jar this step will be skipped.
Colin Cross3063b782018-08-15 11:19:12 -07001452 var outputFile android.ModuleOutPath
Colin Crosse9a275b2017-10-16 17:09:48 -07001453
1454 if len(jars) == 1 && !manifest.Valid() {
Colin Cross3063b782018-08-15 11:19:12 -07001455 if moduleOutPath, ok := jars[0].(android.ModuleOutPath); ok {
1456 // Optimization: skip the combine step if there is nothing to do
1457 // TODO(ccross): this leaves any module-info.class files, but those should only come from
1458 // prebuilt dependencies until we support modules in the platform build, so there shouldn't be
1459 // any if len(jars) == 1.
1460 outputFile = moduleOutPath
1461 } else {
1462 combinedJar := android.PathForModuleOut(ctx, "combined", jarName)
1463 ctx.Build(pctx, android.BuildParams{
1464 Rule: android.Cp,
1465 Input: jars[0],
1466 Output: combinedJar,
1467 })
1468 outputFile = combinedJar
1469 }
Colin Crosse9a275b2017-10-16 17:09:48 -07001470 } else {
Colin Cross1ee23172017-10-18 14:44:18 -07001471 combinedJar := android.PathForModuleOut(ctx, "combined", jarName)
Colin Cross37f6d792018-07-12 12:28:41 -07001472 TransformJarsToJar(ctx, combinedJar, "for javac", jars, manifest,
Colin Cross9b38aef2018-08-27 15:42:25 -07001473 false, nil, nil)
Colin Crosse9a275b2017-10-16 17:09:48 -07001474 outputFile = combinedJar
1475 }
Colin Cross0a6e0072017-08-30 14:24:55 -07001476
Colin Cross331a1212018-08-15 20:40:52 -07001477 // jarjar implementation jar if necessary
Steven Morelandc4efd9c2019-01-18 11:51:25 -08001478 if j.expandJarjarRules != nil {
Colin Cross8649b262017-09-27 18:03:17 -07001479 // Transform classes.jar into classes-jarjar.jar
Colin Cross1ee23172017-10-18 14:44:18 -07001480 jarjarFile := android.PathForModuleOut(ctx, "jarjar", jarName)
Steven Morelandc4efd9c2019-01-18 11:51:25 -08001481 TransformJarJar(ctx, jarjarFile, outputFile, j.expandJarjarRules)
Colin Crosse9a275b2017-10-16 17:09:48 -07001482 outputFile = jarjarFile
Colin Cross331a1212018-08-15 20:40:52 -07001483
1484 // jarjar resource jar if necessary
1485 if j.resourceJar != nil {
1486 resourceJarJarFile := android.PathForModuleOut(ctx, "res-jarjar", jarName)
Steven Morelandc4efd9c2019-01-18 11:51:25 -08001487 TransformJarJar(ctx, resourceJarJarFile, j.resourceJar, j.expandJarjarRules)
Colin Cross331a1212018-08-15 20:40:52 -07001488 j.resourceJar = resourceJarJarFile
1489 }
1490
Colin Cross0a6e0072017-08-30 14:24:55 -07001491 if ctx.Failed() {
1492 return
1493 }
1494 }
Vladimir Marko0975ee02019-04-02 10:29:55 +01001495
1496 // Check package restrictions if necessary.
1497 if len(j.properties.Permitted_packages) > 0 {
1498 // Check packages and copy to package-checked file.
1499 pkgckFile := android.PathForModuleOut(ctx, "package-check.stamp")
1500 CheckJarPackages(ctx, pkgckFile, outputFile, j.properties.Permitted_packages)
1501 j.additionalCheckedModules = append(j.additionalCheckedModules, pkgckFile)
1502
1503 if ctx.Failed() {
1504 return
1505 }
1506 }
1507
Nan Zhanged19fc32017-10-19 13:06:22 -07001508 j.implementationJarFile = outputFile
1509 if j.headerJarFile == nil {
1510 j.headerJarFile = j.implementationJarFile
1511 }
Colin Cross2fe66872015-03-30 17:20:39 -07001512
Colin Cross3144dfc2018-01-03 15:06:47 -08001513 if j.shouldInstrument(ctx) {
Colin Crosscb933592017-11-22 13:49:43 -08001514 outputFile = j.instrument(ctx, flags, outputFile, jarName)
1515 }
1516
Colin Cross331a1212018-08-15 20:40:52 -07001517 // merge implementation jar with resources if necessary
1518 implementationAndResourcesJar := outputFile
1519 if j.resourceJar != nil {
Colin Cross08a409d2019-04-29 10:22:44 -07001520 jars := android.Paths{j.resourceJar, implementationAndResourcesJar}
Colin Cross331a1212018-08-15 20:40:52 -07001521 combinedJar := android.PathForModuleOut(ctx, "withres", jarName)
Colin Cross08a409d2019-04-29 10:22:44 -07001522 TransformJarsToJar(ctx, combinedJar, "for resources", jars, manifest,
Colin Cross331a1212018-08-15 20:40:52 -07001523 false, nil, nil)
1524 implementationAndResourcesJar = combinedJar
1525 }
1526
1527 j.implementationAndResourcesJar = implementationAndResourcesJar
1528
Jiyong Park6b21c7d2020-02-11 09:16:01 +09001529 // Enable dex compilation for the APEX variants, unless it is disabled explicitly
1530 if android.DirectlyInAnyApex(ctx, ctx.ModuleName()) && !j.IsForPlatform() {
1531 if j.deviceProperties.Compile_dex == nil {
1532 j.deviceProperties.Compile_dex = proptools.BoolPtr(true)
1533 }
1534 if j.deviceProperties.Hostdex == nil {
1535 j.deviceProperties.Hostdex = proptools.BoolPtr(true)
1536 }
1537 }
1538
Jaewoong Jungc27ab662019-05-30 15:51:14 -07001539 if ctx.Device() && j.hasCode(ctx) &&
Jaewoong Junga24af3b2019-05-13 09:23:20 -07001540 (Bool(j.properties.Installable) || Bool(j.deviceProperties.Compile_dex)) {
Colin Cross8faf8fc2019-01-16 15:15:52 -08001541 // Dex compilation
Colin Cross3063b782018-08-15 11:19:12 -07001542 var dexOutputFile android.ModuleOutPath
David Brazdil17ef5632018-06-27 10:27:45 +01001543 dexOutputFile = j.compileDex(ctx, flags, outputFile, jarName)
Colin Cross2fe66872015-03-30 17:20:39 -07001544 if ctx.Failed() {
1545 return
1546 }
Colin Cross331a1212018-08-15 20:40:52 -07001547
Jiyong Park09cb6292019-07-15 15:29:23 +09001548 // Hidden API CSV generation and dex encoding
1549 dexOutputFile = j.hiddenAPI.hiddenAPI(ctx, dexOutputFile, j.implementationJarFile,
1550 j.deviceProperties.UncompressDex)
Colin Cross8faf8fc2019-01-16 15:15:52 -08001551
Colin Cross331a1212018-08-15 20:40:52 -07001552 // merge dex jar with resources if necessary
1553 if j.resourceJar != nil {
1554 jars := android.Paths{dexOutputFile, j.resourceJar}
1555 combinedJar := android.PathForModuleOut(ctx, "dex-withres", jarName)
1556 TransformJarsToJar(ctx, combinedJar, "for dex resources", jars, android.OptionalPath{},
1557 false, nil, nil)
Nicolas Geoffrayf3438722019-01-23 15:57:21 +00001558 if j.deviceProperties.UncompressDex {
1559 combinedAlignedJar := android.PathForModuleOut(ctx, "dex-withres-aligned", jarName)
1560 TransformZipAlign(ctx, combinedAlignedJar, combinedJar)
1561 dexOutputFile = combinedAlignedJar
1562 } else {
1563 dexOutputFile = combinedJar
1564 }
Colin Cross331a1212018-08-15 20:40:52 -07001565 }
1566
1567 j.dexJarFile = dexOutputFile
1568
Colin Cross8faf8fc2019-01-16 15:15:52 -08001569 // Dexpreopting
Colin Cross43f08db2018-11-12 10:13:39 -08001570 dexOutputFile = j.dexpreopt(ctx, dexOutputFile)
1571
1572 j.maybeStrippedDexJarFile = dexOutputFile
1573
Colin Cross3063b782018-08-15 11:19:12 -07001574 outputFile = dexOutputFile
Colin Cross43f08db2018-11-12 10:13:39 -08001575
1576 if ctx.Failed() {
1577 return
1578 }
Colin Cross331a1212018-08-15 20:40:52 -07001579 } else {
1580 outputFile = implementationAndResourcesJar
Colin Cross2fe66872015-03-30 17:20:39 -07001581 }
Colin Cross331a1212018-08-15 20:40:52 -07001582
Colin Crossb7a63242015-04-16 14:09:14 -07001583 ctx.CheckbuildFile(outputFile)
Colin Cross3063b782018-08-15 11:19:12 -07001584
1585 // Save the output file with no relative path so that it doesn't end up in a subdirectory when used as a resource
1586 j.outputFile = outputFile.WithoutRel()
Colin Cross2fe66872015-03-30 17:20:39 -07001587}
1588
Colin Cross3b706fd2019-09-05 16:44:18 -07001589func (j *Module) compileJavaClasses(ctx android.ModuleContext, jarName string, idx int,
1590 srcFiles, srcJars android.Paths, flags javaBuilderFlags, extraJarDeps android.Paths) android.WritablePath {
1591
1592 kzipName := pathtools.ReplaceExtension(jarName, "kzip")
1593 if idx >= 0 {
1594 kzipName = strings.TrimSuffix(jarName, filepath.Ext(jarName)) + strconv.Itoa(idx) + ".kzip"
1595 jarName += strconv.Itoa(idx)
1596 }
1597
1598 classes := android.PathForModuleOut(ctx, "javac", jarName)
1599 TransformJavaToClasses(ctx, classes, idx, srcFiles, srcJars, flags, extraJarDeps)
1600
1601 if ctx.Config().EmitXrefRules() {
1602 extractionFile := android.PathForModuleOut(ctx, kzipName)
1603 emitXrefRule(ctx, extractionFile, idx, srcFiles, srcJars, flags, extraJarDeps)
1604 j.kytheFiles = append(j.kytheFiles, extractionFile)
1605 }
1606
1607 return classes
1608}
1609
Zoran Jovanovic8736ce22018-08-21 17:10:29 +02001610// Check for invalid kotlinc flags. Only use this for flags explicitly passed by the user,
1611// since some of these flags may be used internally.
1612func CheckKotlincFlags(ctx android.ModuleContext, flags []string) {
1613 for _, flag := range flags {
1614 flag = strings.TrimSpace(flag)
1615
1616 if !strings.HasPrefix(flag, "-") {
1617 ctx.PropertyErrorf("kotlincflags", "Flag `%s` must start with `-`", flag)
1618 } else if strings.HasPrefix(flag, "-Xintellij-plugin-root") {
1619 ctx.PropertyErrorf("kotlincflags",
1620 "Bad flag: `%s`, only use internal compiler for consistency.", flag)
1621 } else if inList(flag, config.KotlincIllegalFlags) {
1622 ctx.PropertyErrorf("kotlincflags", "Flag `%s` already used by build system", flag)
1623 } else if flag == "-include-runtime" {
1624 ctx.PropertyErrorf("kotlincflags", "Bad flag: `%s`, do not include runtime.", flag)
1625 } else {
1626 args := strings.Split(flag, " ")
1627 if args[0] == "-kotlin-home" {
1628 ctx.PropertyErrorf("kotlincflags",
1629 "Bad flag: `%s`, kotlin home already set to default (path to kotlinc in the repo).", flag)
1630 }
1631 }
1632 }
1633}
1634
Colin Cross8eadbf02017-10-24 17:46:00 -07001635func (j *Module) compileJavaHeader(ctx android.ModuleContext, srcFiles, srcJars android.Paths,
Colin Cross55f63ea2018-08-27 12:37:09 -07001636 deps deps, flags javaBuilderFlags, jarName string, extraJars android.Paths) android.Path {
Nan Zhanged19fc32017-10-19 13:06:22 -07001637
1638 var jars android.Paths
Colin Cross8eadbf02017-10-24 17:46:00 -07001639 if len(srcFiles) > 0 || len(srcJars) > 0 {
Nan Zhanged19fc32017-10-19 13:06:22 -07001640 // Compile java sources into turbine.jar.
1641 turbineJar := android.PathForModuleOut(ctx, "turbine", jarName)
1642 TransformJavaToHeaderClasses(ctx, turbineJar, srcFiles, srcJars, flags)
1643 if ctx.Failed() {
1644 return nil
1645 }
1646 jars = append(jars, turbineJar)
1647 }
1648
Colin Cross55f63ea2018-08-27 12:37:09 -07001649 jars = append(jars, extraJars...)
1650
Nan Zhanged19fc32017-10-19 13:06:22 -07001651 // Combine any static header libraries into classes-header.jar. If there is only
1652 // one input jar this step will be skipped.
1653 var headerJar android.Path
1654 jars = append(jars, deps.staticHeaderJars...)
1655
Colin Cross5c6ecc12017-10-23 18:12:27 -07001656 // we cannot skip the combine step for now if there is only one jar
1657 // since we have to strip META-INF/TRANSITIVE dir from turbine.jar
1658 combinedJar := android.PathForModuleOut(ctx, "turbine-combined", jarName)
Colin Cross37f6d792018-07-12 12:28:41 -07001659 TransformJarsToJar(ctx, combinedJar, "for turbine", jars, android.OptionalPath{},
Colin Cross6c6e6cd2019-05-08 14:30:12 -07001660 false, nil, []string{"META-INF/TRANSITIVE"})
Colin Cross5c6ecc12017-10-23 18:12:27 -07001661 headerJar = combinedJar
Nan Zhanged19fc32017-10-19 13:06:22 -07001662
Steven Morelandc4efd9c2019-01-18 11:51:25 -08001663 if j.expandJarjarRules != nil {
Nan Zhanged19fc32017-10-19 13:06:22 -07001664 // Transform classes.jar into classes-jarjar.jar
1665 jarjarFile := android.PathForModuleOut(ctx, "turbine-jarjar", jarName)
Steven Morelandc4efd9c2019-01-18 11:51:25 -08001666 TransformJarJar(ctx, jarjarFile, headerJar, j.expandJarjarRules)
Nan Zhanged19fc32017-10-19 13:06:22 -07001667 headerJar = jarjarFile
1668 if ctx.Failed() {
1669 return nil
1670 }
1671 }
1672
1673 return headerJar
1674}
1675
Colin Crosscb933592017-11-22 13:49:43 -08001676func (j *Module) instrument(ctx android.ModuleContext, flags javaBuilderFlags,
Colin Cross3063b782018-08-15 11:19:12 -07001677 classesJar android.Path, jarName string) android.ModuleOutPath {
Colin Crosscb933592017-11-22 13:49:43 -08001678
Colin Cross7a3139e2017-12-19 13:57:50 -08001679 specs := j.jacocoModuleToZipCommand(ctx)
Colin Crosscb933592017-11-22 13:49:43 -08001680
Colin Cross84c38822018-01-03 15:59:46 -08001681 jacocoReportClassesFile := android.PathForModuleOut(ctx, "jacoco-report-classes", jarName)
Colin Crosscb933592017-11-22 13:49:43 -08001682 instrumentedJar := android.PathForModuleOut(ctx, "jacoco", jarName)
1683
1684 jacocoInstrumentJar(ctx, instrumentedJar, jacocoReportClassesFile, classesJar, specs)
1685
1686 j.jacocoReportClassesFile = jacocoReportClassesFile
1687
1688 return instrumentedJar
1689}
1690
albaltai36ff7dc2018-12-25 14:35:23 +08001691var _ Dependency = (*Module)(nil)
Colin Cross2fe66872015-03-30 17:20:39 -07001692
Nan Zhanged19fc32017-10-19 13:06:22 -07001693func (j *Module) HeaderJars() android.Paths {
albaltai36ff7dc2018-12-25 14:35:23 +08001694 if j.headerJarFile == nil {
1695 return nil
1696 }
Nan Zhanged19fc32017-10-19 13:06:22 -07001697 return android.Paths{j.headerJarFile}
1698}
1699
1700func (j *Module) ImplementationJars() android.Paths {
shinwang9e4c07a2018-12-24 15:41:04 +08001701 if j.implementationJarFile == nil {
1702 return nil
1703 }
Nan Zhanged19fc32017-10-19 13:06:22 -07001704 return android.Paths{j.implementationJarFile}
Colin Cross2fe66872015-03-30 17:20:39 -07001705}
1706
Colin Crossf24a22a2019-01-31 14:12:44 -08001707func (j *Module) DexJar() android.Path {
1708 return j.dexJarFile
1709}
1710
Colin Cross331a1212018-08-15 20:40:52 -07001711func (j *Module) ResourceJars() android.Paths {
1712 if j.resourceJar == nil {
1713 return nil
1714 }
1715 return android.Paths{j.resourceJar}
1716}
1717
1718func (j *Module) ImplementationAndResourcesJars() android.Paths {
albaltai36ff7dc2018-12-25 14:35:23 +08001719 if j.implementationAndResourcesJar == nil {
1720 return nil
1721 }
Colin Cross331a1212018-08-15 20:40:52 -07001722 return android.Paths{j.implementationAndResourcesJar}
1723}
1724
Colin Cross46c9b8b2017-06-22 16:51:17 -07001725func (j *Module) AidlIncludeDirs() android.Paths {
albaltai36ff7dc2018-12-25 14:35:23 +08001726 // exportAidlIncludeDirs is type android.Paths already
Colin Crossc0b06f12015-04-08 13:03:43 -07001727 return j.exportAidlIncludeDirs
1728}
1729
Jiyong Park1be96912018-05-28 18:02:19 +09001730func (j *Module) ExportedSdkLibs() []string {
albaltai36ff7dc2018-12-25 14:35:23 +08001731 // exportedSdkLibs is type []string
Jiyong Park1be96912018-05-28 18:02:19 +09001732 return j.exportedSdkLibs
1733}
1734
Artur Satayev9cf46692019-11-26 18:08:34 +00001735func (j *Module) ExportedPlugins() (android.Paths, []string) {
1736 return j.exportedPluginJars, j.exportedPluginClasses
1737}
1738
Colin Cross0c4ce212019-05-03 15:28:19 -07001739func (j *Module) SrcJarArgs() ([]string, android.Paths) {
1740 return j.srcJarArgs, j.srcJarDeps
1741}
1742
Colin Cross46c9b8b2017-06-22 16:51:17 -07001743var _ logtagsProducer = (*Module)(nil)
Colin Crossf05fe972015-04-10 17:45:20 -07001744
Colin Cross46c9b8b2017-06-22 16:51:17 -07001745func (j *Module) logtags() android.Paths {
Colin Crossf05fe972015-04-10 17:45:20 -07001746 return j.logtagsSrcs
1747}
1748
Brandon Lee5d45c6f2018-08-15 15:35:38 -07001749// Collect information for opening IDE project files in java/jdeps.go.
1750func (j *Module) IDEInfo(dpInfo *android.IdeInfo) {
1751 dpInfo.Deps = append(dpInfo.Deps, j.CompilerDeps()...)
1752 dpInfo.Srcs = append(dpInfo.Srcs, j.expandIDEInfoCompiledSrcs...)
patricktu18c82ff2019-05-10 15:48:50 +08001753 dpInfo.SrcJars = append(dpInfo.SrcJars, j.compiledSrcJars.Strings()...)
Brandon Lee5d45c6f2018-08-15 15:35:38 -07001754 dpInfo.Aidl_include_dirs = append(dpInfo.Aidl_include_dirs, j.deviceProperties.Aidl.Include_dirs...)
Steven Morelandc4efd9c2019-01-18 11:51:25 -08001755 if j.expandJarjarRules != nil {
1756 dpInfo.Jarjar_rules = append(dpInfo.Jarjar_rules, j.expandJarjarRules.String())
Brandon Lee5d45c6f2018-08-15 15:35:38 -07001757 }
1758}
1759
1760func (j *Module) CompilerDeps() []string {
1761 jdeps := []string{}
1762 jdeps = append(jdeps, j.properties.Libs...)
1763 jdeps = append(jdeps, j.properties.Static_libs...)
1764 return jdeps
1765}
1766
Jaewoong Jungc27ab662019-05-30 15:51:14 -07001767func (j *Module) hasCode(ctx android.ModuleContext) bool {
1768 srcFiles := android.PathsForModuleSrcExcludes(ctx, j.properties.Srcs, j.properties.Exclude_srcs)
1769 return len(srcFiles) > 0 || len(ctx.GetDirectDepsWithTag(staticLibTag)) > 0
1770}
1771
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09001772func (j *Module) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
1773 depTag := ctx.OtherModuleDependencyTag(dep)
Jiyong Park0f80c182020-01-31 02:49:53 +09001774 // Dependencies other than the static linkage are all considered crossing APEX boundary
1775 // Also, a dependency to an sdk member is also considered as such. This is required because
1776 // sdk members should be mutated into APEXes. Refer to sdk.sdkDepsReplaceMutator.
1777 return depTag == staticLibTag || j.IsInAnySdk()
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09001778}
1779
Jiyong Park0b238752019-10-29 11:23:10 +09001780func (j *Module) Stem() string {
1781 return proptools.StringDefault(j.deviceProperties.Stem, j.Name())
1782}
1783
Jiyong Park618922e2020-01-08 13:35:43 +09001784func (j *Module) JacocoReportClassesFile() android.Path {
1785 return j.jacocoReportClassesFile
1786}
1787
Martin Stjernholm6d415272020-01-31 17:10:36 +00001788func (j *Module) IsInstallable() bool {
1789 return Bool(j.properties.Installable)
1790}
1791
Colin Cross2fe66872015-03-30 17:20:39 -07001792//
1793// Java libraries (.jar file)
1794//
1795
Colin Crossf506d872017-07-19 15:53:04 -07001796type Library struct {
Colin Cross46c9b8b2017-06-22 16:51:17 -07001797 Module
Colin Crossf0f2e2c2019-10-15 16:36:40 -07001798
1799 InstallMixin func(ctx android.ModuleContext, installPath android.Path) (extraInstallDeps android.Paths)
Colin Cross2fe66872015-03-30 17:20:39 -07001800}
1801
Colin Cross42be7612019-02-21 18:12:14 -08001802func shouldUncompressDex(ctx android.ModuleContext, dexpreopter *dexpreopter) bool {
Ulya Trafimovichf491dde2020-01-24 12:19:45 +00001803 // Store uncompressed (and aligned) any dex files from jars in APEXes.
1804 if am, ok := ctx.Module().(android.ApexModule); ok && !am.IsForPlatform() {
1805 return true
1806 }
1807
Nicolas Geoffrayfa6e9ec2019-02-12 13:12:16 +00001808 // Store uncompressed (and do not strip) dex files from boot class path jars.
1809 if inList(ctx.ModuleName(), ctx.Config().BootJars()) {
1810 return true
1811 }
1812
1813 // Store uncompressed dex files that are preopted on /system.
Colin Cross42be7612019-02-21 18:12:14 -08001814 if !dexpreopter.dexpreoptDisabled(ctx) && (ctx.Host() || !odexOnSystemOther(ctx, dexpreopter.installPath)) {
Vladimir Markoe8b00d62018-12-21 15:54:16 +00001815 return true
1816 }
Colin Cross083a2aa2019-02-06 16:37:12 -08001817 if ctx.Config().UncompressPrivAppDex() &&
1818 inList(ctx.ModuleName(), ctx.Config().ModulesLoadedByPrivilegedModules()) {
1819 return true
1820 }
1821
Colin Cross2fc72f62018-12-21 12:59:54 -08001822 return false
1823}
1824
Colin Crossf506d872017-07-19 15:53:04 -07001825func (j *Library) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Jeongik Cha2cc570d2019-10-29 15:44:45 +09001826 j.checkSdkVersion(ctx)
Jiyong Park0b238752019-10-29 11:23:10 +09001827 j.dexpreopter.installPath = android.PathForModuleInstall(ctx, "framework", j.Stem()+".jar")
Colin Cross43f08db2018-11-12 10:13:39 -08001828 j.dexpreopter.isSDKLibrary = j.deviceProperties.IsSDKLibrary
Colin Cross42be7612019-02-21 18:12:14 -08001829 j.dexpreopter.uncompressedDex = shouldUncompressDex(ctx, &j.dexpreopter)
Nicolas Geoffrayfa6e9ec2019-02-12 13:12:16 +00001830 j.deviceProperties.UncompressDex = j.dexpreopter.uncompressedDex
Jaewoong Junga24af3b2019-05-13 09:23:20 -07001831 j.compile(ctx, nil)
Colin Crossb7a63242015-04-16 14:09:14 -07001832
Jiyong Park7f7766d2019-07-25 22:02:35 +09001833 exclusivelyForApex := android.InAnyApex(ctx.ModuleName()) && !j.IsForPlatform()
1834 if (Bool(j.properties.Installable) || ctx.Host()) && !exclusivelyForApex {
Colin Crossf0f2e2c2019-10-15 16:36:40 -07001835 var extraInstallDeps android.Paths
1836 if j.InstallMixin != nil {
1837 extraInstallDeps = j.InstallMixin(ctx, j.outputFile)
1838 }
Colin Cross2c429dc2017-08-31 16:45:16 -07001839 j.installFile = ctx.InstallFile(android.PathForModuleInstall(ctx, "framework"),
Colin Crossf0f2e2c2019-10-15 16:36:40 -07001840 ctx.ModuleName()+".jar", j.outputFile, extraInstallDeps...)
Colin Cross2c429dc2017-08-31 16:45:16 -07001841 }
Colin Crossb7a63242015-04-16 14:09:14 -07001842}
1843
Colin Crossf506d872017-07-19 15:53:04 -07001844func (j *Library) DepsMutator(ctx android.BottomUpMutatorContext) {
Colin Cross46c9b8b2017-06-22 16:51:17 -07001845 j.deps(ctx)
1846}
1847
Paul Duffin0e0cf1d2019-11-12 19:39:25 +00001848const (
Paul Duffin1b82e6a2019-12-03 18:06:47 +00001849 aidlIncludeDir = "aidl"
1850 javaDir = "java"
1851 jarFileSuffix = ".jar"
1852 testConfigSuffix = "-AndroidTest.xml"
Paul Duffin0e0cf1d2019-11-12 19:39:25 +00001853)
1854
Paul Duffina0dbf432019-12-05 11:25:53 +00001855// path to the jar file of a java library. Relative to <sdk_root>/<api_dir>
Paul Duffin1b82e6a2019-12-03 18:06:47 +00001856func sdkSnapshotFilePathForJar(member android.SdkMember) string {
1857 return sdkSnapshotFilePathForMember(member, jarFileSuffix)
1858}
1859
1860func sdkSnapshotFilePathForMember(member android.SdkMember, suffix string) string {
1861 return filepath.Join(javaDir, member.Name()+suffix)
Paul Duffin0e0cf1d2019-11-12 19:39:25 +00001862}
1863
Paul Duffin13879572019-11-28 14:31:38 +00001864type librarySdkMemberType struct {
Paul Duffin255f18e2019-12-13 11:22:16 +00001865 android.SdkMemberTypeBase
Paul Duffin13879572019-11-28 14:31:38 +00001866}
1867
1868func (mt *librarySdkMemberType) AddDependencies(mctx android.BottomUpMutatorContext, dependencyTag blueprint.DependencyTag, names []string) {
1869 mctx.AddVariationDependencies(nil, dependencyTag, names...)
1870}
1871
1872func (mt *librarySdkMemberType) IsInstance(module android.Module) bool {
1873 _, ok := module.(*Library)
1874 return ok
1875}
1876
Paul Duffina0dbf432019-12-05 11:25:53 +00001877func (mt *librarySdkMemberType) buildSnapshot(
1878 sdkModuleContext android.ModuleContext,
1879 builder android.SnapshotBuilder,
1880 member android.SdkMember,
1881 jarToExportGetter func(j *Library) android.Path) {
1882
Paul Duffin13879572019-11-28 14:31:38 +00001883 variants := member.Variants()
1884 if len(variants) != 1 {
1885 sdkModuleContext.ModuleErrorf("sdk contains %d variants of member %q but only one is allowed", len(variants), member.Name())
1886 for _, variant := range variants {
1887 sdkModuleContext.ModuleErrorf(" %q", variant)
1888 }
1889 }
1890 variant := variants[0]
1891 j := variant.(*Library)
1892
Paul Duffina0dbf432019-12-05 11:25:53 +00001893 exportedJar := jarToExportGetter(j)
Paul Duffin1b82e6a2019-12-03 18:06:47 +00001894 snapshotRelativeJavaLibPath := sdkSnapshotFilePathForJar(member)
Paul Duffina0dbf432019-12-05 11:25:53 +00001895 builder.CopyToSnapshot(exportedJar, snapshotRelativeJavaLibPath)
Paul Duffin0e0cf1d2019-11-12 19:39:25 +00001896
1897 for _, dir := range j.AidlIncludeDirs() {
1898 // TODO(jiyong): copy parcelable declarations only
1899 aidlFiles, _ := sdkModuleContext.GlobWithDeps(dir.String()+"/**/*.aidl", nil)
1900 for _, file := range aidlFiles {
1901 builder.CopyToSnapshot(android.PathForSource(sdkModuleContext, file), filepath.Join(aidlIncludeDir, file))
1902 }
1903 }
1904
Paul Duffin9d8d6092019-12-05 18:19:29 +00001905 module := builder.AddPrebuiltModule(member, "java_import")
Paul Duffinb645ec82019-11-27 17:43:54 +00001906 module.AddProperty("jars", []string{snapshotRelativeJavaLibPath})
Paul Duffin0e0cf1d2019-11-12 19:39:25 +00001907}
1908
Paul Duffin7b81f5e2020-01-13 21:03:22 +00001909var javaHeaderLibsSdkMemberType android.SdkMemberType = &headerLibrarySdkMemberType{
1910 librarySdkMemberType{
1911 android.SdkMemberTypeBase{
1912 PropertyName: "java_header_libs",
1913 SupportsSdk: true,
1914 },
1915 },
1916}
1917
Paul Duffina0dbf432019-12-05 11:25:53 +00001918type headerLibrarySdkMemberType struct {
1919 librarySdkMemberType
1920}
1921
1922func (mt *headerLibrarySdkMemberType) BuildSnapshot(sdkModuleContext android.ModuleContext, builder android.SnapshotBuilder, member android.SdkMember) {
1923 mt.librarySdkMemberType.buildSnapshot(sdkModuleContext, builder, member, func(j *Library) android.Path {
1924 headerJars := j.HeaderJars()
1925 if len(headerJars) != 1 {
1926 panic(fmt.Errorf("there must be only one header jar from %q", j.Name()))
1927 }
1928
1929 return headerJars[0]
1930 })
1931}
1932
Paul Duffina0dbf432019-12-05 11:25:53 +00001933type implLibrarySdkMemberType struct {
1934 librarySdkMemberType
1935}
1936
1937func (mt *implLibrarySdkMemberType) BuildSnapshot(sdkModuleContext android.ModuleContext, builder android.SnapshotBuilder, member android.SdkMember) {
1938 mt.librarySdkMemberType.buildSnapshot(sdkModuleContext, builder, member, func(j *Library) android.Path {
1939 implementationJars := j.ImplementationJars()
1940 if len(implementationJars) != 1 {
1941 panic(fmt.Errorf("there must be only one implementation jar from %q", j.Name()))
1942 }
1943
1944 return implementationJars[0]
1945 })
1946}
1947
Colin Cross1b16b0e2019-02-12 14:41:32 -08001948// java_library builds and links sources into a `.jar` file for the device, and possibly for the host as well.
1949//
1950// By default, a java_library has a single variant that produces a `.jar` file containing `.class` files that were
1951// compiled against the device bootclasspath. This jar is not suitable for installing on a device, but can be used
1952// as a `static_libs` dependency of another module.
1953//
1954// Specifying `installable: true` will product a `.jar` file containing `classes.dex` files, suitable for installing on
1955// a device.
1956//
1957// Specifying `host_supported: true` will produce two variants, one compiled against the device bootclasspath and one
1958// compiled against the host bootclasspath.
Colin Cross9ae1b922018-06-26 17:59:05 -07001959func LibraryFactory() android.Module {
1960 module := &Library{}
Colin Cross2fe66872015-03-30 17:20:39 -07001961
Colin Cross9ae1b922018-06-26 17:59:05 -07001962 module.AddProperties(
1963 &module.Module.properties,
1964 &module.Module.deviceProperties,
Colin Cross43f08db2018-11-12 10:13:39 -08001965 &module.Module.dexpreoptProperties,
Colin Cross9ae1b922018-06-26 17:59:05 -07001966 &module.Module.protoProperties)
Colin Cross2fe66872015-03-30 17:20:39 -07001967
Jiyong Park7f7766d2019-07-25 22:02:35 +09001968 android.InitApexModule(module)
Jiyong Parkd1063c12019-07-17 20:08:41 +09001969 android.InitSdkAwareModule(module)
Jooyung Han18020ea2019-11-13 10:50:48 +09001970 InitJavaModule(module, android.HostAndDeviceSupported)
Colin Cross9ae1b922018-06-26 17:59:05 -07001971 return module
Colin Cross2fe66872015-03-30 17:20:39 -07001972}
1973
Colin Cross1b16b0e2019-02-12 14:41:32 -08001974// java_library_static is an obsolete alias for java_library.
1975func LibraryStaticFactory() android.Module {
1976 return LibraryFactory()
1977}
1978
1979// java_library_host builds and links sources into a `.jar` file for the host.
1980//
1981// A java_library_host has a single variant that produces a `.jar` file containing `.class` files that were
1982// compiled against the host bootclasspath.
Colin Crossf506d872017-07-19 15:53:04 -07001983func LibraryHostFactory() android.Module {
1984 module := &Library{}
Colin Cross2fe66872015-03-30 17:20:39 -07001985
Colin Cross6af17aa2017-09-20 12:59:05 -07001986 module.AddProperties(
1987 &module.Module.properties,
1988 &module.Module.protoProperties)
Colin Cross36242852017-06-23 15:06:31 -07001989
Colin Cross9ae1b922018-06-26 17:59:05 -07001990 module.Module.properties.Installable = proptools.BoolPtr(true)
1991
Jiyong Park7f7766d2019-07-25 22:02:35 +09001992 android.InitApexModule(module)
Jooyung Han18020ea2019-11-13 10:50:48 +09001993 InitJavaModule(module, android.HostSupported)
Colin Cross36242852017-06-23 15:06:31 -07001994 return module
Colin Cross2fe66872015-03-30 17:20:39 -07001995}
1996
1997//
Colin Crossb628ea52018-08-14 16:42:33 -07001998// Java Tests
Colin Cross05638fc2018-04-09 18:40:24 -07001999//
2000
2001type testProperties struct {
Colin Cross05638fc2018-04-09 18:40:24 -07002002 // list of compatibility suites (for example "cts", "vts") that the module should be
2003 // installed into.
2004 Test_suites []string `android:"arch_variant"`
Julien Despreze146e392018-08-02 15:00:46 -07002005
2006 // the name of the test configuration (for example "AndroidTest.xml") that should be
2007 // installed with the module.
Colin Cross27b922f2019-03-04 22:35:41 -08002008 Test_config *string `android:"path,arch_variant"`
Colin Crossd96ca352018-08-10 16:06:24 -07002009
Jack He33338892018-09-19 02:21:28 -07002010 // the name of the test configuration template (for example "AndroidTestTemplate.xml") that
2011 // should be installed with the module.
Colin Cross27b922f2019-03-04 22:35:41 -08002012 Test_config_template *string `android:"path,arch_variant"`
Jack He33338892018-09-19 02:21:28 -07002013
Colin Crossd96ca352018-08-10 16:06:24 -07002014 // list of files or filegroup modules that provide data that should be installed alongside
2015 // the test
Colin Cross27b922f2019-03-04 22:35:41 -08002016 Data []string `android:"path"`
Dan Shi6ffaaa82019-09-26 11:41:36 -07002017
2018 // Flag to indicate whether or not to create test config automatically. If AndroidTest.xml
2019 // doesn't exist next to the Android.bp, this attribute doesn't need to be set to true
2020 // explicitly.
2021 Auto_gen_config *bool
Colin Cross05638fc2018-04-09 18:40:24 -07002022}
2023
Paul Duffin42df1442019-03-20 12:45:53 +00002024type testHelperLibraryProperties struct {
2025 // list of compatibility suites (for example "cts", "vts") that the module should be
2026 // installed into.
2027 Test_suites []string `android:"arch_variant"`
2028}
2029
Paul Duffin1b82e6a2019-12-03 18:06:47 +00002030type prebuiltTestProperties struct {
2031 // list of compatibility suites (for example "cts", "vts") that the module should be
2032 // installed into.
2033 Test_suites []string `android:"arch_variant"`
2034
2035 // the name of the test configuration (for example "AndroidTest.xml") that should be
2036 // installed with the module.
2037 Test_config *string `android:"path,arch_variant"`
2038}
2039
Colin Cross05638fc2018-04-09 18:40:24 -07002040type Test struct {
2041 Library
2042
2043 testProperties testProperties
Colin Cross303e21f2018-08-07 16:49:25 -07002044
2045 testConfig android.Path
Colin Crossd96ca352018-08-10 16:06:24 -07002046 data android.Paths
Colin Cross303e21f2018-08-07 16:49:25 -07002047}
2048
Paul Duffin42df1442019-03-20 12:45:53 +00002049type TestHelperLibrary struct {
2050 Library
2051
2052 testHelperLibraryProperties testHelperLibraryProperties
2053}
2054
Paul Duffin1b82e6a2019-12-03 18:06:47 +00002055type JavaTestImport struct {
2056 Import
2057
2058 prebuiltTestProperties prebuiltTestProperties
2059
2060 testConfig android.Path
2061}
2062
Colin Cross303e21f2018-08-07 16:49:25 -07002063func (j *Test) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Dan Shi6ffaaa82019-09-26 11:41:36 -07002064 j.testConfig = tradefed.AutoGenJavaTestConfig(ctx, j.testProperties.Test_config, j.testProperties.Test_config_template,
2065 j.testProperties.Test_suites, j.testProperties.Auto_gen_config)
Colin Cross8a497952019-03-05 22:25:09 -08002066 j.data = android.PathsForModuleSrc(ctx, j.testProperties.Data)
Colin Cross303e21f2018-08-07 16:49:25 -07002067
2068 j.Library.GenerateAndroidBuildActions(ctx)
Colin Cross05638fc2018-04-09 18:40:24 -07002069}
2070
Paul Duffin42df1442019-03-20 12:45:53 +00002071func (j *TestHelperLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
2072 j.Library.GenerateAndroidBuildActions(ctx)
2073}
2074
Paul Duffin1b82e6a2019-12-03 18:06:47 +00002075func (j *JavaTestImport) GenerateAndroidBuildActions(ctx android.ModuleContext) {
2076 j.testConfig = tradefed.AutoGenJavaTestConfig(ctx, j.prebuiltTestProperties.Test_config, nil,
2077 j.prebuiltTestProperties.Test_suites, nil)
2078
2079 j.Import.GenerateAndroidBuildActions(ctx)
2080}
2081
2082type testSdkMemberType struct {
2083 android.SdkMemberTypeBase
2084}
2085
2086func (mt *testSdkMemberType) AddDependencies(mctx android.BottomUpMutatorContext, dependencyTag blueprint.DependencyTag, names []string) {
2087 mctx.AddVariationDependencies(nil, dependencyTag, names...)
2088}
2089
2090func (mt *testSdkMemberType) IsInstance(module android.Module) bool {
2091 _, ok := module.(*Test)
2092 return ok
2093}
2094
2095func (mt *testSdkMemberType) BuildSnapshot(sdkModuleContext android.ModuleContext, builder android.SnapshotBuilder, member android.SdkMember) {
2096 variants := member.Variants()
2097 if len(variants) != 1 {
2098 sdkModuleContext.ModuleErrorf("sdk contains %d variants of member %q but only one is allowed", len(variants), member.Name())
2099 for _, variant := range variants {
2100 sdkModuleContext.ModuleErrorf(" %q", variant)
2101 }
2102 }
2103 variant := variants[0]
2104 j := variant.(*Test)
2105
2106 implementationJars := j.ImplementationJars()
2107 if len(implementationJars) != 1 {
2108 panic(fmt.Errorf("there must be only one implementation jar from %q", j.Name()))
2109 }
2110
2111 snapshotRelativeJavaLibPath := sdkSnapshotFilePathForJar(member)
2112 builder.CopyToSnapshot(implementationJars[0], snapshotRelativeJavaLibPath)
2113
2114 snapshotRelativeTestConfigPath := sdkSnapshotFilePathForMember(member, testConfigSuffix)
2115 builder.CopyToSnapshot(j.testConfig, snapshotRelativeTestConfigPath)
2116
2117 module := builder.AddPrebuiltModule(member, "java_test_import")
2118 module.AddProperty("jars", []string{snapshotRelativeJavaLibPath})
2119 module.AddProperty("test_config", snapshotRelativeTestConfigPath)
2120}
2121
Colin Cross1b16b0e2019-02-12 14:41:32 -08002122// java_test builds a and links sources into a `.jar` file for the device, and possibly for the host as well, and
2123// creates an `AndroidTest.xml` file to allow running the test with `atest` or a `TEST_MAPPING` file.
2124//
2125// By default, a java_test has a single variant that produces a `.jar` file containing `classes.dex` files that were
2126// compiled against the device bootclasspath.
2127//
2128// Specifying `host_supported: true` will produce two variants, one compiled against the device bootclasspath and one
2129// compiled against the host bootclasspath.
Colin Cross05638fc2018-04-09 18:40:24 -07002130func TestFactory() android.Module {
2131 module := &Test{}
2132
2133 module.AddProperties(
2134 &module.Module.properties,
2135 &module.Module.deviceProperties,
Colin Cross43f08db2018-11-12 10:13:39 -08002136 &module.Module.dexpreoptProperties,
Colin Cross05638fc2018-04-09 18:40:24 -07002137 &module.Module.protoProperties,
2138 &module.testProperties)
2139
Colin Cross9ae1b922018-06-26 17:59:05 -07002140 module.Module.properties.Installable = proptools.BoolPtr(true)
Colin Crosse3026872019-01-05 22:30:13 -08002141 module.Module.dexpreopter.isTest = true
Colin Cross9ae1b922018-06-26 17:59:05 -07002142
Colin Cross05638fc2018-04-09 18:40:24 -07002143 InitJavaModule(module, android.HostAndDeviceSupported)
Colin Cross05638fc2018-04-09 18:40:24 -07002144 return module
2145}
2146
Paul Duffin42df1442019-03-20 12:45:53 +00002147// java_test_helper_library creates a java library and makes sure that it is added to the appropriate test suite.
2148func TestHelperLibraryFactory() android.Module {
2149 module := &TestHelperLibrary{}
2150
2151 module.AddProperties(
2152 &module.Module.properties,
2153 &module.Module.deviceProperties,
2154 &module.Module.dexpreoptProperties,
2155 &module.Module.protoProperties,
2156 &module.testHelperLibraryProperties)
2157
Colin Cross9a4abed2019-04-24 13:19:28 -07002158 module.Module.properties.Installable = proptools.BoolPtr(true)
2159 module.Module.dexpreopter.isTest = true
2160
Paul Duffin42df1442019-03-20 12:45:53 +00002161 InitJavaModule(module, android.HostAndDeviceSupported)
2162 return module
2163}
2164
Paul Duffin1b82e6a2019-12-03 18:06:47 +00002165// java_test_import imports one or more `.jar` files into the build graph as if they were built by a java_test module
2166// and makes sure that it is added to the appropriate test suite.
2167//
2168// By default, a java_test_import has a single variant that expects a `.jar` file containing `.class` files that were
2169// compiled against an Android classpath.
2170//
2171// Specifying `host_supported: true` will produce two variants, one for use as a dependency of device modules and one
2172// for host modules.
2173func JavaTestImportFactory() android.Module {
2174 module := &JavaTestImport{}
2175
2176 module.AddProperties(
2177 &module.Import.properties,
2178 &module.prebuiltTestProperties)
2179
2180 module.Import.properties.Installable = proptools.BoolPtr(true)
2181
2182 android.InitPrebuiltModule(module, &module.properties.Jars)
2183 android.InitApexModule(module)
2184 android.InitSdkAwareModule(module)
2185 InitJavaModule(module, android.HostAndDeviceSupported)
2186 return module
2187}
2188
Colin Cross1b16b0e2019-02-12 14:41:32 -08002189// java_test_host builds a and links sources into a `.jar` file for the host, and creates an `AndroidTest.xml` file to
2190// allow running the test with `atest` or a `TEST_MAPPING` file.
2191//
2192// A java_test_host has a single variant that produces a `.jar` file containing `.class` files that were
2193// compiled against the host bootclasspath.
Colin Cross05638fc2018-04-09 18:40:24 -07002194func TestHostFactory() android.Module {
2195 module := &Test{}
2196
2197 module.AddProperties(
2198 &module.Module.properties,
2199 &module.Module.protoProperties,
2200 &module.testProperties)
2201
Colin Cross9ae1b922018-06-26 17:59:05 -07002202 module.Module.properties.Installable = proptools.BoolPtr(true)
2203
Colin Cross05638fc2018-04-09 18:40:24 -07002204 InitJavaModule(module, android.HostSupported)
Colin Cross05638fc2018-04-09 18:40:24 -07002205 return module
2206}
2207
2208//
Colin Cross2fe66872015-03-30 17:20:39 -07002209// Java Binaries (.jar file plus wrapper script)
2210//
2211
Colin Crossf506d872017-07-19 15:53:04 -07002212type binaryProperties struct {
Colin Cross7d5136f2015-05-11 13:39:40 -07002213 // installable script to execute the resulting jar
Colin Cross27b922f2019-03-04 22:35:41 -08002214 Wrapper *string `android:"path"`
Colin Cross094054a2018-10-17 15:10:48 -07002215
2216 // Name of the class containing main to be inserted into the manifest as Main-Class.
2217 Main_class *string
Colin Cross7d5136f2015-05-11 13:39:40 -07002218}
2219
Colin Crossf506d872017-07-19 15:53:04 -07002220type Binary struct {
2221 Library
Colin Cross2fe66872015-03-30 17:20:39 -07002222
Colin Crossf506d872017-07-19 15:53:04 -07002223 binaryProperties binaryProperties
Colin Cross10a03492017-08-10 17:09:43 -07002224
Colin Cross6b4a32d2017-12-05 13:42:45 -08002225 isWrapperVariant bool
2226
Colin Crossc3315992017-12-08 19:12:36 -08002227 wrapperFile android.Path
Colin Cross70dda7e2019-10-01 22:05:35 -07002228 binaryFile android.InstallPath
Colin Cross2fe66872015-03-30 17:20:39 -07002229}
2230
Alex Light24237172017-10-26 09:46:21 -07002231func (j *Binary) HostToolPath() android.OptionalPath {
2232 return android.OptionalPathForPath(j.binaryFile)
2233}
2234
Colin Crossf506d872017-07-19 15:53:04 -07002235func (j *Binary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross6b4a32d2017-12-05 13:42:45 -08002236 if ctx.Arch().ArchType == android.Common {
2237 // Compile the jar
Colin Cross094054a2018-10-17 15:10:48 -07002238 if j.binaryProperties.Main_class != nil {
2239 if j.properties.Manifest != nil {
2240 ctx.PropertyErrorf("main_class", "main_class cannot be used when manifest is set")
2241 }
2242 manifestFile := android.PathForModuleOut(ctx, "manifest.txt")
2243 GenerateMainClassManifest(ctx, manifestFile, String(j.binaryProperties.Main_class))
2244 j.overrideManifest = android.OptionalPathForPath(manifestFile)
2245 }
2246
Colin Cross6b4a32d2017-12-05 13:42:45 -08002247 j.Library.GenerateAndroidBuildActions(ctx)
Nan Zhang3c807db2017-11-03 14:53:31 -07002248 } else {
Colin Cross6b4a32d2017-12-05 13:42:45 -08002249 // Handle the binary wrapper
2250 j.isWrapperVariant = true
2251
Colin Cross366938f2017-12-11 16:29:02 -08002252 if j.binaryProperties.Wrapper != nil {
Colin Cross8a497952019-03-05 22:25:09 -08002253 j.wrapperFile = android.PathForModuleSrc(ctx, *j.binaryProperties.Wrapper)
Colin Cross6b4a32d2017-12-05 13:42:45 -08002254 } else {
2255 j.wrapperFile = android.PathForSource(ctx, "build/soong/scripts/jar-wrapper.sh")
2256 }
2257
2258 // Depend on the installed jar so that the wrapper doesn't get executed by
2259 // another build rule before the jar has been installed.
2260 jarFile := ctx.PrimaryModule().(*Binary).installFile
2261
2262 j.binaryFile = ctx.InstallExecutable(android.PathForModuleInstall(ctx, "bin"),
2263 ctx.ModuleName(), j.wrapperFile, jarFile)
Nan Zhang3c807db2017-11-03 14:53:31 -07002264 }
Colin Cross2fe66872015-03-30 17:20:39 -07002265}
2266
Colin Crossf506d872017-07-19 15:53:04 -07002267func (j *Binary) DepsMutator(ctx android.BottomUpMutatorContext) {
Colin Cross6b4a32d2017-12-05 13:42:45 -08002268 if ctx.Arch().ArchType == android.Common {
2269 j.deps(ctx)
2270 }
Colin Cross46c9b8b2017-06-22 16:51:17 -07002271}
2272
Colin Cross1b16b0e2019-02-12 14:41:32 -08002273// java_binary builds a `.jar` file and a shell script that executes it for the device, and possibly for the host
2274// as well.
2275//
2276// By default, a java_binary has a single variant that produces a `.jar` file containing `classes.dex` files that were
2277// compiled against the device bootclasspath.
2278//
2279// Specifying `host_supported: true` will produce two variants, one compiled against the device bootclasspath and one
2280// compiled against the host bootclasspath.
Colin Crossf506d872017-07-19 15:53:04 -07002281func BinaryFactory() android.Module {
2282 module := &Binary{}
Colin Cross2fe66872015-03-30 17:20:39 -07002283
Colin Cross36242852017-06-23 15:06:31 -07002284 module.AddProperties(
Colin Cross540eff82017-06-22 17:01:52 -07002285 &module.Module.properties,
2286 &module.Module.deviceProperties,
Colin Cross43f08db2018-11-12 10:13:39 -08002287 &module.Module.dexpreoptProperties,
Colin Cross6af17aa2017-09-20 12:59:05 -07002288 &module.Module.protoProperties,
Colin Cross540eff82017-06-22 17:01:52 -07002289 &module.binaryProperties)
Colin Cross36242852017-06-23 15:06:31 -07002290
Colin Cross9ae1b922018-06-26 17:59:05 -07002291 module.Module.properties.Installable = proptools.BoolPtr(true)
2292
Colin Cross6b4a32d2017-12-05 13:42:45 -08002293 android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibCommonFirst)
2294 android.InitDefaultableModule(module)
Colin Cross36242852017-06-23 15:06:31 -07002295 return module
Colin Cross2fe66872015-03-30 17:20:39 -07002296}
2297
Colin Cross1b16b0e2019-02-12 14:41:32 -08002298// java_binary_host builds a `.jar` file and a shell script that executes it for the host.
2299//
2300// A java_binary_host has a single variant that produces a `.jar` file containing `.class` files that were
2301// compiled against the host bootclasspath.
Colin Crossf506d872017-07-19 15:53:04 -07002302func BinaryHostFactory() android.Module {
2303 module := &Binary{}
Colin Cross2fe66872015-03-30 17:20:39 -07002304
Colin Cross36242852017-06-23 15:06:31 -07002305 module.AddProperties(
Colin Cross540eff82017-06-22 17:01:52 -07002306 &module.Module.properties,
Colin Cross6af17aa2017-09-20 12:59:05 -07002307 &module.Module.protoProperties,
Colin Cross540eff82017-06-22 17:01:52 -07002308 &module.binaryProperties)
Colin Cross36242852017-06-23 15:06:31 -07002309
Colin Cross9ae1b922018-06-26 17:59:05 -07002310 module.Module.properties.Installable = proptools.BoolPtr(true)
2311
Colin Cross6b4a32d2017-12-05 13:42:45 -08002312 android.InitAndroidArchModule(module, android.HostSupported, android.MultilibCommonFirst)
2313 android.InitDefaultableModule(module)
Colin Cross36242852017-06-23 15:06:31 -07002314 return module
Colin Cross2fe66872015-03-30 17:20:39 -07002315}
2316
2317//
2318// Java prebuilts
2319//
2320
Colin Cross74d73e22017-08-02 11:05:49 -07002321type ImportProperties struct {
Colin Cross27b922f2019-03-04 22:35:41 -08002322 Jars []string `android:"path"`
Colin Cross461bd1a2017-10-20 13:59:18 -07002323
Nan Zhangea568a42017-11-08 21:20:04 -08002324 Sdk_version *string
Colin Cross535e2cf2017-10-20 17:57:49 -07002325
2326 Installable *bool
Jiyong Park1be96912018-05-28 18:02:19 +09002327
2328 // List of shared java libs that this module has dependencies to
2329 Libs []string
Colin Cross37f6d792018-07-12 12:28:41 -07002330
2331 // List of files to remove from the jar file(s)
2332 Exclude_files []string
2333
2334 // List of directories to remove from the jar file(s)
2335 Exclude_dirs []string
Nan Zhang4c819fb2018-08-27 18:31:46 -07002336
2337 // if set to true, run Jetifier against .jar file. Defaults to false.
Colin Cross1001a792019-03-21 22:21:39 -07002338 Jetifier *bool
Jiyong Park4c4c0242019-10-21 14:53:15 +09002339
2340 // set the name of the output
2341 Stem *string
Colin Cross74d73e22017-08-02 11:05:49 -07002342}
2343
2344type Import struct {
Colin Cross635c3b02016-05-18 15:37:25 -07002345 android.ModuleBase
Colin Cross48de9a42018-10-02 13:53:33 -07002346 android.DefaultableModuleBase
Jiyong Park7f7766d2019-07-25 22:02:35 +09002347 android.ApexModuleBase
Colin Crossec7a0422017-07-07 14:47:12 -07002348 prebuilt android.Prebuilt
Jiyong Parkd1063c12019-07-17 20:08:41 +09002349 android.SdkBase
Colin Cross2fe66872015-03-30 17:20:39 -07002350
Colin Cross74d73e22017-08-02 11:05:49 -07002351 properties ImportProperties
2352
Colin Cross0a6e0072017-08-30 14:24:55 -07002353 combinedClasspathFile android.Path
Jiyong Park1be96912018-05-28 18:02:19 +09002354 exportedSdkLibs []string
Colin Cross2fe66872015-03-30 17:20:39 -07002355}
2356
Jiyong Park6a927c42020-01-21 02:03:43 +09002357func (j *Import) sdkVersion() sdkSpec {
2358 return sdkSpecFrom(String(j.properties.Sdk_version))
Colin Cross83bb3162018-06-25 15:48:06 -07002359}
2360
Jiyong Park6a927c42020-01-21 02:03:43 +09002361func (j *Import) minSdkVersion() sdkSpec {
Colin Cross83bb3162018-06-25 15:48:06 -07002362 return j.sdkVersion()
2363}
2364
Colin Cross74d73e22017-08-02 11:05:49 -07002365func (j *Import) Prebuilt() *android.Prebuilt {
Colin Crossec7a0422017-07-07 14:47:12 -07002366 return &j.prebuilt
2367}
2368
Colin Cross74d73e22017-08-02 11:05:49 -07002369func (j *Import) PrebuiltSrcs() []string {
2370 return j.properties.Jars
2371}
2372
2373func (j *Import) Name() string {
Colin Cross5ea9bcc2017-07-27 15:41:32 -07002374 return j.prebuilt.Name(j.ModuleBase.Name())
2375}
2376
Jiyong Park0b238752019-10-29 11:23:10 +09002377func (j *Import) Stem() string {
2378 return proptools.StringDefault(j.properties.Stem, j.ModuleBase.Name())
2379}
2380
Jiyong Park618922e2020-01-08 13:35:43 +09002381func (a *Import) JacocoReportClassesFile() android.Path {
2382 return nil
2383}
2384
Colin Cross74d73e22017-08-02 11:05:49 -07002385func (j *Import) DepsMutator(ctx android.BottomUpMutatorContext) {
Colin Cross42d48b72018-08-29 14:10:52 -07002386 ctx.AddVariationDependencies(nil, libTag, j.properties.Libs...)
Colin Cross1e676be2016-10-12 14:38:15 -07002387}
2388
Colin Cross74d73e22017-08-02 11:05:49 -07002389func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross8a497952019-03-05 22:25:09 -08002390 jars := android.PathsForModuleSrc(ctx, j.properties.Jars)
Colin Crosse1d62a82015-04-03 16:53:05 -07002391
Jiyong Park0b238752019-10-29 11:23:10 +09002392 jarName := j.Stem() + ".jar"
Nan Zhang4c819fb2018-08-27 18:31:46 -07002393 outputFile := android.PathForModuleOut(ctx, "combined", jarName)
Colin Cross37f6d792018-07-12 12:28:41 -07002394 TransformJarsToJar(ctx, outputFile, "for prebuilts", jars, android.OptionalPath{},
2395 false, j.properties.Exclude_files, j.properties.Exclude_dirs)
Colin Cross1001a792019-03-21 22:21:39 -07002396 if Bool(j.properties.Jetifier) {
Nan Zhang4c819fb2018-08-27 18:31:46 -07002397 inputFile := outputFile
2398 outputFile = android.PathForModuleOut(ctx, "jetifier", jarName)
2399 TransformJetifier(ctx, outputFile, inputFile)
2400 }
Colin Crosse9a275b2017-10-16 17:09:48 -07002401 j.combinedClasspathFile = outputFile
Jiyong Park1be96912018-05-28 18:02:19 +09002402
2403 ctx.VisitDirectDeps(func(module android.Module) {
2404 otherName := ctx.OtherModuleName(module)
2405 tag := ctx.OtherModuleDependencyTag(module)
2406
2407 switch dep := module.(type) {
2408 case Dependency:
2409 switch tag {
2410 case libTag, staticLibTag:
2411 // sdk lib names from dependencies are re-exported
2412 j.exportedSdkLibs = append(j.exportedSdkLibs, dep.ExportedSdkLibs()...)
2413 }
2414 case SdkLibraryDependency:
2415 switch tag {
2416 case libTag:
2417 // names of sdk libs that are directly depended are exported
2418 j.exportedSdkLibs = append(j.exportedSdkLibs, otherName)
2419 }
2420 }
2421 })
2422
2423 j.exportedSdkLibs = android.FirstUniqueStrings(j.exportedSdkLibs)
Nan Zhang4973ecf2018-08-10 13:42:12 -07002424 if Bool(j.properties.Installable) {
2425 ctx.InstallFile(android.PathForModuleInstall(ctx, "framework"),
Jiyong Park4c4c0242019-10-21 14:53:15 +09002426 jarName, outputFile)
Nan Zhang4973ecf2018-08-10 13:42:12 -07002427 }
Colin Cross2fe66872015-03-30 17:20:39 -07002428}
2429
Colin Cross74d73e22017-08-02 11:05:49 -07002430var _ Dependency = (*Import)(nil)
Colin Cross2fe66872015-03-30 17:20:39 -07002431
Nan Zhanged19fc32017-10-19 13:06:22 -07002432func (j *Import) HeaderJars() android.Paths {
albaltai36ff7dc2018-12-25 14:35:23 +08002433 if j.combinedClasspathFile == nil {
2434 return nil
2435 }
Colin Cross37f6d792018-07-12 12:28:41 -07002436 return android.Paths{j.combinedClasspathFile}
Nan Zhanged19fc32017-10-19 13:06:22 -07002437}
2438
2439func (j *Import) ImplementationJars() android.Paths {
shinwang9e4c07a2018-12-24 15:41:04 +08002440 if j.combinedClasspathFile == nil {
2441 return nil
2442 }
Colin Cross37f6d792018-07-12 12:28:41 -07002443 return android.Paths{j.combinedClasspathFile}
Colin Cross2fe66872015-03-30 17:20:39 -07002444}
2445
Colin Cross331a1212018-08-15 20:40:52 -07002446func (j *Import) ResourceJars() android.Paths {
2447 return nil
2448}
2449
2450func (j *Import) ImplementationAndResourcesJars() android.Paths {
albaltai36ff7dc2018-12-25 14:35:23 +08002451 if j.combinedClasspathFile == nil {
2452 return nil
2453 }
Colin Cross331a1212018-08-15 20:40:52 -07002454 return android.Paths{j.combinedClasspathFile}
2455}
2456
Colin Crossf24a22a2019-01-31 14:12:44 -08002457func (j *Import) DexJar() android.Path {
2458 return nil
2459}
2460
Colin Cross74d73e22017-08-02 11:05:49 -07002461func (j *Import) AidlIncludeDirs() android.Paths {
Colin Crossc0b06f12015-04-08 13:03:43 -07002462 return nil
2463}
2464
Jiyong Park1be96912018-05-28 18:02:19 +09002465func (j *Import) ExportedSdkLibs() []string {
2466 return j.exportedSdkLibs
2467}
2468
Artur Satayev9cf46692019-11-26 18:08:34 +00002469func (j *Import) ExportedPlugins() (android.Paths, []string) {
2470 return nil, nil
2471}
2472
Colin Cross0c4ce212019-05-03 15:28:19 -07002473func (j *Import) SrcJarArgs() ([]string, android.Paths) {
2474 return nil, nil
2475}
2476
Jiyong Park0f80c182020-01-31 02:49:53 +09002477func (j *Import) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
2478 depTag := ctx.OtherModuleDependencyTag(dep)
2479 // dependencies other than the static linkage are all considered crossing APEX boundary
2480 // Also, a dependency to an sdk member is also considered as such. This is required because
2481 // sdk members should be mutated into APEXes. Refer to sdk.sdkDepsReplaceMutator.
2482 return depTag == staticLibTag || j.IsInAnySdk()
2483}
2484
albaltai36ff7dc2018-12-25 14:35:23 +08002485// Add compile time check for interface implementation
2486var _ android.IDEInfo = (*Import)(nil)
2487var _ android.IDECustomizedModuleName = (*Import)(nil)
2488
Brandon Lee5d45c6f2018-08-15 15:35:38 -07002489// Collect information for opening IDE project files in java/jdeps.go.
2490const (
2491 removedPrefix = "prebuilt_"
2492)
2493
2494func (j *Import) IDEInfo(dpInfo *android.IdeInfo) {
2495 dpInfo.Jars = append(dpInfo.Jars, j.PrebuiltSrcs()...)
2496}
2497
2498func (j *Import) IDECustomizedModuleName() string {
2499 // TODO(b/113562217): Extract the base module name from the Import name, often the Import name
2500 // has a prefix "prebuilt_". Remove the prefix explicitly if needed until we find a better
2501 // solution to get the Import name.
2502 name := j.Name()
2503 if strings.HasPrefix(name, removedPrefix) {
patricktubb640e02018-10-11 18:33:16 +08002504 name = strings.TrimPrefix(name, removedPrefix)
Brandon Lee5d45c6f2018-08-15 15:35:38 -07002505 }
2506 return name
2507}
2508
Colin Cross74d73e22017-08-02 11:05:49 -07002509var _ android.PrebuiltInterface = (*Import)(nil)
Colin Cross2fe66872015-03-30 17:20:39 -07002510
Colin Cross1b16b0e2019-02-12 14:41:32 -08002511// java_import imports one or more `.jar` files into the build graph as if they were built by a java_library module.
2512//
2513// By default, a java_import has a single variant that expects a `.jar` file containing `.class` files that were
2514// compiled against an Android classpath.
2515//
2516// Specifying `host_supported: true` will produce two variants, one for use as a dependency of device modules and one
2517// for host modules.
Colin Cross74d73e22017-08-02 11:05:49 -07002518func ImportFactory() android.Module {
2519 module := &Import{}
Colin Cross36242852017-06-23 15:06:31 -07002520
Colin Cross74d73e22017-08-02 11:05:49 -07002521 module.AddProperties(&module.properties)
2522
2523 android.InitPrebuiltModule(module, &module.properties.Jars)
Jiyong Park7f7766d2019-07-25 22:02:35 +09002524 android.InitApexModule(module)
Jiyong Parkd1063c12019-07-17 20:08:41 +09002525 android.InitSdkAwareModule(module)
Jooyung Han18020ea2019-11-13 10:50:48 +09002526 InitJavaModule(module, android.HostAndDeviceSupported)
Colin Cross36242852017-06-23 15:06:31 -07002527 return module
Colin Cross2fe66872015-03-30 17:20:39 -07002528}
2529
Colin Cross1b16b0e2019-02-12 14:41:32 -08002530// java_import imports one or more `.jar` files into the build graph as if they were built by a java_library_host
2531// module.
2532//
2533// A java_import_host has a single variant that expects a `.jar` file containing `.class` files that were
2534// compiled against a host bootclasspath.
Colin Cross74d73e22017-08-02 11:05:49 -07002535func ImportFactoryHost() android.Module {
2536 module := &Import{}
2537
2538 module.AddProperties(&module.properties)
2539
2540 android.InitPrebuiltModule(module, &module.properties.Jars)
Jiyong Park7f7766d2019-07-25 22:02:35 +09002541 android.InitApexModule(module)
Jooyung Han18020ea2019-11-13 10:50:48 +09002542 InitJavaModule(module, android.HostSupported)
Colin Cross74d73e22017-08-02 11:05:49 -07002543 return module
2544}
2545
Colin Cross42be7612019-02-21 18:12:14 -08002546// dex_import module
2547
2548type DexImportProperties struct {
Colin Cross5cfc70d2019-07-15 13:36:55 -07002549 Jars []string `android:"path"`
Jiyong Park4c4c0242019-10-21 14:53:15 +09002550
2551 // set the name of the output
2552 Stem *string
Colin Cross42be7612019-02-21 18:12:14 -08002553}
2554
2555type DexImport struct {
2556 android.ModuleBase
2557 android.DefaultableModuleBase
Jiyong Park7f7766d2019-07-25 22:02:35 +09002558 android.ApexModuleBase
Colin Cross42be7612019-02-21 18:12:14 -08002559 prebuilt android.Prebuilt
2560
2561 properties DexImportProperties
2562
2563 dexJarFile android.Path
2564 maybeStrippedDexJarFile android.Path
2565
2566 dexpreopter
2567}
2568
2569func (j *DexImport) Prebuilt() *android.Prebuilt {
2570 return &j.prebuilt
2571}
2572
2573func (j *DexImport) PrebuiltSrcs() []string {
2574 return j.properties.Jars
2575}
2576
2577func (j *DexImport) Name() string {
2578 return j.prebuilt.Name(j.ModuleBase.Name())
2579}
2580
Jiyong Park0b238752019-10-29 11:23:10 +09002581func (j *DexImport) Stem() string {
2582 return proptools.StringDefault(j.properties.Stem, j.ModuleBase.Name())
2583}
2584
Martin Stjernholm6d415272020-01-31 17:10:36 +00002585func (j *DexImport) IsInstallable() bool {
2586 return true
2587}
2588
Colin Cross42be7612019-02-21 18:12:14 -08002589func (j *DexImport) GenerateAndroidBuildActions(ctx android.ModuleContext) {
2590 if len(j.properties.Jars) != 1 {
2591 ctx.PropertyErrorf("jars", "exactly one jar must be provided")
2592 }
2593
Jiyong Park0b238752019-10-29 11:23:10 +09002594 j.dexpreopter.installPath = android.PathForModuleInstall(ctx, "framework", j.Stem()+".jar")
Colin Cross42be7612019-02-21 18:12:14 -08002595 j.dexpreopter.uncompressedDex = shouldUncompressDex(ctx, &j.dexpreopter)
2596
2597 inputJar := ctx.ExpandSource(j.properties.Jars[0], "jars")
2598 dexOutputFile := android.PathForModuleOut(ctx, ctx.ModuleName()+".jar")
2599
2600 if j.dexpreopter.uncompressedDex {
2601 rule := android.NewRuleBuilder()
2602
2603 temporary := android.PathForModuleOut(ctx, ctx.ModuleName()+".jar.unaligned")
2604 rule.Temporary(temporary)
2605
2606 // use zip2zip to uncompress classes*.dex files
2607 rule.Command().
Colin Crossee94d6a2019-07-08 17:08:34 -07002608 BuiltTool(ctx, "zip2zip").
Colin Cross42be7612019-02-21 18:12:14 -08002609 FlagWithInput("-i ", inputJar).
2610 FlagWithOutput("-o ", temporary).
2611 FlagWithArg("-0 ", "'classes*.dex'")
2612
2613 // use zipalign to align uncompressed classes*.dex files
2614 rule.Command().
Colin Crossee94d6a2019-07-08 17:08:34 -07002615 BuiltTool(ctx, "zipalign").
Colin Cross42be7612019-02-21 18:12:14 -08002616 Flag("-f").
2617 Text("4").
2618 Input(temporary).
2619 Output(dexOutputFile)
2620
2621 rule.DeleteTemporaryFiles()
2622
2623 rule.Build(pctx, ctx, "uncompress_dex", "uncompress dex")
2624 } else {
2625 ctx.Build(pctx, android.BuildParams{
2626 Rule: android.Cp,
2627 Input: inputJar,
2628 Output: dexOutputFile,
2629 })
2630 }
2631
2632 j.dexJarFile = dexOutputFile
2633
2634 dexOutputFile = j.dexpreopt(ctx, dexOutputFile)
2635
2636 j.maybeStrippedDexJarFile = dexOutputFile
2637
2638 ctx.InstallFile(android.PathForModuleInstall(ctx, "framework"),
2639 ctx.ModuleName()+".jar", dexOutputFile)
2640}
2641
2642func (j *DexImport) DexJar() android.Path {
2643 return j.dexJarFile
2644}
2645
2646// dex_import imports a `.jar` file containing classes.dex files.
2647//
2648// A dex_import module cannot be used as a dependency of a java_* or android_* module, it can only be installed
2649// to the device.
2650func DexImportFactory() android.Module {
2651 module := &DexImport{}
2652
2653 module.AddProperties(&module.properties)
2654
2655 android.InitPrebuiltModule(module, &module.properties.Jars)
Jiyong Park7f7766d2019-07-25 22:02:35 +09002656 android.InitApexModule(module)
Jooyung Han18020ea2019-11-13 10:50:48 +09002657 InitJavaModule(module, android.DeviceSupported)
Colin Cross42be7612019-02-21 18:12:14 -08002658 return module
2659}
2660
Colin Cross89536d42017-07-07 14:35:50 -07002661//
2662// Defaults
2663//
2664type Defaults struct {
2665 android.ModuleBase
2666 android.DefaultsModuleBase
Jiyong Park7f7766d2019-07-25 22:02:35 +09002667 android.ApexModuleBase
Colin Cross89536d42017-07-07 14:35:50 -07002668}
2669
Colin Cross1b16b0e2019-02-12 14:41:32 -08002670// java_defaults provides a set of properties that can be inherited by other java or android modules.
2671//
2672// A module can use the properties from a java_defaults module using `defaults: ["defaults_module_name"]`. Each
2673// property in the defaults module that exists in the depending module will be prepended to the depending module's
2674// value for that property.
2675//
2676// Example:
2677//
2678// java_defaults {
2679// name: "example_defaults",
2680// srcs: ["common/**/*.java"],
2681// javacflags: ["-Xlint:all"],
2682// aaptflags: ["--auto-add-overlay"],
2683// }
2684//
2685// java_library {
2686// name: "example",
2687// defaults: ["example_defaults"],
2688// srcs: ["example/**/*.java"],
2689// }
2690//
2691// is functionally identical to:
2692//
2693// java_library {
2694// name: "example",
2695// srcs: [
2696// "common/**/*.java",
2697// "example/**/*.java",
2698// ],
2699// javacflags: ["-Xlint:all"],
2700// }
Colin Cross89536d42017-07-07 14:35:50 -07002701func defaultsFactory() android.Module {
2702 return DefaultsFactory()
2703}
2704
Paul Duffin47357662019-12-05 14:07:14 +00002705func DefaultsFactory() android.Module {
Colin Cross89536d42017-07-07 14:35:50 -07002706 module := &Defaults{}
2707
Colin Cross89536d42017-07-07 14:35:50 -07002708 module.AddProperties(
2709 &CompilerProperties{},
2710 &CompilerDeviceProperties{},
Colin Cross43f08db2018-11-12 10:13:39 -08002711 &DexpreoptProperties{},
Dan Willemsen6424d172018-03-08 13:27:59 -08002712 &android.ProtoProperties{},
Colin Cross48de9a42018-10-02 13:53:33 -07002713 &aaptProperties{},
2714 &androidLibraryProperties{},
2715 &appProperties{},
2716 &appTestProperties{},
Jaewoong Jung525443a2019-02-28 15:35:54 -08002717 &overridableAppProperties{},
Colin Cross48de9a42018-10-02 13:53:33 -07002718 &ImportProperties{},
2719 &AARImportProperties{},
2720 &sdkLibraryProperties{},
Colin Cross42be7612019-02-21 18:12:14 -08002721 &DexImportProperties{},
Jooyung Han18020ea2019-11-13 10:50:48 +09002722 &android.ApexProperties{},
Colin Cross89536d42017-07-07 14:35:50 -07002723 )
2724
2725 android.InitDefaultsModule(module)
Colin Cross89536d42017-07-07 14:35:50 -07002726 return module
2727}
Nan Zhangea568a42017-11-08 21:20:04 -08002728
Sasha Smundak2a4549e2018-11-05 16:49:08 -08002729func kytheExtractJavaFactory() android.Singleton {
2730 return &kytheExtractJavaSingleton{}
2731}
2732
2733type kytheExtractJavaSingleton struct {
2734}
2735
2736func (ks *kytheExtractJavaSingleton) GenerateBuildActions(ctx android.SingletonContext) {
2737 var xrefTargets android.Paths
2738 ctx.VisitAllModules(func(module android.Module) {
2739 if javaModule, ok := module.(xref); ok {
2740 xrefTargets = append(xrefTargets, javaModule.XrefJavaFiles()...)
2741 }
2742 })
2743 // TODO(asmundak): perhaps emit a rule to output a warning if there were no xrefTargets
2744 if len(xrefTargets) > 0 {
2745 ctx.Build(pctx, android.BuildParams{
2746 Rule: blueprint.Phony,
2747 Output: android.PathForPhony(ctx, "xref_java"),
2748 Inputs: xrefTargets,
2749 })
2750 }
2751}
2752
Nan Zhangea568a42017-11-08 21:20:04 -08002753var Bool = proptools.Bool
Colin Cross38b40df2018-04-10 16:14:46 -07002754var BoolDefault = proptools.BoolDefault
Nan Zhangea568a42017-11-08 21:20:04 -08002755var String = proptools.String
Colin Cross0d0ba592018-02-20 13:33:42 -08002756var inList = android.InList