From 689f429c5088f58c828cd0c778c85ce539fc0a54 Mon Sep 17 00:00:00 2001 From: konsolas Date: Wed, 19 Feb 2020 22:50:56 +0000 Subject: [PATCH] #634: Cross platform patch scripts Removes the need for installing gnu sed on Mac --- applyPatches.sh | 14 +++++++++++++- makePatches.sh | 17 +++++++++++++++-- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/applyPatches.sh b/applyPatches.sh index 02401133f0..1fb7e40fbc 100755 --- a/applyPatches.sh +++ b/applyPatches.sh @@ -6,6 +6,18 @@ then exit fi +# https://stackoverflow.com/a/38595160 +# https://stackoverflow.com/a/800644 +if sed --version >/dev/null 2>&1; then + strip_cr() { + sed -i -- "s/\r//" "$@" + } +else + strip_cr () { + sed -i "" "s/$(printf '\r')//" "$@" + } +fi + nms=$1/net/minecraft/server cb=src/main/java/net/minecraft/server #clean up and rebuild @@ -17,7 +29,7 @@ do file="$(echo $file | cut -d. -f1).java" echo "Patching $file < $patchFile" - sed -i 's/\r//' "$nms/$file" > /dev/null + strip_cr "$nms/$file" > /dev/null cp "$nms/$file" "$cb/$file" patch -d src/main/java/ "net/minecraft/server/$file" < "$patchFile" diff --git a/makePatches.sh b/makePatches.sh index e2e1dbbc4a..bb711353b7 100755 --- a/makePatches.sh +++ b/makePatches.sh @@ -5,6 +5,19 @@ then echo "Please run this script again with the clean decompile sources as an argument. In most cases this will be ../work/decompile-XXXX" exit fi + +# https://stackoverflow.com/a/38595160 +# https://stackoverflow.com/a/800644 +if sed --version >/dev/null 2>&1; then + strip_cr() { + sed -i -- "s/\r//" "$@" + } +else + strip_cr () { + sed -i "" "s/$(printf '\r')//" "$@" + } +fi + cb=src/main/java/net/minecraft/server nms="$1/net/minecraft/server" show_diff_msg=true @@ -24,8 +37,8 @@ do then echo "Diffing $file" fi - sed -i 's/\r//' "$nms/$file" - sed -i 's/\r//' "$cb/$file" + strip_cr "$nms/$file" > /dev/null + strip_cr "$cb/$file" > /dev/null outName=$(echo nms-patches/"$(echo $file | cut -d. -f1)".patch) patchNew=$(diff -u --label a/net/minecraft/server/$file "$nms/$file" --label b/net/minecraft/server/$file "$cb/$file") if [ -f "$outName" ]