Skip to content

Commit

Permalink
Use TR's MixinExtension to remap jars built without refmaps in dev. (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
modmuss50 authored Jan 15, 2024
1 parent 8ae3c8e commit b2608bb
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ dependencies {
// impl dependencies
include 'org.ow2.sat4j:org.ow2.sat4j.core:2.3.6'
include 'org.ow2.sat4j:org.ow2.sat4j.pb:2.3.6'
include "net.fabricmc:tiny-remapper:0.8.2"
include "net.fabricmc:tiny-remapper:0.10.0"
include "net.fabricmc:access-widener:2.1.0"
include ('net.fabricmc:mapping-io:0.5.0') {
// Mapping-io depends on ASM, dont bundle
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
import java.nio.file.FileSystem;
import java.nio.file.Files;
Expand All @@ -28,8 +29,12 @@
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.jar.Attributes;
import java.util.jar.Manifest;
import java.util.stream.Collectors;

import org.objectweb.asm.commons.Remapper;
Expand All @@ -41,6 +46,7 @@
import net.fabricmc.loader.impl.launch.FabricLauncher;
import net.fabricmc.loader.impl.launch.FabricLauncherBase;
import net.fabricmc.loader.impl.util.FileSystemUtil;
import net.fabricmc.loader.impl.util.ManifestUtil;
import net.fabricmc.loader.impl.util.SystemProperties;
import net.fabricmc.loader.impl.util.log.Log;
import net.fabricmc.loader.impl.util.log.LogCategory;
Expand All @@ -49,10 +55,15 @@
import net.fabricmc.tinyremapper.NonClassCopyMode;
import net.fabricmc.tinyremapper.OutputConsumerPath;
import net.fabricmc.tinyremapper.TinyRemapper;
import net.fabricmc.tinyremapper.extension.mixin.MixinExtension;

public final class RuntimeModRemapper {
private static final String REMAP_TYPE_MANIFEST_KEY = "Fabric-Loom-Mixin-Remap-Type";
private static final String REMAP_TYPE_STATIC = "static";

public static void remap(Collection<ModCandidate> modCandidates, Path tmpDir, Path outputDir) {
List<ModCandidate> modsToRemap = new ArrayList<>();
Set<InputTag> remapMixins = new HashSet<>();

for (ModCandidate mod : modCandidates) {
if (mod.getRequiresRemap()) {
Expand All @@ -67,6 +78,7 @@ public static void remap(Collection<ModCandidate> modCandidates, Path tmpDir, Pa
TinyRemapper remapper = TinyRemapper.newRemapper()
.withMappings(TinyRemapperMappingsHelper.create(launcher.getMappingConfiguration().getMappings(), "intermediary", launcher.getTargetNamespace()))
.renameInvalidLocals(false)
.extension(new MixinExtension(remapMixins::contains))
.build();

try {
Expand Down Expand Up @@ -95,6 +107,10 @@ public static void remap(Collection<ModCandidate> modCandidates, Path tmpDir, Pa
info.inputIsTemp = true;
}

if (requiresMixinRemap(info.inputPath)) {
remapMixins.add(tag);
}

info.outputPath = outputDir.resolve(mod.getDefaultFileName());
Files.deleteIfExists(info.outputPath);

Expand Down Expand Up @@ -205,6 +221,12 @@ private static List<Path> getRemapClasspath() throws IOException {
.collect(Collectors.toList());
}

private static boolean requiresMixinRemap(Path inputPath) throws IOException, URISyntaxException {
final Manifest manifest = ManifestUtil.readManifest(inputPath.toUri().toURL());
final Attributes mainAttributes = manifest.getMainAttributes();
return REMAP_TYPE_STATIC.equalsIgnoreCase(mainAttributes.getValue(REMAP_TYPE_MANIFEST_KEY));
}

private static class RemapInfo {
InputTag tag;
Path inputPath;
Expand Down

0 comments on commit b2608bb

Please sign in to comment.