aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormodmuss50 <modmuss50@gmail.com>2021-11-01 13:43:03 +0000
committerGitHub <noreply@github.com>2021-11-01 13:43:03 +0000
commit5f379e4f426951d55f0ac4889c5207f80afcf86c (patch)
tree3478c32d7404670e47013a5044dff33df1144e05 /src
parentd01c20f0490db845a7f2bc634a50d5977878e486 (diff)
downloadarchitectury-loom-5f379e4f426951d55f0ac4889c5207f80afcf86c.tar.gz
architectury-loom-5f379e4f426951d55f0ac4889c5207f80afcf86c.tar.bz2
architectury-loom-5f379e4f426951d55f0ac4889c5207f80afcf86c.zip
Make CFR the default decompiler (#527)
* Make CFR the default decompiler Expose decompiler options * Remove convention, default value is an empty map. * Checkstyle..
Diffstat (limited to 'src')
-rw-r--r--src/main/java/net/fabricmc/loom/api/decompilers/DecompilationMetadata.java3
-rw-r--r--src/main/java/net/fabricmc/loom/decompilers/cfr/LoomCFRDecompiler.java8
-rw-r--r--src/main/java/net/fabricmc/loom/decompilers/fernflower/FabricFernFlowerDecompiler.java23
-rw-r--r--src/main/java/net/fabricmc/loom/task/GenerateSourcesTask.java12
-rw-r--r--src/main/java/net/fabricmc/loom/task/LoomTasks.java33
-rw-r--r--src/test/groovy/net/fabricmc/loom/test/integration/DecompileTest.groovy4
6 files changed, 57 insertions, 26 deletions
diff --git a/src/main/java/net/fabricmc/loom/api/decompilers/DecompilationMetadata.java b/src/main/java/net/fabricmc/loom/api/decompilers/DecompilationMetadata.java
index a4f6dcfa..191a045b 100644
--- a/src/main/java/net/fabricmc/loom/api/decompilers/DecompilationMetadata.java
+++ b/src/main/java/net/fabricmc/loom/api/decompilers/DecompilationMetadata.java
@@ -26,8 +26,9 @@ package net.fabricmc.loom.api.decompilers;
import java.nio.file.Path;
import java.util.Collection;
+import java.util.Map;
import net.fabricmc.loom.util.IOStringConsumer;
-public record DecompilationMetadata(int numberOfThreads, Path javaDocs, Collection<Path> libraries, IOStringConsumer logger) {
+public record DecompilationMetadata(int numberOfThreads, Path javaDocs, Collection<Path> libraries, IOStringConsumer logger, Map<String, String> options) {
}
diff --git a/src/main/java/net/fabricmc/loom/decompilers/cfr/LoomCFRDecompiler.java b/src/main/java/net/fabricmc/loom/decompilers/cfr/LoomCFRDecompiler.java
index bbfb0be2..cb715139 100644
--- a/src/main/java/net/fabricmc/loom/decompilers/cfr/LoomCFRDecompiler.java
+++ b/src/main/java/net/fabricmc/loom/decompilers/cfr/LoomCFRDecompiler.java
@@ -32,6 +32,7 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Collections;
+import java.util.HashMap;
import java.util.Map;
import java.util.jar.Attributes;
import java.util.jar.JarOutputStream;
@@ -64,7 +65,10 @@ public class LoomCFRDecompiler implements LoomDecompiler {
@Override
public void decompile(Path compiledJar, Path sourcesDestination, Path linemapDestination, DecompilationMetadata metaData) {
final String path = compiledJar.toAbsolutePath().toString();
- final Options options = OptionsImpl.getFactory().create(DECOMPILE_OPTIONS);
+ final Map<String, String> allOptions = new HashMap<>(DECOMPILE_OPTIONS);
+ allOptions.putAll(metaData.options());
+
+ final Options options = OptionsImpl.getFactory().create(allOptions);
ClassFileSourceImpl classFileSource = new ClassFileSourceImpl(options);
@@ -138,7 +142,7 @@ public class LoomCFRDecompiler implements LoomDecompiler {
decompiler.decompile(Paths.get("input.jar"),
Paths.get("output-sources.jar"),
lineMap,
- new DecompilationMetadata(4, null, Collections.emptyList(), null)
+ new DecompilationMetadata(4, null, Collections.emptyList(), null, Collections.emptyMap())
);
LineNumberRemapper lineNumberRemapper = new LineNumberRemapper();
diff --git a/src/main/java/net/fabricmc/loom/decompilers/fernflower/FabricFernFlowerDecompiler.java b/src/main/java/net/fabricmc/loom/decompilers/fernflower/FabricFernFlowerDecompiler.java
index c3009448..9ad8111e 100644
--- a/src/main/java/net/fabricmc/loom/decompilers/fernflower/FabricFernFlowerDecompiler.java
+++ b/src/main/java/net/fabricmc/loom/decompilers/fernflower/FabricFernFlowerDecompiler.java
@@ -25,6 +25,7 @@
package net.fabricmc.loom.decompilers.fernflower;
import java.nio.file.Path;
+import java.util.HashMap;
import java.util.Map;
import org.jetbrains.java.decompiler.main.Fernflower;
@@ -38,21 +39,25 @@ import net.fabricmc.loom.api.decompilers.LoomDecompiler;
public final class FabricFernFlowerDecompiler implements LoomDecompiler {
@Override
public String name() {
- return "FabricFlower"; // Or something else?
+ return "FernFlower";
}
@Override
public void decompile(Path compiledJar, Path sourcesDestination, Path linemapDestination, DecompilationMetadata metaData) {
- Map<String, Object> options = Map.of(
- IFernflowerPreferences.DECOMPILE_GENERIC_SIGNATURES, "1",
- IFernflowerPreferences.BYTECODE_SOURCE_MAPPING, "1",
- IFernflowerPreferences.REMOVE_SYNTHETIC, "1",
- IFernflowerPreferences.LOG_LEVEL, "trace",
- IFernflowerPreferences.THREADS, String.valueOf(metaData.numberOfThreads()),
- IFernflowerPreferences.INDENT_STRING, "\t",
- IFabricJavadocProvider.PROPERTY_NAME, new TinyJavadocProvider(metaData.javaDocs().toFile())
+ final Map<String, Object> options = new HashMap<>(
+ Map.of(
+ IFernflowerPreferences.DECOMPILE_GENERIC_SIGNATURES, "1",
+ IFernflowerPreferences.BYTECODE_SOURCE_MAPPING, "1",
+ IFernflowerPreferences.REMOVE_SYNTHETIC, "1",
+ IFernflowerPreferences.LOG_LEVEL, "trace",
+ IFernflowerPreferences.THREADS, String.valueOf(metaData.numberOfThreads()),
+ IFernflowerPreferences.INDENT_STRING, "\t",
+ IFabricJavadocProvider.PROPERTY_NAME, new TinyJavadocProvider(metaData.javaDocs().toFile())
+ )
);
+ options.putAll(metaData.options());
+
IResultSaver saver = new ThreadSafeResultSaver(sourcesDestination::toFile, linemapDestination::toFile);
Fernflower ff = new Fernflower(FernFlowerUtils::getBytecode, saver, options, new FernflowerLogger(metaData.logger()));
diff --git a/src/main/java/net/fabricmc/loom/task/GenerateSourcesTask.java b/src/main/java/net/fabricmc/loom/task/GenerateSourcesTask.java
index c8057ff1..9a127d86 100644
--- a/src/main/java/net/fabricmc/loom/task/GenerateSourcesTask.java
+++ b/src/main/java/net/fabricmc/loom/task/GenerateSourcesTask.java
@@ -43,6 +43,7 @@ import javax.inject.Inject;
import org.gradle.api.file.ConfigurableFileCollection;
import org.gradle.api.file.RegularFileProperty;
+import org.gradle.api.provider.MapProperty;
import org.gradle.api.provider.Property;
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.InputFile;
@@ -83,6 +84,9 @@ public abstract class GenerateSourcesTask extends AbstractLoomTask {
@Input
public abstract Property<Long> getMaxMemory();
+ @Input
+ public abstract MapProperty<String, String> getOptions();
+
@Inject
public abstract WorkerExecutor getWorkerExecutor();
@@ -98,6 +102,7 @@ public abstract class GenerateSourcesTask extends AbstractLoomTask {
getOutputs().upToDateWhen((o) -> false);
getMaxMemory().convention(4096L).finalizeValueOnRead();
+ getOptions().finalizeValueOnRead();
}
@TaskAction
@@ -134,6 +139,8 @@ public abstract class GenerateSourcesTask extends AbstractLoomTask {
workQueue.submit(DecompileAction.class, params -> {
params.getDecompilerClass().set(decompiler.getClass().getCanonicalName());
+ params.getOptions().set(getOptions());
+
params.getInputJar().set(getInputJar());
params.getRuntimeJar().set(getExtension().getMappingsProvider().mappedProvider.getMappedJar());
params.getSourcesDestinationJar().set(getMappedJarFileWithSuffix("-sources.jar"));
@@ -182,6 +189,8 @@ public abstract class GenerateSourcesTask extends AbstractLoomTask {
public interface DecompileParams extends WorkParameters {
Property<String> getDecompilerClass();
+ MapProperty<String, String> getOptions();
+
RegularFileProperty getInputJar();
RegularFileProperty getRuntimeJar();
RegularFileProperty getSourcesDestinationJar();
@@ -231,7 +240,8 @@ public abstract class GenerateSourcesTask extends AbstractLoomTask {
Runtime.getRuntime().availableProcessors(),
getParameters().getMappings().get().getAsFile().toPath(),
getLibraries(),
- logger
+ logger,
+ getParameters().getOptions().get()
);
decompiler.decompile(
diff --git a/src/main/java/net/fabricmc/loom/task/LoomTasks.java b/src/main/java/net/fabricmc/loom/task/LoomTasks.java
index 8847741e..e914046f 100644
--- a/src/main/java/net/fabricmc/loom/task/LoomTasks.java
+++ b/src/main/java/net/fabricmc/loom/task/LoomTasks.java
@@ -34,7 +34,6 @@ import net.fabricmc.loom.LoomGradleExtension;
import net.fabricmc.loom.api.decompilers.LoomDecompiler;
import net.fabricmc.loom.configuration.ide.RunConfigSettings;
import net.fabricmc.loom.configuration.providers.mappings.MappingsProviderImpl;
-import net.fabricmc.loom.decompilers.fernflower.FabricFernFlowerDecompiler;
import net.fabricmc.loom.util.Constants;
public final class LoomTasks {
@@ -129,7 +128,7 @@ public final class LoomTasks {
return;
}
- File inputJar = mappingsProvider.mappedProvider.getMappedJar();
+ File mappedJar = mappingsProvider.mappedProvider.getMappedJar();
if (mappingsProvider.hasUnpickDefinitions()) {
File outputJar = mappingsProvider.mappedProvider.getUnpickedJar();
@@ -140,21 +139,33 @@ public final class LoomTasks {
unpickJarTask.getOutputJar().set(outputJar);
});
- inputJar = outputJar;
+ mappedJar = outputJar;
}
+ final File inputJar = mappedJar;
+
extension.getGameDecompilers().finalizeValue();
for (LoomDecompiler decompiler : extension.getGameDecompilers().get()) {
- String taskName = decompiler instanceof FabricFernFlowerDecompiler ? "genSources" : "genSourcesWith" + decompiler.name();
- // decompiler will be passed to the constructor of GenerateSourcesTask
- GenerateSourcesTask generateSourcesTask = tasks.register(taskName, GenerateSourcesTask.class, decompiler).get();
- generateSourcesTask.getInputJar().set(inputJar);
-
- if (mappingsProvider.hasUnpickDefinitions()) {
- generateSourcesTask.dependsOn(tasks.getByName("unpickJar"));
- }
+ String taskName = "genSourcesWith" + decompiler.name();
+ // Decompiler will be passed to the constructor of GenerateSourcesTask
+ tasks.register(taskName, GenerateSourcesTask.class, decompiler).configure(task -> {
+ task.setDescription("Decompile minecraft using %s.".formatted(decompiler.name()));
+ task.setGroup(Constants.TaskGroup.FABRIC);
+ task.getInputJar().set(inputJar);
+
+ if (mappingsProvider.hasUnpickDefinitions()) {
+ task.dependsOn(tasks.getByName("unpickJar"));
+ }
+ });
}
+
+ tasks.register("genSources", task -> {
+ task.setDescription("Decompile minecraft using the default decompiler.");
+ task.setGroup(Constants.TaskGroup.FABRIC);
+
+ task.dependsOn(project.getTasks().getByName("genSourcesWithCfr"));
+ });
});
}
}
diff --git a/src/test/groovy/net/fabricmc/loom/test/integration/DecompileTest.groovy b/src/test/groovy/net/fabricmc/loom/test/integration/DecompileTest.groovy
index daa2a511..d2ed4b26 100644
--- a/src/test/groovy/net/fabricmc/loom/test/integration/DecompileTest.groovy
+++ b/src/test/groovy/net/fabricmc/loom/test/integration/DecompileTest.groovy
@@ -45,8 +45,8 @@ class DecompileTest extends Specification implements GradleProjectTestTrait {
where:
decompiler | task | version
- 'fernflower' | "genSources" | DEFAULT_GRADLE
- 'fernflower' | "genSources" | PRE_RELEASE_GRADLE
+ 'fernflower' | "genSourcesWithFernFlower" | DEFAULT_GRADLE
+ 'fernflower' | "genSourcesWithFernFlower" | PRE_RELEASE_GRADLE
'cfr' | "genSourcesWithCfr" | DEFAULT_GRADLE
'cfr' | "genSourcesWithCfr" | PRE_RELEASE_GRADLE
}