blob: 05dfde635abfeea4bc6398942c5a6c0f0774301a [file] [log] [blame]
Colin Cross3e3e72d2017-06-22 17:20:19 -07001// Copyright 2017 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 config
16
Colin Cross64162712017-08-08 13:17:59 -070017import (
Colin Cross3bc7ffa2017-11-22 16:19:37 -080018 "path/filepath"
19 "runtime"
Colin Cross64162712017-08-08 13:17:59 -070020 "strings"
21
22 _ "github.com/google/blueprint/bootstrap"
23
24 "android/soong/android"
Ramy Medhat1dcc27e2020-04-21 21:36:23 -040025 "android/soong/remoteexec"
Colin Cross64162712017-08-08 13:17:59 -070026)
Colin Cross3e3e72d2017-06-22 17:20:19 -070027
28var (
Colin Cross64162712017-08-08 13:17:59 -070029 pctx = android.NewPackageContext("android/soong/java/config")
30
Pete Gillin0638dfc2020-07-01 10:48:14 +010031 LegacyCorePlatformBootclasspathLibraries = []string{"legacy.core.platform.api.stubs", "core-lambda-stubs"}
32 LegacyCorePlatformSystemModules = "legacy-core-platform-api-stubs-system-modules"
Pete Gillin84c38072020-07-09 18:03:41 +010033 StableCorePlatformBootclasspathLibraries = []string{"stable.core.platform.api.stubs", "core-lambda-stubs"}
34 StableCorePlatformSystemModules = "stable-core-platform-api-stubs-system-modules"
Pete Gillin0638dfc2020-07-01 10:48:14 +010035 FrameworkLibraries = []string{"ext", "framework"}
36 DefaultLambdaStubsLibrary = "core-lambda-stubs"
37 SdkLambdaStubsPath = "prebuilts/sdk/tools/core-lambda-stubs.jar"
Colin Crosscb933592017-11-22 13:49:43 -080038
Chris Gross2f748692020-06-24 20:36:59 +000039 DefaultMakeJacocoExcludeFilter = []string{"org.junit.*", "org.jacoco.*", "org.mockito.*"}
40 DefaultJacocoExcludeFilter = []string{"org.junit.**", "org.jacoco.**", "org.mockito.**"}
Colin Crosscb933592017-11-22 13:49:43 -080041
42 InstrumentFrameworkModules = []string{
43 "framework",
Allen Hair74cd2862019-11-07 15:09:15 -080044 "framework-minus-apex",
Colin Crosscb933592017-11-22 13:49:43 -080045 "telephony-common",
46 "services",
47 "android.car",
48 "android.car7",
Adam Vartanianfa62cfc2019-03-08 14:46:36 +000049 "conscrypt",
Victor Chang07b5b4c2019-08-06 16:57:40 +010050 "core-icu4j",
Pete Gillin7868a092017-12-19 15:01:39 +000051 "core-oj",
Pete Gillin5d133542018-02-13 15:23:14 +000052 "core-libart",
Anton Hansson91133e62020-01-17 09:55:03 +000053 // TODO: Could this be all updatable bootclasspath jars?
Insun Kang23433862019-01-24 20:46:28 +090054 "updatable-media",
Jeff Sharkey38338a92019-12-15 22:05:02 -070055 "framework-mediaprovider",
Anton Hansson91133e62020-01-17 09:55:03 +000056 "framework-sdkextensions",
evitayan2e560672020-02-24 15:02:02 -080057 "android.net.ipsec.ike",
Colin Crosscb933592017-11-22 13:49:43 -080058 }
Colin Cross3e3e72d2017-06-22 17:20:19 -070059)
60
Colin Cross33961b52019-07-11 11:01:22 -070061const (
62 JavaVmFlags = `-XX:OnError="cat hs_err_pid%p.log" -XX:CICompilerCount=6 -XX:+UseDynamicNumberOfGCThreads`
Jared Duke0849c142022-01-28 11:30:16 -080063 JavacVmFlags = `-J-XX:OnError="cat hs_err_pid%p.log" -J-XX:CICompilerCount=6 -J-XX:+UseDynamicNumberOfGCThreads -J-XX:+TieredCompilation -J-XX:TieredStopAtLevel=1`
Colin Cross33961b52019-07-11 11:01:22 -070064)
65
Colin Cross64162712017-08-08 13:17:59 -070066func init() {
67 pctx.Import("github.com/google/blueprint/bootstrap")
68
Colin Crossfee57cb2017-09-05 13:16:45 -070069 pctx.StaticVariable("JavacHeapSize", "2048M")
70 pctx.StaticVariable("JavacHeapFlags", "-J-Xmx${JavacHeapSize}")
Colin Cross8bf6cad2022-02-28 13:07:03 -080071
72 // ErrorProne can use significantly more memory than javac alone, give it a higher heap
73 // size (b/221480398).
74 pctx.StaticVariable("ErrorProneHeapSize", "4096M")
75 pctx.StaticVariable("ErrorProneHeapFlags", "-J-Xmx${ErrorProneHeapSize}")
76
Sasha Smundakee5c6032019-07-09 11:26:20 -070077 pctx.StaticVariable("DexFlags", "-JXX:OnError='cat hs_err_pid%p.log' -JXX:CICompilerCount=6 -JXX:+UseDynamicNumberOfGCThreads")
Colin Cross3203dde2017-08-28 17:23:21 -070078
Colin Cross64162712017-08-08 13:17:59 -070079 pctx.StaticVariable("CommonJdkFlags", strings.Join([]string{
Colin Cross64162712017-08-08 13:17:59 -070080 `-Xmaxerrs 9999999`,
81 `-encoding UTF-8`,
82 `-sourcepath ""`,
83 `-g`,
Colin Cross945c0002017-09-19 10:52:23 -070084 // Turbine leaves out bridges which can cause javac to unnecessarily insert them into
85 // subclasses (b/65645120). Setting this flag causes our custom javac to assume that
86 // the missing bridges will exist at runtime and not recreate them in subclasses.
87 // If a different javac is used the flag will be ignored and extra bridges will be inserted.
88 // The flag is implemented by https://android-review.googlesource.com/c/486427
89 `-XDskipDuplicateBridges=true`,
Colin Cross64162712017-08-08 13:17:59 -070090
Colin Cross1369cdb2017-09-29 17:58:17 -070091 // b/65004097: prevent using java.lang.invoke.StringConcatFactory when using -target 1.9
92 `-XDstringConcat=inline`,
93 }, " "))
Colin Cross33961b52019-07-11 11:01:22 -070094
95 pctx.StaticVariable("JavaVmFlags", JavaVmFlags)
96 pctx.StaticVariable("JavacVmFlags", JavacVmFlags)
Colin Cross64162712017-08-08 13:17:59 -070097
98 pctx.VariableConfigMethod("hostPrebuiltTag", android.Config.PrebuiltOS)
99
Dan Willemsen54daaf02018-03-12 13:24:09 -0700100 pctx.VariableFunc("JavaHome", func(ctx android.PackageVarContext) string {
Dan Willemsend9e8f0a2017-10-30 13:42:06 -0700101 // This is set up and guaranteed by soong_ui
Dan Willemsen54daaf02018-03-12 13:24:09 -0700102 return ctx.Config().Getenv("ANDROID_JAVA_HOME")
Colin Crosse2ad2302017-10-05 16:48:56 -0700103 })
Pete Gillin1f52e932019-10-09 17:10:08 +0100104 pctx.VariableFunc("JlinkVersion", func(ctx android.PackageVarContext) string {
Pete Gillina2affbb2019-11-07 18:55:53 +0000105 if override := ctx.Config().Getenv("OVERRIDE_JLINK_VERSION_NUMBER"); override != "" {
106 return override
107 }
Colin Cross59c1e6a2022-03-04 13:37:19 -0800108 switch ctx.Config().Getenv("EXPERIMENTAL_USE_OPENJDK17_TOOLCHAIN") {
109 case "true":
110 return "17"
111 default:
112 return "11"
113 }
Pete Gillin1f52e932019-10-09 17:10:08 +0100114 })
Colin Crosse2ad2302017-10-05 16:48:56 -0700115
Colin Cross64162712017-08-08 13:17:59 -0700116 pctx.SourcePathVariable("JavaToolchain", "${JavaHome}/bin")
117 pctx.SourcePathVariableWithEnvOverride("JavacCmd",
118 "${JavaToolchain}/javac", "ALTERNATE_JAVAC")
119 pctx.SourcePathVariable("JavaCmd", "${JavaToolchain}/java")
120 pctx.SourcePathVariable("JarCmd", "${JavaToolchain}/jar")
121 pctx.SourcePathVariable("JavadocCmd", "${JavaToolchain}/javadoc")
Tobias Thierer77d0b412017-08-31 16:08:39 +0100122 pctx.SourcePathVariable("JlinkCmd", "${JavaToolchain}/jlink")
123 pctx.SourcePathVariable("JmodCmd", "${JavaToolchain}/jmod")
Colin Cross1369cdb2017-09-29 17:58:17 -0700124 pctx.SourcePathVariable("JrtFsJar", "${JavaHome}/lib/jrt-fs.jar")
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800125 pctx.SourcePathVariable("JavaKytheExtractorJar", "prebuilts/build-tools/common/framework/javac_extractor.jar")
Nan Zhanged19fc32017-10-19 13:06:22 -0700126 pctx.SourcePathVariable("Ziptime", "prebuilts/build-tools/${hostPrebuiltTag}/bin/ziptime")
Colin Cross64162712017-08-08 13:17:59 -0700127
Colin Cross9b1aa0c2020-06-25 17:12:28 -0700128 pctx.HostBinToolVariable("GenKotlinBuildFileCmd", "gen-kotlin-build-file.py")
Przemyslaw Szczepaniak4b5fe9d2018-02-13 14:32:54 +0000129
Colin Crossb852a582017-08-10 17:58:12 -0700130 pctx.SourcePathVariable("JarArgsCmd", "build/soong/scripts/jar-args.sh")
Vladimir Marko0975ee02019-04-02 10:29:55 +0100131 pctx.SourcePathVariable("PackageCheckCmd", "build/soong/scripts/package-check.sh")
Colin Cross66f78822018-05-02 12:58:28 -0700132 pctx.HostBinToolVariable("ExtractJarPackagesCmd", "extract_jar_packages")
Colin Crossa4820652017-10-17 13:56:52 -0700133 pctx.HostBinToolVariable("SoongZipCmd", "soong_zip")
134 pctx.HostBinToolVariable("MergeZipsCmd", "merge_zips")
Colin Crosscb933592017-11-22 13:49:43 -0800135 pctx.HostBinToolVariable("Zip2ZipCmd", "zip2zip")
Colin Cross436b7652018-03-15 16:24:10 -0700136 pctx.HostBinToolVariable("ZipSyncCmd", "zipsync")
Nan Zhang61819ce2018-05-04 18:49:16 -0700137 pctx.HostBinToolVariable("ApiCheckCmd", "apicheck")
Colin Crossc899d782021-11-04 10:25:20 -0700138 pctx.HostBinToolVariable("D8Cmd", "d8")
139 pctx.HostBinToolVariable("R8Cmd", "r8-compat-proguard")
Colin Crossf24a22a2019-01-31 14:12:44 -0800140 pctx.HostBinToolVariable("HiddenAPICmd", "hiddenapi")
Sasha Smundaka7856c02020-04-23 09:49:59 -0700141 pctx.HostBinToolVariable("ExtractApksCmd", "extract_apks")
Dan Willemsen54daaf02018-03-12 13:24:09 -0700142 pctx.VariableFunc("TurbineJar", func(ctx android.PackageVarContext) string {
Nan Zhang9a364182017-10-25 11:11:37 -0700143 turbine := "turbine.jar"
Jeongik Cha816a23a2020-07-08 01:09:23 +0900144 if ctx.Config().AlwaysUsePrebuiltSdks() {
Dan Willemsen54daaf02018-03-12 13:24:09 -0700145 return "prebuilts/build-tools/common/framework/" + turbine
Nan Zhang9a364182017-10-25 11:11:37 -0700146 } else {
Martin Stjernholm7260d062019-12-09 21:47:14 +0000147 return ctx.Config().HostJavaToolPath(ctx, turbine).String()
Nan Zhang9a364182017-10-25 11:11:37 -0700148 }
149 })
Alan Leung1d476fc2017-10-17 18:50:50 -0700150
Colin Cross64162712017-08-08 13:17:59 -0700151 pctx.HostJavaToolVariable("JarjarCmd", "jarjar.jar")
Nan Zhang581fd212018-01-10 16:06:12 -0800152 pctx.HostJavaToolVariable("JsilverJar", "jsilver.jar")
153 pctx.HostJavaToolVariable("DoclavaJar", "doclava.jar")
Nan Zhang79614d12018-04-19 18:03:39 -0700154 pctx.HostJavaToolVariable("MetalavaJar", "metalava.jar")
Nan Zhang86d2d552018-08-09 15:33:27 -0700155 pctx.HostJavaToolVariable("DokkaJar", "dokka.jar")
Nan Zhang4c819fb2018-08-27 18:31:46 -0700156 pctx.HostJavaToolVariable("JetifierJar", "jetifier.jar")
Ramy Medhat1dcc27e2020-04-21 21:36:23 -0400157 pctx.HostJavaToolVariable("R8Jar", "r8-compat-proguard.jar")
158 pctx.HostJavaToolVariable("D8Jar", "d8.jar")
Colin Cross64162712017-08-08 13:17:59 -0700159
Colin Crossa4820652017-10-17 13:56:52 -0700160 pctx.HostBinToolVariable("SoongJavacWrapper", "soong_javac_wrapper")
Colin Cross43f08db2018-11-12 10:13:39 -0800161 pctx.HostBinToolVariable("DexpreoptGen", "dexpreopt_gen")
Colin Crossa4820652017-10-17 13:56:52 -0700162
Colin Cross77cdcfd2021-03-12 11:28:25 -0800163 pctx.StaticVariableWithEnvOverride("REJavaPool", "RBE_JAVA_POOL", "java16")
164 pctx.StaticVariableWithEnvOverride("REJavacExecStrategy", "RBE_JAVAC_EXEC_STRATEGY", remoteexec.RemoteLocalFallbackExecStrategy)
165 pctx.StaticVariableWithEnvOverride("RED8ExecStrategy", "RBE_D8_EXEC_STRATEGY", remoteexec.RemoteLocalFallbackExecStrategy)
166 pctx.StaticVariableWithEnvOverride("RER8ExecStrategy", "RBE_R8_EXEC_STRATEGY", remoteexec.RemoteLocalFallbackExecStrategy)
167 pctx.StaticVariableWithEnvOverride("RETurbineExecStrategy", "RBE_TURBINE_EXEC_STRATEGY", remoteexec.LocalExecStrategy)
168 pctx.StaticVariableWithEnvOverride("RESignApkExecStrategy", "RBE_SIGNAPK_EXEC_STRATEGY", remoteexec.LocalExecStrategy)
169 pctx.StaticVariableWithEnvOverride("REJarExecStrategy", "RBE_JAR_EXEC_STRATEGY", remoteexec.LocalExecStrategy)
170 pctx.StaticVariableWithEnvOverride("REZipExecStrategy", "RBE_ZIP_EXEC_STRATEGY", remoteexec.LocalExecStrategy)
Ramy Medhat8ea054a2020-01-27 14:19:44 -0500171
Colin Crosscb933592017-11-22 13:49:43 -0800172 pctx.HostJavaToolVariable("JacocoCLIJar", "jacoco-cli.jar")
Colin Cross3bc7ffa2017-11-22 16:19:37 -0800173
Colin Cross72119102019-05-20 13:14:18 -0700174 pctx.HostBinToolVariable("ManifestCheckCmd", "manifest_check")
Colin Cross4af387c2019-05-16 13:16:29 -0700175 pctx.HostBinToolVariable("ManifestFixerCmd", "manifest_fixer")
Colin Crosscfae5a62018-05-24 16:11:20 -0700176
Colin Cross87ecbfe2019-02-26 22:14:04 -0800177 pctx.HostBinToolVariable("ManifestMergerCmd", "manifest-merger")
Colin Cross43f08db2018-11-12 10:13:39 -0800178
Andrei Onea23fea042020-08-12 16:48:23 +0100179 pctx.HostBinToolVariable("Class2NonSdkList", "class2nonsdklist")
Colin Cross8faf8fc2019-01-16 15:15:52 -0800180 pctx.HostBinToolVariable("HiddenAPI", "hiddenapi")
Colin Crossbdf95142019-08-08 12:56:34 -0700181
182 hostBinToolVariableWithSdkToolsPrebuilt("Aapt2Cmd", "aapt2")
183 hostBinToolVariableWithBuildToolsPrebuilt("AidlCmd", "aidl")
184 hostBinToolVariableWithBuildToolsPrebuilt("ZipAlign", "zipalign")
185
186 hostJavaToolVariableWithSdkToolsPrebuilt("SignapkCmd", "signapk")
187 // TODO(ccross): this should come from the signapk dependencies, but we don't have any way
188 // to express host JNI dependencies yet.
189 hostJNIToolVariableWithSdkToolsPrebuilt("SignapkJniLibrary", "libconscrypt_openjdk_jni")
190}
191
192func hostBinToolVariableWithSdkToolsPrebuilt(name, tool string) {
193 pctx.VariableFunc(name, func(ctx android.PackageVarContext) string {
Dan Willemsen9f435972020-05-28 15:28:00 -0700194 if ctx.Config().AlwaysUsePrebuiltSdks() {
Colin Crossbdf95142019-08-08 12:56:34 -0700195 return filepath.Join("prebuilts/sdk/tools", runtime.GOOS, "bin", tool)
196 } else {
Martin Stjernholm7260d062019-12-09 21:47:14 +0000197 return ctx.Config().HostToolPath(ctx, tool).String()
Colin Crossbdf95142019-08-08 12:56:34 -0700198 }
199 })
200}
201
202func hostJavaToolVariableWithSdkToolsPrebuilt(name, tool string) {
203 pctx.VariableFunc(name, func(ctx android.PackageVarContext) string {
Dan Willemsen9f435972020-05-28 15:28:00 -0700204 if ctx.Config().AlwaysUsePrebuiltSdks() {
Colin Crossbdf95142019-08-08 12:56:34 -0700205 return filepath.Join("prebuilts/sdk/tools/lib", tool+".jar")
206 } else {
Martin Stjernholm7260d062019-12-09 21:47:14 +0000207 return ctx.Config().HostJavaToolPath(ctx, tool+".jar").String()
Colin Crossbdf95142019-08-08 12:56:34 -0700208 }
209 })
210}
211
212func hostJNIToolVariableWithSdkToolsPrebuilt(name, tool string) {
213 pctx.VariableFunc(name, func(ctx android.PackageVarContext) string {
Dan Willemsen9f435972020-05-28 15:28:00 -0700214 if ctx.Config().AlwaysUsePrebuiltSdks() {
Colin Crossbdf95142019-08-08 12:56:34 -0700215 ext := ".so"
216 if runtime.GOOS == "darwin" {
217 ext = ".dylib"
218 }
219 return filepath.Join("prebuilts/sdk/tools", runtime.GOOS, "lib64", tool+ext)
220 } else {
Martin Stjernholm7260d062019-12-09 21:47:14 +0000221 return ctx.Config().HostJNIToolPath(ctx, tool).String()
Colin Crossbdf95142019-08-08 12:56:34 -0700222 }
223 })
224}
225
226func hostBinToolVariableWithBuildToolsPrebuilt(name, tool string) {
227 pctx.VariableFunc(name, func(ctx android.PackageVarContext) string {
Dan Willemsen9f435972020-05-28 15:28:00 -0700228 if ctx.Config().AlwaysUsePrebuiltSdks() {
Colin Crossbdf95142019-08-08 12:56:34 -0700229 return filepath.Join("prebuilts/build-tools", ctx.Config().PrebuiltOS(), "bin", tool)
230 } else {
Martin Stjernholm7260d062019-12-09 21:47:14 +0000231 return ctx.Config().HostToolPath(ctx, tool).String()
Colin Crossbdf95142019-08-08 12:56:34 -0700232 }
233 })
Colin Cross64162712017-08-08 13:17:59 -0700234}
Colin Cross33961b52019-07-11 11:01:22 -0700235
236// JavaCmd returns a SourcePath object with the path to the java command.
237func JavaCmd(ctx android.PathContext) android.SourcePath {
238 return javaTool(ctx, "java")
239}
240
241// JavadocCmd returns a SourcePath object with the path to the java command.
242func JavadocCmd(ctx android.PathContext) android.SourcePath {
243 return javaTool(ctx, "javadoc")
244}
245
246func javaTool(ctx android.PathContext, tool string) android.SourcePath {
247 type javaToolKey string
248
249 key := android.NewCustomOnceKey(javaToolKey(tool))
250
251 return ctx.Config().OnceSourcePath(key, func() android.SourcePath {
252 return javaToolchain(ctx).Join(ctx, tool)
253 })
254
255}
256
257var javaToolchainKey = android.NewOnceKey("javaToolchain")
258
259func javaToolchain(ctx android.PathContext) android.SourcePath {
260 return ctx.Config().OnceSourcePath(javaToolchainKey, func() android.SourcePath {
261 return javaHome(ctx).Join(ctx, "bin")
262 })
263}
264
265var javaHomeKey = android.NewOnceKey("javaHome")
266
267func javaHome(ctx android.PathContext) android.SourcePath {
268 return ctx.Config().OnceSourcePath(javaHomeKey, func() android.SourcePath {
269 // This is set up and guaranteed by soong_ui
270 return android.PathForSource(ctx, ctx.Config().Getenv("ANDROID_JAVA_HOME"))
271 })
272}