Skip to content

Commit

Permalink
Adapt SrgMerger into ForgeMappingsMerger (#169)
Browse files Browse the repository at this point in the history
* Fix crash with NeoForge ext creation

* Adapt SrgMerger into ForgeMappingsMerger

* Update tiny-remapper

* Fix spotless

* Resolve reviews

* Fix checkstyle
  • Loading branch information
shedaniel authored Nov 15, 2023
1 parent 553a1f8 commit d43b9c2
Show file tree
Hide file tree
Showing 10 changed files with 139 additions and 244 deletions.
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jackson = "2.15.2"
guava = "32.1.2-jre"

stitch = "0.6.2"
tiny-remapper = "1.9.22"
tiny-remapper = "1.10.23"
access-widener = "2.1.0"
mapping-io = "0.4.2"
lorenz-tiny = "4.0.2"
Expand Down

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 All @@ -70,7 +69,8 @@ public static void provide(MappingConfiguration mappingConfiguration, Project pr
String dep = null;

if (lib.startsWith("org.spongepowered:mixin:")) {
if (PropertyUtil.getAndFinalize(extension.getForge().getUseCustomMixin())) {
// Don't apply custom mixin on NeoForge.
if (extension.isForge() && PropertyUtil.getAndFinalize(extension.getForge().getUseCustomMixin())) {
if (lib.contains("0.8.2")) {
dep = "net.fabricmc:sponge-mixin:0.8.2+build.24";
} else {
Expand Down Expand Up @@ -193,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 @@ -212,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
Original file line number Diff line number Diff line change
Expand Up @@ -104,21 +104,13 @@ public Property<Boolean> getUseForgeLoggerConfig() {

@Override
public List<String> getDataGenMods() {
if (extension.isNeoForge()) {
throw new UnsupportedOperationException("getDataGenMods is not available on NeoForge.");
}

// unmod list prevents uncontrolled additions (we want to create the run config too)
return Collections.unmodifiableList(dataGenMods);
}

@SuppressWarnings("Convert2Lambda")
@Override
public void dataGen(Action<DataGenConsumer> action) {
if (extension.isNeoForge()) {
throw new UnsupportedOperationException("dataGen is not available on NeoForge.");
}

action.execute(new DataGenConsumer() {
@Override
public void mod(String... modIds) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public LoomGradleExtensionImpl(Project project, LoomFiles files) {
this.loomFiles = files;
this.unmappedMods = project.files();
this.forgeExtension = Suppliers.memoize(() -> isForge() ? project.getObjects().newInstance(ForgeExtensionImpl.class, project, this) : null);
this.neoForgeExtension = Suppliers.memoize(() -> isNeoForge() ? project.getObjects().newInstance(NeoForgeExtensionImpl.class, project, this) : null);
this.neoForgeExtension = Suppliers.memoize(() -> isNeoForge() ? project.getObjects().newInstance(NeoForgeExtensionImpl.class, project) : null);

// Setup the default intermediate mappings provider.
setIntermediateMappingsProvider(IntermediaryMappingsProvider.class, provider -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,14 +141,14 @@ public void run() throws IOException {
} else {
launchConfig.property("net.minecraftforge.gradle.GradleStart.srg.srg-mcp", getExtension().getMappingConfiguration().srgToNamedSrg.toAbsolutePath().toString());
}
}

Set<String> mixinConfigs = PropertyUtil.getAndFinalize(getExtension().getForge().getMixinConfigs());
Set<String> mixinConfigs = PropertyUtil.getAndFinalize(getExtension().getForge().getMixinConfigs());

if (!mixinConfigs.isEmpty()) {
for (String config : mixinConfigs) {
launchConfig.argument("-mixin.config");
launchConfig.argument(config);
if (!mixinConfigs.isEmpty()) {
for (String config : mixinConfigs) {
launchConfig.argument("-mixin.config");
launchConfig.argument(config);
}
}
}

Expand Down
Loading

0 comments on commit d43b9c2

Please sign in to comment.