Add proposed field names to the mapped named jar

Changed old named jar to yarn jar
Beautify readme and added groups to gradle tasks
always indent with tabs

Signed-off-by: liach <liach@users.noreply.github.com>
This commit is contained in:
liach 2019-05-12 18:45:52 -07:00
parent a8804c177e
commit ce3f15c1e2
2 changed files with 88 additions and 22 deletions

View File

@ -20,6 +20,17 @@ However, it is a good idea to consult name changes with other people - use pull
## Gradle ## Gradle
Yarn uses Gradle to provide a number of utility tasks for working with the mappings. Yarn uses Gradle to provide a number of utility tasks for working with the mappings.
### `yarn`
[`setupYarn`](#setupYarn) and download and launch the latest version of [Enigma](https://github.com/FabricMC/Enigma) automatically configured to use the merged jar and the mappings.
Compared to launching Enigma externally, the gradle task adds a name guesser plugin that automatically map enums and a few constant field names.
### `build`
Build a GZip'd archive containing a tiny mapping between official (obfuscated), [intermediary](https://github.com/FabricMC/intermediary), and yarn names ("named") and packages enigma mappings into a zip archive..
### `mapNamedJar`
Builds a deobfuscated jar with yarn mappings and automapped fields (enums, etc.). Unmapped names will be filled with [intermediary](https://github.com/FabricMC/Intermediary) names.
### `download` ### `download`
Downloads the client and server Minecraft jars for the current Minecraft version to `.gradle/minecraft` Downloads the client and server Minecraft jars for the current Minecraft version to `.gradle/minecraft`
@ -27,7 +38,4 @@ Downloads the client and server Minecraft jars for the current Minecraft version
Merges the client and server jars into one merged jar, located at `VERSION-merged.jar` in the mappings directory where `VERSION` is the current Minecraft version. Merges the client and server jars into one merged jar, located at `VERSION-merged.jar` in the mappings directory where `VERSION` is the current Minecraft version.
### `setupYarn` ### `setupYarn`
`download` and `mergeJars` [`download`](#download) and [`mergeJars`](#mergeJars)
### `yarn`
`setupYarn` and download and launch the latest version of Enigma automatically configured to use the merged jar and the mappings.

View File

@ -30,7 +30,6 @@ def build_number = ENV.BUILD_NUMBER ?: "local"
def yarnVersion = "${minecraft_version}+build.$build_number" def yarnVersion = "${minecraft_version}+build.$build_number"
repositories { repositories {
mavenCentral() mavenCentral()
maven { maven {
@ -50,14 +49,19 @@ configurations {
dependencies { dependencies {
enigmaRuntime "net.fabricmc:stitch:0.1.2.51+" enigmaRuntime "net.fabricmc:stitch:0.1.2.51+"
enigmaRuntime "cuchaz:enigma:0.13.1.116:all" enigmaRuntime "cuchaz:enigma:0.13.1.116+:all"
} }
def setupGroup = "jar setup"
def yarnGroup = "yarn"
def buildMappingGroup = "mapping build"
def mapJarGroup = "jar mapping"
def mappingsDir = file("mappings") def mappingsDir = file("mappings")
def cacheFilesMinecraft = file(".gradle/minecraft") def cacheFilesMinecraft = file(".gradle/minecraft")
def tempDir = file(".gradle/temp") def tempDir = file(".gradle/temp")
def mergedFile = file("${minecraft_version}-merged.jar") def mergedFile = file("${minecraft_version}-merged.jar")
def intermediaryJar = file("${minecraft_version}-intermediary.jar") def intermediaryJar = file("${minecraft_version}-intermediary.jar")
def yarnJar = file("${minecraft_version}-yarn.jar")
def namedJar = file("${minecraft_version}-named.jar") def namedJar = file("${minecraft_version}-named.jar")
def versionFile = new File(cacheFilesMinecraft, "${minecraft_version}.json") def versionFile = new File(cacheFilesMinecraft, "${minecraft_version}.json")
def clientJar = new File(cacheFilesMinecraft, "${minecraft_version}-client.jar") def clientJar = new File(cacheFilesMinecraft, "${minecraft_version}-client.jar")
@ -65,10 +69,11 @@ def serverJar = new File(cacheFilesMinecraft, "${minecraft_version}-server.jar")
def libraries = new File(cacheFilesMinecraft, "${minecraft_version}-libraries") def libraries = new File(cacheFilesMinecraft, "${minecraft_version}-libraries")
def libs = new File("build/libs/") def libs = new File("build/libs/")
import groovy.json.JsonSlurper
import org.apache.commons.io.FileUtils
import com.google.common.hash.Hashing import com.google.common.hash.Hashing
import com.google.common.io.Files 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.CommandMergeTiny
import net.fabricmc.stitch.commands.CommandProposeFieldNames import net.fabricmc.stitch.commands.CommandProposeFieldNames
import net.fabricmc.stitch.commands.CommandRewriteIntermediary import net.fabricmc.stitch.commands.CommandRewriteIntermediary
@ -78,12 +83,13 @@ import net.fabricmc.tinyremapper.TinyRemapper
import net.fabricmc.tinyremapper.TinyUtils import net.fabricmc.tinyremapper.TinyUtils
import net.fabricmc.weave.CommandFindMappingErrors import net.fabricmc.weave.CommandFindMappingErrors
import net.fabricmc.weave.CommandTinyify import net.fabricmc.weave.CommandTinyify
import groovy.io.FileType import org.apache.commons.io.FileUtils
import java.util.zip.GZIPOutputStream import java.util.zip.GZIPOutputStream
boolean validateChecksum(File file, String checksum) { boolean validateChecksum(File file, String checksum) {
if (file != null) { if (file != null) {
def hash = Files.hash(file, Hashing.sha1()) def hash = Files.asByteSource(file).hash(Hashing.sha1())
def builder = new StringBuilder() def builder = new StringBuilder()
hash.asBytes().each { hash.asBytes().each {
builder.append(Integer.toString((it & 0xFF) + 0x100, 16).substring(1)) builder.append(Integer.toString((it & 0xFF) + 0x100, 16).substring(1))
@ -94,6 +100,7 @@ boolean validateChecksum(File file, String checksum) {
} }
task downloadVersionsManifest { task downloadVersionsManifest {
group = setupGroup
//inputs.property "mc_ver", minecraft_version //inputs.property "mc_ver", minecraft_version
inputs.property "currenttime", new Date() inputs.property "currenttime", new Date()
def manifestFile = new File(cacheFilesMinecraft, "version_manifest.json") def manifestFile = new File(cacheFilesMinecraft, "version_manifest.json")
@ -110,6 +117,7 @@ def getManifestVersion(File manifestFile, String minecraft_version) {
} }
task downloadWantedVersionManifest(dependsOn: downloadVersionsManifest) { task downloadWantedVersionManifest(dependsOn: downloadVersionsManifest) {
group = setupGroup
def manifestFile = downloadVersionsManifest.outputs.files.singleFile def manifestFile = downloadVersionsManifest.outputs.files.singleFile
def manifestVersion = getManifestVersion(manifestFile, minecraft_version) def manifestVersion = getManifestVersion(manifestFile, minecraft_version)
@ -133,7 +141,7 @@ task downloadWantedVersionManifest(dependsOn: downloadVersionsManifest) {
} }
task downloadMcJars(dependsOn: downloadWantedVersionManifest) { task downloadMcJars(dependsOn: downloadWantedVersionManifest) {
group = setupGroup
inputs.files versionFile inputs.files versionFile
outputs.files(clientJar, serverJar) outputs.files(clientJar, serverJar)
@ -166,6 +174,7 @@ task downloadMcJars(dependsOn: downloadWantedVersionManifest) {
} }
task mergeJars(dependsOn: downloadMcJars) { task mergeJars(dependsOn: downloadMcJars) {
group = setupGroup
inputs.files downloadMcJars.outputs.files.files inputs.files downloadMcJars.outputs.files.files
outputs.file(mergedFile) outputs.file(mergedFile)
@ -187,11 +196,13 @@ task mergeJars(dependsOn: downloadMcJars) {
} }
task setupYarn(dependsOn: mergeJars) { task setupYarn(dependsOn: mergeJars) {
group = yarnGroup
} }
task yarn(dependsOn: setupYarn) { task yarn(dependsOn: setupYarn) {
group = yarnGroup
doLast { doLast {
ant.setLifecycleLogLevel "WARN"
ant.java( ant.java(
classname: 'cuchaz.enigma.Main', classname: 'cuchaz.enigma.Main',
classpath: configurations.enigmaRuntime.asPath, classpath: configurations.enigmaRuntime.asPath,
@ -206,6 +217,7 @@ task yarn(dependsOn: setupYarn) {
} }
task buildEnigma(type: Zip) { task buildEnigma(type: Zip) {
group = buildMappingGroup
from mappingsDir from mappingsDir
include "**/*" include "**/*"
archiveName "yarn-enigma-${yarnVersion}.zip" archiveName "yarn-enigma-${yarnVersion}.zip"
@ -213,6 +225,7 @@ task buildEnigma(type: Zip) {
} }
task checkMappings { task checkMappings {
group = buildMappingGroup
inputs.dir mappingsDir inputs.dir mappingsDir
doLast { doLast {
logger.lifecycle(":checking mappings") logger.lifecycle(":checking mappings")
@ -227,12 +240,14 @@ task checkMappings {
} }
task downloadIntermediary(type: Download){ task downloadIntermediary(type: Download){
def url = "https://github.com/FabricMC/intermediary/raw/master/mappings/${minecraft_version}.tiny" group = buildMappingGroup
src url.replaceAll(" ", "%20") def url = "https://github.com/FabricMC/intermediary/raw/master/mappings/${minecraft_version}.tiny"
dest new File(cacheFilesMinecraft, "${minecraft_version}-intermediary.tiny") src UrlEscapers.urlFragmentEscaper().escape(url)
dest new File(cacheFilesMinecraft, "${minecraft_version}-intermediary.tiny")
} }
task patchIntermediary(dependsOn: ["mergeJars", "downloadIntermediary"], type: FileOutput) { task patchIntermediary(dependsOn: ["mergeJars", "downloadIntermediary"], type: FileOutput) {
group = buildMappingGroup
def intermediaryTinyInput = downloadIntermediary.dest def intermediaryTinyInput = downloadIntermediary.dest
def outputFile = new File(cacheFilesMinecraft, "${minecraft_version}-intermediary-full.tiny") def outputFile = new File(cacheFilesMinecraft, "${minecraft_version}-intermediary-full.tiny")
@ -255,6 +270,7 @@ task patchIntermediary(dependsOn: ["mergeJars", "downloadIntermediary"], type: F
} }
task buildYarnTiny(dependsOn: "mergeJars",type: FileOutput) { task buildYarnTiny(dependsOn: "mergeJars",type: FileOutput) {
group = buildMappingGroup
inputs.dir mappingsDir inputs.dir mappingsDir
if (!libs.exists()) { if (!libs.exists()) {
libs.mkdirs() libs.mkdirs()
@ -281,6 +297,7 @@ task buildYarnTiny(dependsOn: "mergeJars",type: FileOutput) {
} }
task mergeTiny(dependsOn: ["buildYarnTiny", "patchIntermediary"], type: FileOutput) { task mergeTiny(dependsOn: ["buildYarnTiny", "patchIntermediary"], type: FileOutput) {
group = buildMappingGroup
def yarnTinyInput = buildYarnTiny.fileOutput def yarnTinyInput = buildYarnTiny.fileOutput
def intermediaryTinyInput = patchIntermediary.fileOutput def intermediaryTinyInput = patchIntermediary.fileOutput
@ -305,6 +322,7 @@ task mergeTiny(dependsOn: ["buildYarnTiny", "patchIntermediary"], type: FileOutp
} }
task tinyJar(type: Jar, dependsOn: "mergeTiny") { task tinyJar(type: Jar, dependsOn: "mergeTiny") {
group = buildMappingGroup
outputs.upToDateWhen {false} outputs.upToDateWhen {false}
archiveName = "yarn-${yarnVersion}.jar" archiveName = "yarn-${yarnVersion}.jar"
destinationDir(file("build/libs")) destinationDir(file("build/libs"))
@ -315,6 +333,7 @@ task tinyJar(type: Jar, dependsOn: "mergeTiny") {
} }
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") def outputFile = new File(libs, "yarn-tiny-${yarnVersion}.gz")
outputs.file(outputFile) outputs.file(outputFile)
fileOutput = outputFile fileOutput = outputFile
@ -339,7 +358,6 @@ task compressTiny(dependsOn: ["tinyJar", "mergeTiny"], type: FileOutput){
fileInputStream.close() fileInputStream.close()
outputStream.finish() outputStream.finish()
outputStream.close() outputStream.close()
inputFile.delete()
} }
} }
@ -352,6 +370,7 @@ tasks.build.dependsOn "buildEnigma"
tasks.build.dependsOn "tinyJar" tasks.build.dependsOn "tinyJar"
task downloadMcLibs(dependsOn: downloadWantedVersionManifest) { task downloadMcLibs(dependsOn: downloadWantedVersionManifest) {
group = setupGroup
inputs.files versionFile inputs.files versionFile
outputs.file(libraries) outputs.file(libraries)
@ -384,6 +403,7 @@ task downloadMcLibs(dependsOn: downloadWantedVersionManifest) {
} }
task mapIntermediaryJar(dependsOn: [downloadMcLibs, build]) { task mapIntermediaryJar(dependsOn: [downloadMcLibs, build]) {
group = mapJarGroup
inputs.files downloadMcLibs.outputs.files.files inputs.files downloadMcLibs.outputs.files.files
outputs.file(intermediaryJar) outputs.file(intermediaryJar)
@ -397,21 +417,59 @@ task mapIntermediaryJar(dependsOn: [downloadMcLibs, build]) {
} }
} }
task mapNamedJar(dependsOn: mapIntermediaryJar) { task mapYarnJar(dependsOn: mapIntermediaryJar) {
group = mapJarGroup
inputs.files downloadMcLibs.outputs.files.files inputs.files downloadMcLibs.outputs.files.files
outputs.file(namedJar) outputs.file(yarnJar)
//Force the task to always run //Force the task to always run
outputs.upToDateWhen {false} outputs.upToDateWhen {false}
doLast { doLast {
logger.lifecycle(":mapping minecraft to named") logger.lifecycle(":mapping minecraft to yarn")
def tinyInput = new File("build/libs/yarn-tiny-${yarnVersion}.gz") def tinyInput = new File("build/libs/yarn-tiny-${yarnVersion}.gz")
mapJar(namedJar, intermediaryJar, tinyInput, libraries, "intermediary", "named") mapJar(yarnJar, intermediaryJar, tinyInput, libraries, "intermediary", "named")
} }
} }
task buildTinyWithEnum(dependsOn: "mergeTiny", type: FileOutput) {
group = buildMappingGroup
def noEnum = mergeTiny.fileOutput
def namedWithEnum = new File(tempDir, "named-with-enum.tiny")
fileOutput = namedWithEnum
outputs.upToDateWhen { false }
doLast {
logger.lifecycle(":seeking auto-mappable fields")
String[] argsPropose = [
mergedFile.getAbsolutePath(), // must use official jar
noEnum.getAbsolutePath(),
namedWithEnum.getAbsolutePath(),
"--writeAll"
]
new CommandProposeFieldNames().run(argsPropose)
}
}
task mapNamedJar(dependsOn: [buildTinyWithEnum, mapIntermediaryJar]) {
group = mapJarGroup
inputs.files downloadMcLibs.outputs.files.files
outputs.file(namedJar)
//Force the task to always run
outputs.upToDateWhen { false }
doLast {
logger.lifecycle(":mapping minecraft to named")
mapJar(yarnJar, intermediaryJar, buildTinyWithEnum.fileOutput, libraries, "intermediary", "named")
}
}
publishing { publishing {
publications { publications {
maven(MavenPublication) { maven(MavenPublication) {
@ -453,7 +511,7 @@ void mapJar(File output, File input, File mappings, File libraries, String from,
.renameInvalidLocals(true) .renameInvalidLocals(true)
.rebuildSourceFilenames(true) .rebuildSourceFilenames(true)
.build() .build()
try { try {
def outputConsumer = new OutputConsumerPath(output.toPath()) def outputConsumer = new OutputConsumerPath(output.toPath())
outputConsumer.addNonClassFiles(input.toPath()) outputConsumer.addNonClassFiles(input.toPath())
@ -467,7 +525,7 @@ void mapJar(File output, File input, File mappings, File libraries, String from,
remapper.finish() remapper.finish()
} catch (Exception e) { } catch (Exception e) {
remapper.finish() remapper.finish()
throw new RuntimeException("Failed to remap jar", e); throw new RuntimeException("Failed to remap jar", e)
} }
} }