Move all jar intermediates to subdirs
Make all the jar intermediates called modulename.jar, and put each in a subdir for the tool that generated it. This will simplify using the jars as inputs to genrules and resources. Test: java_test.go Change-Id: If00e16bd7df5a4ba24ebc4b68c9ccf2cfda49544
This commit is contained in:
parent
702e0f8ab0
commit
1ee2317555
|
@ -160,7 +160,7 @@ func TransformKotlinToClasses(ctx android.ModuleContext, outputFile android.Writ
|
|||
srcFiles android.Paths, srcJars classpath,
|
||||
flags javaBuilderFlags) {
|
||||
|
||||
classDir := android.PathForModuleOut(ctx, "classes-kt")
|
||||
classDir := android.PathForModuleOut(ctx, "kotlinc", "classes")
|
||||
|
||||
inputs := append(android.Paths(nil), srcFiles...)
|
||||
inputs = append(inputs, srcJars...)
|
||||
|
@ -184,7 +184,7 @@ func TransformJavaToClasses(ctx android.ModuleContext, outputFile android.Writab
|
|||
flags javaBuilderFlags, deps android.Paths) {
|
||||
|
||||
transformJavaToClasses(ctx, outputFile, srcFiles, srcJars, flags, deps,
|
||||
"", "javac", javac)
|
||||
"javac", "javac", javac)
|
||||
}
|
||||
|
||||
func RunErrorProne(ctx android.ModuleContext, outputFile android.WritablePath,
|
||||
|
@ -196,7 +196,7 @@ func RunErrorProne(ctx android.ModuleContext, outputFile android.WritablePath,
|
|||
}
|
||||
|
||||
transformJavaToClasses(ctx, outputFile, srcFiles, srcJars, flags, nil,
|
||||
"-errorprone", "errorprone", errorprone)
|
||||
"errorprone", "errorprone", errorprone)
|
||||
}
|
||||
|
||||
// transformJavaToClasses takes source files and converts them to a jar containing .class files.
|
||||
|
@ -211,7 +211,7 @@ func RunErrorProne(ctx android.ModuleContext, outputFile android.WritablePath,
|
|||
func transformJavaToClasses(ctx android.ModuleContext, outputFile android.WritablePath,
|
||||
srcFiles android.Paths, srcJars classpath,
|
||||
flags javaBuilderFlags, deps android.Paths,
|
||||
intermediatesSuffix, desc string, rule blueprint.Rule) {
|
||||
intermediatesDir, desc string, rule blueprint.Rule) {
|
||||
|
||||
deps = append(deps, srcJars...)
|
||||
|
||||
|
@ -237,8 +237,8 @@ func transformJavaToClasses(ctx android.ModuleContext, outputFile android.Writab
|
|||
"bootClasspath": bootClasspath,
|
||||
"sourcepath": srcJars.JavaSourcepath(),
|
||||
"classpath": flags.classpath.JavaClasspath(),
|
||||
"outDir": android.PathForModuleOut(ctx, "classes"+intermediatesSuffix).String(),
|
||||
"annoDir": android.PathForModuleOut(ctx, "anno"+intermediatesSuffix).String(),
|
||||
"outDir": android.PathForModuleOut(ctx, intermediatesDir, "classes").String(),
|
||||
"annoDir": android.PathForModuleOut(ctx, intermediatesDir, "anno").String(),
|
||||
"javaVersion": flags.javaVersion,
|
||||
},
|
||||
})
|
||||
|
@ -288,7 +288,7 @@ func TransformJarsToJar(ctx android.ModuleContext, outputFile android.WritablePa
|
|||
func TransformDesugar(ctx android.ModuleContext, outputFile android.WritablePath,
|
||||
classesJar android.Path, flags javaBuilderFlags) {
|
||||
|
||||
dumpDir := android.PathForModuleOut(ctx, "desugar_dumped_classes")
|
||||
dumpDir := android.PathForModuleOut(ctx, "desugar", "classes")
|
||||
|
||||
javaFlags := ""
|
||||
if ctx.AConfig().UseOpenJDK9() {
|
||||
|
|
24
java/java.go
24
java/java.go
|
@ -502,6 +502,8 @@ func (j *Module) compile(ctx android.ModuleContext) {
|
|||
|
||||
var jars android.Paths
|
||||
|
||||
jarName := ctx.ModuleName() + ".jar"
|
||||
|
||||
if srcFiles.HasExt(".kt") {
|
||||
// If there are kotlin files, compile them first but pass all the kotlin and java files
|
||||
// kotlinc will use the java files to resolve types referenced by the kotlin files, but
|
||||
|
@ -515,7 +517,7 @@ func (j *Module) compile(ctx android.ModuleContext) {
|
|||
flags.kotlincClasspath = append(flags.kotlincClasspath, deps.kotlinStdlib...)
|
||||
flags.kotlincClasspath = append(flags.kotlincClasspath, deps.classpath...)
|
||||
|
||||
kotlinJar := android.PathForModuleOut(ctx, "classes-kt.jar")
|
||||
kotlinJar := android.PathForModuleOut(ctx, "kotlin", jarName)
|
||||
TransformKotlinToClasses(ctx, kotlinJar, srcFiles, srcJars, flags)
|
||||
if ctx.Failed() {
|
||||
return
|
||||
|
@ -536,13 +538,13 @@ func (j *Module) compile(ctx android.ModuleContext) {
|
|||
// a rebuild when error-prone is turned off).
|
||||
// TODO(ccross): Once we always compile with javac9 we may be able to conditionally
|
||||
// enable error-prone without affecting the output class files.
|
||||
errorprone := android.PathForModuleOut(ctx, "classes-errorprone.list")
|
||||
errorprone := android.PathForModuleOut(ctx, "errorprone", jarName)
|
||||
RunErrorProne(ctx, errorprone, javaSrcFiles, srcJars, flags)
|
||||
extraJarDeps = append(extraJarDeps, errorprone)
|
||||
}
|
||||
|
||||
// Compile java sources into .class files
|
||||
classes := android.PathForModuleOut(ctx, "classes-compiled.jar")
|
||||
classes := android.PathForModuleOut(ctx, "javac", jarName)
|
||||
TransformJavaToClasses(ctx, classes, javaSrcFiles, srcJars, flags, extraJarDeps)
|
||||
if ctx.Failed() {
|
||||
return
|
||||
|
@ -570,7 +572,7 @@ func (j *Module) compile(ctx android.ModuleContext) {
|
|||
}
|
||||
|
||||
if len(resArgs) > 0 {
|
||||
resourceJar := android.PathForModuleOut(ctx, "res.jar")
|
||||
resourceJar := android.PathForModuleOut(ctx, "res", jarName)
|
||||
TransformResourcesToJar(ctx, resourceJar, resArgs, resDeps)
|
||||
if ctx.Failed() {
|
||||
return
|
||||
|
@ -592,7 +594,7 @@ func (j *Module) compile(ctx android.ModuleContext) {
|
|||
// Optimization: skip the combine step if there is nothing to do
|
||||
outputFile = jars[0]
|
||||
} else {
|
||||
combinedJar := android.PathForModuleOut(ctx, "classes.jar")
|
||||
combinedJar := android.PathForModuleOut(ctx, "combined", jarName)
|
||||
TransformJarsToJar(ctx, combinedJar, jars, manifest, false)
|
||||
outputFile = combinedJar
|
||||
}
|
||||
|
@ -600,7 +602,7 @@ func (j *Module) compile(ctx android.ModuleContext) {
|
|||
if j.properties.Jarjar_rules != nil {
|
||||
jarjar_rules := android.PathForModuleSrc(ctx, *j.properties.Jarjar_rules)
|
||||
// Transform classes.jar into classes-jarjar.jar
|
||||
jarjarFile := android.PathForModuleOut(ctx, "classes-jarjar.jar")
|
||||
jarjarFile := android.PathForModuleOut(ctx, "jarjar", jarName)
|
||||
TransformJarJar(ctx, jarjarFile, outputFile, jarjar_rules)
|
||||
outputFile = jarjarFile
|
||||
if ctx.Failed() {
|
||||
|
@ -658,17 +660,17 @@ func (j *Module) compile(ctx android.ModuleContext) {
|
|||
|
||||
flags.desugarFlags = strings.Join(desugarFlags, " ")
|
||||
|
||||
desugarJar := android.PathForModuleOut(ctx, "classes-desugar.jar")
|
||||
desugarJar := android.PathForModuleOut(ctx, "desugar", jarName)
|
||||
TransformDesugar(ctx, desugarJar, outputFile, flags)
|
||||
outputFile = desugarJar
|
||||
if ctx.Failed() {
|
||||
return
|
||||
}
|
||||
|
||||
// Compile classes.jar into classes.dex and then javalib.jar
|
||||
javalibJar := android.PathForModuleOut(ctx, "javalib.jar")
|
||||
TransformClassesJarToDexJar(ctx, javalibJar, desugarJar, flags)
|
||||
outputFile = javalibJar
|
||||
// Compile classes.jar into classes.dex and then a dex jar
|
||||
dexJar := android.PathForModuleOut(ctx, "dex", jarName)
|
||||
TransformClassesJarToDexJar(ctx, dexJar, desugarJar, flags)
|
||||
outputFile = dexJar
|
||||
if ctx.Failed() {
|
||||
return
|
||||
}
|
||||
|
|
|
@ -142,7 +142,7 @@ func moduleToPath(name string) string {
|
|||
case strings.HasSuffix(name, ".jar"):
|
||||
return name
|
||||
default:
|
||||
return filepath.Join(buildDir, ".intermediates", name, "android_common", "classes-compiled.jar")
|
||||
return filepath.Join(buildDir, ".intermediates", name, "android_common", "javac", name+".jar")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -173,8 +173,8 @@ func TestSimple(t *testing.T) {
|
|||
t.Errorf(`foo inputs %v != ["a.java"]`, javac.Inputs)
|
||||
}
|
||||
|
||||
bar := filepath.Join(buildDir, ".intermediates", "bar", "android_common", "classes-compiled.jar")
|
||||
baz := filepath.Join(buildDir, ".intermediates", "baz", "android_common", "classes-compiled.jar")
|
||||
bar := ctx.ModuleForTests("bar", "android_common").Rule("javac").Output.String()
|
||||
baz := ctx.ModuleForTests("baz", "android_common").Rule("javac").Output.String()
|
||||
|
||||
if !strings.Contains(javac.Args["classpath"], bar) {
|
||||
t.Errorf("foo classpath %v does not contain %q", javac.Args["classpath"], bar)
|
||||
|
@ -465,12 +465,12 @@ func TestDefaults(t *testing.T) {
|
|||
t.Errorf(`foo inputs %v != ["a.java"]`, javac.Inputs)
|
||||
}
|
||||
|
||||
bar := filepath.Join(buildDir, ".intermediates", "bar", "android_common", "classes-compiled.jar")
|
||||
bar := ctx.ModuleForTests("bar", "android_common").Rule("javac").Output.String()
|
||||
if !strings.Contains(javac.Args["classpath"], bar) {
|
||||
t.Errorf("foo classpath %v does not contain %q", javac.Args["classpath"], bar)
|
||||
}
|
||||
|
||||
baz := filepath.Join(buildDir, ".intermediates", "baz", "android_common", "classes-compiled.jar")
|
||||
baz := ctx.ModuleForTests("baz", "android_common").Rule("javac").Output.String()
|
||||
if len(combineJar.Inputs) != 2 || combineJar.Inputs[1].String() != baz {
|
||||
t.Errorf("foo combineJar inputs %v does not contain %q", combineJar.Inputs, baz)
|
||||
}
|
||||
|
@ -530,8 +530,8 @@ func TestResources(t *testing.T) {
|
|||
}
|
||||
`+test.extra)
|
||||
|
||||
foo := ctx.ModuleForTests("foo", "android_common").Output("classes.jar")
|
||||
fooRes := ctx.ModuleForTests("foo", "android_common").Output("res.jar")
|
||||
foo := ctx.ModuleForTests("foo", "android_common").Output("combined/foo.jar")
|
||||
fooRes := ctx.ModuleForTests("foo", "android_common").Output("res/foo.jar")
|
||||
|
||||
if !inList(fooRes.Output.String(), foo.Inputs.Strings()) {
|
||||
t.Errorf("foo combined jars %v does not contain %q",
|
||||
|
@ -563,7 +563,7 @@ func TestExcludeResources(t *testing.T) {
|
|||
}
|
||||
`)
|
||||
|
||||
fooRes := ctx.ModuleForTests("foo", "android_common").Output("res.jar")
|
||||
fooRes := ctx.ModuleForTests("foo", "android_common").Output("res/foo.jar")
|
||||
|
||||
expected := "-C res -f res/a -f res/b"
|
||||
if fooRes.Args["jarArgs"] != expected {
|
||||
|
@ -572,7 +572,7 @@ func TestExcludeResources(t *testing.T) {
|
|||
|
||||
}
|
||||
|
||||
barRes := ctx.ModuleForTests("bar", "android_common").Output("res.jar")
|
||||
barRes := ctx.ModuleForTests("bar", "android_common").Output("res/bar.jar")
|
||||
|
||||
expected = "-C . -f res/a"
|
||||
if barRes.Args["jarArgs"] != expected {
|
||||
|
@ -625,7 +625,7 @@ func TestKotlin(t *testing.T) {
|
|||
|
||||
kotlinc := ctx.ModuleForTests("foo", "android_common").Rule("kotlinc")
|
||||
javac := ctx.ModuleForTests("foo", "android_common").Rule("javac")
|
||||
jar := ctx.ModuleForTests("foo", "android_common").Output("classes.jar")
|
||||
jar := ctx.ModuleForTests("foo", "android_common").Output("combined/foo.jar")
|
||||
|
||||
if len(kotlinc.Inputs) != 2 || kotlinc.Inputs[0].String() != "a.java" ||
|
||||
kotlinc.Inputs[1].String() != "b.kt" {
|
||||
|
|
Loading…
Reference in New Issue