Skip to content

Commit

Permalink
Merge remote-tracking branch 'FabricMC/exp/1.5' into exp/1.5
Browse files Browse the repository at this point in the history
# Conflicts:
#	build.gradle
#	gradle/libs.versions.toml
#	src/main/java/net/fabricmc/loom/configuration/ide/RunConfigSettings.java
#	src/main/java/net/fabricmc/loom/configuration/mods/ModProcessor.java
#	src/main/java/net/fabricmc/loom/configuration/providers/mappings/MappingConfiguration.java
#	src/test/groovy/net/fabricmc/loom/test/integration/FabricAPITest.groovy
  • Loading branch information
shedaniel committed Nov 17, 2023
2 parents 63b4761 + 7c3bec3 commit ea1d58e
Show file tree
Hide file tree
Showing 30 changed files with 396 additions and 69 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
}

group = "dev.architectury"
def baseVersion = '1.4'
def baseVersion = '1.5'

def ENV = System.getenv()
def runNumber = ENV.GITHUB_RUN_NUMBER ?: "9999"
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ guava = "32.1.2-jre"
stitch = "0.6.2"
tiny-remapper = "1.10.23"
access-widener = "2.1.0"
mapping-io = "0.4.2"
mapping-io = "0.5.0-beta.3"
lorenz-tiny = "4.0.2"
mercury = "0.1.2.15"
kotlinx-metadata = "0.7.0"
Expand Down
2 changes: 1 addition & 1 deletion gradle/test.libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ mockito = "5.4.0"
java-debug = "0.48.0"
mixin = "0.11.4+mixin.0.8.5"

gradle-nightly = "8.5-20230908221250+0000"
gradle-nightly = "8.6-20231107135843+0000"
fabric-loader = "0.14.22"
fabric-installer = "0.11.1"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ public void configureDataGeneration(Action<DataGenerationSettings> action) {
// Create a classpath group for this mod. Assume that the main sourceset is already in a group.
mod.sourceSet(DATAGEN_SOURCESET_NAME);
});

extension.createRemapConfigurations(sourceSets.getByName(DATAGEN_SOURCESET_NAME));
}

