diff --git a/build.gradle b/build.gradle index a8281ca756..38efc6624a 100644 --- a/build.gradle +++ b/build.gradle @@ -5,11 +5,10 @@ buildscript { name "Fabric Repository" url 'https://maven.fabricmc.net' } - mavenLocal() } dependencies { - classpath "cuchaz:enigma:0.14.1.130" - classpath "net.fabricmc:stitch:0.2.1.61" + classpath "cuchaz:enigma:0.14.2.143" + classpath "net.fabricmc:stitch:0.4.0.67" classpath "commons-io:commons-io:2.6" classpath "com.google.guava:guava:28.0-jre" classpath 'de.undercouch:gradle-download-task:3.4.3' @@ -49,8 +48,8 @@ configurations { } dependencies { - enigmaRuntime "net.fabricmc:stitch:0.2.1.61" - enigmaRuntime "cuchaz:enigma:0.14.1.130:all" + enigmaRuntime "net.fabricmc:stitch:0.4.0.67" + enigmaRuntime "cuchaz:enigma:0.14.2.143" } def setupGroup = "jar setup" @@ -58,7 +57,6 @@ def yarnGroup = "yarn" def buildMappingGroup = "mapping build" def mapJarGroup = "jar mapping" def mappingsDir = file("mappings") -def mappingsExportOfficialDir = file("mappings_official") def cacheFilesMinecraft = file(".gradle/minecraft") def tempDir = file(".gradle/temp") def mergedFile = file("${minecraft_version}-merged.jar") @@ -71,18 +69,18 @@ def serverJar = new File(cacheFilesMinecraft, "${minecraft_version}-server.jar") def libraries = new File(cacheFilesMinecraft, "libraries") def libs = new File("build/libs/") + +import com.google.common.hash.Hashing import cuchaz.enigma.command.CheckMappingsCommand import cuchaz.enigma.command.ComposeMappingsCommand import cuchaz.enigma.command.ConvertMappingsCommand -import com.google.common.hash.Hashing -import com.google.common.io.Files -import com.google.common.net.UrlEscapers import groovy.io.FileType import groovy.json.JsonSlurper import net.fabricmc.stitch.commands.CommandMergeTiny import net.fabricmc.stitch.commands.CommandProposeFieldNames import net.fabricmc.stitch.commands.CommandReorderTiny import net.fabricmc.stitch.commands.CommandRewriteIntermediary +import net.fabricmc.stitch.commands.tinyv2.CommandProposeV2FieldNames import net.fabricmc.stitch.merge.JarMerger import net.fabricmc.tinyremapper.OutputConsumerPath import net.fabricmc.tinyremapper.TinyRemapper @@ -94,7 +92,7 @@ import java.util.zip.GZIPOutputStream boolean validateChecksum(File file, String checksum) { if (file != null) { - def hash = Files.asByteSource(file).hash(Hashing.sha1()) + def hash = com.google.common.io.Files.asByteSource(file).hash(Hashing.sha1()) def builder = new StringBuilder() hash.asBytes().each { builder.append(Integer.toString((it & 0xFF) + 0x100, 16).substring(1)) @@ -118,7 +116,9 @@ task downloadVersionsManifest { def getManifestVersion(File manifestFile, String minecraft_version) { def manifest = manifestFile.exists() ? new JsonSlurper().parseText(FileUtils.readFileToString(manifestFile)) : null - return manifest != null ? manifest.versions.stream().filter({it.id.equals(minecraft_version)}).findFirst() : java.util.Optional.empty() + return manifest != null ? manifest.versions.stream().filter({ + it.id.equals(minecraft_version) + }).findFirst() : java.util.Optional.empty() } task downloadWantedVersionManifest(dependsOn: downloadVersionsManifest) { @@ -132,7 +132,8 @@ task downloadWantedVersionManifest(dependsOn: downloadVersionsManifest) { outputs.file versionFile doLast { - manifestVersion = getManifestVersion(manifestFile, minecraft_version) //nb need to re-read here in case it didn't exist before + manifestVersion = getManifestVersion(manifestFile, minecraft_version) + //nb need to re-read here in case it didn't exist before if (manifestVersion.isPresent() || versionFile.exists()) { if (manifestVersion.isPresent()) { @@ -178,10 +179,10 @@ task downloadMcJars(dependsOn: downloadWantedVersionManifest) { } } -task downloadIntermediary(type: Download){ +task downloadIntermediary(type: Download) { group = buildMappingGroup def url = "https://github.com/FabricMC/intermediary/raw/master/mappings/${minecraft_version}.tiny" - src UrlEscapers.urlFragmentEscaper().escape(url) + src com.google.common.net.UrlEscapers.urlFragmentEscaper().escape(url) dest new File(cacheFilesMinecraft, "${minecraft_version}-intermediary.tiny") } @@ -192,11 +193,11 @@ task mergeJars(dependsOn: downloadMcJars) { doLast { logger.lifecycle(":merging jars") - def client = inputs.files.files.find {it.name.endsWith("-client.jar")} - def server = inputs.files.files.find {it.name.endsWith("-server.jar")} + def client = inputs.files.files.find { it.name.endsWith("-client.jar") } + def server = inputs.files.files.find { it.name.endsWith("-server.jar") } def merged = mergedFile - if(merged.exists()){ + if (merged.exists()) { return } @@ -213,7 +214,7 @@ task downloadMcLibs(dependsOn: downloadWantedVersionManifest) { outputs.dir(libraries) - outputs.upToDateWhen {false} + outputs.upToDateWhen { false } doLast { if (!versionFile.exists()) { @@ -240,45 +241,44 @@ task downloadMcLibs(dependsOn: downloadWantedVersionManifest) { } } -task invertIntermediary(dependsOn: ["downloadIntermediary"], type: FileOutput) { +task invertIntermediary(dependsOn: downloadIntermediary, type: FileOutput) { group = buildMappingGroup - def inputFile = downloadIntermediary.dest + def v1Input = downloadIntermediary.dest - def outputFile = new File(cacheFilesMinecraft, "${minecraft_version}-intermediary-inverted.tiny") - outputs.file(outputFile) - fileOutput = outputFile + output = new File(cacheFilesMinecraft, "${minecraft_version}-intermediary-inverted.tiny") + outputs.file(output) - outputs.upToDateWhen {false} + outputs.upToDateWhen { false } doLast { logger.lifecycle(":building inverted intermediary") - String[] args = [ - inputFile.getAbsolutePath(), - outputFile.getAbsolutePath(), - "intermediary", "official" + + String[] v1Args = [ + v1Input.getAbsolutePath(), + output.getAbsolutePath(), + "intermediary", "official" ] - new CommandReorderTiny().run(args) + new CommandReorderTiny().run(v1Args) } } -task patchIntermediary(dependsOn: ["mergeJars", "downloadIntermediary"], type: FileOutput) { +task patchIntermediary(dependsOn: [mergeJars, downloadIntermediary]) { group = buildMappingGroup def intermediaryTinyInput = downloadIntermediary.dest def outputFile = new File(cacheFilesMinecraft, "${minecraft_version}-intermediary-full.tiny") outputs.file(outputFile) - fileOutput = outputFile - outputs.upToDateWhen {false} + outputs.upToDateWhen { false } doLast { logger.lifecycle(":patching intermediary") String[] args = [ - mergedFile.getAbsolutePath(), - intermediaryTinyInput.getAbsolutePath(), - outputFile.getAbsolutePath(), - "--writeAll" + mergedFile.getAbsolutePath(), + intermediaryTinyInput.getAbsolutePath(), + outputFile.getAbsolutePath(), + "--writeAll" ] new CommandRewriteIntermediary().run(args) @@ -291,11 +291,11 @@ task mapIntermediaryJar(dependsOn: [downloadMcLibs, downloadIntermediary, mergeJ outputs.file(intermediaryJar) //Force the task to always run - outputs.upToDateWhen {false} + outputs.upToDateWhen { false } doLast { logger.lifecycle(":mapping minecraft to intermediary") - def tinyInput = new File(cacheFilesMinecraft, "${minecraft_version}-intermediary.tiny") + def tinyInput = downloadIntermediary.dest mapJar(intermediaryJar, mergedFile, tinyInput, libraries, "official", "intermediary") } } @@ -309,10 +309,10 @@ task yarn(dependsOn: setupYarn) { doLast { ant.setLifecycleLogLevel "WARN" ant.java( - classname: 'cuchaz.enigma.Main', - classpath: configurations.enigmaRuntime.asPath, - fork: true, - spawn: true + classname: 'cuchaz.enigma.Main', + classpath: configurations.enigmaRuntime.asPath, + fork: true, + spawn: true ) { jvmarg(value: "-Xmx2048m") arg(value: '-jar') @@ -332,95 +332,102 @@ task checkMappings { logger.lifecycle(":checking mappings") String[] args = [ - mergedFile.getAbsolutePath(), - mappingsDir.getAbsolutePath() + mergedFile.getAbsolutePath(), + mappingsDir.getAbsolutePath() ] new CheckMappingsCommand().run(args) } } -task buildYarnTiny(dependsOn: "mergeJars", type: FileOutput) { +task buildYarnTiny(dependsOn: mergeJars, type: WithV2FileOutput) { group = buildMappingGroup inputs.dir mappingsDir if (!libs.exists()) { libs.mkdirs() } - def yarnTiny = new File(tempDir, "yarn-mappings.tiny") - fileOutput = yarnTiny - - outputs.upToDateWhen {false} + v1Output = new File(tempDir, "yarn-mappings.tiny") + v2Output = new File(tempDir, "yarn-mappings-v2.tiny") + + outputs.upToDateWhen { false } doLast { logger.lifecycle(":generating tiny mappings") - String[] args = [ - "enigma", - mappingsDir.getAbsolutePath(), - "tiny:intermediary:named", - yarnTiny.getAbsolutePath() + String[] v1Args = [ + "enigma", + mappingsDir.getAbsolutePath(), + "tiny:intermediary:named", + v1Output.getAbsolutePath() ] - new ConvertMappingsCommand().run(args) + String[] v2Args = [ + "enigma", + mappingsDir.getAbsolutePath(), + "tinyv2:intermediary:named", + v2Output.getAbsolutePath() + ] + + new ConvertMappingsCommand().run(v1Args) + new ConvertMappingsCommand().run(v2Args) } } task mergeTiny(dependsOn: ["buildYarnTiny", "invertIntermediary"], type: FileOutput) { group = buildMappingGroup - def yarnTinyInput = buildYarnTiny.fileOutput - def intermediaryTinyInput = invertIntermediary.fileOutput + def yarnTinyInput = buildYarnTiny.v1Output + def intermediaryTinyInput = invertIntermediary.output def unorderedResultMappings = new File(tempDir, "mappings-unordered.tiny") - def resultMappings = new File(tempDir, "mappings.tiny") - outputs.file(resultMappings) - fileOutput = resultMappings + output = new File(tempDir, "mappings.tiny") + outputs.file(output) - outputs.upToDateWhen {false} + outputs.upToDateWhen { false } doLast { logger.lifecycle(":merging yarn and intermediary") String[] args = [ - intermediaryTinyInput.getAbsolutePath(), - yarnTinyInput.getAbsolutePath(), - unorderedResultMappings.getAbsolutePath(), - "intermediary", - "official" + intermediaryTinyInput.getAbsolutePath(), + yarnTinyInput.getAbsolutePath(), + unorderedResultMappings.getAbsolutePath(), + "intermediary", + "official" ] new CommandMergeTiny().run(args) logger.lifecycle(":reordering merged intermediary") String[] args2 = [ - unorderedResultMappings.getAbsolutePath(), - resultMappings.getAbsolutePath(), - "official", "intermediary", "named" + unorderedResultMappings.getAbsolutePath(), + output.getAbsolutePath(), + "official", "intermediary", "named" ] new CommandReorderTiny().run(args2) } } -task tinyJar(type: Jar, dependsOn: "mergeTiny") { +task tinyJar(type: Jar, dependsOn: mergeTiny) { group = buildMappingGroup - outputs.upToDateWhen {false} + outputs.upToDateWhen { false } archiveName = "yarn-${yarnVersion}.jar" destinationDir(file("build/libs")) classifier = "" - from (mergeTiny.fileOutput) { + from(mergeTiny.output) { rename { "mappings/mappings.tiny" } } } -task compressTiny(dependsOn: ["tinyJar", "mergeTiny"], type: FileOutput){ +task compressTiny(dependsOn: [tinyJar, mergeTiny], type: FileOutput) { group = buildMappingGroup def outputFile = new File(libs, "yarn-tiny-${yarnVersion}.gz") outputs.file(outputFile) - fileOutput = outputFile + output = outputFile - def inputFile = mergeTiny.fileOutput + def inputFile = mergeTiny.output - outputs.upToDateWhen {false} + outputs.upToDateWhen { false } doLast { logger.lifecycle(":compressing tiny mappings") @@ -445,57 +452,56 @@ clean.doFirst { delete tempDir, cacheFilesMinecraft } -tasks.build.dependsOn "compressTiny" -tasks.build.dependsOn "tinyJar" +tasks.build.dependsOn "compressTiny","tinyJar","v2UnmergedYarnJar" -task mapYarnJar(dependsOn: ["compressTiny", "mapIntermediaryJar"]) { +task mapYarnJar(dependsOn: [compressTiny, mapIntermediaryJar]) { group = mapJarGroup inputs.files downloadMcLibs.outputs.files.files outputs.file(yarnJar) //Force the task to always run - outputs.upToDateWhen {false} + outputs.upToDateWhen { false } doLast { logger.lifecycle(":mapping minecraft to yarn") - def tinyInput = new File("build/libs/yarn-tiny-${yarnVersion}.gz") + File tinyInput = compressTiny.output mapJar(yarnJar, intermediaryJar, tinyInput, libraries, "intermediary", "named") } } -task exportMappingsOfficial(dependsOn: "downloadIntermediary") { +task exportMappingsOfficial(dependsOn: downloadIntermediary) { def composeInput = downloadIntermediary.dest doLast { logger.lifecycle(":exporting mappings") String[] args = [ - "tiny", - composeInput.getAbsolutePath(), - "enigma", - file("mappings/").getAbsolutePath(), - "enigma", - file("mappings_official/").getAbsolutePath(), - "right" + "tiny", + composeInput.getAbsolutePath(), + "enigma", + file("mappings/").getAbsolutePath(), + "enigma", + file("mappings_official/").getAbsolutePath(), + "right" ] new ComposeMappingsCommand().run(args) } } -task importMappingsOfficial(dependsOn: "invertIntermediary") { - def composeInput = invertIntermediary.fileOutput +task importMappingsOfficial(dependsOn: invertIntermediary) { + def composeInput = invertIntermediary.output doLast { logger.lifecycle(":importing mappings") String[] args = [ - "tiny", - composeInput.getAbsolutePath(), - "enigma", - file("mappings_official/").getAbsolutePath(), - "enigma", - file("mappings/").getAbsolutePath(), - "right" + "tiny", + composeInput.getAbsolutePath(), + "enigma", + file("mappings_official/").getAbsolutePath(), + "enigma", + file("mappings/").getAbsolutePath(), + "right" ] new ComposeMappingsCommand().run(args) @@ -504,19 +510,18 @@ task importMappingsOfficial(dependsOn: "invertIntermediary") { task buildTinyWithEnum(dependsOn: "mergeTiny", type: FileOutput) { group = buildMappingGroup - def noEnum = mergeTiny.fileOutput - def namedWithEnum = new File(tempDir, "named-with-enum.tiny") - fileOutput = namedWithEnum + def noEnum = mergeTiny.output + output = new File(tempDir, "named-with-enum.tiny") - outputs.file(namedWithEnum) + outputs.file(output) outputs.upToDateWhen { false } doLast { logger.lifecycle(":seeking auto-mappable fields") String[] argsPropose = [ - mergedFile.getAbsolutePath(), // must use official jar - noEnum.getAbsolutePath(), - namedWithEnum.getAbsolutePath() + mergedFile.getAbsolutePath(), // must use official jar + noEnum.getAbsolutePath(), + output.getAbsolutePath() ] new CommandProposeFieldNames().run(argsPropose) @@ -534,10 +539,43 @@ task mapNamedJar(dependsOn: [buildTinyWithEnum, mapIntermediaryJar]) { doLast { logger.lifecycle(":mapping minecraft to named") - mapJar(namedJar, intermediaryJar, buildTinyWithEnum.fileOutput, libraries, "intermediary", "named") + mapJar(namedJar, intermediaryJar, buildTinyWithEnum.output, libraries, "intermediary", "named") } } +task insertAutoGeneratedEnumMappings(dependsOn : [buildYarnTiny,mapIntermediaryJar], type : FileOutput){ + group = buildMappingGroup + def noEnumV2 = buildYarnTiny.v2Output + output = new File(tempDir, "unmerged-named-v2-with-enum.tiny") + + outputs.upToDateWhen { false } + + doLast { + logger.lifecycle(":seeking auto-mappable fields for unmerged mappings") + + String[] argsProposeV2 = [ + intermediaryJar.getAbsolutePath(), // must use intermediary jar + noEnumV2.getAbsolutePath(), + output.getAbsolutePath(), + "false" // don't replace existing names right now + ] + + new CommandProposeV2FieldNames().run(argsProposeV2) + } +} + +task v2UnmergedYarnJar(dependsOn: insertAutoGeneratedEnumMappings, type: Jar) { + def mappings = insertAutoGeneratedEnumMappings.output + group = "mapping build" + outputs.upToDateWhen { false } + archiveName = "yarn-${yarnVersion}-v2.jar" + + from(file(mappings)) { + rename mappings.name, "mappings/mappings.tiny" + } + destinationDir(file("build/libs")) +} + publishing { publications { @@ -546,12 +584,16 @@ publishing { artifactId "yarn" version yarnVersion - artifact (compressTiny.fileOutput) { + artifact(compressTiny.output) { classifier "tiny" builtBy compressTiny } - artifact (tinyJar) + artifact(tinyJar) + artifact(v2UnmergedYarnJar) { + classifier "v2" + } } + } repositories { maven { @@ -567,23 +609,23 @@ publishing { } -void mapJar(File output, File input, File mappings, File libraries, String from, String to){ +void mapJar(File output, File input, File mappings, File libraries, String from, String to) { if (output.exists()) { output.delete() } def remapper = TinyRemapper.newRemapper() - .withMappings(TinyUtils.createTinyMappingProvider(mappings.toPath(), from, to)) - .renameInvalidLocals(true) - .rebuildSourceFilenames(true) - .build() - + .withMappings(TinyUtils.createTinyMappingProvider(mappings.toPath(), from, to)) + .renameInvalidLocals(true) + .rebuildSourceFilenames(true) + .build() + try { def outputConsumer = new OutputConsumerPath(output.toPath()) outputConsumer.addNonClassFiles(input.toPath()) remapper.readInputs(input.toPath()) - libraries.eachFileRecurse(FileType.FILES) {file -> + libraries.eachFileRecurse(FileType.FILES) { file -> remapper.readClassPath(file.toPath()) } remapper.apply(outputConsumer) @@ -596,5 +638,13 @@ void mapJar(File output, File input, File mappings, File libraries, String from, } class FileOutput extends DefaultTask { - @OutputFile File fileOutput + @OutputFile + File output +} + +class WithV2FileOutput extends DefaultTask { + @OutputFile + File v1Output + @OutputFile + File v2Output }