Refactor errorprone support to reduce duplication
Use a helper function to set up errorprone and javac compiles. Test: m -j checkbuild Test: m -j RUN_ERROR_PRONE=true Change-Id: Icef3a5e1b359487eea3c3306d3d5763dab912b38
This commit is contained in:
parent
8122bd58ba
commit
070879e69e
|
@ -137,36 +137,8 @@ type javaBuilderFlags struct {
|
|||
func TransformJavaToClasses(ctx android.ModuleContext, srcFiles, srcFileLists android.Paths,
|
||||
flags javaBuilderFlags, deps android.Paths) android.ModuleOutPath {
|
||||
|
||||
classDir := android.PathForModuleOut(ctx, "classes")
|
||||
annoDir := android.PathForModuleOut(ctx, "anno")
|
||||
classJar := android.PathForModuleOut(ctx, "classes-compiled.jar")
|
||||
|
||||
javacFlags := flags.javacFlags
|
||||
if len(srcFileLists) > 0 {
|
||||
javacFlags += " " + android.JoinWithPrefix(srcFileLists.Strings(), "@")
|
||||
}
|
||||
|
||||
deps = append(deps, srcFileLists...)
|
||||
deps = append(deps, flags.bootClasspath...)
|
||||
deps = append(deps, flags.classpath...)
|
||||
|
||||
ctx.ModuleBuild(pctx, android.ModuleBuildParams{
|
||||
Rule: javac,
|
||||
Description: "javac",
|
||||
Output: classJar,
|
||||
Inputs: srcFiles,
|
||||
Implicits: deps,
|
||||
Args: map[string]string{
|
||||
"javacFlags": javacFlags,
|
||||
"bootClasspath": flags.bootClasspath.JavaBootClasspath(ctx.Device()),
|
||||
"classpath": flags.classpath.JavaClasspath(),
|
||||
"outDir": classDir.String(),
|
||||
"annoDir": annoDir.String(),
|
||||
"javaVersion": flags.javaVersion,
|
||||
},
|
||||
})
|
||||
|
||||
return classJar
|
||||
return transformJavaToClasses(ctx, srcFiles, srcFileLists, flags, deps,
|
||||
"classes-compiled.jar", "", "javac", javac)
|
||||
}
|
||||
|
||||
func RunErrorProne(ctx android.ModuleContext, srcFiles, srcFileLists android.Paths,
|
||||
|
@ -177,38 +149,54 @@ func RunErrorProne(ctx android.ModuleContext, srcFiles, srcFileLists android.Pat
|
|||
return nil
|
||||
}
|
||||
|
||||
classDir := android.PathForModuleOut(ctx, "classes-errorprone")
|
||||
annoDir := android.PathForModuleOut(ctx, "anno-errorprone")
|
||||
classFileList := android.PathForModuleOut(ctx, "classes-errorprone.list")
|
||||
return transformJavaToClasses(ctx, srcFiles, srcFileLists, flags, nil,
|
||||
"classes-errorprone.list", "-errorprone", "errorprone", errorprone)
|
||||
}
|
||||
|
||||
// transformJavaToClasses takes source files and converts them to a jar containing .class files.
|
||||
// srcFiles is a list of paths to sources, srcFileLists is a list of paths to files that contain
|
||||
// paths to sources. There is no dependency on the sources passed through srcFileLists, those
|
||||
// must be added through the deps argument, which contains a list of paths that should be added
|
||||
// as implicit dependencies. flags contains various command line flags to be passed to the
|
||||
// compiler.
|
||||
//
|
||||
// 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.
|
||||
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)
|
||||
|
||||
javacFlags := flags.javacFlags
|
||||
if len(srcFileLists) > 0 {
|
||||
javacFlags += " " + android.JoinWithPrefix(srcFileLists.Strings(), "@")
|
||||
}
|
||||
|
||||
var deps android.Paths
|
||||
|
||||
deps = append(deps, srcFileLists...)
|
||||
deps = append(deps, flags.bootClasspath...)
|
||||
deps = append(deps, flags.classpath...)
|
||||
|
||||
ctx.ModuleBuild(pctx, android.ModuleBuildParams{
|
||||
Rule: errorprone,
|
||||
Description: "errorprone",
|
||||
Output: classFileList,
|
||||
Rule: rule,
|
||||
Description: desc,
|
||||
Output: outputFile,
|
||||
Inputs: srcFiles,
|
||||
Implicits: deps,
|
||||
Args: map[string]string{
|
||||
"javacFlags": javacFlags,
|
||||
"bootClasspath": flags.bootClasspath.JavaBootClasspath(ctx.Device()),
|
||||
"classpath": flags.classpath.JavaClasspath(),
|
||||
"outDir": classDir.String(),
|
||||
"annoDir": annoDir.String(),
|
||||
"outDir": android.PathForModuleOut(ctx, "classes"+suffix).String(),
|
||||
"annoDir": android.PathForModuleOut(ctx, "anno"+suffix).String(),
|
||||
"javaVersion": flags.javaVersion,
|
||||
},
|
||||
})
|
||||
|
||||
return classFileList
|
||||
return outputFile
|
||||
}
|
||||
|
||||
func TransformResourcesToJar(ctx android.ModuleContext, jarArgs []string,
|
||||
|
|
Loading…
Reference in New Issue