Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Forge 50 (1.20.6) #219

Merged
merged 14 commits into from
Jul 1, 2024
50 changes: 50 additions & 0 deletions .github/workflows/test-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,53 @@ jobs:
with:
name: Reproducible Build ${{ matrix.os }} (${{ matrix.java }}) Results
path: build/reports/

# Special case this test to run on Java 21
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note (mostly for myself): this can be removed in 1.7 since the Fabric API test requires it

neoForge1206Test:
needs: build

strategy:
fail-fast: false
matrix:
java: [ 21 ]
os: [ ubuntu-22.04 ]

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 *NeoForge1206Test --stacktrace --warning-mode fail

- uses: actions/upload-artifact@v4
if: ${{ failure() }}
with:
name: NeoForge 1.20.6 Build Results
# Special case this test to run on Java 21
forge1206Test:
needs: build

strategy:
fail-fast: false
matrix:
java: [ 21 ]
os: [ ubuntu-22.04 ]

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 *Forge1206Test --stacktrace --warning-mode fail

- uses: actions/upload-artifact@v4
if: ${{ failure() }}
with:
name: Forge 1.20.6 Build Results
path: build/reports/
5 changes: 5 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,11 @@ task writeActionsTestMatrix() {
return
}

if (it.name.endsWith("NeoForge1206Test.groovy") || it.name.endsWith("Forge1206Test.groovy")) {
// Arch: The 1.20.6 tests require Java 21
return
}

def className = it.path.toString().replace(".groovy", "")
className = className.substring(className.lastIndexOf("integration/") + "integration/".length()).replace('/', '.')

Expand Down
2 changes: 1 addition & 1 deletion gradle/runtime.libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ access-transformers-new = "8.0.5"
access-transformers-neo = "10.0.2"
unprotect = "1.2.0"
asm = "9.7"
union-relauncher = "1.0.0"
union-relauncher = "1.1.0"
access-transformers-log4j = "2.17.1"

[libraries]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ public static String intermediary(Project project) {
return intermediaryNamespace(project).toString();
}

/**
* Returns the runtime intermediary namespace of the project.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: maybe production instead? There is a dev runtime too.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this also applies in dev runtime I believe

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't dev runtime named though

* This is the namespace used in the compiled jar.
*/
public static String runtimeIntermediary(Project project) {
return runtimeIntermediaryNamespace(project).toString();
}

/**
* Returns the intermediary namespace of the project.
*/
Expand All @@ -49,6 +57,15 @@ public static MappingsNamespace intermediaryNamespace(Project project) {
};
}

/**
* Returns the intermediary namespace of the project.
*/
public static MappingsNamespace runtimeIntermediaryNamespace(Project project) {
LoomGradleExtension extension = LoomGradleExtension.get(project);
if (extension.isForge() && extension.getForgeProvider().usesMojangAtRuntime()) return MappingsNamespace.MOJANG;
return intermediaryNamespace(project);
}

