mirror of
https://github.com/architectury/architectury-loom.git
synced 2026-03-28 04:07:01 -05:00
Merge remote-tracking branch 'upstream/dev/1.3' into dev/1.3
# Conflicts: # build.gradle # src/main/java/net/fabricmc/loom/configuration/mods/ModProcessor.java # src/main/java/net/fabricmc/loom/configuration/providers/minecraft/mapped/AbstractMappedMinecraftProvider.java
This commit is contained in:
@@ -98,7 +98,7 @@ dependencies {
|
||||
}
|
||||
|
||||
// tinyfile management
|
||||
implementation ('dev.architectury:tiny-remapper:1.8.20')
|
||||
implementation ('dev.architectury:tiny-remapper:1.8.20') // TODO: Update
|
||||
implementation 'net.fabricmc:access-widener:2.1.0'
|
||||
implementation 'net.fabricmc:mapping-io:0.2.1'
|
||||
|
||||
|
||||
@@ -174,7 +174,7 @@ public final class IncludedJarFactory {
|
||||
}
|
||||
|
||||
LoomGradleExtension extension = LoomGradleExtension.get(project);
|
||||
File tempDir = new File(extension.getFiles().getUserCache(), "temp/modprocessing");
|
||||
File tempDir = new File(extension.getFiles().getProjectBuildCache(), "temp/modprocessing");
|
||||
|
||||
if (!tempDir.exists()) {
|
||||
tempDir.mkdirs();
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* This file is part of fabric-loom, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2023 FabricMC
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package net.fabricmc.loom.configuration.mods;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import org.objectweb.asm.ClassVisitor;
|
||||
|
||||
import net.fabricmc.accesswidener.AccessWidener;
|
||||
import net.fabricmc.accesswidener.AccessWidenerClassVisitor;
|
||||
import net.fabricmc.accesswidener.AccessWidenerReader;
|
||||
import net.fabricmc.loom.configuration.mods.dependency.ModDependency;
|
||||
import net.fabricmc.loom.util.Constants;
|
||||
import net.fabricmc.tinyremapper.TinyRemapper;
|
||||
|
||||
public record AccessWidenerAnalyzeVisitorProvider(AccessWidener accessWidener) implements TinyRemapper.AnalyzeVisitorProvider {
|
||||
static AccessWidenerAnalyzeVisitorProvider createFromMods(String namespace, List<ModDependency> mods) throws IOException {
|
||||
AccessWidener accessWidener = new AccessWidener();
|
||||
accessWidener.visitHeader(namespace);
|
||||
|
||||
for (ModDependency mod : mods) {
|
||||
final var accessWidenerData = AccessWidenerUtils.readAccessWidenerData(mod.getInputFile());
|
||||
|
||||
if (accessWidenerData == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
final var reader = new AccessWidenerReader(accessWidener);
|
||||
reader.read(accessWidenerData.content());
|
||||
}
|
||||
|
||||
return new AccessWidenerAnalyzeVisitorProvider(accessWidener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClassVisitor insertAnalyzeVisitor(int mrjVersion, String className, ClassVisitor next) {
|
||||
return AccessWidenerClassVisitor.createClassVisitor(Constants.ASM_VERSION, next, accessWidener);
|
||||
}
|
||||
}
|
||||
@@ -167,7 +167,8 @@ public class ModProcessor {
|
||||
.logger(project.getLogger()::lifecycle)
|
||||
.logUnknownInvokeDynamic(false)
|
||||
.withMappings(TinyRemapperHelper.create(mappings, fromM, toM, false))
|
||||
.renameInvalidLocals(false);
|
||||
.renameInvalidLocals(false)
|
||||
.extraAnalyzeVisitor(AccessWidenerAnalyzeVisitorProvider.createFromMods(fromM, remapList));
|
||||
|
||||
final KotlinClasspathService kotlinClasspathService = KotlinClasspathService.getOrCreateIfRequired(serviceManager, project);
|
||||
KotlinRemapperClassloader kotlinRemapperClassloader = null;
|
||||
|
||||
@@ -37,6 +37,7 @@ import org.slf4j.LoggerFactory;
|
||||
import net.fabricmc.loom.api.mappings.intermediate.IntermediateMappingsProvider;
|
||||
|
||||
public abstract class IntermediaryMappingsProvider extends IntermediateMappingsProvider {
|
||||
public static final String NAME = "intermediary-v2";
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(IntermediateMappingsProvider.class);
|
||||
|
||||
public abstract Property<String> getIntermediaryUrl();
|
||||
@@ -68,6 +69,6 @@ public abstract class IntermediaryMappingsProvider extends IntermediateMappingsP
|
||||
|
||||
@Override
|
||||
public @NotNull String getName() {
|
||||
return "intermediary-v2";
|
||||
return NAME;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,6 +49,7 @@ import net.fabricmc.loom.api.mappings.layered.MappingContext;
|
||||
import net.fabricmc.loom.api.mappings.layered.MappingLayer;
|
||||
import net.fabricmc.loom.api.mappings.layered.MappingsNamespace;
|
||||
import net.fabricmc.loom.configuration.providers.mappings.extras.unpick.UnpickLayer;
|
||||
import net.fabricmc.loom.configuration.providers.mappings.utils.AddConstructorMappingVisitor;
|
||||
import net.fabricmc.loom.util.ZipUtils;
|
||||
import net.fabricmc.mappingio.adapter.MappingDstNsReorder;
|
||||
import net.fabricmc.mappingio.adapter.MappingSourceNsSwitch;
|
||||
@@ -102,7 +103,8 @@ public class LayeredMappingsDependency implements SelfResolvingDependency, FileC
|
||||
|
||||
MappingDstNsReorder nsReorder = new MappingDstNsReorder(tiny2Writer, Collections.singletonList(MappingsNamespace.NAMED.toString()));
|
||||
MappingSourceNsSwitch nsSwitch = new MappingSourceNsSwitch(nsReorder, MappingsNamespace.INTERMEDIARY.toString(), true);
|
||||
mappings.accept(nsSwitch);
|
||||
AddConstructorMappingVisitor addConstructor = new AddConstructorMappingVisitor(nsSwitch);
|
||||
mappings.accept(addConstructor);
|
||||
|
||||
Files.deleteIfExists(mappingsFile);
|
||||
ZipUtils.add(mappingsFile, "mappings/mappings.tiny", writer.toString().getBytes(StandardCharsets.UTF_8));
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* This file is part of fabric-loom, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2021 FabricMC
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package net.fabricmc.loom.configuration.providers.mappings.utils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import net.fabricmc.mappingio.MappedElementKind;
|
||||
import net.fabricmc.mappingio.MappingVisitor;
|
||||
import net.fabricmc.mappingio.adapter.ForwardingMappingVisitor;
|
||||
|
||||
/**
|
||||
* Adds the constructor method {@code <init>} to the destination namespaces,
|
||||
* as long as the source name is {@code <init>} and the destination mapping is null.
|
||||
*/
|
||||
public class AddConstructorMappingVisitor extends ForwardingMappingVisitor {
|
||||
private boolean inConstructor;
|
||||
private boolean[] namespaceVisited;
|
||||
|
||||
public AddConstructorMappingVisitor(MappingVisitor next) {
|
||||
super(next);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitNamespaces(String srcNamespace, List<String> dstNamespaces) throws IOException {
|
||||
namespaceVisited = new boolean[dstNamespaces.size()];
|
||||
super.visitNamespaces(srcNamespace, dstNamespaces);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visitMethod(String srcName, String srcDesc) throws IOException {
|
||||
if ("<init>".equals(srcName)) {
|
||||
inConstructor = true;
|
||||
Arrays.fill(namespaceVisited, false);
|
||||
} else {
|
||||
inConstructor = false;
|
||||
}
|
||||
|
||||
return super.visitMethod(srcName, srcDesc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visitElementContent(MappedElementKind targetKind) throws IOException {
|
||||
if (inConstructor) {
|
||||
inConstructor = false;
|
||||
|
||||
for (int i = 0; i < namespaceVisited.length; i++) {
|
||||
if (!namespaceVisited[i]) {
|
||||
visitDstName(targetKind, i, "<init>");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return super.visitElementContent(targetKind);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitDstName(MappedElementKind targetKind, int namespace, String name) throws IOException {
|
||||
namespaceVisited[namespace] = true;
|
||||
super.visitDstName(targetKind, namespace, name);
|
||||
}
|
||||
}
|
||||
@@ -33,6 +33,7 @@ import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.StringJoiner;
|
||||
import java.util.function.Function;
|
||||
|
||||
import dev.architectury.tinyremapper.OutputConsumerPath;
|
||||
@@ -43,6 +44,7 @@ import net.fabricmc.loom.LoomGradleExtension;
|
||||
import net.fabricmc.loom.api.mappings.layered.MappingsNamespace;
|
||||
import net.fabricmc.loom.configuration.ConfigContext;
|
||||
import net.fabricmc.loom.configuration.mods.dependency.LocalMavenHelper;
|
||||
import net.fabricmc.loom.configuration.providers.mappings.IntermediaryMappingsProvider;
|
||||
import net.fabricmc.loom.configuration.providers.mappings.MappingConfiguration;
|
||||
import net.fabricmc.loom.configuration.providers.mappings.TinyMappingsService;
|
||||
import net.fabricmc.loom.configuration.providers.minecraft.MinecraftJar;
|
||||
@@ -141,13 +143,22 @@ public abstract class AbstractMappedMinecraftProvider<M extends MinecraftProvide
|
||||
}
|
||||
|
||||
protected String getName(String name) {
|
||||
String computedName = minecraftProvider.getJarPrefix() + "minecraft-" + name;;
|
||||
final String intermediateName = extension.getIntermediateMappingsProvider().getName();
|
||||
|
||||
if (getTargetNamespace() != MappingsNamespace.NAMED) {
|
||||
computedName = getTargetNamespace().name() + "-" + name;
|
||||
var sj = new StringJoiner("-");
|
||||
sj.add("minecraft");
|
||||
sj.add(name);
|
||||
|
||||
// Include the intermediate mapping name if it's not the default intermediary
|
||||
if (!intermediateName.equals(IntermediaryMappingsProvider.NAME)) {
|
||||
sj.add(intermediateName);
|
||||
}
|
||||
|
||||
return computedName.toLowerCase(Locale.ROOT);
|
||||
if (getTargetNamespace() != MappingsNamespace.NAMED) {
|
||||
sj.add(getTargetNamespace().name());
|
||||
}
|
||||
|
||||
return minecraftProvider.getJarPrefix() + sj.toString().toLowerCase(Locale.ROOT);
|
||||
}
|
||||
|
||||
protected String getVersion() {
|
||||
|
||||
@@ -27,6 +27,7 @@ package net.fabricmc.loom.task;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.UncheckedIOException;
|
||||
import java.nio.charset.CharsetEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
@@ -49,6 +50,8 @@ import net.fabricmc.loom.util.Constants;
|
||||
import net.fabricmc.loom.util.gradle.SyncTaskBuildService;
|
||||
|
||||
public abstract class AbstractRunTask extends JavaExec {
|
||||
private static final CharsetEncoder ASCII_ENCODER = StandardCharsets.US_ASCII.newEncoder();
|
||||
|
||||
private final RunConfig config;
|
||||
// We control the classpath, as we use a ArgFile to pass it over the command line: https://docs.oracle.com/javase/7/docs/technotes/tools/windows/javac.html#commandlineargfile
|
||||
private final ConfigurableFileCollection classpath = getProject().getObjects().fileCollection();
|
||||
@@ -71,10 +74,20 @@ public abstract class AbstractRunTask extends JavaExec {
|
||||
}
|
||||
|
||||
private boolean canUseArgFile() {
|
||||
if (!canPathBeASCIIEncoded()) {
|
||||
// The gradle home or project dir contain chars that cannot be ascii encoded, thus are not supported by an arg file.
|
||||
return false;
|
||||
}
|
||||
|
||||
// @-files were added for java (not javac) in Java 9, see https://bugs.openjdk.org/browse/JDK-8027634
|
||||
return getJavaVersion().isJava9Compatible();
|
||||
}
|
||||
|
||||
private boolean canPathBeASCIIEncoded() {
|
||||
return ASCII_ENCODER.canEncode(getProject().getProjectDir().getAbsolutePath())
|
||||
&& ASCII_ENCODER.canEncode(getProject().getGradle().getGradleUserHomeDir().getAbsolutePath());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exec() {
|
||||
if (canUseArgFile()) {
|
||||
|
||||
@@ -54,6 +54,7 @@ import org.gradle.api.services.ServiceReference;
|
||||
import org.gradle.api.tasks.Input;
|
||||
import org.gradle.api.tasks.InputFile;
|
||||
import org.gradle.api.tasks.InputFiles;
|
||||
import org.gradle.api.tasks.Optional;
|
||||
import org.gradle.api.tasks.OutputFile;
|
||||
import org.gradle.api.tasks.TaskAction;
|
||||
import org.gradle.process.ExecOperations;
|
||||
@@ -80,6 +81,7 @@ import net.fabricmc.loom.decompilers.LineNumberRemapper;
|
||||
import net.fabricmc.loom.decompilers.linemap.LineMapClassFilter;
|
||||
import net.fabricmc.loom.decompilers.linemap.LineMapVisitor;
|
||||
import net.fabricmc.loom.util.Constants;
|
||||
import net.fabricmc.loom.util.ExceptionUtil;
|
||||
import net.fabricmc.loom.util.FileSystemUtil;
|
||||
import net.fabricmc.loom.util.IOStringConsumer;
|
||||
import net.fabricmc.loom.util.Platform;
|
||||
@@ -113,15 +115,19 @@ public abstract class GenerateSourcesTask extends AbstractLoomTask {
|
||||
|
||||
// Unpick
|
||||
@InputFile
|
||||
@Optional
|
||||
public abstract RegularFileProperty getUnpickDefinitions();
|
||||
|
||||
@InputFiles
|
||||
@Optional
|
||||
public abstract ConfigurableFileCollection getUnpickConstantJar();
|
||||
|
||||
@InputFiles
|
||||
@Optional
|
||||
public abstract ConfigurableFileCollection getUnpickClasspath();
|
||||
|
||||
@OutputFile
|
||||
@Optional
|
||||
public abstract RegularFileProperty getUnpickOutputJar();
|
||||
|
||||
// Injects
|
||||
@@ -360,7 +366,7 @@ public abstract class GenerateSourcesTask extends AbstractLoomTask {
|
||||
try (IPCClient ipcClient = new IPCClient(ipcPath)) {
|
||||
doDecompile(new ThreadedSimpleProgressLogger(ipcClient));
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Failed to decompile", e);
|
||||
throw ExceptionUtil.createDescriptiveWrapper(RuntimeException::new, "Failed to decompile", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -41,6 +41,7 @@ import net.fabricmc.loom.configuration.providers.mappings.IntermediateMappingsSe
|
||||
import net.fabricmc.loom.configuration.providers.mappings.LayeredMappingSpec
|
||||
import net.fabricmc.loom.configuration.providers.mappings.LayeredMappingsProcessor
|
||||
import net.fabricmc.loom.configuration.providers.mappings.extras.unpick.UnpickLayer
|
||||
import net.fabricmc.loom.configuration.providers.mappings.utils.AddConstructorMappingVisitor
|
||||
import net.fabricmc.loom.configuration.providers.minecraft.MinecraftProvider
|
||||
import net.fabricmc.loom.test.unit.LoomMocks
|
||||
import net.fabricmc.loom.util.download.Download
|
||||
@@ -109,7 +110,8 @@ abstract class LayeredMappingsSpecification extends Specification implements Lay
|
||||
def reorderedMappings = new MemoryMappingTree()
|
||||
def nsReorder = new MappingDstNsReorder(reorderedMappings, Collections.singletonList(MappingsNamespace.NAMED.toString()))
|
||||
def nsSwitch = new MappingSourceNsSwitch(nsReorder, MappingsNamespace.INTERMEDIARY.toString(), true)
|
||||
mappingTree.accept(nsSwitch)
|
||||
def addConstructor = new AddConstructorMappingVisitor(nsSwitch)
|
||||
mappingTree.accept(addConstructor)
|
||||
return reorderedMappings
|
||||
}
|
||||
|
||||
|
||||
@@ -51,6 +51,7 @@ class ParchmentMappingLayerTest extends LayeredMappingsSpecification {
|
||||
mappings.classes[0].getDstName(0) == "net/minecraft/class_2573"
|
||||
mappings.classes[0].methods[0].args[0].srcName.hashCode() == -1008297992
|
||||
reorderedMappings.getClass("net/minecraft/class_2573").getMethod("method_10913", "(Lnet/minecraft/class_1799;Lnet/minecraft/class_1767;)V").args.size() > 0
|
||||
reorderedMappings.getClass("net/minecraft/class_2573").getMethod("<init>", "()V") != null
|
||||
}
|
||||
|
||||
def "Read parchment mappings remove prefix" () {
|
||||
|
||||
Reference in New Issue
Block a user