Several improvements to fork support

Fork projects should perform better and be more stable now. Upstream
patch tasks will now cache as expected, with only the base patch tasks
not caching.

MCDev imports and paperclipJar should both work correctly now as well.
applyPatches and rebuildPatches should work first time as well as
repeat runs, including when running with new MCDev imports and changes
to upstream.

Fixes #25
This commit is contained in:
Kyle Wood 2021-06-19 23:45:09 -05:00
parent 2ce26f2fb1
commit e24891ba33
No known key found for this signature in database
GPG key ID: 86AF5613ACA30CC5
16 changed files with 128 additions and 62 deletions

View file

@ -9,7 +9,7 @@ repositories {
}
dependencies {
// implementation(libs.gradle.licenser)
implementation(libs.gradle.licenser)
implementation(libs.gradle.ktlint)
implementation(libs.gradle.shadow)
implementation(libs.gradle.kotlin.dsl)

View file

@ -3,7 +3,7 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
idea
id("org.gradle.kotlin.kotlin-dsl")
// id("org.cadixdev.licenser")
id("org.cadixdev.licenser")
id("org.jlleitschuh.gradle.ktlint")
}
@ -62,13 +62,13 @@ ktlint {
tasks.register("format") {
group = "formatting"
description = "Formats source code according to project style"
dependsOn(/*tasks.licenseFormat,*/ tasks.ktlintFormat)
dependsOn(tasks.licenseFormat, tasks.ktlintFormat)
}
// license {
// header.set(resources.text.fromFile(rootProject.file("license/copyright.txt")))
// include("**/*.kt")
// }
license {
header.set(resources.text.fromFile(rootProject.file("license/copyright.txt")))
include("**/*.kt")
}
idea {
module {

View file

@ -1,2 +1,2 @@
group = io.papermc.paperweight
version = 1.1.3-SNAPSHOT
version = 1.1.3

View file

@ -28,7 +28,7 @@ lorenzTiny = "org.quiltmc:lorenz-tiny:3.0.0"
jbsdiff = "io.sigpipe:jbsdiff:1.0"
# Gradle
gradle-licenser = "org.cadixdev.licenser:org.cadixdev.licenser.gradle.plugin:0.6.0"
gradle-licenser = "org.cadixdev.licenser:org.cadixdev.licenser.gradle.plugin:0.6.1"
gradle-shadow = "com.github.johnrengelman.shadow:com.github.johnrengelman.shadow.gradle.plugin:7.0.0"
gradle-ktlint = "org.jlleitschuh.gradle.ktlint:org.jlleitschuh.gradle.ktlint.gradle.plugin:10.0.0"
gradle-kotlin-dsl = "org.gradle.kotlin.kotlin-dsl:org.gradle.kotlin.kotlin-dsl.gradle.plugin:2.1.4"

View file

@ -83,7 +83,9 @@ class PaperweightCore : Plugin<Project> {
mcVersion.set(target.ext.minecraftVersion)
mcLibrariesFile.set(tasks.inspectVanillaJar.flatMap { it.serverLibraries })
mcLibrariesDir.set(tasks.downloadMcLibraries.flatMap { it.sourcesOutputDir })
reobfMappings.set(generateReobfMappings.flatMap { it.reobfMappings })
mappings.set(tasks.patchMappings.flatMap { it.outputMappings })
notchToSpigotMappings.set(tasks.generateSpigotMappings.flatMap { it.notchToSpigotMappings })
sourceMappings.set(tasks.generateMappings.flatMap { it.outputMappings })
dataFile.set(target.layout.file(providers.gradleProperty(Constants.PAPERWEIGHT_PREPARE_DOWNSTREAM).map { File(it) }))
}
@ -130,7 +132,7 @@ class PaperweightCore : Plugin<Project> {
}
from(target.zipTree(generatePaperclipPatch.flatMap { it.outputZip }))
manifest.from(paperclipZip.matching { include("META-INF/MANIFEST.MF") }.singleFile)
manifest.from(paperclipZip.matching { include("META-INF/MANIFEST.MF") }.elements.map { it.single() })
}
}
}

View file

