From 6ab248b3879d265fe32ee1cd7f2e09005f57a801 Mon Sep 17 00:00:00 2001 From: js6pak Date: Wed, 1 Nov 2023 21:29:38 +0100 Subject: [PATCH] Babric-ify --- .github/workflows/test-push.yml | 145 ------------------ build.gradle | 16 +- gradle.properties | 2 +- gradle/libs.versions.toml | 8 +- gradle/runtime.libs.versions.toml | 4 +- .../fabricmc/loom/LoomGradleExtension.java | 3 +- .../loom/api/LoomGradleExtensionAPI.java | 4 + .../mappings/layered/MappingsNamespace.java | 20 ++- .../configuration/CompileConfiguration.java | 4 +- .../loom/configuration/ide/RunConfig.java | 1 + .../mappings/IntermediateMappingsService.java | 4 +- .../mappings/MappingConfiguration.java | 3 + .../mappings/tiny/MappingsMerger.java | 6 +- .../minecraft/GluedMinecraftProvider.java | 97 ++++++++++++ .../minecraft/MergedMinecraftProvider.java | 28 ++-- .../minecraft/MinecraftJarConfiguration.java | 8 + .../minecraft/MinecraftProvider.java | 10 +- .../AbstractMappedMinecraftProvider.java | 2 +- .../mapped/IntermediaryMinecraftProvider.java | 16 +- .../mapped/NamedMinecraftProvider.java | 19 +++ .../ProcessedNamedMinecraftProvider.java | 12 ++ .../loom/util/TinyRemapperHelper.java | 5 + .../loom/util/gradle/GradleUtils.java | 2 +- 23 files changed, 234 insertions(+), 185 deletions(-) delete mode 100644 .github/workflows/test-push.yml create mode 100644 src/main/java/net/fabricmc/loom/configuration/providers/minecraft/GluedMinecraftProvider.java diff --git a/.github/workflows/test-push.yml b/.github/workflows/test-push.yml deleted file mode 100644 index 54e2b1b0a2..0000000000 --- a/.github/workflows/test-push.yml +++ /dev/null @@ -1,145 +0,0 @@ -name: Run Tests -on: [push, pull_request] - -concurrency: - group: build-${{ github.event.pull_request.number || github.ref }} - cancel-in-progress: true - -jobs: - build: - strategy: - fail-fast: false - matrix: - version: [8.3.0-jdk17] - runs-on: ubuntu-22.04 - container: - image: gradle:${{ matrix.version }} - options: --user root - steps: - - uses: actions/checkout@v4 - - uses: gradle/wrapper-validation-action@v1 - - run: gradle build check -x test --stacktrace --warning-mode fail - - build_windows: - runs-on: windows-2022 - steps: - - uses: actions/checkout@v4 - - name: setup jdk - uses: actions/setup-java@v4 - with: - java-version: 17 - distribution: 'temurin' - - uses: gradle/wrapper-validation-action@v1 - - run: ./gradlew build check -x test --stacktrace --warning-mode fail - - # This job is used to feed the test matrix of next job to allow the tests to run in parallel - prepare_test_matrix: - # Lets wait to ensure it builds before going running tests - needs: build - - runs-on: ubuntu-22.04 - container: - image: gradle:8.3.0-jdk17 - options: --user root - - steps: - - uses: actions/checkout@v4 - - run: gradle writeActionsTestMatrix --stacktrace --warning-mode fail - - - id: set-matrix - run: echo "matrix=$(cat build/test_matrix.json)" >> $GITHUB_OUTPUT - - outputs: - matrix: ${{ steps.set-matrix.outputs.matrix }} - - run_tests: - needs: prepare_test_matrix - - strategy: - fail-fast: false - matrix: - version: [8.3.0-jdk17] - test: ${{ fromJson(needs.prepare_test_matrix.outputs.matrix) }} - - runs-on: ubuntu-22.04 - container: - image: gradle:${{ matrix.version }} - options: --user root - - steps: - - uses: actions/checkout@v4 - - run: gradle printActionsTestName --name="${{ matrix.test }}" test --tests ${{ matrix.test }} --stacktrace --warning-mode fail - env: - TEST_WARNING_MODE: fail - id: test - - - uses: actions/upload-artifact@v3 - if: ${{ failure() }} - with: - name: ${{ steps.test.outputs.test }} Results - path: build/reports/ - - uses: actions/upload-artifact@v3 - if: ${{ failure() }} - with: - name: ${{ steps.test.outputs.test }} Heap Dump - path: "*.hprof" - - run_tests_windows: - needs: prepare_test_matrix - - strategy: - fail-fast: false - matrix: - java: [17] - test: ${{ fromJson(needs.prepare_test_matrix.outputs.matrix) }} - - runs-on: windows-2022 - - steps: - - uses: actions/checkout@v4 - - name: setup jdk ${{ matrix.java }} - uses: actions/setup-java@v4 - with: - java-version: ${{ matrix.java }} - distribution: 'temurin' - - run: ./gradlew printActionsTestName --name="${{ matrix.test }}" test --tests ${{ matrix.test }} --stacktrace --warning-mode fail - env: - TEST_WARNING_MODE: fail - id: test - - - uses: actions/upload-artifact@v3 - if: ${{ failure() }} - with: - name: ${{ steps.test.outputs.test }} (${{ matrix.java }}) Results (Windows) - path: build/reports/ - - uses: actions/upload-artifact@v3 - if: ${{ failure() }} - with: - name: ${{ steps.test.outputs.test }} Heap Dump (Windows) - path: "*.hprof" - - # Special case this test to run across all os's - reproducible_build_test: - needs: build - - strategy: - fail-fast: false - matrix: - java: [ 17, 20 ] - os: [ windows-2022, ubuntu-22.04, macos-12 ] - - runs-on: ${{ matrix.os }} - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-java@v4 - with: - java-version: ${{ matrix.java }} - distribution: 'temurin' - - - run: ./gradlew test --tests *ReproducibleBuildTest --stacktrace --warning-mode fail - - - uses: actions/upload-artifact@v3 - if: ${{ failure() }} - with: - name: Reproducible Build ${{ matrix.os }} (${{ matrix.java }}) Results - path: build/reports/ \ No newline at end of file diff --git a/build.gradle b/build.gradle index de84c29fa4..90104b4678 100644 --- a/build.gradle +++ b/build.gradle @@ -49,7 +49,7 @@ tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all { } } -group = 'net.fabricmc' +group = 'babric' def baseVersion = '1.5' def ENV = System.getenv() @@ -71,6 +71,10 @@ repositories { url = 'https://maven.fabricmc.net/' } mavenCentral() + maven { + name = 'Babric' + url = 'https://maven.glass-launcher.net/babric' + } } configurations { @@ -253,7 +257,7 @@ codenarc { gradlePlugin { plugins { fabricLoom { - id = 'fabric-loom' + id = 'babric-loom' implementationClass = 'net.fabricmc.loom.bootstrap.LoomGradlePluginBootstrap' } } @@ -312,8 +316,8 @@ publishing { // Manually crate the plugin marker for snapshot versions snapshotPlugin(MavenPublication) { publication -> - groupId 'fabric-loom' - artifactId 'fabric-loom.gradle.plugin' + groupId 'babric-loom' + artifactId 'babric-loom.gradle.plugin' version baseVersion + '-SNAPSHOT' pom.withXml({ @@ -323,9 +327,9 @@ publishing { Node dependencies = root.appendChild(document.createElement('dependencies')) Node dependency = dependencies.appendChild(document.createElement('dependency')) Node groupId = dependency.appendChild(document.createElement('groupId')) - groupId.setTextContent('net.fabricmc') + groupId.setTextContent('babric') Node artifactId = dependency.appendChild(document.createElement('artifactId')) - artifactId.setTextContent('fabric-loom') + artifactId.setTextContent('babric-loom') Node version = dependency.appendChild(document.createElement('version')) version.setTextContent(baseVersion + '-SNAPSHOT') }) diff --git a/gradle.properties b/gradle.properties index 31014b1561..012efb5658 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -name = fabric-loom +name = babric-loom description = The Gradle plugin for Fabric url = https://github.com/FabricMC/fabric-loom diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 0b2075ca75..c612fb1ea6 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -5,11 +5,11 @@ commons-io = "2.15.1" gson = "2.10.1" guava = "33.0.0-jre" -stitch = "0.6.2" +stitch = "0.6.2-babric.1" tiny-remapper = "0.10.0" access-widener = "2.1.0" mapping-io = "0.5.1" -lorenz-tiny = "4.0.2" +lorenz-tiny = "4.0.2-babric.2" mercury = "0.4.1" kotlinx-metadata = "0.8.0" @@ -32,11 +32,11 @@ commons-io = { module = "commons-io:commons-io", version.ref = "commons-io" } gson = { module = "com.google.code.gson:gson", version.ref = "gson" } guava = { module = "com.google.guava:guava", version.ref = "guava" } -fabric-stitch = { module = "net.fabricmc:stitch", version.ref = "stitch" } +fabric-stitch = { module = "babric:stitch", version.ref = "stitch" } fabric-tiny-remapper = { module = "net.fabricmc:tiny-remapper", version.ref = "tiny-remapper" } fabric-access-widener = { module = "net.fabricmc:access-widener", version.ref = "access-widener" } fabric-mapping-io = { module = "net.fabricmc:mapping-io", version.ref = "mapping-io" } -fabric-lorenz-tiny = { module = "net.fabricmc:lorenz-tiny", version.ref = "lorenz-tiny" } +fabric-lorenz-tiny = { module = "babric:lorenz-tiny", version.ref = "lorenz-tiny" } fabric-mercury = { module = "net.fabricmc:mercury", version.ref = "mercury" } # Misc diff --git a/gradle/runtime.libs.versions.toml b/gradle/runtime.libs.versions.toml index 8b6872bf4d..182ed0edfe 100644 --- a/gradle/runtime.libs.versions.toml +++ b/gradle/runtime.libs.versions.toml @@ -5,7 +5,7 @@ cfr = "0.2.1" vineflower = "1.9.3" # Runtime depedencies -mixin-compile-extensions = "0.6.0" +mixin-compile-extensions = "0.6.0-babric.1" dev-launch-injector = "0.2.1+build.8" terminal-console-appender = "1.3.0" jetbrains-annotations = "24.1.0" @@ -18,7 +18,7 @@ cfr = { module = "net.fabricmc:cfr", version.ref = "cfr" } vineflower = { module = "org.vineflower:vineflower", version.ref = "vineflower" } # Runtime depedencies -mixin-compile-extensions = { module = "net.fabricmc:fabric-mixin-compile-extensions", version.ref = "mixin-compile-extensions" } +mixin-compile-extensions = { module = "babric:fabric-mixin-compile-extensions", version.ref = "mixin-compile-extensions" } dev-launch-injector = { module = "net.fabricmc:dev-launch-injector", version.ref = "dev-launch-injector" } terminal-console-appender = { module = "net.minecrell:terminalconsoleappender", version.ref = "terminal-console-appender" } jetbrains-annotations = { module = "org.jetbrains:annotations", version.ref = "jetbrains-annotations" } diff --git a/src/main/java/net/fabricmc/loom/LoomGradleExtension.java b/src/main/java/net/fabricmc/loom/LoomGradleExtension.java index 836138bacb..5f115e7266 100644 --- a/src/main/java/net/fabricmc/loom/LoomGradleExtension.java +++ b/src/main/java/net/fabricmc/loom/LoomGradleExtension.java @@ -86,7 +86,8 @@ default List getMinecraftJars(MappingsNamespace mappingsNamespace) { return switch (mappingsNamespace) { case NAMED -> getNamedMinecraftProvider().getMinecraftJarPaths(); case INTERMEDIARY -> getIntermediaryMinecraftProvider().getMinecraftJarPaths(); - case OFFICIAL -> getMinecraftProvider().getMinecraftJars(); + case OFFICIAL, GLUE -> getMinecraftProvider().getMinecraftJars(); + case SERVER, CLIENT -> null; }; } diff --git a/src/main/java/net/fabricmc/loom/api/LoomGradleExtensionAPI.java b/src/main/java/net/fabricmc/loom/api/LoomGradleExtensionAPI.java index 6570178e40..f4aa60b167 100644 --- a/src/main/java/net/fabricmc/loom/api/LoomGradleExtensionAPI.java +++ b/src/main/java/net/fabricmc/loom/api/LoomGradleExtensionAPI.java @@ -221,6 +221,10 @@ default void splitMinecraftJar() { boolean areEnvironmentSourceSetsSplit(); + default void gluedMinecraftJar() { + getMinecraftJarConfiguration().set(MinecraftJarConfiguration.GLUED); + } + Property getRuntimeOnlyLog4j(); Property getSplitModDependencies(); diff --git a/src/main/java/net/fabricmc/loom/api/mappings/layered/MappingsNamespace.java b/src/main/java/net/fabricmc/loom/api/mappings/layered/MappingsNamespace.java index 4e3a628ad2..e9d98b9550 100644 --- a/src/main/java/net/fabricmc/loom/api/mappings/layered/MappingsNamespace.java +++ b/src/main/java/net/fabricmc/loom/api/mappings/layered/MappingsNamespace.java @@ -49,7 +49,22 @@ public enum MappingsNamespace { /** * Named mappings are the developer friendly names used to develop mods against. */ - NAMED; + NAMED, + + /** + * Mappings used for merging two jars that were obfuscated differently. + */ + GLUE, + + /** + * Official mappings are the names that are used in the vanilla Minecraft server jars, these are usually obfuscated. + */ + SERVER, + + /** + * Official mappings are the names that are used in the vanilla Minecraft client jars, these are usually obfuscated. + */ + CLIENT; /** * Gets a {@code MappingsNamespace} from a namespace string. @@ -62,6 +77,9 @@ public enum MappingsNamespace { case "official" -> OFFICIAL; case "intermediary" -> INTERMEDIARY; case "named" -> NAMED; + case "glue" -> GLUE; + case "server" -> SERVER; + case "client" -> CLIENT; default -> null; }; } diff --git a/src/main/java/net/fabricmc/loom/configuration/CompileConfiguration.java b/src/main/java/net/fabricmc/loom/configuration/CompileConfiguration.java index 041bc42db9..fecef0e20b 100644 --- a/src/main/java/net/fabricmc/loom/configuration/CompileConfiguration.java +++ b/src/main/java/net/fabricmc/loom/configuration/CompileConfiguration.java @@ -146,13 +146,15 @@ private synchronized void setupMinecraft(ConfigContext configContext) throws Exc // Provide the vanilla mc jars -- TODO share across getProject()s. final MinecraftProvider minecraftProvider = jarConfiguration.getMinecraftProviderFunction().apply(configContext); extension.setMinecraftProvider(minecraftProvider); - minecraftProvider.provide(); + minecraftProvider.init(); final DependencyInfo mappingsDep = DependencyInfo.create(getProject(), Configurations.MAPPINGS); final MappingConfiguration mappingConfiguration = MappingConfiguration.create(getProject(), configContext.serviceManager(), mappingsDep, minecraftProvider); extension.setMappingConfiguration(mappingConfiguration); mappingConfiguration.applyToProject(getProject(), mappingsDep); + minecraftProvider.provide(); + // Provide the remapped mc jars final IntermediaryMinecraftProvider intermediaryMinecraftProvider = jarConfiguration.getIntermediaryMinecraftProviderBiFunction().apply(project, minecraftProvider); NamedMinecraftProvider namedMinecraftProvider = jarConfiguration.getNamedMinecraftProviderBiFunction().apply(project, minecraftProvider); diff --git a/src/main/java/net/fabricmc/loom/configuration/ide/RunConfig.java b/src/main/java/net/fabricmc/loom/configuration/ide/RunConfig.java index 242558e159..e7229cb13b 100644 --- a/src/main/java/net/fabricmc/loom/configuration/ide/RunConfig.java +++ b/src/main/java/net/fabricmc/loom/configuration/ide/RunConfig.java @@ -121,6 +121,7 @@ private static void populate(Project project, LoomGradleExtension extension, Run runConfig.mainClass = "net.fabricmc.devlaunchinjector.Main"; runConfig.vmArgs.add("-Dfabric.dli.config=" + encodeEscaped(extension.getFiles().getDevLauncherConfig().getAbsolutePath())); runConfig.vmArgs.add("-Dfabric.dli.env=" + environment.toLowerCase()); + runConfig.vmArgs.add("-Djava.library.path=" + extension.getFiles().getNativesDirectory(project).getAbsolutePath()); } // Turns camelCase/PascalCase into Capital Case diff --git a/src/main/java/net/fabricmc/loom/configuration/providers/mappings/IntermediateMappingsService.java b/src/main/java/net/fabricmc/loom/configuration/providers/mappings/IntermediateMappingsService.java index 80171fa160..473a85db14 100644 --- a/src/main/java/net/fabricmc/loom/configuration/providers/mappings/IntermediateMappingsService.java +++ b/src/main/java/net/fabricmc/loom/configuration/providers/mappings/IntermediateMappingsService.java @@ -44,8 +44,8 @@ import net.fabricmc.loom.configuration.providers.minecraft.MinecraftProvider; import net.fabricmc.loom.util.service.SharedService; import net.fabricmc.loom.util.service.SharedServiceManager; +import net.fabricmc.mappingio.MappingReader; import net.fabricmc.mappingio.adapter.MappingNsCompleter; -import net.fabricmc.mappingio.format.tiny.Tiny2FileReader; import net.fabricmc.mappingio.tree.MemoryMappingTree; public final class IntermediateMappingsService implements SharedService { @@ -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)) { - Tiny2FileReader.read(reader, nsCompleter); + MappingReader.read(reader, nsCompleter); } } catch (IOException e) { throw new UncheckedIOException("Failed to read intermediary mappings", e); diff --git a/src/main/java/net/fabricmc/loom/configuration/providers/mappings/MappingConfiguration.java b/src/main/java/net/fabricmc/loom/configuration/providers/mappings/MappingConfiguration.java index bce9d5d076..827ae851ee 100644 --- a/src/main/java/net/fabricmc/loom/configuration/providers/mappings/MappingConfiguration.java +++ b/src/main/java/net/fabricmc/loom/configuration/providers/mappings/MappingConfiguration.java @@ -51,6 +51,7 @@ import net.fabricmc.loom.configuration.DependencyInfo; import net.fabricmc.loom.configuration.providers.mappings.tiny.MappingsMerger; import net.fabricmc.loom.configuration.providers.mappings.tiny.TinyJarInfo; +import net.fabricmc.loom.configuration.providers.minecraft.GluedMinecraftProvider; import net.fabricmc.loom.configuration.providers.minecraft.MinecraftProvider; import net.fabricmc.loom.util.Constants; import net.fabricmc.loom.util.DeletingFileVisitor; @@ -177,6 +178,8 @@ private void storeMappings(Project project, SharedServiceManager serviceManager, IntermediateMappingsService intermediateMappingsService = IntermediateMappingsService.getInstance(serviceManager, project, minecraftProvider); MappingsMerger.mergeAndSaveMappings(baseTinyMappings, tinyMappings, intermediateMappingsService); + } else if (minecraftProvider instanceof GluedMinecraftProvider) { + Files.move(baseTinyMappings, tinyMappings); } else { final List minecraftJars = minecraftProvider.getMinecraftJars(); diff --git a/src/main/java/net/fabricmc/loom/configuration/providers/mappings/tiny/MappingsMerger.java b/src/main/java/net/fabricmc/loom/configuration/providers/mappings/tiny/MappingsMerger.java index db845663bb..36473f7e6c 100644 --- a/src/main/java/net/fabricmc/loom/configuration/providers/mappings/tiny/MappingsMerger.java +++ b/src/main/java/net/fabricmc/loom/configuration/providers/mappings/tiny/MappingsMerger.java @@ -60,9 +60,11 @@ public static void mergeAndSaveMappings(Path from, Path out, IntermediateMapping Tiny2FileReader.read(reader, intermediaryTree); } + String sourceNs = intermediaryTree.getDstNamespaces().contains(MappingsNamespace.GLUE.toString()) ? MappingsNamespace.GLUE.toString() : MappingsNamespace.OFFICIAL.toString(); + MemoryMappingTree officialTree = new MemoryMappingTree(); - MappingNsCompleter nsCompleter = new MappingNsCompleter(officialTree, Map.of(MappingsNamespace.OFFICIAL.toString(), MappingsNamespace.INTERMEDIARY.toString())); - MappingSourceNsSwitch nsSwitch = new MappingSourceNsSwitch(nsCompleter, MappingsNamespace.OFFICIAL.toString()); + MappingNsCompleter nsCompleter = new MappingNsCompleter(officialTree, Map.of(sourceNs, MappingsNamespace.INTERMEDIARY.toString())); + MappingSourceNsSwitch nsSwitch = new MappingSourceNsSwitch(nsCompleter, sourceNs); intermediaryTree.accept(nsSwitch); inheritMappedNamesOfEnclosingClasses(officialTree); diff --git a/src/main/java/net/fabricmc/loom/configuration/providers/minecraft/GluedMinecraftProvider.java b/src/main/java/net/fabricmc/loom/configuration/providers/minecraft/GluedMinecraftProvider.java new file mode 100644 index 0000000000..f3cc59ec2c --- /dev/null +++ b/src/main/java/net/fabricmc/loom/configuration/providers/minecraft/GluedMinecraftProvider.java @@ -0,0 +1,97 @@ +/* + * This file is part of fabric-loom, licensed under the MIT License (MIT). + * + * Copyright (c) 2022 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.minecraft; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Path; + +import net.fabricmc.loom.api.mappings.layered.MappingsNamespace; +import net.fabricmc.loom.configuration.ConfigContext; +import net.fabricmc.loom.util.TinyRemapperHelper; +import net.fabricmc.stitch.commands.CommandFixNesting; +import net.fabricmc.tinyremapper.IMappingProvider; +import net.fabricmc.tinyremapper.NonClassCopyMode; +import net.fabricmc.tinyremapper.OutputConsumerPath; +import net.fabricmc.tinyremapper.TinyRemapper; +import net.fabricmc.tinyremapper.TinyUtils; + +public final class GluedMinecraftProvider extends MergedMinecraftProvider { + private File minecraftClientGlueJar; + private File minecraftServerGlueJar; + + public GluedMinecraftProvider(ConfigContext configContext) { + super(configContext); + } + + @Override + protected void initFiles() { + super.initFiles(); + minecraftClientGlueJar = file("minecraft-client-glue.jar"); + minecraftServerGlueJar = file("minecraft-server-glue.jar"); + } + + @Override + protected void mergeJars(File clientJar, File serverJar) throws IOException { + Path mappings = getExtension().getMappingConfiguration().tinyMappings; + + if (!minecraftClientGlueJar.exists()) { + getLogger().lifecycle(":Gluing client"); + remapJar(clientJar.toPath(), minecraftClientGlueJar.toPath(), mappings, MappingsNamespace.CLIENT, MappingsNamespace.GLUE); + } + + if (!minecraftServerGlueJar.exists()) { + getLogger().lifecycle(":Gluing server"); + remapJar(serverJar.toPath(), minecraftServerGlueJar.toPath(), mappings, MappingsNamespace.SERVER, MappingsNamespace.GLUE); + } + + super.mergeJars(minecraftClientGlueJar, minecraftServerGlueJar); + + CommandFixNesting.run(getMergedJar().toFile()); + } + + private void remapJar(Path input, Path output, Path mappingsPath, MappingsNamespace fromM, MappingsNamespace toM) { + getLogger().lifecycle(":Remapping minecraft (TinyRemapper, " + fromM + " -> " + toM + ')'); + + IMappingProvider mappings = TinyUtils.createTinyMappingProvider(mappingsPath, fromM.toString(), toM.toString()); + + TinyRemapper remapper = TinyRemapper.newRemapper() + .withMappings(mappings) + .ignoreConflicts(false) + .renameInvalidLocals(true) + .rebuildSourceFilenames(true) + .build(); + + try (OutputConsumerPath outputConsumer = new OutputConsumerPath.Builder(output).build()) { + remapper.readInputs(input); + remapper.apply(outputConsumer); + outputConsumer.addNonClassFiles(input, NonClassCopyMode.FIX_META_INF, remapper); + } catch (Exception e) { + throw new RuntimeException("Failed to remap JARs " + input + " with mappings from " + mappings, e); + } finally { + remapper.finish(); + } + } +} diff --git a/src/main/java/net/fabricmc/loom/configuration/providers/minecraft/MergedMinecraftProvider.java b/src/main/java/net/fabricmc/loom/configuration/providers/minecraft/MergedMinecraftProvider.java index 4020630611..68c2e3afb7 100644 --- a/src/main/java/net/fabricmc/loom/configuration/providers/minecraft/MergedMinecraftProvider.java +++ b/src/main/java/net/fabricmc/loom/configuration/providers/minecraft/MergedMinecraftProvider.java @@ -33,7 +33,7 @@ import net.fabricmc.loom.configuration.ConfigContext; -public final class MergedMinecraftProvider extends MinecraftProvider { +public class MergedMinecraftProvider extends MinecraftProvider { private Path minecraftMergedJar; public MergedMinecraftProvider(ConfigContext configContext) { @@ -55,13 +55,22 @@ public List getMinecraftJars() { public void provide() throws Exception { super.provide(); - if (!getVersionInfo().isVersionOrNewer("2012-07-25T22:00:00+00:00" /* 1.3 release date */)) { + if (!(this instanceof GluedMinecraftProvider) && !getVersionInfo().isVersionOrNewer("2012-07-25T22:00:00+00:00" /* 1.3 release date */)) { throw new UnsupportedOperationException("Minecraft versions 1.2.5 and older cannot be merged. Please use `loom { server/clientOnlyMinecraftJar() }`"); } if (!Files.exists(minecraftMergedJar) || getExtension().refreshDeps()) { try { - mergeJars(); + File serverJar = getMinecraftServerJar(); + + if (getServerBundleMetadata() != null) { + extractBundledServerJar(); + serverJar = getMinecraftExtractedServerJar(); + } + + Objects.requireNonNull(serverJar, "Cannot merge null input jar?"); + + mergeJars(getMinecraftClientJar(), serverJar); } catch (Throwable e) { Files.deleteIfExists(getMinecraftClientJar().toPath()); Files.deleteIfExists(getMinecraftServerJar().toPath()); @@ -73,19 +82,10 @@ public void provide() throws Exception { } } - private void mergeJars() throws IOException { + protected void mergeJars(File clientJar, File serverJar) throws IOException { getLogger().info(":merging jars"); - File jarToMerge = getMinecraftServerJar(); - - if (getServerBundleMetadata() != null) { - extractBundledServerJar(); - jarToMerge = getMinecraftExtractedServerJar(); - } - - Objects.requireNonNull(jarToMerge, "Cannot merge null input jar?"); - - try (var jarMerger = new MinecraftJarMerger(getMinecraftClientJar(), jarToMerge, minecraftMergedJar.toFile())) { + try (var jarMerger = new MinecraftJarMerger(clientJar, serverJar, minecraftMergedJar.toFile())) { jarMerger.enableSyntheticParamsOffset(); jarMerger.merge(); } diff --git a/src/main/java/net/fabricmc/loom/configuration/providers/minecraft/MinecraftJarConfiguration.java b/src/main/java/net/fabricmc/loom/configuration/providers/minecraft/MinecraftJarConfiguration.java index 34e8f42e2e..b558dae7a9 100644 --- a/src/main/java/net/fabricmc/loom/configuration/providers/minecraft/MinecraftJarConfiguration.java +++ b/src/main/java/net/fabricmc/loom/configuration/providers/minecraft/MinecraftJarConfiguration.java @@ -72,6 +72,14 @@ public enum MinecraftJarConfiguration { ProcessedNamedMinecraftProvider.SplitImpl::new, SplitDecompileConfiguration::new, List.of("client", "server") + ), + GLUED( + GluedMinecraftProvider::new, + IntermediaryMinecraftProvider.GluedImpl::new, + NamedMinecraftProvider.GluedImpl::new, + ProcessedNamedMinecraftProvider.GluedImpl::new, + SingleJarDecompileConfiguration::new, + List.of("client", "server") ); private final Function minecraftProviderFunction; diff --git a/src/main/java/net/fabricmc/loom/configuration/providers/minecraft/MinecraftProvider.java b/src/main/java/net/fabricmc/loom/configuration/providers/minecraft/MinecraftProvider.java index f206a7a9c8..d0de18f7e4 100644 --- a/src/main/java/net/fabricmc/loom/configuration/providers/minecraft/MinecraftProvider.java +++ b/src/main/java/net/fabricmc/loom/configuration/providers/minecraft/MinecraftProvider.java @@ -63,6 +63,13 @@ public MinecraftProvider(ConfigContext configContext) { this.project = configContext.project(); } + public void init() { + final DependencyInfo dependency = DependencyInfo.create(getProject(), Constants.Configurations.MINECRAFT); + minecraftVersion = dependency.getDependency().getVersion(); + + initFiles(); + } + protected boolean provideClient() { return true; } @@ -72,9 +79,6 @@ protected boolean provideServer() { } public void provide() throws Exception { - final DependencyInfo dependency = DependencyInfo.create(getProject(), Constants.Configurations.MINECRAFT); - minecraftVersion = dependency.getDependency().getVersion(); - initFiles(); metadataProvider = new MinecraftMetadataProvider( diff --git a/src/main/java/net/fabricmc/loom/configuration/providers/minecraft/mapped/AbstractMappedMinecraftProvider.java b/src/main/java/net/fabricmc/loom/configuration/providers/minecraft/mapped/AbstractMappedMinecraftProvider.java index c81e308484..556c2f7838 100644 --- a/src/main/java/net/fabricmc/loom/configuration/providers/minecraft/mapped/AbstractMappedMinecraftProvider.java +++ b/src/main/java/net/fabricmc/loom/configuration/providers/minecraft/mapped/AbstractMappedMinecraftProvider.java @@ -190,7 +190,7 @@ private void remapJar(RemappedJars remappedJars, ConfigContext configContext) th Files.deleteIfExists(remappedJars.outputJarPath()); final Map remappedSignatures = SignatureFixerApplyVisitor.getRemappedSignatures(getTargetNamespace() == MappingsNamespace.INTERMEDIARY, mappingConfiguration, getProject(), configContext.serviceManager(), toM); - TinyRemapper remapper = TinyRemapperHelper.getTinyRemapper(getProject(), configContext.serviceManager(), fromM, toM, true, (builder) -> { + TinyRemapper remapper = TinyRemapperHelper.getTinyRemapper(getProject(), configContext.serviceManager(), fromM, toM, remappedJars.sourceNamespace() == MappingsNamespace.INTERMEDIARY, (builder) -> { builder.extraPostApplyVisitor(new SignatureFixerApplyVisitor(remappedSignatures)); configureRemapper(remappedJars, builder); }); diff --git a/src/main/java/net/fabricmc/loom/configuration/providers/minecraft/mapped/IntermediaryMinecraftProvider.java b/src/main/java/net/fabricmc/loom/configuration/providers/minecraft/mapped/IntermediaryMinecraftProvider.java index aefed08be9..b2183160b6 100644 --- a/src/main/java/net/fabricmc/loom/configuration/providers/minecraft/mapped/IntermediaryMinecraftProvider.java +++ b/src/main/java/net/fabricmc/loom/configuration/providers/minecraft/mapped/IntermediaryMinecraftProvider.java @@ -34,9 +34,10 @@ import net.fabricmc.loom.configuration.providers.minecraft.SingleJarEnvType; import net.fabricmc.loom.configuration.providers.minecraft.SingleJarMinecraftProvider; import net.fabricmc.loom.configuration.providers.minecraft.SplitMinecraftProvider; +import net.fabricmc.loom.configuration.providers.minecraft.GluedMinecraftProvider; import net.fabricmc.tinyremapper.TinyRemapper; -public abstract sealed class IntermediaryMinecraftProvider extends AbstractMappedMinecraftProvider permits IntermediaryMinecraftProvider.MergedImpl, IntermediaryMinecraftProvider.SingleJarImpl, IntermediaryMinecraftProvider.SplitImpl { +public abstract sealed class IntermediaryMinecraftProvider extends AbstractMappedMinecraftProvider permits IntermediaryMinecraftProvider.GluedImpl, IntermediaryMinecraftProvider.MergedImpl, IntermediaryMinecraftProvider.SingleJarImpl, IntermediaryMinecraftProvider.SplitImpl { public IntermediaryMinecraftProvider(Project project, M minecraftProvider) { super(project, minecraftProvider); } @@ -111,4 +112,17 @@ public SingleJarEnvType env() { return env; } } + + public static final class GluedImpl extends IntermediaryMinecraftProvider implements Merged { + public GluedImpl(Project project, GluedMinecraftProvider minecraftProvider) { + super(project, minecraftProvider); + } + + @Override + public List getRemappedJars() { + return List.of( + new RemappedJars(minecraftProvider.getMergedJar(), getMergedJar(), MappingsNamespace.GLUE) + ); + } + } } diff --git a/src/main/java/net/fabricmc/loom/configuration/providers/minecraft/mapped/NamedMinecraftProvider.java b/src/main/java/net/fabricmc/loom/configuration/providers/minecraft/mapped/NamedMinecraftProvider.java index 1bfdbe72e9..145fbbdf19 100644 --- a/src/main/java/net/fabricmc/loom/configuration/providers/minecraft/mapped/NamedMinecraftProvider.java +++ b/src/main/java/net/fabricmc/loom/configuration/providers/minecraft/mapped/NamedMinecraftProvider.java @@ -35,6 +35,7 @@ import net.fabricmc.loom.configuration.providers.minecraft.SingleJarEnvType; import net.fabricmc.loom.configuration.providers.minecraft.SingleJarMinecraftProvider; import net.fabricmc.loom.configuration.providers.minecraft.SplitMinecraftProvider; +import net.fabricmc.loom.configuration.providers.minecraft.GluedMinecraftProvider; import net.fabricmc.tinyremapper.TinyRemapper; public abstract class NamedMinecraftProvider extends AbstractMappedMinecraftProvider { @@ -127,4 +128,22 @@ public SingleJarEnvType env() { return env; } } + + public static final class GluedImpl extends NamedMinecraftProvider implements Merged { + public GluedImpl(Project project, GluedMinecraftProvider minecraftProvider) { + super(project, minecraftProvider); + } + + @Override + public List getRemappedJars() { + return List.of( + new RemappedJars(minecraftProvider.getMergedJar(), getMergedJar(), MappingsNamespace.GLUE) + ); + } + + @Override + public List getDependencyTypes() { + return List.of(MinecraftJar.Type.MERGED); + } + } } diff --git a/src/main/java/net/fabricmc/loom/configuration/providers/minecraft/mapped/ProcessedNamedMinecraftProvider.java b/src/main/java/net/fabricmc/loom/configuration/providers/minecraft/mapped/ProcessedNamedMinecraftProvider.java index 5d28071ef3..fef0d08162 100644 --- a/src/main/java/net/fabricmc/loom/configuration/providers/minecraft/mapped/ProcessedNamedMinecraftProvider.java +++ b/src/main/java/net/fabricmc/loom/configuration/providers/minecraft/mapped/ProcessedNamedMinecraftProvider.java @@ -44,6 +44,7 @@ import net.fabricmc.loom.configuration.providers.minecraft.SingleJarEnvType; import net.fabricmc.loom.configuration.providers.minecraft.SingleJarMinecraftProvider; import net.fabricmc.loom.configuration.providers.minecraft.SplitMinecraftProvider; +import net.fabricmc.loom.configuration.providers.minecraft.GluedMinecraftProvider; public abstract class ProcessedNamedMinecraftProvider> extends NamedMinecraftProvider { private final P parentMinecraftProvider; @@ -219,4 +220,15 @@ public SingleJarEnvType env() { return env; } } + + public static final class GluedImpl extends ProcessedNamedMinecraftProvider implements Merged { + public GluedImpl(NamedMinecraftProvider.GluedImpl parentMinecraftProvide, MinecraftJarProcessorManager jarProcessorManager) { + super(parentMinecraftProvide, jarProcessorManager); + } + + @Override + public MinecraftJar getMergedJar() { + return getProcessedJar(getParentMinecraftProvider().getMergedJar()); + } + } } diff --git a/src/main/java/net/fabricmc/loom/util/TinyRemapperHelper.java b/src/main/java/net/fabricmc/loom/util/TinyRemapperHelper.java index 202e4646a7..f87c89b7e0 100644 --- a/src/main/java/net/fabricmc/loom/util/TinyRemapperHelper.java +++ b/src/main/java/net/fabricmc/loom/util/TinyRemapperHelper.java @@ -111,6 +111,11 @@ public static IMappingProvider create(MappingTree mappings, String from, String for (MappingTree.ClassMapping classDef : mappings.getClasses()) { String className = classDef.getName(fromId); + + if (className == null) { + className = classDef.getSrcName(); + } + String dstName = classDef.getName(toId); if (dstName == null) { diff --git a/src/main/java/net/fabricmc/loom/util/gradle/GradleUtils.java b/src/main/java/net/fabricmc/loom/util/gradle/GradleUtils.java index dbe9144276..0806974a4c 100644 --- a/src/main/java/net/fabricmc/loom/util/gradle/GradleUtils.java +++ b/src/main/java/net/fabricmc/loom/util/gradle/GradleUtils.java @@ -55,7 +55,7 @@ public static void allLoomProjects(Gradle gradle, Consumer consumer) { } public static boolean isLoomProject(Project project) { - return project.getPluginManager().hasPlugin("fabric-loom"); + return project.getPluginManager().hasPlugin("babric-loom"); } public static Provider getBooleanPropertyProvider(Project project, String key) {