mirror of
https://github.com/architectury/architectury-loom.git
synced 2026-04-02 13:37:45 -05:00
Update tiny remapper
This commit is contained in:
@@ -35,6 +35,7 @@ import java.util.function.BiConsumer;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
import org.gradle.api.Action;
|
||||
import org.gradle.api.Project;
|
||||
import org.objectweb.asm.commons.Remapper;
|
||||
|
||||
import net.fabricmc.loom.util.LoggerFilter;
|
||||
@@ -64,9 +65,10 @@ public class JarRemapper {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void remap() throws IOException {
|
||||
public void remap(Project project) throws IOException {
|
||||
LoggerFilter.replaceSystemOut();
|
||||
TinyRemapper.Builder remapperBuilder = TinyRemapper.newRemapper();
|
||||
remapperBuilder.logger(project.getLogger()::lifecycle);
|
||||
mappingProviders.forEach(remapperBuilder::withMappings);
|
||||
|
||||
if (remapOptions != null) {
|
||||
|
||||
@@ -320,7 +320,7 @@ public final class CompileConfiguration {
|
||||
rootProject.getTasks().register("remapAllJars", AbstractLoomTask.class, task -> {
|
||||
task.doLast(t -> {
|
||||
try {
|
||||
jarRemapper.remap();
|
||||
jarRemapper.remap(rootProject);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Failed to remap jars", e);
|
||||
}
|
||||
|
||||
@@ -95,7 +95,8 @@ public class AccessWidenerJarProcessor implements JarProcessor {
|
||||
throw new UnsupportedOperationException(String.format("Access Widener namespace '%s' is not a valid namespace, it must be one of: '%s'", accessWidener.getNamespace(), String.join(", ", validNamespaces)));
|
||||
}
|
||||
|
||||
TinyRemapper tinyRemapper = loomGradleExtension.getMinecraftMappedProvider().getTinyRemapper(null, "official", "named");
|
||||
TinyRemapper tinyRemapper = loomGradleExtension.getMinecraftMappedProvider().getTinyRemapper();
|
||||
tinyRemapper.replaceMappings(loomGradleExtension.getMinecraftMappedProvider().getMappings(null, "official", "named"));
|
||||
loomGradleExtension.getMinecraftMappedProvider();
|
||||
tinyRemapper.readClassPath(MinecraftMappedProvider.getRemapClasspath(project));
|
||||
|
||||
|
||||
@@ -155,6 +155,7 @@ public class ModProcessor {
|
||||
TinyTree mappings = extension.isForge() ? mappingsProvider.getMappingsWithSrg() : mappingsProvider.getMappings();
|
||||
LoggerFilter.replaceSystemOut();
|
||||
TinyRemapper remapper = TinyRemapper.newRemapper()
|
||||
.logger(project.getLogger()::lifecycle)
|
||||
.withMappings(TinyRemapperMappingsHelper.create(mappings, fromM, toM, false))
|
||||
.renameInvalidLocals(false)
|
||||
.build();
|
||||
|
||||
@@ -428,6 +428,7 @@ public class MinecraftPatchedProvider extends DependencyProvider {
|
||||
Files.deleteIfExists(output);
|
||||
|
||||
TinyRemapper remapper = TinyRemapper.newRemapper()
|
||||
.logger(getProject().getLogger()::lifecycle)
|
||||
.withMappings(TinyRemapperMappingsHelper.create(mappingsWithSrg, "srg", "official", true))
|
||||
.withMappings(InnerClassRemapper.of(input, mappingsWithSrg, "srg", "official"))
|
||||
.renameInvalidLocals(true)
|
||||
|
||||
@@ -35,7 +35,9 @@ import java.nio.file.FileSystems;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.jar.Attributes;
|
||||
import java.util.jar.Manifest;
|
||||
@@ -48,12 +50,12 @@ import net.fabricmc.loom.configuration.DependencyProvider;
|
||||
import net.fabricmc.loom.configuration.providers.MinecraftProvider;
|
||||
import net.fabricmc.loom.configuration.providers.mappings.MappingsProvider;
|
||||
import net.fabricmc.loom.util.Constants;
|
||||
import net.fabricmc.loom.util.ThreadingUtils;
|
||||
import net.fabricmc.loom.util.TinyRemapperMappingsHelper;
|
||||
import net.fabricmc.loom.util.srg.AtRemapper;
|
||||
import net.fabricmc.loom.util.srg.CoreModClassRemapper;
|
||||
import net.fabricmc.loom.util.srg.InnerClassRemapper;
|
||||
import net.fabricmc.mapping.tree.TinyTree;
|
||||
import net.fabricmc.tinyremapper.IMappingProvider;
|
||||
import net.fabricmc.tinyremapper.NonClassCopyMode;
|
||||
import net.fabricmc.tinyremapper.OutputConsumerPath;
|
||||
import net.fabricmc.tinyremapper.TinyRemapper;
|
||||
@@ -137,14 +139,15 @@ public class MinecraftMappedProvider extends DependencyProvider {
|
||||
Path outputSrg = minecraftSrgJar == null ? null : minecraftSrgJar.toPath();
|
||||
|
||||
Path[] libraries = getRemapClasspath(getProject());
|
||||
TinyRemapper remapper = getTinyRemapper();
|
||||
remapper.readClassPath(libraries);
|
||||
remapper.prepareClasses();
|
||||
|
||||
ThreadingUtils.run(getExtension().isForge() ? Arrays.asList("named", "intermediary", "srg") : Arrays.asList("named", "intermediary"), toM -> {
|
||||
for (String toM : getExtension().isForge() ? Arrays.asList("named", "intermediary", "srg") : Arrays.asList("named", "intermediary")) {
|
||||
Path output = "named".equals(toM) ? outputMapped : "srg".equals(toM) ? outputSrg : outputIntermediary;
|
||||
|
||||
getProject().getLogger().lifecycle(":remapping minecraft (TinyRemapper, " + fromM + " -> " + toM + ")");
|
||||
|
||||
TinyRemapper remapper = getTinyRemapper(input, fromM, toM);
|
||||
|
||||
try (OutputConsumerPath outputConsumer = new OutputConsumerPath.Builder(output).build()) {
|
||||
if (getExtension().isForge()) {
|
||||
outputConsumer.addNonClassFiles(input, NonClassCopyMode.FIX_META_INF, remapper);
|
||||
@@ -152,14 +155,14 @@ public class MinecraftMappedProvider extends DependencyProvider {
|
||||
outputConsumer.addNonClassFiles(input);
|
||||
}
|
||||
|
||||
remapper.readClassPath(libraries);
|
||||
remapper.replaceMappings(getMappings(input, fromM, toM));
|
||||
remapper.readInputs(input);
|
||||
remapper.apply(outputConsumer);
|
||||
} catch (Exception e) {
|
||||
Files.deleteIfExists(output);
|
||||
throw new RuntimeException("Failed to remap JAR " + input + " with mappings from " + mappingsProvider.tinyMappings, e);
|
||||
} finally {
|
||||
remapper.finish();
|
||||
remapper.removeInput();
|
||||
}
|
||||
|
||||
if (getExtension().isForge() && !"srg".equals(toM)) {
|
||||
@@ -196,14 +199,18 @@ public class MinecraftMappedProvider extends DependencyProvider {
|
||||
AtRemapper.remap(getProject().getLogger(), output, yarnWithSrg);
|
||||
CoreModClassRemapper.remapJar(output, yarnWithSrg, getProject().getLogger());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
remapper.finish();
|
||||
}
|
||||
|
||||
public TinyRemapper getTinyRemapper(@Nullable Path fromJar, String fromM, String toM) throws IOException {
|
||||
public TinyRemapper getTinyRemapper() throws IOException {
|
||||
TinyRemapper.Builder builder = TinyRemapper.newRemapper()
|
||||
.withMappings(TinyRemapperMappingsHelper.create(getExtension().isForge() ? getExtension().getMappingsProvider().getMappingsWithSrg() : getExtension().getMappingsProvider().getMappings(), fromM, toM, true))
|
||||
.renameInvalidLocals(true)
|
||||
.ignoreConflicts(getExtension().isForge())
|
||||
.cacheMappings(true)
|
||||
.threads(Runtime.getRuntime().availableProcessors())
|
||||
.logger(getProject().getLogger()::lifecycle)
|
||||
.rebuildSourceFilenames(true);
|
||||
|
||||
if (getExtension().isForge()) {
|
||||
@@ -211,17 +218,26 @@ public class MinecraftMappedProvider extends DependencyProvider {
|
||||
* They won't get remapped to their proper packages, so IllegalAccessErrors will happen without ._.
|
||||
*/
|
||||
builder.fixPackageAccess(true);
|
||||
|
||||
if (fromJar != null) {
|
||||
builder.withMappings(InnerClassRemapper.of(fromJar, getExtension().getMappingsProvider().getMappingsWithSrg(), fromM, toM));
|
||||
}
|
||||
} else {
|
||||
builder.withMappings(out -> JSR_TO_JETBRAINS.forEach(out::acceptClass));
|
||||
}
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
public Set<IMappingProvider> getMappings(@Nullable Path fromJar, String fromM, String toM) throws IOException {
|
||||
Set<IMappingProvider> providers = new HashSet<>();
|
||||
providers.add(TinyRemapperMappingsHelper.create(getExtension().isForge() ? getExtension().getMappingsProvider().getMappingsWithSrg() : getExtension().getMappingsProvider().getMappings(), fromM, toM, true));
|
||||
|
||||
if (getExtension().isForge()) {
|
||||
if (fromJar != null) {
|
||||
providers.add(InnerClassRemapper.of(fromJar, getExtension().getMappingsProvider().getMappingsWithSrg(), fromM, toM));
|
||||
}
|
||||
} else {
|
||||
providers.add(out -> JSR_TO_JETBRAINS.forEach(out::acceptClass));
|
||||
}
|
||||
|
||||
return providers;
|
||||
}
|
||||
|
||||
public static Path[] getRemapClasspath(Project project) {
|
||||
return project.getConfigurations().getByName(Constants.Configurations.MINECRAFT_DEPENDENCIES).getFiles()
|
||||
.stream().map(File::toPath).toArray(Path[]::new);
|
||||
|
||||
@@ -119,7 +119,7 @@ public class RemapJarTask extends Jar {
|
||||
|
||||
LoggerFilter.replaceSystemOut();
|
||||
TinyRemapper.Builder remapperBuilder = TinyRemapper.newRemapper();
|
||||
|
||||
remapperBuilder.logger(getProject().getLogger()::lifecycle);
|
||||
remapperBuilder = remapperBuilder.withMappings(TinyRemapperMappingsHelper.create(extension.isForge() ? mappingsProvider.getMappingsWithSrg() : mappingsProvider.getMappings(), fromM, toM, false));
|
||||
|
||||
for (File mixinMapFile : extension.getAllMixinMappings()) {
|
||||
|
||||
Reference in New Issue
Block a user