blob: 9a35675fedbf08a11ffaa8fb8c202b01398dcef7 [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
230 // list of flags that will be passed to the AIDL compiler
231 Flags []string
232 }
233
234 // If true, export a copy of the module as a -hostdex module for host testing.
235 Hostdex *bool
236
237 Target struct {
238 Hostdex struct {
239 // Additional required dependencies to add to -hostdex modules.
240 Required []string
241 }
242 }
243
244 // When targeting 1.9 and above, override the modules to use with --system,
245 // otherwise provides defaults libraries to add to the bootclasspath.
246 System_modules *string
247
Jaewoong Jung26342642021-03-17 15:56:23 -0700248 IsSDKLibrary bool `blueprint:"mutated"`
249
250 // If true, generate the signature file of APK Signing Scheme V4, along side the signed APK file.
251 // Defaults to false.
252 V4_signature *bool
253
254 // Only for libraries created by a sysprop_library module, SyspropPublicStub is the name of the
255 // public stubs library.
256 SyspropPublicStub string `blueprint:"mutated"`
257}
258
Jooyung Han01d80d82022-01-08 12:16:32 +0900259// Device properties that can be overridden by overriding module (e.g. override_android_app)
260type OverridableDeviceProperties struct {
261 // set the name of the output. If not set, `name` is used.
262 // To override a module with this property set, overriding module might need to set this as well.
263 // Otherwise, both the overridden and the overriding modules will have the same output name, which
264 // can cause the duplicate output error.
265 Stem *string
266}
267
Jaewoong Jung26342642021-03-17 15:56:23 -0700268// Functionality common to Module and Import
269//
270// It is embedded in Module so its functionality can be used by methods in Module
271// but it is currently only initialized by Import and Library.
272type embeddableInModuleAndImport struct {
273
274 // Functionality related to this being used as a component of a java_sdk_library.
275 EmbeddableSdkLibraryComponent
276}
277
Paul Duffin71b33cc2021-06-23 11:39:47 +0100278func (e *embeddableInModuleAndImport) initModuleAndImport(module android.Module) {
279 e.initSdkLibraryComponent(module)
Jaewoong Jung26342642021-03-17 15:56:23 -0700280}
281
282// Module/Import's DepIsInSameApex(...) delegates to this method.
283//
284// This cannot implement DepIsInSameApex(...) directly as that leads to ambiguity with
285// the one provided by ApexModuleBase.
286func (e *embeddableInModuleAndImport) depIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
287 // dependencies other than the static linkage are all considered crossing APEX boundary
288 if staticLibTag == ctx.OtherModuleDependencyTag(dep) {
289 return true
290 }
291 return false
292}
293
Martin Stjernholm8be1e6d2021-09-15 03:34:04 +0100294// OptionalDexJarPath can be either unset, hold a valid path to a dex jar file,
295// or an invalid path describing the reason it is invalid.
296//
297// It is unset if a dex jar isn't applicable, i.e. no build rule has been
298// requested to create one.
299//
300// If a dex jar has been requested to be built then it is set, and it may be
301// either a valid android.Path, or invalid with a reason message. The latter
302// happens if the source that should produce the dex file isn't able to.
303//
304// E.g. it is invalid with a reason message if there is a prebuilt APEX that
305// could produce the dex jar through a deapexer module, but the APEX isn't
306// installable so doing so wouldn't be safe.
307type OptionalDexJarPath struct {
308 isSet bool
309 path android.OptionalPath
310}
311
312// IsSet returns true if a path has been set, either invalid or valid.
313func (o OptionalDexJarPath) IsSet() bool {
314 return o.isSet
315}
316
317// Valid returns true if there is a path that is valid.
318func (o OptionalDexJarPath) Valid() bool {
319 return o.isSet && o.path.Valid()
320}
321
322// Path returns the valid path, or panics if it's either not set or is invalid.
323func (o OptionalDexJarPath) Path() android.Path {
324 if !o.isSet {
325 panic("path isn't set")
326 }
327 return o.path.Path()
328}
329
330// PathOrNil returns the path if it's set and valid, or else nil.
331func (o OptionalDexJarPath) PathOrNil() android.Path {
332 if o.Valid() {
333 return o.Path()
334 }
335 return nil
336}
337
338// InvalidReason returns the reason for an invalid path, which is never "". It
339// returns "" for an unset or valid path.
340func (o OptionalDexJarPath) InvalidReason() string {
341 if !o.isSet {
342 return ""
343 }
344 return o.path.InvalidReason()
345}
346
347func (o OptionalDexJarPath) String() string {
348 if !o.isSet {
349 return "<unset>"
350 }
351 return o.path.String()
352}
353
354// makeUnsetDexJarPath returns an unset OptionalDexJarPath.
355func makeUnsetDexJarPath() OptionalDexJarPath {
356 return OptionalDexJarPath{isSet: false}
357}
358
359// makeDexJarPathFromOptionalPath returns an OptionalDexJarPath that is set with
360// the given OptionalPath, which may be valid or invalid.
361func makeDexJarPathFromOptionalPath(path android.OptionalPath) OptionalDexJarPath {
362 return OptionalDexJarPath{isSet: true, path: path}
363}
364
365// makeDexJarPathFromPath returns an OptionalDexJarPath that is set with the
366// valid given path. It returns an unset OptionalDexJarPath if the given path is
367// nil.
368func makeDexJarPathFromPath(path android.Path) OptionalDexJarPath {
369 if path == nil {
370 return makeUnsetDexJarPath()
371 }
372 return makeDexJarPathFromOptionalPath(android.OptionalPathForPath(path))
373}
374
Jaewoong Jung26342642021-03-17 15:56:23 -0700375// Module contains the properties and members used by all java module types
376type Module struct {
377 android.ModuleBase
378 android.DefaultableModuleBase
379 android.ApexModuleBase
380 android.SdkBase
Wei Libafb6d62021-12-10 03:14:59 -0800381 android.BazelModuleBase
Jaewoong Jung26342642021-03-17 15:56:23 -0700382
383 // Functionality common to Module and Import.
384 embeddableInModuleAndImport
385
386 properties CommonProperties
387 protoProperties android.ProtoProperties
388 deviceProperties DeviceProperties
389
Jooyung Han01d80d82022-01-08 12:16:32 +0900390 overridableDeviceProperties OverridableDeviceProperties
391
Jaewoong Jung26342642021-03-17 15:56:23 -0700392 // jar file containing header classes including static library dependencies, suitable for
393 // inserting into the bootclasspath/classpath of another compile
394 headerJarFile android.Path
395
396 // jar file containing implementation classes including static library dependencies but no
397 // resources
398 implementationJarFile android.Path
399
400 // jar file containing only resources including from static library dependencies
401 resourceJar android.Path
402
403 // args and dependencies to package source files into a srcjar
404 srcJarArgs []string
405 srcJarDeps android.Paths
406
407 // jar file containing implementation classes and resources including static library
408 // dependencies
409 implementationAndResourcesJar android.Path
410
411 // output file containing classes.dex and resources
Martin Stjernholm8be1e6d2021-09-15 03:34:04 +0100412 dexJarFile OptionalDexJarPath
Jaewoong Jung26342642021-03-17 15:56:23 -0700413
414 // output file containing uninstrumented classes that will be instrumented by jacoco
415 jacocoReportClassesFile android.Path
416
417 // output file of the module, which may be a classes jar or a dex jar
418 outputFile android.Path
419 extraOutputFiles android.Paths
420
421 exportAidlIncludeDirs android.Paths
422
423 logtagsSrcs android.Paths
424
425 // installed file for binary dependency
426 installFile android.Path
427
Colin Cross3108ce12021-11-10 14:38:50 -0800428 // installed file for hostdex copy
429 hostdexInstallFile android.InstallPath
430
Jaewoong Jung26342642021-03-17 15:56:23 -0700431 // list of .java files and srcjars that was passed to javac
432 compiledJavaSrcs android.Paths
433 compiledSrcJars android.Paths
434
435 // manifest file to use instead of properties.Manifest
436 overrideManifest android.OptionalPath
437
438 // map of SDK version to class loader context
439 classLoaderContexts dexpreopt.ClassLoaderContextMap
440
441 // list of plugins that this java module is exporting
442 exportedPluginJars android.Paths
443
444 // list of plugins that this java module is exporting
445 exportedPluginClasses []string
446
447 // if true, the exported plugins generate API and require disabling turbine.
448 exportedDisableTurbine bool
449
450 // list of source files, collected from srcFiles with unique java and all kt files,
451 // will be used by android.IDEInfo struct
452 expandIDEInfoCompiledSrcs []string
453
454 // expanded Jarjar_rules
455 expandJarjarRules android.Path
456
Jaewoong Jung26342642021-03-17 15:56:23 -0700457 // Extra files generated by the module type to be added as java resources.
458 extraResources android.Paths
459
460 hiddenAPI
461 dexer
462 dexpreopter
463 usesLibrary
464 linter
465
466 // list of the xref extraction files
467 kytheFiles android.Paths
468
469 // Collect the module directory for IDE info in java/jdeps.go.
470 modulePaths []string
471
472 hideApexVariantFromMake bool
Jiyong Park92315372021-04-02 08:45:46 +0900473
474 sdkVersion android.SdkSpec
475 minSdkVersion android.SdkSpec
satayev0a420e72021-11-29 17:25:52 +0000476 maxSdkVersion android.SdkSpec
Romain Jobredeaux3ec36ad42021-10-29 13:08:48 -0400477
478 sourceExtensions []string
Jaewoong Jung26342642021-03-17 15:56:23 -0700479}
480
Jiyong Park92315372021-04-02 08:45:46 +0900481func (j *Module) CheckStableSdkVersion(ctx android.BaseModuleContext) error {
482 sdkVersion := j.SdkVersion(ctx)
Jiyong Parkf1691d22021-03-29 20:11:58 +0900483 if sdkVersion.Stable() {
Jaewoong Jung26342642021-03-17 15:56:23 -0700484 return nil
485 }
Jiyong Parkf1691d22021-03-29 20:11:58 +0900486 if sdkVersion.Kind == android.SdkCorePlatform {
Paul Duffin1ea7c9f2021-03-15 09:39:13 +0000487 if useLegacyCorePlatformApi(ctx, j.BaseModuleName()) {
Jaewoong Jung26342642021-03-17 15:56:23 -0700488 return fmt.Errorf("non stable SDK %v - uses legacy core platform", sdkVersion)
489 } else {
490 // Treat stable core platform as stable.
491 return nil
492 }
493 } else {
494 return fmt.Errorf("non stable SDK %v", sdkVersion)
495 }
496}
497
498// checkSdkVersions enforces restrictions around SDK dependencies.
499func (j *Module) checkSdkVersions(ctx android.ModuleContext) {
500 if j.RequiresStableAPIs(ctx) {
Jiyong Parkf1691d22021-03-29 20:11:58 +0900501 if sc, ok := ctx.Module().(android.SdkContext); ok {
Jiyong Park92315372021-04-02 08:45:46 +0900502 if !sc.SdkVersion(ctx).Specified() {
Jaewoong Jung26342642021-03-17 15:56:23 -0700503 ctx.PropertyErrorf("sdk_version",
504 "sdk_version must have a value when the module is located at vendor or product(only if PRODUCT_ENFORCE_PRODUCT_PARTITION_INTERFACE is set).")
505 }
506 }
507 }
508
509 // Make sure this module doesn't statically link to modules with lower-ranked SDK link type.
510 // See rank() for details.
511 ctx.VisitDirectDeps(func(module android.Module) {
512 tag := ctx.OtherModuleDependencyTag(module)
513 switch module.(type) {
514 // TODO(satayev): cover other types as well, e.g. imports
515 case *Library, *AndroidLibrary:
516 switch tag {
517 case bootClasspathTag, libTag, staticLibTag, java9LibTag:
518 j.checkSdkLinkType(ctx, module.(moduleWithSdkDep), tag.(dependencyTag))
519 }
520 }
521 })
522}
523
524func (j *Module) checkPlatformAPI(ctx android.ModuleContext) {
Jiyong Parkf1691d22021-03-29 20:11:58 +0900525 if sc, ok := ctx.Module().(android.SdkContext); ok {
Jaewoong Jung26342642021-03-17 15:56:23 -0700526 usePlatformAPI := proptools.Bool(j.deviceProperties.Platform_apis)
Jiyong Park92315372021-04-02 08:45:46 +0900527 sdkVersionSpecified := sc.SdkVersion(ctx).Specified()
Jaewoong Jung26342642021-03-17 15:56:23 -0700528 if usePlatformAPI && sdkVersionSpecified {
Spandan Das60999342021-11-16 04:15:33 +0000529 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 -0700530 } else if !usePlatformAPI && !sdkVersionSpecified {
Spandan Das60999342021-11-16 04:15:33 +0000531 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 -0700532 }
533
534 }
535}
536
537func (j *Module) addHostProperties() {
538 j.AddProperties(
539 &j.properties,
540 &j.protoProperties,
541 &j.usesLibraryProperties,
542 )
543}
544
545func (j *Module) addHostAndDeviceProperties() {
546 j.addHostProperties()
547 j.AddProperties(
548 &j.deviceProperties,
Jooyung Han01d80d82022-01-08 12:16:32 +0900549 &j.overridableDeviceProperties,
Jaewoong Jung26342642021-03-17 15:56:23 -0700550 &j.dexer.dexProperties,
551 &j.dexpreoptProperties,
552 &j.linter.properties,
553 )
554}
555
556func (j *Module) OutputFiles(tag string) (android.Paths, error) {
557 switch tag {
558 case "":
559 return append(android.Paths{j.outputFile}, j.extraOutputFiles...), nil
560 case android.DefaultDistTag:
561 return android.Paths{j.outputFile}, nil
562 case ".jar":
563 return android.Paths{j.implementationAndResourcesJar}, nil
564 case ".proguard_map":
565 if j.dexer.proguardDictionary.Valid() {
566 return android.Paths{j.dexer.proguardDictionary.Path()}, nil
567 }
568 return nil, fmt.Errorf("%q was requested, but no output file was found.", tag)
569 default:
570 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
571 }
572}
573
574var _ android.OutputFileProducer = (*Module)(nil)
575
576func InitJavaModule(module android.DefaultableModule, hod android.HostOrDeviceSupported) {
577 initJavaModule(module, hod, false)
578}
579
580func InitJavaModuleMultiTargets(module android.DefaultableModule, hod android.HostOrDeviceSupported) {
581 initJavaModule(module, hod, true)
582}
583
584func initJavaModule(module android.DefaultableModule, hod android.HostOrDeviceSupported, multiTargets bool) {
585 multilib := android.MultilibCommon
586 if multiTargets {
587 android.InitAndroidMultiTargetsArchModule(module, hod, multilib)
588 } else {
589 android.InitAndroidArchModule(module, hod, multilib)
590 }
591 android.InitDefaultableModule(module)
592}
593
594func (j *Module) shouldInstrument(ctx android.BaseModuleContext) bool {
595 return j.properties.Instrument &&
596 ctx.Config().IsEnvTrue("EMMA_INSTRUMENT") &&
597 ctx.DeviceConfig().JavaCoverageEnabledForPath(ctx.ModuleDir())
598}
599
600func (j *Module) shouldInstrumentStatic(ctx android.BaseModuleContext) bool {
601 return j.shouldInstrument(ctx) &&
602 (ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_STATIC") ||
603 ctx.Config().UnbundledBuild())
604}
605
606func (j *Module) shouldInstrumentInApex(ctx android.BaseModuleContext) bool {
607 // Force enable the instrumentation for java code that is built for APEXes ...
608 // except for the jacocoagent itself (because instrumenting jacocoagent using jacocoagent
609 // doesn't make sense) or framework libraries (e.g. libraries found in the InstrumentFrameworkModules list) unless EMMA_INSTRUMENT_FRAMEWORK is true.
610 apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo)
611 isJacocoAgent := ctx.ModuleName() == "jacocoagent"
612 if j.DirectlyInAnyApex() && !isJacocoAgent && !apexInfo.IsForPlatform() {
613 if !inList(ctx.ModuleName(), config.InstrumentFrameworkModules) {
614 return true
615 } else if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
616 return true
617 }
618 }
619 return false
620}
621
Jiyong Park92315372021-04-02 08:45:46 +0900622func (j *Module) SdkVersion(ctx android.EarlyModuleContext) android.SdkSpec {
623 return android.SdkSpecFrom(ctx, String(j.deviceProperties.Sdk_version))
Jaewoong Jung26342642021-03-17 15:56:23 -0700624}
625
Jiyong Parkf1691d22021-03-29 20:11:58 +0900626func (j *Module) SystemModules() string {
Jaewoong Jung26342642021-03-17 15:56:23 -0700627 return proptools.String(j.deviceProperties.System_modules)
628}
629
Jiyong Park92315372021-04-02 08:45:46 +0900630func (j *Module) MinSdkVersion(ctx android.EarlyModuleContext) android.SdkSpec {
Jaewoong Jung26342642021-03-17 15:56:23 -0700631 if j.deviceProperties.Min_sdk_version != nil {
Jiyong Park92315372021-04-02 08:45:46 +0900632 return android.SdkSpecFrom(ctx, *j.deviceProperties.Min_sdk_version)
Jaewoong Jung26342642021-03-17 15:56:23 -0700633 }
Jiyong Park92315372021-04-02 08:45:46 +0900634 return j.SdkVersion(ctx)
Jaewoong Jung26342642021-03-17 15:56:23 -0700635}
636
satayev0a420e72021-11-29 17:25:52 +0000637func (j *Module) MaxSdkVersion(ctx android.EarlyModuleContext) android.SdkSpec {
638 maxSdkVersion := proptools.StringDefault(j.deviceProperties.Max_sdk_version, "")
639 // SdkSpecFrom returns SdkSpecPrivate for this, which may be confusing.
640 // TODO(b/208456999): ideally MaxSdkVersion should be an ApiLevel and not SdkSpec.
641 return android.SdkSpecFrom(ctx, maxSdkVersion)
642}
643
Jiyong Parkf1691d22021-03-29 20:11:58 +0900644func (j *Module) MinSdkVersionString() string {
Jiyong Park92315372021-04-02 08:45:46 +0900645 return j.minSdkVersion.Raw
646}
647
648func (j *Module) TargetSdkVersion(ctx android.EarlyModuleContext) android.SdkSpec {
649 if j.deviceProperties.Target_sdk_version != nil {
650 return android.SdkSpecFrom(ctx, *j.deviceProperties.Target_sdk_version)
651 }
652 return j.SdkVersion(ctx)
Jaewoong Jung26342642021-03-17 15:56:23 -0700653}
654
655func (j *Module) AvailableFor(what string) bool {
656 if what == android.AvailableToPlatform && Bool(j.deviceProperties.Hostdex) {
657 // Exception: for hostdex: true libraries, the platform variant is created
658 // even if it's not marked as available to platform. In that case, the platform
659 // variant is used only for the hostdex and not installed to the device.
660 return true
661 }
662 return j.ApexModuleBase.AvailableFor(what)
663}
664
665func (j *Module) deps(ctx android.BottomUpMutatorContext) {
666 if ctx.Device() {
667 j.linter.deps(ctx)
668
Jiyong Parkf1691d22021-03-29 20:11:58 +0900669 sdkDeps(ctx, android.SdkContext(j), j.dexer)
Jaewoong Jung26342642021-03-17 15:56:23 -0700670
671 if j.deviceProperties.SyspropPublicStub != "" {
672 // This is a sysprop implementation library that has a corresponding sysprop public
673 // stubs library, and a dependency on it so that dependencies on the implementation can
674 // be forwarded to the public stubs library when necessary.
675 ctx.AddVariationDependencies(nil, syspropPublicStubDepTag, j.deviceProperties.SyspropPublicStub)
676 }
677 }
678
679 libDeps := ctx.AddVariationDependencies(nil, libTag, j.properties.Libs...)
680 ctx.AddVariationDependencies(nil, staticLibTag, j.properties.Static_libs...)
681
682 // Add dependency on libraries that provide additional hidden api annotations.
683 ctx.AddVariationDependencies(nil, hiddenApiAnnotationsTag, j.properties.Hiddenapi_additional_annotations...)
684
685 if ctx.DeviceConfig().VndkVersion() != "" && ctx.Config().EnforceInterPartitionJavaSdkLibrary() {
686 // Require java_sdk_library at inter-partition java dependency to ensure stable
687 // interface between partitions. If inter-partition java_library dependency is detected,
688 // raise build error because java_library doesn't have a stable interface.
689 //
690 // Inputs:
691 // PRODUCT_ENFORCE_INTER_PARTITION_JAVA_SDK_LIBRARY
692 // if true, enable enforcement
693 // PRODUCT_INTER_PARTITION_JAVA_LIBRARY_ALLOWLIST
694 // exception list of java_library names to allow inter-partition dependency
695 for idx := range j.properties.Libs {
696 if libDeps[idx] == nil {
697 continue
698 }
699
700 if javaDep, ok := libDeps[idx].(javaSdkLibraryEnforceContext); ok {
701 // java_sdk_library is always allowed at inter-partition dependency.
702 // So, skip check.
703 if _, ok := javaDep.(*SdkLibrary); ok {
704 continue
705 }
706
707 j.checkPartitionsForJavaDependency(ctx, "libs", javaDep)
708 }
709 }
710 }
711
712 // For library dependencies that are component libraries (like stubs), add the implementation
713 // as a dependency (dexpreopt needs to be against the implementation library, not stubs).
714 for _, dep := range libDeps {
715 if dep != nil {
716 if component, ok := dep.(SdkLibraryComponentDependency); ok {
717 if lib := component.OptionalSdkLibraryImplementation(); lib != nil {
Ulya Trafimovichfc0f6e32021-08-12 16:16:11 +0100718 // Add library as optional if it's one of the optional compatibility libs.
Ulya Trafimovich0b1c70e2021-08-20 15:39:12 +0100719 optional := android.InList(*lib, dexpreopt.OptionalCompatUsesLibs)
720 tag := makeUsesLibraryDependencyTag(dexpreopt.AnySdkVersion, optional, true)
Ulya Trafimovichfc0f6e32021-08-12 16:16:11 +0100721 ctx.AddVariationDependencies(nil, tag, *lib)
Jaewoong Jung26342642021-03-17 15:56:23 -0700722 }
723 }
724 }
725 }
726
727 ctx.AddFarVariationDependencies(ctx.Config().BuildOSCommonTarget.Variations(), pluginTag, j.properties.Plugins...)
728 ctx.AddFarVariationDependencies(ctx.Config().BuildOSCommonTarget.Variations(), errorpronePluginTag, j.properties.Errorprone.Extra_check_modules...)
729 ctx.AddFarVariationDependencies(ctx.Config().BuildOSCommonTarget.Variations(), exportedPluginTag, j.properties.Exported_plugins...)
730
731 android.ProtoDeps(ctx, &j.protoProperties)
732 if j.hasSrcExt(".proto") {
733 protoDeps(ctx, &j.protoProperties)
734 }
735
736 if j.hasSrcExt(".kt") {
737 // TODO(ccross): move this to a mutator pass that can tell if generated sources contain
738 // Kotlin files
739 ctx.AddVariationDependencies(nil, kotlinStdlibTag,
740 "kotlin-stdlib", "kotlin-stdlib-jdk7", "kotlin-stdlib-jdk8")
741 if len(j.properties.Plugins) > 0 {
742 ctx.AddVariationDependencies(nil, kotlinAnnotationsTag, "kotlin-annotations")
743 }
744 }
745
746 // Framework libraries need special handling in static coverage builds: they should not have
747 // static dependency on jacoco, otherwise there would be multiple conflicting definitions of
748 // the same jacoco classes coming from different bootclasspath jars.
749 if inList(ctx.ModuleName(), config.InstrumentFrameworkModules) {
750 if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
751 j.properties.Instrument = true
752 }
753 } else if j.shouldInstrumentStatic(ctx) {
754 ctx.AddVariationDependencies(nil, staticLibTag, "jacocoagent")
755 }
Colin Crossa1ff7c62021-09-17 14:11:52 -0700756
757 if j.useCompose() {
758 ctx.AddVariationDependencies(ctx.Config().BuildOSCommonTarget.Variations(), kotlinPluginTag,
759 "androidx.compose.compiler_compiler-hosted")
760 }
Jaewoong Jung26342642021-03-17 15:56:23 -0700761}
762
763func hasSrcExt(srcs []string, ext string) bool {
764 for _, src := range srcs {
765 if filepath.Ext(src) == ext {
766 return true
767 }
768 }
769
770 return false
771}
772
773func (j *Module) hasSrcExt(ext string) bool {
774 return hasSrcExt(j.properties.Srcs, ext)
775}
776
777func (j *Module) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.OptionalPath,
778 aidlIncludeDirs android.Paths) (string, android.Paths) {
779
780 aidlIncludes := android.PathsForModuleSrc(ctx, j.deviceProperties.Aidl.Local_include_dirs)
781 aidlIncludes = append(aidlIncludes,
782 android.PathsForModuleSrc(ctx, j.deviceProperties.Aidl.Export_include_dirs)...)
783 aidlIncludes = append(aidlIncludes,
784 android.PathsForSource(ctx, j.deviceProperties.Aidl.Include_dirs)...)
785
786 var flags []string
787 var deps android.Paths
788
789 flags = append(flags, j.deviceProperties.Aidl.Flags...)
790
791 if aidlPreprocess.Valid() {
792 flags = append(flags, "-p"+aidlPreprocess.String())
793 deps = append(deps, aidlPreprocess.Path())
794 } else if len(aidlIncludeDirs) > 0 {
795 flags = append(flags, android.JoinWithPrefix(aidlIncludeDirs.Strings(), "-I"))
796 }
797
798 if len(j.exportAidlIncludeDirs) > 0 {
799 flags = append(flags, android.JoinWithPrefix(j.exportAidlIncludeDirs.Strings(), "-I"))
800 }
801
802 if len(aidlIncludes) > 0 {
803 flags = append(flags, android.JoinWithPrefix(aidlIncludes.Strings(), "-I"))
804 }
805
806 flags = append(flags, "-I"+android.PathForModuleSrc(ctx).String())
807 if src := android.ExistentPathForSource(ctx, ctx.ModuleDir(), "src"); src.Valid() {
808 flags = append(flags, "-I"+src.String())
809 }
810
811 if Bool(j.deviceProperties.Aidl.Generate_traces) {
812 flags = append(flags, "-t")
813 }
814
815 if Bool(j.deviceProperties.Aidl.Generate_get_transaction_name) {
816 flags = append(flags, "--transaction_names")
817 }
818
Jooyung Han07f70c02021-11-06 07:08:45 +0900819 aidlMinSdkVersion := j.MinSdkVersion(ctx).ApiLevel.String()
820 flags = append(flags, "--min_sdk_version="+aidlMinSdkVersion)
821
Jaewoong Jung26342642021-03-17 15:56:23 -0700822 return strings.Join(flags, " "), deps
823}
824
825func (j *Module) collectBuilderFlags(ctx android.ModuleContext, deps deps) javaBuilderFlags {
826
827 var flags javaBuilderFlags
828
829 // javaVersion flag.
Jiyong Parkf1691d22021-03-29 20:11:58 +0900830 flags.javaVersion = getJavaVersion(ctx, String(j.properties.Java_version), android.SdkContext(j))
Jaewoong Jung26342642021-03-17 15:56:23 -0700831
Cole Faust2b1536e2021-06-18 12:25:54 -0700832 epEnabled := j.properties.Errorprone.Enabled
833 if (ctx.Config().RunErrorProne() && epEnabled == nil) || Bool(epEnabled) {
Jaewoong Jung26342642021-03-17 15:56:23 -0700834 if config.ErrorProneClasspath == nil && ctx.Config().TestProductVariables == nil {
835 ctx.ModuleErrorf("cannot build with Error Prone, missing external/error_prone?")
836 }
837
838 errorProneFlags := []string{
839 "-Xplugin:ErrorProne",
840 "${config.ErrorProneChecks}",
841 }
842 errorProneFlags = append(errorProneFlags, j.properties.Errorprone.Javacflags...)
843
844 flags.errorProneExtraJavacFlags = "${config.ErrorProneFlags} " +
845 "'" + strings.Join(errorProneFlags, " ") + "'"
846 flags.errorProneProcessorPath = classpath(android.PathsForSource(ctx, config.ErrorProneClasspath))
847 }
848
849 // classpath
850 flags.bootClasspath = append(flags.bootClasspath, deps.bootClasspath...)
851 flags.classpath = append(flags.classpath, deps.classpath...)
852 flags.java9Classpath = append(flags.java9Classpath, deps.java9Classpath...)
853 flags.processorPath = append(flags.processorPath, deps.processorPath...)
854 flags.errorProneProcessorPath = append(flags.errorProneProcessorPath, deps.errorProneProcessorPath...)
855
856 flags.processors = append(flags.processors, deps.processorClasses...)
857 flags.processors = android.FirstUniqueStrings(flags.processors)
858
859 if len(flags.bootClasspath) == 0 && ctx.Host() && !flags.javaVersion.usesJavaModules() &&
Jiyong Parkf1691d22021-03-29 20:11:58 +0900860 decodeSdkDep(ctx, android.SdkContext(j)).hasStandardLibs() {
Jaewoong Jung26342642021-03-17 15:56:23 -0700861 // Give host-side tools a version of OpenJDK's standard libraries
862 // close to what they're targeting. As of Dec 2017, AOSP is only
863 // bundling OpenJDK 8 and 9, so nothing < 8 is available.
864 //
865 // When building with OpenJDK 8, the following should have no
866 // effect since those jars would be available by default.
867 //
868 // When building with OpenJDK 9 but targeting a version < 1.8,
869 // putting them on the bootclasspath means that:
870 // a) code can't (accidentally) refer to OpenJDK 9 specific APIs
871 // b) references to existing APIs are not reinterpreted in an
872 // OpenJDK 9-specific way, eg. calls to subclasses of
873 // java.nio.Buffer as in http://b/70862583
874 java8Home := ctx.Config().Getenv("ANDROID_JAVA8_HOME")
875 flags.bootClasspath = append(flags.bootClasspath,
876 android.PathForSource(ctx, java8Home, "jre/lib/jce.jar"),
877 android.PathForSource(ctx, java8Home, "jre/lib/rt.jar"))
878 if Bool(j.properties.Use_tools_jar) {
879 flags.bootClasspath = append(flags.bootClasspath,
880 android.PathForSource(ctx, java8Home, "lib/tools.jar"))
881 }
882 }
883
884 // systemModules
885 flags.systemModules = deps.systemModules
886
887 // aidl flags.
888 flags.aidlFlags, flags.aidlDeps = j.aidlFlags(ctx, deps.aidlPreprocess, deps.aidlIncludeDirs)
889
890 return flags
891}
892
893func (j *Module) collectJavacFlags(
894 ctx android.ModuleContext, flags javaBuilderFlags, srcFiles android.Paths) javaBuilderFlags {
895 // javac flags.
896 javacFlags := j.properties.Javacflags
897
898 if ctx.Config().MinimizeJavaDebugInfo() && !ctx.Host() {
899 // For non-host binaries, override the -g flag passed globally to remove
900 // local variable debug info to reduce disk and memory usage.
901 javacFlags = append(javacFlags, "-g:source,lines")
902 }
903 javacFlags = append(javacFlags, "-Xlint:-dep-ann")
904
905 if flags.javaVersion.usesJavaModules() {
906 javacFlags = append(javacFlags, j.properties.Openjdk9.Javacflags...)
907
908 if j.properties.Patch_module != nil {
909 // Manually specify build directory in case it is not under the repo root.
910 // (javac doesn't seem to expand into symbolic links when searching for patch-module targets, so
911 // just adding a symlink under the root doesn't help.)
Lukacs T. Berki9f6c24a2021-08-26 15:07:24 +0200912 patchPaths := []string{".", ctx.Config().SoongOutDir()}
Jaewoong Jung26342642021-03-17 15:56:23 -0700913
914 // b/150878007
915 //
916 // Workaround to support *Bazel-executed* JDK9 javac in Bazel's
917 // execution root for --patch-module. If this javac command line is
918 // invoked within Bazel's execution root working directory, the top
919 // level directories (e.g. libcore/, tools/, frameworks/) are all
920 // symlinks. JDK9 javac does not traverse into symlinks, which causes
921 // --patch-module to fail source file lookups when invoked in the
922 // execution root.
923 //
924 // Short of patching javac or enumerating *all* directories as possible
925 // input dirs, manually add the top level dir of the source files to be
926 // compiled.
927 topLevelDirs := map[string]bool{}
928 for _, srcFilePath := range srcFiles {
929 srcFileParts := strings.Split(srcFilePath.String(), "/")
930 // Ignore source files that are already in the top level directory
931 // as well as generated files in the out directory. The out
932 // directory may be an absolute path, which means srcFileParts[0] is the
933 // empty string, so check that as well. Note that "out" in Bazel's execution
934 // root is *not* a symlink, which doesn't cause problems for --patch-modules
935 // anyway, so it's fine to not apply this workaround for generated
936 // source files.
937 if len(srcFileParts) > 1 &&
938 srcFileParts[0] != "" &&
939 srcFileParts[0] != "out" {
940 topLevelDirs[srcFileParts[0]] = true
941 }
942 }
943 patchPaths = append(patchPaths, android.SortedStringKeys(topLevelDirs)...)
944
945 classPath := flags.classpath.FormJavaClassPath("")
946 if classPath != "" {
947 patchPaths = append(patchPaths, classPath)
948 }
949 javacFlags = append(
950 javacFlags,
951 "--patch-module="+String(j.properties.Patch_module)+"="+strings.Join(patchPaths, ":"))
952 }
953 }
954
955 if len(javacFlags) > 0 {
956 // optimization.
957 ctx.Variable(pctx, "javacFlags", strings.Join(javacFlags, " "))
958 flags.javacFlags = "$javacFlags"
959 }
960
961 return flags
962}
963
Romain Jobredeaux3ec36ad42021-10-29 13:08:48 -0400964func (j *Module) AddJSONData(d *map[string]interface{}) {
965 (&j.ModuleBase).AddJSONData(d)
966 (*d)["Java"] = map[string]interface{}{
967 "SourceExtensions": j.sourceExtensions,
968 }
969
970}
971
Jaewoong Jung26342642021-03-17 15:56:23 -0700972func (j *Module) compile(ctx android.ModuleContext, aaptSrcJar android.Path) {
973 j.exportAidlIncludeDirs = android.PathsForModuleSrc(ctx, j.deviceProperties.Aidl.Export_include_dirs)
974
975 deps := j.collectDeps(ctx)
976 flags := j.collectBuilderFlags(ctx, deps)
977
978 if flags.javaVersion.usesJavaModules() {
979 j.properties.Srcs = append(j.properties.Srcs, j.properties.Openjdk9.Srcs...)
980 }
Sorin Basca9347ae32021-12-20 11:51:24 +0000981
Jaewoong Jung26342642021-03-17 15:56:23 -0700982 srcFiles := android.PathsForModuleSrcExcludes(ctx, j.properties.Srcs, j.properties.Exclude_srcs)
Romain Jobredeaux3ec36ad42021-10-29 13:08:48 -0400983 j.sourceExtensions = []string{}
984 for _, ext := range []string{".kt", ".proto", ".aidl", ".java", ".logtags"} {
985 if hasSrcExt(srcFiles.Strings(), ext) {
986 j.sourceExtensions = append(j.sourceExtensions, ext)
987 }
988 }
Jaewoong Jung26342642021-03-17 15:56:23 -0700989 if hasSrcExt(srcFiles.Strings(), ".proto") {
990 flags = protoFlags(ctx, &j.properties, &j.protoProperties, flags)
991 }
992
993 kotlinCommonSrcFiles := android.PathsForModuleSrcExcludes(ctx, j.properties.Common_srcs, nil)
994 if len(kotlinCommonSrcFiles.FilterOutByExt(".kt")) > 0 {
995 ctx.PropertyErrorf("common_srcs", "common_srcs must be .kt files")
996 }
997
998 srcFiles = j.genSources(ctx, srcFiles, flags)
999
1000 // Collect javac flags only after computing the full set of srcFiles to
1001 // ensure that the --patch-module lookup paths are complete.
1002 flags = j.collectJavacFlags(ctx, flags, srcFiles)
1003
1004 srcJars := srcFiles.FilterByExt(".srcjar")
1005 srcJars = append(srcJars, deps.srcJars...)
1006 if aaptSrcJar != nil {
1007 srcJars = append(srcJars, aaptSrcJar)
1008 }
Colin Crossb0ef30a2021-06-29 10:42:00 -07001009 srcFiles = srcFiles.FilterOutByExt(".srcjar")
Jaewoong Jung26342642021-03-17 15:56:23 -07001010
1011 if j.properties.Jarjar_rules != nil {
1012 j.expandJarjarRules = android.PathForModuleSrc(ctx, *j.properties.Jarjar_rules)
1013 }
1014
1015 jarName := ctx.ModuleName() + ".jar"
1016
1017 javaSrcFiles := srcFiles.FilterByExt(".java")
1018 var uniqueSrcFiles android.Paths
1019 set := make(map[string]bool)
1020 for _, v := range javaSrcFiles {
1021 if _, found := set[v.String()]; !found {
1022 set[v.String()] = true
1023 uniqueSrcFiles = append(uniqueSrcFiles, v)
1024 }
1025 }
1026
1027 // Collect .java files for AIDEGen
1028 j.expandIDEInfoCompiledSrcs = append(j.expandIDEInfoCompiledSrcs, uniqueSrcFiles.Strings()...)
1029
1030 var kotlinJars android.Paths
1031
1032 if srcFiles.HasExt(".kt") {
1033 // user defined kotlin flags.
1034 kotlincFlags := j.properties.Kotlincflags
1035 CheckKotlincFlags(ctx, kotlincFlags)
1036
Aurimas Liutikas24a987f2021-05-17 17:47:10 +00001037 // Workaround for KT-46512
1038 kotlincFlags = append(kotlincFlags, "-Xsam-conversions=class")
Jaewoong Jung26342642021-03-17 15:56:23 -07001039
1040 // If there are kotlin files, compile them first but pass all the kotlin and java files
1041 // kotlinc will use the java files to resolve types referenced by the kotlin files, but
1042 // won't emit any classes for them.
1043 kotlincFlags = append(kotlincFlags, "-no-stdlib")
1044 if ctx.Device() {
1045 kotlincFlags = append(kotlincFlags, "-no-jdk")
1046 }
Colin Crossa1ff7c62021-09-17 14:11:52 -07001047
1048 for _, plugin := range deps.kotlinPlugins {
1049 kotlincFlags = append(kotlincFlags, "-Xplugin="+plugin.String())
1050 }
1051 flags.kotlincDeps = append(flags.kotlincDeps, deps.kotlinPlugins...)
1052
Jaewoong Jung26342642021-03-17 15:56:23 -07001053 if len(kotlincFlags) > 0 {
1054 // optimization.
1055 ctx.Variable(pctx, "kotlincFlags", strings.Join(kotlincFlags, " "))
1056 flags.kotlincFlags += "$kotlincFlags"
1057 }
1058
1059 var kotlinSrcFiles android.Paths
1060 kotlinSrcFiles = append(kotlinSrcFiles, uniqueSrcFiles...)
1061 kotlinSrcFiles = append(kotlinSrcFiles, srcFiles.FilterByExt(".kt")...)
1062
1063 // Collect .kt files for AIDEGen
1064 j.expandIDEInfoCompiledSrcs = append(j.expandIDEInfoCompiledSrcs, srcFiles.FilterByExt(".kt").Strings()...)
1065 j.expandIDEInfoCompiledSrcs = append(j.expandIDEInfoCompiledSrcs, kotlinCommonSrcFiles.Strings()...)
1066
1067 flags.classpath = append(flags.classpath, deps.kotlinStdlib...)
1068 flags.classpath = append(flags.classpath, deps.kotlinAnnotations...)
1069
1070 flags.kotlincClasspath = append(flags.kotlincClasspath, flags.bootClasspath...)
1071 flags.kotlincClasspath = append(flags.kotlincClasspath, flags.classpath...)
1072
1073 if len(flags.processorPath) > 0 {
1074 // Use kapt for annotation processing
1075 kaptSrcJar := android.PathForModuleOut(ctx, "kapt", "kapt-sources.jar")
1076 kaptResJar := android.PathForModuleOut(ctx, "kapt", "kapt-res.jar")
1077 kotlinKapt(ctx, kaptSrcJar, kaptResJar, kotlinSrcFiles, kotlinCommonSrcFiles, srcJars, flags)
1078 srcJars = append(srcJars, kaptSrcJar)
1079 kotlinJars = append(kotlinJars, kaptResJar)
1080 // Disable annotation processing in javac, it's already been handled by kapt
1081 flags.processorPath = nil
1082 flags.processors = nil
1083 }
1084
1085 kotlinJar := android.PathForModuleOut(ctx, "kotlin", jarName)
1086 kotlinCompile(ctx, kotlinJar, kotlinSrcFiles, kotlinCommonSrcFiles, srcJars, flags)
1087 if ctx.Failed() {
1088 return
1089 }
1090
1091 // Make javac rule depend on the kotlinc rule
1092 flags.classpath = append(flags.classpath, kotlinJar)
1093
1094 kotlinJars = append(kotlinJars, kotlinJar)
1095 // Jar kotlin classes into the final jar after javac
1096 if BoolDefault(j.properties.Static_kotlin_stdlib, true) {
1097 kotlinJars = append(kotlinJars, deps.kotlinStdlib...)
1098 }
1099 }
1100
1101 jars := append(android.Paths(nil), kotlinJars...)
1102
1103 // Store the list of .java files that was passed to javac
1104 j.compiledJavaSrcs = uniqueSrcFiles
1105 j.compiledSrcJars = srcJars
1106
1107 enableSharding := false
Colin Cross3d56ed52021-11-18 22:23:12 -08001108 var headerJarFileWithoutDepsOrJarjar android.Path
Jaewoong Jung26342642021-03-17 15:56:23 -07001109 if ctx.Device() && !ctx.Config().IsEnvFalse("TURBINE_ENABLED") && !deps.disableTurbine {
1110 if j.properties.Javac_shard_size != nil && *(j.properties.Javac_shard_size) > 0 {
1111 enableSharding = true
1112 // Formerly, there was a check here that prevented annotation processors
1113 // from being used when sharding was enabled, as some annotation processors
1114 // do not function correctly in sharded environments. It was removed to
1115 // allow for the use of annotation processors that do function correctly
1116 // with sharding enabled. See: b/77284273.
1117 }
Colin Cross3d56ed52021-11-18 22:23:12 -08001118 headerJarFileWithoutDepsOrJarjar, j.headerJarFile =
Jaewoong Jung26342642021-03-17 15:56:23 -07001119 j.compileJavaHeader(ctx, uniqueSrcFiles, srcJars, deps, flags, jarName, kotlinJars)
1120 if ctx.Failed() {
1121 return
1122 }
1123 }
1124 if len(uniqueSrcFiles) > 0 || len(srcJars) > 0 {
1125 var extraJarDeps android.Paths
Cole Faust75fffb12021-06-13 15:23:16 -07001126 if Bool(j.properties.Errorprone.Enabled) {
1127 // If error-prone is enabled, enable errorprone flags on the regular
1128 // build.
1129 flags = enableErrorproneFlags(flags)
Cole Faust2b1536e2021-06-18 12:25:54 -07001130 } else if ctx.Config().RunErrorProne() && j.properties.Errorprone.Enabled == nil {
Cole Faust75fffb12021-06-13 15:23:16 -07001131 // Otherwise, if the RUN_ERROR_PRONE environment variable is set, create
1132 // a new jar file just for compiling with the errorprone compiler to.
1133 // This is because we don't want to cause the java files to get completely
1134 // rebuilt every time the state of the RUN_ERROR_PRONE variable changes.
1135 // We also don't want to run this if errorprone is enabled by default for
1136 // this module, or else we could have duplicated errorprone messages.
1137 errorproneFlags := enableErrorproneFlags(flags)
Jaewoong Jung26342642021-03-17 15:56:23 -07001138 errorprone := android.PathForModuleOut(ctx, "errorprone", jarName)
Cole Faust75fffb12021-06-13 15:23:16 -07001139
1140 transformJavaToClasses(ctx, errorprone, -1, uniqueSrcFiles, srcJars, errorproneFlags, nil,
1141 "errorprone", "errorprone")
1142
Jaewoong Jung26342642021-03-17 15:56:23 -07001143 extraJarDeps = append(extraJarDeps, errorprone)
1144 }
1145
1146 if enableSharding {
Colin Cross3d56ed52021-11-18 22:23:12 -08001147 if headerJarFileWithoutDepsOrJarjar != nil {
1148 flags.classpath = append(classpath{headerJarFileWithoutDepsOrJarjar}, flags.classpath...)
1149 }
Jaewoong Jung26342642021-03-17 15:56:23 -07001150 shardSize := int(*(j.properties.Javac_shard_size))
1151 var shardSrcs []android.Paths
1152 if len(uniqueSrcFiles) > 0 {
1153 shardSrcs = android.ShardPaths(uniqueSrcFiles, shardSize)
1154 for idx, shardSrc := range shardSrcs {
1155 classes := j.compileJavaClasses(ctx, jarName, idx, shardSrc,
1156 nil, flags, extraJarDeps)
1157 jars = append(jars, classes)
1158 }
1159 }
1160 if len(srcJars) > 0 {
1161 classes := j.compileJavaClasses(ctx, jarName, len(shardSrcs),
1162 nil, srcJars, flags, extraJarDeps)
1163 jars = append(jars, classes)
1164 }
1165 } else {
1166 classes := j.compileJavaClasses(ctx, jarName, -1, uniqueSrcFiles, srcJars, flags, extraJarDeps)
1167 jars = append(jars, classes)
1168 }
1169 if ctx.Failed() {
1170 return
1171 }
1172 }
1173
1174 j.srcJarArgs, j.srcJarDeps = resourcePathsToJarArgs(srcFiles), srcFiles
1175
1176 var includeSrcJar android.WritablePath
1177 if Bool(j.properties.Include_srcs) {
1178 includeSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+".srcjar")
1179 TransformResourcesToJar(ctx, includeSrcJar, j.srcJarArgs, j.srcJarDeps)
1180 }
1181
1182 dirArgs, dirDeps := ResourceDirsToJarArgs(ctx, j.properties.Java_resource_dirs,
1183 j.properties.Exclude_java_resource_dirs, j.properties.Exclude_java_resources)
1184 fileArgs, fileDeps := ResourceFilesToJarArgs(ctx, j.properties.Java_resources, j.properties.Exclude_java_resources)
1185 extraArgs, extraDeps := resourcePathsToJarArgs(j.extraResources), j.extraResources
1186
1187 var resArgs []string
1188 var resDeps android.Paths
1189
1190 resArgs = append(resArgs, dirArgs...)
1191 resDeps = append(resDeps, dirDeps...)
1192
1193 resArgs = append(resArgs, fileArgs...)
1194 resDeps = append(resDeps, fileDeps...)
1195
1196 resArgs = append(resArgs, extraArgs...)
1197 resDeps = append(resDeps, extraDeps...)
1198
1199 if len(resArgs) > 0 {
1200 resourceJar := android.PathForModuleOut(ctx, "res", jarName)
1201 TransformResourcesToJar(ctx, resourceJar, resArgs, resDeps)
1202 j.resourceJar = resourceJar
1203 if ctx.Failed() {
1204 return
1205 }
1206 }
1207
1208 var resourceJars android.Paths
1209 if j.resourceJar != nil {
1210 resourceJars = append(resourceJars, j.resourceJar)
1211 }
1212 if Bool(j.properties.Include_srcs) {
1213 resourceJars = append(resourceJars, includeSrcJar)
1214 }
1215 resourceJars = append(resourceJars, deps.staticResourceJars...)
1216
1217 if len(resourceJars) > 1 {
1218 combinedJar := android.PathForModuleOut(ctx, "res-combined", jarName)
1219 TransformJarsToJar(ctx, combinedJar, "for resources", resourceJars, android.OptionalPath{},
1220 false, nil, nil)
1221 j.resourceJar = combinedJar
1222 } else if len(resourceJars) == 1 {
1223 j.resourceJar = resourceJars[0]
1224 }
1225
1226 if len(deps.staticJars) > 0 {
1227 jars = append(jars, deps.staticJars...)
1228 }
1229
1230 manifest := j.overrideManifest
1231 if !manifest.Valid() && j.properties.Manifest != nil {
1232 manifest = android.OptionalPathForPath(android.PathForModuleSrc(ctx, *j.properties.Manifest))
1233 }
1234
1235 services := android.PathsForModuleSrc(ctx, j.properties.Services)
1236 if len(services) > 0 {
1237 servicesJar := android.PathForModuleOut(ctx, "services", jarName)
1238 var zipargs []string
1239 for _, file := range services {
1240 serviceFile := file.String()
1241 zipargs = append(zipargs, "-C", filepath.Dir(serviceFile), "-f", serviceFile)
1242 }
1243 rule := zip
1244 args := map[string]string{
1245 "jarArgs": "-P META-INF/services/ " + strings.Join(proptools.NinjaAndShellEscapeList(zipargs), " "),
1246 }
1247 if ctx.Config().UseRBE() && ctx.Config().IsEnvTrue("RBE_ZIP") {
1248 rule = zipRE
1249 args["implicits"] = strings.Join(services.Strings(), ",")
1250 }
1251 ctx.Build(pctx, android.BuildParams{
1252 Rule: rule,
1253 Output: servicesJar,
1254 Implicits: services,
1255 Args: args,
1256 })
1257 jars = append(jars, servicesJar)
1258 }
1259
1260 // Combine the classes built from sources, any manifests, and any static libraries into
1261 // classes.jar. If there is only one input jar this step will be skipped.
1262 var outputFile android.OutputPath
1263
1264 if len(jars) == 1 && !manifest.Valid() {
1265 // Optimization: skip the combine step as there is nothing to do
1266 // TODO(ccross): this leaves any module-info.class files, but those should only come from
1267 // prebuilt dependencies until we support modules in the platform build, so there shouldn't be
1268 // any if len(jars) == 1.
1269
1270 // Transform the single path to the jar into an OutputPath as that is required by the following
1271 // code.
1272 if moduleOutPath, ok := jars[0].(android.ModuleOutPath); ok {
1273 // The path contains an embedded OutputPath so reuse that.
1274 outputFile = moduleOutPath.OutputPath
1275 } else if outputPath, ok := jars[0].(android.OutputPath); ok {
1276 // The path is an OutputPath so reuse it directly.
1277 outputFile = outputPath
1278 } else {
1279 // The file is not in the out directory so create an OutputPath into which it can be copied
1280 // and which the following code can use to refer to it.
1281 combinedJar := android.PathForModuleOut(ctx, "combined", jarName)
1282 ctx.Build(pctx, android.BuildParams{
1283 Rule: android.Cp,
1284 Input: jars[0],
1285 Output: combinedJar,
1286 })
1287 outputFile = combinedJar.OutputPath
1288 }
1289 } else {
1290 combinedJar := android.PathForModuleOut(ctx, "combined", jarName)
1291 TransformJarsToJar(ctx, combinedJar, "for javac", jars, manifest,
1292 false, nil, nil)
1293 outputFile = combinedJar.OutputPath
1294 }
1295
1296 // jarjar implementation jar if necessary
1297 if j.expandJarjarRules != nil {
1298 // Transform classes.jar into classes-jarjar.jar
1299 jarjarFile := android.PathForModuleOut(ctx, "jarjar", jarName).OutputPath
1300 TransformJarJar(ctx, jarjarFile, outputFile, j.expandJarjarRules)
1301 outputFile = jarjarFile
1302
1303 // jarjar resource jar if necessary
1304 if j.resourceJar != nil {
1305 resourceJarJarFile := android.PathForModuleOut(ctx, "res-jarjar", jarName)
1306 TransformJarJar(ctx, resourceJarJarFile, j.resourceJar, j.expandJarjarRules)
1307 j.resourceJar = resourceJarJarFile
1308 }
1309
1310 if ctx.Failed() {
1311 return
1312 }
1313 }
1314
1315 // Check package restrictions if necessary.
1316 if len(j.properties.Permitted_packages) > 0 {
Paul Duffin08a18bf2021-10-01 13:19:58 +01001317 // Time stamp file created by the package check rule.
Jaewoong Jung26342642021-03-17 15:56:23 -07001318 pkgckFile := android.PathForModuleOut(ctx, "package-check.stamp")
Paul Duffin08a18bf2021-10-01 13:19:58 +01001319
1320 // Create a rule to copy the output jar to another path and add a validate dependency that
1321 // will check that the jar only contains the permitted packages. The new location will become
1322 // the output file of this module.
1323 inputFile := outputFile
1324 outputFile = android.PathForModuleOut(ctx, "package-check", jarName).OutputPath
1325 ctx.Build(pctx, android.BuildParams{
1326 Rule: android.Cp,
1327 Input: inputFile,
1328 Output: outputFile,
1329 // Make sure that any dependency on the output file will cause ninja to run the package check
1330 // rule.
1331 Validation: pkgckFile,
1332 })
1333
1334 // Check packages and create a timestamp file when complete.
Jaewoong Jung26342642021-03-17 15:56:23 -07001335 CheckJarPackages(ctx, pkgckFile, outputFile, j.properties.Permitted_packages)
Jaewoong Jung26342642021-03-17 15:56:23 -07001336
1337 if ctx.Failed() {
1338 return
1339 }
1340 }
1341
1342 j.implementationJarFile = outputFile
1343 if j.headerJarFile == nil {
1344 j.headerJarFile = j.implementationJarFile
1345 }
1346
1347 if j.shouldInstrumentInApex(ctx) {
1348 j.properties.Instrument = true
1349 }
1350
Yuntao Xu5b009ae2021-05-13 12:42:24 -07001351 // enforce syntax check to jacoco filters for any build (http://b/183622051)
1352 specs := j.jacocoModuleToZipCommand(ctx)
1353 if ctx.Failed() {
1354 return
1355 }
1356
Jaewoong Jung26342642021-03-17 15:56:23 -07001357 if j.shouldInstrument(ctx) {
Yuntao Xu5b009ae2021-05-13 12:42:24 -07001358 outputFile = j.instrument(ctx, flags, outputFile, jarName, specs)
Jaewoong Jung26342642021-03-17 15:56:23 -07001359 }
1360
1361 // merge implementation jar with resources if necessary
1362 implementationAndResourcesJar := outputFile
1363 if j.resourceJar != nil {
1364 jars := android.Paths{j.resourceJar, implementationAndResourcesJar}
1365 combinedJar := android.PathForModuleOut(ctx, "withres", jarName).OutputPath
1366 TransformJarsToJar(ctx, combinedJar, "for resources", jars, manifest,
1367 false, nil, nil)
1368 implementationAndResourcesJar = combinedJar
1369 }
1370
1371 j.implementationAndResourcesJar = implementationAndResourcesJar
1372
1373 // Enable dex compilation for the APEX variants, unless it is disabled explicitly
1374 apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo)
1375 if j.DirectlyInAnyApex() && !apexInfo.IsForPlatform() {
1376 if j.dexProperties.Compile_dex == nil {
1377 j.dexProperties.Compile_dex = proptools.BoolPtr(true)
1378 }
1379 if j.deviceProperties.Hostdex == nil {
1380 j.deviceProperties.Hostdex = proptools.BoolPtr(true)
1381 }
1382 }
1383
1384 if ctx.Device() && (Bool(j.properties.Installable) || Bool(j.dexProperties.Compile_dex)) {
1385 if j.hasCode(ctx) {
1386 if j.shouldInstrumentStatic(ctx) {
1387 j.dexer.extraProguardFlagFiles = append(j.dexer.extraProguardFlagFiles,
1388 android.PathForSource(ctx, "build/make/core/proguard.jacoco.flags"))
1389 }
1390 // Dex compilation
1391 var dexOutputFile android.OutputPath
Colin Crossa79a52c2021-08-04 10:52:44 -07001392 dexOutputFile = j.dexer.compileDex(ctx, flags, j.MinSdkVersion(ctx), implementationAndResourcesJar, jarName)
Jaewoong Jung26342642021-03-17 15:56:23 -07001393 if ctx.Failed() {
1394 return
1395 }
1396
Jaewoong Jung26342642021-03-17 15:56:23 -07001397 // merge dex jar with resources if necessary
1398 if j.resourceJar != nil {
1399 jars := android.Paths{dexOutputFile, j.resourceJar}
1400 combinedJar := android.PathForModuleOut(ctx, "dex-withres", jarName).OutputPath
1401 TransformJarsToJar(ctx, combinedJar, "for dex resources", jars, android.OptionalPath{},
1402 false, nil, nil)
1403 if *j.dexProperties.Uncompress_dex {
1404 combinedAlignedJar := android.PathForModuleOut(ctx, "dex-withres-aligned", jarName).OutputPath
1405 TransformZipAlign(ctx, combinedAlignedJar, combinedJar)
1406 dexOutputFile = combinedAlignedJar
1407 } else {
1408 dexOutputFile = combinedJar
1409 }
1410 }
1411
Paul Duffin4de94502021-05-16 05:21:16 +01001412 // Initialize the hiddenapi structure.
Martin Stjernholm8be1e6d2021-09-15 03:34:04 +01001413
1414 j.initHiddenAPI(ctx, makeDexJarPathFromPath(dexOutputFile), j.implementationJarFile, j.dexProperties.Uncompress_dex)
Paul Duffin4de94502021-05-16 05:21:16 +01001415
1416 // Encode hidden API flags in dex file, if needed.
1417 dexOutputFile = j.hiddenAPIEncodeDex(ctx, dexOutputFile)
1418
Martin Stjernholm8be1e6d2021-09-15 03:34:04 +01001419 j.dexJarFile = makeDexJarPathFromPath(dexOutputFile)
Jaewoong Jung26342642021-03-17 15:56:23 -07001420
1421 // Dexpreopting
1422 j.dexpreopt(ctx, dexOutputFile)
1423
1424 outputFile = dexOutputFile
1425 } else {
1426 // There is no code to compile into a dex jar, make sure the resources are propagated
1427 // to the APK if this is an app.
1428 outputFile = implementationAndResourcesJar
Martin Stjernholm8be1e6d2021-09-15 03:34:04 +01001429 j.dexJarFile = makeDexJarPathFromPath(j.resourceJar)
Jaewoong Jung26342642021-03-17 15:56:23 -07001430 }
1431
1432 if ctx.Failed() {
1433 return
1434 }
1435 } else {
1436 outputFile = implementationAndResourcesJar
1437 }
1438
1439 if ctx.Device() {
Jiyong Parkf1691d22021-03-29 20:11:58 +09001440 lintSDKVersionString := func(sdkSpec android.SdkSpec) string {
Jiyong Park54105c42021-03-31 18:17:53 +09001441 if v := sdkSpec.ApiLevel; !v.IsPreview() {
Jaewoong Jung26342642021-03-17 15:56:23 -07001442 return v.String()
1443 } else {
1444 return ctx.Config().DefaultAppTargetSdk(ctx).String()
1445 }
1446 }
1447
1448 j.linter.name = ctx.ModuleName()
1449 j.linter.srcs = srcFiles
1450 j.linter.srcJars = srcJars
1451 j.linter.classpath = append(append(android.Paths(nil), flags.bootClasspath...), flags.classpath...)
1452 j.linter.classes = j.implementationJarFile
Jiyong Park92315372021-04-02 08:45:46 +09001453 j.linter.minSdkVersion = lintSDKVersionString(j.MinSdkVersion(ctx))
1454 j.linter.targetSdkVersion = lintSDKVersionString(j.TargetSdkVersion(ctx))
1455 j.linter.compileSdkVersion = lintSDKVersionString(j.SdkVersion(ctx))
Pedro Loureiro18233a22021-06-08 18:11:21 +00001456 j.linter.compileSdkKind = j.SdkVersion(ctx).Kind
Jaewoong Jung26342642021-03-17 15:56:23 -07001457 j.linter.javaLanguageLevel = flags.javaVersion.String()
1458 j.linter.kotlinLanguageLevel = "1.3"
1459 if !apexInfo.IsForPlatform() && ctx.Config().UnbundledBuildApps() {
1460 j.linter.buildModuleReportZip = true
1461 }
1462 j.linter.lint(ctx)
1463 }
1464
1465 ctx.CheckbuildFile(outputFile)
1466
1467 ctx.SetProvider(JavaInfoProvider, JavaInfo{
1468 HeaderJars: android.PathsIfNonNil(j.headerJarFile),
1469 ImplementationAndResourcesJars: android.PathsIfNonNil(j.implementationAndResourcesJar),
1470 ImplementationJars: android.PathsIfNonNil(j.implementationJarFile),
1471 ResourceJars: android.PathsIfNonNil(j.resourceJar),
1472 AidlIncludeDirs: j.exportAidlIncludeDirs,
1473 SrcJarArgs: j.srcJarArgs,
1474 SrcJarDeps: j.srcJarDeps,
1475 ExportedPlugins: j.exportedPluginJars,
1476 ExportedPluginClasses: j.exportedPluginClasses,
1477 ExportedPluginDisableTurbine: j.exportedDisableTurbine,
1478 JacocoReportClassesFile: j.jacocoReportClassesFile,
1479 })
1480
1481 // Save the output file with no relative path so that it doesn't end up in a subdirectory when used as a resource
1482 j.outputFile = outputFile.WithoutRel()
1483}
1484
Colin Crossa1ff7c62021-09-17 14:11:52 -07001485func (j *Module) useCompose() bool {
1486 return android.InList("androidx.compose.runtime_runtime", j.properties.Static_libs)
1487}
1488
Cole Faust75fffb12021-06-13 15:23:16 -07001489// Returns a copy of the supplied flags, but with all the errorprone-related
1490// fields copied to the regular build's fields.
1491func enableErrorproneFlags(flags javaBuilderFlags) javaBuilderFlags {
1492 flags.processorPath = append(flags.errorProneProcessorPath, flags.processorPath...)
1493
1494 if len(flags.errorProneExtraJavacFlags) > 0 {
1495 if len(flags.javacFlags) > 0 {
1496 flags.javacFlags += " " + flags.errorProneExtraJavacFlags
1497 } else {
1498 flags.javacFlags = flags.errorProneExtraJavacFlags
1499 }
1500 }
1501 return flags
1502}
1503
Jaewoong Jung26342642021-03-17 15:56:23 -07001504func (j *Module) compileJavaClasses(ctx android.ModuleContext, jarName string, idx int,
1505 srcFiles, srcJars android.Paths, flags javaBuilderFlags, extraJarDeps android.Paths) android.WritablePath {
1506
1507 kzipName := pathtools.ReplaceExtension(jarName, "kzip")
1508 if idx >= 0 {
1509 kzipName = strings.TrimSuffix(jarName, filepath.Ext(jarName)) + strconv.Itoa(idx) + ".kzip"
1510 jarName += strconv.Itoa(idx)
1511 }
1512
1513 classes := android.PathForModuleOut(ctx, "javac", jarName).OutputPath
1514 TransformJavaToClasses(ctx, classes, idx, srcFiles, srcJars, flags, extraJarDeps)
1515
1516 if ctx.Config().EmitXrefRules() {
1517 extractionFile := android.PathForModuleOut(ctx, kzipName)
1518 emitXrefRule(ctx, extractionFile, idx, srcFiles, srcJars, flags, extraJarDeps)
1519 j.kytheFiles = append(j.kytheFiles, extractionFile)
1520 }
1521
1522 return classes
1523}
1524
1525// Check for invalid kotlinc flags. Only use this for flags explicitly passed by the user,
1526// since some of these flags may be used internally.
1527func CheckKotlincFlags(ctx android.ModuleContext, flags []string) {
1528 for _, flag := range flags {
1529 flag = strings.TrimSpace(flag)
1530
1531 if !strings.HasPrefix(flag, "-") {
1532 ctx.PropertyErrorf("kotlincflags", "Flag `%s` must start with `-`", flag)
1533 } else if strings.HasPrefix(flag, "-Xintellij-plugin-root") {
1534 ctx.PropertyErrorf("kotlincflags",
1535 "Bad flag: `%s`, only use internal compiler for consistency.", flag)
1536 } else if inList(flag, config.KotlincIllegalFlags) {
1537 ctx.PropertyErrorf("kotlincflags", "Flag `%s` already used by build system", flag)
1538 } else if flag == "-include-runtime" {
1539 ctx.PropertyErrorf("kotlincflags", "Bad flag: `%s`, do not include runtime.", flag)
1540 } else {
1541 args := strings.Split(flag, " ")
1542 if args[0] == "-kotlin-home" {
1543 ctx.PropertyErrorf("kotlincflags",
1544 "Bad flag: `%s`, kotlin home already set to default (path to kotlinc in the repo).", flag)
1545 }
1546 }
1547 }
1548}
1549
1550func (j *Module) compileJavaHeader(ctx android.ModuleContext, srcFiles, srcJars android.Paths,
1551 deps deps, flags javaBuilderFlags, jarName string,
Colin Cross3d56ed52021-11-18 22:23:12 -08001552 extraJars android.Paths) (headerJar, jarjarAndDepsHeaderJar android.Path) {
Jaewoong Jung26342642021-03-17 15:56:23 -07001553
1554 var jars android.Paths
1555 if len(srcFiles) > 0 || len(srcJars) > 0 {
1556 // Compile java sources into turbine.jar.
1557 turbineJar := android.PathForModuleOut(ctx, "turbine", jarName)
1558 TransformJavaToHeaderClasses(ctx, turbineJar, srcFiles, srcJars, flags)
1559 if ctx.Failed() {
1560 return nil, nil
1561 }
1562 jars = append(jars, turbineJar)
Colin Cross3d56ed52021-11-18 22:23:12 -08001563 headerJar = turbineJar
Jaewoong Jung26342642021-03-17 15:56:23 -07001564 }
1565
1566 jars = append(jars, extraJars...)
1567
1568 // Combine any static header libraries into classes-header.jar. If there is only
1569 // one input jar this step will be skipped.
1570 jars = append(jars, deps.staticHeaderJars...)
1571
1572 // we cannot skip the combine step for now if there is only one jar
1573 // since we have to strip META-INF/TRANSITIVE dir from turbine.jar
1574 combinedJar := android.PathForModuleOut(ctx, "turbine-combined", jarName)
1575 TransformJarsToJar(ctx, combinedJar, "for turbine", jars, android.OptionalPath{},
1576 false, nil, []string{"META-INF/TRANSITIVE"})
Colin Cross3d56ed52021-11-18 22:23:12 -08001577 jarjarAndDepsHeaderJar = combinedJar
Jaewoong Jung26342642021-03-17 15:56:23 -07001578
1579 if j.expandJarjarRules != nil {
1580 // Transform classes.jar into classes-jarjar.jar
1581 jarjarFile := android.PathForModuleOut(ctx, "turbine-jarjar", jarName)
Colin Cross3d56ed52021-11-18 22:23:12 -08001582 TransformJarJar(ctx, jarjarFile, jarjarAndDepsHeaderJar, j.expandJarjarRules)
1583 jarjarAndDepsHeaderJar = jarjarFile
Jaewoong Jung26342642021-03-17 15:56:23 -07001584 if ctx.Failed() {
1585 return nil, nil
1586 }
1587 }
1588
Colin Cross3d56ed52021-11-18 22:23:12 -08001589 return headerJar, jarjarAndDepsHeaderJar
Jaewoong Jung26342642021-03-17 15:56:23 -07001590}
1591
1592func (j *Module) instrument(ctx android.ModuleContext, flags javaBuilderFlags,
Yuntao Xu5b009ae2021-05-13 12:42:24 -07001593 classesJar android.Path, jarName string, specs string) android.OutputPath {
Jaewoong Jung26342642021-03-17 15:56:23 -07001594
1595 jacocoReportClassesFile := android.PathForModuleOut(ctx, "jacoco-report-classes", jarName)
1596 instrumentedJar := android.PathForModuleOut(ctx, "jacoco", jarName).OutputPath
1597
1598 jacocoInstrumentJar(ctx, instrumentedJar, jacocoReportClassesFile, classesJar, specs)
1599
1600 j.jacocoReportClassesFile = jacocoReportClassesFile
1601
1602 return instrumentedJar
1603}
1604
1605func (j *Module) HeaderJars() android.Paths {
1606 if j.headerJarFile == nil {
1607 return nil
1608 }
1609 return android.Paths{j.headerJarFile}
1610}
1611
1612func (j *Module) ImplementationJars() android.Paths {
1613 if j.implementationJarFile == nil {
1614 return nil
1615 }
1616 return android.Paths{j.implementationJarFile}
1617}
1618
Martin Stjernholm8be1e6d2021-09-15 03:34:04 +01001619func (j *Module) DexJarBuildPath() OptionalDexJarPath {
Jaewoong Jung26342642021-03-17 15:56:23 -07001620 return j.dexJarFile
1621}
1622
1623func (j *Module) DexJarInstallPath() android.Path {
1624 return j.installFile
1625}
1626
1627func (j *Module) ImplementationAndResourcesJars() android.Paths {
1628 if j.implementationAndResourcesJar == nil {
1629 return nil
1630 }
1631 return android.Paths{j.implementationAndResourcesJar}
1632}
1633
1634func (j *Module) AidlIncludeDirs() android.Paths {
1635 // exportAidlIncludeDirs is type android.Paths already
1636 return j.exportAidlIncludeDirs
1637}
1638
1639func (j *Module) ClassLoaderContexts() dexpreopt.ClassLoaderContextMap {
1640 return j.classLoaderContexts
1641}
1642
1643// Collect information for opening IDE project files in java/jdeps.go.
1644func (j *Module) IDEInfo(dpInfo *android.IdeInfo) {
1645 dpInfo.Deps = append(dpInfo.Deps, j.CompilerDeps()...)
1646 dpInfo.Srcs = append(dpInfo.Srcs, j.expandIDEInfoCompiledSrcs...)
1647 dpInfo.SrcJars = append(dpInfo.SrcJars, j.compiledSrcJars.Strings()...)
1648 dpInfo.Aidl_include_dirs = append(dpInfo.Aidl_include_dirs, j.deviceProperties.Aidl.Include_dirs...)
1649 if j.expandJarjarRules != nil {
1650 dpInfo.Jarjar_rules = append(dpInfo.Jarjar_rules, j.expandJarjarRules.String())
1651 }
1652 dpInfo.Paths = append(dpInfo.Paths, j.modulePaths...)
1653}
1654
1655func (j *Module) CompilerDeps() []string {
1656 jdeps := []string{}
1657 jdeps = append(jdeps, j.properties.Libs...)
1658 jdeps = append(jdeps, j.properties.Static_libs...)
1659 return jdeps
1660}
1661
1662func (j *Module) hasCode(ctx android.ModuleContext) bool {
1663 srcFiles := android.PathsForModuleSrcExcludes(ctx, j.properties.Srcs, j.properties.Exclude_srcs)
1664 return len(srcFiles) > 0 || len(ctx.GetDirectDepsWithTag(staticLibTag)) > 0
1665}
1666
1667// Implements android.ApexModule
1668func (j *Module) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
1669 return j.depIsInSameApex(ctx, dep)
1670}
1671
1672// Implements android.ApexModule
satayev758968a2021-12-06 11:42:40 +00001673func (j *Module) ShouldSupportSdkVersion(ctx android.BaseModuleContext, sdkVersion android.ApiLevel) error {
Jiyong Park92315372021-04-02 08:45:46 +09001674 sdkSpec := j.MinSdkVersion(ctx)
Jiyong Parkf1691d22021-03-29 20:11:58 +09001675 if !sdkSpec.Specified() {
Jaewoong Jung26342642021-03-17 15:56:23 -07001676 return fmt.Errorf("min_sdk_version is not specified")
1677 }
Jiyong Parkf1691d22021-03-29 20:11:58 +09001678 if sdkSpec.Kind == android.SdkCore {
Jaewoong Jung26342642021-03-17 15:56:23 -07001679 return nil
1680 }
Jooyung Han4c4da062021-06-23 10:23:16 +09001681 if sdkSpec.ApiLevel.GreaterThan(sdkVersion) {
1682 return fmt.Errorf("newer SDK(%v)", sdkSpec.ApiLevel)
Jaewoong Jung26342642021-03-17 15:56:23 -07001683 }
1684 return nil
1685}
1686
1687func (j *Module) Stem() string {
Jooyung Han01d80d82022-01-08 12:16:32 +09001688 return proptools.StringDefault(j.overridableDeviceProperties.Stem, j.Name())
Jaewoong Jung26342642021-03-17 15:56:23 -07001689}
1690
Jaewoong Jung26342642021-03-17 15:56:23 -07001691func (j *Module) JacocoReportClassesFile() android.Path {
1692 return j.jacocoReportClassesFile
1693}
1694
1695func (j *Module) IsInstallable() bool {
1696 return Bool(j.properties.Installable)
1697}
1698
1699type sdkLinkType int
1700
1701const (
1702 // TODO(jiyong) rename these for better readability. Make the allowed
1703 // and disallowed link types explicit
1704 // order is important here. See rank()
1705 javaCore sdkLinkType = iota
1706 javaSdk
1707 javaSystem
1708 javaModule
1709 javaSystemServer
1710 javaPlatform
1711)
1712
1713func (lt sdkLinkType) String() string {
1714 switch lt {
1715 case javaCore:
1716 return "core Java API"
1717 case javaSdk:
1718 return "Android API"
1719 case javaSystem:
1720 return "system API"
1721 case javaModule:
1722 return "module API"
1723 case javaSystemServer:
1724 return "system server API"
1725 case javaPlatform:
1726 return "private API"
1727 default:
1728 panic(fmt.Errorf("unrecognized linktype: %d", lt))
1729 }
1730}
1731
1732// rank determines the total order among sdkLinkType. An SDK link type of rank A can link to
1733// another SDK link type of rank B only when B <= A. For example, a module linking to Android SDK
1734// can't statically depend on modules that use Platform API.
1735func (lt sdkLinkType) rank() int {
1736 return int(lt)
1737}
1738
1739type moduleWithSdkDep interface {
1740 android.Module
Jiyong Park92315372021-04-02 08:45:46 +09001741 getSdkLinkType(ctx android.BaseModuleContext, name string) (ret sdkLinkType, stubs bool)
Jaewoong Jung26342642021-03-17 15:56:23 -07001742}
1743
Jiyong Park92315372021-04-02 08:45:46 +09001744func (m *Module) getSdkLinkType(ctx android.BaseModuleContext, name string) (ret sdkLinkType, stubs bool) {
Jaewoong Jung26342642021-03-17 15:56:23 -07001745 switch name {
1746 case "core.current.stubs", "legacy.core.platform.api.stubs", "stable.core.platform.api.stubs",
1747 "stub-annotations", "private-stub-annotations-jar",
1748 "core-lambda-stubs", "core-generated-annotation-stubs":
1749 return javaCore, true
1750 case "android_stubs_current":
1751 return javaSdk, true
1752 case "android_system_stubs_current":
1753 return javaSystem, true
1754 case "android_module_lib_stubs_current":
1755 return javaModule, true
1756 case "android_system_server_stubs_current":
1757 return javaSystemServer, true
1758 case "android_test_stubs_current":
1759 return javaSystem, true
1760 }
1761
1762 if stub, linkType := moduleStubLinkType(name); stub {
1763 return linkType, true
1764 }
1765
Jiyong Park92315372021-04-02 08:45:46 +09001766 ver := m.SdkVersion(ctx)
Jiyong Parkf1691d22021-03-29 20:11:58 +09001767 switch ver.Kind {
1768 case android.SdkCore:
Jaewoong Jung26342642021-03-17 15:56:23 -07001769 return javaCore, false
Jiyong Parkf1691d22021-03-29 20:11:58 +09001770 case android.SdkSystem:
Jaewoong Jung26342642021-03-17 15:56:23 -07001771 return javaSystem, false
Jiyong Parkf1691d22021-03-29 20:11:58 +09001772 case android.SdkPublic:
Jaewoong Jung26342642021-03-17 15:56:23 -07001773 return javaSdk, false
Jiyong Parkf1691d22021-03-29 20:11:58 +09001774 case android.SdkModule:
Jaewoong Jung26342642021-03-17 15:56:23 -07001775 return javaModule, false
Jiyong Parkf1691d22021-03-29 20:11:58 +09001776 case android.SdkSystemServer:
Jaewoong Jung26342642021-03-17 15:56:23 -07001777 return javaSystemServer, false
Jiyong Parkf1691d22021-03-29 20:11:58 +09001778 case android.SdkPrivate, android.SdkNone, android.SdkCorePlatform, android.SdkTest:
Jaewoong Jung26342642021-03-17 15:56:23 -07001779 return javaPlatform, false
1780 }
1781
Jiyong Parkf1691d22021-03-29 20:11:58 +09001782 if !ver.Valid() {
1783 panic(fmt.Errorf("sdk_version is invalid. got %q", ver.Raw))
Jaewoong Jung26342642021-03-17 15:56:23 -07001784 }
1785 return javaSdk, false
1786}
1787
1788// checkSdkLinkType make sures the given dependency doesn't have a lower SDK link type rank than
1789// this module's. See the comment on rank() for details and an example.
1790func (j *Module) checkSdkLinkType(
1791 ctx android.ModuleContext, dep moduleWithSdkDep, tag dependencyTag) {
1792 if ctx.Host() {
1793 return
1794 }
1795
Jiyong Park92315372021-04-02 08:45:46 +09001796 myLinkType, stubs := j.getSdkLinkType(ctx, ctx.ModuleName())
Jaewoong Jung26342642021-03-17 15:56:23 -07001797 if stubs {
1798 return
1799 }
Jiyong Park92315372021-04-02 08:45:46 +09001800 depLinkType, _ := dep.getSdkLinkType(ctx, ctx.OtherModuleName(dep))
Jaewoong Jung26342642021-03-17 15:56:23 -07001801
1802 if myLinkType.rank() < depLinkType.rank() {
1803 ctx.ModuleErrorf("compiles against %v, but dependency %q is compiling against %v. "+
1804 "In order to fix this, consider adjusting sdk_version: OR platform_apis: "+
1805 "property of the source or target module so that target module is built "+
1806 "with the same or smaller API set when compared to the source.",
1807 myLinkType, ctx.OtherModuleName(dep), depLinkType)
1808 }
1809}
1810
1811func (j *Module) collectDeps(ctx android.ModuleContext) deps {
1812 var deps deps
1813
1814 if ctx.Device() {
Jiyong Parkf1691d22021-03-29 20:11:58 +09001815 sdkDep := decodeSdkDep(ctx, android.SdkContext(j))
Jaewoong Jung26342642021-03-17 15:56:23 -07001816 if sdkDep.invalidVersion {
1817 ctx.AddMissingDependencies(sdkDep.bootclasspath)
1818 ctx.AddMissingDependencies(sdkDep.java9Classpath)
1819 } else if sdkDep.useFiles {
1820 // sdkDep.jar is actually equivalent to turbine header.jar.
1821 deps.classpath = append(deps.classpath, sdkDep.jars...)
1822 deps.aidlPreprocess = sdkDep.aidl
1823 } else {
1824 deps.aidlPreprocess = sdkDep.aidl
1825 }
1826 }
1827
Jiyong Park92315372021-04-02 08:45:46 +09001828 sdkLinkType, _ := j.getSdkLinkType(ctx, ctx.ModuleName())
Jaewoong Jung26342642021-03-17 15:56:23 -07001829
1830 ctx.VisitDirectDeps(func(module android.Module) {
1831 otherName := ctx.OtherModuleName(module)
1832 tag := ctx.OtherModuleDependencyTag(module)
1833
1834 if IsJniDepTag(tag) {
1835 // Handled by AndroidApp.collectAppDeps
1836 return
1837 }
1838 if tag == certificateTag {
1839 // Handled by AndroidApp.collectAppDeps
1840 return
1841 }
1842
1843 if dep, ok := module.(SdkLibraryDependency); ok {
1844 switch tag {
1845 case libTag:
Jiyong Park92315372021-04-02 08:45:46 +09001846 deps.classpath = append(deps.classpath, dep.SdkHeaderJars(ctx, j.SdkVersion(ctx))...)
Jaewoong Jung26342642021-03-17 15:56:23 -07001847 case staticLibTag:
1848 ctx.ModuleErrorf("dependency on java_sdk_library %q can only be in libs", otherName)
1849 }
1850 } else if ctx.OtherModuleHasProvider(module, JavaInfoProvider) {
1851 dep := ctx.OtherModuleProvider(module, JavaInfoProvider).(JavaInfo)
1852 if sdkLinkType != javaPlatform &&
1853 ctx.OtherModuleHasProvider(module, SyspropPublicStubInfoProvider) {
1854 // dep is a sysprop implementation library, but this module is not linking against
1855 // the platform, so it gets the sysprop public stubs library instead. Replace
1856 // dep with the JavaInfo from the SyspropPublicStubInfoProvider.
1857 syspropDep := ctx.OtherModuleProvider(module, SyspropPublicStubInfoProvider).(SyspropPublicStubInfo)
1858 dep = syspropDep.JavaInfo
1859 }
1860 switch tag {
1861 case bootClasspathTag:
1862 deps.bootClasspath = append(deps.bootClasspath, dep.HeaderJars...)
1863 case libTag, instrumentationForTag:
1864 deps.classpath = append(deps.classpath, dep.HeaderJars...)
1865 deps.aidlIncludeDirs = append(deps.aidlIncludeDirs, dep.AidlIncludeDirs...)
1866 addPlugins(&deps, dep.ExportedPlugins, dep.ExportedPluginClasses...)
1867 deps.disableTurbine = deps.disableTurbine || dep.ExportedPluginDisableTurbine
1868 case java9LibTag:
1869 deps.java9Classpath = append(deps.java9Classpath, dep.HeaderJars...)
1870 case staticLibTag:
1871 deps.classpath = append(deps.classpath, dep.HeaderJars...)
1872 deps.staticJars = append(deps.staticJars, dep.ImplementationJars...)
1873 deps.staticHeaderJars = append(deps.staticHeaderJars, dep.HeaderJars...)
1874 deps.staticResourceJars = append(deps.staticResourceJars, dep.ResourceJars...)
1875 deps.aidlIncludeDirs = append(deps.aidlIncludeDirs, dep.AidlIncludeDirs...)
1876 addPlugins(&deps, dep.ExportedPlugins, dep.ExportedPluginClasses...)
1877 // Turbine doesn't run annotation processors, so any module that uses an
1878 // annotation processor that generates API is incompatible with the turbine
1879 // optimization.
1880 deps.disableTurbine = deps.disableTurbine || dep.ExportedPluginDisableTurbine
1881 case pluginTag:
1882 if plugin, ok := module.(*Plugin); ok {
1883 if plugin.pluginProperties.Processor_class != nil {
1884 addPlugins(&deps, dep.ImplementationAndResourcesJars, *plugin.pluginProperties.Processor_class)
1885 } else {
1886 addPlugins(&deps, dep.ImplementationAndResourcesJars)
1887 }
1888 // Turbine doesn't run annotation processors, so any module that uses an
1889 // annotation processor that generates API is incompatible with the turbine
1890 // optimization.
1891 deps.disableTurbine = deps.disableTurbine || Bool(plugin.pluginProperties.Generates_api)
1892 } else {
1893 ctx.PropertyErrorf("plugins", "%q is not a java_plugin module", otherName)
1894 }
1895 case errorpronePluginTag:
1896 if _, ok := module.(*Plugin); ok {
1897 deps.errorProneProcessorPath = append(deps.errorProneProcessorPath, dep.ImplementationAndResourcesJars...)
1898 } else {
1899 ctx.PropertyErrorf("plugins", "%q is not a java_plugin module", otherName)
1900 }
1901 case exportedPluginTag:
1902 if plugin, ok := module.(*Plugin); ok {
1903 j.exportedPluginJars = append(j.exportedPluginJars, dep.ImplementationAndResourcesJars...)
1904 if plugin.pluginProperties.Processor_class != nil {
1905 j.exportedPluginClasses = append(j.exportedPluginClasses, *plugin.pluginProperties.Processor_class)
1906 }
1907 // Turbine doesn't run annotation processors, so any module that uses an
1908 // annotation processor that generates API is incompatible with the turbine
1909 // optimization.
1910 j.exportedDisableTurbine = Bool(plugin.pluginProperties.Generates_api)
1911 } else {
1912 ctx.PropertyErrorf("exported_plugins", "%q is not a java_plugin module", otherName)
1913 }
1914 case kotlinStdlibTag:
1915 deps.kotlinStdlib = append(deps.kotlinStdlib, dep.HeaderJars...)
1916 case kotlinAnnotationsTag:
1917 deps.kotlinAnnotations = dep.HeaderJars
Colin Crossa1ff7c62021-09-17 14:11:52 -07001918 case kotlinPluginTag:
1919 deps.kotlinPlugins = append(deps.kotlinPlugins, dep.ImplementationAndResourcesJars...)
Jaewoong Jung26342642021-03-17 15:56:23 -07001920 case syspropPublicStubDepTag:
1921 // This is a sysprop implementation library, forward the JavaInfoProvider from
1922 // the corresponding sysprop public stub library as SyspropPublicStubInfoProvider.
1923 ctx.SetProvider(SyspropPublicStubInfoProvider, SyspropPublicStubInfo{
1924 JavaInfo: dep,
1925 })
1926 }
1927 } else if dep, ok := module.(android.SourceFileProducer); ok {
1928 switch tag {
1929 case libTag:
1930 checkProducesJars(ctx, dep)
1931 deps.classpath = append(deps.classpath, dep.Srcs()...)
1932 case staticLibTag:
1933 checkProducesJars(ctx, dep)
1934 deps.classpath = append(deps.classpath, dep.Srcs()...)
1935 deps.staticJars = append(deps.staticJars, dep.Srcs()...)
1936 deps.staticHeaderJars = append(deps.staticHeaderJars, dep.Srcs()...)
1937 }
1938 } else {
1939 switch tag {
1940 case bootClasspathTag:
1941 // If a system modules dependency has been added to the bootclasspath
1942 // then add its libs to the bootclasspath.
1943 sm := module.(SystemModulesProvider)
1944 deps.bootClasspath = append(deps.bootClasspath, sm.HeaderJars()...)
1945
1946 case systemModulesTag:
1947 if deps.systemModules != nil {
1948 panic("Found two system module dependencies")
1949 }
1950 sm := module.(SystemModulesProvider)
1951 outputDir, outputDeps := sm.OutputDirAndDeps()
1952 deps.systemModules = &systemModules{outputDir, outputDeps}
Paul Duffin53a70a42022-01-11 14:35:55 +00001953
1954 case instrumentationForTag:
1955 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 -07001956 }
1957 }
1958
1959 addCLCFromDep(ctx, module, j.classLoaderContexts)
1960 })
1961
1962 return deps
1963}
1964
1965func addPlugins(deps *deps, pluginJars android.Paths, pluginClasses ...string) {
1966 deps.processorPath = append(deps.processorPath, pluginJars...)
1967 deps.processorClasses = append(deps.processorClasses, pluginClasses...)
1968}
1969
1970// TODO(b/132357300) Generalize SdkLibrarComponentDependency to non-SDK libraries and merge with
1971// this interface.
1972type ProvidesUsesLib interface {
1973 ProvidesUsesLib() *string
1974}
1975
1976func (j *Module) ProvidesUsesLib() *string {
1977 return j.usesLibraryProperties.Provides_uses_lib
1978}
satayev1c564cc2021-05-25 19:50:30 +01001979
1980type ModuleWithStem interface {
1981 Stem() string
1982}
1983
1984var _ ModuleWithStem = (*Module)(nil)
Wei Libafb6d62021-12-10 03:14:59 -08001985
1986func (j *Module) ConvertWithBp2build(ctx android.TopDownMutatorContext) {
1987 switch ctx.ModuleType() {
Sam Delmericofde9fb52022-01-28 20:53:38 +00001988 case "java_library", "java_library_host", "java_library_static":
Wei Libafb6d62021-12-10 03:14:59 -08001989 if lib, ok := ctx.Module().(*Library); ok {
1990 javaLibraryBp2Build(ctx, lib)
1991 }
1992 case "java_binary_host":
1993 if binary, ok := ctx.Module().(*Binary); ok {
1994 javaBinaryHostBp2Build(ctx, binary)
1995 }
1996 }
Wei Libafb6d62021-12-10 03:14:59 -08001997}