blob: 75176c9854467ec1fef2c3b973a1f90987808123 [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 Cross3bc7ffa2017-11-22 16:19:37 -080018 "path/filepath"
19 "runtime"
Colin Cross64162712017-08-08 13:17:59 -070020 "strings"
21
22 _ "github.com/google/blueprint/bootstrap"
23
24 "android/soong/android"
25)
Colin Cross3e3e72d2017-06-22 17:20:19 -070026
27var (
Colin Cross64162712017-08-08 13:17:59 -070028 pctx = android.NewPackageContext("android/soong/java/config")
29
Colin Crosscb2c9292017-09-23 19:57:16 -070030 DefaultBootclasspathLibraries = []string{"core-oj", "core-libart"}
Colin Cross1369cdb2017-09-29 17:58:17 -070031 DefaultSystemModules = "core-system-modules"
Colin Crosscb2c9292017-09-23 19:57:16 -070032 DefaultLibraries = []string{"ext", "framework", "okhttp"}
Colin Crosscb933592017-11-22 13:49:43 -080033
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 Cross3e3e72d2017-06-22 17:20:19 -070043)
44
Colin Cross64162712017-08-08 13:17:59 -070045func init() {
46 pctx.Import("github.com/google/blueprint/bootstrap")
47
Colin Crossfee57cb2017-09-05 13:16:45 -070048 pctx.StaticVariable("JavacHeapSize", "2048M")
49 pctx.StaticVariable("JavacHeapFlags", "-J-Xmx${JavacHeapSize}")
Colin Cross3203dde2017-08-28 17:23:21 -070050
Colin Cross64162712017-08-08 13:17:59 -070051 pctx.StaticVariable("CommonJdkFlags", strings.Join([]string{
Colin Cross64162712017-08-08 13:17:59 -070052 `-Xmaxerrs 9999999`,
53 `-encoding UTF-8`,
54 `-sourcepath ""`,
55 `-g`,
Colin Cross945c0002017-09-19 10:52:23 -070056 // 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 Cross64162712017-08-08 13:17:59 -070062
Colin Cross1369cdb2017-09-29 17:58:17 -070063 // b/65004097: prevent using java.lang.invoke.StringConcatFactory when using -target 1.9
64 `-XDstringConcat=inline`,
65 }, " "))
Colin Cross64162712017-08-08 13:17:59 -070066
67 pctx.VariableConfigMethod("hostPrebuiltTag", android.Config.PrebuiltOS)
68
Colin Cross0875c522017-11-28 17:34:01 -080069 pctx.VariableFunc("JavaHome", func(config android.Config) (string, error) {
Dan Willemsend9e8f0a2017-10-30 13:42:06 -070070 // This is set up and guaranteed by soong_ui
Colin Cross0875c522017-11-28 17:34:01 -080071 return config.Getenv("ANDROID_JAVA_HOME"), nil
Colin Crosse2ad2302017-10-05 16:48:56 -070072 })
73
Colin Cross64162712017-08-08 13:17:59 -070074 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 Thierer77d0b412017-08-31 16:08:39 +010080 pctx.SourcePathVariable("JlinkCmd", "${JavaToolchain}/jlink")
81 pctx.SourcePathVariable("JmodCmd", "${JavaToolchain}/jmod")
Colin Cross1369cdb2017-09-29 17:58:17 -070082 pctx.SourcePathVariable("JrtFsJar", "${JavaHome}/lib/jrt-fs.jar")
Nan Zhanged19fc32017-10-19 13:06:22 -070083 pctx.SourcePathVariable("Ziptime", "prebuilts/build-tools/${hostPrebuiltTag}/bin/ziptime")
Colin Cross64162712017-08-08 13:17:59 -070084
Colin Crossaf050172017-11-15 23:01:59 -080085 pctx.SourcePathVariable("ExtractSrcJarsCmd", "build/soong/scripts/extract-srcjars.sh")
Colin Crossb852a582017-08-10 17:58:12 -070086 pctx.SourcePathVariable("JarArgsCmd", "build/soong/scripts/jar-args.sh")
Colin Crossa4820652017-10-17 13:56:52 -070087 pctx.HostBinToolVariable("SoongZipCmd", "soong_zip")
88 pctx.HostBinToolVariable("MergeZipsCmd", "merge_zips")
Colin Crosscb933592017-11-22 13:49:43 -080089 pctx.HostBinToolVariable("Zip2ZipCmd", "zip2zip")
Colin Cross0875c522017-11-28 17:34:01 -080090 pctx.VariableFunc("DxCmd", func(config android.Config) (string, error) {
91 if config.IsEnvFalse("USE_D8") {
92 if config.UnbundledBuild() || config.IsPdkBuild() {
Yohann Roussel2e19cd82017-10-23 14:55:05 +020093 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 Leung1d476fc2017-10-17 18:50:50 -0700101 } else {
Yohann Roussel2e19cd82017-10-23 14:55:05 +0200102 path, err := pctx.HostBinToolPath(config, "d8-compat-dx")
Alan Leung1d476fc2017-10-17 18:50:50 -0700103 if err != nil {
104 return "", err
105 }
106 return path.String(), nil
107 }
108 })
Colin Crossf0056cb2017-12-22 15:56:08 -0800109 pctx.HostBinToolVariable("D8Cmd", "d8")
Colin Cross66dbc0b2017-12-28 12:23:20 -0800110 pctx.HostBinToolVariable("R8Cmd", "r8-compat-proguard")
Colin Crossf0056cb2017-12-22 15:56:08 -0800111
Colin Cross0875c522017-11-28 17:34:01 -0800112 pctx.VariableFunc("TurbineJar", func(config android.Config) (string, error) {
Nan Zhang9a364182017-10-25 11:11:37 -0700113 turbine := "turbine.jar"
Colin Cross0875c522017-11-28 17:34:01 -0800114 if config.UnbundledBuild() {
Nan Zhang9a364182017-10-25 11:11:37 -0700115 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 Leung1d476fc2017-10-17 18:50:50 -0700124
Colin Cross64162712017-08-08 13:17:59 -0700125 pctx.HostJavaToolVariable("JarjarCmd", "jarjar.jar")
Colin Cross6ade34f2017-09-15 13:00:47 -0700126 pctx.HostJavaToolVariable("DesugarJar", "desugar.jar")
Colin Cross64162712017-08-08 13:17:59 -0700127
Colin Crossa4820652017-10-17 13:56:52 -0700128 pctx.HostBinToolVariable("SoongJavacWrapper", "soong_javac_wrapper")
129
Colin Cross0875c522017-11-28 17:34:01 -0800130 pctx.VariableFunc("JavacWrapper", func(config android.Config) (string, error) {
131 if override := config.Getenv("JAVAC_WRAPPER"); override != "" {
Colin Cross64162712017-08-08 13:17:59 -0700132 return override + " ", nil
133 }
134 return "", nil
135 })
Colin Crosscb933592017-11-22 13:49:43 -0800136
137 pctx.HostJavaToolVariable("JacocoCLIJar", "jacoco-cli.jar")
Colin Cross3bc7ffa2017-11-22 16:19:37 -0800138
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 Cross42f3a762017-12-02 16:14:26 -0800153 hostBinToolVariableWithPrebuilt("Aapt2Cmd", "prebuilts/sdk/tools", "aapt2")
Colin Cross64162712017-08-08 13:17:59 -0700154}