Mercurial > hg > beaglert
diff scripts/build_pd_heavy.sh @ 442:6462d0cc8906 prerelease
build_pd_heavy.sh: major refactoring. Safer, nicer, cleaner
author | Giulio Moro <giuliomoro@yahoo.it> |
---|---|
date | Sun, 19 Jun 2016 00:35:41 +0100 |
parents | e49ae69acbe8 |
children | 2b09be3fb0f2 |
line wrap: on
line diff
--- a/scripts/build_pd_heavy.sh Sun Jun 19 00:30:48 2016 +0100 +++ b/scripts/build_pd_heavy.sh Sun Jun 19 00:35:41 2016 +0100 @@ -9,7 +9,6 @@ workingdir=".." verbose="0" -render="0" pdpath="" NO_UPLOAD="0" WATCH="0" @@ -47,7 +46,7 @@ usage () { printf "\nUSAGE: build_pd.sh [[-i input folder containing _main.pd file ]\ - [-o output folder for new heavy project .c files (default ../projects/heavy/hvtemp)]\ + [-o output folder for new 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\ @@ -61,7 +60,7 @@ while [ "$1" != "" ]; do case $1 in - -b | --bbb ) shift + -b | --belaPath ) shift BBB_BELA_HOME=$1 ;; -i | --input ) shift @@ -75,14 +74,11 @@ ;; -v | --verbose ) verbose=1 ;; - -r | --render ) shift - render=1 - ;; -s | --screen ) RUN_WITHOUT_SCREEN="0" ;; -w | --watch ) WATCH=1 ;; - -n | --noupload ) NO_UPLOAD=1 + -n | --noupload ) NO_UPLOAD=1 ;; -h | --help ) usage exit @@ -93,6 +89,9 @@ shift done +[ -z "$ENZIENAUDIO_COM_PATCH_NAME" ] && ENZIENAUDIO_COM_PATCH_NAME=bbb +[ "$NO_UPLOAD" -eq 0 ] && [ -z "$pdpath" ] && { echo "Error: a path to the source folder should be provided"; exit 1; } + if [ -z "$release" ] then RELEASE_STRING= @@ -103,56 +102,61 @@ #create destination folder if it does not exist" mkdir -p "$projectpath" +# 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*' uploadBuildRun(){ if [ $NO_UPLOAD -eq 0 ]; then # remove old static files to avoid obsolete errors + # make sure the path is not empty, so avoiding to rm -rf / by mistake + [ -z $projectpath ] && { echo 'ERROR: $projectpath is empty.'; exit 0; } # use -rf to prevent warnings in case they do not exist - rm -rf "$projectpath"/Hv* "$projectpath"/Message* "$projectpath"/Control* "$projectpath"/Signal* >/dev/null 2>&1 + for file in $HEAVY_FILES + do + rm -rf "$projectpath"/$file + done # invoke the online compiler - "$BELA_PYTHON27" hvresources/uploader.py "$pdpath"/ -n bbb -g c -o "$projectpath" $RELEASE_STRING; - if [ $? -ne 0 ]; then - #echo "ERROR: an error occurred while executing the uploader.py script" - echo "error" - exit 1 - fi; + echo "$BELA_PYTHON27" hvresources/uploader.py "$pdpath"/ -n $ENZIENAUDIO_COM_PATCH_NAME -g c -o "$projectpath" $RELEASE_STRING + "$BELA_PYTHON27" hvresources/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; echo ""; - #echo "*|*|* Successfully uploaded and converted pd patch into super-fast optimized C code. Brought to you by Heavy! *|*|*"; - echo ""; + + # Test that files have been retrieved from the online compiler. + # 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 || { echo "The online compiler failed, please try again."; exit 1; } + done + # Apply any Bela-specific patches here + cp "hvresources/HvUtils.h" $projectpath/; BBB_PROJECT_FOLDER=$BBB_PROJECT_HOME"/"$BBB_PROJECT_NAME #make sure there is no trailing slash here BBB_NETWORK_TARGET_FOLDER=$BBB_ADDRESS:$BBB_PROJECT_FOLDER # check how to copy/sync render.cpp file... - # don't replace render.cpp file if custom one provided in output folder - if [ -f $projectpath"/render.cpp" ]; then - echo "Found custom render.cpp file in output folder"; - ssh -t $BBB_ADDRESS "rm ${BBB_PROJECT_FOLDER}/build/render.*" + # check if custom heavy_render.cpp file is provided in the input folder + # TODO: extend this to all non-Pd files + 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/" else - if [ $render -eq 0 ]; then - cp "hvresources/render.cpp" $projectpath/; - fi; - fi; + echo "Using default heavy_render.cpp" + cp "hvresources/heavy_render.cpp" $projectpath/ + 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 + 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; } ||\ + { echo "ERROR: while synchronizing files with the BBB. Is the board connected?"; exit 1; } - cp "hvresources/HvUtils.h" $projectpath/; + # 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.*" - echo "updating files on board..." - - rsync -c -rv --exclude 'HvContext*' "$projectpath"/ "$BBB_NETWORK_TARGET_FOLDER"; - if [ $NO_UPLOAD -eq 0 ]; then - # for whatever reason these big files used to hang when transferring with rsync - scp "$projectpath"/HvContext* $BBB_NETWORK_TARGET_FOLDER - fi; - - if [ $? -ne 0 ]; then - echo ""; - echo ":( :( :( ERROR: while synchronizing files with the BBB. Is the board connected and the correct SD card inserted? :( :( :("; - echo ""; - exit 1; - fi; - # exit #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 "\.$"` @@ -162,7 +166,7 @@ if [ $NO_UPLOAD -eq 0 ]; then ssh $BBB_ADDRESS "rm -rf "$BBB_PROJECT_FOLDER/$BBB_PROJECT_NAME; fi; - # Make new Bela execut/able and run + # 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 MAKE_COMMAND="make stop -C $BBB_BELA_HOME PROJECT='$BBB_PROJECT_NAME' CL='$COMMAND_ARGS'"