Work on patch remapping
This commit is contained in:
parent
bca098dd60
commit
675a61ecfd
7 changed files with 53 additions and 37 deletions
|
@ -152,6 +152,7 @@ class Paperweight : Plugin<Project> {
|
|||
val patchPaperServer by tasks.registering<ApplyPaperPatches> {
|
||||
patchDir.set(extension.paper.spigotServerPatchDir)
|
||||
remappedSource.set(spigotTasks.remapSpigotSources.flatMap { it.outputZip })
|
||||
spigotServerDir.set(spigotTasks.patchSpigotServer.flatMap { it.outputDir })
|
||||
sourceMcDevJar.set(decompileJar.flatMap { it.outputJar })
|
||||
mcLibrariesDir.set(vanillaTasks.downloadMcLibraries.flatMap { it.outputDir }.get())
|
||||
libraryImports.set(extension.paper.libraryClassImports)
|
||||
|
@ -486,11 +487,12 @@ class Paperweight : Plugin<Project> {
|
|||
apiPatchDir.set(extension.paper.spigotApiPatchDir)
|
||||
|
||||
mappingsFile.set(spigotTasks.patchMappings.flatMap { it.outputMappings }.get())
|
||||
ats.set(spigotTasks.remapSpigotSources.flatMap { it.generatedAt }.get())
|
||||
|
||||
// Pull in as many jars as possible to reduce the possibility of type bindings not resolving
|
||||
classpathJars.add(generalTasks.downloadServerJar.flatMap { it.outputJar }.get())
|
||||
classpathJars.add(spigotTasks.remapSpigotSources.flatMap { it.vanillaRemappedSpigotJar }.get())
|
||||
classpathJars.add(applyMergedAt.flatMap { it.outputJar }.get())
|
||||
classpathJars.add(applyMergedAt.flatMap { it.outputJar }.get()) // final remapped jar
|
||||
classpathJars.add(spigotTasks.remapSpigotSources.flatMap { it.vanillaRemappedSpigotJar }.get()) // Spigot remapped jar
|
||||
classpathJars.add(generalTasks.downloadServerJar.flatMap { it.outputJar }.get()) // pure vanilla jar
|
||||
|
||||
spigotApiDir.set(spigotTasks.patchSpigotApi.flatMap { it.outputDir }.get())
|
||||
spigotServerDir.set(spigotTasks.patchSpigotServer.flatMap { it.outputDir }.get())
|
||||
|
|
|
@ -38,6 +38,8 @@ abstract class ApplyPaperPatches : ControllableOutputTask() {
|
|||
abstract val patchDir: DirectoryProperty
|
||||
@get:InputFile
|
||||
abstract val remappedSource: RegularFileProperty
|
||||
@get:InputDirectory
|
||||
abstract val spigotServerDir: DirectoryProperty
|
||||
@get:InputFile
|
||||
abstract val sourceMcDevJar: RegularFileProperty
|
||||
@get:InputDirectory
|
||||
|
@ -70,7 +72,7 @@ abstract class ApplyPaperPatches : ControllableOutputTask() {
|
|||
}
|
||||
|
||||
Git(outputFile).let { git ->
|
||||
git("init").runSilently(silenceErr = true)
|
||||
git("clone", spigotServerDir.file.absolutePath, outputFile.absolutePath).executeSilently()
|
||||
|
||||
val sourceDir = remapTargetDir.file
|
||||
if (sourceDir.exists()) {
|
||||
|
@ -87,7 +89,7 @@ abstract class ApplyPaperPatches : ControllableOutputTask() {
|
|||
McDev.importMcDev(patches, sourceMcDevJar.file, libraryImports.file, mcLibrariesDir.file, sourceDir)
|
||||
|
||||
git("add", ".").executeSilently()
|
||||
git("commit", "-m", "Initial", "--author=Initial <auto@mated.null>").executeSilently()
|
||||
git("commit", "-m", "Initial", "--author=Initial Source <auto@mated.null>").executeSilently()
|
||||
git("tag", "base").executeSilently()
|
||||
|
||||
applyGitPatches(git, target, outputFile, patchDir.file, printOutput.get())
|
||||
|
|
|
@ -16,7 +16,7 @@ abstract class RebuildPaperPatches : ControllableOutputTask() {
|
|||
abstract val inputDir: DirectoryProperty
|
||||
@get:Console
|
||||
abstract val server: Property<Boolean>
|
||||
@get:Option(option = "filter-patches", description = "Controlls if patches should be cleaned up, defaults to true")
|
||||
@get:Option(option = "filter-patches", description = "Controls if patches should be cleaned up, defaults to true")
|
||||
abstract val filterPatches: Property<Boolean>
|
||||
|
||||
@get:OutputDirectory
|
||||
|
|
|
@ -34,7 +34,6 @@ import org.cadixdev.at.io.AccessTransformFormats
|
|||
import org.cadixdev.mercury.Mercury
|
||||
import org.cadixdev.mercury.at.AccessTransformerRewriter
|
||||
import org.cadixdev.mercury.extra.AccessAnalyzerProcessor
|
||||
import org.cadixdev.mercury.extra.BridgeMethodRewriter
|
||||
import org.cadixdev.mercury.remapper.MercuryRemapper
|
||||
import org.gradle.api.file.DirectoryProperty
|
||||
import org.gradle.api.file.RegularFileProperty
|
||||
|
@ -52,7 +51,7 @@ abstract class RemapSources : ZippedTask() {
|
|||
@get:InputFile
|
||||
abstract val vanillaJar: RegularFileProperty
|
||||
@get:InputFile
|
||||
abstract val vanillaRemappedSpigotJar: RegularFileProperty // Required for pre-remap pass
|
||||
abstract val vanillaRemappedSpigotJar: RegularFileProperty
|
||||
@get:InputFile
|
||||
abstract val mappings: RegularFileProperty
|
||||
|
||||
|
@ -66,8 +65,6 @@ abstract class RemapSources : ZippedTask() {
|
|||
|
||||
@get:OutputFile
|
||||
abstract val generatedAt: RegularFileProperty
|
||||
@get:OutputFile
|
||||
abstract val parameterNames: RegularFileProperty
|
||||
|
||||
@get:Inject
|
||||
abstract val workerExecutor: WorkerExecutor
|
||||
|
@ -75,7 +72,6 @@ abstract class RemapSources : ZippedTask() {
|
|||
override fun init() {
|
||||
super.init()
|
||||
generatedAt.convention(defaultOutput("at"))
|
||||
parameterNames.convention(defaultOutput("params"))
|
||||
}
|
||||
|
||||
override fun run(rootDir: File) {
|
||||
|
@ -86,8 +82,8 @@ abstract class RemapSources : ZippedTask() {
|
|||
}
|
||||
|
||||
queue.submit(RemapAction::class) {
|
||||
classpath.add(vanillaJar.file)
|
||||
classpath.add(vanillaRemappedSpigotJar.file)
|
||||
classpath.add(vanillaJar.file)
|
||||
classpath.add(spigotApiDir.dir("src/main/java").get().asFile)
|
||||
classpath.addAll(spigotDeps.get().asFileTree.filter { it.name.endsWith(".jar") && !it.name.endsWith("-sources.jar") }.files)
|
||||
|
||||
|
@ -96,7 +92,6 @@ abstract class RemapSources : ZippedTask() {
|
|||
|
||||
outputDir.set(rootDir)
|
||||
generatedAtOutput.set(generatedAt.file)
|
||||
paramNamesOutput.set(parameterNames.file)
|
||||
}
|
||||
|
||||
queue.await()
|
||||
|
@ -107,7 +102,7 @@ abstract class RemapSources : ZippedTask() {
|
|||
val mappingSet = TinyMappingFormat.STANDARD.read(parameters.mappings.path, Constants.SPIGOT_NAMESPACE, Constants.DEOBF_NAMESPACE)
|
||||
val processAt = AccessTransformSet.create()
|
||||
|
||||
// Remap any references Spigot maps to SRG
|
||||
// Remap any references Spigot maps to mojmap+yarn
|
||||
Mercury().let { merc ->
|
||||
merc.classPath.addAll(parameters.classpath.get().map { it.toPath() })
|
||||
|
||||
|
@ -118,7 +113,6 @@ abstract class RemapSources : ZippedTask() {
|
|||
merc.processors.clear()
|
||||
merc.processors.addAll(listOf(
|
||||
MercuryRemapper.create(mappingSet),
|
||||
BridgeMethodRewriter.create(),
|
||||
AccessTransformerRewriter.create(processAt)
|
||||
))
|
||||
|
||||
|
@ -136,6 +130,5 @@ abstract class RemapSources : ZippedTask() {
|
|||
|
||||
val generatedAtOutput: RegularFileProperty
|
||||
val outputDir: RegularFileProperty
|
||||
val paramNamesOutput: RegularFileProperty
|
||||
}
|
||||
}
|
||||
|
|
|
@ -63,6 +63,15 @@ class PatchApplier(
|
|||
git("tag", remappedBaseTag)
|
||||
}
|
||||
|
||||
fun commitRemappingDifferences(remapper: PatchSourceRemapWorker) {
|
||||
checkoutRemapped() // Switch to remapped branch without checkout out files
|
||||
remapper.remap() // Remap to new mappings
|
||||
println("Committing remap")
|
||||
git("add", ".").executeSilently()
|
||||
git("commit", "-m", "Remap", "--author=Initial <auto@mated.null>").executeSilently()
|
||||
checkoutOld()
|
||||
}
|
||||
|
||||
fun recordCommit() {
|
||||
commitMessage = git("log", "--format=%B", "-n", "1", "HEAD").getText()
|
||||
commitAuthor = git("log", "--format=%an <%ae>", "-n", "1", "HEAD").getText()
|
||||
|
@ -82,15 +91,6 @@ class PatchApplier(
|
|||
git("commit", "-m", message, "--author=$author", "--date=$time").execute()
|
||||
}
|
||||
|
||||
fun commitRemappingDifferences(remapper: PatchSourceRemapWorker) {
|
||||
checkoutRemapped() // Switch to remapped branch without checkout out files
|
||||
remapper.remap() // Remap to new mappings
|
||||
println("Committing remap")
|
||||
git("add", ".").executeSilently()
|
||||
git("commit", "-m", "Remap", "--author=Initial <auto@mated.null>").executeSilently()
|
||||
checkoutOld()
|
||||
}
|
||||
|
||||
fun applyPatch(patch: File) {
|
||||
println("Applying patch ${patch.name}")
|
||||
val result = git("am", "--3way", "--ignore-whitespace", patch.absolutePath).runOut()
|
||||
|
|
|
@ -25,34 +25,47 @@ package io.papermc.paperweight.tasks.patchremap
|
|||
import io.papermc.paperweight.util.Constants
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.Path
|
||||
import org.cadixdev.at.AccessTransformSet
|
||||
import org.cadixdev.lorenz.MappingSet
|
||||
import org.cadixdev.mercury.Mercury
|
||||
import org.cadixdev.mercury.at.AccessTransformerRewriter
|
||||
import org.cadixdev.mercury.remapper.MercuryRemapper
|
||||
|
||||
class PatchSourceRemapWorker(
|
||||
mappings: MappingSet,
|
||||
classpath: Collection<Path>,
|
||||
private val mappings: MappingSet,
|
||||
private val ats: AccessTransformSet,
|
||||
private val classpath: Collection<Path>,
|
||||
private val inputDir: Path,
|
||||
private val outputDir: Path
|
||||
) {
|
||||
|
||||
private val merc : Mercury = Mercury()
|
||||
// private val merc : Mercury = Mercury()
|
||||
|
||||
init {
|
||||
merc.classPath.addAll(classpath)
|
||||
|
||||
merc.processors.addAll(listOf(
|
||||
MercuryRemapper.create(mappings)
|
||||
))
|
||||
|
||||
merc.isGracefulClasspathChecks = true
|
||||
}
|
||||
// init {
|
||||
// merc.classPath.addAll(classpath)
|
||||
//
|
||||
// merc.processors.addAll(listOf(
|
||||
// MercuryRemapper.create(mappings),
|
||||
// AccessTransformerRewriter.create(ats)
|
||||
// ))
|
||||
//
|
||||
// merc.isGracefulClasspathChecks = true
|
||||
// }
|
||||
|
||||
fun remap() {
|
||||
setup()
|
||||
|
||||
println("mapping to ${Constants.DEOBF_NAMESPACE}")
|
||||
|
||||
val merc = Mercury()
|
||||
merc.classPath.addAll(classpath)
|
||||
|
||||
merc.processors.addAll(listOf(
|
||||
MercuryRemapper.create(mappings),
|
||||
AccessTransformerRewriter.create(ats)
|
||||
))
|
||||
|
||||
merc.isGracefulClasspathChecks = true
|
||||
merc.rewrite(inputDir, outputDir)
|
||||
|
||||
cleanup()
|
||||
|
|
|
@ -31,6 +31,7 @@ import io.papermc.paperweight.util.file
|
|||
import io.papermc.paperweight.util.path
|
||||
import java.io.File
|
||||
import net.fabricmc.lorenztiny.TinyMappingFormat
|
||||
import org.cadixdev.at.io.AccessTransformFormats
|
||||
import org.gradle.api.file.DirectoryProperty
|
||||
import org.gradle.api.file.RegularFile
|
||||
import org.gradle.api.file.RegularFileProperty
|
||||
|
@ -54,6 +55,8 @@ abstract class RemapPatches : BaseTask() {
|
|||
|
||||
@get:InputFile
|
||||
abstract val mappingsFile: RegularFileProperty
|
||||
@get:InputFile
|
||||
abstract val ats: RegularFileProperty
|
||||
|
||||
@get:Classpath
|
||||
abstract val classpathJars: ListProperty<RegularFile>
|
||||
|
@ -119,6 +122,7 @@ abstract class RemapPatches : BaseTask() {
|
|||
|
||||
PatchSourceRemapWorker(
|
||||
mappings,
|
||||
AccessTransformFormats.FML.read(ats.path),
|
||||
listOf(*classpathFiles.toTypedArray(), tempApiDir.resolve("src/main/java")).map { it.toPath() },
|
||||
sourceInputDir.toPath(),
|
||||
tempOutputDir.toPath()
|
||||
|
@ -127,7 +131,9 @@ abstract class RemapPatches : BaseTask() {
|
|||
|
||||
if (skip == 0) {
|
||||
// We need to include any missing classes for the patches later on
|
||||
// TODO we should pull these from the vanilla remapped jar instead
|
||||
McDev.importMcDev(patches, spigotDecompJar.file, libraryImports.file, mcLibrariesDir.file, tempInputDir.resolve("src/main/java"))
|
||||
|
||||
patchApplier.commitInitialSource() // Initial commit of Spigot sources
|
||||
patchApplier.checkoutRemapped() // Switch to remapped branch without checking out files
|
||||
|
||||
|
|
Loading…
Reference in a new issue