Mercurial > hg > beaglert
diff scripts/build_project.sh @ 274:cf98c06c72fd prerelease
merge
author | Liam Donovan <l.b.donovan@qmul.ac.uk> |
---|---|
date | Tue, 17 May 2016 16:42:02 +0100 |
parents | 156191dffa8c |
children | 428f13c2cb49 |
line wrap: on
line diff
--- a/scripts/build_project.sh Tue May 17 16:31:51 2016 +0100 +++ b/scripts/build_project.sh Tue May 17 16:42:02 2016 +0100 @@ -4,12 +4,16 @@ # optionally runs it. Pass a directory path in the first argument. # The source files in this directory are copied to the board and compiled. -BBB_ADDRESS="root@192.168.7.2" -BBB_PATH="~/BeagleRT" -RUN_PROJECT=1 -COMMAND_ARGS= -RUN_IN_FOREGROUND=0 -RUN_WITHOUT_SCREEN=0 +# set defaults unless variables are already set +[ -z "$BBB_ADDRESS" ] && BBB_ADDRESS="root@192.168.7.2" +[ -z "$BBB_BELA_HOME" ] && BBB_BELA_HOME="~/BeagleRT/" +[ -z "$BBB_SCREEN_NAME" ] && BBB_SCREEN_NAME="BeagleRT" +[ -z "$RUN_PROJECT" ] && RUN_PROJECT=1 +[ -z "$COMMAND_ARGS" ] && COMMAND_ARGS= +[ -z "$RUN_IN_FOREGROUND" ] && RUN_IN_FOREGROUND=1 +[ -z "$RUN_WITHOUT_SCREEN" ] && RUN_WITHOUT_SCREEN=0 +[ -z "$BBB_PROJECT_HOME" ] && BBB_PROJECT_HOME="${BBB_BELA_HOME}/projects/" +[ -z "$BBB_PROJECT_NAME" ] && BBB_PROJECT_NAME="scriptUploadedProject" function usage { @@ -26,23 +30,24 @@ BeagleRT files are found. The -c option passes command-line arguments to the BeagleRT program; enclose the argument string in quotes. - The -f argument runs the project in the foreground of the current terminal, + 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 project in the foreground of the current terminal, without screen, so + the output can be piped to another destination. The -f argument runs it + in a screen in the background, so no output is shown." } OPTIND=1 while getopts "b:c:nfFh" opt; do case $opt in - b) BBB_PATH=$OPTARG + b) BBB_BELA_HOME=$OPTARG ;; c) COMMAND_ARGS=$OPTARG ;; - f) RUN_IN_FOREGROUND=1 + f) RUN_IN_FOREGROUND=0 ;; - F) RUN_WITHOUT_SCREEN=1 + F) RUN_WITHOUT_SCREEN=1 ;; n) RUN_PROJECT=0 ;; @@ -76,27 +81,35 @@ exit fi +BBB_PROJECT_FOLDER=$BBB_PROJECT_HOME"/"$BBB_PROJECT_NAME"/" +BBB_NETWORK_TARGET_FOLDER=$BBB_ADDRESS:$BBB_PROJECT_FOLDER + # Stop BeagleRT and clean out old source files -echo "Stopping BeagleRT and removing old source files..." -ssh -t -t $BBB_ADDRESS "screen -X -S BeagleRT quit &>/dev/null; pkill BeagleRT ; make sourceclean -C $BBB_PATH" +echo "Stopping running program..." +# sets the date, stops the running process +ssh $BBB_ADDRESS "date -s '`date`' > /dev/null; mkdir -p $BBB_PROJECT_FOLDER; screen -X -S '"$BBB_SCREEN_NAME"' quit &>/dev/null;" #concatenate arguments to form path. -BBB_SOURCE_PATH= #initially empty, will be filled with input arguments +HOST_SOURCE_PATH= #initially empty, will be filled with input arguments for i in "$@" #parse input arguments do - if [ -d "$1" ] #check if the path is a folder - then #if it is, include all of its files - BBB_SOURCE_PATH+=" ${1}/* " - else - BBB_SOURCE_PATH+=" $1 " - fi + HOST_SOURCE_PATH+=" $1 " shift # Copy new souce files to the board done # Copy new source files to the board echo "Copying new source files to BeagleBone..." -scp $BBB_SOURCE_PATH "$BBB_ADDRESS:$BBB_PATH/source/" +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 -C $BBB_BELA_HOME sourceclean PROJECT=$BBB_PROJECT_NAME"; + scp $HOST_SOURCE_PATH "$BBB_NETWORK_TARGET_FOLDER" +else + #rsync --delete makes sure it removes files that are not in the origin folder + rsync -av --delete-after --exclude=build $HOST_SOURCE_PATH "$BBB_NETWORK_TARGET_FOLDER" +fi; if [ $? -ne 0 ] then @@ -108,17 +121,17 @@ if [ $RUN_PROJECT -eq 0 ] then echo "Building project..." - ssh $BBB_ADDRESS "make all -C $BBB_PATH" + ssh $BBB_ADDRESS "make all -C $BBB_BELA_HOME PROJECT=$BBB_PROJECT_NAME" else echo "Building and running project..." if [ $RUN_WITHOUT_SCREEN -ne 0 ] then - ssh -t $BBB_ADDRESS "cd $BBB_PATH && make all && cd source && ../BeagleRT $COMMAND_ARGS" + ssh -t $BBB_ADDRESS "cd $BBB_BELA_HOME && make all && cd source && $BBB_PROJECT_FOLDER/$BBB_PROJECT_NAME $COMMAND_ARGS" elif [ $RUN_IN_FOREGROUND -eq 0 ] then - ssh $BBB_ADDRESS "cd $BBB_PATH && make all && cd source && screen -S BeagleRT -d -m ../BeagleRT $COMMAND_ARGS" + ssh $BBB_ADDRESS "cd $BBB_BELA_HOME && make all PROJECT=$BBB_PROJECT_NAME && cd source && screen -S $BBB_SCREEN_NAME -d -m $BBB_PROJECT_FOLDER/$BBB_PROJECT_NAME $COMMAND_ARGS" else - ssh -t $BBB_ADDRESS "cd $BBB_PATH && make all && cd source && screen -S BeagleRT ../BeagleRT $COMMAND_ARGS" + ssh -t $BBB_ADDRESS "cd $BBB_BELA_HOME && make all PROJECT=$BBB_PROJECT_NAME && cd source && screen -S $BBB_SCREEN_NAME $BBB_PROJECT_FOLDER/$BBB_PROJECT_NAME $COMMAND_ARGS" fi fi