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 | 6416271 | 2017-08-08 13:17:59 -0700 | [diff] [blame] | 18 | "strings" |
| 19 | |
| 20 | _ "github.com/google/blueprint/bootstrap" |
| 21 | |
| 22 | "android/soong/android" |
| 23 | ) |
Colin Cross | 3e3e72d | 2017-06-22 17:20:19 -0700 | [diff] [blame] | 24 | |
| 25 | var ( |
Colin Cross | 6416271 | 2017-08-08 13:17:59 -0700 | [diff] [blame] | 26 | pctx = android.NewPackageContext("android/soong/java/config") |
| 27 | |
Colin Cross | cb2c929 | 2017-09-23 19:57:16 -0700 | [diff] [blame] | 28 | DefaultBootclasspathLibraries = []string{"core-oj", "core-libart"} |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 29 | DefaultSystemModules = "core-system-modules" |
Colin Cross | cb2c929 | 2017-09-23 19:57:16 -0700 | [diff] [blame] | 30 | DefaultLibraries = []string{"ext", "framework", "okhttp"} |
Colin Cross | 3e3e72d | 2017-06-22 17:20:19 -0700 | [diff] [blame] | 31 | ) |
| 32 | |
Colin Cross | 6416271 | 2017-08-08 13:17:59 -0700 | [diff] [blame] | 33 | func init() { |
| 34 | pctx.Import("github.com/google/blueprint/bootstrap") |
| 35 | |
Colin Cross | fee57cb | 2017-09-05 13:16:45 -0700 | [diff] [blame] | 36 | pctx.StaticVariable("JavacHeapSize", "2048M") |
| 37 | pctx.StaticVariable("JavacHeapFlags", "-J-Xmx${JavacHeapSize}") |
Colin Cross | 3203dde | 2017-08-28 17:23:21 -0700 | [diff] [blame] | 38 | |
Colin Cross | 6416271 | 2017-08-08 13:17:59 -0700 | [diff] [blame] | 39 | pctx.StaticVariable("CommonJdkFlags", strings.Join([]string{ |
Colin Cross | 6416271 | 2017-08-08 13:17:59 -0700 | [diff] [blame] | 40 | `-Xmaxerrs 9999999`, |
| 41 | `-encoding UTF-8`, |
| 42 | `-sourcepath ""`, |
| 43 | `-g`, |
Colin Cross | 945c000 | 2017-09-19 10:52:23 -0700 | [diff] [blame] | 44 | // Turbine leaves out bridges which can cause javac to unnecessarily insert them into |
| 45 | // subclasses (b/65645120). Setting this flag causes our custom javac to assume that |
| 46 | // the missing bridges will exist at runtime and not recreate them in subclasses. |
| 47 | // If a different javac is used the flag will be ignored and extra bridges will be inserted. |
| 48 | // The flag is implemented by https://android-review.googlesource.com/c/486427 |
| 49 | `-XDskipDuplicateBridges=true`, |
Colin Cross | 6416271 | 2017-08-08 13:17:59 -0700 | [diff] [blame] | 50 | |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 51 | // b/65004097: prevent using java.lang.invoke.StringConcatFactory when using -target 1.9 |
| 52 | `-XDstringConcat=inline`, |
| 53 | }, " ")) |
Colin Cross | 6416271 | 2017-08-08 13:17:59 -0700 | [diff] [blame] | 54 | |
| 55 | pctx.VariableConfigMethod("hostPrebuiltTag", android.Config.PrebuiltOS) |
| 56 | |
Colin Cross | e2ad230 | 2017-10-05 16:48:56 -0700 | [diff] [blame] | 57 | pctx.VariableFunc("JavaHome", func(config interface{}) (string, error) { |
| 58 | if override := config.(android.Config).Getenv("OVERRIDE_ANDROID_JAVA_HOME"); override != "" { |
| 59 | return override, nil |
| 60 | } |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 61 | if config.(android.Config).UseOpenJDK9() { |
Colin Cross | e2ad230 | 2017-10-05 16:48:56 -0700 | [diff] [blame] | 62 | return "prebuilts/jdk/jdk9/${hostPrebuiltTag}", nil |
| 63 | } |
| 64 | return "prebuilts/jdk/jdk8/${hostPrebuiltTag}", nil |
| 65 | }) |
| 66 | |
Colin Cross | 6416271 | 2017-08-08 13:17:59 -0700 | [diff] [blame] | 67 | pctx.SourcePathVariable("JavaToolchain", "${JavaHome}/bin") |
| 68 | pctx.SourcePathVariableWithEnvOverride("JavacCmd", |
| 69 | "${JavaToolchain}/javac", "ALTERNATE_JAVAC") |
| 70 | pctx.SourcePathVariable("JavaCmd", "${JavaToolchain}/java") |
| 71 | pctx.SourcePathVariable("JarCmd", "${JavaToolchain}/jar") |
| 72 | pctx.SourcePathVariable("JavadocCmd", "${JavaToolchain}/javadoc") |
Tobias Thierer | 77d0b41 | 2017-08-31 16:08:39 +0100 | [diff] [blame] | 73 | pctx.SourcePathVariable("JlinkCmd", "${JavaToolchain}/jlink") |
| 74 | pctx.SourcePathVariable("JmodCmd", "${JavaToolchain}/jmod") |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 75 | pctx.SourcePathVariable("JrtFsJar", "${JavaHome}/lib/jrt-fs.jar") |
Colin Cross | 6416271 | 2017-08-08 13:17:59 -0700 | [diff] [blame] | 76 | |
Colin Cross | b852a58 | 2017-08-10 17:58:12 -0700 | [diff] [blame] | 77 | pctx.SourcePathVariable("JarArgsCmd", "build/soong/scripts/jar-args.sh") |
Colin Cross | a482065 | 2017-10-17 13:56:52 -0700 | [diff] [blame] | 78 | pctx.HostBinToolVariable("SoongZipCmd", "soong_zip") |
| 79 | pctx.HostBinToolVariable("MergeZipsCmd", "merge_zips") |
Alan Leung | 1d476fc | 2017-10-17 18:50:50 -0700 | [diff] [blame^] | 80 | pctx.VariableFunc("DxCmd", func(config interface{}) (string, error) { |
| 81 | dexer := "dx" |
| 82 | if config.(android.Config).Getenv("USE_D8") == "true" { |
| 83 | dexer = "d8" |
| 84 | } |
| 85 | if config.(android.Config).UnbundledBuild() { |
| 86 | return "prebuilts/build-tools/common/bin/" + dexer, nil |
| 87 | } else { |
| 88 | path, err := pctx.HostBinToolPath(config, dexer) |
| 89 | if err != nil { |
| 90 | return "", err |
| 91 | } |
| 92 | return path.String(), nil |
| 93 | } |
| 94 | }) |
| 95 | |
Colin Cross | 6416271 | 2017-08-08 13:17:59 -0700 | [diff] [blame] | 96 | pctx.HostJavaToolVariable("JarjarCmd", "jarjar.jar") |
Colin Cross | 6ade34f | 2017-09-15 13:00:47 -0700 | [diff] [blame] | 97 | pctx.HostJavaToolVariable("DesugarJar", "desugar.jar") |
Colin Cross | 6416271 | 2017-08-08 13:17:59 -0700 | [diff] [blame] | 98 | |
Colin Cross | a482065 | 2017-10-17 13:56:52 -0700 | [diff] [blame] | 99 | pctx.HostBinToolVariable("SoongJavacWrapper", "soong_javac_wrapper") |
| 100 | |
Colin Cross | 6416271 | 2017-08-08 13:17:59 -0700 | [diff] [blame] | 101 | pctx.VariableFunc("JavacWrapper", func(config interface{}) (string, error) { |
| 102 | if override := config.(android.Config).Getenv("JAVAC_WRAPPER"); override != "" { |
| 103 | return override + " ", nil |
| 104 | } |
| 105 | return "", nil |
| 106 | }) |
| 107 | } |