2015-03-31 08:20:39 +08: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-03 04:28:15 +08:00
|
|
|
"path/filepath"
|
|
|
|
"strconv"
|
2015-03-31 08:20:39 +08:00
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/google/blueprint"
|
2017-09-06 04:16:45 +08:00
|
|
|
|
|
|
|
"android/soong/android"
|
|
|
|
"android/soong/java/config"
|
2015-03-31 08:20:39 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2016-05-19 06:37:25 +08:00
|
|
|
pctx = android.NewPackageContext("android/soong/java")
|
2015-03-31 08:20:39 +08: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-09 04:48:39 +08: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.
|
2017-06-05 16:41:50 +08:00
|
|
|
javac = pctx.AndroidGomaStaticRule("javac",
|
2015-03-31 08:20:39 +08:00
|
|
|
blueprint.RuleParams{
|
2017-10-25 08:46:00 +08:00
|
|
|
Command: `rm -rf "$outDir" "$annoDir" "$srcJarDir" && mkdir -p "$outDir" "$annoDir" "$srcJarDir" && ` +
|
2018-03-16 07:24:10 +08:00
|
|
|
`${config.ZipSyncCmd} -d $srcJarDir -l $srcJarDir/list -f "*.java" $srcJars && ` +
|
2017-10-18 04:56:52 +08:00
|
|
|
`${config.SoongJavacWrapper} ${config.JavacWrapper}${config.JavacCmd} ${config.JavacHeapFlags} ${config.CommonJdkFlags} ` +
|
2018-06-20 13:43:34 +08:00
|
|
|
`$processorpath $javacFlags $bootClasspath $classpath ` +
|
2017-08-09 04:17:59 +08:00
|
|
|
`-source $javaVersion -target $javaVersion ` +
|
2017-10-25 08:46:00 +08:00
|
|
|
`-d $outDir -s $annoDir @$out.rsp @$srcJarDir/list && ` +
|
2017-08-31 05:24:55 +08:00
|
|
|
`${config.SoongZipCmd} -jar -o $out -C $outDir -D $outDir`,
|
2017-10-25 08:46:00 +08:00
|
|
|
CommandDeps: []string{
|
|
|
|
"${config.JavacCmd}",
|
|
|
|
"${config.SoongZipCmd}",
|
2018-03-16 07:24:10 +08:00
|
|
|
"${config.ZipSyncCmd}",
|
2017-10-25 08:46:00 +08:00
|
|
|
},
|
2017-10-18 04:56:52 +08:00
|
|
|
CommandOrderOnly: []string{"${config.SoongJavacWrapper}"},
|
|
|
|
Rspfile: "$out.rsp",
|
|
|
|
RspfileContent: "$in",
|
2015-03-31 08:20:39 +08:00
|
|
|
},
|
2018-06-20 13:43:34 +08:00
|
|
|
"javacFlags", "bootClasspath", "classpath", "processorpath", "srcJars", "srcJarDir",
|
2017-10-25 08:46:00 +08:00
|
|
|
"outDir", "annoDir", "javaVersion")
|
2015-03-31 08:20:39 +08:00
|
|
|
|
2017-08-16 04:34:18 +08:00
|
|
|
kotlinc = pctx.AndroidGomaStaticRule("kotlinc",
|
|
|
|
blueprint.RuleParams{
|
2018-02-13 22:32:54 +08:00
|
|
|
Command: `rm -rf "$outDir" "$srcJarDir" && mkdir -p "$outDir" "$srcJarDir" && ` +
|
2018-03-16 07:24:10 +08:00
|
|
|
`${config.ZipSyncCmd} -d $srcJarDir -l $srcJarDir/list -f "*.java" $srcJars && ` +
|
2018-02-13 22:32:54 +08:00
|
|
|
`${config.GenKotlinBuildFileCmd} $classpath $outDir $out.rsp $srcJarDir/list > $outDir/kotlinc-build.xml &&` +
|
|
|
|
`${config.KotlincCmd} $kotlincFlags ` +
|
|
|
|
`-jvm-target $kotlinJvmTarget -Xbuild-file=$outDir/kotlinc-build.xml && ` +
|
2018-03-08 21:21:55 +08:00
|
|
|
`rm $outDir/kotlinc-build.xml && ` +
|
2017-08-16 04:34:18 +08:00
|
|
|
`${config.SoongZipCmd} -jar -o $out -C $outDir -D $outDir`,
|
|
|
|
CommandDeps: []string{
|
|
|
|
"${config.KotlincCmd}",
|
|
|
|
"${config.KotlinCompilerJar}",
|
2018-02-13 22:32:54 +08:00
|
|
|
"${config.GenKotlinBuildFileCmd}",
|
2017-08-16 04:34:18 +08:00
|
|
|
"${config.SoongZipCmd}",
|
2018-03-16 07:24:10 +08:00
|
|
|
"${config.ZipSyncCmd}",
|
2017-08-16 04:34:18 +08:00
|
|
|
},
|
2018-02-13 22:32:54 +08:00
|
|
|
Rspfile: "$out.rsp",
|
|
|
|
RspfileContent: `$in`,
|
2017-08-16 04:34:18 +08:00
|
|
|
},
|
2018-02-13 22:32:54 +08:00
|
|
|
"kotlincFlags", "classpath", "srcJars", "srcJarDir", "outDir", "kotlinJvmTarget")
|
2017-08-16 04:34:18 +08:00
|
|
|
|
2017-08-15 05:16:06 +08:00
|
|
|
errorprone = pctx.AndroidStaticRule("errorprone",
|
|
|
|
blueprint.RuleParams{
|
2017-10-25 08:46:00 +08:00
|
|
|
Command: `rm -rf "$outDir" "$annoDir" "$srcJarDir" && mkdir -p "$outDir" "$annoDir" "$srcJarDir" && ` +
|
2018-03-16 07:24:10 +08:00
|
|
|
`${config.ZipSyncCmd} -d $srcJarDir -l $srcJarDir/list -f "*.java" $srcJars && ` +
|
2017-10-18 04:56:52 +08:00
|
|
|
`${config.SoongJavacWrapper} ${config.ErrorProneCmd} ` +
|
2018-06-20 13:43:34 +08:00
|
|
|
`$processorpath $javacFlags $bootClasspath $classpath ` +
|
2017-08-15 05:16:06 +08:00
|
|
|
`-source $javaVersion -target $javaVersion ` +
|
2017-10-25 08:46:00 +08:00
|
|
|
`-d $outDir -s $annoDir @$out.rsp @$srcJarDir/list && ` +
|
2017-08-31 05:24:55 +08:00
|
|
|
`${config.SoongZipCmd} -jar -o $out -C $outDir -D $outDir`,
|
2017-08-15 05:16:06 +08:00
|
|
|
CommandDeps: []string{
|
|
|
|
"${config.JavaCmd}",
|
|
|
|
"${config.ErrorProneJavacJar}",
|
|
|
|
"${config.ErrorProneJar}",
|
2017-08-31 05:24:55 +08:00
|
|
|
"${config.SoongZipCmd}",
|
2018-03-16 07:24:10 +08:00
|
|
|
"${config.ZipSyncCmd}",
|
2017-08-15 05:16:06 +08:00
|
|
|
},
|
2017-10-18 04:56:52 +08:00
|
|
|
CommandOrderOnly: []string{"${config.SoongJavacWrapper}"},
|
|
|
|
Rspfile: "$out.rsp",
|
|
|
|
RspfileContent: "$in",
|
2017-08-15 05:16:06 +08:00
|
|
|
},
|
2018-06-20 13:43:34 +08:00
|
|
|
"javacFlags", "bootClasspath", "classpath", "processorpath", "srcJars", "srcJarDir",
|
2017-10-25 08:46:00 +08:00
|
|
|
"outDir", "annoDir", "javaVersion")
|
2017-08-15 05:16:06 +08:00
|
|
|
|
2017-10-20 04:06:22 +08:00
|
|
|
turbine = pctx.AndroidStaticRule("turbine",
|
|
|
|
blueprint.RuleParams{
|
2018-03-08 07:14:50 +08:00
|
|
|
Command: `rm -rf "$outDir" && mkdir -p "$outDir" && ` +
|
2017-10-20 04:06:22 +08:00
|
|
|
`${config.JavaCmd} -jar ${config.TurbineJar} --output $out.tmp ` +
|
2018-03-08 07:14:50 +08:00
|
|
|
`--temp_dir "$outDir" --sources @$out.rsp --source_jars $srcJars ` +
|
2017-10-20 04:06:22 +08:00
|
|
|
`--javacopts ${config.CommonJdkFlags} ` +
|
2018-03-08 02:51:05 +08:00
|
|
|
`$javacFlags -source $javaVersion -target $javaVersion -- $bootClasspath $classpath && ` +
|
2017-10-20 04:06:22 +08:00
|
|
|
`${config.Ziptime} $out.tmp && ` +
|
|
|
|
`(if cmp -s $out.tmp $out ; then rm $out.tmp ; else mv $out.tmp $out ; fi )`,
|
2017-10-25 08:46:00 +08:00
|
|
|
CommandDeps: []string{
|
|
|
|
"${config.TurbineJar}",
|
|
|
|
"${config.JavaCmd}",
|
|
|
|
"${config.Ziptime}",
|
|
|
|
},
|
2017-10-20 04:06:22 +08:00
|
|
|
Rspfile: "$out.rsp",
|
|
|
|
RspfileContent: "$in",
|
|
|
|
Restat: true,
|
|
|
|
},
|
2018-03-08 07:14:50 +08:00
|
|
|
"javacFlags", "bootClasspath", "classpath", "srcJars", "outDir", "javaVersion")
|
2017-10-20 04:06:22 +08:00
|
|
|
|
2016-08-30 07:14:13 +08:00
|
|
|
jar = pctx.AndroidStaticRule("jar",
|
2015-03-31 08:20:39 +08: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 10:30:36 +08:00
|
|
|
Command: `${config.SoongZipCmd} -jar -o $out @$out.rsp`,
|
|
|
|
CommandDeps: []string{"${config.SoongZipCmd}"},
|
|
|
|
Rspfile: "$out.rsp",
|
|
|
|
RspfileContent: "$jarArgs",
|
2015-03-31 08:20:39 +08:00
|
|
|
},
|
2017-08-31 05:24:55 +08:00
|
|
|
"jarArgs")
|
|
|
|
|
|
|
|
combineJar = pctx.AndroidStaticRule("combineJar",
|
|
|
|
blueprint.RuleParams{
|
2018-02-08 07:41:31 +08:00
|
|
|
Command: `${config.MergeZipsCmd} --ignore-duplicates -j $jarArgs $out $in`,
|
2017-08-31 05:24:55 +08:00
|
|
|
CommandDeps: []string{"${config.MergeZipsCmd}"},
|
|
|
|
},
|
2017-09-13 13:50:46 +08:00
|
|
|
"jarArgs")
|
2015-03-31 08:20:39 +08:00
|
|
|
|
2016-08-30 07:14:13 +08:00
|
|
|
jarjar = pctx.AndroidStaticRule("jarjar",
|
2015-04-04 07:54:17 +08:00
|
|
|
blueprint.RuleParams{
|
2017-08-09 04:17:59 +08:00
|
|
|
Command: "${config.JavaCmd} -jar ${config.JarjarCmd} process $rulesFile $in $out",
|
|
|
|
CommandDeps: []string{"${config.JavaCmd}", "${config.JarjarCmd}", "$rulesFile"},
|
2015-04-04 07:54:17 +08:00
|
|
|
},
|
|
|
|
"rulesFile")
|
2015-03-31 08:20:39 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2017-08-09 04:17:59 +08:00
|
|
|
pctx.Import("android/soong/java/config")
|
2015-03-31 08:20:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
type javaBuilderFlags struct {
|
|
|
|
javacFlags string
|
2017-09-16 04:00:47 +08:00
|
|
|
bootClasspath classpath
|
|
|
|
classpath classpath
|
2018-06-20 13:43:34 +08:00
|
|
|
processorPath classpath
|
2017-09-30 08:58:17 +08:00
|
|
|
systemModules classpath
|
2015-04-09 04:03:43 +08:00
|
|
|
aidlFlags string
|
2017-08-09 04:17:59 +08:00
|
|
|
javaVersion string
|
2017-09-21 03:59:05 +08:00
|
|
|
|
2018-01-23 13:27:21 +08:00
|
|
|
errorProneExtraJavacFlags string
|
|
|
|
|
2017-08-16 04:34:18 +08:00
|
|
|
kotlincFlags string
|
|
|
|
kotlincClasspath classpath
|
|
|
|
|
2017-11-19 10:23:14 +08:00
|
|
|
protoFlags []string
|
|
|
|
protoOutTypeFlag string // The flag itself: --java_out
|
|
|
|
protoOutParams string // Parameters to that flag: --java_out=$protoOutParams:$outDir
|
2018-02-15 05:58:34 +08:00
|
|
|
protoRoot bool
|
2015-03-31 08:20:39 +08:00
|
|
|
}
|
|
|
|
|
2017-08-16 04:34:18 +08:00
|
|
|
func TransformKotlinToClasses(ctx android.ModuleContext, outputFile android.WritablePath,
|
2017-10-25 08:46:00 +08:00
|
|
|
srcFiles, srcJars android.Paths,
|
2017-08-16 04:34:18 +08:00
|
|
|
flags javaBuilderFlags) {
|
|
|
|
|
|
|
|
inputs := append(android.Paths(nil), srcFiles...)
|
|
|
|
|
2017-12-16 12:20:39 +08:00
|
|
|
var deps android.Paths
|
|
|
|
deps = append(deps, flags.kotlincClasspath...)
|
2018-02-13 22:32:54 +08:00
|
|
|
deps = append(deps, srcJars...)
|
2017-12-16 12:20:39 +08:00
|
|
|
|
2017-10-24 08:16:14 +08:00
|
|
|
ctx.Build(pctx, android.BuildParams{
|
2017-08-16 04:34:18 +08:00
|
|
|
Rule: kotlinc,
|
|
|
|
Description: "kotlinc",
|
|
|
|
Output: outputFile,
|
|
|
|
Inputs: inputs,
|
2017-12-16 12:20:39 +08:00
|
|
|
Implicits: deps,
|
2017-08-16 04:34:18 +08:00
|
|
|
Args: map[string]string{
|
2017-10-26 11:32:18 +08:00
|
|
|
"classpath": flags.kotlincClasspath.FormJavaClassPath("-classpath"),
|
2017-08-16 04:34:18 +08:00
|
|
|
"kotlincFlags": flags.kotlincFlags,
|
2018-02-13 22:32:54 +08:00
|
|
|
"srcJars": strings.Join(srcJars.Strings(), " "),
|
|
|
|
"outDir": android.PathForModuleOut(ctx, "kotlinc", "classes").String(),
|
|
|
|
"srcJarDir": android.PathForModuleOut(ctx, "kotlinc", "srcJars").String(),
|
2017-11-18 11:10:51 +08:00
|
|
|
// http://b/69160377 kotlinc only supports -jvm-target 1.6 and 1.8
|
|
|
|
"kotlinJvmTarget": "1.8",
|
2017-08-16 04:34:18 +08:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-11-03 04:28:15 +08: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 08:20:39 +08:00
|
|
|
|
2017-11-03 04:28:15 +08:00
|
|
|
transformJavaToClasses(ctx, outputFile, shardIdx, srcFiles, srcJars, flags, deps, "javac", desc, javac)
|
2015-03-31 08:20:39 +08:00
|
|
|
}
|
|
|
|
|
2017-10-17 08:09:48 +08:00
|
|
|
func RunErrorProne(ctx android.ModuleContext, outputFile android.WritablePath,
|
2017-10-25 08:46:00 +08:00
|
|
|
srcFiles, srcJars android.Paths, flags javaBuilderFlags) {
|
2017-08-15 05:16:06 +08:00
|
|
|
|
2017-09-06 04:16:45 +08:00
|
|
|
if config.ErrorProneJar == "" {
|
|
|
|
ctx.ModuleErrorf("cannot build with Error Prone, missing external/error_prone?")
|
|
|
|
}
|
|
|
|
|
2018-01-23 13:27:21 +08:00
|
|
|
if len(flags.errorProneExtraJavacFlags) > 0 {
|
|
|
|
if len(flags.javacFlags) > 0 {
|
|
|
|
flags.javacFlags = flags.errorProneExtraJavacFlags + " " + flags.javacFlags
|
|
|
|
} else {
|
|
|
|
flags.javacFlags = flags.errorProneExtraJavacFlags
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-03 04:28:15 +08:00
|
|
|
transformJavaToClasses(ctx, outputFile, -1, srcFiles, srcJars, flags, nil,
|
2017-10-19 05:44:18 +08:00
|
|
|
"errorprone", "errorprone", errorprone)
|
2017-10-12 02:21:07 +08:00
|
|
|
}
|
|
|
|
|
2017-10-20 04:06:22 +08:00
|
|
|
func TransformJavaToHeaderClasses(ctx android.ModuleContext, outputFile android.WritablePath,
|
2017-10-25 08:46:00 +08:00
|
|
|
srcFiles, srcJars android.Paths, flags javaBuilderFlags) {
|
2017-10-20 04:06:22 +08:00
|
|
|
|
|
|
|
var deps android.Paths
|
|
|
|
deps = append(deps, srcJars...)
|
|
|
|
deps = append(deps, flags.bootClasspath...)
|
|
|
|
deps = append(deps, flags.classpath...)
|
|
|
|
|
|
|
|
var bootClasspath string
|
|
|
|
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 {
|
2018-06-07 05:46:32 +08:00
|
|
|
bootClasspath = strings.Join(flags.bootClasspath.FormTurbineClasspath("--bootclasspath"), " ")
|
2017-10-20 04:06:22 +08:00
|
|
|
}
|
2017-10-25 08:46:00 +08:00
|
|
|
|
2017-10-24 08:16:14 +08:00
|
|
|
ctx.Build(pctx, android.BuildParams{
|
2017-10-20 04:06:22 +08:00
|
|
|
Rule: turbine,
|
|
|
|
Description: "turbine",
|
|
|
|
Output: outputFile,
|
|
|
|
Inputs: srcFiles,
|
|
|
|
Implicits: deps,
|
|
|
|
Args: map[string]string{
|
|
|
|
"javacFlags": flags.javacFlags,
|
|
|
|
"bootClasspath": bootClasspath,
|
2017-10-25 08:46:00 +08:00
|
|
|
"srcJars": strings.Join(srcJars.Strings(), " "),
|
2018-06-07 05:46:32 +08:00
|
|
|
"classpath": strings.Join(flags.classpath.FormTurbineClasspath("--classpath"), " "),
|
2017-10-20 04:06:22 +08:00
|
|
|
"outDir": android.PathForModuleOut(ctx, "turbine", "classes").String(),
|
|
|
|
"javaVersion": flags.javaVersion,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-10-12 02:21:07 +08:00
|
|
|
// transformJavaToClasses takes source files and converts them to a jar containing .class files.
|
2017-10-17 09:07:29 +08: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-12 02:21:07 +08: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 08:09:48 +08:00
|
|
|
func transformJavaToClasses(ctx android.ModuleContext, outputFile android.WritablePath,
|
2017-11-03 04:28:15 +08:00
|
|
|
shardIdx int, srcFiles, srcJars android.Paths,
|
2017-10-17 08:09:48 +08:00
|
|
|
flags javaBuilderFlags, deps android.Paths,
|
2017-10-19 05:44:18 +08:00
|
|
|
intermediatesDir, desc string, rule blueprint.Rule) {
|
2017-08-15 05:16:06 +08:00
|
|
|
|
2017-10-17 09:07:29 +08:00
|
|
|
deps = append(deps, srcJars...)
|
2017-09-30 08:58:17 +08:00
|
|
|
|
|
|
|
var bootClasspath string
|
|
|
|
if flags.javaVersion == "1.9" {
|
|
|
|
deps = append(deps, flags.systemModules...)
|
2017-10-20 04:06:22 +08:00
|
|
|
bootClasspath = flags.systemModules.FormJavaSystemModulesPath("--system=", ctx.Device())
|
2017-09-30 08:58:17 +08:00
|
|
|
} else {
|
|
|
|
deps = append(deps, flags.bootClasspath...)
|
2017-10-20 04:06:22 +08: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 08:58:17 +08:00
|
|
|
}
|
|
|
|
|
2017-09-16 04:00:47 +08:00
|
|
|
deps = append(deps, flags.classpath...)
|
2018-06-20 13:43:34 +08:00
|
|
|
deps = append(deps, flags.processorPath...)
|
2017-08-15 05:16:06 +08:00
|
|
|
|
2017-11-03 04:28:15 +08: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 08:16:14 +08:00
|
|
|
ctx.Build(pctx, android.BuildParams{
|
2017-10-12 02:21:07 +08:00
|
|
|
Rule: rule,
|
|
|
|
Description: desc,
|
|
|
|
Output: outputFile,
|
2017-08-15 05:16:06 +08:00
|
|
|
Inputs: srcFiles,
|
|
|
|
Implicits: deps,
|
|
|
|
Args: map[string]string{
|
2017-10-17 09:07:29 +08:00
|
|
|
"javacFlags": flags.javacFlags,
|
2017-09-30 08:58:17 +08:00
|
|
|
"bootClasspath": bootClasspath,
|
2017-10-25 08:46:00 +08:00
|
|
|
"classpath": flags.classpath.FormJavaClassPath("-classpath"),
|
2018-06-20 13:43:34 +08:00
|
|
|
"processorpath": flags.processorPath.FormJavaClassPath("-processorpath"),
|
2017-10-25 08:46:00 +08:00
|
|
|
"srcJars": strings.Join(srcJars.Strings(), " "),
|
2017-11-03 04:28:15 +08:00
|
|
|
"srcJarDir": android.PathForModuleOut(ctx, intermediatesDir, srcJarDir).String(),
|
|
|
|
"outDir": android.PathForModuleOut(ctx, intermediatesDir, outDir).String(),
|
|
|
|
"annoDir": android.PathForModuleOut(ctx, intermediatesDir, annoDir).String(),
|
2017-10-25 08:46:00 +08:00
|
|
|
"javaVersion": flags.javaVersion,
|
2017-08-15 05:16:06 +08:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-10-17 08:09:48 +08:00
|
|
|
func TransformResourcesToJar(ctx android.ModuleContext, outputFile android.WritablePath,
|
|
|
|
jarArgs []string, deps android.Paths) {
|
2015-03-31 08:20:39 +08:00
|
|
|
|
2017-10-24 08:16:14 +08:00
|
|
|
ctx.Build(pctx, android.BuildParams{
|
2017-05-10 04:45:28 +08:00
|
|
|
Rule: jar,
|
|
|
|
Description: "jar",
|
|
|
|
Output: outputFile,
|
|
|
|
Implicits: deps,
|
2015-03-31 08:20:39 +08:00
|
|
|
Args: map[string]string{
|
2017-08-31 05:24:55 +08:00
|
|
|
"jarArgs": strings.Join(jarArgs, " "),
|
2015-03-31 08:20:39 +08:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-10-20 04:06:22 +08:00
|
|
|
func TransformJarsToJar(ctx android.ModuleContext, outputFile android.WritablePath, desc string,
|
|
|
|
jars android.Paths, manifest android.OptionalPath, stripDirs bool, dirsToStrip []string) {
|
2017-08-31 05:24:55 +08:00
|
|
|
|
2017-09-13 13:50:46 +08:00
|
|
|
var deps android.Paths
|
|
|
|
|
|
|
|
var jarArgs []string
|
|
|
|
if manifest.Valid() {
|
2017-10-20 04:06:22 +08:00
|
|
|
jarArgs = append(jarArgs, "-m ", manifest.String())
|
2017-09-13 13:50:46 +08:00
|
|
|
deps = append(deps, manifest.Path())
|
|
|
|
}
|
|
|
|
|
2017-10-20 04:06:22 +08:00
|
|
|
if dirsToStrip != nil {
|
|
|
|
for _, dir := range dirsToStrip {
|
|
|
|
jarArgs = append(jarArgs, "-stripDir ", dir)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-22 05:52:58 +08: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-03-08 21:21:55 +08:00
|
|
|
// Remove any kotlin-reflect related files
|
|
|
|
// TODO(pszczepaniak): Support kotlin-reflect
|
|
|
|
jarArgs = append(jarArgs, "-stripFile \"*.kotlin_module\"")
|
|
|
|
jarArgs = append(jarArgs, "-stripFile \"*.kotlin_builtin\"")
|
|
|
|
|
2017-09-13 13:50:46 +08:00
|
|
|
if stripDirs {
|
|
|
|
jarArgs = append(jarArgs, "-D")
|
|
|
|
}
|
|
|
|
|
2017-10-24 08:16:14 +08:00
|
|
|
ctx.Build(pctx, android.BuildParams{
|
2017-08-31 05:24:55 +08:00
|
|
|
Rule: combineJar,
|
2017-10-20 04:06:22 +08:00
|
|
|
Description: desc,
|
2017-08-31 05:24:55 +08:00
|
|
|
Output: outputFile,
|
|
|
|
Inputs: jars,
|
2017-09-13 13:50:46 +08:00
|
|
|
Implicits: deps,
|
|
|
|
Args: map[string]string{
|
|
|
|
"jarArgs": strings.Join(jarArgs, " "),
|
|
|
|
},
|
2017-08-31 05:24:55 +08:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-10-17 08:09:48 +08:00
|
|
|
func TransformJarJar(ctx android.ModuleContext, outputFile android.WritablePath,
|
|
|
|
classesJar android.Path, rulesFile android.Path) {
|
2017-10-24 08:16:14 +08:00
|
|
|
ctx.Build(pctx, android.BuildParams{
|
2017-05-10 04:45:28 +08:00
|
|
|
Rule: jarjar,
|
|
|
|
Description: "jarjar",
|
|
|
|
Output: outputFile,
|
|
|
|
Input: classesJar,
|
|
|
|
Implicit: rulesFile,
|
2015-04-04 07:54:17 +08:00
|
|
|
Args: map[string]string{
|
2015-09-24 06:26:20 +08:00
|
|
|
"rulesFile": rulesFile.String(),
|
2015-04-04 07:54:17 +08:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
2017-09-16 04:00:47 +08:00
|
|
|
|
|
|
|
type classpath []android.Path
|
|
|
|
|
2017-10-20 04:06:22 +08:00
|
|
|
func (x *classpath) FormJavaClassPath(optName string) string {
|
2017-09-16 04:00:47 +08:00
|
|
|
if len(*x) > 0 {
|
2017-10-20 04:06:22 +08:00
|
|
|
return optName + " " + strings.Join(x.Strings(), ":")
|
2017-09-16 04:00:47 +08:00
|
|
|
} else {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-30 08:58:17 +08:00
|
|
|
// Returns a --system argument in the form javac expects with -source 1.9. If forceEmpty is true,
|
|
|
|
// returns --system=none if the list is empty to ensure javac does not fall back to the default
|
|
|
|
// system modules.
|
2017-10-20 04:06:22 +08:00
|
|
|
func (x *classpath) FormJavaSystemModulesPath(optName string, forceEmpty bool) string {
|
2017-09-30 08:58:17 +08:00
|
|
|
if len(*x) > 1 {
|
|
|
|
panic("more than one system module")
|
|
|
|
} else if len(*x) == 1 {
|
2017-10-20 04:06:22 +08:00
|
|
|
return optName + strings.TrimSuffix((*x)[0].String(), "lib/modules")
|
2017-09-30 08:58:17 +08:00
|
|
|
} else if forceEmpty {
|
2017-10-20 04:06:22 +08:00
|
|
|
return optName + "none"
|
2017-09-30 08:58:17 +08:00
|
|
|
} else {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-07 05:46:32 +08:00
|
|
|
func (x *classpath) FormTurbineClasspath(optName string) []string {
|
2017-09-16 04:00:47 +08:00
|
|
|
if x == nil || *x == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
flags := make([]string, len(*x))
|
|
|
|
for i, v := range *x {
|
2017-10-20 04:06:22 +08:00
|
|
|
flags[i] = optName + " " + v.String()
|
2017-09-16 04:00:47 +08: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
|
|
|
|
}
|