Skip to content

Commit

Permalink
Port to mapping-io (Glitch's Version) (#432)
Browse files Browse the repository at this point in the history
* Port to mapping-io (Glitch's Version)

This is step 0 in adding the ability for Loader to use alternative intermediates for mods, or use something like mojmaps at runtime. This commit migrates the pre-existing MappingConfiguration to use mapping-io, but doesn't do much to actually refactor Loader to take advantage of mapping-io's strengths.

This PR moves a few dependencies to be shadowed that Floader moved as well. Tiny Remapper was required to be moved to work with mapping-io, tiny mapping parser was removed by upstream, and I just decided to bring AccessWidener in line with upstream as well.

(PS: I know QMT exists-ish, but it's not finished and I want to work on a modloader, not a mappings parser. When and if QMT is finished, we can evaluate migrating to it, but the potential to use a first-party library later shouldn't prevent us from improving Loader today)

* Fix "duplicate class" spam from Tiny Remapper in RuntimeModRemapper

TR eagerly opens nested ZIP files and flattens them, and this slightly bizarre behavior
causes lots of issues when trying to remap mods that include JiJ candidates. To mitigate this,
we create a read-only view of *only* the `.class` files. This has minimal memory impact as the
FS is copy-on-write, so it is just a big map of file paths.

* Update actions for Java 21

* Update actions for Java 21 take 2

* Mount instead of CoW

* Remove Proguard

Proguard is magically adding SequencedCollection to the LVT of MemoryMappingTree.accept
in mapping-io. We couldn't find a minimal reproduction, so we're just going to move away from
it for now.

* Fix mods that need remapping, but don't contain any class files, causing the remapper to crash because the mod directory didn't exist.

Also comment out the DedicatedServerOnly annotation on TestMixinGuiHelper, because we're not testing package-stripping annotations any more. This allows us to run the test mod.

* Mount temporary files as READ_ONLY

---------

Co-authored-by: AlexIIL <alexj9@me.com>
Co-authored-by: AlexIIL <AlexIIL@users.noreply.github.com>
  • Loading branch information
3 people authored Oct 9, 2024
1 parent 3379b2e commit fe82575
Show file tree
Hide file tree
Showing 33 changed files with 572 additions and 403 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
# needs: build
runs-on: ubuntu-22.04
container:
image: eclipse-temurin:17
image: eclipse-temurin:21
options: --user root
steps:
- uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ jobs:
build:
runs-on: ubuntu-22.04
container:
image: eclipse-temurin:17
image: eclipse-temurin:21
options: --user root
steps:
- uses: actions/checkout@v3
Expand Down
47 changes: 15 additions & 32 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import org.slf4j.LoggerFactory
buildscript {
dependencies {
classpath "org.kohsuke:github-api:${project.github_api}"
classpath "com.guardsquare:proguard-gradle:${project.proguard_gradle}"
}
}

Expand All @@ -14,7 +13,7 @@ plugins {
id 'eclipse'
id 'maven-publish'
id 'org.quiltmc.gradle.licenser' version '2.0.1'
id 'org.quiltmc.loom' version '1.3.3' apply false
id 'org.quiltmc.loom' version '1.6.7' apply false
id 'com.github.johnrengelman.shadow' version '8.1.1'
}

Expand Down Expand Up @@ -129,10 +128,7 @@ processResources {

filesMatching(["quilt_installer.json", "fabric-installer.launchwrapper.json"]) {
expand(
"tiny_mappings_parser": project.tiny_mappings_parser,
"sponge_mixin": project.sponge_mixin,
"tiny_remapper": project.tiny_remapper,
"access_widener": project.access_widener,
"quilt_json5": project.quilt_json5,
"asm": project.asm,
"asm_analysis": project.asm,
Expand Down Expand Up @@ -180,6 +176,9 @@ task getSat4jAbout(type: Copy) {
into layout.buildDirectory.dir("sat4j")
}

File outputFile = file("build/libs/quilt-loader-${version}.jar")
evaluationDependsOnChildren()

task fatJar(type: ShadowJar, dependsOn: getSat4jAbout) {
from sourceSets.main.output
from project(":minecraft").sourceSets.main.output
Expand All @@ -196,17 +195,23 @@ task fatJar(type: ShadowJar, dependsOn: getSat4jAbout) {
)
}

archiveClassifier = "fat"
archiveClassifier = ""
configurations = [project.configurations.include]

relocate 'org.quiltmc.loader.util.sat4j', 'org.quiltmc.loader.impl.lib.sat4j'
relocate 'org.quiltmc.parsers', 'org.quiltmc.loader.impl.lib.parsers'
relocate 'com.electronwill', 'org.quiltmc.loader.impl.lib.electronwill'
relocate 'com.unascribed.flexver', 'org.quiltmc.loader.impl.lib.flexver'
//relocate 'org.quiltmc.json5', 'org.quiltmc.loader.impl.lib.json5'
relocate 'net.fabricmc.mappingio', 'org.quiltmc.loader.impl.lib.mappingio'
relocate 'net.fabricmc.tinyremapper', 'org.quiltmc.loader.impl.lib.tinyremapper'
relocate 'net.fabricmc.accesswidener', 'org.quiltmc.loader.impl.lib.accesswidener'

minimize()

exclude 'about.html'
exclude 'sat4j.version'
exclude 'META-INF/maven/org.ow2.sat4j/*/**'
exclude 'META-INF/FABRIC1.*'

doLast {
JarNester.nestJars(project.configurations.development.files, archiveFile.get().asFile, LoggerFactory.getLogger("JiJ"))
Expand All @@ -215,29 +220,7 @@ task fatJar(type: ShadowJar, dependsOn: getSat4jAbout) {
outputs.upToDateWhen { false }
}

File proguardFile = file("build/libs/quilt-loader-${version}.jar")

import proguard.gradle.ProGuardTask
task proguardJar(type: ProGuardTask, dependsOn: fatJar) {
def classpath = project(":minecraft").configurations.compileClasspath

inputs.files(fatJar, classpath)
outputs.files(proguardFile)
outputs.upToDateWhen { false }

doFirst {
classpath.resolve().forEach {
libraryjars it
}
}

libraryjars JavaVersion.current().java9Compatible ? "${System.getProperty('java.home')}/jmods" : "${System.getProperty('java.home')}/lib/rt.jar"

injars fatJar.archiveFile
outjars proguardFile
configuration file("proguard.conf")
}
build.dependsOn proguardJar
build.dependsOn("fatJar")

jar {
enabled = false
Expand Down Expand Up @@ -334,8 +317,8 @@ allprojects {
[configurations.runtimeElements, configurations.apiElements].each { configuration ->
configuration.outgoing.artifacts.clear()
artifacts {
add(configuration.name, proguardFile) {
builtBy proguardJar
add(configuration.name, outputFile) {
builtBy fatJar
}
}
}
Expand Down
10 changes: 7 additions & 3 deletions dependencies/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,6 @@ dependencies {
exclude module: 'launchwrapper'
exclude module: 'guava'
}
published "net.fabricmc:tiny-mappings-parser:${project.tiny_mappings_parser}"
published "net.fabricmc:tiny-remapper:${project.tiny_remapper}"
published "net.fabricmc:access-widener:${project.access_widener}"

/*include*/ published "org.quiltmc:quilt-json5:${project.quilt_json5}"
published "org.quiltmc:quilt-config:${project.quilt_config}"
Expand All @@ -78,6 +75,13 @@ dependencies {

include "org.quiltmc.parsers:json:${project.quilt_parsers}"
include "com.unascribed:flexver-java:${project.flexver}"

include "net.fabricmc:tiny-remapper:${project.tiny_remapper}"
include "net.fabricmc:access-widener:${project.access_widener}"
include ("net.fabricmc:mapping-io:${project.mapping_io}") {
// dont include asm
transitive = false
}
}

publishing {
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ sponge_mixin = 0.15.3+mixin.0.8.7
tiny_mappings_parser = 0.3.0+build.17
tiny_remapper = 0.10.4
access_widener = 2.1.0
mapping_io = 0.6.1
quilt_json5 = 1.0.4+final
quilt_parsers = 0.2.0
quilt_loader_sat4j = 2.3.5.1
Expand All @@ -24,7 +25,6 @@ quilt_chasm = 0.1.0-20230126.045734-27
night_config = 3.6.6
annotations = 24.0.1
junit_bom = 5.9.3
proguard_gradle = 7.4.2
github_api = 1.315
flexver = 1.1.0
mixin_extras = 0.4.1
5 changes: 0 additions & 5 deletions minecraft/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@ dependencies {
compileOnly 'org.apache.logging.log4j:log4j-api:2.8.1'
// slf4j wrapper
compileOnly 'org.slf4j:slf4j-api:1.8.0-beta4'
// HACK: work around proguard only seeing dependencies on the minecraft compile classpath
compileOnly "org.quiltmc.chasm:chassembly:${project.quilt_chasm}"
compileOnly "org.quiltmc.chasm:chasm:${project.quilt_chasm}"
// compileOnly 'org.quiltmc:quilt-json5:1.0.1'
// testCompileOnly 'org.quiltmc:quilt-json5:1.0.1'
// launchwrapper + dependencies
compileOnly ('net.minecraft:launchwrapper:1.12') {
transitive = false
Expand Down
4 changes: 2 additions & 2 deletions minecraft/minecraft-test/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ repositories {

dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter:5.8.1'
minecraft "com.mojang:minecraft:1.20.2"
mappings "org.quiltmc:quilt-mappings:1.20.2+build.1:intermediary-v2"
minecraft "com.mojang:minecraft:1.20.6"
mappings "org.quiltmc:quilt-mappings:1.20.6+build.6:intermediary-v2"

implementation project(":minecraft")
implementation project(":dependencies")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package net.fabricmc.minecraft.test.server_only;

import org.quiltmc.loader.api.minecraft.DedicatedServerOnly;

@DedicatedServerOnly
//@DedicatedServerOnly
public class TestMixinGuiHelper {

public static void help() {
Expand Down
61 changes: 61 additions & 0 deletions minecraft/minecraft-test/src/test/java/MappingResolverTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Copyright 2016 FabricMC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertIterableEquals;

import java.util.List;

import org.junit.jupiter.api.Test;
import org.quiltmc.loader.api.MappingResolver;
import org.quiltmc.loader.api.QuiltLoader;


public class MappingResolverTest {
final MappingResolver mappingResolver = QuiltLoader.getMappingResolver();

@Test
void getNamespaces() {
assertIterableEquals(List.of( "official", "intermediary", "named"), mappingResolver.getNamespaces());
}

@Test
void getCurrentRuntimeNamespace() {
assertEquals("named", mappingResolver.getCurrentRuntimeNamespace());
}

@Test
void mapClassName() {
assertEquals("net.minecraft.client.MinecraftClient", mappingResolver.mapClassName("intermediary", "net.minecraft.class_310"));
assertEquals("net.minecraft.client.MinecraftClient$ChatRestriction", mappingResolver.mapClassName("intermediary", "net.minecraft.class_310$class_5859"));
assertEquals("net.minecraft.Unknown", mappingResolver.mapClassName("intermediary", "net.minecraft.Unknown"));
}

@Test
void unmapClassName() {
assertEquals("net.minecraft.class_6327", mappingResolver.unmapClassName("intermediary", "net.minecraft.server.command.DebugPathCommand"));
}

@Test
void mapFieldName() {
assertEquals("world", mappingResolver.mapFieldName("intermediary", "net.minecraft.class_2586", "field_11863", "Lnet/minecraft/class_1937;"));
}

@Test
void mapMethodName() {
assertEquals("getWorld", mappingResolver.mapMethodName("intermediary", "net.minecraft.class_2586", "method_10997", "()Lnet/minecraft/class_1937;"));
}
}
10 changes: 0 additions & 10 deletions proguard.conf

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@

@Deprecated
public interface FabricLauncher {
MappingConfiguration getMappingConfiguration();

void addToClassPath(Path path, String... allowedPrefixes);
void setAllowedPrefixes(Path path, String... prefixes);
// void setValidParentClassPath(Collection<Path> paths);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,6 @@ public static Class<?> getClass(String className) throws ClassNotFoundException
return Class.forName(className, true, getLauncher().getTargetClassLoader());
}

@Override
public MappingConfiguration getMappingConfiguration() {
return mappingConfiguration;
}

@Override
public void addToClassPath(Path path, String... allowedPrefixes) {
delegate.addToClassPath(path, allowedPrefixes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

package net.fabricmc.loader.impl.launch;

import net.fabricmc.mapping.tree.TinyTree;

@Deprecated
public final class MappingConfiguration {
private final org.quiltmc.loader.impl.launch.common.MappingConfiguration delegate;
Expand All @@ -38,9 +36,6 @@ public boolean matches(String gameId, String gameVersion) {
return delegate.matches(gameId, gameVersion);
}

public TinyTree getMappings() {
return delegate.getMappings();
}

public String getTargetNamespace() {
return delegate.getTargetNamespace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
*/
@Deprecated
public interface FabricLauncher {
MappingConfiguration getMappingConfiguration();
void propose(URL url);
EnvType getEnvironmentType();
boolean isClassLoaded(String name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,6 @@ public static FabricLauncher getLauncher() {
return new FabricLauncherBase();
}

@Override
public MappingConfiguration getMappingConfiguration() {
return new MappingConfiguration();
}

@Override
public void propose(URL url) {
parent.addToClassPath(UrlUtil.asPath(url));
Expand Down

This file was deleted.

Loading

0 comments on commit fe82575

Please sign in to comment.