annotate scripts/build_pd_heavy.sh @ 451:7f9032f43f41 prerelease

Do a coreclean in update_board
author Liam Donovan <l.b.donovan@qmul.ac.uk>
date Sun, 19 Jun 2016 22:43:06 +0100
parents 86591d203c78
children d9a4fc5357e7
rev   line source
giuliomoro@425 1 #!/bin/sh
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@431 8 trap "{ echo "";exit 0; }" 2
giuliomoro@203 9
chris@160 10 workingdir=".."
chris@160 11 pdpath=""
giuliomoro@398 12 NO_UPLOAD="0"
giuliomoro@203 13 WATCH="0"
giuliomoro@203 14 FORCE="0"
giuliomoro@203 15 #make sure the paths have the trailing / .
giuliomoro@431 16 projectpath="../tmp/heavy/hvtemp/"
giuliomoro@295 17 BBB_DEFAULT_PROJECT_NAME="heavyProject"
chris@160 18 COMMAND_ARGS=
chris@160 19 RUN_PROJECT=1
chris@160 20 RUN_IN_FOREGROUND=0
chris@160 21 RUN_WITHOUT_SCREEN=1
giuliomoro@203 22 BELA_PYTHON27=
giuliomoro@203 23
giuliomoro@447 24 . ./.bela_common || exit 1
giuliomoro@447 25
giuliomoro@203 26 if [ -z "$BELA_PYTHON27" ]; then
giuliomoro@203 27 for PY in python python2.7 ; do
giuliomoro@428 28 python --version 2>&1 | grep "2\.7" >/dev/null 2>&1
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@403 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
giuliomoro@430 43 usage ()
chris@160 44 {
giuliomoro@203 45 printf "\nUSAGE: build_pd.sh [[-i input folder containing _main.pd file ]\
giuliomoro@445 46 [-o output folder for temp heavy project .c files (default $projectpath)]\
giuliomoro@403 47 [-b bbb path to copy to (default ~/Bela)] | [-h] | [-w|--watch] | [-n|--noupload] | [-r|--release arg]\n"
giuliomoro@203 48 printf "\nexample: build_pd.sh -i ../projects/heavy/pd/hello-world -o ../projects/heavy/hello-world\n"
giuliomoro@445 49 echo "If --watch is selected, the script will check every 1s for any file that is modified in the source folder, which re-triggers\
giuliomoro@445 50 the building process.
giuliomoro@403 51 If --screen is selected, the prompt returns to the user after launching Bela 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@403 53 still trigger a new build.
giuliomoro@403 54 -r allows to build against a specific Heavy release. Default is the most recent version.
giuliomoro@403 55 "
chris@160 56 }
chris@160 57
chris@160 58 while [ "$1" != "" ]; do
chris@160 59 case $1 in
giuliomoro@442 60 -b | --belaPath ) shift
giuliomoro@295 61 BBB_BELA_HOME=$1
chris@160 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@403 69 -r | --release ) shift
giuliomoro@403 70 release=$1
giuliomoro@403 71 ;;
giuliomoro@203 72 -s | --screen ) RUN_WITHOUT_SCREEN="0"
giuliomoro@203 73 ;;
giuliomoro@203 74 -w | --watch ) WATCH=1
giuliomoro@203 75 ;;
giuliomoro@442 76 -n | --noupload ) NO_UPLOAD=1
giuliomoro@398 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@442 87 [ -z "$ENZIENAUDIO_COM_PATCH_NAME" ] && ENZIENAUDIO_COM_PATCH_NAME=bbb
giuliomoro@442 88 [ "$NO_UPLOAD" -eq 0 ] && [ -z "$pdpath" ] && { echo "Error: a path to the source folder should be provided"; exit 1; }
giuliomoro@442 89
giuliomoro@439 90 if [ -z "$release" ]
giuliomoro@403 91 then
giuliomoro@403 92 RELEASE_STRING=
giuliomoro@403 93 else
giuliomoro@403 94 RELEASE_STRING="-r $release"
giuliomoro@403 95 fi
chris@190 96
giuliomoro@431 97 #create destination folder if it does not exist"
giuliomoro@431 98 mkdir -p "$projectpath"
giuliomoro@431 99
giuliomoro@442 100 # These files will be cleared from $projectpath before calling uploader.py
giuliomoro@442 101 #TODO: get a reliable, exhaustive, up-to-date list.
giuliomoro@442 102 HEAVY_FILES='Heavy* Hv* Message* Signal*'
giuliomoro@445 103
giuliomoro@445 104 set_date
giuliomoro@445 105 reference_time_file="$projectpath"/
giuliomoro@445 106 trap "kill -9 "'$BACKGROUND_PROCESS_PID'"; exit 0;" 2 9
giuliomoro@430 107 uploadBuildRun(){
giuliomoro@398 108 if [ $NO_UPLOAD -eq 0 ]; then
giuliomoro@398 109 # remove old static files to avoid obsolete errors
giuliomoro@442 110 # make sure the path is not empty, so avoiding to rm -rf / by mistake
giuliomoro@442 111 [ -z $projectpath ] && { echo 'ERROR: $projectpath is empty.'; exit 0; }
giuliomoro@398 112 # use -rf to prevent warnings in case they do not exist
giuliomoro@442 113 for file in $HEAVY_FILES
giuliomoro@442 114 do
giuliomoro@442 115 rm -rf "$projectpath"/$file
giuliomoro@442 116 done
giuliomoro@203 117
giuliomoro@398 118 # invoke the online compiler
giuliomoro@442 119 echo "$BELA_PYTHON27" hvresources/uploader.py "$pdpath"/ -n $ENZIENAUDIO_COM_PATCH_NAME -g c -o "$projectpath" $RELEASE_STRING
giuliomoro@442 120 "$BELA_PYTHON27" hvresources/uploader.py "$pdpath"/ -n $ENZIENAUDIO_COM_PATCH_NAME -g c -o "$projectpath" $RELEASE_STRING ||\
giuliomoro@442 121 { echo "ERROR: an error occurred while executing the uploader.py script"; exit 1; }
chris@160 122 fi;
chris@160 123
giuliomoro@203 124 echo "";
giuliomoro@442 125
giuliomoro@442 126 # Test that files have been retrieved from the online compiler.
giuliomoro@442 127 # TODO: find a more reliable way of doing this. e.g.: have uploader.py fail with a non-zero error code.
giuliomoro@442 128 for file in $HEAVY_FILES;
giuliomoro@442 129 do
giuliomoro@442 130 ls "$projectpath"/$file >/dev/null 2>&1 || { echo "The online compiler failed, please try again."; exit 1; }
giuliomoro@442 131 done
giuliomoro@442 132 # Apply any Bela-specific patches here
giuliomoro@442 133 cp "hvresources/HvUtils.h" $projectpath/;
giuliomoro@203 134
giuliomoro@398 135 BBB_PROJECT_FOLDER=$BBB_PROJECT_HOME"/"$BBB_PROJECT_NAME #make sure there is no trailing slash here
giuliomoro@398 136 BBB_NETWORK_TARGET_FOLDER=$BBB_ADDRESS:$BBB_PROJECT_FOLDER
giuliomoro@398 137
giuliomoro@203 138 # check how to copy/sync render.cpp file...
giuliomoro@442 139 # check if custom heavy_render.cpp file is provided in the input folder
giuliomoro@442 140 # TODO: extend this to all non-Pd files
giuliomoro@442 141 CUSTOM_RENDER_SOURCE_PATH="$pdpath/heavy_render.cpp"
giuliomoro@442 142 if [ -f "$CUSTOM_RENDER_SOURCE_PATH" ]; then
giuliomoro@442 143 echo "Found custom heavy_render.cpp file in input folder, using that one instead of the default one.";
giuliomoro@445 144 cp "$CUSTOM_RENDER_SOURCE_PATH" "$projectpath/render.cpp"
giuliomoro@398 145 else
giuliomoro@442 146 echo "Using default heavy_render.cpp"
giuliomoro@445 147 cp "hvresources/heavy_render.cpp" "$projectpath/render.cpp"
giuliomoro@442 148 fi
giuliomoro@442 149
giuliomoro@442 150 echo "Updating files on board..."
giuliomoro@442 151 # HvContext* files tend to hang when transferring with rsync because they are very large and -c checksum takes a lot, I guess
giuliomoro@445 152
giuliomoro@445 153 touch $reference_time_file
giuliomoro@445 154 # Transfer the files
giuliomoro@442 155 rsync -ac --out-format=" %n" --no-t --delete-after --exclude='HvContext*' --exclude=build --exclude=$BBB_PROJECT_NAME "$projectpath"/ "$BBB_NETWORK_TARGET_FOLDER" &&\
giuliomoro@445 156 { [ $NO_UPLOAD -eq 1 ] || scp "$projectpath"/HvContext* $BBB_NETWORK_TARGET_FOLDER; } ||\
giuliomoro@442 157 { echo "ERROR: while synchronizing files with the BBB. Is the board connected?"; exit 1; }
chris@160 158
giuliomoro@445 159 # TODO: rsync should upload a list of modified files, so that the corresponding objects can be deleted
giuliomoro@442 160 # TODO: this should be run only when Heavy_bbb.h changes. Otherwise render is recompiled every time for no good reason
giuliomoro@445 161 #ssh $BBB_ADDRESS "rm -rf ${BBB_PROJECT_FOLDER}/build/render.*"
chris@190 162
giuliomoro@203 163 #produce a list of files which content has changed (not just the date)
giuliomoro@203 164 #TODO: could be made faster (perhaps) by backing up the folder locally instead of bbb
giuliomoro@295 165 # UPDATED_FILES=`rsync -naic --log-format="%f" "$projectpath" "$BBB_BELA_HOME"/source | grep -v "\.$"`
giuliomoro@203 166 # echo "UPDATEDFILES : $UPDATED_FILES"
giuliomoro@203 167 # exit 2
giuliomoro@445 168 # remove old executable
giuliomoro@445 169 #if [ $NO_UPLOAD -eq 0 ]; then
giuliomoro@445 170 # ssh $BBB_ADDRESS "rm -rf "$BBB_PROJECT_FOLDER/$BBB_PROJECT_NAME;
giuliomoro@445 171 #fi;
giuliomoro@442 172 # Make new Bela executable and run
giuliomoro@203 173 # It does not look very nice that we type the same things over and over
giuliomoro@203 174 # but that is because each line is an ssh session in its own right
giuliomoro@329 175 MAKE_COMMAND="make stop -C $BBB_BELA_HOME PROJECT='$BBB_PROJECT_NAME' CL='$COMMAND_ARGS'"
giuliomoro@203 176 if [ $RUN_PROJECT -eq 0 ]
giuliomoro@203 177 then
giuliomoro@203 178 echo "Building project..."
giuliomoro@329 179 ssh $BBB_ADDRESS "$MAKE_COMMAND"
giuliomoro@203 180 else
giuliomoro@203 181 echo "Building and running project..."
giuliomoro@445 182 echo "WATCH: $WATCH"
giuliomoro@445 183 if [ $WATCH -eq 1 ]
giuliomoro@445 184 then
giuliomoro@445 185 # try to emulate run_without_screen: run with fifo
giuliomoro@445 186 [ $RUN_WITHOUT_SCREEN -eq 1 ] && { ssh $BBB_ADDRESS "$MAKE_COMMAND runscreenfifo"& BACKGROUND_PROCESS_PID=$!; } ||\
giuliomoro@445 187 { ssh $BBB_ADDRESS "$MAKE_COMMAND runscreen"; }
giuliomoro@445 188 elif [ $RUN_WITHOUT_SCREEN -eq 1 ]
giuliomoro@203 189 then
giuliomoro@329 190 ssh -t $BBB_ADDRESS "$MAKE_COMMAND run"
giuliomoro@203 191 elif [ $RUN_IN_FOREGROUND -eq 1 ]
giuliomoro@203 192 then
giuliomoro@203 193 # Run in screen without detaching
giuliomoro@329 194 ssh -t $BBB_ADDRESS "$MAKE_COMMAND runscreenfg"
giuliomoro@445 195 else
giuliomoro@203 196 # Run in screen and detach
giuliomoro@445 197 ssh $BBB_ADDRESS "$MAKE_COMMAND runscreen"
giuliomoro@203 198 fi
giuliomoro@203 199 fi
giuliomoro@403 200 } #uploadBuildRun
giuliomoro@203 201
giuliomoro@403 202 uploadBuildRun
giuliomoro@203 203
giuliomoro@203 204 if [ $WATCH -ne 0 ]; then
giuliomoro@445 205 BACK_NO_UPLOAD=$NO_UPLOAD
giuliomoro@445 206 while true
giuliomoro@445 207 do
giuliomoro@445 208 echo "Waiting for changes in $pdpath, or press ctrl-c to terminate"
giuliomoro@445 209 wait_for_change "$pdpath" "$reference_time_file"
giuliomoro@445 210 echo "Files changed"
giuliomoro@445 211 # if .pd files did not change, no point in re-uploading
giuliomoro@445 212 folder_has_changed "$pdpath" "$reference_time_file" "\.pd" &&\
giuliomoro@445 213 NO_UPLOAD=$BACK_NO_UPLOAD || NO_UPLOAD=1
giuliomoro@445 214 uploadBuildRun
giuliomoro@445 215 done
chris@160 216 fi;
chris@160 217 #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