Pass output file names into java.Transform* functions
Pass the output file name into the java.Transform* functions. This consistently puts control of the filename into java.go, which is often necessary to avoid collisions when the same rule is used multiple times in a single module. It also has the side-effect of removing the poorly named "stem" parameters. Test: java_test.go Change-Id: I7bc1d1f3bfae6f9d2c92870e6df381817817aab4
This commit is contained in:
@@ -135,23 +135,24 @@ type javaBuilderFlags struct {
|
||||
protoOutFlag string
|
||||
}
|
||||
|
||||
func TransformJavaToClasses(ctx android.ModuleContext, srcFiles, srcFileLists android.Paths,
|
||||
flags javaBuilderFlags, deps android.Paths) android.ModuleOutPath {
|
||||
func TransformJavaToClasses(ctx android.ModuleContext, outputFile android.WritablePath,
|
||||
srcFiles, srcFileLists android.Paths,
|
||||
flags javaBuilderFlags, deps android.Paths) {
|
||||
|
||||
return transformJavaToClasses(ctx, srcFiles, srcFileLists, flags, deps,
|
||||
"classes-compiled.jar", "", "javac", javac)
|
||||
transformJavaToClasses(ctx, outputFile, srcFiles, srcFileLists, flags, deps,
|
||||
"", "javac", javac)
|
||||
}
|
||||
|
||||
func RunErrorProne(ctx android.ModuleContext, srcFiles, srcFileLists android.Paths,
|
||||
flags javaBuilderFlags) android.Path {
|
||||
func RunErrorProne(ctx android.ModuleContext, outputFile android.WritablePath,
|
||||
srcFiles, srcFileLists android.Paths,
|
||||
flags javaBuilderFlags) {
|
||||
|
||||
if config.ErrorProneJar == "" {
|
||||
ctx.ModuleErrorf("cannot build with Error Prone, missing external/error_prone?")
|
||||
return nil
|
||||
}
|
||||
|
||||
return transformJavaToClasses(ctx, srcFiles, srcFileLists, flags, nil,
|
||||
"classes-errorprone.list", "-errorprone", "errorprone", errorprone)
|
||||
transformJavaToClasses(ctx, outputFile, srcFiles, srcFileLists, flags, nil,
|
||||
"-errorprone", "errorprone", errorprone)
|
||||
}
|
||||
|
||||
// transformJavaToClasses takes source files and converts them to a jar containing .class files.
|
||||
@@ -166,11 +167,10 @@ func RunErrorProne(ctx android.ModuleContext, srcFiles, srcFileLists android.Pat
|
||||
// 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.
|
||||
func transformJavaToClasses(ctx android.ModuleContext, srcFiles, srcFileLists android.Paths,
|
||||
flags javaBuilderFlags, deps android.Paths, stem, suffix, desc string,
|
||||
rule blueprint.Rule) android.ModuleOutPath {
|
||||
|
||||
outputFile := android.PathForModuleOut(ctx, stem)
|
||||
func transformJavaToClasses(ctx android.ModuleContext, outputFile android.WritablePath,
|
||||
srcFiles, srcFileLists android.Paths,
|
||||
flags javaBuilderFlags, deps android.Paths,
|
||||
intermediatesSuffix, desc string, rule blueprint.Rule) {
|
||||
|
||||
javacFlags := flags.javacFlags
|
||||
if len(srcFileLists) > 0 {
|
||||
@@ -200,19 +200,15 @@ func transformJavaToClasses(ctx android.ModuleContext, srcFiles, srcFileLists an
|
||||
"javacFlags": javacFlags,
|
||||
"bootClasspath": bootClasspath,
|
||||
"classpath": flags.classpath.JavaClasspath(),
|
||||
"outDir": android.PathForModuleOut(ctx, "classes"+suffix).String(),
|
||||
"annoDir": android.PathForModuleOut(ctx, "anno"+suffix).String(),
|
||||
"outDir": android.PathForModuleOut(ctx, "classes"+intermediatesSuffix).String(),
|
||||
"annoDir": android.PathForModuleOut(ctx, "anno"+intermediatesSuffix).String(),
|
||||
"javaVersion": flags.javaVersion,
|
||||
},
|
||||
})
|
||||
|
||||
return outputFile
|
||||
}
|
||||
|
||||
func TransformResourcesToJar(ctx android.ModuleContext, jarArgs []string,
|
||||
deps android.Paths) android.Path {
|
||||
|
||||
outputFile := android.PathForModuleOut(ctx, "res.jar")
|
||||
func TransformResourcesToJar(ctx android.ModuleContext, outputFile android.WritablePath,
|
||||
jarArgs []string, deps android.Paths) {
|
||||
|
||||
ctx.ModuleBuild(pctx, android.ModuleBuildParams{
|
||||
Rule: jar,
|
||||
@@ -223,18 +219,10 @@ func TransformResourcesToJar(ctx android.ModuleContext, jarArgs []string,
|
||||
"jarArgs": strings.Join(jarArgs, " "),
|
||||
},
|
||||
})
|
||||
|
||||
return outputFile
|
||||
}
|
||||
|
||||
func TransformJarsToJar(ctx android.ModuleContext, stem string, jars android.Paths,
|
||||
manifest android.OptionalPath, stripDirs bool) android.Path {
|
||||
|
||||
outputFile := android.PathForModuleOut(ctx, stem)
|
||||
|
||||
if len(jars) == 1 && !manifest.Valid() {
|
||||
return jars[0]
|
||||
}
|
||||
func TransformJarsToJar(ctx android.ModuleContext, outputFile android.WritablePath,
|
||||
jars android.Paths, manifest android.OptionalPath, stripDirs bool) {
|
||||
|
||||
var deps android.Paths
|
||||
|
||||
@@ -258,14 +246,11 @@ func TransformJarsToJar(ctx android.ModuleContext, stem string, jars android.Pat
|
||||
"jarArgs": strings.Join(jarArgs, " "),
|
||||
},
|
||||
})
|
||||
|
||||
return outputFile
|
||||
}
|
||||
|
||||
func TransformDesugar(ctx android.ModuleContext, classesJar android.Path,
|
||||
flags javaBuilderFlags) android.Path {
|
||||
func TransformDesugar(ctx android.ModuleContext, outputFile android.WritablePath,
|
||||
classesJar android.Path, flags javaBuilderFlags) {
|
||||
|
||||
outputFile := android.PathForModuleOut(ctx, "classes-desugar.jar")
|
||||
dumpDir := android.PathForModuleOut(ctx, "desugar_dumped_classes")
|
||||
|
||||
javaFlags := ""
|
||||
@@ -294,17 +279,14 @@ func TransformDesugar(ctx android.ModuleContext, classesJar android.Path,
|
||||
"desugarFlags": flags.desugarFlags,
|
||||
},
|
||||
})
|
||||
|
||||
return outputFile
|
||||
}
|
||||
|
||||
// Converts a classes.jar file to classes*.dex, then combines the dex files with any resources
|
||||
// in the classes.jar file into a dex jar.
|
||||
func TransformClassesJarToDexJar(ctx android.ModuleContext, stem string, classesJar android.Path,
|
||||
flags javaBuilderFlags) android.Path {
|
||||
func TransformClassesJarToDexJar(ctx android.ModuleContext, outputFile android.WritablePath,
|
||||
classesJar android.Path, flags javaBuilderFlags) {
|
||||
|
||||
outDir := android.PathForModuleOut(ctx, "dex")
|
||||
outputFile := android.PathForModuleOut(ctx, stem)
|
||||
|
||||
ctx.ModuleBuild(pctx, android.ModuleBuildParams{
|
||||
Rule: dx,
|
||||
@@ -316,12 +298,10 @@ func TransformClassesJarToDexJar(ctx android.ModuleContext, stem string, classes
|
||||
"outDir": outDir.String(),
|
||||
},
|
||||
})
|
||||
|
||||
return outputFile
|
||||
}
|
||||
|
||||
func TransformJarJar(ctx android.ModuleContext, classesJar android.Path, rulesFile android.Path) android.ModuleOutPath {
|
||||
outputFile := android.PathForModuleOut(ctx, "classes-jarjar.jar")
|
||||
func TransformJarJar(ctx android.ModuleContext, outputFile android.WritablePath,
|
||||
classesJar android.Path, rulesFile android.Path) {
|
||||
ctx.ModuleBuild(pctx, android.ModuleBuildParams{
|
||||
Rule: jarjar,
|
||||
Description: "jarjar",
|
||||
@@ -332,8 +312,6 @@ func TransformJarJar(ctx android.ModuleContext, classesJar android.Path, rulesFi
|
||||
"rulesFile": rulesFile.String(),
|
||||
},
|
||||
})
|
||||
|
||||
return outputFile
|
||||
}
|
||||
|
||||
type classpath []android.Path
|
||||
|
36
java/java.go
36
java/java.go
@@ -501,12 +501,14 @@ 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 := RunErrorProne(ctx, srcFiles, srcFileLists, flags)
|
||||
errorprone := android.PathForModuleOut(ctx, "classes-errorprone.list")
|
||||
RunErrorProne(ctx, errorprone, srcFiles, srcFileLists, flags)
|
||||
extraJarDeps = append(extraJarDeps, errorprone)
|
||||
}
|
||||
|
||||
// Compile java sources into .class files
|
||||
classes := TransformJavaToClasses(ctx, srcFiles, srcFileLists, flags, extraJarDeps)
|
||||
classes := android.PathForModuleOut(ctx, "classes-compiled.jar")
|
||||
TransformJavaToClasses(ctx, classes, srcFiles, srcFileLists, flags, extraJarDeps)
|
||||
if ctx.Failed() {
|
||||
return
|
||||
}
|
||||
@@ -533,7 +535,8 @@ func (j *Module) compile(ctx android.ModuleContext) {
|
||||
}
|
||||
|
||||
if len(resArgs) > 0 {
|
||||
resourceJar := TransformResourcesToJar(ctx, resArgs, resDeps)
|
||||
resourceJar := android.PathForModuleOut(ctx, "res.jar")
|
||||
TransformResourcesToJar(ctx, resourceJar, resArgs, resDeps)
|
||||
if ctx.Failed() {
|
||||
return
|
||||
}
|
||||
@@ -548,12 +551,23 @@ func (j *Module) compile(ctx android.ModuleContext) {
|
||||
|
||||
// Combine the classes built from sources, any manifests, and any static libraries into
|
||||
// classes.jar. If there is only one input jar this step will be skipped.
|
||||
outputFile := TransformJarsToJar(ctx, "classes.jar", jars, manifest, false)
|
||||
var outputFile android.Path
|
||||
|
||||
if len(jars) == 1 && !manifest.Valid() {
|
||||
// Optimization: skip the combine step if there is nothing to do
|
||||
outputFile = jars[0]
|
||||
} else {
|
||||
combinedJar := android.PathForModuleOut(ctx, "classes.jar")
|
||||
TransformJarsToJar(ctx, combinedJar, jars, manifest, false)
|
||||
outputFile = combinedJar
|
||||
}
|
||||
|
||||
if j.properties.Jarjar_rules != nil {
|
||||
jarjar_rules := android.PathForModuleSrc(ctx, *j.properties.Jarjar_rules)
|
||||
// Transform classes.jar into classes-jarjar.jar
|
||||
outputFile = TransformJarJar(ctx, outputFile, jarjar_rules)
|
||||
jarjarFile := android.PathForModuleOut(ctx, "classes-jarjar.jar")
|
||||
TransformJarJar(ctx, jarjarFile, outputFile, jarjar_rules)
|
||||
outputFile = jarjarFile
|
||||
if ctx.Failed() {
|
||||
return
|
||||
}
|
||||
@@ -609,13 +623,17 @@ func (j *Module) compile(ctx android.ModuleContext) {
|
||||
|
||||
flags.desugarFlags = strings.Join(desugarFlags, " ")
|
||||
|
||||
desugarJar := TransformDesugar(ctx, outputFile, flags)
|
||||
desugarJar := android.PathForModuleOut(ctx, "classes-desugar.jar")
|
||||
TransformDesugar(ctx, desugarJar, outputFile, flags)
|
||||
outputFile = desugarJar
|
||||
if ctx.Failed() {
|
||||
return
|
||||
}
|
||||
|
||||
// Compile classes.jar into classes.dex and then javalib.jar
|
||||
outputFile = TransformClassesJarToDexJar(ctx, "javalib.jar", desugarJar, flags)
|
||||
javalibJar := android.PathForModuleOut(ctx, "javalib.jar")
|
||||
TransformClassesJarToDexJar(ctx, javalibJar, desugarJar, flags)
|
||||
outputFile = javalibJar
|
||||
if ctx.Failed() {
|
||||
return
|
||||
}
|
||||
@@ -790,7 +808,9 @@ func (j *Import) DepsMutator(ctx android.BottomUpMutatorContext) {
|
||||
func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
||||
j.classpathFiles = android.PathsForModuleSrc(ctx, j.properties.Jars)
|
||||
|
||||
j.combinedClasspathFile = TransformJarsToJar(ctx, "classes.jar", j.classpathFiles, android.OptionalPath{}, false)
|
||||
outputFile := android.PathForModuleOut(ctx, "classes.jar")
|
||||
TransformJarsToJar(ctx, outputFile, j.classpathFiles, android.OptionalPath{}, false)
|
||||
j.combinedClasspathFile = outputFile
|
||||
}
|
||||
|
||||
var _ Dependency = (*Import)(nil)
|
||||
|
Reference in New Issue
Block a user