Colin Cross | 3e3e72d | 2017-06-22 17:20:19 -0700 | [diff] [blame] | 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 | |
| 15 | package config |
| 16 | |
Colin Cross | 6416271 | 2017-08-08 13:17:59 -0700 | [diff] [blame] | 17 | import ( |
Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 18 | "path/filepath" |
| 19 | "runtime" |
Colin Cross | 6416271 | 2017-08-08 13:17:59 -0700 | [diff] [blame] | 20 | "strings" |
| 21 | |
| 22 | _ "github.com/google/blueprint/bootstrap" |
| 23 | |
| 24 | "android/soong/android" |
| 25 | ) |
Colin Cross | 3e3e72d | 2017-06-22 17:20:19 -0700 | [diff] [blame] | 26 | |
| 27 | var ( |
Colin Cross | 6416271 | 2017-08-08 13:17:59 -0700 | [diff] [blame] | 28 | pctx = android.NewPackageContext("android/soong/java/config") |
| 29 | |
Colin Cross | cb2c929 | 2017-09-23 19:57:16 -0700 | [diff] [blame] | 30 | DefaultBootclasspathLibraries = []string{"core-oj", "core-libart"} |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 31 | DefaultSystemModules = "core-system-modules" |
Colin Cross | cb2c929 | 2017-09-23 19:57:16 -0700 | [diff] [blame] | 32 | DefaultLibraries = []string{"ext", "framework", "okhttp"} |
Colin Cross | cb93359 | 2017-11-22 13:49:43 -0800 | [diff] [blame] | 33 | |
| 34 | DefaultJacocoExcludeFilter = []string{"org.junit.*", "org.jacoco.*", "org.mockito.*"} |
| 35 | |
| 36 | InstrumentFrameworkModules = []string{ |
| 37 | "framework", |
| 38 | "telephony-common", |
| 39 | "services", |
| 40 | "android.car", |
| 41 | "android.car7", |
| 42 | } |
Colin Cross | 3e3e72d | 2017-06-22 17:20:19 -0700 | [diff] [blame] | 43 | ) |
| 44 | |
Colin Cross | 6416271 | 2017-08-08 13:17:59 -0700 | [diff] [blame] | 45 | func init() { |
| 46 | pctx.Import("github.com/google/blueprint/bootstrap") |
| 47 | |
Colin Cross | fee57cb | 2017-09-05 13:16:45 -0700 | [diff] [blame] | 48 | pctx.StaticVariable("JavacHeapSize", "2048M") |
| 49 | pctx.StaticVariable("JavacHeapFlags", "-J-Xmx${JavacHeapSize}") |
Colin Cross | 3203dde | 2017-08-28 17:23:21 -0700 | [diff] [blame] | 50 | |
Colin Cross | 6416271 | 2017-08-08 13:17:59 -0700 | [diff] [blame] | 51 | pctx.StaticVariable("CommonJdkFlags", strings.Join([]string{ |
Colin Cross | 6416271 | 2017-08-08 13:17:59 -0700 | [diff] [blame] | 52 | `-Xmaxerrs 9999999`, |
| 53 | `-encoding UTF-8`, |
| 54 | `-sourcepath ""`, |
| 55 | `-g`, |
Colin Cross | 945c000 | 2017-09-19 10:52:23 -0700 | [diff] [blame] | 56 | // Turbine leaves out bridges which can cause javac to unnecessarily insert them into |
| 57 | // subclasses (b/65645120). Setting this flag causes our custom javac to assume that |
| 58 | // the missing bridges will exist at runtime and not recreate them in subclasses. |
| 59 | // If a different javac is used the flag will be ignored and extra bridges will be inserted. |
| 60 | // The flag is implemented by https://android-review.googlesource.com/c/486427 |
| 61 | `-XDskipDuplicateBridges=true`, |
Colin Cross | 6416271 | 2017-08-08 13:17:59 -0700 | [diff] [blame] | 62 | |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 63 | // b/65004097: prevent using java.lang.invoke.StringConcatFactory when using -target 1.9 |
| 64 | `-XDstringConcat=inline`, |
| 65 | }, " ")) |
Colin Cross | 6416271 | 2017-08-08 13:17:59 -0700 | [diff] [blame] | 66 | |
| 67 | pctx.VariableConfigMethod("hostPrebuiltTag", android.Config.PrebuiltOS) |
| 68 | |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 69 | pctx.VariableFunc("JavaHome", func(config android.Config) (string, error) { |
Dan Willemsen | d9e8f0a | 2017-10-30 13:42:06 -0700 | [diff] [blame] | 70 | // This is set up and guaranteed by soong_ui |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 71 | return config.Getenv("ANDROID_JAVA_HOME"), nil |
Colin Cross | e2ad230 | 2017-10-05 16:48:56 -0700 | [diff] [blame] | 72 | }) |
| 73 | |
Colin Cross | 6416271 | 2017-08-08 13:17:59 -0700 | [diff] [blame] | 74 | pctx.SourcePathVariable("JavaToolchain", "${JavaHome}/bin") |
| 75 | pctx.SourcePathVariableWithEnvOverride("JavacCmd", |
| 76 | "${JavaToolchain}/javac", "ALTERNATE_JAVAC") |
| 77 | pctx.SourcePathVariable("JavaCmd", "${JavaToolchain}/java") |
| 78 | pctx.SourcePathVariable("JarCmd", "${JavaToolchain}/jar") |
| 79 | pctx.SourcePathVariable("JavadocCmd", "${JavaToolchain}/javadoc") |
Tobias Thierer | 77d0b41 | 2017-08-31 16:08:39 +0100 | [diff] [blame] | 80 | pctx.SourcePathVariable("JlinkCmd", "${JavaToolchain}/jlink") |
| 81 | pctx.SourcePathVariable("JmodCmd", "${JavaToolchain}/jmod") |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 82 | pctx.SourcePathVariable("JrtFsJar", "${JavaHome}/lib/jrt-fs.jar") |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 83 | pctx.SourcePathVariable("Ziptime", "prebuilts/build-tools/${hostPrebuiltTag}/bin/ziptime") |
Colin Cross | 6416271 | 2017-08-08 13:17:59 -0700 | [diff] [blame] | 84 | |
Colin Cross | af05017 | 2017-11-15 23:01:59 -0800 | [diff] [blame] | 85 | pctx.SourcePathVariable("ExtractSrcJarsCmd", "build/soong/scripts/extract-srcjars.sh") |
Colin Cross | b852a58 | 2017-08-10 17:58:12 -0700 | [diff] [blame] | 86 | pctx.SourcePathVariable("JarArgsCmd", "build/soong/scripts/jar-args.sh") |
Colin Cross | a482065 | 2017-10-17 13:56:52 -0700 | [diff] [blame] | 87 | pctx.HostBinToolVariable("SoongZipCmd", "soong_zip") |
| 88 | pctx.HostBinToolVariable("MergeZipsCmd", "merge_zips") |
Colin Cross | cb93359 | 2017-11-22 13:49:43 -0800 | [diff] [blame] | 89 | pctx.HostBinToolVariable("Zip2ZipCmd", "zip2zip") |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 90 | pctx.VariableFunc("DxCmd", func(config android.Config) (string, error) { |
| 91 | if config.IsEnvFalse("USE_D8") { |
| 92 | if config.UnbundledBuild() || config.IsPdkBuild() { |
Yohann Roussel | 2e19cd8 | 2017-10-23 14:55:05 +0200 | [diff] [blame] | 93 | return "prebuilts/build-tools/common/bin/dx", nil |
| 94 | } else { |
| 95 | path, err := pctx.HostBinToolPath(config, "dx") |
| 96 | if err != nil { |
| 97 | return "", err |
| 98 | } |
| 99 | return path.String(), nil |
| 100 | } |
Alan Leung | 1d476fc | 2017-10-17 18:50:50 -0700 | [diff] [blame] | 101 | } else { |
Yohann Roussel | 2e19cd8 | 2017-10-23 14:55:05 +0200 | [diff] [blame] | 102 | path, err := pctx.HostBinToolPath(config, "d8-compat-dx") |
Alan Leung | 1d476fc | 2017-10-17 18:50:50 -0700 | [diff] [blame] | 103 | if err != nil { |
| 104 | return "", err |
| 105 | } |
| 106 | return path.String(), nil |
| 107 | } |
| 108 | }) |
Colin Cross | f0056cb | 2017-12-22 15:56:08 -0800 | [diff] [blame] | 109 | pctx.HostBinToolVariable("D8Cmd", "d8") |
Colin Cross | 66dbc0b | 2017-12-28 12:23:20 -0800 | [diff] [blame^] | 110 | pctx.HostBinToolVariable("R8Cmd", "r8-compat-proguard") |
Colin Cross | f0056cb | 2017-12-22 15:56:08 -0800 | [diff] [blame] | 111 | |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 112 | pctx.VariableFunc("TurbineJar", func(config android.Config) (string, error) { |
Nan Zhang | 9a36418 | 2017-10-25 11:11:37 -0700 | [diff] [blame] | 113 | turbine := "turbine.jar" |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 114 | if config.UnbundledBuild() { |
Nan Zhang | 9a36418 | 2017-10-25 11:11:37 -0700 | [diff] [blame] | 115 | return "prebuilts/build-tools/common/framework/" + turbine, nil |
| 116 | } else { |
| 117 | path, err := pctx.HostJavaToolPath(config, turbine) |
| 118 | if err != nil { |
| 119 | return "", err |
| 120 | } |
| 121 | return path.String(), nil |
| 122 | } |
| 123 | }) |
Alan Leung | 1d476fc | 2017-10-17 18:50:50 -0700 | [diff] [blame] | 124 | |
Colin Cross | 6416271 | 2017-08-08 13:17:59 -0700 | [diff] [blame] | 125 | pctx.HostJavaToolVariable("JarjarCmd", "jarjar.jar") |
Colin Cross | 6ade34f | 2017-09-15 13:00:47 -0700 | [diff] [blame] | 126 | pctx.HostJavaToolVariable("DesugarJar", "desugar.jar") |
Colin Cross | 6416271 | 2017-08-08 13:17:59 -0700 | [diff] [blame] | 127 | |
Colin Cross | a482065 | 2017-10-17 13:56:52 -0700 | [diff] [blame] | 128 | pctx.HostBinToolVariable("SoongJavacWrapper", "soong_javac_wrapper") |
| 129 | |
Colin Cross | 0875c52 | 2017-11-28 17:34:01 -0800 | [diff] [blame] | 130 | pctx.VariableFunc("JavacWrapper", func(config android.Config) (string, error) { |
| 131 | if override := config.Getenv("JAVAC_WRAPPER"); override != "" { |
Colin Cross | 6416271 | 2017-08-08 13:17:59 -0700 | [diff] [blame] | 132 | return override + " ", nil |
| 133 | } |
| 134 | return "", nil |
| 135 | }) |
Colin Cross | cb93359 | 2017-11-22 13:49:43 -0800 | [diff] [blame] | 136 | |
| 137 | pctx.HostJavaToolVariable("JacocoCLIJar", "jacoco-cli.jar") |
Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 138 | |
| 139 | hostBinToolVariableWithPrebuilt := func(name, prebuiltDir, tool string) { |
| 140 | pctx.VariableFunc(name, func(config android.Config) (string, error) { |
| 141 | if config.UnbundledBuild() || config.IsPdkBuild() { |
| 142 | return filepath.Join(prebuiltDir, runtime.GOOS, "bin", tool), nil |
| 143 | } else { |
| 144 | if path, err := pctx.HostBinToolPath(config, tool); err != nil { |
| 145 | return "", err |
| 146 | } else { |
| 147 | return path.String(), nil |
| 148 | } |
| 149 | } |
| 150 | }) |
| 151 | } |
| 152 | |
Colin Cross | 42f3a76 | 2017-12-02 16:14:26 -0800 | [diff] [blame] | 153 | hostBinToolVariableWithPrebuilt("Aapt2Cmd", "prebuilts/sdk/tools", "aapt2") |
Colin Cross | 6416271 | 2017-08-08 13:17:59 -0700 | [diff] [blame] | 154 | } |