Produce TinyV2 mappings (#914)

This commit is contained in:
Fudge 2019-11-07 13:38:33 +02:00 committed by Player
parent c37fc0ee16
commit 62a62ba816
2 changed files with 193 additions and 122 deletions

View File

@ -5,11 +5,10 @@ buildscript {
name "Fabric Repository"
url 'https://maven.fabricmc.net'
}
mavenLocal()
}
dependencies {
classpath "cuchaz:enigma:0.14.2.134"
classpath "net.fabricmc:stitch:0.2.1.61"
classpath "net.fabricmc:stitch:0.3.0.66"
classpath "commons-io:commons-io:2.6"
classpath "com.google.guava:guava:28.0-jre"
classpath 'de.undercouch:gradle-download-task:3.4.3'
@ -46,11 +45,13 @@ configurations {
cacheChangingModulesFor 0, "seconds"
}
}
intermediary
}
dependencies {
enigmaRuntime "net.fabricmc:stitch:0.2.1.61"
enigmaRuntime "cuchaz:enigma:0.14.2.134:all"
enigmaRuntime "net.fabricmc:stitch:0.3.0.66"
enigmaRuntime "cuchaz:enigma:0.14.2.134"
intermediary "net.fabricmc:intermediary:$minecraft_version"
}
def setupGroup = "jar setup"
@ -58,7 +59,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 +71,19 @@ 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 com.google.common.collect.Iterables
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
@ -90,11 +91,14 @@ import net.fabricmc.tinyremapper.TinyUtils
import org.apache.commons.io.FileUtils
import java.nio.charset.StandardCharsets
import java.nio.file.FileSystems
import java.nio.file.Files
import java.nio.file.Path
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 +122,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 +138,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,13 +185,27 @@ task downloadMcJars(dependsOn: downloadWantedVersionManifest) {
}
}
task downloadIntermediary(type: Download){
task extractIntermediary(type: FileOutput) {
group = buildMappingGroup
def url = "https://github.com/FabricMC/intermediary/raw/master/mappings/${minecraft_version}.tiny"
src UrlEscapers.urlFragmentEscaper().escape(url)
dest new File(cacheFilesMinecraft, "${minecraft_version}-intermediary.tiny")
def v1Input = Iterables.getOnlyElement(configurations.intermediary.files)
output = new File(cacheFilesMinecraft.getPath(), "${minecraft_version}-intermediary.tiny")
doLast {
FileSystems.newFileSystem(v1Input.toPath(), null).withCloseable {
Path fileToExtract = it.getPath("mappings/mappings.tiny")
try {
Files.copy(fileToExtract, output.toPath())
} catch (Exception ignored) {
} // fuck groovy
}
}
}
task mergeJars(dependsOn: downloadMcJars) {
group = setupGroup
inputs.files downloadMcJars.outputs.files.files
@ -192,11 +213,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 +234,7 @@ task downloadMcLibs(dependsOn: downloadWantedVersionManifest) {
outputs.dir(libraries)
outputs.upToDateWhen {false}
outputs.upToDateWhen { false }
doLast {
if (!versionFile.exists()) {
@ -240,62 +261,61 @@ task downloadMcLibs(dependsOn: downloadWantedVersionManifest) {
}
}
task invertIntermediary(dependsOn: ["downloadIntermediary"], type: FileOutput) {
task invertIntermediary(dependsOn: extractIntermediary, type: FileOutput) {
group = buildMappingGroup
def inputFile = downloadIntermediary.dest
def v1Input = extractIntermediary.output
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, extractIntermediary]) {
group = buildMappingGroup
def intermediaryTinyInput = downloadIntermediary.dest
def intermediaryTinyInput = extractIntermediary.output
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)
}
}
task mapIntermediaryJar(dependsOn: [downloadMcLibs, downloadIntermediary, mergeJars]) {
task mapIntermediaryJar(dependsOn: [downloadMcLibs, extractIntermediary, mergeJars]) {
group = mapJarGroup
inputs.files downloadMcLibs.outputs.files.files
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 = extractIntermediary.output
mapJar(intermediaryJar, mergedFile, tinyInput, libraries, "official", "intermediary")
}
}
@ -309,10 +329,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 +352,103 @@ 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)
def x = 2
}
}
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 +473,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") {
def composeInput = downloadIntermediary.dest
task exportMappingsOfficial(dependsOn: extractIntermediary) {
def composeInput = extractIntermediary.output
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 +531,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 +560,42 @@ 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()
]
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 +604,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 +629,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 +658,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
}

View File

@ -1,5 +1,6 @@
#Wed Oct 16 22:10:09 IDT 2019
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.3-all.zip
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.3-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME