More buildscript updates (#3566)

This commit is contained in:
modmuss50 2023-05-10 18:16:40 +01:00 committed by GitHub
parent 09085b2dbb
commit 31a9278db7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 213 additions and 260 deletions

View File

@ -4,7 +4,7 @@ jobs:
build:
strategy:
matrix:
java: [17-jdk, 18-jdk]
java: [17-jdk, 20-jdk]
runs-on: ubuntu-22.04
container:
image: eclipse-temurin:${{ matrix.java }}
@ -13,7 +13,7 @@ jobs:
- uses: actions/checkout@v3
- run: ./gradlew build javadocJar checkMappings --stacktrace --warning-mode fail
- name: Build artifacts
if: ${{ matrix.java == '18-jdk' }}
if: ${{ matrix.java == '20-jdk' }}
continue-on-error: true
uses: actions/upload-artifact@v3
with:
@ -23,7 +23,7 @@ jobs:
test-build-logic:
runs-on: ubuntu-22.04
container:
image: eclipse-temurin:18-jdk
image: eclipse-temurin:20-jdk
options: --user root
steps:
- uses: actions/checkout@v3

View File

@ -6,7 +6,7 @@ jobs:
if: ${{ github.repository_owner == 'FabricMC' }}
runs-on: ubuntu-22.04
container:
image: eclipse-temurin:18-jdk
image: eclipse-temurin:20-jdk
options: --user root
steps:
- uses: actions/checkout@v3

View File

@ -4,7 +4,7 @@ jobs:
build:
runs-on: ubuntu-22.04
container:
image: eclipse-temurin:18-jdk
image: eclipse-temurin:20-jdk
options: --user root
steps:
- uses: actions/checkout@v3

View File

@ -9,7 +9,6 @@ buildscript {
}
dependencies {
classpath "cuchaz:enigma-cli:${project.enigma_version}"
classpath "net.fabricmc:stitch:${project.stitch_version}"
classpath "net.fabricmc:name-proposal:${project.name_proposal_version}"
}
}
@ -100,72 +99,26 @@ def minecraftLibraries = configurations.minecraftLibraries
import cuchaz.enigma.command.CheckMappingsCommand
import net.fabricmc.filament.task.MapJarTask
import net.fabricmc.filament.task.DownloadTask
import net.fabricmc.filament.task.ExtractZipEntryTask
import net.fabricmc.filament.task.UnpickJarTask
import net.fabricmc.filament.task.base.WithFileInput
import net.fabricmc.filament.task.base.WithFileOutput
import net.fabricmc.filament.task.enigma.ConvertMappingsTask
import net.fabricmc.filament.task.enigma.MapSpecializedMethodsTask
import net.fabricmc.stitch.commands.CommandMergeTiny
import net.fabricmc.stitch.commands.CommandReorderTiny
import net.fabricmc.stitch.commands.tinyv2.CommandMergeTinyV2
import net.fabricmc.stitch.commands.tinyv2.CommandReorderTinyV2
import net.fabricmc.filament.task.mappingio.ConvertMappingsTask
import net.fabricmc.filament.task.mappingio.MergeMappingsTask
import net.fabricmc.mappingio.format.MappingFormat
import net.fabricmc.nameproposal.MappingNameCompleter
import org.gradle.work.DisableCachingByDefault
import java.util.zip.GZIPOutputStream
task downloadIntermediary(type: DownloadTask) {
tasks.register('downloadIntermediary', DownloadTask) {
group = buildMappingGroup
url = "https://github.com/FabricMC/intermediary/raw/master/mappings/${minecraft_version}.tiny"
output = new File(cacheFilesMinecraft, "${minecraft_version}-intermediary.tiny")
}
task downloadIntermediaryV2(type: DownloadTask) {
group = buildMappingGroup
url = "https://maven.fabricmc.net/net/fabricmc/intermediary/${minecraft_version}/intermediary-${minecraft_version}-v2.jar"
output = new File(cacheFilesMinecraft, "${minecraft_version}-intermediary-v2.jar")
}
task extractIntermediaryV2(type: ExtractZipEntryTask) {
input = downloadIntermediaryV2.output
output = new File(cacheFilesMinecraft, "${minecraft_version}-intermediary-v2.tiny")
entry = "mappings/mappings.tiny"
}
task invertIntermediary(dependsOn: downloadIntermediary, type: FileInputOutput) {
group = buildMappingGroup
input = downloadIntermediary.output
output = new File(cacheFilesMinecraft, "${minecraft_version}-intermediary-inverted.tiny")
doLast {
String[] v1Args = [
inputFile.getAbsolutePath(),
outputFile.getAbsolutePath(),
"intermediary", "official"
]
new CommandReorderTiny().run(v1Args)
}
}
task invertIntermediaryv2(dependsOn: [downloadIntermediaryV2, extractIntermediaryV2], type: FileInputOutput) {
group = buildMappingGroup
output = new File(cacheFilesMinecraft, "${minecraft_version}-intermediary-inverted-v2.tiny")
input = extractIntermediaryV2.output
doLast {
String[] v2Args = [
inputFile.getAbsolutePath(),
outputFile.getAbsolutePath(),
"intermediary", "official"
]
new CommandReorderTinyV2().run(v2Args)
}
}
task mapIntermediaryJar(type: MapJarTask, dependsOn: [downloadIntermediary, mergeMinecraftJars]) {
tasks.register('mapIntermediaryJar', MapJarTask) {
dependsOn downloadIntermediary, mergeMinecraftJars
group = mapJarGroup
output = file("${minecraft_version}-intermediary.jar")
input = mergeMinecraftJars.output
@ -175,7 +128,8 @@ task mapIntermediaryJar(type: MapJarTask, dependsOn: [downloadIntermediary, merg
to = 'intermediary'
}
task mapServerIntermediaryJar(type: MapJarTask, dependsOn: [downloadIntermediary, extractBundledServer]) {
tasks.register('mapServerIntermediaryJar', MapJarTask) {
dependsOn downloadIntermediary, extractBundledServer
group = mapJarGroup
output = file("${minecraft_version}-server-intermediary.jar")
input = extractBundledServer.output
@ -185,19 +139,20 @@ task mapServerIntermediaryJar(type: MapJarTask, dependsOn: [downloadIntermediary
to = 'intermediary'
}
task yarn(dependsOn: mapIntermediaryJar, type: EnigmaTask) {
tasks.register('yarn', EnigmaTask) {
dependsOn mapIntermediaryJar
group = yarnGroup
jar = mapIntermediaryJar.output
mappings = mappingsDir
}
task yarnCommon(type: EnigmaTask) {
tasks.register('yarnCommon', EnigmaTask) {
group = yarnGroup
jar = mapServerIntermediaryJar.output
mappings = mappingsDir
}
task checkMappings() {
tasks.register('checkMappings') {
group = buildMappingGroup
inputs.dir mappingsDir
inputs.file mapIntermediaryJar.output
@ -206,8 +161,8 @@ task checkMappings() {
doLast {
String[] args = [
intermediaryJarPath,
mappingsDir.getAbsolutePath()
intermediaryJarPath,
mappingsDir.getAbsolutePath()
]
try {
@ -218,7 +173,7 @@ task checkMappings() {
}
}
task mapSpecializedMethods(type: MapSpecializedMethodsTask) {
tasks.register('mapSpecializedMethods', MapSpecializedMethodsTask) {
intermediaryJarFile = mapIntermediaryJar.output
mappings = mappingsDir
output = new File(tempDir, "yarn-mappings-v2.tiny")
@ -227,48 +182,18 @@ task mapSpecializedMethods(type: MapSpecializedMethodsTask) {
outputMappingsFormat = "tinyv2:intermediary:named"
}
task convertToV1(type: ConvertMappingsTask) {
tasks.register('convertToV1', ConvertMappingsTask) {
input = mapSpecializedMethods.output
output = new File(tempDir, "yarn-mappings.tiny")
inputMappingsFormat = "tinyv2"
outputMappingsFormat = "tiny:intermediary:named"
outputFormat = MappingFormat.TINY
}
task mergeTiny(dependsOn: ["convertToV1", "invertIntermediary"], type: FileOutput) {
tasks.register('mergeTiny', MergeMappingsTask) {
group = buildMappingGroup
def unorderedResultMappings = new File(tempDir, "mappings-unordered.tiny")
outputs.file unorderedResultMappings
output = new File(tempDir, "mappings.tiny")
inputs.file convertToV1.output
inputs.file invertIntermediary.output
def intermediaryTinyPath = invertIntermediary.outputFile.absolutePath
def yarnTinyPath = convertToV1.outputFile.absolutePath
def outputPath = unorderedResultMappings.absolutePath
doLast {
String[] args = [
intermediaryTinyPath,
yarnTinyPath,
outputPath,
"intermediary",
"official"
]
new CommandMergeTiny().run(args)
String[] args2 = [
unorderedResultMappings.getAbsolutePath(),
output.getAbsolutePath(),
"official", "intermediary", "named"
]
new CommandReorderTiny().run(args2)
}
mappingInputs.from downloadIntermediary.output
mappingInputs.from convertToV1.output
outputFormat = MappingFormat.TINY
}
// Disable the default jar task
@ -276,7 +201,8 @@ jar {
enabled = false
}
task tinyJar(type: Jar, dependsOn: mergeTiny) {
tasks.register('tinyJar', Jar) {
dependsOn mergeTiny
group = buildMappingGroup
archiveFileName = "yarn-${yarnVersion}.jar"
destinationDirectory.set(file("build/libs"))
@ -290,7 +216,8 @@ task tinyJar(type: Jar, dependsOn: mergeTiny) {
}
}
task compressTiny(dependsOn: [tinyJar, mergeTiny], type: FileInputOutput) {
tasks.register('compressTiny', FileInputOutput) {
dependsOn tinyJar, mergeTiny
group = buildMappingGroup
input = mergeTiny.output
@ -322,7 +249,7 @@ sourceSets {
packageDocs // package info files
}
task constantsJar(type: Jar) {
tasks.register('constantsJar', Jar) {
from sourceSets.constants.output
archiveClassifier = "constants"
}
@ -355,7 +282,8 @@ spotless {
}
}
task sourcesJar(type: Jar, dependsOn: classes) {
tasks.register('sourcesJar', Jar) {
dependsOn classes
archiveClassifier = "sources"
from sourceSets.constants.allSource
}
@ -364,7 +292,8 @@ task sourcesJar(type: Jar, dependsOn: classes) {
build.dependsOn constantsJar
task insertAutoGeneratedEnumMappings(dependsOn : [mapIntermediaryJar, downloadIntermediary], type : FileInputOutput){
tasks.register('insertAutoGeneratedEnumMappings', FileInputOutput) {
dependsOn mapIntermediaryJar, downloadIntermediary
group = buildMappingGroup
input = mapSpecializedMethods.output
output = new File(tempDir, "unmerged-named-v2-with-enum.tiny")
@ -377,10 +306,10 @@ task insertAutoGeneratedEnumMappings(dependsOn : [mapIntermediaryJar, downloadIn
doLast {
MappingNameCompleter.completeNames(
intermediaryJarPath,
inputPath,
intermediaryMappingsPath,
outputPath
intermediaryJarPath,
inputPath,
intermediaryMappingsPath,
outputPath
)
}
}
@ -391,7 +320,7 @@ remapUnpickDefinitionsIntermediary {
mappings = insertAutoGeneratedEnumMappings.output
}
task unpickIntermediaryJar(type: UnpickJarTask) {
tasks.register('unpickIntermediaryJar', UnpickJarTask) {
group = 'unpick'
input = mapIntermediaryJar.output
output = file("${minecraft_version}-intermediary-unpicked.jar")
@ -400,48 +329,23 @@ task unpickIntermediaryJar(type: UnpickJarTask) {
classpath.from minecraftLibraries
}
task yarnUnpicked(dependsOn: "unpickIntermediaryJar", type: EnigmaTask) {
tasks.register('yarnUnpicked', EnigmaTask) {
dependsOn "unpickIntermediaryJar"
group = yarnGroup
jar = unpickIntermediaryJar.output
mappings = mappingsDir
}
task mergeV2(dependsOn: ["v2UnmergedYarnJar"], type: FileOutput) {
def mergedV2 = new File(tempDir, "merged-v2.tiny");
outputs.file mergedV2
output = new File(tempDir, "merged-reordered-v2.tiny")
inputs.file insertAutoGeneratedEnumMappings.output
inputs.file invertIntermediaryv2.output
def intermediaryPath = invertIntermediaryv2.outputFile.absolutePath
def mappingsPath = insertAutoGeneratedEnumMappings.outputFile.absolutePath
doLast {
String[] args = [
intermediaryPath,
mappingsPath,
mergedV2.getAbsolutePath(),
"intermediary",
"official"
]
new CommandMergeTinyV2().run(args)
//Reorder the mappings to match the output of loom
args = [
mergedV2.getAbsolutePath(),
output.getAbsolutePath(),
"official",
"intermediary",
"named"
]
new CommandReorderTinyV2().run(args)
}
tasks.register('mergeV2', MergeMappingsTask) {
group = buildMappingGroup
output = new File(tempDir, "merged-v2.tiny")
mappingInputs.from downloadIntermediary.output
mappingInputs.from insertAutoGeneratedEnumMappings.output
outputFormat = MappingFormat.TINY_2
}
task v2UnmergedYarnJar(dependsOn: [insertAutoGeneratedEnumMappings, combineUnpickDefinitions], type: Jar) {
tasks.register('v2UnmergedYarnJar', Jar) {
dependsOn insertAutoGeneratedEnumMappings, combineUnpickDefinitions
def mappings = insertAutoGeneratedEnumMappings.output
group = "mapping build"
archiveFileName = "yarn-${yarnVersion}-v2.jar"
@ -452,7 +356,7 @@ task v2UnmergedYarnJar(dependsOn: [insertAutoGeneratedEnumMappings, combineUnpic
from(combineUnpickDefinitions.output) {
rename combineUnpickDefinitions.output.get().asFile.name, "extras/definitions.unpick"
}
from (file(unpickMetaFile)) {
from(file(unpickMetaFile)) {
expand version: project.unpick_version
rename unpickMetaFile.name, "extras/unpick.json"
}
@ -462,8 +366,9 @@ task v2UnmergedYarnJar(dependsOn: [insertAutoGeneratedEnumMappings, combineUnpic
}
}
task v2MergedYarnJar(dependsOn: ["mergeV2"], type: Jar) {
def mappings = mergeV2.output
tasks.register('v2MergedYarnJar', Jar) {
dependsOn mergeV2
def mappings = mergeV2.outputFile
group = "mapping build"
archiveFileName = "yarn-${yarnVersion}-mergedv2.jar"
@ -473,7 +378,7 @@ task v2MergedYarnJar(dependsOn: ["mergeV2"], type: Jar) {
from(combineUnpickDefinitions.output) {
rename combineUnpickDefinitions.output.get().asFile.name, "extras/definitions.unpick"
}
from (file(unpickMetaFile)) {
from(file(unpickMetaFile)) {
expand version: project.unpick_version
rename unpickMetaFile.name, "extras/unpick.json"
}
@ -483,7 +388,8 @@ task v2MergedYarnJar(dependsOn: ["mergeV2"], type: Jar) {
}
}
task mapNamedJar(type: MapJarTask, dependsOn: ["mergeV2", "unpickIntermediaryJar"]) {
tasks.register('mapNamedJar', MapJarTask) {
dependsOn mergeV2, unpickIntermediaryJar
group = mapJarGroup
output = file("${minecraft_version}-named.jar")
input = unpickIntermediaryJar.output
@ -492,22 +398,23 @@ task mapNamedJar(type: MapJarTask, dependsOn: ["mergeV2", "unpickIntermediaryJar
from = 'intermediary'
to = 'named'
classMappings = [
"javax/annotation/Nullable": "org/jetbrains/annotations/Nullable",
"javax/annotation/Nonnull": "org/jetbrains/annotations/NotNull",
"javax/annotation/concurrent/Immutable": "org/jetbrains/annotations/Unmodifiable"
"javax/annotation/Nullable" : "org/jetbrains/annotations/Nullable",
"javax/annotation/Nonnull" : "org/jetbrains/annotations/NotNull",
"javax/annotation/concurrent/Immutable": "org/jetbrains/annotations/Unmodifiable"
]
}
def mcLibsDir = file('build/tmp/mclibs')
// Task to copy all the mc libs into a single directory.
task syncDependencies(type: Sync) {
tasks.register('syncDependencies', Sync) {
from minecraftLibraries
into mcLibsDir
}
def fakeSourceDir = file(".gradle/temp/fakeSource")
task genFakeSource(type: JavaExec, dependsOn: ["mergeV2", "mapNamedJar", syncDependencies]) {
tasks.register('genFakeSource', JavaExec) {
dependsOn mergeV2, mapNamedJar, syncDependencies
group = "javadoc generation"
inputs.file mergeV2.output
@ -519,10 +426,11 @@ task genFakeSource(type: JavaExec, dependsOn: ["mergeV2", "mapNamedJar", syncDep
mainClass = "net.fabricmc.mappingpoet.Main"
classpath configurations.mappingPoet
// use merged v2 so we have all namespaces in jd
args mergeV2.output.getAbsolutePath(), mapNamedJar.outputFile.getAbsolutePath(), fakeSourceDir.getAbsolutePath(), mcLibsDir.getAbsolutePath()
args mergeV2.outputFile.getAbsolutePath(), mapNamedJar.outputFile.getAbsolutePath(), fakeSourceDir.getAbsolutePath(), mcLibsDir.getAbsolutePath()
}
task decompileCFR(type: JavaExec, dependsOn: [mapNamedJar]) {
tasks.register('decompileCFR', JavaExec) {
dependsOn mapNamedJar
mainClass = "org.benf.cfr.reader.Main"
args mapNamedJar.outputFile.getAbsolutePath(), "--outputdir", file("namedSrc").absolutePath
@ -618,7 +526,8 @@ javadoc {
}
}
task javadocJar(type: Jar, dependsOn: ["javadoc"]) {
tasks.register('javadocJar', Jar) {
dependsOn javadoc
group = "javadoc generation"
from javadoc.destinationDir
@ -680,7 +589,7 @@ publishing {
}
// A task to ensure that the version being released has not already been released.
task checkVersion {
tasks.register('checkVersion') {
doFirst {
def xml = new URL("https://maven.fabricmc.net/net/fabricmc/yarn/maven-metadata.xml").text
def metadata = new XmlSlurper().parseText(xml)
@ -693,10 +602,6 @@ task checkVersion {
publish.mustRunAfter checkVersion
abstract class FileOutput extends DefaultTask {
@OutputFile
File output
}
abstract class FileInputOutput extends DefaultTask implements WithFileInput, WithFileOutput {
}

View File

@ -24,6 +24,7 @@ repositories {
url 'https://maven.fabricmc.net'
}
mavenCentral()
mavenLocal()
}
dependencies {
@ -34,20 +35,16 @@ dependencies {
implementation "net.fabricmc.unpick:unpick:$properties.unpick_version"
implementation "net.fabricmc.unpick:unpick-format-utils:$properties.unpick_version"
implementation "net.fabricmc.unpick:unpick-cli:$properties.unpick_version"
implementation "net.fabricmc:tiny-mappings-parser:$properties.tiny_mappings_parser_version"
implementation "net.fabricmc:tiny-remapper:$properties.tiny_remapper_version"
implementation "net.fabricmc:mappingpoet:$properties.mappingpoet_version"
implementation 'com.fasterxml.jackson.core:jackson-databind:2.13.4.2'
implementation 'net.fabricmc:mapping-io:0.4.0'
// Contains a number of useful utilities we can re-use.
implementation ("net.fabricmc:fabric-loom:1.1.10") {
implementation ("net.fabricmc:fabric-loom:1.2.7") {
transitive = false
}
implementation ('net.fabricmc:stitch:0.6.2') {
exclude module: 'enigma'
}
testImplementation platform("org.junit:junit-bom:$properties.junit_version")
testImplementation 'org.junit.jupiter:junit-jupiter'
testImplementation "org.assertj:assertj-core:$properties.assertj_version"

View File

@ -1 +1 @@
filament_version=0.5.0
filament_version=0.6.0

View File

@ -1,24 +0,0 @@
package net.fabricmc.filament.task;
import java.io.IOException;
import java.nio.file.Files;
import org.gradle.api.provider.Property;
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.TaskAction;
import net.fabricmc.filament.task.base.FilamentTask;
import net.fabricmc.filament.task.base.WithFileInput;
import net.fabricmc.filament.task.base.WithFileOutput;
import net.fabricmc.loom.util.ZipUtils;
public abstract class ExtractZipEntryTask extends FilamentTask implements WithFileInput, WithFileOutput {
@Input
public abstract Property<String> getEntry();
@TaskAction
public void run() throws IOException {
byte[] bytes = ZipUtils.unpack(getInputPath(), getEntry().get());
Files.write(getOutputPath(), bytes);
}
}

View File

@ -1,9 +1,7 @@
package net.fabricmc.filament.task;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.util.HashMap;
@ -30,11 +28,9 @@ import org.gradle.workers.WorkerExecutor;
import net.fabricmc.filament.util.FileUtil;
import net.fabricmc.filament.util.UnpickUtil;
import net.fabricmc.mapping.tree.ClassDef;
import net.fabricmc.mapping.tree.FieldDef;
import net.fabricmc.mapping.tree.MethodDef;
import net.fabricmc.mapping.tree.TinyMappingFactory;
import net.fabricmc.mapping.tree.TinyTree;
import net.fabricmc.mappingio.MappingReader;
import net.fabricmc.mappingio.tree.MappingTree;
import net.fabricmc.mappingio.tree.MemoryMappingTree;
public abstract class RemapUnpickDefinitionsTask extends DefaultTask {
@InputFile
@ -98,28 +94,28 @@ public abstract class RemapUnpickDefinitionsTask extends DefaultTask {
Map<String, String> classMappings = new HashMap<>();
Map<MethodKey, String> methodMappings = new HashMap<>();
Map<FieldKey, String> fieldMappings = new HashMap<>();
String fromM = getParameters().getSourceNamespace().get();
String toM = getParameters().getTargetNamespace().get();
try (BufferedReader reader = new BufferedReader(new FileReader(getParameters().getMappings().getAsFile().get()))) {
TinyTree tinyTree = TinyMappingFactory.loadWithDetection(reader);
final MemoryMappingTree mappingTree = new MemoryMappingTree();
MappingReader.read(getParameters().getMappings().getAsFile().get().toPath(), mappingTree);
for (ClassDef classDef : tinyTree.getClasses()) {
classMappings.put(classDef.getName(fromM), classDef.getName(toM));
final int fromM = mappingTree.getNamespaceId(getParameters().getSourceNamespace().get());
final int toM = mappingTree.getNamespaceId(getParameters().getTargetNamespace().get());
for (MethodDef methodDef : classDef.getMethods()) {
methodMappings.put(
new MethodKey(classDef.getName(fromM), methodDef.getName(fromM), methodDef.getDescriptor(fromM)),
methodDef.getName(toM)
);
}
for (MappingTree.ClassMapping classDef : mappingTree.getClasses()) {
classMappings.put(classDef.getName(fromM), classDef.getName(toM));
for (FieldDef fieldDef : classDef.getFields()) {
fieldMappings.put(
new FieldKey(classDef.getName(fromM), fieldDef.getName(fromM)),
fieldDef.getName(toM)
);
}
for (MappingTree.MethodMapping methodDef : classDef.getMethods()) {
methodMappings.put(
new MethodKey(classDef.getName(fromM), methodDef.getName(fromM), methodDef.getDesc(fromM)),
methodDef.getName(toM)
);
}
for (MappingTree.FieldMapping fieldDef : classDef.getFields()) {
fieldMappings.put(
new FieldKey(classDef.getName(fromM), fieldDef.getName(fromM)),
fieldDef.getName(toM)
);
}
}

View File

@ -1,34 +0,0 @@
package net.fabricmc.filament.task.enigma;
import java.util.List;
import cuchaz.enigma.command.Command;
import cuchaz.enigma.command.ConvertMappingsCommand;
import org.gradle.api.provider.Property;
import org.gradle.api.tasks.Input;
import net.fabricmc.filament.task.base.WithFileInput;
import net.fabricmc.filament.task.base.WithFileOutput;
public abstract class ConvertMappingsTask extends EnigmaCommandTask implements WithFileInput, WithFileOutput {
@Input
public abstract Property<String> getInputMappingsFormat();
@Input
public abstract Property<String> getOutputMappingsFormat();
@Override
public Class<? extends Command> getCommandClass() {
return ConvertMappingsCommand.class;
}
@Override
protected List<String> getArguments() {
return List.of(
getInputMappingsFormat().get(),
getInputFile().getAbsolutePath(),
getOutputMappingsFormat().get(),
getOutputFile().getAbsolutePath()
);
}
}

View File

@ -0,0 +1,14 @@
package net.fabricmc.filament.task.mappingio;
import java.io.IOException;
import net.fabricmc.filament.task.base.WithFileInput;
import net.fabricmc.mappingio.MappingReader;
import net.fabricmc.mappingio.MappingWriter;
public abstract class ConvertMappingsTask extends MappingOutputTask implements WithFileInput {
@Override
void run(MappingWriter writer) throws IOException {
MappingReader.read(getInputPath(), writer);
}
}

View File

@ -0,0 +1,26 @@
package net.fabricmc.filament.task.mappingio;
import java.io.IOException;
import org.gradle.api.provider.Property;
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.TaskAction;
import net.fabricmc.filament.task.base.FilamentTask;
import net.fabricmc.filament.task.base.WithFileOutput;
import net.fabricmc.mappingio.MappingWriter;
import net.fabricmc.mappingio.format.MappingFormat;
public abstract class MappingOutputTask extends FilamentTask implements WithFileOutput {
@Input
public abstract Property<MappingFormat> getOutputFormat();
@TaskAction
public final void run() throws IOException {
try (MappingWriter mappingWriter = MappingWriter.create(getOutputPath(), getOutputFormat().get())) {
run(mappingWriter);
}
}
abstract void run(MappingWriter writer) throws IOException;
}

View File

@ -0,0 +1,75 @@
package net.fabricmc.filament.task.mappingio;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;
import org.gradle.api.file.ConfigurableFileCollection;
import org.gradle.api.tasks.InputFiles;
import net.fabricmc.mappingio.MappingReader;
import net.fabricmc.mappingio.MappingWriter;
import net.fabricmc.mappingio.adapter.MappingDstNsReorder;
import net.fabricmc.mappingio.adapter.MappingNsCompleter;
import net.fabricmc.mappingio.adapter.MappingSourceNsSwitch;
import net.fabricmc.mappingio.tree.MappingTree;
import net.fabricmc.mappingio.tree.MemoryMappingTree;
public abstract class MergeMappingsTask extends MappingOutputTask {
@InputFiles
public abstract ConfigurableFileCollection getMappingInputs();
@Override
void run(MappingWriter writer) throws IOException {
var mappingTree = new MemoryMappingTree();
for (File file : getMappingInputs().getFiles()) {
var nsSwitch = new MappingSourceNsSwitch(mappingTree, "intermediary");
MappingReader.read(file.toPath(), nsSwitch);
}
fixInnerClasses(mappingTree);
var nsCompleter = new MappingNsCompleter(writer, Map.of("named", "intermediary"), true);
var dstReorder = new MappingDstNsReorder(nsCompleter, List.of("official", "named"));
mappingTree.accept(dstReorder);
}
private void fixInnerClasses(MemoryMappingTree mappingTree) {
int named = mappingTree.getNamespaceId("named");
for (MappingTree.ClassMapping entry : mappingTree.getClasses()) {
String name = entry.getName(named);
if (name != null) {
continue;
}
entry.setDstName(matchEnclosingClass(entry.getSrcName(), mappingTree), named);
}
}
/*
* Takes something like net/minecraft/class_123$class_124 that doesn't have a mapping, tries to find net/minecraft/class_123
* , say the mapping of net/minecraft/class_123 is path/to/someclass and then returns a class of the form
* path/to/someclass$class124
*/
private String matchEnclosingClass(String sharedName, MemoryMappingTree mappingTree) {
final int named = mappingTree.getNamespaceId("named");
final String[] path = sharedName.split(Pattern.quote("$"));
for (int i = path.length - 2; i >= 0; i--) {
final String currentPath = String.join("$", Arrays.copyOfRange(path, 0, i + 1));
final MappingTree.ClassMapping match = mappingTree.getClass(currentPath);
if (match != null && match.getName(named) != null) {
return match.getName(named) + "$" + String.join("$", Arrays.copyOfRange(path, i + 1, path.length));
}
}
return sharedName;
}
}

View File

@ -7,7 +7,7 @@ import org.gradle.api.tasks.InputFile;
import org.gradle.api.tasks.TaskAction;
import net.fabricmc.filament.task.base.FileOutputTask;
import net.fabricmc.stitch.merge.JarMerger;
import net.fabricmc.loom.configuration.providers.minecraft.MinecraftJarMerger;
public abstract class MergeMinecraftTask extends FileOutputTask {
@InputFile
@ -18,7 +18,7 @@ public abstract class MergeMinecraftTask extends FileOutputTask {
@TaskAction
public void run() throws IOException {
try (JarMerger jarMerger = new JarMerger(
try (MinecraftJarMerger jarMerger = new MinecraftJarMerger(
getClientJar().getAsFile().get(),
getServerJar().getAsFile().get(),
getOutput().getAsFile().get())) {

View File

@ -4,12 +4,10 @@ org.gradle.parallel=true
org.gradle.configuration-cache=true
enigma_version=2.3.1
stitch_version=0.6.1
unpick_version=2.3.0
cfr_version=0.1.1
name_proposal_version=0.1.4
tiny_remapper_version=0.8.5
asm_version=9.4
asm_version=9.5
# Javadoc generation/linking
fabric_loader_version=0.14.14
@ -17,6 +15,6 @@ jetbrains_annotations_version=23.0.0
mappingpoet_version=0.3.2
# Build logic
tiny_mappings_parser_version=0.3.0+build.17
tiny_remapper_version=0.8.5
junit_version=5.7.1
assertj_version=3.19.0