blob: c8fb93cca34051dac742fda9a8be8ed8d2bcb3af [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"
Wei Libafb6d62021-12-10 03:14:59 -080024 "strings"
Colin Cross2fe66872015-03-30 17:20:39 -070025
Wei Libafb6d62021-12-10 03:14:59 -080026 "android/soong/bazel"
Sam Delmerico4e272292022-01-06 20:03:51 +000027
Colin Cross2fe66872015-03-30 17:20:39 -070028 "github.com/google/blueprint"
Colin Cross76b5f0c2017-08-29 16:02:06 -070029 "github.com/google/blueprint/proptools"
Colin Cross2fe66872015-03-30 17:20:39 -070030
Colin Cross635c3b02016-05-18 15:37:25 -070031 "android/soong/android"
Colin Crossf8d9c492021-01-26 11:01:43 -080032 "android/soong/cc"
Ulya Trafimovich31e444e2020-08-14 17:32:16 +010033 "android/soong/dexpreopt"
Colin Cross3e3e72d2017-06-22 17:20:19 -070034 "android/soong/java/config"
Colin Cross303e21f2018-08-07 16:49:25 -070035 "android/soong/tradefed"
Colin Cross2fe66872015-03-30 17:20:39 -070036)
37
Colin Cross463a90e2015-06-17 14:20:06 -070038func init() {
Paul Duffin535e0a12021-03-30 23:34:32 +010039 registerJavaBuildComponents(android.InitRegistrationContext)
Paul Duffin255f18e2019-12-13 11:22:16 +000040
Jaewoong Jungbc15e3a2021-03-10 17:02:43 -080041 RegisterJavaSdkMemberTypes()
42}
43
Paul Duffin535e0a12021-03-30 23:34:32 +010044func registerJavaBuildComponents(ctx android.RegistrationContext) {
Jaewoong Jungbc15e3a2021-03-10 17:02:43 -080045 ctx.RegisterModuleType("java_defaults", DefaultsFactory)
46
47 ctx.RegisterModuleType("java_library", LibraryFactory)
48 ctx.RegisterModuleType("java_library_static", LibraryStaticFactory)
49 ctx.RegisterModuleType("java_library_host", LibraryHostFactory)
50 ctx.RegisterModuleType("java_binary", BinaryFactory)
51 ctx.RegisterModuleType("java_binary_host", BinaryHostFactory)
52 ctx.RegisterModuleType("java_test", TestFactory)
53 ctx.RegisterModuleType("java_test_helper_library", TestHelperLibraryFactory)
54 ctx.RegisterModuleType("java_test_host", TestHostFactory)
55 ctx.RegisterModuleType("java_test_import", JavaTestImportFactory)
56 ctx.RegisterModuleType("java_import", ImportFactory)
57 ctx.RegisterModuleType("java_import_host", ImportFactoryHost)
58 ctx.RegisterModuleType("java_device_for_host", DeviceForHostFactory)
59 ctx.RegisterModuleType("java_host_for_device", HostForDeviceFactory)
60 ctx.RegisterModuleType("dex_import", DexImportFactory)
61
Martin Stjernholm0e4cceb2021-05-13 02:38:35 +010062 // This mutator registers dependencies on dex2oat for modules that should be
63 // dexpreopted. This is done late when the final variants have been
64 // established, to not get the dependencies split into the wrong variants and
65 // to support the checks in dexpreoptDisabled().
Jaewoong Jungbc15e3a2021-03-10 17:02:43 -080066 ctx.FinalDepsMutators(func(ctx android.RegisterMutatorsContext) {
67 ctx.BottomUp("dexpreopt_tool_deps", dexpreoptToolDepsMutator).Parallel()
68 })
69
70 ctx.RegisterSingletonType("logtags", LogtagsSingleton)
71 ctx.RegisterSingletonType("kythe_java_extract", kytheExtractJavaFactory)
72}
73
74func RegisterJavaSdkMemberTypes() {
Paul Duffin255f18e2019-12-13 11:22:16 +000075 // Register sdk member types.
Paul Duffin7b81f5e2020-01-13 21:03:22 +000076 android.RegisterSdkMemberType(javaHeaderLibsSdkMemberType)
Paul Duffin2da04242021-04-23 19:43:28 +010077 android.RegisterSdkMemberType(javaLibsSdkMemberType)
78 android.RegisterSdkMemberType(javaBootLibsSdkMemberType)
Jiakai Zhangea180332021-09-26 08:58:02 +000079 android.RegisterSdkMemberType(javaSystemserverLibsSdkMemberType)
Paul Duffin2da04242021-04-23 19:43:28 +010080 android.RegisterSdkMemberType(javaTestSdkMemberType)
81}
82
83var (
84 // Supports adding java header libraries to module_exports and sdk.
85 javaHeaderLibsSdkMemberType = &librarySdkMemberType{
86 android.SdkMemberTypeBase{
87 PropertyName: "java_header_libs",
88 SupportsSdk: true,
89 },
90 func(_ android.SdkMemberContext, j *Library) android.Path {
91 headerJars := j.HeaderJars()
92 if len(headerJars) != 1 {
93 panic(fmt.Errorf("there must be only one header jar from %q", j.Name()))
94 }
95
96 return headerJars[0]
97 },
98 sdkSnapshotFilePathForJar,
99 copyEverythingToSnapshot,
100 }
Paul Duffin255f18e2019-12-13 11:22:16 +0000101
Paul Duffin22ff0aa2021-02-04 11:15:34 +0000102 // Export implementation classes jar as part of the sdk.
Paul Duffin2da04242021-04-23 19:43:28 +0100103 exportImplementationClassesJar = func(_ android.SdkMemberContext, j *Library) android.Path {
Paul Duffin22ff0aa2021-02-04 11:15:34 +0000104 implementationJars := j.ImplementationAndResourcesJars()
105 if len(implementationJars) != 1 {
106 panic(fmt.Errorf("there must be only one implementation jar from %q", j.Name()))
107 }
108 return implementationJars[0]
109 }
110
Paul Duffin2da04242021-04-23 19:43:28 +0100111 // Supports adding java implementation libraries to module_exports but not sdk.
112 javaLibsSdkMemberType = &librarySdkMemberType{
Paul Duffinf5c0a9c2020-02-28 14:39:53 +0000113 android.SdkMemberTypeBase{
114 PropertyName: "java_libs",
115 },
Paul Duffin22ff0aa2021-02-04 11:15:34 +0000116 exportImplementationClassesJar,
Paul Duffindb170e42020-12-08 17:48:25 +0000117 sdkSnapshotFilePathForJar,
118 copyEverythingToSnapshot,
Paul Duffin2da04242021-04-23 19:43:28 +0100119 }
Paul Duffin1b82e6a2019-12-03 18:06:47 +0000120
Paul Duffin2da04242021-04-23 19:43:28 +0100121 // Supports adding java boot libraries to module_exports and sdk.
Paul Duffindb170e42020-12-08 17:48:25 +0000122 //
123 // The build has some implicit dependencies (via the boot jars configuration) on a number of
124 // modules, e.g. core-oj, apache-xml, that are part of the java boot class path and which are
125 // provided by mainline modules (e.g. art, conscrypt, runtime-i18n) but which are not otherwise
126 // used outside those mainline modules.
127 //
128 // As they are not needed outside the mainline modules adding them to the sdk/module-exports as
129 // either java_libs, or java_header_libs would end up exporting more information than was strictly
130 // necessary. The java_boot_libs property to allow those modules to be exported as part of the
131 // sdk/module_exports without exposing any unnecessary information.
Paul Duffin2da04242021-04-23 19:43:28 +0100132 javaBootLibsSdkMemberType = &librarySdkMemberType{
Paul Duffindb170e42020-12-08 17:48:25 +0000133 android.SdkMemberTypeBase{
134 PropertyName: "java_boot_libs",
135 SupportsSdk: true,
136 },
Paul Duffin5c211452021-07-15 12:42:44 +0100137 func(ctx android.SdkMemberContext, j *Library) android.Path {
138 // Java boot libs are only provided in the SDK to provide access to their dex implementation
139 // jar for use by dexpreopting and boot jars package check. They do not need to provide an
140 // actual implementation jar but the java_import will need a file that exists so just copy an
141 // empty file. Any attempt to use that file as a jar will cause a build error.
142 return ctx.SnapshotBuilder().EmptyFile()
143 },
144 func(osPrefix, name string) string {
145 // Create a special name for the implementation jar to try and provide some useful information
146 // to a developer that attempts to compile against this.
147 // TODO(b/175714559): Provide a proper error message in Soong not ninja.
148 return filepath.Join(osPrefix, "java_boot_libs", "snapshot", "jars", "are", "invalid", name+jarFileSuffix)
149 },
Paul Duffindb170e42020-12-08 17:48:25 +0000150 onlyCopyJarToSnapshot,
Paul Duffin2da04242021-04-23 19:43:28 +0100151 }
Paul Duffindb170e42020-12-08 17:48:25 +0000152
Jiakai Zhangea180332021-09-26 08:58:02 +0000153 // Supports adding java systemserver libraries to module_exports and sdk.
154 //
155 // The build has some implicit dependencies (via the systemserver jars configuration) on a number
156 // of modules that are part of the java systemserver classpath and which are provided by mainline
157 // modules but which are not otherwise used outside those mainline modules.
158 //
159 // As they are not needed outside the mainline modules adding them to the sdk/module-exports as
160 // either java_libs, or java_header_libs would end up exporting more information than was strictly
161 // necessary. The java_systemserver_libs property to allow those modules to be exported as part of
162 // the sdk/module_exports without exposing any unnecessary information.
163 javaSystemserverLibsSdkMemberType = &librarySdkMemberType{
164 android.SdkMemberTypeBase{
165 PropertyName: "java_systemserver_libs",
166 SupportsSdk: true,
167 },
168 func(ctx android.SdkMemberContext, j *Library) android.Path {
169 // Java systemserver libs are only provided in the SDK to provide access to their dex
170 // implementation jar for use by dexpreopting. They do not need to provide an actual
171 // implementation jar but the java_import will need a file that exists so just copy an empty
172 // file. Any attempt to use that file as a jar will cause a build error.
173 return ctx.SnapshotBuilder().EmptyFile()
174 },
175 func(osPrefix, name string) string {
176 // Create a special name for the implementation jar to try and provide some useful information
177 // to a developer that attempts to compile against this.
178 // TODO(b/175714559): Provide a proper error message in Soong not ninja.
179 return filepath.Join(osPrefix, "java_systemserver_libs", "snapshot", "jars", "are", "invalid", name+jarFileSuffix)
180 },
181 onlyCopyJarToSnapshot,
182 }
183
Paul Duffin2da04242021-04-23 19:43:28 +0100184 // Supports adding java test libraries to module_exports but not sdk.
185 javaTestSdkMemberType = &testSdkMemberType{
Paul Duffin1b82e6a2019-12-03 18:06:47 +0000186 SdkMemberTypeBase: android.SdkMemberTypeBase{
187 PropertyName: "java_tests",
188 },
Paul Duffin2da04242021-04-23 19:43:28 +0100189 }
190)
Jeongik Cha538c0d02019-07-11 15:54:27 +0900191
Colin Crossdcf71b22021-02-01 13:59:03 -0800192// JavaInfo contains information about a java module for use by modules that depend on it.
193type JavaInfo struct {
194 // HeaderJars is a list of jars that can be passed as the javac classpath in order to link
195 // against this module. If empty, ImplementationJars should be used instead.
196 HeaderJars android.Paths
197
198 // ImplementationAndResourceJars is a list of jars that contain the implementations of classes
199 // in the module as well as any resources included in the module.
200 ImplementationAndResourcesJars android.Paths
201
202 // ImplementationJars is a list of jars that contain the implementations of classes in the
203 //module.
204 ImplementationJars android.Paths
205
206 // ResourceJars is a list of jars that contain the resources included in the module.
207 ResourceJars android.Paths
208
209 // AidlIncludeDirs is a list of directories that should be passed to the aidl tool when
210 // depending on this module.
211 AidlIncludeDirs android.Paths
212
213 // SrcJarArgs is a list of arguments to pass to soong_zip to package the sources of this
214 // module.
215 SrcJarArgs []string
216
217 // SrcJarDeps is a list of paths to depend on when packaging the sources of this module.
218 SrcJarDeps android.Paths
219
220 // ExportedPlugins is a list of paths that should be used as annotation processors for any
221 // module that depends on this module.
222 ExportedPlugins android.Paths
223
224 // ExportedPluginClasses is a list of classes that should be run as annotation processors for
225 // any module that depends on this module.
226 ExportedPluginClasses []string
227
228 // ExportedPluginDisableTurbine is true if this module's annotation processors generate APIs,
229 // requiring disbling turbine for any modules that depend on it.
230 ExportedPluginDisableTurbine bool
231
232 // JacocoReportClassesFile is the path to a jar containing uninstrumented classes that will be
233 // instrumented by jacoco.
234 JacocoReportClassesFile android.Path
235}
236
237var JavaInfoProvider = blueprint.NewProvider(JavaInfo{})
238
Colin Cross75ce9ec2021-02-26 16:20:32 -0800239// SyspropPublicStubInfo contains info about the sysprop public stub library that corresponds to
240// the sysprop implementation library.
241type SyspropPublicStubInfo struct {
242 // JavaInfo is the JavaInfoProvider of the sysprop public stub library that corresponds to
243 // the sysprop implementation library.
244 JavaInfo JavaInfo
245}
246
247var SyspropPublicStubInfoProvider = blueprint.NewProvider(SyspropPublicStubInfo{})
248
Paul Duffin44b481b2020-06-17 16:59:43 +0100249// Methods that need to be implemented for a module that is added to apex java_libs property.
250type ApexDependency interface {
Nan Zhanged19fc32017-10-19 13:06:22 -0700251 HeaderJars() android.Paths
Paul Duffin44b481b2020-06-17 16:59:43 +0100252 ImplementationAndResourcesJars() android.Paths
253}
254
Ulya Trafimovich31e444e2020-08-14 17:32:16 +0100255// Provides build path and install path to DEX jars.
256type UsesLibraryDependency interface {
Martin Stjernholm8be1e6d2021-09-15 03:34:04 +0100257 DexJarBuildPath() OptionalDexJarPath
Ulya Trafimovich9f3052c2020-06-09 14:31:19 +0100258 DexJarInstallPath() android.Path
Ulya Trafimovichdbf31662020-12-17 12:07:54 +0000259 ClassLoaderContexts() dexpreopt.ClassLoaderContextMap
Ulya Trafimovich31e444e2020-08-14 17:32:16 +0100260}
261
Jaewoong Jung26342642021-03-17 15:56:23 -0700262// TODO(jungjw): Move this to kythe.go once it's created.
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800263type xref interface {
264 XrefJavaFiles() android.Paths
265}
266
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800267func (j *Module) XrefJavaFiles() android.Paths {
268 return j.kytheFiles
269}
270
Colin Crossbe1da472017-07-07 15:59:46 -0700271type dependencyTag struct {
272 blueprint.BaseDependencyTag
273 name string
Colin Cross65cb3142021-12-10 23:05:02 +0000274
275 // True if the dependency is relinked at runtime.
276 runtimeLinked bool
Colin Crossce564252022-01-12 11:13:32 -0800277
278 // True if the dependency is a toolchain, for example an annotation processor.
279 toolchain bool
Colin Cross2fe66872015-03-30 17:20:39 -0700280}
281
Colin Crosse9fe2942020-11-10 18:12:15 -0800282// installDependencyTag is a dependency tag that is annotated to cause the installed files of the
283// dependency to be installed when the parent module is installed.
284type installDependencyTag struct {
285 blueprint.BaseDependencyTag
286 android.InstallAlwaysNeededDependencyTag
287 name string
288}
289
Colin Cross65cb3142021-12-10 23:05:02 +0000290func (d dependencyTag) LicenseAnnotations() []android.LicenseAnnotation {
291 if d.runtimeLinked {
292 return []android.LicenseAnnotation{android.LicenseAnnotationSharedDependency}
Colin Crossce564252022-01-12 11:13:32 -0800293 } else if d.toolchain {
294 return []android.LicenseAnnotation{android.LicenseAnnotationToolchain}
Colin Cross65cb3142021-12-10 23:05:02 +0000295 }
296 return nil
297}
298
299var _ android.LicenseAnnotationsDependencyTag = dependencyTag{}
300
Ulya Trafimovichb5218112020-10-07 15:11:32 +0100301type usesLibraryDependencyTag struct {
302 dependencyTag
Ulya Trafimovich0b1c70e2021-08-20 15:39:12 +0100303
304 // SDK version in which the library appared as a standalone library.
305 sdkVersion int
306
307 // If the dependency is optional or required.
308 optional bool
309
310 // Whether this is an implicit dependency inferred by Soong, or an explicit one added via
311 // `uses_libs`/`optional_uses_libs` properties.
312 implicit bool
Ulya Trafimovichb5218112020-10-07 15:11:32 +0100313}
314
Ulya Trafimovich0b1c70e2021-08-20 15:39:12 +0100315func makeUsesLibraryDependencyTag(sdkVersion int, optional bool, implicit bool) usesLibraryDependencyTag {
Ulya Trafimovichb5218112020-10-07 15:11:32 +0100316 return usesLibraryDependencyTag{
Colin Cross65cb3142021-12-10 23:05:02 +0000317 dependencyTag: dependencyTag{
318 name: fmt.Sprintf("uses-library-%d", sdkVersion),
319 runtimeLinked: true,
320 },
321 sdkVersion: sdkVersion,
322 optional: optional,
323 implicit: implicit,
Ulya Trafimovichb5218112020-10-07 15:11:32 +0100324 }
325}
326
Jiyong Park8be103b2019-11-08 15:53:48 +0900327func IsJniDepTag(depTag blueprint.DependencyTag) bool {
Colin Crossde78d132020-10-09 18:59:49 -0700328 return depTag == jniLibTag
Jiyong Park8be103b2019-11-08 15:53:48 +0900329}
330
Colin Crossbe1da472017-07-07 15:59:46 -0700331var (
Colin Cross75ce9ec2021-02-26 16:20:32 -0800332 dataNativeBinsTag = dependencyTag{name: "dataNativeBins"}
Sam Delmericob3342ce2022-01-20 21:10:28 +0000333 dataDeviceBinsTag = dependencyTag{name: "dataDeviceBins"}
Colin Cross75ce9ec2021-02-26 16:20:32 -0800334 staticLibTag = dependencyTag{name: "staticlib"}
Colin Cross65cb3142021-12-10 23:05:02 +0000335 libTag = dependencyTag{name: "javalib", runtimeLinked: true}
336 java9LibTag = dependencyTag{name: "java9lib", runtimeLinked: true}
Colin Crossce564252022-01-12 11:13:32 -0800337 pluginTag = dependencyTag{name: "plugin", toolchain: true}
338 errorpronePluginTag = dependencyTag{name: "errorprone-plugin", toolchain: true}
339 exportedPluginTag = dependencyTag{name: "exported-plugin", toolchain: true}
Colin Cross65cb3142021-12-10 23:05:02 +0000340 bootClasspathTag = dependencyTag{name: "bootclasspath", runtimeLinked: true}
341 systemModulesTag = dependencyTag{name: "system modules", runtimeLinked: true}
Colin Cross75ce9ec2021-02-26 16:20:32 -0800342 frameworkResTag = dependencyTag{name: "framework-res"}
Colin Cross65cb3142021-12-10 23:05:02 +0000343 kotlinStdlibTag = dependencyTag{name: "kotlin-stdlib", runtimeLinked: true}
344 kotlinAnnotationsTag = dependencyTag{name: "kotlin-annotations", runtimeLinked: true}
Colin Crossce564252022-01-12 11:13:32 -0800345 kotlinPluginTag = dependencyTag{name: "kotlin-plugin", toolchain: true}
Colin Cross75ce9ec2021-02-26 16:20:32 -0800346 proguardRaiseTag = dependencyTag{name: "proguard-raise"}
347 certificateTag = dependencyTag{name: "certificate"}
348 instrumentationForTag = dependencyTag{name: "instrumentation_for"}
Colin Crossce564252022-01-12 11:13:32 -0800349 extraLintCheckTag = dependencyTag{name: "extra-lint-check", toolchain: true}
Colin Cross65cb3142021-12-10 23:05:02 +0000350 jniLibTag = dependencyTag{name: "jnilib", runtimeLinked: true}
Colin Cross75ce9ec2021-02-26 16:20:32 -0800351 syspropPublicStubDepTag = dependencyTag{name: "sysprop public stub"}
352 jniInstallTag = installDependencyTag{name: "jni install"}
353 binaryInstallTag = installDependencyTag{name: "binary install"}
Colin Crossbe1da472017-07-07 15:59:46 -0700354)
Colin Cross2fe66872015-03-30 17:20:39 -0700355
Jiyong Park83dc74b2020-01-14 18:38:44 +0900356func IsLibDepTag(depTag blueprint.DependencyTag) bool {
357 return depTag == libTag
358}
359
360func IsStaticLibDepTag(depTag blueprint.DependencyTag) bool {
361 return depTag == staticLibTag
362}
363
Colin Crossfc3674a2017-09-18 17:41:52 -0700364type sdkDep struct {
Pete Gilline3d44b22020-06-29 11:28:51 +0100365 useModule, useFiles, invalidVersion bool
Colin Cross47ff2522017-10-02 14:22:08 -0700366
Colin Cross6cef4812019-10-17 14:23:50 -0700367 // The modules that will be added to the bootclasspath when targeting 1.8 or lower
368 bootclasspath []string
Paul Duffine25c6442019-10-11 13:50:28 +0100369
370 // The default system modules to use. Will be an empty string if no system
371 // modules are to be used.
Colin Cross1369cdb2017-09-29 17:58:17 -0700372 systemModules string
373
Pete Gilline3d44b22020-06-29 11:28:51 +0100374 // The modules that will be added to the classpath regardless of the Java language level targeted
375 classpath []string
376
Colin Cross6cef4812019-10-17 14:23:50 -0700377 // The modules that will be added ot the classpath when targeting 1.9 or higher
Pete Gilline3d44b22020-06-29 11:28:51 +0100378 // (normally these will be on the bootclasspath when targeting 1.8 or lower)
Colin Cross6cef4812019-10-17 14:23:50 -0700379 java9Classpath []string
380
Colin Crossa97c5d32018-03-28 14:58:31 -0700381 frameworkResModule string
382
Colin Cross86a60ae2018-05-29 14:44:55 -0700383 jars android.Paths
Colin Cross3047fa22019-04-18 10:56:44 -0700384 aidl android.OptionalPath
Paul Duffin250e6192019-06-07 10:44:37 +0100385
386 noStandardLibs, noFrameworksLibs bool
387}
388
389func (s sdkDep) hasStandardLibs() bool {
390 return !s.noStandardLibs
391}
392
393func (s sdkDep) hasFrameworkLibs() bool {
394 return !s.noStandardLibs && !s.noFrameworksLibs
Colin Cross1369cdb2017-09-29 17:58:17 -0700395}
396
Colin Crossa4f08812018-10-02 22:03:40 -0700397type jniLib struct {
Colin Cross403cc152020-07-06 14:15:24 -0700398 name string
399 path android.Path
400 target android.Target
401 coverageFile android.OptionalPath
402 unstrippedFile android.Path
Colin Crossa4f08812018-10-02 22:03:40 -0700403}
404
Jiyong Parkf1691d22021-03-29 20:11:58 +0900405func sdkDeps(ctx android.BottomUpMutatorContext, sdkContext android.SdkContext, d dexer) {
Liz Kammerd6c31d22020-08-05 15:40:41 -0700406 sdkDep := decodeSdkDep(ctx, sdkContext)
407 if sdkDep.useModule {
408 ctx.AddVariationDependencies(nil, bootClasspathTag, sdkDep.bootclasspath...)
409 ctx.AddVariationDependencies(nil, java9LibTag, sdkDep.java9Classpath...)
410 ctx.AddVariationDependencies(nil, libTag, sdkDep.classpath...)
411 if d.effectiveOptimizeEnabled() && sdkDep.hasStandardLibs() {
412 ctx.AddVariationDependencies(nil, proguardRaiseTag, config.LegacyCorePlatformBootclasspathLibraries...)
413 }
414 if d.effectiveOptimizeEnabled() && sdkDep.hasFrameworkLibs() {
415 ctx.AddVariationDependencies(nil, proguardRaiseTag, config.FrameworkLibraries...)
416 }
417 }
418 if sdkDep.systemModules != "" {
419 ctx.AddVariationDependencies(nil, systemModulesTag, sdkDep.systemModules)
420 }
421}
422
Colin Cross32f676a2017-09-06 13:41:06 -0700423type deps struct {
Colin Cross9bb9bfb2022-03-17 11:12:32 -0700424 // bootClasspath is the list of jars that form the boot classpath (generally the java.* and
425 // android.* classes) for tools that still use it. javac targeting 1.9 or higher uses
426 // systemModules and java9Classpath instead.
427 bootClasspath classpath
428
429 // classpath is the list of jars that form the classpath for javac and kotlinc rules. It
430 // contains header jars for all static and non-static dependencies.
431 classpath classpath
432
433 // dexClasspath is the list of jars that form the classpath for d8 and r8 rules. It contains
434 // header jars for all non-static dependencies. Static dependencies have already been
435 // combined into the program jar.
436 dexClasspath classpath
437
438 // java9Classpath is the list of jars that will be added to the classpath when targeting
439 // 1.9 or higher. It generally contains the android.* classes, while the java.* classes
440 // are provided by systemModules.
441 java9Classpath classpath
442
Colin Cross748b2d82020-11-19 13:52:06 -0800443 processorPath classpath
444 errorProneProcessorPath classpath
445 processorClasses []string
446 staticJars android.Paths
447 staticHeaderJars android.Paths
448 staticResourceJars android.Paths
449 aidlIncludeDirs android.Paths
450 srcs android.Paths
451 srcJars android.Paths
452 systemModules *systemModules
453 aidlPreprocess android.OptionalPath
454 kotlinStdlib android.Paths
455 kotlinAnnotations android.Paths
Colin Crossa1ff7c62021-09-17 14:11:52 -0700456 kotlinPlugins android.Paths
Colin Crossbe9cdb82019-01-21 21:37:16 -0800457
458 disableTurbine bool
Colin Cross32f676a2017-09-06 13:41:06 -0700459}
Colin Cross2fe66872015-03-30 17:20:39 -0700460
Colin Cross54250902017-12-05 09:28:08 -0800461func checkProducesJars(ctx android.ModuleContext, dep android.SourceFileProducer) {
462 for _, f := range dep.Srcs() {
463 if f.Ext() != ".jar" {
464 ctx.ModuleErrorf("genrule %q must generate files ending with .jar to be used as a libs or static_libs dependency",
465 ctx.OtherModuleName(dep.(blueprint.Module)))
466 }
467 }
468}
469
Jiyong Parkf1691d22021-03-29 20:11:58 +0900470func getJavaVersion(ctx android.ModuleContext, javaVersion string, sdkContext android.SdkContext) javaVersion {
Nan Zhang357466b2018-04-17 17:38:36 -0700471 if javaVersion != "" {
Colin Cross1e743852019-10-28 11:37:20 -0700472 return normalizeJavaVersion(ctx, javaVersion)
Colin Cross17dec172020-05-14 18:05:32 -0700473 } else if ctx.Device() {
Jiyong Park92315372021-04-02 08:45:46 +0900474 return defaultJavaLanguageVersion(ctx, sdkContext.SdkVersion(ctx))
Sorin Basca8d3e0bb2022-01-20 15:21:51 +0000475 } else {
Sorin Basca18ecf612022-01-23 09:01:07 +0000476 return JAVA_VERSION_11
Nan Zhang357466b2018-04-17 17:38:36 -0700477 }
Nan Zhang357466b2018-04-17 17:38:36 -0700478}
479
Colin Cross1e743852019-10-28 11:37:20 -0700480type javaVersion int
481
482const (
483 JAVA_VERSION_UNSUPPORTED = 0
484 JAVA_VERSION_6 = 6
485 JAVA_VERSION_7 = 7
486 JAVA_VERSION_8 = 8
487 JAVA_VERSION_9 = 9
Sorin Bascac0244da2021-11-26 17:26:33 +0000488 JAVA_VERSION_11 = 11
Colin Cross1e743852019-10-28 11:37:20 -0700489)
490
491func (v javaVersion) String() string {
492 switch v {
493 case JAVA_VERSION_6:
494 return "1.6"
495 case JAVA_VERSION_7:
496 return "1.7"
497 case JAVA_VERSION_8:
498 return "1.8"
499 case JAVA_VERSION_9:
500 return "1.9"
Sorin Bascac0244da2021-11-26 17:26:33 +0000501 case JAVA_VERSION_11:
502 return "11"
Colin Cross1e743852019-10-28 11:37:20 -0700503 default:
504 return "unsupported"
505 }
506}
507
508// Returns true if javac targeting this version uses system modules instead of a bootclasspath.
509func (v javaVersion) usesJavaModules() bool {
510 return v >= 9
511}
512
513func normalizeJavaVersion(ctx android.BaseModuleContext, javaVersion string) javaVersion {
Pete Gillin4e8b48a2019-07-12 13:16:17 +0100514 switch javaVersion {
515 case "1.6", "6":
Colin Cross1e743852019-10-28 11:37:20 -0700516 return JAVA_VERSION_6
Pete Gillin4e8b48a2019-07-12 13:16:17 +0100517 case "1.7", "7":
Colin Cross1e743852019-10-28 11:37:20 -0700518 return JAVA_VERSION_7
Pete Gillin4e8b48a2019-07-12 13:16:17 +0100519 case "1.8", "8":
Colin Cross1e743852019-10-28 11:37:20 -0700520 return JAVA_VERSION_8
Pete Gillin4e8b48a2019-07-12 13:16:17 +0100521 case "1.9", "9":
Colin Cross1e743852019-10-28 11:37:20 -0700522 return JAVA_VERSION_9
Sorin Bascac0244da2021-11-26 17:26:33 +0000523 case "11":
524 return JAVA_VERSION_11
525 case "10":
526 ctx.PropertyErrorf("java_version", "Java language levels 10 is not supported")
Colin Cross1e743852019-10-28 11:37:20 -0700527 return JAVA_VERSION_UNSUPPORTED
Pete Gillin4e8b48a2019-07-12 13:16:17 +0100528 default:
529 ctx.PropertyErrorf("java_version", "Unrecognized Java language level")
Colin Cross1e743852019-10-28 11:37:20 -0700530 return JAVA_VERSION_UNSUPPORTED
Pete Gillin4e8b48a2019-07-12 13:16:17 +0100531 }
532}
533
Colin Cross2fe66872015-03-30 17:20:39 -0700534//
535// Java libraries (.jar file)
536//
537
Colin Crossf506d872017-07-19 15:53:04 -0700538type Library struct {
Colin Cross46c9b8b2017-06-22 16:51:17 -0700539 Module
Colin Crossf0f2e2c2019-10-15 16:36:40 -0700540
541 InstallMixin func(ctx android.ModuleContext, installPath android.Path) (extraInstallDeps android.Paths)
Colin Cross2fe66872015-03-30 17:20:39 -0700542}
543
Jiyong Park45bf82e2020-12-15 22:29:02 +0900544var _ android.ApexModule = (*Library)(nil)
545
satayevd604b212021-07-21 14:23:52 +0100546// Provides access to the list of permitted packages from apex boot jars.
Paul Duffine739f1e2020-05-29 11:24:51 +0100547type PermittedPackagesForUpdatableBootJars interface {
548 PermittedPackagesForUpdatableBootJars() []string
549}
550
551var _ PermittedPackagesForUpdatableBootJars = (*Library)(nil)
552
553func (j *Library) PermittedPackagesForUpdatableBootJars() []string {
554 return j.properties.Permitted_packages
555}
556
Colin Cross42be7612019-02-21 18:12:14 -0800557func shouldUncompressDex(ctx android.ModuleContext, dexpreopter *dexpreopter) bool {
Ulya Trafimovichf491dde2020-01-24 12:19:45 +0000558 // Store uncompressed (and aligned) any dex files from jars in APEXes.
Colin Cross56a83212020-09-15 18:30:11 -0700559 if apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo); !apexInfo.IsForPlatform() {
Ulya Trafimovichf491dde2020-01-24 12:19:45 +0000560 return true
561 }
562
Nicolas Geoffrayfa6e9ec2019-02-12 13:12:16 +0000563 // Store uncompressed (and do not strip) dex files from boot class path jars.
564 if inList(ctx.ModuleName(), ctx.Config().BootJars()) {
565 return true
566 }
567
568 // Store uncompressed dex files that are preopted on /system.
Jiakai Zhang519c5c82021-09-16 06:15:39 +0000569 if !dexpreopter.dexpreoptDisabled(ctx) && (ctx.Host() || !dexpreopter.odexOnSystemOther(ctx, dexpreopter.installPath)) {
Vladimir Markoe8b00d62018-12-21 15:54:16 +0000570 return true
571 }
Colin Cross083a2aa2019-02-06 16:37:12 -0800572 if ctx.Config().UncompressPrivAppDex() &&
573 inList(ctx.ModuleName(), ctx.Config().ModulesLoadedByPrivilegedModules()) {
574 return true
575 }
576
Colin Cross2fc72f62018-12-21 12:59:54 -0800577 return false
578}
579
Jiakai Zhang22450f22021-10-11 03:05:20 +0000580// Sets `dexer.dexProperties.Uncompress_dex` to the proper value.
581func setUncompressDex(ctx android.ModuleContext, dexpreopter *dexpreopter, dexer *dexer) {
582 if dexer.dexProperties.Uncompress_dex == nil {
583 // If the value was not force-set by the user, use reasonable default based on the module.
584 dexer.dexProperties.Uncompress_dex = proptools.BoolPtr(shouldUncompressDex(ctx, dexpreopter))
585 }
586}
587
Colin Crossf506d872017-07-19 15:53:04 -0700588func (j *Library) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Jiyong Park92315372021-04-02 08:45:46 +0900589 j.sdkVersion = j.SdkVersion(ctx)
590 j.minSdkVersion = j.MinSdkVersion(ctx)
satayev0a420e72021-11-29 17:25:52 +0000591 j.maxSdkVersion = j.MaxSdkVersion(ctx)
Jiyong Park92315372021-04-02 08:45:46 +0900592
Colin Cross56a83212020-09-15 18:30:11 -0700593 apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo)
594 if !apexInfo.IsForPlatform() {
595 j.hideApexVariantFromMake = true
596 }
597
Artur Satayev2db1c3f2020-04-08 19:09:30 +0100598 j.checkSdkVersions(ctx)
Jiakai Zhang519c5c82021-09-16 06:15:39 +0000599 j.dexpreopter.installPath = j.dexpreopter.getInstallPath(
600 ctx, android.PathForModuleInstall(ctx, "framework", j.Stem()+".jar"))
Colin Cross43f08db2018-11-12 10:13:39 -0800601 j.dexpreopter.isSDKLibrary = j.deviceProperties.IsSDKLibrary
Jiakai Zhang22450f22021-10-11 03:05:20 +0000602 setUncompressDex(ctx, &j.dexpreopter, &j.dexer)
Liz Kammera7a64f32020-07-09 15:16:41 -0700603 j.dexpreopter.uncompressedDex = *j.dexProperties.Uncompress_dex
Ulya Trafimoviche4432872021-08-18 16:57:11 +0100604 j.classLoaderContexts = j.usesLibrary.classLoaderContextForUsesLibDeps(ctx)
Jaewoong Junga24af3b2019-05-13 09:23:20 -0700605 j.compile(ctx, nil)
Colin Crossb7a63242015-04-16 14:09:14 -0700606
bralee1fbf4402020-05-21 10:11:59 +0800607 // Collect the module directory for IDE info in java/jdeps.go.
608 j.modulePaths = append(j.modulePaths, ctx.ModuleDir())
609
Colin Cross56a83212020-09-15 18:30:11 -0700610 exclusivelyForApex := !apexInfo.IsForPlatform()
Jiyong Park7f7766d2019-07-25 22:02:35 +0900611 if (Bool(j.properties.Installable) || ctx.Host()) && !exclusivelyForApex {
Colin Crossf0f2e2c2019-10-15 16:36:40 -0700612 var extraInstallDeps android.Paths
613 if j.InstallMixin != nil {
614 extraInstallDeps = j.InstallMixin(ctx, j.outputFile)
615 }
Colin Cross1d0eb7a2021-11-03 14:08:20 -0700616 hostDexNeeded := Bool(j.deviceProperties.Hostdex) && !ctx.Host()
617 if hostDexNeeded {
Colin Cross3108ce12021-11-10 14:38:50 -0800618 j.hostdexInstallFile = ctx.InstallFile(
619 android.PathForHostDexInstall(ctx, "framework"),
Colin Cross1d0eb7a2021-11-03 14:08:20 -0700620 j.Stem()+"-hostdex.jar", j.outputFile)
621 }
622 var installDir android.InstallPath
623 if ctx.InstallInTestcases() {
624 var archDir string
625 if !ctx.Host() {
626 archDir = ctx.DeviceConfig().DeviceArch()
627 }
628 installDir = android.PathForModuleInstall(ctx, ctx.ModuleName(), archDir)
629 } else {
630 installDir = android.PathForModuleInstall(ctx, "framework")
631 }
632 j.installFile = ctx.InstallFile(installDir, j.Stem()+".jar", j.outputFile, extraInstallDeps...)
Colin Cross2c429dc2017-08-31 16:45:16 -0700633 }
Colin Crossb7a63242015-04-16 14:09:14 -0700634}
635
Colin Crossf506d872017-07-19 15:53:04 -0700636func (j *Library) DepsMutator(ctx android.BottomUpMutatorContext) {
Colin Cross46c9b8b2017-06-22 16:51:17 -0700637 j.deps(ctx)
Ulya Trafimoviche4432872021-08-18 16:57:11 +0100638 j.usesLibrary.deps(ctx, false)
Colin Cross46c9b8b2017-06-22 16:51:17 -0700639}
640
Paul Duffin0e0cf1d2019-11-12 19:39:25 +0000641const (
Paul Duffin1b82e6a2019-12-03 18:06:47 +0000642 aidlIncludeDir = "aidl"
643 javaDir = "java"
644 jarFileSuffix = ".jar"
645 testConfigSuffix = "-AndroidTest.xml"
Paul Duffin0e0cf1d2019-11-12 19:39:25 +0000646)
647
Paul Duffina0dbf432019-12-05 11:25:53 +0000648// path to the jar file of a java library. Relative to <sdk_root>/<api_dir>
Paul Duffina04c1072020-03-02 10:16:35 +0000649func sdkSnapshotFilePathForJar(osPrefix, name string) string {
650 return sdkSnapshotFilePathForMember(osPrefix, name, jarFileSuffix)
Paul Duffin1b82e6a2019-12-03 18:06:47 +0000651}
652
Paul Duffina04c1072020-03-02 10:16:35 +0000653func sdkSnapshotFilePathForMember(osPrefix, name string, suffix string) string {
654 return filepath.Join(javaDir, osPrefix, name+suffix)
Paul Duffin0e0cf1d2019-11-12 19:39:25 +0000655}
656
Paul Duffin13879572019-11-28 14:31:38 +0000657type librarySdkMemberType struct {
Paul Duffin255f18e2019-12-13 11:22:16 +0000658 android.SdkMemberTypeBase
Paul Duffinf5c0a9c2020-02-28 14:39:53 +0000659
660 // Function to retrieve the appropriate output jar (implementation or header) from
661 // the library.
Paul Duffindb170e42020-12-08 17:48:25 +0000662 jarToExportGetter func(ctx android.SdkMemberContext, j *Library) android.Path
663
664 // Function to compute the snapshot relative path to which the named library's
665 // jar should be copied.
666 snapshotPathGetter func(osPrefix, name string) string
667
668 // True if only the jar should be copied to the snapshot, false if the jar plus any additional
669 // files like aidl files should also be copied.
670 onlyCopyJarToSnapshot bool
Paul Duffin13879572019-11-28 14:31:38 +0000671}
672
Paul Duffindb170e42020-12-08 17:48:25 +0000673const (
674 onlyCopyJarToSnapshot = true
675 copyEverythingToSnapshot = false
676)
677
Paul Duffin296701e2021-07-14 10:29:36 +0100678func (mt *librarySdkMemberType) AddDependencies(ctx android.SdkDependencyContext, dependencyTag blueprint.DependencyTag, names []string) {
679 ctx.AddVariationDependencies(nil, dependencyTag, names...)
Paul Duffin13879572019-11-28 14:31:38 +0000680}
681
682func (mt *librarySdkMemberType) IsInstance(module android.Module) bool {
683 _, ok := module.(*Library)
684 return ok
685}
686
Paul Duffin3a4eb502020-03-19 16:11:18 +0000687func (mt *librarySdkMemberType) AddPrebuiltModule(ctx android.SdkMemberContext, member android.SdkMember) android.BpModule {
688 return ctx.SnapshotBuilder().AddPrebuiltModule(member, "java_import")
Paul Duffin14eb4672020-03-02 11:33:02 +0000689}
Paul Duffina0dbf432019-12-05 11:25:53 +0000690
Paul Duffin14eb4672020-03-02 11:33:02 +0000691func (mt *librarySdkMemberType) CreateVariantPropertiesStruct() android.SdkMemberProperties {
Paul Duffina551a1c2020-03-17 21:04:24 +0000692 return &librarySdkMemberProperties{}
Paul Duffin14eb4672020-03-02 11:33:02 +0000693}
694
695type librarySdkMemberProperties struct {
696 android.SdkMemberPropertiesBase
697
Paul Duffin864e1b42020-05-06 10:23:19 +0100698 JarToExport android.Path `android:"arch_variant"`
Paul Duffina551a1c2020-03-17 21:04:24 +0000699 AidlIncludeDirs android.Paths
Paul Duffin869de142021-07-15 14:14:41 +0100700
701 // The list of permitted packages that need to be passed to the prebuilts as they are used to
702 // create the updatable-bcp-packages.txt file.
703 PermittedPackages []string
Paul Duffin14eb4672020-03-02 11:33:02 +0000704}
705
Paul Duffin3a4eb502020-03-19 16:11:18 +0000706func (p *librarySdkMemberProperties) PopulateFromVariant(ctx android.SdkMemberContext, variant android.Module) {
Paul Duffin13879572019-11-28 14:31:38 +0000707 j := variant.(*Library)
708
Paul Duffindb170e42020-12-08 17:48:25 +0000709 p.JarToExport = ctx.MemberType().(*librarySdkMemberType).jarToExportGetter(ctx, j)
710
Paul Duffina551a1c2020-03-17 21:04:24 +0000711 p.AidlIncludeDirs = j.AidlIncludeDirs()
Paul Duffin869de142021-07-15 14:14:41 +0100712
713 p.PermittedPackages = j.PermittedPackagesForUpdatableBootJars()
Paul Duffin14eb4672020-03-02 11:33:02 +0000714}
Paul Duffin0e0cf1d2019-11-12 19:39:25 +0000715
Paul Duffin3a4eb502020-03-19 16:11:18 +0000716func (p *librarySdkMemberProperties) AddToPropertySet(ctx android.SdkMemberContext, propertySet android.BpPropertySet) {
Paul Duffina551a1c2020-03-17 21:04:24 +0000717 builder := ctx.SnapshotBuilder()
Paul Duffin3a4eb502020-03-19 16:11:18 +0000718
Paul Duffindb170e42020-12-08 17:48:25 +0000719 memberType := ctx.MemberType().(*librarySdkMemberType)
720
Paul Duffina551a1c2020-03-17 21:04:24 +0000721 exportedJar := p.JarToExport
722 if exportedJar != nil {
Paul Duffindb170e42020-12-08 17:48:25 +0000723 // Delegate the creation of the snapshot relative path to the member type.
724 snapshotRelativeJavaLibPath := memberType.snapshotPathGetter(p.OsPrefix(), ctx.Name())
725
726 // Copy the exported jar to the snapshot.
Paul Duffin14eb4672020-03-02 11:33:02 +0000727 builder.CopyToSnapshot(exportedJar, snapshotRelativeJavaLibPath)
728
Paul Duffina551a1c2020-03-17 21:04:24 +0000729 propertySet.AddProperty("jars", []string{snapshotRelativeJavaLibPath})
730 }
731
Paul Duffin869de142021-07-15 14:14:41 +0100732 if len(p.PermittedPackages) > 0 {
733 propertySet.AddProperty("permitted_packages", p.PermittedPackages)
734 }
735
Paul Duffindb170e42020-12-08 17:48:25 +0000736 // Do not copy anything else to the snapshot.
737 if memberType.onlyCopyJarToSnapshot {
738 return
739 }
740
Paul Duffina551a1c2020-03-17 21:04:24 +0000741 aidlIncludeDirs := p.AidlIncludeDirs
742 if len(aidlIncludeDirs) != 0 {
743 sdkModuleContext := ctx.SdkModuleContext()
744 for _, dir := range aidlIncludeDirs {
Paul Duffin14eb4672020-03-02 11:33:02 +0000745 // TODO(jiyong): copy parcelable declarations only
746 aidlFiles, _ := sdkModuleContext.GlobWithDeps(dir.String()+"/**/*.aidl", nil)
747 for _, file := range aidlFiles {
748 builder.CopyToSnapshot(android.PathForSource(sdkModuleContext, file), filepath.Join(aidlIncludeDir, file))
749 }
Paul Duffin0e0cf1d2019-11-12 19:39:25 +0000750 }
Paul Duffin0e0cf1d2019-11-12 19:39:25 +0000751
Paul Duffina551a1c2020-03-17 21:04:24 +0000752 // TODO(b/151933053) - add aidl include dirs property
Paul Duffin14eb4672020-03-02 11:33:02 +0000753 }
Paul Duffin0e0cf1d2019-11-12 19:39:25 +0000754}
755
Colin Cross1b16b0e2019-02-12 14:41:32 -0800756// java_library builds and links sources into a `.jar` file for the device, and possibly for the host as well.
757//
758// By default, a java_library has a single variant that produces a `.jar` file containing `.class` files that were
759// compiled against the device bootclasspath. This jar is not suitable for installing on a device, but can be used
760// as a `static_libs` dependency of another module.
761//
762// Specifying `installable: true` will product a `.jar` file containing `classes.dex` files, suitable for installing on
763// a device.
764//
765// Specifying `host_supported: true` will produce two variants, one compiled against the device bootclasspath and one
766// compiled against the host bootclasspath.
Colin Cross9ae1b922018-06-26 17:59:05 -0700767func LibraryFactory() android.Module {
768 module := &Library{}
Colin Cross2fe66872015-03-30 17:20:39 -0700769
Colin Crossce6734e2020-06-15 16:09:53 -0700770 module.addHostAndDeviceProperties()
Colin Cross2fe66872015-03-30 17:20:39 -0700771
Paul Duffin71b33cc2021-06-23 11:39:47 +0100772 module.initModuleAndImport(module)
Paul Duffin859fe962020-05-15 10:20:31 +0100773
Jiyong Park7f7766d2019-07-25 22:02:35 +0900774 android.InitApexModule(module)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900775 android.InitSdkAwareModule(module)
Wei Libafb6d62021-12-10 03:14:59 -0800776 android.InitBazelModule(module)
Jooyung Han18020ea2019-11-13 10:50:48 +0900777 InitJavaModule(module, android.HostAndDeviceSupported)
Colin Cross9ae1b922018-06-26 17:59:05 -0700778 return module
Colin Cross2fe66872015-03-30 17:20:39 -0700779}
780
Colin Cross1b16b0e2019-02-12 14:41:32 -0800781// java_library_static is an obsolete alias for java_library.
782func LibraryStaticFactory() android.Module {
783 return LibraryFactory()
784}
785
786// java_library_host builds and links sources into a `.jar` file for the host.
787//
788// A java_library_host has a single variant that produces a `.jar` file containing `.class` files that were
789// compiled against the host bootclasspath.
Colin Crossf506d872017-07-19 15:53:04 -0700790func LibraryHostFactory() android.Module {
791 module := &Library{}
Colin Cross2fe66872015-03-30 17:20:39 -0700792
Colin Crossce6734e2020-06-15 16:09:53 -0700793 module.addHostProperties()
Colin Cross36242852017-06-23 15:06:31 -0700794
Colin Cross9ae1b922018-06-26 17:59:05 -0700795 module.Module.properties.Installable = proptools.BoolPtr(true)
796
Jiyong Park7f7766d2019-07-25 22:02:35 +0900797 android.InitApexModule(module)
Paul Duffinb6b89a42021-05-06 16:33:43 +0100798 android.InitSdkAwareModule(module)
Wei Libafb6d62021-12-10 03:14:59 -0800799 android.InitBazelModule(module)
Jooyung Han18020ea2019-11-13 10:50:48 +0900800 InitJavaModule(module, android.HostSupported)
Colin Cross36242852017-06-23 15:06:31 -0700801 return module
Colin Cross2fe66872015-03-30 17:20:39 -0700802}
803
804//
Colin Crossb628ea52018-08-14 16:42:33 -0700805// Java Tests
Colin Cross05638fc2018-04-09 18:40:24 -0700806//
807
Dan Shi95d19422020-08-15 12:24:26 -0700808// Test option struct.
809type TestOptions struct {
810 // a list of extra test configuration files that should be installed with the module.
811 Extra_test_configs []string `android:"path,arch_variant"`
Dan Shid79572f2020-11-13 14:33:46 -0800812
813 // If the test is a hostside(no device required) unittest that shall be run during presubmit check.
814 Unit_test *bool
Dan Shi95d19422020-08-15 12:24:26 -0700815}
816
Colin Cross05638fc2018-04-09 18:40:24 -0700817type testProperties struct {
Colin Cross05638fc2018-04-09 18:40:24 -0700818 // list of compatibility suites (for example "cts", "vts") that the module should be
819 // installed into.
820 Test_suites []string `android:"arch_variant"`
Julien Despreze146e392018-08-02 15:00:46 -0700821
822 // the name of the test configuration (for example "AndroidTest.xml") that should be
823 // installed with the module.
Colin Cross27b922f2019-03-04 22:35:41 -0800824 Test_config *string `android:"path,arch_variant"`
Colin Crossd96ca352018-08-10 16:06:24 -0700825
Jack He33338892018-09-19 02:21:28 -0700826 // the name of the test configuration template (for example "AndroidTestTemplate.xml") that
827 // should be installed with the module.
Colin Cross27b922f2019-03-04 22:35:41 -0800828 Test_config_template *string `android:"path,arch_variant"`
Jack He33338892018-09-19 02:21:28 -0700829
Colin Crossd96ca352018-08-10 16:06:24 -0700830 // list of files or filegroup modules that provide data that should be installed alongside
831 // the test
Jiyong Park2b0e4902021-02-16 06:52:39 +0900832 Data []string `android:"path"`
Dan Shi6ffaaa82019-09-26 11:41:36 -0700833
834 // Flag to indicate whether or not to create test config automatically. If AndroidTest.xml
835 // doesn't exist next to the Android.bp, this attribute doesn't need to be set to true
836 // explicitly.
837 Auto_gen_config *bool
easoncylee5bcff5d2020-04-30 14:57:06 +0800838
839 // Add parameterized mainline modules to auto generated test config. The options will be
840 // handled by TradeFed to do downloading and installing the specified modules on the device.
841 Test_mainline_modules []string
Dan Shi95d19422020-08-15 12:24:26 -0700842
843 // Test options.
844 Test_options TestOptions
Colin Crossf8d9c492021-01-26 11:01:43 -0800845
846 // Names of modules containing JNI libraries that should be installed alongside the test.
847 Jni_libs []string
Colin Crosscfb0f5e2021-09-24 15:47:17 -0700848
849 // Install the test into a folder named for the module in all test suites.
850 Per_testcase_directory *bool
Colin Cross05638fc2018-04-09 18:40:24 -0700851}
852
Liz Kammerdd849a82020-06-12 16:38:45 -0700853type hostTestProperties struct {
854 // list of native binary modules that should be installed alongside the test
855 Data_native_bins []string `android:"arch_variant"`
Sam Delmericob3342ce2022-01-20 21:10:28 +0000856
857 // list of device binary modules that should be installed alongside the test
Sam Delmericob706b4e2022-06-01 15:45:02 +0000858 // This property only adds the first variant of the dependency
859 Data_device_bins_first []string `android:"arch_variant"`
860
861 // list of device binary modules that should be installed alongside the test
862 // This property adds 64bit AND 32bit variants of the dependency
863 Data_device_bins_both []string `android:"arch_variant"`
864
865 // list of device binary modules that should be installed alongside the test
866 // This property only adds 64bit variants of the dependency
867 Data_device_bins_64 []string `android:"arch_variant"`
868
869 // list of device binary modules that should be installed alongside the test
870 // This property adds 32bit variants of the dependency if available, or else
871 // defaults to the 64bit variant
872 Data_device_bins_prefer32 []string `android:"arch_variant"`
873
874 // list of device binary modules that should be installed alongside the test
875 // This property only adds 32bit variants of the dependency
876 Data_device_bins_32 []string `android:"arch_variant"`
Liz Kammerdd849a82020-06-12 16:38:45 -0700877}
878
Paul Duffin42df1442019-03-20 12:45:53 +0000879type testHelperLibraryProperties struct {
880 // list of compatibility suites (for example "cts", "vts") that the module should be
881 // installed into.
882 Test_suites []string `android:"arch_variant"`
Colin Crosscfb0f5e2021-09-24 15:47:17 -0700883
884 // Install the test into a folder named for the module in all test suites.
885 Per_testcase_directory *bool
Paul Duffin42df1442019-03-20 12:45:53 +0000886}
887
Paul Duffin1b82e6a2019-12-03 18:06:47 +0000888type prebuiltTestProperties struct {
889 // list of compatibility suites (for example "cts", "vts") that the module should be
890 // installed into.
891 Test_suites []string `android:"arch_variant"`
892
893 // the name of the test configuration (for example "AndroidTest.xml") that should be
894 // installed with the module.
895 Test_config *string `android:"path,arch_variant"`
896}
897
Colin Cross05638fc2018-04-09 18:40:24 -0700898type Test struct {
899 Library
900
901 testProperties testProperties
Colin Cross303e21f2018-08-07 16:49:25 -0700902
Dan Shi95d19422020-08-15 12:24:26 -0700903 testConfig android.Path
904 extraTestConfigs android.Paths
905 data android.Paths
Colin Cross303e21f2018-08-07 16:49:25 -0700906}
907
Liz Kammerdd849a82020-06-12 16:38:45 -0700908type TestHost struct {
909 Test
910
911 testHostProperties hostTestProperties
912}
913
Paul Duffin42df1442019-03-20 12:45:53 +0000914type TestHelperLibrary struct {
915 Library
916
917 testHelperLibraryProperties testHelperLibraryProperties
918}
919
Paul Duffin1b82e6a2019-12-03 18:06:47 +0000920type JavaTestImport struct {
921 Import
922
923 prebuiltTestProperties prebuiltTestProperties
924
925 testConfig android.Path
Liz Kammerd6c31d22020-08-05 15:40:41 -0700926 dexJarFile android.Path
Paul Duffin1b82e6a2019-12-03 18:06:47 +0000927}
928
Colin Cross24cc4be62021-11-03 14:09:41 -0700929func (j *Test) InstallInTestcases() bool {
930 // Host java tests install into $(HOST_OUT_JAVA_LIBRARIES), and then are copied into
931 // testcases by base_rules.mk.
932 return !j.Host()
933}
934
935func (j *TestHelperLibrary) InstallInTestcases() bool {
936 return true
937}
938
939func (j *JavaTestImport) InstallInTestcases() bool {
940 return true
941}
942
Sam Delmericob706b4e2022-06-01 15:45:02 +0000943func (j *TestHost) addDataDeviceBinsDeps(ctx android.BottomUpMutatorContext) {
944 if len(j.testHostProperties.Data_device_bins_first) > 0 {
945 deviceVariations := ctx.Config().AndroidFirstDeviceTarget.Variations()
946 ctx.AddFarVariationDependencies(deviceVariations, dataDeviceBinsTag, j.testHostProperties.Data_device_bins_first...)
947 }
948
949 var maybeAndroid32Target *android.Target
950 var maybeAndroid64Target *android.Target
951 android32TargetList := android.FirstTarget(ctx.Config().Targets[android.Android], "lib32")
952 android64TargetList := android.FirstTarget(ctx.Config().Targets[android.Android], "lib64")
953 if len(android32TargetList) > 0 {
954 maybeAndroid32Target = &android32TargetList[0]
955 }
956 if len(android64TargetList) > 0 {
957 maybeAndroid64Target = &android64TargetList[0]
958 }
959
960 if len(j.testHostProperties.Data_device_bins_both) > 0 {
961 if maybeAndroid32Target == nil && maybeAndroid64Target == nil {
962 ctx.PropertyErrorf("data_device_bins_both", "no device targets available. Targets: %q", ctx.Config().Targets)
963 return
964 }
965 if maybeAndroid32Target != nil {
966 ctx.AddFarVariationDependencies(
967 maybeAndroid32Target.Variations(),
968 dataDeviceBinsTag,
969 j.testHostProperties.Data_device_bins_both...,
970 )
971 }
972 if maybeAndroid64Target != nil {
973 ctx.AddFarVariationDependencies(
974 maybeAndroid64Target.Variations(),
975 dataDeviceBinsTag,
976 j.testHostProperties.Data_device_bins_both...,
977 )
978 }
979 }
980
981 if len(j.testHostProperties.Data_device_bins_prefer32) > 0 {
982 if maybeAndroid32Target != nil {
983 ctx.AddFarVariationDependencies(
984 maybeAndroid32Target.Variations(),
985 dataDeviceBinsTag,
986 j.testHostProperties.Data_device_bins_prefer32...,
987 )
988 } else {
989 if maybeAndroid64Target == nil {
990 ctx.PropertyErrorf("data_device_bins_prefer32", "no device targets available. Targets: %q", ctx.Config().Targets)
991 return
992 }
993 ctx.AddFarVariationDependencies(
994 maybeAndroid64Target.Variations(),
995 dataDeviceBinsTag,
996 j.testHostProperties.Data_device_bins_prefer32...,
997 )
998 }
999 }
1000
1001 if len(j.testHostProperties.Data_device_bins_32) > 0 {
1002 if maybeAndroid32Target == nil {
1003 ctx.PropertyErrorf("data_device_bins_32", "cannot find 32bit device target. Targets: %q", ctx.Config().Targets)
1004 return
1005 }
1006 deviceVariations := maybeAndroid32Target.Variations()
1007 ctx.AddFarVariationDependencies(deviceVariations, dataDeviceBinsTag, j.testHostProperties.Data_device_bins_32...)
1008 }
1009
1010 if len(j.testHostProperties.Data_device_bins_64) > 0 {
1011 if maybeAndroid64Target == nil {
1012 ctx.PropertyErrorf("data_device_bins_64", "cannot find 64bit device target. Targets: %q", ctx.Config().Targets)
1013 return
1014 }
1015 deviceVariations := maybeAndroid64Target.Variations()
1016 ctx.AddFarVariationDependencies(deviceVariations, dataDeviceBinsTag, j.testHostProperties.Data_device_bins_64...)
1017 }
1018}
1019
Liz Kammerdd849a82020-06-12 16:38:45 -07001020func (j *TestHost) DepsMutator(ctx android.BottomUpMutatorContext) {
1021 if len(j.testHostProperties.Data_native_bins) > 0 {
1022 for _, target := range ctx.MultiTargets() {
1023 ctx.AddVariationDependencies(target.Variations(), dataNativeBinsTag, j.testHostProperties.Data_native_bins...)
1024 }
1025 }
1026
Colin Crossf8d9c492021-01-26 11:01:43 -08001027 if len(j.testProperties.Jni_libs) > 0 {
1028 for _, target := range ctx.MultiTargets() {
1029 sharedLibVariations := append(target.Variations(), blueprint.Variation{Mutator: "link", Variation: "shared"})
1030 ctx.AddFarVariationDependencies(sharedLibVariations, jniLibTag, j.testProperties.Jni_libs...)
1031 }
1032 }
1033
Sam Delmericob706b4e2022-06-01 15:45:02 +00001034 j.addDataDeviceBinsDeps(ctx)
1035
Liz Kammerdd849a82020-06-12 16:38:45 -07001036 j.deps(ctx)
1037}
1038
Yuexi Ma627263f2021-03-04 13:47:56 -08001039func (j *TestHost) AddExtraResource(p android.Path) {
1040 j.extraResources = append(j.extraResources, p)
1041}
1042
Sam Delmericob706b4e2022-06-01 15:45:02 +00001043func (j *TestHost) dataDeviceBins() []string {
1044 ret := make([]string, 0,
1045 len(j.testHostProperties.Data_device_bins_first)+
1046 len(j.testHostProperties.Data_device_bins_both)+
1047 len(j.testHostProperties.Data_device_bins_prefer32)+
1048 len(j.testHostProperties.Data_device_bins_32)+
1049 len(j.testHostProperties.Data_device_bins_64),
1050 )
1051
1052 ret = append(ret, j.testHostProperties.Data_device_bins_first...)
1053 ret = append(ret, j.testHostProperties.Data_device_bins_both...)
1054 ret = append(ret, j.testHostProperties.Data_device_bins_prefer32...)
1055 ret = append(ret, j.testHostProperties.Data_device_bins_32...)
1056 ret = append(ret, j.testHostProperties.Data_device_bins_64...)
1057
1058 return ret
1059}
1060
Sam Delmericob3342ce2022-01-20 21:10:28 +00001061func (j *TestHost) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1062 var configs []tradefed.Config
Sam Delmericob706b4e2022-06-01 15:45:02 +00001063 dataDeviceBins := j.dataDeviceBins()
1064 if len(dataDeviceBins) > 0 {
Sam Delmericob3342ce2022-01-20 21:10:28 +00001065 // add Tradefed configuration to push device bins to device for testing
1066 remoteDir := filepath.Join("/data/local/tests/unrestricted/", j.Name())
1067 options := []tradefed.Option{{Name: "cleanup", Value: "true"}}
Sam Delmericob706b4e2022-06-01 15:45:02 +00001068 for _, bin := range dataDeviceBins {
Sam Delmericob3342ce2022-01-20 21:10:28 +00001069 fullPath := filepath.Join(remoteDir, bin)
1070 options = append(options, tradefed.Option{Name: "push-file", Key: bin, Value: fullPath})
1071 }
Sam Delmericob706b4e2022-06-01 15:45:02 +00001072 configs = append(configs, tradefed.Object{
1073 Type: "target_preparer",
1074 Class: "com.android.tradefed.targetprep.PushFilePreparer",
1075 Options: options,
1076 })
Sam Delmericob3342ce2022-01-20 21:10:28 +00001077 }
1078
1079 j.Test.generateAndroidBuildActionsWithConfig(ctx, configs)
1080}
1081
Colin Cross303e21f2018-08-07 16:49:25 -07001082func (j *Test) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Sam Delmericob3342ce2022-01-20 21:10:28 +00001083 j.generateAndroidBuildActionsWithConfig(ctx, nil)
1084}
1085
1086func (j *Test) generateAndroidBuildActionsWithConfig(ctx android.ModuleContext, configs []tradefed.Config) {
Julien Desprezb2166612021-03-05 18:08:36 +00001087 if j.testProperties.Test_options.Unit_test == nil && ctx.Host() {
1088 // TODO(b/): Clean temporary heuristic to avoid unexpected onboarding.
Julien Desprezf666b152021-03-15 13:07:53 -07001089 defaultUnitTest := !inList("tradefed", j.properties.Libs) && !inList("cts", j.testProperties.Test_suites)
Julien Desprezb2166612021-03-05 18:08:36 +00001090 j.testProperties.Test_options.Unit_test = proptools.BoolPtr(defaultUnitTest)
1091 }
Sam Delmericob3342ce2022-01-20 21:10:28 +00001092
Dan Shi6ffaaa82019-09-26 11:41:36 -07001093 j.testConfig = tradefed.AutoGenJavaTestConfig(ctx, j.testProperties.Test_config, j.testProperties.Test_config_template,
Sam Delmericob3342ce2022-01-20 21:10:28 +00001094 j.testProperties.Test_suites, configs, j.testProperties.Auto_gen_config, j.testProperties.Test_options.Unit_test)
Liz Kammerdd849a82020-06-12 16:38:45 -07001095
Colin Cross8a497952019-03-05 22:25:09 -08001096 j.data = android.PathsForModuleSrc(ctx, j.testProperties.Data)
Colin Cross303e21f2018-08-07 16:49:25 -07001097
Dan Shi95d19422020-08-15 12:24:26 -07001098 j.extraTestConfigs = android.PathsForModuleSrc(ctx, j.testProperties.Test_options.Extra_test_configs)
1099
Liz Kammerdd849a82020-06-12 16:38:45 -07001100 ctx.VisitDirectDepsWithTag(dataNativeBinsTag, func(dep android.Module) {
1101 j.data = append(j.data, android.OutputFileForModule(ctx, dep, ""))
1102 })
1103
Sam Delmericob3342ce2022-01-20 21:10:28 +00001104 ctx.VisitDirectDepsWithTag(dataDeviceBinsTag, func(dep android.Module) {
1105 j.data = append(j.data, android.OutputFileForModule(ctx, dep, ""))
1106 })
1107
Colin Crossf8d9c492021-01-26 11:01:43 -08001108 ctx.VisitDirectDepsWithTag(jniLibTag, func(dep android.Module) {
1109 sharedLibInfo := ctx.OtherModuleProvider(dep, cc.SharedLibraryInfoProvider).(cc.SharedLibraryInfo)
1110 if sharedLibInfo.SharedLibrary != nil {
1111 // Copy to an intermediate output directory to append "lib[64]" to the path,
1112 // so that it's compatible with the default rpath values.
1113 var relPath string
1114 if sharedLibInfo.Target.Arch.ArchType.Multilib == "lib64" {
1115 relPath = filepath.Join("lib64", sharedLibInfo.SharedLibrary.Base())
1116 } else {
1117 relPath = filepath.Join("lib", sharedLibInfo.SharedLibrary.Base())
1118 }
1119 relocatedLib := android.PathForModuleOut(ctx, "relocated").Join(ctx, relPath)
1120 ctx.Build(pctx, android.BuildParams{
1121 Rule: android.Cp,
1122 Input: sharedLibInfo.SharedLibrary,
1123 Output: relocatedLib,
1124 })
1125 j.data = append(j.data, relocatedLib)
1126 } else {
1127 ctx.PropertyErrorf("jni_libs", "%q of type %q is not supported", dep.Name(), ctx.OtherModuleType(dep))
1128 }
1129 })
1130
Colin Cross303e21f2018-08-07 16:49:25 -07001131 j.Library.GenerateAndroidBuildActions(ctx)
Colin Cross05638fc2018-04-09 18:40:24 -07001132}
1133
Paul Duffin42df1442019-03-20 12:45:53 +00001134func (j *TestHelperLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1135 j.Library.GenerateAndroidBuildActions(ctx)
1136}
1137
Paul Duffin1b82e6a2019-12-03 18:06:47 +00001138func (j *JavaTestImport) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1139 j.testConfig = tradefed.AutoGenJavaTestConfig(ctx, j.prebuiltTestProperties.Test_config, nil,
Sam Delmericob3342ce2022-01-20 21:10:28 +00001140 j.prebuiltTestProperties.Test_suites, nil, nil, nil)
Paul Duffin1b82e6a2019-12-03 18:06:47 +00001141
1142 j.Import.GenerateAndroidBuildActions(ctx)
1143}
1144
1145type testSdkMemberType struct {
1146 android.SdkMemberTypeBase
1147}
1148
Paul Duffin296701e2021-07-14 10:29:36 +01001149func (mt *testSdkMemberType) AddDependencies(ctx android.SdkDependencyContext, dependencyTag blueprint.DependencyTag, names []string) {
1150 ctx.AddVariationDependencies(nil, dependencyTag, names...)
Paul Duffin1b82e6a2019-12-03 18:06:47 +00001151}
1152
1153func (mt *testSdkMemberType) IsInstance(module android.Module) bool {
1154 _, ok := module.(*Test)
1155 return ok
1156}
1157
Paul Duffin3a4eb502020-03-19 16:11:18 +00001158func (mt *testSdkMemberType) AddPrebuiltModule(ctx android.SdkMemberContext, member android.SdkMember) android.BpModule {
1159 return ctx.SnapshotBuilder().AddPrebuiltModule(member, "java_test_import")
Paul Duffin14eb4672020-03-02 11:33:02 +00001160}
Paul Duffin1b82e6a2019-12-03 18:06:47 +00001161
Paul Duffin14eb4672020-03-02 11:33:02 +00001162func (mt *testSdkMemberType) CreateVariantPropertiesStruct() android.SdkMemberProperties {
1163 return &testSdkMemberProperties{}
1164}
1165
1166type testSdkMemberProperties struct {
1167 android.SdkMemberPropertiesBase
1168
Paul Duffina551a1c2020-03-17 21:04:24 +00001169 JarToExport android.Path
1170 TestConfig android.Path
Paul Duffin14eb4672020-03-02 11:33:02 +00001171}
1172
Paul Duffin3a4eb502020-03-19 16:11:18 +00001173func (p *testSdkMemberProperties) PopulateFromVariant(ctx android.SdkMemberContext, variant android.Module) {
Paul Duffin14eb4672020-03-02 11:33:02 +00001174 test := variant.(*Test)
1175
1176 implementationJars := test.ImplementationJars()
Paul Duffin1b82e6a2019-12-03 18:06:47 +00001177 if len(implementationJars) != 1 {
Paul Duffin14eb4672020-03-02 11:33:02 +00001178 panic(fmt.Errorf("there must be only one implementation jar from %q", test.Name()))
Paul Duffin1b82e6a2019-12-03 18:06:47 +00001179 }
1180
Paul Duffina551a1c2020-03-17 21:04:24 +00001181 p.JarToExport = implementationJars[0]
1182 p.TestConfig = test.testConfig
Paul Duffin14eb4672020-03-02 11:33:02 +00001183}
Paul Duffin1b82e6a2019-12-03 18:06:47 +00001184
Paul Duffin3a4eb502020-03-19 16:11:18 +00001185func (p *testSdkMemberProperties) AddToPropertySet(ctx android.SdkMemberContext, propertySet android.BpPropertySet) {
Paul Duffina551a1c2020-03-17 21:04:24 +00001186 builder := ctx.SnapshotBuilder()
Paul Duffin3a4eb502020-03-19 16:11:18 +00001187
Paul Duffina551a1c2020-03-17 21:04:24 +00001188 exportedJar := p.JarToExport
1189 if exportedJar != nil {
1190 snapshotRelativeJavaLibPath := sdkSnapshotFilePathForJar(p.OsPrefix(), ctx.Name())
1191 builder.CopyToSnapshot(exportedJar, snapshotRelativeJavaLibPath)
Paul Duffin14eb4672020-03-02 11:33:02 +00001192
1193 propertySet.AddProperty("jars", []string{snapshotRelativeJavaLibPath})
Paul Duffina551a1c2020-03-17 21:04:24 +00001194 }
1195
1196 testConfig := p.TestConfig
1197 if testConfig != nil {
1198 snapshotRelativeTestConfigPath := sdkSnapshotFilePathForMember(p.OsPrefix(), ctx.Name(), testConfigSuffix)
1199 builder.CopyToSnapshot(testConfig, snapshotRelativeTestConfigPath)
Paul Duffin14eb4672020-03-02 11:33:02 +00001200 propertySet.AddProperty("test_config", snapshotRelativeTestConfigPath)
1201 }
Paul Duffin1b82e6a2019-12-03 18:06:47 +00001202}
1203
Colin Cross1b16b0e2019-02-12 14:41:32 -08001204// java_test builds a and links sources into a `.jar` file for the device, and possibly for the host as well, and
1205// creates an `AndroidTest.xml` file to allow running the test with `atest` or a `TEST_MAPPING` file.
1206//
1207// By default, a java_test has a single variant that produces a `.jar` file containing `classes.dex` files that were
1208// compiled against the device bootclasspath.
1209//
1210// Specifying `host_supported: true` will produce two variants, one compiled against the device bootclasspath and one
1211// compiled against the host bootclasspath.
Colin Cross05638fc2018-04-09 18:40:24 -07001212func TestFactory() android.Module {
1213 module := &Test{}
1214
Colin Crossce6734e2020-06-15 16:09:53 -07001215 module.addHostAndDeviceProperties()
1216 module.AddProperties(&module.testProperties)
Colin Cross05638fc2018-04-09 18:40:24 -07001217
Colin Cross9ae1b922018-06-26 17:59:05 -07001218 module.Module.properties.Installable = proptools.BoolPtr(true)
Colin Crosse3026872019-01-05 22:30:13 -08001219 module.Module.dexpreopter.isTest = true
Colin Cross014489c2020-06-02 20:09:13 -07001220 module.Module.linter.test = true
Colin Cross9ae1b922018-06-26 17:59:05 -07001221
Paul Duffinb6b89a42021-05-06 16:33:43 +01001222 android.InitSdkAwareModule(module)
Colin Cross05638fc2018-04-09 18:40:24 -07001223 InitJavaModule(module, android.HostAndDeviceSupported)
Colin Cross05638fc2018-04-09 18:40:24 -07001224 return module
1225}
1226
Paul Duffin42df1442019-03-20 12:45:53 +00001227// java_test_helper_library creates a java library and makes sure that it is added to the appropriate test suite.
1228func TestHelperLibraryFactory() android.Module {
1229 module := &TestHelperLibrary{}
1230
Colin Crossce6734e2020-06-15 16:09:53 -07001231 module.addHostAndDeviceProperties()
1232 module.AddProperties(&module.testHelperLibraryProperties)
Paul Duffin42df1442019-03-20 12:45:53 +00001233
Colin Cross9a4abed2019-04-24 13:19:28 -07001234 module.Module.properties.Installable = proptools.BoolPtr(true)
1235 module.Module.dexpreopter.isTest = true
Colin Cross014489c2020-06-02 20:09:13 -07001236 module.Module.linter.test = true
Colin Cross9a4abed2019-04-24 13:19:28 -07001237
Paul Duffin42df1442019-03-20 12:45:53 +00001238 InitJavaModule(module, android.HostAndDeviceSupported)
1239 return module
1240}
1241
Paul Duffin1b82e6a2019-12-03 18:06:47 +00001242// java_test_import imports one or more `.jar` files into the build graph as if they were built by a java_test module
1243// and makes sure that it is added to the appropriate test suite.
1244//
1245// By default, a java_test_import has a single variant that expects a `.jar` file containing `.class` files that were
1246// compiled against an Android classpath.
1247//
1248// Specifying `host_supported: true` will produce two variants, one for use as a dependency of device modules and one
1249// for host modules.
1250func JavaTestImportFactory() android.Module {
1251 module := &JavaTestImport{}
1252
1253 module.AddProperties(
1254 &module.Import.properties,
1255 &module.prebuiltTestProperties)
1256
1257 module.Import.properties.Installable = proptools.BoolPtr(true)
1258
1259 android.InitPrebuiltModule(module, &module.properties.Jars)
1260 android.InitApexModule(module)
1261 android.InitSdkAwareModule(module)
1262 InitJavaModule(module, android.HostAndDeviceSupported)
1263 return module
1264}
1265
Colin Cross1b16b0e2019-02-12 14:41:32 -08001266// java_test_host builds a and links sources into a `.jar` file for the host, and creates an `AndroidTest.xml` file to
1267// allow running the test with `atest` or a `TEST_MAPPING` file.
1268//
1269// A java_test_host has a single variant that produces a `.jar` file containing `.class` files that were
1270// compiled against the host bootclasspath.
Colin Cross05638fc2018-04-09 18:40:24 -07001271func TestHostFactory() android.Module {
Liz Kammerdd849a82020-06-12 16:38:45 -07001272 module := &TestHost{}
Colin Cross05638fc2018-04-09 18:40:24 -07001273
Colin Crossce6734e2020-06-15 16:09:53 -07001274 module.addHostProperties()
1275 module.AddProperties(&module.testProperties)
Liz Kammerdd849a82020-06-12 16:38:45 -07001276 module.AddProperties(&module.testHostProperties)
Colin Cross05638fc2018-04-09 18:40:24 -07001277
Yuexi Ma627263f2021-03-04 13:47:56 -08001278 InitTestHost(
1279 module,
1280 proptools.BoolPtr(true),
1281 nil,
1282 nil)
Colin Cross9ae1b922018-06-26 17:59:05 -07001283
Liz Kammerdd849a82020-06-12 16:38:45 -07001284 InitJavaModuleMultiTargets(module, android.HostSupported)
Julien Desprezb2166612021-03-05 18:08:36 +00001285
Colin Cross05638fc2018-04-09 18:40:24 -07001286 return module
1287}
1288
Yuexi Ma627263f2021-03-04 13:47:56 -08001289func InitTestHost(th *TestHost, installable *bool, testSuites []string, autoGenConfig *bool) {
1290 th.properties.Installable = installable
1291 th.testProperties.Auto_gen_config = autoGenConfig
1292 th.testProperties.Test_suites = testSuites
1293}
1294
Colin Cross05638fc2018-04-09 18:40:24 -07001295//
Colin Cross2fe66872015-03-30 17:20:39 -07001296// Java Binaries (.jar file plus wrapper script)
1297//
1298
Colin Crossf506d872017-07-19 15:53:04 -07001299type binaryProperties struct {
Colin Cross7d5136f2015-05-11 13:39:40 -07001300 // installable script to execute the resulting jar
Dan Willemsen8e6b3712021-09-20 23:11:24 -07001301 Wrapper *string `android:"path,arch_variant"`
Colin Cross094054a2018-10-17 15:10:48 -07001302
1303 // Name of the class containing main to be inserted into the manifest as Main-Class.
1304 Main_class *string
Colin Cross89226d92020-10-09 19:00:54 -07001305
1306 // Names of modules containing JNI libraries that should be installed alongside the host
1307 // variant of the binary.
Dan Willemsen8e6b3712021-09-20 23:11:24 -07001308 Jni_libs []string `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -07001309}
1310
Colin Crossf506d872017-07-19 15:53:04 -07001311type Binary struct {
1312 Library
Colin Cross2fe66872015-03-30 17:20:39 -07001313
Colin Crossf506d872017-07-19 15:53:04 -07001314 binaryProperties binaryProperties
Colin Cross10a03492017-08-10 17:09:43 -07001315
Colin Cross6b4a32d2017-12-05 13:42:45 -08001316 isWrapperVariant bool
1317
Colin Crossc3315992017-12-08 19:12:36 -08001318 wrapperFile android.Path
Colin Cross70dda7e2019-10-01 22:05:35 -07001319 binaryFile android.InstallPath
Colin Cross2fe66872015-03-30 17:20:39 -07001320}
1321
Alex Light24237172017-10-26 09:46:21 -07001322func (j *Binary) HostToolPath() android.OptionalPath {
1323 return android.OptionalPathForPath(j.binaryFile)
1324}
1325
Colin Crossf506d872017-07-19 15:53:04 -07001326func (j *Binary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross6b4a32d2017-12-05 13:42:45 -08001327 if ctx.Arch().ArchType == android.Common {
1328 // Compile the jar
Colin Cross094054a2018-10-17 15:10:48 -07001329 if j.binaryProperties.Main_class != nil {
1330 if j.properties.Manifest != nil {
1331 ctx.PropertyErrorf("main_class", "main_class cannot be used when manifest is set")
1332 }
1333 manifestFile := android.PathForModuleOut(ctx, "manifest.txt")
1334 GenerateMainClassManifest(ctx, manifestFile, String(j.binaryProperties.Main_class))
1335 j.overrideManifest = android.OptionalPathForPath(manifestFile)
1336 }
1337
Colin Cross6b4a32d2017-12-05 13:42:45 -08001338 j.Library.GenerateAndroidBuildActions(ctx)
Nan Zhang3c807db2017-11-03 14:53:31 -07001339 } else {
Colin Cross6b4a32d2017-12-05 13:42:45 -08001340 // Handle the binary wrapper
1341 j.isWrapperVariant = true
1342
Colin Cross366938f2017-12-11 16:29:02 -08001343 if j.binaryProperties.Wrapper != nil {
Colin Cross8a497952019-03-05 22:25:09 -08001344 j.wrapperFile = android.PathForModuleSrc(ctx, *j.binaryProperties.Wrapper)
Colin Cross6b4a32d2017-12-05 13:42:45 -08001345 } else {
Dan Willemsen8e6b3712021-09-20 23:11:24 -07001346 if ctx.Windows() {
1347 ctx.PropertyErrorf("wrapper", "wrapper is required for Windows")
1348 }
1349
Colin Cross6b4a32d2017-12-05 13:42:45 -08001350 j.wrapperFile = android.PathForSource(ctx, "build/soong/scripts/jar-wrapper.sh")
1351 }
1352
Dan Willemsen8e6b3712021-09-20 23:11:24 -07001353 ext := ""
1354 if ctx.Windows() {
1355 ext = ".bat"
1356 }
1357
Colin Crossc179ea62020-10-09 10:54:15 -07001358 // The host installation rules make the installed wrapper depend on all the dependencies
Colin Cross89226d92020-10-09 19:00:54 -07001359 // of the wrapper variant, which will include the common variant's jar file and any JNI
1360 // libraries. This is verified by TestBinary.
Colin Cross6b4a32d2017-12-05 13:42:45 -08001361 j.binaryFile = ctx.InstallExecutable(android.PathForModuleInstall(ctx, "bin"),
Dan Willemsen8e6b3712021-09-20 23:11:24 -07001362 ctx.ModuleName()+ext, j.wrapperFile)
1363 }
Colin Cross2fe66872015-03-30 17:20:39 -07001364}
1365
Colin Crossf506d872017-07-19 15:53:04 -07001366func (j *Binary) DepsMutator(ctx android.BottomUpMutatorContext) {
Liz Kammer356f7d42021-01-26 09:18:53 -05001367 if ctx.Arch().ArchType == android.Common || ctx.BazelConversionMode() {
Colin Cross6b4a32d2017-12-05 13:42:45 -08001368 j.deps(ctx)
Liz Kammer356f7d42021-01-26 09:18:53 -05001369 }
1370 if ctx.Arch().ArchType != android.Common || ctx.BazelConversionMode() {
Colin Crosse9fe2942020-11-10 18:12:15 -08001371 // These dependencies ensure the host installation rules will install the jar file and
1372 // the jni libraries when the wrapper is installed.
1373 ctx.AddVariationDependencies(nil, jniInstallTag, j.binaryProperties.Jni_libs...)
1374 ctx.AddVariationDependencies(
1375 []blueprint.Variation{{Mutator: "arch", Variation: android.CommonArch.String()}},
1376 binaryInstallTag, ctx.ModuleName())
Colin Cross6b4a32d2017-12-05 13:42:45 -08001377 }
Colin Cross46c9b8b2017-06-22 16:51:17 -07001378}
1379
Colin Cross1b16b0e2019-02-12 14:41:32 -08001380// java_binary builds a `.jar` file and a shell script that executes it for the device, and possibly for the host
1381// as well.
1382//
1383// By default, a java_binary has a single variant that produces a `.jar` file containing `classes.dex` files that were
1384// compiled against the device bootclasspath.
1385//
1386// Specifying `host_supported: true` will produce two variants, one compiled against the device bootclasspath and one
1387// compiled against the host bootclasspath.
Colin Crossf506d872017-07-19 15:53:04 -07001388func BinaryFactory() android.Module {
1389 module := &Binary{}
Colin Cross2fe66872015-03-30 17:20:39 -07001390
Colin Crossce6734e2020-06-15 16:09:53 -07001391 module.addHostAndDeviceProperties()
1392 module.AddProperties(&module.binaryProperties)
Colin Cross36242852017-06-23 15:06:31 -07001393
Colin Cross9ae1b922018-06-26 17:59:05 -07001394 module.Module.properties.Installable = proptools.BoolPtr(true)
1395
Colin Cross6b4a32d2017-12-05 13:42:45 -08001396 android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibCommonFirst)
1397 android.InitDefaultableModule(module)
Wei Libafb6d62021-12-10 03:14:59 -08001398 android.InitBazelModule(module)
1399
Colin Cross36242852017-06-23 15:06:31 -07001400 return module
Colin Cross2fe66872015-03-30 17:20:39 -07001401}
1402
Colin Cross1b16b0e2019-02-12 14:41:32 -08001403// java_binary_host builds a `.jar` file and a shell script that executes it for the host.
1404//
1405// A java_binary_host has a single variant that produces a `.jar` file containing `.class` files that were
1406// compiled against the host bootclasspath.
Colin Crossf506d872017-07-19 15:53:04 -07001407func BinaryHostFactory() android.Module {
1408 module := &Binary{}
Colin Cross2fe66872015-03-30 17:20:39 -07001409
Colin Crossce6734e2020-06-15 16:09:53 -07001410 module.addHostProperties()
1411 module.AddProperties(&module.binaryProperties)
Colin Cross36242852017-06-23 15:06:31 -07001412
Colin Cross9ae1b922018-06-26 17:59:05 -07001413 module.Module.properties.Installable = proptools.BoolPtr(true)
1414
Colin Cross6b4a32d2017-12-05 13:42:45 -08001415 android.InitAndroidArchModule(module, android.HostSupported, android.MultilibCommonFirst)
1416 android.InitDefaultableModule(module)
Wei Libafb6d62021-12-10 03:14:59 -08001417 android.InitBazelModule(module)
Colin Cross36242852017-06-23 15:06:31 -07001418 return module
Colin Cross2fe66872015-03-30 17:20:39 -07001419}
1420
1421//
1422// Java prebuilts
1423//
1424
Colin Cross74d73e22017-08-02 11:05:49 -07001425type ImportProperties struct {
Paul Duffina04c1072020-03-02 10:16:35 +00001426 Jars []string `android:"path,arch_variant"`
Colin Cross461bd1a2017-10-20 13:59:18 -07001427
Jaewoong Jung56e12db2021-04-02 00:38:25 +00001428 // The version of the SDK that the source prebuilt file was built against. Defaults to the
1429 // current version if not specified.
Nan Zhangea568a42017-11-08 21:20:04 -08001430 Sdk_version *string
Colin Cross535e2cf2017-10-20 17:57:49 -07001431
Jaewoong Jung56e12db2021-04-02 00:38:25 +00001432 // The minimum version of the SDK that this module supports. Defaults to sdk_version if not
1433 // specified.
1434 Min_sdk_version *string
1435
Colin Cross535e2cf2017-10-20 17:57:49 -07001436 Installable *bool
Jiyong Park1be96912018-05-28 18:02:19 +09001437
Paul Duffin869de142021-07-15 14:14:41 +01001438 // If not empty, classes are restricted to the specified packages and their sub-packages.
Paul Duffin869de142021-07-15 14:14:41 +01001439 Permitted_packages []string
1440
Jiyong Park1be96912018-05-28 18:02:19 +09001441 // List of shared java libs that this module has dependencies to
1442 Libs []string
Colin Cross37f6d792018-07-12 12:28:41 -07001443
1444 // List of files to remove from the jar file(s)
1445 Exclude_files []string
1446
1447 // List of directories to remove from the jar file(s)
1448 Exclude_dirs []string
Nan Zhang4c819fb2018-08-27 18:31:46 -07001449
1450 // if set to true, run Jetifier against .jar file. Defaults to false.
Colin Cross1001a792019-03-21 22:21:39 -07001451 Jetifier *bool
Jiyong Park4c4c0242019-10-21 14:53:15 +09001452
1453 // set the name of the output
1454 Stem *string
Jiyong Park19604de2020-03-24 16:44:11 +09001455
1456 Aidl struct {
1457 // directories that should be added as include directories for any aidl sources of modules
1458 // that depend on this module, as well as to aidl for this module.
1459 Export_include_dirs []string
1460 }
Colin Cross74d73e22017-08-02 11:05:49 -07001461}
1462
1463type Import struct {
Colin Cross635c3b02016-05-18 15:37:25 -07001464 android.ModuleBase
Colin Cross48de9a42018-10-02 13:53:33 -07001465 android.DefaultableModuleBase
Jiyong Park7f7766d2019-07-25 22:02:35 +09001466 android.ApexModuleBase
Romain Jobredeaux428a3662022-01-28 11:12:52 -05001467 android.BazelModuleBase
Colin Crossec7a0422017-07-07 14:47:12 -07001468 prebuilt android.Prebuilt
Jiyong Parkd1063c12019-07-17 20:08:41 +09001469 android.SdkBase
Colin Cross2fe66872015-03-30 17:20:39 -07001470
Paul Duffin0d3c2e12020-05-17 08:34:50 +01001471 // Functionality common to Module and Import.
1472 embeddableInModuleAndImport
1473
Liz Kammerd6c31d22020-08-05 15:40:41 -07001474 hiddenAPI
1475 dexer
Bill Peckhamff89ffa2020-12-23 16:13:04 -08001476 dexpreopter
Liz Kammerd6c31d22020-08-05 15:40:41 -07001477
Colin Cross74d73e22017-08-02 11:05:49 -07001478 properties ImportProperties
1479
Liz Kammerd6c31d22020-08-05 15:40:41 -07001480 // output file containing classes.dex and resources
Martin Stjernholm8be1e6d2021-09-15 03:34:04 +01001481 dexJarFile OptionalDexJarPath
Jeongik Chad5fe8782021-07-08 01:13:11 +09001482 dexJarInstallFile android.Path
Liz Kammerd6c31d22020-08-05 15:40:41 -07001483
Colin Cross0a6e0072017-08-30 14:24:55 -07001484 combinedClasspathFile android.Path
Ulya Trafimovichb23d28c2020-10-08 12:53:58 +01001485 classLoaderContexts dexpreopt.ClassLoaderContextMap
Jiyong Park19604de2020-03-24 16:44:11 +09001486 exportAidlIncludeDirs android.Paths
Colin Cross56a83212020-09-15 18:30:11 -07001487
1488 hideApexVariantFromMake bool
Jiyong Park92315372021-04-02 08:45:46 +09001489
1490 sdkVersion android.SdkSpec
1491 minSdkVersion android.SdkSpec
Colin Cross2fe66872015-03-30 17:20:39 -07001492}
1493
Paul Duffin630b11e2021-07-15 13:35:26 +01001494var _ PermittedPackagesForUpdatableBootJars = (*Import)(nil)
1495
1496func (j *Import) PermittedPackagesForUpdatableBootJars() []string {
1497 return j.properties.Permitted_packages
1498}
1499
Jiyong Park92315372021-04-02 08:45:46 +09001500func (j *Import) SdkVersion(ctx android.EarlyModuleContext) android.SdkSpec {
1501 return android.SdkSpecFrom(ctx, String(j.properties.Sdk_version))
Liz Kammer2d2fd852020-08-12 14:42:30 -07001502}
1503
Jiyong Parkf1691d22021-03-29 20:11:58 +09001504func (j *Import) SystemModules() string {
Liz Kammerd6c31d22020-08-05 15:40:41 -07001505 return "none"
1506}
1507
Jiyong Park92315372021-04-02 08:45:46 +09001508func (j *Import) MinSdkVersion(ctx android.EarlyModuleContext) android.SdkSpec {
Jaewoong Jung56e12db2021-04-02 00:38:25 +00001509 if j.properties.Min_sdk_version != nil {
Jiyong Park92315372021-04-02 08:45:46 +09001510 return android.SdkSpecFrom(ctx, *j.properties.Min_sdk_version)
Jaewoong Jung56e12db2021-04-02 00:38:25 +00001511 }
Jiyong Park92315372021-04-02 08:45:46 +09001512 return j.SdkVersion(ctx)
Colin Cross83bb3162018-06-25 15:48:06 -07001513}
1514
Jiyong Park92315372021-04-02 08:45:46 +09001515func (j *Import) TargetSdkVersion(ctx android.EarlyModuleContext) android.SdkSpec {
1516 return j.SdkVersion(ctx)
Artur Satayev480e25b2020-04-27 18:53:18 +01001517}
1518
Colin Cross74d73e22017-08-02 11:05:49 -07001519func (j *Import) Prebuilt() *android.Prebuilt {
Colin Crossec7a0422017-07-07 14:47:12 -07001520 return &j.prebuilt
1521}
1522
Colin Cross74d73e22017-08-02 11:05:49 -07001523func (j *Import) PrebuiltSrcs() []string {
1524 return j.properties.Jars
1525}
1526
1527func (j *Import) Name() string {
Colin Cross5ea9bcc2017-07-27 15:41:32 -07001528 return j.prebuilt.Name(j.ModuleBase.Name())
1529}
1530
Jiyong Park0b238752019-10-29 11:23:10 +09001531func (j *Import) Stem() string {
1532 return proptools.StringDefault(j.properties.Stem, j.ModuleBase.Name())
1533}
1534
Jiyong Park618922e2020-01-08 13:35:43 +09001535func (a *Import) JacocoReportClassesFile() android.Path {
1536 return nil
1537}
1538
Bill Peckhama41a6962021-01-11 10:58:54 -08001539func (j *Import) LintDepSets() LintDepSets {
1540 return LintDepSets{}
1541}
1542
Jaewoong Jung476b9d62021-05-10 15:30:00 -07001543func (j *Import) getStrictUpdatabilityLinting() bool {
1544 return false
1545}
1546
1547func (j *Import) setStrictUpdatabilityLinting(bool) {
1548}
1549
Colin Cross74d73e22017-08-02 11:05:49 -07001550func (j *Import) DepsMutator(ctx android.BottomUpMutatorContext) {
Colin Cross42d48b72018-08-29 14:10:52 -07001551 ctx.AddVariationDependencies(nil, libTag, j.properties.Libs...)
Liz Kammerd6c31d22020-08-05 15:40:41 -07001552
1553 if ctx.Device() && Bool(j.dexProperties.Compile_dex) {
Jiyong Parkf1691d22021-03-29 20:11:58 +09001554 sdkDeps(ctx, android.SdkContext(j), j.dexer)
Liz Kammerd6c31d22020-08-05 15:40:41 -07001555 }
Colin Cross1e676be2016-10-12 14:38:15 -07001556}
1557
Colin Cross74d73e22017-08-02 11:05:49 -07001558func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Jiyong Park92315372021-04-02 08:45:46 +09001559 j.sdkVersion = j.SdkVersion(ctx)
1560 j.minSdkVersion = j.MinSdkVersion(ctx)
1561
Colin Cross56a83212020-09-15 18:30:11 -07001562 if !ctx.Provider(android.ApexInfoProvider).(android.ApexInfo).IsForPlatform() {
1563 j.hideApexVariantFromMake = true
1564 }
1565
Dan Willemsen8e6b3712021-09-20 23:11:24 -07001566 if ctx.Windows() {
1567 j.HideFromMake()
1568 }
1569
Colin Cross8a497952019-03-05 22:25:09 -08001570 jars := android.PathsForModuleSrc(ctx, j.properties.Jars)
Colin Crosse1d62a82015-04-03 16:53:05 -07001571
Jiyong Park0b238752019-10-29 11:23:10 +09001572 jarName := j.Stem() + ".jar"
Nan Zhang4c819fb2018-08-27 18:31:46 -07001573 outputFile := android.PathForModuleOut(ctx, "combined", jarName)
Colin Cross37f6d792018-07-12 12:28:41 -07001574 TransformJarsToJar(ctx, outputFile, "for prebuilts", jars, android.OptionalPath{},
1575 false, j.properties.Exclude_files, j.properties.Exclude_dirs)
Colin Cross1001a792019-03-21 22:21:39 -07001576 if Bool(j.properties.Jetifier) {
Nan Zhang4c819fb2018-08-27 18:31:46 -07001577 inputFile := outputFile
1578 outputFile = android.PathForModuleOut(ctx, "jetifier", jarName)
1579 TransformJetifier(ctx, outputFile, inputFile)
1580 }
Colin Crosse9a275b2017-10-16 17:09:48 -07001581 j.combinedClasspathFile = outputFile
Ulya Trafimovichb23d28c2020-10-08 12:53:58 +01001582 j.classLoaderContexts = make(dexpreopt.ClassLoaderContextMap)
Paul Duffin859fe962020-05-15 10:20:31 +01001583
Liz Kammerd6c31d22020-08-05 15:40:41 -07001584 var flags javaBuilderFlags
1585
Jiyong Park1be96912018-05-28 18:02:19 +09001586 ctx.VisitDirectDeps(func(module android.Module) {
Jiyong Park1be96912018-05-28 18:02:19 +09001587 tag := ctx.OtherModuleDependencyTag(module)
1588
Colin Crossdcf71b22021-02-01 13:59:03 -08001589 if ctx.OtherModuleHasProvider(module, JavaInfoProvider) {
1590 dep := ctx.OtherModuleProvider(module, JavaInfoProvider).(JavaInfo)
Jiyong Park1be96912018-05-28 18:02:19 +09001591 switch tag {
Colin Cross9bb9bfb2022-03-17 11:12:32 -07001592 case libTag:
1593 flags.classpath = append(flags.classpath, dep.HeaderJars...)
1594 flags.dexClasspath = append(flags.dexClasspath, dep.HeaderJars...)
1595 case staticLibTag:
Colin Crossdcf71b22021-02-01 13:59:03 -08001596 flags.classpath = append(flags.classpath, dep.HeaderJars...)
Liz Kammerd6c31d22020-08-05 15:40:41 -07001597 case bootClasspathTag:
Colin Crossdcf71b22021-02-01 13:59:03 -08001598 flags.bootClasspath = append(flags.bootClasspath, dep.HeaderJars...)
Jiyong Park1be96912018-05-28 18:02:19 +09001599 }
Colin Crossdcf71b22021-02-01 13:59:03 -08001600 } else if dep, ok := module.(SdkLibraryDependency); ok {
Jiyong Park1be96912018-05-28 18:02:19 +09001601 switch tag {
1602 case libTag:
Jiyong Park92315372021-04-02 08:45:46 +09001603 flags.classpath = append(flags.classpath, dep.SdkHeaderJars(ctx, j.SdkVersion(ctx))...)
Jiyong Park1be96912018-05-28 18:02:19 +09001604 }
1605 }
Ulya Trafimovich65b03192020-12-03 16:50:22 +00001606
Ulya Trafimovich88bb6f62020-12-16 16:16:11 +00001607 addCLCFromDep(ctx, module, j.classLoaderContexts)
Jiyong Park1be96912018-05-28 18:02:19 +09001608 })
1609
Nan Zhang4973ecf2018-08-10 13:42:12 -07001610 if Bool(j.properties.Installable) {
Colin Cross1d0eb7a2021-11-03 14:08:20 -07001611 var installDir android.InstallPath
1612 if ctx.InstallInTestcases() {
1613 var archDir string
1614 if !ctx.Host() {
1615 archDir = ctx.DeviceConfig().DeviceArch()
1616 }
1617 installDir = android.PathForModuleInstall(ctx, ctx.ModuleName(), archDir)
1618 } else {
1619 installDir = android.PathForModuleInstall(ctx, "framework")
1620 }
1621 ctx.InstallFile(installDir, jarName, outputFile)
Nan Zhang4973ecf2018-08-10 13:42:12 -07001622 }
Jiyong Park19604de2020-03-24 16:44:11 +09001623
1624 j.exportAidlIncludeDirs = android.PathsForModuleSrc(ctx, j.properties.Aidl.Export_include_dirs)
Liz Kammerd6c31d22020-08-05 15:40:41 -07001625
Paul Duffin064b70c2020-11-02 17:32:38 +00001626 if ctx.Device() {
1627 // If this is a variant created for a prebuilt_apex then use the dex implementation jar
1628 // obtained from the associated deapexer module.
1629 ai := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo)
1630 if ai.ForPrebuiltApex {
Paul Duffin064b70c2020-11-02 17:32:38 +00001631 // Get the path of the dex implementation jar from the `deapexer` module.
Martin Stjernholm44825602021-09-17 01:44:12 +01001632 di := android.FindDeapexerProviderForModule(ctx)
1633 if di == nil {
1634 return // An error has been reported by FindDeapexerProviderForModule.
1635 }
Paul Duffinb4bbf2c2021-06-17 15:59:07 +01001636 if dexOutputPath := di.PrebuiltExportPath(apexRootRelativePathToJavaLib(j.BaseModuleName())); dexOutputPath != nil {
Martin Stjernholm8be1e6d2021-09-15 03:34:04 +01001637 dexJarFile := makeDexJarPathFromPath(dexOutputPath)
1638 j.dexJarFile = dexJarFile
Jiakai Zhang5b24f722021-09-30 09:32:57 +00001639 installPath := android.PathForModuleInPartitionInstall(ctx, "apex", ai.ApexVariationName, apexRootRelativePathToJavaLib(j.BaseModuleName()))
1640 j.dexJarInstallFile = installPath
Paul Duffin74d18d12021-05-14 14:18:47 +01001641
Jiakai Zhang5b24f722021-09-30 09:32:57 +00001642 j.dexpreopter.installPath = j.dexpreopter.getInstallPath(ctx, installPath)
Jiakai Zhang22450f22021-10-11 03:05:20 +00001643 setUncompressDex(ctx, &j.dexpreopter, &j.dexer)
Jiakai Zhang5b24f722021-09-30 09:32:57 +00001644 j.dexpreopter.uncompressedDex = *j.dexProperties.Uncompress_dex
1645 j.dexpreopt(ctx, dexOutputPath)
Jiakai Zhang22450f22021-10-11 03:05:20 +00001646
1647 // Initialize the hiddenapi structure.
1648 j.initHiddenAPI(ctx, dexJarFile, outputFile, j.dexProperties.Uncompress_dex)
Paul Duffin9d67ca62021-02-03 20:06:33 +00001649 } else {
Paul Duffin064b70c2020-11-02 17:32:38 +00001650 // This should never happen as a variant for a prebuilt_apex is only created if the
1651 // prebuilt_apex has been configured to export the java library dex file.
Martin Stjernholm44825602021-09-17 01:44:12 +01001652 ctx.ModuleErrorf("internal error: no dex implementation jar available from prebuilt APEX %s", di.ApexModuleName())
Paul Duffin064b70c2020-11-02 17:32:38 +00001653 }
1654 } else if Bool(j.dexProperties.Compile_dex) {
Jiyong Parkf1691d22021-03-29 20:11:58 +09001655 sdkDep := decodeSdkDep(ctx, android.SdkContext(j))
Paul Duffin064b70c2020-11-02 17:32:38 +00001656 if sdkDep.invalidVersion {
1657 ctx.AddMissingDependencies(sdkDep.bootclasspath)
1658 ctx.AddMissingDependencies(sdkDep.java9Classpath)
1659 } else if sdkDep.useFiles {
1660 // sdkDep.jar is actually equivalent to turbine header.jar.
1661 flags.classpath = append(flags.classpath, sdkDep.jars...)
1662 }
1663
1664 // Dex compilation
1665
Jiakai Zhang519c5c82021-09-16 06:15:39 +00001666 j.dexpreopter.installPath = j.dexpreopter.getInstallPath(
1667 ctx, android.PathForModuleInstall(ctx, "framework", jarName))
Jiakai Zhang22450f22021-10-11 03:05:20 +00001668 setUncompressDex(ctx, &j.dexpreopter, &j.dexer)
Paul Duffin064b70c2020-11-02 17:32:38 +00001669 j.dexpreopter.uncompressedDex = *j.dexProperties.Uncompress_dex
1670
Paul Duffin612e6102021-02-02 13:38:13 +00001671 var dexOutputFile android.OutputPath
Jiyong Park92315372021-04-02 08:45:46 +09001672 dexOutputFile = j.dexer.compileDex(ctx, flags, j.MinSdkVersion(ctx), outputFile, jarName)
Paul Duffin064b70c2020-11-02 17:32:38 +00001673 if ctx.Failed() {
1674 return
1675 }
1676
Paul Duffin74d18d12021-05-14 14:18:47 +01001677 // Initialize the hiddenapi structure.
Martin Stjernholm8be1e6d2021-09-15 03:34:04 +01001678 j.initHiddenAPI(ctx, makeDexJarPathFromPath(dexOutputFile), outputFile, j.dexProperties.Uncompress_dex)
Paul Duffinafaa47c2021-05-14 13:04:04 +01001679
1680 // Encode hidden API flags in dex file.
Paul Duffin1bbd0622021-05-14 15:52:25 +01001681 dexOutputFile = j.hiddenAPIEncodeDex(ctx, dexOutputFile)
Paul Duffin064b70c2020-11-02 17:32:38 +00001682
Martin Stjernholm8be1e6d2021-09-15 03:34:04 +01001683 j.dexJarFile = makeDexJarPathFromPath(dexOutputFile)
Jeongik Chad5fe8782021-07-08 01:13:11 +09001684 j.dexJarInstallFile = android.PathForModuleInstall(ctx, "framework", jarName)
Liz Kammerd6c31d22020-08-05 15:40:41 -07001685 }
Liz Kammerd6c31d22020-08-05 15:40:41 -07001686 }
Colin Crossdcf71b22021-02-01 13:59:03 -08001687
1688 ctx.SetProvider(JavaInfoProvider, JavaInfo{
1689 HeaderJars: android.PathsIfNonNil(j.combinedClasspathFile),
1690 ImplementationAndResourcesJars: android.PathsIfNonNil(j.combinedClasspathFile),
1691 ImplementationJars: android.PathsIfNonNil(j.combinedClasspathFile),
1692 AidlIncludeDirs: j.exportAidlIncludeDirs,
1693 })
Colin Cross2fe66872015-03-30 17:20:39 -07001694}
1695
Paul Duffinaa55f742020-10-06 17:20:13 +01001696func (j *Import) OutputFiles(tag string) (android.Paths, error) {
1697 switch tag {
Saeid Farivar Asanjan128fe5c2020-10-15 17:54:40 +00001698 case "", ".jar":
Paul Duffinaa55f742020-10-06 17:20:13 +01001699 return android.Paths{j.combinedClasspathFile}, nil
1700 default:
1701 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
1702 }
1703}
1704
1705var _ android.OutputFileProducer = (*Import)(nil)
1706
Nan Zhanged19fc32017-10-19 13:06:22 -07001707func (j *Import) HeaderJars() android.Paths {
albaltai36ff7dc2018-12-25 14:35:23 +08001708 if j.combinedClasspathFile == nil {
1709 return nil
1710 }
Colin Cross37f6d792018-07-12 12:28:41 -07001711 return android.Paths{j.combinedClasspathFile}
Nan Zhanged19fc32017-10-19 13:06:22 -07001712}
1713
Colin Cross331a1212018-08-15 20:40:52 -07001714func (j *Import) ImplementationAndResourcesJars() android.Paths {
albaltai36ff7dc2018-12-25 14:35:23 +08001715 if j.combinedClasspathFile == nil {
1716 return nil
1717 }
Colin Cross331a1212018-08-15 20:40:52 -07001718 return android.Paths{j.combinedClasspathFile}
1719}
1720
Martin Stjernholm8be1e6d2021-09-15 03:34:04 +01001721func (j *Import) DexJarBuildPath() OptionalDexJarPath {
Liz Kammerd6c31d22020-08-05 15:40:41 -07001722 return j.dexJarFile
Colin Crossf24a22a2019-01-31 14:12:44 -08001723}
1724
Ulya Trafimovich9f3052c2020-06-09 14:31:19 +01001725func (j *Import) DexJarInstallPath() android.Path {
Jeongik Chad5fe8782021-07-08 01:13:11 +09001726 return j.dexJarInstallFile
Ulya Trafimovich9f3052c2020-06-09 14:31:19 +01001727}
1728
Ulya Trafimovichb23d28c2020-10-08 12:53:58 +01001729func (j *Import) ClassLoaderContexts() dexpreopt.ClassLoaderContextMap {
1730 return j.classLoaderContexts
Jiyong Park1be96912018-05-28 18:02:19 +09001731}
1732
Jiyong Park45bf82e2020-12-15 22:29:02 +09001733var _ android.ApexModule = (*Import)(nil)
1734
1735// Implements android.ApexModule
Jiyong Park0f80c182020-01-31 02:49:53 +09001736func (j *Import) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
Paul Duffin0d3c2e12020-05-17 08:34:50 +01001737 return j.depIsInSameApex(ctx, dep)
Jiyong Park0f80c182020-01-31 02:49:53 +09001738}
1739
Jiyong Park45bf82e2020-12-15 22:29:02 +09001740// Implements android.ApexModule
Dan Albertc8060532020-07-22 22:32:17 -07001741func (j *Import) ShouldSupportSdkVersion(ctx android.BaseModuleContext,
1742 sdkVersion android.ApiLevel) error {
Jiyong Park92315372021-04-02 08:45:46 +09001743 sdkSpec := j.MinSdkVersion(ctx)
Jiyong Parkf1691d22021-03-29 20:11:58 +09001744 if !sdkSpec.Specified() {
Jaewoong Jung56e12db2021-04-02 00:38:25 +00001745 return fmt.Errorf("min_sdk_version is not specified")
1746 }
Jiyong Parkf1691d22021-03-29 20:11:58 +09001747 if sdkSpec.Kind == android.SdkCore {
Jaewoong Jung56e12db2021-04-02 00:38:25 +00001748 return nil
1749 }
Jooyung Han4c4da062021-06-23 10:23:16 +09001750 if sdkSpec.ApiLevel.GreaterThan(sdkVersion) {
1751 return fmt.Errorf("newer SDK(%v)", sdkSpec.ApiLevel)
Jaewoong Jung56e12db2021-04-02 00:38:25 +00001752 }
Jooyung Han749dc692020-04-15 11:03:39 +09001753 return nil
1754}
1755
Paul Duffinfef55002021-06-17 14:56:05 +01001756// requiredFilesFromPrebuiltApexForImport returns information about the files that a java_import or
1757// java_sdk_library_import with the specified base module name requires to be exported from a
1758// prebuilt_apex/apex_set.
Paul Duffinb4bbf2c2021-06-17 15:59:07 +01001759func requiredFilesFromPrebuiltApexForImport(name string) []string {
1760 // Add the dex implementation jar to the set of exported files.
1761 return []string{
1762 apexRootRelativePathToJavaLib(name),
Paul Duffinfef55002021-06-17 14:56:05 +01001763 }
1764}
1765
Paul Duffinb4bbf2c2021-06-17 15:59:07 +01001766// apexRootRelativePathToJavaLib returns the path, relative to the root of the apex's contents, for
1767// the java library with the specified name.
1768func apexRootRelativePathToJavaLib(name string) string {
1769 return filepath.Join("javalib", name+".jar")
1770}
1771
Paul Duffinfef55002021-06-17 14:56:05 +01001772var _ android.RequiredFilesFromPrebuiltApex = (*Import)(nil)
1773
Paul Duffinb4bbf2c2021-06-17 15:59:07 +01001774func (j *Import) RequiredFilesFromPrebuiltApex(_ android.BaseModuleContext) []string {
Paul Duffinfef55002021-06-17 14:56:05 +01001775 name := j.BaseModuleName()
1776 return requiredFilesFromPrebuiltApexForImport(name)
1777}
1778
albaltai36ff7dc2018-12-25 14:35:23 +08001779// Add compile time check for interface implementation
1780var _ android.IDEInfo = (*Import)(nil)
1781var _ android.IDECustomizedModuleName = (*Import)(nil)
1782
Brandon Lee5d45c6f2018-08-15 15:35:38 -07001783// Collect information for opening IDE project files in java/jdeps.go.
Brandon Lee5d45c6f2018-08-15 15:35:38 -07001784
1785func (j *Import) IDEInfo(dpInfo *android.IdeInfo) {
1786 dpInfo.Jars = append(dpInfo.Jars, j.PrebuiltSrcs()...)
1787}
1788
1789func (j *Import) IDECustomizedModuleName() string {
1790 // TODO(b/113562217): Extract the base module name from the Import name, often the Import name
1791 // has a prefix "prebuilt_". Remove the prefix explicitly if needed until we find a better
1792 // solution to get the Import name.
Ulya Trafimovich497a0932021-07-14 16:35:33 +01001793 return android.RemoveOptionalPrebuiltPrefix(j.Name())
Brandon Lee5d45c6f2018-08-15 15:35:38 -07001794}
1795
Colin Cross74d73e22017-08-02 11:05:49 -07001796var _ android.PrebuiltInterface = (*Import)(nil)
Colin Cross2fe66872015-03-30 17:20:39 -07001797
Bill Peckhamff89ffa2020-12-23 16:13:04 -08001798func (j *Import) IsInstallable() bool {
1799 return Bool(j.properties.Installable)
1800}
1801
Jiakai Zhang519c5c82021-09-16 06:15:39 +00001802var _ DexpreopterInterface = (*Import)(nil)
Bill Peckhamff89ffa2020-12-23 16:13:04 -08001803
Colin Cross1b16b0e2019-02-12 14:41:32 -08001804// java_import imports one or more `.jar` files into the build graph as if they were built by a java_library module.
1805//
1806// By default, a java_import has a single variant that expects a `.jar` file containing `.class` files that were
1807// compiled against an Android classpath.
1808//
1809// Specifying `host_supported: true` will produce two variants, one for use as a dependency of device modules and one
1810// for host modules.
Colin Cross74d73e22017-08-02 11:05:49 -07001811func ImportFactory() android.Module {
1812 module := &Import{}
Colin Cross36242852017-06-23 15:06:31 -07001813
Liz Kammerd6c31d22020-08-05 15:40:41 -07001814 module.AddProperties(
1815 &module.properties,
1816 &module.dexer.dexProperties,
1817 )
Colin Cross74d73e22017-08-02 11:05:49 -07001818
Paul Duffin71b33cc2021-06-23 11:39:47 +01001819 module.initModuleAndImport(module)
Paul Duffin859fe962020-05-15 10:20:31 +01001820
Liz Kammerd6c31d22020-08-05 15:40:41 -07001821 module.dexProperties.Optimize.EnabledByDefault = false
1822
Colin Cross74d73e22017-08-02 11:05:49 -07001823 android.InitPrebuiltModule(module, &module.properties.Jars)
Jiyong Park7f7766d2019-07-25 22:02:35 +09001824 android.InitApexModule(module)
Jiyong Parkd1063c12019-07-17 20:08:41 +09001825 android.InitSdkAwareModule(module)
Romain Jobredeaux428a3662022-01-28 11:12:52 -05001826 android.InitBazelModule(module)
Jooyung Han18020ea2019-11-13 10:50:48 +09001827 InitJavaModule(module, android.HostAndDeviceSupported)
Colin Cross36242852017-06-23 15:06:31 -07001828 return module
Colin Cross2fe66872015-03-30 17:20:39 -07001829}
1830
Colin Cross1b16b0e2019-02-12 14:41:32 -08001831// java_import imports one or more `.jar` files into the build graph as if they were built by a java_library_host
1832// module.
1833//
1834// A java_import_host has a single variant that expects a `.jar` file containing `.class` files that were
1835// compiled against a host bootclasspath.
Colin Cross74d73e22017-08-02 11:05:49 -07001836func ImportFactoryHost() android.Module {
1837 module := &Import{}
1838
1839 module.AddProperties(&module.properties)
1840
1841 android.InitPrebuiltModule(module, &module.properties.Jars)
Jiyong Park7f7766d2019-07-25 22:02:35 +09001842 android.InitApexModule(module)
Sam Delmerico5f83b492022-02-28 18:50:56 +00001843 android.InitBazelModule(module)
Jooyung Han18020ea2019-11-13 10:50:48 +09001844 InitJavaModule(module, android.HostSupported)
Colin Cross74d73e22017-08-02 11:05:49 -07001845 return module
1846}
1847
Colin Cross42be7612019-02-21 18:12:14 -08001848// dex_import module
1849
1850type DexImportProperties struct {
Colin Cross5cfc70d2019-07-15 13:36:55 -07001851 Jars []string `android:"path"`
Jiyong Park4c4c0242019-10-21 14:53:15 +09001852
1853 // set the name of the output
1854 Stem *string
Colin Cross42be7612019-02-21 18:12:14 -08001855}
1856
1857type DexImport struct {
1858 android.ModuleBase
1859 android.DefaultableModuleBase
Jiyong Park7f7766d2019-07-25 22:02:35 +09001860 android.ApexModuleBase
Colin Cross42be7612019-02-21 18:12:14 -08001861 prebuilt android.Prebuilt
1862
1863 properties DexImportProperties
1864
Martin Stjernholm8be1e6d2021-09-15 03:34:04 +01001865 dexJarFile OptionalDexJarPath
Colin Cross42be7612019-02-21 18:12:14 -08001866
1867 dexpreopter
Colin Cross56a83212020-09-15 18:30:11 -07001868
1869 hideApexVariantFromMake bool
Colin Cross42be7612019-02-21 18:12:14 -08001870}
1871
1872func (j *DexImport) Prebuilt() *android.Prebuilt {
1873 return &j.prebuilt
1874}
1875
1876func (j *DexImport) PrebuiltSrcs() []string {
1877 return j.properties.Jars
1878}
1879
1880func (j *DexImport) Name() string {
1881 return j.prebuilt.Name(j.ModuleBase.Name())
1882}
1883
Jiyong Park0b238752019-10-29 11:23:10 +09001884func (j *DexImport) Stem() string {
1885 return proptools.StringDefault(j.properties.Stem, j.ModuleBase.Name())
1886}
1887
Jiyong Park77acec62020-06-01 21:39:15 +09001888func (a *DexImport) JacocoReportClassesFile() android.Path {
1889 return nil
1890}
1891
Colin Cross08dca382020-07-21 20:31:17 -07001892func (a *DexImport) LintDepSets() LintDepSets {
1893 return LintDepSets{}
1894}
1895
Martin Stjernholm6d415272020-01-31 17:10:36 +00001896func (j *DexImport) IsInstallable() bool {
1897 return true
1898}
1899
Jaewoong Jung476b9d62021-05-10 15:30:00 -07001900func (j *DexImport) getStrictUpdatabilityLinting() bool {
1901 return false
1902}
1903
1904func (j *DexImport) setStrictUpdatabilityLinting(bool) {
1905}
1906
Colin Cross42be7612019-02-21 18:12:14 -08001907func (j *DexImport) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1908 if len(j.properties.Jars) != 1 {
1909 ctx.PropertyErrorf("jars", "exactly one jar must be provided")
1910 }
1911
Colin Cross56a83212020-09-15 18:30:11 -07001912 apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo)
1913 if !apexInfo.IsForPlatform() {
1914 j.hideApexVariantFromMake = true
1915 }
1916
Jiakai Zhang519c5c82021-09-16 06:15:39 +00001917 j.dexpreopter.installPath = j.dexpreopter.getInstallPath(
1918 ctx, android.PathForModuleInstall(ctx, "framework", j.Stem()+".jar"))
Colin Cross42be7612019-02-21 18:12:14 -08001919 j.dexpreopter.uncompressedDex = shouldUncompressDex(ctx, &j.dexpreopter)
1920
1921 inputJar := ctx.ExpandSource(j.properties.Jars[0], "jars")
1922 dexOutputFile := android.PathForModuleOut(ctx, ctx.ModuleName()+".jar")
1923
1924 if j.dexpreopter.uncompressedDex {
Colin Crossf1a035e2020-11-16 17:32:30 -08001925 rule := android.NewRuleBuilder(pctx, ctx)
Colin Cross42be7612019-02-21 18:12:14 -08001926
1927 temporary := android.PathForModuleOut(ctx, ctx.ModuleName()+".jar.unaligned")
1928 rule.Temporary(temporary)
1929
1930 // use zip2zip to uncompress classes*.dex files
1931 rule.Command().
Colin Crossf1a035e2020-11-16 17:32:30 -08001932 BuiltTool("zip2zip").
Colin Cross42be7612019-02-21 18:12:14 -08001933 FlagWithInput("-i ", inputJar).
1934 FlagWithOutput("-o ", temporary).
1935 FlagWithArg("-0 ", "'classes*.dex'")
1936
1937 // use zipalign to align uncompressed classes*.dex files
1938 rule.Command().
Colin Crossf1a035e2020-11-16 17:32:30 -08001939 BuiltTool("zipalign").
Colin Cross42be7612019-02-21 18:12:14 -08001940 Flag("-f").
1941 Text("4").
1942 Input(temporary).
1943 Output(dexOutputFile)
1944
1945 rule.DeleteTemporaryFiles()
1946
Colin Crossf1a035e2020-11-16 17:32:30 -08001947 rule.Build("uncompress_dex", "uncompress dex")
Colin Cross42be7612019-02-21 18:12:14 -08001948 } else {
1949 ctx.Build(pctx, android.BuildParams{
1950 Rule: android.Cp,
1951 Input: inputJar,
1952 Output: dexOutputFile,
1953 })
1954 }
1955
Martin Stjernholm8be1e6d2021-09-15 03:34:04 +01001956 j.dexJarFile = makeDexJarPathFromPath(dexOutputFile)
Colin Cross42be7612019-02-21 18:12:14 -08001957
Jaewoong Jung4b97a562020-12-17 09:43:28 -08001958 j.dexpreopt(ctx, dexOutputFile)
Colin Cross42be7612019-02-21 18:12:14 -08001959
Colin Cross56a83212020-09-15 18:30:11 -07001960 if apexInfo.IsForPlatform() {
Jiyong Park01bca752020-06-08 19:24:09 +09001961 ctx.InstallFile(android.PathForModuleInstall(ctx, "framework"),
1962 j.Stem()+".jar", dexOutputFile)
1963 }
Colin Cross42be7612019-02-21 18:12:14 -08001964}
1965
Martin Stjernholm8be1e6d2021-09-15 03:34:04 +01001966func (j *DexImport) DexJarBuildPath() OptionalDexJarPath {
Colin Cross42be7612019-02-21 18:12:14 -08001967 return j.dexJarFile
1968}
1969
Jiyong Park45bf82e2020-12-15 22:29:02 +09001970var _ android.ApexModule = (*DexImport)(nil)
1971
1972// Implements android.ApexModule
Dan Albertc8060532020-07-22 22:32:17 -07001973func (j *DexImport) ShouldSupportSdkVersion(ctx android.BaseModuleContext,
1974 sdkVersion android.ApiLevel) error {
Jooyung Han749dc692020-04-15 11:03:39 +09001975 // we don't check prebuilt modules for sdk_version
1976 return nil
1977}
1978
Colin Cross42be7612019-02-21 18:12:14 -08001979// dex_import imports a `.jar` file containing classes.dex files.
1980//
1981// A dex_import module cannot be used as a dependency of a java_* or android_* module, it can only be installed
1982// to the device.
1983func DexImportFactory() android.Module {
1984 module := &DexImport{}
1985
1986 module.AddProperties(&module.properties)
1987
1988 android.InitPrebuiltModule(module, &module.properties.Jars)
Jiyong Park7f7766d2019-07-25 22:02:35 +09001989 android.InitApexModule(module)
Jooyung Han18020ea2019-11-13 10:50:48 +09001990 InitJavaModule(module, android.DeviceSupported)
Colin Cross42be7612019-02-21 18:12:14 -08001991 return module
1992}
1993
Colin Cross89536d42017-07-07 14:35:50 -07001994//
1995// Defaults
1996//
1997type Defaults struct {
1998 android.ModuleBase
1999 android.DefaultsModuleBase
Jiyong Park7f7766d2019-07-25 22:02:35 +09002000 android.ApexModuleBase
Colin Cross89536d42017-07-07 14:35:50 -07002001}
2002
Colin Cross1b16b0e2019-02-12 14:41:32 -08002003// java_defaults provides a set of properties that can be inherited by other java or android modules.
2004//
2005// A module can use the properties from a java_defaults module using `defaults: ["defaults_module_name"]`. Each
2006// property in the defaults module that exists in the depending module will be prepended to the depending module's
2007// value for that property.
2008//
2009// Example:
2010//
2011// java_defaults {
2012// name: "example_defaults",
2013// srcs: ["common/**/*.java"],
2014// javacflags: ["-Xlint:all"],
2015// aaptflags: ["--auto-add-overlay"],
2016// }
2017//
2018// java_library {
2019// name: "example",
2020// defaults: ["example_defaults"],
2021// srcs: ["example/**/*.java"],
2022// }
2023//
2024// is functionally identical to:
2025//
2026// java_library {
2027// name: "example",
2028// srcs: [
2029// "common/**/*.java",
2030// "example/**/*.java",
2031// ],
2032// javacflags: ["-Xlint:all"],
2033// }
Paul Duffin47357662019-12-05 14:07:14 +00002034func DefaultsFactory() android.Module {
Colin Cross89536d42017-07-07 14:35:50 -07002035 module := &Defaults{}
2036
Colin Cross89536d42017-07-07 14:35:50 -07002037 module.AddProperties(
Jaewoong Jungbc15e3a2021-03-10 17:02:43 -08002038 &CommonProperties{},
2039 &DeviceProperties{},
Jooyung Han01d80d82022-01-08 12:16:32 +09002040 &OverridableDeviceProperties{},
Liz Kammera7a64f32020-07-09 15:16:41 -07002041 &DexProperties{},
Colin Cross43f08db2018-11-12 10:13:39 -08002042 &DexpreoptProperties{},
Dan Willemsen6424d172018-03-08 13:27:59 -08002043 &android.ProtoProperties{},
Colin Cross48de9a42018-10-02 13:53:33 -07002044 &aaptProperties{},
2045 &androidLibraryProperties{},
2046 &appProperties{},
2047 &appTestProperties{},
Jaewoong Jung525443a2019-02-28 15:35:54 -08002048 &overridableAppProperties{},
Roland Levillainb5b0ff32020-02-04 15:45:49 +00002049 &testProperties{},
Colin Cross48de9a42018-10-02 13:53:33 -07002050 &ImportProperties{},
2051 &AARImportProperties{},
2052 &sdkLibraryProperties{},
Paul Duffin1b1e8062020-05-08 13:44:43 +01002053 &commonToSdkLibraryAndImportProperties{},
Colin Cross42be7612019-02-21 18:12:14 -08002054 &DexImportProperties{},
Jooyung Han18020ea2019-11-13 10:50:48 +09002055 &android.ApexProperties{},
Jaewoong Jungbf135462020-04-26 15:10:51 -07002056 &RuntimeResourceOverlayProperties{},
Colin Cross014489c2020-06-02 20:09:13 -07002057 &LintProperties{},
Colin Crosscbce0b02021-02-09 10:38:30 -08002058 &appTestHelperAppProperties{},
Colin Cross89536d42017-07-07 14:35:50 -07002059 )
2060
2061 android.InitDefaultsModule(module)
Colin Cross89536d42017-07-07 14:35:50 -07002062 return module
2063}
Nan Zhangea568a42017-11-08 21:20:04 -08002064
Sasha Smundak2a4549e2018-11-05 16:49:08 -08002065func kytheExtractJavaFactory() android.Singleton {
2066 return &kytheExtractJavaSingleton{}
2067}
2068
2069type kytheExtractJavaSingleton struct {
2070}
2071
2072func (ks *kytheExtractJavaSingleton) GenerateBuildActions(ctx android.SingletonContext) {
2073 var xrefTargets android.Paths
2074 ctx.VisitAllModules(func(module android.Module) {
2075 if javaModule, ok := module.(xref); ok {
2076 xrefTargets = append(xrefTargets, javaModule.XrefJavaFiles()...)
2077 }
2078 })
2079 // TODO(asmundak): perhaps emit a rule to output a warning if there were no xrefTargets
2080 if len(xrefTargets) > 0 {
Colin Crossc3d87d32020-06-04 13:25:17 -07002081 ctx.Phony("xref_java", xrefTargets...)
Sasha Smundak2a4549e2018-11-05 16:49:08 -08002082 }
2083}
2084
Nan Zhangea568a42017-11-08 21:20:04 -08002085var Bool = proptools.Bool
Colin Cross38b40df2018-04-10 16:14:46 -07002086var BoolDefault = proptools.BoolDefault
Nan Zhangea568a42017-11-08 21:20:04 -08002087var String = proptools.String
Colin Cross0d0ba592018-02-20 13:33:42 -08002088var inList = android.InList
Ulya Trafimovich65b03192020-12-03 16:50:22 +00002089
Ulya Trafimovich88bb6f62020-12-16 16:16:11 +00002090// Add class loader context (CLC) of a given dependency to the current CLC.
2091func addCLCFromDep(ctx android.ModuleContext, depModule android.Module,
2092 clcMap dexpreopt.ClassLoaderContextMap) {
2093
2094 dep, ok := depModule.(UsesLibraryDependency)
2095 if !ok {
2096 return
2097 }
2098
Ulya Trafimovich840efb62021-07-15 14:34:40 +01002099 depName := android.RemoveOptionalPrebuiltPrefix(ctx.OtherModuleName(depModule))
2100
2101 var sdkLib *string
2102 if lib, ok := depModule.(SdkLibraryDependency); ok && lib.sharedLibrary() {
2103 // A shared SDK library. This should be added as a top-level CLC element.
2104 sdkLib = &depName
2105 } else if ulib, ok := depModule.(ProvidesUsesLib); ok {
2106 // A non-SDK library disguised as an SDK library by the means of `provides_uses_lib`
2107 // property. This should be handled in the same way as a shared SDK library.
2108 sdkLib = ulib.ProvidesUsesLib()
Ulya Trafimovich65b03192020-12-03 16:50:22 +00002109 }
Ulya Trafimovich88bb6f62020-12-16 16:16:11 +00002110
2111 depTag := ctx.OtherModuleDependencyTag(depModule)
Ulya Trafimovichfc0f6e32021-08-12 16:16:11 +01002112 if depTag == libTag {
Ulya Trafimovich88bb6f62020-12-16 16:16:11 +00002113 // Ok, propagate <uses-library> through non-static library dependencies.
Ulya Trafimovich0b1c70e2021-08-20 15:39:12 +01002114 } else if tag, ok := depTag.(usesLibraryDependencyTag); ok &&
2115 tag.sdkVersion == dexpreopt.AnySdkVersion && tag.implicit {
2116 // Ok, propagate <uses-library> through non-compatibility implicit <uses-library>
2117 // dependencies.
Ulya Trafimovich88bb6f62020-12-16 16:16:11 +00002118 } else if depTag == staticLibTag {
2119 // Propagate <uses-library> through static library dependencies, unless it is a component
2120 // library (such as stubs). Component libraries have a dependency on their SDK library,
2121 // which should not be pulled just because of a static component library.
Ulya Trafimovich840efb62021-07-15 14:34:40 +01002122 if sdkLib != nil {
Ulya Trafimovich88bb6f62020-12-16 16:16:11 +00002123 return
2124 }
2125 } else {
2126 // Don't propagate <uses-library> for other dependency tags.
2127 return
2128 }
2129
Ulya Trafimovich840efb62021-07-15 14:34:40 +01002130 // If this is an SDK (or SDK-like) library, then it should be added as a node in the CLC tree,
2131 // and its CLC should be added as subtree of that node. Otherwise the library is not a
2132 // <uses_library> and should not be added to CLC, but the transitive <uses-library> dependencies
2133 // from its CLC should be added to the current CLC.
2134 if sdkLib != nil {
Ulya Trafimovich0b1c70e2021-08-20 15:39:12 +01002135 clcMap.AddContext(ctx, dexpreopt.AnySdkVersion, *sdkLib, false, true,
Martin Stjernholm8be1e6d2021-09-15 03:34:04 +01002136 dep.DexJarBuildPath().PathOrNil(), dep.DexJarInstallPath(), dep.ClassLoaderContexts())
Ulya Trafimovich88bb6f62020-12-16 16:16:11 +00002137 } else {
Ulya Trafimovich88bb6f62020-12-16 16:16:11 +00002138 clcMap.AddContextMap(dep.ClassLoaderContexts(), depName)
2139 }
Ulya Trafimovich65b03192020-12-03 16:50:22 +00002140}
Wei Libafb6d62021-12-10 03:14:59 -08002141
Sam Delmericoc0161432022-02-25 21:34:51 +00002142type javaCommonAttributes struct {
Wei Libafb6d62021-12-10 03:14:59 -08002143 Srcs bazel.LabelListAttribute
Sam Delmerico77267c72022-03-18 14:11:07 +00002144 Plugins bazel.LabelListAttribute
Wei Libafb6d62021-12-10 03:14:59 -08002145 Javacopts bazel.StringListAttribute
2146}
2147
Sam Delmericoc0161432022-02-25 21:34:51 +00002148type javaDependencyLabels struct {
2149 // Dependencies which DO NOT contribute to the API visible to upstream dependencies.
2150 Deps bazel.LabelListAttribute
2151 // Dependencies which DO contribute to the API visible to upstream dependencies.
2152 StaticDeps bazel.LabelListAttribute
2153}
2154
2155// convertLibraryAttrsBp2Build converts a few shared attributes from java_* modules
2156// and also separates dependencies into dynamic dependencies and static dependencies.
2157// Each corresponding Bazel target type, can have a different method for handling
2158// dynamic vs. static dependencies, and so these are returned to the calling function.
Sam Delmerico24da73c2022-03-16 20:36:54 +00002159type eventLogTagsAttributes struct {
2160 Srcs bazel.LabelListAttribute
2161}
2162
Sam Delmericoc0161432022-02-25 21:34:51 +00002163func (m *Library) convertLibraryAttrsBp2Build(ctx android.TopDownMutatorContext) (*javaCommonAttributes, *javaDependencyLabels) {
Sam Delmericoe91d0302022-02-23 15:28:33 +00002164 var srcs bazel.LabelListAttribute
2165 archVariantProps := m.GetArchVariantProperties(ctx, &CommonProperties{})
2166 for axis, configToProps := range archVariantProps {
2167 for config, _props := range configToProps {
2168 if archProps, ok := _props.(*CommonProperties); ok {
2169 archSrcs := android.BazelLabelForModuleSrcExcludes(ctx, archProps.Srcs, archProps.Exclude_srcs)
2170 srcs.SetSelectValue(axis, config, archSrcs)
2171 }
2172 }
2173 }
Sam Delmericoc7681022022-02-04 21:01:20 +00002174
2175 javaSrcPartition := "java"
2176 protoSrcPartition := "proto"
Sam Delmerico24da73c2022-03-16 20:36:54 +00002177 logtagSrcPartition := "logtag"
Sam Delmericoc7681022022-02-04 21:01:20 +00002178 srcPartitions := bazel.PartitionLabelListAttribute(ctx, &srcs, bazel.LabelPartitions{
Sam Delmerico24da73c2022-03-16 20:36:54 +00002179 javaSrcPartition: bazel.LabelPartition{Extensions: []string{".java"}, Keep_remainder: true},
2180 logtagSrcPartition: bazel.LabelPartition{Extensions: []string{".logtags", ".logtag"}},
2181 protoSrcPartition: android.ProtoSrcLabelPartition,
Sam Delmericoc7681022022-02-04 21:01:20 +00002182 })
2183
Sam Delmerico24da73c2022-03-16 20:36:54 +00002184 javaSrcs := srcPartitions[javaSrcPartition]
2185
2186 var logtagsSrcs bazel.LabelList
2187 if !srcPartitions[logtagSrcPartition].IsEmpty() {
2188 logtagsLibName := m.Name() + "_logtags"
2189 logtagsSrcs = bazel.MakeLabelList([]bazel.Label{{Label: ":" + logtagsLibName}})
2190 ctx.CreateBazelTargetModule(
2191 bazel.BazelTargetModuleProperties{
2192 Rule_class: "event_log_tags",
2193 Bzl_load_location: "//build/make/tools:event_log_tags.bzl",
2194 },
2195 android.CommonAttributes{Name: logtagsLibName},
2196 &eventLogTagsAttributes{
2197 Srcs: srcPartitions[logtagSrcPartition],
2198 },
2199 )
2200 }
2201 javaSrcs.Append(bazel.MakeLabelListAttribute(logtagsSrcs))
2202
Sam Delmerico58614c02022-03-15 21:02:09 +00002203 var javacopts []string
2204 if m.properties.Javacflags != nil {
2205 javacopts = append(javacopts, m.properties.Javacflags...)
2206 }
2207 epEnabled := m.properties.Errorprone.Enabled
2208 //TODO(b/227504307) add configuration that depends on RUN_ERROR_PRONE environment variable
2209 if Bool(epEnabled) {
2210 javacopts = append(javacopts, m.properties.Errorprone.Javacflags...)
2211 }
2212
Sam Delmericoc0161432022-02-25 21:34:51 +00002213 commonAttrs := &javaCommonAttributes{
Sam Delmerico24da73c2022-03-16 20:36:54 +00002214 Srcs: javaSrcs,
Sam Delmerico77267c72022-03-18 14:11:07 +00002215 Plugins: bazel.MakeLabelListAttribute(
2216 android.BazelLabelForModuleDeps(ctx, m.properties.Plugins),
2217 ),
Sam Delmerico58614c02022-03-15 21:02:09 +00002218 Javacopts: bazel.MakeStringListAttribute(javacopts),
Wei Libafb6d62021-12-10 03:14:59 -08002219 }
2220
Sam Delmericoc0161432022-02-25 21:34:51 +00002221 depLabels := &javaDependencyLabels{}
2222
Sam Delmericofde9fb52022-01-28 20:53:38 +00002223 var deps bazel.LabelList
Wei Libafb6d62021-12-10 03:14:59 -08002224 if m.properties.Libs != nil {
Sam Delmericofde9fb52022-01-28 20:53:38 +00002225 deps.Append(android.BazelLabelForModuleDeps(ctx, m.properties.Libs))
Wei Libafb6d62021-12-10 03:14:59 -08002226 }
Sam Delmericoc0161432022-02-25 21:34:51 +00002227
2228 var staticDeps bazel.LabelList
Sam Delmericofde9fb52022-01-28 20:53:38 +00002229 if m.properties.Static_libs != nil {
Sam Delmericoc0161432022-02-25 21:34:51 +00002230 staticDeps.Append(android.BazelLabelForModuleDeps(ctx, m.properties.Static_libs))
Sam Delmericofde9fb52022-01-28 20:53:38 +00002231 }
Sam Delmericoc7681022022-02-04 21:01:20 +00002232
Sam Delmericoc0161432022-02-25 21:34:51 +00002233 protoDepLabel := bp2buildProto(ctx, &m.Module, srcPartitions[protoSrcPartition])
2234 // Soong does not differentiate between a java_library and the Bazel equivalent of
2235 // a java_proto_library + proto_library pair. Instead, in Soong proto sources are
2236 // listed directly in the srcs of a java_library, and the classes produced
2237 // by protoc are included directly in the resulting JAR. Thus upstream dependencies
2238 // that depend on a java_library with proto sources can link directly to the protobuf API,
2239 // and so this should be a static dependency.
2240 staticDeps.Add(protoDepLabel)
Sam Delmericoc7681022022-02-04 21:01:20 +00002241
Sam Delmericoc0161432022-02-25 21:34:51 +00002242 depLabels.Deps = bazel.MakeLabelListAttribute(deps)
2243 depLabels.StaticDeps = bazel.MakeLabelListAttribute(staticDeps)
Sam Delmericofde9fb52022-01-28 20:53:38 +00002244
Sam Delmericoc0161432022-02-25 21:34:51 +00002245 return commonAttrs, depLabels
2246}
2247
2248type javaLibraryAttributes struct {
2249 *javaCommonAttributes
2250 Deps bazel.LabelListAttribute
2251 Exports bazel.LabelListAttribute
Sam Delmericofde9fb52022-01-28 20:53:38 +00002252}
2253
2254func javaLibraryBp2Build(ctx android.TopDownMutatorContext, m *Library) {
Sam Delmericoc0161432022-02-25 21:34:51 +00002255 commonAttrs, depLabels := m.convertLibraryAttrsBp2Build(ctx)
2256
2257 deps := depLabels.Deps
2258 if !commonAttrs.Srcs.IsEmpty() {
2259 deps.Append(depLabels.StaticDeps) // we should only append these if there are sources to use them
2260
2261 sdkVersion := m.SdkVersion(ctx)
2262 if sdkVersion.Kind == android.SdkPublic && sdkVersion.ApiLevel == android.FutureApiLevel {
2263 // TODO(b/220869005) remove forced dependency on current public android.jar
2264 deps.Add(bazel.MakeLabelAttribute("//prebuilts/sdk:public_current_android_sdk_java_import"))
2265 }
2266 } else if !depLabels.Deps.IsEmpty() {
2267 ctx.ModuleErrorf("Module has direct dependencies but no sources. Bazel will not allow this.")
2268 }
2269
2270 attrs := &javaLibraryAttributes{
2271 javaCommonAttributes: commonAttrs,
2272 Deps: deps,
2273 Exports: depLabels.StaticDeps,
2274 }
Wei Libafb6d62021-12-10 03:14:59 -08002275
2276 props := bazel.BazelTargetModuleProperties{
2277 Rule_class: "java_library",
2278 Bzl_load_location: "//build/bazel/rules/java:library.bzl",
2279 }
2280
2281 ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: m.Name()}, attrs)
2282}
2283
2284type javaBinaryHostAttributes struct {
Sam Delmericoc0161432022-02-25 21:34:51 +00002285 *javaCommonAttributes
2286 Deps bazel.LabelListAttribute
2287 Runtime_deps bazel.LabelListAttribute
2288 Main_class string
2289 Jvm_flags bazel.StringListAttribute
Wei Libafb6d62021-12-10 03:14:59 -08002290}
2291
2292// JavaBinaryHostBp2Build is for java_binary_host bp2build.
2293func javaBinaryHostBp2Build(ctx android.TopDownMutatorContext, m *Binary) {
Sam Delmericoc0161432022-02-25 21:34:51 +00002294 commonAttrs, depLabels := m.convertLibraryAttrsBp2Build(ctx)
2295
2296 deps := depLabels.Deps
2297 deps.Append(depLabels.StaticDeps)
2298 if m.binaryProperties.Jni_libs != nil {
2299 deps.Append(bazel.MakeLabelListAttribute(android.BazelLabelForModuleDeps(ctx, m.binaryProperties.Jni_libs)))
2300 }
2301
2302 var runtimeDeps bazel.LabelListAttribute
2303 if commonAttrs.Srcs.IsEmpty() {
2304 // if there are no sources, then the dependencies can only be used at runtime
2305 runtimeDeps = deps
2306 deps = bazel.LabelListAttribute{}
2307 }
2308
Wei Libafb6d62021-12-10 03:14:59 -08002309 mainClass := ""
2310 if m.binaryProperties.Main_class != nil {
2311 mainClass = *m.binaryProperties.Main_class
2312 }
2313 if m.properties.Manifest != nil {
2314 mainClassInManifest, err := android.GetMainClassInManifest(ctx.Config(), android.PathForModuleSrc(ctx, *m.properties.Manifest).String())
2315 if err != nil {
2316 return
2317 }
2318 mainClass = mainClassInManifest
2319 }
Sam Delmericoc0161432022-02-25 21:34:51 +00002320
Wei Libafb6d62021-12-10 03:14:59 -08002321 attrs := &javaBinaryHostAttributes{
Sam Delmericoc0161432022-02-25 21:34:51 +00002322 javaCommonAttributes: commonAttrs,
2323 Deps: deps,
2324 Runtime_deps: runtimeDeps,
2325 Main_class: mainClass,
Wei Libafb6d62021-12-10 03:14:59 -08002326 }
2327
2328 // Attribute jvm_flags
2329 if m.binaryProperties.Jni_libs != nil {
2330 jniLibPackages := map[string]bool{}
2331 for _, jniLibLabel := range android.BazelLabelForModuleDeps(ctx, m.binaryProperties.Jni_libs).Includes {
2332 jniLibPackage := jniLibLabel.Label
2333 indexOfColon := strings.Index(jniLibLabel.Label, ":")
2334 if indexOfColon > 0 {
2335 // JNI lib from other package
2336 jniLibPackage = jniLibLabel.Label[2:indexOfColon]
2337 } else if indexOfColon == 0 {
2338 // JNI lib in the same package of java_binary
2339 packageOfCurrentModule := m.GetBazelLabel(ctx, m)
2340 jniLibPackage = packageOfCurrentModule[2:strings.Index(packageOfCurrentModule, ":")]
2341 }
2342 if _, inMap := jniLibPackages[jniLibPackage]; !inMap {
2343 jniLibPackages[jniLibPackage] = true
2344 }
2345 }
2346 jniLibPaths := []string{}
2347 for jniLibPackage, _ := range jniLibPackages {
2348 // See cs/f:.*/third_party/bazel/.*java_stub_template.txt for the use of RUNPATH
2349 jniLibPaths = append(jniLibPaths, "$${RUNPATH}"+jniLibPackage)
2350 }
2351 attrs.Jvm_flags = bazel.MakeStringListAttribute([]string{"-Djava.library.path=" + strings.Join(jniLibPaths, ":")})
2352 }
2353
2354 props := bazel.BazelTargetModuleProperties{
2355 Rule_class: "java_binary",
2356 }
2357
2358 // Create the BazelTargetModule.
2359 ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: m.Name()}, attrs)
2360}
Romain Jobredeaux428a3662022-01-28 11:12:52 -05002361
2362type bazelJavaImportAttributes struct {
2363 Jars bazel.LabelListAttribute
2364}
2365
2366// java_import bp2Build converter.
2367func (i *Import) ConvertWithBp2build(ctx android.TopDownMutatorContext) {
Sam Delmerico48983162022-02-22 21:41:33 +00002368 var jars bazel.LabelListAttribute
2369 archVariantProps := i.GetArchVariantProperties(ctx, &ImportProperties{})
2370 for axis, configToProps := range archVariantProps {
2371 for config, _props := range configToProps {
2372 if archProps, ok := _props.(*ImportProperties); ok {
2373 archJars := android.BazelLabelForModuleSrcExcludes(ctx, archProps.Jars, []string(nil))
2374 jars.SetSelectValue(axis, config, archJars)
2375 }
2376 }
2377 }
Romain Jobredeaux428a3662022-01-28 11:12:52 -05002378
2379 attrs := &bazelJavaImportAttributes{
2380 Jars: jars,
2381 }
2382 props := bazel.BazelTargetModuleProperties{Rule_class: "java_import"}
2383
2384 ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: android.RemoveOptionalPrebuiltPrefix(i.Name())}, attrs)
2385
2386}