blob: 0351009403fa6eab8f03cd836153835c0527ab61 [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"
33 FrameworkLibraries = []string{"ext", "framework"}
34 DefaultLambdaStubsLibrary = "core-lambda-stubs"
35 SdkLambdaStubsPath = "prebuilts/sdk/tools/core-lambda-stubs.jar"
Colin Crosscb933592017-11-22 13:49:43 -080036
37 DefaultJacocoExcludeFilter = []string{"org.junit.*", "org.jacoco.*", "org.mockito.*"}
38
39 InstrumentFrameworkModules = []string{
40 "framework",
41 "telephony-common",
42 "services",
43 "android.car",
44 "android.car7",
Adam Vartanianfa62cfc2019-03-08 14:46:36 +000045 "conscrypt",
Victor Chang07b5b4c2019-08-06 16:57:40 +010046 "core-icu4j",
Pete Gillin7868a092017-12-19 15:01:39 +000047 "core-oj",
Pete Gillin5d133542018-02-13 15:23:14 +000048 "core-libart",
Anton Hansson91133e62020-01-17 09:55:03 +000049 // TODO: Could this be all updatable bootclasspath jars?
Insun Kang23433862019-01-24 20:46:28 +090050 "updatable-media",
Anton Hansson91133e62020-01-17 09:55:03 +000051 "framework-sdkextensions",
evitayan2e560672020-02-24 15:02:02 -080052 "android.net.ipsec.ike",
Colin Crosscb933592017-11-22 13:49:43 -080053 }
Colin Cross3e3e72d2017-06-22 17:20:19 -070054)
55
Colin Cross33961b52019-07-11 11:01:22 -070056const (
57 JavaVmFlags = `-XX:OnError="cat hs_err_pid%p.log" -XX:CICompilerCount=6 -XX:+UseDynamicNumberOfGCThreads`
58 JavacVmFlags = `-J-XX:OnError="cat hs_err_pid%p.log" -J-XX:CICompilerCount=6 -J-XX:+UseDynamicNumberOfGCThreads`
59)
60
Colin Cross64162712017-08-08 13:17:59 -070061func init() {
62 pctx.Import("github.com/google/blueprint/bootstrap")
63
Colin Crossfee57cb2017-09-05 13:16:45 -070064 pctx.StaticVariable("JavacHeapSize", "2048M")
65 pctx.StaticVariable("JavacHeapFlags", "-J-Xmx${JavacHeapSize}")
Sasha Smundakee5c6032019-07-09 11:26:20 -070066 pctx.StaticVariable("DexFlags", "-JXX:OnError='cat hs_err_pid%p.log' -JXX:CICompilerCount=6 -JXX:+UseDynamicNumberOfGCThreads")
Colin Cross3203dde2017-08-28 17:23:21 -070067
Colin Cross64162712017-08-08 13:17:59 -070068 pctx.StaticVariable("CommonJdkFlags", strings.Join([]string{
Colin Cross64162712017-08-08 13:17:59 -070069 `-Xmaxerrs 9999999`,
70 `-encoding UTF-8`,
71 `-sourcepath ""`,
72 `-g`,
Colin Cross945c0002017-09-19 10:52:23 -070073 // Turbine leaves out bridges which can cause javac to unnecessarily insert them into
74 // subclasses (b/65645120). Setting this flag causes our custom javac to assume that
75 // the missing bridges will exist at runtime and not recreate them in subclasses.
76 // If a different javac is used the flag will be ignored and extra bridges will be inserted.
77 // The flag is implemented by https://android-review.googlesource.com/c/486427
78 `-XDskipDuplicateBridges=true`,
Colin Cross64162712017-08-08 13:17:59 -070079
Colin Cross1369cdb2017-09-29 17:58:17 -070080 // b/65004097: prevent using java.lang.invoke.StringConcatFactory when using -target 1.9
81 `-XDstringConcat=inline`,
82 }, " "))
Colin Cross33961b52019-07-11 11:01:22 -070083
84 pctx.StaticVariable("JavaVmFlags", JavaVmFlags)
85 pctx.StaticVariable("JavacVmFlags", JavacVmFlags)
Colin Cross64162712017-08-08 13:17:59 -070086
87 pctx.VariableConfigMethod("hostPrebuiltTag", android.Config.PrebuiltOS)
88
Dan Willemsen54daaf02018-03-12 13:24:09 -070089 pctx.VariableFunc("JavaHome", func(ctx android.PackageVarContext) string {
Dan Willemsend9e8f0a2017-10-30 13:42:06 -070090 // This is set up and guaranteed by soong_ui
Dan Willemsen54daaf02018-03-12 13:24:09 -070091 return ctx.Config().Getenv("ANDROID_JAVA_HOME")
Colin Crosse2ad2302017-10-05 16:48:56 -070092 })
Pete Gillin1f52e932019-10-09 17:10:08 +010093 pctx.VariableFunc("JlinkVersion", func(ctx android.PackageVarContext) string {
Pete Gillina2affbb2019-11-07 18:55:53 +000094 if override := ctx.Config().Getenv("OVERRIDE_JLINK_VERSION_NUMBER"); override != "" {
95 return override
96 }
Pete Gillina7a3d642019-11-07 18:58:42 +000097 return "11"
Pete Gillin1f52e932019-10-09 17:10:08 +010098 })
Colin Crosse2ad2302017-10-05 16:48:56 -070099
Colin Cross64162712017-08-08 13:17:59 -0700100 pctx.SourcePathVariable("JavaToolchain", "${JavaHome}/bin")
101 pctx.SourcePathVariableWithEnvOverride("JavacCmd",
102 "${JavaToolchain}/javac", "ALTERNATE_JAVAC")
103 pctx.SourcePathVariable("JavaCmd", "${JavaToolchain}/java")
104 pctx.SourcePathVariable("JarCmd", "${JavaToolchain}/jar")
105 pctx.SourcePathVariable("JavadocCmd", "${JavaToolchain}/javadoc")
Tobias Thierer77d0b412017-08-31 16:08:39 +0100106 pctx.SourcePathVariable("JlinkCmd", "${JavaToolchain}/jlink")
107 pctx.SourcePathVariable("JmodCmd", "${JavaToolchain}/jmod")
Colin Cross1369cdb2017-09-29 17:58:17 -0700108 pctx.SourcePathVariable("JrtFsJar", "${JavaHome}/lib/jrt-fs.jar")
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800109 pctx.SourcePathVariable("JavaKytheExtractorJar", "prebuilts/build-tools/common/framework/javac_extractor.jar")
Nan Zhanged19fc32017-10-19 13:06:22 -0700110 pctx.SourcePathVariable("Ziptime", "prebuilts/build-tools/${hostPrebuiltTag}/bin/ziptime")
Colin Cross64162712017-08-08 13:17:59 -0700111
Przemyslaw Szczepaniak4b5fe9d2018-02-13 14:32:54 +0000112 pctx.SourcePathVariable("GenKotlinBuildFileCmd", "build/soong/scripts/gen-kotlin-build-file.sh")
113
Colin Crossb852a582017-08-10 17:58:12 -0700114 pctx.SourcePathVariable("JarArgsCmd", "build/soong/scripts/jar-args.sh")
Vladimir Marko0975ee02019-04-02 10:29:55 +0100115 pctx.SourcePathVariable("PackageCheckCmd", "build/soong/scripts/package-check.sh")
Colin Cross66f78822018-05-02 12:58:28 -0700116 pctx.HostBinToolVariable("ExtractJarPackagesCmd", "extract_jar_packages")
Colin Crossa4820652017-10-17 13:56:52 -0700117 pctx.HostBinToolVariable("SoongZipCmd", "soong_zip")
118 pctx.HostBinToolVariable("MergeZipsCmd", "merge_zips")
Colin Crosscb933592017-11-22 13:49:43 -0800119 pctx.HostBinToolVariable("Zip2ZipCmd", "zip2zip")
Colin Cross436b7652018-03-15 16:24:10 -0700120 pctx.HostBinToolVariable("ZipSyncCmd", "zipsync")
Nan Zhang61819ce2018-05-04 18:49:16 -0700121 pctx.HostBinToolVariable("ApiCheckCmd", "apicheck")
Colin Crossf0056cb2017-12-22 15:56:08 -0800122 pctx.HostBinToolVariable("D8Cmd", "d8")
Colin Cross66dbc0b2017-12-28 12:23:20 -0800123 pctx.HostBinToolVariable("R8Cmd", "r8-compat-proguard")
Colin Crossf24a22a2019-01-31 14:12:44 -0800124 pctx.HostBinToolVariable("HiddenAPICmd", "hiddenapi")
Sasha Smundaka7856c02020-04-23 09:49:59 -0700125 pctx.HostBinToolVariable("ExtractApksCmd", "extract_apks")
Dan Willemsen54daaf02018-03-12 13:24:09 -0700126 pctx.VariableFunc("TurbineJar", func(ctx android.PackageVarContext) string {
Nan Zhang9a364182017-10-25 11:11:37 -0700127 turbine := "turbine.jar"
Dan Willemsen54daaf02018-03-12 13:24:09 -0700128 if ctx.Config().UnbundledBuild() {
129 return "prebuilts/build-tools/common/framework/" + turbine
Nan Zhang9a364182017-10-25 11:11:37 -0700130 } else {
Martin Stjernholm7260d062019-12-09 21:47:14 +0000131 return ctx.Config().HostJavaToolPath(ctx, turbine).String()
Nan Zhang9a364182017-10-25 11:11:37 -0700132 }
133 })
Alan Leung1d476fc2017-10-17 18:50:50 -0700134
Colin Cross64162712017-08-08 13:17:59 -0700135 pctx.HostJavaToolVariable("JarjarCmd", "jarjar.jar")
Nan Zhang581fd212018-01-10 16:06:12 -0800136 pctx.HostJavaToolVariable("JsilverJar", "jsilver.jar")
137 pctx.HostJavaToolVariable("DoclavaJar", "doclava.jar")
Nan Zhang79614d12018-04-19 18:03:39 -0700138 pctx.HostJavaToolVariable("MetalavaJar", "metalava.jar")
Nan Zhang86d2d552018-08-09 15:33:27 -0700139 pctx.HostJavaToolVariable("DokkaJar", "dokka.jar")
Nan Zhang4c819fb2018-08-27 18:31:46 -0700140 pctx.HostJavaToolVariable("JetifierJar", "jetifier.jar")
Ramy Medhat1dcc27e2020-04-21 21:36:23 -0400141 pctx.HostJavaToolVariable("R8Jar", "r8-compat-proguard.jar")
142 pctx.HostJavaToolVariable("D8Jar", "d8.jar")
Colin Cross64162712017-08-08 13:17:59 -0700143
Colin Crossa4820652017-10-17 13:56:52 -0700144 pctx.HostBinToolVariable("SoongJavacWrapper", "soong_javac_wrapper")
Colin Cross43f08db2018-11-12 10:13:39 -0800145 pctx.HostBinToolVariable("DexpreoptGen", "dexpreopt_gen")
Colin Crossa4820652017-10-17 13:56:52 -0700146
Ramy Medhat1dcc27e2020-04-21 21:36:23 -0400147 pctx.VariableFunc("REJavaPool", remoteexec.EnvOverrideFunc("RBE_JAVA_POOL", "java16"))
148 pctx.VariableFunc("REJavacExecStrategy", remoteexec.EnvOverrideFunc("RBE_JAVAC_EXEC_STRATEGY", remoteexec.LocalExecStrategy))
149 pctx.VariableFunc("RED8ExecStrategy", remoteexec.EnvOverrideFunc("RBE_D8_EXEC_STRATEGY", remoteexec.LocalExecStrategy))
150 pctx.VariableFunc("RER8ExecStrategy", remoteexec.EnvOverrideFunc("RBE_R8_EXEC_STRATEGY", remoteexec.LocalExecStrategy))
Kousik Kumar1372c1b2020-05-20 07:55:56 -0700151 pctx.VariableFunc("RETurbineExecStrategy", remoteexec.EnvOverrideFunc("RBE_TURBINE_EXEC_STRATEGY", remoteexec.LocalExecStrategy))
Kousik Kumar309b1c02020-05-28 06:13:33 -0700152 pctx.VariableFunc("RESignApkExecStrategy", remoteexec.EnvOverrideFunc("RBE_SIGNAPK_EXEC_STRATEGY", remoteexec.LocalExecStrategy))
Kousik Kumar366afc52020-05-20 11:27:16 -0700153 pctx.VariableFunc("REJarExecStrategy", remoteexec.EnvOverrideFunc("RBE_JAR_EXEC_STRATEGY", remoteexec.LocalExecStrategy))
154 pctx.VariableFunc("REZipExecStrategy", remoteexec.EnvOverrideFunc("RBE_ZIP_EXEC_STRATEGY", remoteexec.LocalExecStrategy))
Ramy Medhat8ea054a2020-01-27 14:19:44 -0500155
Colin Crosscb933592017-11-22 13:49:43 -0800156 pctx.HostJavaToolVariable("JacocoCLIJar", "jacoco-cli.jar")
Colin Cross3bc7ffa2017-11-22 16:19:37 -0800157
Colin Cross72119102019-05-20 13:14:18 -0700158 pctx.HostBinToolVariable("ManifestCheckCmd", "manifest_check")
Colin Cross4af387c2019-05-16 13:16:29 -0700159 pctx.HostBinToolVariable("ManifestFixerCmd", "manifest_fixer")
Colin Crosscfae5a62018-05-24 16:11:20 -0700160
Colin Cross87ecbfe2019-02-26 22:14:04 -0800161 pctx.HostBinToolVariable("ManifestMergerCmd", "manifest-merger")
Colin Cross43f08db2018-11-12 10:13:39 -0800162
Colin Cross8faf8fc2019-01-16 15:15:52 -0800163 pctx.HostBinToolVariable("Class2Greylist", "class2greylist")
164 pctx.HostBinToolVariable("HiddenAPI", "hiddenapi")
Colin Crossbdf95142019-08-08 12:56:34 -0700165
166 hostBinToolVariableWithSdkToolsPrebuilt("Aapt2Cmd", "aapt2")
167 hostBinToolVariableWithBuildToolsPrebuilt("AidlCmd", "aidl")
168 hostBinToolVariableWithBuildToolsPrebuilt("ZipAlign", "zipalign")
169
170 hostJavaToolVariableWithSdkToolsPrebuilt("SignapkCmd", "signapk")
171 // TODO(ccross): this should come from the signapk dependencies, but we don't have any way
172 // to express host JNI dependencies yet.
173 hostJNIToolVariableWithSdkToolsPrebuilt("SignapkJniLibrary", "libconscrypt_openjdk_jni")
174}
175
176func hostBinToolVariableWithSdkToolsPrebuilt(name, tool string) {
177 pctx.VariableFunc(name, func(ctx android.PackageVarContext) string {
178 if ctx.Config().UnbundledBuild() || ctx.Config().IsPdkBuild() {
179 return filepath.Join("prebuilts/sdk/tools", runtime.GOOS, "bin", tool)
180 } else {
Martin Stjernholm7260d062019-12-09 21:47:14 +0000181 return ctx.Config().HostToolPath(ctx, tool).String()
Colin Crossbdf95142019-08-08 12:56:34 -0700182 }
183 })
184}
185
186func hostJavaToolVariableWithSdkToolsPrebuilt(name, tool string) {
187 pctx.VariableFunc(name, func(ctx android.PackageVarContext) string {
188 if ctx.Config().UnbundledBuild() || ctx.Config().IsPdkBuild() {
189 return filepath.Join("prebuilts/sdk/tools/lib", tool+".jar")
190 } else {
Martin Stjernholm7260d062019-12-09 21:47:14 +0000191 return ctx.Config().HostJavaToolPath(ctx, tool+".jar").String()
Colin Crossbdf95142019-08-08 12:56:34 -0700192 }
193 })
194}
195
196func hostJNIToolVariableWithSdkToolsPrebuilt(name, tool string) {
197 pctx.VariableFunc(name, func(ctx android.PackageVarContext) string {
198 if ctx.Config().UnbundledBuild() || ctx.Config().IsPdkBuild() {
199 ext := ".so"
200 if runtime.GOOS == "darwin" {
201 ext = ".dylib"
202 }
203 return filepath.Join("prebuilts/sdk/tools", runtime.GOOS, "lib64", tool+ext)
204 } else {
Martin Stjernholm7260d062019-12-09 21:47:14 +0000205 return ctx.Config().HostJNIToolPath(ctx, tool).String()
Colin Crossbdf95142019-08-08 12:56:34 -0700206 }
207 })
208}
209
210func hostBinToolVariableWithBuildToolsPrebuilt(name, tool string) {
211 pctx.VariableFunc(name, func(ctx android.PackageVarContext) string {
212 if ctx.Config().UnbundledBuild() || ctx.Config().IsPdkBuild() {
213 return filepath.Join("prebuilts/build-tools", ctx.Config().PrebuiltOS(), "bin", tool)
214 } else {
Martin Stjernholm7260d062019-12-09 21:47:14 +0000215 return ctx.Config().HostToolPath(ctx, tool).String()
Colin Crossbdf95142019-08-08 12:56:34 -0700216 }
217 })
Colin Cross64162712017-08-08 13:17:59 -0700218}
Colin Cross33961b52019-07-11 11:01:22 -0700219
220// JavaCmd returns a SourcePath object with the path to the java command.
221func JavaCmd(ctx android.PathContext) android.SourcePath {
222 return javaTool(ctx, "java")
223}
224
225// JavadocCmd returns a SourcePath object with the path to the java command.
226func JavadocCmd(ctx android.PathContext) android.SourcePath {
227 return javaTool(ctx, "javadoc")
228}
229
230func javaTool(ctx android.PathContext, tool string) android.SourcePath {
231 type javaToolKey string
232
233 key := android.NewCustomOnceKey(javaToolKey(tool))
234
235 return ctx.Config().OnceSourcePath(key, func() android.SourcePath {
236 return javaToolchain(ctx).Join(ctx, tool)
237 })
238
239}
240
241var javaToolchainKey = android.NewOnceKey("javaToolchain")
242
243func javaToolchain(ctx android.PathContext) android.SourcePath {
244 return ctx.Config().OnceSourcePath(javaToolchainKey, func() android.SourcePath {
245 return javaHome(ctx).Join(ctx, "bin")
246 })
247}
248
249var javaHomeKey = android.NewOnceKey("javaHome")
250
251func javaHome(ctx android.PathContext) android.SourcePath {
252 return ctx.Config().OnceSourcePath(javaHomeKey, func() android.SourcePath {
253 // This is set up and guaranteed by soong_ui
254 return android.PathForSource(ctx, ctx.Config().Getenv("ANDROID_JAVA_HOME"))
255 })
256}