diff --git a/paper b/paper index 9d0e260c3..340acf43d 100755 --- a/paper +++ b/paper @@ -22,59 +22,81 @@ paperunstash() { case "$1" in "rbp" | "rebuild") - ( + ( + set -e cd "$basedir" scripts/rebuildPatches.sh "$basedir" - ) + ) ;; - "a" | "apply") - ( + "p" | "patch") + ( + set -e cd "$basedir" scripts/build.sh "$basedir" - ) + ) ;; "j" | "jar") - ( - cd "$basedir" + ( + set -e + cd "$basedir" scripts/build.sh "$basedir" "--jar" - ) + ) + ;; + "make") + ( + if [[ "$2" = "bacon" ]] ; then + set -e + cd "$basedir" + scripts/build.sh "$basedir" "--jar" + fi + ) ;; "r" | "root") cd "$basedir" ;; - "api") + "a" | "api") cd "$basedir/Paper-API" ;; - "serv" | "server") + "s" | "server") cd "$basedir" ;; "e" | "edit") case "$2" in - "server") - cd "$basedir/Paper-Server" - export LAST_EDIT=$(pwd) + "s" | "server") + export LAST_EDIT="$basedir/Paper-Server" + cd "$basedir/Paper-Server" + ( + set -e paperstash git rebase -i upstream/upstream paperunstash + ) ;; - "api") - cd "$basedir/Paper-API" - export LAST_EDIT=$(pwd) + "a" | "api") + export LAST_EDIT="$basedir/Paper-API" + cd "$basedir/Paper-API" + ( + set -e paperstash git rebase -i upstream/upstream paperunstash + ) ;; - "continue") - cd "$LAST_EDIT" + "c" | "continue") + cd "$LAST_EDIT" + unset LAST_EDIT + ( + set -e + git add . + git commit --amend git rebase --continue - unset LAST_EDIT - ( - cd "$basedir" - scripts/rebuildPatches.sh "$basedir" - ) + + cd "$basedir" + scripts/rebuildPatches.sh "$basedir" + ) ;; *) echo "You must edit either the api or server." @@ -83,24 +105,40 @@ case "$1" in ;; "setup") if [[ -f ~/.bashrc ]] ; then - (grep "alias paper=" ~/.bashrc > /dev/null) && (sed -i "s|alias paper=.*|alias paper='. $SOURCE'|g" ~/.bashrc) || (echo "alias paper='. $SOURCE'" >> ~/.bashrc) - alias paper=". $SOURCE" - echo "You can now just type 'paper' at any time to access the paper tool." + NAME="paper" + if [[ ! -z "${2+x}" ]] ; then + NAME="$2" + fi + (grep "alias $NAME=" ~/.bashrc > /dev/null) && (sed -i "s|alias $NAME=.*|alias $NAME='. $SOURCE'|g" ~/.bashrc) || (echo "alias $NAME='. $SOURCE'" >> ~/.bashrc) + alias "$NAME=. $SOURCE" + echo "You can now just type '$NAME' at any time to access the paper tool." fi ;; *) - echo "rbp, rebuild | Rebuild patches, can be called from anywhere." - echo "p, patch | Apply all patches to the project without building it. Can be run from anywhere." - echo "j, jar | Apply all patches and build the project, paperclip.jar will be output. Can be run from anywhere." - echo "r, root | Change directory to the root of the project." - echo "api | Move to the Paper-API directory." - echo "serv, server | Move to the Paper-Server directory." - echo "e, edit | Use to edit a specific patch, give it the argument \"server\" or \"api\"" - echo " | respectively to edit the correct project. Use the argument \"continue\" after" - echo " | the changes have been made to finish and rebuild patches. Can be called from anywhere." - echo "setup | Add an alias to .bashrc to allow full functionality of this script. Run as:" - echo " | . ./paper setup" - echo " | After you run this command you'll be able to just run 'paper' from anywhere." + echo "PaperMC build tool command. This provides a variety of commands to build and manage the PaperMC build" + echo "environment. For all of the functionality of this command to be available, you must first run the" + echo "'setup' command. View below for details. For essential building and patching, you do not need to do the setup." + echo "" + echo " Normal commands:" + echo " * rbp, rebuild | Rebuild patches, can be called from anywhere." + echo " * p, patch | Apply all patches to the project without building it. Can be run from anywhere." + echo " * j, jar | Apply all patches and build the project, paperclip.jar will be output. Can be run from anywhere." + echo "" + echo " These commands require the setup command before use:" + echo " * r, root | Change directory to the root of the project." + echo " * a. api | Move to the Paper-API directory." + echo " * s, server | Move to the Paper-Server directory." + echo " * e, edit | Use to edit a specific patch, give it the argument \"server\" or \"api\"" + echo " | respectively to edit the correct project. Use the argument \"continue\" after" + echo " | the changes have been made to finish and rebuild patches. Can be called from anywhere." + echo "" + echo " * setup | Add an alias to .bashrc to allow full functionality of this script. Run as:" + echo " | . ./paper setup" + echo " | After you run this command you'll be able to just run 'paper' from anywhere." + echo " | The default name for the resulting alias is 'paper', you can give an argument to override" + echo " | this default, such as:" + echo " | . ./paper setup example" + echo " | Which will allow you to run 'example' instead." ;; esac diff --git a/scripts/applyPatches.sh b/scripts/applyPatches.sh index ef40406c9..697cec183 100755 --- a/scripts/applyPatches.sh +++ b/scripts/applyPatches.sh @@ -1,5 +1,7 @@ #!/usr/bin/env bash +( +set -e PS1="$" basedir=$(realpath "$1") workdir="$basedir/work" @@ -67,4 +69,4 @@ cd "$basedir" echo "Failed to apply Paper Patches" exit 1 ) || exit 1 - +) diff --git a/scripts/build.sh b/scripts/build.sh index 4fee2815d..606668748 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -1,5 +1,7 @@ #!/usr/bin/env bash +( +set -e basedir=$(realpath "$1") (git submodule update --init && ./scripts/remap.sh "$basedir" && ./scripts/decompile.sh "$basedir" && ./scripts/init.sh "$basedir" && ./scripts/applyPatches.sh "$basedir") || ( @@ -7,5 +9,6 @@ basedir=$(realpath "$1") exit 1 ) || exit 1 if [ "$2" == "--jar" ]; then - (mvn clean install && ./scripts/paperclip.sh "$basedir") || exit 1 + mvn clean install && ./scripts/paperclip.sh "$basedir" fi +) diff --git a/scripts/decompile.sh b/scripts/decompile.sh index 7acd0a881..2e6cd50d3 100755 --- a/scripts/decompile.sh +++ b/scripts/decompile.sh @@ -1,5 +1,7 @@ #!/usr/bin/env bash +( +set -e PS1="$" basedir=$(realpath "$1") workdir="$basedir/work" @@ -28,3 +30,4 @@ if [ ! -d "$decompiledir/net/minecraft/server" ]; then exit 1 fi fi +) diff --git a/scripts/importmcdev.sh b/scripts/importmcdev.sh index e95d06deb..95cf07547 100755 --- a/scripts/importmcdev.sh +++ b/scripts/importmcdev.sh @@ -1,5 +1,7 @@ #!/usr/bin/env bash +( +set -e nms="net/minecraft/server" export MODLOG="" PS1="$" @@ -59,8 +61,7 @@ import PathfinderGoalFloat import PersistentVillage import TileEntityEnderChest -( - cd "$workdir/Spigot/Spigot-Server/" - git add src -A - echo -e "mc-dev Imports\n\n$MODLOG" | git commit src -F - +cd "$workdir/Spigot/Spigot-Server/" +git add src -A +echo -e "mc-dev Imports\n\n$MODLOG" | git commit src -F - ) diff --git a/scripts/init.sh b/scripts/init.sh index e2f3354c8..cf66b387b 100755 --- a/scripts/init.sh +++ b/scripts/init.sh @@ -1,5 +1,7 @@ #!/usr/bin/env bash +( +set -e PS1="$" basedir=$(realpath "$1") workdir="$basedir/work" @@ -24,12 +26,15 @@ do file="$(echo "$file" | cut -d. -f1).java" echo "Patching $file < $patchFile" + set +e sed -i 's/\r//' "$nms/$file" > /dev/null + set -e cp "$nms/$file" "$cb/$file" "$patch" -s -d src/main/java/ "net/minecraft/server/$file" < "$patchFile" done -git add src >/dev/null 2>&1 || exit 1 -git commit -m "CraftBukkit $ $(date)" >/dev/null 2>&1 || exit 1 -git checkout -f HEAD^ >/dev/null 2>&1 || exit 1 +git add src >/dev/null 2>&1 +git commit -m "CraftBukkit $ $(date)" >/dev/null 2>&1 +git checkout -f HEAD^ >/dev/null 2>&1 +) diff --git a/scripts/makemcdevsrc.sh b/scripts/makemcdevsrc.sh index a689356c4..cbe17f920 100755 --- a/scripts/makemcdevsrc.sh +++ b/scripts/makemcdevsrc.sh @@ -1,5 +1,7 @@ #!/usr/bin/env bash +( +set -e PS1="$" basedir=$(realpath "$1") @@ -23,3 +25,4 @@ do fi done echo "Built $decompiledir/src to be included in your project for src access"; +) diff --git a/scripts/paperclip.sh b/scripts/paperclip.sh index 0e2a4e80b..c8d55bd84 100755 --- a/scripts/paperclip.sh +++ b/scripts/paperclip.sh @@ -1,4 +1,7 @@ #!/usr/bin/env bash + +( +set -e basedir=$(realpath "$1") workdir="$basedir/work" mcver=$(cat "$workdir/BuildData/info.json" | grep minecraftVersion | cut -d '"' -f 4) @@ -7,7 +10,7 @@ vanillajar="../$mcver/$mcver.jar" ( cd "$workdir/Paperclip" - mvn clean package "-Dmcver=$mcver" "-Dpaperjar=$paperjar" "-Dvanillajar=$vanillajar" || exit 1 + mvn clean package "-Dmcver=$mcver" "-Dpaperjar=$paperjar" "-Dvanillajar=$vanillajar" ) cp "$workdir/Paperclip/target/paperclip-${mcver}.jar" "$basedir/paperclip.jar" @@ -16,3 +19,4 @@ echo "" echo "" echo "Build success!" echo "Copied final jar to "$(realpath "$basedir/paperclip.jar") +) diff --git a/scripts/rebuildPatches.sh b/scripts/rebuildPatches.sh index f4848b208..af7ed88f0 100755 --- a/scripts/rebuildPatches.sh +++ b/scripts/rebuildPatches.sh @@ -1,5 +1,7 @@ #!/usr/bin/env bash +( +set -e PS1="$" basedir=$(realpath "$1") workdir="$basedir/work" @@ -15,7 +17,9 @@ function cleanupPatches { testver=$(echo "$diffs" | tail -n 2 | grep -ve "^$" | tail -n 1 | grep "$gitver") if [ "x$testver" != "x" ]; then + set +e diffs=$(echo "$diffs" | sed 'N;$!P;$!D;$d') + set -e fi if [ "x$diffs" == "x" ] ; then @@ -45,3 +49,4 @@ function savePatches { savePatches "$workdir/Spigot/Spigot-API" "Paper-API" savePatches "$workdir/Spigot/Spigot-Server" "Paper-Server" +) diff --git a/scripts/remap.sh b/scripts/remap.sh index 8e6b21ad1..a5200a915 100755 --- a/scripts/remap.sh +++ b/scripts/remap.sh @@ -1,5 +1,7 @@ #!/usr/bin/env bash +( +set -e PS1="$" basedir=$(realpath "$1") workdir="$basedir/work" @@ -68,3 +70,4 @@ if [ "$?" != "0" ]; then echo "Failed to install remapped jar." exit 1 fi +) diff --git a/scripts/upstreamMerge.sh b/scripts/upstreamMerge.sh index 7b3620507..77781b302 100755 --- a/scripts/upstreamMerge.sh +++ b/scripts/upstreamMerge.sh @@ -1,5 +1,7 @@ #!/usr/bin/env bash +( +set -e PS1="$" basedir=$(realpath "$1") workdir="$basedir/work" @@ -14,3 +16,4 @@ function update { update Bukkit update CraftBukkit update Spigot +)