Skip to content

Commit

Permalink
Switch to Parchment and ART
Browse files Browse the repository at this point in the history
Rather than using Yarn for parameter names (which don't match Mojang
mappings), we are now using Parchment mappings. This simplifies our
process significantly.

This also switches to use NeoForged's AutoRenamingTool (ART) for
applying the base mappings, rather than tiny-remapper, as tiny-remapper
never produced deterministic output.

This commit also updates Hypo which has a number of fixes and
improvements which enabled deterministic output from Hypo as well, which
makes the total output from codebook entirely deterministic.
  • Loading branch information
DenWav committed Jul 29, 2023
1 parent 4ff1e4a commit 42706b9
Show file tree
Hide file tree
Showing 22 changed files with 330 additions and 968 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ build/
out/
!**/src/main/**/out/
!**/src/test/**/out/
src/main/generated/

### Eclipse ###
.apt_generated
Expand Down
15 changes: 15 additions & 0 deletions build-logic/src/main/kotlin/codebook.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,28 @@ plugins {

repositories {
mavenCentral()
maven("https://maven.parchmentmc.org") {
name = "ParchmentMC"
mavenContent {
releasesOnly()
includeGroupAndSubgroups("org.parchmentmc")
}
}
maven("https://maven.neoforged.net/releases") {
name = "NeoForged"
mavenContent {
releasesOnly()
includeGroupAndSubgroups("net.neoforged")
}
}
maven("https://maven.fabricmc.net") {
name = "FabricMC"
mavenContent {
releasesOnly()
includeGroupAndSubgroups("net.fabricmc")
}
}
maven("https://s01.oss.sonatype.org/content/repositories/snapshots/")
}

java {
Expand Down
7 changes: 3 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,15 @@ dependencies {
implementation(libs.bytes)
implementation(libs.bundles.asm)

implementation(libs.lorenz)
implementation(libs.lorenz.proguard)

implementation(libs.lorenz.tiny)
implementation(libs.unpick.format)
implementation(libs.unpick.cli)

implementation(platform(libs.hypo.platform))
implementation(libs.bundles.hypo)

implementation(libs.feather.core)
implementation(libs.feather.gson)

annotationProcessor(libs.recordBuilder.processor)
compileOnly(libs.recordBuilder.core)

Expand Down
155 changes: 112 additions & 43 deletions codebook-cli/src/main/java/io/papermc/codebook/cli/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,21 +69,22 @@ public final class Main implements Callable<Integer> {
static final class RemapperOptions {
@CommandLine.Option(
names = {"-r", "--remapper-coords"},
paramLabel = "<tiny-remapper-coords>",
paramLabel = "<art-coords>",
description =
"The Maven coordinates for the executable tiny-remapper jar to use for the remapping process.")
"The Maven coordinates for the executable AutoRenamingTool jar to use for the remapping process.")
private @Nullable String remapperCoords;

@CommandLine.Option(
names = {"--remapper-file"},
paramLabel = "<tiny-remapper-file>",
description = "The executable tiny-remapper jar to use for the remapping process.")
paramLabel = "<art-file>",
description = "The executable AutoRenamingTool jar to use for the remapping process.")
private @Nullable Path remapperFile;

@CommandLine.Option(
names = "--remapper-uri",
paramLabel = "<tiny-remapper-uri>",
description = "A download URL for the executable tiny-remapper jar to use for the remapping process.")
paramLabel = "<art-uri>",
description =
"A download URL for the executable AutoRenamingTool jar to use for the remapping process.")
private @Nullable URI remapperUri;

@CommandLine.Option(
Expand Down Expand Up @@ -140,30 +141,61 @@ static final class ParamMappingsOptions {
private @Nullable URI paramsUri;
}

@CommandLine.ArgGroup(
heading =
"%n%nUnpick requires a constants jar. This is optional when specifying the parameter mappings using Maven coordinates (preferred). "
+ "If not using Maven coordinates for parameter mappings, then this is required for unpick to run, otherwise it will be skipped.%n")
private @Nullable ConstantsJarOptions constantsJar;

static final class ConstantsJarOptions {
@CommandLine.Option(
names = "--constants-coords",
paramLabel = "<constants-coords>",
description = "The Maven coordinates for the constants jar to use for the unpick process.")
private @Nullable String constantsCoords;

@CommandLine.Option(
names = {"--constants-file"},
paramLabel = "<constants-jar-file>",
description = "The constants jar to use for the unpick process.")
private @Nullable Path constantsFile;
@CommandLine.ArgGroup(exclusive = false)
private @Nullable UnpickOptions unpick;

static final class UnpickOptions {
@CommandLine.ArgGroup(
heading =
"%n%nUnpick requires unpick definitions. When specifying unpick definitions, unpick constants are also required.%n",
multiplicity = "1")
private @Nullable UnpickDefinitionsOptions unpickDefinitions;

static final class UnpickDefinitionsOptions {
@CommandLine.Option(
names = "--unpick-coords",
paramLabel = "<unpick-coords>",
description = "The Maven coordinates for the unpick definitions to use for the unpick process.")
private @Nullable String unpickCoords;

@CommandLine.Option(
names = {"--unpick-file"},
paramLabel = "<unpick-jar-file>",
description = "The unpick definitions file to use for the unpick process.")
private @Nullable Path unpickFile;

@CommandLine.Option(
names = "--unpick-uri",
paramLabel = "<unpick-uri>",
description = "A download URL for the unpick definitions to use for the unpick process.")
private @Nullable URI unpickUri;
}

@CommandLine.Option(
names = "--constants-uri",
paramLabel = "<constants-uri>",
description = "A download URL for the constants jar to use for the unpick process.")
private @Nullable URI constantsUri;
@CommandLine.ArgGroup(
heading =
"%n%nUnpick requires a constants jar. When specifying unpick constants, unpick definitions are also required.%n",
multiplicity = "1")
private @Nullable ConstantsJarOptions constantsJar;

static final class ConstantsJarOptions {
@CommandLine.Option(
names = "--constants-coords",
paramLabel = "<constants-coords>",
description = "The Maven coordinates for the constants jar to use for the unpick process.")
private @Nullable String constantsCoords;

@CommandLine.Option(
names = {"--constants-file"},
paramLabel = "<constants-jar-file>",
description = "The constants jar to use for the unpick process.")
private @Nullable Path constantsFile;

@CommandLine.Option(
names = "--constants-uri",
paramLabel = "<constants-uri>",
description = "A download URL for the constants jar to use for the unpick process.")
private @Nullable URI constantsUri;
}
}

@CommandLine.Option(
Expand Down Expand Up @@ -217,13 +249,30 @@ static class InputFileOptions {
}

@CommandLine.Option(
names = "--maven-base-url",
names = "--mappings-maven-base-url",
paramLabel = "url",
description = "Provide a different Maven URL to resolve all Maven coordinates (params, remapper, etc). "
description = "Provide a different Maven URL to resolve parameter mapping Maven coordinates. "
+ "It should be the base URL so the Maven artifact path can be appended to it. "
+ "The default value when not provided is ${DEFAULT-VALUE}.",
defaultValue = Downloader.FABRIC_MAVEN)
private String mavenBaseUrl;
defaultValue = Downloader.PARCHMENT_MAVEN)
private String paramsMavenBaseUrl;

@CommandLine.Option(
names = "--remapper-maven-base-url",
paramLabel = "url",
description = "Provide a different Maven URL to resolve remapper Maven coordinates. "
+ "It should be the base URL so the Maven artifact path can be appended to it. "
+ "The default value when not provided is ${DEFAULT-VALUE}.",
defaultValue = Downloader.NEO_MAVEN)
private String remapperMavenBaseUrl;

@CommandLine.Option(
names = "--unpick-maven-base-url",
paramLabel = "url",
description = "Provide a different Maven URL to resolve unpick Maven coordinates. "
+ "It should be the base URL so the Maven artifact path can be appended to it. "
+ "There is no default value when not provided.")
private @Nullable String unpickMavenBaseUrl;

public Main() {}

Expand Down Expand Up @@ -316,36 +365,56 @@ private CodeBookContext createContext() {
}

final @Nullable CodeBookResource remapper = this.getResource(
"tiny-remapper.jar",
"AutoRenamingTool.jar",
this.remapper,
r -> r.remapperFile,
r -> r.remapperUri,
r -> new Coords(r.remapperCoords, "fat", null));
r -> new Coords(r.remapperCoords, "all", null, this.remapperMavenBaseUrl));
if (remapper == null) {
throw new UserErrorException("No remapper provided");
}

final @Nullable CodeBookResource mappings =
this.getResource("server_mappings.txt", this.mappings, m -> m.mappingsFile, m -> m.mappingsUri, null);

final @Nullable CodeBookResource paramMappings = this.getResource(
"yarn_mappings.jar",
"parchment.zip",
this.paramMappings,
p -> p.paramsFile,
p -> p.paramsUri,
p -> new Coords(p.paramsCoords, "mergedv2", null));
p -> new Coords(p.paramsCoords, null, "zip", this.paramsMavenBaseUrl));

final @Nullable CodeBookResource unpickDefinitions = this.getResource(
"unpick_definitions.jar",
this.unpick != null ? this.unpick.unpickDefinitions : null,
d -> d.unpickFile,
d -> d.unpickUri,
d -> {
if (this.unpickMavenBaseUrl == null) {
throw new UserErrorException(
"Cannot define unpick definitions Maven coordinates without also setting --unpick-maven-base-url");
}
return new Coords(d.unpickCoords, "constants", null, this.unpickMavenBaseUrl);
});

final @Nullable CodeBookResource constantJar = this.getResource(
"unpick_constants.jar",
this.constantsJar,
this.unpick != null ? this.unpick.constantsJar : null,
c -> c.constantsFile,
c -> c.constantsUri,
c -> new Coords(c.constantsCoords, "constants", null));
c -> {
if (this.unpickMavenBaseUrl == null) {
throw new UserErrorException(
"Cannot define unpick constants Maven coordinates without also setting --unpick-maven-base-url");
}
return new Coords(c.constantsCoords, "constants", null, this.unpickMavenBaseUrl);
});

return CodeBookContext.builder()
.mavenBaseUrl(this.mavenBaseUrl)
.remapperJar(remapper)
.mappings(mappings)
.paramMappings(paramMappings)
.unpickDefinitions(unpickDefinitions)
.constantsJar(constantJar)
.outputJar(this.outputJar)
.overwrite(this.forceWrite)
Expand Down Expand Up @@ -377,15 +446,15 @@ private CodeBookContext createContext() {
if (resourceCoords != null) {
final Coords coords = resourceCoords.apply(resource);
if (coords.coords != null) {
return new CodeBookCoordsResource(
coords.coords, coords.classifier, coords.extension, this.mavenBaseUrl);
return new CodeBookCoordsResource(coords.coords, coords.classifier, coords.extension, coords.baseUrl);
}
}

throw new UserErrorException("No valid mappings configuration found (this is probably a bug)");
}

private record Coords(@Nullable String coords, @Nullable String classifier, @Nullable String extension) {}
private record Coords(
@Nullable String coords, @Nullable String classifier, @Nullable String extension, String baseUrl) {}

private void verifyFileExists(final String name, final Path file) {
if (!Files.isRegularFile(file)) {
Expand Down
13 changes: 6 additions & 7 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ slf4j = "2.0.7"
lorenz = "0.5.7"
unpick = "2.3.0"
asm = "9.5"
feather = "1.1.0"
recordBuilder = "37"

junit = "5.10.0"
Expand Down Expand Up @@ -37,20 +38,18 @@ asm = { module = "org.ow2.asm:asm", version.ref = "asm" }
asm-util = { module = "org.ow2.asm:asm-util", version.ref = "asm" }
asm-tree = { module = "org.ow2.asm:asm-tree", version.ref = "asm" }

lorenz = { module = "org.cadixdev:lorenz", version.ref = "lorenz" }
lorenz-proguard = { module = "org.cadixdev:lorenz-io-proguard", version.ref = "lorenz" }

lorenz-tiny = "net.fabricmc:lorenz-tiny:4.0.0"
unpick-format = { module = "net.fabricmc.unpick:unpick-format-utils", version.ref = "unpick" }
unpick-cli = { module = "net.fabricmc.unpick:unpick-cli", version.ref = "unpick" }

hypo-platform = "dev.denwav.hypo:hypo-platform:1.2.7"
hypo-platform = "dev.denwav.hypo:hypo-platform:2.0.0-SNAPSHOT"
hypo-model = { module = "dev.denwav.hypo:hypo-model" }
hypo-core = { module = "dev.denwav.hypo:hypo-core" }
hypo-asm = { module = "dev.denwav.hypo:hypo-asm" }
hypo-hydrate = { module = "dev.denwav.hypo:hypo-hydrate" }
hypo-asm-hydrate = { module = "dev.denwav.hypo:hypo-asm-hydrate" }
hypo-mappings = { module = "dev.denwav.hypo:hypo-mappings" }

feather-core = { module = "org.parchmentmc:feather", version.ref = "feather" }
feather-gson = { module = "org.parchmentmc.feather:io-gson", version.ref = "feather" }

recordBuilder-processor = { module = "io.soabase.record-builder:record-builder-processor", version.ref = "recordBuilder" }
recordBuilder-core = { module = "io.soabase.record-builder:record-builder-core", version.ref = "recordBuilder" }
Expand All @@ -64,4 +63,4 @@ mockito-junit = { module = "org.mockito:mockito-junit-jupiter", version.ref = "m

[bundles]
asm = ["asm", "asm-util", "asm-tree"]
hypo = ["hypo-model", "hypo-core", "hypo-asm", "hypo-hydrate", "hypo-asm-hydrate", "hypo-mappings"]
hypo = ["hypo-model", "hypo-core", "hypo-asm", "hypo-hydrate", "hypo-asm-hydrate"]
Loading

0 comments on commit 42706b9

Please sign in to comment.