0.2.7 refactors (#178)

* Rough work on project based jars, skeleton for AccessEscalators?

* First working draft

* Minor changes

* Add support for mutable, better error checking when parsing file.
Code cleanup
Remap if needed when reading

* Fix inner classes and genSources

* Fix CME

* Caching, only regen jar when input changes

* Some work, untested

* Fix writing, fix checkstyle issues

* More fixes

* Move jars into a maven file structure, cleans up the file structure, and will benefit idea 2020
Add some basic validation to the AccessWidenerRemapper, will present any issues with the mappings when building (May need a way to disable?)
+ Some bugs fixes

* Fix issues with source jars in idea 2020, should be backwards compatible with 2019

* Move to lorenz-tiny

* Build fix + small cleanup

* Remove accesswidener's for now

* Update dev launch injector, should fix all issues with spaces in the path.
This commit is contained in:
modmuss50
2020-03-06 11:15:34 +00:00
committed by GitHub
parent d62a63c8bd
commit ee462f8f9e
24 changed files with 445 additions and 242 deletions

View File

@@ -32,18 +32,11 @@ import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.function.BiFunction;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables;
import org.cadixdev.lorenz.MappingSet;
import org.cadixdev.lorenz.io.MappingsReader;
import org.cadixdev.lorenz.model.ClassMapping;
import org.cadixdev.lorenz.model.Mapping;
import org.cadixdev.mercury.Mercury;
import org.cadixdev.mercury.remapper.MercuryRemapper;
import org.gradle.api.GradleException;
@@ -56,10 +49,7 @@ import net.fabricmc.loom.LoomGradleExtension;
import net.fabricmc.loom.providers.MappingsProvider;
import net.fabricmc.loom.providers.MinecraftMappedProvider;
import net.fabricmc.loom.util.SourceRemapper;
import net.fabricmc.mapping.tree.ClassDef;
import net.fabricmc.mapping.tree.Descriptored;
import net.fabricmc.mapping.tree.FieldDef;
import net.fabricmc.mapping.tree.MethodDef;
import net.fabricmc.lorenztiny.LorenzTiny;
import net.fabricmc.mapping.tree.TinyMappingFactory;
import net.fabricmc.mapping.tree.TinyTree;
@@ -159,14 +149,14 @@ public class MigrateMappingsTask extends AbstractLoomTask {
Path inputDir, Path outputDir, TinyTree currentMappings, TinyTree targetMappings
) throws IOException {
project.getLogger().lifecycle(":joining mappings");
MappingSet mappingSet = new MappingsJoiner(currentMappings, targetMappings,
MappingSet mappingSet = LorenzTiny.readMappings(currentMappings, targetMappings,
"intermediary", "named").read();
project.getLogger().lifecycle(":remapping");
Mercury mercury = SourceRemapper.createMercuryWithClassPath(project, false);
mercury.getClassPath().add(minecraftMappedProvider.MINECRAFT_MAPPED_JAR.toPath());
mercury.getClassPath().add(minecraftMappedProvider.MINECRAFT_INTERMEDIARY_JAR.toPath());
mercury.getClassPath().add(minecraftMappedProvider.getMappedJar().toPath());
mercury.getClassPath().add(minecraftMappedProvider.getIntermediaryJar().toPath());
mercury.getProcessors().add(MercuryRemapper.create(mappingSet));
@@ -179,72 +169,4 @@ public class MigrateMappingsTask extends AbstractLoomTask {
project.getLogger().lifecycle(":cleaning file descriptors");
System.gc();
}
private static class MappingsJoiner extends MappingsReader {
private final TinyTree sourceMappings, targetMappings;
private final String fromNamespace, toNamespace;
/**
* Say A is the source mappings and B is the target mappings.
* It does not map from intermediary to named but rather maps from named-A to named-B, by matching intermediary names.
* It goes through all of the intermediary names of A, and for every such intermediary name, call it I,
* matches the named mapping of I in A, with the named mapping of I in B.
* As you might imagine, this requires intermediary mappings to be stable across all versions.
* Since we only use intermediary names (and not descriptors) to match, and intermediary names are unique,
* this will migrate methods that have had their signature changed too.
*/
private MappingsJoiner(TinyTree sourceMappings, TinyTree targetMappings, String fromNamespace, String toNamespace) {
this.sourceMappings = sourceMappings;
this.targetMappings = targetMappings;
this.fromNamespace = fromNamespace;
this.toNamespace = toNamespace;
}
@Override
public MappingSet read(MappingSet mappings) {
Map<String, ClassDef> targetClasses = new HashMap<>();
Map<String, FieldDef> targetFields = new HashMap<>();
Map<String, MethodDef> targetMethods = new HashMap<>();
for (ClassDef newClass : targetMappings.getClasses()) {
targetClasses.put(newClass.getName(fromNamespace), newClass);
for (FieldDef field : newClass.getFields()) {
targetFields.put(field.getName(fromNamespace), field);
}
for (MethodDef method : newClass.getMethods()) {
targetMethods.put(method.getName(fromNamespace), method);
}
}
for (ClassDef oldClass : sourceMappings.getClasses()) {
String namedMappingOfSourceMapping = oldClass.getName(toNamespace);
String namedMappingOfTargetMapping = targetClasses.getOrDefault(oldClass.getName(fromNamespace), oldClass).getName(toNamespace);
ClassMapping classMapping = mappings.getOrCreateClassMapping(namedMappingOfSourceMapping).setDeobfuscatedName(namedMappingOfTargetMapping);
mapMembers(oldClass.getFields(), targetFields, classMapping::getOrCreateFieldMapping);
mapMembers(oldClass.getMethods(), targetMethods, classMapping::getOrCreateMethodMapping);
}
return mappings;
}
private <T extends Descriptored> void mapMembers(Collection<T> oldMembers, Map<String, T> newMembers,
BiFunction<String, String, Mapping> mapper) {
for (T oldMember : oldMembers) {
String oldName = oldMember.getName(toNamespace);
String oldDescriptor = oldMember.getDescriptor(toNamespace);
// We only use the intermediary name (and not the descriptor) because every method has a unique intermediary name
String newName = newMembers.getOrDefault(oldMember.getName(fromNamespace), oldMember).getName(toNamespace);
mapper.apply(oldName, oldDescriptor).setDeobfuscatedName(newName);
}
}
@Override
public void close() {
}
}
}