giuliomoro@425: #!/bin/sh chris@160: chris@160: # shell script for automatic uploading/compiling of pd patch onto bbb chris@160: # Christian Heinrichs 2015 chris@160: # chris@160: # example usage: sh upload-and-compile.sh -f bwg-tests -q -e chris@160: giuliomoro@203: trap "{ echo "";exit 0; }" SIGINT SIGTERM giuliomoro@203: chris@160: workingdir=".." chris@160: verbose="0" chris@160: render="0" chris@160: pdpath="" giuliomoro@398: NO_UPLOAD="0" giuliomoro@203: WATCH="0" giuliomoro@203: FORCE="0" giuliomoro@203: #make sure the paths have the trailing / . giuliomoro@203: projectpath="../projects/heavy/hvtemp/" giuliomoro@295: [ -z "$BBB_ADDRESS" ] && BBB_ADDRESS="root@192.168.7.2" giuliomoro@403: [ -z "$BBB_BELA_HOME" ] && BBB_BELA_HOME="~/Bela/" giuliomoro@295: [ -z "$BBB_PROJECT_HOME" ] && BBB_PROJECT_HOME="${BBB_BELA_HOME}/projects/" giuliomoro@295: BBB_DEFAULT_PROJECT_NAME="heavyProject" giuliomoro@295: [ -z "$BBB_PROJECT_NAME" ] && BBB_PROJECT_NAME=$BBB_DEFAULT_PROJECT_NAME chris@160: COMMAND_ARGS= chris@160: RUN_PROJECT=1 chris@160: RUN_IN_FOREGROUND=0 chris@160: RUN_WITHOUT_SCREEN=1 giuliomoro@203: BELA_PYTHON27= giuliomoro@203: giuliomoro@203: if [ -z "$BELA_PYTHON27" ]; then giuliomoro@203: for PY in python python2.7 ; do giuliomoro@203: python --version 2>&1 | grep "2\.7" &> /dev/null giuliomoro@203: if [ $? -eq 0 ]; then giuliomoro@203: BELA_PYTHON27=$PY giuliomoro@203: break; giuliomoro@203: fi; giuliomoro@203: done; giuliomoro@203: fi; giuliomoro@203: giuliomoro@203: if [ -z "$BELA_PYTHON27" ]; then giuliomoro@203: echo "It looks like you might not have python2.7 installed. If you do, please specify the path giuliomoro@403: to your python2.7 executable in the environmental variable \$BELA_PYTHON27" giuliomoro@203: exit 1; giuliomoro@203: fi; giuliomoro@203: chris@160: chris@160: function usage chris@160: { giuliomoro@203: printf "\nUSAGE: build_pd.sh [[-i input folder containing _main.pd file ]\ giuliomoro@203: [-o output folder for new heavy project .c files (default ../projects/heavy/hvtemp)]\ giuliomoro@403: [-b bbb path to copy to (default ~/Bela)] | [-h] | [-w|--watch] | [-n|--noupload] | [-r|--release arg]\n" giuliomoro@203: printf "\nexample: build_pd.sh -i ../projects/heavy/pd/hello-world -o ../projects/heavy/hello-world\n" giuliomoro@203: echo "If --watch is selected, the script will check every 1s for any file that is modified in the source folder, which triggers\ giuliomoro@203: the building process and runs the process. giuliomoro@403: If --screen is selected, the prompt returns to the user after launching Bela in a screen on the target device. giuliomoro@203: If --screen and --watch are combined, while the process is running in the screen, modifications to the source files will \ giuliomoro@403: still trigger a new build. giuliomoro@403: -r allows to build against a specific Heavy release. Default is the most recent version. giuliomoro@403: " chris@160: } chris@160: chris@160: while [ "$1" != "" ]; do chris@160: case $1 in chris@160: -b | --bbb ) shift giuliomoro@295: BBB_BELA_HOME=$1 chris@160: ;; chris@160: -i | --input ) shift chris@160: pdpath=$1 chris@160: ;; chris@160: -o | --output ) shift chris@160: projectpath=$1 chris@160: ;; giuliomoro@403: -r | --release ) shift giuliomoro@403: release=$1 giuliomoro@403: ;; giuliomoro@203: -v | --verbose ) verbose=1 chris@160: ;; chris@160: -r | --render ) shift chris@160: render=1 chris@160: ;; giuliomoro@203: -s | --screen ) RUN_WITHOUT_SCREEN="0" giuliomoro@203: ;; giuliomoro@203: -w | --watch ) WATCH=1 giuliomoro@203: ;; giuliomoro@398: -n | --noupload ) NO_UPLOAD=1 giuliomoro@398: ;; chris@160: -h | --help ) usage chris@160: exit chris@160: ;; chris@160: * ) usage chris@160: exit 1 chris@160: esac chris@160: shift chris@160: done chris@160: giuliomoro@403: if [ -z $release ] giuliomoro@403: then giuliomoro@403: RELEASE_STRING= giuliomoro@403: else giuliomoro@403: RELEASE_STRING="-r $release" giuliomoro@403: fi chris@190: giuliomoro@403: function uploadBuildRun(){ giuliomoro@398: if [ $NO_UPLOAD -eq 0 ]; then giuliomoro@398: # remove old static files to avoid obsolete errors giuliomoro@398: # use -rf to prevent warnings in case they do not exist giuliomoro@398: rm -rf "$projectpath"/Hv* "$projectpath"/Message* "$projectpath"/Control* "$projectpath"/Signal* &>/dev/null giuliomoro@203: giuliomoro@398: # invoke the online compiler giuliomoro@403: "$BELA_PYTHON27" hvresources/uploader.py "$pdpath"/ -n bbb -g c -o "$projectpath" $RELEASE_STRING; giuliomoro@398: if [ $? -ne 0 ]; then giuliomoro@398: #echo "ERROR: an error occurred while executing the uploader.py script" giuliomoro@398: echo "error" giuliomoro@398: exit 1 giuliomoro@398: fi; chris@160: fi; chris@160: giuliomoro@203: echo ""; giuliomoro@203: #echo "*|*|* Successfully uploaded and converted pd patch into super-fast optimized C code. Brought to you by Heavy! *|*|*"; giuliomoro@203: echo ""; giuliomoro@203: giuliomoro@398: BBB_PROJECT_FOLDER=$BBB_PROJECT_HOME"/"$BBB_PROJECT_NAME #make sure there is no trailing slash here giuliomoro@398: BBB_NETWORK_TARGET_FOLDER=$BBB_ADDRESS:$BBB_PROJECT_FOLDER giuliomoro@398: giuliomoro@203: # check how to copy/sync render.cpp file... giuliomoro@398: # don't replace render.cpp file if custom one provided in output folder giuliomoro@398: if [ -f $projectpath"/render.cpp" ]; then giuliomoro@398: echo "Found custom render.cpp file in output folder"; giuliomoro@398: ssh -t $BBB_ADDRESS "rm ${BBB_PROJECT_FOLDER}/build/render.*" giuliomoro@398: else giuliomoro@398: if [ $render -eq 0 ]; then giuliomoro@398: cp "hvresources/render.cpp" $projectpath/; giuliomoro@398: fi; giuliomoro@203: fi; chris@160: giuliomoro@203: cp "hvresources/HvUtils.h" $projectpath/; chris@190: giuliomoro@203: echo "updating files on board..." chris@190: giuliomoro@398: rsync -c -rv --exclude 'HvContext*' "$projectpath"/ "$BBB_NETWORK_TARGET_FOLDER"; giuliomoro@398: if [ $NO_UPLOAD -eq 0 ]; then giuliomoro@398: # for whatever reason these big files used to hang when transferring with rsync giuliomoro@398: scp "$projectpath"/HvContext* $BBB_NETWORK_TARGET_FOLDER giuliomoro@398: fi; chris@160: giuliomoro@203: if [ $? -ne 0 ]; then chris@160: echo ""; chris@160: echo ":( :( :( ERROR: while synchronizing files with the BBB. Is the board connected and the correct SD card inserted? :( :( :("; chris@160: echo ""; chris@160: exit 1; giuliomoro@203: fi; giuliomoro@203: # exit giuliomoro@203: #produce a list of files which content has changed (not just the date) giuliomoro@203: #TODO: could be made faster (perhaps) by backing up the folder locally instead of bbb giuliomoro@295: # UPDATED_FILES=`rsync -naic --log-format="%f" "$projectpath" "$BBB_BELA_HOME"/source | grep -v "\.$"` giuliomoro@203: # echo "UPDATEDFILES : $UPDATED_FILES" giuliomoro@203: # exit 2 giuliomoro@398: # remove old executable and heavy context .o/.d files giuliomoro@398: if [ $NO_UPLOAD -eq 0 ]; then giuliomoro@398: ssh $BBB_ADDRESS "rm -rf "$BBB_PROJECT_FOLDER/$BBB_PROJECT_NAME; giuliomoro@398: fi; giuliomoro@403: SCREEN_NAME=Bela giuliomoro@403: # Make new Bela execut/able and run giuliomoro@203: # It does not look very nice that we type the same things over and over giuliomoro@203: # but that is because each line is an ssh session in its own right giuliomoro@329: MAKE_COMMAND="make stop -C $BBB_BELA_HOME PROJECT='$BBB_PROJECT_NAME' CL='$COMMAND_ARGS'" giuliomoro@203: if [ $RUN_PROJECT -eq 0 ] giuliomoro@203: then giuliomoro@203: echo "Building project..." giuliomoro@329: ssh $BBB_ADDRESS "$MAKE_COMMAND" giuliomoro@203: else giuliomoro@203: echo "Building and running project..." giuliomoro@203: if [ $RUN_WITHOUT_SCREEN -eq 1 ] giuliomoro@203: then giuliomoro@329: ssh -t $BBB_ADDRESS "$MAKE_COMMAND run" giuliomoro@203: elif [ $RUN_IN_FOREGROUND -eq 1 ] giuliomoro@203: then giuliomoro@203: # Run in screen without detaching giuliomoro@329: ssh -t $BBB_ADDRESS "$MAKE_COMMAND runscreenfg" giuliomoro@203: else giuliomoro@203: # Run in screen and detach giuliomoro@329: ssh -t $BBB_ADDRESS "$MAKE_COMMAND runscreen" giuliomoro@203: fi giuliomoro@203: fi giuliomoro@403: } #uploadBuildRun giuliomoro@203: giuliomoro@403: uploadBuildRun giuliomoro@203: giuliomoro@203: if [ $WATCH -ne 0 ]; then giuliomoro@203: WAIT_STRING="\rWaiting for changes in $pdpath" giuliomoro@203: while true; do giuliomoro@203: printf "$WAIT_STRING " giuliomoro@203: sleep 0.3 giuliomoro@203: printf "$WAIT_STRING. " giuliomoro@203: sleep 0.3 giuliomoro@203: printf "$WAIT_STRING.. " giuliomoro@203: sleep 0.3 giuliomoro@203: printf "$WAIT_STRING..." giuliomoro@203: sleep 0.3 giuliomoro@403: uploadBuildRun giuliomoro@203: done; chris@160: fi; chris@160: #ssh -t root@192.168.7.2 "kill -s 2 \`pidof heavy_template\` 2>/dev/null; sleep 0.5; rm -f ~/$filename_bbb/Release/source/heavy/HvContext_bbb.? ~/$filename_bbb/Release/heavy_template && make all -C ~/$filename_bbb/Release" &>/dev/null