-
-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update hypo, implement fuzzy patching, start playing with patch remap
- Loading branch information
1 parent
7332ed9
commit fc64771
Showing
10 changed files
with
179 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ plugins { | |
} | ||
|
||
java { | ||
//withSourcesJar() | ||
//withSourcesJar() // TODO | ||
} | ||
|
||
kotlin { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
paperweight-lib/src/main/kotlin/io/papermc/paperweight/tasks/patchremapv2/RemapCBPatches.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
package io.papermc.paperweight.tasks.patchremapv2 | ||
|
||
import com.github.difflib.DiffUtils | ||
import com.github.difflib.UnifiedDiffUtils | ||
import io.papermc.paperweight.tasks.* | ||
import io.papermc.paperweight.util.* | ||
import io.papermc.paperweight.util.constants.* | ||
import java.nio.file.Path | ||
import kotlin.io.path.* | ||
import org.cadixdev.mercury.Mercury | ||
import org.cadixdev.mercury.remapper.MercuryRemapper | ||
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 org.gradle.api.tasks.UntrackedTask | ||
import org.gradle.kotlin.dsl.* | ||
|
||
@UntrackedTask(because = "RemapCBPatches should always run when requested") | ||
abstract class RemapCBPatches : BaseTask() { | ||
|
||
@get:InputDirectory | ||
abstract val base: DirectoryProperty | ||
|
||
@get:InputDirectory | ||
abstract val craftBukkit: DirectoryProperty | ||
|
||
@get:InputFile | ||
abstract val mappingsFile: RegularFileProperty | ||
|
||
@get:OutputDirectory | ||
abstract val outputPatchDir: DirectoryProperty | ||
|
||
@TaskAction | ||
fun run() { | ||
val workDir = layout.cache.resolve(REMAPPED_CB).ensureClean() | ||
val patches = outputPatchDir.convertToPath().ensureClean() | ||
val mappings = MappingFormats.TINY.read(mappingsFile.convertToPath(), SPIGOT_NAMESPACE, DEOBF_NAMESPACE) | ||
|
||
val configFiles = project.project(":paper-server").configurations["runtimeClasspath"].resolve().map { it.toPath() } | ||
val classpath = configFiles + listOf( | ||
project.project(":paper-api").projectDir.toPath().resolve("src/main/java"), | ||
project.file(".gradle/caches/paperweight/taskCache/spigotRemapJar.jar").toPath(), | ||
Path.of("C:\\Users\\Martin\\.m2\\repository\\org\\jetbrains\\annotations\\24.0.1\\annotations-24.0.1.jar") | ||
) | ||
|
||
println("dum $classpath") | ||
|
||
val merc = Mercury() | ||
merc.classPath.addAll(classpath) | ||
merc.processors.addAll( | ||
listOf( | ||
MercuryRemapper.create(mappings) | ||
) | ||
) | ||
merc.isGracefulClasspathChecks = true | ||
merc.rewrite(craftBukkit.convertToPath().resolve("src/main/java"), workDir) | ||
|
||
val inputDir = workDir | ||
val baseDir = Path.of("D:\\IdeaProjects\\Paper\\.gradle\\caches\\paperweight\\mache\\dum") | ||
|
||
val patchesCreated = baseDir.walk() | ||
.sumOf { | ||
diffFile(inputDir, baseDir, it.relativeTo(baseDir).toString().replace("\\", "/"), patches) | ||
} | ||
|
||
logger.lifecycle("Rebuilt $patchesCreated patches") | ||
} | ||
|
||
private fun diffFile(sourceRoot: Path, decompRoot: Path, relativePath: String, patchDir: Path): Int { | ||
val source = sourceRoot.resolve(relativePath) | ||
val decomp = decompRoot.resolve(relativePath) | ||
|
||
if (!source.exists() || !decomp.exists()) return 0 | ||
|
||
val sourceLines = source.readLines(Charsets.UTF_8) | ||
val decompLines = decomp.readLines(Charsets.UTF_8) | ||
|
||
val patch = DiffUtils.diff(decompLines, sourceLines) | ||
if (patch.deltas.isEmpty()) { | ||
return 0 | ||
} | ||
|
||
// remove all non craftbukkit chunks | ||
patch.deltas.removeIf { | ||
!it.target.lines.any { l -> l.contains("CraftBukkit") } | ||
} | ||
|
||
val unifiedPatch = UnifiedDiffUtils.generateUnifiedDiff( | ||
"a/$relativePath", | ||
"b/$relativePath", | ||
decompLines, | ||
patch, | ||
3, | ||
) | ||
|
||
val patchFile = patchDir.resolve("$relativePath.patch") | ||
patchFile.parent.createDirectories() | ||
patchFile.writeText(unifiedPatch.joinToString("\n", postfix = "\n"), Charsets.UTF_8) | ||
|
||
return 1 | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
paperweight-lib/src/main/kotlin/io/papermc/paperweight/tasks/softspoon/ApplyPatchesFuzzy.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package io.papermc.paperweight.tasks.softspoon | ||
|
||
import io.papermc.paperweight.util.patches.* | ||
import io.papermc.paperweight.util.patches.Patcher | ||
import org.gradle.api.provider.Property | ||
import org.gradle.api.tasks.Input | ||
import org.gradle.api.tasks.UntrackedTask | ||
import org.gradle.api.tasks.options.Option | ||
|
||
@UntrackedTask(because = "Always apply patches") | ||
abstract class ApplyPatchesFuzzy : ApplyPatches() { | ||
|
||
@get:Input | ||
@get:Option( | ||
option = "max-fuzz", | ||
description = "Max fuzz. Cannot be set higher than context (3). Setting this " + | ||
"value higher increases the chances of a faulty patch.", | ||
) | ||
abstract val maxFuzz: Property<String> | ||
|
||
override fun createPatcher(): Patcher { | ||
return if (useNativeDiff.get()) { | ||
NativePatcherFuzzy(exec, patchExecutable.get(), maxFuzz.get().toInt()) | ||
} else { | ||
JavaPatcherFuzzy(maxFuzz.get().toInt()) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters