github.com/westcoastroms/westcoastroms-build@v0.0.0-20190928114312-2350e5a73030/build/soong/java/config/config.go (about)

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