changeset 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 a084456960c9
children 9f455f01edd5
files scripts/.bela_common scripts/build_pd_heavy.sh scripts/build_project.sh
diffstat 3 files changed, 160 insertions(+), 131 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/.bela_common	Thu Jun 23 03:46:56 2016 +0100
+++ b/scripts/.bela_common	Thu Jun 23 04:31:09 2016 +0100
@@ -15,7 +15,8 @@
 folder_has_changed(){
 	[ -z "$2" ] && { echo "Error: folder_has_changed(folder, reference, [filter])"; return 1; }
 	[ -z "$3" ] && FILTER="." || FILTER="$3"
-	find "$1" -type f -newer "$2" | grep "$FILTER"
+	# Do not watch hidden files or folders 
+	find "$1" -type f -not -path '*/\.*' -newer "$2" | grep "$FILTER"
 	return $?
 }
 
@@ -40,3 +41,33 @@
 		exit 1;
 	}
 }
+
+build_script_usage(){
+	echo "	The program can be run in one of the following modes:
+		-f arg : runs in the foreground (default).
+		-b arg : runs in the background (no output is shown)
+
+	When running in the foreground you can stop the currently running program 
+	with ctrl-C.
+	When running in the background, you can use \`./stop_running.sh' to stop
+	the current process and \`./connect_to_project.sh' to see the program's output.
+
+	Other options:
+	--clean : cleans the pre-compiled object files on the board (same as \`-m coreclean').
+	          If the linker issues warnings during a build, or you see that your latest changes are not
+	          being applied to the running program, try to add the --clean flag for the next build and see 
+	          if that fixes it. 
+	
+	--watch: the script will wait for changes in the source folder and when it detects them it
+	         triggers a new build. If you do not run the program with -b, then you will have to
+			 either kill the process or detach from the screen in order for the watchdog to be active.
+	-n : the output will not be run after compiling.
+	-c \"args\" : passes command-line arguments to the Bela program; e
+	              close the argument string in quotes.
+	-p arg : sets the name of the project to in the remote folder (default: $BBB_PROJECT_NAME ) 
+	         do not use spaces in your project names, please
+	-m \"args\" allows to pass arguments to the Makefile before the run target. For instance,
+	           pass -m \`"projectclean"\` or \`-m "distclean"\` to clean project-specific
+	           pre-built objects, or all the pre-built objects, respectively.
+	"
+}
--- 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
 
--- a/scripts/build_project.sh	Thu Jun 23 03:46:56 2016 +0100
+++ b/scripts/build_project.sh	Thu Jun 23 04:31:09 2016 +0100
@@ -3,7 +3,6 @@
 # This script compiles a Bela project on the BeagleBone Black and
 # optionally runs it. Pass a directory path in the first argument. 
 # The source files in this directory are copied to the board and compiled.
-
 # set defaults unless variables are already set
 
 SCRIPTDIR=$(dirname "$0")
@@ -18,28 +17,20 @@
 	echo "
 	This script copies a directory of source files to the BeagleBone, compiles
 	and runs it. The Bela core files should have first been copied over
-	using the setup_board.sh script supplied with Bela.
+	using the \`update_board' script once.
+	The source directory should contain at least one .c, .cpp, .S or .pd file.
 
-	The source directory should contain at least one .c, .cpp or .S file.
-	If the argument -n is passed, the output will not be run after compiling.
-	The -c option passes command-line arguments to
-	the Bela program; enclose the argument string in quotes.
+"
+	build_script_usage
+}
+# UNDOCUMENTED OPTION -s runs in a screen in the foreground 
 
-	-p arg : sets the name of the project to run (default: $BBB_PROJECT_NAME ) 
-	-r arg : additional folder which contents will be copied to the destination folder. Use this, e.g.: for audio files or Pd/pyo sources
+RUN_MODE=foreground
 
-	By default, the project runs in the foreground of the current terminal,
-	within a screen session that can be detached later. The -f argument runs
-	the project in the foreground of the current terminal, without screen, so
-	the output can be piped to another destination. The -b argument runs it
-	in a screen in the background, so no output is shown. The -m argument allows
-	to pass arguments to the Makefile before the run target. For instance,
-	pass -m \`"projectclean"\` or \`-m "distclean"\` to clean project-specific
-	pre-built objects, or all the pre-built objects, respectively."
+# We are "whiling" $2 because the last command is going to be the path/to/project
+[ $# -lt 2 ]  && {
+	[ -d $1 ] || { usage; exit; }
 }
-
-OPTIND=1
-
 while [ "$2" != "" ]; do
 	case $1 in
 		-c)
@@ -47,10 +38,13 @@
 			COMMAND_ARGS="$1"
 		;;
 		-b)
-			RUN_IN_FOREGROUND=0
+			RUN_MODE=screen
 		;;
 		-f)
-			RUN_WITHOUT_SCREEN=1
+			RUN_MODE=foreground
+		;;
+		-s)
+			RUN_MODE=screenfg
 		;;
 		-n)
 			RUN_PROJECT=0
@@ -59,14 +53,12 @@
 			shift
 			BBB_PROJECT_NAME="$1"
 		;;	
-		-r)
-			shift
-			# TODO: this option can probably be removed, replaced by including multiple paths as regular positional arguments at the end.
-			ADDITIONAL_PATH="$1"
+		--clean)
+			BBB_MAKEFILE_OPTIONS="$BBB_MAKEFILE_OPTIONS clean"
 		;;
 		-m)
 			shift
-			BBB_MAKEFILE_OPTIONS="$1"
+			BBB_MAKEFILE_OPTIONS="$BBB_MAKEFILE_OPTIONS $1"
 		;;
 		--watch)
 			WATCH=1
@@ -84,9 +76,6 @@
 done
 
 
-#Only include all the files if the provided path is not empty
-[ -z "$ADDITIONAL_PATH" ] || ADDITIONAL_PATH="$ADDITIONAL_PATH/*"
-
 # Check that we have a directory containing at least one source file
 # as an argument
 
@@ -102,7 +91,7 @@
 if [ -z "$FOUND_FILES" ]
 then
 	 printf "ERROR: Please provide a directory containing .c, .cpp, .S or .pd files.\n\n"
-	 exit
+	 exit 1
 fi
 
 BBB_PROJECT_FOLDER=$BBB_PROJECT_HOME"/"$BBB_PROJECT_NAME #make sure there is no trailing slash here
@@ -131,16 +120,16 @@
 	if [ -z "`which rsync`" ];
 	then
 		#if rsync is not available, brutally clean the destination folder
-		#and copy over all the files again and recompile them
 		ssh bbb "make --no-print-directory -C $BBB_BELA_HOME sourceclean PROJECT=$BBB_PROJECT_NAME";
-		scp -r $HOST_SOURCE_PATH $ADDITIONAL_PATH "$BBB_NETWORK_TARGET_FOLDER"
+		#and copy over all the files again
+		scp -r $HOST_SOURCE_PATH "$BBB_NETWORK_TARGET_FOLDER"
 	else
 		#rsync 
 		# --delete makes sure it removes files that are not in the origin folder
 		# -c evaluates changes using md5 checksum instead of file date, so we don't care about time skews 
 		# --no-t makes sure file timestamps are not preserved, so that the Makefile will not think that targets are up to date when replacing files on the BBB
 		#  with older files from the host. This will solve 99% of the issues with Makefile thinking a target is up to date when it is not.
-		rsync -ac --out-format="   %n" --no-t --delete-after --exclude=$BBB_PROJECT_NAME --exclude=build $HOST_SOURCE_PATH"/" $ADDITIONAL_PATH "$BBB_NETWORK_TARGET_FOLDER/" #trailing slashes used here make sure rsync does not create another folder inside the target folder
+		rsync -ac --out-format="   %n" --no-t --delete-after --exclude=$BBB_PROJECT_NAME --exclude=build $HOST_SOURCE_PATH"/" "$BBB_NETWORK_TARGET_FOLDER/" #trailing slashes used here make sure rsync does not create another folder inside the target folder
 	fi
 
 	if [ $? -ne 0 ]
@@ -157,29 +146,22 @@
 		ssh $BBB_ADDRESS "$MAKE_COMMAND"
 	else
       echo "Building and running project..."
-	    if [ $WATCH -eq 1 ]
-		then
-          if [ $RUN_WITHOUT_SCREEN -eq 1 ];
-          then 
-              # try to emulate run_without_screen: run with fifo
-             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 
-           else
-             ssh $BBB_ADDRESS "$MAKE_COMMAND runscreen"
-           fi
-		else
-		  if [ $RUN_WITHOUT_SCREEN -ne 0 ]
-		  then
-		  	ssh -t $BBB_ADDRESS "$MAKE_COMMAND run"	
-		  elif [ $RUN_IN_FOREGROUND -eq 0 ]
-		  then
-		  	ssh $BBB_ADDRESS "$MAKE_COMMAND runscreen"
-		  else
-		  	ssh -t $BBB_ADDRESS "$MAKE_COMMAND runscreenfg"
-		  fi
-		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
 }
 # run it once and then (maybe) start waiting for changes