• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
15package config
16
17import (
18	"path/filepath"
19	"runtime"
20	"strings"
21
22	_ "github.com/google/blueprint/bootstrap"
23
24	"android/soong/android"
25)
26
27var (
28	pctx = android.NewPackageContext("android/soong/java/config")
29
30	DefaultBootclasspathLibraries = []string{"core.platform.api.stubs", "core-lambda-stubs"}
31	DefaultSystemModules          = "core-platform-api-stubs-system-modules"
32	DefaultLibraries              = []string{"ext", "framework", "updatable_media_stubs"}
33	DefaultLambdaStubsLibrary     = "core-lambda-stubs"
34	SdkLambdaStubsPath            = "prebuilts/sdk/tools/core-lambda-stubs.jar"
35
36	DefaultJacocoExcludeFilter = []string{"org.junit.*", "org.jacoco.*", "org.mockito.*"}
37
38	InstrumentFrameworkModules = []string{
39		"framework",
40		"telephony-common",
41		"services",
42		"android.car",
43		"android.car7",
44		"conscrypt",
45		"core-oj",
46		"core-libart",
47		"updatable-media",
48	}
49)
50
51func init() {
52	pctx.Import("github.com/google/blueprint/bootstrap")
53
54	pctx.StaticVariable("JavacHeapSize", "2048M")
55	pctx.StaticVariable("JavacHeapFlags", "-J-Xmx${JavacHeapSize}")
56	pctx.StaticVariable("DexFlags", "-JXX:+TieredCompilation -JXX:TieredStopAtLevel=1")
57
58	pctx.StaticVariable("CommonJdkFlags", strings.Join([]string{
59		`-Xmaxerrs 9999999`,
60		`-encoding UTF-8`,
61		`-sourcepath ""`,
62		`-g`,
63		// Turbine leaves out bridges which can cause javac to unnecessarily insert them into
64		// subclasses (b/65645120).  Setting this flag causes our custom javac to assume that
65		// the missing bridges will exist at runtime and not recreate them in subclasses.
66		// If a different javac is used the flag will be ignored and extra bridges will be inserted.
67		// The flag is implemented by https://android-review.googlesource.com/c/486427
68		`-XDskipDuplicateBridges=true`,
69
70		// b/65004097: prevent using java.lang.invoke.StringConcatFactory when using -target 1.9
71		`-XDstringConcat=inline`,
72	}, " "))
73
74	pctx.VariableConfigMethod("hostPrebuiltTag", android.Config.PrebuiltOS)
75
76	pctx.VariableFunc("JavaHome", func(ctx android.PackageVarContext) string {
77		// This is set up and guaranteed by soong_ui
78		return ctx.Config().Getenv("ANDROID_JAVA_HOME")
79	})
80
81	pctx.SourcePathVariable("JavaToolchain", "${JavaHome}/bin")
82	pctx.SourcePathVariableWithEnvOverride("JavacCmd",
83		"${JavaToolchain}/javac", "ALTERNATE_JAVAC")
84	pctx.SourcePathVariable("JavaCmd", "${JavaToolchain}/java")
85	pctx.SourcePathVariable("JarCmd", "${JavaToolchain}/jar")
86	pctx.SourcePathVariable("JavadocCmd", "${JavaToolchain}/javadoc")
87	pctx.SourcePathVariable("JlinkCmd", "${JavaToolchain}/jlink")
88	pctx.SourcePathVariable("JmodCmd", "${JavaToolchain}/jmod")
89	pctx.SourcePathVariable("JrtFsJar", "${JavaHome}/lib/jrt-fs.jar")
90	pctx.SourcePathVariable("Ziptime", "prebuilts/build-tools/${hostPrebuiltTag}/bin/ziptime")
91
92	pctx.SourcePathVariable("GenKotlinBuildFileCmd", "build/soong/scripts/gen-kotlin-build-file.sh")
93
94	pctx.SourcePathVariable("JarArgsCmd", "build/soong/scripts/jar-args.sh")
95	pctx.SourcePathVariable("PackageCheckCmd", "build/soong/scripts/package-check.sh")
96	pctx.HostBinToolVariable("ExtractJarPackagesCmd", "extract_jar_packages")
97	pctx.HostBinToolVariable("SoongZipCmd", "soong_zip")
98	pctx.HostBinToolVariable("MergeZipsCmd", "merge_zips")
99	pctx.HostBinToolVariable("Zip2ZipCmd", "zip2zip")
100	pctx.HostBinToolVariable("ZipSyncCmd", "zipsync")
101	pctx.HostBinToolVariable("ApiCheckCmd", "apicheck")
102	pctx.HostBinToolVariable("D8Cmd", "d8")
103	pctx.HostBinToolVariable("R8Cmd", "r8-compat-proguard")
104	pctx.HostBinToolVariable("HiddenAPICmd", "hiddenapi")
105
106	pctx.VariableFunc("TurbineJar", func(ctx android.PackageVarContext) string {
107		turbine := "turbine.jar"
108		if ctx.Config().UnbundledBuild() {
109			return "prebuilts/build-tools/common/framework/" + turbine
110		} else {
111			return pctx.HostJavaToolPath(ctx, turbine).String()
112		}
113	})
114
115	pctx.HostJavaToolVariable("JarjarCmd", "jarjar.jar")
116	pctx.HostJavaToolVariable("JsilverJar", "jsilver.jar")
117	pctx.HostJavaToolVariable("DoclavaJar", "doclava.jar")
118	pctx.HostJavaToolVariable("MetalavaJar", "metalava.jar")
119	pctx.HostJavaToolVariable("DokkaJar", "dokka.jar")
120	pctx.HostJavaToolVariable("JetifierJar", "jetifier.jar")
121
122	pctx.HostBinToolVariable("SoongJavacWrapper", "soong_javac_wrapper")
123	pctx.HostBinToolVariable("DexpreoptGen", "dexpreopt_gen")
124
125	pctx.VariableFunc("JavacWrapper", func(ctx android.PackageVarContext) string {
126		if override := ctx.Config().Getenv("JAVAC_WRAPPER"); override != "" {
127			return override + " "
128		}
129		return ""
130	})
131
132	pctx.HostJavaToolVariable("JacocoCLIJar", "jacoco-cli.jar")
133
134	hostBinToolVariableWithPrebuilt := func(name, prebuiltDir, tool string) {
135		pctx.VariableFunc(name, func(ctx android.PackageVarContext) string {
136			if ctx.Config().UnbundledBuild() || ctx.Config().IsPdkBuild() {
137				return filepath.Join(prebuiltDir, runtime.GOOS, "bin", tool)
138			} else {
139				return pctx.HostBinToolPath(ctx, tool).String()
140			}
141		})
142	}
143
144	hostBinToolVariableWithPrebuilt("Aapt2Cmd", "prebuilts/sdk/tools", "aapt2")
145
146	pctx.SourcePathVariable("ManifestFixerCmd", "build/soong/scripts/manifest_fixer.py")
147
148	pctx.HostBinToolVariable("ManifestMergerCmd", "manifest-merger")
149
150	pctx.HostBinToolVariable("ZipAlign", "zipalign")
151
152	pctx.HostBinToolVariable("Class2Greylist", "class2greylist")
153	pctx.HostBinToolVariable("HiddenAPI", "hiddenapi")
154}
155