Add architectury decompiler

Signed-off-by: shedaniel <daniel@shedaniel.me>
This commit is contained in:
shedaniel
2021-12-02 19:55:00 +08:00
parent 537057bb61
commit ed331c87a6
9 changed files with 190 additions and 7 deletions

View File

@@ -119,6 +119,8 @@ public interface LoomGradleExtension extends LoomGradleExtensionAPI {
// ===================
// Architectury Loom
// ===================
Project getProject();
default PatchProvider getPatchProvider() {
return getDependencyManager().getProvider(PatchProvider.class);
}

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,61 @@
/*
* 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.Action;
import org.gradle.api.Project;
import org.gradle.api.artifacts.ConfigurationContainer;
import org.gradle.api.artifacts.dsl.DependencyHandler;
import org.gradle.api.file.FileCollection;
import org.gradle.api.logging.Logger;
import org.gradle.process.ExecResult;
import org.gradle.process.JavaExecSpec;
import net.fabricmc.loom.task.GenerateSourcesTask;
public interface ArchitecturyLoomDecompiler {
String name();
void decompile(Logger logger, GenerateSourcesTask.DecompileParams params);
static ExecResult javaexec(Project project, Action<? super JavaExecSpec> action) {
return project.javaexec(spec -> {
spec.classpath(getClasspath(project));
action.execute(spec);
});
}
private static Object getClasspath(Project project) {
return getRuntimeClasspath(project.getRootProject().getPlugins().hasPlugin("fabric-loom") ? project.getRootProject() : project);
}
private static FileCollection getRuntimeClasspath(Project project) {
ConfigurationContainer configurations = project.getBuildscript().getConfigurations();
DependencyHandler handler = project.getDependencies();
return configurations.getByName("classpath")
.plus(project.getRootProject().getBuildscript().getConfigurations().getByName("classpath"))
.plus(configurations.detachedConfiguration(handler.localGroovy()));
}
}

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
// ===================
protected 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

@@ -87,7 +87,7 @@ public class LoomGradleExtensionImpl extends LoomGradleExtensionApiImpl implemen
}
@Override
protected Project getProject() {
public Project getProject() {
return project;
}

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

@@ -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(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;
public static Path getMappings(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, extension.getProject().getLogger());
return outputMappings;
}

View File

@@ -34,9 +34,11 @@ 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;
import net.fabricmc.loom.task.architectury.ArchitecturyGenerateSourcesTask;
import net.fabricmc.loom.util.Constants;
public final class LoomTasks {
@@ -188,6 +190,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

@@ -0,0 +1,81 @@
/*
* 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.architectury;
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.task.AbstractLoomTask;
import net.fabricmc.loom.task.GenerateSourcesTask;
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(getExtension()).toFile());
params.getClassPath().setFrom(getProject().getConfigurations().getByName(Constants.Configurations.MINECRAFT_DEPENDENCIES));
decompiler.decompile(getLogger(), params);
}
}