Mercurial > hg > beaglert
diff scripts/build_pd_heavy.sh @ 445:2b09be3fb0f2 prerelease
Re-implemented watch for build_heavy ... added .bela_common file for shared config and utilities
author | Giulio Moro <giuliomoro@yahoo.it> |
---|---|
date | Sun, 19 Jun 2016 03:28:53 +0100 |
parents | 6462d0cc8906 |
children | 86591d203c78 |
line wrap: on
line diff
--- a/scripts/build_pd_heavy.sh Sun Jun 19 01:18:45 2016 +0100 +++ b/scripts/build_pd_heavy.sh Sun Jun 19 03:28:53 2016 +0100 @@ -8,24 +8,20 @@ trap "{ echo "";exit 0; }" 2 workingdir=".." -verbose="0" pdpath="" NO_UPLOAD="0" WATCH="0" FORCE="0" #make sure the paths have the trailing / . projectpath="../tmp/heavy/hvtemp/" -[ -z "$BBB_ADDRESS" ] && BBB_ADDRESS="root@192.168.7.2" -[ -z "$BBB_BELA_HOME" ] && BBB_BELA_HOME="~/Bela/" -[ -z "$BBB_PROJECT_HOME" ] && BBB_PROJECT_HOME="${BBB_BELA_HOME}/projects/" BBB_DEFAULT_PROJECT_NAME="heavyProject" -[ -z "$BBB_PROJECT_NAME" ] && BBB_PROJECT_NAME=$BBB_DEFAULT_PROJECT_NAME COMMAND_ARGS= RUN_PROJECT=1 RUN_IN_FOREGROUND=0 RUN_WITHOUT_SCREEN=1 BELA_PYTHON27= +source .bela_common || exit 1 if [ -z "$BELA_PYTHON27" ]; then for PY in python python2.7 ; do python --version 2>&1 | grep "2\.7" >/dev/null 2>&1 @@ -46,11 +42,11 @@ usage () { printf "\nUSAGE: build_pd.sh [[-i input folder containing _main.pd file ]\ - [-o output folder for new heavy project .c files (default $projectpath)]\ + [-o output folder for temp heavy project .c files (default $projectpath)]\ [-b bbb 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 triggers\ -the building process and runs the process. +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. @@ -72,8 +68,6 @@ -r | --release ) shift release=$1 ;; - -v | --verbose ) verbose=1 - ;; -s | --screen ) RUN_WITHOUT_SCREEN="0" ;; -w | --watch ) WATCH=1 @@ -105,6 +99,10 @@ # These files will be cleared from $projectpath before calling uploader.py #TODO: get a reliable, exhaustive, up-to-date list. HEAVY_FILES='Heavy* Hv* Message* Signal*' + +set_date +reference_time_file="$projectpath"/ +trap "kill -9 "'$BACKGROUND_PROCESS_PID'"; exit 0;" 2 9 uploadBuildRun(){ if [ $NO_UPLOAD -eq 0 ]; then # remove old static files to avoid obsolete errors @@ -142,30 +140,34 @@ CUSTOM_RENDER_SOURCE_PATH="$pdpath/heavy_render.cpp" if [ -f "$CUSTOM_RENDER_SOURCE_PATH" ]; then echo "Found custom heavy_render.cpp file in input folder, using that one instead of the default one."; - cp "$CUSTOM_RENDER_SOURCE_PATH" "$projectpath/" + cp "$CUSTOM_RENDER_SOURCE_PATH" "$projectpath/render.cpp" else echo "Using default heavy_render.cpp" - cp "hvresources/heavy_render.cpp" $projectpath/ + cp "hvresources/heavy_render.cpp" "$projectpath/render.cpp" fi echo "Updating files on board..." # HvContext* files tend to hang when transferring with rsync because they are very large and -c checksum takes a lot, I guess + + touch $reference_time_file + # Transfer the files rsync -ac --out-format=" %n" --no-t --delete-after --exclude='HvContext*' --exclude=build --exclude=$BBB_PROJECT_NAME "$projectpath"/ "$BBB_NETWORK_TARGET_FOLDER" &&\ - { [ $NO_UPLOAD -eq 0 ] && scp "$projectpath"/HvContext* $BBB_NETWORK_TARGET_FOLDER; } ||\ + { [ $NO_UPLOAD -eq 1 ] || scp "$projectpath"/HvContext* $BBB_NETWORK_TARGET_FOLDER; } ||\ { echo "ERROR: while synchronizing files with the BBB. Is the board connected?"; exit 1; } + # TODO: rsync should upload a list of modified files, so that the corresponding objects can be deleted # TODO: this should be run only when Heavy_bbb.h changes. Otherwise render is recompiled every time for no good reason - ssh $BBB_ADDRESS "rm -rf ${BBB_PROJECT_FOLDER}/build/render.*" + #ssh $BBB_ADDRESS "rm -rf ${BBB_PROJECT_FOLDER}/build/render.*" #produce a list of files which content has changed (not just the date) #TODO: could be made faster (perhaps) by backing up the folder locally instead of bbb # UPDATED_FILES=`rsync -naic --log-format="%f" "$projectpath" "$BBB_BELA_HOME"/source | grep -v "\.$"` # echo "UPDATEDFILES : $UPDATED_FILES" # exit 2 - # remove old executable and heavy context .o/.d files - if [ $NO_UPLOAD -eq 0 ]; then - ssh $BBB_ADDRESS "rm -rf "$BBB_PROJECT_FOLDER/$BBB_PROJECT_NAME; - fi; + # remove old executable + #if [ $NO_UPLOAD -eq 0 ]; then + # ssh $BBB_ADDRESS "rm -rf "$BBB_PROJECT_FOLDER/$BBB_PROJECT_NAME; + #fi; # Make new Bela executable and run # It does not look very nice that we type the same things over and over # but that is because each line is an ssh session in its own right @@ -176,16 +178,22 @@ ssh $BBB_ADDRESS "$MAKE_COMMAND" else echo "Building and running project..." - if [ $RUN_WITHOUT_SCREEN -eq 1 ] + echo "WATCH: $WATCH" + if [ $WATCH -eq 1 ] + then + # try to emulate run_without_screen: run with fifo + [ $RUN_WITHOUT_SCREEN -eq 1 ] && { ssh $BBB_ADDRESS "$MAKE_COMMAND runscreenfifo"& BACKGROUND_PROCESS_PID=$!; } ||\ + { ssh $BBB_ADDRESS "$MAKE_COMMAND runscreen"; } + 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 + else # Run in screen and detach - ssh -t $BBB_ADDRESS "$MAKE_COMMAND runscreen" + ssh $BBB_ADDRESS "$MAKE_COMMAND runscreen" fi fi } #uploadBuildRun @@ -193,17 +201,16 @@ uploadBuildRun if [ $WATCH -ne 0 ]; then - WAIT_STRING="\rWaiting for changes in $pdpath" - while true; do - printf "$WAIT_STRING " - sleep 0.3 - printf "$WAIT_STRING. " - sleep 0.3 - printf "$WAIT_STRING.. " - sleep 0.3 - printf "$WAIT_STRING..." - sleep 0.3 - uploadBuildRun - done; + BACK_NO_UPLOAD=$NO_UPLOAD + while true + do + echo "Waiting for changes in $pdpath, or press ctrl-c to terminate" + wait_for_change "$pdpath" "$reference_time_file" + echo "Files changed" + # if .pd files did not change, no point in re-uploading + folder_has_changed "$pdpath" "$reference_time_file" "\.pd" &&\ + NO_UPLOAD=$BACK_NO_UPLOAD || NO_UPLOAD=1 + uploadBuildRun + done fi; #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