unify mapping loader with tiny-remapper
parent
a2903acd3b
commit
170735618c
|
@ -24,8 +24,7 @@
|
||||||
|
|
||||||
package net.fabricmc.loom.mixin;
|
package net.fabricmc.loom.mixin;
|
||||||
|
|
||||||
import cuchaz.enigma.analysis.Access;
|
import net.fabricmc.tinyremapper.TinyUtils;
|
||||||
import org.objectweb.asm.commons.Remapper;
|
|
||||||
import org.spongepowered.asm.obfuscation.mapping.common.MappingField;
|
import org.spongepowered.asm.obfuscation.mapping.common.MappingField;
|
||||||
import org.spongepowered.asm.obfuscation.mapping.common.MappingMethod;
|
import org.spongepowered.asm.obfuscation.mapping.common.MappingMethod;
|
||||||
import org.spongepowered.tools.obfuscation.mapping.common.MappingProvider;
|
import org.spongepowered.tools.obfuscation.mapping.common.MappingProvider;
|
||||||
|
@ -35,26 +34,11 @@ import javax.annotation.processing.Messager;
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.reflect.Field;
|
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
public class MixinMappingProviderTiny extends MappingProvider {
|
public class MixinMappingProviderTiny extends MappingProvider {
|
||||||
private final String from, to;
|
private final String from, to;
|
||||||
|
|
||||||
private static class SimpleClassMapper extends Remapper {
|
|
||||||
final Map<String, String> classMap;
|
|
||||||
|
|
||||||
public SimpleClassMapper(Map<String, String> map) {
|
|
||||||
this.classMap = map;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String map(String typeName) {
|
|
||||||
return classMap.get(typeName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public MixinMappingProviderTiny(Messager messager, Filer filer, String from, String to) {
|
public MixinMappingProviderTiny(Messager messager, Filer filer, String from, String to) {
|
||||||
super(messager, filer);
|
super(messager, filer);
|
||||||
this.from = from;
|
this.from = from;
|
||||||
|
@ -137,60 +121,19 @@ public class MixinMappingProviderTiny extends MappingProvider {
|
||||||
@Override
|
@Override
|
||||||
public void read(File input) throws IOException {
|
public void read(File input) throws IOException {
|
||||||
BufferedReader reader = Files.newBufferedReader(input.toPath());
|
BufferedReader reader = Files.newBufferedReader(input.toPath());
|
||||||
String[] header = reader.readLine().split("\t");
|
|
||||||
if (header.length <= 1
|
|
||||||
|| !header[0].equals("v1")) {
|
|
||||||
throw new IOException("Invalid mapping version!");
|
|
||||||
}
|
|
||||||
|
|
||||||
List<String> headerList = Arrays.asList(removeFirst(header, 1));
|
TinyUtils.read(reader, from, to, (classFrom, classTo) -> {
|
||||||
int fromIndex = headerList.indexOf(from);
|
classMap.put(classFrom, classTo);
|
||||||
int toIndex = headerList.indexOf(to);
|
}, (fieldFrom, fieldTo) -> {
|
||||||
|
fieldMap.put(
|
||||||
if (fromIndex < 0) throw new IOException("Could not find mapping '" + from + "'!");
|
new MappingField(fieldFrom.owner, fieldFrom.name, fieldFrom.desc),
|
||||||
if (toIndex < 0) throw new IOException("Could not find mapping '" + to + "'!");
|
new MappingField(fieldTo.owner, fieldTo.name, fieldTo.desc)
|
||||||
|
);
|
||||||
Map<String, String> obfFrom = new HashMap<>();
|
}, (methodFrom, methodTo) -> {
|
||||||
Map<String, String> obfTo = new HashMap<>();
|
methodMap.put(
|
||||||
List<String[]> linesStageTwo = new ArrayList<>();
|
new MappingMethod(methodFrom.owner, methodFrom.name, methodFrom.desc),
|
||||||
|
new MappingMethod(methodTo.owner, methodTo.name, methodTo.desc)
|
||||||
String line;
|
);
|
||||||
while ((line = reader.readLine()) != null) {
|
});
|
||||||
String[] splitLine = line.split("\t");
|
|
||||||
if (splitLine.length >= 2) {
|
|
||||||
if ("CLASS".equals(splitLine[0])) {
|
|
||||||
classMap.put(splitLine[1 + fromIndex], splitLine[1 + toIndex]);
|
|
||||||
obfFrom.put(splitLine[1], splitLine[1 + fromIndex]);
|
|
||||||
obfTo.put(splitLine[1], splitLine[1 + toIndex]);
|
|
||||||
} else {
|
|
||||||
linesStageTwo.add(splitLine);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
SimpleClassMapper descObfFrom = new SimpleClassMapper(obfFrom);
|
|
||||||
SimpleClassMapper descObfTo = new SimpleClassMapper(obfTo);
|
|
||||||
|
|
||||||
for (String[] splitLine : linesStageTwo) {
|
|
||||||
if ("FIELD".equals(splitLine[0])) {
|
|
||||||
String ownerFrom = obfFrom.getOrDefault(splitLine[1], splitLine[1]);
|
|
||||||
String ownerTo = obfTo.getOrDefault(splitLine[1], splitLine[1]);
|
|
||||||
String descFrom = descObfFrom.mapDesc(splitLine[2]);
|
|
||||||
String descTo = descObfTo.mapDesc(splitLine[2]);
|
|
||||||
fieldMap.put(
|
|
||||||
new MappingField(ownerFrom, splitLine[3 + fromIndex], descFrom),
|
|
||||||
new MappingField(ownerTo, splitLine[3 + toIndex], descTo)
|
|
||||||
);
|
|
||||||
} else if ("METHOD".equals(splitLine[0])) {
|
|
||||||
String ownerFrom = obfFrom.getOrDefault(splitLine[1], splitLine[1]);
|
|
||||||
String ownerTo = obfTo.getOrDefault(splitLine[1], splitLine[1]);
|
|
||||||
String descFrom = descObfFrom.mapMethodDesc(splitLine[2]);
|
|
||||||
String descTo = descObfTo.mapMethodDesc(splitLine[2]);
|
|
||||||
methodMap.put(
|
|
||||||
new MappingMethod(ownerFrom, splitLine[3 + fromIndex], descFrom),
|
|
||||||
new MappingMethod(ownerTo, splitLine[3 + toIndex], descTo)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue