Skip to content

Commit

Permalink
try to remap patches
Browse files Browse the repository at this point in the history
  • Loading branch information
MiniDigger committed Jul 10, 2023
1 parent a1acc70 commit cecca9d
Show file tree
Hide file tree
Showing 3 changed files with 474 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,44 @@ open class PatchRemapTasks(

val patchCraftBukkit by tasks.registering<ApplyCraftBukkitPatches> {
// TODO temp to speed stuff up
//sourceJar.set(spigotDecompileJar.flatMap { it.outputJar })
sourceJar.set(cache.resolve("paperweight/taskCache/spigotDecompileJar.jar"))
sourceJar.set(spigotDecompileJar.flatMap { it.outputJar })
//sourceJar.set(cache.resolve("paperweight/taskCache/spigotDecompileJar.jar"))
cleanDirPath.set("net/minecraft")
patchDir.set(extension.patchRemap.patchDir)
craftBukkitDir.set(extension.patchRemap.craftBukkitDir)
outputDir.set(extension.patchRemap.patchedCraftBukkitDir)

//dependsOn(cloneForPatchRemap)
}

//val filterSpigotMojMapExcludes by tasks.registering<FilterSpigotExcludes> {
// inputZip.set(spigotMojMapRemapJar.flatMap { it.outputJar })
// excludesFile.set(extension.patchRemap.excludesFile)
//}
//
//val spigotDecompileMojMapJar by tasks.registering<SpigotDecompileJar> {
// inputJar.set(filterSpigotMojMapExcludes.flatMap { it.outputZip })
// fernFlowerJar.set(extension.patchRemap.fernFlowerJar)
// decompileCommand.set(buildDataInfo.map { it.decompileCommand })
//}

val remapCraftBukkitSources by tasks.registering<RemapSources> {
vanillaJar.set(allTasks.extractFromBundler.flatMap { it.serverJar })
//mojangMappedVanillaJar.set(fixJar.flatMap { it.outputJar })
//vanillaRemappedSpigotJar.set(filterSpigotExcludes.flatMap { it.outputZip })
//mappings.set(generateSpigotMappings.flatMap { it.outputMappings })
mappings.set(cache.resolve(SPIGOT_MOJANG_YARN_MAPPINGS))
//sources.set(patchCraftBukkit.flatMap { it.outputDir }) // todo temp to speed stuff up
sources.set(extension.patchRemap.patchedCraftBukkitDir);
//spigotDeps.from(downloadSpigotDependencies.map { it.outputDir.asFileTree })
//additionalAts.set(mergePaperAts.flatMap { it.outputFile })
}

// todo first try diffing against remapped mcp config source
// if that fails, we have to diff against spigot decompiled mojmap+yarn mapped vanilla jar
val diffCraftBukkitAgainstVanilla by tasks.registering<DiffCraftBukkitAgainstVanilla> {
craftBukkit.set(remapCraftBukkitSources.flatMap { it.sourcesOutputZip })
//vanilla.set(allTasks.prepareBase.flatMap { it.output })
vanilla.set(cache.resolve(BASE_PROJECT))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package io.papermc.paperweight.tasks.patchremap

import codechicken.diffpatch.cli.DiffOperation
import io.papermc.paperweight.tasks.BaseTask
import io.papermc.paperweight.util.defaultOutput
import io.papermc.paperweight.util.filesMatchingRecursive
import io.papermc.paperweight.util.path
import org.gradle.api.file.DirectoryProperty
import org.gradle.api.file.RegularFileProperty
import org.gradle.api.tasks.InputDirectory
import org.gradle.api.tasks.InputFile
import org.gradle.api.tasks.OutputDirectory
import org.gradle.api.tasks.TaskAction
import java.nio.file.Files

abstract class DiffCraftBukkitAgainstVanilla: BaseTask() {

@get:InputFile
abstract val craftBukkit: RegularFileProperty

@get:InputDirectory
abstract val vanilla: DirectoryProperty

@get:OutputDirectory
abstract val patches: RegularFileProperty

override fun init() {
patches.convention(defaultOutput())
}

@TaskAction
open fun run() {
val diffOp = DiffOperation.builder()
.logTo(System.out)
.aPath(vanilla.path.resolve("src/vanilla"))
.bPath(craftBukkit.path)
.outputPath(patches.path.resolve("dum"))
.verbose(false)
.summary(true)
.lineEnding("\n")
//.ignorePattern(ignorePattern.get())
.build()

diffOp.operate()

patches.path.resolve("dum").filesMatchingRecursive("*.patch").forEach { p ->
if (Files.readAllLines(p)[1].contains("+++ /dev/null")) {
Files.delete(p)
}
}
Files.walk(patches.path.resolve("dum"))
.filter { Files.isDirectory(it) }
.filter { it.toFile().listFiles()?.isEmpty() ?: false }
.forEach { Files.delete(it) }
}
}
Loading

0 comments on commit cecca9d

Please sign in to comment.