Files
ReplayModCinematic/build.gradle.kts
Jonas Herzig 8bc0b0a4df Update preprocessor and replace 1.13.2 subproject with 1.14.4-forge
The new preprocessor version brings first-party support for fabric, in
particular for automatically fetching mappings loom and for
automatically remapping between MC versions via intermediary mappings.
This will come in handy when updating to 1.15.

It also supports automatic remapping between fabric and forge on the
same MC version (by going mcp<->srg<->mojang<->intermediary<->yarn).
Therefore this commit replaces the previous 1.13.2 (forge) subproject
with a 1.14.4-forge one. Instead of manually providing full mappings for
1.14.4-fabric to 1.13.2-forge and partial (classes) for 1.13.2-forge to
1.12.2-forge, we now only need partial (classes) for 1.12.2-forge to
1.14.4-forge and preprocessor will take care of the forge to fabric
step (in fact, our mapping file for that is currently completely empty).

In an attempt to write an IDE (IntelliJ) plugin for quicker and easier
working with the preprocessor (e.g. immediately mapping single files
from within the IDE, jumping between different versions for the same
file), the preprocessor gradle plugin declaration now requires you to
explicitly specify variables in the common.gradle and the overall
relationship between projects in the build.gradle (latter is required
anyway, so the plugin can know where it should map between forge and
fabric and which subprojects are which versions).
Since that necessitated some changes to the build.gradle file, I took
the opportunity to convert it to Kotlin. As such we now also use
Gradle's newer plugin-block with the pluginManagement-block instead of
manually declaring buildScript (not for the common.gradle though), which
imo is nicer anyway and comes with various advantages (see gradle docs).

There were also some remapping bugs fixed and some new ones
introduced (e.g. manually declared inner class mappings seem to no
longer function properly under certain conditions).
There's also support for remapping Kotlin now. Just saying.
2020-01-12 23:34:10 +01:00

201 lines
7.4 KiB
Kotlin
Executable File