@ -29,6 +29,7 @@ import io.papermc.paperweight.tasks.patchremap.ApplyAccessTransform
import io.papermc.paperweight.util.Constants
import io.papermc.paperweight.util.cache
import io.papermc.paperweight.util.fileExists
import io.papermc.paperweight.util.isBaseExecution
import io.papermc.paperweight.util.registering
import io.papermc.paperweight.util.set
import java.nio.file.Path
@ -73,11 +74,16 @@ open class AllTasks(
val applyApiPatches by tasks.registering<ApplyGitPatches> {
group = "paper"
description = "Setup the Paper-API project"
if (project.isBaseExecution) {
outputs.upToDateWhen { false }
}
printOutput.set(project.isBaseExecution)
branch.set("HEAD")
upstreamBranch.set("upstream")
upstream.set(patchSpigotApi.flatMap { it.outputDir })
patchDir.set(extension.paper.spigotApiPatchDir)
printOutput.set(true)
unneededFiles.value(listOf("README.md"))
outputDir.set(extension.paper.paperApiDir)
@ -87,6 +93,12 @@ open class AllTasks(
val applyServerPatches by tasks.registering<ApplyPaperPatches> {
group = "paper"
description = "Setup the Paper-Server project"
if (project.isBaseExecution) {
outputs.upToDateWhen { false }
}
printOutput.set(project.isBaseExecution)
patchDir.set(extension.paper.spigotServerPatchDir)
remappedSource.set(remapSpigotSources.flatMap { it.sourcesOutputZip })
remappedTests.set(remapSpigotSources.flatMap { it.testsOutputZip })

View file

@ -67,7 +67,13 @@ abstract class PaperweightCoreUpstreamData : DefaultTask() {
abstract val mcdevFile: RegularFileProperty
@get:InputFile
abstract val reobfMappings: RegularFileProperty
abstract val mappings: RegularFileProperty
@get:InputFile
abstract val notchToSpigotMappings: RegularFileProperty
@get:InputFile
abstract val sourceMappings: RegularFileProperty
@get:OutputFile
abstract val dataFile: RegularFileProperty
@ -89,7 +95,9 @@ abstract class PaperweightCoreUpstreamData : DefaultTask() {
mcLibrariesDir.path,
mcLibrariesFile.pathOrNull,
mcdevFile.pathOrNull,
reobfMappings.path
mappings.path,
notchToSpigotMappings.path,
sourceMappings.path
)
dataFilePath.bufferedWriter(Charsets.UTF_8).use { writer ->
gson.toJson(data, writer)

View file

@ -36,7 +36,6 @@ import org.gradle.api.tasks.InputFile
import org.gradle.api.tasks.Optional
import org.gradle.api.tasks.OutputDirectory
import org.gradle.api.tasks.TaskAction
import org.gradle.internal.os.OperatingSystem
abstract class ApplyGitPatches : ControllableOutputTask() {
@ -65,15 +64,14 @@ abstract class ApplyGitPatches : ControllableOutputTask() {
abstract val outputDir: DirectoryProperty
override fun init() {
outputs.upToDateWhen { false }
printOutput.convention(false)
printOutput.convention(false).finalizeValueOnRead()
}
@TaskAction
fun run() {
Git(upstream.path).let { git ->
git("fetch").setupOut().run()
git("branch", "-f", upstreamBranch.get(), branch.get()).runSilently()
git("branch", "-f", upstreamBranch.get(), branch.get()).runSilently(silenceErr = true)
}
val outputPath = outputDir.path
@ -93,12 +91,12 @@ abstract class ApplyGitPatches : ControllableOutputTask() {
if (unneededFiles.isPresent && unneededFiles.get().size > 0) {
unneededFiles.get().forEach { path -> outputDir.path.resolve(path).deleteRecursively() }
git("add", ".").runOut()
git("commit", "-m", "Initial", "--author=Initial Source <auto@mated.null>").runOut()
git("add", ".").setupOut().run()
git("commit", "-m", "Initial", "--author=Initial Source <auto@mated.null>").setupOut().run()
}
git("tag", "-d", "base").runSilently(silenceErr = true)
git("tag", "base").executeSilently()
git("tag", "base").executeSilently(silenceErr = true)
applyGitPatches(git, target, outputDir.path, rootPatchDir, printOutput.get())
}
@ -149,14 +147,7 @@ fun ControllableOutputTask.applyGitPatches(
if (git("am", "--3way", "--ignore-whitespace", tempDir.absolutePathString()).showErrors().run() != 0) {
statusFile.writeText("1")
logger.error("*** Please review above details and finish the apply then")
logger.error("*** save the changes with `./gradlew rebuildPaperPatches`")
if (OperatingSystem.current().isWindows) {
logger.error("")
logger.error("*** Because you're on Windows you'll need to finish the AM,")
logger.error("*** rebuild all patches, and then re-run the patch apply again.")
logger.error("*** Consider using the scripts with Windows Subsystem for Linux.")
}
logger.error("*** save the changes with `./gradlew rebuildPatches`")
throw PaperweightException("Failed to apply patches")
} else {
@ -171,8 +162,8 @@ fun ControllableOutputTask.applyGitPatches(
}
fun checkoutRepoFromUpstream(git: Git, upstream: Path, upstreamBranch: String) {
git("init", "--quiet").executeSilently()
git("config", "commit.gpgsign", "false").executeSilently()
git("init", "--quiet").executeSilently(silenceErr = true)
git("config", "commit.gpgsign", "false").executeSilently(silenceErr = true)
git("remote", "remove", "upstream").runSilently(silenceErr = true)
git("remote", "add", "upstream", upstream.toUri().toString()).executeSilently(silenceErr = true)
git("fetch", "upstream", "--prune").executeSilently(silenceErr = true)

View file

@ -74,9 +74,7 @@ abstract class ApplyPaperPatches : ControllableOutputTask() {
abstract val outputDir: DirectoryProperty
override fun init() {
outputs.upToDateWhen { false }
upstreamBranch.convention("master")
printOutput.convention(true)
}
@TaskAction
@ -106,7 +104,15 @@ abstract class ApplyPaperPatches : ControllableOutputTask() {
}
val patches = patchDir.path.listDirectoryEntries("*.patch")
McDev.importMcDev(patches, sourceMcDevJar.path, libraryImports.pathOrNull, mcLibrariesDir.path, mcdevImports.pathOrNull, sourceDir)
McDev.importMcDev(
patches,
sourceMcDevJar.path,
libraryImports.pathOrNull,
mcLibrariesDir.path,
mcdevImports.pathOrNull,
sourceDir,
printOutput.get()
)
val caseOnlyChanges = caseOnlyClassNameChanges.path.bufferedReader(Charsets.UTF_8).use { reader ->
gson.fromJson<List<ClassNameChange>>(reader)

View file

@ -25,6 +25,7 @@ package io.papermc.paperweight.util
import io.papermc.paperweight.PaperweightException
import java.nio.file.Path
import kotlin.io.path.*
import org.gradle.api.logging.LogLevel
import org.gradle.api.logging.Logger
import org.gradle.api.logging.Logging
@ -37,7 +38,15 @@ object McDev {
"ServerWorkerThread",
)
fun importMcDev(patches: Iterable<Path>, decompJar: Path, libraryImports: Path?, libraryDir: Path?, additionalClasses: Path?, targetDir: Path) {
fun importMcDev(
patches: Iterable<Path>,
decompJar: Path,
libraryImports: Path?,
libraryDir: Path?,
additionalClasses: Path?,
targetDir: Path,
printOutput: Boolean = true
) {
val patchLines = readPatchLines(patches)
val importMcDev = readMcDevNames(patchLines, additionalClasses).asSequence()
@ -46,7 +55,7 @@ object McDev {
.filterNot { file -> bannedClasses.any { file.toString().contains(it) } }
.toSet()
logger.lifecycle("Importing {} classes from vanilla...", importMcDev.size)
logger.log(if (printOutput) LogLevel.LIFECYCLE else LogLevel.DEBUG, "Importing {} classes from vanilla...", importMcDev.size)
decompJar.openZip().use { zipFile ->
// pull in all package-info classes
@ -89,7 +98,7 @@ object McDev {
// Import library classes
val imports = findLibraries(libraryImports, libFiles, patchLines)
logger.lifecycle("Importing {} classes from library sources...", imports.size)
logger.log(if (printOutput) LogLevel.LIFECYCLE else LogLevel.DEBUG, "Importing {} classes from library sources...", imports.size)
for ((libraryFileName, importFilePath) in imports) {
val libFile = libFiles.firstOrNull { it.name == libraryFileName }

View file

@ -36,7 +36,9 @@ data class UpstreamData(
val libSourceDir: Path,
val libFile: Path?,
val mcdevFile: Path?,
val reobfMappings: Path
val mappings: Path,
val notchToSpigotMappings: Path,
val sourceMappings: Path
)
fun readUpstreamData(inputFile: RegularFile): UpstreamData? {

View file

@ -53,10 +53,10 @@ val Provider<out FileSystemLocation>.path: Path
val Provider<out FileSystemLocation>.pathOrNull: Path?
get() = orNull?.path
fun FileSystemLocationProperty<*>.set(path: Path?) = set(path?.toFile())
fun DirectoryProperty.convention(project: Project, path: Path?) = convention(project.layout.dir(project.provider { path?.toFile() }))
fun DirectoryProperty.convention(project: Project, path: Provider<Path>) = convention(project.layout.dir(path.map { it.toFile() }))
fun RegularFileProperty.convention(project: Project, path: Path?) = convention(project.layout.file(project.provider { path?.toFile() }))
fun RegularFileProperty.convention(project: Project, path: Provider<Path>) = convention(project.layout.file(path.map { it.toFile() }))
fun FileSystemLocationProperty<*>.pathProvider(path: Provider<Path?>) = fileProvider(path.map { it.toFile() })
fun DirectoryProperty.convention(project: Project, path: Provider<Path?>) = convention(project.layout.dir(path.map { it.toFile() }))
fun RegularFileProperty.convention(project: Project, path: Provider<Path?>) = convention(project.layout.file(path.map { it.toFile() }))
val Path.isLibraryJar: Boolean
get() = name.endsWith(".jar") && !name.endsWith("-sources.jar")

View file

@ -30,25 +30,30 @@ import org.gradle.api.tasks.TaskProvider
import org.gradle.jvm.tasks.Jar
import org.gradle.kotlin.dsl.*
fun Project.setupServerProject(parent: Project, remappedJar: Any?, libsFile: Any?, reobfConfig: RemapJar.() -> Unit): TaskProvider<RemapJar>? {
fun Project.setupServerProject(parent: Project, remappedJar: Any, libsFile: Any, reobfConfig: RemapJar.() -> Unit): TaskProvider<RemapJar>? {
if (!projectDir.exists()) {
return null
}
plugins.apply("java")
dependencies.apply {
val remapped = remappedJar.convertToPathOrNull()
if (remapped != null && remapped.exists()) {
add("implementation", parent.files(remapped))
}
val libs = libsFile.convertToPathOrNull()
if (libs != null && libs.exists()) {
libs.forEachLine { line ->
add("implementation", line)
configurations {
named("implementation") {
withDependencies {
dependencies {
val libs = libsFile.convertToPathOrNull()
if (libs != null && libs.exists()) {
libs.forEachLine { line ->
add("implementation", line)
}
}
}
}
}
}
dependencies.apply {
add("implementation", parent.files(remappedJar))
}
apply(plugin = "com.github.johnrengelman.shadow")
return createBuildTasks(reobfConfig)

View file

@ -104,6 +104,13 @@ fun commentRegex(): Regex {
return Regex("\\s*#.*")
}
val Project.isBaseExecution: Boolean
get() = providers.gradleProperty(Constants.PAPERWEIGHT_PREPARE_DOWNSTREAM)
.forUseAtConfigurationTime()
.orElse(provider { "false" })
.map { it == "false" }
.get()
fun redirect(input: InputStream, out: OutputStream): Thread {
return Thread {
try {

View file

@ -31,6 +31,7 @@ import io.papermc.paperweight.patcher.upstream.PatchTaskConfig
import io.papermc.paperweight.patcher.upstream.PatcherUpstream
import io.papermc.paperweight.patcher.upstream.RepoPatcherUpstream
import io.papermc.paperweight.tasks.GeneratePaperclipPatch
import io.papermc.paperweight.tasks.GenerateReobfMappings
import io.papermc.paperweight.util.*
import java.io.File
import java.util.concurrent.atomic.AtomicReference
@ -67,6 +68,7 @@ class PaperweightPatcher : Plugin<Project> {
val applyPatches by target.tasks.registering { group = "paperweight" }
val rebuildPatches by target.tasks.registering { group = "paperweight" }
val downstreamData = target.tasks.register(Constants.PAPERWEIGHT_PREPARE_DOWNSTREAM)
val generateReobfMappings by target.tasks.registering(GenerateReobfMappings::class)
val upstreamDataTaskRef = AtomicReference<TaskProvider<PaperweightPatcherUpstreamData>>(null)
@ -99,21 +101,30 @@ class PaperweightPatcher : Plugin<Project> {
}
}
val upstreamData = upstreamDataTask.readUpstreamData().orNull ?: return@afterEvaluate
val upstreamData = upstreamDataTask.readUpstreamData()
val serverProj = patcher.serverProject.forUseAtConfigurationTime().orNull ?: return@afterEvaluate
generateReobfMappings {
inputMappings.pathProvider(upstreamData.map { it.mappings })
notchToSpigotMappings.pathProvider(upstreamData.map { it.notchToSpigotMappings })
sourceMappings.pathProvider(upstreamData.map { it.sourceMappings })
inputJar.fileProvider(serverProj.tasks.named("shadowJar", Jar::class).map { it.outputs.files.singleFile })
reobfMappings.set(target.layout.cache.resolve(Constants.REOBF_SPIGOT_MOJANG_YARN_MAPPINGS))
}
val reobfJar = serverProj.setupServerProject(
target,
upstreamData.remappedJar,
upstreamData.libFile
upstreamData.map { it.remappedJar },
upstreamData.flatMap { provider { it.libFile } }
) {
mappingsFile.set(upstreamData.reobfMappings)
mappingsFile.set(generateReobfMappings.flatMap { it.reobfMappings })
} ?: return@afterEvaluate
val generatePaperclipPatch by target.tasks.registering<GeneratePaperclipPatch> {
originalJar.set(upstreamData.vanillaJar)
originalJar.pathProvider(upstreamData.map { it.vanillaJar })
patchedJar.set(reobfJar.flatMap { it.outputJar })
mcVersion.set(upstreamData.mcVersion)
mcVersion.set(upstreamData.map { it.mcVersion })
}
paperclipJar {
@ -128,7 +139,7 @@ class PaperweightPatcher : Plugin<Project> {
}
from(target.zipTree(generatePaperclipPatch.flatMap { it.outputZip }.get()))
manifest.from(paperclipZip.matching { include("META-INF/MANIFEST.MF") }.singleFile)
manifest.from(paperclipZip.matching { include("META-INF/MANIFEST.MF") }.elements.map { it.single() })
}
}
}
@ -194,6 +205,12 @@ class PaperweightPatcher : Plugin<Project> {
val project = this
val patchTask = tasks.configureTask<SimpleApplyGitPatches>(config.patchTaskName) {
group = "paperweight"
if (isBaseExecution) {
outputs.upToDateWhen { false }
}
printOutput.set(isBaseExecution)
val (cloneTask, upstreamDataTask) = upstreamTaskPair
dependsOn(upstreamDataTask)

View file

@ -80,10 +80,9 @@ abstract class SimpleApplyGitPatches : ControllableOutputTask() {
abstract val outputDir: DirectoryProperty
override fun init() {
outputs.upToDateWhen { false }
upstreamBranch.convention("master")
importMcDev.convention(false)
printOutput.convention(true)
printOutput.convention(true).finalizeValueOnRead()
}
@TaskAction
@ -119,7 +118,15 @@ abstract class SimpleApplyGitPatches : ControllableOutputTask() {
val patches = patchDir.pathOrNull?.listDirectoryEntries("*.patch") ?: listOf()
if (sourceMcDevJar.isPresent && importMcDev.get()) {
McDev.importMcDev(patches, sourceMcDevJar.path, libraryImports.pathOrNull, mcLibrariesDir.pathOrNull, mcdevImports.pathOrNull, srcDir)
McDev.importMcDev(
patches,
sourceMcDevJar.path,
libraryImports.pathOrNull,
mcLibrariesDir.pathOrNull,
mcdevImports.pathOrNull,
srcDir,
printOutput.get()
)
}
git("add", ".").executeSilently()