Skip to content

Commit

Permalink
Consider options in the cache key
Browse files Browse the repository at this point in the history
  • Loading branch information
shartte committed May 26, 2024
1 parent e241d5f commit 60470e6
Showing 1 changed file with 14 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,22 @@
* Uses the current JDKs java compiler interface to recompile the sources.
*/
public class RecompileSourcesActionWithJDK extends RecompileSourcesAction {
private final List<String> compilerOptions = new ArrayList<>();

public RecompileSourcesActionWithJDK() {
compilerOptions.add("--release");
compilerOptions.add("21");
compilerOptions.add("-proc:none"); // No annotation processing on Minecraft sources
compilerOptions.add("-nowarn"); // We have no influence on Minecraft sources, so no warnings
compilerOptions.add("-g"); // Gradle compiles with debug by default, so we replicate this
compilerOptions.add("-XDuseUnsharedTable=true"); // Gradle also adds this unconditionally
}

@Override
public void run(ProcessingEnvironment environment) throws IOException, InterruptedException {
var sources = environment.getRequiredInputPath("sources");
var classpath = getEffectiveClasspath(environment);

var javaCompilerOptions = new ArrayList<String>();
javaCompilerOptions.add("--release");
javaCompilerOptions.add("21");
javaCompilerOptions.add("-proc:none"); // No annotation processing on Minecraft sources
javaCompilerOptions.add("-nowarn"); // We have no influence on Minecraft sources, so no warnings
javaCompilerOptions.add("-g"); // Gradle compiles with debug by default, so we replicate this
javaCompilerOptions.add("-XDuseUnsharedTable=true"); // Gradle also adds this unconditionally

URI uri = URI.create("jar:" + sources.toUri());
try (var sourceFs = FileSystems.newFileSystem(uri, Map.of())) {
var compiler = ToolProvider.getSystemJavaCompiler();
Expand All @@ -55,7 +58,7 @@ public void run(ProcessingEnvironment environment) throws IOException, Interrupt
});
}

LOG.println("Compiling " + sourcePaths.size() + " source files");
LOG.println(" Compiling " + sourcePaths.size() + " source files");

var diagnostics = new DiagnosticListener<JavaFileObject>() {
@Override
Expand All @@ -78,7 +81,7 @@ public void report(Diagnostic<? extends JavaFileObject> d) {
fileManager.setLocationFromPaths(StandardLocation.CLASS_PATH, classpath);

var sourceJavaFiles = fileManager.getJavaFileObjectsFromPaths(sourcePaths);
var task = compiler.getTask(null, fileManager, diagnostics, javaCompilerOptions, null, sourceJavaFiles);
var task = compiler.getTask(null, fileManager, diagnostics, compilerOptions, null, sourceJavaFiles);
if (!task.call()) {
throw new IOException("Compilation failed");
}
Expand All @@ -100,5 +103,6 @@ public void report(Diagnostic<? extends JavaFileObject> d) {
public void computeCacheKey(CacheKeyBuilder ck) {
super.computeCacheKey(ck);
ck.add("compiler type", "javac");
ck.addStrings("compiler options", compilerOptions);
}
}

0 comments on commit 60470e6

Please sign in to comment.