annotate scripts/build_pd_heavy.sh @ 403:83e1acf38d35 prerelease

Updated build_pd_heavy to support the release flag
author Giulio Moro <giuliomoro@yahoo.it>
date Wed, 15 Jun 2016 02:37:34 +0100
parents 8a7c35ee8b3f
children 99de323c13b3
rev   line source
chris@160 1 #!/bin/bash
chris@160 2
chris@160 3 # shell script for automatic uploading/compiling of pd patch onto bbb
chris@160 4 # Christian Heinrichs 2015
chris@160 5 #
chris@160 6 # example usage: sh upload-and-compile.sh -f bwg-tests -q -e
chris@160 7
giuliomoro@203 8 trap "{ echo "";exit 0; }" SIGINT SIGTERM
giuliomoro@203 9
chris@160 10 workingdir=".."
chris@160 11 verbose="0"
chris@160 12 render="0"
chris@160 13 pdpath=""
giuliomoro@398 14 NO_UPLOAD="0"
giuliomoro@203 15 WATCH="0"
giuliomoro@203 16 FORCE="0"
giuliomoro@203 17 #make sure the paths have the trailing / .
giuliomoro@203 18 projectpath="../projects/heavy/hvtemp/"
giuliomoro@295 19 [ -z "$BBB_ADDRESS" ] && BBB_ADDRESS="root@192.168.7.2"
giuliomoro@403 20 [ -z "$BBB_BELA_HOME" ] && BBB_BELA_HOME="~/Bela/"
giuliomoro@295 21 [ -z "$BBB_PROJECT_HOME" ] && BBB_PROJECT_HOME="${BBB_BELA_HOME}/projects/"
giuliomoro@295 22 BBB_DEFAULT_PROJECT_NAME="heavyProject"
giuliomoro@295 23 [ -z "$BBB_PROJECT_NAME" ] && BBB_PROJECT_NAME=$BBB_DEFAULT_PROJECT_NAME
chris@160 24 COMMAND_ARGS=
chris@160 25 RUN_PROJECT=1
chris@160 26 RUN_IN_FOREGROUND=0
chris@160 27 RUN_WITHOUT_SCREEN=1
giuliomoro@203 28 BELA_PYTHON27=
giuliomoro@203 29
giuliomoro@203 30 if [ -z "$BELA_PYTHON27" ]; then
giuliomoro@203 31 for PY in python python2.7 ; do
giuliomoro@203 32 python --version 2>&1 | grep "2\.7" &> /dev/null
giuliomoro@203 33 if [ $? -eq 0 ]; then
giuliomoro@203 34 BELA_PYTHON27=$PY
giuliomoro@203 35 break;
giuliomoro@203 36 fi;
giuliomoro@203 37 done;
giuliomoro@203 38 fi;
giuliomoro@203 39
giuliomoro@203 40 if [ -z "$BELA_PYTHON27" ]; then
giuliomoro@203 41 echo "It looks like you might not have python2.7 installed. If you do, please specify the path
giuliomoro@403 42 to your python2.7 executable in the environmental variable \$BELA_PYTHON27"
giuliomoro@203 43 exit 1;
giuliomoro@203 44 fi;
giuliomoro@203 45
chris@160 46
chris@160 47 function usage
chris@160 48 {
giuliomoro@203 49 printf "\nUSAGE: build_pd.sh [[-i input folder containing _main.pd file ]\
giuliomoro@203 50 [-o output folder for new heavy project .c files (default ../projects/heavy/hvtemp)]\
giuliomoro@403 51 [-b bbb path to copy to (default ~/Bela)] | [-h] | [-w|--watch] | [-n|--noupload] | [-r|--release arg]\n"
giuliomoro@203 52 printf "\nexample: build_pd.sh -i ../projects/heavy/pd/hello-world -o ../projects/heavy/hello-world\n"
giuliomoro@203 53 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 54 the building process and runs the process.
giuliomoro@403 55 If --screen is selected, the prompt returns to the user after launching Bela in a screen on the target device.
giuliomoro@203 56 If --screen and --watch are combined, while the process is running in the screen, modifications to the source files will \
giuliomoro@403 57 still trigger a new build.
giuliomoro@403 58 -r allows to build against a specific Heavy release. Default is the most recent version.
giuliomoro@403 59 "
chris@160 60 }
chris@160 61
chris@160 62 while [ "$1" != "" ]; do
chris@160 63 case $1 in
chris@160 64 -b | --bbb ) shift
giuliomoro@295 65 BBB_BELA_HOME=$1
chris@160 66 ;;
chris@160 67 -i | --input ) shift
chris@160 68 pdpath=$1
chris@160 69 ;;
chris@160 70 -o | --output ) shift
chris@160 71 projectpath=$1
chris@160 72 ;;
giuliomoro@403 73 -r | --release ) shift
giuliomoro@403 74 release=$1
giuliomoro@403 75 ;;
giuliomoro@203 76 -v | --verbose ) verbose=1
chris@160 77 ;;
chris@160 78 -r | --render ) shift
chris@160 79 render=1
chris@160 80 ;;
giuliomoro@203 81 -s | --screen ) RUN_WITHOUT_SCREEN="0"
giuliomoro@203 82 ;;
giuliomoro@203 83 -w | --watch ) WATCH=1
giuliomoro@203 84 ;;
giuliomoro@398 85 -n | --noupload ) NO_UPLOAD=1
giuliomoro@398 86 ;;
chris@160 87 -h | --help ) usage
chris@160 88 exit
chris@160 89 ;;
chris@160 90 * ) usage
chris@160 91 exit 1
chris@160 92 esac
chris@160 93 shift
chris@160 94 done
chris@160 95
giuliomoro@403 96 if [ -z $release ]
giuliomoro@403 97 then
giuliomoro@403 98 RELEASE_STRING=
giuliomoro@403 99 else
giuliomoro@403 100 RELEASE_STRING="-r $release"
giuliomoro@403 101 fi
chris@190 102
giuliomoro@403 103 function uploadBuildRun(){
giuliomoro@398 104 if [ $NO_UPLOAD -eq 0 ]; then
giuliomoro@398 105 # remove old static files to avoid obsolete errors
giuliomoro@398 106 # use -rf to prevent warnings in case they do not exist
giuliomoro@398 107 rm -rf "$projectpath"/Hv* "$projectpath"/Message* "$projectpath"/Control* "$projectpath"/Signal* &>/dev/null
giuliomoro@203 108
giuliomoro@398 109 # invoke the online compiler
giuliomoro@403 110 "$BELA_PYTHON27" hvresources/uploader.py "$pdpath"/ -n bbb -g c -o "$projectpath" $RELEASE_STRING;
giuliomoro@398 111 if [ $? -ne 0 ]; then
giuliomoro@398 112 #echo "ERROR: an error occurred while executing the uploader.py script"
giuliomoro@398 113 echo "error"
giuliomoro@398 114 exit 1
giuliomoro@398 115 fi;
chris@160 116 fi;
chris@160 117
giuliomoro@203 118 echo "";
giuliomoro@203 119 #echo "*|*|* Successfully uploaded and converted pd patch into super-fast optimized C code. Brought to you by Heavy! *|*|*";
giuliomoro@203 120 echo "";
giuliomoro@203 121
giuliomoro@398 122 BBB_PROJECT_FOLDER=$BBB_PROJECT_HOME"/"$BBB_PROJECT_NAME #make sure there is no trailing slash here
giuliomoro@398 123 BBB_NETWORK_TARGET_FOLDER=$BBB_ADDRESS:$BBB_PROJECT_FOLDER
giuliomoro@398 124
giuliomoro@203 125 # check how to copy/sync render.cpp file...
giuliomoro@398 126 # don't replace render.cpp file if custom one provided in output folder
giuliomoro@398 127 if [ -f $projectpath"/render.cpp" ]; then
giuliomoro@398 128 echo "Found custom render.cpp file in output folder";
giuliomoro@398 129 ssh -t $BBB_ADDRESS "rm ${BBB_PROJECT_FOLDER}/build/render.*"
giuliomoro@398 130 else
giuliomoro@398 131 if [ $render -eq 0 ]; then
giuliomoro@398 132 cp "hvresources/render.cpp" $projectpath/;
giuliomoro@398 133 fi;
giuliomoro@203 134 fi;
chris@160 135
giuliomoro@203 136 cp "hvresources/HvUtils.h" $projectpath/;
chris@190 137
giuliomoro@203 138 echo "updating files on board..."
chris@190 139
giuliomoro@398 140 rsync -c -rv --exclude 'HvContext*' "$projectpath"/ "$BBB_NETWORK_TARGET_FOLDER";
giuliomoro@398 141 if [ $NO_UPLOAD -eq 0 ]; then
giuliomoro@398 142 # for whatever reason these big files used to hang when transferring with rsync
giuliomoro@398 143 scp "$projectpath"/HvContext* $BBB_NETWORK_TARGET_FOLDER
giuliomoro@398 144 fi;
chris@160 145
giuliomoro@203 146 if [ $? -ne 0 ]; then
chris@160 147 echo "";
chris@160 148 echo ":( :( :( ERROR: while synchronizing files with the BBB. Is the board connected and the correct SD card inserted? :( :( :(";
chris@160 149 echo "";
chris@160 150 exit 1;
giuliomoro@203 151 fi;
giuliomoro@203 152 # exit
giuliomoro@203 153 #produce a list of files which content has changed (not just the date)
giuliomoro@203 154 #TODO: could be made faster (perhaps) by backing up the folder locally instead of bbb
giuliomoro@295 155 # UPDATED_FILES=`rsync -naic --log-format="%f" "$projectpath" "$BBB_BELA_HOME"/source | grep -v "\.$"`
giuliomoro@203 156 # echo "UPDATEDFILES : $UPDATED_FILES"
giuliomoro@203 157 # exit 2
giuliomoro@398 158 # remove old executable and heavy context .o/.d files
giuliomoro@398 159 if [ $NO_UPLOAD -eq 0 ]; then
giuliomoro@398 160 ssh $BBB_ADDRESS "rm -rf "$BBB_PROJECT_FOLDER/$BBB_PROJECT_NAME;
giuliomoro@398 161 fi;
giuliomoro@403 162 SCREEN_NAME=Bela
giuliomoro@403 163 # Make new Bela execut/able and run
giuliomoro@203 164 # It does not look very nice that we type the same things over and over
giuliomoro@203 165 # but that is because each line is an ssh session in its own right
giuliomoro@329 166 MAKE_COMMAND="make stop -C $BBB_BELA_HOME PROJECT='$BBB_PROJECT_NAME' CL='$COMMAND_ARGS'"
giuliomoro@203 167 if [ $RUN_PROJECT -eq 0 ]
giuliomoro@203 168 then
giuliomoro@203 169 echo "Building project..."
giuliomoro@329 170 ssh $BBB_ADDRESS "$MAKE_COMMAND"
giuliomoro@203 171 else
giuliomoro@203 172 echo "Building and running project..."
giuliomoro@203 173 if [ $RUN_WITHOUT_SCREEN -eq 1 ]
giuliomoro@203 174 then
giuliomoro@329 175 ssh -t $BBB_ADDRESS "$MAKE_COMMAND run"
giuliomoro@203 176 elif [ $RUN_IN_FOREGROUND -eq 1 ]
giuliomoro@203 177 then
giuliomoro@203 178 # Run in screen without detaching
giuliomoro@329 179 ssh -t $BBB_ADDRESS "$MAKE_COMMAND runscreenfg"
giuliomoro@203 180 else
giuliomoro@203 181 # Run in screen and detach
giuliomoro@329 182 ssh -t $BBB_ADDRESS "$MAKE_COMMAND runscreen"
giuliomoro@203 183 fi
giuliomoro@203 184 fi
giuliomoro@403 185 } #uploadBuildRun
giuliomoro@203 186
giuliomoro@403 187 uploadBuildRun
giuliomoro@203 188
giuliomoro@203 189 if [ $WATCH -ne 0 ]; then
giuliomoro@203 190 WAIT_STRING="\rWaiting for changes in $pdpath"
giuliomoro@203 191 while true; do
giuliomoro@203 192 printf "$WAIT_STRING "
giuliomoro@203 193 sleep 0.3
giuliomoro@203 194 printf "$WAIT_STRING. "
giuliomoro@203 195 sleep 0.3
giuliomoro@203 196 printf "$WAIT_STRING.. "
giuliomoro@203 197 sleep 0.3
giuliomoro@203 198 printf "$WAIT_STRING..."
giuliomoro@203 199 sleep 0.3
giuliomoro@403 200 uploadBuildRun
giuliomoro@203 201 done;
chris@160 202 fi;
chris@160 203 #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