Add architectury decompiler (#59)

* Add architectury decompiler

Signed-off-by: shedaniel <daniel@shedaniel.me>

* Perhaps let's not include javaexec helpers

Signed-off-by: shedaniel <daniel@shedaniel.me>

* Fix checkstyle and resolve reviews

Signed-off-by: shedaniel <daniel@shedaniel.me>
This commit is contained in:
shedaniel
2021-12-04 03:55:47 +08:00
committed by GitHub
parent 537057bb61
commit 6a18e007a7
11 changed files with 163 additions and 13 deletions

View File

@@ -40,6 +40,7 @@ import org.gradle.api.publish.maven.MavenPublication;
import org.jetbrains.annotations.ApiStatus;
import net.fabricmc.loom.api.decompilers.LoomDecompiler;
import net.fabricmc.loom.api.decompilers.architectury.ArchitecturyLoomDecompiler;
import net.fabricmc.loom.api.mappings.layered.spec.LayeredMappingSpecBuilder;
import net.fabricmc.loom.configuration.ide.RunConfig;
import net.fabricmc.loom.configuration.ide.RunConfigSettings;
@@ -227,6 +228,12 @@ public interface LoomGradleExtensionAPI {
// ===================
// Architectury Loom
// ===================
ListProperty<ArchitecturyLoomDecompiler> getArchGameDecompilers();
default void addArchDecompiler(ArchitecturyLoomDecompiler decompiler) {
getArchGameDecompilers().add(decompiler);
}
void silentMojangMappingsLicense();
boolean isSilentMojangMappingsLicenseEnabled();

View File

@@ -0,0 +1,35 @@
/*
* This file is part of fabric-loom, licensed under the MIT License (MIT).
*
* Copyright (c) 2021 FabricMC
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package net.fabricmc.loom.api.decompilers.architectury;
import org.gradle.api.logging.Logger;
import net.fabricmc.loom.task.GenerateSourcesTask;
public interface ArchitecturyLoomDecompiler {
String name();
void decompile(Logger logger, GenerateSourcesTask.DecompileParams params);
}

View File

@@ -350,7 +350,7 @@ public class MinecraftProviderImpl extends DependencyProvider implements Minecra
if (isNewerThan21w39a != null) {
return isNewerThan21w39a;
}
return isNewerThan21w39a = ZipUtils.contains(minecraftServerJar.toPath(), "META-INF/versions.list");
}

View File

@@ -207,10 +207,10 @@ public class McpConfigProvider extends DependencyProvider {
List<String> args = this.args.stream()
.map(str -> {
return switch (str) {
case "{input}" -> input.toAbsolutePath().toString();
case "{output}" -> output.toAbsolutePath().toString();
case "{mappings}" -> mappings.toAbsolutePath().toString();
default -> str;
case "{input}" -> input.toAbsolutePath().toString();
case "{output}" -> output.toAbsolutePath().toString();
case "{mappings}" -> mappings.toAbsolutePath().toString();
default -> str;
};
})
.collect(Collectors.toList());

View File

@@ -87,7 +87,6 @@ import org.objectweb.asm.tree.ClassNode;
import net.fabricmc.loom.configuration.DependencyProvider;
import net.fabricmc.loom.configuration.providers.MinecraftProviderImpl;
import net.fabricmc.loom.extension.LoomGradleExtensionImpl;
import net.fabricmc.loom.util.Constants;
import net.fabricmc.loom.util.DependencyDownloader;
import net.fabricmc.loom.util.FileSystemUtil;

View File

@@ -47,6 +47,7 @@ import net.fabricmc.loom.api.ForgeExtensionAPI;
import net.fabricmc.loom.api.LoomGradleExtensionAPI;
import net.fabricmc.loom.api.MixinExtensionAPI;
import net.fabricmc.loom.api.decompilers.LoomDecompiler;
import net.fabricmc.loom.api.decompilers.architectury.ArchitecturyLoomDecompiler;
import net.fabricmc.loom.api.mappings.layered.spec.LayeredMappingSpecBuilder;
import net.fabricmc.loom.configuration.ide.RunConfig;
import net.fabricmc.loom.configuration.ide.RunConfigSettings;
@@ -86,6 +87,7 @@ public abstract class LoomGradleExtensionApiImpl implements LoomGradleExtensionA
// ===================
// Architectury Loom
// ===================
private final ListProperty<ArchitecturyLoomDecompiler> archDecompilers;
private Provider<ModPlatform> platform;
private boolean silentMojangMappingsLicense = false;
public Boolean generateSrgTiny = null;
@@ -136,6 +138,8 @@ public abstract class LoomGradleExtensionApiImpl implements LoomGradleExtensionA
})::get);
this.launchConfigs = project.container(LaunchProviderSettings.class,
baseName -> new LaunchProviderSettings(project, baseName));
this.archDecompilers = project.getObjects().listProperty(ArchitecturyLoomDecompiler.class)
.empty();
}
@Override
@@ -286,6 +290,11 @@ public abstract class LoomGradleExtensionApiImpl implements LoomGradleExtensionA
action.execute(getForge());
}
@Override
public ListProperty<ArchitecturyLoomDecompiler> getArchGameDecompilers() {
return archDecompilers;
}
// This is here to ensure that LoomGradleExtensionApiImpl compiles without any unimplemented methods
private final class EnsureCompile extends LoomGradleExtensionApiImpl {
private EnsureCompile() {

View File

@@ -41,6 +41,7 @@ import net.fabricmc.loom.api.ForgeExtensionAPI;
import net.fabricmc.loom.api.LoomGradleExtensionAPI;
import net.fabricmc.loom.api.MixinExtensionAPI;
import net.fabricmc.loom.api.decompilers.LoomDecompiler;
import net.fabricmc.loom.api.decompilers.architectury.ArchitecturyLoomDecompiler;
import net.fabricmc.loom.api.mappings.layered.spec.LayeredMappingSpecBuilder;
import net.fabricmc.loom.configuration.ide.RunConfig;
import net.fabricmc.loom.configuration.ide.RunConfigSettings;
@@ -171,6 +172,12 @@ public class MinecraftGradleExtension implements LoomGradleExtensionAPI {
return parent.getIntermediaryUrl();
}
@Override
public ListProperty<ArchitecturyLoomDecompiler> getArchGameDecompilers() {
reportDeprecation();
return parent.getArchGameDecompilers();
}
@Override
public void silentMojangMappingsLicense() {
reportDeprecation();

View File

@@ -0,0 +1,79 @@
/*
* This file is part of fabric-loom, licensed under the MIT License (MIT).
*
* Copyright (c) 2021 FabricMC
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package net.fabricmc.loom.task;
import java.io.IOException;
import javax.inject.Inject;
import org.gradle.api.file.RegularFileProperty;
import org.gradle.api.provider.MapProperty;
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.InputFile;
import org.gradle.api.tasks.TaskAction;
import net.fabricmc.loom.api.decompilers.architectury.ArchitecturyLoomDecompiler;
import net.fabricmc.loom.util.Constants;
import net.fabricmc.loom.util.OperatingSystem;
public abstract class ArchitecturyGenerateSourcesTask extends AbstractLoomTask {
private final ArchitecturyLoomDecompiler decompiler;
@InputFile
public abstract RegularFileProperty getInputJar();
@Input
public abstract MapProperty<String, String> getOptions();
@Inject
public ArchitecturyGenerateSourcesTask(ArchitecturyLoomDecompiler decompiler) {
this.decompiler = decompiler;
getOutputs().upToDateWhen((o) -> false);
getOptions().finalizeValueOnRead();
}
@TaskAction
public void run() throws IOException {
if (!OperatingSystem.is64Bit()) {
throw new UnsupportedOperationException("GenSources task requires a 64bit JVM to run due to the memory requirements.");
}
GenerateSourcesTask.DecompileParams params = getProject().getObjects().newInstance(GenerateSourcesTask.DecompileParams.class);
// TODO: Need a good way to not keep a duplicated code for this
params.getOptions().set(getOptions());
params.getInputJar().set(getInputJar());
params.getRuntimeJar().set(getExtension().getMappingsProvider().mappedProvider.getMappedJar());
params.getSourcesDestinationJar().set(GenerateSourcesTask.getMappedJarFileWithSuffix(getProject(), "-sources.jar"));
params.getLinemap().set(GenerateSourcesTask.getMappedJarFileWithSuffix(getProject(), "-sources.lmap"));
params.getLinemapJar().set(GenerateSourcesTask.getMappedJarFileWithSuffix(getProject(), "-linemapped.jar"));
params.getMappings().set(GenerateSourcesTask.getMappings(getProject(), getExtension()).toFile());
params.getClassPath().setFrom(getProject().getConfigurations().getByName(Constants.Configurations.MINECRAFT_DEPENDENCIES));
decompiler.decompile(getLogger(), params);
}
}

View File

@@ -147,7 +147,7 @@ public abstract class GenerateSourcesTask extends AbstractLoomTask {
params.getSourcesDestinationJar().set(getMappedJarFileWithSuffix("-sources.jar"));
params.getLinemap().set(getMappedJarFileWithSuffix("-sources.lmap"));
params.getLinemapJar().set(getMappedJarFileWithSuffix("-linemapped.jar"));
params.getMappings().set(getMappings().toFile());
params.getMappings().set(getMappings(getProject(), getExtension()).toFile());
if (ipcPath != null) {
params.getIPCPath().set(ipcPath.toFile());
@@ -308,11 +308,11 @@ public abstract class GenerateSourcesTask extends AbstractLoomTask {
return new File(path.substring(0, path.length() - 4) + suffix);
}
private Path getMappings() {
Path baseMappings = getExtension().isForge() ? getExtension().getMappingsProvider().tinyMappingsWithSrg : getExtension().getMappingsProvider().tinyMappings;
static Path getMappings(Project project, LoomGradleExtension extension) {
Path baseMappings = extension.isForge() ? extension.getMappingsProvider().tinyMappingsWithSrg : extension.getMappingsProvider().tinyMappings;
if (getExtension().getEnableTransitiveAccessWideners().get()) {
List<AccessWidenerFile> accessWideners = getExtension().getTransitiveAccessWideners();
if (extension.getEnableTransitiveAccessWideners().get()) {
List<AccessWidenerFile> accessWideners = extension.getTransitiveAccessWideners();
if (accessWideners.isEmpty()) {
return baseMappings;
@@ -326,7 +326,7 @@ public abstract class GenerateSourcesTask extends AbstractLoomTask {
throw new RuntimeException("Failed to create temp file", e);
}
TransitiveAccessWidenerMappingsProcessor.process(baseMappings, outputMappings, accessWideners, getProject().getLogger());
TransitiveAccessWidenerMappingsProcessor.process(baseMappings, outputMappings, accessWideners, project.getLogger());
return outputMappings;
}

View File

@@ -34,6 +34,7 @@ import org.gradle.api.tasks.TaskContainer;
import net.fabricmc.loom.LoomGradleExtension;
import net.fabricmc.loom.api.decompilers.LoomDecompiler;
import net.fabricmc.loom.api.decompilers.architectury.ArchitecturyLoomDecompiler;
import net.fabricmc.loom.configuration.ide.RunConfigSettings;
import net.fabricmc.loom.configuration.ide.SetupIntelijRunConfigs;
import net.fabricmc.loom.configuration.providers.mappings.MappingsProviderImpl;
@@ -188,6 +189,20 @@ public final class LoomTasks {
});
}
for (ArchitecturyLoomDecompiler decompiler : extension.getArchGameDecompilers().get()) {
String taskName = "genSourcesWith" + decompiler.name();
// Decompiler will be passed to the constructor of ArchitecturyGenerateSourcesTask
tasks.register(taskName, ArchitecturyGenerateSourcesTask.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);

View File

@@ -37,7 +37,6 @@ import java.util.stream.Collectors;
import com.google.common.base.Stopwatch;
import org.apache.commons.io.output.NullOutputStream;
import org.gradle.api.Project;
import org.gradle.api.file.FileCollection;
import org.gradle.api.logging.LogLevel;
import org.gradle.api.logging.configuration.ShowStacktrace;