if (settings.getCreateRunConfiguration().get()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,11 @@ public void client() {
environment("client");
defaultMainClass(Constants.Knot.KNOT_CLIENT);

if (Platform.CURRENT.isRaspberryPi()) {
getProject().getLogger().info("Raspberry Pi detected, setting MESA_GL_VERSION_OVERRIDE=4.3");
environmentVariable("MESA_GL_VERSION_OVERRIDE", "4.3");
}

if (getExtension().isForgeLike()) {
forgeTemplate("client");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* 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.BufferedReader;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;

import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;

import net.fabricmc.loom.LoomGradlePlugin;
import net.fabricmc.loom.util.FileSystemUtil;
import net.fabricmc.loom.util.fmj.FabricModJson;
import net.fabricmc.loom.util.fmj.FabricModJsonFactory;

public final class MixinDetector {
public static boolean hasMixinsWithoutRefmap(Path modJar) throws IOException {
try (FileSystemUtil.Delegate fs = FileSystemUtil.getJarFileSystem(modJar)) {
final List<String> mixinConfigs = getMixinConfigs(modJar);

if (!mixinConfigs.isEmpty()) {
for (String mixinConfig : mixinConfigs) {
final Path configPath = fs.getPath(mixinConfig);
if (Files.notExists(configPath)) continue;

try (BufferedReader reader = Files.newBufferedReader(configPath)) {
final JsonObject json = LoomGradlePlugin.GSON.fromJson(reader, JsonObject.class);

if (!json.has("refmap")) {
// We found a mixin config with no refmap, exit the loop.
return true;
}
} catch (JsonParseException e) {
throw new RuntimeException("Could not parse mixin config %s from jar %s".formatted(mixinConfig, modJar.toAbsolutePath()), e);
}
}
}

return false;
}
}

private static List<String> getMixinConfigs(Path modJar) {
// Nullable because we don't care here if we can't read it.
// We can just assume there are no mixins.
final FabricModJson fabricModJson = FabricModJsonFactory.createFromZipNullable(modJar);
return fabricModJson != null ? fabricModJson.getMixinConfigurations() : List.of();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.jar.Manifest;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -187,9 +189,9 @@ private void remapJars(List<ModDependency> remapList) throws IOException {
builder.extension(kotlinRemapperClassloader.getTinyRemapperExtension());
}

if (extension.isNeoForge()) {
builder.extension(new MixinExtension());
}
final Set<InputTag> hasMixinsWithoutRefmaps = new HashSet<>();
// Configure the mixin extension to remap mixins from mod jars detected not to contain refmaps.
builder.extension(new MixinExtension(tag -> extension.isNeoForge() || hasMixinsWithoutRefmaps.contains(tag)));

final TinyRemapper remapper = builder.build();

Expand Down Expand Up @@ -218,6 +220,12 @@ private void remapJars(List<ModDependency> remapList) throws IOException {

project.getLogger().debug("Adding " + info.getInputFile() + " as a remap input");

// Note: this is done at a jar level, not at the level of an individual mixin config.
// If a mod has multiple mixin configs, it's assumed that either all or none of them have refmaps.
if (MixinDetector.hasMixinsWithoutRefmap(info.getInputFile())) {
hasMixinsWithoutRefmaps.add(tag);
}

remapper.readInputsAsync(tag, info.getInputFile());
tagMap.put(info, tag);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
import net.fabricmc.loom.util.service.SharedService;
import net.fabricmc.loom.util.service.SharedServiceManager;
import net.fabricmc.mappingio.adapter.MappingNsCompleter;
import net.fabricmc.mappingio.format.Tiny2Reader;
import net.fabricmc.mappingio.format.tiny.Tiny2FileReader;
import net.fabricmc.mappingio.tree.MemoryMappingTree;

public final class IntermediateMappingsService implements SharedService {
Expand Down Expand Up @@ -90,7 +90,7 @@ private MemoryMappingTree createMemoryMappingTree() {
MappingNsCompleter nsCompleter = new MappingNsCompleter(tree, Collections.singletonMap(MappingsNamespace.NAMED.toString(), MappingsNamespace.INTERMEDIARY.toString()), true);

try (BufferedReader reader = Files.newBufferedReader(getIntermediaryTiny(), StandardCharsets.UTF_8)) {
Tiny2Reader.read(reader, nsCompleter);
Tiny2FileReader.read(reader, nsCompleter);
}
} catch (IOException e) {
throw new UncheckedIOException("Failed to read intermediary mappings", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
import net.fabricmc.loom.util.ZipUtils;
import net.fabricmc.mappingio.adapter.MappingDstNsReorder;
import net.fabricmc.mappingio.adapter.MappingSourceNsSwitch;
import net.fabricmc.mappingio.format.Tiny2Writer;
import net.fabricmc.mappingio.format.tiny.Tiny2FileWriter;
import net.fabricmc.mappingio.tree.MemoryMappingTree;

public class LayeredMappingsDependency implements SelfResolvingDependency, FileCollectionDependency {
Expand Down Expand Up @@ -99,7 +99,7 @@ private void writeMapping(LayeredMappingsProcessor processor, List<MappingLayer>
MemoryMappingTree mappings = processor.getMappings(layers);

try (Writer writer = new StringWriter()) {
Tiny2Writer tiny2Writer = new Tiny2Writer(writer, false);
var tiny2Writer = new Tiny2FileWriter(writer, false);

MappingDstNsReorder nsReorder = new MappingDstNsReorder(tiny2Writer, Collections.singletonList(MappingsNamespace.NAMED.toString()));
MappingSourceNsSwitch nsSwitch = new MappingSourceNsSwitch(nsReorder, MappingsNamespace.INTERMEDIARY.toString(), true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ private boolean isMCP(Path path) throws IOException {

private static boolean areMappingsV2(Path path) throws IOException {
try (BufferedReader reader = Files.newBufferedReader(path)) {
return MappingReader.detectFormat(reader) == MappingFormat.TINY_2;
return MappingReader.detectFormat(reader) == MappingFormat.TINY_2_FILE;
} catch (NoSuchFileException e) {
// TODO: just check the mappings version when Parser supports V1 in readMetadata()
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ private void visit(Path path, MappingVisitor mappingVisitor) throws IOException
);
MappingNsRenamer renamer = new MappingNsRenamer(nsSwitch, fallbackNamespaceReplacements);

MappingReader.read(path, enigma ? MappingFormat.ENIGMA : null, renamer);
MappingReader.read(path, enigma ? MappingFormat.ENIGMA_DIR : null, renamer);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
import net.fabricmc.loom.configuration.providers.mappings.utils.DstNameFilterMappingVisitor;
import net.fabricmc.mappingio.MappingVisitor;
import net.fabricmc.mappingio.adapter.MappingSourceNsSwitch;
import net.fabricmc.mappingio.format.ProGuardReader;
import net.fabricmc.mappingio.format.proguard.ProGuardFileReader;

public record MojangMappingLayer(String minecraftVersion,
Path clientMappings,
Expand All @@ -63,8 +63,8 @@ public void visit(MappingVisitor mappingVisitor) throws IOException {

try (BufferedReader clientBufferedReader = Files.newBufferedReader(clientMappings, StandardCharsets.UTF_8);
BufferedReader serverBufferedReader = Files.newBufferedReader(serverMappings, StandardCharsets.UTF_8)) {
ProGuardReader.read(clientBufferedReader, MappingsNamespace.NAMED.toString(), MappingsNamespace.OFFICIAL.toString(), nsSwitch);
ProGuardReader.read(serverBufferedReader, MappingsNamespace.NAMED.toString(), MappingsNamespace.OFFICIAL.toString(), nsSwitch);
ProGuardFileReader.read(clientBufferedReader, MappingsNamespace.NAMED.toString(), MappingsNamespace.OFFICIAL.toString(), nsSwitch);
ProGuardFileReader.read(serverBufferedReader, MappingsNamespace.NAMED.toString(), MappingsNamespace.OFFICIAL.toString(), nsSwitch);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@
import net.fabricmc.loom.configuration.providers.mappings.IntermediateMappingsService;
import net.fabricmc.mappingio.adapter.MappingNsCompleter;
import net.fabricmc.mappingio.adapter.MappingSourceNsSwitch;
import net.fabricmc.mappingio.format.Tiny2Reader;
import net.fabricmc.mappingio.format.Tiny2Writer;
import net.fabricmc.mappingio.format.tiny.Tiny2FileReader;
import net.fabricmc.mappingio.format.tiny.Tiny2FileWriter;
import net.fabricmc.mappingio.tree.MappingTree;
import net.fabricmc.mappingio.tree.MemoryMappingTree;

Expand All @@ -57,7 +57,7 @@ public static void mergeAndSaveMappings(Path from, Path out, IntermediateMapping
intermediateMappingsService.getMemoryMappingTree().accept(new MappingSourceNsSwitch(intermediaryTree, MappingsNamespace.INTERMEDIARY.toString()));

try (BufferedReader reader = Files.newBufferedReader(from, StandardCharsets.UTF_8)) {
Tiny2Reader.read(reader, intermediaryTree);
Tiny2FileReader.read(reader, intermediaryTree);
}

MemoryMappingTree officialTree = new MemoryMappingTree();
Expand All @@ -67,7 +67,7 @@ public static void mergeAndSaveMappings(Path from, Path out, IntermediateMapping

inheritMappedNamesOfEnclosingClasses(officialTree);

try (Tiny2Writer writer = new Tiny2Writer(Files.newBufferedWriter(out, StandardCharsets.UTF_8), false)) {
try (var writer = new Tiny2FileWriter(Files.newBufferedWriter(out, StandardCharsets.UTF_8), false)) {
officialTree.accept(writer);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public static TinyJarInfo get(Path jar) {
private static boolean doesJarContainV2Mappings(Path path) throws IOException {
try (FileSystemUtil.Delegate delegate = FileSystemUtil.getJarFileSystem(path)) {
try (BufferedReader reader = Files.newBufferedReader(delegate.fs().getPath("mappings", "mappings.tiny"))) {
return MappingReader.detectFormat(reader) == MappingFormat.TINY_2;
return MappingReader.detectFormat(reader) == MappingFormat.TINY_2_FILE;
}
} catch (NoSuchFileException e) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import java.nio.file.Path;
import java.util.Objects;

public abstract sealed class MinecraftJar permits MinecraftJar.Merged, MinecraftJar.Common, MinecraftJar.ServerOnly, MinecraftJar.ClientOnly {
public abstract sealed class MinecraftJar permits MinecraftJar.Client, MinecraftJar.ClientOnly, MinecraftJar.Common, MinecraftJar.Merged, MinecraftJar.Server {
private final Path path;
private final boolean merged, client, server;
private final String name;
Expand Down Expand Up @@ -68,8 +68,10 @@ public String getName() {
public abstract MinecraftJar forPath(Path path);

public static final class Merged extends MinecraftJar {
public static final String NAME = "merged";

public Merged(Path path) {
super(path, true, true, true, "merged");
super(path, true, true, true, NAME);
}

@Override
Expand All @@ -79,8 +81,10 @@ public MinecraftJar forPath(Path path) {
}

public static final class Common extends MinecraftJar {
public static final String NAME = "common";

public Common(Path path) {
super(path, false, false, true, "common");
super(path, false, false, true, NAME);
}

@Override
Expand All @@ -89,20 +93,39 @@ public MinecraftJar forPath(Path path) {
}
}

public static final class ServerOnly extends MinecraftJar {
public ServerOnly(Path path) {
super(path, false, false, true, "serverOnly");
public static final class Server extends MinecraftJar {
public static final String NAME = "server";

public Server(Path path) {
super(path, false, false, true, NAME);
}

@Override
public MinecraftJar forPath(Path path) {
return new Server(path);
}
}

// Un-split client jar
public static final class Client extends MinecraftJar {
public static final String NAME = "client";

public Client(Path path) {
super(path, false, true, false, NAME);
}

@Override
public MinecraftJar forPath(Path path) {
return new ServerOnly(path);
return new Client(path);
}
}

// Split client jar
public static final class ClientOnly extends MinecraftJar {
public static final String NAME = "clientOnly";

public ClientOnly(Path path) {
super(path, false, true, false, "clientOnly");
super(path, false, true, false, NAME);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,13 @@ public static final class Split extends MinecraftSourceSets {
@Override
public void applyDependencies(BiConsumer<String, String> consumer, List<String> targets) {
Preconditions.checkArgument(targets.size() == 2);
Preconditions.checkArgument(targets.contains("common"));
Preconditions.checkArgument(targets.contains("clientOnly"));
Preconditions.checkArgument(targets.contains(MinecraftJar.Common.NAME));
Preconditions.checkArgument(targets.contains(MinecraftJar.ClientOnly.NAME));

consumer.accept(MINECRAFT_COMMON_NAMED.runtime(), "common");
consumer.accept(MINECRAFT_CLIENT_ONLY_NAMED.runtime(), "clientOnly");
consumer.accept(MINECRAFT_COMMON_NAMED.compile(), "common");
consumer.accept(MINECRAFT_CLIENT_ONLY_NAMED.compile(), "clientOnly");
consumer.accept(MINECRAFT_COMMON_NAMED.runtime(), MinecraftJar.Common.NAME);
consumer.accept(MINECRAFT_CLIENT_ONLY_NAMED.runtime(), MinecraftJar.ClientOnly.NAME);
consumer.accept(MINECRAFT_COMMON_NAMED.compile(), MinecraftJar.Common.NAME);
consumer.accept(MINECRAFT_CLIENT_ONLY_NAMED.compile(), MinecraftJar.ClientOnly.NAME);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,22 @@
import java.util.function.Function;

public enum SingleJarEnvType {
CLIENT(MinecraftJar.ClientOnly::new),
SERVER(MinecraftJar.ServerOnly::new);
CLIENT(MinecraftJar.Client::new, MinecraftJar.Client.NAME),
SERVER(MinecraftJar.Server::new, MinecraftJar.Server.NAME);

private final Function<Path, MinecraftJar> jarFunction;
private final String name;

SingleJarEnvType(Function<Path, MinecraftJar> jarFunction) {
SingleJarEnvType(Function<Path, MinecraftJar> jarFunction, String name) {
this.jarFunction = jarFunction;
this.name = name;
}

public Function<Path, MinecraftJar> getJar() {
return jarFunction;
}

public String getName() {
return name;
}
}
Loading

0 comments on commit ea1d58e

Please sign in to comment.