diff scripts/build_pd_heavy.sh @ 523:42f6af3a5f1d prerelease

build_project and build_pd_heavy mostly done
author Giulio Moro <giuliomoro@yahoo.it>
date Thu, 23 Jun 2016 04:31:09 +0100
parents 633ade85e798
children 1ca196e35105
line wrap: on
line diff
--- a/scripts/build_pd_heavy.sh	Thu Jun 23 03:46:56 2016 +0100
+++ b/scripts/build_pd_heavy.sh	Thu Jun 23 04:31:09 2016 +0100
@@ -1,22 +1,12 @@
 #!/bin/sh
+# This script uploads Pd patches to Enzienaudio's server and compiles them on Bela
 
-# shell script for automatic uploading/compiling of pd patch onto bbb
-# Christian Heinrichs 2015
-#
-
-trap "{ echo "";exit 0; }" 2 
-
-workingdir=".."
 pdpath=""
 NO_UPLOAD="0"
 WATCH="0"
 FORCE="0"
 #make sure the paths have the trailing / . 
 BBB_DEFAULT_PROJECT_NAME="heavyProject"
-COMMAND_ARGS=
-RUN_PROJECT=1
-RUN_IN_FOREGROUND=0
-RUN_WITHOUT_SCREEN=1
 BELA_PYTHON27=
 
 SCRIPTDIR=$(dirname "$0")
@@ -45,50 +35,83 @@
 
 usage ()
 {
-printf "\nUSAGE: build_pd.sh [[-i input folder containing _main.pd file ]\
- [-o output folder for temp heavy project .c files (default $projectpath)]\
- [-b remote path to copy to (default ~/Bela)] | [-h] | [-w|--watch] | [-n|--noupload] | [-r|--release arg]\n"
-printf "\nexample: build_pd.sh -i ../projects/heavy/pd/hello-world -o ../projects/heavy/hello-world\n"
-echo "If --watch is selected, the script will check every 1s for any file that is modified in the source folder, which re-triggers\
-the building process.
-If --screen is selected, the prompt returns to the user after launching Bela in a screen on the target device.
-If --screen and --watch are combined, while the process is running in the screen, modifications to the source files will \
-still trigger a new build.
+echo "
+USAGE: build_pd.sh [[-i input folder containing _main.pd file ]
+ [-o output folder for temp heavy project .c files (default $projectpath)]
+ [-b remote path to copy to (default ~/Bela)] | [-h] | [-w|--watch] | [-n|--noupload] | [-r|--release arg]
+
+example: build_pd.sh -o ../projects/heavy/hello-world ../projects/heavy/pd/hello-world
+
 -r allows to build against a specific Heavy release. Default is the most recent version.
 "
+	build_script_usage
 }
 
-while [ "$1" != "" ]; do
+
+COMMAND_ARGS=
+RUN_PROJECT=1
+RUN_MODE=foreground
+
+[ $# -lt 2 ]  && {
+	[ -d $1 ] || { usage; exit; }
+}
+while [ "$2" != "" ]; do
     case $1 in
-        -b | --belaPath )       shift
-                                BBB_BELA_HOME=$1
-                                ;;
-        -i | --input )          shift
-                                pdpath=$1
-                                ;;
-        -o | --output )         shift
-                                projectpath=$1
-                                ;;
-        -r | --release )        shift
-                                release=$1
-                                ;;
-        -s | --screen )         RUN_WITHOUT_SCREEN="0"
-                                ;;
-        -w | --watch )          WATCH=1
-                                ;;
-        -n | --noupload )       NO_UPLOAD=1
-                                ;;
-        -h | --help )           usage
-                                exit
-                                ;;
-        * )                     usage
-                                exit 1
+		-c)
+			shift
+			COMMAND_ARGS="$1"
+		;;
+		-b)
+			RUN_MODE=screen
+		;;
+		-f)
+			RUN_MODE=foreground
+		;;
+		-s)
+			RUN_MODE=screenfg
+		;;
+		-n)
+			RUN_PROJECT=0
+		;;
+		-p)
+			shift
+			BBB_PROJECT_NAME="$1"
+		;;	
+		--clean)
+			BBB_MAKEFILE_OPTIONS="$BBB_MAKEFILE_OPTIONS clean"
+		;;
+		-m)
+			shift
+			BBB_MAKEFILE_OPTIONS="BBB_MAKEFILE_OPTIONS $1"
+		;;
+		--watch)
+			WATCH=1
+		;;
+        -o | --output )
+			shift
+			projectpath=$1
+        ;;
+        -r | --release )
+			shift
+			release=$1
+		;;
+        -n | --noupload )
+			NO_UPLOAD=1
+		;;
+        -h | --help | -\?)
+			usage
+			exit
+		;;
+        *)
+			usage
+			exit 1
     esac
     shift
 done
