annotate scripts/build_pd.sh @ 214:1721296e3e71

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