annotate scripts/build_pd_heavy.sh @ 295:e63d35c6ae96 prerelease

Defaulting to gcc compiler (see #1695), updates to build_pd_heavy to make it compile with the new Makefile
author Giulio Moro <giuliomoro@yahoo.it>
date Wed, 25 May 2016 00:18:37 +0100
parents 64e288a3d881
children 9a2a5f14b587
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@203 14 WATCH="0"
giuliomoro@203 15 FORCE="0"
giuliomoro@203 16 #make sure the paths have the trailing / .
giuliomoro@203 17 projectpath="../projects/heavy/hvtemp/"
giuliomoro@295 18 [ -z "$BBB_ADDRESS" ] && BBB_ADDRESS="root@192.168.7.2"
giuliomoro@295 19 [ -z "$BBB_BELA_HOME" ] && BBB_BELA_HOME="~/BeagleRT/"
giuliomoro@295 20 [ -z "$BBB_PROJECT_HOME" ] && BBB_PROJECT_HOME="${BBB_BELA_HOME}/projects/"
giuliomoro@295 21 BBB_DEFAULT_PROJECT_NAME="heavyProject"
giuliomoro@295 22 [ -z "$BBB_PROJECT_NAME" ] && BBB_PROJECT_NAME=$BBB_DEFAULT_PROJECT_NAME
chris@160 23 COMMAND_ARGS=
chris@160 24 RUN_PROJECT=1
chris@160 25 RUN_IN_FOREGROUND=0
chris@160 26 RUN_WITHOUT_SCREEN=1
giuliomoro@203 27 BELA_PYTHON27=
giuliomoro@203 28
giuliomoro@203 29 if [ -z "$BELA_PYTHON27" ]; then
giuliomoro@203 30 for PY in python python2.7 ; do
giuliomoro@203 31 python --version 2>&1 | grep "2\.7" &> /dev/null
giuliomoro@203 32 if [ $? -eq 0 ]; then
giuliomoro@203 33 BELA_PYTHON27=$PY
giuliomoro@203 34 break;
giuliomoro@203 35 fi;
giuliomoro@203 36 done;
giuliomoro@203 37 fi;
giuliomoro@203 38
giuliomoro@203 39 if [ -z "$BELA_PYTHON27" ]; then
giuliomoro@203 40 echo "It looks like you might not have python2.7 installed. If you do, please specify the path
giuliomoro@203 41 to your python2.7 executable in the environmental variable $BELA_PYTHON27"
giuliomoro@203 42 exit 1;
giuliomoro@203 43 fi;
giuliomoro@203 44
chris@160 45
chris@160 46 function usage
chris@160 47 {
giuliomoro@203 48 printf "\nUSAGE: build_pd.sh [[-i input folder containing _main.pd file ]\
giuliomoro@203 49 [-o output folder for new heavy project .c files (default ../projects/heavy/hvtemp)]\
giuliomoro@203 50 [-b bbb path to copy to (default ~/BeagleRT)] | [-h] | [-f|--force] | [-w|--watch]\n"
giuliomoro@203 51 printf "\nexample: build_pd.sh -i ../projects/heavy/pd/hello-world -o ../projects/heavy/hello-world\n"
giuliomoro@203 52 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 53 the building process and runs the process.
giuliomoro@203 54 If --screen is selected, the prompt returns to the user after launching BeagleRT in a screen on the target device.
giuliomoro@203 55 If --screen and --watch are combined, while the process is running in the screen, modifications to the source files will \
giuliomoro@203 56 still trigger a new build."
chris@160 57 }
chris@160 58
chris@160 59 while [ "$1" != "" ]; do
chris@160 60 case $1 in
chris@160 61 -b | --bbb ) shift
giuliomoro@295 62 BBB_BELA_HOME=$1
chris@160 63 ;;
giuliomoro@203 64 -f | --force) FORCE="1"
giuliomoro@203 65 ;;
chris@160 66 -i | --input ) shift
chris@160 67 pdpath=$1
chris@160 68 ;;
chris@160 69 -o | --output ) shift
chris@160 70 projectpath=$1
chris@160 71 ;;
giuliomoro@203 72 -v | --verbose ) verbose=1
chris@160 73 ;;
chris@160 74 -r | --render ) shift
chris@160 75 render=1
chris@160 76 ;;
giuliomoro@203 77 -s | --screen ) RUN_WITHOUT_SCREEN="0"
giuliomoro@203 78 ;;
giuliomoro@203 79 -w | --watch ) WATCH=1
giuliomoro@203 80 ;;
chris@160 81 -h | --help ) usage
chris@160 82 exit
chris@160 83 ;;
chris@160 84 * ) usage
chris@160 85 exit 1
chris@160 86 esac
chris@160 87 shift
chris@160 88 done
chris@160 89
giuliomoro@203 90 function hasNotChanged(){
giuliomoro@203 91 if [ $WATCH -eq 0 ];
giuliomoro@203 92 then
giuliomoro@214 93 echo "Files in the source folder did not change since the last build, use --force to force recompiling";
giuliomoro@203 94 exit 0;
giuliomoro@203 95 fi;
giuliomoro@203 96 }
chris@190 97
giuliomoro@203 98 function checkChanged(){
giuliomoro@203 99 PD_BACKUP_PATH="hvresources/patch_back/"
giuliomoro@203 100 if [ $FORCE -eq 1 ] && [ $WATCH -eq 0 ];
giuliomoro@203 101 then
giuliomoro@203 102 rm -rf $PD_BACKUP_PATH;
giuliomoro@203 103 return;
giuliomoro@203 104 fi;
giuliomoro@203 105 mkdir -p $PD_BACKUP_PATH;
giuliomoro@203 106 # count files that have changed
giuliomoro@203 107 HAS_CHANGED=$(rsync -nac --out-format="%f" "$pdpath" $PD_BACKUP_PATH | grep -v "\/\.$"| wc -l);
giuliomoro@203 108 if [ $HAS_CHANGED -eq 0 ] && [ $FORCE -eq 0 ];
giuliomoro@203 109 then
giuliomoro@203 110 hasNotChanged;
giuliomoro@203 111 return 1;
giuliomoro@203 112 fi;
giuliomoro@203 113 #if we are here and $FORCE==1, it means that $WATCH==1
giuliomoro@203 114 # so let's make sure only the first run get forced:
giuliomoro@203 115 FORCE=0;
giuliomoro@203 116 echo "Files have changed"
giuliomoro@203 117 # otherwise back up the files that have changed
giuliomoro@203 118 rsync -vac "$pdpath" $PD_BACKUP_PATH
giuliomoro@203 119
giuliomoro@203 120 return 0;
giuliomoro@203 121 }
giuliomoro@203 122
giuliomoro@203 123 function checkUploadBuildRun(){
giuliomoro@203 124 checkChanged || return # exits if source files have not changed
giuliomoro@203 125
giuliomoro@203 126 # remove old static files to avoid obsolete errors
giuliomoro@203 127 # use -rf to prevent warnings in case they do not exist
giuliomoro@203 128 rm -rf "$projectpath"/Hv* "$projectpath"/Message* "$projectpath"/Control* "$projectpath"/Signal* &>/dev/null
giuliomoro@203 129
giuliomoro@203 130 # invoke the online compiler
giuliomoro@203 131 "$BELA_PYTHON27" hvresources/uploader.py "$pdpath"/ -n bbb -g c -o "$projectpath";
chris@160 132 if [ $? -ne 0 ]; then
giuliomoro@203 133 #echo "ERROR: an error occurred while executing the uploader.py script"
giuliomoro@203 134 echo "error"
giuliomoro@203 135 exit 1
chris@160 136 fi;
chris@160 137
giuliomoro@203 138 echo "";
giuliomoro@203 139 #echo "*|*|* Successfully uploaded and converted pd patch into super-fast optimized C code. Brought to you by Heavy! *|*|*";
giuliomoro@203 140 echo "";
giuliomoro@203 141
giuliomoro@203 142 # check how to copy/sync render.cpp file...
giuliomoro@203 143 if [ $render -eq 0 ]; then
chris@190 144 cp "hvresources/render.cpp" $projectpath/;
giuliomoro@203 145 fi;
chris@160 146
giuliomoro@203 147 cp "hvresources/HvUtils.h" $projectpath/;
chris@190 148
giuliomoro@203 149 echo "updating files on board..."
chris@190 150
giuliomoro@295 151 BBB_PROJECT_FOLDER=$BBB_PROJECT_HOME"/"$BBB_PROJECT_NAME #make sure there is no trailing slash here
giuliomoro@295 152 BBB_NETWORK_TARGET_FOLDER=$BBB_ADDRESS:$BBB_PROJECT_FOLDER
giuliomoro@295 153 rsync -c -rv --exclude 'HvContext*' "$projectpath"/ "$BBB_NETWORK_TARGET_FOLDER";
giuliomoro@295 154 # rsync -c -rv "$projectpath"/ "$BBB_ADDRESS":"$BBB_BELA_HOME"/source;
chris@190 155
giuliomoro@203 156 # for whatever reason these big files used to hang when transferring with rsync
giuliomoro@295 157 scp "$projectpath"/HvContext* $BBB_NETWORK_TARGET_FOLDER
chris@160 158
giuliomoro@203 159 if [ $? -ne 0 ]; then
chris@160 160 echo "";
chris@160 161 echo ":( :( :( ERROR: while synchronizing files with the BBB. Is the board connected and the correct SD card inserted? :( :( :(";
chris@160 162 echo "";
chris@160 163 exit 1;
giuliomoro@203 164 fi;
giuliomoro@203 165 # exit
giuliomoro@203 166 #produce a list of files which content has changed (not just the date)
giuliomoro@203 167 #TODO: could be made faster (perhaps) by backing up the folder locally instead of bbb
giuliomoro@295 168 # UPDATED_FILES=`rsync -naic --log-format="%f" "$projectpath" "$BBB_BELA_HOME"/source | grep -v "\.$"`
giuliomoro@203 169 # echo "UPDATEDFILES : $UPDATED_FILES"
giuliomoro@203 170 # exit 2
giuliomoro@203 171 # remove old executable and heavy context .o/.d files
giuliomoro@295 172 ssh $BBB_ADDRESS "rm -rf "$BBB_PROJECT_FOLDER/$BBB_PROJECT_NAME;
giuliomoro@203 173 SCREEN_NAME=BeagleRT
giuliomoro@203 174 KILL_RUNNING_PROCESS="bash -c 'kill -s 2 \`pidof BeagleRT\` 2>/dev/null; screen -r $SCREEN_NAME -X quit 2>/dev/null; sleep 0.5; exit 0'" #always returns true
giuliomoro@203 175 # Make new BeagleRT executable and run
giuliomoro@203 176 # It does not look very nice that we type the same things over and over
giuliomoro@203 177 # but that is because each line is an ssh session in its own right
giuliomoro@203 178 if [ $RUN_PROJECT -eq 0 ]
giuliomoro@203 179 then
giuliomoro@203 180 echo "Building project..."
giuliomoro@295 181 ssh $BBB_ADDRESS "make all -C $BBB_BELA_HOME PROJECT=$BBB_PROJECT_NAME"
giuliomoro@203 182 else
giuliomoro@203 183 echo "Building and running project..."
giuliomoro@203 184 if [ $RUN_WITHOUT_SCREEN -eq 1 ]
giuliomoro@203 185 then
giuliomoro@295 186 ssh -t $BBB_ADDRESS "make all -C $BBB_BELA_HOME PROJECT=$BBB_PROJECT_NAME && $KILL_RUNNING_PROCESS && $BBB_PROJECT_FOLDER/$BBB_PROJECT_NAME $COMMAND_ARGS"
giuliomoro@203 187 elif [ $RUN_IN_FOREGROUND -eq 1 ]
giuliomoro@203 188 then
giuliomoro@203 189 # Run in screen without detaching
giuliomoro@295 190 ssh -t $BBB_ADDRESS "make all -C $BBB_BELA_HOME PROJECT=$BBB_PROJECT_NAME&& $KILL_RUNNING_PROCESS && screen -S $SCREEN_NAME $BBB_PROJECT_FOLDER/$BBB_PROJECT_NAME $COMMAND_ARGS"
giuliomoro@203 191 else
giuliomoro@203 192 # Run in screen and detach
giuliomoro@295 193 ssh $BBB_ADDRESS "make all -C $BBB_BELA_HOME PROJECT=$BBB_PROJECT_NAME && $KILL_RUNNING_PROCESS && screen -dmS $SCREEN_NAME $BBB_PROJECT_FOLDER/$BBB_PROJECT_NAME $COMMAND_ARGS"
giuliomoro@295 194
giuliomoro@203 195 fi
giuliomoro@203 196 fi
giuliomoro@203 197 } #checkUploadBuildRun
giuliomoro@203 198
giuliomoro@203 199 checkUploadBuildRun
giuliomoro@203 200
giuliomoro@203 201 if [ $WATCH -ne 0 ]; then
giuliomoro@203 202 WAIT_STRING="\rWaiting for changes in $pdpath"
giuliomoro@203 203 while true; do
giuliomoro@203 204 printf "$WAIT_STRING "
giuliomoro@203 205 sleep 0.3
giuliomoro@203 206 printf "$WAIT_STRING. "
giuliomoro@203 207 sleep 0.3
giuliomoro@203 208 printf "$WAIT_STRING.. "
giuliomoro@203 209 sleep 0.3
giuliomoro@203 210 printf "$WAIT_STRING..."
giuliomoro@203 211 sleep 0.3
giuliomoro@203 212 checkUploadBuildRun
giuliomoro@203 213 done;
chris@160 214 fi;
chris@160 215 #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