Skip to content

Commit

Permalink
Adapt SrgMerger into ForgeMappingsMerger
Browse files Browse the repository at this point in the history
  • Loading branch information
shedaniel committed Nov 14, 2023
1 parent 3b58237 commit fcb79cb
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 225 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import java.util.List;

import com.google.common.hash.Hashing;
import dev.architectury.loom.neoforge.MojangMappingsMerger;
import org.gradle.api.Project;
import org.gradle.api.artifacts.Dependency;
import org.gradle.api.artifacts.ModuleDependency;
Expand All @@ -52,7 +51,7 @@
import net.fabricmc.loom.util.FileSystemUtil;
import net.fabricmc.loom.util.PropertyUtil;
import net.fabricmc.loom.util.srg.RemapObjectHolderVisitor;
import net.fabricmc.loom.util.srg.SrgMerger;
import net.fabricmc.loom.util.srg.ForgeMappingsMerger;
import net.fabricmc.mappingio.tree.MemoryMappingTree;

public class ForgeLibrariesProvider {
Expand Down Expand Up @@ -194,8 +193,8 @@ private static void remapObjectHolder(Project project, Path outputJar, MappingCo
// Merge SRG mappings. The real SRG mapping file hasn't been created yet since the usual SRG merging
// process occurs after all Forge libraries have been provided.
// Forge libs are needed for MC, which is needed for the mappings.
final SrgMerger.ExtraMappings extraMappings = SrgMerger.ExtraMappings.ofMojmapTsrg(MappingConfiguration.getMojmapSrgFileIfPossible(project));
final MemoryMappingTree mappings = SrgMerger.mergeSrg(MappingConfiguration.getRawSrgFile(project), mappingConfiguration.tinyMappings, extraMappings, true);
final ForgeMappingsMerger.ExtraMappings extraMappings = ForgeMappingsMerger.ExtraMappings.ofMojmapTsrg(MappingConfiguration.getMojmapSrgFileIfPossible(project));
final MemoryMappingTree mappings = ForgeMappingsMerger.mergeSrg(MappingConfiguration.getRawSrgFile(project), mappingConfiguration.tinyMappings, extraMappings, true);

// Remap the object holders.
RemapObjectHolderVisitor.remapObjectHolder(
Expand All @@ -213,7 +212,7 @@ private static void remapNeoForgeObjectHolder(Project project, Path outputJar, M
// process occurs after all Forge libraries have been provided.
// Forge libs are needed for MC, which is needed for the mappings.
final MappingContext context = new GradleMappingContext(project, "tmp-neoforge-libs");
final MemoryMappingTree mappings = MojangMappingsMerger.mergeMojangMappings(context, mappingConfiguration.tinyMappings);
final MemoryMappingTree mappings = ForgeMappingsMerger.mergeMojang(context, mappingConfiguration.tinyMappings, null, true);

// Remap the object holders.
RemapObjectHolderVisitor.remapObjectHolder(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import org.gradle.api.logging.LogLevel;

import net.fabricmc.loom.LoomGradleExtension;
import net.fabricmc.loom.api.mappings.layered.MappingContext;
import net.fabricmc.loom.api.mappings.layered.MappingsNamespace;
import net.fabricmc.loom.configuration.DependencyInfo;
import net.fabricmc.loom.configuration.providers.mappings.GradleMappingContext;
Expand Down Expand Up @@ -216,7 +217,8 @@ public static Path getMojmapTsrg(Project project, LoomGradleExtension extension)

if (Files.notExists(mojmapTsrg) || extension.refreshDeps()) {
try (BufferedWriter writer = Files.newBufferedWriter(mojmapTsrg, StandardCharsets.UTF_8, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING)) {
Tsrg2Utils.writeTsrg(visitor -> visitMojmap(visitor, project),
GradleMappingContext context = new GradleMappingContext(project, "tmp-mojmap");
Tsrg2Utils.writeTsrg(visitor -> visitMojangMappings(visitor, context),
MappingsNamespace.NAMED.toString(), false, writer);
}
}
Expand All @@ -233,8 +235,9 @@ public static Path getMojmapTsrg2(Project project, LoomGradleExtension extension

if (Files.notExists(mojmapTsrg2) || extension.refreshDeps()) {
try (BufferedWriter writer = Files.newBufferedWriter(mojmapTsrg2, StandardCharsets.UTF_8, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING)) {
GradleMappingContext context = new GradleMappingContext(project, "tmp-mojmap");
MemoryMappingTree tree = new MemoryMappingTree();
visitMojmap(tree, project);
visitMojangMappings(tree, context);
writer.write(Tsrg2Writer.serialize(tree));
}
}
Expand All @@ -243,21 +246,12 @@ public static Path getMojmapTsrg2(Project project, LoomGradleExtension extension
return mojmapTsrg2;
}

private static void visitMojmap(MappingVisitor visitor, Project project) {
GradleMappingContext context = new GradleMappingContext(project, "tmp-mojmap");

public static void visitMojangMappings(MappingVisitor visitor, MappingContext context) {
try {
FileUtils.deleteDirectory(context.workingDirectory("/").toFile());
MojangMappingLayer layer = new MojangMappingsSpec(() -> true, true).createLayer(context);
layer.visit(visitor);
} catch (IOException e) {
throw new UncheckedIOException(e);
} finally {
try {
FileUtils.deleteDirectory(context.workingDirectory("/").toFile());
} catch (IOException e) {
e.printStackTrace();
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@

import com.google.common.base.Stopwatch;
import com.google.gson.JsonObject;
import dev.architectury.loom.neoforge.MojangMappingsMerger;
import dev.architectury.loom.util.MappingOption;
import org.apache.tools.ant.util.StringUtils;
import org.gradle.api.Project;
Expand All @@ -70,10 +69,11 @@
import net.fabricmc.loom.util.service.ScopedSharedServiceManager;
import net.fabricmc.loom.util.service.SharedServiceManager;
import net.fabricmc.loom.util.srg.MCPReader;
import net.fabricmc.loom.util.srg.SrgMerger;
import net.fabricmc.loom.util.srg.ForgeMappingsMerger;
import net.fabricmc.loom.util.srg.SrgNamedWriter;
import net.fabricmc.mappingio.MappingReader;
import net.fabricmc.mappingio.format.MappingFormat;
import net.fabricmc.mappingio.format.Tiny2Writer;
import net.fabricmc.stitch.Command;
import net.fabricmc.stitch.commands.CommandProposeFieldNames;
import net.fabricmc.stitch.commands.tinyv2.TinyFile;
Expand Down Expand Up @@ -213,7 +213,11 @@ public void setupPost(Project project) throws IOException {
if (Files.notExists(tinyMappingsWithMojang) || extension.refreshDeps()) {
final Stopwatch stopwatch = Stopwatch.createStarted();
final MappingContext context = new GradleMappingContext(project, "tmp-neoforge");
MojangMappingsMerger.mergeMojangMappings(context, tinyMappings, tinyMappingsWithMojang);

try (Tiny2Writer writer = new Tiny2Writer(Files.newBufferedWriter(tinyMappingsWithMojang), false)) {
ForgeMappingsMerger.mergeMojang(context, tinyMappings, null, true).accept(writer);
}

project.getLogger().info(":merged mojang mappings in {}", stopwatch.stop());
}
}
Expand All @@ -222,8 +226,12 @@ public void setupPost(Project project) throws IOException {
if (Files.notExists(tinyMappingsWithSrg) || extension.refreshDeps()) {
// Merge tiny mappings with srg
Stopwatch stopwatch = Stopwatch.createStarted();
SrgMerger.ExtraMappings extraMappings = SrgMerger.ExtraMappings.ofMojmapTsrg(getMojmapSrgFileIfPossible(project));
SrgMerger.mergeSrg(getRawSrgFile(project), tinyMappings, tinyMappingsWithSrg, extraMappings, true);
ForgeMappingsMerger.ExtraMappings extraMappings = ForgeMappingsMerger.ExtraMappings.ofMojmapTsrg(getMojmapSrgFileIfPossible(project));

try (Tiny2Writer writer = new Tiny2Writer(Files.newBufferedWriter(tinyMappingsWithSrg), false)) {
ForgeMappingsMerger.mergeSrg(getRawSrgFile(project), tinyMappings, extraMappings, true).accept(writer);
}

project.getLogger().info(":merged srg mappings in " + stopwatch.stop());
}
}
Expand Down
Loading

0 comments on commit fcb79cb

Please sign in to comment.