/**
* Potentially replaces the remapping target namespace for mixin refmaps.
*
Expand All @@ -62,6 +79,6 @@ public static MappingsNamespace intermediaryNamespace(Project project) {
* @return the correct namespace to use
*/
public static String replaceMixinIntermediaryNamespace(Project project, String namespace) {
return namespace.equals(intermediary(project)) ? MappingsNamespace.INTERMEDIARY.toString() : namespace;
return namespace.equals(runtimeIntermediary(project)) ? MappingsNamespace.INTERMEDIARY.toString() : namespace;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ private void stripNestedJars(Path path) {
private void remapJars(List<ModDependency> remapList) throws IOException {
final LoomGradleExtension extension = LoomGradleExtension.get(project);
final MappingConfiguration mappingConfiguration = extension.getMappingConfiguration();
String fromM = IntermediaryNamespaces.intermediary(project);
String fromM = IntermediaryNamespaces.runtimeIntermediary(project);

Stopwatch stopwatch = Stopwatch.createStarted();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ public ForgeVersion getVersion() {
return version;
}

public boolean usesMojangAtRuntime() {
return platform == ModPlatform.NEOFORGE || version.getMajorVersion() >= Constants.Forge.MIN_USE_MOJANG_NS_VERSION;
}

public File getGlobalCache() {
if (globalCache == null) {
globalCache = getMinecraftProvider().dir(platform.id() + "/" + version.getCombined());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,18 @@
import java.nio.file.NoSuchFileException;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.nio.file.StandardOpenOption;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

import org.apache.tools.ant.util.StringUtils;
import com.google.common.base.Stopwatch;
import com.google.gson.JsonObject;
import dev.architectury.loom.util.MappingOption;
import org.apache.tools.ant.util.StringUtils;
import org.gradle.api.Project;
import org.gradle.api.artifacts.Configuration;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -211,28 +212,20 @@ public void setupPost(Project project) throws IOException {
// Generate the Mojmap-merged mappings if needed.
// Note that this needs to happen before manipulateMappings for FieldMigratedMappingConfiguration.
if (Files.notExists(tinyMappingsWithMojang) || extension.refreshDeps()) {
final Stopwatch stopwatch = Stopwatch.createStarted();
final MappingContext context = new GradleMappingContext(project, "tmp-neoforge");

try (Tiny2FileWriter writer = new Tiny2FileWriter(Files.newBufferedWriter(tinyMappingsWithMojang), false)) {
ForgeMappingsMerger.mergeMojang(context, tinyMappings, null, true).accept(writer);
}

project.getLogger().info(":merged mojang mappings in {}", stopwatch.stop());
mergeMojang(project, tinyMappings, tinyMappingsWithMojang);
}
}

if (extension.shouldGenerateSrgTiny()) {
if (Files.notExists(tinyMappingsWithSrg) || extension.refreshDeps()) {
// Merge tiny mappings with srg
Stopwatch stopwatch = Stopwatch.createStarted();
ForgeMappingsMerger.ExtraMappings extraMappings = ForgeMappingsMerger.ExtraMappings.ofMojmapTsrg(getMojmapSrgFileIfPossible(project));

try (Tiny2FileWriter writer = new Tiny2FileWriter(Files.newBufferedWriter(tinyMappingsWithSrg), false)) {
ForgeMappingsMerger.mergeSrg(getRawSrgFile(project), tinyMappings, extraMappings, true).accept(writer);
if (extension.isForge() && extension.getForgeProvider().usesMojangAtRuntime()) {
Path tmp = Files.createTempFile("mappings", ".tiny");
mergeMojang(project, tinyMappings, tmp);
mergeSrg(project, tmp, tinyMappingsWithSrg);
Files.deleteIfExists(tmp);
} else {
mergeSrg(project, tinyMappings, tinyMappingsWithSrg);
}

project.getLogger().info(":merged srg mappings in " + stopwatch.stop());
}
}

Expand Down Expand Up @@ -288,6 +281,28 @@ public static Path getMojmapSrgFileIfPossible(Project project) {
}
}

private static void mergeMojang(Project project, Path source, Path target) throws IOException {
final Stopwatch stopwatch = Stopwatch.createStarted();
final MappingContext context = new GradleMappingContext(project, "tmp-mojang");

try (Tiny2FileWriter writer = new Tiny2FileWriter(Files.newBufferedWriter(target, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING), false)) {
ForgeMappingsMerger.mergeMojang(context, source, null, true).accept(writer);
}

project.getLogger().info(":merged mojang mappings in {}", stopwatch.stop());
}

private static void mergeSrg(Project project, Path source, Path target) throws IOException {
Stopwatch stopwatch = Stopwatch.createStarted();
ForgeMappingsMerger.ExtraMappings extraMappings = ForgeMappingsMerger.ExtraMappings.ofMojmapTsrg(getMojmapSrgFileIfPossible(project));

try (Tiny2FileWriter writer = new Tiny2FileWriter(Files.newBufferedWriter(target, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING), false)) {
ForgeMappingsMerger.mergeSrg(getRawSrgFile(project), source, extraMappings, true).accept(writer);
}

project.getLogger().info(":merged srg mappings in " + stopwatch.stop());
}

protected void manipulateMappings(Project project, Path mappingsJar) throws IOException {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ public abstract class MixinExtensionApiImpl implements MixinExtensionAPI {
public MixinExtensionApiImpl(Project project) {
this.project = Objects.requireNonNull(project);
this.useMixinAp = project.getObjects().property(Boolean.class)
.convention(project.provider(() -> !LoomGradleExtension.get(project).isNeoForge()));
.convention(project.provider(() -> !LoomGradleExtension.get(project).isNeoForge() && (!LoomGradleExtension.get(project).isForge() || !LoomGradleExtension.get(project).getForgeProvider().usesMojangAtRuntime())));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic here is a bit ugly, it could be better for readability to use a block lambda.

@shedaniel Do you remember if there's any reason why we have this set to false for Fabric? Upstream 1.6 has it on true: https://github.com/FabricMC/fabric-loom/blob/c4d36fac4ea7ccd1ef9526aa138139a154c8f581/src/main/java/net/fabricmc/loom/extension/MixinExtensionApiImpl.java#L51-L52
(possibly for common projects that need their refmap to be transformed? But that's not needed if refmaps are removed altogether)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe old forge mods should have this as false

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's fine. I think we could change it for Fabric if it didn't break common projects not getting refmaps on old Forge (arch plugin could set it to true?)


this.refmapTargetNamespace = project.getObjects().property(String.class)
.convention(project.provider(() -> IntermediaryNamespaces.intermediary(project)));
.convention(project.provider(() -> IntermediaryNamespaces.runtimeIntermediary(project)));
this.refmapTargetNamespace.finalizeValueOnRead();

this.messages = project.getObjects().mapProperty(String.class, String.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public abstract class AbstractRemapJarTask extends Jar {
@Inject
public AbstractRemapJarTask() {
getSourceNamespace().convention(MappingsNamespace.NAMED.toString()).finalizeValueOnRead();
getTargetNamespace().convention(IntermediaryNamespaces.intermediary(getProject())).finalizeValueOnRead();
getTargetNamespace().convention(getProject().provider(() -> IntermediaryNamespaces.runtimeIntermediary(getProject()))).finalizeValueOnRead();
getRemapperIsolation().convention(true).finalizeValueOnRead();
getIncludesClientOnlyClasses().convention(false).finalizeValueOnRead();
getJarType().finalizeValueOnRead();
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/net/fabricmc/loom/util/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,11 @@ public static final class Forge {
public static final String UNION_RELAUNCHER_MAIN_CLASS = "juuxel.unionrelauncher.UnionRelauncher";
public static final String UNION_RELAUNCHER_MAIN_CLASS_PROPERTY = "unionRelauncher.mainClass";

/**
* The minimum version of Forge that uses "mojang" as the namespace in production.
*/
public static final int MIN_USE_MOJANG_NS_VERSION = 50;

private Forge() {
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/fabricmc/loom/util/SourceRemapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public class SourceRemapper {
private Mercury mercury;

public SourceRemapper(Project project, SharedServiceManager serviceManager, boolean toNamed) {
this(project, serviceManager, toNamed ? IntermediaryNamespaces.intermediary(project) : "named", !toNamed ? IntermediaryNamespaces.intermediary(project) : "named");
this(project, serviceManager, toNamed ? IntermediaryNamespaces.runtimeIntermediary(project) : "named", !toNamed ? IntermediaryNamespaces.runtimeIntermediary(project) : "named");
}

public SourceRemapper(Project project, SharedServiceManager serviceManager, String from, String to) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public final class CoreModClassRemapper {

public static void remapJar(Project project, ModPlatform platform, Path jar, MappingTree mappings) throws IOException {
final Logger logger = project.getLogger();
final String sourceNamespace = IntermediaryNamespaces.intermediary(project);
final String sourceNamespace = IntermediaryNamespaces.runtimeIntermediary(project);

try (FileSystemUtil.Delegate fs = FileSystemUtil.getJarFileSystem(jar, false)) {
Path coremodsJsonPath = fs.getPath("META-INF", "coremods.json");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
*/
public final class ForgeMappingsMerger {
private static final List<String> INPUT_NAMESPACES = List.of("official", "intermediary", "named");
private static final List<String> INPUT_NAMESPACES_WITH_MOJANG = List.of("official", "mojang", "intermediary", "named");
private final MemoryMappingTree newNs;
private final MemoryMappingTree src;
private final MemoryMappingTree output;
Expand Down Expand Up @@ -111,8 +112,8 @@ private static MemoryMappingTree readInput(Path tiny) throws IOException {
List<String> inputNamespaces = new ArrayList<>(src.getDstNamespaces());
inputNamespaces.add(0, src.getSrcNamespace());

if (!inputNamespaces.equals(INPUT_NAMESPACES)) {
throw new MappingException("Mapping file " + tiny + " does not have 'official, intermediary, named' as its namespaces! Found: " + inputNamespaces);
if (!inputNamespaces.equals(INPUT_NAMESPACES) && !inputNamespaces.equals(INPUT_NAMESPACES_WITH_MOJANG)) {
throw new MappingException("Mapping file " + tiny + " does not have 'official(, mojang), intermediary, named' as its namespaces! Found: " + inputNamespaces);
}

return src;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* This file is part of fabric-loom, licensed under the MIT License (MIT).
*
* Copyright (c) 2024 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.integration.forge

import spock.lang.Specification
import spock.lang.Unroll

import net.fabricmc.loom.test.util.GradleProjectTestTrait

import static net.fabricmc.loom.test.LoomTestConstants.DEFAULT_GRADLE
import static org.gradle.testkit.runner.TaskOutcome.SUCCESS

class Forge1206Test extends Specification implements GradleProjectTestTrait {
@Unroll
def "build #mcVersion #neoforgeVersion #mappings #patches"() {
if (Integer.valueOf(System.getProperty("java.version").split("\\.")[0]) < 21) {
println("This test requires Java 21. Currently you have Java ${System.getProperty("java.version")}.")
return
}

setup:
def gradle = gradleProject(project: "forge/1206", version: DEFAULT_GRADLE)
gradle.buildGradle.text = gradle.buildGradle.text.replace('@MCVERSION@', mcVersion)
.replace('@FORGEVERSION@', neoforgeVersion)
.replace('MAPPINGS', mappings) // Spotless doesn't like the @'s
.replace('PATCHES', patches)

when:
def result = gradle.run(task: "build")

then:
result.task(":build").outcome == SUCCESS

where:
mcVersion | neoforgeVersion | mappings | patches
'1.20.6' | '1.20.6-50.1.3' | 'loom.officialMojangMappings()' | ''
}
}
Loading