import groovy.json.JsonOutput
import java.io.ByteArrayOutputStream
plugins {
id("fabric-loom") version "0.2.5-SNAPSHOT" apply false
id("com.replaymod.preprocess") version "b744ea7"
id("com.github.hierynomus.license") version "0.15.0"
}
val latestVersion = file("version.txt").readLines().first()
var releaseCommit = command("git", "blame", "-p", "-l", "version.txt").first().split(" ").first()
if (latestVersion == "2.1.0") { // First version since change from tag-based
releaseCommit = "35ac26e91689ac9bdf12dbb9902c452464a75108" // git rev-parse 1.12.2-2.1.0
}
val currentCommit = command("git", "rev-parse", "HEAD").first()
if (releaseCommit == currentCommit) {
version = latestVersion
} else {
val diff = command("git", "log", "--format=oneline", "$releaseCommit..$currentCommit").size
version = "$latestVersion-$diff-g${currentCommit.substring(0, 7)}"
}
if (gitDescribe().endsWith("*")) {
version = "$version-dirty"
}
group = "com.replaymod"
// Loom tries to find the active mixin version by recursing up to the root project and checking each project's
// compileClasspath and build script classpath (in that order). Since we've loom in our root project's classpath,
// loom will only find it after checking the root project's compileClasspath (which doesn't exist by default).
configurations.register("compileClasspath")
val shadowJar by tasks.creating(Copy::class) {
into("$buildDir/libs")
}
subprojects {
buildscript {
repositories {
maven("https://jitpack.io")
}
}
afterEvaluate {
val projectShadowJar = project.tasks.findByName("shadowJar")
if (projectShadowJar != null && projectShadowJar.hasProperty("archivePath") && project.name != "core") {
shadowJar.dependsOn(projectShadowJar)
shadowJar.from(projectShadowJar.withGroovyBuilder { getProperty("archivePath") })
}
}
}
fun gitDescribe(): String {
try {
val stdout = ByteArrayOutputStream()
exec {
commandLine("git", "describe", "--always", "--dirty=*")
standardOutput = stdout
}
return stdout.toString().trim()
} catch (e: Throwable) {
return "unknown"
}
}
fun command(vararg cmd: Any): List<String> {
val stdout = ByteArrayOutputStream()
exec {
commandLine(*cmd)
standardOutput = stdout
}
return stdout.toString().split("\n")
}
fun generateVersionsJson(): Map<String, Any> {
// Find all tag-style releases by listing all tags
val tagVersions = command("git", "for-each-ref", "--sort=taggerdate", "--format=%(refname:short)", "refs/tags")
// Find all commit-style releases
// List all commits
val releaseCommits =
command("git", "log", "--format=%H", "--date-order", "-E",
"--grep", "Pre-release [0-9]+ of [0-9]+\\.[0-9]+\\.[0-9]+",
"--grep", "Release [0-9]+\\.[0-9]+\\.[0-9]+")
// Find version string and MC versions for each commit hash
val commitVersions = releaseCommits.map { commit ->
val version = command("git", "show", "$commit:version.txt").first()
val mcVersions = command("git", "ls-tree", "-d", "--name-only", "$commit:versions")
mcVersions.map { "$it-$version" }
}.flatten()
val versions = commitVersions + tagVersions.reversed()
val mcVersions = versions
.map {it.substring(0, it.indexOf("-"))}
.distinct()
.sortedWith(compareBy(
{ (it.split(".")[0] ?: "0").toInt() },
{ (it.split(".")[1] ?: "0").toInt() },
{ (it.split(".")[2] ?: "0").toInt() }
))
val promos = mutableMapOf<String, String>()
val root = mutableMapOf<String, Any>(
"homepage" to "https://www.replaymod.com/download/",
"promos" to promos
)
mcVersions.forEach { mcVersion ->
var mcVersionRoot = mutableMapOf<String, String>()
var latest: String? = null
var recommended: String? = null
versions.forEach {
val (thisMcVersion, modVersion, preVersion) = it.split("-")
if (thisMcVersion == mcVersion) {
mcVersionRoot[it] = if (tagVersions.contains(it))
"See https://github.com/ReplayMod/ReplayMod/releases/$it"
else
"See https://www.replaymod.com/forum/thread/100"
if (latest == null) latest = it
if (preVersion == null) {
if (recommended == null) recommended = it
}
}
}
root[mcVersion] = mcVersionRoot
promos[mcVersion + "-latest"] = latest!!
if (recommended != null) {
promos[mcVersion + "-recommended"] = recommended!!
}
}
return root
}
val doRelease by tasks.registering {
doLast {
// Parse version
val version = project.extra("releaseVersion") as String
if (gitDescribe().endsWith("*")) {
throw InvalidUserDataException("Git working tree is dirty. Make sure to commit all changes.")
}
val (modVersion, preVersion) = if ("-b" in version) {
version.split("-b")
} else {
listOf(version, null)
}
// Create new commit
val commitMessage = if (preVersion != null)
"Pre-release $preVersion of $modVersion"
else
"Release $modVersion"
file("version.txt").writeText("$version\n")
command("git", "add", "version.txt")
command("git", "commit", "-m", commitMessage)
// Generate versions.json content
val versionsRoot = generateVersionsJson()
val versionsJson = JsonOutput.prettyPrint(JsonOutput.toJson(versionsRoot))
// Switch to master branch to update versions.json
command("git", "checkout", "master")
// Write versions.json
File("versions.json").writeText(versionsJson)
// Commit changes
project.exec { commandLine("git", "add", "versions.json") }
project.exec { commandLine("git", "commit", "-m", "Update versions.json for $version") }
// Return to previous branch
project.exec { commandLine("git", "checkout", "-") }
}
}
defaultTasks("shadowJar")
preprocess {
"1.14.4"(11404, "yarn") {
"1.14.4-forge"(11404, "srg", file("versions/mapping-1.14.4-fabric-forge.txt")) {
"1.12.2"(11202, "srg", file("versions/1.14.4-forge/mapping.txt")) {
"1.12.1"(11201, "srg") {
"1.12"(11200, "srg") {
"1.11.2"(11102, "srg", file("versions/1.12/mapping.txt")) {
"1.11"(11100, "srg", file("versions/1.11.2/mapping.txt")) {
"1.10.2"(11002, "srg", file("versions/1.11/mapping.txt")) {
"1.9.4"(10904, "srg") {
"1.8.9"(10809, "srg", file("versions/1.9.4/mapping.txt")) {
"1.8"(10800, "srg", file("versions/1.8.9/mapping.txt")) {
"1.7.10"(10710, "srg", file("versions/1.8/mapping.txt"))
}
}
}
}
}
}
}
}
}
}
}
}