Skip to content

Commit

Permalink
Add proposed field names to the mapped named jar
Browse files Browse the repository at this point in the history
Changed old named jar to yarn jar
Beautify readme and added groups to gradle tasks
always indent with tabs

Signed-off-by: liach <[email protected]>
  • Loading branch information
liach committed Jun 17, 2019
1 parent a8804c1 commit ce3f15c
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 22 deletions.
16 changes: 12 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,22 @@ However, it is a good idea to consult name changes with other people - use pull
## Gradle
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`
Downloads the client and server Minecraft jars for the current Minecraft version to `.gradle/minecraft`

### `mergeJars`
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`
`download` and `mergeJars`

### `yarn`
`setupYarn` and download and launch the latest version of Enigma automatically configured to use the merged jar and the mappings.
[`download`](#download) and [`mergeJars`](#mergeJars)
94 changes: 76 additions & 18 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ def build_number = ENV.BUILD_NUMBER ?: "local"

def yarnVersion = "${minecraft_version}+build.$build_number"


repositories {
mavenCentral()
maven {
Expand All @@ -50,25 +49,31 @@ configurations {

dependencies {
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 cacheFilesMinecraft = file(".gradle/minecraft")
def tempDir = file(".gradle/temp")
def mergedFile = file("${minecraft_version}-merged.jar")
def intermediaryJar = file("${minecraft_version}-intermediary.jar")
def yarnJar = file("${minecraft_version}-yarn.jar")
def namedJar = file("${minecraft_version}-named.jar")
def versionFile = new File(cacheFilesMinecraft, "${minecraft_version}.json")
def clientJar = new File(cacheFilesMinecraft, "${minecraft_version}-client.jar")
def serverJar = new File(cacheFilesMinecraft, "${minecraft_version}-server.jar")
def libraries = new File(cacheFilesMinecraft, "${minecraft_version}-libraries")
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.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.CommandRewriteIntermediary
Expand All @@ -78,12 +83,13 @@ import net.fabricmc.tinyremapper.TinyRemapper
import net.fabricmc.tinyremapper.TinyUtils
import net.fabricmc.weave.CommandFindMappingErrors
import net.fabricmc.weave.CommandTinyify
import groovy.io.FileType
import org.apache.commons.io.FileUtils

import java.util.zip.GZIPOutputStream

boolean validateChecksum(File file, String checksum) {
if (file != null) {
def hash = Files.hash(file, Hashing.sha1())
def hash = Files.asByteSource(file).hash(Hashing.sha1())
def builder = new StringBuilder()
hash.asBytes().each {
builder.append(Integer.toString((it & 0xFF) + 0x100, 16).substring(1))
Expand All @@ -94,6 +100,7 @@ boolean validateChecksum(File file, String checksum) {
}

task downloadVersionsManifest {
group = setupGroup
//inputs.property "mc_ver", minecraft_version
inputs.property "currenttime", new Date()
def manifestFile = new File(cacheFilesMinecraft, "version_manifest.json")
Expand All @@ -110,6 +117,7 @@ def getManifestVersion(File manifestFile, String minecraft_version) {
}

task downloadWantedVersionManifest(dependsOn: downloadVersionsManifest) {
group = setupGroup
def manifestFile = downloadVersionsManifest.outputs.files.singleFile
def manifestVersion = getManifestVersion(manifestFile, minecraft_version)

Expand All @@ -133,7 +141,7 @@ task downloadWantedVersionManifest(dependsOn: downloadVersionsManifest) {
}

task downloadMcJars(dependsOn: downloadWantedVersionManifest) {

group = setupGroup
inputs.files versionFile

outputs.files(clientJar, serverJar)
Expand Down Expand Up @@ -166,6 +174,7 @@ task downloadMcJars(dependsOn: downloadWantedVersionManifest) {
}

task mergeJars(dependsOn: downloadMcJars) {
group = setupGroup
inputs.files downloadMcJars.outputs.files.files
outputs.file(mergedFile)

Expand All @@ -187,11 +196,13 @@ task mergeJars(dependsOn: downloadMcJars) {
}

task setupYarn(dependsOn: mergeJars) {

group = yarnGroup
}

task yarn(dependsOn: setupYarn) {
group = yarnGroup
doLast {
ant.setLifecycleLogLevel "WARN"
ant.java(
classname: 'cuchaz.enigma.Main',
classpath: configurations.enigmaRuntime.asPath,
Expand All @@ -206,13 +217,15 @@ task yarn(dependsOn: setupYarn) {
}

task buildEnigma(type: Zip) {
group = buildMappingGroup
from mappingsDir
include "**/*"
archiveName "yarn-enigma-${yarnVersion}.zip"
destinationDir(file("build/libs"))
}

task checkMappings {
group = buildMappingGroup
inputs.dir mappingsDir
doLast {
logger.lifecycle(":checking mappings")
Expand All @@ -227,12 +240,14 @@ task checkMappings {
}

task downloadIntermediary(type: Download){
def url = "https://github.com/FabricMC/intermediary/raw/master/mappings/${minecraft_version}.tiny"
src url.replaceAll(" ", "%20")
dest new File(cacheFilesMinecraft, "${minecraft_version}-intermediary.tiny")
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")
}

task patchIntermediary(dependsOn: ["mergeJars", "downloadIntermediary"], type: FileOutput) {
group = buildMappingGroup
def intermediaryTinyInput = downloadIntermediary.dest

def outputFile = new File(cacheFilesMinecraft, "${minecraft_version}-intermediary-full.tiny")
Expand All @@ -255,6 +270,7 @@ task patchIntermediary(dependsOn: ["mergeJars", "downloadIntermediary"], type: F
}

task buildYarnTiny(dependsOn: "mergeJars",type: FileOutput) {
group = buildMappingGroup
inputs.dir mappingsDir
if (!libs.exists()) {
libs.mkdirs()
Expand All @@ -281,6 +297,7 @@ task buildYarnTiny(dependsOn: "mergeJars",type: FileOutput) {
}

task mergeTiny(dependsOn: ["buildYarnTiny", "patchIntermediary"], type: FileOutput) {
group = buildMappingGroup
def yarnTinyInput = buildYarnTiny.fileOutput
def intermediaryTinyInput = patchIntermediary.fileOutput

Expand All @@ -305,6 +322,7 @@ task mergeTiny(dependsOn: ["buildYarnTiny", "patchIntermediary"], type: FileOutp
}

task tinyJar(type: Jar, dependsOn: "mergeTiny") {
group = buildMappingGroup
outputs.upToDateWhen {false}
archiveName = "yarn-${yarnVersion}.jar"
destinationDir(file("build/libs"))
Expand All @@ -315,6 +333,7 @@ task tinyJar(type: Jar, dependsOn: "mergeTiny") {
}

task compressTiny(dependsOn: ["tinyJar", "mergeTiny"], type: FileOutput){
group = buildMappingGroup
def outputFile = new File(libs, "yarn-tiny-${yarnVersion}.gz")
outputs.file(outputFile)
fileOutput = outputFile
Expand All @@ -339,7 +358,6 @@ task compressTiny(dependsOn: ["tinyJar", "mergeTiny"], type: FileOutput){
fileInputStream.close()
outputStream.finish()
outputStream.close()
inputFile.delete()
}
}

Expand All @@ -352,6 +370,7 @@ tasks.build.dependsOn "buildEnigma"
tasks.build.dependsOn "tinyJar"

task downloadMcLibs(dependsOn: downloadWantedVersionManifest) {
group = setupGroup
inputs.files versionFile

outputs.file(libraries)
Expand Down Expand Up @@ -384,6 +403,7 @@ task downloadMcLibs(dependsOn: downloadWantedVersionManifest) {
}

task mapIntermediaryJar(dependsOn: [downloadMcLibs, build]) {
group = mapJarGroup
inputs.files downloadMcLibs.outputs.files.files
outputs.file(intermediaryJar)

Expand All @@ -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
outputs.file(namedJar)
outputs.file(yarnJar)

//Force the task to always run
outputs.upToDateWhen {false}

doLast {
logger.lifecycle(":mapping minecraft to named")
logger.lifecycle(":mapping minecraft to yarn")

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 {
publications {
maven(MavenPublication) {
Expand Down Expand Up @@ -453,7 +511,7 @@ void mapJar(File output, File input, File mappings, File libraries, String from,
.renameInvalidLocals(true)
.rebuildSourceFilenames(true)
.build()
try {
def outputConsumer = new OutputConsumerPath(output.toPath())
outputConsumer.addNonClassFiles(input.toPath())
Expand All @@ -467,7 +525,7 @@ void mapJar(File output, File input, File mappings, File libraries, String from,
remapper.finish()
} catch (Exception e) {
remapper.finish()
throw new RuntimeException("Failed to remap jar", e);
throw new RuntimeException("Failed to remap jar", e)
}
}

Expand Down

0 comments on commit ce3f15c

Please sign in to comment.