mirror of
https://github.com/architectury/architectury-loom.git
synced 2026-04-02 13:37:45 -05:00
Proper mod depending
This commit is contained in:
@@ -81,7 +81,10 @@ public class LaunchProvider extends DependencyProvider {
|
||||
.argument("client", "fmluserdevclient")
|
||||
|
||||
.argument("server", "--launchTarget")
|
||||
.argument("server", "fmluserdevserver");
|
||||
.argument("server", "fmluserdevserver")
|
||||
|
||||
.property("mixin.env.remapRefMap", "true")
|
||||
.property("net.minecraftforge.gradle.GradleStart.srg.srg-mcp", getExtension().getMappingsProvider().srgToNamedSrg.getAbsolutePath());
|
||||
|
||||
String mixinConfig = getExtension().mixinConfig;
|
||||
|
||||
|
||||
@@ -40,6 +40,7 @@ import java.util.function.Consumer;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.net.UrlEscapers;
|
||||
import net.fabricmc.loom.util.srg.SrgNamedWriter;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.tools.ant.util.StringUtils;
|
||||
import org.gradle.api.Project;
|
||||
@@ -83,6 +84,7 @@ public class MappingsProvider extends DependencyProvider {
|
||||
public File mappingsMixinExport;
|
||||
public Path tinyMappingsWithSrg;
|
||||
public File mixinTinyMappingsWithSrg; // FORGE: The mixin mappings have srg names in intermediary.
|
||||
public File srgToNamedSrg; // FORGE: srg to named in srg file format
|
||||
|
||||
public MappingsProvider(Project project) {
|
||||
super(project);
|
||||
@@ -152,6 +154,7 @@ public class MappingsProvider extends DependencyProvider {
|
||||
tinyMappingsJar = new File(getExtension().getUserCache(), mappingsJar.getName().replace(".jar", "-" + jarClassifier + ".jar"));
|
||||
tinyMappingsWithSrg = mappingsDir.resolve(StringUtils.removeSuffix(mappingsJar.getName(), ".jar") + "-srg.tiny");
|
||||
mixinTinyMappingsWithSrg = mappingsDir.resolve(StringUtils.removeSuffix(mappingsJar.getName(), ".jar") + "-mixin-srg.tiny").toFile();
|
||||
srgToNamedSrg = mappingsDir.resolve(StringUtils.removeSuffix(mappingsJar.getName(), ".jar") + "-srg-named.srg").toFile();
|
||||
|
||||
if (!tinyMappings.exists() || isRefreshDeps()) {
|
||||
storeMappings(getProject(), minecraftProvider, mappingsJar.toPath());
|
||||
@@ -172,6 +175,10 @@ public class MappingsProvider extends DependencyProvider {
|
||||
Files.deleteIfExists(mixinTinyMappingsWithSrg.toPath());
|
||||
Files.write(mixinTinyMappingsWithSrg.toPath(), lines);
|
||||
}
|
||||
|
||||
if (!srgToNamedSrg.exists() || isRefreshDeps()) {
|
||||
SrgNamedWriter.writeTo(getProject().getLogger(), srgToNamedSrg.toPath(), getMappingsWithSrg());
|
||||
}
|
||||
}
|
||||
|
||||
addDependency(tinyMappingsJar, Constants.Configurations.MAPPINGS_FINAL);
|
||||
|
||||
@@ -24,11 +24,20 @@
|
||||
|
||||
package net.fabricmc.loom.providers;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import net.fabricmc.loom.util.Constants;
|
||||
import net.fabricmc.loom.util.DependencyProvider;
|
||||
import net.fabricmc.loom.util.TinyRemapperMappingsHelper;
|
||||
import net.fabricmc.loom.util.srg.AtRemapper;
|
||||
import net.fabricmc.loom.util.srg.CoreModClassRemapper;
|
||||
import net.fabricmc.mapping.tree.TinyTree;
|
||||
import net.fabricmc.tinyremapper.NonClassCopyMode;
|
||||
import net.fabricmc.tinyremapper.OutputConsumerPath;
|
||||
import net.fabricmc.tinyremapper.TinyRemapper;
|
||||
import org.gradle.api.Project;
|
||||
import org.zeroturnaround.zip.ZipUtil;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.URI;
|
||||
import java.nio.file.FileSystem;
|
||||
import java.nio.file.FileSystems;
|
||||
@@ -41,19 +50,6 @@ import java.util.function.Consumer;
|
||||
import java.util.jar.Attributes;
|
||||
import java.util.jar.Manifest;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import org.gradle.api.Project;
|
||||
|
||||
import net.fabricmc.loom.util.TinyRemapperMappingsHelper;
|
||||
import net.fabricmc.loom.util.srg.AtRemapper;
|
||||
import net.fabricmc.loom.util.srg.CoreModClassRemapper;
|
||||
import net.fabricmc.mapping.tree.TinyTree;
|
||||
import net.fabricmc.tinyremapper.NonClassCopyMode;
|
||||
import net.fabricmc.tinyremapper.OutputConsumerPath;
|
||||
import net.fabricmc.tinyremapper.TinyRemapper;
|
||||
import net.fabricmc.loom.util.Constants;
|
||||
import net.fabricmc.loom.util.DependencyProvider;
|
||||
|
||||
public class MinecraftMappedProvider extends DependencyProvider {
|
||||
private static final Map<String, String> JSR_TO_JETBRAINS = new ImmutableMap.Builder<String, String>()
|
||||
.put("javax/annotation/Nullable", "org/jetbrains/annotations/Nullable")
|
||||
@@ -64,6 +60,7 @@ public class MinecraftMappedProvider extends DependencyProvider {
|
||||
private File inputJar;
|
||||
private File minecraftMappedJar;
|
||||
private File minecraftIntermediaryJar;
|
||||
private File minecraftSrgJar;
|
||||
|
||||
private MinecraftProvider minecraftProvider;
|
||||
|
||||
@@ -83,7 +80,7 @@ public class MinecraftMappedProvider extends DependencyProvider {
|
||||
|
||||
boolean isForgeAtDirty = getExtension().isForge() && getExtension().getMappingsProvider().patchedProvider.isAtDirty();
|
||||
|
||||
if (!minecraftMappedJar.exists() || !getIntermediaryJar().exists() || isRefreshDeps() || isForgeAtDirty) {
|
||||
if (!minecraftMappedJar.exists() || !getIntermediaryJar().exists() || (getExtension().isForge() && !getSrgJar().exists()) || isRefreshDeps() || isForgeAtDirty) {
|
||||
if (minecraftMappedJar.exists()) {
|
||||
minecraftMappedJar.delete();
|
||||
}
|
||||
@@ -93,6 +90,10 @@ public class MinecraftMappedProvider extends DependencyProvider {
|
||||
if (minecraftIntermediaryJar.exists()) {
|
||||
minecraftIntermediaryJar.delete();
|
||||
}
|
||||
|
||||
if (getExtension().isForge() && minecraftSrgJar.exists()) {
|
||||
minecraftSrgJar.delete();
|
||||
}
|
||||
|
||||
try {
|
||||
mapMinecraftJar();
|
||||
@@ -100,6 +101,9 @@ public class MinecraftMappedProvider extends DependencyProvider {
|
||||
// Cleanup some some things that may be in a bad state now
|
||||
minecraftMappedJar.delete();
|
||||
minecraftIntermediaryJar.delete();
|
||||
if (getExtension().isForge()) {
|
||||
minecraftSrgJar.delete();
|
||||
}
|
||||
getExtension().getMappingsProvider().cleanFiles();
|
||||
throw new RuntimeException("Failed to remap minecraft", t);
|
||||
}
|
||||
@@ -120,9 +124,10 @@ public class MinecraftMappedProvider extends DependencyProvider {
|
||||
Path input = inputJar.toPath();
|
||||
Path outputMapped = minecraftMappedJar.toPath();
|
||||
Path outputIntermediary = minecraftIntermediaryJar.toPath();
|
||||
Path outputSrg = minecraftSrgJar == null ? null : minecraftSrgJar.toPath();
|
||||
|
||||
for (String toM : Arrays.asList("named", "intermediary")) {
|
||||
Path output = "named".equals(toM) ? outputMapped : outputIntermediary;
|
||||
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 + ")");
|
||||
|
||||
@@ -144,7 +149,7 @@ public class MinecraftMappedProvider extends DependencyProvider {
|
||||
remapper.finish();
|
||||
}
|
||||
|
||||
if (getExtension().isForge()) {
|
||||
if (getExtension().isForge() && !"srg".equals(toM)) {
|
||||
getProject().getLogger().lifecycle(":running forge finalising tasks");
|
||||
|
||||
// TODO: Relocate this to its own class
|
||||
@@ -183,7 +188,7 @@ public class MinecraftMappedProvider extends DependencyProvider {
|
||||
|
||||
public TinyRemapper getTinyRemapper(String fromM, String toM) throws IOException {
|
||||
TinyRemapper.Builder builder = TinyRemapper.newRemapper()
|
||||
.withMappings(TinyRemapperMappingsHelper.create(getExtension().getMappingsProvider().getMappings(), fromM, toM, true))
|
||||
.withMappings(TinyRemapperMappingsHelper.create(getExtension().isForge() ? getExtension().getMappingsProvider().getMappingsWithSrg() : getExtension().getMappingsProvider().getMappings(), fromM, toM, true))
|
||||
.renameInvalidLocals(true)
|
||||
.rebuildSourceFilenames(true);
|
||||
|
||||
@@ -213,6 +218,7 @@ public class MinecraftMappedProvider extends DependencyProvider {
|
||||
public void initFiles(MinecraftProvider minecraftProvider, MappingsProvider mappingsProvider) {
|
||||
this.minecraftProvider = minecraftProvider;
|
||||
minecraftIntermediaryJar = new File(getExtension().getUserCache(), "minecraft-" + getJarVersionString("intermediary") + ".jar");
|
||||
minecraftSrgJar = !getExtension().isForge() ? null : new File(getExtension().getUserCache(), "minecraft-" + getJarVersionString("srg") + ".jar");
|
||||
minecraftMappedJar = new File(getJarDirectory(getExtension().getUserCache(), "mapped"), "minecraft-" + getJarVersionString("mapped") + ".jar");
|
||||
inputJar = getExtension().isForge() ? mappingsProvider.patchedProvider.getMergedJar() : minecraftProvider.getMergedJar();
|
||||
}
|
||||
@@ -232,6 +238,10 @@ public class MinecraftMappedProvider extends DependencyProvider {
|
||||
public File getIntermediaryJar() {
|
||||
return minecraftIntermediaryJar;
|
||||
}
|
||||
|
||||
public File getSrgJar() {
|
||||
return minecraftSrgJar;
|
||||
}
|
||||
|
||||
public File getMappedJar() {
|
||||
return minecraftMappedJar;
|
||||
|
||||
@@ -139,7 +139,7 @@ public class ModProcessor {
|
||||
MinecraftMappedProvider mappedProvider = extension.getMinecraftMappedProvider();
|
||||
MappingsProvider mappingsProvider = extension.getMappingsProvider();
|
||||
|
||||
Path mc = mappedProvider.getIntermediaryJar().toPath();
|
||||
Path mc = extension.isForge() ? mappedProvider.getSrgJar().toPath() : mappedProvider.getIntermediaryJar().toPath();
|
||||
Path[] mcDeps = mappedProvider.getMapperPaths().stream().map(File::toPath).toArray(Path[]::new);
|
||||
|
||||
List<ModDependencyInfo> remapList = processList.stream().filter(ModDependencyInfo::requiresRemapping).collect(Collectors.toList());
|
||||
|
||||
@@ -178,6 +178,9 @@ public class SourceRemapper {
|
||||
|
||||
m.getClassPath().add(extension.getMinecraftMappedProvider().getMappedJar().toPath());
|
||||
m.getClassPath().add(extension.getMinecraftMappedProvider().getIntermediaryJar().toPath());
|
||||
if (extension.isForge()) {
|
||||
m.getClassPath().add(extension.getMinecraftMappedProvider().getSrgJar().toPath());
|
||||
}
|
||||
|
||||
Dependency annotationDependency = extension.getDependencyManager().getProvider(LaunchProvider.class).annotationDependency;
|
||||
Set<File> files = project.getConfigurations().getByName("compileOnly")
|
||||
|
||||
@@ -24,21 +24,19 @@
|
||||
|
||||
package net.fabricmc.loom.util.srg;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.nio.file.FileSystem;
|
||||
import java.nio.file.FileSystems;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
import net.fabricmc.loom.util.function.CollectionUtil;
|
||||
import net.fabricmc.mapping.tree.TinyTree;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.gradle.api.logging.Logger;
|
||||
import org.zeroturnaround.zip.ZipUtil;
|
||||
import org.zeroturnaround.zip.transform.StringZipEntryTransformer;
|
||||
import org.zeroturnaround.zip.transform.ZipEntryTransformerEntry;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.zip.ZipEntry;
|
||||
|
||||
/**
|
||||
* Remaps AT classes from SRG to Yarn.
|
||||
@@ -47,21 +45,20 @@ import org.gradle.api.logging.Logger;
|
||||
*/
|
||||
public final class AtRemapper {
|
||||
public static void remap(Logger logger, Path jar, TinyTree mappings) throws IOException {
|
||||
try (FileSystem fs = FileSystems.newFileSystem(URI.create("jar:" + jar.toUri()), ImmutableMap.of("create", false))) {
|
||||
Path atPath = fs.getPath("META-INF", "accesstransformer.cfg");
|
||||
|
||||
if (Files.exists(atPath)) {
|
||||
List<String> lines = Files.readAllLines(atPath);
|
||||
List<String> output = new ArrayList<>(lines.size());
|
||||
|
||||
for (int i = 0; i < lines.size(); i++) {
|
||||
String line = lines.get(i).trim();
|
||||
|
||||
ZipUtil.transformEntries(jar.toFile(), new ZipEntryTransformerEntry[]{(new ZipEntryTransformerEntry("META-INF/accesstransformer.cfg", new StringZipEntryTransformer() {
|
||||
@Override
|
||||
protected String transform(ZipEntry zipEntry, String input) {
|
||||
String[] lines = input.split("\n");
|
||||
List<String> output = new ArrayList<>(lines.length);
|
||||
|
||||
for (int i = 0; i < lines.length; i++) {
|
||||
String line = lines[i].trim();
|
||||
|
||||
if (line.startsWith("#") || StringUtils.isBlank(line)) {
|
||||
output.add(i, line);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
String[] parts = line.split(" ");
|
||||
if (parts.length < 2) {
|
||||
logger.warn("Invalid AT Line: " + line);
|
||||
@@ -73,15 +70,12 @@ public final class AtRemapper {
|
||||
mappings.getClasses(),
|
||||
def -> def.getName("srg").equals(name)
|
||||
).map(def -> def.getName("named")).orElse(name).replace('/', '.');
|
||||
|
||||
|
||||
output.add(i, String.join(" ", parts));
|
||||
}
|
||||
|
||||
if (!lines.equals(output)) {
|
||||
Files.delete(atPath);
|
||||
Files.write(atPath, output);
|
||||
}
|
||||
|
||||
return String.join("\n", output);
|
||||
}
|
||||
}
|
||||
}))});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,28 +24,27 @@
|
||||
|
||||
package net.fabricmc.loom.util.srg;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import net.fabricmc.loom.util.function.CollectionUtil;
|
||||
import net.fabricmc.mapping.tree.TinyTree;
|
||||
import org.apache.logging.log4j.util.Strings;
|
||||
import org.gradle.api.logging.Logger;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.io.Writer;
|
||||
import java.net.URI;
|
||||
import java.nio.file.FileSystem;
|
||||
import java.nio.file.FileSystems;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import org.gradle.api.logging.Logger;
|
||||
|
||||
import net.fabricmc.loom.util.function.CollectionUtil;
|
||||
import net.fabricmc.mapping.tree.TinyTree;
|
||||
|
||||
/**
|
||||
* Remaps coremod class names from SRG to Yarn.
|
||||
*
|
||||
@@ -102,10 +101,11 @@ public final class CoreModClassRemapper {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!lines.equals(output)) {
|
||||
Files.delete(js);
|
||||
Files.write(js, output);
|
||||
try (Writer writer = Files.newBufferedWriter(js, StandardCharsets.UTF_8, StandardOpenOption.WRITE)) {
|
||||
writer.write(String.join(Strings.LINE_SEPARATOR, output));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
21
src/main/java/net/fabricmc/loom/util/srg/SrgNamedWriter.java
Normal file
21
src/main/java/net/fabricmc/loom/util/srg/SrgNamedWriter.java
Normal file
@@ -0,0 +1,21 @@
|
||||
package net.fabricmc.loom.util.srg;
|
||||
|
||||
import net.fabricmc.lorenztiny.TinyMappingsReader;
|
||||
import net.fabricmc.mapping.tree.TinyTree;
|
||||
import org.cadixdev.lorenz.io.srg.SrgWriter;
|
||||
import org.gradle.api.logging.Logger;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
public class SrgNamedWriter {
|
||||
public static void writeTo(Logger logger, Path srgFile, TinyTree mappings) throws IOException {
|
||||
Files.deleteIfExists(srgFile);
|
||||
try (SrgWriter writer = new SrgWriter(Files.newBufferedWriter(srgFile))) {
|
||||
try (TinyMappingsReader reader = new TinyMappingsReader(mappings, "srg", "named")) {
|
||||
writer.write(reader.read());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user