blob: 6ff2d0383ee77e60ca240a647a3bebd579bcbac5 [file] [log] [blame]
Jaewoong Jung26342642021-03-17 15:56:23 -07001// Copyright 2021 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
17import (
18 "fmt"
19 "path/filepath"
20 "strconv"
21 "strings"
22
23 "github.com/google/blueprint/pathtools"
24 "github.com/google/blueprint/proptools"
25
26 "android/soong/android"
27 "android/soong/dexpreopt"
28 "android/soong/java/config"
29)
30
31// This file contains the definition and the implementation of the base module that most
32// source-based Java module structs embed.
33
34// TODO:
35// Autogenerated files:
36// Renderscript
37// Post-jar passes:
38// Proguard
39// Rmtypedefs
40// DroidDoc
41// Findbugs
42
43// Properties that are common to most Java modules, i.e. whether it's a host or device module.
44type CommonProperties struct {
45 // list of source files used to compile the Java module. May be .java, .kt, .logtags, .proto,
46 // or .aidl files.
47 Srcs []string `android:"path,arch_variant"`
48
49 // list Kotlin of source files containing Kotlin code that should be treated as common code in
50 // a codebase that supports Kotlin multiplatform. See
51 // https://kotlinlang.org/docs/reference/multiplatform.html. May be only be .kt files.
52 Common_srcs []string `android:"path,arch_variant"`
53
54 // list of source files that should not be used to build the Java module.
55 // This is most useful in the arch/multilib variants to remove non-common files
56 Exclude_srcs []string `android:"path,arch_variant"`
57
58 // list of directories containing Java resources
59 Java_resource_dirs []string `android:"arch_variant"`
60
61 // list of directories that should be excluded from java_resource_dirs
62 Exclude_java_resource_dirs []string `android:"arch_variant"`
63
64 // list of files to use as Java resources
65 Java_resources []string `android:"path,arch_variant"`
66
67 // list of files that should be excluded from java_resources and java_resource_dirs
68 Exclude_java_resources []string `android:"path,arch_variant"`
69
70 // list of module-specific flags that will be used for javac compiles
71 Javacflags []string `android:"arch_variant"`
72
73 // list of module-specific flags that will be used for kotlinc compiles
74 Kotlincflags []string `android:"arch_variant"`
75
76 // list of java libraries that will be in the classpath
77 Libs []string `android:"arch_variant"`
78
79 // list of java libraries that will be compiled into the resulting jar
80 Static_libs []string `android:"arch_variant"`
81
82 // manifest file to be included in resulting jar
83 Manifest *string `android:"path"`
84
85 // if not blank, run jarjar using the specified rules file
86 Jarjar_rules *string `android:"path,arch_variant"`
87
88 // If not blank, set the java version passed to javac as -source and -target
89 Java_version *string
90
91 // If set to true, allow this module to be dexed and installed on devices. Has no
92 // effect on host modules, which are always considered installable.
93 Installable *bool
94
95 // If set to true, include sources used to compile the module in to the final jar
96 Include_srcs *bool
97
98 // If not empty, classes are restricted to the specified packages and their sub-packages.
99 // This restriction is checked after applying jarjar rules and including static libs.
100 Permitted_packages []string
101
102 // List of modules to use as annotation processors
103 Plugins []string
104
105 // List of modules to export to libraries that directly depend on this library as annotation
106 // processors. Note that if the plugins set generates_api: true this will disable the turbine
107 // optimization on modules that depend on this module, which will reduce parallelism and cause
108 // more recompilation.
109 Exported_plugins []string
110
111 // The number of Java source entries each Javac instance can process
112 Javac_shard_size *int64
113
114 // Add host jdk tools.jar to bootclasspath
115 Use_tools_jar *bool
116
117 Openjdk9 struct {
118 // List of source files that should only be used when passing -source 1.9 or higher
119 Srcs []string `android:"path"`
120
121 // List of javac flags that should only be used when passing -source 1.9 or higher
122 Javacflags []string
123 }
124
125 // When compiling language level 9+ .java code in packages that are part of
126 // a system module, patch_module names the module that your sources and
127 // dependencies should be patched into. The Android runtime currently
128 // doesn't implement the JEP 261 module system so this option is only
129 // supported at compile time. It should only be needed to compile tests in
130 // packages that exist in libcore and which are inconvenient to move
131 // elsewhere.
132 Patch_module *string `android:"arch_variant"`
133
134 Jacoco struct {
135 // List of classes to include for instrumentation with jacoco to collect coverage
136 // information at runtime when building with coverage enabled. If unset defaults to all
137 // classes.
138 // Supports '*' as the last character of an entry in the list as a wildcard match.
139 // If preceded by '.' it matches all classes in the package and subpackages, otherwise
140 // it matches classes in the package that have the class name as a prefix.
141 Include_filter []string
142
143 // List of classes to exclude from instrumentation with jacoco to collect coverage
144 // information at runtime when building with coverage enabled. Overrides classes selected
145 // by the include_filter property.
146 // Supports '*' as the last character of an entry in the list as a wildcard match.
147 // If preceded by '.' it matches all classes in the package and subpackages, otherwise
148 // it matches classes in the package that have the class name as a prefix.
149 Exclude_filter []string
150 }
151
152 Errorprone struct {
153 // List of javac flags that should only be used when running errorprone.
154 Javacflags []string
155
156 // List of java_plugin modules that provide extra errorprone checks.
157 Extra_check_modules []string
Cole Faust75fffb12021-06-13 15:23:16 -0700158
Cole Faust2b1536e2021-06-18 12:25:54 -0700159 // This property can be in 3 states. When set to true, errorprone will
160 // be run during the regular build. When set to false, errorprone will
161 // never be run. When unset, errorprone will be run when the RUN_ERROR_PRONE
162 // environment variable is true. Setting this to false will improve build
163 // performance more than adding -XepDisableAllChecks in javacflags.
Cole Faust75fffb12021-06-13 15:23:16 -0700164 Enabled *bool
Jaewoong Jung26342642021-03-17 15:56:23 -0700165 }
166
167 Proto struct {
168 // List of extra options that will be passed to the proto generator.
169 Output_params []string
170 }
171
172 Instrument bool `blueprint:"mutated"`
173
174 // List of files to include in the META-INF/services folder of the resulting jar.
175 Services []string `android:"path,arch_variant"`
176
177 // If true, package the kotlin stdlib into the jar. Defaults to true.
178 Static_kotlin_stdlib *bool `android:"arch_variant"`
179
180 // A list of java_library instances that provide additional hiddenapi annotations for the library.
181 Hiddenapi_additional_annotations []string
182}
183
184// Properties that are specific to device modules. Host module factories should not add these when
185// constructing a new module.
186type DeviceProperties struct {
Trevor Radcliffe347e5e42021-11-05 19:30:24 +0000187 // If not blank, set to the version of the sdk to compile against.
Jaewoong Jung26342642021-03-17 15:56:23 -0700188 // Defaults to compiling against the current platform.
Trevor Radcliffe347e5e42021-11-05 19:30:24 +0000189 // Values are of one of the following forms:
190 // 1) numerical API level or "current"
191 // 2) An SDK kind with an API level: "<sdk kind>_<API level>". See
192 // build/soong/android/sdk_version.go for the complete and up to date list of
193 // SDK kinds. If the SDK kind value is empty, it will be set to public.
Jaewoong Jung26342642021-03-17 15:56:23 -0700194 Sdk_version *string
195
196 // if not blank, set the minimum version of the sdk that the compiled artifacts will run against.
Trevor Radcliffe347e5e42021-11-05 19:30:24 +0000197 // Defaults to sdk_version if not set. See sdk_version for possible values.
Jaewoong Jung26342642021-03-17 15:56:23 -0700198 Min_sdk_version *string
199
satayev0a420e72021-11-29 17:25:52 +0000200 // if not blank, set the maximum version of the sdk that the compiled artifacts will run against.
201 // Defaults to empty string "". See sdk_version for possible values.
202 Max_sdk_version *string
203
Jaewoong Jung26342642021-03-17 15:56:23 -0700204 // if not blank, set the targetSdkVersion in the AndroidManifest.xml.
Trevor Radcliffe347e5e42021-11-05 19:30:24 +0000205 // Defaults to sdk_version if not set. See sdk_version for possible values.
Jaewoong Jung26342642021-03-17 15:56:23 -0700206 Target_sdk_version *string
207
208 // Whether to compile against the platform APIs instead of an SDK.
209 // If true, then sdk_version must be empty. The value of this field
210 // is ignored when module's type isn't android_app.
211 Platform_apis *bool
212
213 Aidl struct {
214 // Top level directories to pass to aidl tool
215 Include_dirs []string
216
217 // Directories rooted at the Android.bp file to pass to aidl tool
218 Local_include_dirs []string
219
220 // directories that should be added as include directories for any aidl sources of modules
221 // that depend on this module, as well as to aidl for this module.
222 Export_include_dirs []string
223
224 // whether to generate traces (for systrace) for this interface
225 Generate_traces *bool
226
227 // whether to generate Binder#GetTransaction name method.
228 Generate_get_transaction_name *bool
229
Thiébaud Weksteende8417c2022-02-10 15:41:46 +1100230 // whether all interfaces should be annotated with required permissions.
231 Enforce_permissions *bool
232
233 // allowlist for interfaces that (temporarily) do not require annotation for permissions.
234 Enforce_permissions_exceptions []string `android:"path"`
235
Jaewoong Jung26342642021-03-17 15:56:23 -0700236 // list of flags that will be passed to the AIDL compiler
237 Flags []string
238 }
239
240 // If true, export a copy of the module as a -hostdex module for host testing.
241 Hostdex *bool
242
243 Target struct {
244 Hostdex struct {
245 // Additional required dependencies to add to -hostdex modules.
246 Required []string
247 }
248 }
249
250 // When targeting 1.9 and above, override the modules to use with --system,
251 // otherwise provides defaults libraries to add to the bootclasspath.
252 System_modules *string
253
Jaewoong Jung26342642021-03-17 15:56:23 -0700254 IsSDKLibrary bool `blueprint:"mutated"`
255
256 // If true, generate the signature file of APK Signing Scheme V4, along side the signed APK file.
257 // Defaults to false.
258 V4_signature *bool
259
260 // Only for libraries created by a sysprop_library module, SyspropPublicStub is the name of the
261 // public stubs library.
262 SyspropPublicStub string `blueprint:"mutated"`
263}
264
Jooyung Han01d80d82022-01-08 12:16:32 +0900265// Device properties that can be overridden by overriding module (e.g. override_android_app)
266type OverridableDeviceProperties struct {
267 // set the name of the output. If not set, `name` is used.
268 // To override a module with this property set, overriding module might need to set this as well.
269 // Otherwise, both the overridden and the overriding modules will have the same output name, which
270 // can cause the duplicate output error.
271 Stem *string
272}
273
Jaewoong Jung26342642021-03-17 15:56:23 -0700274// Functionality common to Module and Import
275//
276// It is embedded in Module so its functionality can be used by methods in Module
277// but it is currently only initialized by Import and Library.
278type embeddableInModuleAndImport struct {
279
280 // Functionality related to this being used as a component of a java_sdk_library.
281 EmbeddableSdkLibraryComponent
282}
283
Paul Duffin71b33cc2021-06-23 11:39:47 +0100284func (e *embeddableInModuleAndImport) initModuleAndImport(module android.Module) {
285 e.initSdkLibraryComponent(module)
Jaewoong Jung26342642021-03-17 15:56:23 -0700286}
287
288// Module/Import's DepIsInSameApex(...) delegates to this method.
289//
290// This cannot implement DepIsInSameApex(...) directly as that leads to ambiguity with
291// the one provided by ApexModuleBase.
292func (e *embeddableInModuleAndImport) depIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
293 // dependencies other than the static linkage are all considered crossing APEX boundary
294 if staticLibTag == ctx.OtherModuleDependencyTag(dep) {
295 return true
296 }
297 return false
298}
299
Martin Stjernholm8be1e6d2021-09-15 03:34:04 +0100300// OptionalDexJarPath can be either unset, hold a valid path to a dex jar file,
301// or an invalid path describing the reason it is invalid.
302//
303// It is unset if a dex jar isn't applicable, i.e. no build rule has been
304// requested to create one.
305//
306// If a dex jar has been requested to be built then it is set, and it may be
307// either a valid android.Path, or invalid with a reason message. The latter
308// happens if the source that should produce the dex file isn't able to.
309//
310// E.g. it is invalid with a reason message if there is a prebuilt APEX that
311// could produce the dex jar through a deapexer module, but the APEX isn't
312// installable so doing so wouldn't be safe.
313type OptionalDexJarPath struct {
314 isSet bool
315 path android.OptionalPath
316}
317
318// IsSet returns true if a path has been set, either invalid or valid.
319func (o OptionalDexJarPath) IsSet() bool {
320 return o.isSet
321}
322
323// Valid returns true if there is a path that is valid.
324func (o OptionalDexJarPath) Valid() bool {
325 return o.isSet && o.path.Valid()
326}
327
328// Path returns the valid path, or panics if it's either not set or is invalid.
329func (o OptionalDexJarPath) Path() android.Path {
330 if !o.isSet {
331 panic("path isn't set")
332 }
333 return o.path.Path()
334}
335
336// PathOrNil returns the path if it's set and valid, or else nil.
337func (o OptionalDexJarPath) PathOrNil() android.Path {
338 if o.Valid() {
339 return o.Path()
340 }
341 return nil
342}
343
344// InvalidReason returns the reason for an invalid path, which is never "". It
345// returns "" for an unset or valid path.
346func (o OptionalDexJarPath) InvalidReason() string {
347 if !o.isSet {
348 return ""
349 }
350 return o.path.InvalidReason()
351}
352
353func (o OptionalDexJarPath) String() string {
354 if !o.isSet {
355 return "<unset>"
356 }
357 return o.path.String()
358}
359
360// makeUnsetDexJarPath returns an unset OptionalDexJarPath.
361func makeUnsetDexJarPath() OptionalDexJarPath {
362 return OptionalDexJarPath{isSet: false}
363}
364
365// makeDexJarPathFromOptionalPath returns an OptionalDexJarPath that is set with
366// the given OptionalPath, which may be valid or invalid.
367func makeDexJarPathFromOptionalPath(path android.OptionalPath) OptionalDexJarPath {
368 return OptionalDexJarPath{isSet: true, path: path}
369}
370
371// makeDexJarPathFromPath returns an OptionalDexJarPath that is set with the
372// valid given path. It returns an unset OptionalDexJarPath if the given path is
373// nil.
374func makeDexJarPathFromPath(path android.Path) OptionalDexJarPath {
375 if path == nil {
376 return makeUnsetDexJarPath()
377 }
378 return makeDexJarPathFromOptionalPath(android.OptionalPathForPath(path))
379}
380
Jaewoong Jung26342642021-03-17 15:56:23 -0700381// Module contains the properties and members used by all java module types
382type Module struct {
383 android.ModuleBase
384 android.DefaultableModuleBase
385 android.ApexModuleBase
386 android.SdkBase
Wei Libafb6d62021-12-10 03:14:59 -0800387 android.BazelModuleBase
Jaewoong Jung26342642021-03-17 15:56:23 -0700388
389 // Functionality common to Module and Import.
390 embeddableInModuleAndImport
391
392 properties CommonProperties
393 protoProperties android.ProtoProperties
394 deviceProperties DeviceProperties
395
Jooyung Han01d80d82022-01-08 12:16:32 +0900396 overridableDeviceProperties OverridableDeviceProperties
397
Jaewoong Jung26342642021-03-17 15:56:23 -0700398 // jar file containing header classes including static library dependencies, suitable for
399 // inserting into the bootclasspath/classpath of another compile
400 headerJarFile android.Path
401
402 // jar file containing implementation classes including static library dependencies but no
403 // resources
404 implementationJarFile android.Path
405
406 // jar file containing only resources including from static library dependencies
407 resourceJar android.Path
408
409 // args and dependencies to package source files into a srcjar
410 srcJarArgs []string
411 srcJarDeps android.Paths
412
413 // jar file containing implementation classes and resources including static library
414 // dependencies
415 implementationAndResourcesJar android.Path
416
417 // output file containing classes.dex and resources
Martin Stjernholm8be1e6d2021-09-15 03:34:04 +0100418 dexJarFile OptionalDexJarPath
Jaewoong Jung26342642021-03-17 15:56:23 -0700419
420 // output file containing uninstrumented classes that will be instrumented by jacoco
421 jacocoReportClassesFile android.Path
422
423 // output file of the module, which may be a classes jar or a dex jar
424 outputFile android.Path
425 extraOutputFiles android.Paths
426
Thiébaud Weksteende8417c2022-02-10 15:41:46 +1100427 exportAidlIncludeDirs android.Paths
428 ignoredAidlPermissionList android.Paths
Jaewoong Jung26342642021-03-17 15:56:23 -0700429
430 logtagsSrcs android.Paths
431
432 // installed file for binary dependency
433 installFile android.Path
434
Colin Cross3108ce12021-11-10 14:38:50 -0800435 // installed file for hostdex copy
436 hostdexInstallFile android.InstallPath
437
Jaewoong Jung26342642021-03-17 15:56:23 -0700438 // list of .java files and srcjars that was passed to javac
439 compiledJavaSrcs android.Paths
440 compiledSrcJars android.Paths
441
442 // manifest file to use instead of properties.Manifest
443 overrideManifest android.OptionalPath
444
445 // map of SDK version to class loader context
446 classLoaderContexts dexpreopt.ClassLoaderContextMap
447
448 // list of plugins that this java module is exporting
449 exportedPluginJars android.Paths
450
451 // list of plugins that this java module is exporting
452 exportedPluginClasses []string
453
454 // if true, the exported plugins generate API and require disabling turbine.
455 exportedDisableTurbine bool
456
457 // list of source files, collected from srcFiles with unique java and all kt files,
458 // will be used by android.IDEInfo struct
459 expandIDEInfoCompiledSrcs []string
460
461 // expanded Jarjar_rules
462 expandJarjarRules android.Path
463
Jaewoong Jung26342642021-03-17 15:56:23 -0700464 // Extra files generated by the module type to be added as java resources.
465 extraResources android.Paths
466
467 hiddenAPI
468 dexer
469 dexpreopter
470 usesLibrary
471 linter
472
473 // list of the xref extraction files
474 kytheFiles android.Paths
475
476 // Collect the module directory for IDE info in java/jdeps.go.
477 modulePaths []string
478
479 hideApexVariantFromMake bool
Jiyong Park92315372021-04-02 08:45:46 +0900480
481 sdkVersion android.SdkSpec
482 minSdkVersion android.SdkSpec
satayev0a420e72021-11-29 17:25:52 +0000483 maxSdkVersion android.SdkSpec
Jaewoong Jung26342642021-03-17 15:56:23 -0700484}
485
Jiyong Park92315372021-04-02 08:45:46 +0900486func (j *Module) CheckStableSdkVersion(ctx android.BaseModuleContext) error {
487 sdkVersion := j.SdkVersion(ctx)
Jiyong Parkf1691d22021-03-29 20:11:58 +0900488 if sdkVersion.Stable() {
Jaewoong Jung26342642021-03-17 15:56:23 -0700489 return nil
490 }
Jiyong Parkf1691d22021-03-29 20:11:58 +0900491 if sdkVersion.Kind == android.SdkCorePlatform {
Paul Duffin1ea7c9f2021-03-15 09:39:13 +0000492 if useLegacyCorePlatformApi(ctx, j.BaseModuleName()) {
Jaewoong Jung26342642021-03-17 15:56:23 -0700493 return fmt.Errorf("non stable SDK %v - uses legacy core platform", sdkVersion)
494 } else {
495 // Treat stable core platform as stable.
496 return nil
497 }
498 } else {
499 return fmt.Errorf("non stable SDK %v", sdkVersion)
500 }
501}
502
503// checkSdkVersions enforces restrictions around SDK dependencies.
504func (j *Module) checkSdkVersions(ctx android.ModuleContext) {
505 if j.RequiresStableAPIs(ctx) {
Jiyong Parkf1691d22021-03-29 20:11:58 +0900506 if sc, ok := ctx.Module().(android.SdkContext); ok {
Jiyong Park92315372021-04-02 08:45:46 +0900507 if !sc.SdkVersion(ctx).Specified() {
Jaewoong Jung26342642021-03-17 15:56:23 -0700508 ctx.PropertyErrorf("sdk_version",
509 "sdk_version must have a value when the module is located at vendor or product(only if PRODUCT_ENFORCE_PRODUCT_PARTITION_INTERFACE is set).")
510 }
511 }
512 }
513
514 // Make sure this module doesn't statically link to modules with lower-ranked SDK link type.
515 // See rank() for details.
516 ctx.VisitDirectDeps(func(module android.Module) {
517 tag := ctx.OtherModuleDependencyTag(module)
518 switch module.(type) {
519 // TODO(satayev): cover other types as well, e.g. imports
520 case *Library, *AndroidLibrary:
521 switch tag {
522 case bootClasspathTag, libTag, staticLibTag, java9LibTag:
523 j.checkSdkLinkType(ctx, module.(moduleWithSdkDep), tag.(dependencyTag))
524 }
525 }
526 })
527}
528
529func (j *Module) checkPlatformAPI(ctx android.ModuleContext) {
Jiyong Parkf1691d22021-03-29 20:11:58 +0900530 if sc, ok := ctx.Module().(android.SdkContext); ok {
Jaewoong Jung26342642021-03-17 15:56:23 -0700531 usePlatformAPI := proptools.Bool(j.deviceProperties.Platform_apis)
Jiyong Park92315372021-04-02 08:45:46 +0900532 sdkVersionSpecified := sc.SdkVersion(ctx).Specified()
Jaewoong Jung26342642021-03-17 15:56:23 -0700533 if usePlatformAPI && sdkVersionSpecified {
Spandan Das60999342021-11-16 04:15:33 +0000534 ctx.PropertyErrorf("platform_apis", "This module has conflicting settings. sdk_version is not empty, which means this module cannot use platform APIs. However platform_apis is set to true.")
Jaewoong Jung26342642021-03-17 15:56:23 -0700535 } else if !usePlatformAPI && !sdkVersionSpecified {
Spandan Das60999342021-11-16 04:15:33 +0000536 ctx.PropertyErrorf("platform_apis", "This module has conflicting settings. sdk_version is empty, which means that this module is build against platform APIs. However platform_apis is not set to true")
Jaewoong Jung26342642021-03-17 15:56:23 -0700537 }
538
539 }
540}
541
542func (j *Module) addHostProperties() {
543 j.AddProperties(
544 &j.properties,
545 &j.protoProperties,
546 &j.usesLibraryProperties,
547 )
548}
549
550func (j *Module) addHostAndDeviceProperties() {
551 j.addHostProperties()
552 j.AddProperties(
553 &j.deviceProperties,
Jooyung Han01d80d82022-01-08 12:16:32 +0900554 &j.overridableDeviceProperties,
Jaewoong Jung26342642021-03-17 15:56:23 -0700555 &j.dexer.dexProperties,
556 &j.dexpreoptProperties,
557 &j.linter.properties,
558 )
559}
560
561func (j *Module) OutputFiles(tag string) (android.Paths, error) {
562 switch tag {
563 case "":
564 return append(android.Paths{j.outputFile}, j.extraOutputFiles...), nil
565 case android.DefaultDistTag:
566 return android.Paths{j.outputFile}, nil
567 case ".jar":
568 return android.Paths{j.implementationAndResourcesJar}, nil
569 case ".proguard_map":
570 if j.dexer.proguardDictionary.Valid() {
571 return android.Paths{j.dexer.proguardDictionary.Path()}, nil
572 }
573 return nil, fmt.Errorf("%q was requested, but no output file was found.", tag)
574 default:
575 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
576 }
577}
578
579var _ android.OutputFileProducer = (*Module)(nil)
580
581func InitJavaModule(module android.DefaultableModule, hod android.HostOrDeviceSupported) {
582 initJavaModule(module, hod, false)
583}
584
585func InitJavaModuleMultiTargets(module android.DefaultableModule, hod android.HostOrDeviceSupported) {
586 initJavaModule(module, hod, true)
587}
588
589func initJavaModule(module android.DefaultableModule, hod android.HostOrDeviceSupported, multiTargets bool) {
590 multilib := android.MultilibCommon
591 if multiTargets {
592 android.InitAndroidMultiTargetsArchModule(module, hod, multilib)
593 } else {
594 android.InitAndroidArchModule(module, hod, multilib)
595 }
596 android.InitDefaultableModule(module)
597}
598
599func (j *Module) shouldInstrument(ctx android.BaseModuleContext) bool {
600 return j.properties.Instrument &&
601 ctx.Config().IsEnvTrue("EMMA_INSTRUMENT") &&
602 ctx.DeviceConfig().JavaCoverageEnabledForPath(ctx.ModuleDir())
603}
604
605func (j *Module) shouldInstrumentStatic(ctx android.BaseModuleContext) bool {
606 return j.shouldInstrument(ctx) &&
607 (ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_STATIC") ||
608 ctx.Config().UnbundledBuild())
609}
610
611func (j *Module) shouldInstrumentInApex(ctx android.BaseModuleContext) bool {
612 // Force enable the instrumentation for java code that is built for APEXes ...
613 // except for the jacocoagent itself (because instrumenting jacocoagent using jacocoagent
614 // doesn't make sense) or framework libraries (e.g. libraries found in the InstrumentFrameworkModules list) unless EMMA_INSTRUMENT_FRAMEWORK is true.
615 apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo)
616 isJacocoAgent := ctx.ModuleName() == "jacocoagent"
617 if j.DirectlyInAnyApex() && !isJacocoAgent && !apexInfo.IsForPlatform() {
618 if !inList(ctx.ModuleName(), config.InstrumentFrameworkModules) {
619 return true
620 } else if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
621 return true
622 }
623 }
624 return false
625}
626
Jiyong Park92315372021-04-02 08:45:46 +0900627func (j *Module) SdkVersion(ctx android.EarlyModuleContext) android.SdkSpec {
628 return android.SdkSpecFrom(ctx, String(j.deviceProperties.Sdk_version))
Jaewoong Jung26342642021-03-17 15:56:23 -0700629}
630
Jiyong Parkf1691d22021-03-29 20:11:58 +0900631func (j *Module) SystemModules() string {
Jaewoong Jung26342642021-03-17 15:56:23 -0700632 return proptools.String(j.deviceProperties.System_modules)
633}
634
Jiyong Park92315372021-04-02 08:45:46 +0900635func (j *Module) MinSdkVersion(ctx android.EarlyModuleContext) android.SdkSpec {
Jaewoong Jung26342642021-03-17 15:56:23 -0700636 if j.deviceProperties.Min_sdk_version != nil {
Jiyong Park92315372021-04-02 08:45:46 +0900637 return android.SdkSpecFrom(ctx, *j.deviceProperties.Min_sdk_version)
Jaewoong Jung26342642021-03-17 15:56:23 -0700638 }
Jiyong Park92315372021-04-02 08:45:46 +0900639 return j.SdkVersion(ctx)
Jaewoong Jung26342642021-03-17 15:56:23 -0700640}
641
satayev0a420e72021-11-29 17:25:52 +0000642func (j *Module) MaxSdkVersion(ctx android.EarlyModuleContext) android.SdkSpec {
643 maxSdkVersion := proptools.StringDefault(j.deviceProperties.Max_sdk_version, "")
644 // SdkSpecFrom returns SdkSpecPrivate for this, which may be confusing.
645 // TODO(b/208456999): ideally MaxSdkVersion should be an ApiLevel and not SdkSpec.
646 return android.SdkSpecFrom(ctx, maxSdkVersion)
647}
648
Jiyong Parkf1691d22021-03-29 20:11:58 +0900649func (j *Module) MinSdkVersionString() string {
Jiyong Park92315372021-04-02 08:45:46 +0900650 return j.minSdkVersion.Raw
651}
652
653func (j *Module) TargetSdkVersion(ctx android.EarlyModuleContext) android.SdkSpec {
654 if j.deviceProperties.Target_sdk_version != nil {
655 return android.SdkSpecFrom(ctx, *j.deviceProperties.Target_sdk_version)
656 }
657 return j.SdkVersion(ctx)
Jaewoong Jung26342642021-03-17 15:56:23 -0700658}
659
660func (j *Module) AvailableFor(what string) bool {
661 if what == android.AvailableToPlatform && Bool(j.deviceProperties.Hostdex) {
662 // Exception: for hostdex: true libraries, the platform variant is created
663 // even if it's not marked as available to platform. In that case, the platform
664 // variant is used only for the hostdex and not installed to the device.
665 return true
666 }
667 return j.ApexModuleBase.AvailableFor(what)
668}
669
670func (j *Module) deps(ctx android.BottomUpMutatorContext) {
671 if ctx.Device() {
672 j.linter.deps(ctx)
673
Jiyong Parkf1691d22021-03-29 20:11:58 +0900674 sdkDeps(ctx, android.SdkContext(j), j.dexer)
Jaewoong Jung26342642021-03-17 15:56:23 -0700675
676 if j.deviceProperties.SyspropPublicStub != "" {
677 // This is a sysprop implementation library that has a corresponding sysprop public
678 // stubs library, and a dependency on it so that dependencies on the implementation can
679 // be forwarded to the public stubs library when necessary.
680 ctx.AddVariationDependencies(nil, syspropPublicStubDepTag, j.deviceProperties.SyspropPublicStub)
681 }
682 }
683
684 libDeps := ctx.AddVariationDependencies(nil, libTag, j.properties.Libs...)
685 ctx.AddVariationDependencies(nil, staticLibTag, j.properties.Static_libs...)
686
687 // Add dependency on libraries that provide additional hidden api annotations.
688 ctx.AddVariationDependencies(nil, hiddenApiAnnotationsTag, j.properties.Hiddenapi_additional_annotations...)
689
690 if ctx.DeviceConfig().VndkVersion() != "" && ctx.Config().EnforceInterPartitionJavaSdkLibrary() {
691 // Require java_sdk_library at inter-partition java dependency to ensure stable
692 // interface between partitions. If inter-partition java_library dependency is detected,
693 // raise build error because java_library doesn't have a stable interface.
694 //
695 // Inputs:
696 // PRODUCT_ENFORCE_INTER_PARTITION_JAVA_SDK_LIBRARY
697 // if true, enable enforcement
698 // PRODUCT_INTER_PARTITION_JAVA_LIBRARY_ALLOWLIST
699 // exception list of java_library names to allow inter-partition dependency
700 for idx := range j.properties.Libs {
701 if libDeps[idx] == nil {
702 continue
703 }
704
705 if javaDep, ok := libDeps[idx].(javaSdkLibraryEnforceContext); ok {
706 // java_sdk_library is always allowed at inter-partition dependency.
707 // So, skip check.
708 if _, ok := javaDep.(*SdkLibrary); ok {
709 continue
710 }
711
712 j.checkPartitionsForJavaDependency(ctx, "libs", javaDep)
713 }
714 }
715 }
716
717 // For library dependencies that are component libraries (like stubs), add the implementation
718 // as a dependency (dexpreopt needs to be against the implementation library, not stubs).
719 for _, dep := range libDeps {
720 if dep != nil {
721 if component, ok := dep.(SdkLibraryComponentDependency); ok {
722 if lib := component.OptionalSdkLibraryImplementation(); lib != nil {
Ulya Trafimovichfc0f6e32021-08-12 16:16:11 +0100723 // Add library as optional if it's one of the optional compatibility libs.
Ulya Trafimovich0b1c70e2021-08-20 15:39:12 +0100724 optional := android.InList(*lib, dexpreopt.OptionalCompatUsesLibs)
725 tag := makeUsesLibraryDependencyTag(dexpreopt.AnySdkVersion, optional, true)
Ulya Trafimovichfc0f6e32021-08-12 16:16:11 +0100726 ctx.AddVariationDependencies(nil, tag, *lib)
Jaewoong Jung26342642021-03-17 15:56:23 -0700727 }
728 }
729 }
730 }
731
732 ctx.AddFarVariationDependencies(ctx.Config().BuildOSCommonTarget.Variations(), pluginTag, j.properties.Plugins...)
733 ctx.AddFarVariationDependencies(ctx.Config().BuildOSCommonTarget.Variations(), errorpronePluginTag, j.properties.Errorprone.Extra_check_modules...)
734 ctx.AddFarVariationDependencies(ctx.Config().BuildOSCommonTarget.Variations(), exportedPluginTag, j.properties.Exported_plugins...)
735
736 android.ProtoDeps(ctx, &j.protoProperties)
737 if j.hasSrcExt(".proto") {
738 protoDeps(ctx, &j.protoProperties)
739 }
740
741 if j.hasSrcExt(".kt") {
742 // TODO(ccross): move this to a mutator pass that can tell if generated sources contain
743 // Kotlin files
744 ctx.AddVariationDependencies(nil, kotlinStdlibTag,
745 "kotlin-stdlib", "kotlin-stdlib-jdk7", "kotlin-stdlib-jdk8")
746 if len(j.properties.Plugins) > 0 {
747 ctx.AddVariationDependencies(nil, kotlinAnnotationsTag, "kotlin-annotations")
748 }
749 }
750
751 // Framework libraries need special handling in static coverage builds: they should not have
752 // static dependency on jacoco, otherwise there would be multiple conflicting definitions of
753 // the same jacoco classes coming from different bootclasspath jars.
754 if inList(ctx.ModuleName(), config.InstrumentFrameworkModules) {
755 if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
756 j.properties.Instrument = true
757 }
758 } else if j.shouldInstrumentStatic(ctx) {
759 ctx.AddVariationDependencies(nil, staticLibTag, "jacocoagent")
760 }
Colin Crossa1ff7c62021-09-17 14:11:52 -0700761
762 if j.useCompose() {
763 ctx.AddVariationDependencies(ctx.Config().BuildOSCommonTarget.Variations(), kotlinPluginTag,
764 "androidx.compose.compiler_compiler-hosted")
765 }
Jaewoong Jung26342642021-03-17 15:56:23 -0700766}
767
768func hasSrcExt(srcs []string, ext string) bool {
769 for _, src := range srcs {
770 if filepath.Ext(src) == ext {
771 return true
772 }
773 }
774
775 return false
776}
777
778func (j *Module) hasSrcExt(ext string) bool {
779 return hasSrcExt(j.properties.Srcs, ext)
780}
781
Thiébaud Weksteende8417c2022-02-10 15:41:46 +1100782func (j *Module) individualAidlFlags(ctx android.ModuleContext, aidlFile android.Path) string {
783 var flags string
784
785 if Bool(j.deviceProperties.Aidl.Enforce_permissions) {
786 if !android.InList(aidlFile.String(), j.ignoredAidlPermissionList.Strings()) {
787 flags = "-Wmissing-permission-annotation -Werror"
788 }
789 }
790 return flags
791}
792
Jaewoong Jung26342642021-03-17 15:56:23 -0700793func (j *Module) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.OptionalPath,
794 aidlIncludeDirs android.Paths) (string, android.Paths) {
795
796 aidlIncludes := android.PathsForModuleSrc(ctx, j.deviceProperties.Aidl.Local_include_dirs)
797 aidlIncludes = append(aidlIncludes,
798 android.PathsForModuleSrc(ctx, j.deviceProperties.Aidl.Export_include_dirs)...)
799 aidlIncludes = append(aidlIncludes,
800 android.PathsForSource(ctx, j.deviceProperties.Aidl.Include_dirs)...)
801
802 var flags []string
803 var deps android.Paths
804
805 flags = append(flags, j.deviceProperties.Aidl.Flags...)
806
807 if aidlPreprocess.Valid() {
808 flags = append(flags, "-p"+aidlPreprocess.String())
809 deps = append(deps, aidlPreprocess.Path())
810 } else if len(aidlIncludeDirs) > 0 {
811 flags = append(flags, android.JoinWithPrefix(aidlIncludeDirs.Strings(), "-I"))
812 }
813
814 if len(j.exportAidlIncludeDirs) > 0 {
815 flags = append(flags, android.JoinWithPrefix(j.exportAidlIncludeDirs.Strings(), "-I"))
816 }
817
818 if len(aidlIncludes) > 0 {
819 flags = append(flags, android.JoinWithPrefix(aidlIncludes.Strings(), "-I"))
820 }
821
822 flags = append(flags, "-I"+android.PathForModuleSrc(ctx).String())
823 if src := android.ExistentPathForSource(ctx, ctx.ModuleDir(), "src"); src.Valid() {
824 flags = append(flags, "-I"+src.String())
825 }
826
827 if Bool(j.deviceProperties.Aidl.Generate_traces) {
828 flags = append(flags, "-t")
829 }
830
831 if Bool(j.deviceProperties.Aidl.Generate_get_transaction_name) {
832 flags = append(flags, "--transaction_names")
833 }
834
Thiébaud Weksteende8417c2022-02-10 15:41:46 +1100835 if Bool(j.deviceProperties.Aidl.Enforce_permissions) {
836 exceptions := j.deviceProperties.Aidl.Enforce_permissions_exceptions
837 j.ignoredAidlPermissionList = android.PathsForModuleSrcExcludes(ctx, exceptions, nil)
838 }
839
Jooyung Han07f70c02021-11-06 07:08:45 +0900840 aidlMinSdkVersion := j.MinSdkVersion(ctx).ApiLevel.String()
841 flags = append(flags, "--min_sdk_version="+aidlMinSdkVersion)
842
Jaewoong Jung26342642021-03-17 15:56:23 -0700843 return strings.Join(flags, " "), deps
844}
845
846func (j *Module) collectBuilderFlags(ctx android.ModuleContext, deps deps) javaBuilderFlags {
847
848 var flags javaBuilderFlags
849
850 // javaVersion flag.
Jiyong Parkf1691d22021-03-29 20:11:58 +0900851 flags.javaVersion = getJavaVersion(ctx, String(j.properties.Java_version), android.SdkContext(j))
Jaewoong Jung26342642021-03-17 15:56:23 -0700852
Cole Faust2b1536e2021-06-18 12:25:54 -0700853 epEnabled := j.properties.Errorprone.Enabled
854 if (ctx.Config().RunErrorProne() && epEnabled == nil) || Bool(epEnabled) {
Jaewoong Jung26342642021-03-17 15:56:23 -0700855 if config.ErrorProneClasspath == nil && ctx.Config().TestProductVariables == nil {
856 ctx.ModuleErrorf("cannot build with Error Prone, missing external/error_prone?")
857 }
858
859 errorProneFlags := []string{
860 "-Xplugin:ErrorProne",
861 "${config.ErrorProneChecks}",
862 }
863 errorProneFlags = append(errorProneFlags, j.properties.Errorprone.Javacflags...)
864
865 flags.errorProneExtraJavacFlags = "${config.ErrorProneFlags} " +
866 "'" + strings.Join(errorProneFlags, " ") + "'"
867 flags.errorProneProcessorPath = classpath(android.PathsForSource(ctx, config.ErrorProneClasspath))
868 }
869
870 // classpath
871 flags.bootClasspath = append(flags.bootClasspath, deps.bootClasspath...)
872 flags.classpath = append(flags.classpath, deps.classpath...)
873 flags.java9Classpath = append(flags.java9Classpath, deps.java9Classpath...)
874 flags.processorPath = append(flags.processorPath, deps.processorPath...)
875 flags.errorProneProcessorPath = append(flags.errorProneProcessorPath, deps.errorProneProcessorPath...)
876
877 flags.processors = append(flags.processors, deps.processorClasses...)
878 flags.processors = android.FirstUniqueStrings(flags.processors)
879
880 if len(flags.bootClasspath) == 0 && ctx.Host() && !flags.javaVersion.usesJavaModules() &&
Jiyong Parkf1691d22021-03-29 20:11:58 +0900881 decodeSdkDep(ctx, android.SdkContext(j)).hasStandardLibs() {
Jaewoong Jung26342642021-03-17 15:56:23 -0700882 // Give host-side tools a version of OpenJDK's standard libraries
883 // close to what they're targeting. As of Dec 2017, AOSP is only
884 // bundling OpenJDK 8 and 9, so nothing < 8 is available.
885 //
886 // When building with OpenJDK 8, the following should have no
887 // effect since those jars would be available by default.
888 //
889 // When building with OpenJDK 9 but targeting a version < 1.8,
890 // putting them on the bootclasspath means that:
891 // a) code can't (accidentally) refer to OpenJDK 9 specific APIs
892 // b) references to existing APIs are not reinterpreted in an
893 // OpenJDK 9-specific way, eg. calls to subclasses of
894 // java.nio.Buffer as in http://b/70862583
895 java8Home := ctx.Config().Getenv("ANDROID_JAVA8_HOME")
896 flags.bootClasspath = append(flags.bootClasspath,
897 android.PathForSource(ctx, java8Home, "jre/lib/jce.jar"),
898 android.PathForSource(ctx, java8Home, "jre/lib/rt.jar"))
899 if Bool(j.properties.Use_tools_jar) {
900 flags.bootClasspath = append(flags.bootClasspath,
901 android.PathForSource(ctx, java8Home, "lib/tools.jar"))
902 }
903 }
904
905 // systemModules
906 flags.systemModules = deps.systemModules
907
908 // aidl flags.
909 flags.aidlFlags, flags.aidlDeps = j.aidlFlags(ctx, deps.aidlPreprocess, deps.aidlIncludeDirs)
910
911 return flags
912}
913
914func (j *Module) collectJavacFlags(
915 ctx android.ModuleContext, flags javaBuilderFlags, srcFiles android.Paths) javaBuilderFlags {
916 // javac flags.
917 javacFlags := j.properties.Javacflags
918
919 if ctx.Config().MinimizeJavaDebugInfo() && !ctx.Host() {
920 // For non-host binaries, override the -g flag passed globally to remove
921 // local variable debug info to reduce disk and memory usage.
922 javacFlags = append(javacFlags, "-g:source,lines")
923 }
924 javacFlags = append(javacFlags, "-Xlint:-dep-ann")
925
926 if flags.javaVersion.usesJavaModules() {
927 javacFlags = append(javacFlags, j.properties.Openjdk9.Javacflags...)
928
929 if j.properties.Patch_module != nil {
930 // Manually specify build directory in case it is not under the repo root.
931 // (javac doesn't seem to expand into symbolic links when searching for patch-module targets, so
932 // just adding a symlink under the root doesn't help.)
Lukacs T. Berki9f6c24a2021-08-26 15:07:24 +0200933 patchPaths := []string{".", ctx.Config().SoongOutDir()}
Jaewoong Jung26342642021-03-17 15:56:23 -0700934
935 // b/150878007
936 //
937 // Workaround to support *Bazel-executed* JDK9 javac in Bazel's
938 // execution root for --patch-module. If this javac command line is
939 // invoked within Bazel's execution root working directory, the top
940 // level directories (e.g. libcore/, tools/, frameworks/) are all
941 // symlinks. JDK9 javac does not traverse into symlinks, which causes
942 // --patch-module to fail source file lookups when invoked in the
943 // execution root.
944 //
945 // Short of patching javac or enumerating *all* directories as possible
946 // input dirs, manually add the top level dir of the source files to be
947 // compiled.
948 topLevelDirs := map[string]bool{}
949 for _, srcFilePath := range srcFiles {
950 srcFileParts := strings.Split(srcFilePath.String(), "/")
951 // Ignore source files that are already in the top level directory
952 // as well as generated files in the out directory. The out
953 // directory may be an absolute path, which means srcFileParts[0] is the
954 // empty string, so check that as well. Note that "out" in Bazel's execution
955 // root is *not* a symlink, which doesn't cause problems for --patch-modules
956 // anyway, so it's fine to not apply this workaround for generated
957 // source files.
958 if len(srcFileParts) > 1 &&
959 srcFileParts[0] != "" &&
960 srcFileParts[0] != "out" {
961 topLevelDirs[srcFileParts[0]] = true
962 }
963 }
964 patchPaths = append(patchPaths, android.SortedStringKeys(topLevelDirs)...)
965
966 classPath := flags.classpath.FormJavaClassPath("")
967 if classPath != "" {
968 patchPaths = append(patchPaths, classPath)
969 }
970 javacFlags = append(
971 javacFlags,
972 "--patch-module="+String(j.properties.Patch_module)+"="+strings.Join(patchPaths, ":"))
973 }
974 }
975
976 if len(javacFlags) > 0 {
977 // optimization.
978 ctx.Variable(pctx, "javacFlags", strings.Join(javacFlags, " "))
979 flags.javacFlags = "$javacFlags"
980 }
981
982 return flags
983}
984
985func (j *Module) compile(ctx android.ModuleContext, aaptSrcJar android.Path) {
986 j.exportAidlIncludeDirs = android.PathsForModuleSrc(ctx, j.deviceProperties.Aidl.Export_include_dirs)
987
988 deps := j.collectDeps(ctx)
989 flags := j.collectBuilderFlags(ctx, deps)
990
991 if flags.javaVersion.usesJavaModules() {
992 j.properties.Srcs = append(j.properties.Srcs, j.properties.Openjdk9.Srcs...)
993 }
Sorin Basca9347ae32021-12-20 11:51:24 +0000994
Jaewoong Jung26342642021-03-17 15:56:23 -0700995 srcFiles := android.PathsForModuleSrcExcludes(ctx, j.properties.Srcs, j.properties.Exclude_srcs)
996 if hasSrcExt(srcFiles.Strings(), ".proto") {
997 flags = protoFlags(ctx, &j.properties, &j.protoProperties, flags)
998 }
999
1000 kotlinCommonSrcFiles := android.PathsForModuleSrcExcludes(ctx, j.properties.Common_srcs, nil)
1001 if len(kotlinCommonSrcFiles.FilterOutByExt(".kt")) > 0 {
1002 ctx.PropertyErrorf("common_srcs", "common_srcs must be .kt files")
1003 }
1004
1005 srcFiles = j.genSources(ctx, srcFiles, flags)
1006
1007 // Collect javac flags only after computing the full set of srcFiles to
1008 // ensure that the --patch-module lookup paths are complete.
1009 flags = j.collectJavacFlags(ctx, flags, srcFiles)
1010
1011 srcJars := srcFiles.FilterByExt(".srcjar")
1012 srcJars = append(srcJars, deps.srcJars...)
1013 if aaptSrcJar != nil {
1014 srcJars = append(srcJars, aaptSrcJar)
1015 }
Colin Crossb0ef30a2021-06-29 10:42:00 -07001016 srcFiles = srcFiles.FilterOutByExt(".srcjar")
Jaewoong Jung26342642021-03-17 15:56:23 -07001017
1018 if j.properties.Jarjar_rules != nil {
1019 j.expandJarjarRules = android.PathForModuleSrc(ctx, *j.properties.Jarjar_rules)
1020 }
1021
1022 jarName := ctx.ModuleName() + ".jar"
1023
1024 javaSrcFiles := srcFiles.FilterByExt(".java")
1025 var uniqueSrcFiles android.Paths
1026 set := make(map[string]bool)
1027 for _, v := range javaSrcFiles {
1028 if _, found := set[v.String()]; !found {
1029 set[v.String()] = true
1030 uniqueSrcFiles = append(uniqueSrcFiles, v)
1031 }
1032 }
1033
1034 // Collect .java files for AIDEGen
1035 j.expandIDEInfoCompiledSrcs = append(j.expandIDEInfoCompiledSrcs, uniqueSrcFiles.Strings()...)
1036
1037 var kotlinJars android.Paths
1038
1039 if srcFiles.HasExt(".kt") {
1040 // user defined kotlin flags.
1041 kotlincFlags := j.properties.Kotlincflags
1042 CheckKotlincFlags(ctx, kotlincFlags)
1043
Aurimas Liutikas24a987f2021-05-17 17:47:10 +00001044 // Workaround for KT-46512
1045 kotlincFlags = append(kotlincFlags, "-Xsam-conversions=class")
Jaewoong Jung26342642021-03-17 15:56:23 -07001046
1047 // If there are kotlin files, compile them first but pass all the kotlin and java files
1048 // kotlinc will use the java files to resolve types referenced by the kotlin files, but
1049 // won't emit any classes for them.
1050 kotlincFlags = append(kotlincFlags, "-no-stdlib")
1051 if ctx.Device() {
1052 kotlincFlags = append(kotlincFlags, "-no-jdk")
1053 }
Colin Crossa1ff7c62021-09-17 14:11:52 -07001054
1055 for _, plugin := range deps.kotlinPlugins {
1056 kotlincFlags = append(kotlincFlags, "-Xplugin="+plugin.String())
1057 }
1058 flags.kotlincDeps = append(flags.kotlincDeps, deps.kotlinPlugins...)
1059
Jaewoong Jung26342642021-03-17 15:56:23 -07001060 if len(kotlincFlags) > 0 {
1061 // optimization.
1062 ctx.Variable(pctx, "kotlincFlags", strings.Join(kotlincFlags, " "))
1063 flags.kotlincFlags += "$kotlincFlags"
1064 }
1065
1066 var kotlinSrcFiles android.Paths
1067 kotlinSrcFiles = append(kotlinSrcFiles, uniqueSrcFiles...)
1068 kotlinSrcFiles = append(kotlinSrcFiles, srcFiles.FilterByExt(".kt")...)
1069
1070 // Collect .kt files for AIDEGen
1071 j.expandIDEInfoCompiledSrcs = append(j.expandIDEInfoCompiledSrcs, srcFiles.FilterByExt(".kt").Strings()...)
1072 j.expandIDEInfoCompiledSrcs = append(j.expandIDEInfoCompiledSrcs, kotlinCommonSrcFiles.Strings()...)
1073
1074 flags.classpath = append(flags.classpath, deps.kotlinStdlib...)
1075 flags.classpath = append(flags.classpath, deps.kotlinAnnotations...)
1076
1077 flags.kotlincClasspath = append(flags.kotlincClasspath, flags.bootClasspath...)
1078 flags.kotlincClasspath = append(flags.kotlincClasspath, flags.classpath...)
1079
1080 if len(flags.processorPath) > 0 {
1081 // Use kapt for annotation processing
1082 kaptSrcJar := android.PathForModuleOut(ctx, "kapt", "kapt-sources.jar")
1083 kaptResJar := android.PathForModuleOut(ctx, "kapt", "kapt-res.jar")
1084 kotlinKapt(ctx, kaptSrcJar, kaptResJar, kotlinSrcFiles, kotlinCommonSrcFiles, srcJars, flags)
1085 srcJars = append(srcJars, kaptSrcJar)
1086 kotlinJars = append(kotlinJars, kaptResJar)
1087 // Disable annotation processing in javac, it's already been handled by kapt
1088 flags.processorPath = nil
1089 flags.processors = nil
1090 }
1091
1092 kotlinJar := android.PathForModuleOut(ctx, "kotlin", jarName)
1093 kotlinCompile(ctx, kotlinJar, kotlinSrcFiles, kotlinCommonSrcFiles, srcJars, flags)
1094 if ctx.Failed() {
1095 return
1096 }
1097
1098 // Make javac rule depend on the kotlinc rule
1099 flags.classpath = append(flags.classpath, kotlinJar)
1100
1101 kotlinJars = append(kotlinJars, kotlinJar)
1102 // Jar kotlin classes into the final jar after javac
1103 if BoolDefault(j.properties.Static_kotlin_stdlib, true) {
1104 kotlinJars = append(kotlinJars, deps.kotlinStdlib...)
1105 }
1106 }
1107
1108 jars := append(android.Paths(nil), kotlinJars...)
1109
1110 // Store the list of .java files that was passed to javac
1111 j.compiledJavaSrcs = uniqueSrcFiles
1112 j.compiledSrcJars = srcJars
1113
1114 enableSharding := false
Colin Cross3d56ed52021-11-18 22:23:12 -08001115 var headerJarFileWithoutDepsOrJarjar android.Path
Jaewoong Jung26342642021-03-17 15:56:23 -07001116 if ctx.Device() && !ctx.Config().IsEnvFalse("TURBINE_ENABLED") && !deps.disableTurbine {
1117 if j.properties.Javac_shard_size != nil && *(j.properties.Javac_shard_size) > 0 {
1118 enableSharding = true
1119 // Formerly, there was a check here that prevented annotation processors
1120 // from being used when sharding was enabled, as some annotation processors
1121 // do not function correctly in sharded environments. It was removed to
1122 // allow for the use of annotation processors that do function correctly
1123 // with sharding enabled. See: b/77284273.
1124 }
Colin Cross3d56ed52021-11-18 22:23:12 -08001125 headerJarFileWithoutDepsOrJarjar, j.headerJarFile =
Jaewoong Jung26342642021-03-17 15:56:23 -07001126 j.compileJavaHeader(ctx, uniqueSrcFiles, srcJars, deps, flags, jarName, kotlinJars)
1127 if ctx.Failed() {
1128 return
1129 }
1130 }
1131 if len(uniqueSrcFiles) > 0 || len(srcJars) > 0 {
1132 var extraJarDeps android.Paths
Cole Faust75fffb12021-06-13 15:23:16 -07001133 if Bool(j.properties.Errorprone.Enabled) {
1134 // If error-prone is enabled, enable errorprone flags on the regular
1135 // build.
1136 flags = enableErrorproneFlags(flags)
Cole Faust2b1536e2021-06-18 12:25:54 -07001137 } else if ctx.Config().RunErrorProne() && j.properties.Errorprone.Enabled == nil {
Cole Faust75fffb12021-06-13 15:23:16 -07001138 // Otherwise, if the RUN_ERROR_PRONE environment variable is set, create
1139 // a new jar file just for compiling with the errorprone compiler to.
1140 // This is because we don't want to cause the java files to get completely
1141 // rebuilt every time the state of the RUN_ERROR_PRONE variable changes.
1142 // We also don't want to run this if errorprone is enabled by default for
1143 // this module, or else we could have duplicated errorprone messages.
1144 errorproneFlags := enableErrorproneFlags(flags)
Jaewoong Jung26342642021-03-17 15:56:23 -07001145 errorprone := android.PathForModuleOut(ctx, "errorprone", jarName)
Cole Faust75fffb12021-06-13 15:23:16 -07001146
1147 transformJavaToClasses(ctx, errorprone, -1, uniqueSrcFiles, srcJars, errorproneFlags, nil,
1148 "errorprone", "errorprone")
1149
Jaewoong Jung26342642021-03-17 15:56:23 -07001150 extraJarDeps = append(extraJarDeps, errorprone)
1151 }
1152
1153 if enableSharding {
Colin Cross3d56ed52021-11-18 22:23:12 -08001154 if headerJarFileWithoutDepsOrJarjar != nil {
1155 flags.classpath = append(classpath{headerJarFileWithoutDepsOrJarjar}, flags.classpath...)
1156 }
Jaewoong Jung26342642021-03-17 15:56:23 -07001157 shardSize := int(*(j.properties.Javac_shard_size))
1158 var shardSrcs []android.Paths
1159 if len(uniqueSrcFiles) > 0 {
1160 shardSrcs = android.ShardPaths(uniqueSrcFiles, shardSize)
1161 for idx, shardSrc := range shardSrcs {
1162 classes := j.compileJavaClasses(ctx, jarName, idx, shardSrc,
1163 nil, flags, extraJarDeps)
1164 jars = append(jars, classes)
1165 }
1166 }
1167 if len(srcJars) > 0 {
1168 classes := j.compileJavaClasses(ctx, jarName, len(shardSrcs),
1169 nil, srcJars, flags, extraJarDeps)
1170 jars = append(jars, classes)
1171 }
1172 } else {
1173 classes := j.compileJavaClasses(ctx, jarName, -1, uniqueSrcFiles, srcJars, flags, extraJarDeps)
1174 jars = append(jars, classes)
1175 }
1176 if ctx.Failed() {
1177 return
1178 }
1179 }
1180
1181 j.srcJarArgs, j.srcJarDeps = resourcePathsToJarArgs(srcFiles), srcFiles
1182
1183 var includeSrcJar android.WritablePath
1184 if Bool(j.properties.Include_srcs) {
1185 includeSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+".srcjar")
1186 TransformResourcesToJar(ctx, includeSrcJar, j.srcJarArgs, j.srcJarDeps)
1187 }
1188
1189 dirArgs, dirDeps := ResourceDirsToJarArgs(ctx, j.properties.Java_resource_dirs,
1190 j.properties.Exclude_java_resource_dirs, j.properties.Exclude_java_resources)
1191 fileArgs, fileDeps := ResourceFilesToJarArgs(ctx, j.properties.Java_resources, j.properties.Exclude_java_resources)
1192 extraArgs, extraDeps := resourcePathsToJarArgs(j.extraResources), j.extraResources
1193
1194 var resArgs []string
1195 var resDeps android.Paths
1196
1197 resArgs = append(resArgs, dirArgs...)
1198 resDeps = append(resDeps, dirDeps...)
1199
1200 resArgs = append(resArgs, fileArgs...)
1201 resDeps = append(resDeps, fileDeps...)
1202
1203 resArgs = append(resArgs, extraArgs...)
1204 resDeps = append(resDeps, extraDeps...)
1205
1206 if len(resArgs) > 0 {
1207 resourceJar := android.PathForModuleOut(ctx, "res", jarName)
1208 TransformResourcesToJar(ctx, resourceJar, resArgs, resDeps)
1209 j.resourceJar = resourceJar
1210 if ctx.Failed() {
1211 return
1212 }
1213 }
1214
1215 var resourceJars android.Paths
1216 if j.resourceJar != nil {
1217 resourceJars = append(resourceJars, j.resourceJar)
1218 }
1219 if Bool(j.properties.Include_srcs) {
1220 resourceJars = append(resourceJars, includeSrcJar)
1221 }
1222 resourceJars = append(resourceJars, deps.staticResourceJars...)
1223
1224 if len(resourceJars) > 1 {
1225 combinedJar := android.PathForModuleOut(ctx, "res-combined", jarName)
1226 TransformJarsToJar(ctx, combinedJar, "for resources", resourceJars, android.OptionalPath{},
1227 false, nil, nil)
1228 j.resourceJar = combinedJar
1229 } else if len(resourceJars) == 1 {
1230 j.resourceJar = resourceJars[0]
1231 }
1232
1233 if len(deps.staticJars) > 0 {
1234 jars = append(jars, deps.staticJars...)
1235 }
1236
1237 manifest := j.overrideManifest
1238 if !manifest.Valid() && j.properties.Manifest != nil {
1239 manifest = android.OptionalPathForPath(android.PathForModuleSrc(ctx, *j.properties.Manifest))
1240 }
1241
1242 services := android.PathsForModuleSrc(ctx, j.properties.Services)
1243 if len(services) > 0 {
1244 servicesJar := android.PathForModuleOut(ctx, "services", jarName)
1245 var zipargs []string
1246 for _, file := range services {
1247 serviceFile := file.String()
1248 zipargs = append(zipargs, "-C", filepath.Dir(serviceFile), "-f", serviceFile)
1249 }
1250 rule := zip
1251 args := map[string]string{
1252 "jarArgs": "-P META-INF/services/ " + strings.Join(proptools.NinjaAndShellEscapeList(zipargs), " "),
1253 }
1254 if ctx.Config().UseRBE() && ctx.Config().IsEnvTrue("RBE_ZIP") {
1255 rule = zipRE
1256 args["implicits"] = strings.Join(services.Strings(), ",")
1257 }
1258 ctx.Build(pctx, android.BuildParams{
1259 Rule: rule,
1260 Output: servicesJar,
1261 Implicits: services,
1262 Args: args,
1263 })
1264 jars = append(jars, servicesJar)
1265 }
1266
1267 // Combine the classes built from sources, any manifests, and any static libraries into
1268 // classes.jar. If there is only one input jar this step will be skipped.
1269 var outputFile android.OutputPath
1270
1271 if len(jars) == 1 && !manifest.Valid() {
1272 // Optimization: skip the combine step as there is nothing to do
1273 // TODO(ccross): this leaves any module-info.class files, but those should only come from
1274 // prebuilt dependencies until we support modules in the platform build, so there shouldn't be
1275 // any if len(jars) == 1.
1276
1277 // Transform the single path to the jar into an OutputPath as that is required by the following
1278 // code.
1279 if moduleOutPath, ok := jars[0].(android.ModuleOutPath); ok {
1280 // The path contains an embedded OutputPath so reuse that.
1281 outputFile = moduleOutPath.OutputPath
1282 } else if outputPath, ok := jars[0].(android.OutputPath); ok {
1283 // The path is an OutputPath so reuse it directly.
1284 outputFile = outputPath
1285 } else {
1286 // The file is not in the out directory so create an OutputPath into which it can be copied
1287 // and which the following code can use to refer to it.
1288 combinedJar := android.PathForModuleOut(ctx, "combined", jarName)
1289 ctx.Build(pctx, android.BuildParams{
1290 Rule: android.Cp,
1291 Input: jars[0],
1292 Output: combinedJar,
1293 })
1294 outputFile = combinedJar.OutputPath
1295 }
1296 } else {
1297 combinedJar := android.PathForModuleOut(ctx, "combined", jarName)
1298 TransformJarsToJar(ctx, combinedJar, "for javac", jars, manifest,
1299 false, nil, nil)
1300 outputFile = combinedJar.OutputPath
1301 }
1302
1303 // jarjar implementation jar if necessary
1304 if j.expandJarjarRules != nil {
1305 // Transform classes.jar into classes-jarjar.jar
1306 jarjarFile := android.PathForModuleOut(ctx, "jarjar", jarName).OutputPath
1307 TransformJarJar(ctx, jarjarFile, outputFile, j.expandJarjarRules)
1308 outputFile = jarjarFile
1309
1310 // jarjar resource jar if necessary
1311 if j.resourceJar != nil {
1312 resourceJarJarFile := android.PathForModuleOut(ctx, "res-jarjar", jarName)
1313 TransformJarJar(ctx, resourceJarJarFile, j.resourceJar, j.expandJarjarRules)
1314 j.resourceJar = resourceJarJarFile
1315 }
1316
1317 if ctx.Failed() {
1318 return
1319 }
1320 }
1321
1322 // Check package restrictions if necessary.
1323 if len(j.properties.Permitted_packages) > 0 {
Paul Duffin08a18bf2021-10-01 13:19:58 +01001324 // Time stamp file created by the package check rule.
Jaewoong Jung26342642021-03-17 15:56:23 -07001325 pkgckFile := android.PathForModuleOut(ctx, "package-check.stamp")
Paul Duffin08a18bf2021-10-01 13:19:58 +01001326
1327 // Create a rule to copy the output jar to another path and add a validate dependency that
1328 // will check that the jar only contains the permitted packages. The new location will become
1329 // the output file of this module.
1330 inputFile := outputFile
1331 outputFile = android.PathForModuleOut(ctx, "package-check", jarName).OutputPath
1332 ctx.Build(pctx, android.BuildParams{
1333 Rule: android.Cp,
1334 Input: inputFile,
1335 Output: outputFile,
1336 // Make sure that any dependency on the output file will cause ninja to run the package check
1337 // rule.
1338 Validation: pkgckFile,
1339 })
1340
1341 // Check packages and create a timestamp file when complete.
Jaewoong Jung26342642021-03-17 15:56:23 -07001342 CheckJarPackages(ctx, pkgckFile, outputFile, j.properties.Permitted_packages)
Jaewoong Jung26342642021-03-17 15:56:23 -07001343
1344 if ctx.Failed() {
1345 return
1346 }
1347 }
1348
1349 j.implementationJarFile = outputFile
1350 if j.headerJarFile == nil {
1351 j.headerJarFile = j.implementationJarFile
1352 }
1353
1354 if j.shouldInstrumentInApex(ctx) {
1355 j.properties.Instrument = true
1356 }
1357
Yuntao Xu5b009ae2021-05-13 12:42:24 -07001358 // enforce syntax check to jacoco filters for any build (http://b/183622051)
1359 specs := j.jacocoModuleToZipCommand(ctx)
1360 if ctx.Failed() {
1361 return
1362 }
1363
Jaewoong Jung26342642021-03-17 15:56:23 -07001364 if j.shouldInstrument(ctx) {
Yuntao Xu5b009ae2021-05-13 12:42:24 -07001365 outputFile = j.instrument(ctx, flags, outputFile, jarName, specs)
Jaewoong Jung26342642021-03-17 15:56:23 -07001366 }
1367
1368 // merge implementation jar with resources if necessary
1369 implementationAndResourcesJar := outputFile
1370 if j.resourceJar != nil {
1371 jars := android.Paths{j.resourceJar, implementationAndResourcesJar}
1372 combinedJar := android.PathForModuleOut(ctx, "withres", jarName).OutputPath
1373 TransformJarsToJar(ctx, combinedJar, "for resources", jars, manifest,
1374 false, nil, nil)
1375 implementationAndResourcesJar = combinedJar
1376 }
1377
1378 j.implementationAndResourcesJar = implementationAndResourcesJar
1379
1380 // Enable dex compilation for the APEX variants, unless it is disabled explicitly
1381 apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo)
1382 if j.DirectlyInAnyApex() && !apexInfo.IsForPlatform() {
1383 if j.dexProperties.Compile_dex == nil {
1384 j.dexProperties.Compile_dex = proptools.BoolPtr(true)
1385 }
1386 if j.deviceProperties.Hostdex == nil {
1387 j.deviceProperties.Hostdex = proptools.BoolPtr(true)
1388 }
1389 }
1390
1391 if ctx.Device() && (Bool(j.properties.Installable) || Bool(j.dexProperties.Compile_dex)) {
1392 if j.hasCode(ctx) {
1393 if j.shouldInstrumentStatic(ctx) {
1394 j.dexer.extraProguardFlagFiles = append(j.dexer.extraProguardFlagFiles,
1395 android.PathForSource(ctx, "build/make/core/proguard.jacoco.flags"))
1396 }
1397 // Dex compilation
1398 var dexOutputFile android.OutputPath
Colin Crossa79a52c2021-08-04 10:52:44 -07001399 dexOutputFile = j.dexer.compileDex(ctx, flags, j.MinSdkVersion(ctx), implementationAndResourcesJar, jarName)
Jaewoong Jung26342642021-03-17 15:56:23 -07001400 if ctx.Failed() {
1401 return
1402 }
1403
Jaewoong Jung26342642021-03-17 15:56:23 -07001404 // merge dex jar with resources if necessary
1405 if j.resourceJar != nil {
1406 jars := android.Paths{dexOutputFile, j.resourceJar}
1407 combinedJar := android.PathForModuleOut(ctx, "dex-withres", jarName).OutputPath
1408 TransformJarsToJar(ctx, combinedJar, "for dex resources", jars, android.OptionalPath{},
1409 false, nil, nil)
1410 if *j.dexProperties.Uncompress_dex {
1411 combinedAlignedJar := android.PathForModuleOut(ctx, "dex-withres-aligned", jarName).OutputPath
1412 TransformZipAlign(ctx, combinedAlignedJar, combinedJar)
1413 dexOutputFile = combinedAlignedJar
1414 } else {
1415 dexOutputFile = combinedJar
1416 }
1417 }
1418
Paul Duffin4de94502021-05-16 05:21:16 +01001419 // Initialize the hiddenapi structure.
Martin Stjernholm8be1e6d2021-09-15 03:34:04 +01001420
1421 j.initHiddenAPI(ctx, makeDexJarPathFromPath(dexOutputFile), j.implementationJarFile, j.dexProperties.Uncompress_dex)
Paul Duffin4de94502021-05-16 05:21:16 +01001422
1423 // Encode hidden API flags in dex file, if needed.
1424 dexOutputFile = j.hiddenAPIEncodeDex(ctx, dexOutputFile)
1425
Martin Stjernholm8be1e6d2021-09-15 03:34:04 +01001426 j.dexJarFile = makeDexJarPathFromPath(dexOutputFile)
Jaewoong Jung26342642021-03-17 15:56:23 -07001427
1428 // Dexpreopting
1429 j.dexpreopt(ctx, dexOutputFile)
1430
1431 outputFile = dexOutputFile
1432 } else {
1433 // There is no code to compile into a dex jar, make sure the resources are propagated
1434 // to the APK if this is an app.
1435 outputFile = implementationAndResourcesJar
Martin Stjernholm8be1e6d2021-09-15 03:34:04 +01001436 j.dexJarFile = makeDexJarPathFromPath(j.resourceJar)
Jaewoong Jung26342642021-03-17 15:56:23 -07001437 }
1438
1439 if ctx.Failed() {
1440 return
1441 }
1442 } else {
1443 outputFile = implementationAndResourcesJar
1444 }
1445
1446 if ctx.Device() {
Jiyong Parkf1691d22021-03-29 20:11:58 +09001447 lintSDKVersionString := func(sdkSpec android.SdkSpec) string {
Jiyong Park54105c42021-03-31 18:17:53 +09001448 if v := sdkSpec.ApiLevel; !v.IsPreview() {
Jaewoong Jung26342642021-03-17 15:56:23 -07001449 return v.String()
1450 } else {
1451 return ctx.Config().DefaultAppTargetSdk(ctx).String()
1452 }
1453 }
1454
1455 j.linter.name = ctx.ModuleName()
1456 j.linter.srcs = srcFiles
1457 j.linter.srcJars = srcJars
1458 j.linter.classpath = append(append(android.Paths(nil), flags.bootClasspath...), flags.classpath...)
1459 j.linter.classes = j.implementationJarFile
Jiyong Park92315372021-04-02 08:45:46 +09001460 j.linter.minSdkVersion = lintSDKVersionString(j.MinSdkVersion(ctx))
1461 j.linter.targetSdkVersion = lintSDKVersionString(j.TargetSdkVersion(ctx))
1462 j.linter.compileSdkVersion = lintSDKVersionString(j.SdkVersion(ctx))
Pedro Loureiro18233a22021-06-08 18:11:21 +00001463 j.linter.compileSdkKind = j.SdkVersion(ctx).Kind
Jaewoong Jung26342642021-03-17 15:56:23 -07001464 j.linter.javaLanguageLevel = flags.javaVersion.String()
1465 j.linter.kotlinLanguageLevel = "1.3"
1466 if !apexInfo.IsForPlatform() && ctx.Config().UnbundledBuildApps() {
1467 j.linter.buildModuleReportZip = true
1468 }
1469 j.linter.lint(ctx)
1470 }
1471
1472 ctx.CheckbuildFile(outputFile)
1473
1474 ctx.SetProvider(JavaInfoProvider, JavaInfo{
1475 HeaderJars: android.PathsIfNonNil(j.headerJarFile),
1476 ImplementationAndResourcesJars: android.PathsIfNonNil(j.implementationAndResourcesJar),
1477 ImplementationJars: android.PathsIfNonNil(j.implementationJarFile),
1478 ResourceJars: android.PathsIfNonNil(j.resourceJar),
1479 AidlIncludeDirs: j.exportAidlIncludeDirs,
1480 SrcJarArgs: j.srcJarArgs,
1481 SrcJarDeps: j.srcJarDeps,
1482 ExportedPlugins: j.exportedPluginJars,
1483 ExportedPluginClasses: j.exportedPluginClasses,
1484 ExportedPluginDisableTurbine: j.exportedDisableTurbine,
1485 JacocoReportClassesFile: j.jacocoReportClassesFile,
1486 })
1487
1488 // Save the output file with no relative path so that it doesn't end up in a subdirectory when used as a resource
1489 j.outputFile = outputFile.WithoutRel()
1490}
1491
Colin Crossa1ff7c62021-09-17 14:11:52 -07001492func (j *Module) useCompose() bool {
1493 return android.InList("androidx.compose.runtime_runtime", j.properties.Static_libs)
1494}
1495
Cole Faust75fffb12021-06-13 15:23:16 -07001496// Returns a copy of the supplied flags, but with all the errorprone-related
1497// fields copied to the regular build's fields.
1498func enableErrorproneFlags(flags javaBuilderFlags) javaBuilderFlags {
1499 flags.processorPath = append(flags.errorProneProcessorPath, flags.processorPath...)
1500
1501 if len(flags.errorProneExtraJavacFlags) > 0 {
1502 if len(flags.javacFlags) > 0 {
1503 flags.javacFlags += " " + flags.errorProneExtraJavacFlags
1504 } else {
1505 flags.javacFlags = flags.errorProneExtraJavacFlags
1506 }
1507 }
1508 return flags
1509}
1510
Jaewoong Jung26342642021-03-17 15:56:23 -07001511func (j *Module) compileJavaClasses(ctx android.ModuleContext, jarName string, idx int,
1512 srcFiles, srcJars android.Paths, flags javaBuilderFlags, extraJarDeps android.Paths) android.WritablePath {
1513
1514 kzipName := pathtools.ReplaceExtension(jarName, "kzip")
1515 if idx >= 0 {
1516 kzipName = strings.TrimSuffix(jarName, filepath.Ext(jarName)) + strconv.Itoa(idx) + ".kzip"
1517 jarName += strconv.Itoa(idx)
1518 }
1519
1520 classes := android.PathForModuleOut(ctx, "javac", jarName).OutputPath
1521 TransformJavaToClasses(ctx, classes, idx, srcFiles, srcJars, flags, extraJarDeps)
1522
1523 if ctx.Config().EmitXrefRules() {
1524 extractionFile := android.PathForModuleOut(ctx, kzipName)
1525 emitXrefRule(ctx, extractionFile, idx, srcFiles, srcJars, flags, extraJarDeps)
1526 j.kytheFiles = append(j.kytheFiles, extractionFile)
1527 }
1528
1529 return classes
1530}
1531
1532// Check for invalid kotlinc flags. Only use this for flags explicitly passed by the user,
1533// since some of these flags may be used internally.
1534func CheckKotlincFlags(ctx android.ModuleContext, flags []string) {
1535 for _, flag := range flags {
1536 flag = strings.TrimSpace(flag)
1537
1538 if !strings.HasPrefix(flag, "-") {
1539 ctx.PropertyErrorf("kotlincflags", "Flag `%s` must start with `-`", flag)
1540 } else if strings.HasPrefix(flag, "-Xintellij-plugin-root") {
1541 ctx.PropertyErrorf("kotlincflags",
1542 "Bad flag: `%s`, only use internal compiler for consistency.", flag)
1543 } else if inList(flag, config.KotlincIllegalFlags) {
1544 ctx.PropertyErrorf("kotlincflags", "Flag `%s` already used by build system", flag)
1545 } else if flag == "-include-runtime" {
1546 ctx.PropertyErrorf("kotlincflags", "Bad flag: `%s`, do not include runtime.", flag)
1547 } else {
1548 args := strings.Split(flag, " ")
1549 if args[0] == "-kotlin-home" {
1550 ctx.PropertyErrorf("kotlincflags",
1551 "Bad flag: `%s`, kotlin home already set to default (path to kotlinc in the repo).", flag)
1552 }
1553 }
1554 }
1555}
1556
1557func (j *Module) compileJavaHeader(ctx android.ModuleContext, srcFiles, srcJars android.Paths,
1558 deps deps, flags javaBuilderFlags, jarName string,
Colin Cross3d56ed52021-11-18 22:23:12 -08001559 extraJars android.Paths) (headerJar, jarjarAndDepsHeaderJar android.Path) {
Jaewoong Jung26342642021-03-17 15:56:23 -07001560
1561 var jars android.Paths
1562 if len(srcFiles) > 0 || len(srcJars) > 0 {
1563 // Compile java sources into turbine.jar.
1564 turbineJar := android.PathForModuleOut(ctx, "turbine", jarName)
1565 TransformJavaToHeaderClasses(ctx, turbineJar, srcFiles, srcJars, flags)
1566 if ctx.Failed() {
1567 return nil, nil
1568 }
1569 jars = append(jars, turbineJar)
Colin Cross3d56ed52021-11-18 22:23:12 -08001570 headerJar = turbineJar
Jaewoong Jung26342642021-03-17 15:56:23 -07001571 }
1572
1573 jars = append(jars, extraJars...)
1574
1575 // Combine any static header libraries into classes-header.jar. If there is only
1576 // one input jar this step will be skipped.
1577 jars = append(jars, deps.staticHeaderJars...)
1578
1579 // we cannot skip the combine step for now if there is only one jar
1580 // since we have to strip META-INF/TRANSITIVE dir from turbine.jar
1581 combinedJar := android.PathForModuleOut(ctx, "turbine-combined", jarName)
1582 TransformJarsToJar(ctx, combinedJar, "for turbine", jars, android.OptionalPath{},
1583 false, nil, []string{"META-INF/TRANSITIVE"})
Colin Cross3d56ed52021-11-18 22:23:12 -08001584 jarjarAndDepsHeaderJar = combinedJar
Jaewoong Jung26342642021-03-17 15:56:23 -07001585
1586 if j.expandJarjarRules != nil {
1587 // Transform classes.jar into classes-jarjar.jar
1588 jarjarFile := android.PathForModuleOut(ctx, "turbine-jarjar", jarName)
Colin Cross3d56ed52021-11-18 22:23:12 -08001589 TransformJarJar(ctx, jarjarFile, jarjarAndDepsHeaderJar, j.expandJarjarRules)
1590 jarjarAndDepsHeaderJar = jarjarFile
Jaewoong Jung26342642021-03-17 15:56:23 -07001591 if ctx.Failed() {
1592 return nil, nil
1593 }
1594 }
1595
Colin Cross3d56ed52021-11-18 22:23:12 -08001596 return headerJar, jarjarAndDepsHeaderJar
Jaewoong Jung26342642021-03-17 15:56:23 -07001597}
1598
1599func (j *Module) instrument(ctx android.ModuleContext, flags javaBuilderFlags,
Yuntao Xu5b009ae2021-05-13 12:42:24 -07001600 classesJar android.Path, jarName string, specs string) android.OutputPath {
Jaewoong Jung26342642021-03-17 15:56:23 -07001601
1602 jacocoReportClassesFile := android.PathForModuleOut(ctx, "jacoco-report-classes", jarName)
1603 instrumentedJar := android.PathForModuleOut(ctx, "jacoco", jarName).OutputPath
1604
1605 jacocoInstrumentJar(ctx, instrumentedJar, jacocoReportClassesFile, classesJar, specs)
1606
1607 j.jacocoReportClassesFile = jacocoReportClassesFile
1608
1609 return instrumentedJar
1610}
1611
1612func (j *Module) HeaderJars() android.Paths {
1613 if j.headerJarFile == nil {
1614 return nil
1615 }
1616 return android.Paths{j.headerJarFile}
1617}
1618
1619func (j *Module) ImplementationJars() android.Paths {
1620 if j.implementationJarFile == nil {
1621 return nil
1622 }
1623 return android.Paths{j.implementationJarFile}
1624}
1625
Martin Stjernholm8be1e6d2021-09-15 03:34:04 +01001626func (j *Module) DexJarBuildPath() OptionalDexJarPath {
Jaewoong Jung26342642021-03-17 15:56:23 -07001627 return j.dexJarFile
1628}
1629
1630func (j *Module) DexJarInstallPath() android.Path {
1631 return j.installFile
1632}
1633
1634func (j *Module) ImplementationAndResourcesJars() android.Paths {
1635 if j.implementationAndResourcesJar == nil {
1636 return nil
1637 }
1638 return android.Paths{j.implementationAndResourcesJar}
1639}
1640
1641func (j *Module) AidlIncludeDirs() android.Paths {
1642 // exportAidlIncludeDirs is type android.Paths already
1643 return j.exportAidlIncludeDirs
1644}
1645
1646func (j *Module) ClassLoaderContexts() dexpreopt.ClassLoaderContextMap {
1647 return j.classLoaderContexts
1648}
1649
1650// Collect information for opening IDE project files in java/jdeps.go.
1651func (j *Module) IDEInfo(dpInfo *android.IdeInfo) {
1652 dpInfo.Deps = append(dpInfo.Deps, j.CompilerDeps()...)
1653 dpInfo.Srcs = append(dpInfo.Srcs, j.expandIDEInfoCompiledSrcs...)
1654 dpInfo.SrcJars = append(dpInfo.SrcJars, j.compiledSrcJars.Strings()...)
1655 dpInfo.Aidl_include_dirs = append(dpInfo.Aidl_include_dirs, j.deviceProperties.Aidl.Include_dirs...)
1656 if j.expandJarjarRules != nil {
1657 dpInfo.Jarjar_rules = append(dpInfo.Jarjar_rules, j.expandJarjarRules.String())
1658 }
1659 dpInfo.Paths = append(dpInfo.Paths, j.modulePaths...)
1660}
1661
1662func (j *Module) CompilerDeps() []string {
1663 jdeps := []string{}
1664 jdeps = append(jdeps, j.properties.Libs...)
1665 jdeps = append(jdeps, j.properties.Static_libs...)
1666 return jdeps
1667}
1668
1669func (j *Module) hasCode(ctx android.ModuleContext) bool {
1670 srcFiles := android.PathsForModuleSrcExcludes(ctx, j.properties.Srcs, j.properties.Exclude_srcs)
1671 return len(srcFiles) > 0 || len(ctx.GetDirectDepsWithTag(staticLibTag)) > 0
1672}
1673
1674// Implements android.ApexModule
1675func (j *Module) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
1676 return j.depIsInSameApex(ctx, dep)
1677}
1678
1679// Implements android.ApexModule
satayev758968a2021-12-06 11:42:40 +00001680func (j *Module) ShouldSupportSdkVersion(ctx android.BaseModuleContext, sdkVersion android.ApiLevel) error {
Jiyong Park92315372021-04-02 08:45:46 +09001681 sdkSpec := j.MinSdkVersion(ctx)
Jiyong Parkf1691d22021-03-29 20:11:58 +09001682 if !sdkSpec.Specified() {
Jaewoong Jung26342642021-03-17 15:56:23 -07001683 return fmt.Errorf("min_sdk_version is not specified")
1684 }
Jiyong Parkf1691d22021-03-29 20:11:58 +09001685 if sdkSpec.Kind == android.SdkCore {
Jaewoong Jung26342642021-03-17 15:56:23 -07001686 return nil
1687 }
Jooyung Han4c4da062021-06-23 10:23:16 +09001688 if sdkSpec.ApiLevel.GreaterThan(sdkVersion) {
1689 return fmt.Errorf("newer SDK(%v)", sdkSpec.ApiLevel)
Jaewoong Jung26342642021-03-17 15:56:23 -07001690 }
1691 return nil
1692}
1693
1694func (j *Module) Stem() string {
Jooyung Han01d80d82022-01-08 12:16:32 +09001695 return proptools.StringDefault(j.overridableDeviceProperties.Stem, j.Name())
Jaewoong Jung26342642021-03-17 15:56:23 -07001696}
1697
Jaewoong Jung26342642021-03-17 15:56:23 -07001698func (j *Module) JacocoReportClassesFile() android.Path {
1699 return j.jacocoReportClassesFile
1700}
1701
1702func (j *Module) IsInstallable() bool {
1703 return Bool(j.properties.Installable)
1704}
1705
1706type sdkLinkType int
1707
1708const (
1709 // TODO(jiyong) rename these for better readability. Make the allowed
1710 // and disallowed link types explicit
1711 // order is important here. See rank()
1712 javaCore sdkLinkType = iota
1713 javaSdk
1714 javaSystem
1715 javaModule
1716 javaSystemServer
1717 javaPlatform
1718)
1719
1720func (lt sdkLinkType) String() string {
1721 switch lt {
1722 case javaCore:
1723 return "core Java API"
1724 case javaSdk:
1725 return "Android API"
1726 case javaSystem:
1727 return "system API"
1728 case javaModule:
1729 return "module API"
1730 case javaSystemServer:
1731 return "system server API"
1732 case javaPlatform:
1733 return "private API"
1734 default:
1735 panic(fmt.Errorf("unrecognized linktype: %d", lt))
1736 }
1737}
1738
1739// rank determines the total order among sdkLinkType. An SDK link type of rank A can link to
1740// another SDK link type of rank B only when B <= A. For example, a module linking to Android SDK
1741// can't statically depend on modules that use Platform API.
1742func (lt sdkLinkType) rank() int {
1743 return int(lt)
1744}
1745
1746type moduleWithSdkDep interface {
1747 android.Module
Jiyong Park92315372021-04-02 08:45:46 +09001748 getSdkLinkType(ctx android.BaseModuleContext, name string) (ret sdkLinkType, stubs bool)
Jaewoong Jung26342642021-03-17 15:56:23 -07001749}
1750
Jiyong Park92315372021-04-02 08:45:46 +09001751func (m *Module) getSdkLinkType(ctx android.BaseModuleContext, name string) (ret sdkLinkType, stubs bool) {
Jaewoong Jung26342642021-03-17 15:56:23 -07001752 switch name {
1753 case "core.current.stubs", "legacy.core.platform.api.stubs", "stable.core.platform.api.stubs",
1754 "stub-annotations", "private-stub-annotations-jar",
1755 "core-lambda-stubs", "core-generated-annotation-stubs":
1756 return javaCore, true
1757 case "android_stubs_current":
1758 return javaSdk, true
1759 case "android_system_stubs_current":
1760 return javaSystem, true
1761 case "android_module_lib_stubs_current":
1762 return javaModule, true
1763 case "android_system_server_stubs_current":
1764 return javaSystemServer, true
1765 case "android_test_stubs_current":
1766 return javaSystem, true
1767 }
1768
1769 if stub, linkType := moduleStubLinkType(name); stub {
1770 return linkType, true
1771 }
1772
Jiyong Park92315372021-04-02 08:45:46 +09001773 ver := m.SdkVersion(ctx)
Jiyong Parkf1691d22021-03-29 20:11:58 +09001774 switch ver.Kind {
1775 case android.SdkCore:
Jaewoong Jung26342642021-03-17 15:56:23 -07001776 return javaCore, false
Jiyong Parkf1691d22021-03-29 20:11:58 +09001777 case android.SdkSystem:
Jaewoong Jung26342642021-03-17 15:56:23 -07001778 return javaSystem, false
Jiyong Parkf1691d22021-03-29 20:11:58 +09001779 case android.SdkPublic:
Jaewoong Jung26342642021-03-17 15:56:23 -07001780 return javaSdk, false
Jiyong Parkf1691d22021-03-29 20:11:58 +09001781 case android.SdkModule:
Jaewoong Jung26342642021-03-17 15:56:23 -07001782 return javaModule, false
Jiyong Parkf1691d22021-03-29 20:11:58 +09001783 case android.SdkSystemServer:
Jaewoong Jung26342642021-03-17 15:56:23 -07001784 return javaSystemServer, false
Jiyong Parkf1691d22021-03-29 20:11:58 +09001785 case android.SdkPrivate, android.SdkNone, android.SdkCorePlatform, android.SdkTest:
Jaewoong Jung26342642021-03-17 15:56:23 -07001786 return javaPlatform, false
1787 }
1788
Jiyong Parkf1691d22021-03-29 20:11:58 +09001789 if !ver.Valid() {
1790 panic(fmt.Errorf("sdk_version is invalid. got %q", ver.Raw))
Jaewoong Jung26342642021-03-17 15:56:23 -07001791 }
1792 return javaSdk, false
1793}
1794
1795// checkSdkLinkType make sures the given dependency doesn't have a lower SDK link type rank than
1796// this module's. See the comment on rank() for details and an example.
1797func (j *Module) checkSdkLinkType(
1798 ctx android.ModuleContext, dep moduleWithSdkDep, tag dependencyTag) {
1799 if ctx.Host() {
1800 return
1801 }
1802
Jiyong Park92315372021-04-02 08:45:46 +09001803 myLinkType, stubs := j.getSdkLinkType(ctx, ctx.ModuleName())
Jaewoong Jung26342642021-03-17 15:56:23 -07001804 if stubs {
1805 return
1806 }
Jiyong Park92315372021-04-02 08:45:46 +09001807 depLinkType, _ := dep.getSdkLinkType(ctx, ctx.OtherModuleName(dep))
Jaewoong Jung26342642021-03-17 15:56:23 -07001808
1809 if myLinkType.rank() < depLinkType.rank() {
1810 ctx.ModuleErrorf("compiles against %v, but dependency %q is compiling against %v. "+
1811 "In order to fix this, consider adjusting sdk_version: OR platform_apis: "+
1812 "property of the source or target module so that target module is built "+
1813 "with the same or smaller API set when compared to the source.",
1814 myLinkType, ctx.OtherModuleName(dep), depLinkType)
1815 }
1816}
1817
1818func (j *Module) collectDeps(ctx android.ModuleContext) deps {
1819 var deps deps
1820
1821 if ctx.Device() {
Jiyong Parkf1691d22021-03-29 20:11:58 +09001822 sdkDep := decodeSdkDep(ctx, android.SdkContext(j))
Jaewoong Jung26342642021-03-17 15:56:23 -07001823 if sdkDep.invalidVersion {
1824 ctx.AddMissingDependencies(sdkDep.bootclasspath)
1825 ctx.AddMissingDependencies(sdkDep.java9Classpath)
1826 } else if sdkDep.useFiles {
1827 // sdkDep.jar is actually equivalent to turbine header.jar.
1828 deps.classpath = append(deps.classpath, sdkDep.jars...)
1829 deps.aidlPreprocess = sdkDep.aidl
1830 } else {
1831 deps.aidlPreprocess = sdkDep.aidl
1832 }
1833 }
1834
Jiyong Park92315372021-04-02 08:45:46 +09001835 sdkLinkType, _ := j.getSdkLinkType(ctx, ctx.ModuleName())
Jaewoong Jung26342642021-03-17 15:56:23 -07001836
1837 ctx.VisitDirectDeps(func(module android.Module) {
1838 otherName := ctx.OtherModuleName(module)
1839 tag := ctx.OtherModuleDependencyTag(module)
1840
1841 if IsJniDepTag(tag) {
1842 // Handled by AndroidApp.collectAppDeps
1843 return
1844 }
1845 if tag == certificateTag {
1846 // Handled by AndroidApp.collectAppDeps
1847 return
1848 }
1849
1850 if dep, ok := module.(SdkLibraryDependency); ok {
1851 switch tag {
1852 case libTag:
Jiyong Park92315372021-04-02 08:45:46 +09001853 deps.classpath = append(deps.classpath, dep.SdkHeaderJars(ctx, j.SdkVersion(ctx))...)
Jaewoong Jung26342642021-03-17 15:56:23 -07001854 case staticLibTag:
1855 ctx.ModuleErrorf("dependency on java_sdk_library %q can only be in libs", otherName)
1856 }
1857 } else if ctx.OtherModuleHasProvider(module, JavaInfoProvider) {
1858 dep := ctx.OtherModuleProvider(module, JavaInfoProvider).(JavaInfo)
1859 if sdkLinkType != javaPlatform &&
1860 ctx.OtherModuleHasProvider(module, SyspropPublicStubInfoProvider) {
1861 // dep is a sysprop implementation library, but this module is not linking against
1862 // the platform, so it gets the sysprop public stubs library instead. Replace
1863 // dep with the JavaInfo from the SyspropPublicStubInfoProvider.
1864 syspropDep := ctx.OtherModuleProvider(module, SyspropPublicStubInfoProvider).(SyspropPublicStubInfo)
1865 dep = syspropDep.JavaInfo
1866 }
1867 switch tag {
1868 case bootClasspathTag:
1869 deps.bootClasspath = append(deps.bootClasspath, dep.HeaderJars...)
1870 case libTag, instrumentationForTag:
1871 deps.classpath = append(deps.classpath, dep.HeaderJars...)
1872 deps.aidlIncludeDirs = append(deps.aidlIncludeDirs, dep.AidlIncludeDirs...)
1873 addPlugins(&deps, dep.ExportedPlugins, dep.ExportedPluginClasses...)
1874 deps.disableTurbine = deps.disableTurbine || dep.ExportedPluginDisableTurbine
1875 case java9LibTag:
1876 deps.java9Classpath = append(deps.java9Classpath, dep.HeaderJars...)
1877 case staticLibTag:
1878 deps.classpath = append(deps.classpath, dep.HeaderJars...)
1879 deps.staticJars = append(deps.staticJars, dep.ImplementationJars...)
1880 deps.staticHeaderJars = append(deps.staticHeaderJars, dep.HeaderJars...)
1881 deps.staticResourceJars = append(deps.staticResourceJars, dep.ResourceJars...)
1882 deps.aidlIncludeDirs = append(deps.aidlIncludeDirs, dep.AidlIncludeDirs...)
1883 addPlugins(&deps, dep.ExportedPlugins, dep.ExportedPluginClasses...)
1884 // Turbine doesn't run annotation processors, so any module that uses an
1885 // annotation processor that generates API is incompatible with the turbine
1886 // optimization.
1887 deps.disableTurbine = deps.disableTurbine || dep.ExportedPluginDisableTurbine
1888 case pluginTag:
1889 if plugin, ok := module.(*Plugin); ok {
1890 if plugin.pluginProperties.Processor_class != nil {
1891 addPlugins(&deps, dep.ImplementationAndResourcesJars, *plugin.pluginProperties.Processor_class)
1892 } else {
1893 addPlugins(&deps, dep.ImplementationAndResourcesJars)
1894 }
1895 // Turbine doesn't run annotation processors, so any module that uses an
1896 // annotation processor that generates API is incompatible with the turbine
1897 // optimization.
1898 deps.disableTurbine = deps.disableTurbine || Bool(plugin.pluginProperties.Generates_api)
1899 } else {
1900 ctx.PropertyErrorf("plugins", "%q is not a java_plugin module", otherName)
1901 }
1902 case errorpronePluginTag:
1903 if _, ok := module.(*Plugin); ok {
1904 deps.errorProneProcessorPath = append(deps.errorProneProcessorPath, dep.ImplementationAndResourcesJars...)
1905 } else {
1906 ctx.PropertyErrorf("plugins", "%q is not a java_plugin module", otherName)
1907 }
1908 case exportedPluginTag:
1909 if plugin, ok := module.(*Plugin); ok {
1910 j.exportedPluginJars = append(j.exportedPluginJars, dep.ImplementationAndResourcesJars...)
1911 if plugin.pluginProperties.Processor_class != nil {
1912 j.exportedPluginClasses = append(j.exportedPluginClasses, *plugin.pluginProperties.Processor_class)
1913 }
1914 // Turbine doesn't run annotation processors, so any module that uses an
1915 // annotation processor that generates API is incompatible with the turbine
1916 // optimization.
1917 j.exportedDisableTurbine = Bool(plugin.pluginProperties.Generates_api)
1918 } else {
1919 ctx.PropertyErrorf("exported_plugins", "%q is not a java_plugin module", otherName)
1920 }
1921 case kotlinStdlibTag:
1922 deps.kotlinStdlib = append(deps.kotlinStdlib, dep.HeaderJars...)
1923 case kotlinAnnotationsTag:
1924 deps.kotlinAnnotations = dep.HeaderJars
Colin Crossa1ff7c62021-09-17 14:11:52 -07001925 case kotlinPluginTag:
1926 deps.kotlinPlugins = append(deps.kotlinPlugins, dep.ImplementationAndResourcesJars...)
Jaewoong Jung26342642021-03-17 15:56:23 -07001927 case syspropPublicStubDepTag:
1928 // This is a sysprop implementation library, forward the JavaInfoProvider from
1929 // the corresponding sysprop public stub library as SyspropPublicStubInfoProvider.
1930 ctx.SetProvider(SyspropPublicStubInfoProvider, SyspropPublicStubInfo{
1931 JavaInfo: dep,
1932 })
1933 }
1934 } else if dep, ok := module.(android.SourceFileProducer); ok {
1935 switch tag {
1936 case libTag:
1937 checkProducesJars(ctx, dep)
1938 deps.classpath = append(deps.classpath, dep.Srcs()...)
1939 case staticLibTag:
1940 checkProducesJars(ctx, dep)
1941 deps.classpath = append(deps.classpath, dep.Srcs()...)
1942 deps.staticJars = append(deps.staticJars, dep.Srcs()...)
1943 deps.staticHeaderJars = append(deps.staticHeaderJars, dep.Srcs()...)
1944 }
1945 } else {
1946 switch tag {
1947 case bootClasspathTag:
1948 // If a system modules dependency has been added to the bootclasspath
1949 // then add its libs to the bootclasspath.
1950 sm := module.(SystemModulesProvider)
1951 deps.bootClasspath = append(deps.bootClasspath, sm.HeaderJars()...)
1952
1953 case systemModulesTag:
1954 if deps.systemModules != nil {
1955 panic("Found two system module dependencies")
1956 }
1957 sm := module.(SystemModulesProvider)
1958 outputDir, outputDeps := sm.OutputDirAndDeps()
1959 deps.systemModules = &systemModules{outputDir, outputDeps}
Paul Duffin53a70a42022-01-11 14:35:55 +00001960
1961 case instrumentationForTag:
1962 ctx.PropertyErrorf("instrumentation_for", "dependency %q of type %q does not provide JavaInfo so is unsuitable for use with this property", ctx.OtherModuleName(module), ctx.OtherModuleType(module))
Jaewoong Jung26342642021-03-17 15:56:23 -07001963 }
1964 }
1965
1966 addCLCFromDep(ctx, module, j.classLoaderContexts)
1967 })
1968
1969 return deps
1970}
1971
1972func addPlugins(deps *deps, pluginJars android.Paths, pluginClasses ...string) {
1973 deps.processorPath = append(deps.processorPath, pluginJars...)
1974 deps.processorClasses = append(deps.processorClasses, pluginClasses...)
1975}
1976
1977// TODO(b/132357300) Generalize SdkLibrarComponentDependency to non-SDK libraries and merge with
1978// this interface.
1979type ProvidesUsesLib interface {
1980 ProvidesUsesLib() *string
1981}
1982
1983func (j *Module) ProvidesUsesLib() *string {
1984 return j.usesLibraryProperties.Provides_uses_lib
1985}
satayev1c564cc2021-05-25 19:50:30 +01001986
1987type ModuleWithStem interface {
1988 Stem() string
1989}
1990
1991var _ ModuleWithStem = (*Module)(nil)
Wei Libafb6d62021-12-10 03:14:59 -08001992
1993func (j *Module) ConvertWithBp2build(ctx android.TopDownMutatorContext) {
1994 switch ctx.ModuleType() {
Sam Delmericofde9fb52022-01-28 20:53:38 +00001995 case "java_library", "java_library_host", "java_library_static":
Wei Libafb6d62021-12-10 03:14:59 -08001996 if lib, ok := ctx.Module().(*Library); ok {
1997 javaLibraryBp2Build(ctx, lib)
1998 }
1999 case "java_binary_host":
2000 if binary, ok := ctx.Module().(*Binary); ok {
2001 javaBinaryHostBp2Build(ctx, binary)
2002 }
2003 }
Wei Libafb6d62021-12-10 03:14:59 -08002004}