blob: 036c7afd4d4a1d0475b5bed0e44b8ca5877aebf9 [file] [log] [blame]
Colin Cross2fe66872015-03-30 17:20:39 -07001// Copyright 2015 Google Inc. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package java
16
17// This file contains the module types for compiling Java for Android, and converts the properties
Colin Cross46c9b8b2017-06-22 16:51:17 -070018// into the flags and filenames necessary to pass to the Module. The final creation of the rules
Colin Cross2fe66872015-03-30 17:20:39 -070019// is handled in builder.go
20
21import (
Colin Crossf19b9bb2018-03-26 14:42:44 -070022 "fmt"
Colin Crossfc3674a2017-09-18 17:41:52 -070023 "path/filepath"
Colin Cross74d73e22017-08-02 11:05:49 -070024 "strconv"
Colin Cross2fe66872015-03-30 17:20:39 -070025 "strings"
26
27 "github.com/google/blueprint"
Colin Cross3b706fd2019-09-05 16:44:18 -070028 "github.com/google/blueprint/pathtools"
Colin Cross76b5f0c2017-08-29 16:02:06 -070029 "github.com/google/blueprint/proptools"
Colin Cross2fe66872015-03-30 17:20:39 -070030
Colin Cross635c3b02016-05-18 15:37:25 -070031 "android/soong/android"
Ulya Trafimovich31e444e2020-08-14 17:32:16 +010032 "android/soong/dexpreopt"
Colin Cross3e3e72d2017-06-22 17:20:19 -070033 "android/soong/java/config"
Colin Cross303e21f2018-08-07 16:49:25 -070034 "android/soong/tradefed"
Colin Cross2fe66872015-03-30 17:20:39 -070035)
36
Colin Cross463a90e2015-06-17 14:20:06 -070037func init() {
Paul Duffinf9b1da02019-12-18 19:51:55 +000038 RegisterJavaBuildComponents(android.InitRegistrationContext)
Paul Duffin255f18e2019-12-13 11:22:16 +000039
40 // Register sdk member types.
Paul Duffin7b81f5e2020-01-13 21:03:22 +000041 android.RegisterSdkMemberType(javaHeaderLibsSdkMemberType)
Paul Duffin255f18e2019-12-13 11:22:16 +000042
Paul Duffin22ff0aa2021-02-04 11:15:34 +000043 // Export implementation classes jar as part of the sdk.
44 exportImplementationClassesJar := func(_ android.SdkMemberContext, j *Library) android.Path {
45 implementationJars := j.ImplementationAndResourcesJars()
46 if len(implementationJars) != 1 {
47 panic(fmt.Errorf("there must be only one implementation jar from %q", j.Name()))
48 }
49 return implementationJars[0]
50 }
51
Paul Duffindb170e42020-12-08 17:48:25 +000052 // Register java implementation libraries for use only in module_exports (not sdk).
Paul Duffinf5c0a9c2020-02-28 14:39:53 +000053 android.RegisterSdkMemberType(&librarySdkMemberType{
54 android.SdkMemberTypeBase{
55 PropertyName: "java_libs",
56 },
Paul Duffin22ff0aa2021-02-04 11:15:34 +000057 exportImplementationClassesJar,
Paul Duffindb170e42020-12-08 17:48:25 +000058 sdkSnapshotFilePathForJar,
59 copyEverythingToSnapshot,
Paul Duffin255f18e2019-12-13 11:22:16 +000060 })
Paul Duffin1b82e6a2019-12-03 18:06:47 +000061
Paul Duffindb170e42020-12-08 17:48:25 +000062 // Register java boot libraries for use in sdk.
63 //
64 // The build has some implicit dependencies (via the boot jars configuration) on a number of
65 // modules, e.g. core-oj, apache-xml, that are part of the java boot class path and which are
66 // provided by mainline modules (e.g. art, conscrypt, runtime-i18n) but which are not otherwise
67 // used outside those mainline modules.
68 //
69 // As they are not needed outside the mainline modules adding them to the sdk/module-exports as
70 // either java_libs, or java_header_libs would end up exporting more information than was strictly
71 // necessary. The java_boot_libs property to allow those modules to be exported as part of the
72 // sdk/module_exports without exposing any unnecessary information.
73 android.RegisterSdkMemberType(&librarySdkMemberType{
74 android.SdkMemberTypeBase{
75 PropertyName: "java_boot_libs",
76 SupportsSdk: true,
77 },
Paul Duffin22ff0aa2021-02-04 11:15:34 +000078 // Temporarily export implementation classes jar for java_boot_libs as it is required for the
79 // hiddenapi processing.
80 // TODO(b/179354495): Revert once hiddenapi processing has been modularized.
81 exportImplementationClassesJar,
82 sdkSnapshotFilePathForJar,
Paul Duffindb170e42020-12-08 17:48:25 +000083 onlyCopyJarToSnapshot,
84 })
85
86 // Register java test libraries for use only in module_exports (not sdk).
Paul Duffin1b82e6a2019-12-03 18:06:47 +000087 android.RegisterSdkMemberType(&testSdkMemberType{
88 SdkMemberTypeBase: android.SdkMemberTypeBase{
89 PropertyName: "java_tests",
90 },
91 })
Colin Cross463a90e2015-06-17 14:20:06 -070092}
93
Paul Duffinf9b1da02019-12-18 19:51:55 +000094func RegisterJavaBuildComponents(ctx android.RegistrationContext) {
95 ctx.RegisterModuleType("java_defaults", DefaultsFactory)
96
97 ctx.RegisterModuleType("java_library", LibraryFactory)
98 ctx.RegisterModuleType("java_library_static", LibraryStaticFactory)
99 ctx.RegisterModuleType("java_library_host", LibraryHostFactory)
100 ctx.RegisterModuleType("java_binary", BinaryFactory)
101 ctx.RegisterModuleType("java_binary_host", BinaryHostFactory)
102 ctx.RegisterModuleType("java_test", TestFactory)
103 ctx.RegisterModuleType("java_test_helper_library", TestHelperLibraryFactory)
104 ctx.RegisterModuleType("java_test_host", TestHostFactory)
Paul Duffin1b82e6a2019-12-03 18:06:47 +0000105 ctx.RegisterModuleType("java_test_import", JavaTestImportFactory)
Paul Duffinf9b1da02019-12-18 19:51:55 +0000106 ctx.RegisterModuleType("java_import", ImportFactory)
107 ctx.RegisterModuleType("java_import_host", ImportFactoryHost)
108 ctx.RegisterModuleType("java_device_for_host", DeviceForHostFactory)
109 ctx.RegisterModuleType("java_host_for_device", HostForDeviceFactory)
110 ctx.RegisterModuleType("dex_import", DexImportFactory)
111
Martin Stjernholm6d415272020-01-31 17:10:36 +0000112 ctx.FinalDepsMutators(func(ctx android.RegisterMutatorsContext) {
113 ctx.BottomUp("dexpreopt_tool_deps", dexpreoptToolDepsMutator).Parallel()
114 })
Martin Stjernholmd90676f2020-01-11 00:37:30 +0000115
Paul Duffinf9b1da02019-12-18 19:51:55 +0000116 ctx.RegisterSingletonType("logtags", LogtagsSingleton)
117 ctx.RegisterSingletonType("kythe_java_extract", kytheExtractJavaFactory)
118}
119
Artur Satayev8cf899a2020-04-15 17:29:42 +0100120func (j *Module) CheckStableSdkVersion() error {
121 sdkVersion := j.sdkVersion()
122 if sdkVersion.stable() {
123 return nil
124 }
Paul Duffin043f5e72021-03-05 00:00:01 +0000125 if sdkVersion.kind == sdkCorePlatform {
126 if useLegacyCorePlatformApiByName(j.BaseModuleName()) {
127 return fmt.Errorf("non stable SDK %v - uses legacy core platform", sdkVersion)
128 } else {
129 // Treat stable core platform as stable.
130 return nil
131 }
132 } else {
133 return fmt.Errorf("non stable SDK %v", sdkVersion)
134 }
Artur Satayev8cf899a2020-04-15 17:29:42 +0100135}
136
Artur Satayev2db1c3f2020-04-08 19:09:30 +0100137func (j *Module) checkSdkVersions(ctx android.ModuleContext) {
Colin Crossc2d24052020-05-13 11:05:02 -0700138 if j.RequiresStableAPIs(ctx) {
Jeongik Cha2cc570d2019-10-29 15:44:45 +0900139 if sc, ok := ctx.Module().(sdkContext); ok {
Jiyong Park6a927c42020-01-21 02:03:43 +0900140 if !sc.sdkVersion().specified() {
Jeongik Cha2cc570d2019-10-29 15:44:45 +0900141 ctx.PropertyErrorf("sdk_version",
142 "sdk_version must have a value when the module is located at vendor or product(only if PRODUCT_ENFORCE_PRODUCT_PARTITION_INTERFACE is set).")
143 }
144 }
145 }
Artur Satayev2db1c3f2020-04-08 19:09:30 +0100146
147 ctx.VisitDirectDeps(func(module android.Module) {
148 tag := ctx.OtherModuleDependencyTag(module)
149 switch module.(type) {
150 // TODO(satayev): cover other types as well, e.g. imports
151 case *Library, *AndroidLibrary:
152 switch tag {
153 case bootClasspathTag, libTag, staticLibTag, java9LibTag:
154 checkLinkType(ctx, j, module.(linkTypeContext), tag.(dependencyTag))
155 }
156 }
157 })
Jeongik Cha2cc570d2019-10-29 15:44:45 +0900158}
159
Jeongik Cha538c0d02019-07-11 15:54:27 +0900160func (j *Module) checkPlatformAPI(ctx android.ModuleContext) {
161 if sc, ok := ctx.Module().(sdkContext); ok {
162 usePlatformAPI := proptools.Bool(j.deviceProperties.Platform_apis)
Jiyong Park6a927c42020-01-21 02:03:43 +0900163 sdkVersionSpecified := sc.sdkVersion().specified()
164 if usePlatformAPI && sdkVersionSpecified {
165 ctx.PropertyErrorf("platform_apis", "platform_apis must be false when sdk_version is not empty.")
166 } else if !usePlatformAPI && !sdkVersionSpecified {
167 ctx.PropertyErrorf("platform_apis", "platform_apis must be true when sdk_version is empty.")
Jeongik Cha538c0d02019-07-11 15:54:27 +0900168 }
169
170 }
171}
172
Colin Cross2fe66872015-03-30 17:20:39 -0700173// TODO:
174// Autogenerated files:
Colin Cross2fe66872015-03-30 17:20:39 -0700175// Renderscript
176// Post-jar passes:
177// Proguard
Colin Cross2fe66872015-03-30 17:20:39 -0700178// Rmtypedefs
Colin Cross2fe66872015-03-30 17:20:39 -0700179// DroidDoc
180// Findbugs
181
Colin Cross89536d42017-07-07 14:35:50 -0700182type CompilerProperties struct {
Colin Crossa4c8cc62020-06-25 17:13:36 -0700183 // list of source files used to compile the Java module. May be .java, .kt, .logtags, .proto,
Colin Cross7d5136f2015-05-11 13:39:40 -0700184 // or .aidl files.
Colin Cross27b922f2019-03-04 22:35:41 -0800185 Srcs []string `android:"path,arch_variant"`
Dan Willemsen2ef08f42015-06-30 18:15:24 -0700186
Colin Crossa4c8cc62020-06-25 17:13:36 -0700187 // list Kotlin of source files containing Kotlin code that should be treated as common code in
188 // a codebase that supports Kotlin multiplatform. See
189 // https://kotlinlang.org/docs/reference/multiplatform.html. May be only be .kt files.
190 Common_srcs []string `android:"path,arch_variant"`
191
Dan Willemsen2ef08f42015-06-30 18:15:24 -0700192 // list of source files that should not be used to build the Java module.
193 // This is most useful in the arch/multilib variants to remove non-common files
Colin Cross27b922f2019-03-04 22:35:41 -0800194 Exclude_srcs []string `android:"path,arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700195
196 // list of directories containing Java resources
Colin Cross86a63ff2017-09-27 17:33:10 -0700197 Java_resource_dirs []string `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700198
Colin Cross86a63ff2017-09-27 17:33:10 -0700199 // list of directories that should be excluded from java_resource_dirs
200 Exclude_java_resource_dirs []string `android:"arch_variant"`
Dan Willemsen2ef08f42015-06-30 18:15:24 -0700201
Colin Cross0f37af02017-09-27 17:42:05 -0700202 // list of files to use as Java resources
Colin Cross27b922f2019-03-04 22:35:41 -0800203 Java_resources []string `android:"path,arch_variant"`
Colin Cross0f37af02017-09-27 17:42:05 -0700204
Colin Crosscedd4762018-09-13 11:26:19 -0700205 // list of files that should be excluded from java_resources and java_resource_dirs
Colin Cross27b922f2019-03-04 22:35:41 -0800206 Exclude_java_resources []string `android:"path,arch_variant"`
Colin Cross0f37af02017-09-27 17:42:05 -0700207
Colin Cross7d5136f2015-05-11 13:39:40 -0700208 // list of module-specific flags that will be used for javac compiles
209 Javacflags []string `android:"arch_variant"`
210
Zoran Jovanovic8736ce22018-08-21 17:10:29 +0200211 // list of module-specific flags that will be used for kotlinc compiles
212 Kotlincflags []string `android:"arch_variant"`
213
Colin Cross7d5136f2015-05-11 13:39:40 -0700214 // list of of java libraries that will be in the classpath
Colin Crosse8dc34a2017-07-19 11:22:16 -0700215 Libs []string `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700216
217 // list of java libraries that will be compiled into the resulting jar
Colin Crosse8dc34a2017-07-19 11:22:16 -0700218 Static_libs []string `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700219
220 // manifest file to be included in resulting jar
Colin Cross27b922f2019-03-04 22:35:41 -0800221 Manifest *string `android:"path"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700222
Colin Cross540eff82017-06-22 17:01:52 -0700223 // if not blank, run jarjar using the specified rules file
Colin Cross27b922f2019-03-04 22:35:41 -0800224 Jarjar_rules *string `android:"path,arch_variant"`
Colin Cross64162712017-08-08 13:17:59 -0700225
226 // If not blank, set the java version passed to javac as -source and -target
227 Java_version *string
Colin Cross2c429dc2017-08-31 16:45:16 -0700228
Colin Cross9ae1b922018-06-26 17:59:05 -0700229 // If set to true, allow this module to be dexed and installed on devices. Has no
230 // effect on host modules, which are always considered installable.
Colin Cross2c429dc2017-08-31 16:45:16 -0700231 Installable *bool
Colin Cross32f676a2017-09-06 13:41:06 -0700232
Colin Cross0f37af02017-09-27 17:42:05 -0700233 // If set to true, include sources used to compile the module in to the final jar
234 Include_srcs *bool
235
Vladimir Marko0975ee02019-04-02 10:29:55 +0100236 // If not empty, classes are restricted to the specified packages and their sub-packages.
237 // This restriction is checked after applying jarjar rules and including static libs.
238 Permitted_packages []string
239
Colin Crossbe9cdb82019-01-21 21:37:16 -0800240 // List of modules to use as annotation processors
241 Plugins []string
Colin Cross1369cdb2017-09-29 17:58:17 -0700242
Colin Crossc9fe10f2020-11-19 18:06:03 -0800243 // List of modules to export to libraries that directly depend on this library as annotation
244 // processors. Note that if the plugins set generates_api: true this will disable the turbine
245 // optimization on modules that depend on this module, which will reduce parallelism and cause
246 // more recompilation.
Artur Satayev9cf46692019-11-26 18:08:34 +0000247 Exported_plugins []string
248
Nan Zhang61eaedb2017-11-02 13:28:15 -0700249 // The number of Java source entries each Javac instance can process
250 Javac_shard_size *int64
251
Nan Zhang5f8cb422018-02-06 10:34:32 -0800252 // Add host jdk tools.jar to bootclasspath
253 Use_tools_jar *bool
254
Colin Cross1369cdb2017-09-29 17:58:17 -0700255 Openjdk9 struct {
Colin Cross6cef4812019-10-17 14:23:50 -0700256 // List of source files that should only be used when passing -source 1.9 or higher
Colin Cross27b922f2019-03-04 22:35:41 -0800257 Srcs []string `android:"path"`
Colin Cross1369cdb2017-09-29 17:58:17 -0700258
Colin Cross6cef4812019-10-17 14:23:50 -0700259 // List of javac flags that should only be used when passing -source 1.9 or higher
Colin Cross1369cdb2017-09-29 17:58:17 -0700260 Javacflags []string
261 }
Colin Crosscb933592017-11-22 13:49:43 -0800262
Colin Cross81440082018-08-15 20:21:55 -0700263 // When compiling language level 9+ .java code in packages that are part of
264 // a system module, patch_module names the module that your sources and
265 // dependencies should be patched into. The Android runtime currently
266 // doesn't implement the JEP 261 module system so this option is only
267 // supported at compile time. It should only be needed to compile tests in
268 // packages that exist in libcore and which are inconvenient to move
269 // elsewhere.
Tobias Thiererdda713d2018-09-19 16:16:19 +0100270 Patch_module *string `android:"arch_variant"`
Colin Cross81440082018-08-15 20:21:55 -0700271
Colin Crosscb933592017-11-22 13:49:43 -0800272 Jacoco struct {
273 // List of classes to include for instrumentation with jacoco to collect coverage
274 // information at runtime when building with coverage enabled. If unset defaults to all
275 // classes.
276 // Supports '*' as the last character of an entry in the list as a wildcard match.
277 // If preceded by '.' it matches all classes in the package and subpackages, otherwise
278 // it matches classes in the package that have the class name as a prefix.
279 Include_filter []string
280
281 // List of classes to exclude from instrumentation with jacoco to collect coverage
282 // information at runtime when building with coverage enabled. Overrides classes selected
283 // by the include_filter property.
284 // Supports '*' as the last character of an entry in the list as a wildcard match.
285 // If preceded by '.' it matches all classes in the package and subpackages, otherwise
286 // it matches classes in the package that have the class name as a prefix.
287 Exclude_filter []string
288 }
289
Andreas Gampef3e5b552018-01-22 21:27:21 -0800290 Errorprone struct {
291 // List of javac flags that should only be used when running errorprone.
292 Javacflags []string
Colin Cross748b2d82020-11-19 13:52:06 -0800293
294 // List of java_plugin modules that provide extra errorprone checks.
295 Extra_check_modules []string
Andreas Gampef3e5b552018-01-22 21:27:21 -0800296 }
297
Colin Cross0f2ee152017-12-14 15:22:43 -0800298 Proto struct {
299 // List of extra options that will be passed to the proto generator.
300 Output_params []string
301 }
302
Colin Crosscb933592017-11-22 13:49:43 -0800303 Instrument bool `blueprint:"mutated"`
Alex Light7f004a72019-02-21 13:27:37 -0800304
305 // List of files to include in the META-INF/services folder of the resulting jar.
Colin Cross27b922f2019-03-04 22:35:41 -0800306 Services []string `android:"path,arch_variant"`
Colin Cross0b67a8b2020-06-18 15:52:01 -0700307
308 // If true, package the kotlin stdlib into the jar. Defaults to true.
309 Static_kotlin_stdlib *bool `android:"arch_variant"`
Paul Duffin031d8692021-02-12 11:46:42 +0000310
311 // A list of java_library instances that provide additional hiddenapi annotations for the library.
312 Hiddenapi_additional_annotations []string
Colin Cross540eff82017-06-22 17:01:52 -0700313}
314
Colin Cross89536d42017-07-07 14:35:50 -0700315type CompilerDeviceProperties struct {
Jeongik Cha538c0d02019-07-11 15:54:27 +0900316 // if not blank, set to the version of the sdk to compile against.
317 // Defaults to compiling against the current platform.
Nan Zhangea568a42017-11-08 21:20:04 -0800318 Sdk_version *string
Colin Cross7d5136f2015-05-11 13:39:40 -0700319
Colin Cross83bb3162018-06-25 15:48:06 -0700320 // if not blank, set the minimum version of the sdk that the compiled artifacts will run against.
321 // Defaults to sdk_version if not set.
322 Min_sdk_version *string
323
Dan Willemsen419290a2018-10-31 15:28:47 -0700324 // if not blank, set the targetSdkVersion in the AndroidManifest.xml.
325 // Defaults to sdk_version if not set.
326 Target_sdk_version *string
327
Jeongik Cha356dac42019-08-19 14:09:52 +0900328 // Whether to compile against the platform APIs instead of an SDK.
329 // If true, then sdk_version must be empty. The value of this field
330 // is ignored when module's type isn't android_app.
Colin Cross6af2e492018-05-22 11:12:33 -0700331 Platform_apis *bool
332
Colin Crossebe1a512017-11-14 13:12:14 -0800333 Aidl struct {
334 // Top level directories to pass to aidl tool
335 Include_dirs []string
Colin Cross7d5136f2015-05-11 13:39:40 -0700336
Colin Crossebe1a512017-11-14 13:12:14 -0800337 // Directories rooted at the Android.bp file to pass to aidl tool
338 Local_include_dirs []string
339
340 // directories that should be added as include directories for any aidl sources of modules
341 // that depend on this module, as well as to aidl for this module.
342 Export_include_dirs []string
Martijn Coeneneab15642018-03-09 09:29:59 +0100343
344 // whether to generate traces (for systrace) for this interface
345 Generate_traces *bool
Olivier Gaillard0a4cfbc2018-07-16 23:37:03 +0100346
347 // whether to generate Binder#GetTransaction name method.
348 Generate_get_transaction_name *bool
Jooyung Hane197d8b2021-01-05 10:33:16 +0900349
350 // list of flags that will be passed to the AIDL compiler
351 Flags []string
Colin Crossebe1a512017-11-14 13:12:14 -0800352 }
Colin Cross92430102017-10-09 14:59:32 -0700353
354 // If true, export a copy of the module as a -hostdex module for host testing.
355 Hostdex *bool
Colin Cross1369cdb2017-09-29 17:58:17 -0700356
Colin Cross7f87f4f2019-04-24 13:41:45 -0700357 Target struct {
358 Hostdex struct {
359 // Additional required dependencies to add to -hostdex modules.
360 Required []string
361 }
362 }
363
Paul Duffine25c6442019-10-11 13:50:28 +0100364 // When targeting 1.9 and above, override the modules to use with --system,
365 // otherwise provides defaults libraries to add to the bootclasspath.
Colin Cross1369cdb2017-09-29 17:58:17 -0700366 System_modules *string
Colin Cross5a0dcd52018-10-05 14:20:06 -0700367
Paul Duffina2058f82020-06-24 16:22:38 +0100368 // The name of the module as used in build configuration.
369 //
370 // Allows a library to separate its actual name from the name used in
371 // build configuration, e.g.ctx.Config().BootJars().
372 ConfigurationName *string `blueprint:"mutated"`
373
Jiyong Park4c4c0242019-10-21 14:53:15 +0900374 // set the name of the output
375 Stem *string
376
David Srbeckye033cba2020-05-20 22:20:28 +0100377 IsSDKLibrary bool `blueprint:"mutated"`
Songchun Fan17d69e32020-03-24 20:32:24 -0700378
379 // If true, generate the signature file of APK Signing Scheme V4, along side the signed APK file.
380 // Defaults to false.
381 V4_signature *bool
Colin Cross75ce9ec2021-02-26 16:20:32 -0800382
383 // Only for libraries created by a sysprop_library module, SyspropPublicStub is the name of the
384 // public stubs library.
385 SyspropPublicStub string `blueprint:"mutated"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700386}
387
Paul Duffin0d3c2e12020-05-17 08:34:50 +0100388// Functionality common to Module and Import
Paul Duffin859fe962020-05-15 10:20:31 +0100389//
390// It is embedded in Module so its functionality can be used by methods in Module
391// but it is currently only initialized by Import and Library.
Paul Duffin0d3c2e12020-05-17 08:34:50 +0100392type embeddableInModuleAndImport struct {
Paul Duffin859fe962020-05-15 10:20:31 +0100393
394 // Functionality related to this being used as a component of a java_sdk_library.
395 EmbeddableSdkLibraryComponent
396}
397
398func (e *embeddableInModuleAndImport) initModuleAndImport(moduleBase *android.ModuleBase) {
399 e.initSdkLibraryComponent(moduleBase)
Paul Duffin0d3c2e12020-05-17 08:34:50 +0100400}
401
402// Module/Import's DepIsInSameApex(...) delegates to this method.
403//
404// This cannot implement DepIsInSameApex(...) directly as that leads to ambiguity with
405// the one provided by ApexModuleBase.
406func (e *embeddableInModuleAndImport) depIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
407 // dependencies other than the static linkage are all considered crossing APEX boundary
408 if staticLibTag == ctx.OtherModuleDependencyTag(dep) {
409 return true
410 }
411 return false
412}
413
Colin Cross46c9b8b2017-06-22 16:51:17 -0700414// Module contains the properties and members used by all java module types
415type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700416 android.ModuleBase
Colin Cross89536d42017-07-07 14:35:50 -0700417 android.DefaultableModuleBase
Jiyong Park7f7766d2019-07-25 22:02:35 +0900418 android.ApexModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +0900419 android.SdkBase
Colin Cross2fe66872015-03-30 17:20:39 -0700420
Paul Duffin0d3c2e12020-05-17 08:34:50 +0100421 // Functionality common to Module and Import.
422 embeddableInModuleAndImport
423
Colin Cross89536d42017-07-07 14:35:50 -0700424 properties CompilerProperties
Colin Cross6af17aa2017-09-20 12:59:05 -0700425 protoProperties android.ProtoProperties
Colin Cross89536d42017-07-07 14:35:50 -0700426 deviceProperties CompilerDeviceProperties
Colin Cross2fe66872015-03-30 17:20:39 -0700427
Colin Cross331a1212018-08-15 20:40:52 -0700428 // jar file containing header classes including static library dependencies, suitable for
429 // inserting into the bootclasspath/classpath of another compile
Nan Zhanged19fc32017-10-19 13:06:22 -0700430 headerJarFile android.Path
431
Colin Cross331a1212018-08-15 20:40:52 -0700432 // jar file containing implementation classes including static library dependencies but no
433 // resources
Nan Zhanged19fc32017-10-19 13:06:22 -0700434 implementationJarFile android.Path
Colin Cross2fe66872015-03-30 17:20:39 -0700435
Colin Cross331a1212018-08-15 20:40:52 -0700436 // jar file containing only resources including from static library dependencies
437 resourceJar android.Path
438
Colin Cross0c4ce212019-05-03 15:28:19 -0700439 // args and dependencies to package source files into a srcjar
440 srcJarArgs []string
441 srcJarDeps android.Paths
442
Colin Cross331a1212018-08-15 20:40:52 -0700443 // jar file containing implementation classes and resources including static library
444 // dependencies
445 implementationAndResourcesJar android.Path
446
447 // output file containing classes.dex and resources
Colin Cross6ade34f2017-09-15 13:00:47 -0700448 dexJarFile android.Path
449
Colin Crosscb933592017-11-22 13:49:43 -0800450 // output file containing uninstrumented classes that will be instrumented by jacoco
451 jacocoReportClassesFile android.Path
452
Colin Cross331a1212018-08-15 20:40:52 -0700453 // output file of the module, which may be a classes jar or a dex jar
Colin Crosse560c4a2019-03-19 16:03:11 -0700454 outputFile android.Path
455 extraOutputFiles android.Paths
Colin Crossb7a63242015-04-16 14:09:14 -0700456
Colin Cross635c3b02016-05-18 15:37:25 -0700457 exportAidlIncludeDirs android.Paths
Colin Crossc0b06f12015-04-08 13:03:43 -0700458
Colin Cross635c3b02016-05-18 15:37:25 -0700459 logtagsSrcs android.Paths
Colin Crossf05fe972015-04-10 17:45:20 -0700460
Colin Cross2fe66872015-03-30 17:20:39 -0700461 // installed file for binary dependency
Colin Cross635c3b02016-05-18 15:37:25 -0700462 installFile android.Path
Colin Cross5ab4e6d2017-11-22 16:20:45 -0800463
464 // list of .java files and srcjars that was passed to javac
465 compiledJavaSrcs android.Paths
466 compiledSrcJars android.Paths
Colin Cross66dbc0b2017-12-28 12:23:20 -0800467
Colin Cross094054a2018-10-17 15:10:48 -0700468 // manifest file to use instead of properties.Manifest
469 overrideManifest android.OptionalPath
470
Ulya Trafimovich8cbc5d22020-11-03 15:15:46 +0000471 // map of SDK version to class loader context
Ulya Trafimovichb23d28c2020-10-08 12:53:58 +0100472 classLoaderContexts dexpreopt.ClassLoaderContextMap
Brandon Lee5d45c6f2018-08-15 15:35:38 -0700473
Artur Satayev9cf46692019-11-26 18:08:34 +0000474 // list of plugins that this java module is exporting
475 exportedPluginJars android.Paths
476
477 // list of plugins that this java module is exporting
478 exportedPluginClasses []string
479
Colin Crossc9fe10f2020-11-19 18:06:03 -0800480 // if true, the exported plugins generate API and require disabling turbine.
481 exportedDisableTurbine bool
482
Artur Satayev9cf46692019-11-26 18:08:34 +0000483 // list of source files, collected from srcFiles with unique java and all kt files,
patricktu242faad2019-09-24 15:41:30 +0800484 // will be used by android.IDEInfo struct
Brandon Lee5d45c6f2018-08-15 15:35:38 -0700485 expandIDEInfoCompiledSrcs []string
Colin Cross43f08db2018-11-12 10:13:39 -0800486
Steven Morelandc4efd9c2019-01-18 11:51:25 -0800487 // expanded Jarjar_rules
488 expandJarjarRules android.Path
489
Vladimir Marko0975ee02019-04-02 10:29:55 +0100490 // list of additional targets for checkbuild
491 additionalCheckedModules android.Paths
492
Colin Cross988708c2019-05-06 14:04:11 -0700493 // Extra files generated by the module type to be added as java resources.
494 extraResources android.Paths
495
Colin Crossf24a22a2019-01-31 14:12:44 -0800496 hiddenAPI
Liz Kammera7a64f32020-07-09 15:16:41 -0700497 dexer
Colin Cross43f08db2018-11-12 10:13:39 -0800498 dexpreopter
Ulya Trafimovich21a73752020-09-01 17:33:48 +0100499 usesLibrary
Colin Cross014489c2020-06-02 20:09:13 -0700500 linter
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800501
502 // list of the xref extraction files
503 kytheFiles android.Paths
Anton Hansson78156ef2020-03-27 19:39:48 +0000504
bralee1fbf4402020-05-21 10:11:59 +0800505 // Collect the module directory for IDE info in java/jdeps.go.
506 modulePaths []string
Colin Cross56a83212020-09-15 18:30:11 -0700507
508 hideApexVariantFromMake bool
Colin Cross2fe66872015-03-30 17:20:39 -0700509}
510
Colin Crossce6734e2020-06-15 16:09:53 -0700511func (j *Module) addHostProperties() {
512 j.AddProperties(
513 &j.properties,
514 &j.protoProperties,
Ulya Trafimovich21a73752020-09-01 17:33:48 +0100515 &j.usesLibraryProperties,
Colin Crossce6734e2020-06-15 16:09:53 -0700516 )
517}
518
519func (j *Module) addHostAndDeviceProperties() {
520 j.addHostProperties()
521 j.AddProperties(
522 &j.deviceProperties,
Liz Kammera7a64f32020-07-09 15:16:41 -0700523 &j.dexer.dexProperties,
Colin Crossce6734e2020-06-15 16:09:53 -0700524 &j.dexpreoptProperties,
Colin Cross014489c2020-06-02 20:09:13 -0700525 &j.linter.properties,
Colin Crossce6734e2020-06-15 16:09:53 -0700526 )
527}
528
Colin Cross41955e82019-05-29 14:40:35 -0700529func (j *Module) OutputFiles(tag string) (android.Paths, error) {
530 switch tag {
531 case "":
532 return append(android.Paths{j.outputFile}, j.extraOutputFiles...), nil
Paul Duffin74f05592020-11-25 16:37:46 +0000533 case android.DefaultDistTag:
534 return android.Paths{j.outputFile}, nil
Colin Cross375ca3c2019-05-29 14:40:58 -0700535 case ".jar":
536 return android.Paths{j.implementationAndResourcesJar}, nil
Colin Cross2d975b12019-07-29 16:47:42 -0700537 case ".proguard_map":
Liz Kammera7a64f32020-07-09 15:16:41 -0700538 if j.dexer.proguardDictionary.Valid() {
539 return android.Paths{j.dexer.proguardDictionary.Path()}, nil
540 }
541 return nil, fmt.Errorf("%q was requested, but no output file was found.", tag)
Colin Cross41955e82019-05-29 14:40:35 -0700542 default:
543 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
544 }
Colin Cross54250902017-12-05 09:28:08 -0800545}
546
Colin Cross41955e82019-05-29 14:40:35 -0700547var _ android.OutputFileProducer = (*Module)(nil)
Colin Cross54250902017-12-05 09:28:08 -0800548
Colin Crossdcf71b22021-02-01 13:59:03 -0800549// JavaInfo contains information about a java module for use by modules that depend on it.
550type JavaInfo struct {
551 // HeaderJars is a list of jars that can be passed as the javac classpath in order to link
552 // against this module. If empty, ImplementationJars should be used instead.
553 HeaderJars android.Paths
554
555 // ImplementationAndResourceJars is a list of jars that contain the implementations of classes
556 // in the module as well as any resources included in the module.
557 ImplementationAndResourcesJars android.Paths
558
559 // ImplementationJars is a list of jars that contain the implementations of classes in the
560 //module.
561 ImplementationJars android.Paths
562
563 // ResourceJars is a list of jars that contain the resources included in the module.
564 ResourceJars android.Paths
565
566 // AidlIncludeDirs is a list of directories that should be passed to the aidl tool when
567 // depending on this module.
568 AidlIncludeDirs android.Paths
569
570 // SrcJarArgs is a list of arguments to pass to soong_zip to package the sources of this
571 // module.
572 SrcJarArgs []string
573
574 // SrcJarDeps is a list of paths to depend on when packaging the sources of this module.
575 SrcJarDeps android.Paths
576
577 // ExportedPlugins is a list of paths that should be used as annotation processors for any
578 // module that depends on this module.
579 ExportedPlugins android.Paths
580
581 // ExportedPluginClasses is a list of classes that should be run as annotation processors for
582 // any module that depends on this module.
583 ExportedPluginClasses []string
584
585 // ExportedPluginDisableTurbine is true if this module's annotation processors generate APIs,
586 // requiring disbling turbine for any modules that depend on it.
587 ExportedPluginDisableTurbine bool
588
589 // JacocoReportClassesFile is the path to a jar containing uninstrumented classes that will be
590 // instrumented by jacoco.
591 JacocoReportClassesFile android.Path
592}
593
594var JavaInfoProvider = blueprint.NewProvider(JavaInfo{})
595
Colin Cross75ce9ec2021-02-26 16:20:32 -0800596// SyspropPublicStubInfo contains info about the sysprop public stub library that corresponds to
597// the sysprop implementation library.
598type SyspropPublicStubInfo struct {
599 // JavaInfo is the JavaInfoProvider of the sysprop public stub library that corresponds to
600 // the sysprop implementation library.
601 JavaInfo JavaInfo
602}
603
604var SyspropPublicStubInfoProvider = blueprint.NewProvider(SyspropPublicStubInfo{})
605
Paul Duffin44b481b2020-06-17 16:59:43 +0100606// Methods that need to be implemented for a module that is added to apex java_libs property.
607type ApexDependency interface {
Nan Zhanged19fc32017-10-19 13:06:22 -0700608 HeaderJars() android.Paths
Paul Duffin44b481b2020-06-17 16:59:43 +0100609 ImplementationAndResourcesJars() android.Paths
610}
611
Ulya Trafimovich31e444e2020-08-14 17:32:16 +0100612// Provides build path and install path to DEX jars.
613type UsesLibraryDependency interface {
Ulyana Trafimovich5539e7b2020-06-04 14:08:17 +0000614 DexJarBuildPath() android.Path
Ulya Trafimovich9f3052c2020-06-09 14:31:19 +0100615 DexJarInstallPath() android.Path
Ulya Trafimovichdbf31662020-12-17 12:07:54 +0000616 ClassLoaderContexts() dexpreopt.ClassLoaderContextMap
Ulya Trafimovich31e444e2020-08-14 17:32:16 +0100617}
618
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800619type xref interface {
620 XrefJavaFiles() android.Paths
621}
622
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800623func (j *Module) XrefJavaFiles() android.Paths {
624 return j.kytheFiles
625}
626
Colin Cross89536d42017-07-07 14:35:50 -0700627func InitJavaModule(module android.DefaultableModule, hod android.HostOrDeviceSupported) {
Liz Kammerdd849a82020-06-12 16:38:45 -0700628 initJavaModule(module, hod, false)
629}
630
631func InitJavaModuleMultiTargets(module android.DefaultableModule, hod android.HostOrDeviceSupported) {
632 initJavaModule(module, hod, true)
633}
634
635func initJavaModule(module android.DefaultableModule, hod android.HostOrDeviceSupported, multiTargets bool) {
636 multilib := android.MultilibCommon
637 if multiTargets {
638 android.InitAndroidMultiTargetsArchModule(module, hod, multilib)
639 } else {
640 android.InitAndroidArchModule(module, hod, multilib)
641 }
Colin Cross89536d42017-07-07 14:35:50 -0700642 android.InitDefaultableModule(module)
643}
644
Colin Crossbe1da472017-07-07 15:59:46 -0700645type dependencyTag struct {
646 blueprint.BaseDependencyTag
647 name string
Colin Cross2fe66872015-03-30 17:20:39 -0700648}
649
Colin Crosse9fe2942020-11-10 18:12:15 -0800650// installDependencyTag is a dependency tag that is annotated to cause the installed files of the
651// dependency to be installed when the parent module is installed.
652type installDependencyTag struct {
653 blueprint.BaseDependencyTag
654 android.InstallAlwaysNeededDependencyTag
655 name string
656}
657
Ulya Trafimovichb5218112020-10-07 15:11:32 +0100658type usesLibraryDependencyTag struct {
659 dependencyTag
660 sdkVersion int // SDK version in which the library appared as a standalone library.
661}
662
663func makeUsesLibraryDependencyTag(sdkVersion int) usesLibraryDependencyTag {
664 return usesLibraryDependencyTag{
665 dependencyTag: dependencyTag{name: fmt.Sprintf("uses-library-%d", sdkVersion)},
666 sdkVersion: sdkVersion,
667 }
668}
669
Jiyong Park8be103b2019-11-08 15:53:48 +0900670func IsJniDepTag(depTag blueprint.DependencyTag) bool {
Colin Crossde78d132020-10-09 18:59:49 -0700671 return depTag == jniLibTag
Jiyong Park8be103b2019-11-08 15:53:48 +0900672}
673
Colin Crossbe1da472017-07-07 15:59:46 -0700674var (
Colin Cross75ce9ec2021-02-26 16:20:32 -0800675 dataNativeBinsTag = dependencyTag{name: "dataNativeBins"}
676 staticLibTag = dependencyTag{name: "staticlib"}
677 libTag = dependencyTag{name: "javalib"}
678 java9LibTag = dependencyTag{name: "java9lib"}
679 pluginTag = dependencyTag{name: "plugin"}
680 errorpronePluginTag = dependencyTag{name: "errorprone-plugin"}
681 exportedPluginTag = dependencyTag{name: "exported-plugin"}
682 bootClasspathTag = dependencyTag{name: "bootclasspath"}
683 systemModulesTag = dependencyTag{name: "system modules"}
684 frameworkResTag = dependencyTag{name: "framework-res"}
685 kotlinStdlibTag = dependencyTag{name: "kotlin-stdlib"}
686 kotlinAnnotationsTag = dependencyTag{name: "kotlin-annotations"}
687 proguardRaiseTag = dependencyTag{name: "proguard-raise"}
688 certificateTag = dependencyTag{name: "certificate"}
689 instrumentationForTag = dependencyTag{name: "instrumentation_for"}
690 extraLintCheckTag = dependencyTag{name: "extra-lint-check"}
691 jniLibTag = dependencyTag{name: "jnilib"}
692 syspropPublicStubDepTag = dependencyTag{name: "sysprop public stub"}
693 jniInstallTag = installDependencyTag{name: "jni install"}
694 binaryInstallTag = installDependencyTag{name: "binary install"}
695 usesLibTag = makeUsesLibraryDependencyTag(dexpreopt.AnySdkVersion)
696 usesLibCompat28Tag = makeUsesLibraryDependencyTag(28)
697 usesLibCompat29Tag = makeUsesLibraryDependencyTag(29)
698 usesLibCompat30Tag = makeUsesLibraryDependencyTag(30)
Colin Crossbe1da472017-07-07 15:59:46 -0700699)
Colin Cross2fe66872015-03-30 17:20:39 -0700700
Jiyong Park83dc74b2020-01-14 18:38:44 +0900701func IsLibDepTag(depTag blueprint.DependencyTag) bool {
702 return depTag == libTag
703}
704
705func IsStaticLibDepTag(depTag blueprint.DependencyTag) bool {
706 return depTag == staticLibTag
707}
708
Colin Crossfc3674a2017-09-18 17:41:52 -0700709type sdkDep struct {
Pete Gilline3d44b22020-06-29 11:28:51 +0100710 useModule, useFiles, invalidVersion bool
Colin Cross47ff2522017-10-02 14:22:08 -0700711
Colin Cross6cef4812019-10-17 14:23:50 -0700712 // The modules that will be added to the bootclasspath when targeting 1.8 or lower
713 bootclasspath []string
Paul Duffine25c6442019-10-11 13:50:28 +0100714
715 // The default system modules to use. Will be an empty string if no system
716 // modules are to be used.
Colin Cross1369cdb2017-09-29 17:58:17 -0700717 systemModules string
718
Pete Gilline3d44b22020-06-29 11:28:51 +0100719 // The modules that will be added to the classpath regardless of the Java language level targeted
720 classpath []string
721
Colin Cross6cef4812019-10-17 14:23:50 -0700722 // The modules that will be added ot the classpath when targeting 1.9 or higher
Pete Gilline3d44b22020-06-29 11:28:51 +0100723 // (normally these will be on the bootclasspath when targeting 1.8 or lower)
Colin Cross6cef4812019-10-17 14:23:50 -0700724 java9Classpath []string
725
Colin Crossa97c5d32018-03-28 14:58:31 -0700726 frameworkResModule string
727
Colin Cross86a60ae2018-05-29 14:44:55 -0700728 jars android.Paths
Colin Cross3047fa22019-04-18 10:56:44 -0700729 aidl android.OptionalPath
Paul Duffin250e6192019-06-07 10:44:37 +0100730
731 noStandardLibs, noFrameworksLibs bool
732}
733
734func (s sdkDep) hasStandardLibs() bool {
735 return !s.noStandardLibs
736}
737
738func (s sdkDep) hasFrameworkLibs() bool {
739 return !s.noStandardLibs && !s.noFrameworksLibs
Colin Cross1369cdb2017-09-29 17:58:17 -0700740}
741
Colin Crossa4f08812018-10-02 22:03:40 -0700742type jniLib struct {
Colin Cross403cc152020-07-06 14:15:24 -0700743 name string
744 path android.Path
745 target android.Target
746 coverageFile android.OptionalPath
747 unstrippedFile android.Path
Colin Crossa4f08812018-10-02 22:03:40 -0700748}
749
Colin Cross0ea8ba82019-06-06 14:33:29 -0700750func (j *Module) shouldInstrument(ctx android.BaseModuleContext) bool {
Roland Levillainada12702020-06-09 13:07:36 +0100751 return j.properties.Instrument &&
752 ctx.Config().IsEnvTrue("EMMA_INSTRUMENT") &&
753 ctx.DeviceConfig().JavaCoverageEnabledForPath(ctx.ModuleDir())
Colin Cross3144dfc2018-01-03 15:06:47 -0800754}
755
Colin Cross0ea8ba82019-06-06 14:33:29 -0700756func (j *Module) shouldInstrumentStatic(ctx android.BaseModuleContext) bool {
Colin Cross3144dfc2018-01-03 15:06:47 -0800757 return j.shouldInstrument(ctx) &&
758 (ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_STATIC") ||
759 ctx.Config().UnbundledBuild())
760}
761
Chris Gross190fdc02020-05-29 16:01:19 +0000762func (j *Module) shouldInstrumentInApex(ctx android.BaseModuleContext) bool {
763 // Force enable the instrumentation for java code that is built for APEXes ...
764 // except for the jacocoagent itself (because instrumenting jacocoagent using jacocoagent
765 // doesn't make sense) or framework libraries (e.g. libraries found in the InstrumentFrameworkModules list) unless EMMA_INSTRUMENT_FRAMEWORK is true.
Colin Cross56a83212020-09-15 18:30:11 -0700766 apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo)
Chris Gross190fdc02020-05-29 16:01:19 +0000767 isJacocoAgent := ctx.ModuleName() == "jacocoagent"
Colin Cross56a83212020-09-15 18:30:11 -0700768 if j.DirectlyInAnyApex() && !isJacocoAgent && !apexInfo.IsForPlatform() {
Chris Gross190fdc02020-05-29 16:01:19 +0000769 if !inList(ctx.ModuleName(), config.InstrumentFrameworkModules) {
770 return true
771 } else if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
772 return true
773 }
774 }
775 return false
776}
777
Jiyong Park6a927c42020-01-21 02:03:43 +0900778func (j *Module) sdkVersion() sdkSpec {
779 return sdkSpecFrom(String(j.deviceProperties.Sdk_version))
Colin Cross83bb3162018-06-25 15:48:06 -0700780}
781
Paul Duffine25c6442019-10-11 13:50:28 +0100782func (j *Module) systemModules() string {
783 return proptools.String(j.deviceProperties.System_modules)
784}
785
Jiyong Park6a927c42020-01-21 02:03:43 +0900786func (j *Module) minSdkVersion() sdkSpec {
Colin Cross83bb3162018-06-25 15:48:06 -0700787 if j.deviceProperties.Min_sdk_version != nil {
Jiyong Park6a927c42020-01-21 02:03:43 +0900788 return sdkSpecFrom(*j.deviceProperties.Min_sdk_version)
Colin Cross83bb3162018-06-25 15:48:06 -0700789 }
790 return j.sdkVersion()
791}
792
Jiyong Park6a927c42020-01-21 02:03:43 +0900793func (j *Module) targetSdkVersion() sdkSpec {
Dan Willemsen419290a2018-10-31 15:28:47 -0700794 if j.deviceProperties.Target_sdk_version != nil {
Jiyong Park6a927c42020-01-21 02:03:43 +0900795 return sdkSpecFrom(*j.deviceProperties.Target_sdk_version)
Dan Willemsen419290a2018-10-31 15:28:47 -0700796 }
797 return j.sdkVersion()
798}
799
Artur Satayev480e25b2020-04-27 18:53:18 +0100800func (j *Module) MinSdkVersion() string {
801 return j.minSdkVersion().version.String()
802}
803
Jiyong Parkb02bb402019-12-03 00:43:57 +0900804func (j *Module) AvailableFor(what string) bool {
805 if what == android.AvailableToPlatform && Bool(j.deviceProperties.Hostdex) {
806 // Exception: for hostdex: true libraries, the platform variant is created
807 // even if it's not marked as available to platform. In that case, the platform
808 // variant is used only for the hostdex and not installed to the device.
809 return true
810 }
811 return j.ApexModuleBase.AvailableFor(what)
812}
813
Liz Kammerd6c31d22020-08-05 15:40:41 -0700814func sdkDeps(ctx android.BottomUpMutatorContext, sdkContext sdkContext, d dexer) {
815 sdkDep := decodeSdkDep(ctx, sdkContext)
816 if sdkDep.useModule {
817 ctx.AddVariationDependencies(nil, bootClasspathTag, sdkDep.bootclasspath...)
818 ctx.AddVariationDependencies(nil, java9LibTag, sdkDep.java9Classpath...)
819 ctx.AddVariationDependencies(nil, libTag, sdkDep.classpath...)
820 if d.effectiveOptimizeEnabled() && sdkDep.hasStandardLibs() {
821 ctx.AddVariationDependencies(nil, proguardRaiseTag, config.LegacyCorePlatformBootclasspathLibraries...)
822 }
823 if d.effectiveOptimizeEnabled() && sdkDep.hasFrameworkLibs() {
824 ctx.AddVariationDependencies(nil, proguardRaiseTag, config.FrameworkLibraries...)
825 }
826 }
827 if sdkDep.systemModules != "" {
828 ctx.AddVariationDependencies(nil, systemModulesTag, sdkDep.systemModules)
829 }
830}
831
Colin Crossbe1da472017-07-07 15:59:46 -0700832func (j *Module) deps(ctx android.BottomUpMutatorContext) {
Colin Cross1369cdb2017-09-29 17:58:17 -0700833 if ctx.Device() {
Colin Cross92e4b462020-06-18 15:56:48 -0700834 j.linter.deps(ctx)
835
Liz Kammerd6c31d22020-08-05 15:40:41 -0700836 sdkDeps(ctx, sdkContext(j), j.dexer)
Colin Cross1369cdb2017-09-29 17:58:17 -0700837
Colin Cross75ce9ec2021-02-26 16:20:32 -0800838 if j.deviceProperties.SyspropPublicStub != "" {
839 // This is a sysprop implementation library that has a corresponding sysprop public
840 // stubs library, and a dependency on it so that dependencies on the implementation can
841 // be forwarded to the public stubs library when necessary.
842 ctx.AddVariationDependencies(nil, syspropPublicStubDepTag, j.deviceProperties.SyspropPublicStub)
Inseob Kimac1e9862019-12-09 18:15:47 +0900843 }
Inseob Kimac1e9862019-12-09 18:15:47 +0900844 }
845
Colin Cross75ce9ec2021-02-26 16:20:32 -0800846 libDeps := ctx.AddVariationDependencies(nil, libTag, j.properties.Libs...)
847 ctx.AddVariationDependencies(nil, staticLibTag, j.properties.Static_libs...)
Colin Crossa4f08812018-10-02 22:03:40 -0700848
Paul Duffin031d8692021-02-12 11:46:42 +0000849 // Add dependency on libraries that provide additional hidden api annotations.
850 ctx.AddVariationDependencies(nil, hiddenApiAnnotationsTag, j.properties.Hiddenapi_additional_annotations...)
851
JaeMan Parkff715562020-10-19 17:25:58 +0900852 if ctx.DeviceConfig().VndkVersion() != "" && ctx.Config().EnforceInterPartitionJavaSdkLibrary() {
853 // Require java_sdk_library at inter-partition java dependency to ensure stable
854 // interface between partitions. If inter-partition java_library dependency is detected,
855 // raise build error because java_library doesn't have a stable interface.
856 //
857 // Inputs:
858 // PRODUCT_ENFORCE_INTER_PARTITION_JAVA_SDK_LIBRARY
859 // if true, enable enforcement
860 // PRODUCT_INTER_PARTITION_JAVA_LIBRARY_ALLOWLIST
861 // exception list of java_library names to allow inter-partition dependency
Colin Cross75ce9ec2021-02-26 16:20:32 -0800862 for idx := range j.properties.Libs {
JaeMan Parkff715562020-10-19 17:25:58 +0900863 if libDeps[idx] == nil {
864 continue
865 }
866
JaeMan Parkff715562020-10-19 17:25:58 +0900867 if javaDep, ok := libDeps[idx].(javaSdkLibraryEnforceContext); ok {
868 // java_sdk_library is always allowed at inter-partition dependency.
869 // So, skip check.
870 if _, ok := javaDep.(*SdkLibrary); ok {
871 continue
872 }
873
874 j.checkPartitionsForJavaDependency(ctx, "libs", javaDep)
875 }
876 }
877 }
878
Ulya Trafimovich39b437b2020-09-23 16:42:35 +0100879 // For library dependencies that are component libraries (like stubs), add the implementation
880 // as a dependency (dexpreopt needs to be against the implementation library, not stubs).
881 for _, dep := range libDeps {
882 if dep != nil {
883 if component, ok := dep.(SdkLibraryComponentDependency); ok {
884 if lib := component.OptionalSdkLibraryImplementation(); lib != nil {
885 ctx.AddVariationDependencies(nil, usesLibTag, *lib)
886 }
887 }
888 }
889 }
890
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700891 ctx.AddFarVariationDependencies(ctx.Config().BuildOSCommonTarget.Variations(), pluginTag, j.properties.Plugins...)
Colin Cross748b2d82020-11-19 13:52:06 -0800892 ctx.AddFarVariationDependencies(ctx.Config().BuildOSCommonTarget.Variations(), errorpronePluginTag, j.properties.Errorprone.Extra_check_modules...)
Artur Satayev9cf46692019-11-26 18:08:34 +0000893 ctx.AddFarVariationDependencies(ctx.Config().BuildOSCommonTarget.Variations(), exportedPluginTag, j.properties.Exported_plugins...)
Colin Crossbe9cdb82019-01-21 21:37:16 -0800894
Colin Crossfe17f6f2019-03-28 19:30:56 -0700895 android.ProtoDeps(ctx, &j.protoProperties)
Colin Cross6af17aa2017-09-20 12:59:05 -0700896 if j.hasSrcExt(".proto") {
897 protoDeps(ctx, &j.protoProperties)
898 }
Colin Cross93e85952017-08-15 13:34:18 -0700899
900 if j.hasSrcExt(".kt") {
901 // TODO(ccross): move this to a mutator pass that can tell if generated sources contain
902 // Kotlin files
Colin Cross0b03d972019-05-13 11:06:25 -0700903 ctx.AddVariationDependencies(nil, kotlinStdlibTag,
904 "kotlin-stdlib", "kotlin-stdlib-jdk7", "kotlin-stdlib-jdk8")
Colin Cross7788c122019-01-23 16:14:02 -0800905 if len(j.properties.Plugins) > 0 {
Colin Crossafbb1732019-01-17 15:42:52 -0800906 ctx.AddVariationDependencies(nil, kotlinAnnotationsTag, "kotlin-annotations")
907 }
Colin Cross93e85952017-08-15 13:34:18 -0700908 }
Colin Cross3144dfc2018-01-03 15:06:47 -0800909
Ulya Trafimovich38dfa0f2020-01-07 16:37:02 +0000910 // Framework libraries need special handling in static coverage builds: they should not have
911 // static dependency on jacoco, otherwise there would be multiple conflicting definitions of
912 // the same jacoco classes coming from different bootclasspath jars.
913 if inList(ctx.ModuleName(), config.InstrumentFrameworkModules) {
914 if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
915 j.properties.Instrument = true
916 }
917 } else if j.shouldInstrumentStatic(ctx) {
Colin Cross42d48b72018-08-29 14:10:52 -0700918 ctx.AddVariationDependencies(nil, staticLibTag, "jacocoagent")
Colin Cross3144dfc2018-01-03 15:06:47 -0800919 }
Colin Cross6af17aa2017-09-20 12:59:05 -0700920}
921
922func hasSrcExt(srcs []string, ext string) bool {
923 for _, src := range srcs {
924 if filepath.Ext(src) == ext {
925 return true
926 }
927 }
928
929 return false
930}
931
932func (j *Module) hasSrcExt(ext string) bool {
933 return hasSrcExt(j.properties.Srcs, ext)
Colin Cross2fe66872015-03-30 17:20:39 -0700934}
935
Colin Cross46c9b8b2017-06-22 16:51:17 -0700936func (j *Module) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.OptionalPath,
Colin Cross3047fa22019-04-18 10:56:44 -0700937 aidlIncludeDirs android.Paths) (string, android.Paths) {
Colin Crossc0b06f12015-04-08 13:03:43 -0700938
Colin Crossebe1a512017-11-14 13:12:14 -0800939 aidlIncludes := android.PathsForModuleSrc(ctx, j.deviceProperties.Aidl.Local_include_dirs)
940 aidlIncludes = append(aidlIncludes,
941 android.PathsForModuleSrc(ctx, j.deviceProperties.Aidl.Export_include_dirs)...)
942 aidlIncludes = append(aidlIncludes,
943 android.PathsForSource(ctx, j.deviceProperties.Aidl.Include_dirs)...)
Colin Crossc0b06f12015-04-08 13:03:43 -0700944
Colin Cross3047fa22019-04-18 10:56:44 -0700945 var flags []string
946 var deps android.Paths
Steven Moreland667f6882018-07-26 12:55:08 -0700947
Jooyung Hane197d8b2021-01-05 10:33:16 +0900948 flags = append(flags, j.deviceProperties.Aidl.Flags...)
949
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700950 if aidlPreprocess.Valid() {
951 flags = append(flags, "-p"+aidlPreprocess.String())
Colin Cross3047fa22019-04-18 10:56:44 -0700952 deps = append(deps, aidlPreprocess.Path())
953 } else if len(aidlIncludeDirs) > 0 {
Colin Cross635c3b02016-05-18 15:37:25 -0700954 flags = append(flags, android.JoinWithPrefix(aidlIncludeDirs.Strings(), "-I"))
Colin Crossc0b06f12015-04-08 13:03:43 -0700955 }
956
Colin Cross3047fa22019-04-18 10:56:44 -0700957 if len(j.exportAidlIncludeDirs) > 0 {
958 flags = append(flags, android.JoinWithPrefix(j.exportAidlIncludeDirs.Strings(), "-I"))
959 }
960
961 if len(aidlIncludes) > 0 {
962 flags = append(flags, android.JoinWithPrefix(aidlIncludes.Strings(), "-I"))
963 }
964
Colin Cross635c3b02016-05-18 15:37:25 -0700965 flags = append(flags, "-I"+android.PathForModuleSrc(ctx).String())
Colin Cross32f38982018-02-22 11:47:25 -0800966 if src := android.ExistentPathForSource(ctx, ctx.ModuleDir(), "src"); src.Valid() {
Colin Crossd48633a2017-07-13 14:41:17 -0700967 flags = append(flags, "-I"+src.String())
968 }
Colin Crossc0b06f12015-04-08 13:03:43 -0700969
Martijn Coeneneab15642018-03-09 09:29:59 +0100970 if Bool(j.deviceProperties.Aidl.Generate_traces) {
971 flags = append(flags, "-t")
972 }
973
Olivier Gaillard0a4cfbc2018-07-16 23:37:03 +0100974 if Bool(j.deviceProperties.Aidl.Generate_get_transaction_name) {
975 flags = append(flags, "--transaction_names")
976 }
977
Colin Cross3047fa22019-04-18 10:56:44 -0700978 return strings.Join(flags, " "), deps
Colin Crossc0b06f12015-04-08 13:03:43 -0700979}
980
Colin Cross32f676a2017-09-06 13:41:06 -0700981type deps struct {
Colin Cross748b2d82020-11-19 13:52:06 -0800982 classpath classpath
983 java9Classpath classpath
984 bootClasspath classpath
985 processorPath classpath
986 errorProneProcessorPath classpath
987 processorClasses []string
988 staticJars android.Paths
989 staticHeaderJars android.Paths
990 staticResourceJars android.Paths
991 aidlIncludeDirs android.Paths
992 srcs android.Paths
993 srcJars android.Paths
994 systemModules *systemModules
995 aidlPreprocess android.OptionalPath
996 kotlinStdlib android.Paths
997 kotlinAnnotations android.Paths
Colin Crossbe9cdb82019-01-21 21:37:16 -0800998
999 disableTurbine bool
Colin Cross32f676a2017-09-06 13:41:06 -07001000}
Colin Cross2fe66872015-03-30 17:20:39 -07001001
Colin Cross54250902017-12-05 09:28:08 -08001002func checkProducesJars(ctx android.ModuleContext, dep android.SourceFileProducer) {
1003 for _, f := range dep.Srcs() {
1004 if f.Ext() != ".jar" {
1005 ctx.ModuleErrorf("genrule %q must generate files ending with .jar to be used as a libs or static_libs dependency",
1006 ctx.OtherModuleName(dep.(blueprint.Module)))
1007 }
1008 }
1009}
1010
Jiyong Park2d492942018-03-05 17:44:10 +09001011type linkType int
1012
1013const (
Jiyong Park50146e92020-01-30 18:00:15 +09001014 // TODO(jiyong) rename these for better readability. Make the allowed
1015 // and disallowed link types explicit
Jiyong Park7f87e1a2021-02-18 20:29:05 +09001016 // order is important here. See rank()
Jiyong Park2d492942018-03-05 17:44:10 +09001017 javaCore linkType = iota
1018 javaSdk
1019 javaSystem
Jiyong Park50146e92020-01-30 18:00:15 +09001020 javaModule
Jiyong Parkaae9bd12020-02-12 04:36:43 +09001021 javaSystemServer
Jiyong Park2d492942018-03-05 17:44:10 +09001022 javaPlatform
1023)
1024
Jiyong Park670e0f62021-02-18 13:10:18 +09001025func (lt linkType) String() string {
1026 switch lt {
1027 case javaCore:
1028 return "core Java API"
1029 case javaSdk:
1030 return "Android API"
1031 case javaSystem:
1032 return "system API"
1033 case javaModule:
1034 return "module API"
1035 case javaSystemServer:
1036 return "system server API"
1037 case javaPlatform:
1038 return "private API"
1039 default:
Jiyong Parkd4cbf342021-02-23 11:14:31 +09001040 panic(fmt.Errorf("unrecognized linktype: %d", lt))
Jiyong Park670e0f62021-02-18 13:10:18 +09001041 }
1042}
1043
Jiyong Park7f87e1a2021-02-18 20:29:05 +09001044// rank determins the total order among linkTypes. A link type of rank A can link to another link
1045// type of rank B only when B <= A
1046func (lt linkType) rank() int {
1047 return int(lt)
1048}
1049
Jeongik Cha75b83b02019-11-01 15:28:00 +09001050type linkTypeContext interface {
1051 android.Module
1052 getLinkType(name string) (ret linkType, stubs bool)
1053}
1054
1055func (m *Module) getLinkType(name string) (ret linkType, stubs bool) {
Anton Hanssoncc51a682020-05-19 12:06:48 +01001056 switch name {
Pete Gillin1f41dbf2020-06-02 15:59:45 +01001057 case "core.current.stubs", "legacy.core.platform.api.stubs", "stable.core.platform.api.stubs",
1058 "stub-annotations", "private-stub-annotations-jar",
1059 "core-lambda-stubs", "core-generated-annotation-stubs":
Jiyong Park46f78fb2018-10-20 16:33:17 +09001060 return javaCore, true
Anton Hanssoncc51a682020-05-19 12:06:48 +01001061 case "android_stubs_current":
Jiyong Park46f78fb2018-10-20 16:33:17 +09001062 return javaSdk, true
Anton Hanssoncc51a682020-05-19 12:06:48 +01001063 case "android_system_stubs_current":
1064 return javaSystem, true
1065 case "android_module_lib_stubs_current":
Jiyong Park50146e92020-01-30 18:00:15 +09001066 return javaModule, true
Anton Hanssoncc51a682020-05-19 12:06:48 +01001067 case "android_system_server_stubs_current":
Jiyong Parkaae9bd12020-02-12 04:36:43 +09001068 return javaSystemServer, true
Anton Hanssoncc51a682020-05-19 12:06:48 +01001069 case "android_test_stubs_current":
1070 return javaSystem, true
Jiyong Park2d492942018-03-05 17:44:10 +09001071 }
Anton Hanssoncc51a682020-05-19 12:06:48 +01001072
Anton Hansson2d0c1942020-05-25 12:20:51 +01001073 if stub, linkType := moduleStubLinkType(name); stub {
1074 return linkType, true
1075 }
1076
Anton Hanssoncc51a682020-05-19 12:06:48 +01001077 ver := m.sdkVersion()
1078 switch ver.kind {
1079 case sdkCore:
1080 return javaCore, false
1081 case sdkSystem:
1082 return javaSystem, false
1083 case sdkPublic:
1084 return javaSdk, false
1085 case sdkModule:
1086 return javaModule, false
1087 case sdkSystemServer:
1088 return javaSystemServer, false
1089 case sdkPrivate, sdkNone, sdkCorePlatform, sdkTest:
1090 return javaPlatform, false
1091 }
1092
1093 if !ver.valid() {
1094 panic(fmt.Errorf("sdk_version is invalid. got %q", ver.raw))
1095 }
1096 return javaSdk, false
Jiyong Park2d492942018-03-05 17:44:10 +09001097}
1098
Jeongik Cha75b83b02019-11-01 15:28:00 +09001099func checkLinkType(ctx android.ModuleContext, from *Module, to linkTypeContext, tag dependencyTag) {
Colin Crossf19b9bb2018-03-26 14:42:44 -07001100 if ctx.Host() {
1101 return
1102 }
1103
Jeongik Cha75b83b02019-11-01 15:28:00 +09001104 myLinkType, stubs := from.getLinkType(ctx.ModuleName())
Jiyong Park46f78fb2018-10-20 16:33:17 +09001105 if stubs {
1106 return
1107 }
Jeongik Cha75b83b02019-11-01 15:28:00 +09001108 otherLinkType, _ := to.getLinkType(ctx.OtherModuleName(to))
Jiyong Park2d492942018-03-05 17:44:10 +09001109
Jiyong Park7f87e1a2021-02-18 20:29:05 +09001110 if myLinkType.rank() < otherLinkType.rank() {
Jiyong Park670e0f62021-02-18 13:10:18 +09001111 ctx.ModuleErrorf("compiles against %v, but dependency %q is compiling against %v. "+
1112 "In order to fix this, consider adjusting sdk_version: OR platform_apis: "+
1113 "property of the source or target module so that target module is built "+
1114 "with the same or smaller API set when compared to the source.",
1115 myLinkType, ctx.OtherModuleName(to), otherLinkType)
1116 }
Jiyong Park750e5572018-01-31 00:20:13 +09001117}
1118
Colin Cross32f676a2017-09-06 13:41:06 -07001119func (j *Module) collectDeps(ctx android.ModuleContext) deps {
1120 var deps deps
Colin Crossfc3674a2017-09-18 17:41:52 -07001121
Colin Cross300f0382018-03-06 13:11:51 -08001122 if ctx.Device() {
Colin Cross83bb3162018-06-25 15:48:06 -07001123 sdkDep := decodeSdkDep(ctx, sdkContext(j))
Colin Cross300f0382018-03-06 13:11:51 -08001124 if sdkDep.invalidVersion {
Colin Cross6cef4812019-10-17 14:23:50 -07001125 ctx.AddMissingDependencies(sdkDep.bootclasspath)
1126 ctx.AddMissingDependencies(sdkDep.java9Classpath)
Colin Cross300f0382018-03-06 13:11:51 -08001127 } else if sdkDep.useFiles {
1128 // sdkDep.jar is actually equivalent to turbine header.jar.
Colin Cross86a60ae2018-05-29 14:44:55 -07001129 deps.classpath = append(deps.classpath, sdkDep.jars...)
Colin Cross3047fa22019-04-18 10:56:44 -07001130 deps.aidlPreprocess = sdkDep.aidl
1131 } else {
1132 deps.aidlPreprocess = sdkDep.aidl
Colin Cross300f0382018-03-06 13:11:51 -08001133 }
Colin Crossfc3674a2017-09-18 17:41:52 -07001134 }
1135
Colin Cross75ce9ec2021-02-26 16:20:32 -08001136 linkType, _ := j.getLinkType(ctx.ModuleName())
1137
Colin Crossd11fcda2017-10-23 17:59:01 -07001138 ctx.VisitDirectDeps(func(module android.Module) {
Colin Cross2fe66872015-03-30 17:20:39 -07001139 otherName := ctx.OtherModuleName(module)
Colin Crossec7a0422017-07-07 14:47:12 -07001140 tag := ctx.OtherModuleDependencyTag(module)
1141
Colin Crossde78d132020-10-09 18:59:49 -07001142 if IsJniDepTag(tag) {
Colin Crossbd01e2a2018-10-04 15:21:03 -07001143 // Handled by AndroidApp.collectAppDeps
1144 return
1145 }
1146 if tag == certificateTag {
1147 // Handled by AndroidApp.collectAppDeps
Colin Crossa4f08812018-10-02 22:03:40 -07001148 return
1149 }
Artur Satayev2db1c3f2020-04-08 19:09:30 +01001150
Colin Crossdcf71b22021-02-01 13:59:03 -08001151 if dep, ok := module.(SdkLibraryDependency); ok {
Colin Cross897d2ed2019-02-11 14:03:51 -08001152 switch tag {
1153 case libTag:
1154 deps.classpath = append(deps.classpath, dep.SdkHeaderJars(ctx, j.sdkVersion())...)
Colin Cross79c7c262019-04-17 11:11:46 -07001155 case staticLibTag:
Colin Cross897d2ed2019-02-11 14:03:51 -08001156 ctx.ModuleErrorf("dependency on java_sdk_library %q can only be in libs", otherName)
1157 }
Colin Crossdcf71b22021-02-01 13:59:03 -08001158 } else if ctx.OtherModuleHasProvider(module, JavaInfoProvider) {
1159 dep := ctx.OtherModuleProvider(module, JavaInfoProvider).(JavaInfo)
Colin Cross75ce9ec2021-02-26 16:20:32 -08001160 if linkType != javaPlatform &&
1161 ctx.OtherModuleHasProvider(module, SyspropPublicStubInfoProvider) {
1162 // dep is a sysprop implementation library, but this module is not linking against
1163 // the platform, so it gets the sysprop public stubs library instead. Replace
1164 // dep with the JavaInfo from the SyspropPublicStubInfoProvider.
1165 syspropDep := ctx.OtherModuleProvider(module, SyspropPublicStubInfoProvider).(SyspropPublicStubInfo)
1166 dep = syspropDep.JavaInfo
1167 }
Colin Cross54250902017-12-05 09:28:08 -08001168 switch tag {
1169 case bootClasspathTag:
Colin Crossdcf71b22021-02-01 13:59:03 -08001170 deps.bootClasspath = append(deps.bootClasspath, dep.HeaderJars...)
Colin Cross4b964c02018-10-15 16:18:06 -07001171 case libTag, instrumentationForTag:
Colin Crossdcf71b22021-02-01 13:59:03 -08001172 deps.classpath = append(deps.classpath, dep.HeaderJars...)
1173 deps.aidlIncludeDirs = append(deps.aidlIncludeDirs, dep.AidlIncludeDirs...)
1174 addPlugins(&deps, dep.ExportedPlugins, dep.ExportedPluginClasses...)
1175 deps.disableTurbine = deps.disableTurbine || dep.ExportedPluginDisableTurbine
Colin Cross6cef4812019-10-17 14:23:50 -07001176 case java9LibTag:
Colin Crossdcf71b22021-02-01 13:59:03 -08001177 deps.java9Classpath = append(deps.java9Classpath, dep.HeaderJars...)
Colin Cross54250902017-12-05 09:28:08 -08001178 case staticLibTag:
Colin Crossdcf71b22021-02-01 13:59:03 -08001179 deps.classpath = append(deps.classpath, dep.HeaderJars...)
1180 deps.staticJars = append(deps.staticJars, dep.ImplementationJars...)
1181 deps.staticHeaderJars = append(deps.staticHeaderJars, dep.HeaderJars...)
1182 deps.staticResourceJars = append(deps.staticResourceJars, dep.ResourceJars...)
1183 deps.aidlIncludeDirs = append(deps.aidlIncludeDirs, dep.AidlIncludeDirs...)
1184 addPlugins(&deps, dep.ExportedPlugins, dep.ExportedPluginClasses...)
Colin Crossc9fe10f2020-11-19 18:06:03 -08001185 // Turbine doesn't run annotation processors, so any module that uses an
1186 // annotation processor that generates API is incompatible with the turbine
1187 // optimization.
Colin Crossdcf71b22021-02-01 13:59:03 -08001188 deps.disableTurbine = deps.disableTurbine || dep.ExportedPluginDisableTurbine
Colin Crossbe9cdb82019-01-21 21:37:16 -08001189 case pluginTag:
Colin Crossdcf71b22021-02-01 13:59:03 -08001190 if plugin, ok := module.(*Plugin); ok {
Colin Crossbe9cdb82019-01-21 21:37:16 -08001191 if plugin.pluginProperties.Processor_class != nil {
Colin Crossdcf71b22021-02-01 13:59:03 -08001192 addPlugins(&deps, dep.ImplementationAndResourcesJars, *plugin.pluginProperties.Processor_class)
Artur Satayev9cf46692019-11-26 18:08:34 +00001193 } else {
Colin Crossdcf71b22021-02-01 13:59:03 -08001194 addPlugins(&deps, dep.ImplementationAndResourcesJars)
Colin Crossbe9cdb82019-01-21 21:37:16 -08001195 }
Colin Crossc9fe10f2020-11-19 18:06:03 -08001196 // Turbine doesn't run annotation processors, so any module that uses an
1197 // annotation processor that generates API is incompatible with the turbine
1198 // optimization.
Colin Crossbe9cdb82019-01-21 21:37:16 -08001199 deps.disableTurbine = deps.disableTurbine || Bool(plugin.pluginProperties.Generates_api)
1200 } else {
1201 ctx.PropertyErrorf("plugins", "%q is not a java_plugin module", otherName)
1202 }
Colin Cross748b2d82020-11-19 13:52:06 -08001203 case errorpronePluginTag:
Colin Crossdcf71b22021-02-01 13:59:03 -08001204 if _, ok := module.(*Plugin); ok {
1205 deps.errorProneProcessorPath = append(deps.errorProneProcessorPath, dep.ImplementationAndResourcesJars...)
Colin Cross748b2d82020-11-19 13:52:06 -08001206 } else {
1207 ctx.PropertyErrorf("plugins", "%q is not a java_plugin module", otherName)
1208 }
Artur Satayev9cf46692019-11-26 18:08:34 +00001209 case exportedPluginTag:
Colin Crossdcf71b22021-02-01 13:59:03 -08001210 if plugin, ok := module.(*Plugin); ok {
1211 j.exportedPluginJars = append(j.exportedPluginJars, dep.ImplementationAndResourcesJars...)
Artur Satayev9cf46692019-11-26 18:08:34 +00001212 if plugin.pluginProperties.Processor_class != nil {
1213 j.exportedPluginClasses = append(j.exportedPluginClasses, *plugin.pluginProperties.Processor_class)
1214 }
Colin Crossc9fe10f2020-11-19 18:06:03 -08001215 // Turbine doesn't run annotation processors, so any module that uses an
1216 // annotation processor that generates API is incompatible with the turbine
1217 // optimization.
1218 j.exportedDisableTurbine = Bool(plugin.pluginProperties.Generates_api)
Artur Satayev9cf46692019-11-26 18:08:34 +00001219 } else {
1220 ctx.PropertyErrorf("exported_plugins", "%q is not a java_plugin module", otherName)
1221 }
Colin Cross54250902017-12-05 09:28:08 -08001222 case kotlinStdlibTag:
Colin Crossdcf71b22021-02-01 13:59:03 -08001223 deps.kotlinStdlib = append(deps.kotlinStdlib, dep.HeaderJars...)
Colin Crossafbb1732019-01-17 15:42:52 -08001224 case kotlinAnnotationsTag:
Colin Crossdcf71b22021-02-01 13:59:03 -08001225 deps.kotlinAnnotations = dep.HeaderJars
Colin Cross75ce9ec2021-02-26 16:20:32 -08001226 case syspropPublicStubDepTag:
1227 // This is a sysprop implementation library, forward the JavaInfoProvider from
1228 // the corresponding sysprop public stub library as SyspropPublicStubInfoProvider.
1229 ctx.SetProvider(SyspropPublicStubInfoProvider, SyspropPublicStubInfo{
1230 JavaInfo: dep,
1231 })
Colin Cross54250902017-12-05 09:28:08 -08001232 }
Colin Crossdcf71b22021-02-01 13:59:03 -08001233 } else if dep, ok := module.(android.SourceFileProducer); ok {
Colin Cross54250902017-12-05 09:28:08 -08001234 switch tag {
1235 case libTag:
1236 checkProducesJars(ctx, dep)
1237 deps.classpath = append(deps.classpath, dep.Srcs()...)
1238 case staticLibTag:
1239 checkProducesJars(ctx, dep)
1240 deps.classpath = append(deps.classpath, dep.Srcs()...)
1241 deps.staticJars = append(deps.staticJars, dep.Srcs()...)
1242 deps.staticHeaderJars = append(deps.staticHeaderJars, dep.Srcs()...)
Colin Cross54250902017-12-05 09:28:08 -08001243 }
Colin Crossdcf71b22021-02-01 13:59:03 -08001244 } else {
Colin Crossec7a0422017-07-07 14:47:12 -07001245 switch tag {
Paul Duffin68289b02019-09-20 13:50:52 +01001246 case bootClasspathTag:
1247 // If a system modules dependency has been added to the bootclasspath
1248 // then add its libs to the bootclasspath.
Paul Duffin83a2d962019-11-19 19:44:10 +00001249 sm := module.(SystemModulesProvider)
1250 deps.bootClasspath = append(deps.bootClasspath, sm.HeaderJars()...)
Paul Duffin68289b02019-09-20 13:50:52 +01001251
Colin Cross1369cdb2017-09-29 17:58:17 -07001252 case systemModulesTag:
1253 if deps.systemModules != nil {
1254 panic("Found two system module dependencies")
1255 }
Paul Duffin83a2d962019-11-19 19:44:10 +00001256 sm := module.(SystemModulesProvider)
1257 outputDir, outputDeps := sm.OutputDirAndDeps()
1258 deps.systemModules = &systemModules{outputDir, outputDeps}
Colin Cross2fe66872015-03-30 17:20:39 -07001259 }
Colin Crossec7a0422017-07-07 14:47:12 -07001260 }
Ulya Trafimovich65b03192020-12-03 16:50:22 +00001261
Ulya Trafimovich88bb6f62020-12-16 16:16:11 +00001262 addCLCFromDep(ctx, module, j.classLoaderContexts)
Colin Cross2fe66872015-03-30 17:20:39 -07001263 })
1264
Colin Cross32f676a2017-09-06 13:41:06 -07001265 return deps
Colin Cross2fe66872015-03-30 17:20:39 -07001266}
1267
Artur Satayev9cf46692019-11-26 18:08:34 +00001268func addPlugins(deps *deps, pluginJars android.Paths, pluginClasses ...string) {
1269 deps.processorPath = append(deps.processorPath, pluginJars...)
1270 deps.processorClasses = append(deps.processorClasses, pluginClasses...)
1271}
1272
Colin Cross1e743852019-10-28 11:37:20 -07001273func getJavaVersion(ctx android.ModuleContext, javaVersion string, sdkContext sdkContext) javaVersion {
Nan Zhang357466b2018-04-17 17:38:36 -07001274 if javaVersion != "" {
Colin Cross1e743852019-10-28 11:37:20 -07001275 return normalizeJavaVersion(ctx, javaVersion)
Colin Cross17dec172020-05-14 18:05:32 -07001276 } else if ctx.Device() {
1277 return sdkContext.sdkVersion().defaultJavaLanguageVersion(ctx)
Nan Zhang357466b2018-04-17 17:38:36 -07001278 } else {
Colin Cross1e743852019-10-28 11:37:20 -07001279 return JAVA_VERSION_9
Nan Zhang357466b2018-04-17 17:38:36 -07001280 }
Nan Zhang357466b2018-04-17 17:38:36 -07001281}
1282
Colin Cross1e743852019-10-28 11:37:20 -07001283type javaVersion int
1284
1285const (
1286 JAVA_VERSION_UNSUPPORTED = 0
1287 JAVA_VERSION_6 = 6
1288 JAVA_VERSION_7 = 7
1289 JAVA_VERSION_8 = 8
1290 JAVA_VERSION_9 = 9
1291)
1292
1293func (v javaVersion) String() string {
1294 switch v {
1295 case JAVA_VERSION_6:
1296 return "1.6"
1297 case JAVA_VERSION_7:
1298 return "1.7"
1299 case JAVA_VERSION_8:
1300 return "1.8"
1301 case JAVA_VERSION_9:
1302 return "1.9"
1303 default:
1304 return "unsupported"
1305 }
1306}
1307
1308// Returns true if javac targeting this version uses system modules instead of a bootclasspath.
1309func (v javaVersion) usesJavaModules() bool {
1310 return v >= 9
1311}
1312
1313func normalizeJavaVersion(ctx android.BaseModuleContext, javaVersion string) javaVersion {
Pete Gillin4e8b48a2019-07-12 13:16:17 +01001314 switch javaVersion {
1315 case "1.6", "6":
Colin Cross1e743852019-10-28 11:37:20 -07001316 return JAVA_VERSION_6
Pete Gillin4e8b48a2019-07-12 13:16:17 +01001317 case "1.7", "7":
Colin Cross1e743852019-10-28 11:37:20 -07001318 return JAVA_VERSION_7
Pete Gillin4e8b48a2019-07-12 13:16:17 +01001319 case "1.8", "8":
Colin Cross1e743852019-10-28 11:37:20 -07001320 return JAVA_VERSION_8
Pete Gillin4e8b48a2019-07-12 13:16:17 +01001321 case "1.9", "9":
Colin Cross1e743852019-10-28 11:37:20 -07001322 return JAVA_VERSION_9
Pete Gillin4e8b48a2019-07-12 13:16:17 +01001323 case "10", "11":
1324 ctx.PropertyErrorf("java_version", "Java language levels above 9 are not supported")
Colin Cross1e743852019-10-28 11:37:20 -07001325 return JAVA_VERSION_UNSUPPORTED
Pete Gillin4e8b48a2019-07-12 13:16:17 +01001326 default:
1327 ctx.PropertyErrorf("java_version", "Unrecognized Java language level")
Colin Cross1e743852019-10-28 11:37:20 -07001328 return JAVA_VERSION_UNSUPPORTED
Pete Gillin4e8b48a2019-07-12 13:16:17 +01001329 }
1330}
1331
Nan Zhanged19fc32017-10-19 13:06:22 -07001332func (j *Module) collectBuilderFlags(ctx android.ModuleContext, deps deps) javaBuilderFlags {
Colin Crossc0b06f12015-04-08 13:03:43 -07001333
Colin Crossf03c82b2015-04-13 13:53:40 -07001334 var flags javaBuilderFlags
1335
Tobias Thierer06dd04f2018-09-11 16:21:05 +01001336 // javaVersion flag.
1337 flags.javaVersion = getJavaVersion(ctx, String(j.properties.Java_version), sdkContext(j))
1338
Colin Cross66548102018-06-19 22:47:35 -07001339 if ctx.Config().RunErrorProne() {
Colin Cross748b2d82020-11-19 13:52:06 -08001340 if config.ErrorProneClasspath == nil && ctx.Config().TestProductVariables == nil {
Colin Cross66548102018-06-19 22:47:35 -07001341 ctx.ModuleErrorf("cannot build with Error Prone, missing external/error_prone?")
1342 }
1343
1344 errorProneFlags := []string{
1345 "-Xplugin:ErrorProne",
1346 "${config.ErrorProneChecks}",
1347 }
1348 errorProneFlags = append(errorProneFlags, j.properties.Errorprone.Javacflags...)
1349
1350 flags.errorProneExtraJavacFlags = "${config.ErrorProneFlags} " +
1351 "'" + strings.Join(errorProneFlags, " ") + "'"
1352 flags.errorProneProcessorPath = classpath(android.PathsForSource(ctx, config.ErrorProneClasspath))
Andreas Gampef3e5b552018-01-22 21:27:21 -08001353 }
1354
Nan Zhanged19fc32017-10-19 13:06:22 -07001355 // classpath
Nan Zhang581fd212018-01-10 16:06:12 -08001356 flags.bootClasspath = append(flags.bootClasspath, deps.bootClasspath...)
1357 flags.classpath = append(flags.classpath, deps.classpath...)
Colin Cross6cef4812019-10-17 14:23:50 -07001358 flags.java9Classpath = append(flags.java9Classpath, deps.java9Classpath...)
Colin Cross6a77c982018-06-19 22:43:34 -07001359 flags.processorPath = append(flags.processorPath, deps.processorPath...)
Colin Cross748b2d82020-11-19 13:52:06 -08001360 flags.errorProneProcessorPath = append(flags.errorProneProcessorPath, deps.errorProneProcessorPath...)
Colin Cross7fdd2b72018-01-02 18:14:25 -08001361
Colin Cross5a116862020-04-22 11:44:34 -07001362 flags.processors = append(flags.processors, deps.processorClasses...)
1363 flags.processors = android.FirstUniqueStrings(flags.processors)
Colin Crossbe9cdb82019-01-21 21:37:16 -08001364
Colin Cross1e743852019-10-28 11:37:20 -07001365 if len(flags.bootClasspath) == 0 && ctx.Host() && !flags.javaVersion.usesJavaModules() &&
1366 decodeSdkDep(ctx, sdkContext(j)).hasStandardLibs() {
Colin Cross7fdd2b72018-01-02 18:14:25 -08001367 // Give host-side tools a version of OpenJDK's standard libraries
1368 // close to what they're targeting. As of Dec 2017, AOSP is only
1369 // bundling OpenJDK 8 and 9, so nothing < 8 is available.
1370 //
1371 // When building with OpenJDK 8, the following should have no
1372 // effect since those jars would be available by default.
1373 //
1374 // When building with OpenJDK 9 but targeting a version < 1.8,
1375 // putting them on the bootclasspath means that:
1376 // a) code can't (accidentally) refer to OpenJDK 9 specific APIs
1377 // b) references to existing APIs are not reinterpreted in an
1378 // OpenJDK 9-specific way, eg. calls to subclasses of
1379 // java.nio.Buffer as in http://b/70862583
1380 java8Home := ctx.Config().Getenv("ANDROID_JAVA8_HOME")
1381 flags.bootClasspath = append(flags.bootClasspath,
1382 android.PathForSource(ctx, java8Home, "jre/lib/jce.jar"),
1383 android.PathForSource(ctx, java8Home, "jre/lib/rt.jar"))
Nan Zhang5f8cb422018-02-06 10:34:32 -08001384 if Bool(j.properties.Use_tools_jar) {
1385 flags.bootClasspath = append(flags.bootClasspath,
1386 android.PathForSource(ctx, java8Home, "lib/tools.jar"))
1387 }
Colin Cross7fdd2b72018-01-02 18:14:25 -08001388 }
1389
Nan Zhanged19fc32017-10-19 13:06:22 -07001390 // systemModules
Colin Crossb77043e2019-07-16 13:57:13 -07001391 flags.systemModules = deps.systemModules
Colin Cross1369cdb2017-09-29 17:58:17 -07001392
Nan Zhanged19fc32017-10-19 13:06:22 -07001393 // aidl flags.
Colin Cross3047fa22019-04-18 10:56:44 -07001394 flags.aidlFlags, flags.aidlDeps = j.aidlFlags(ctx, deps.aidlPreprocess, deps.aidlIncludeDirs)
Colin Cross2fe66872015-03-30 17:20:39 -07001395
Jingwen Chen9cb8d1b2020-10-21 10:06:35 -04001396 return flags
1397}
1398
Jingwen Chen5136a6e2020-10-30 01:01:35 -04001399func (j *Module) collectJavacFlags(
1400 ctx android.ModuleContext, flags javaBuilderFlags, srcFiles android.Paths) javaBuilderFlags {
Jingwen Chen9cb8d1b2020-10-21 10:06:35 -04001401 // javac flags.
1402 javacFlags := j.properties.Javacflags
1403
1404 if ctx.Config().MinimizeJavaDebugInfo() && !ctx.Host() {
1405 // For non-host binaries, override the -g flag passed globally to remove
1406 // local variable debug info to reduce disk and memory usage.
1407 javacFlags = append(javacFlags, "-g:source,lines")
1408 }
1409 javacFlags = append(javacFlags, "-Xlint:-dep-ann")
1410
1411 if flags.javaVersion.usesJavaModules() {
1412 javacFlags = append(javacFlags, j.properties.Openjdk9.Javacflags...)
1413
1414 if j.properties.Patch_module != nil {
1415 // Manually specify build directory in case it is not under the repo root.
Jingwen Chen5136a6e2020-10-30 01:01:35 -04001416 // (javac doesn't seem to expand into symbolic links when searching for patch-module targets, so
Jingwen Chen9cb8d1b2020-10-21 10:06:35 -04001417 // just adding a symlink under the root doesn't help.)
Jingwen Chen5136a6e2020-10-30 01:01:35 -04001418 patchPaths := []string{".", ctx.Config().BuildDir()}
1419
1420 // b/150878007
1421 //
1422 // Workaround to support *Bazel-executed* JDK9 javac in Bazel's
1423 // execution root for --patch-module. If this javac command line is
1424 // invoked within Bazel's execution root working directory, the top
1425 // level directories (e.g. libcore/, tools/, frameworks/) are all
1426 // symlinks. JDK9 javac does not traverse into symlinks, which causes
1427 // --patch-module to fail source file lookups when invoked in the
1428 // execution root.
1429 //
1430 // Short of patching javac or enumerating *all* directories as possible
1431 // input dirs, manually add the top level dir of the source files to be
1432 // compiled.
1433 topLevelDirs := map[string]bool{}
1434 for _, srcFilePath := range srcFiles {
1435 srcFileParts := strings.Split(srcFilePath.String(), "/")
1436 // Ignore source files that are already in the top level directory
1437 // as well as generated files in the out directory. The out
1438 // directory may be an absolute path, which means srcFileParts[0] is the
1439 // empty string, so check that as well. Note that "out" in Bazel's execution
1440 // root is *not* a symlink, which doesn't cause problems for --patch-modules
1441 // anyway, so it's fine to not apply this workaround for generated
1442 // source files.
1443 if len(srcFileParts) > 1 &&
1444 srcFileParts[0] != "" &&
1445 srcFileParts[0] != "out" {
1446 topLevelDirs[srcFileParts[0]] = true
1447 }
1448 }
1449 patchPaths = append(patchPaths, android.SortedStringKeys(topLevelDirs)...)
1450
Jingwen Chen9cb8d1b2020-10-21 10:06:35 -04001451 classPath := flags.classpath.FormJavaClassPath("")
1452 if classPath != "" {
Jingwen Chen5136a6e2020-10-30 01:01:35 -04001453 patchPaths = append(patchPaths, classPath)
Jingwen Chen9cb8d1b2020-10-21 10:06:35 -04001454 }
Jingwen Chen5136a6e2020-10-30 01:01:35 -04001455 javacFlags = append(
1456 javacFlags,
1457 "--patch-module="+String(j.properties.Patch_module)+"="+strings.Join(patchPaths, ":"))
Jingwen Chen9cb8d1b2020-10-21 10:06:35 -04001458 }
1459 }
1460
Colin Cross81440082018-08-15 20:21:55 -07001461 if len(javacFlags) > 0 {
1462 // optimization.
1463 ctx.Variable(pctx, "javacFlags", strings.Join(javacFlags, " "))
1464 flags.javacFlags = "$javacFlags"
1465 }
1466
Nan Zhanged19fc32017-10-19 13:06:22 -07001467 return flags
1468}
Colin Crossc0b06f12015-04-08 13:03:43 -07001469
Jaewoong Junga24af3b2019-05-13 09:23:20 -07001470func (j *Module) compile(ctx android.ModuleContext, aaptSrcJar android.Path) {
Colin Crossebe1a512017-11-14 13:12:14 -08001471 j.exportAidlIncludeDirs = android.PathsForModuleSrc(ctx, j.deviceProperties.Aidl.Export_include_dirs)
Nan Zhanged19fc32017-10-19 13:06:22 -07001472
1473 deps := j.collectDeps(ctx)
1474 flags := j.collectBuilderFlags(ctx, deps)
1475
Colin Cross1e743852019-10-28 11:37:20 -07001476 if flags.javaVersion.usesJavaModules() {
Nan Zhanged19fc32017-10-19 13:06:22 -07001477 j.properties.Srcs = append(j.properties.Srcs, j.properties.Openjdk9.Srcs...)
1478 }
Colin Cross8a497952019-03-05 22:25:09 -08001479 srcFiles := android.PathsForModuleSrcExcludes(ctx, j.properties.Srcs, j.properties.Exclude_srcs)
Colin Cross6af17aa2017-09-20 12:59:05 -07001480 if hasSrcExt(srcFiles.Strings(), ".proto") {
Colin Cross0f2ee152017-12-14 15:22:43 -08001481 flags = protoFlags(ctx, &j.properties, &j.protoProperties, flags)
Colin Cross6af17aa2017-09-20 12:59:05 -07001482 }
1483
Colin Crossa4c8cc62020-06-25 17:13:36 -07001484 kotlinCommonSrcFiles := android.PathsForModuleSrcExcludes(ctx, j.properties.Common_srcs, nil)
1485 if len(kotlinCommonSrcFiles.FilterOutByExt(".kt")) > 0 {
1486 ctx.PropertyErrorf("common_srcs", "common_srcs must be .kt files")
1487 }
1488
Colin Crossaf050172017-11-15 23:01:59 -08001489 srcFiles = j.genSources(ctx, srcFiles, flags)
1490
Jingwen Chen5136a6e2020-10-30 01:01:35 -04001491 // Collect javac flags only after computing the full set of srcFiles to
1492 // ensure that the --patch-module lookup paths are complete.
1493 flags = j.collectJavacFlags(ctx, flags, srcFiles)
Jingwen Chen9cb8d1b2020-10-21 10:06:35 -04001494
Colin Crossaf050172017-11-15 23:01:59 -08001495 srcJars := srcFiles.FilterByExt(".srcjar")
Colin Cross59149b62017-10-16 18:07:29 -07001496 srcJars = append(srcJars, deps.srcJars...)
Jaewoong Junga24af3b2019-05-13 09:23:20 -07001497 if aaptSrcJar != nil {
1498 srcJars = append(srcJars, aaptSrcJar)
1499 }
Colin Crossb7a63242015-04-16 14:09:14 -07001500
Steven Morelandc4efd9c2019-01-18 11:51:25 -08001501 if j.properties.Jarjar_rules != nil {
Colin Cross8a497952019-03-05 22:25:09 -08001502 j.expandJarjarRules = android.PathForModuleSrc(ctx, *j.properties.Jarjar_rules)
Steven Morelandc4efd9c2019-01-18 11:51:25 -08001503 }
1504
Colin Cross1ee23172017-10-18 14:44:18 -07001505 jarName := ctx.ModuleName() + ".jar"
1506
Przemyslaw Szczepaniak4b5fe9d2018-02-13 14:32:54 +00001507 javaSrcFiles := srcFiles.FilterByExt(".java")
1508 var uniqueSrcFiles android.Paths
1509 set := make(map[string]bool)
1510 for _, v := range javaSrcFiles {
1511 if _, found := set[v.String()]; !found {
1512 set[v.String()] = true
1513 uniqueSrcFiles = append(uniqueSrcFiles, v)
1514 }
1515 }
1516
patricktu242faad2019-09-24 15:41:30 +08001517 // Collect .java files for AIDEGen
1518 j.expandIDEInfoCompiledSrcs = append(j.expandIDEInfoCompiledSrcs, uniqueSrcFiles.Strings()...)
1519
Colin Cross55f63ea2018-08-27 12:37:09 -07001520 var kotlinJars android.Paths
1521
Colin Cross93e85952017-08-15 13:34:18 -07001522 if srcFiles.HasExt(".kt") {
Zoran Jovanovic8736ce22018-08-21 17:10:29 +02001523 // user defined kotlin flags.
1524 kotlincFlags := j.properties.Kotlincflags
1525 CheckKotlincFlags(ctx, kotlincFlags)
1526
Mads Agerad2bfda2020-12-03 12:21:14 +01001527 // Dogfood the JVM_IR backend.
1528 kotlincFlags = append(kotlincFlags, "-Xuse-ir")
1529
Colin Cross93e85952017-08-15 13:34:18 -07001530 // If there are kotlin files, compile them first but pass all the kotlin and java files
1531 // kotlinc will use the java files to resolve types referenced by the kotlin files, but
1532 // won't emit any classes for them.
Zoran Jovanovic8736ce22018-08-21 17:10:29 +02001533 kotlincFlags = append(kotlincFlags, "-no-stdlib")
Colin Cross93e85952017-08-15 13:34:18 -07001534 if ctx.Device() {
Zoran Jovanovic8736ce22018-08-21 17:10:29 +02001535 kotlincFlags = append(kotlincFlags, "-no-jdk")
1536 }
1537 if len(kotlincFlags) > 0 {
1538 // optimization.
1539 ctx.Variable(pctx, "kotlincFlags", strings.Join(kotlincFlags, " "))
1540 flags.kotlincFlags += "$kotlincFlags"
Colin Cross93e85952017-08-15 13:34:18 -07001541 }
1542
Przemyslaw Szczepaniak4b5fe9d2018-02-13 14:32:54 +00001543 var kotlinSrcFiles android.Paths
1544 kotlinSrcFiles = append(kotlinSrcFiles, uniqueSrcFiles...)
1545 kotlinSrcFiles = append(kotlinSrcFiles, srcFiles.FilterByExt(".kt")...)
1546
patricktu242faad2019-09-24 15:41:30 +08001547 // Collect .kt files for AIDEGen
1548 j.expandIDEInfoCompiledSrcs = append(j.expandIDEInfoCompiledSrcs, srcFiles.FilterByExt(".kt").Strings()...)
Colin Crossa4c8cc62020-06-25 17:13:36 -07001549 j.expandIDEInfoCompiledSrcs = append(j.expandIDEInfoCompiledSrcs, kotlinCommonSrcFiles.Strings()...)
patricktu242faad2019-09-24 15:41:30 +08001550
Colin Crossafbb1732019-01-17 15:42:52 -08001551 flags.classpath = append(flags.classpath, deps.kotlinStdlib...)
1552 flags.classpath = append(flags.classpath, deps.kotlinAnnotations...)
1553
1554 flags.kotlincClasspath = append(flags.kotlincClasspath, flags.bootClasspath...)
1555 flags.kotlincClasspath = append(flags.kotlincClasspath, flags.classpath...)
1556
1557 if len(flags.processorPath) > 0 {
1558 // Use kapt for annotation processing
1559 kaptSrcJar := android.PathForModuleOut(ctx, "kapt", "kapt-sources.jar")
Colin Cross9ca38d22020-06-18 15:46:32 -07001560 kaptResJar := android.PathForModuleOut(ctx, "kapt", "kapt-res.jar")
Colin Crossa4c8cc62020-06-25 17:13:36 -07001561 kotlinKapt(ctx, kaptSrcJar, kaptResJar, kotlinSrcFiles, kotlinCommonSrcFiles, srcJars, flags)
Colin Crossafbb1732019-01-17 15:42:52 -08001562 srcJars = append(srcJars, kaptSrcJar)
Colin Cross9ca38d22020-06-18 15:46:32 -07001563 kotlinJars = append(kotlinJars, kaptResJar)
Colin Crossafbb1732019-01-17 15:42:52 -08001564 // Disable annotation processing in javac, it's already been handled by kapt
1565 flags.processorPath = nil
Colin Cross5a116862020-04-22 11:44:34 -07001566 flags.processors = nil
Colin Crossafbb1732019-01-17 15:42:52 -08001567 }
Colin Cross93e85952017-08-15 13:34:18 -07001568
Colin Cross1ee23172017-10-18 14:44:18 -07001569 kotlinJar := android.PathForModuleOut(ctx, "kotlin", jarName)
Colin Crossa4c8cc62020-06-25 17:13:36 -07001570 kotlinCompile(ctx, kotlinJar, kotlinSrcFiles, kotlinCommonSrcFiles, srcJars, flags)
Colin Cross93e85952017-08-15 13:34:18 -07001571 if ctx.Failed() {
1572 return
1573 }
1574
1575 // Make javac rule depend on the kotlinc rule
1576 flags.classpath = append(flags.classpath, kotlinJar)
Przemyslaw Szczepaniak66c0c402018-03-08 13:21:55 +00001577
Colin Cross55f63ea2018-08-27 12:37:09 -07001578 kotlinJars = append(kotlinJars, kotlinJar)
Colin Cross0b67a8b2020-06-18 15:52:01 -07001579 // Jar kotlin classes into the final jar after javac
1580 if BoolDefault(j.properties.Static_kotlin_stdlib, true) {
1581 kotlinJars = append(kotlinJars, deps.kotlinStdlib...)
1582 }
Colin Cross93e85952017-08-15 13:34:18 -07001583 }
1584
Colin Cross55f63ea2018-08-27 12:37:09 -07001585 jars := append(android.Paths(nil), kotlinJars...)
1586
Colin Cross5ab4e6d2017-11-22 16:20:45 -08001587 // Store the list of .java files that was passed to javac
1588 j.compiledJavaSrcs = uniqueSrcFiles
1589 j.compiledSrcJars = srcJars
1590
Jaewoong Jung18aefc12020-12-21 09:11:10 -08001591 enableSharding := false
Colin Crossf7d84012020-02-21 08:16:41 -08001592 var headerJarFileWithoutJarjar android.Path
Colin Crossbe9cdb82019-01-21 21:37:16 -08001593 if ctx.Device() && !ctx.Config().IsEnvFalse("TURBINE_ENABLED") && !deps.disableTurbine {
Nan Zhang61eaedb2017-11-02 13:28:15 -07001594 if j.properties.Javac_shard_size != nil && *(j.properties.Javac_shard_size) > 0 {
Jaewoong Jung18aefc12020-12-21 09:11:10 -08001595 enableSharding = true
Ashley Rosee36efcf2019-01-16 17:34:08 -05001596 // Formerly, there was a check here that prevented annotation processors
1597 // from being used when sharding was enabled, as some annotation processors
1598 // do not function correctly in sharded environments. It was removed to
1599 // allow for the use of annotation processors that do function correctly
1600 // with sharding enabled. See: b/77284273.
Nan Zhang61eaedb2017-11-02 13:28:15 -07001601 }
Colin Crossf7d84012020-02-21 08:16:41 -08001602 headerJarFileWithoutJarjar, j.headerJarFile =
1603 j.compileJavaHeader(ctx, uniqueSrcFiles, srcJars, deps, flags, jarName, kotlinJars)
Colin Crossf19b9bb2018-03-26 14:42:44 -07001604 if ctx.Failed() {
1605 return
Nan Zhanged19fc32017-10-19 13:06:22 -07001606 }
1607 }
Colin Cross8eadbf02017-10-24 17:46:00 -07001608 if len(uniqueSrcFiles) > 0 || len(srcJars) > 0 {
Colin Crossd6891432017-09-27 17:39:56 -07001609 var extraJarDeps android.Paths
Colin Cross66548102018-06-19 22:47:35 -07001610 if ctx.Config().RunErrorProne() {
Colin Crossc6bbef32017-08-14 14:16:06 -07001611 // If error-prone is enabled, add an additional rule to compile the java files into
1612 // a separate set of classes (so that they don't overwrite the normal ones and require
Colin Crossd6891432017-09-27 17:39:56 -07001613 // a rebuild when error-prone is turned off).
Colin Crossc6bbef32017-08-14 14:16:06 -07001614 // TODO(ccross): Once we always compile with javac9 we may be able to conditionally
1615 // enable error-prone without affecting the output class files.
Colin Cross1ee23172017-10-18 14:44:18 -07001616 errorprone := android.PathForModuleOut(ctx, "errorprone", jarName)
Nan Zhang61eaedb2017-11-02 13:28:15 -07001617 RunErrorProne(ctx, errorprone, uniqueSrcFiles, srcJars, flags)
Colin Crossc6bbef32017-08-14 14:16:06 -07001618 extraJarDeps = append(extraJarDeps, errorprone)
1619 }
1620
Jaewoong Jung18aefc12020-12-21 09:11:10 -08001621 if enableSharding {
Colin Crossf7d84012020-02-21 08:16:41 -08001622 flags.classpath = append(flags.classpath, headerJarFileWithoutJarjar)
Nan Zhang61eaedb2017-11-02 13:28:15 -07001623 shardSize := int(*(j.properties.Javac_shard_size))
1624 var shardSrcs []android.Paths
1625 if len(uniqueSrcFiles) > 0 {
Colin Cross0a2f7192019-09-23 14:33:09 -07001626 shardSrcs = android.ShardPaths(uniqueSrcFiles, shardSize)
Nan Zhang61eaedb2017-11-02 13:28:15 -07001627 for idx, shardSrc := range shardSrcs {
Colin Cross3b706fd2019-09-05 16:44:18 -07001628 classes := j.compileJavaClasses(ctx, jarName, idx, shardSrc,
1629 nil, flags, extraJarDeps)
Nan Zhang61eaedb2017-11-02 13:28:15 -07001630 jars = append(jars, classes)
1631 }
1632 }
1633 if len(srcJars) > 0 {
Colin Cross3b706fd2019-09-05 16:44:18 -07001634 classes := j.compileJavaClasses(ctx, jarName, len(shardSrcs),
1635 nil, srcJars, flags, extraJarDeps)
Nan Zhang61eaedb2017-11-02 13:28:15 -07001636 jars = append(jars, classes)
1637 }
1638 } else {
Colin Cross3b706fd2019-09-05 16:44:18 -07001639 classes := j.compileJavaClasses(ctx, jarName, -1, uniqueSrcFiles, srcJars, flags, extraJarDeps)
Nan Zhang61eaedb2017-11-02 13:28:15 -07001640 jars = append(jars, classes)
1641 }
Colin Crossd6891432017-09-27 17:39:56 -07001642 if ctx.Failed() {
1643 return
1644 }
Colin Cross2fe66872015-03-30 17:20:39 -07001645 }
1646
Colin Cross0c4ce212019-05-03 15:28:19 -07001647 j.srcJarArgs, j.srcJarDeps = resourcePathsToJarArgs(srcFiles), srcFiles
1648
1649 var includeSrcJar android.WritablePath
1650 if Bool(j.properties.Include_srcs) {
1651 includeSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+".srcjar")
1652 TransformResourcesToJar(ctx, includeSrcJar, j.srcJarArgs, j.srcJarDeps)
1653 }
1654
Colin Crosscedd4762018-09-13 11:26:19 -07001655 dirArgs, dirDeps := ResourceDirsToJarArgs(ctx, j.properties.Java_resource_dirs,
1656 j.properties.Exclude_java_resource_dirs, j.properties.Exclude_java_resources)
Colin Cross0f37af02017-09-27 17:42:05 -07001657 fileArgs, fileDeps := ResourceFilesToJarArgs(ctx, j.properties.Java_resources, j.properties.Exclude_java_resources)
Colin Cross988708c2019-05-06 14:04:11 -07001658 extraArgs, extraDeps := resourcePathsToJarArgs(j.extraResources), j.extraResources
Colin Cross0f37af02017-09-27 17:42:05 -07001659
1660 var resArgs []string
1661 var resDeps android.Paths
1662
1663 resArgs = append(resArgs, dirArgs...)
1664 resDeps = append(resDeps, dirDeps...)
1665
1666 resArgs = append(resArgs, fileArgs...)
1667 resDeps = append(resDeps, fileDeps...)
1668
Colin Cross988708c2019-05-06 14:04:11 -07001669 resArgs = append(resArgs, extraArgs...)
1670 resDeps = append(resDeps, extraDeps...)
1671
Colin Cross40a36712017-09-27 17:41:35 -07001672 if len(resArgs) > 0 {
Colin Cross1ee23172017-10-18 14:44:18 -07001673 resourceJar := android.PathForModuleOut(ctx, "res", jarName)
Colin Crosse9a275b2017-10-16 17:09:48 -07001674 TransformResourcesToJar(ctx, resourceJar, resArgs, resDeps)
Colin Cross331a1212018-08-15 20:40:52 -07001675 j.resourceJar = resourceJar
Colin Cross65bf4f22015-04-03 16:54:17 -07001676 if ctx.Failed() {
1677 return
1678 }
1679 }
1680
Colin Cross0c4ce212019-05-03 15:28:19 -07001681 var resourceJars android.Paths
1682 if j.resourceJar != nil {
1683 resourceJars = append(resourceJars, j.resourceJar)
1684 }
1685 if Bool(j.properties.Include_srcs) {
1686 resourceJars = append(resourceJars, includeSrcJar)
1687 }
1688 resourceJars = append(resourceJars, deps.staticResourceJars...)
Colin Cross331a1212018-08-15 20:40:52 -07001689
Colin Cross0c4ce212019-05-03 15:28:19 -07001690 if len(resourceJars) > 1 {
Colin Cross331a1212018-08-15 20:40:52 -07001691 combinedJar := android.PathForModuleOut(ctx, "res-combined", jarName)
Colin Cross0c4ce212019-05-03 15:28:19 -07001692 TransformJarsToJar(ctx, combinedJar, "for resources", resourceJars, android.OptionalPath{},
Colin Cross331a1212018-08-15 20:40:52 -07001693 false, nil, nil)
1694 j.resourceJar = combinedJar
Colin Cross0c4ce212019-05-03 15:28:19 -07001695 } else if len(resourceJars) == 1 {
1696 j.resourceJar = resourceJars[0]
Colin Cross331a1212018-08-15 20:40:52 -07001697 }
1698
Jaewoong Junga24af3b2019-05-13 09:23:20 -07001699 if len(deps.staticJars) > 0 {
1700 jars = append(jars, deps.staticJars...)
Jaewoong Junga24af3b2019-05-13 09:23:20 -07001701 }
Colin Cross0a6e0072017-08-30 14:24:55 -07001702
Colin Cross094054a2018-10-17 15:10:48 -07001703 manifest := j.overrideManifest
1704 if !manifest.Valid() && j.properties.Manifest != nil {
Colin Cross8a497952019-03-05 22:25:09 -08001705 manifest = android.OptionalPathForPath(android.PathForModuleSrc(ctx, *j.properties.Manifest))
Colin Cross366938f2017-12-11 16:29:02 -08001706 }
Colin Cross635acc92017-09-12 22:50:46 -07001707
Colin Cross8a497952019-03-05 22:25:09 -08001708 services := android.PathsForModuleSrc(ctx, j.properties.Services)
Alex Light7f004a72019-02-21 13:27:37 -08001709 if len(services) > 0 {
1710 servicesJar := android.PathForModuleOut(ctx, "services", jarName)
1711 var zipargs []string
1712 for _, file := range services {
1713 serviceFile := file.String()
1714 zipargs = append(zipargs, "-C", filepath.Dir(serviceFile), "-f", serviceFile)
1715 }
Kousik Kumar366afc52020-05-20 11:27:16 -07001716 rule := zip
1717 args := map[string]string{
1718 "jarArgs": "-P META-INF/services/ " + strings.Join(proptools.NinjaAndShellEscapeList(zipargs), " "),
1719 }
Ramy Medhat16f23a42020-09-03 01:29:49 -04001720 if ctx.Config().UseRBE() && ctx.Config().IsEnvTrue("RBE_ZIP") {
Kousik Kumar366afc52020-05-20 11:27:16 -07001721 rule = zipRE
1722 args["implicits"] = strings.Join(services.Strings(), ",")
1723 }
Alex Light7f004a72019-02-21 13:27:37 -08001724 ctx.Build(pctx, android.BuildParams{
Kousik Kumar366afc52020-05-20 11:27:16 -07001725 Rule: rule,
Alex Light7f004a72019-02-21 13:27:37 -08001726 Output: servicesJar,
1727 Implicits: services,
Kousik Kumar366afc52020-05-20 11:27:16 -07001728 Args: args,
Alex Light7f004a72019-02-21 13:27:37 -08001729 })
1730 jars = append(jars, servicesJar)
1731 }
1732
Colin Cross0a6e0072017-08-30 14:24:55 -07001733 // Combine the classes built from sources, any manifests, and any static libraries into
Nan Zhanged19fc32017-10-19 13:06:22 -07001734 // classes.jar. If there is only one input jar this step will be skipped.
Paul Duffin612e6102021-02-02 13:38:13 +00001735 var outputFile android.OutputPath
Colin Crosse9a275b2017-10-16 17:09:48 -07001736
1737 if len(jars) == 1 && !manifest.Valid() {
Paul Duffin612e6102021-02-02 13:38:13 +00001738 // Optimization: skip the combine step as there is nothing to do
1739 // TODO(ccross): this leaves any module-info.class files, but those should only come from
1740 // prebuilt dependencies until we support modules in the platform build, so there shouldn't be
1741 // any if len(jars) == 1.
1742
1743 // Transform the single path to the jar into an OutputPath as that is required by the following
1744 // code.
Colin Cross3063b782018-08-15 11:19:12 -07001745 if moduleOutPath, ok := jars[0].(android.ModuleOutPath); ok {
Paul Duffin612e6102021-02-02 13:38:13 +00001746 // The path contains an embedded OutputPath so reuse that.
1747 outputFile = moduleOutPath.OutputPath
1748 } else if outputPath, ok := jars[0].(android.OutputPath); ok {
1749 // The path is an OutputPath so reuse it directly.
1750 outputFile = outputPath
Colin Cross3063b782018-08-15 11:19:12 -07001751 } else {
Paul Duffin612e6102021-02-02 13:38:13 +00001752 // The file is not in the out directory so create an OutputPath into which it can be copied
1753 // and which the following code can use to refer to it.
Colin Cross3063b782018-08-15 11:19:12 -07001754 combinedJar := android.PathForModuleOut(ctx, "combined", jarName)
1755 ctx.Build(pctx, android.BuildParams{
1756 Rule: android.Cp,
1757 Input: jars[0],
1758 Output: combinedJar,
1759 })
Paul Duffin612e6102021-02-02 13:38:13 +00001760 outputFile = combinedJar.OutputPath
Colin Cross3063b782018-08-15 11:19:12 -07001761 }
Colin Crosse9a275b2017-10-16 17:09:48 -07001762 } else {
Colin Cross1ee23172017-10-18 14:44:18 -07001763 combinedJar := android.PathForModuleOut(ctx, "combined", jarName)
Colin Cross37f6d792018-07-12 12:28:41 -07001764 TransformJarsToJar(ctx, combinedJar, "for javac", jars, manifest,
Colin Cross9b38aef2018-08-27 15:42:25 -07001765 false, nil, nil)
Paul Duffin612e6102021-02-02 13:38:13 +00001766 outputFile = combinedJar.OutputPath
Colin Crosse9a275b2017-10-16 17:09:48 -07001767 }
Colin Cross0a6e0072017-08-30 14:24:55 -07001768
Colin Cross331a1212018-08-15 20:40:52 -07001769 // jarjar implementation jar if necessary
Steven Morelandc4efd9c2019-01-18 11:51:25 -08001770 if j.expandJarjarRules != nil {
Colin Cross8649b262017-09-27 18:03:17 -07001771 // Transform classes.jar into classes-jarjar.jar
Paul Duffin612e6102021-02-02 13:38:13 +00001772 jarjarFile := android.PathForModuleOut(ctx, "jarjar", jarName).OutputPath
Steven Morelandc4efd9c2019-01-18 11:51:25 -08001773 TransformJarJar(ctx, jarjarFile, outputFile, j.expandJarjarRules)
Colin Crosse9a275b2017-10-16 17:09:48 -07001774 outputFile = jarjarFile
Colin Cross331a1212018-08-15 20:40:52 -07001775
1776 // jarjar resource jar if necessary
1777 if j.resourceJar != nil {
1778 resourceJarJarFile := android.PathForModuleOut(ctx, "res-jarjar", jarName)
Steven Morelandc4efd9c2019-01-18 11:51:25 -08001779 TransformJarJar(ctx, resourceJarJarFile, j.resourceJar, j.expandJarjarRules)
Colin Cross331a1212018-08-15 20:40:52 -07001780 j.resourceJar = resourceJarJarFile
1781 }
1782
Colin Cross0a6e0072017-08-30 14:24:55 -07001783 if ctx.Failed() {
1784 return
1785 }
1786 }
Vladimir Marko0975ee02019-04-02 10:29:55 +01001787
1788 // Check package restrictions if necessary.
1789 if len(j.properties.Permitted_packages) > 0 {
1790 // Check packages and copy to package-checked file.
1791 pkgckFile := android.PathForModuleOut(ctx, "package-check.stamp")
1792 CheckJarPackages(ctx, pkgckFile, outputFile, j.properties.Permitted_packages)
1793 j.additionalCheckedModules = append(j.additionalCheckedModules, pkgckFile)
1794
1795 if ctx.Failed() {
1796 return
1797 }
1798 }
1799
Nan Zhanged19fc32017-10-19 13:06:22 -07001800 j.implementationJarFile = outputFile
1801 if j.headerJarFile == nil {
1802 j.headerJarFile = j.implementationJarFile
1803 }
Colin Cross2fe66872015-03-30 17:20:39 -07001804
Chris Gross190fdc02020-05-29 16:01:19 +00001805 if j.shouldInstrumentInApex(ctx) {
Jiyong Park00cae1c2020-02-18 12:50:44 +00001806 j.properties.Instrument = true
1807 }
1808
Colin Cross3144dfc2018-01-03 15:06:47 -08001809 if j.shouldInstrument(ctx) {
Colin Crosscb933592017-11-22 13:49:43 -08001810 outputFile = j.instrument(ctx, flags, outputFile, jarName)
1811 }
1812
Colin Cross331a1212018-08-15 20:40:52 -07001813 // merge implementation jar with resources if necessary
1814 implementationAndResourcesJar := outputFile
1815 if j.resourceJar != nil {
Colin Cross08a409d2019-04-29 10:22:44 -07001816 jars := android.Paths{j.resourceJar, implementationAndResourcesJar}
Paul Duffin612e6102021-02-02 13:38:13 +00001817 combinedJar := android.PathForModuleOut(ctx, "withres", jarName).OutputPath
Colin Cross08a409d2019-04-29 10:22:44 -07001818 TransformJarsToJar(ctx, combinedJar, "for resources", jars, manifest,
Colin Cross331a1212018-08-15 20:40:52 -07001819 false, nil, nil)
1820 implementationAndResourcesJar = combinedJar
1821 }
1822
1823 j.implementationAndResourcesJar = implementationAndResourcesJar
1824
Jiyong Park6b21c7d2020-02-11 09:16:01 +09001825 // Enable dex compilation for the APEX variants, unless it is disabled explicitly
Colin Cross56a83212020-09-15 18:30:11 -07001826 apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo)
1827 if j.DirectlyInAnyApex() && !apexInfo.IsForPlatform() {
Liz Kammera7a64f32020-07-09 15:16:41 -07001828 if j.dexProperties.Compile_dex == nil {
1829 j.dexProperties.Compile_dex = proptools.BoolPtr(true)
Jiyong Park6b21c7d2020-02-11 09:16:01 +09001830 }
1831 if j.deviceProperties.Hostdex == nil {
1832 j.deviceProperties.Hostdex = proptools.BoolPtr(true)
1833 }
1834 }
1835
Colin Crossb014f072021-02-26 14:54:36 -08001836 if ctx.Device() && (Bool(j.properties.Installable) || Bool(j.dexProperties.Compile_dex)) {
1837 if j.hasCode(ctx) {
1838 if j.shouldInstrumentStatic(ctx) {
1839 j.dexer.extraProguardFlagFiles = append(j.dexer.extraProguardFlagFiles,
1840 android.PathForSource(ctx, "build/make/core/proguard.jacoco.flags"))
Nicolas Geoffrayf3438722019-01-23 15:57:21 +00001841 }
Colin Crossb014f072021-02-26 14:54:36 -08001842 // Dex compilation
1843 var dexOutputFile android.OutputPath
1844 dexOutputFile = j.dexer.compileDex(ctx, flags, j.minSdkVersion(), outputFile, jarName)
1845 if ctx.Failed() {
1846 return
1847 }
1848
1849 // Hidden API CSV generation and dex encoding
1850 dexOutputFile = j.hiddenAPIExtractAndEncode(ctx, dexOutputFile, j.implementationJarFile,
1851 proptools.Bool(j.dexProperties.Uncompress_dex))
1852
1853 // merge dex jar with resources if necessary
1854 if j.resourceJar != nil {
1855 jars := android.Paths{dexOutputFile, j.resourceJar}
1856 combinedJar := android.PathForModuleOut(ctx, "dex-withres", jarName).OutputPath
1857 TransformJarsToJar(ctx, combinedJar, "for dex resources", jars, android.OptionalPath{},
1858 false, nil, nil)
1859 if *j.dexProperties.Uncompress_dex {
1860 combinedAlignedJar := android.PathForModuleOut(ctx, "dex-withres-aligned", jarName).OutputPath
1861 TransformZipAlign(ctx, combinedAlignedJar, combinedJar)
1862 dexOutputFile = combinedAlignedJar
1863 } else {
1864 dexOutputFile = combinedJar
1865 }
1866 }
1867
1868 j.dexJarFile = dexOutputFile
1869
1870 // Dexpreopting
1871 j.dexpreopt(ctx, dexOutputFile)
1872
1873 outputFile = dexOutputFile
1874 } else {
1875 // There is no code to compile into a dex jar, make sure the resources are propagated
1876 // to the APK if this is an app.
1877 outputFile = implementationAndResourcesJar
1878 j.dexJarFile = j.resourceJar
Colin Cross331a1212018-08-15 20:40:52 -07001879 }
1880
Colin Cross43f08db2018-11-12 10:13:39 -08001881 if ctx.Failed() {
1882 return
1883 }
Colin Cross331a1212018-08-15 20:40:52 -07001884 } else {
1885 outputFile = implementationAndResourcesJar
Colin Cross2fe66872015-03-30 17:20:39 -07001886 }
Colin Cross331a1212018-08-15 20:40:52 -07001887
Colin Cross014489c2020-06-02 20:09:13 -07001888 if ctx.Device() {
1889 lintSDKVersionString := func(sdkSpec sdkSpec) string {
1890 if v := sdkSpec.version; v.isNumbered() {
1891 return v.String()
1892 } else {
Dan Albert4f378d72020-07-23 17:32:15 -07001893 return ctx.Config().DefaultAppTargetSdk(ctx).String()
Colin Cross014489c2020-06-02 20:09:13 -07001894 }
1895 }
1896
1897 j.linter.name = ctx.ModuleName()
1898 j.linter.srcs = srcFiles
1899 j.linter.srcJars = srcJars
1900 j.linter.classpath = append(append(android.Paths(nil), flags.bootClasspath...), flags.classpath...)
1901 j.linter.classes = j.implementationJarFile
1902 j.linter.minSdkVersion = lintSDKVersionString(j.minSdkVersion())
1903 j.linter.targetSdkVersion = lintSDKVersionString(j.targetSdkVersion())
1904 j.linter.compileSdkVersion = lintSDKVersionString(j.sdkVersion())
1905 j.linter.javaLanguageLevel = flags.javaVersion.String()
1906 j.linter.kotlinLanguageLevel = "1.3"
Colin Cross56a83212020-09-15 18:30:11 -07001907 if !apexInfo.IsForPlatform() && ctx.Config().UnbundledBuildApps() {
Colin Cross08dca382020-07-21 20:31:17 -07001908 j.linter.buildModuleReportZip = true
1909 }
Colin Cross014489c2020-06-02 20:09:13 -07001910 j.linter.lint(ctx)
1911 }
1912
Colin Crossb7a63242015-04-16 14:09:14 -07001913 ctx.CheckbuildFile(outputFile)
Colin Cross3063b782018-08-15 11:19:12 -07001914
Colin Crossdcf71b22021-02-01 13:59:03 -08001915 ctx.SetProvider(JavaInfoProvider, JavaInfo{
1916 HeaderJars: android.PathsIfNonNil(j.headerJarFile),
1917 ImplementationAndResourcesJars: android.PathsIfNonNil(j.implementationAndResourcesJar),
1918 ImplementationJars: android.PathsIfNonNil(j.implementationJarFile),
1919 ResourceJars: android.PathsIfNonNil(j.resourceJar),
1920 AidlIncludeDirs: j.exportAidlIncludeDirs,
1921 SrcJarArgs: j.srcJarArgs,
1922 SrcJarDeps: j.srcJarDeps,
1923 ExportedPlugins: j.exportedPluginJars,
1924 ExportedPluginClasses: j.exportedPluginClasses,
1925 ExportedPluginDisableTurbine: j.exportedDisableTurbine,
1926 JacocoReportClassesFile: j.jacocoReportClassesFile,
1927 })
1928
Colin Cross3063b782018-08-15 11:19:12 -07001929 // Save the output file with no relative path so that it doesn't end up in a subdirectory when used as a resource
1930 j.outputFile = outputFile.WithoutRel()
Colin Cross2fe66872015-03-30 17:20:39 -07001931}
1932
Colin Cross3b706fd2019-09-05 16:44:18 -07001933func (j *Module) compileJavaClasses(ctx android.ModuleContext, jarName string, idx int,
1934 srcFiles, srcJars android.Paths, flags javaBuilderFlags, extraJarDeps android.Paths) android.WritablePath {
1935
1936 kzipName := pathtools.ReplaceExtension(jarName, "kzip")
1937 if idx >= 0 {
1938 kzipName = strings.TrimSuffix(jarName, filepath.Ext(jarName)) + strconv.Itoa(idx) + ".kzip"
1939 jarName += strconv.Itoa(idx)
1940 }
1941
Paul Duffin612e6102021-02-02 13:38:13 +00001942 classes := android.PathForModuleOut(ctx, "javac", jarName).OutputPath
Colin Cross3b706fd2019-09-05 16:44:18 -07001943 TransformJavaToClasses(ctx, classes, idx, srcFiles, srcJars, flags, extraJarDeps)
1944
1945 if ctx.Config().EmitXrefRules() {
1946 extractionFile := android.PathForModuleOut(ctx, kzipName)
1947 emitXrefRule(ctx, extractionFile, idx, srcFiles, srcJars, flags, extraJarDeps)
1948 j.kytheFiles = append(j.kytheFiles, extractionFile)
1949 }
1950
1951 return classes
1952}
1953
Zoran Jovanovic8736ce22018-08-21 17:10:29 +02001954// Check for invalid kotlinc flags. Only use this for flags explicitly passed by the user,
1955// since some of these flags may be used internally.
1956func CheckKotlincFlags(ctx android.ModuleContext, flags []string) {
1957 for _, flag := range flags {
1958 flag = strings.TrimSpace(flag)
1959
1960 if !strings.HasPrefix(flag, "-") {
1961 ctx.PropertyErrorf("kotlincflags", "Flag `%s` must start with `-`", flag)
1962 } else if strings.HasPrefix(flag, "-Xintellij-plugin-root") {
1963 ctx.PropertyErrorf("kotlincflags",
1964 "Bad flag: `%s`, only use internal compiler for consistency.", flag)
1965 } else if inList(flag, config.KotlincIllegalFlags) {
1966 ctx.PropertyErrorf("kotlincflags", "Flag `%s` already used by build system", flag)
1967 } else if flag == "-include-runtime" {
1968 ctx.PropertyErrorf("kotlincflags", "Bad flag: `%s`, do not include runtime.", flag)
1969 } else {
1970 args := strings.Split(flag, " ")
1971 if args[0] == "-kotlin-home" {
1972 ctx.PropertyErrorf("kotlincflags",
1973 "Bad flag: `%s`, kotlin home already set to default (path to kotlinc in the repo).", flag)
1974 }
1975 }
1976 }
1977}
1978
Colin Cross8eadbf02017-10-24 17:46:00 -07001979func (j *Module) compileJavaHeader(ctx android.ModuleContext, srcFiles, srcJars android.Paths,
Colin Crossf7d84012020-02-21 08:16:41 -08001980 deps deps, flags javaBuilderFlags, jarName string,
1981 extraJars android.Paths) (headerJar, jarjarHeaderJar android.Path) {
Nan Zhanged19fc32017-10-19 13:06:22 -07001982
1983 var jars android.Paths
Colin Cross8eadbf02017-10-24 17:46:00 -07001984 if len(srcFiles) > 0 || len(srcJars) > 0 {
Nan Zhanged19fc32017-10-19 13:06:22 -07001985 // Compile java sources into turbine.jar.
1986 turbineJar := android.PathForModuleOut(ctx, "turbine", jarName)
1987 TransformJavaToHeaderClasses(ctx, turbineJar, srcFiles, srcJars, flags)
1988 if ctx.Failed() {
Colin Crossf7d84012020-02-21 08:16:41 -08001989 return nil, nil
Nan Zhanged19fc32017-10-19 13:06:22 -07001990 }
1991 jars = append(jars, turbineJar)
1992 }
1993
Colin Cross55f63ea2018-08-27 12:37:09 -07001994 jars = append(jars, extraJars...)
1995
Nan Zhanged19fc32017-10-19 13:06:22 -07001996 // Combine any static header libraries into classes-header.jar. If there is only
1997 // one input jar this step will be skipped.
Nan Zhanged19fc32017-10-19 13:06:22 -07001998 jars = append(jars, deps.staticHeaderJars...)
1999
Colin Cross5c6ecc12017-10-23 18:12:27 -07002000 // we cannot skip the combine step for now if there is only one jar
2001 // since we have to strip META-INF/TRANSITIVE dir from turbine.jar
2002 combinedJar := android.PathForModuleOut(ctx, "turbine-combined", jarName)
Colin Cross37f6d792018-07-12 12:28:41 -07002003 TransformJarsToJar(ctx, combinedJar, "for turbine", jars, android.OptionalPath{},
Colin Cross6c6e6cd2019-05-08 14:30:12 -07002004 false, nil, []string{"META-INF/TRANSITIVE"})
Colin Cross5c6ecc12017-10-23 18:12:27 -07002005 headerJar = combinedJar
Colin Crossf7d84012020-02-21 08:16:41 -08002006 jarjarHeaderJar = combinedJar
Nan Zhanged19fc32017-10-19 13:06:22 -07002007
Steven Morelandc4efd9c2019-01-18 11:51:25 -08002008 if j.expandJarjarRules != nil {
Nan Zhanged19fc32017-10-19 13:06:22 -07002009 // Transform classes.jar into classes-jarjar.jar
2010 jarjarFile := android.PathForModuleOut(ctx, "turbine-jarjar", jarName)
Steven Morelandc4efd9c2019-01-18 11:51:25 -08002011 TransformJarJar(ctx, jarjarFile, headerJar, j.expandJarjarRules)
Colin Crossf7d84012020-02-21 08:16:41 -08002012 jarjarHeaderJar = jarjarFile
Nan Zhanged19fc32017-10-19 13:06:22 -07002013 if ctx.Failed() {
Colin Crossf7d84012020-02-21 08:16:41 -08002014 return nil, nil
Nan Zhanged19fc32017-10-19 13:06:22 -07002015 }
2016 }
2017
Colin Crossf7d84012020-02-21 08:16:41 -08002018 return headerJar, jarjarHeaderJar
Nan Zhanged19fc32017-10-19 13:06:22 -07002019}
2020
Colin Crosscb933592017-11-22 13:49:43 -08002021func (j *Module) instrument(ctx android.ModuleContext, flags javaBuilderFlags,
Paul Duffin612e6102021-02-02 13:38:13 +00002022 classesJar android.Path, jarName string) android.OutputPath {
Colin Crosscb933592017-11-22 13:49:43 -08002023
Colin Cross7a3139e2017-12-19 13:57:50 -08002024 specs := j.jacocoModuleToZipCommand(ctx)
Colin Crosscb933592017-11-22 13:49:43 -08002025
Colin Cross84c38822018-01-03 15:59:46 -08002026 jacocoReportClassesFile := android.PathForModuleOut(ctx, "jacoco-report-classes", jarName)
Paul Duffin612e6102021-02-02 13:38:13 +00002027 instrumentedJar := android.PathForModuleOut(ctx, "jacoco", jarName).OutputPath
Colin Crosscb933592017-11-22 13:49:43 -08002028
2029 jacocoInstrumentJar(ctx, instrumentedJar, jacocoReportClassesFile, classesJar, specs)
2030
2031 j.jacocoReportClassesFile = jacocoReportClassesFile
2032
2033 return instrumentedJar
2034}
2035
Nan Zhanged19fc32017-10-19 13:06:22 -07002036func (j *Module) HeaderJars() android.Paths {
albaltai36ff7dc2018-12-25 14:35:23 +08002037 if j.headerJarFile == nil {
2038 return nil
2039 }
Nan Zhanged19fc32017-10-19 13:06:22 -07002040 return android.Paths{j.headerJarFile}
2041}
2042
2043func (j *Module) ImplementationJars() android.Paths {
shinwang9e4c07a2018-12-24 15:41:04 +08002044 if j.implementationJarFile == nil {
2045 return nil
2046 }
Nan Zhanged19fc32017-10-19 13:06:22 -07002047 return android.Paths{j.implementationJarFile}
Colin Cross2fe66872015-03-30 17:20:39 -07002048}
2049
Ulyana Trafimovich5539e7b2020-06-04 14:08:17 +00002050func (j *Module) DexJarBuildPath() android.Path {
Colin Crossf24a22a2019-01-31 14:12:44 -08002051 return j.dexJarFile
2052}
2053
Ulya Trafimovich9f3052c2020-06-09 14:31:19 +01002054func (j *Module) DexJarInstallPath() android.Path {
2055 return j.installFile
2056}
2057
Colin Cross331a1212018-08-15 20:40:52 -07002058func (j *Module) ImplementationAndResourcesJars() android.Paths {
albaltai36ff7dc2018-12-25 14:35:23 +08002059 if j.implementationAndResourcesJar == nil {
2060 return nil
2061 }
Colin Cross331a1212018-08-15 20:40:52 -07002062 return android.Paths{j.implementationAndResourcesJar}
2063}
2064
Colin Cross46c9b8b2017-06-22 16:51:17 -07002065func (j *Module) AidlIncludeDirs() android.Paths {
albaltai36ff7dc2018-12-25 14:35:23 +08002066 // exportAidlIncludeDirs is type android.Paths already
Colin Crossc0b06f12015-04-08 13:03:43 -07002067 return j.exportAidlIncludeDirs
2068}
2069
Ulya Trafimovichb23d28c2020-10-08 12:53:58 +01002070func (j *Module) ClassLoaderContexts() dexpreopt.ClassLoaderContextMap {
2071 return j.classLoaderContexts
Jiyong Park1be96912018-05-28 18:02:19 +09002072}
2073
Colin Cross46c9b8b2017-06-22 16:51:17 -07002074var _ logtagsProducer = (*Module)(nil)
Colin Crossf05fe972015-04-10 17:45:20 -07002075
Colin Cross46c9b8b2017-06-22 16:51:17 -07002076func (j *Module) logtags() android.Paths {
Colin Crossf05fe972015-04-10 17:45:20 -07002077 return j.logtagsSrcs
2078}
2079
Brandon Lee5d45c6f2018-08-15 15:35:38 -07002080// Collect information for opening IDE project files in java/jdeps.go.
2081func (j *Module) IDEInfo(dpInfo *android.IdeInfo) {
2082 dpInfo.Deps = append(dpInfo.Deps, j.CompilerDeps()...)
2083 dpInfo.Srcs = append(dpInfo.Srcs, j.expandIDEInfoCompiledSrcs...)
patricktu18c82ff2019-05-10 15:48:50 +08002084 dpInfo.SrcJars = append(dpInfo.SrcJars, j.compiledSrcJars.Strings()...)
Brandon Lee5d45c6f2018-08-15 15:35:38 -07002085 dpInfo.Aidl_include_dirs = append(dpInfo.Aidl_include_dirs, j.deviceProperties.Aidl.Include_dirs...)
Steven Morelandc4efd9c2019-01-18 11:51:25 -08002086 if j.expandJarjarRules != nil {
2087 dpInfo.Jarjar_rules = append(dpInfo.Jarjar_rules, j.expandJarjarRules.String())
Brandon Lee5d45c6f2018-08-15 15:35:38 -07002088 }
bralee1fbf4402020-05-21 10:11:59 +08002089 dpInfo.Paths = append(dpInfo.Paths, j.modulePaths...)
Brandon Lee5d45c6f2018-08-15 15:35:38 -07002090}
2091
2092func (j *Module) CompilerDeps() []string {
2093 jdeps := []string{}
2094 jdeps = append(jdeps, j.properties.Libs...)
2095 jdeps = append(jdeps, j.properties.Static_libs...)
2096 return jdeps
2097}
2098
Jaewoong Jungc27ab662019-05-30 15:51:14 -07002099func (j *Module) hasCode(ctx android.ModuleContext) bool {
2100 srcFiles := android.PathsForModuleSrcExcludes(ctx, j.properties.Srcs, j.properties.Exclude_srcs)
2101 return len(srcFiles) > 0 || len(ctx.GetDirectDepsWithTag(staticLibTag)) > 0
2102}
2103
Jiyong Park45bf82e2020-12-15 22:29:02 +09002104// Implements android.ApexModule
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09002105func (j *Module) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
Paul Duffin0d3c2e12020-05-17 08:34:50 +01002106 return j.depIsInSameApex(ctx, dep)
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09002107}
2108
Jiyong Park45bf82e2020-12-15 22:29:02 +09002109// Implements android.ApexModule
Dan Albertc8060532020-07-22 22:32:17 -07002110func (j *Module) ShouldSupportSdkVersion(ctx android.BaseModuleContext,
2111 sdkVersion android.ApiLevel) error {
Jooyung Han749dc692020-04-15 11:03:39 +09002112 sdkSpec := j.minSdkVersion()
2113 if !sdkSpec.specified() {
2114 return fmt.Errorf("min_sdk_version is not specified")
2115 }
2116 if sdkSpec.kind == sdkCore {
2117 return nil
2118 }
2119 ver, err := sdkSpec.effectiveVersion(ctx)
2120 if err != nil {
2121 return err
2122 }
Dan Albertc8060532020-07-22 22:32:17 -07002123 if ver.ApiLevel(ctx).GreaterThan(sdkVersion) {
Jooyung Han749dc692020-04-15 11:03:39 +09002124 return fmt.Errorf("newer SDK(%v)", ver)
2125 }
2126 return nil
2127}
2128
Jiyong Park0b238752019-10-29 11:23:10 +09002129func (j *Module) Stem() string {
2130 return proptools.StringDefault(j.deviceProperties.Stem, j.Name())
2131}
2132
Paul Duffin4103e922021-02-01 19:01:34 +00002133// ConfigurationName returns the name of the module as used in build configuration.
2134//
2135// This is usually the same as BaseModuleName() except for the <x>.impl libraries created by
2136// java_sdk_library in which case this is the BaseModuleName() without the ".impl" suffix,
2137// i.e. just <x>.
Paul Duffina2058f82020-06-24 16:22:38 +01002138func (j *Module) ConfigurationName() string {
2139 return proptools.StringDefault(j.deviceProperties.ConfigurationName, j.BaseModuleName())
2140}
2141
Jiyong Park618922e2020-01-08 13:35:43 +09002142func (j *Module) JacocoReportClassesFile() android.Path {
2143 return j.jacocoReportClassesFile
2144}
2145
Martin Stjernholm6d415272020-01-31 17:10:36 +00002146func (j *Module) IsInstallable() bool {
2147 return Bool(j.properties.Installable)
2148}
2149
Colin Cross2fe66872015-03-30 17:20:39 -07002150//
2151// Java libraries (.jar file)
2152//
2153
Colin Crossf506d872017-07-19 15:53:04 -07002154type Library struct {
Colin Cross46c9b8b2017-06-22 16:51:17 -07002155 Module
Colin Crossf0f2e2c2019-10-15 16:36:40 -07002156
2157 InstallMixin func(ctx android.ModuleContext, installPath android.Path) (extraInstallDeps android.Paths)
Colin Cross2fe66872015-03-30 17:20:39 -07002158}
2159
Jiyong Park45bf82e2020-12-15 22:29:02 +09002160var _ android.ApexModule = (*Library)(nil)
2161
Paul Duffine739f1e2020-05-29 11:24:51 +01002162// Provides access to the list of permitted packages from updatable boot jars.
2163type PermittedPackagesForUpdatableBootJars interface {
2164 PermittedPackagesForUpdatableBootJars() []string
2165}
2166
2167var _ PermittedPackagesForUpdatableBootJars = (*Library)(nil)
2168
2169func (j *Library) PermittedPackagesForUpdatableBootJars() []string {
2170 return j.properties.Permitted_packages
2171}
2172
Colin Cross42be7612019-02-21 18:12:14 -08002173func shouldUncompressDex(ctx android.ModuleContext, dexpreopter *dexpreopter) bool {
Ulya Trafimovichf491dde2020-01-24 12:19:45 +00002174 // Store uncompressed (and aligned) any dex files from jars in APEXes.
Colin Cross56a83212020-09-15 18:30:11 -07002175 if apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo); !apexInfo.IsForPlatform() {
Ulya Trafimovichf491dde2020-01-24 12:19:45 +00002176 return true
2177 }
2178
Nicolas Geoffrayfa6e9ec2019-02-12 13:12:16 +00002179 // Store uncompressed (and do not strip) dex files from boot class path jars.
2180 if inList(ctx.ModuleName(), ctx.Config().BootJars()) {
2181 return true
2182 }
2183
2184 // Store uncompressed dex files that are preopted on /system.
Colin Cross42be7612019-02-21 18:12:14 -08002185 if !dexpreopter.dexpreoptDisabled(ctx) && (ctx.Host() || !odexOnSystemOther(ctx, dexpreopter.installPath)) {
Vladimir Markoe8b00d62018-12-21 15:54:16 +00002186 return true
2187 }
Colin Cross083a2aa2019-02-06 16:37:12 -08002188 if ctx.Config().UncompressPrivAppDex() &&
2189 inList(ctx.ModuleName(), ctx.Config().ModulesLoadedByPrivilegedModules()) {
2190 return true
2191 }
2192
Colin Cross2fc72f62018-12-21 12:59:54 -08002193 return false
2194}
2195
Colin Crossf506d872017-07-19 15:53:04 -07002196func (j *Library) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Paul Duffin4103e922021-02-01 19:01:34 +00002197 // Initialize the hiddenapi structure. Pass in the configuration name rather than the module name
2198 // so the hidden api will encode the <x>.impl java_ library created by java_sdk_library just as it
2199 // would the <x> library if <x> was configured as a boot jar.
2200 j.initHiddenAPI(ctx, j.ConfigurationName())
2201
Colin Cross56a83212020-09-15 18:30:11 -07002202 apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo)
2203 if !apexInfo.IsForPlatform() {
2204 j.hideApexVariantFromMake = true
2205 }
2206
Artur Satayev2db1c3f2020-04-08 19:09:30 +01002207 j.checkSdkVersions(ctx)
Jiyong Park0b238752019-10-29 11:23:10 +09002208 j.dexpreopter.installPath = android.PathForModuleInstall(ctx, "framework", j.Stem()+".jar")
Colin Cross43f08db2018-11-12 10:13:39 -08002209 j.dexpreopter.isSDKLibrary = j.deviceProperties.IsSDKLibrary
Liz Kammera7a64f32020-07-09 15:16:41 -07002210 if j.dexProperties.Uncompress_dex == nil {
David Srbeckye033cba2020-05-20 22:20:28 +01002211 // If the value was not force-set by the user, use reasonable default based on the module.
Liz Kammera7a64f32020-07-09 15:16:41 -07002212 j.dexProperties.Uncompress_dex = proptools.BoolPtr(shouldUncompressDex(ctx, &j.dexpreopter))
David Srbeckye033cba2020-05-20 22:20:28 +01002213 }
Liz Kammera7a64f32020-07-09 15:16:41 -07002214 j.dexpreopter.uncompressedDex = *j.dexProperties.Uncompress_dex
Ulya Trafimovichb23d28c2020-10-08 12:53:58 +01002215 j.classLoaderContexts = make(dexpreopt.ClassLoaderContextMap)
Jaewoong Junga24af3b2019-05-13 09:23:20 -07002216 j.compile(ctx, nil)
Colin Crossb7a63242015-04-16 14:09:14 -07002217
bralee1fbf4402020-05-21 10:11:59 +08002218 // Collect the module directory for IDE info in java/jdeps.go.
2219 j.modulePaths = append(j.modulePaths, ctx.ModuleDir())
2220
Colin Cross56a83212020-09-15 18:30:11 -07002221 exclusivelyForApex := !apexInfo.IsForPlatform()
Jiyong Park7f7766d2019-07-25 22:02:35 +09002222 if (Bool(j.properties.Installable) || ctx.Host()) && !exclusivelyForApex {
Colin Crossf0f2e2c2019-10-15 16:36:40 -07002223 var extraInstallDeps android.Paths
2224 if j.InstallMixin != nil {
2225 extraInstallDeps = j.InstallMixin(ctx, j.outputFile)
2226 }
Colin Cross2c429dc2017-08-31 16:45:16 -07002227 j.installFile = ctx.InstallFile(android.PathForModuleInstall(ctx, "framework"),
Jiyong Parka62aa232020-05-28 23:46:55 +09002228 j.Stem()+".jar", j.outputFile, extraInstallDeps...)
Colin Cross2c429dc2017-08-31 16:45:16 -07002229 }
Colin Crossb7a63242015-04-16 14:09:14 -07002230}
2231
Colin Crossf506d872017-07-19 15:53:04 -07002232func (j *Library) DepsMutator(ctx android.BottomUpMutatorContext) {
Colin Cross46c9b8b2017-06-22 16:51:17 -07002233 j.deps(ctx)
2234}
2235
Paul Duffin0e0cf1d2019-11-12 19:39:25 +00002236const (
Paul Duffin1b82e6a2019-12-03 18:06:47 +00002237 aidlIncludeDir = "aidl"
2238 javaDir = "java"
2239 jarFileSuffix = ".jar"
2240 testConfigSuffix = "-AndroidTest.xml"
Paul Duffin0e0cf1d2019-11-12 19:39:25 +00002241)
2242
Paul Duffina0dbf432019-12-05 11:25:53 +00002243// path to the jar file of a java library. Relative to <sdk_root>/<api_dir>
Paul Duffina04c1072020-03-02 10:16:35 +00002244func sdkSnapshotFilePathForJar(osPrefix, name string) string {
2245 return sdkSnapshotFilePathForMember(osPrefix, name, jarFileSuffix)
Paul Duffin1b82e6a2019-12-03 18:06:47 +00002246}
2247
Paul Duffina04c1072020-03-02 10:16:35 +00002248func sdkSnapshotFilePathForMember(osPrefix, name string, suffix string) string {
2249 return filepath.Join(javaDir, osPrefix, name+suffix)
Paul Duffin0e0cf1d2019-11-12 19:39:25 +00002250}
2251
Paul Duffin13879572019-11-28 14:31:38 +00002252type librarySdkMemberType struct {
Paul Duffin255f18e2019-12-13 11:22:16 +00002253 android.SdkMemberTypeBase
Paul Duffinf5c0a9c2020-02-28 14:39:53 +00002254
2255 // Function to retrieve the appropriate output jar (implementation or header) from
2256 // the library.
Paul Duffindb170e42020-12-08 17:48:25 +00002257 jarToExportGetter func(ctx android.SdkMemberContext, j *Library) android.Path
2258
2259 // Function to compute the snapshot relative path to which the named library's
2260 // jar should be copied.
2261 snapshotPathGetter func(osPrefix, name string) string
2262
2263 // True if only the jar should be copied to the snapshot, false if the jar plus any additional
2264 // files like aidl files should also be copied.
2265 onlyCopyJarToSnapshot bool
Paul Duffin13879572019-11-28 14:31:38 +00002266}
2267
Paul Duffindb170e42020-12-08 17:48:25 +00002268const (
2269 onlyCopyJarToSnapshot = true
2270 copyEverythingToSnapshot = false
2271)
2272
Paul Duffin13879572019-11-28 14:31:38 +00002273func (mt *librarySdkMemberType) AddDependencies(mctx android.BottomUpMutatorContext, dependencyTag blueprint.DependencyTag, names []string) {
2274 mctx.AddVariationDependencies(nil, dependencyTag, names...)
2275}
2276
2277func (mt *librarySdkMemberType) IsInstance(module android.Module) bool {
2278 _, ok := module.(*Library)
2279 return ok
2280}
2281
Paul Duffin3a4eb502020-03-19 16:11:18 +00002282func (mt *librarySdkMemberType) AddPrebuiltModule(ctx android.SdkMemberContext, member android.SdkMember) android.BpModule {
2283 return ctx.SnapshotBuilder().AddPrebuiltModule(member, "java_import")
Paul Duffin14eb4672020-03-02 11:33:02 +00002284}
Paul Duffina0dbf432019-12-05 11:25:53 +00002285
Paul Duffin14eb4672020-03-02 11:33:02 +00002286func (mt *librarySdkMemberType) CreateVariantPropertiesStruct() android.SdkMemberProperties {
Paul Duffina551a1c2020-03-17 21:04:24 +00002287 return &librarySdkMemberProperties{}
Paul Duffin14eb4672020-03-02 11:33:02 +00002288}
2289
2290type librarySdkMemberProperties struct {
2291 android.SdkMemberPropertiesBase
2292
Paul Duffin864e1b42020-05-06 10:23:19 +01002293 JarToExport android.Path `android:"arch_variant"`
Paul Duffina551a1c2020-03-17 21:04:24 +00002294 AidlIncludeDirs android.Paths
Paul Duffin14eb4672020-03-02 11:33:02 +00002295}
2296
Paul Duffin3a4eb502020-03-19 16:11:18 +00002297func (p *librarySdkMemberProperties) PopulateFromVariant(ctx android.SdkMemberContext, variant android.Module) {
Paul Duffin13879572019-11-28 14:31:38 +00002298 j := variant.(*Library)
2299
Paul Duffindb170e42020-12-08 17:48:25 +00002300 p.JarToExport = ctx.MemberType().(*librarySdkMemberType).jarToExportGetter(ctx, j)
2301
Paul Duffina551a1c2020-03-17 21:04:24 +00002302 p.AidlIncludeDirs = j.AidlIncludeDirs()
Paul Duffin14eb4672020-03-02 11:33:02 +00002303}
Paul Duffin0e0cf1d2019-11-12 19:39:25 +00002304
Paul Duffin3a4eb502020-03-19 16:11:18 +00002305func (p *librarySdkMemberProperties) AddToPropertySet(ctx android.SdkMemberContext, propertySet android.BpPropertySet) {
Paul Duffina551a1c2020-03-17 21:04:24 +00002306 builder := ctx.SnapshotBuilder()
Paul Duffin3a4eb502020-03-19 16:11:18 +00002307
Paul Duffindb170e42020-12-08 17:48:25 +00002308 memberType := ctx.MemberType().(*librarySdkMemberType)
2309
Paul Duffina551a1c2020-03-17 21:04:24 +00002310 exportedJar := p.JarToExport
2311 if exportedJar != nil {
Paul Duffindb170e42020-12-08 17:48:25 +00002312 // Delegate the creation of the snapshot relative path to the member type.
2313 snapshotRelativeJavaLibPath := memberType.snapshotPathGetter(p.OsPrefix(), ctx.Name())
2314
2315 // Copy the exported jar to the snapshot.
Paul Duffin14eb4672020-03-02 11:33:02 +00002316 builder.CopyToSnapshot(exportedJar, snapshotRelativeJavaLibPath)
2317
Paul Duffina551a1c2020-03-17 21:04:24 +00002318 propertySet.AddProperty("jars", []string{snapshotRelativeJavaLibPath})
2319 }
2320
Paul Duffindb170e42020-12-08 17:48:25 +00002321 // Do not copy anything else to the snapshot.
2322 if memberType.onlyCopyJarToSnapshot {
2323 return
2324 }
2325
Paul Duffina551a1c2020-03-17 21:04:24 +00002326 aidlIncludeDirs := p.AidlIncludeDirs
2327 if len(aidlIncludeDirs) != 0 {
2328 sdkModuleContext := ctx.SdkModuleContext()
2329 for _, dir := range aidlIncludeDirs {
Paul Duffin14eb4672020-03-02 11:33:02 +00002330 // TODO(jiyong): copy parcelable declarations only
2331 aidlFiles, _ := sdkModuleContext.GlobWithDeps(dir.String()+"/**/*.aidl", nil)
2332 for _, file := range aidlFiles {
2333 builder.CopyToSnapshot(android.PathForSource(sdkModuleContext, file), filepath.Join(aidlIncludeDir, file))
2334 }
Paul Duffin0e0cf1d2019-11-12 19:39:25 +00002335 }
Paul Duffin0e0cf1d2019-11-12 19:39:25 +00002336
Paul Duffina551a1c2020-03-17 21:04:24 +00002337 // TODO(b/151933053) - add aidl include dirs property
Paul Duffin14eb4672020-03-02 11:33:02 +00002338 }
Paul Duffin0e0cf1d2019-11-12 19:39:25 +00002339}
2340
Paul Duffinf5c0a9c2020-02-28 14:39:53 +00002341var javaHeaderLibsSdkMemberType android.SdkMemberType = &librarySdkMemberType{
2342 android.SdkMemberTypeBase{
2343 PropertyName: "java_header_libs",
2344 SupportsSdk: true,
Paul Duffin7b81f5e2020-01-13 21:03:22 +00002345 },
Paul Duffindb170e42020-12-08 17:48:25 +00002346 func(_ android.SdkMemberContext, j *Library) android.Path {
Paul Duffina0dbf432019-12-05 11:25:53 +00002347 headerJars := j.HeaderJars()
2348 if len(headerJars) != 1 {
2349 panic(fmt.Errorf("there must be only one header jar from %q", j.Name()))
2350 }
2351
2352 return headerJars[0]
Paul Duffinf5c0a9c2020-02-28 14:39:53 +00002353 },
Paul Duffindb170e42020-12-08 17:48:25 +00002354 sdkSnapshotFilePathForJar,
2355 copyEverythingToSnapshot,
Paul Duffina0dbf432019-12-05 11:25:53 +00002356}
2357
Colin Cross1b16b0e2019-02-12 14:41:32 -08002358// java_library builds and links sources into a `.jar` file for the device, and possibly for the host as well.
2359//
2360// By default, a java_library has a single variant that produces a `.jar` file containing `.class` files that were
2361// compiled against the device bootclasspath. This jar is not suitable for installing on a device, but can be used
2362// as a `static_libs` dependency of another module.
2363//
2364// Specifying `installable: true` will product a `.jar` file containing `classes.dex` files, suitable for installing on
2365// a device.
2366//
2367// Specifying `host_supported: true` will produce two variants, one compiled against the device bootclasspath and one
2368// compiled against the host bootclasspath.
Colin Cross9ae1b922018-06-26 17:59:05 -07002369func LibraryFactory() android.Module {
2370 module := &Library{}
Colin Cross2fe66872015-03-30 17:20:39 -07002371
Colin Crossce6734e2020-06-15 16:09:53 -07002372 module.addHostAndDeviceProperties()
Colin Cross2fe66872015-03-30 17:20:39 -07002373
Paul Duffin859fe962020-05-15 10:20:31 +01002374 module.initModuleAndImport(&module.ModuleBase)
2375
Jiyong Park7f7766d2019-07-25 22:02:35 +09002376 android.InitApexModule(module)
Jiyong Parkd1063c12019-07-17 20:08:41 +09002377 android.InitSdkAwareModule(module)
Jooyung Han18020ea2019-11-13 10:50:48 +09002378 InitJavaModule(module, android.HostAndDeviceSupported)
Colin Cross9ae1b922018-06-26 17:59:05 -07002379 return module
Colin Cross2fe66872015-03-30 17:20:39 -07002380}
2381
Colin Cross1b16b0e2019-02-12 14:41:32 -08002382// java_library_static is an obsolete alias for java_library.
2383func LibraryStaticFactory() android.Module {
2384 return LibraryFactory()
2385}
2386
2387// java_library_host builds and links sources into a `.jar` file for the host.
2388//
2389// A java_library_host has a single variant that produces a `.jar` file containing `.class` files that were
2390// compiled against the host bootclasspath.
Colin Crossf506d872017-07-19 15:53:04 -07002391func LibraryHostFactory() android.Module {
2392 module := &Library{}
Colin Cross2fe66872015-03-30 17:20:39 -07002393
Colin Crossce6734e2020-06-15 16:09:53 -07002394 module.addHostProperties()
Colin Cross36242852017-06-23 15:06:31 -07002395
Colin Cross9ae1b922018-06-26 17:59:05 -07002396 module.Module.properties.Installable = proptools.BoolPtr(true)
2397
Jiyong Park7f7766d2019-07-25 22:02:35 +09002398 android.InitApexModule(module)
Jooyung Han18020ea2019-11-13 10:50:48 +09002399 InitJavaModule(module, android.HostSupported)
Colin Cross36242852017-06-23 15:06:31 -07002400 return module
Colin Cross2fe66872015-03-30 17:20:39 -07002401}
2402
2403//
Colin Crossb628ea52018-08-14 16:42:33 -07002404// Java Tests
Colin Cross05638fc2018-04-09 18:40:24 -07002405//
2406
Dan Shi95d19422020-08-15 12:24:26 -07002407// Test option struct.
2408type TestOptions struct {
2409 // a list of extra test configuration files that should be installed with the module.
2410 Extra_test_configs []string `android:"path,arch_variant"`
Dan Shid79572f2020-11-13 14:33:46 -08002411
2412 // If the test is a hostside(no device required) unittest that shall be run during presubmit check.
2413 Unit_test *bool
Dan Shi95d19422020-08-15 12:24:26 -07002414}
2415
Colin Cross05638fc2018-04-09 18:40:24 -07002416type testProperties struct {
Colin Cross05638fc2018-04-09 18:40:24 -07002417 // list of compatibility suites (for example "cts", "vts") that the module should be
2418 // installed into.
2419 Test_suites []string `android:"arch_variant"`
Julien Despreze146e392018-08-02 15:00:46 -07002420
2421 // the name of the test configuration (for example "AndroidTest.xml") that should be
2422 // installed with the module.
Colin Cross27b922f2019-03-04 22:35:41 -08002423 Test_config *string `android:"path,arch_variant"`
Colin Crossd96ca352018-08-10 16:06:24 -07002424
Jack He33338892018-09-19 02:21:28 -07002425 // the name of the test configuration template (for example "AndroidTestTemplate.xml") that
2426 // should be installed with the module.
Colin Cross27b922f2019-03-04 22:35:41 -08002427 Test_config_template *string `android:"path,arch_variant"`
Jack He33338892018-09-19 02:21:28 -07002428
Colin Crossd96ca352018-08-10 16:06:24 -07002429 // list of files or filegroup modules that provide data that should be installed alongside
2430 // the test
Jiyong Park2b0e4902021-02-16 06:52:39 +09002431 Data []string `android:"path"`
Dan Shi6ffaaa82019-09-26 11:41:36 -07002432
2433 // Flag to indicate whether or not to create test config automatically. If AndroidTest.xml
2434 // doesn't exist next to the Android.bp, this attribute doesn't need to be set to true
2435 // explicitly.
2436 Auto_gen_config *bool
easoncylee5bcff5d2020-04-30 14:57:06 +08002437
2438 // Add parameterized mainline modules to auto generated test config. The options will be
2439 // handled by TradeFed to do downloading and installing the specified modules on the device.
2440 Test_mainline_modules []string
Dan Shi95d19422020-08-15 12:24:26 -07002441
2442 // Test options.
2443 Test_options TestOptions
Colin Cross05638fc2018-04-09 18:40:24 -07002444}
2445
Liz Kammerdd849a82020-06-12 16:38:45 -07002446type hostTestProperties struct {
2447 // list of native binary modules that should be installed alongside the test
2448 Data_native_bins []string `android:"arch_variant"`
2449}
2450
Paul Duffin42df1442019-03-20 12:45:53 +00002451type testHelperLibraryProperties struct {
2452 // list of compatibility suites (for example "cts", "vts") that the module should be
2453 // installed into.
2454 Test_suites []string `android:"arch_variant"`
2455}
2456
Paul Duffin1b82e6a2019-12-03 18:06:47 +00002457type prebuiltTestProperties struct {
2458 // list of compatibility suites (for example "cts", "vts") that the module should be
2459 // installed into.
2460 Test_suites []string `android:"arch_variant"`
2461
2462 // the name of the test configuration (for example "AndroidTest.xml") that should be
2463 // installed with the module.
2464 Test_config *string `android:"path,arch_variant"`
2465}
2466
Colin Cross05638fc2018-04-09 18:40:24 -07002467type Test struct {
2468 Library
2469
2470 testProperties testProperties
Colin Cross303e21f2018-08-07 16:49:25 -07002471
Dan Shi95d19422020-08-15 12:24:26 -07002472 testConfig android.Path
2473 extraTestConfigs android.Paths
2474 data android.Paths
Colin Cross303e21f2018-08-07 16:49:25 -07002475}
2476
Liz Kammerdd849a82020-06-12 16:38:45 -07002477type TestHost struct {
2478 Test
2479
2480 testHostProperties hostTestProperties
2481}
2482
Paul Duffin42df1442019-03-20 12:45:53 +00002483type TestHelperLibrary struct {
2484 Library
2485
2486 testHelperLibraryProperties testHelperLibraryProperties
2487}
2488
Paul Duffin1b82e6a2019-12-03 18:06:47 +00002489type JavaTestImport struct {
2490 Import
2491
2492 prebuiltTestProperties prebuiltTestProperties
2493
2494 testConfig android.Path
Liz Kammerd6c31d22020-08-05 15:40:41 -07002495 dexJarFile android.Path
Paul Duffin1b82e6a2019-12-03 18:06:47 +00002496}
2497
Liz Kammerdd849a82020-06-12 16:38:45 -07002498func (j *TestHost) DepsMutator(ctx android.BottomUpMutatorContext) {
2499 if len(j.testHostProperties.Data_native_bins) > 0 {
2500 for _, target := range ctx.MultiTargets() {
2501 ctx.AddVariationDependencies(target.Variations(), dataNativeBinsTag, j.testHostProperties.Data_native_bins...)
2502 }
2503 }
2504
2505 j.deps(ctx)
2506}
2507
Colin Cross303e21f2018-08-07 16:49:25 -07002508func (j *Test) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Julien Desprezb2166612021-03-05 18:08:36 +00002509 if j.testProperties.Test_options.Unit_test == nil && ctx.Host() {
2510 // TODO(b/): Clean temporary heuristic to avoid unexpected onboarding.
Julien Desprez3f4e7a12021-03-09 13:02:29 -08002511 defaultUnitTest := !inList("tradefed", j.properties.Static_libs) && !inList("tradefed", j.properties.Libs) && !inList("cts", j.testProperties.Test_suites)
Julien Desprezb2166612021-03-05 18:08:36 +00002512 j.testProperties.Test_options.Unit_test = proptools.BoolPtr(defaultUnitTest)
2513 }
Dan Shi6ffaaa82019-09-26 11:41:36 -07002514 j.testConfig = tradefed.AutoGenJavaTestConfig(ctx, j.testProperties.Test_config, j.testProperties.Test_config_template,
Julien Desprez70898c42020-11-19 09:43:45 -08002515 j.testProperties.Test_suites, j.testProperties.Auto_gen_config, j.testProperties.Test_options.Unit_test)
Liz Kammerdd849a82020-06-12 16:38:45 -07002516
Colin Cross8a497952019-03-05 22:25:09 -08002517 j.data = android.PathsForModuleSrc(ctx, j.testProperties.Data)
Colin Cross303e21f2018-08-07 16:49:25 -07002518
Dan Shi95d19422020-08-15 12:24:26 -07002519 j.extraTestConfigs = android.PathsForModuleSrc(ctx, j.testProperties.Test_options.Extra_test_configs)
2520
Liz Kammerdd849a82020-06-12 16:38:45 -07002521 ctx.VisitDirectDepsWithTag(dataNativeBinsTag, func(dep android.Module) {
2522 j.data = append(j.data, android.OutputFileForModule(ctx, dep, ""))
2523 })
2524
Colin Cross303e21f2018-08-07 16:49:25 -07002525 j.Library.GenerateAndroidBuildActions(ctx)
Colin Cross05638fc2018-04-09 18:40:24 -07002526}
2527
Paul Duffin42df1442019-03-20 12:45:53 +00002528func (j *TestHelperLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
2529 j.Library.GenerateAndroidBuildActions(ctx)
2530}
2531
Paul Duffin1b82e6a2019-12-03 18:06:47 +00002532func (j *JavaTestImport) GenerateAndroidBuildActions(ctx android.ModuleContext) {
2533 j.testConfig = tradefed.AutoGenJavaTestConfig(ctx, j.prebuiltTestProperties.Test_config, nil,
Julien Desprez70898c42020-11-19 09:43:45 -08002534 j.prebuiltTestProperties.Test_suites, nil, nil)
Paul Duffin1b82e6a2019-12-03 18:06:47 +00002535
2536 j.Import.GenerateAndroidBuildActions(ctx)
2537}
2538
2539type testSdkMemberType struct {
2540 android.SdkMemberTypeBase
2541}
2542
2543func (mt *testSdkMemberType) AddDependencies(mctx android.BottomUpMutatorContext, dependencyTag blueprint.DependencyTag, names []string) {
2544 mctx.AddVariationDependencies(nil, dependencyTag, names...)
2545}
2546
2547func (mt *testSdkMemberType) IsInstance(module android.Module) bool {
2548 _, ok := module.(*Test)
2549 return ok
2550}
2551
Paul Duffin3a4eb502020-03-19 16:11:18 +00002552func (mt *testSdkMemberType) AddPrebuiltModule(ctx android.SdkMemberContext, member android.SdkMember) android.BpModule {
2553 return ctx.SnapshotBuilder().AddPrebuiltModule(member, "java_test_import")
Paul Duffin14eb4672020-03-02 11:33:02 +00002554}
Paul Duffin1b82e6a2019-12-03 18:06:47 +00002555
Paul Duffin14eb4672020-03-02 11:33:02 +00002556func (mt *testSdkMemberType) CreateVariantPropertiesStruct() android.SdkMemberProperties {
2557 return &testSdkMemberProperties{}
2558}
2559
2560type testSdkMemberProperties struct {
2561 android.SdkMemberPropertiesBase
2562
Paul Duffina551a1c2020-03-17 21:04:24 +00002563 JarToExport android.Path
2564 TestConfig android.Path
Paul Duffin14eb4672020-03-02 11:33:02 +00002565}
2566
Paul Duffin3a4eb502020-03-19 16:11:18 +00002567func (p *testSdkMemberProperties) PopulateFromVariant(ctx android.SdkMemberContext, variant android.Module) {
Paul Duffin14eb4672020-03-02 11:33:02 +00002568 test := variant.(*Test)
2569
2570 implementationJars := test.ImplementationJars()
Paul Duffin1b82e6a2019-12-03 18:06:47 +00002571 if len(implementationJars) != 1 {
Paul Duffin14eb4672020-03-02 11:33:02 +00002572 panic(fmt.Errorf("there must be only one implementation jar from %q", test.Name()))
Paul Duffin1b82e6a2019-12-03 18:06:47 +00002573 }
2574
Paul Duffina551a1c2020-03-17 21:04:24 +00002575 p.JarToExport = implementationJars[0]
2576 p.TestConfig = test.testConfig
Paul Duffin14eb4672020-03-02 11:33:02 +00002577}
Paul Duffin1b82e6a2019-12-03 18:06:47 +00002578
Paul Duffin3a4eb502020-03-19 16:11:18 +00002579func (p *testSdkMemberProperties) AddToPropertySet(ctx android.SdkMemberContext, propertySet android.BpPropertySet) {
Paul Duffina551a1c2020-03-17 21:04:24 +00002580 builder := ctx.SnapshotBuilder()
Paul Duffin3a4eb502020-03-19 16:11:18 +00002581
Paul Duffina551a1c2020-03-17 21:04:24 +00002582 exportedJar := p.JarToExport
2583 if exportedJar != nil {
2584 snapshotRelativeJavaLibPath := sdkSnapshotFilePathForJar(p.OsPrefix(), ctx.Name())
2585 builder.CopyToSnapshot(exportedJar, snapshotRelativeJavaLibPath)
Paul Duffin14eb4672020-03-02 11:33:02 +00002586
2587 propertySet.AddProperty("jars", []string{snapshotRelativeJavaLibPath})
Paul Duffina551a1c2020-03-17 21:04:24 +00002588 }
2589
2590 testConfig := p.TestConfig
2591 if testConfig != nil {
2592 snapshotRelativeTestConfigPath := sdkSnapshotFilePathForMember(p.OsPrefix(), ctx.Name(), testConfigSuffix)
2593 builder.CopyToSnapshot(testConfig, snapshotRelativeTestConfigPath)
Paul Duffin14eb4672020-03-02 11:33:02 +00002594 propertySet.AddProperty("test_config", snapshotRelativeTestConfigPath)
2595 }
Paul Duffin1b82e6a2019-12-03 18:06:47 +00002596}
2597
Colin Cross1b16b0e2019-02-12 14:41:32 -08002598// java_test builds a and links sources into a `.jar` file for the device, and possibly for the host as well, and
2599// creates an `AndroidTest.xml` file to allow running the test with `atest` or a `TEST_MAPPING` file.
2600//
2601// By default, a java_test has a single variant that produces a `.jar` file containing `classes.dex` files that were
2602// compiled against the device bootclasspath.
2603//
2604// Specifying `host_supported: true` will produce two variants, one compiled against the device bootclasspath and one
2605// compiled against the host bootclasspath.
Colin Cross05638fc2018-04-09 18:40:24 -07002606func TestFactory() android.Module {
2607 module := &Test{}
2608
Colin Crossce6734e2020-06-15 16:09:53 -07002609 module.addHostAndDeviceProperties()
2610 module.AddProperties(&module.testProperties)
Colin Cross05638fc2018-04-09 18:40:24 -07002611
Colin Cross9ae1b922018-06-26 17:59:05 -07002612 module.Module.properties.Installable = proptools.BoolPtr(true)
Colin Crosse3026872019-01-05 22:30:13 -08002613 module.Module.dexpreopter.isTest = true
Colin Cross014489c2020-06-02 20:09:13 -07002614 module.Module.linter.test = true
Colin Cross9ae1b922018-06-26 17:59:05 -07002615
Colin Cross05638fc2018-04-09 18:40:24 -07002616 InitJavaModule(module, android.HostAndDeviceSupported)
Colin Cross05638fc2018-04-09 18:40:24 -07002617 return module
2618}
2619
Paul Duffin42df1442019-03-20 12:45:53 +00002620// java_test_helper_library creates a java library and makes sure that it is added to the appropriate test suite.
2621func TestHelperLibraryFactory() android.Module {
2622 module := &TestHelperLibrary{}
2623
Colin Crossce6734e2020-06-15 16:09:53 -07002624 module.addHostAndDeviceProperties()
2625 module.AddProperties(&module.testHelperLibraryProperties)
Paul Duffin42df1442019-03-20 12:45:53 +00002626
Colin Cross9a4abed2019-04-24 13:19:28 -07002627 module.Module.properties.Installable = proptools.BoolPtr(true)
2628 module.Module.dexpreopter.isTest = true
Colin Cross014489c2020-06-02 20:09:13 -07002629 module.Module.linter.test = true
Colin Cross9a4abed2019-04-24 13:19:28 -07002630
Paul Duffin42df1442019-03-20 12:45:53 +00002631 InitJavaModule(module, android.HostAndDeviceSupported)
2632 return module
2633}
2634
Paul Duffin1b82e6a2019-12-03 18:06:47 +00002635// java_test_import imports one or more `.jar` files into the build graph as if they were built by a java_test module
2636// and makes sure that it is added to the appropriate test suite.
2637//
2638// By default, a java_test_import has a single variant that expects a `.jar` file containing `.class` files that were
2639// compiled against an Android classpath.
2640//
2641// Specifying `host_supported: true` will produce two variants, one for use as a dependency of device modules and one
2642// for host modules.
2643func JavaTestImportFactory() android.Module {
2644 module := &JavaTestImport{}
2645
2646 module.AddProperties(
2647 &module.Import.properties,
2648 &module.prebuiltTestProperties)
2649
2650 module.Import.properties.Installable = proptools.BoolPtr(true)
2651
2652 android.InitPrebuiltModule(module, &module.properties.Jars)
2653 android.InitApexModule(module)
2654 android.InitSdkAwareModule(module)
2655 InitJavaModule(module, android.HostAndDeviceSupported)
2656 return module
2657}
2658
Colin Cross1b16b0e2019-02-12 14:41:32 -08002659// java_test_host builds a and links sources into a `.jar` file for the host, and creates an `AndroidTest.xml` file to
2660// allow running the test with `atest` or a `TEST_MAPPING` file.
2661//
2662// A java_test_host has a single variant that produces a `.jar` file containing `.class` files that were
2663// compiled against the host bootclasspath.
Colin Cross05638fc2018-04-09 18:40:24 -07002664func TestHostFactory() android.Module {
Liz Kammerdd849a82020-06-12 16:38:45 -07002665 module := &TestHost{}
Colin Cross05638fc2018-04-09 18:40:24 -07002666
Colin Crossce6734e2020-06-15 16:09:53 -07002667 module.addHostProperties()
2668 module.AddProperties(&module.testProperties)
Liz Kammerdd849a82020-06-12 16:38:45 -07002669 module.AddProperties(&module.testHostProperties)
Colin Cross05638fc2018-04-09 18:40:24 -07002670
Colin Cross9ae1b922018-06-26 17:59:05 -07002671 module.Module.properties.Installable = proptools.BoolPtr(true)
2672
Liz Kammerdd849a82020-06-12 16:38:45 -07002673 InitJavaModuleMultiTargets(module, android.HostSupported)
Julien Desprezb2166612021-03-05 18:08:36 +00002674
Colin Cross05638fc2018-04-09 18:40:24 -07002675 return module
2676}
2677
2678//
Colin Cross2fe66872015-03-30 17:20:39 -07002679// Java Binaries (.jar file plus wrapper script)
2680//
2681
Colin Crossf506d872017-07-19 15:53:04 -07002682type binaryProperties struct {
Colin Cross7d5136f2015-05-11 13:39:40 -07002683 // installable script to execute the resulting jar
Colin Cross27b922f2019-03-04 22:35:41 -08002684 Wrapper *string `android:"path"`
Colin Cross094054a2018-10-17 15:10:48 -07002685
2686 // Name of the class containing main to be inserted into the manifest as Main-Class.
2687 Main_class *string
Colin Cross89226d92020-10-09 19:00:54 -07002688
2689 // Names of modules containing JNI libraries that should be installed alongside the host
2690 // variant of the binary.
2691 Jni_libs []string
Colin Cross7d5136f2015-05-11 13:39:40 -07002692}
2693
Colin Crossf506d872017-07-19 15:53:04 -07002694type Binary struct {
2695 Library
Colin Cross2fe66872015-03-30 17:20:39 -07002696
Colin Crossf506d872017-07-19 15:53:04 -07002697 binaryProperties binaryProperties
Colin Cross10a03492017-08-10 17:09:43 -07002698
Colin Cross6b4a32d2017-12-05 13:42:45 -08002699 isWrapperVariant bool
2700
Colin Crossc3315992017-12-08 19:12:36 -08002701 wrapperFile android.Path
Colin Cross70dda7e2019-10-01 22:05:35 -07002702 binaryFile android.InstallPath
Colin Cross2fe66872015-03-30 17:20:39 -07002703}
2704
Alex Light24237172017-10-26 09:46:21 -07002705func (j *Binary) HostToolPath() android.OptionalPath {
2706 return android.OptionalPathForPath(j.binaryFile)
2707}
2708
Colin Crossf506d872017-07-19 15:53:04 -07002709func (j *Binary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross6b4a32d2017-12-05 13:42:45 -08002710 if ctx.Arch().ArchType == android.Common {
2711 // Compile the jar
Colin Cross094054a2018-10-17 15:10:48 -07002712 if j.binaryProperties.Main_class != nil {
2713 if j.properties.Manifest != nil {
2714 ctx.PropertyErrorf("main_class", "main_class cannot be used when manifest is set")
2715 }
2716 manifestFile := android.PathForModuleOut(ctx, "manifest.txt")
2717 GenerateMainClassManifest(ctx, manifestFile, String(j.binaryProperties.Main_class))
2718 j.overrideManifest = android.OptionalPathForPath(manifestFile)
2719 }
2720
Colin Cross6b4a32d2017-12-05 13:42:45 -08002721 j.Library.GenerateAndroidBuildActions(ctx)
Nan Zhang3c807db2017-11-03 14:53:31 -07002722 } else {
Colin Cross6b4a32d2017-12-05 13:42:45 -08002723 // Handle the binary wrapper
2724 j.isWrapperVariant = true
2725
Colin Cross366938f2017-12-11 16:29:02 -08002726 if j.binaryProperties.Wrapper != nil {
Colin Cross8a497952019-03-05 22:25:09 -08002727 j.wrapperFile = android.PathForModuleSrc(ctx, *j.binaryProperties.Wrapper)
Colin Cross6b4a32d2017-12-05 13:42:45 -08002728 } else {
2729 j.wrapperFile = android.PathForSource(ctx, "build/soong/scripts/jar-wrapper.sh")
2730 }
2731
Colin Crossc179ea62020-10-09 10:54:15 -07002732 // The host installation rules make the installed wrapper depend on all the dependencies
Colin Cross89226d92020-10-09 19:00:54 -07002733 // of the wrapper variant, which will include the common variant's jar file and any JNI
2734 // libraries. This is verified by TestBinary.
Colin Cross6b4a32d2017-12-05 13:42:45 -08002735 j.binaryFile = ctx.InstallExecutable(android.PathForModuleInstall(ctx, "bin"),
Colin Crossc179ea62020-10-09 10:54:15 -07002736 ctx.ModuleName(), j.wrapperFile)
Nan Zhang3c807db2017-11-03 14:53:31 -07002737 }
Colin Cross2fe66872015-03-30 17:20:39 -07002738}
2739
Colin Crossf506d872017-07-19 15:53:04 -07002740func (j *Binary) DepsMutator(ctx android.BottomUpMutatorContext) {
Liz Kammer356f7d42021-01-26 09:18:53 -05002741 if ctx.Arch().ArchType == android.Common || ctx.BazelConversionMode() {
Colin Cross6b4a32d2017-12-05 13:42:45 -08002742 j.deps(ctx)
Liz Kammer356f7d42021-01-26 09:18:53 -05002743 }
2744 if ctx.Arch().ArchType != android.Common || ctx.BazelConversionMode() {
Colin Crosse9fe2942020-11-10 18:12:15 -08002745 // These dependencies ensure the host installation rules will install the jar file and
2746 // the jni libraries when the wrapper is installed.
2747 ctx.AddVariationDependencies(nil, jniInstallTag, j.binaryProperties.Jni_libs...)
2748 ctx.AddVariationDependencies(
2749 []blueprint.Variation{{Mutator: "arch", Variation: android.CommonArch.String()}},
2750 binaryInstallTag, ctx.ModuleName())
Colin Cross6b4a32d2017-12-05 13:42:45 -08002751 }
Colin Cross46c9b8b2017-06-22 16:51:17 -07002752}
2753
Colin Cross1b16b0e2019-02-12 14:41:32 -08002754// java_binary builds a `.jar` file and a shell script that executes it for the device, and possibly for the host
2755// as well.
2756//
2757// By default, a java_binary has a single variant that produces a `.jar` file containing `classes.dex` files that were
2758// compiled against the device bootclasspath.
2759//
2760// Specifying `host_supported: true` will produce two variants, one compiled against the device bootclasspath and one
2761// compiled against the host bootclasspath.
Colin Crossf506d872017-07-19 15:53:04 -07002762func BinaryFactory() android.Module {
2763 module := &Binary{}
Colin Cross2fe66872015-03-30 17:20:39 -07002764
Colin Crossce6734e2020-06-15 16:09:53 -07002765 module.addHostAndDeviceProperties()
2766 module.AddProperties(&module.binaryProperties)
Colin Cross36242852017-06-23 15:06:31 -07002767
Colin Cross9ae1b922018-06-26 17:59:05 -07002768 module.Module.properties.Installable = proptools.BoolPtr(true)
2769
Colin Cross6b4a32d2017-12-05 13:42:45 -08002770 android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibCommonFirst)
2771 android.InitDefaultableModule(module)
Colin Cross36242852017-06-23 15:06:31 -07002772 return module
Colin Cross2fe66872015-03-30 17:20:39 -07002773}
2774
Colin Cross1b16b0e2019-02-12 14:41:32 -08002775// java_binary_host builds a `.jar` file and a shell script that executes it for the host.
2776//
2777// A java_binary_host has a single variant that produces a `.jar` file containing `.class` files that were
2778// compiled against the host bootclasspath.
Colin Crossf506d872017-07-19 15:53:04 -07002779func BinaryHostFactory() android.Module {
2780 module := &Binary{}
Colin Cross2fe66872015-03-30 17:20:39 -07002781
Colin Crossce6734e2020-06-15 16:09:53 -07002782 module.addHostProperties()
2783 module.AddProperties(&module.binaryProperties)
Colin Cross36242852017-06-23 15:06:31 -07002784
Colin Cross9ae1b922018-06-26 17:59:05 -07002785 module.Module.properties.Installable = proptools.BoolPtr(true)
2786
Colin Cross6b4a32d2017-12-05 13:42:45 -08002787 android.InitAndroidArchModule(module, android.HostSupported, android.MultilibCommonFirst)
2788 android.InitDefaultableModule(module)
Colin Cross36242852017-06-23 15:06:31 -07002789 return module
Colin Cross2fe66872015-03-30 17:20:39 -07002790}
2791
2792//
2793// Java prebuilts
2794//
2795
Colin Cross74d73e22017-08-02 11:05:49 -07002796type ImportProperties struct {
Paul Duffina04c1072020-03-02 10:16:35 +00002797 Jars []string `android:"path,arch_variant"`
Colin Cross461bd1a2017-10-20 13:59:18 -07002798
Nan Zhangea568a42017-11-08 21:20:04 -08002799 Sdk_version *string
Colin Cross535e2cf2017-10-20 17:57:49 -07002800
2801 Installable *bool
Jiyong Park1be96912018-05-28 18:02:19 +09002802
2803 // List of shared java libs that this module has dependencies to
2804 Libs []string
Colin Cross37f6d792018-07-12 12:28:41 -07002805
2806 // List of files to remove from the jar file(s)
2807 Exclude_files []string
2808
2809 // List of directories to remove from the jar file(s)
2810 Exclude_dirs []string
Nan Zhang4c819fb2018-08-27 18:31:46 -07002811
2812 // if set to true, run Jetifier against .jar file. Defaults to false.
Colin Cross1001a792019-03-21 22:21:39 -07002813 Jetifier *bool
Jiyong Park4c4c0242019-10-21 14:53:15 +09002814
2815 // set the name of the output
2816 Stem *string
Jiyong Park19604de2020-03-24 16:44:11 +09002817
2818 Aidl struct {
2819 // directories that should be added as include directories for any aidl sources of modules
2820 // that depend on this module, as well as to aidl for this module.
2821 Export_include_dirs []string
2822 }
Colin Cross74d73e22017-08-02 11:05:49 -07002823}
2824
2825type Import struct {
Colin Cross635c3b02016-05-18 15:37:25 -07002826 android.ModuleBase
Colin Cross48de9a42018-10-02 13:53:33 -07002827 android.DefaultableModuleBase
Jiyong Park7f7766d2019-07-25 22:02:35 +09002828 android.ApexModuleBase
Colin Crossec7a0422017-07-07 14:47:12 -07002829 prebuilt android.Prebuilt
Jiyong Parkd1063c12019-07-17 20:08:41 +09002830 android.SdkBase
Colin Cross2fe66872015-03-30 17:20:39 -07002831
Paul Duffin0d3c2e12020-05-17 08:34:50 +01002832 // Functionality common to Module and Import.
2833 embeddableInModuleAndImport
2834
Liz Kammerd6c31d22020-08-05 15:40:41 -07002835 hiddenAPI
2836 dexer
Bill Peckhamff89ffa2020-12-23 16:13:04 -08002837 dexpreopter
Liz Kammerd6c31d22020-08-05 15:40:41 -07002838
Colin Cross74d73e22017-08-02 11:05:49 -07002839 properties ImportProperties
2840
Liz Kammerd6c31d22020-08-05 15:40:41 -07002841 // output file containing classes.dex and resources
2842 dexJarFile android.Path
2843
Colin Cross0a6e0072017-08-30 14:24:55 -07002844 combinedClasspathFile android.Path
Ulya Trafimovichb23d28c2020-10-08 12:53:58 +01002845 classLoaderContexts dexpreopt.ClassLoaderContextMap
Jiyong Park19604de2020-03-24 16:44:11 +09002846 exportAidlIncludeDirs android.Paths
Colin Cross56a83212020-09-15 18:30:11 -07002847
2848 hideApexVariantFromMake bool
Colin Cross2fe66872015-03-30 17:20:39 -07002849}
2850
Jiyong Park6a927c42020-01-21 02:03:43 +09002851func (j *Import) sdkVersion() sdkSpec {
2852 return sdkSpecFrom(String(j.properties.Sdk_version))
Colin Cross83bb3162018-06-25 15:48:06 -07002853}
2854
Liz Kammer2d2fd852020-08-12 14:42:30 -07002855func (j *Import) makeSdkVersion() string {
2856 return j.sdkVersion().raw
2857}
2858
Liz Kammerd6c31d22020-08-05 15:40:41 -07002859func (j *Import) systemModules() string {
2860 return "none"
2861}
2862
Jiyong Park6a927c42020-01-21 02:03:43 +09002863func (j *Import) minSdkVersion() sdkSpec {
Colin Cross83bb3162018-06-25 15:48:06 -07002864 return j.sdkVersion()
2865}
2866
Liz Kammerd6c31d22020-08-05 15:40:41 -07002867func (j *Import) targetSdkVersion() sdkSpec {
2868 return j.sdkVersion()
2869}
2870
Artur Satayev480e25b2020-04-27 18:53:18 +01002871func (j *Import) MinSdkVersion() string {
2872 return j.minSdkVersion().version.String()
2873}
2874
Colin Cross74d73e22017-08-02 11:05:49 -07002875func (j *Import) Prebuilt() *android.Prebuilt {
Colin Crossec7a0422017-07-07 14:47:12 -07002876 return &j.prebuilt
2877}
2878
Colin Cross74d73e22017-08-02 11:05:49 -07002879func (j *Import) PrebuiltSrcs() []string {
2880 return j.properties.Jars
2881}
2882
2883func (j *Import) Name() string {
Colin Cross5ea9bcc2017-07-27 15:41:32 -07002884 return j.prebuilt.Name(j.ModuleBase.Name())
2885}
2886
Jiyong Park0b238752019-10-29 11:23:10 +09002887func (j *Import) Stem() string {
2888 return proptools.StringDefault(j.properties.Stem, j.ModuleBase.Name())
2889}
2890
Jiyong Park618922e2020-01-08 13:35:43 +09002891func (a *Import) JacocoReportClassesFile() android.Path {
2892 return nil
2893}
2894
Bill Peckhama41a6962021-01-11 10:58:54 -08002895func (j *Import) LintDepSets() LintDepSets {
2896 return LintDepSets{}
2897}
2898
Colin Cross74d73e22017-08-02 11:05:49 -07002899func (j *Import) DepsMutator(ctx android.BottomUpMutatorContext) {
Colin Cross42d48b72018-08-29 14:10:52 -07002900 ctx.AddVariationDependencies(nil, libTag, j.properties.Libs...)
Liz Kammerd6c31d22020-08-05 15:40:41 -07002901
2902 if ctx.Device() && Bool(j.dexProperties.Compile_dex) {
2903 sdkDeps(ctx, sdkContext(j), j.dexer)
2904 }
Colin Cross1e676be2016-10-12 14:38:15 -07002905}
2906
Colin Cross74d73e22017-08-02 11:05:49 -07002907func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Paul Duffin4103e922021-02-01 19:01:34 +00002908 // Initialize the hiddenapi structure.
2909 j.initHiddenAPI(ctx, j.BaseModuleName())
2910
Colin Cross56a83212020-09-15 18:30:11 -07002911 if !ctx.Provider(android.ApexInfoProvider).(android.ApexInfo).IsForPlatform() {
2912 j.hideApexVariantFromMake = true
2913 }
2914
Colin Cross8a497952019-03-05 22:25:09 -08002915 jars := android.PathsForModuleSrc(ctx, j.properties.Jars)
Colin Crosse1d62a82015-04-03 16:53:05 -07002916
Jiyong Park0b238752019-10-29 11:23:10 +09002917 jarName := j.Stem() + ".jar"
Nan Zhang4c819fb2018-08-27 18:31:46 -07002918 outputFile := android.PathForModuleOut(ctx, "combined", jarName)
Colin Cross37f6d792018-07-12 12:28:41 -07002919 TransformJarsToJar(ctx, outputFile, "for prebuilts", jars, android.OptionalPath{},
2920 false, j.properties.Exclude_files, j.properties.Exclude_dirs)
Colin Cross1001a792019-03-21 22:21:39 -07002921 if Bool(j.properties.Jetifier) {
Nan Zhang4c819fb2018-08-27 18:31:46 -07002922 inputFile := outputFile
2923 outputFile = android.PathForModuleOut(ctx, "jetifier", jarName)
2924 TransformJetifier(ctx, outputFile, inputFile)
2925 }
Colin Crosse9a275b2017-10-16 17:09:48 -07002926 j.combinedClasspathFile = outputFile
Ulya Trafimovichb23d28c2020-10-08 12:53:58 +01002927 j.classLoaderContexts = make(dexpreopt.ClassLoaderContextMap)
Paul Duffin859fe962020-05-15 10:20:31 +01002928
Liz Kammerd6c31d22020-08-05 15:40:41 -07002929 var flags javaBuilderFlags
Paul Duffin064b70c2020-11-02 17:32:38 +00002930 var deapexerModule android.Module
Liz Kammerd6c31d22020-08-05 15:40:41 -07002931
Jiyong Park1be96912018-05-28 18:02:19 +09002932 ctx.VisitDirectDeps(func(module android.Module) {
Jiyong Park1be96912018-05-28 18:02:19 +09002933 tag := ctx.OtherModuleDependencyTag(module)
2934
Colin Crossdcf71b22021-02-01 13:59:03 -08002935 if ctx.OtherModuleHasProvider(module, JavaInfoProvider) {
2936 dep := ctx.OtherModuleProvider(module, JavaInfoProvider).(JavaInfo)
Jiyong Park1be96912018-05-28 18:02:19 +09002937 switch tag {
2938 case libTag, staticLibTag:
Colin Crossdcf71b22021-02-01 13:59:03 -08002939 flags.classpath = append(flags.classpath, dep.HeaderJars...)
Liz Kammerd6c31d22020-08-05 15:40:41 -07002940 case bootClasspathTag:
Colin Crossdcf71b22021-02-01 13:59:03 -08002941 flags.bootClasspath = append(flags.bootClasspath, dep.HeaderJars...)
Jiyong Park1be96912018-05-28 18:02:19 +09002942 }
Colin Crossdcf71b22021-02-01 13:59:03 -08002943 } else if dep, ok := module.(SdkLibraryDependency); ok {
Jiyong Park1be96912018-05-28 18:02:19 +09002944 switch tag {
2945 case libTag:
Liz Kammerd6c31d22020-08-05 15:40:41 -07002946 flags.classpath = append(flags.classpath, dep.SdkHeaderJars(ctx, j.sdkVersion())...)
Jiyong Park1be96912018-05-28 18:02:19 +09002947 }
2948 }
Ulya Trafimovich65b03192020-12-03 16:50:22 +00002949
Ulya Trafimovich88bb6f62020-12-16 16:16:11 +00002950 addCLCFromDep(ctx, module, j.classLoaderContexts)
Paul Duffin064b70c2020-11-02 17:32:38 +00002951
2952 // Save away the `deapexer` module on which this depends, if any.
2953 if tag == android.DeapexerTag {
2954 deapexerModule = module
2955 }
Jiyong Park1be96912018-05-28 18:02:19 +09002956 })
2957
Nan Zhang4973ecf2018-08-10 13:42:12 -07002958 if Bool(j.properties.Installable) {
Ulya Trafimovich88bb6f62020-12-16 16:16:11 +00002959 ctx.InstallFile(android.PathForModuleInstall(ctx, "framework"),
Jiyong Park4c4c0242019-10-21 14:53:15 +09002960 jarName, outputFile)
Nan Zhang4973ecf2018-08-10 13:42:12 -07002961 }
Jiyong Park19604de2020-03-24 16:44:11 +09002962
2963 j.exportAidlIncludeDirs = android.PathsForModuleSrc(ctx, j.properties.Aidl.Export_include_dirs)
Liz Kammerd6c31d22020-08-05 15:40:41 -07002964
Paul Duffin064b70c2020-11-02 17:32:38 +00002965 if ctx.Device() {
2966 // If this is a variant created for a prebuilt_apex then use the dex implementation jar
2967 // obtained from the associated deapexer module.
2968 ai := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo)
2969 if ai.ForPrebuiltApex {
2970 if deapexerModule == nil {
2971 // This should never happen as a variant for a prebuilt_apex is only created if the
2972 // deapxer module has been configured to export the dex implementation jar for this module.
2973 ctx.ModuleErrorf("internal error: module %q does not depend on a `deapexer` module for prebuilt_apex %q",
2974 j.Name(), ai.ApexVariationName)
2975 }
2976
2977 // Get the path of the dex implementation jar from the `deapexer` module.
2978 di := ctx.OtherModuleProvider(deapexerModule, android.DeapexerProvider).(android.DeapexerInfo)
Paul Duffin9d67ca62021-02-03 20:06:33 +00002979 if dexOutputPath := di.PrebuiltExportPath(j.BaseModuleName(), ".dexjar"); dexOutputPath != nil {
2980 j.dexJarFile = dexOutputPath
Paul Duffinf75e5272021-02-09 14:34:25 +00002981 j.hiddenAPIExtractInformation(ctx, dexOutputPath, outputFile)
Paul Duffin9d67ca62021-02-03 20:06:33 +00002982 } else {
Paul Duffin064b70c2020-11-02 17:32:38 +00002983 // This should never happen as a variant for a prebuilt_apex is only created if the
2984 // prebuilt_apex has been configured to export the java library dex file.
2985 ctx.ModuleErrorf("internal error: no dex implementation jar available from prebuilt_apex %q", deapexerModule.Name())
2986 }
2987 } else if Bool(j.dexProperties.Compile_dex) {
2988 sdkDep := decodeSdkDep(ctx, sdkContext(j))
2989 if sdkDep.invalidVersion {
2990 ctx.AddMissingDependencies(sdkDep.bootclasspath)
2991 ctx.AddMissingDependencies(sdkDep.java9Classpath)
2992 } else if sdkDep.useFiles {
2993 // sdkDep.jar is actually equivalent to turbine header.jar.
2994 flags.classpath = append(flags.classpath, sdkDep.jars...)
2995 }
2996
2997 // Dex compilation
2998
2999 j.dexpreopter.installPath = android.PathForModuleInstall(ctx, "framework", jarName)
3000 if j.dexProperties.Uncompress_dex == nil {
3001 // If the value was not force-set by the user, use reasonable default based on the module.
3002 j.dexProperties.Uncompress_dex = proptools.BoolPtr(shouldUncompressDex(ctx, &j.dexpreopter))
3003 }
3004 j.dexpreopter.uncompressedDex = *j.dexProperties.Uncompress_dex
3005
Paul Duffin612e6102021-02-02 13:38:13 +00003006 var dexOutputFile android.OutputPath
Paul Duffin064b70c2020-11-02 17:32:38 +00003007 dexOutputFile = j.dexer.compileDex(ctx, flags, j.minSdkVersion(), outputFile, jarName)
3008 if ctx.Failed() {
3009 return
3010 }
3011
Paul Duffin064b70c2020-11-02 17:32:38 +00003012 // Hidden API CSV generation and dex encoding
Paul Duffinf75e5272021-02-09 14:34:25 +00003013 dexOutputFile = j.hiddenAPIExtractAndEncode(ctx, dexOutputFile, outputFile,
Paul Duffin064b70c2020-11-02 17:32:38 +00003014 proptools.Bool(j.dexProperties.Uncompress_dex))
3015
3016 j.dexJarFile = dexOutputFile
Liz Kammerd6c31d22020-08-05 15:40:41 -07003017 }
Liz Kammerd6c31d22020-08-05 15:40:41 -07003018 }
Colin Crossdcf71b22021-02-01 13:59:03 -08003019
3020 ctx.SetProvider(JavaInfoProvider, JavaInfo{
3021 HeaderJars: android.PathsIfNonNil(j.combinedClasspathFile),
3022 ImplementationAndResourcesJars: android.PathsIfNonNil(j.combinedClasspathFile),
3023 ImplementationJars: android.PathsIfNonNil(j.combinedClasspathFile),
3024 AidlIncludeDirs: j.exportAidlIncludeDirs,
3025 })
Colin Cross2fe66872015-03-30 17:20:39 -07003026}
3027
Paul Duffinaa55f742020-10-06 17:20:13 +01003028func (j *Import) OutputFiles(tag string) (android.Paths, error) {
3029 switch tag {
Saeid Farivar Asanjan128fe5c2020-10-15 17:54:40 +00003030 case "", ".jar":
Paul Duffinaa55f742020-10-06 17:20:13 +01003031 return android.Paths{j.combinedClasspathFile}, nil
3032 default:
3033 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
3034 }
3035}
3036
3037var _ android.OutputFileProducer = (*Import)(nil)
3038
Nan Zhanged19fc32017-10-19 13:06:22 -07003039func (j *Import) HeaderJars() android.Paths {
albaltai36ff7dc2018-12-25 14:35:23 +08003040 if j.combinedClasspathFile == nil {
3041 return nil
3042 }
Colin Cross37f6d792018-07-12 12:28:41 -07003043 return android.Paths{j.combinedClasspathFile}
Nan Zhanged19fc32017-10-19 13:06:22 -07003044}
3045
Colin Cross331a1212018-08-15 20:40:52 -07003046func (j *Import) ImplementationAndResourcesJars() android.Paths {
albaltai36ff7dc2018-12-25 14:35:23 +08003047 if j.combinedClasspathFile == nil {
3048 return nil
3049 }
Colin Cross331a1212018-08-15 20:40:52 -07003050 return android.Paths{j.combinedClasspathFile}
3051}
3052
Ulyana Trafimovich5539e7b2020-06-04 14:08:17 +00003053func (j *Import) DexJarBuildPath() android.Path {
Liz Kammerd6c31d22020-08-05 15:40:41 -07003054 return j.dexJarFile
Colin Crossf24a22a2019-01-31 14:12:44 -08003055}
3056
Ulya Trafimovich9f3052c2020-06-09 14:31:19 +01003057func (j *Import) DexJarInstallPath() android.Path {
3058 return nil
3059}
3060
Ulya Trafimovichb23d28c2020-10-08 12:53:58 +01003061func (j *Import) ClassLoaderContexts() dexpreopt.ClassLoaderContextMap {
3062 return j.classLoaderContexts
Jiyong Park1be96912018-05-28 18:02:19 +09003063}
3064
Jiyong Park45bf82e2020-12-15 22:29:02 +09003065var _ android.ApexModule = (*Import)(nil)
3066
3067// Implements android.ApexModule
Jiyong Park0f80c182020-01-31 02:49:53 +09003068func (j *Import) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
Paul Duffin0d3c2e12020-05-17 08:34:50 +01003069 return j.depIsInSameApex(ctx, dep)
Jiyong Park0f80c182020-01-31 02:49:53 +09003070}
3071
Jiyong Park45bf82e2020-12-15 22:29:02 +09003072// Implements android.ApexModule
Dan Albertc8060532020-07-22 22:32:17 -07003073func (j *Import) ShouldSupportSdkVersion(ctx android.BaseModuleContext,
3074 sdkVersion android.ApiLevel) error {
Jooyung Han749dc692020-04-15 11:03:39 +09003075 // Do not check for prebuilts against the min_sdk_version of enclosing APEX
3076 return nil
3077}
3078
albaltai36ff7dc2018-12-25 14:35:23 +08003079// Add compile time check for interface implementation
3080var _ android.IDEInfo = (*Import)(nil)
3081var _ android.IDECustomizedModuleName = (*Import)(nil)
3082
Brandon Lee5d45c6f2018-08-15 15:35:38 -07003083// Collect information for opening IDE project files in java/jdeps.go.
3084const (
3085 removedPrefix = "prebuilt_"
3086)
3087
3088func (j *Import) IDEInfo(dpInfo *android.IdeInfo) {
3089 dpInfo.Jars = append(dpInfo.Jars, j.PrebuiltSrcs()...)
3090}
3091
3092func (j *Import) IDECustomizedModuleName() string {
3093 // TODO(b/113562217): Extract the base module name from the Import name, often the Import name
3094 // has a prefix "prebuilt_". Remove the prefix explicitly if needed until we find a better
3095 // solution to get the Import name.
3096 name := j.Name()
3097 if strings.HasPrefix(name, removedPrefix) {
patricktubb640e02018-10-11 18:33:16 +08003098 name = strings.TrimPrefix(name, removedPrefix)
Brandon Lee5d45c6f2018-08-15 15:35:38 -07003099 }
3100 return name
3101}
3102
Colin Cross74d73e22017-08-02 11:05:49 -07003103var _ android.PrebuiltInterface = (*Import)(nil)
Colin Cross2fe66872015-03-30 17:20:39 -07003104
Bill Peckhamff89ffa2020-12-23 16:13:04 -08003105func (j *Import) IsInstallable() bool {
3106 return Bool(j.properties.Installable)
3107}
3108
3109var _ dexpreopterInterface = (*Import)(nil)
3110
Colin Cross1b16b0e2019-02-12 14:41:32 -08003111// java_import imports one or more `.jar` files into the build graph as if they were built by a java_library module.
3112//
3113// By default, a java_import has a single variant that expects a `.jar` file containing `.class` files that were
3114// compiled against an Android classpath.
3115//
3116// Specifying `host_supported: true` will produce two variants, one for use as a dependency of device modules and one
3117// for host modules.
Colin Cross74d73e22017-08-02 11:05:49 -07003118func ImportFactory() android.Module {
3119 module := &Import{}
Colin Cross36242852017-06-23 15:06:31 -07003120
Liz Kammerd6c31d22020-08-05 15:40:41 -07003121 module.AddProperties(
3122 &module.properties,
3123 &module.dexer.dexProperties,
3124 )
Colin Cross74d73e22017-08-02 11:05:49 -07003125
Paul Duffin859fe962020-05-15 10:20:31 +01003126 module.initModuleAndImport(&module.ModuleBase)
3127
Liz Kammerd6c31d22020-08-05 15:40:41 -07003128 module.dexProperties.Optimize.EnabledByDefault = false
3129
Colin Cross74d73e22017-08-02 11:05:49 -07003130 android.InitPrebuiltModule(module, &module.properties.Jars)
Jiyong Park7f7766d2019-07-25 22:02:35 +09003131 android.InitApexModule(module)
Jiyong Parkd1063c12019-07-17 20:08:41 +09003132 android.InitSdkAwareModule(module)
Jooyung Han18020ea2019-11-13 10:50:48 +09003133 InitJavaModule(module, android.HostAndDeviceSupported)
Colin Cross36242852017-06-23 15:06:31 -07003134 return module
Colin Cross2fe66872015-03-30 17:20:39 -07003135}
3136
Colin Cross1b16b0e2019-02-12 14:41:32 -08003137// java_import imports one or more `.jar` files into the build graph as if they were built by a java_library_host
3138// module.
3139//
3140// A java_import_host has a single variant that expects a `.jar` file containing `.class` files that were
3141// compiled against a host bootclasspath.
Colin Cross74d73e22017-08-02 11:05:49 -07003142func ImportFactoryHost() android.Module {
3143 module := &Import{}
3144
3145 module.AddProperties(&module.properties)
3146
3147 android.InitPrebuiltModule(module, &module.properties.Jars)
Jiyong Park7f7766d2019-07-25 22:02:35 +09003148 android.InitApexModule(module)
Jooyung Han18020ea2019-11-13 10:50:48 +09003149 InitJavaModule(module, android.HostSupported)
Colin Cross74d73e22017-08-02 11:05:49 -07003150 return module
3151}
3152
Colin Cross42be7612019-02-21 18:12:14 -08003153// dex_import module
3154
3155type DexImportProperties struct {
Colin Cross5cfc70d2019-07-15 13:36:55 -07003156 Jars []string `android:"path"`
Jiyong Park4c4c0242019-10-21 14:53:15 +09003157
3158 // set the name of the output
3159 Stem *string
Colin Cross42be7612019-02-21 18:12:14 -08003160}
3161
3162type DexImport struct {
3163 android.ModuleBase
3164 android.DefaultableModuleBase
Jiyong Park7f7766d2019-07-25 22:02:35 +09003165 android.ApexModuleBase
Colin Cross42be7612019-02-21 18:12:14 -08003166 prebuilt android.Prebuilt
3167
3168 properties DexImportProperties
3169
Colin Crossb014f072021-02-26 14:54:36 -08003170 dexJarFile android.Path
Colin Cross42be7612019-02-21 18:12:14 -08003171
3172 dexpreopter
Colin Cross56a83212020-09-15 18:30:11 -07003173
3174 hideApexVariantFromMake bool
Colin Cross42be7612019-02-21 18:12:14 -08003175}
3176
3177func (j *DexImport) Prebuilt() *android.Prebuilt {
3178 return &j.prebuilt
3179}
3180
3181func (j *DexImport) PrebuiltSrcs() []string {
3182 return j.properties.Jars
3183}
3184
3185func (j *DexImport) Name() string {
3186 return j.prebuilt.Name(j.ModuleBase.Name())
3187}
3188
Jiyong Park0b238752019-10-29 11:23:10 +09003189func (j *DexImport) Stem() string {
3190 return proptools.StringDefault(j.properties.Stem, j.ModuleBase.Name())
3191}
3192
Jiyong Park77acec62020-06-01 21:39:15 +09003193func (a *DexImport) JacocoReportClassesFile() android.Path {
3194 return nil
3195}
3196
Colin Cross08dca382020-07-21 20:31:17 -07003197func (a *DexImport) LintDepSets() LintDepSets {
3198 return LintDepSets{}
3199}
3200
Martin Stjernholm6d415272020-01-31 17:10:36 +00003201func (j *DexImport) IsInstallable() bool {
3202 return true
3203}
3204
Colin Cross42be7612019-02-21 18:12:14 -08003205func (j *DexImport) GenerateAndroidBuildActions(ctx android.ModuleContext) {
3206 if len(j.properties.Jars) != 1 {
3207 ctx.PropertyErrorf("jars", "exactly one jar must be provided")
3208 }
3209
Colin Cross56a83212020-09-15 18:30:11 -07003210 apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo)
3211 if !apexInfo.IsForPlatform() {
3212 j.hideApexVariantFromMake = true
3213 }
3214
Jiyong Park0b238752019-10-29 11:23:10 +09003215 j.dexpreopter.installPath = android.PathForModuleInstall(ctx, "framework", j.Stem()+".jar")
Colin Cross42be7612019-02-21 18:12:14 -08003216 j.dexpreopter.uncompressedDex = shouldUncompressDex(ctx, &j.dexpreopter)
3217
3218 inputJar := ctx.ExpandSource(j.properties.Jars[0], "jars")
3219 dexOutputFile := android.PathForModuleOut(ctx, ctx.ModuleName()+".jar")
3220
3221 if j.dexpreopter.uncompressedDex {
Colin Crossf1a035e2020-11-16 17:32:30 -08003222 rule := android.NewRuleBuilder(pctx, ctx)
Colin Cross42be7612019-02-21 18:12:14 -08003223
3224 temporary := android.PathForModuleOut(ctx, ctx.ModuleName()+".jar.unaligned")
3225 rule.Temporary(temporary)
3226
3227 // use zip2zip to uncompress classes*.dex files
3228 rule.Command().
Colin Crossf1a035e2020-11-16 17:32:30 -08003229 BuiltTool("zip2zip").
Colin Cross42be7612019-02-21 18:12:14 -08003230 FlagWithInput("-i ", inputJar).
3231 FlagWithOutput("-o ", temporary).
3232 FlagWithArg("-0 ", "'classes*.dex'")
3233
3234 // use zipalign to align uncompressed classes*.dex files
3235 rule.Command().
Colin Crossf1a035e2020-11-16 17:32:30 -08003236 BuiltTool("zipalign").
Colin Cross42be7612019-02-21 18:12:14 -08003237 Flag("-f").
3238 Text("4").
3239 Input(temporary).
3240 Output(dexOutputFile)
3241
3242 rule.DeleteTemporaryFiles()
3243
Colin Crossf1a035e2020-11-16 17:32:30 -08003244 rule.Build("uncompress_dex", "uncompress dex")
Colin Cross42be7612019-02-21 18:12:14 -08003245 } else {
3246 ctx.Build(pctx, android.BuildParams{
3247 Rule: android.Cp,
3248 Input: inputJar,
3249 Output: dexOutputFile,
3250 })
3251 }
3252
3253 j.dexJarFile = dexOutputFile
3254
Jaewoong Jung4b97a562020-12-17 09:43:28 -08003255 j.dexpreopt(ctx, dexOutputFile)
Colin Cross42be7612019-02-21 18:12:14 -08003256
Colin Cross56a83212020-09-15 18:30:11 -07003257 if apexInfo.IsForPlatform() {
Jiyong Park01bca752020-06-08 19:24:09 +09003258 ctx.InstallFile(android.PathForModuleInstall(ctx, "framework"),
3259 j.Stem()+".jar", dexOutputFile)
3260 }
Colin Cross42be7612019-02-21 18:12:14 -08003261}
3262
Ulyana Trafimovich5539e7b2020-06-04 14:08:17 +00003263func (j *DexImport) DexJarBuildPath() android.Path {
Colin Cross42be7612019-02-21 18:12:14 -08003264 return j.dexJarFile
3265}
3266
Jiyong Park45bf82e2020-12-15 22:29:02 +09003267var _ android.ApexModule = (*DexImport)(nil)
3268
3269// Implements android.ApexModule
Dan Albertc8060532020-07-22 22:32:17 -07003270func (j *DexImport) ShouldSupportSdkVersion(ctx android.BaseModuleContext,
3271 sdkVersion android.ApiLevel) error {
Jooyung Han749dc692020-04-15 11:03:39 +09003272 // we don't check prebuilt modules for sdk_version
3273 return nil
3274}
3275
Colin Cross42be7612019-02-21 18:12:14 -08003276// dex_import imports a `.jar` file containing classes.dex files.
3277//
3278// A dex_import module cannot be used as a dependency of a java_* or android_* module, it can only be installed
3279// to the device.
3280func DexImportFactory() android.Module {
3281 module := &DexImport{}
3282
3283 module.AddProperties(&module.properties)
3284
3285 android.InitPrebuiltModule(module, &module.properties.Jars)
Jiyong Park7f7766d2019-07-25 22:02:35 +09003286 android.InitApexModule(module)
Jooyung Han18020ea2019-11-13 10:50:48 +09003287 InitJavaModule(module, android.DeviceSupported)
Colin Cross42be7612019-02-21 18:12:14 -08003288 return module
3289}
3290
Colin Cross89536d42017-07-07 14:35:50 -07003291//
3292// Defaults
3293//
3294type Defaults struct {
3295 android.ModuleBase
3296 android.DefaultsModuleBase
Jiyong Park7f7766d2019-07-25 22:02:35 +09003297 android.ApexModuleBase
Colin Cross89536d42017-07-07 14:35:50 -07003298}
3299
Colin Cross1b16b0e2019-02-12 14:41:32 -08003300// java_defaults provides a set of properties that can be inherited by other java or android modules.
3301//
3302// A module can use the properties from a java_defaults module using `defaults: ["defaults_module_name"]`. Each
3303// property in the defaults module that exists in the depending module will be prepended to the depending module's
3304// value for that property.
3305//
3306// Example:
3307//
3308// java_defaults {
3309// name: "example_defaults",
3310// srcs: ["common/**/*.java"],
3311// javacflags: ["-Xlint:all"],
3312// aaptflags: ["--auto-add-overlay"],
3313// }
3314//
3315// java_library {
3316// name: "example",
3317// defaults: ["example_defaults"],
3318// srcs: ["example/**/*.java"],
3319// }
3320//
3321// is functionally identical to:
3322//
3323// java_library {
3324// name: "example",
3325// srcs: [
3326// "common/**/*.java",
3327// "example/**/*.java",
3328// ],
3329// javacflags: ["-Xlint:all"],
3330// }
Paul Duffin47357662019-12-05 14:07:14 +00003331func DefaultsFactory() android.Module {
Colin Cross89536d42017-07-07 14:35:50 -07003332 module := &Defaults{}
3333
Colin Cross89536d42017-07-07 14:35:50 -07003334 module.AddProperties(
3335 &CompilerProperties{},
3336 &CompilerDeviceProperties{},
Liz Kammera7a64f32020-07-09 15:16:41 -07003337 &DexProperties{},
Colin Cross43f08db2018-11-12 10:13:39 -08003338 &DexpreoptProperties{},
Dan Willemsen6424d172018-03-08 13:27:59 -08003339 &android.ProtoProperties{},
Colin Cross48de9a42018-10-02 13:53:33 -07003340 &aaptProperties{},
3341 &androidLibraryProperties{},
3342 &appProperties{},
3343 &appTestProperties{},
Jaewoong Jung525443a2019-02-28 15:35:54 -08003344 &overridableAppProperties{},
Roland Levillainb5b0ff32020-02-04 15:45:49 +00003345 &testProperties{},
Colin Cross48de9a42018-10-02 13:53:33 -07003346 &ImportProperties{},
3347 &AARImportProperties{},
3348 &sdkLibraryProperties{},
Paul Duffin1b1e8062020-05-08 13:44:43 +01003349 &commonToSdkLibraryAndImportProperties{},
Colin Cross42be7612019-02-21 18:12:14 -08003350 &DexImportProperties{},
Jooyung Han18020ea2019-11-13 10:50:48 +09003351 &android.ApexProperties{},
Jaewoong Jungbf135462020-04-26 15:10:51 -07003352 &RuntimeResourceOverlayProperties{},
Colin Cross014489c2020-06-02 20:09:13 -07003353 &LintProperties{},
Colin Crosscbce0b02021-02-09 10:38:30 -08003354 &appTestHelperAppProperties{},
Colin Cross89536d42017-07-07 14:35:50 -07003355 )
3356
3357 android.InitDefaultsModule(module)
Colin Cross89536d42017-07-07 14:35:50 -07003358 return module
3359}
Nan Zhangea568a42017-11-08 21:20:04 -08003360
Sasha Smundak2a4549e2018-11-05 16:49:08 -08003361func kytheExtractJavaFactory() android.Singleton {
3362 return &kytheExtractJavaSingleton{}
3363}
3364
3365type kytheExtractJavaSingleton struct {
3366}
3367
3368func (ks *kytheExtractJavaSingleton) GenerateBuildActions(ctx android.SingletonContext) {
3369 var xrefTargets android.Paths
3370 ctx.VisitAllModules(func(module android.Module) {
3371 if javaModule, ok := module.(xref); ok {
3372 xrefTargets = append(xrefTargets, javaModule.XrefJavaFiles()...)
3373 }
3374 })
3375 // TODO(asmundak): perhaps emit a rule to output a warning if there were no xrefTargets
3376 if len(xrefTargets) > 0 {
Colin Crossc3d87d32020-06-04 13:25:17 -07003377 ctx.Phony("xref_java", xrefTargets...)
Sasha Smundak2a4549e2018-11-05 16:49:08 -08003378 }
3379}
3380
Nan Zhangea568a42017-11-08 21:20:04 -08003381var Bool = proptools.Bool
Colin Cross38b40df2018-04-10 16:14:46 -07003382var BoolDefault = proptools.BoolDefault
Nan Zhangea568a42017-11-08 21:20:04 -08003383var String = proptools.String
Colin Cross0d0ba592018-02-20 13:33:42 -08003384var inList = android.InList
Ulya Trafimovich65b03192020-12-03 16:50:22 +00003385
Ulya Trafimovich88bb6f62020-12-16 16:16:11 +00003386// TODO(b/132357300) Generalize SdkLibrarComponentDependency to non-SDK libraries and merge with
3387// this interface.
3388type ProvidesUsesLib interface {
3389 ProvidesUsesLib() *string
3390}
Ulya Trafimovich65b03192020-12-03 16:50:22 +00003391
Ulya Trafimovich88bb6f62020-12-16 16:16:11 +00003392func (j *Module) ProvidesUsesLib() *string {
3393 return j.usesLibraryProperties.Provides_uses_lib
3394}
Ulya Trafimovich65b03192020-12-03 16:50:22 +00003395
Ulya Trafimovich88bb6f62020-12-16 16:16:11 +00003396// Add class loader context (CLC) of a given dependency to the current CLC.
3397func addCLCFromDep(ctx android.ModuleContext, depModule android.Module,
3398 clcMap dexpreopt.ClassLoaderContextMap) {
3399
3400 dep, ok := depModule.(UsesLibraryDependency)
3401 if !ok {
3402 return
3403 }
3404
3405 // Find out if the dependency is either an SDK library or an ordinary library that is disguised
3406 // as an SDK library by the means of `provides_uses_lib` property. If yes, the library is itself
3407 // a <uses-library> and should be added as a node in the CLC tree, and its CLC should be added
3408 // as subtree of that node. Otherwise the library is not a <uses_library> and should not be
3409 // added to CLC, but the transitive <uses-library> dependencies from its CLC should be added to
3410 // the current CLC.
3411 var implicitSdkLib *string
3412 comp, isComp := depModule.(SdkLibraryComponentDependency)
3413 if isComp {
3414 implicitSdkLib = comp.OptionalImplicitSdkLibrary()
3415 // OptionalImplicitSdkLibrary() may be nil so need to fall through to ProvidesUsesLib().
3416 }
3417 if implicitSdkLib == nil {
3418 if ulib, ok := depModule.(ProvidesUsesLib); ok {
3419 implicitSdkLib = ulib.ProvidesUsesLib()
Ulya Trafimovich65b03192020-12-03 16:50:22 +00003420 }
3421 }
Ulya Trafimovich88bb6f62020-12-16 16:16:11 +00003422
3423 depTag := ctx.OtherModuleDependencyTag(depModule)
3424 if depTag == libTag || depTag == usesLibTag {
3425 // Ok, propagate <uses-library> through non-static library dependencies.
3426 } else if depTag == staticLibTag {
3427 // Propagate <uses-library> through static library dependencies, unless it is a component
3428 // library (such as stubs). Component libraries have a dependency on their SDK library,
3429 // which should not be pulled just because of a static component library.
3430 if implicitSdkLib != nil {
3431 return
3432 }
3433 } else {
3434 // Don't propagate <uses-library> for other dependency tags.
3435 return
3436 }
3437
3438 if implicitSdkLib != nil {
Ulya Trafimovich7bc1cf52021-01-05 15:41:55 +00003439 clcMap.AddContext(ctx, dexpreopt.AnySdkVersion, *implicitSdkLib,
Ulya Trafimovich88bb6f62020-12-16 16:16:11 +00003440 dep.DexJarBuildPath(), dep.DexJarInstallPath(), dep.ClassLoaderContexts())
3441 } else {
3442 depName := ctx.OtherModuleName(depModule)
3443 clcMap.AddContextMap(dep.ClassLoaderContexts(), depName)
3444 }
Ulya Trafimovich65b03192020-12-03 16:50:22 +00003445}