From eaa475107dc4cc21c061b643dd08b270442facf4 Mon Sep 17 00:00:00 2001 From: Spandan Das Date: Tue, 9 Apr 2024 21:30:12 +0000 Subject: [PATCH] Add the implicit deps of javacRE This includes 1. the prebuilt javac binary 2. the input .java files 3. the jars that are placed on the classpath during javac (2) is passed via ${out}.rsp. This rsp file gets populated with the input java files For (3), this CL creates a new intermediate file whose content is comma separated jars available on the classpath (this is the format expected by rewrapper). This file is then registered in RSPFiles of javacRE command, so that it gets passed to the rewrapper cmd as `--input_list_paths` (rspfiles are necesary for modules like framework-minus-apex to avoid exceeding cmd line limits) Bug: 308687455 Test: m framework-minus-apex; # verified that the relevant files are added as `--inputs` of javac Change-Id: I2ab9277fc394eb00454ef503c78a9f3451e596ac --- java/builder.go | 46 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 14 deletions(-) diff --git a/java/builder.go b/java/builder.go index 5d84d0b43..6a5772583 100644 --- a/java/builder.go +++ b/java/builder.go @@ -19,6 +19,7 @@ package java // functions. import ( + "fmt" "path/filepath" "strconv" "strings" @@ -68,6 +69,8 @@ var ( }, map[string]*remoteexec.REParams{ "$javaTemplate": &remoteexec.REParams{ Labels: map[string]string{"type": "compile", "lang": "java", "compiler": "javac"}, + Inputs: []string{"${config.JavacCmd}"}, + RSPFiles: []string{"${out}.rsp", "${javacREClasspathDeps}"}, ExecStrategy: "${config.REJavacExecStrategy}", Platform: map[string]string{remoteexec.PoolKey: "${config.REJavaPool}"}, }, @@ -86,7 +89,7 @@ var ( Platform: map[string]string{remoteexec.PoolKey: "${config.REJavaPool}"}, }, }, []string{"javacFlags", "bootClasspath", "classpath", "processorpath", "processor", "srcJars", "srcJarDir", - "outDir", "annoDir", "annoSrcJar", "javaVersion"}, nil) + "outDir", "annoDir", "annoSrcJar", "javaVersion"}, []string{"javacREClasspathDeps"}) _ = pctx.VariableFunc("kytheCorpus", func(ctx android.PackageVarContext) string { return ctx.Config().XrefCorpusName() }) @@ -601,8 +604,35 @@ func transformJavaToClasses(ctx android.ModuleContext, outputFile android.Writab annoDir = filepath.Join(shardDir, annoDir) } rule := javac + args := map[string]string{ + "javacFlags": flags.javacFlags, + "bootClasspath": bootClasspath, + "classpath": classpathArg, + "processorpath": flags.processorPath.FormJavaClassPath("-processorpath"), + "processor": processor, + "srcJars": strings.Join(srcJars.Strings(), " "), + "srcJarDir": android.PathForModuleOut(ctx, intermediatesDir, srcJarDir).String(), + "outDir": android.PathForModuleOut(ctx, intermediatesDir, outDir).String(), + "annoDir": android.PathForModuleOut(ctx, intermediatesDir, annoDir).String(), + "annoSrcJar": annoSrcJar.String(), + "javaVersion": flags.javaVersion.String(), + } + if ctx.Config().UseRBE() && ctx.Config().IsEnvTrue("RBE_JAVAC") { rule = javacRE + + // Write the classpath deps to a file that can be passed as an input to javacRE. + // Skip the shardIdx if the java library is unsharded + shardIdxSuffix := strconv.Itoa(shardIdx) + if shardIdx == -1 { + shardIdxSuffix = "" + } + javacREClasspathDepsFile := outputFile.ReplaceExtension(ctx, fmt.Sprintf("javacre.classpathdeps%v", shardIdxSuffix)) + android.WriteFileRule(ctx, javacREClasspathDepsFile, strings.Join(javacClasspath.Strings(), ",")) // The classpath jars are an implicit dep of javacRE + args["javacREClasspathDeps"] = javacREClasspathDepsFile.String() + + // Add the deps file to the implicit inputs + deps = append(deps, javacREClasspathDepsFile) } ctx.Build(pctx, android.BuildParams{ Rule: rule, @@ -611,19 +641,7 @@ func transformJavaToClasses(ctx android.ModuleContext, outputFile android.Writab ImplicitOutput: annoSrcJar, Inputs: srcFiles, Implicits: deps, - Args: map[string]string{ - "javacFlags": flags.javacFlags, - "bootClasspath": bootClasspath, - "classpath": classpathArg, - "processorpath": flags.processorPath.FormJavaClassPath("-processorpath"), - "processor": processor, - "srcJars": strings.Join(srcJars.Strings(), " "), - "srcJarDir": android.PathForModuleOut(ctx, intermediatesDir, srcJarDir).String(), - "outDir": android.PathForModuleOut(ctx, intermediatesDir, outDir).String(), - "annoDir": android.PathForModuleOut(ctx, intermediatesDir, annoDir).String(), - "annoSrcJar": annoSrcJar.String(), - "javaVersion": flags.javaVersion.String(), - }, + Args: args, }) }