blob: d4994a1c9ef6ac13245d3df815b22e4da3c4d8a0 [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 Cross64162712017-08-08 13:17:59 -070018 "strings"
19
20 _ "github.com/google/blueprint/bootstrap"
21
22 "android/soong/android"
23)
Colin Cross3e3e72d2017-06-22 17:20:19 -070024
25var (
Colin Cross64162712017-08-08 13:17:59 -070026 pctx = android.NewPackageContext("android/soong/java/config")
27
Colin Crosscb2c9292017-09-23 19:57:16 -070028 DefaultBootclasspathLibraries = []string{"core-oj", "core-libart"}
Colin Cross1369cdb2017-09-29 17:58:17 -070029 DefaultSystemModules = "core-system-modules"
Colin Crosscb2c9292017-09-23 19:57:16 -070030 DefaultLibraries = []string{"ext", "framework", "okhttp"}
Colin Cross3e3e72d2017-06-22 17:20:19 -070031)
32
Colin Cross64162712017-08-08 13:17:59 -070033func init() {
34 pctx.Import("github.com/google/blueprint/bootstrap")
35
Colin Crossfee57cb2017-09-05 13:16:45 -070036 pctx.StaticVariable("JavacHeapSize", "2048M")
37 pctx.StaticVariable("JavacHeapFlags", "-J-Xmx${JavacHeapSize}")
Colin Cross3203dde2017-08-28 17:23:21 -070038
Colin Cross64162712017-08-08 13:17:59 -070039 pctx.StaticVariable("CommonJdkFlags", strings.Join([]string{
Colin Cross64162712017-08-08 13:17:59 -070040 `-Xmaxerrs 9999999`,
41 `-encoding UTF-8`,
42 `-sourcepath ""`,
43 `-g`,
Colin Cross945c0002017-09-19 10:52:23 -070044 // 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 Cross64162712017-08-08 13:17:59 -070050
Colin Cross1369cdb2017-09-29 17:58:17 -070051 // b/65004097: prevent using java.lang.invoke.StringConcatFactory when using -target 1.9
52 `-XDstringConcat=inline`,
53 }, " "))
Colin Cross64162712017-08-08 13:17:59 -070054
55 pctx.VariableConfigMethod("hostPrebuiltTag", android.Config.PrebuiltOS)
56
Colin Crosse2ad2302017-10-05 16:48:56 -070057 pctx.VariableFunc("JavaHome", func(config interface{}) (string, error) {
Dan Willemsend9e8f0a2017-10-30 13:42:06 -070058 // This is set up and guaranteed by soong_ui
59 return config.(android.Config).Getenv("ANDROID_JAVA_HOME"), nil
Colin Crosse2ad2302017-10-05 16:48:56 -070060 })
61
Colin Cross64162712017-08-08 13:17:59 -070062 pctx.SourcePathVariable("JavaToolchain", "${JavaHome}/bin")
63 pctx.SourcePathVariableWithEnvOverride("JavacCmd",
64 "${JavaToolchain}/javac", "ALTERNATE_JAVAC")
65 pctx.SourcePathVariable("JavaCmd", "${JavaToolchain}/java")
66 pctx.SourcePathVariable("JarCmd", "${JavaToolchain}/jar")
67 pctx.SourcePathVariable("JavadocCmd", "${JavaToolchain}/javadoc")
Tobias Thierer77d0b412017-08-31 16:08:39 +010068 pctx.SourcePathVariable("JlinkCmd", "${JavaToolchain}/jlink")
69 pctx.SourcePathVariable("JmodCmd", "${JavaToolchain}/jmod")
Colin Cross1369cdb2017-09-29 17:58:17 -070070 pctx.SourcePathVariable("JrtFsJar", "${JavaHome}/lib/jrt-fs.jar")
Nan Zhanged19fc32017-10-19 13:06:22 -070071 pctx.SourcePathVariable("Ziptime", "prebuilts/build-tools/${hostPrebuiltTag}/bin/ziptime")
Colin Cross64162712017-08-08 13:17:59 -070072
Colin Cross8eadbf02017-10-24 17:46:00 -070073 pctx.SourcePathVariable("ExtractSrcJarsCmd", "build/soong/scripts/extract-src-jars.sh")
Colin Crossb852a582017-08-10 17:58:12 -070074 pctx.SourcePathVariable("JarArgsCmd", "build/soong/scripts/jar-args.sh")
Colin Crossa4820652017-10-17 13:56:52 -070075 pctx.HostBinToolVariable("SoongZipCmd", "soong_zip")
76 pctx.HostBinToolVariable("MergeZipsCmd", "merge_zips")
Alan Leung1d476fc2017-10-17 18:50:50 -070077 pctx.VariableFunc("DxCmd", func(config interface{}) (string, error) {
Alan Leung899f3742017-10-20 13:36:29 -070078 if config.(android.Config).IsEnvFalse("USE_D8") {
Yohann Roussel2e19cd82017-10-23 14:55:05 +020079 if config.(android.Config).UnbundledBuild() || config.(android.Config).IsPdkBuild() {
80 return "prebuilts/build-tools/common/bin/dx", nil
81 } else {
82 path, err := pctx.HostBinToolPath(config, "dx")
83 if err != nil {
84 return "", err
85 }
86 return path.String(), nil
87 }
Alan Leung1d476fc2017-10-17 18:50:50 -070088 } else {
Yohann Roussel2e19cd82017-10-23 14:55:05 +020089 path, err := pctx.HostBinToolPath(config, "d8-compat-dx")
Alan Leung1d476fc2017-10-17 18:50:50 -070090 if err != nil {
91 return "", err
92 }
93 return path.String(), nil
94 }
95 })
Nan Zhang9a364182017-10-25 11:11:37 -070096 pctx.VariableFunc("TurbineJar", func(config interface{}) (string, error) {
97 turbine := "turbine.jar"
98 if config.(android.Config).UnbundledBuild() {
99 return "prebuilts/build-tools/common/framework/" + turbine, nil
100 } else {
101 path, err := pctx.HostJavaToolPath(config, turbine)
102 if err != nil {
103 return "", err
104 }
105 return path.String(), nil
106 }
107 })
Alan Leung1d476fc2017-10-17 18:50:50 -0700108
Colin Cross64162712017-08-08 13:17:59 -0700109 pctx.HostJavaToolVariable("JarjarCmd", "jarjar.jar")
Colin Cross6ade34f2017-09-15 13:00:47 -0700110 pctx.HostJavaToolVariable("DesugarJar", "desugar.jar")
Colin Cross64162712017-08-08 13:17:59 -0700111
Colin Crossa4820652017-10-17 13:56:52 -0700112 pctx.HostBinToolVariable("SoongJavacWrapper", "soong_javac_wrapper")
113
Colin Cross64162712017-08-08 13:17:59 -0700114 pctx.VariableFunc("JavacWrapper", func(config interface{}) (string, error) {
115 if override := config.(android.Config).Getenv("JAVAC_WRAPPER"); override != "" {
116 return override + " ", nil
117 }
118 return "", nil
119 })
120}