Skip to content

Commit

Permalink
Finish 1.19.2 vanilla
Browse files Browse the repository at this point in the history
  • Loading branch information
shartte committed Sep 4, 2024
1 parent 89fda21 commit b9048b0
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,17 @@
import java.util.List;

public abstract class RecompileSourcesAction extends BuiltInAction implements ExecutionNodeAction {

private final ExtensibleClasspath classpath = new ExtensibleClasspath();
private final ExtensibleClasspath sourcepath = new ExtensibleClasspath();
private int targetJavaVersion = 21;

@Override
public void computeCacheKey(CacheKeyBuilder ck) {
super.computeCacheKey(ck);
classpath.computeCacheKey("compile classpath", ck);
sourcepath.computeCacheKey("compile sourcepath", ck);
ck.add("target java version", String.valueOf(targetJavaVersion));
}

protected final List<Path> getEffectiveClasspath(ProcessingEnvironment environment) throws IOException {
Expand Down Expand Up @@ -53,4 +56,12 @@ public ExtensibleClasspath getClasspath() {
public ExtensibleClasspath getSourcepath() {
return sourcepath;
}

public int getTargetJavaVersion() {
return targetJavaVersion;
}

public void setTargetJavaVersion(int targetJavaVersion) {
this.targetJavaVersion = targetJavaVersion;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public class RecompileSourcesActionWithECJ extends RecompileSourcesAction {
@Override
public void run(ProcessingEnvironment environment) throws IOException, InterruptedException {
var sources = environment.getRequiredInputPath("sources");
var javaRelease = String.valueOf(getTargetJavaVersion());

// Merge the original Minecraft classpath with the libs required by additional patches that we made
var classpathPaths = getEffectiveClasspath(environment);
Expand All @@ -69,7 +70,7 @@ public void run(ProcessingEnvironment environment) throws IOException, Interrupt
true,
new AccessRuleSet(new AccessRule[0], AccessRestriction.COMMAND_LINE, library.getFileName().toString()),
"none",
"21"
javaRelease
));
}

Expand All @@ -81,9 +82,9 @@ public void run(ProcessingEnvironment environment) throws IOException, Interrupt
var policy = DefaultErrorHandlingPolicies.exitOnFirstError();

var options = new CompilerOptions(Map.of(
CompilerOptions.OPTION_Source, "21",
CompilerOptions.OPTION_Compliance, "21",
CompilerOptions.OPTION_TargetPlatform, "21",
CompilerOptions.OPTION_Source, javaRelease,
CompilerOptions.OPTION_Compliance, javaRelease,
CompilerOptions.OPTION_TargetPlatform, javaRelease,
CompilerOptions.OPTION_ReportDeprecation, CompilerOptions.IGNORE,
CompilerOptions.OPTION_ReportDeprecationInDeprecatedCode, CompilerOptions.DISABLED,
CompilerOptions.OPTION_ReportDeprecationWhenOverridingDeprecatedMethod, CompilerOptions.DISABLED,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,6 @@
* 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
compilerOptions.add("-implicit:none"); // Prevents source files from the source-path from being emitted
}

@Override
public void run(ProcessingEnvironment environment) throws IOException, InterruptedException {
var sources = environment.getRequiredInputPath("sources");
Expand Down Expand Up @@ -84,7 +72,7 @@ public void report(Diagnostic<? extends JavaFileObject> d) {
fileManager.setLocationFromPaths(StandardLocation.SOURCE_PATH, sourcepath);

var sourceJavaFiles = fileManager.getJavaFileObjectsFromPaths(sourcePaths);
var task = compiler.getTask(null, fileManager, diagnostics, compilerOptions, null, sourceJavaFiles);
var task = compiler.getTask(null, fileManager, diagnostics, getCompilerOptions(), null, sourceJavaFiles);
if (!task.call()) {
throw new IOException("Compilation failed");
}
Expand All @@ -106,6 +94,18 @@ 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);
ck.addStrings("compiler options", getCompilerOptions());
}

private List<String> getCompilerOptions() {
return List.of(
"--release",
String.valueOf(getTargetJavaVersion()),
"-proc:none", // No annotation processing on Minecraft sources
"-nowarn", // We have no influence on Minecraft sources, so no warnings
"-g", // Gradle compiles with debug by default, so we replicate this
"-XDuseUnsharedTable=true", // Gradle also adds this unconditionally
"-implicit:none" // Prevents source files from the source-path from being emitted
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.google.gson.JsonObject;
import com.google.gson.JsonSyntaxException;
import com.google.gson.annotations.SerializedName;
import net.neoforged.neoform.runtime.config.neoforge.NeoForgeConfig;
import net.neoforged.neoform.runtime.utils.MavenCoordinate;
import org.jetbrains.annotations.Nullable;

Expand All @@ -18,7 +17,7 @@
public record NeoFormConfig(int spec,
@SerializedName("version") String minecraftVersion,
boolean official,
@SerializedName("java_target") String javaVersion,
@SerializedName("java_target") int javaVersion,
String encoding,
Map<String, Object> data,
Map<String, List<NeoFormStep>> steps,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ public NeoFormDistConfig(NeoFormConfig config, String dist) {
this.dist = dist;
}

public int javaVersion() {
return config.javaVersion();
}

public String minecraftVersion() {
return config.minecraftVersion();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,12 @@ private NodeOutput addRecompileStep(NeoFormDistConfig distConfig, NodeOutput sou
compileAction = new RecompileSourcesActionWithJDK();
}

compileAction.setTargetJavaVersion(distConfig.javaVersion());

// Add NeoForm libraries or apply overridden classpath fully
compileAction.getClasspath().setOverriddenClasspath(buildOptions.getOverriddenCompileClasspath());
compileAction.getClasspath().addMavenLibraries(distConfig.libraries());

builder.action(compileAction);
builder.build();
return compiledOutput;
Expand Down

0 comments on commit b9048b0

Please sign in to comment.