mirror of
https://github.com/architectury/architectury-loom.git
synced 2026-04-01 21:17:46 -05:00
a
This commit is contained in:
27
build.gradle
27
build.gradle
@@ -35,7 +35,6 @@ if (!isSnapshot) {
|
||||
logger.lifecycle(":building plugin v${version}")
|
||||
|
||||
configurations {
|
||||
shadowArchitectury
|
||||
forgeInjectShadow
|
||||
forgeInjectCompileClasspath.extendsFrom(forgeInjectShadow)
|
||||
forgeInjectRuntimeClasspath.extendsFrom(forgeInjectShadow)
|
||||
@@ -48,8 +47,9 @@ sourceSets {
|
||||
repositories {
|
||||
maven { url "https://maven.fabricmc.net/" }
|
||||
maven { url "https://maven.minecraftforge.net/" }
|
||||
maven { url "https://maven.shedaniel.me/" }
|
||||
maven { url "https://maven.architectury.dev/" }
|
||||
mavenCentral()
|
||||
mavenLocal()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
@@ -77,10 +77,7 @@ dependencies {
|
||||
}
|
||||
|
||||
// tinyfile management
|
||||
compileOnly ('net.fabricmc:tiny-remapper:0.3.2-architectury.7')
|
||||
shadowArchitectury ('net.fabricmc:tiny-remapper:0.3.2-architectury.7') {
|
||||
transitive = false
|
||||
}
|
||||
implementation ('dev.architectury:tiny-remapper:1.0.0')
|
||||
implementation ('net.fabricmc:tiny-mappings-parser:0.3.0+build.17')
|
||||
|
||||
implementation 'net.fabricmc:access-widener:1.0.0'
|
||||
@@ -89,10 +86,7 @@ dependencies {
|
||||
transitive = false
|
||||
}
|
||||
implementation ('org.cadixdev:lorenz-io-proguard:0.5.6')
|
||||
compileOnly "me.shedaniel.architectury:refmap-remapper:1.0.4"
|
||||
shadowArchitectury ("me.shedaniel.architectury:refmap-remapper:1.0.4") {
|
||||
transitive = false
|
||||
}
|
||||
implementation "dev.architectury:refmap-remapper:1.0.5"
|
||||
|
||||
// decompilers
|
||||
implementation ('net.fabricmc:fabric-fernflower:1.3.0')
|
||||
@@ -110,7 +104,7 @@ dependencies {
|
||||
implementation ('org.cadixdev:lorenz-asm:0.5.3')
|
||||
implementation ('net.minecraftforge:accesstransformers:2.2.0')
|
||||
implementation ('de.oceanlabs.mcp:mcinjector:3.8.0')
|
||||
implementation ('net.md-5:SpecialSource:1.8.3')
|
||||
implementation ('com.opencsv:opencsv:5.4')
|
||||
|
||||
// Forge injection
|
||||
forgeInjectShadow ('net.fabricmc:tiny-mappings-parser:0.2.2.14')
|
||||
@@ -141,17 +135,10 @@ jar {
|
||||
classifier 'jar'
|
||||
}
|
||||
|
||||
shadowJar {
|
||||
relocate "net.fabricmc.tinyremapper", "me.shedaniel.architectury.loom.shadowed.impl.net.fabricmc.tinyremapper"
|
||||
relocate "me.shedaniel.architectury.refmapremapper", "me.shedaniel.architectury.loom.shadowed.impl.me.shedaniel.architectury.refmapremapper"
|
||||
configurations = [project.configurations.shadowArchitectury]
|
||||
classifier "shadow"
|
||||
}
|
||||
|
||||
task mainJar(type: Jar, dependsOn: shadowJar) {
|
||||
task mainJar(type: Jar, dependsOn: jar) {
|
||||
dependsOn forgeInjectJar
|
||||
|
||||
from zipTree(shadowJar.archivePath)
|
||||
from zipTree(jar.archivePath)
|
||||
from(forgeInjectJar.outputs) {
|
||||
into "inject"
|
||||
rename { "injection.jar" }
|
||||
|
||||
@@ -35,16 +35,16 @@ import java.util.Set;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
import dev.architectury.tinyremapper.IMappingProvider;
|
||||
import dev.architectury.tinyremapper.InputTag;
|
||||
import dev.architectury.tinyremapper.OutputConsumerPath;
|
||||
import dev.architectury.tinyremapper.TinyRemapper;
|
||||
import org.gradle.api.Action;
|
||||
import org.gradle.api.Project;
|
||||
import org.objectweb.asm.commons.Remapper;
|
||||
|
||||
import net.fabricmc.loom.util.LoggerFilter;
|
||||
import net.fabricmc.stitch.util.Pair;
|
||||
import net.fabricmc.tinyremapper.IMappingProvider;
|
||||
import net.fabricmc.tinyremapper.InputTag;
|
||||
import net.fabricmc.tinyremapper.OutputConsumerPath;
|
||||
import net.fabricmc.tinyremapper.TinyRemapper;
|
||||
|
||||
public class JarRemapper {
|
||||
private final List<IMappingProvider> mappingProviders = new ArrayList<>();
|
||||
|
||||
@@ -38,6 +38,7 @@ import java.util.zip.ZipEntry;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonObject;
|
||||
import dev.architectury.tinyremapper.TinyRemapper;
|
||||
import org.gradle.api.Project;
|
||||
import org.objectweb.asm.ClassReader;
|
||||
import org.objectweb.asm.ClassVisitor;
|
||||
@@ -58,7 +59,6 @@ import net.fabricmc.loom.configuration.processors.JarProcessor;
|
||||
import net.fabricmc.loom.configuration.providers.minecraft.MinecraftMappedProvider;
|
||||
import net.fabricmc.loom.util.Checksum;
|
||||
import net.fabricmc.loom.util.Constants;
|
||||
import net.fabricmc.tinyremapper.TinyRemapper;
|
||||
|
||||
public class AccessWidenerJarProcessor implements JarProcessor {
|
||||
private AccessWidener accessWidener = new AccessWidener();
|
||||
|
||||
@@ -45,7 +45,11 @@ import java.util.jar.Manifest;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.zip.ZipEntry;
|
||||
|
||||
import com.google.common.base.Stopwatch;
|
||||
import com.google.gson.JsonObject;
|
||||
import dev.architectury.tinyremapper.InputTag;
|
||||
import dev.architectury.tinyremapper.OutputConsumerPath;
|
||||
import dev.architectury.tinyremapper.TinyRemapper;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.gradle.api.Project;
|
||||
import org.objectweb.asm.commons.Remapper;
|
||||
@@ -69,9 +73,6 @@ import net.fabricmc.loom.util.TinyRemapperMappingsHelper;
|
||||
import net.fabricmc.loom.util.srg.AtRemapper;
|
||||
import net.fabricmc.loom.util.srg.CoreModClassRemapper;
|
||||
import net.fabricmc.mapping.tree.TinyTree;
|
||||
import net.fabricmc.tinyremapper.InputTag;
|
||||
import net.fabricmc.tinyremapper.OutputConsumerPath;
|
||||
import net.fabricmc.tinyremapper.TinyRemapper;
|
||||
|
||||
public class ModProcessor {
|
||||
public static void processMods(Project project, List<ModDependencyInfo> processList) throws IOException {
|
||||
@@ -150,6 +151,7 @@ public class ModProcessor {
|
||||
|
||||
List<ModDependencyInfo> remapList = processList.stream().filter(ModDependencyInfo::requiresRemapping).collect(Collectors.toList());
|
||||
|
||||
Stopwatch stopwatch = Stopwatch.createStarted();
|
||||
project.getLogger().lifecycle(":remapping " + remapList.size() + " mods (TinyRemapper, " + fromM + " -> " + toM + ")");
|
||||
|
||||
TinyTree mappings = extension.isForge() ? mappingsProvider.getMappingsWithSrg() : mappingsProvider.getMappings();
|
||||
@@ -201,6 +203,7 @@ public class ModProcessor {
|
||||
}
|
||||
|
||||
remapper.finish();
|
||||
project.getLogger().lifecycle(":remapped " + remapList.size() + " mods (TinyRemapper, " + fromM + " -> " + toM + ") in " + stopwatch.stop());
|
||||
|
||||
for (ModDependencyInfo info : remapList) {
|
||||
outputConsumerMap.get(info).close();
|
||||
|
||||
@@ -55,6 +55,8 @@ import com.google.common.base.Stopwatch;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.gson.JsonParser;
|
||||
import de.oceanlabs.mcp.mcinjector.adaptors.ParameterAnnotationFixer;
|
||||
import dev.architectury.tinyremapper.OutputConsumerPath;
|
||||
import dev.architectury.tinyremapper.TinyRemapper;
|
||||
import net.minecraftforge.accesstransformer.AccessTransformerEngine;
|
||||
import net.minecraftforge.accesstransformer.TransformerProcessor;
|
||||
import net.minecraftforge.accesstransformer.parser.AccessTransformerList;
|
||||
@@ -88,8 +90,6 @@ import net.fabricmc.loom.util.function.FsPathConsumer;
|
||||
import net.fabricmc.loom.util.srg.InnerClassRemapper;
|
||||
import net.fabricmc.loom.util.srg.SpecialSourceExecutor;
|
||||
import net.fabricmc.mapping.tree.TinyTree;
|
||||
import net.fabricmc.tinyremapper.OutputConsumerPath;
|
||||
import net.fabricmc.tinyremapper.TinyRemapper;
|
||||
|
||||
public class MinecraftPatchedProvider extends DependencyProvider {
|
||||
private final MappingsProvider mappingsProvider;
|
||||
|
||||
@@ -42,13 +42,14 @@ import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.jar.Attributes;
|
||||
import java.util.jar.Manifest;
|
||||
|
||||
import com.google.common.base.Stopwatch;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import dev.architectury.tinyremapper.IMappingProvider;
|
||||
import dev.architectury.tinyremapper.TinyRemapper;
|
||||
import org.gradle.api.Project;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.objectweb.asm.ClassReader;
|
||||
@@ -70,8 +71,6 @@ import net.fabricmc.loom.util.srg.AtRemapper;
|
||||
import net.fabricmc.loom.util.srg.CoreModClassRemapper;
|
||||
import net.fabricmc.loom.util.srg.InnerClassRemapper;
|
||||
import net.fabricmc.mapping.tree.TinyTree;
|
||||
import net.fabricmc.tinyremapper.IMappingProvider;
|
||||
import net.fabricmc.tinyremapper.TinyRemapper;
|
||||
|
||||
public class MinecraftMappedProvider extends DependencyProvider {
|
||||
private static final Map<String, String> JSR_TO_JETBRAINS = new ImmutableMap.Builder<String, String>()
|
||||
@@ -158,9 +157,37 @@ public class MinecraftMappedProvider extends DependencyProvider {
|
||||
remapper.prepareClasses();
|
||||
remapper.readInputs(input);
|
||||
|
||||
Files.copy(input, outputMapped, StandardCopyOption.REPLACE_EXISTING);
|
||||
Path tmpAssets = Files.createTempFile("tmpAssets", null);
|
||||
Files.deleteIfExists(tmpAssets);
|
||||
tmpAssets.toFile().deleteOnExit();
|
||||
|
||||
try (FileSystemUtil.FileSystemDelegate inputFs = FileSystemUtil.getJarFileSystem(input, false)) {
|
||||
ThreadingUtils.TaskCompleter taskCompleter = ThreadingUtils.taskCompleter();
|
||||
|
||||
try (FileSystemUtil.FileSystemDelegate assetsFs = FileSystemUtil.getJarFileSystem(tmpAssets, true)) {
|
||||
for (Path path : (Iterable<? extends Path>) Files.walk(inputFs.get().getPath("/"))::iterator) {
|
||||
if (Files.isRegularFile(path) && !path.getFileName().toString().endsWith(".class")) {
|
||||
Path p = assetsFs.get().getPath(path.toString());
|
||||
|
||||
if (p.getParent() != null) {
|
||||
Files.createDirectories(p.getParent());
|
||||
}
|
||||
|
||||
taskCompleter.add(() -> {
|
||||
Files.copy(path, p);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
taskCompleter.complete();
|
||||
}
|
||||
}
|
||||
|
||||
Files.copy(tmpAssets, outputMapped, StandardCopyOption.REPLACE_EXISTING);
|
||||
FileSystemUtil.FileSystemDelegate systemMapped = FileSystemUtil.getJarFileSystem(outputMapped, true);
|
||||
ThreadingUtils.TaskCompleter taskCompleter = ThreadingUtils.taskCompleter();
|
||||
ThreadingUtils.TaskCompleter mappedRemapper = ThreadingUtils.taskCompleter().onComplete(stopwatch -> {
|
||||
getProject().getLogger().lifecycle(":remapped minecraft (AsmRemapper, intermediary -> named) in " + stopwatch);
|
||||
});
|
||||
MappingsCompiled compiledMapped = new MappingsCompiled(getMappings(input, "intermediary", "named"));
|
||||
|
||||
for (String toM : getExtension().isForge() ? Arrays.asList("intermediary", "srg") : Collections.singletonList("intermediary")) {
|
||||
@@ -169,15 +196,15 @@ public class MinecraftMappedProvider extends DependencyProvider {
|
||||
getProject().getLogger().lifecycle(":remapping minecraft (TinyRemapper, " + fromM + " -> " + toM + ")");
|
||||
|
||||
remapper.replaceMappings(getMappings(input, fromM, toM));
|
||||
OutputRemappingHandler.remap(remapper, input, output, toM.equals("intermediary") ? (path, bytes) -> {
|
||||
OutputRemappingHandler.remap(remapper, tmpAssets, output, toM.equals("intermediary") ? (path, bytes) -> {
|
||||
try {
|
||||
Path fsPath = systemMapped.get().getPath(compiledMapped.mapClass(path) + ".class");
|
||||
Path fsPath = systemMapped.get().getPath(compiledMapped.map(path) + ".class");
|
||||
|
||||
if (fsPath.getParent() != null) {
|
||||
Files.createDirectories(fsPath.getParent());
|
||||
}
|
||||
|
||||
taskCompleter.add(() -> {
|
||||
mappedRemapper.add(() -> {
|
||||
ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS);
|
||||
ClassRemapper classRemapper = new CompiledMappedClassRemapper(writer, compiledMapped);
|
||||
new ClassReader(bytes).accept(classRemapper, ClassReader.EXPAND_FRAMES);
|
||||
@@ -187,10 +214,9 @@ public class MinecraftMappedProvider extends DependencyProvider {
|
||||
} catch (IOException e) {
|
||||
throw new UncheckedIOException(e);
|
||||
}
|
||||
} : (path, bytes) -> {
|
||||
});
|
||||
} : null);
|
||||
|
||||
getProject().getLogger().info(":remapped minecraft (TinyRemapper, " + fromM + " -> " + toM + ") in " + stopwatch);
|
||||
getProject().getLogger().lifecycle(":remapped minecraft (TinyRemapper, " + fromM + " -> " + toM + ") in " + stopwatch);
|
||||
|
||||
if (getExtension().isForge() && !"srg".equals(toM)) {
|
||||
getProject().getLogger().info(":running forge finalising tasks");
|
||||
@@ -231,7 +257,7 @@ public class MinecraftMappedProvider extends DependencyProvider {
|
||||
remapper.finish();
|
||||
|
||||
getProject().getLogger().lifecycle(":remapping minecraft (AsmRemapper, intermediary -> named)");
|
||||
taskCompleter.complete();
|
||||
mappedRemapper.complete();
|
||||
|
||||
systemMapped.close();
|
||||
}
|
||||
|
||||
@@ -1,51 +1,50 @@
|
||||
package net.fabricmc.loom.configuration.providers.minecraft.tr;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import dev.architectury.tinyremapper.AsmClassRemapper;
|
||||
import org.objectweb.asm.ClassVisitor;
|
||||
import org.objectweb.asm.Label;
|
||||
import org.objectweb.asm.MethodVisitor;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
import org.objectweb.asm.commons.ClassRemapper;
|
||||
import org.objectweb.asm.commons.MethodRemapper;
|
||||
import org.objectweb.asm.commons.Remapper;
|
||||
import org.objectweb.asm.tree.MethodNode;
|
||||
|
||||
public class CompiledMappedClassRemapper extends ClassRemapper {
|
||||
private final MappingsCompiled compiled;
|
||||
private String lastMethodName;
|
||||
private String lastName;
|
||||
private MethodNode lastMethod;
|
||||
|
||||
public CompiledMappedClassRemapper(ClassVisitor classVisitor, MappingsCompiled compiled) {
|
||||
super(Opcodes.ASM9, classVisitor, new Remapper() {
|
||||
@Override
|
||||
public String map(String internalName) {
|
||||
return compiled.mapClass(internalName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String mapFieldName(String owner, String name, String descriptor) {
|
||||
return compiled.mapField(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String mapMethodName(String owner, String name, String descriptor) {
|
||||
return compiled.mapMethod(name);
|
||||
}
|
||||
});
|
||||
super(Opcodes.ASM9, classVisitor, compiled);
|
||||
|
||||
this.compiled = compiled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {
|
||||
lastName = name;
|
||||
this.compiled.lastSuperClass = superName;
|
||||
this.compiled.lastInterfaces = interfaces;
|
||||
super.visit(version, access, name, signature, superName, interfaces);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MethodVisitor visitMethod(int access, String name, String descriptor, String signature, String[] exceptions) {
|
||||
lastMethodName = name;
|
||||
lastMethod = new MethodNode(api, access, name, descriptor, signature, exceptions);
|
||||
return super.visitMethod(access, name, descriptor, signature, exceptions);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected MethodVisitor createMethodRemapper(MethodVisitor methodVisitor) {
|
||||
return new MethodRemapper(api, methodVisitor, remapper) {
|
||||
return new MethodRemapper(api, lastMethod, remapper) {
|
||||
@Override
|
||||
public void visitLocalVariable(String name, String descriptor, String signature, Label start, Label end, int index) {
|
||||
super.visitLocalVariable(compiled.mapMethodArg(lastMethodName, index, name),
|
||||
descriptor, signature, start, end, index);
|
||||
public void visitEnd() {
|
||||
lastMethod.localVariables = null;
|
||||
lastMethod.parameters = null;
|
||||
AsmClassRemapper.AsmMethodRemapper.processLocals(compiled, lastName, lastMethod, false, true, new HashMap<>());
|
||||
lastMethod.visitEnd();
|
||||
lastMethod.accept(methodVisitor);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -4,19 +4,25 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import net.fabricmc.tinyremapper.IMappingProvider;
|
||||
import com.google.common.collect.HashBasedTable;
|
||||
import com.google.common.collect.Table;
|
||||
import dev.architectury.tinyremapper.IMappingProvider;
|
||||
import dev.architectury.tinyremapper.MethodRemapperProvider;
|
||||
import org.objectweb.asm.commons.Remapper;
|
||||
|
||||
public class MappingsCompiled {
|
||||
public class MappingsCompiled extends Remapper implements MethodRemapperProvider {
|
||||
private final Map<String, String> classes;
|
||||
private final Map<String, String> fields;
|
||||
private final Map<String, String> methods;
|
||||
private final Map<String, String> methodArgs;
|
||||
private final Table<String, Integer, String> methodArgs;
|
||||
String lastSuperClass;
|
||||
String[] lastInterfaces;
|
||||
|
||||
public MappingsCompiled(Set<IMappingProvider> mappings) {
|
||||
this.classes = new HashMap<>();
|
||||
this.fields = new HashMap<>();
|
||||
this.methods = new HashMap<>();
|
||||
this.methodArgs = new HashMap<>();
|
||||
this.methodArgs = HashBasedTable.create();
|
||||
|
||||
for (IMappingProvider mapping : mappings) {
|
||||
mapping.load(new IMappingProvider.MappingAcceptor() {
|
||||
@@ -32,7 +38,7 @@ public class MappingsCompiled {
|
||||
|
||||
@Override
|
||||
public void acceptMethodArg(IMappingProvider.Member method, int lvIndex, String dstName) {
|
||||
methodArgs.put(method.name + "|" + lvIndex, dstName);
|
||||
methodArgs.put(method.owner + "|" + method.name, lvIndex, dstName);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -47,19 +53,55 @@ public class MappingsCompiled {
|
||||
}
|
||||
}
|
||||
|
||||
public String mapClass(String name) {
|
||||
@Override
|
||||
public String map(String name) {
|
||||
return classes.getOrDefault(name, name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String mapFieldName(String owner, String name, String descriptor) {
|
||||
return mapField(name);
|
||||
}
|
||||
|
||||
public String mapField(String name) {
|
||||
return fields.getOrDefault(name, name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String mapMethodName(String owner, String name, String descriptor) {
|
||||
return mapMethod(name);
|
||||
}
|
||||
|
||||
public String mapMethod(String name) {
|
||||
return methods.getOrDefault(name, name);
|
||||
}
|
||||
|
||||
public String mapMethodArg(String methodName, int lvIndex, String def) {
|
||||
return methodArgs.getOrDefault(methodName + "|" + lvIndex, def);
|
||||
public String mapMethodArg(String methodOwner, String methodName, int lvIndex, String def) {
|
||||
String arg = methodArgs.get(methodOwner + "|" + methodName, lvIndex);
|
||||
if (arg != null) return arg;
|
||||
|
||||
if (lastSuperClass != null) {
|
||||
arg = methodArgs.get(lastSuperClass + "|" + methodName, lvIndex);
|
||||
if (arg != null) return arg;
|
||||
}
|
||||
|
||||
if (lastInterfaces != null) {
|
||||
for (String lastInterface : lastInterfaces) {
|
||||
arg = methodArgs.get(lastInterface + "|" + methodName, lvIndex);
|
||||
if (arg != null) return arg;
|
||||
}
|
||||
}
|
||||
|
||||
return def;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String mapMethodVar(String methodOwner, String methodName, String methodDesc, int lvIndex, int startOpIdx, int asmIndex, String name) {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String mapMethodArg(String methodOwner, String methodName, String methodDesc, int lvIndex, String name) {
|
||||
return mapMethodArg(methodOwner, methodName, lvIndex, name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package net.fabricmc.loom.configuration.providers.minecraft.tr;
|
||||
|
||||
import org.cadixdev.mercury.Mercury;
|
||||
|
||||
public class MercuryUtils {
|
||||
public static Mercury copyMercury(Mercury mercury) {
|
||||
Mercury copy = new Mercury();
|
||||
copy.getClassPath().addAll(mercury.getClassPath());
|
||||
copy.getContext().putAll(mercury.getContext());
|
||||
copy.getProcessors().addAll(mercury.getProcessors());
|
||||
copy.setEncoding(mercury.getEncoding());
|
||||
copy.setFlexibleAnonymousClassMemberLookups(mercury.isFlexibleAnonymousClassMemberLookups());
|
||||
copy.setGracefulClasspathChecks(mercury.isGracefulClasspathChecks());
|
||||
copy.setGracefulJavadocClasspathChecks(mercury.isGracefulJavadocClasspathChecks());
|
||||
copy.setSourceCompatibility(mercury.getSourceCompatibility());
|
||||
return copy;
|
||||
}
|
||||
}
|
||||
@@ -8,19 +8,25 @@ import java.nio.file.StandardCopyOption;
|
||||
import java.nio.file.StandardOpenOption;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
import dev.architectury.tinyremapper.InputTag;
|
||||
import dev.architectury.tinyremapper.TinyRemapper;
|
||||
|
||||
import net.fabricmc.loom.util.FileSystemUtil;
|
||||
import net.fabricmc.loom.util.FileSystemUtil.FileSystemDelegate;
|
||||
import net.fabricmc.loom.util.ThreadingUtils;
|
||||
import net.fabricmc.tinyremapper.TinyRemapper;
|
||||
|
||||
public class OutputRemappingHandler {
|
||||
public static void remap(TinyRemapper remapper, Path input, Path output) throws IOException {
|
||||
remap(remapper, input, output, (path, bytes) -> {
|
||||
public static void remap(TinyRemapper remapper, Path assets, Path output) throws IOException {
|
||||
remap(remapper, assets, output, (path, bytes) -> {
|
||||
});
|
||||
}
|
||||
|
||||
public static void remap(TinyRemapper remapper, Path input, Path output, BiConsumer<String, byte[]> then) throws IOException {
|
||||
Files.copy(input, output, StandardCopyOption.REPLACE_EXISTING);
|
||||
public static void remap(TinyRemapper remapper, Path assets, Path output, BiConsumer<String, byte[]> then) throws IOException {
|
||||
remap(remapper, assets, output, then, (InputTag[]) null);
|
||||
}
|
||||
|
||||
public static void remap(TinyRemapper remapper, Path assets, Path output, BiConsumer<String, byte[]> then, InputTag... inputTags) throws IOException {
|
||||
Files.copy(assets, output, StandardCopyOption.REPLACE_EXISTING);
|
||||
|
||||
try (FileSystemDelegate system = FileSystemUtil.getJarFileSystem(output, true)) {
|
||||
ThreadingUtils.TaskCompleter taskCompleter = ThreadingUtils.taskCompleter();
|
||||
@@ -39,11 +45,13 @@ public class OutputRemappingHandler {
|
||||
Files.write(fsPath, bytes, StandardOpenOption.CREATE);
|
||||
});
|
||||
|
||||
then.accept(path, bytes);
|
||||
if (then != null) {
|
||||
then.accept(path, bytes);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new UncheckedIOException(e);
|
||||
}
|
||||
});
|
||||
}, inputTags);
|
||||
|
||||
taskCompleter.complete();
|
||||
}
|
||||
|
||||
@@ -28,10 +28,11 @@ import org.gradle.api.DefaultTask;
|
||||
import org.gradle.api.tasks.Internal;
|
||||
|
||||
import net.fabricmc.loom.LoomGradleExtension;
|
||||
import net.fabricmc.loom.util.Constants;
|
||||
|
||||
public abstract class AbstractLoomTask extends DefaultTask {
|
||||
public AbstractLoomTask() {
|
||||
setGroup("fabric");
|
||||
setGroup(Constants.TASK_CATEGORY);
|
||||
}
|
||||
|
||||
@Internal
|
||||
|
||||
@@ -35,13 +35,14 @@ import org.gradle.api.Project;
|
||||
import org.gradle.api.tasks.JavaExec;
|
||||
|
||||
import net.fabricmc.loom.configuration.ide.RunConfig;
|
||||
import net.fabricmc.loom.util.Constants;
|
||||
|
||||
public abstract class AbstractRunTask extends JavaExec {
|
||||
private final RunConfig config;
|
||||
|
||||
public AbstractRunTask(Function<Project, RunConfig> configProvider) {
|
||||
super();
|
||||
setGroup("fabric");
|
||||
setGroup(Constants.TASK_CATEGORY);
|
||||
this.config = configProvider.apply(getProject());
|
||||
|
||||
setClasspath(config.sourceSet.getRuntimeClasspath());
|
||||
|
||||
@@ -56,7 +56,6 @@ public class GenerateSourcesTask extends AbstractLoomTask {
|
||||
public GenerateSourcesTask(LoomDecompiler decompiler) {
|
||||
this.decompiler = decompiler;
|
||||
|
||||
setGroup("fabric");
|
||||
getOutputs().upToDateWhen((o) -> false);
|
||||
}
|
||||
|
||||
|
||||
@@ -35,6 +35,7 @@ import net.fabricmc.loom.api.decompilers.LoomDecompiler;
|
||||
import net.fabricmc.loom.configuration.ide.RunConfigSettings;
|
||||
import net.fabricmc.loom.configuration.providers.mappings.MappingsProvider;
|
||||
import net.fabricmc.loom.decompilers.fernflower.FabricFernFlowerDecompiler;
|
||||
import net.fabricmc.loom.util.Constants;
|
||||
|
||||
public final class LoomTasks {
|
||||
private LoomTasks() {
|
||||
@@ -50,7 +51,7 @@ public final class LoomTasks {
|
||||
|
||||
tasks.register("remapJar", RemapJarTask.class, t -> {
|
||||
t.setDescription("Remaps the built project jar to intermediary mappings.");
|
||||
t.setGroup("fabric");
|
||||
t.setGroup(Constants.TASK_CATEGORY);
|
||||
});
|
||||
|
||||
tasks.register("downloadAssets", DownloadAssetsTask.class, t -> t.setDescription("Downloads required assets for Fabric."));
|
||||
@@ -97,7 +98,6 @@ public final class LoomTasks {
|
||||
|
||||
tasks.register(taskName, RunGameTask.class, config).configure(t -> {
|
||||
t.setDescription("Starts the '" + config.getConfigName() + "' run configuration");
|
||||
t.setGroup("fabric");
|
||||
|
||||
if (config.getEnvironment().equals("client")) {
|
||||
t.dependsOn("downloadAssets");
|
||||
|
||||
@@ -39,21 +39,24 @@ import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonObject;
|
||||
import me.shedaniel.architectury.refmapremapper.RefmapRemapper;
|
||||
import me.shedaniel.architectury.refmapremapper.remapper.MappingsRemapper;
|
||||
import me.shedaniel.architectury.refmapremapper.remapper.ReferenceRemapper;
|
||||
import me.shedaniel.architectury.refmapremapper.remapper.Remapper;
|
||||
import me.shedaniel.architectury.refmapremapper.remapper.SimpleReferenceRemapper;
|
||||
import dev.architectury.refmapremapper.RefmapRemapper;
|
||||
import dev.architectury.refmapremapper.remapper.MappingsRemapper;
|
||||
import dev.architectury.refmapremapper.remapper.ReferenceRemapper;
|
||||
import dev.architectury.refmapremapper.remapper.Remapper;
|
||||
import dev.architectury.refmapremapper.remapper.SimpleReferenceRemapper;
|
||||
import dev.architectury.tinyremapper.IMappingProvider;
|
||||
import dev.architectury.tinyremapper.TinyRemapper;
|
||||
import dev.architectury.tinyremapper.TinyUtils;
|
||||
import org.gradle.api.Action;
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.artifacts.Configuration;
|
||||
@@ -72,27 +75,23 @@ import net.fabricmc.loom.LoomGradleExtension;
|
||||
import net.fabricmc.loom.build.JarRemapper;
|
||||
import net.fabricmc.loom.build.MixinRefmapHelper;
|
||||
import net.fabricmc.loom.build.nesting.EmptyNestedJarProvider;
|
||||
import net.fabricmc.loom.build.nesting.NestedJarPathProvider;
|
||||
import net.fabricmc.loom.build.nesting.JarNester;
|
||||
import net.fabricmc.loom.build.nesting.MergedNestedJarProvider;
|
||||
import net.fabricmc.loom.build.nesting.NestedDependencyProvider;
|
||||
import net.fabricmc.loom.build.nesting.NestedJarPathProvider;
|
||||
import net.fabricmc.loom.build.nesting.NestedJarProvider;
|
||||
import net.fabricmc.loom.configuration.accesswidener.AccessWidenerJarProcessor;
|
||||
import net.fabricmc.loom.configuration.providers.mappings.MappingsProvider;
|
||||
import net.fabricmc.loom.util.Constants;
|
||||
import net.fabricmc.loom.util.SourceRemapper;
|
||||
import net.fabricmc.loom.util.TinyRemapperMappingsHelper;
|
||||
import net.fabricmc.loom.util.gradle.GradleSupport;
|
||||
import net.fabricmc.loom.util.ZipReprocessorUtil;
|
||||
import net.fabricmc.loom.util.gradle.GradleSupport;
|
||||
import net.fabricmc.mapping.tree.ClassDef;
|
||||
import net.fabricmc.mapping.tree.FieldDef;
|
||||
import net.fabricmc.mapping.tree.MethodDef;
|
||||
import net.fabricmc.mapping.tree.TinyTree;
|
||||
import net.fabricmc.stitch.util.Pair;
|
||||
import net.fabricmc.tinyremapper.IMappingProvider;
|
||||
import net.fabricmc.tinyremapper.OutputConsumerPath;
|
||||
import net.fabricmc.tinyremapper.TinyRemapper;
|
||||
import net.fabricmc.tinyremapper.TinyUtils;
|
||||
|
||||
public class RemapJarTask extends Jar {
|
||||
private final RegularFileProperty input;
|
||||
|
||||
@@ -40,6 +40,7 @@ public class Constants {
|
||||
public static final String VERSION_MANIFESTS = "https://launchermeta.mojang.com/mc/game/version_manifest_v2.json";
|
||||
|
||||
public static final String SYSTEM_ARCH = System.getProperty("os.arch").equals("64") ? "64" : "32";
|
||||
public static final String TASK_CATEGORY = "loom";
|
||||
|
||||
public static final int ASM_VERSION = Opcodes.ASM9;
|
||||
|
||||
|
||||
@@ -33,6 +33,7 @@ import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import com.google.common.base.Stopwatch;
|
||||
import org.cadixdev.lorenz.MappingSet;
|
||||
import org.cadixdev.mercury.Mercury;
|
||||
import org.cadixdev.mercury.remapper.MercuryRemapper;
|
||||
@@ -45,7 +46,7 @@ import net.fabricmc.loom.LoomGradleExtension;
|
||||
import net.fabricmc.loom.configuration.RemappedConfigurationEntry;
|
||||
import net.fabricmc.loom.configuration.providers.LaunchProvider;
|
||||
import net.fabricmc.loom.configuration.providers.mappings.MappingsProvider;
|
||||
import net.fabricmc.loom.util.gradle.ProgressLogger;
|
||||
import net.fabricmc.loom.configuration.providers.minecraft.tr.MercuryUtils;
|
||||
import net.fabricmc.lorenztiny.TinyMappingsReader;
|
||||
import net.fabricmc.mapping.tree.TinyTree;
|
||||
import net.fabricmc.stitch.util.StitchUtil;
|
||||
@@ -54,7 +55,7 @@ public class SourceRemapper {
|
||||
private final Project project;
|
||||
private String from;
|
||||
private String to;
|
||||
private final List<Consumer<ProgressLogger>> remapTasks = new ArrayList<>();
|
||||
private final List<Consumer<Mercury>> remapTasks = new ArrayList<>();
|
||||
|
||||
private Mercury mercury;
|
||||
|
||||
@@ -80,10 +81,9 @@ public class SourceRemapper {
|
||||
}
|
||||
|
||||
public void scheduleRemapSources(File source, File destination, boolean reproducibleFileOrder, boolean preserveFileTimestamps) {
|
||||
remapTasks.add((logger) -> {
|
||||
remapTasks.add((mercury) -> {
|
||||
try {
|
||||
logger.progress("remapping sources - " + source.getName());
|
||||
remapSourcesInner(source, destination);
|
||||
remapSourcesInner(mercury, source, destination);
|
||||
ZipReprocessorUtil.reprocessZip(destination, reproducibleFileOrder, preserveFileTimestamps);
|
||||
|
||||
// Set the remapped sources creation date to match the sources if we're likely succeeded in making it
|
||||
@@ -101,22 +101,21 @@ public class SourceRemapper {
|
||||
return;
|
||||
}
|
||||
|
||||
project.getLogger().lifecycle(":remapping sources");
|
||||
Stopwatch stopwatch = Stopwatch.createStarted();
|
||||
project.getLogger().lifecycle(":remapping " + remapTasks.size() + " sources");
|
||||
|
||||
ProgressLogger progressLogger = ProgressLogger.getProgressFactory(project, SourceRemapper.class.getName());
|
||||
progressLogger.start("Remapping dependency sources", "sources");
|
||||
Mercury mercury = getMercuryInstance();
|
||||
ThreadingUtils.run(remapTasks, consumer -> consumer.accept(MercuryUtils.copyMercury(mercury)));
|
||||
|
||||
remapTasks.forEach(consumer -> consumer.accept(progressLogger));
|
||||
|
||||
progressLogger.completed();
|
||||
project.getLogger().lifecycle(":remapped " + remapTasks.size() + " sources in " + stopwatch.stop());
|
||||
|
||||
// TODO: FIXME - WORKAROUND https://github.com/FabricMC/fabric-loom/issues/45
|
||||
System.gc();
|
||||
}
|
||||
|
||||
private void remapSourcesInner(File source, File destination) throws Exception {
|
||||
private void remapSourcesInner(Mercury mercury, File source, File destination) throws Exception {
|
||||
Stopwatch stopwatch = Stopwatch.createStarted();
|
||||
project.getLogger().info(":remapping source jar " + source.getName() + " from " + from + " to " + to);
|
||||
Mercury mercury = getMercuryInstance();
|
||||
|
||||
if (source.equals(destination)) {
|
||||
if (source.isDirectory()) {
|
||||
@@ -166,6 +165,8 @@ public class SourceRemapper {
|
||||
if (isSrcTmp) {
|
||||
Files.walkFileTree(srcPath, new DeletingFileVisitor());
|
||||
}
|
||||
|
||||
project.getLogger().info(":remapped source jar " + source.getName() + " from " + from + " to " + to + " in " + stopwatch.stop());
|
||||
}
|
||||
|
||||
private Mercury getMercuryInstance() {
|
||||
|
||||
@@ -34,9 +34,12 @@ import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.google.common.base.Stopwatch;
|
||||
|
||||
public class ThreadingUtils {
|
||||
public static <T> void run(Collection<T> values, UnsafeConsumer<T> action) {
|
||||
run(values.stream()
|
||||
@@ -128,10 +131,16 @@ public class ThreadingUtils {
|
||||
}
|
||||
|
||||
public static class TaskCompleter {
|
||||
Stopwatch stopwatch = Stopwatch.createUnstarted();
|
||||
List<CompletableFuture<?>> tasks = new ArrayList<>();
|
||||
ExecutorService service = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
|
||||
List<Consumer<Stopwatch>> completionListener = new ArrayList<>();
|
||||
|
||||
public TaskCompleter add(UnsafeRunnable job) {
|
||||
if (!stopwatch.isRunning()) {
|
||||
stopwatch.start();
|
||||
}
|
||||
|
||||
tasks.add(CompletableFuture.runAsync(() -> {
|
||||
try {
|
||||
job.run();
|
||||
@@ -139,6 +148,12 @@ public class ThreadingUtils {
|
||||
throw new RuntimeException(throwable);
|
||||
}
|
||||
}, service));
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public TaskCompleter onComplete(Consumer<Stopwatch> consumer) {
|
||||
completionListener.add(consumer);
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -146,6 +161,11 @@ public class ThreadingUtils {
|
||||
try {
|
||||
CompletableFuture.allOf(tasks.toArray(new CompletableFuture[0])).get();
|
||||
service.shutdownNow();
|
||||
stopwatch.stop();
|
||||
|
||||
for (Consumer<Stopwatch> consumer : completionListener) {
|
||||
consumer.accept(stopwatch);
|
||||
}
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
@@ -24,13 +24,14 @@
|
||||
|
||||
package net.fabricmc.loom.util;
|
||||
|
||||
import dev.architectury.tinyremapper.IMappingProvider;
|
||||
|
||||
import net.fabricmc.mapping.tree.ClassDef;
|
||||
import net.fabricmc.mapping.tree.FieldDef;
|
||||
import net.fabricmc.mapping.tree.LocalVariableDef;
|
||||
import net.fabricmc.mapping.tree.MethodDef;
|
||||
import net.fabricmc.mapping.tree.ParameterDef;
|
||||
import net.fabricmc.mapping.tree.TinyTree;
|
||||
import net.fabricmc.tinyremapper.IMappingProvider;
|
||||
|
||||
public class TinyRemapperMappingsHelper {
|
||||
private TinyRemapperMappingsHelper() { }
|
||||
|
||||
@@ -32,11 +32,12 @@ import java.util.Map;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import dev.architectury.tinyremapper.IMappingProvider;
|
||||
|
||||
import net.fabricmc.loom.util.FileSystemUtil;
|
||||
import net.fabricmc.loom.util.FileSystemUtil.FileSystemDelegate;
|
||||
import net.fabricmc.mapping.tree.ClassDef;
|
||||
import net.fabricmc.mapping.tree.TinyTree;
|
||||
import net.fabricmc.tinyremapper.IMappingProvider;
|
||||
|
||||
public class InnerClassRemapper {
|
||||
public static IMappingProvider of(Path fromJar, TinyTree mappingsWithSrg, String from, String to) throws IOException {
|
||||
|
||||
@@ -39,7 +39,8 @@ import java.util.Objects;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import au.com.bytecode.opencsv.CSVReader;
|
||||
import com.opencsv.CSVReader;
|
||||
import com.opencsv.exceptions.CsvValidationException;
|
||||
import org.cadixdev.lorenz.MappingSet;
|
||||
import org.cadixdev.lorenz.io.srg.tsrg.TSrgReader;
|
||||
import org.cadixdev.lorenz.model.ClassMapping;
|
||||
@@ -71,7 +72,12 @@ public class MCPReader {
|
||||
Map<String, String> intermediaryToMCPMap = createIntermediaryToMCPMap(intermediaryTiny, srgTokens);
|
||||
Map<String, String[]> intermediaryToDocsMap = new HashMap<>();
|
||||
Map<String, Map<Integer, String>> intermediaryToParamsMap = new HashMap<>();
|
||||
injectMcp(mcpJar, intermediaryToMCPMap, intermediaryToDocsMap, intermediaryToParamsMap);
|
||||
|
||||
try {
|
||||
injectMcp(mcpJar, intermediaryToMCPMap, intermediaryToDocsMap, intermediaryToParamsMap);
|
||||
} catch (CsvValidationException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
mergeTokensIntoIntermediary(intermediaryTiny, intermediaryToMCPMap, intermediaryToDocsMap, intermediaryToParamsMap);
|
||||
return intermediaryTiny;
|
||||
@@ -186,7 +192,7 @@ public class MCPReader {
|
||||
}
|
||||
|
||||
private void injectMcp(Path mcpJar, Map<String, String> intermediaryToSrgMap, Map<String, String[]> intermediaryToDocsMap, Map<String, Map<Integer, String>> intermediaryToParamsMap)
|
||||
throws IOException {
|
||||
throws IOException, CsvValidationException {
|
||||
Map<String, List<String>> srgToIntermediary = inverseMap(intermediaryToSrgMap);
|
||||
Map<String, List<String>> simpleSrgToIntermediary = new HashMap<>();
|
||||
Pattern methodPattern = Pattern.compile("(func_\\d*)_.*");
|
||||
|
||||
Reference in New Issue
Block a user