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 ( |
| 18 | "path/filepath" |
| 19 | "strings" |
| 20 | |
| 21 | _ "github.com/google/blueprint/bootstrap" |
| 22 | |
| 23 | "android/soong/android" |
| 24 | ) |
Colin Cross | 3e3e72d | 2017-06-22 17:20:19 -0700 | [diff] [blame] | 25 | |
| 26 | var ( |
Colin Cross | 6416271 | 2017-08-08 13:17:59 -0700 | [diff] [blame] | 27 | pctx = android.NewPackageContext("android/soong/java/config") |
| 28 | |
Colin Cross | 3e3e72d | 2017-06-22 17:20:19 -0700 | [diff] [blame] | 29 | DefaultLibraries = []string{"core-oj", "core-libart", "ext", "framework", "okhttp"} |
| 30 | ) |
| 31 | |
Colin Cross | 6416271 | 2017-08-08 13:17:59 -0700 | [diff] [blame] | 32 | func init() { |
| 33 | pctx.Import("github.com/google/blueprint/bootstrap") |
| 34 | |
Colin Cross | fee57cb | 2017-09-05 13:16:45 -0700 | [diff] [blame] | 35 | pctx.StaticVariable("JavacHeapSize", "2048M") |
| 36 | pctx.StaticVariable("JavacHeapFlags", "-J-Xmx${JavacHeapSize}") |
Colin Cross | 3203dde | 2017-08-28 17:23:21 -0700 | [diff] [blame] | 37 | |
Colin Cross | 6416271 | 2017-08-08 13:17:59 -0700 | [diff] [blame] | 38 | pctx.StaticVariable("CommonJdkFlags", strings.Join([]string{ |
Colin Cross | 6416271 | 2017-08-08 13:17:59 -0700 | [diff] [blame] | 39 | `-Xmaxerrs 9999999`, |
| 40 | `-encoding UTF-8`, |
| 41 | `-sourcepath ""`, |
| 42 | `-g`, |
Colin Cross | 945c000 | 2017-09-19 10:52:23 -0700 | [diff] [blame] | 43 | // Turbine leaves out bridges which can cause javac to unnecessarily insert them into |
| 44 | // subclasses (b/65645120). Setting this flag causes our custom javac to assume that |
| 45 | // the missing bridges will exist at runtime and not recreate them in subclasses. |
| 46 | // If a different javac is used the flag will be ignored and extra bridges will be inserted. |
| 47 | // The flag is implemented by https://android-review.googlesource.com/c/486427 |
| 48 | `-XDskipDuplicateBridges=true`, |
Colin Cross | 6416271 | 2017-08-08 13:17:59 -0700 | [diff] [blame] | 49 | }, " ")) |
| 50 | |
| 51 | pctx.StaticVariable("DefaultJavaVersion", "1.8") |
| 52 | |
| 53 | pctx.VariableConfigMethod("hostPrebuiltTag", android.Config.PrebuiltOS) |
| 54 | |
| 55 | pctx.SourcePathVariableWithEnvOverride("JavaHome", |
| 56 | "prebuilts/jdk/jdk8/${hostPrebuiltTag}", "OVERRIDE_ANDROID_JAVA_HOME") |
| 57 | pctx.SourcePathVariable("JavaToolchain", "${JavaHome}/bin") |
| 58 | pctx.SourcePathVariableWithEnvOverride("JavacCmd", |
| 59 | "${JavaToolchain}/javac", "ALTERNATE_JAVAC") |
| 60 | pctx.SourcePathVariable("JavaCmd", "${JavaToolchain}/java") |
| 61 | pctx.SourcePathVariable("JarCmd", "${JavaToolchain}/jar") |
| 62 | pctx.SourcePathVariable("JavadocCmd", "${JavaToolchain}/javadoc") |
Tobias Thierer | 77d0b41 | 2017-08-31 16:08:39 +0100 | [diff] [blame] | 63 | pctx.SourcePathVariable("JlinkCmd", "${JavaToolchain}/jlink") |
| 64 | pctx.SourcePathVariable("JmodCmd", "${JavaToolchain}/jmod") |
Colin Cross | 6416271 | 2017-08-08 13:17:59 -0700 | [diff] [blame] | 65 | |
Colin Cross | b852a58 | 2017-08-10 17:58:12 -0700 | [diff] [blame] | 66 | pctx.SourcePathVariable("JarArgsCmd", "build/soong/scripts/jar-args.sh") |
Colin Cross | 0a6e007 | 2017-08-30 14:24:55 -0700 | [diff] [blame] | 67 | pctx.StaticVariable("SoongZipCmd", filepath.Join("${bootstrap.ToolDir}", "soong_zip")) |
| 68 | pctx.StaticVariable("MergeZipsCmd", filepath.Join("${bootstrap.ToolDir}", "merge_zips")) |
Colin Cross | 6416271 | 2017-08-08 13:17:59 -0700 | [diff] [blame] | 69 | pctx.HostBinToolVariable("DxCmd", "dx") |
| 70 | pctx.HostJavaToolVariable("JarjarCmd", "jarjar.jar") |
Colin Cross | 6ade34f | 2017-09-15 13:00:47 -0700 | [diff] [blame^] | 71 | pctx.HostJavaToolVariable("DesugarJar", "desugar.jar") |
Colin Cross | 6416271 | 2017-08-08 13:17:59 -0700 | [diff] [blame] | 72 | |
| 73 | pctx.VariableFunc("JavacWrapper", func(config interface{}) (string, error) { |
| 74 | if override := config.(android.Config).Getenv("JAVAC_WRAPPER"); override != "" { |
| 75 | return override + " ", nil |
| 76 | } |
| 77 | return "", nil |
| 78 | }) |
| 79 | } |
Colin Cross | 4f26bc0 | 2017-09-06 12:52:16 -0700 | [diff] [blame] | 80 | |
| 81 | func StripJavac9Flags(flags []string) []string { |
| 82 | var ret []string |
| 83 | for _, f := range flags { |
| 84 | switch { |
| 85 | case strings.HasPrefix(f, "-J--add-modules="): |
| 86 | // drop |
| 87 | default: |
| 88 | ret = append(ret, f) |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | return ret |
| 93 | } |