fix line number remapping, add option to disable mixin refmap remapping (unnecessary in loader 0.4.0+, but needs testting)
parent
b4beaed968
commit
b5b3138e24
|
@ -46,6 +46,7 @@ public class LoomGradleExtension {
|
|||
public String refmapName;
|
||||
public String loaderLaunchMethod;
|
||||
public boolean remapMod = true;
|
||||
public boolean remapDependencyMixinRefMaps = true;
|
||||
public boolean autoGenIDERuns = true;
|
||||
public boolean extractJars = false;
|
||||
|
||||
|
|
|
@ -25,15 +25,20 @@
|
|||
package net.fabricmc.loom;
|
||||
|
||||
import net.fabricmc.loom.providers.MappingsProvider;
|
||||
import net.fabricmc.loom.providers.MinecraftAssetsProvider;
|
||||
import net.fabricmc.loom.providers.MinecraftLibraryProvider;
|
||||
import net.fabricmc.loom.task.*;
|
||||
import net.fabricmc.loom.task.fernflower.FernFlowerTask;
|
||||
import net.fabricmc.loom.util.LineNumberRemapper;
|
||||
import net.fabricmc.loom.util.progress.ProgressLogger;
|
||||
import net.fabricmc.stitch.util.StitchUtil;
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.tasks.TaskContainer;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Locale;
|
||||
|
||||
public class LoomGradlePlugin extends AbstractPlugin {
|
||||
|
@ -71,8 +76,8 @@ public class LoomGradlePlugin extends AbstractPlugin {
|
|||
MinecraftLibraryProvider libraryProvider = extension.getMinecraftProvider().libraryProvider;
|
||||
MappingsProvider mappingsProvider = extension.getMappingsProvider();
|
||||
File mappedJar = mappingsProvider.mappedProvider.getMappedJar();
|
||||
File sourcesJar = getMappedByproduct(project, "-sources-tmp.jar");
|
||||
File sourcesFinalJar = getMappedByproduct(project, "-sources.jar");
|
||||
File linemappedJarTmp = getMappedByproduct(project, "-linemapped.jar.tmp");
|
||||
File sourcesJar = getMappedByproduct(project, "-sources.jar");
|
||||
File linemapFile = getMappedByproduct(project, "-sources.lmap");
|
||||
|
||||
task.setInput(mappedJar);
|
||||
|
@ -80,23 +85,33 @@ public class LoomGradlePlugin extends AbstractPlugin {
|
|||
task.setLineMapFile(linemapFile);
|
||||
task.setLibraries(libraryProvider.getLibraries());
|
||||
|
||||
if (sourcesJar.exists()) {
|
||||
sourcesJar.delete();
|
||||
}
|
||||
|
||||
task.doLast((tt) -> {
|
||||
project.getLogger().lifecycle(":readjusting line numbers");
|
||||
project.getLogger().lifecycle(":adjusting line numbers");
|
||||
LineNumberRemapper remapper = new LineNumberRemapper();
|
||||
remapper.readMappings(linemapFile);
|
||||
|
||||
try {
|
||||
remapper.process(sourcesJar.toPath(), sourcesFinalJar.toPath());
|
||||
ProgressLogger progressLogger = ProgressLogger.getProgressFactory(project, FernFlowerTask.class.getName());
|
||||
progressLogger.start("Adjusting line numbers", "linemap");
|
||||
|
||||
try (StitchUtil.FileSystemDelegate inFs = StitchUtil.getJarFileSystem(mappedJar, true);
|
||||
StitchUtil.FileSystemDelegate outFs = StitchUtil.getJarFileSystem(linemappedJarTmp, true)) {
|
||||
remapper.process(progressLogger, inFs.get().getPath("/"), outFs.get().getPath("/"));
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
if (sourcesJar.exists()) {
|
||||
sourcesJar.delete();
|
||||
progressLogger.completed();
|
||||
|
||||
Path mappedJarPath = mappedJar.toPath();
|
||||
Path linemappedJarTmpPath = linemappedJarTmp.toPath();
|
||||
|
||||
if (Files.exists(linemappedJarTmpPath)) {
|
||||
try {
|
||||
Files.deleteIfExists(mappedJarPath);
|
||||
Files.move(linemappedJarTmpPath, mappedJarPath);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
|
@ -74,7 +74,7 @@ public class ThreadSafeResultSaver implements IResultSaver, IFabricResultSaver {
|
|||
try {
|
||||
lineMapWriter = new PrintWriter(new FileWriter(lineMapFile.get()));
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Unable to create LineMap file.", e);
|
||||
throw new RuntimeException("Unable to create line mapping file: " + lineMapFile.get(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -100,16 +100,15 @@ public class ThreadSafeResultSaver implements IResultSaver, IFabricResultSaver {
|
|||
}
|
||||
if (mapping != null && lineMapWriter != null) {
|
||||
int maxLine = 0;
|
||||
int maxLineDist = 0;
|
||||
// 2 loops here is meh, perhaps merge with a buffer?
|
||||
int maxLineDest = 0;
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for (int i = 0; i < mapping.length; i += 2) {
|
||||
maxLine = Math.max(maxLine, mapping[i]);
|
||||
maxLineDist = Math.max(maxLineDist, mapping[i + 1]);
|
||||
}
|
||||
lineMapWriter.println(qualifiedName + "\t" + maxLine + "\t" + maxLineDist);
|
||||
for (int i = 0; i < mapping.length; i += 2) {
|
||||
lineMapWriter.println("\t" + mapping[i] + "\t" + mapping[i + 1]);
|
||||
maxLineDest = Math.max(maxLineDest, mapping[i + 1]);
|
||||
builder.append("\t").append(mapping[i]).append("\t").append(mapping[i + 1]).append("\n");
|
||||
}
|
||||
lineMapWriter.println(qualifiedName + "\t" + maxLine + "\t" + maxLineDest);
|
||||
lineMapWriter.println(builder.toString());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -24,6 +24,8 @@
|
|||
|
||||
package net.fabricmc.loom.util;
|
||||
|
||||
import net.fabricmc.loom.util.progress.ProgressLogger;
|
||||
import org.gradle.api.logging.Logger;
|
||||
import org.objectweb.asm.*;
|
||||
|
||||
import java.io.*;
|
||||
|
@ -56,9 +58,9 @@ public class LineNumberRemapper {
|
|||
if (line.charAt(0) != '\t') {
|
||||
clazz = lineMap.computeIfAbsent(segs[0], RClass::new);
|
||||
clazz.maxLine = Integer.parseInt(segs[1]);
|
||||
clazz.maxLineDist = Integer.parseInt(segs[2]);
|
||||
clazz.maxLineDest = Integer.parseInt(segs[2]);
|
||||
} else {
|
||||
clazz.lineMap.put(Integer.parseInt(segs[0]), (Integer) Integer.parseInt(segs[1]));
|
||||
clazz.lineMap.put(Integer.parseInt(segs[0]), Integer.parseInt(segs[1]));
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
@ -70,7 +72,7 @@ public class LineNumberRemapper {
|
|||
}
|
||||
}
|
||||
|
||||
public void process(Path input, Path output) throws IOException {
|
||||
public void process(ProgressLogger logger, Path input, Path output) throws IOException {
|
||||
Files.walkFileTree(input, new SimpleFileVisitor<Path>() {
|
||||
@Override
|
||||
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
|
||||
|
@ -86,6 +88,10 @@ public class LineNumberRemapper {
|
|||
Files.delete(dst);
|
||||
}
|
||||
String idx = rel.substring(0, rel.length() - 6);
|
||||
if (logger != null) {
|
||||
logger.progress("Remapping " + idx);
|
||||
}
|
||||
|
||||
int dollarPos = idx.indexOf('$'); //This makes the assumption that only Java classes are to be remapped.
|
||||
if (dollarPos >= 0) {
|
||||
idx = idx.substring(0, dollarPos);
|
||||
|
@ -127,13 +133,13 @@ public class LineNumberRemapper {
|
|||
if (tLine <= 0) {
|
||||
super.visitLineNumber(line, start);
|
||||
} else if (tLine >= rClass.maxLine) {
|
||||
super.visitLineNumber(rClass.maxLineDist, start);
|
||||
super.visitLineNumber(rClass.maxLineDest, start);
|
||||
} else {
|
||||
Integer matchedLine = null;
|
||||
while (tLine <= rClass.maxLine && ((matchedLine = rClass.lineMap.get(tLine)) != null)) {
|
||||
while (tLine <= rClass.maxLine && ((matchedLine = rClass.lineMap.get(tLine)) == null)) {
|
||||
tLine++;
|
||||
}
|
||||
super.visitLineNumber(matchedLine != null ? matchedLine : rClass.maxLineDist, start);
|
||||
super.visitLineNumber(matchedLine != null ? matchedLine : rClass.maxLineDest, start);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -144,7 +150,7 @@ public class LineNumberRemapper {
|
|||
|
||||
private final String name;
|
||||
private int maxLine;
|
||||
private int maxLineDist;
|
||||
private int maxLineDest;
|
||||
private Map<Integer, Integer> lineMap = new HashMap<>();
|
||||
|
||||
private RClass(String name) {
|
||||
|
|
|
@ -182,11 +182,13 @@ public class ModProcessor {
|
|||
throw new RuntimeException("Failed to remap JAR to " + toM + " file not found: " + output.getAbsolutePath());
|
||||
}
|
||||
|
||||
if (extension.remapDependencyMixinRefMaps) {
|
||||
if (MixinRefmapHelper.transformRefmaps(remapper, output)) {
|
||||
project.getLogger().lifecycle(":remapping " + input.getName() + " (Mixin reference maps)");
|
||||
remapper.finish();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void readInstallerJson(File file, Project project){
|
||||
try {
|
||||
|
|
Loading…
Reference in New Issue