From af79dc6c1eadccbfe40225dcf858dbc2de1e2506 Mon Sep 17 00:00:00 2001 From: Juuz <6596629+Juuxel@users.noreply.github.com> Date: Wed, 3 Jul 2024 14:18:52 +0300 Subject: [PATCH] Remove MappingOption.forPlatform This fixes dep AT remapping on Forge 1.20.6+ - the filter was choosing the wrong mapping option as it's only designed for one extra namespace. The optimisation isn't strictly needed. If it's added back in the future, we need to make sure that ModProcessor gets the full mapping tree. --- .../architectury/loom/util/MappingOption.java | 27 ++-------- .../loom/configuration/mods/ModProcessor.java | 2 +- .../loom/util/TinyRemapperHelper.java | 2 +- .../architectury/MappingOptionTest.groovy | 49 ------------------- 4 files changed, 5 insertions(+), 75 deletions(-) delete mode 100644 src/test/groovy/net/fabricmc/loom/test/unit/architectury/MappingOptionTest.groovy diff --git a/src/main/java/dev/architectury/loom/util/MappingOption.java b/src/main/java/dev/architectury/loom/util/MappingOption.java index 47ac2565..4946634e 100644 --- a/src/main/java/dev/architectury/loom/util/MappingOption.java +++ b/src/main/java/dev/architectury/loom/util/MappingOption.java @@ -1,32 +1,11 @@ package dev.architectury.loom.util; -import org.jetbrains.annotations.Nullable; - import net.fabricmc.loom.api.LoomGradleExtensionAPI; -import net.fabricmc.loom.api.mappings.layered.MappingsNamespace; public enum MappingOption { - DEFAULT(null), - WITH_SRG(MappingsNamespace.SRG.toString()), - WITH_MOJANG(MappingsNamespace.MOJANG.toString()); - - private final String extraNamespace; - - MappingOption(@Nullable String extraNamespace) { - this.extraNamespace = extraNamespace; - } - - public MappingOption forNamespaces(String... namespaces) { - if (extraNamespace == null) return this; - - for (String namespace : namespaces) { - if (extraNamespace.equals(namespace)) { - return this; - } - } - - return DEFAULT; - } + DEFAULT, + WITH_SRG, + WITH_MOJANG; public static MappingOption forPlatform(LoomGradleExtensionAPI extension) { return switch (extension.getPlatform().get()) { diff --git a/src/main/java/net/fabricmc/loom/configuration/mods/ModProcessor.java b/src/main/java/net/fabricmc/loom/configuration/mods/ModProcessor.java index 832fdecc..ebe57d24 100644 --- a/src/main/java/net/fabricmc/loom/configuration/mods/ModProcessor.java +++ b/src/main/java/net/fabricmc/loom/configuration/mods/ModProcessor.java @@ -169,7 +169,7 @@ public class ModProcessor { Stopwatch stopwatch = Stopwatch.createStarted(); - MappingOption mappingOption = MappingOption.forPlatform(extension).forNamespaces(fromM, toM); + MappingOption mappingOption = MappingOption.forPlatform(extension); MemoryMappingTree mappings = mappingConfiguration.getMappingsService(serviceManager, mappingOption).getMappingTree(); LoggerFilter.replaceSystemOut(); TinyRemapper.Builder builder = TinyRemapper.newRemapper() diff --git a/src/main/java/net/fabricmc/loom/util/TinyRemapperHelper.java b/src/main/java/net/fabricmc/loom/util/TinyRemapperHelper.java index f182b46b..50e32aca 100644 --- a/src/main/java/net/fabricmc/loom/util/TinyRemapperHelper.java +++ b/src/main/java/net/fabricmc/loom/util/TinyRemapperHelper.java @@ -70,7 +70,7 @@ public final class TinyRemapperHelper { public static TinyRemapper getTinyRemapper(Project project, SharedServiceManager serviceManager, String fromM, String toM, boolean fixRecords, Consumer builderConsumer, Set fromClassNames) throws IOException { LoomGradleExtension extension = LoomGradleExtension.get(project); - final MappingOption mappingOption = MappingOption.forPlatform(extension).forNamespaces(fromM, toM); + final MappingOption mappingOption = MappingOption.forPlatform(extension); MemoryMappingTree mappingTree = extension.getMappingConfiguration().getMappingsService(serviceManager, mappingOption).getMappingTree(); if (fixRecords && !mappingTree.getSrcNamespace().equals(fromM)) { diff --git a/src/test/groovy/net/fabricmc/loom/test/unit/architectury/MappingOptionTest.groovy b/src/test/groovy/net/fabricmc/loom/test/unit/architectury/MappingOptionTest.groovy deleted file mode 100644 index f24f04eb..00000000 --- a/src/test/groovy/net/fabricmc/loom/test/unit/architectury/MappingOptionTest.groovy +++ /dev/null @@ -1,49 +0,0 @@ -/* - * 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.test.unit.architectury - -import spock.lang.Specification - -import static dev.architectury.loom.util.MappingOption.* - -class MappingOptionTest extends Specification { - def "namespace filtering with empty array should not change mapping option"() { - when: - def filtered = mappingOption.forNamespaces(namespaces as String[]) - then: - filtered == expected - where: - mappingOption | namespaces | expected - DEFAULT | [] | DEFAULT - WITH_MOJANG | [] | DEFAULT - WITH_SRG | [] | DEFAULT - DEFAULT | ['a', 'srg'] | DEFAULT - WITH_SRG | ['a', 'srg'] | WITH_SRG - WITH_MOJANG | ['a', 'srg'] | DEFAULT - DEFAULT | ['mojang', 'a'] | DEFAULT - WITH_SRG | ['mojang', 'a'] | DEFAULT - WITH_MOJANG | ['mojang', 'a'] | WITH_MOJANG - } -}