1// 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 17import ( 18 "path/filepath" 19 "runtime" 20 "strings" 21 22 _ "github.com/google/blueprint/bootstrap" 23 24 "android/soong/android" 25 "android/soong/remoteexec" 26) 27 28var ( 29 pctx = android.NewPackageContext("android/soong/java/config") 30 31 LegacyCorePlatformBootclasspathLibraries = []string{"legacy.core.platform.api.stubs", "core-lambda-stubs"} 32 LegacyCorePlatformSystemModules = "legacy-core-platform-api-stubs-system-modules" 33 StableCorePlatformBootclasspathLibraries = []string{"stable.core.platform.api.stubs", "core-lambda-stubs"} 34 StableCorePlatformSystemModules = "stable-core-platform-api-stubs-system-modules" 35 FrameworkLibraries = []string{"ext", "framework"} 36 DefaultLambdaStubsLibrary = "core-lambda-stubs" 37 SdkLambdaStubsPath = "prebuilts/sdk/tools/core-lambda-stubs.jar" 38 39 DefaultMakeJacocoExcludeFilter = []string{"org.junit.*", "org.jacoco.*", "org.mockito.*"} 40 DefaultJacocoExcludeFilter = []string{"org.junit.**", "org.jacoco.**", "org.mockito.**"} 41 42 InstrumentFrameworkModules = []string{ 43 "framework", 44 "framework-minus-apex", 45 "telephony-common", 46 "services", 47 "android.car", 48 "android.car7", 49 "conscrypt", 50 "core-icu4j", 51 "core-oj", 52 "core-libart", 53 // TODO: Could this be all updatable bootclasspath jars? 54 "updatable-media", 55 "framework-mediaprovider", 56 "framework-sdkextensions", 57 "android.net.ipsec.ike", 58 } 59) 60 61const ( 62 JavaVmFlags = `-XX:OnError="cat hs_err_pid%p.log" -XX:CICompilerCount=6 -XX:+UseDynamicNumberOfGCThreads` 63 JavacVmFlags = `-J-XX:OnError="cat hs_err_pid%p.log" -J-XX:CICompilerCount=6 -J-XX:+UseDynamicNumberOfGCThreads` 64) 65 66func init() { 67 pctx.Import("github.com/google/blueprint/bootstrap") 68 69 pctx.StaticVariable("JavacHeapSize", "2048M") 70 pctx.StaticVariable("JavacHeapFlags", "-J-Xmx${JavacHeapSize}") 71 pctx.StaticVariable("DexFlags", "-JXX:OnError='cat hs_err_pid%p.log' -JXX:CICompilerCount=6 -JXX:+UseDynamicNumberOfGCThreads") 72 // TODO(b/181095653): remove duplicated flags. 73 pctx.StaticVariable("DexJavaFlags", "-XX:OnError='cat hs_err_pid%p.log' -XX:CICompilerCount=6 -XX:+UseDynamicNumberOfGCThreads -Xmx2G") 74 75 pctx.StaticVariable("CommonJdkFlags", strings.Join([]string{ 76 `-Xmaxerrs 9999999`, 77 `-encoding UTF-8`, 78 `-sourcepath ""`, 79 `-g`, 80 // Turbine leaves out bridges which can cause javac to unnecessarily insert them into 81 // subclasses (b/65645120). Setting this flag causes our custom javac to assume that 82 // the missing bridges will exist at runtime and not recreate them in subclasses. 83 // If a different javac is used the flag will be ignored and extra bridges will be inserted. 84 // The flag is implemented by https://android-review.googlesource.com/c/486427 85 `-XDskipDuplicateBridges=true`, 86 87 // b/65004097: prevent using java.lang.invoke.StringConcatFactory when using -target 1.9 88 `-XDstringConcat=inline`, 89 }, " ")) 90 91 pctx.StaticVariable("JavaVmFlags", JavaVmFlags) 92 pctx.StaticVariable("JavacVmFlags", JavacVmFlags) 93 94 pctx.VariableConfigMethod("hostPrebuiltTag", android.Config.PrebuiltOS) 95 96 pctx.VariableFunc("JavaHome", func(ctx android.PackageVarContext) string { 97 // This is set up and guaranteed by soong_ui 98 return ctx.Config().Getenv("ANDROID_JAVA_HOME") 99 }) 100 pctx.VariableFunc("JlinkVersion", func(ctx android.PackageVarContext) string { 101 if override := ctx.Config().Getenv("OVERRIDE_JLINK_VERSION_NUMBER"); override != "" { 102 return override 103 } 104 return "11" 105 }) 106 107 pctx.SourcePathVariable("JavaToolchain", "${JavaHome}/bin") 108 pctx.SourcePathVariableWithEnvOverride("JavacCmd", 109 "${JavaToolchain}/javac", "ALTERNATE_JAVAC") 110 pctx.SourcePathVariable("JavaCmd", "${JavaToolchain}/java") 111 pctx.SourcePathVariable("JarCmd", "${JavaToolchain}/jar") 112 pctx.SourcePathVariable("JavadocCmd", "${JavaToolchain}/javadoc") 113 pctx.SourcePathVariable("JlinkCmd", "${JavaToolchain}/jlink") 114 pctx.SourcePathVariable("JmodCmd", "${JavaToolchain}/jmod") 115 pctx.SourcePathVariable("JrtFsJar", "${JavaHome}/lib/jrt-fs.jar") 116 pctx.SourcePathVariable("JavaKytheExtractorJar", "prebuilts/build-tools/common/framework/javac_extractor.jar") 117 pctx.SourcePathVariable("Ziptime", "prebuilts/build-tools/${hostPrebuiltTag}/bin/ziptime") 118 119 pctx.HostBinToolVariable("GenKotlinBuildFileCmd", "gen-kotlin-build-file.py") 120 121 pctx.SourcePathVariable("JarArgsCmd", "build/soong/scripts/jar-args.sh") 122 pctx.SourcePathVariable("PackageCheckCmd", "build/soong/scripts/package-check.sh") 123 pctx.HostBinToolVariable("ExtractJarPackagesCmd", "extract_jar_packages") 124 pctx.HostBinToolVariable("SoongZipCmd", "soong_zip") 125 pctx.HostBinToolVariable("MergeZipsCmd", "merge_zips") 126 pctx.HostBinToolVariable("Zip2ZipCmd", "zip2zip") 127 pctx.HostBinToolVariable("ZipSyncCmd", "zipsync") 128 pctx.HostBinToolVariable("ApiCheckCmd", "apicheck") 129 pctx.HostBinToolVariable("D8Cmd", "d8") 130 pctx.HostBinToolVariable("R8Cmd", "r8-compat-proguard") 131 pctx.HostBinToolVariable("HiddenAPICmd", "hiddenapi") 132 pctx.HostBinToolVariable("ExtractApksCmd", "extract_apks") 133 pctx.VariableFunc("TurbineJar", func(ctx android.PackageVarContext) string { 134 turbine := "turbine.jar" 135 if ctx.Config().AlwaysUsePrebuiltSdks() { 136 return "prebuilts/build-tools/common/framework/" + turbine 137 } else { 138 return ctx.Config().HostJavaToolPath(ctx, turbine).String() 139 } 140 }) 141 142 pctx.HostJavaToolVariable("JarjarCmd", "jarjar.jar") 143 pctx.HostJavaToolVariable("JsilverJar", "jsilver.jar") 144 pctx.HostJavaToolVariable("DoclavaJar", "doclava.jar") 145 pctx.HostJavaToolVariable("MetalavaJar", "metalava.jar") 146 pctx.HostJavaToolVariable("DokkaJar", "dokka.jar") 147 pctx.HostJavaToolVariable("JetifierJar", "jetifier.jar") 148 pctx.HostJavaToolVariable("R8Jar", "r8-compat-proguard.jar") 149 pctx.HostJavaToolVariable("D8Jar", "d8.jar") 150 151 pctx.HostBinToolVariable("SoongJavacWrapper", "soong_javac_wrapper") 152 pctx.HostBinToolVariable("DexpreoptGen", "dexpreopt_gen") 153 154 pctx.StaticVariableWithEnvOverride("REJavaPool", "RBE_JAVA_POOL", "java16") 155 pctx.StaticVariableWithEnvOverride("REJavacExecStrategy", "RBE_JAVAC_EXEC_STRATEGY", remoteexec.RemoteLocalFallbackExecStrategy) 156 pctx.StaticVariableWithEnvOverride("RED8ExecStrategy", "RBE_D8_EXEC_STRATEGY", remoteexec.RemoteLocalFallbackExecStrategy) 157 pctx.StaticVariableWithEnvOverride("RER8ExecStrategy", "RBE_R8_EXEC_STRATEGY", remoteexec.RemoteLocalFallbackExecStrategy) 158 pctx.StaticVariableWithEnvOverride("RETurbineExecStrategy", "RBE_TURBINE_EXEC_STRATEGY", remoteexec.LocalExecStrategy) 159 pctx.StaticVariableWithEnvOverride("RESignApkExecStrategy", "RBE_SIGNAPK_EXEC_STRATEGY", remoteexec.LocalExecStrategy) 160 pctx.StaticVariableWithEnvOverride("REJarExecStrategy", "RBE_JAR_EXEC_STRATEGY", remoteexec.LocalExecStrategy) 161 pctx.StaticVariableWithEnvOverride("REZipExecStrategy", "RBE_ZIP_EXEC_STRATEGY", remoteexec.LocalExecStrategy) 162 163 pctx.HostJavaToolVariable("JacocoCLIJar", "jacoco-cli.jar") 164 165 pctx.HostBinToolVariable("ManifestCheckCmd", "manifest_check") 166 pctx.HostBinToolVariable("ManifestFixerCmd", "manifest_fixer") 167 168 pctx.HostBinToolVariable("ManifestMergerCmd", "manifest-merger") 169 170 pctx.HostBinToolVariable("Class2NonSdkList", "class2nonsdklist") 171 pctx.HostBinToolVariable("HiddenAPI", "hiddenapi") 172 173 hostBinToolVariableWithSdkToolsPrebuilt("Aapt2Cmd", "aapt2") 174 hostBinToolVariableWithBuildToolsPrebuilt("AidlCmd", "aidl") 175 hostBinToolVariableWithBuildToolsPrebuilt("ZipAlign", "zipalign") 176 177 hostJavaToolVariableWithSdkToolsPrebuilt("SignapkCmd", "signapk") 178 // TODO(ccross): this should come from the signapk dependencies, but we don't have any way 179 // to express host JNI dependencies yet. 180 hostJNIToolVariableWithSdkToolsPrebuilt("SignapkJniLibrary", "libconscrypt_openjdk_jni") 181} 182 183func hostBinToolVariableWithSdkToolsPrebuilt(name, tool string) { 184 pctx.VariableFunc(name, func(ctx android.PackageVarContext) string { 185 if ctx.Config().AlwaysUsePrebuiltSdks() { 186 return filepath.Join("prebuilts/sdk/tools", runtime.GOOS, "bin", tool) 187 } else { 188 return ctx.Config().HostToolPath(ctx, tool).String() 189 } 190 }) 191} 192 193func hostJavaToolVariableWithSdkToolsPrebuilt(name, tool string) { 194 pctx.VariableFunc(name, func(ctx android.PackageVarContext) string { 195 if ctx.Config().AlwaysUsePrebuiltSdks() { 196 return filepath.Join("prebuilts/sdk/tools/lib", tool+".jar") 197 } else { 198 return ctx.Config().HostJavaToolPath(ctx, tool+".jar").String() 199 } 200 }) 201} 202 203func hostJNIToolVariableWithSdkToolsPrebuilt(name, tool string) { 204 pctx.VariableFunc(name, func(ctx android.PackageVarContext) string { 205 if ctx.Config().AlwaysUsePrebuiltSdks() { 206 ext := ".so" 207 if runtime.GOOS == "darwin" { 208 ext = ".dylib" 209 } 210 return filepath.Join("prebuilts/sdk/tools", runtime.GOOS, "lib64", tool+ext) 211 } else { 212 return ctx.Config().HostJNIToolPath(ctx, tool).String() 213 } 214 }) 215} 216 217func hostBinToolVariableWithBuildToolsPrebuilt(name, tool string) { 218 pctx.VariableFunc(name, func(ctx android.PackageVarContext) string { 219 if ctx.Config().AlwaysUsePrebuiltSdks() { 220 return filepath.Join("prebuilts/build-tools", ctx.Config().PrebuiltOS(), "bin", tool) 221 } else { 222 return ctx.Config().HostToolPath(ctx, tool).String() 223 } 224 }) 225} 226 227// JavaCmd returns a SourcePath object with the path to the java command. 228func JavaCmd(ctx android.PathContext) android.SourcePath { 229 return javaTool(ctx, "java") 230} 231 232// JavadocCmd returns a SourcePath object with the path to the java command. 233func JavadocCmd(ctx android.PathContext) android.SourcePath { 234 return javaTool(ctx, "javadoc") 235} 236 237func javaTool(ctx android.PathContext, tool string) android.SourcePath { 238 type javaToolKey string 239 240 key := android.NewCustomOnceKey(javaToolKey(tool)) 241 242 return ctx.Config().OnceSourcePath(key, func() android.SourcePath { 243 return javaToolchain(ctx).Join(ctx, tool) 244 }) 245 246} 247 248var javaToolchainKey = android.NewOnceKey("javaToolchain") 249 250func javaToolchain(ctx android.PathContext) android.SourcePath { 251 return ctx.Config().OnceSourcePath(javaToolchainKey, func() android.SourcePath { 252 return javaHome(ctx).Join(ctx, "bin") 253 }) 254} 255 256var javaHomeKey = android.NewOnceKey("javaHome") 257 258func javaHome(ctx android.PathContext) android.SourcePath { 259 return ctx.Config().OnceSourcePath(javaHomeKey, func() android.SourcePath { 260 // This is set up and guaranteed by soong_ui 261 return android.PathForSource(ctx, ctx.Config().Getenv("ANDROID_JAVA_HOME")) 262 }) 263} 264