Clean up apply and rebuild logging
use paperweight.verboseApplyPatches to see all the Git output, even on success (when the task's output is enabled)
This commit is contained in:
parent
f1548964e7
commit
8230d7d997
11 changed files with 61 additions and 66 deletions
|
@ -82,7 +82,7 @@ open class AllTasks(
|
|||
if (project.isBaseExecution) {
|
||||
doNotTrackState("$name should always run when requested as part of the base execution.")
|
||||
}
|
||||
printOutput.set(project.printApplyPatchesOutput())
|
||||
printOutput.set(project.isBaseExecution)
|
||||
|
||||
branch.set("HEAD")
|
||||
upstreamBranch.set("upstream")
|
||||
|
@ -110,7 +110,7 @@ open class AllTasks(
|
|||
if (project.isBaseExecution) {
|
||||
doNotTrackState("$name should always run when requested as part of the base execution.")
|
||||
}
|
||||
printOutput.set(project.printApplyPatchesOutput())
|
||||
printOutput.set(project.isBaseExecution)
|
||||
|
||||
patchDir.set(extension.paper.spigotServerPatchDir)
|
||||
remappedSource.set(remapSpigotSources.flatMap { it.sourcesOutputZip })
|
||||
|
@ -140,7 +140,6 @@ open class AllTasks(
|
|||
baseRef.set("base")
|
||||
|
||||
patchDir.set(extension.paper.spigotApiPatchDir)
|
||||
printOutput.set(project.printRebuildPatchesOutput())
|
||||
}
|
||||
|
||||
val rebuildServerPatches by tasks.registering<RebuildGitPatches> {
|
||||
|
@ -150,7 +149,6 @@ open class AllTasks(
|
|||
baseRef.set("base")
|
||||
|
||||
patchDir.set(extension.paper.spigotServerPatchDir)
|
||||
printOutput.set(project.printRebuildPatchesOutput())
|
||||
}
|
||||
|
||||
@Suppress("unused")
|
||||
|
|
|
@ -71,9 +71,13 @@ abstract class ApplyGitPatches : ControllableOutputTask() {
|
|||
@get:Inject
|
||||
abstract val providers: ProviderFactory
|
||||
|
||||
@get:Input
|
||||
abstract val verbose: Property<Boolean>
|
||||
|
||||
override fun init() {
|
||||
printOutput.convention(false).finalizeValueOnRead()
|
||||
ignoreGitIgnore.convention(Git.ignoreProperty(providers)).finalizeValueOnRead()
|
||||
verbose.convention(providers.verboseApplyPatches())
|
||||
}
|
||||
|
||||
@TaskAction
|
||||
|
@ -91,7 +95,7 @@ abstract class ApplyGitPatches : ControllableOutputTask() {
|
|||
val target = outputPath.name
|
||||
|
||||
if (printOutput.get()) {
|
||||
println(" Resetting $target to ${upstream.path.name}...")
|
||||
logger.lifecycle("Resetting $target to ${upstream.path.name}...")
|
||||
}
|
||||
|
||||
val rootPatchDir = patchDir.pathOrNull ?: patchZip.path.let { unzip(it, findOutputDir(it)) }
|
||||
|
@ -102,14 +106,14 @@ abstract class ApplyGitPatches : ControllableOutputTask() {
|
|||
|
||||
if (unneededFiles.isPresent && unneededFiles.get().size > 0) {
|
||||
unneededFiles.get().forEach { path -> outputDir.path.resolve(path).deleteRecursive() }
|
||||
git(*Git.add(ignoreGitIgnore, ".")).setupOut().run()
|
||||
git("commit", "-m", "Initial", "--author=Initial Source <auto@mated.null>").setupOut().run()
|
||||
git(*Git.add(ignoreGitIgnore, ".")).executeSilently()
|
||||
git("commit", "-m", "Initial", "--author=Initial Source <auto@mated.null>").executeSilently()
|
||||
}
|
||||
|
||||
git("tag", "-d", "base").runSilently(silenceErr = true)
|
||||
git("tag", "base").executeSilently(silenceErr = true)
|
||||
|
||||
applyGitPatches(git, target, outputDir.path, rootPatchDir, printOutput.get())
|
||||
applyGitPatches(git, target, outputDir.path, rootPatchDir, printOutput.get(), verbose.get())
|
||||
}
|
||||
} finally {
|
||||
if (rootPatchDir != patchDir.pathOrNull) {
|
||||
|
@ -124,10 +128,11 @@ fun ControllableOutputTask.applyGitPatches(
|
|||
target: String,
|
||||
outputDir: Path,
|
||||
patchDir: Path?,
|
||||
printOutput: Boolean
|
||||
printOutput: Boolean,
|
||||
verbose: Boolean,
|
||||
) {
|
||||
if (printOutput) {
|
||||
println(" Applying patches to $target...")
|
||||
logger.lifecycle("Applying patches to $target...")
|
||||
}
|
||||
|
||||
val statusFile = outputDir.resolve(".git/patch-apply-failed")
|
||||
|
@ -138,7 +143,7 @@ fun ControllableOutputTask.applyGitPatches(
|
|||
val patches = patchDir?.useDirectoryEntries("*.patch") { it.toMutableList() } ?: mutableListOf()
|
||||
if (patches.isEmpty()) {
|
||||
if (printOutput) {
|
||||
println("No patches found")
|
||||
logger.lifecycle("No patches found")
|
||||
}
|
||||
return
|
||||
}
|
||||
|
@ -155,11 +160,12 @@ fun ControllableOutputTask.applyGitPatches(
|
|||
patch.copyTo(mailDir.resolve(patch.fileName))
|
||||
}
|
||||
|
||||
val result = git("am", "--3way", "--ignore-whitespace", tempDir.absolutePathString()).captureOut()
|
||||
val gitOut = printOutput && verbose
|
||||
val result = git("am", "--3way", "--ignore-whitespace", tempDir.absolutePathString()).captureOut(gitOut)
|
||||
if (result.exit != 0) {
|
||||
statusFile.writeText("1")
|
||||
|
||||
if (!printOutput) {
|
||||
if (!gitOut) {
|
||||
// Log the output anyway on failure
|
||||
logger.lifecycle(result.out)
|
||||
}
|
||||
|
@ -170,7 +176,7 @@ fun ControllableOutputTask.applyGitPatches(
|
|||
} else {
|
||||
statusFile.deleteForcefully()
|
||||
if (printOutput) {
|
||||
println(" Patches applied cleanly to $target")
|
||||
logger.lifecycle("${patches.size} patches applied cleanly to $target")
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
|
|
|
@ -89,9 +89,13 @@ abstract class ApplyPaperPatches : ControllableOutputTask() {
|
|||
@get:OutputDirectory
|
||||
abstract val mcDevSources: DirectoryProperty
|
||||
|
||||
@get:Input
|
||||
abstract val verbose: Property<Boolean>
|
||||
|
||||
override fun init() {
|
||||
upstreamBranch.convention("master")
|
||||
ignoreGitIgnore.convention(Git.ignoreProperty(providers)).finalizeValueOnRead()
|
||||
verbose.convention(providers.verboseApplyPatches())
|
||||
}
|
||||
|
||||
@TaskAction
|
||||
|
@ -114,7 +118,7 @@ abstract class ApplyPaperPatches : ControllableOutputTask() {
|
|||
val target = outputFile.name
|
||||
|
||||
if (printOutput.get()) {
|
||||
println(" Creating $target from remapped source...")
|
||||
logger.lifecycle("Creating $target from remapped source...")
|
||||
}
|
||||
|
||||
Git(outputFile).let { git ->
|
||||
|
@ -161,7 +165,7 @@ abstract class ApplyPaperPatches : ControllableOutputTask() {
|
|||
git("tag", "-d", "base").runSilently(silenceErr = true)
|
||||
git("tag", "base").executeSilently()
|
||||
|
||||
applyGitPatches(git, target, outputFile, patchDir.path, printOutput.get())
|
||||
applyGitPatches(git, target, outputFile, patchDir.path, printOutput.get(), verbose.get())
|
||||
|
||||
makeMcDevSrc(layout.cache, sourceMcDevJar.path, mcDevSources.path, outputDir.path, sourceDir, mcDataDir)
|
||||
}
|
||||
|
|
|
@ -23,8 +23,6 @@
|
|||
package io.papermc.paperweight.tasks
|
||||
|
||||
import io.papermc.paperweight.util.*
|
||||
import java.io.ByteArrayOutputStream
|
||||
import java.io.OutputStream
|
||||
import org.gradle.api.provider.Property
|
||||
import org.gradle.api.tasks.Console
|
||||
|
||||
|
@ -49,21 +47,4 @@ abstract class ControllableOutputTask : BaseTask() {
|
|||
setup(UselessOutputStream, System.out)
|
||||
}
|
||||
}
|
||||
|
||||
class Result(val exit: Int, val out: String)
|
||||
|
||||
fun Command.captureOut(): Result = run {
|
||||
val out = ByteArrayOutputStream()
|
||||
if (printOutput.get()) {
|
||||
val combined = System.out + out
|
||||
setup(combined, combined)
|
||||
} else {
|
||||
setup(out, out)
|
||||
}
|
||||
Result(run(), String(out.toByteArray()))
|
||||
}
|
||||
|
||||
private operator fun OutputStream.plus(out: OutputStream): OutputStream {
|
||||
return DelegatingOutputStream(this, out)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -70,13 +70,13 @@ abstract class RebuildGitPatches : ControllableOutputTask() {
|
|||
}
|
||||
|
||||
if (printOutput.get()) {
|
||||
println("Formatting patches for $what...")
|
||||
logger.lifecycle("Formatting patches for $what...")
|
||||
}
|
||||
|
||||
if (inputDir.path.resolve(".git/rebase-apply").exists()) {
|
||||
// in middle of a rebase, be smarter
|
||||
if (printOutput.get()) {
|
||||
println("REBASE DETECTED - PARTIAL SAVE")
|
||||
logger.lifecycle("REBASE DETECTED - PARTIAL SAVE")
|
||||
val last = inputDir.path.resolve(".git/rebase-apply/last").readText().trim().toInt()
|
||||
val next = inputDir.path.resolve(".git/rebase-apply/next").readText().trim().toInt()
|
||||
val orderedFiles = patchFolder.useDirectoryEntries("*.patch") { it.toMutableList() }
|
||||
|
@ -106,10 +106,12 @@ abstract class RebuildGitPatches : ControllableOutputTask() {
|
|||
|
||||
if (filterPatches.get()) {
|
||||
cleanupPatches(patchDirGit)
|
||||
}
|
||||
} else {
|
||||
if (printOutput.get()) {
|
||||
val saved = patchFolder.listDirectoryEntries("*.patch").size
|
||||
|
||||
if (printOutput.get()) {
|
||||
println(" Patches saved for $what to ${patchFolder.name}/")
|
||||
logger.lifecycle("Saved $saved patches for $what to ${layout.projectDirectory.path.relativize(patchFolder)}/")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -153,9 +155,9 @@ abstract class RebuildGitPatches : ControllableOutputTask() {
|
|||
}
|
||||
|
||||
if (printOutput.get()) {
|
||||
for (patch in patchFiles) {
|
||||
println(patch.name)
|
||||
}
|
||||
val saved = patchFiles.size - noChangesPatches.size
|
||||
val relDir = layout.projectDirectory.path.relativize(patchDir.path)
|
||||
logger.lifecycle("Saved modified patches ($saved/${patchFiles.size}) for ${inputDir.path.name} to $relDir/")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -101,7 +101,7 @@ object McDev {
|
|||
if (dataTargetDir != null) {
|
||||
logger.log(
|
||||
if (printOutput) LogLevel.LIFECYCLE else LogLevel.DEBUG,
|
||||
"Importing {} data files from vanilla data...",
|
||||
"Importing {} data files from vanilla...",
|
||||
dataImportMcDev.size
|
||||
)
|
||||
|
||||
|
|
|
@ -29,8 +29,7 @@ import org.gradle.api.Task
|
|||
|
||||
const val PAPERWEIGHT_EXTENSION = "paperweight"
|
||||
const val PAPERWEIGHT_DEBUG = "paperweight.debug"
|
||||
const val PAPERWEIGHT_PRINT_APPLY_PATCHES_OUTPUT = "paperweight.printBaseExecutionApplyPatchesOutput"
|
||||
const val PAPERWEIGHT_PRINT_REBUILD_PATCHES_OUTPUT = "paperweight.printRebuildPatchesOutput"
|
||||
const val PAPERWEIGHT_VERBOSE_APPLY_PATCHES = "paperweight.verboseApplyPatches"
|
||||
|
||||
const val MC_LIBRARY_URL = "https://libraries.minecraft.net/"
|
||||
|
||||
|
|
|
@ -199,4 +199,17 @@ class Command(private val processBuilder: ProcessBuilder, private val command: S
|
|||
setup(out, System.err)
|
||||
return if (run() == 0) String(out.toByteArray(), Charset.defaultCharset()) else null
|
||||
}
|
||||
|
||||
class Result(val exit: Int, val out: String)
|
||||
|
||||
fun captureOut(logOut: Boolean): Result = run {
|
||||
val out = ByteArrayOutputStream()
|
||||
if (logOut) {
|
||||
val combined = DelegatingOutputStream(System.out, out)
|
||||
setup(combined, combined)
|
||||
} else {
|
||||
setup(out, out)
|
||||
}
|
||||
Result(run(), String(out.toByteArray()))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -124,29 +124,18 @@ fun commentRegex(): Regex {
|
|||
return Regex("\\s*#.*")
|
||||
}
|
||||
|
||||
val Project.isBaseExecutionProvider: Provider<Boolean>
|
||||
get() = providers.gradleProperty(PAPERWEIGHT_DOWNSTREAM_FILE_PROPERTY)
|
||||
val ProviderFactory.isBaseExecution: Provider<Boolean>
|
||||
get() = gradleProperty(PAPERWEIGHT_DOWNSTREAM_FILE_PROPERTY)
|
||||
.orElse(provider { "false" })
|
||||
.map { it == "false" }
|
||||
|
||||
val Project.isBaseExecution: Boolean
|
||||
get() = isBaseExecutionProvider.get()
|
||||
get() = providers.isBaseExecution.get()
|
||||
|
||||
fun Project.printApplyPatchesOutput(): Provider<Boolean> {
|
||||
val base = isBaseExecutionProvider
|
||||
val showOutput = providers.gradleProperty(PAPERWEIGHT_PRINT_APPLY_PATCHES_OUTPUT)
|
||||
fun ProviderFactory.verboseApplyPatches(): Provider<Boolean> =
|
||||
gradleProperty(PAPERWEIGHT_VERBOSE_APPLY_PATCHES)
|
||||
.map { it.toBoolean() }
|
||||
.orElse(false)
|
||||
return base.zip(showOutput) { baseExecution, showOutputProp ->
|
||||
return@zip baseExecution && showOutputProp
|
||||
}
|
||||
}
|
||||
|
||||
fun Project.printRebuildPatchesOutput(): Provider<Boolean> {
|
||||
return providers.gradleProperty(PAPERWEIGHT_PRINT_REBUILD_PATCHES_OUTPUT)
|
||||
.map { it.toBoolean() }
|
||||
.orElse(false)
|
||||
}
|
||||
|
||||
val redirectThreadCount: AtomicLong = AtomicLong(0)
|
||||
|
||||
|
|
|
@ -261,7 +261,7 @@ class PaperweightPatcher : Plugin<Project> {
|
|||
if (isBaseExecution) {
|
||||
doNotTrackState("$name should always run when requested as part of the base execution.")
|
||||
}
|
||||
printOutput.set(printApplyPatchesOutput())
|
||||
printOutput.set(isBaseExecution)
|
||||
|
||||
val (cloneTask, upstreamDataTask) = upstreamTaskPair
|
||||
dependsOn(upstreamDataTask)
|
||||
|
@ -295,7 +295,6 @@ class PaperweightPatcher : Plugin<Project> {
|
|||
patchDir.convention(config.patchDir)
|
||||
inputDir.convention(config.outputDir)
|
||||
baseRef.convention("base")
|
||||
printOutput.set(project.printRebuildPatchesOutput())
|
||||
}
|
||||
|
||||
rebuildPatches {
|
||||
|
|
|
@ -85,11 +85,15 @@ abstract class PatcherApplyGitPatches : ControllableOutputTask() {
|
|||
@get:OutputDirectory
|
||||
abstract val mcDevSources: DirectoryProperty
|
||||
|
||||
@get:Input
|
||||
abstract val verbose: Property<Boolean>
|
||||
|
||||
override fun init() {
|
||||
upstreamBranch.convention("master")
|
||||
importMcDev.convention(false)
|
||||
printOutput.convention(true).finalizeValueOnRead()
|
||||
ignoreGitIgnore.convention(Git.ignoreProperty(providers)).finalizeValueOnRead()
|
||||
verbose.convention(providers.verboseApplyPatches())
|
||||
}
|
||||
|
||||
@TaskAction
|
||||
|
@ -112,7 +116,7 @@ abstract class PatcherApplyGitPatches : ControllableOutputTask() {
|
|||
val target = output.name
|
||||
|
||||
if (printOutput.get()) {
|
||||
println(" Creating $target from patch source...")
|
||||
logger.lifecycle("Creating $target from patch source...")
|
||||
}
|
||||
|
||||
if (bareDirectory.get()) {
|
||||
|
@ -157,7 +161,7 @@ abstract class PatcherApplyGitPatches : ControllableOutputTask() {
|
|||
git("tag", "-d", "base").runSilently(silenceErr = true)
|
||||
git("tag", "base").executeSilently()
|
||||
|
||||
applyGitPatches(git, target, output, patchDir.pathOrNull, printOutput.get())
|
||||
applyGitPatches(git, target, output, patchDir.pathOrNull, printOutput.get(), verbose.get())
|
||||
|
||||
makeMcDevSrc(layout.cache, sourceMcDevJar.path, mcDevSources.path, outputDir.path, srcDir, dataDir)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue