2015-03-31 02:20:39 +02:00
|
|
|
// Copyright 2015 Google Inc. All rights reserved.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package java
|
|
|
|
|
|
|
|
// This file generates the final rules for compiling all Java. All properties related to
|
|
|
|
// compiling should have been translated into javaBuilderFlags or another argument to the Transform*
|
|
|
|
// functions.
|
|
|
|
|
|
|
|
import (
|
2017-11-02 21:28:15 +01:00
|
|
|
"path/filepath"
|
|
|
|
"strconv"
|
2015-03-31 02:20:39 +02:00
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/google/blueprint"
|
2018-09-12 19:02:13 +02:00
|
|
|
"github.com/google/blueprint/proptools"
|
2017-09-05 22:16:45 +02:00
|
|
|
|
|
|
|
"android/soong/android"
|
2015-03-31 02:20:39 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2016-05-19 00:37:25 +02:00
|
|
|
pctx = android.NewPackageContext("android/soong/java")
|
2015-03-31 02:20:39 +02:00
|
|
|
|
|
|
|
// Compiling java is not conducive to proper dependency tracking. The path-matches-class-name
|
|
|
|
// requirement leads to unpredictable generated source file names, and a single .java file
|
|
|
|
// will get compiled into multiple .class files if it contains inner classes. To work around
|
2018-02-08 21:48:39 +01:00
|
|
|
// this, all java rules write into separate directories and then are combined into a .jar file
|
|
|
|
// (if the rule produces .class files) or a .srcjar file (if the rule produces .java files).
|
|
|
|
// .srcjar files are unzipped into a temporary directory when compiled with javac.
|
2019-11-05 00:16:11 +01:00
|
|
|
javac = pctx.AndroidRemoteStaticRule("javac", android.SUPPORTS_GOMA,
|
2015-03-31 02:20:39 +02:00
|
|
|
blueprint.RuleParams{
|
2017-10-25 02:46:00 +02:00
|
|
|
Command: `rm -rf "$outDir" "$annoDir" "$srcJarDir" && mkdir -p "$outDir" "$annoDir" "$srcJarDir" && ` +
|
2018-03-16 00:24:10 +01:00
|
|
|
`${config.ZipSyncCmd} -d $srcJarDir -l $srcJarDir/list -f "*.java" $srcJars && ` +
|
2018-06-28 07:53:20 +02:00
|
|
|
`(if [ -s $srcJarDir/list ] || [ -s $out.rsp ] ; then ` +
|
2019-06-11 22:30:13 +02:00
|
|
|
`${config.SoongJavacWrapper} ${config.JavacWrapper}${config.JavacCmd} ` +
|
|
|
|
`${config.JavacHeapFlags} ${config.JavacVmFlags} ${config.CommonJdkFlags} ` +
|
2019-01-22 06:37:16 +01:00
|
|
|
`$processorpath $processor $javacFlags $bootClasspath $classpath ` +
|
2017-08-08 22:17:59 +02:00
|
|
|
`-source $javaVersion -target $javaVersion ` +
|
2018-06-28 07:53:20 +02:00
|
|
|
`-d $outDir -s $annoDir @$out.rsp @$srcJarDir/list ; fi ) && ` +
|
2019-01-25 01:36:57 +01:00
|
|
|
`${config.SoongZipCmd} -jar -o $out -C $outDir -D $outDir && ` +
|
|
|
|
`rm -rf "$srcJarDir"`,
|
2017-10-25 02:46:00 +02:00
|
|
|
CommandDeps: []string{
|
|
|
|
"${config.JavacCmd}",
|
|
|
|
"${config.SoongZipCmd}",
|
2018-03-16 00:24:10 +01:00
|
|
|
"${config.ZipSyncCmd}",
|
2017-10-25 02:46:00 +02:00
|
|
|
},
|
2017-10-17 22:56:52 +02:00
|
|
|
CommandOrderOnly: []string{"${config.SoongJavacWrapper}"},
|
|
|
|
Rspfile: "$out.rsp",
|
|
|
|
RspfileContent: "$in",
|
2015-03-31 02:20:39 +02:00
|
|
|
},
|
2019-01-22 06:37:16 +01:00
|
|
|
"javacFlags", "bootClasspath", "classpath", "processorpath", "processor", "srcJars", "srcJarDir",
|
2017-10-25 02:46:00 +02:00
|
|
|
"outDir", "annoDir", "javaVersion")
|
2015-03-31 02:20:39 +02:00
|
|
|
|
2018-11-06 01:49:08 +01:00
|
|
|
_ = pctx.VariableFunc("kytheCorpus",
|
|
|
|
func(ctx android.PackageVarContext) string { return ctx.Config().XrefCorpusName() })
|
2019-09-27 05:14:28 +02:00
|
|
|
_ = pctx.SourcePathVariable("kytheVnames", "build/soong/vnames.json")
|
2018-11-06 01:49:08 +01:00
|
|
|
// Run it with -add-opens=java.base/java.nio=ALL-UNNAMED to avoid JDK9's warning about
|
|
|
|
// "Illegal reflective access by com.google.protobuf.Utf8$UnsafeProcessor ...
|
|
|
|
// to field java.nio.Buffer.address"
|
|
|
|
kytheExtract = pctx.AndroidStaticRule("kythe",
|
|
|
|
blueprint.RuleParams{
|
|
|
|
Command: `${config.ZipSyncCmd} -d $srcJarDir ` +
|
|
|
|
`-l $srcJarDir/list -f "*.java" $srcJars && ` +
|
|
|
|
`( [ ! -s $srcJarDir/list -a ! -s $out.rsp ] || ` +
|
|
|
|
`KYTHE_ROOT_DIRECTORY=. KYTHE_OUTPUT_FILE=$out ` +
|
|
|
|
`KYTHE_CORPUS=${kytheCorpus} ` +
|
2019-09-27 05:14:28 +02:00
|
|
|
`KYTHE_VNAMES=${kytheVnames} ` +
|
2018-11-06 01:49:08 +01:00
|
|
|
`${config.SoongJavacWrapper} ${config.JavaCmd} ` +
|
|
|
|
`--add-opens=java.base/java.nio=ALL-UNNAMED ` +
|
|
|
|
`-jar ${config.JavaKytheExtractorJar} ` +
|
|
|
|
`${config.JavacHeapFlags} ${config.CommonJdkFlags} ` +
|
|
|
|
`$processorpath $processor $javacFlags $bootClasspath $classpath ` +
|
|
|
|
`-source $javaVersion -target $javaVersion ` +
|
|
|
|
`-d $outDir -s $annoDir @$out.rsp @$srcJarDir/list)`,
|
|
|
|
CommandDeps: []string{
|
|
|
|
"${config.JavaCmd}",
|
|
|
|
"${config.JavaKytheExtractorJar}",
|
2019-09-27 05:14:28 +02:00
|
|
|
"${kytheVnames}",
|
2018-11-06 01:49:08 +01:00
|
|
|
"${config.ZipSyncCmd}",
|
|
|
|
},
|
|
|
|
CommandOrderOnly: []string{"${config.SoongJavacWrapper}"},
|
|
|
|
Rspfile: "$out.rsp",
|
|
|
|
RspfileContent: "$in",
|
|
|
|
},
|
|
|
|
"javacFlags", "bootClasspath", "classpath", "processorpath", "processor", "srcJars", "srcJarDir",
|
|
|
|
"outDir", "annoDir", "javaVersion")
|
|
|
|
|
2017-10-19 22:06:22 +02:00
|
|
|
turbine = pctx.AndroidStaticRule("turbine",
|
|
|
|
blueprint.RuleParams{
|
2018-03-08 00:14:50 +01:00
|
|
|
Command: `rm -rf "$outDir" && mkdir -p "$outDir" && ` +
|
2019-06-11 22:30:13 +02:00
|
|
|
`${config.JavaCmd} ${config.JavaVmFlags} -jar ${config.TurbineJar} --output $out.tmp ` +
|
2018-03-08 00:14:50 +01:00
|
|
|
`--temp_dir "$outDir" --sources @$out.rsp --source_jars $srcJars ` +
|
2017-10-19 22:06:22 +02:00
|
|
|
`--javacopts ${config.CommonJdkFlags} ` +
|
2018-03-07 19:51:05 +01:00
|
|
|
`$javacFlags -source $javaVersion -target $javaVersion -- $bootClasspath $classpath && ` +
|
2017-10-19 22:06:22 +02:00
|
|
|
`${config.Ziptime} $out.tmp && ` +
|
|
|
|
`(if cmp -s $out.tmp $out ; then rm $out.tmp ; else mv $out.tmp $out ; fi )`,
|
2017-10-25 02:46:00 +02:00
|
|
|
CommandDeps: []string{
|
|
|
|
"${config.TurbineJar}",
|
|
|
|
"${config.JavaCmd}",
|
|
|
|
"${config.Ziptime}",
|
|
|
|
},
|
2017-10-19 22:06:22 +02:00
|
|
|
Rspfile: "$out.rsp",
|
|
|
|
RspfileContent: "$in",
|
|
|
|
Restat: true,
|
|
|
|
},
|
2018-03-08 00:14:50 +01:00
|
|
|
"javacFlags", "bootClasspath", "classpath", "srcJars", "outDir", "javaVersion")
|
2017-10-19 22:06:22 +02:00
|
|
|
|
2016-08-30 01:14:13 +02:00
|
|
|
jar = pctx.AndroidStaticRule("jar",
|
2015-03-31 02:20:39 +02:00
|
|
|
blueprint.RuleParams{
|
Add Respfile support for soong_zip.
Sometime the size of our command line passed to soong_zip go program
exceeds the cmdline size limit. So add an RespFile support with "@" special
character prefix.
The args in the cmdline will be considered together with the
args in RespFile during soong_zip running.
Test: real tests in my local machine, and compare the
res/libphonenumber.jar before and after changes.
./cmd -o test.zip '""'-C -> [./cmd,-o,test.zip,""-C]
./cmd -o test.zip '-C -f -> [./cmd,-o,test.zip,-C -f]
./cmd -o test.zip '\"'-C -f -> [./cmd,-o,test.zip,\"-C -f]
./cmd -o test.zip '\\'-C -f -> [./cmd,-o,test.zip,\\-C -f]
./cmd -o test.zip '\a'-C -f -> [./cmd,-o,test.zip,\a-C -f]
./cmd -o test.zip \'-C -> [./cmd,-o,test.zip,'-C]
./cmd -o test.zip \\-C -> [./cmd,-o,test.zip,\-C]
./cmd -o test.zip \"-C -> [./cmd,-o,test.zip,"-C]
./cmd -o test.zip "'"-C -> [./cmd,-o,test.zip,'-C]
./cmd -o test.zip "\\"-C -f -> [./cmd,-o,test.zip,\a-C -f]
./cmd -o test.zip "\""-C -f -> [./cmd,-o,test.zip,"a-C -f]
Bug: b/72484223
Change-Id: I83c3630b70c8396c8e8a3f266244d868d754c4e8
2018-01-27 03:30:36 +01:00
|
|
|
Command: `${config.SoongZipCmd} -jar -o $out @$out.rsp`,
|
|
|
|
CommandDeps: []string{"${config.SoongZipCmd}"},
|
|
|
|
Rspfile: "$out.rsp",
|
|
|
|
RspfileContent: "$jarArgs",
|
2015-03-31 02:20:39 +02:00
|
|
|
},
|
2017-08-30 23:24:55 +02:00
|
|
|
"jarArgs")
|
|
|
|
|
2018-10-03 07:03:40 +02:00
|
|
|
zip = pctx.AndroidStaticRule("zip",
|
|
|
|
blueprint.RuleParams{
|
|
|
|
Command: `${config.SoongZipCmd} -o $out @$out.rsp`,
|
|
|
|
CommandDeps: []string{"${config.SoongZipCmd}"},
|
|
|
|
Rspfile: "$out.rsp",
|
|
|
|
RspfileContent: "$jarArgs",
|
|
|
|
},
|
|
|
|
"jarArgs")
|
|
|
|
|
2017-08-30 23:24:55 +02:00
|
|
|
combineJar = pctx.AndroidStaticRule("combineJar",
|
|
|
|
blueprint.RuleParams{
|
2018-02-08 00:41:31 +01:00
|
|
|
Command: `${config.MergeZipsCmd} --ignore-duplicates -j $jarArgs $out $in`,
|
2017-08-30 23:24:55 +02:00
|
|
|
CommandDeps: []string{"${config.MergeZipsCmd}"},
|
|
|
|
},
|
2017-09-13 07:50:46 +02:00
|
|
|
"jarArgs")
|
2015-03-31 02:20:39 +02:00
|
|
|
|
2016-08-30 01:14:13 +02:00
|
|
|
jarjar = pctx.AndroidStaticRule("jarjar",
|
2015-04-04 01:54:17 +02:00
|
|
|
blueprint.RuleParams{
|
2019-06-11 22:30:13 +02:00
|
|
|
Command: "${config.JavaCmd} ${config.JavaVmFlags} -jar ${config.JarjarCmd} process $rulesFile $in $out",
|
2017-08-08 22:17:59 +02:00
|
|
|
CommandDeps: []string{"${config.JavaCmd}", "${config.JarjarCmd}", "$rulesFile"},
|
2015-04-04 01:54:17 +02:00
|
|
|
},
|
|
|
|
"rulesFile")
|
2018-08-28 03:31:46 +02:00
|
|
|
|
2019-04-02 11:29:55 +02:00
|
|
|
packageCheck = pctx.AndroidStaticRule("packageCheck",
|
|
|
|
blueprint.RuleParams{
|
|
|
|
Command: "rm -f $out && " +
|
|
|
|
"${config.PackageCheckCmd} $in $packages && " +
|
|
|
|
"touch $out",
|
|
|
|
CommandDeps: []string{"${config.PackageCheckCmd}"},
|
|
|
|
},
|
|
|
|
"packages")
|
|
|
|
|
2018-08-28 03:31:46 +02:00
|
|
|
jetifier = pctx.AndroidStaticRule("jetifier",
|
|
|
|
blueprint.RuleParams{
|
2019-06-11 22:30:13 +02:00
|
|
|
Command: "${config.JavaCmd} ${config.JavaVmFlags} -jar ${config.JetifierJar} -l error -o $out -i $in",
|
2018-08-28 03:31:46 +02:00
|
|
|
CommandDeps: []string{"${config.JavaCmd}", "${config.JetifierJar}"},
|
|
|
|
},
|
|
|
|
)
|
2018-11-12 19:13:39 +01:00
|
|
|
|
|
|
|
zipalign = pctx.AndroidStaticRule("zipalign",
|
|
|
|
blueprint.RuleParams{
|
2019-02-06 06:55:21 +01:00
|
|
|
Command: "if ! ${config.ZipAlign} -c -p 4 $in > /dev/null; then " +
|
|
|
|
"${config.ZipAlign} -f -p 4 $in $out; " +
|
2018-11-12 19:13:39 +01:00
|
|
|
"else " +
|
|
|
|
"cp -f $in $out; " +
|
|
|
|
"fi",
|
|
|
|
CommandDeps: []string{"${config.ZipAlign}"},
|
|
|
|
},
|
|
|
|
)
|
2015-03-31 02:20:39 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2019-04-03 01:14:11 +02:00
|
|
|
pctx.Import("android/soong/android")
|
2017-08-08 22:17:59 +02:00
|
|
|
pctx.Import("android/soong/java/config")
|
2015-03-31 02:20:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
type javaBuilderFlags struct {
|
2019-10-17 23:23:50 +02:00
|
|
|
javacFlags string
|
|
|
|
bootClasspath classpath
|
|
|
|
classpath classpath
|
|
|
|
java9Classpath classpath
|
|
|
|
processorPath classpath
|
|
|
|
processor string
|
|
|
|
systemModules *systemModules
|
|
|
|
aidlFlags string
|
|
|
|
aidlDeps android.Paths
|
|
|
|
javaVersion javaVersion
|
2017-09-20 21:59:05 +02:00
|
|
|
|
2018-01-23 06:27:21 +01:00
|
|
|
errorProneExtraJavacFlags string
|
2018-06-20 07:47:35 +02:00
|
|
|
errorProneProcessorPath classpath
|
2018-01-23 06:27:21 +01:00
|
|
|
|
2017-08-15 22:34:18 +02:00
|
|
|
kotlincFlags string
|
|
|
|
kotlincClasspath classpath
|
|
|
|
|
2019-03-28 22:45:07 +01:00
|
|
|
proto android.ProtoFlags
|
2015-03-31 02:20:39 +02:00
|
|
|
}
|
|
|
|
|
2017-11-02 21:28:15 +01:00
|
|
|
func TransformJavaToClasses(ctx android.ModuleContext, outputFile android.WritablePath, shardIdx int,
|
|
|
|
srcFiles, srcJars android.Paths, flags javaBuilderFlags, deps android.Paths) {
|
|
|
|
|
|
|
|
// Compile java sources into .class files
|
|
|
|
desc := "javac"
|
|
|
|
if shardIdx >= 0 {
|
|
|
|
desc += strconv.Itoa(shardIdx)
|
|
|
|
}
|
2015-03-31 02:20:39 +02:00
|
|
|
|
2018-06-20 07:47:35 +02:00
|
|
|
transformJavaToClasses(ctx, outputFile, shardIdx, srcFiles, srcJars, flags, deps, "javac", desc)
|
2015-03-31 02:20:39 +02:00
|
|
|
}
|
|
|
|
|
2017-10-17 02:09:48 +02:00
|
|
|
func RunErrorProne(ctx android.ModuleContext, outputFile android.WritablePath,
|
2017-10-25 02:46:00 +02:00
|
|
|
srcFiles, srcJars android.Paths, flags javaBuilderFlags) {
|
2017-08-14 23:16:06 +02:00
|
|
|
|
2018-06-20 07:47:35 +02:00
|
|
|
flags.processorPath = append(flags.errorProneProcessorPath, flags.processorPath...)
|
2017-09-05 22:16:45 +02:00
|
|
|
|
2018-01-23 06:27:21 +01:00
|
|
|
if len(flags.errorProneExtraJavacFlags) > 0 {
|
|
|
|
if len(flags.javacFlags) > 0 {
|
2018-06-20 07:47:35 +02:00
|
|
|
flags.javacFlags += " " + flags.errorProneExtraJavacFlags
|
2018-01-23 06:27:21 +01:00
|
|
|
} else {
|
|
|
|
flags.javacFlags = flags.errorProneExtraJavacFlags
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-02 21:28:15 +01:00
|
|
|
transformJavaToClasses(ctx, outputFile, -1, srcFiles, srcJars, flags, nil,
|
2018-06-20 07:47:35 +02:00
|
|
|
"errorprone", "errorprone")
|
2017-10-11 20:21:07 +02:00
|
|
|
}
|
|
|
|
|
2018-11-06 01:49:08 +01:00
|
|
|
// Emits the rule to generate Xref input file (.kzip file) for the given set of source files and source jars
|
|
|
|
// to compile with given set of builder flags, etc.
|
2019-09-06 01:44:18 +02:00
|
|
|
func emitXrefRule(ctx android.ModuleContext, xrefFile android.WritablePath, idx int,
|
2018-11-06 01:49:08 +01:00
|
|
|
srcFiles, srcJars android.Paths,
|
2019-09-06 01:44:18 +02:00
|
|
|
flags javaBuilderFlags, deps android.Paths) {
|
2018-11-06 01:49:08 +01:00
|
|
|
|
|
|
|
deps = append(deps, srcJars...)
|
2019-11-05 01:29:45 +01:00
|
|
|
classpath := flags.classpath
|
2018-11-06 01:49:08 +01:00
|
|
|
|
|
|
|
var bootClasspath string
|
2019-10-28 19:37:20 +01:00
|
|
|
if flags.javaVersion.usesJavaModules() {
|
2018-11-06 01:49:08 +01:00
|
|
|
var systemModuleDeps android.Paths
|
|
|
|
bootClasspath, systemModuleDeps = flags.systemModules.FormJavaSystemModulesPath(ctx.Device())
|
|
|
|
deps = append(deps, systemModuleDeps...)
|
2019-11-05 01:29:45 +01:00
|
|
|
classpath = append(flags.java9Classpath, classpath...)
|
2018-11-06 01:49:08 +01:00
|
|
|
} else {
|
|
|
|
deps = append(deps, flags.bootClasspath...)
|
|
|
|
if len(flags.bootClasspath) == 0 && ctx.Device() {
|
|
|
|
// explicitly specify -bootclasspath "" if the bootclasspath is empty to
|
|
|
|
// ensure java does not fall back to the default bootclasspath.
|
|
|
|
bootClasspath = `-bootclasspath ""`
|
|
|
|
} else {
|
|
|
|
bootClasspath = flags.bootClasspath.FormJavaClassPath("-bootclasspath")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-05 01:29:45 +01:00
|
|
|
deps = append(deps, classpath...)
|
2018-11-06 01:49:08 +01:00
|
|
|
deps = append(deps, flags.processorPath...)
|
|
|
|
|
|
|
|
processor := "-proc:none"
|
|
|
|
if flags.processor != "" {
|
|
|
|
processor = "-processor " + flags.processor
|
|
|
|
}
|
|
|
|
|
2019-09-06 01:44:18 +02:00
|
|
|
intermediatesDir := "xref"
|
|
|
|
if idx >= 0 {
|
|
|
|
intermediatesDir += strconv.Itoa(idx)
|
|
|
|
}
|
|
|
|
|
2018-11-06 01:49:08 +01:00
|
|
|
ctx.Build(pctx,
|
|
|
|
android.BuildParams{
|
|
|
|
Rule: kytheExtract,
|
|
|
|
Description: "Xref Java extractor",
|
|
|
|
Output: xrefFile,
|
|
|
|
Inputs: srcFiles,
|
|
|
|
Implicits: deps,
|
|
|
|
Args: map[string]string{
|
|
|
|
"annoDir": android.PathForModuleOut(ctx, intermediatesDir, "anno").String(),
|
|
|
|
"bootClasspath": bootClasspath,
|
2019-11-05 01:29:45 +01:00
|
|
|
"classpath": classpath.FormJavaClassPath("-classpath"),
|
2018-11-06 01:49:08 +01:00
|
|
|
"javacFlags": flags.javacFlags,
|
2019-10-28 19:37:20 +01:00
|
|
|
"javaVersion": flags.javaVersion.String(),
|
2018-11-06 01:49:08 +01:00
|
|
|
"outDir": android.PathForModuleOut(ctx, "javac", "classes.xref").String(),
|
|
|
|
"processorpath": flags.processorPath.FormJavaClassPath("-processorpath"),
|
|
|
|
"processor": processor,
|
|
|
|
"srcJarDir": android.PathForModuleOut(ctx, intermediatesDir, "srcjars.xref").String(),
|
|
|
|
"srcJars": strings.Join(srcJars.Strings(), " "),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-10-19 22:06:22 +02:00
|
|
|
func TransformJavaToHeaderClasses(ctx android.ModuleContext, outputFile android.WritablePath,
|
2017-10-25 02:46:00 +02:00
|
|
|
srcFiles, srcJars android.Paths, flags javaBuilderFlags) {
|
2017-10-19 22:06:22 +02:00
|
|
|
|
|
|
|
var deps android.Paths
|
|
|
|
deps = append(deps, srcJars...)
|
|
|
|
|
2019-10-17 23:23:50 +02:00
|
|
|
classpath := flags.classpath
|
|
|
|
|
2017-10-19 22:06:22 +02:00
|
|
|
var bootClasspath string
|
2019-10-28 22:25:10 +01:00
|
|
|
if flags.javaVersion.usesJavaModules() {
|
|
|
|
var systemModuleDeps android.Paths
|
|
|
|
bootClasspath, systemModuleDeps = flags.systemModules.FormTurbineSystemModulesPath(ctx.Device())
|
|
|
|
deps = append(deps, systemModuleDeps...)
|
2019-10-17 23:23:50 +02:00
|
|
|
classpath = append(flags.java9Classpath, classpath...)
|
2017-10-19 22:06:22 +02:00
|
|
|
} else {
|
2019-10-28 22:25:10 +01:00
|
|
|
deps = append(deps, flags.bootClasspath...)
|
|
|
|
if len(flags.bootClasspath) == 0 && ctx.Device() {
|
|
|
|
// explicitly specify -bootclasspath "" if the bootclasspath is empty to
|
|
|
|
// ensure turbine does not fall back to the default bootclasspath.
|
|
|
|
bootClasspath = `--bootclasspath ""`
|
|
|
|
} else {
|
2019-10-31 23:22:57 +01:00
|
|
|
bootClasspath = flags.bootClasspath.FormTurbineClassPath("--bootclasspath ")
|
2019-10-28 22:25:10 +01:00
|
|
|
}
|
2017-10-19 22:06:22 +02:00
|
|
|
}
|
2017-10-25 02:46:00 +02:00
|
|
|
|
2019-10-17 23:23:50 +02:00
|
|
|
deps = append(deps, classpath...)
|
2019-10-28 22:25:10 +01:00
|
|
|
deps = append(deps, flags.processorPath...)
|
|
|
|
|
2017-10-24 02:16:14 +02:00
|
|
|
ctx.Build(pctx, android.BuildParams{
|
2017-10-19 22:06:22 +02:00
|
|
|
Rule: turbine,
|
|
|
|
Description: "turbine",
|
|
|
|
Output: outputFile,
|
|
|
|
Inputs: srcFiles,
|
|
|
|
Implicits: deps,
|
|
|
|
Args: map[string]string{
|
|
|
|
"javacFlags": flags.javacFlags,
|
|
|
|
"bootClasspath": bootClasspath,
|
2017-10-25 02:46:00 +02:00
|
|
|
"srcJars": strings.Join(srcJars.Strings(), " "),
|
2019-10-31 23:22:57 +01:00
|
|
|
"classpath": classpath.FormTurbineClassPath("--classpath "),
|
2017-10-19 22:06:22 +02:00
|
|
|
"outDir": android.PathForModuleOut(ctx, "turbine", "classes").String(),
|
2019-10-28 19:37:20 +01:00
|
|
|
"javaVersion": flags.javaVersion.String(),
|
2017-10-19 22:06:22 +02:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-10-11 20:21:07 +02:00
|
|
|
// transformJavaToClasses takes source files and converts them to a jar containing .class files.
|
2017-10-17 03:07:29 +02:00
|
|
|
// srcFiles is a list of paths to sources, srcJars is a list of paths to jar files that contain
|
|
|
|
// sources. flags contains various command line flags to be passed to the compiler.
|
2017-10-11 20:21:07 +02:00
|
|
|
//
|
|
|
|
// This method may be used for different compilers, including javac and Error Prone. The rule
|
|
|
|
// argument specifies which command line to use and desc sets the description of the rule that will
|
|
|
|
// be printed at build time. The stem argument provides the file name of the output jar, and
|
|
|
|
// suffix will be appended to various intermediate files and directories to avoid collisions when
|
|
|
|
// this function is called twice in the same module directory.
|
2017-10-17 02:09:48 +02:00
|
|
|
func transformJavaToClasses(ctx android.ModuleContext, outputFile android.WritablePath,
|
2017-11-02 21:28:15 +01:00
|
|
|
shardIdx int, srcFiles, srcJars android.Paths,
|
2017-10-17 02:09:48 +02:00
|
|
|
flags javaBuilderFlags, deps android.Paths,
|
2018-06-20 07:47:35 +02:00
|
|
|
intermediatesDir, desc string) {
|
2017-08-14 23:16:06 +02:00
|
|
|
|
2017-10-17 03:07:29 +02:00
|
|
|
deps = append(deps, srcJars...)
|
2017-09-30 02:58:17 +02:00
|
|
|
|
2019-10-17 23:23:50 +02:00
|
|
|
classpath := flags.classpath
|
|
|
|
|
2017-09-30 02:58:17 +02:00
|
|
|
var bootClasspath string
|
2019-10-28 19:37:20 +01:00
|
|
|
if flags.javaVersion.usesJavaModules() {
|
2019-07-16 22:57:13 +02:00
|
|
|
var systemModuleDeps android.Paths
|
|
|
|
bootClasspath, systemModuleDeps = flags.systemModules.FormJavaSystemModulesPath(ctx.Device())
|
|
|
|
deps = append(deps, systemModuleDeps...)
|
2019-10-17 23:23:50 +02:00
|
|
|
classpath = append(flags.java9Classpath, classpath...)
|
2017-09-30 02:58:17 +02:00
|
|
|
} else {
|
|
|
|
deps = append(deps, flags.bootClasspath...)
|
2017-10-19 22:06:22 +02:00
|
|
|
if len(flags.bootClasspath) == 0 && ctx.Device() {
|
|
|
|
// explicitly specify -bootclasspath "" if the bootclasspath is empty to
|
|
|
|
// ensure java does not fall back to the default bootclasspath.
|
|
|
|
bootClasspath = `-bootclasspath ""`
|
|
|
|
} else {
|
|
|
|
bootClasspath = flags.bootClasspath.FormJavaClassPath("-bootclasspath")
|
|
|
|
}
|
2017-09-30 02:58:17 +02:00
|
|
|
}
|
|
|
|
|
2019-10-17 23:23:50 +02:00
|
|
|
deps = append(deps, classpath...)
|
2018-06-20 07:43:34 +02:00
|
|
|
deps = append(deps, flags.processorPath...)
|
2017-08-14 23:16:06 +02:00
|
|
|
|
2019-01-24 01:14:02 +01:00
|
|
|
processor := "-proc:none"
|
2019-01-22 06:37:16 +01:00
|
|
|
if flags.processor != "" {
|
|
|
|
processor = "-processor " + flags.processor
|
|
|
|
}
|
|
|
|
|
2017-11-02 21:28:15 +01:00
|
|
|
srcJarDir := "srcjars"
|
|
|
|
outDir := "classes"
|
|
|
|
annoDir := "anno"
|
|
|
|
if shardIdx >= 0 {
|
|
|
|
shardDir := "shard" + strconv.Itoa(shardIdx)
|
|
|
|
srcJarDir = filepath.Join(shardDir, srcJarDir)
|
|
|
|
outDir = filepath.Join(shardDir, outDir)
|
|
|
|
annoDir = filepath.Join(shardDir, annoDir)
|
|
|
|
}
|
2017-10-24 02:16:14 +02:00
|
|
|
ctx.Build(pctx, android.BuildParams{
|
2018-06-20 07:47:35 +02:00
|
|
|
Rule: javac,
|
2017-10-11 20:21:07 +02:00
|
|
|
Description: desc,
|
|
|
|
Output: outputFile,
|
2017-08-14 23:16:06 +02:00
|
|
|
Inputs: srcFiles,
|
|
|
|
Implicits: deps,
|
|
|
|
Args: map[string]string{
|
2017-10-17 03:07:29 +02:00
|
|
|
"javacFlags": flags.javacFlags,
|
2017-09-30 02:58:17 +02:00
|
|
|
"bootClasspath": bootClasspath,
|
2019-10-17 23:23:50 +02:00
|
|
|
"classpath": classpath.FormJavaClassPath("-classpath"),
|
2018-06-20 07:43:34 +02:00
|
|
|
"processorpath": flags.processorPath.FormJavaClassPath("-processorpath"),
|
2019-01-22 06:37:16 +01:00
|
|
|
"processor": processor,
|
2017-10-25 02:46:00 +02:00
|
|
|
"srcJars": strings.Join(srcJars.Strings(), " "),
|
2017-11-02 21:28:15 +01:00
|
|
|
"srcJarDir": android.PathForModuleOut(ctx, intermediatesDir, srcJarDir).String(),
|
|
|
|
"outDir": android.PathForModuleOut(ctx, intermediatesDir, outDir).String(),
|
|
|
|
"annoDir": android.PathForModuleOut(ctx, intermediatesDir, annoDir).String(),
|
2019-10-28 19:37:20 +01:00
|
|
|
"javaVersion": flags.javaVersion.String(),
|
2017-08-14 23:16:06 +02:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-10-17 02:09:48 +02:00
|
|
|
func TransformResourcesToJar(ctx android.ModuleContext, outputFile android.WritablePath,
|
|
|
|
jarArgs []string, deps android.Paths) {
|
2015-03-31 02:20:39 +02:00
|
|
|
|
2017-10-24 02:16:14 +02:00
|
|
|
ctx.Build(pctx, android.BuildParams{
|
2017-05-09 22:45:28 +02:00
|
|
|
Rule: jar,
|
|
|
|
Description: "jar",
|
|
|
|
Output: outputFile,
|
|
|
|
Implicits: deps,
|
2015-03-31 02:20:39 +02:00
|
|
|
Args: map[string]string{
|
2019-02-28 20:00:01 +01:00
|
|
|
"jarArgs": strings.Join(proptools.NinjaAndShellEscapeList(jarArgs), " "),
|
2015-03-31 02:20:39 +02:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-10-19 22:06:22 +02:00
|
|
|
func TransformJarsToJar(ctx android.ModuleContext, outputFile android.WritablePath, desc string,
|
2018-07-12 21:28:41 +02:00
|
|
|
jars android.Paths, manifest android.OptionalPath, stripDirEntries bool, filesToStrip []string,
|
|
|
|
dirsToStrip []string) {
|
2017-08-30 23:24:55 +02:00
|
|
|
|
2017-09-13 07:50:46 +02:00
|
|
|
var deps android.Paths
|
|
|
|
|
|
|
|
var jarArgs []string
|
|
|
|
if manifest.Valid() {
|
2017-10-19 22:06:22 +02:00
|
|
|
jarArgs = append(jarArgs, "-m ", manifest.String())
|
2017-09-13 07:50:46 +02:00
|
|
|
deps = append(deps, manifest.Path())
|
|
|
|
}
|
|
|
|
|
2018-07-12 21:28:41 +02:00
|
|
|
for _, dir := range dirsToStrip {
|
|
|
|
jarArgs = append(jarArgs, "-stripDir ", dir)
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, file := range filesToStrip {
|
|
|
|
jarArgs = append(jarArgs, "-stripFile ", file)
|
2017-10-19 22:06:22 +02:00
|
|
|
}
|
|
|
|
|
2017-12-21 22:52:58 +01:00
|
|
|
// Remove any module-info.class files that may have come from prebuilt jars, they cause problems
|
|
|
|
// for downstream tools like desugar.
|
|
|
|
jarArgs = append(jarArgs, "-stripFile module-info.class")
|
|
|
|
|
2018-07-12 21:28:41 +02:00
|
|
|
if stripDirEntries {
|
2017-09-13 07:50:46 +02:00
|
|
|
jarArgs = append(jarArgs, "-D")
|
|
|
|
}
|
|
|
|
|
2017-10-24 02:16:14 +02:00
|
|
|
ctx.Build(pctx, android.BuildParams{
|
2017-08-30 23:24:55 +02:00
|
|
|
Rule: combineJar,
|
2017-10-19 22:06:22 +02:00
|
|
|
Description: desc,
|
2017-08-30 23:24:55 +02:00
|
|
|
Output: outputFile,
|
|
|
|
Inputs: jars,
|
2017-09-13 07:50:46 +02:00
|
|
|
Implicits: deps,
|
|
|
|
Args: map[string]string{
|
|
|
|
"jarArgs": strings.Join(jarArgs, " "),
|
|
|
|
},
|
2017-08-30 23:24:55 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-10-17 02:09:48 +02:00
|
|
|
func TransformJarJar(ctx android.ModuleContext, outputFile android.WritablePath,
|
|
|
|
classesJar android.Path, rulesFile android.Path) {
|
2017-10-24 02:16:14 +02:00
|
|
|
ctx.Build(pctx, android.BuildParams{
|
2017-05-09 22:45:28 +02:00
|
|
|
Rule: jarjar,
|
|
|
|
Description: "jarjar",
|
|
|
|
Output: outputFile,
|
|
|
|
Input: classesJar,
|
|
|
|
Implicit: rulesFile,
|
2015-04-04 01:54:17 +02:00
|
|
|
Args: map[string]string{
|
2015-09-24 00:26:20 +02:00
|
|
|
"rulesFile": rulesFile.String(),
|
2015-04-04 01:54:17 +02:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
2017-09-15 22:00:47 +02:00
|
|
|
|
2019-04-02 11:29:55 +02:00
|
|
|
func CheckJarPackages(ctx android.ModuleContext, outputFile android.WritablePath,
|
|
|
|
classesJar android.Path, permittedPackages []string) {
|
|
|
|
ctx.Build(pctx, android.BuildParams{
|
|
|
|
Rule: packageCheck,
|
|
|
|
Description: "packageCheck",
|
|
|
|
Output: outputFile,
|
|
|
|
Input: classesJar,
|
|
|
|
Args: map[string]string{
|
|
|
|
"packages": strings.Join(permittedPackages, " "),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-08-28 03:31:46 +02:00
|
|
|
func TransformJetifier(ctx android.ModuleContext, outputFile android.WritablePath,
|
|
|
|
inputFile android.Path) {
|
|
|
|
ctx.Build(pctx, android.BuildParams{
|
|
|
|
Rule: jetifier,
|
|
|
|
Description: "jetifier",
|
|
|
|
Output: outputFile,
|
|
|
|
Input: inputFile,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-10-18 00:10:48 +02:00
|
|
|
func GenerateMainClassManifest(ctx android.ModuleContext, outputFile android.WritablePath, mainClass string) {
|
|
|
|
ctx.Build(pctx, android.BuildParams{
|
|
|
|
Rule: android.WriteFile,
|
|
|
|
Description: "manifest",
|
|
|
|
Output: outputFile,
|
|
|
|
Args: map[string]string{
|
|
|
|
"content": "Main-Class: " + mainClass + "\n",
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-11-12 19:13:39 +01:00
|
|
|
func TransformZipAlign(ctx android.ModuleContext, outputFile android.WritablePath, inputFile android.Path) {
|
|
|
|
ctx.Build(pctx, android.BuildParams{
|
|
|
|
Rule: zipalign,
|
|
|
|
Description: "align",
|
|
|
|
Input: inputFile,
|
|
|
|
Output: outputFile,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-07-11 20:01:22 +02:00
|
|
|
type classpath android.Paths
|
2017-09-15 22:00:47 +02:00
|
|
|
|
2019-10-31 23:22:57 +01:00
|
|
|
func (x *classpath) formJoinedClassPath(optName string, sep string) string {
|
2018-08-16 05:21:55 +02:00
|
|
|
if optName != "" && !strings.HasSuffix(optName, "=") && !strings.HasSuffix(optName, " ") {
|
|
|
|
optName += " "
|
|
|
|
}
|
2017-09-15 22:00:47 +02:00
|
|
|
if len(*x) > 0 {
|
2019-10-31 23:22:57 +01:00
|
|
|
return optName + strings.Join(x.Strings(), sep)
|
2017-09-15 22:00:47 +02:00
|
|
|
} else {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
}
|
2019-10-31 23:22:57 +01:00
|
|
|
func (x *classpath) FormJavaClassPath(optName string) string {
|
|
|
|
return x.formJoinedClassPath(optName, ":")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (x *classpath) FormTurbineClassPath(optName string) string {
|
|
|
|
return x.formJoinedClassPath(optName, " ")
|
|
|
|
}
|
2017-09-15 22:00:47 +02:00
|
|
|
|
2019-10-31 23:22:57 +01:00
|
|
|
// FormRepeatedClassPath returns a list of arguments with the given optName prefixed to each element of the classpath.
|
|
|
|
func (x *classpath) FormRepeatedClassPath(optName string) []string {
|
2017-09-15 22:00:47 +02:00
|
|
|
if x == nil || *x == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
flags := make([]string, len(*x))
|
|
|
|
for i, v := range *x {
|
2019-01-18 00:42:52 +01:00
|
|
|
flags[i] = optName + v.String()
|
2017-09-15 22:00:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return flags
|
|
|
|
}
|
|
|
|
|
|
|
|
// Convert a classpath to an android.Paths
|
|
|
|
func (x *classpath) Paths() android.Paths {
|
|
|
|
return append(android.Paths(nil), (*x)...)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (x *classpath) Strings() []string {
|
|
|
|
if x == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
ret := make([]string, len(*x))
|
|
|
|
for i, path := range *x {
|
|
|
|
ret[i] = path.String()
|
|
|
|
}
|
|
|
|
return ret
|
|
|
|
}
|
2019-07-16 22:57:13 +02:00
|
|
|
|
|
|
|
type systemModules struct {
|
|
|
|
dir android.Path
|
|
|
|
deps android.Paths
|
|
|
|
}
|
|
|
|
|
2019-10-28 22:25:10 +01:00
|
|
|
// Returns a --system argument in the form javac expects with -source 1.9 and the list of files to
|
|
|
|
// depend on. If forceEmpty is true, returns --system=none if the list is empty to ensure javac
|
|
|
|
// does not fall back to the default system modules.
|
2019-07-16 22:57:13 +02:00
|
|
|
func (x *systemModules) FormJavaSystemModulesPath(forceEmpty bool) (string, android.Paths) {
|
|
|
|
if x != nil {
|
|
|
|
return "--system=" + x.dir.String(), x.deps
|
|
|
|
} else if forceEmpty {
|
|
|
|
return "--system=none", nil
|
|
|
|
} else {
|
|
|
|
return "", nil
|
|
|
|
}
|
|
|
|
}
|
2019-10-28 22:25:10 +01:00
|
|
|
|
|
|
|
// Returns a --system argument in the form turbine expects with -source 1.9 and the list of files to
|
|
|
|
// depend on. If forceEmpty is true, returns --bootclasspath "" if the list is empty to ensure turbine
|
|
|
|
// does not fall back to the default bootclasspath.
|
|
|
|
func (x *systemModules) FormTurbineSystemModulesPath(forceEmpty bool) (string, android.Paths) {
|
|
|
|
if x != nil {
|
|
|
|
return "--system " + x.dir.String(), x.deps
|
|
|
|
} else if forceEmpty {
|
|
|
|
return `--bootclasspath ""`, nil
|
|
|
|
} else {
|
|
|
|
return "", nil
|
|
|
|
}
|
|
|
|
}
|