Use new build system from Waterfall
This commit is contained in:

committed by
Marc Baloup

parent
0281ce1223
commit
2ffb99b297
73
scripts/applyPatches.sh
Normal file
73
scripts/applyPatches.sh
Normal file
@@ -0,0 +1,73 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
PS1="$"
|
||||
basedir="$(cd "$1" && pwd -P)"
|
||||
workdir="$basedir/work"
|
||||
gpgsign="$(git config commit.gpgsign || echo "false")"
|
||||
echo "Rebuilding Forked projects.... "
|
||||
|
||||
function enableCommitSigningIfNeeded {
|
||||
if [[ "$gpgsign" == "true" ]]; then
|
||||
echo "Re-enabling GPG Signing"
|
||||
# Yes, this has to be global
|
||||
git config --global commit.gpgsign true
|
||||
fi
|
||||
}
|
||||
|
||||
function applyPatch {
|
||||
what=$1
|
||||
what_name=$(basename "$what")
|
||||
target=$2
|
||||
branch=$3
|
||||
|
||||
cd "$basedir/$what"
|
||||
git fetch
|
||||
git branch -f upstream "$branch" >/dev/null
|
||||
|
||||
cd "$basedir"
|
||||
if [ ! -d "$basedir/$target" ]; then
|
||||
git clone "$what" "$target"
|
||||
fi
|
||||
cd "$basedir/$target"
|
||||
|
||||
echo "Resetting $target to $what_name..."
|
||||
git remote rm upstream > /dev/null 2>&1
|
||||
git remote add upstream "$basedir/$what" >/dev/null 2>&1
|
||||
git checkout master 2>/dev/null || git checkout -b master
|
||||
git fetch upstream >/dev/null 2>&1
|
||||
git reset --hard upstream/upstream
|
||||
|
||||
echo " Applying patches to $target..."
|
||||
|
||||
git am --abort >/dev/null 2>&1
|
||||
git am --3way --ignore-whitespace "$basedir/${what_name}-Patches/"*.patch
|
||||
if [ "$?" != "0" ]; then
|
||||
echo " Something did not apply cleanly to $target."
|
||||
echo " Please review above details and finish the apply then"
|
||||
echo " save the changes with rebuildPatches.sh"
|
||||
enableCommitSigningIfNeeded
|
||||
exit 1
|
||||
else
|
||||
echo " Patches applied cleanly to $target"
|
||||
fi
|
||||
}
|
||||
|
||||
# Disable GPG signing before AM, slows things down and doesn't play nicely.
|
||||
# There is also zero rational or logical reason to do so for these sub-repo AMs.
|
||||
# Calm down kids, it's re-enabled (if needed) immediately after, pass or fail.
|
||||
if [[ "$gpgsign" == "true" ]]; then
|
||||
echo "_Temporarily_ disabling GPG signing"
|
||||
git config --global commit.gpgsign false
|
||||
fi
|
||||
|
||||
# Apply waterfall patches
|
||||
basedir=$basedir/Waterfall
|
||||
pushd Waterfall
|
||||
applyPatch BungeeCord Waterfall-Proxy HEAD
|
||||
popd
|
||||
basedir=$(dirname $basedir)
|
||||
|
||||
# Apply travertine patches
|
||||
applyPatch Waterfall/Waterfall-Proxy Travertine-Proxy HEAD
|
||||
|
||||
enableCommitSigningIfNeeded
|
3
scripts/build.sh
Normal file
3
scripts/build.sh
Normal file
@@ -0,0 +1,3 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
git submodule update --recursive --init && ./scripts/applyPatches.sh && pushd Travertine-Proxy && mvn clean package && popd
|
5
scripts/edit.sh
Normal file
5
scripts/edit.sh
Normal file
@@ -0,0 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
pushd Travertine-Proxy
|
||||
git rebase --interactive upstream/upstream
|
||||
popd
|
16
scripts/mergeUpstream.sh
Normal file
16
scripts/mergeUpstream.sh
Normal file
@@ -0,0 +1,16 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
PS1="$"
|
||||
basedir=`pwd`
|
||||
|
||||
function update {
|
||||
cd "$basedir/$1"
|
||||
git fetch && git reset --hard origin/master
|
||||
cd "$basedir/$1/.."
|
||||
git add $1
|
||||
}
|
||||
|
||||
update Waterfall
|
||||
|
||||
# Update submodules
|
||||
git submodule update --recursive
|
61
scripts/rebuildPatches.sh
Normal file
61
scripts/rebuildPatches.sh
Normal file
@@ -0,0 +1,61 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
(
|
||||
PS1="$"
|
||||
basedir="$(cd "$1" && pwd -P)"
|
||||
workdir="$basedir/work"
|
||||
echo "Rebuilding patch files from current fork state..."
|
||||
git config core.safecrlf false
|
||||
|
||||
function cleanupPatches {
|
||||
cd "$1"
|
||||
for patch in *.patch; do
|
||||
echo "$patch"
|
||||
gitver=$(tail -n 2 "$patch" | grep -ve "^$" | tail -n 1)
|
||||
diffs=$(git diff --staged "$patch" | grep -E "^(\+|\-)" | grep -Ev "(From [a-z0-9]{32,}|\-\-\- a|\+\+\+ b|.index)")
|
||||
|
||||
testver=$(echo "$diffs" | tail -n 2 | grep -ve "^$" | tail -n 1 | grep "$gitver")
|
||||
if [ "x$testver" != "x" ]; then
|
||||
diffs=$(echo "$diffs" | sed 'N;$!P;$!D;$d')
|
||||
fi
|
||||
|
||||
if [ "x$diffs" == "x" ] ; then
|
||||
git reset HEAD "$patch" >/dev/null
|
||||
git checkout -- "$patch" >/dev/null
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
function savePatches {
|
||||
what=$1
|
||||
what_name=$(basename "$what")
|
||||
target=$2
|
||||
echo "Formatting patches for $what..."
|
||||
|
||||
cd "$basedir/${what_name}-Patches/"
|
||||
if [ -d "$basedir/$target/.git/rebase-apply" ]; then
|
||||
# in middle of a rebase, be smarter
|
||||
echo "REBASE DETECTED - PARTIAL SAVE"
|
||||
last=$(cat "$basedir/$target/.git/rebase-apply/last")
|
||||
next=$(cat "$basedir/$target/.git/rebase-apply/next")
|
||||
for i in $(seq -f "%04g" 1 1 $last)
|
||||
do
|
||||
if [ $i -lt $next ]; then
|
||||
rm ${i}-*.patch
|
||||
fi
|
||||
done
|
||||
else
|
||||
rm -rf *.patch
|
||||
fi
|
||||
|
||||
cd "$basedir/$target"
|
||||
|
||||
git format-patch --no-stat -N -o "$basedir/${what_name}-Patches/" upstream/upstream >/dev/null
|
||||
cd "$basedir"
|
||||
git add -A "$basedir/${what_name}-Patches"
|
||||
cleanupPatches "$basedir/${what_name}-Patches"
|
||||
echo " Patches saved for $what to $what_name-Patches/"
|
||||
}
|
||||
|
||||
savePatches "Waterfall/Waterfall-Proxy" "Travertine-Proxy"
|
||||
)
|
149
scripts/wigglePatch.py
Normal file
149
scripts/wigglePatch.py
Normal file
@@ -0,0 +1,149 @@
|
||||
#!/usr/bin/env python3
|
||||
from subprocess import run, PIPE, CalledProcessError
|
||||
from argparse import ArgumentParser
|
||||
import os
|
||||
from os import path
|
||||
from sys import stderr, stdout
|
||||
import re
|
||||
from enum import Enum, unique
|
||||
|
||||
@unique
|
||||
class FileStatus(Enum):
|
||||
UNTRACKED = '?'
|
||||
UNMODIFIED = ' '
|
||||
MODIFIED = 'M'
|
||||
ADDED = 'A'
|
||||
DELETED = 'D'
|
||||
RENAMED = 'R'
|
||||
COPIED = 'C'
|
||||
UNMERGED = 'U'
|
||||
IGNORED = '!'
|
||||
|
||||
class GitRepository:
|
||||
def __init__(self, directory):
|
||||
if not path.isdir(directory):
|
||||
if not path.exists(directory):
|
||||
raise ValueError("Repository doesn't exist:", directory)
|
||||
else:
|
||||
raise ValueError("Repository isn't a valid directory:", directory)
|
||||
elif not path.isdir(path.join(directory, ".git")):
|
||||
raise ValueError("Directory isn't a git repository:", directory)
|
||||
self.directory = directory
|
||||
|
||||
def status(self):
|
||||
status_lines = run(
|
||||
["git", "status", "--porcelain"],
|
||||
check=True, stdout=PIPE, universal_newlines=True,
|
||||
cwd=self.directory
|
||||
).stdout
|
||||
status = dict()
|
||||
for line in status_lines.splitlines():
|
||||
old_status = FileStatus(line[0])
|
||||
new_status = FileStatus(line[1])
|
||||
file_name = line[3:]
|
||||
status[file_name] = (old_status, new_status)
|
||||
return status
|
||||
|
||||
def is_clean(self):
|
||||
try:
|
||||
return len(self.status()) == 0
|
||||
except CalledProcessError:
|
||||
return False
|
||||
|
||||
def is_automatically_merging(self):
|
||||
return path.exists(path.join(self.directory, ".git", "rebase-apply", "applying"))
|
||||
|
||||
def wiggle_patch(self, patch):
|
||||
assert self.is_clean()
|
||||
# By default, wiggle won't create files the patch needs, and just fails
|
||||
for created_file in patch.created_files:
|
||||
# mkdir -p $(dirname created_file)
|
||||
os.makedirs(path.join(self.directory, path.dirname(created_file)), exist_ok=True)
|
||||
# touch created_file
|
||||
with open(path.join(self.directory, created_file), 'a'):
|
||||
pass
|
||||
result = run(["wiggle", "-rp", path.relpath(patch.file, start=self.directory)],
|
||||
stderr=stderr, cwd=self.directory)
|
||||
for file_name, (old_status, new_status) in self.status().items():
|
||||
if new_status == FileStatus.UNTRACKED and old_status == FileStatus.UNTRACKED \
|
||||
and file_name.endswith(".porig"):
|
||||
# Remove wiggle's automatically created backup files
|
||||
# They're completely unessicary since the entire repo is version-controlled
|
||||
os.remove(path.join(self.directory, file_name))
|
||||
if result.returncode == 1:
|
||||
return False # There were unresolved conflicts
|
||||
else:
|
||||
# Check for an unexpected error
|
||||
# Since conflicts were already checked for, this will only raise for unexpected errors
|
||||
result.check_returncode()
|
||||
return True # Successfully wiggled
|
||||
|
||||
def __str__(self):
|
||||
return path.basename(self.directory)
|
||||
|
||||
class PatchFile:
|
||||
def __init__(self, file):
|
||||
if not path.isfile(file):
|
||||
if not path.exists(file):
|
||||
raise ValueError("Patch file doesn't exist:", file)
|
||||
else:
|
||||
raise ValueError("Patch isn't a file:", file)
|
||||
self.file = file
|
||||
try:
|
||||
summary = run(["git", "apply", "--summary", file],
|
||||
check=True, stdout=PIPE, universal_newlines=True).stdout
|
||||
except CalledProcessError:
|
||||
raise ValueError("Invalid patch file:", file)
|
||||
summary_pattern = re.compile(r"\s*(create) mode \d+ (\S+)")
|
||||
created_files = list()
|
||||
for line in summary.splitlines():
|
||||
match = summary_pattern.match(line)
|
||||
if not match:
|
||||
raise NotImplementedError("Don't know how to parse summary line: {}".format(line))
|
||||
(action, target_file) = match.groups()
|
||||
if action == "create":
|
||||
created_files.append(target_file)
|
||||
self.created_files = tuple(created_files) # Immutable copy
|
||||
|
||||
def __str__(self):
|
||||
return path.basename(self.file)
|
||||
|
||||
parser = ArgumentParser(description="Wiggle the patch into the specified git repository")
|
||||
parser.add_argument("repo", help="The git repository to apply the patch to", type=GitRepository)
|
||||
parser.add_argument("patch", help="The patch to apply to the repository", type=PatchFile)
|
||||
parser.add_argument("--git-am", "--am", "-a", action="store_true",
|
||||
help="If an automatic merge is in progress, continue it after wiggling")
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
repository, patch = args.repo, args.patch
|
||||
|
||||
if not repository.is_clean():
|
||||
print(repository, "isn't a clean repo!")
|
||||
exit(1)
|
||||
|
||||
|
||||
was_automatically_merging = False
|
||||
if args.git_am and repository.is_automatically_merging():
|
||||
print("Automatic merge in progress, will continue applying if successful")
|
||||
was_automatically_merging = True
|
||||
|
||||
if not repository.wiggle_patch(patch):
|
||||
print("Unresolved conflicts found while wiggling!", file=stderr)
|
||||
print("Manual intervention is required to fix the conflicts!", file=stderr)
|
||||
exit(2)
|
||||
|
||||
if args.git_am and was_automatically_merging:
|
||||
assert repository.is_automatically_merging()
|
||||
try:
|
||||
print("Adding changed files to index")
|
||||
run(["git", "add", "."], stdout=stdout, stderr=stderr, check=True,
|
||||
cwd=repository.directory)
|
||||
print("Continuing automatic merge after successful wiggle")
|
||||
run(["git", "am", "--continue"], stdout=stdout, stderr=stderr, check=True,
|
||||
cwd=repository.directory)
|
||||
except CalledProcessError as e:
|
||||
print("Failed to continue automatic merge!", file=stderr)
|
||||
exit(3)
|
||||
else:
|
||||
print("Successfully Wiggled", patch, "into", repository)
|
Reference in New Issue
Block a user