Add super classes to decompiler cache ClassEntry (#1118)

* Add super classes to decompiler cache ClassEntry

* And implement

* Add existing classes jar for the decompiler
This commit is contained in:
modmuss
2024-05-14 21:31:26 +01:00
committed by GitHub
parent db65759c88
commit 8110523508
8 changed files with 499 additions and 134 deletions

View File

@@ -156,6 +156,11 @@ public abstract class GenerateSourcesTask extends AbstractLoomTask {
@ApiStatus.Experimental
public abstract Property<Boolean> getUseCache();
@Input
@Option(option = "reset-cache", description = "When set the cache will be reset")
@ApiStatus.Experimental
public abstract Property<Boolean> getResetCache();
// Internal outputs
@ApiStatus.Internal
@Internal
@@ -188,6 +193,7 @@ public abstract class GenerateSourcesTask extends AbstractLoomTask {
getUnpickRuntimeClasspath().from(getProject().getConfigurations().getByName(Constants.Configurations.UNPICK_CLASSPATH));
getUseCache().convention(true);
getResetCache().convention(false);
}
@TaskAction
@@ -214,6 +220,11 @@ public abstract class GenerateSourcesTask extends AbstractLoomTask {
try (var timer = new Timer("Decompiled sources with cache")) {
final Path cacheFile = getDecompileCacheFile().getAsFile().get().toPath();
if (getResetCache().get()) {
LOGGER.warn("Resetting decompile cache");
Files.deleteIfExists(cacheFile);
}
// TODO ensure we have a lock on this file to prevent multiple tasks from running at the same time
// TODO handle being unable to read the cache file
Files.createDirectories(cacheFile.getParent());
@@ -250,16 +261,16 @@ public abstract class GenerateSourcesTask extends AbstractLoomTask {
if (job instanceof CachedJarProcessor.WorkToDoJob workToDoJob) {
Path inputJar = workToDoJob.incomplete();
@Nullable Path existing = (job instanceof CachedJarProcessor.PartialWorkJob partialWorkJob) ? partialWorkJob.existing() : null;
@Nullable Path existingClasses = (job instanceof CachedJarProcessor.PartialWorkJob partialWorkJob) ? partialWorkJob.existingClasses() : null;
if (getUnpickDefinitions().isPresent()) {
try (var timer = new Timer("Unpick")) {
inputJar = unpickJar(inputJar, existing);
inputJar = unpickJar(inputJar, existingClasses);
}
}
try (var timer = new Timer("Decompile")) {
outputLineNumbers = runDecompileJob(inputJar, workToDoJob.output(), existing);
outputLineNumbers = runDecompileJob(inputJar, workToDoJob.output(), existingClasses);
}
if (Files.notExists(workToDoJob.output())) {
@@ -277,6 +288,8 @@ public abstract class GenerateSourcesTask extends AbstractLoomTask {
cachedJarProcessor.completeJob(sourcesJar, job, outputLineNumbers);
}
LOGGER.info("Decompiled sources written to {}", sourcesJar);
// This is the minecraft jar used at runtime.
final Path classesJar = minecraftJar.getPath();
@@ -326,6 +339,8 @@ public abstract class GenerateSourcesTask extends AbstractLoomTask {
throw new RuntimeException("Failed to decompile sources");
}
LOGGER.info("Decompiled sources written to {}", sourcesJar);
if (lineNumbers == null) {
LOGGER.info("No line numbers to remap, skipping remapping");
return;
@@ -436,9 +451,9 @@ public abstract class GenerateSourcesTask extends AbstractLoomTask {
);
}
private Path unpickJar(Path inputJar, @Nullable Path existingJar) {
private Path unpickJar(Path inputJar, @Nullable Path existingClasses) {
final Path outputJar = getUnpickOutputJar().get().getAsFile().toPath();
final List<String> args = getUnpickArgs(inputJar, outputJar, existingJar);
final List<String> args = getUnpickArgs(inputJar, outputJar, existingClasses);
ExecResult result = getExecOperations().javaexec(spec -> {
spec.getMainClass().set("daomephsta.unpick.cli.Main");
@@ -452,7 +467,7 @@ public abstract class GenerateSourcesTask extends AbstractLoomTask {
return outputJar;
}
private List<String> getUnpickArgs(Path inputJar, Path outputJar, @Nullable Path existingJar) {
private List<String> getUnpickArgs(Path inputJar, Path outputJar, @Nullable Path existingClasses) {
var fileArgs = new ArrayList<File>();
fileArgs.add(inputJar.toFile());
@@ -469,8 +484,8 @@ public abstract class GenerateSourcesTask extends AbstractLoomTask {
fileArgs.add(file);
}
if (existingJar != null) {
fileArgs.add(existingJar.toFile());
if (existingClasses != null) {
fileArgs.add(existingClasses.toFile());
}
return fileArgs.stream()
@@ -505,15 +520,15 @@ public abstract class GenerateSourcesTask extends AbstractLoomTask {
LOGGER.info("Wrote linemap to {}", lineMap);
}
private void doWork(@Nullable IPCServer ipcServer, Path inputJar, Path outputJar, Path linemapFile, @Nullable Path existingJar) {
private void doWork(@Nullable IPCServer ipcServer, Path inputJar, Path outputJar, Path linemapFile, @Nullable Path existingClasses) {
final String jvmMarkerValue = UUID.randomUUID().toString();
final WorkQueue workQueue = createWorkQueue(jvmMarkerValue);
ConfigurableFileCollection classpath = getProject().files();
classpath.from(getProject().getConfigurations().getByName(Constants.Configurations.MINECRAFT_COMPILE_LIBRARIES));
if (existingJar != null) {
classpath.from(existingJar);
if (existingClasses != null) {
classpath.from(existingClasses);
}
workQueue.submit(DecompileAction.class, params -> {