Skip to content

Commit

Permalink
Switch to diffpatch
Browse files Browse the repository at this point in the history
  • Loading branch information
coehlrich committed Oct 16, 2023
1 parent 0ae0d6e commit 42208ff
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 60 deletions.
6 changes: 0 additions & 6 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -286,12 +286,6 @@ jobs:
build/download-task/**
.gradle/**
key: gradle-other-
- name: Prepare test jdk
if: ${{ matrix.jdk_version >= needs.common.outputs.jdk_version}}
uses: gradle/gradle-build-action@v2
with:
arguments: :${{ needs.common.outputs.version_name }}:testCompile${{ matrix.side }}${{ matrix.mappings }}${{ matrix.jdk_version }} -Ptype=${{ needs.common.outputs.version_type }}
generate-job-summary: false
- name: Test jdk
if: ${{ matrix.jdk_version >= needs.common.outputs.jdk_version}}
uses: gradle/gradle-build-action@v2
Expand Down
76 changes: 30 additions & 46 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
plugins {
id 'de.undercouch.download'
id 'uk.jamierocks.propatcher' version '2.0.1' apply false
}

import net.minecraftforge.mcpconfig.tasks.*
import net.minecraftforge.srgutils.MinecraftVersion
import java.nio.file.Files
import java.util.function.BiFunction
import java.util.stream.Collectors
import uk.jamierocks.propatcher.task.*

group = 'net.neoforged'

Expand Down Expand Up @@ -400,31 +398,24 @@ subprojects {
sides.server.slimsrc = serverOut = file(PATH_CACHED_VERSION + 'server.decompile.slim.jar')
sides.joined.slimsrc = joinedOut = file(PATH_CACHED_VERSION + 'joined.decompile.slim.jar')
}

task projectSharedMakeDir(type: MakeDir, dependsOn: [projectRoot]) {
folder = project.file('projects/shared')
}
task projectSharedMakePatchesDir(type: MakeDir) {
folder = project.file('patches/shared')
}

task projectSharedReset(type: ResetSourcesTask, dependsOn: [deduplicateSources, projectSharedMakeDir]) {
mustRunAfter projectRoot
rootZip deduplicateSources.duplicates.get().getAsFile()
target projectSharedMakeDir.folder.get().getAsFile()

task projectSharedApplyPatches(type: ApplyPatches, dependsOn: [deduplicateSources, projectRoot]) {
baseZip = deduplicateSources.duplicates
output = project.file('projects/shared')
patches = project.file('patches/shared')
}
task projectSharedApplyPatches(type: ApplyPatchesTask, dependsOn: [projectSharedReset, projectSharedMakePatchesDir]) {
target projectSharedReset.target
patches projectSharedMakePatchesDir.folder.get().getAsFile()
task projectSharedMakePatches(type: MakePatches, dependsOn: [deduplicateSources, projectRoot]) {
mustRunAfter projectSharedApplyPatches
baseZip = deduplicateSources.duplicates
modified = project.file('projects/shared')
patches = project.file('patches/shared')
}
task projectSharedMakePatches(type: MakePatchesTask, dependsOn: [deduplicateSources, projectSharedMakePatchesDir, projectSharedMakeDir]) {
mustRunAfter projectRoot
rootZip deduplicateSources.duplicates.get().getAsFile()
target projectSharedApplyPatches.target
patches projectSharedApplyPatches.patches
task projectSharedReset(type: Copy, dependsOn: [deduplicateSources, projectRoot]) {
from zipTree(deduplicateSources.duplicates)
into project.file('projects/shared')
}
task renameSourcesShared(type: RenameSources, dependsOn: [projectSharedApplyPatches, makeObfToIntermediate, downloadClientMappings]) {
input = projectSharedApplyPatches.target
input = projectSharedApplyPatches.output
srg = makeObfToIntermediate.dest
official = downloadClientMappings.dest
dest = project.file(PATH_CACHED_VERSION + "test/official/shared/src/")
Expand Down Expand Up @@ -460,44 +451,37 @@ subprojects {
replaceFile '{inject}', PATH_INJECT
replaceFile '{assets}', child.assets ? downloadAssets.dest : null
replaceFile '{natives}', child.jsonlibs ? extractNatives.dest : null
replaceFile '{merged_src}', MERGE_PATCHES ? projectSharedReset.target : null
replaceFile '{merged_src}', MERGE_PATCHES ? project.file('projects/shared') : null
}
projectAll.dependsOn(child.project)

child.makePkgsDir = task "project${child.Name}MakePkgsDir"(type: MakeDir, dependsOn: [projectRoot, child.project]) {
folder = new File(project_dir, 'src/pkginfo/java')
}
child.resetPkgs = task "project${child.Name}ResetPackages"(type: ResetSourcesTask, dependsOn: [child.makePkgsDir, child.pkgs]) {
mustRunAfter child.project
rootZip child.pkgs.dest.get().getAsFile()
target child.makePkgsDir.folder.get().getAsFile()
child.resetPkgs = task "project${child.Name}ResetPackages"(type: Copy, dependsOn: [child.pkgs, child.project]) {
from zipTree(child.pkgs.dest)
into new File(project_dir, 'src/pkginfo/java')
}

child.makeSrcDir = task "project${child.Name}MakeSrcDir"(type: MakeDir, dependsOn: [projectRoot, child.project]) {
folder = new File(project_dir, 'src/main/java')
}
child.reset = task "project${child.Name}Reset"(type: ResetSourcesTask, dependsOn: [child.resetPkgs, child.makeSrcDir, child.project, child.decompile] + (MERGE_PATCHES ? [projectSharedReset] : [])) {
child.reset = task "project${child.Name}Reset"(type: Copy, dependsOn: [child.resetPkgs, child.project, child.decompile] + (MERGE_PATCHES ? [projectSharedReset] : [])) {
mustRunAfter child.project
rootZip MERGE_PATCHES ? child.slimsrc : child.decompile.dest.get().getAsFile()
target child.makeSrcDir.folder.get().getAsFile()
from zipTree(MERGE_PATCHES ? child.slimsrc : child.decompile.dest)
into new File(project_dir, 'src/main/java')
}
projectResetAll.dependsOn(child.reset)

child.makePatchesDir = task "project${child.Name}MakePatchesDir"(type: MakeDir) {
folder = patches_dir
}
child.apply = task "project${child.Name}ApplyPatches"(type: ApplyPatchesTask, dependsOn: [child.reset, child.makePatchesDir] + (MERGE_PATCHES ? [projectSharedApplyPatches] : [])) {
target new File(project_dir, 'src/main/java')
patches patches_dir
child.apply = task "project${child.Name}ApplyPatches"(type: ApplyPatches, dependsOn: [child.resetPkgs, child.project, child.decompile, child.makePatchesDir] + (MERGE_PATCHES ? [projectSharedApplyPatches] : [])) {
baseZip = MERGE_PATCHES ? child.slimsrc : child.decompile.dest
output = new File(project_dir, 'src/main/java')
patches = patches_dir
}
projectApplyAll.dependsOn(child.apply)

child.makePatches = task "project${child.Name}MakePatches"(type: MakePatchesTask, dependsOn: [child.makePatchesDir, child.makeSrcDir] + (MERGE_PATCHES ? [deduplicateSources, projectSharedMakePatches] : [child.decompile])) {
mustRunAfter projectRoot
mustRunAfter child.project
rootZip MERGE_PATCHES ? child.slimsrc : child.decompile.dest.get().getAsFile()
target new File(project_dir, 'src/main/java')
patches patches_dir
child.makePatches = task "project${child.Name}MakePatches"(type: MakePatches, dependsOn: [projectRoot, child.project] + (MERGE_PATCHES ? [deduplicateSources, projectSharedMakePatches] : [child.decompile])) {
mustRunAfter child.apply
baseZip = MERGE_PATCHES ? child.slimsrc : child.decompile.dest
modified = new File(project_dir, 'src/main/java')
patches = patches_dir
}
projectMakeAll.dependsOn child.makePatches

Expand Down
1 change: 1 addition & 0 deletions buildSrc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ dependencies {
implementation 'de.undercouch:gradle-download-task:5.5.0' // Bulk DownloadLibraries task
implementation 'net.minecraftforge:mapping-verifier:2.0.8'
implementation 'net.sf.jopt-simple:jopt-simple:5.0.4' // Needed for verifier
implementation 'codechicken:DiffPatch:1.5.0.29'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package net.minecraftforge.mcpconfig.tasks

import codechicken.diffpatch.cli.*
import codechicken.diffpatch.util.LoggingOutputStream
import codechicken.diffpatch.util.PatchMode
import org.gradle.api.*
import org.gradle.api.logging.*
import org.gradle.api.file.*
import org.gradle.api.tasks.*

public abstract class ApplyPatches extends DefaultTask {
@InputFile abstract RegularFileProperty getBaseZip()
@InputDirectory @Optional abstract RegularFileProperty getPatches()
@OutputDirectory abstract RegularFileProperty getOutput()

@TaskAction
def exec() {
Utils.init()

def baseZip = baseZip.get().asFile
def output = output.get().asFile
def patches = patches.get().asFile

def result = PatchOperation.builder()
.logTo(new LoggingOutputStream(logger, LogLevel.LIFECYCLE))
.basePath(baseZip.toPath())
.patchesPath(patches.toPath())
.outputPath(output.toPath())
.level(codechicken.diffpatch.util.LogLevel.WARN)
.mode(PatchMode.OFFSET)
.build().operate()

def exit = result.exit
if (exit != 0 && exit != 1) {
throw new RuntimeException("DiffPatch failed with exit code: " + exit)
}
if (exit != 0) {
throw new RuntimeException("Patches failed to apply")
}

output.mkdirs()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package net.minecraftforge.mcpconfig.tasks

import codechicken.diffpatch.cli.*
import codechicken.diffpatch.util.LoggingOutputStream
import org.gradle.api.*
import org.gradle.api.logging.*
import org.gradle.api.file.*
import org.gradle.api.tasks.*

public abstract class MakePatches extends DefaultTask {
@InputFile abstract RegularFileProperty getBaseZip()
@InputDirectory abstract RegularFileProperty getModified()
@OutputDirectory abstract RegularFileProperty getPatches()

@TaskAction
def exec() {
Utils.init()

def baseZip = baseZip.get().asFile
def modified = modified.get().asFile
def patches = patches.get().asFile

def result = DiffOperation.builder()
.logTo(new LoggingOutputStream(logger, LogLevel.LIFECYCLE))
.aPath(baseZip.toPath())
.bPath(modified.toPath())
.outputPath(patches.toPath())
.level(codechicken.diffpatch.util.LogLevel.WARN)
.build().operate()

def exit = result.exit
if (exit != 0 && exit != 1) {
throw new RuntimeException("DiffPatch failed with exit code: " + exit)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@
worldloader$packconfig,
p_247857_ -> {
DynamicOps<Tag> dynamicops = RegistryOps.create(NbtOps.INSTANCE, p_247857_.datapackWorldgen());
@@ -184,11 +186,8 @@
@@ -184,10 +186,7 @@
}
);

- record Data(LevelSettings levelSettings, WorldOptions options, Registry<LevelStem> existingDimensions) {
}

- }
-
- }

private WorldLoader.PackConfig getPackConfigFromLevelData(LevelStorageSource.LevelStorageAccess p_249986_, boolean p_248615_, PackRepository p_249167_) {
WorldDataConfiguration worlddataconfiguration = p_249986_.getDataConfiguration();
if (worlddataconfiguration == null) {
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,15 @@
worldloader$packconfig,
p_247857_ -> {
DynamicOps<Tag> dynamicops = RegistryOps.create(NbtOps.INSTANCE, p_247857_.datapackWorldgen());
@@ -187,12 +190,8 @@
@@ -187,11 +190,7 @@
}
);

- @OnlyIn(Dist.CLIENT)
- record Data(LevelSettings levelSettings, WorldOptions options, Registry<LevelStem> existingDimensions) {
}

- }
-
- }

private WorldLoader.PackConfig getPackConfigFromLevelData(LevelStorageSource.LevelStorageAccess p_249986_, boolean p_248615_, PackRepository p_249167_) {
WorldDataConfiguration worlddataconfiguration = p_249986_.getDataConfiguration();
if (worlddataconfiguration == null) {

0 comments on commit 42208ff

Please sign in to comment.