+pdpath=$1
 
+[ "$NO_UPLOAD" -eq 0 ] && [ -z "$pdpath" ] && { echo "Error: a path to the source folder should be provided"; exit 1; }
 [ -z "$ENZIENAUDIO_COM_PATCH_NAME" ] && ENZIENAUDIO_COM_PATCH_NAME=bela
-[ "$NO_UPLOAD" -eq 0 ] && [ -z "$pdpath" ] && { echo "Error: a path to the source folder should be provided"; exit 1; }
 
 if [ -z "$release" ]
 then 
@@ -97,7 +120,7 @@
   RELEASE_STRING="-r $release"
 fi
 
-#create destination folder if it does not exist"
+#truncated the destination folder if it does not exist"
 mkdir -p "$projectpath"
 
 # These files will be cleared from $projectpath before calling uploader.py
@@ -117,8 +140,8 @@
 	do 
 	    rm -rf "$projectpath"/$file
 	done
-
         # invoke the online compiler
+		echo "$BELA_PYTHON27" $HVRESOURCES_DIR/uploader.py "$pdpath"/ -n $ENZIENAUDIO_COM_PATCH_NAME -g c -o "$projectpath" $RELEASE_STRING
         "$BELA_PYTHON27" $HVRESOURCES_DIR/uploader.py "$pdpath"/ -n $ENZIENAUDIO_COM_PATCH_NAME -g c -o "$projectpath" $RELEASE_STRING ||\
             { echo "ERROR: an error occurred while executing the uploader.py script"; exit 1; }
     fi;
@@ -129,7 +152,10 @@
     # TODO: find a more reliable way of doing this. e.g.: have uploader.py fail with a non-zero error code.
     for file in $HEAVY_FILES;
     do
-        ls "$projectpath"/$file >/dev/null 2>&1 || { printf "The online compiler did not return all the files or failed without notice, please try again and/or change HEAVY_FILES to be less strict.\n\n"; exit 1; }
+        ls "$projectpath"/$file >/dev/null 2>&1 || { 
+			[ $NO_UPLOAD -eq 0 ] && printf "The online compiler did not return all the files or failed without notice, please try again and/or change HEAVY_FILES to be less strict.\n\n" ||\
+			printf "Folder $projectpath does not contain a valid Heavy project\n";
+			exit 1; }
     done
 
     # Apply any Bela-specific patches here 
@@ -177,32 +203,22 @@
         echo "Building project..."
         ssh $BBB_ADDRESS "$MAKE_COMMAND"
     else
-        echo "Building and running project..."
-        if [ $WATCH -eq 1 ]
-	       then
-	         # try to emulate run_without_screen: run with fifo
-              if [ $RUN_WITHOUT_SCREEN -eq 1 ];
-              then 
-	         	  ssh $BBB_ADDRESS "$MAKE_COMMAND runscreenfifo" & BACKGROUND_PROCESS_PID=$!
-	           # run this in the background, it will be killed anyhow when the process stops.
-	           # Either with the trap below or in another way
-                       trap "kill $BACKGROUND_PROCESS_PID; exit 0;" 2 9 
-	          # add the line below to the trap if you want to kill the process on the board when you exit the script
-	          # ssh -o ConnectTimeout 2 $BBB_ADDRESS make --no-print-directory -C $BBB_BELA_HOME stop ;
-	           else
-                ssh $BBB_ADDRESS "$MAKE_COMMAND runscreen"
-	           fi
-          elif [ $RUN_WITHOUT_SCREEN -eq 1 ]
-          then
-              ssh -t $BBB_ADDRESS "$MAKE_COMMAND run" 
-          elif [ $RUN_IN_FOREGROUND -eq 1 ]
-          then
-              # Run in screen without detaching
-              ssh -t $BBB_ADDRESS "$MAKE_COMMAND runscreenfg"
-          else 
-              # Run in screen and detach
-              ssh $BBB_ADDRESS "$MAKE_COMMAND runscreen"
-          fi
+	  case $RUN_MODE in
+		# Sorry for repeating the options, but "ssh / ssh -t" makes things complicated
+		foreground)
+			ssh -t $BBB_ADDRESS "$MAKE_COMMAND run"
+		;;
+		screen)
+			ssh $BBB_ADDRESS "$MAKE_COMMAND runscreen"
+		;;
+		screenfg)
+			ssh -t $BBB_ADDRESS "$MAKE_COMMAND runscreenfg"
+		;;
+		*)
+			echo $RUN_MODE
+			error
+		;;
+      esac
     fi
 } #uploadBuildRun