comparison scripts/build_pd_heavy.sh @ 445:2b09be3fb0f2 prerelease

Re-implemented watch for build_heavy ... added .bela_common file for shared config and utilities
author Giulio Moro <giuliomoro@yahoo.it>
date Sun, 19 Jun 2016 03:28:53 +0100
parents 6462d0cc8906
children 86591d203c78
comparison
equal deleted inserted replaced
444:cdf77b9e66bf 445:2b09be3fb0f2
6 # example usage: sh upload-and-compile.sh -f bwg-tests -q -e 6 # example usage: sh upload-and-compile.sh -f bwg-tests -q -e
7 7
8 trap "{ echo "";exit 0; }" 2 8 trap "{ echo "";exit 0; }" 2
9 9
10 workingdir=".." 10 workingdir=".."
11 verbose="0"
12 pdpath="" 11 pdpath=""
13 NO_UPLOAD="0" 12 NO_UPLOAD="0"
14 WATCH="0" 13 WATCH="0"
15 FORCE="0" 14 FORCE="0"
16 #make sure the paths have the trailing / . 15 #make sure the paths have the trailing / .
17 projectpath="../tmp/heavy/hvtemp/" 16 projectpath="../tmp/heavy/hvtemp/"
18 [ -z "$BBB_ADDRESS" ] && BBB_ADDRESS="root@192.168.7.2"
19 [ -z "$BBB_BELA_HOME" ] && BBB_BELA_HOME="~/Bela/"
20 [ -z "$BBB_PROJECT_HOME" ] && BBB_PROJECT_HOME="${BBB_BELA_HOME}/projects/"
21 BBB_DEFAULT_PROJECT_NAME="heavyProject" 17 BBB_DEFAULT_PROJECT_NAME="heavyProject"
22 [ -z "$BBB_PROJECT_NAME" ] && BBB_PROJECT_NAME=$BBB_DEFAULT_PROJECT_NAME
23 COMMAND_ARGS= 18 COMMAND_ARGS=
24 RUN_PROJECT=1 19 RUN_PROJECT=1
25 RUN_IN_FOREGROUND=0 20 RUN_IN_FOREGROUND=0
26 RUN_WITHOUT_SCREEN=1 21 RUN_WITHOUT_SCREEN=1
27 BELA_PYTHON27= 22 BELA_PYTHON27=
28 23
24 source .bela_common || exit 1
29 if [ -z "$BELA_PYTHON27" ]; then 25 if [ -z "$BELA_PYTHON27" ]; then
30 for PY in python python2.7 ; do 26 for PY in python python2.7 ; do
31 python --version 2>&1 | grep "2\.7" >/dev/null 2>&1 27 python --version 2>&1 | grep "2\.7" >/dev/null 2>&1
32 if [ $? -eq 0 ]; then 28 if [ $? -eq 0 ]; then
33 BELA_PYTHON27=$PY 29 BELA_PYTHON27=$PY
44 40
45 41
46 usage () 42 usage ()
47 { 43 {
48 printf "\nUSAGE: build_pd.sh [[-i input folder containing _main.pd file ]\ 44 printf "\nUSAGE: build_pd.sh [[-i input folder containing _main.pd file ]\
49 [-o output folder for new heavy project .c files (default $projectpath)]\ 45 [-o output folder for temp heavy project .c files (default $projectpath)]\
50 [-b bbb path to copy to (default ~/Bela)] | [-h] | [-w|--watch] | [-n|--noupload] | [-r|--release arg]\n" 46 [-b bbb path to copy to (default ~/Bela)] | [-h] | [-w|--watch] | [-n|--noupload] | [-r|--release arg]\n"
51 printf "\nexample: build_pd.sh -i ../projects/heavy/pd/hello-world -o ../projects/heavy/hello-world\n" 47 printf "\nexample: build_pd.sh -i ../projects/heavy/pd/hello-world -o ../projects/heavy/hello-world\n"
52 echo "If --watch is selected, the script will check every 1s for any file that is modified in the source folder, which triggers\ 48 echo "If --watch is selected, the script will check every 1s for any file that is modified in the source folder, which re-triggers\
53 the building process and runs the process. 49 the building process.
54 If --screen is selected, the prompt returns to the user after launching Bela in a screen on the target device. 50 If --screen is selected, the prompt returns to the user after launching Bela in a screen on the target device.
55 If --screen and --watch are combined, while the process is running in the screen, modifications to the source files will \ 51 If --screen and --watch are combined, while the process is running in the screen, modifications to the source files will \
56 still trigger a new build. 52 still trigger a new build.
57 -r allows to build against a specific Heavy release. Default is the most recent version. 53 -r allows to build against a specific Heavy release. Default is the most recent version.
58 " 54 "
70 projectpath=$1 66 projectpath=$1
71 ;; 67 ;;
72 -r | --release ) shift 68 -r | --release ) shift
73 release=$1 69 release=$1
74 ;; 70 ;;
75 -v | --verbose ) verbose=1
76 ;;
77 -s | --screen ) RUN_WITHOUT_SCREEN="0" 71 -s | --screen ) RUN_WITHOUT_SCREEN="0"
78 ;; 72 ;;
79 -w | --watch ) WATCH=1 73 -w | --watch ) WATCH=1
80 ;; 74 ;;
81 -n | --noupload ) NO_UPLOAD=1 75 -n | --noupload ) NO_UPLOAD=1
103 mkdir -p "$projectpath" 97 mkdir -p "$projectpath"
104 98
105 # These files will be cleared from $projectpath before calling uploader.py 99 # These files will be cleared from $projectpath before calling uploader.py
106 #TODO: get a reliable, exhaustive, up-to-date list. 100 #TODO: get a reliable, exhaustive, up-to-date list.
107 HEAVY_FILES='Heavy* Hv* Message* Signal*' 101 HEAVY_FILES='Heavy* Hv* Message* Signal*'
102
103 set_date
104 reference_time_file="$projectpath"/
105 trap "kill -9 "'$BACKGROUND_PROCESS_PID'"; exit 0;" 2 9
108 uploadBuildRun(){ 106 uploadBuildRun(){
109 if [ $NO_UPLOAD -eq 0 ]; then 107 if [ $NO_UPLOAD -eq 0 ]; then
110 # remove old static files to avoid obsolete errors 108 # remove old static files to avoid obsolete errors
111 # make sure the path is not empty, so avoiding to rm -rf / by mistake 109 # make sure the path is not empty, so avoiding to rm -rf / by mistake
112 [ -z $projectpath ] && { echo 'ERROR: $projectpath is empty.'; exit 0; } 110 [ -z $projectpath ] && { echo 'ERROR: $projectpath is empty.'; exit 0; }
140 # check if custom heavy_render.cpp file is provided in the input folder 138 # check if custom heavy_render.cpp file is provided in the input folder
141 # TODO: extend this to all non-Pd files 139 # TODO: extend this to all non-Pd files
142 CUSTOM_RENDER_SOURCE_PATH="$pdpath/heavy_render.cpp" 140 CUSTOM_RENDER_SOURCE_PATH="$pdpath/heavy_render.cpp"
143 if [ -f "$CUSTOM_RENDER_SOURCE_PATH" ]; then 141 if [ -f "$CUSTOM_RENDER_SOURCE_PATH" ]; then
144 echo "Found custom heavy_render.cpp file in input folder, using that one instead of the default one."; 142 echo "Found custom heavy_render.cpp file in input folder, using that one instead of the default one.";
145 cp "$CUSTOM_RENDER_SOURCE_PATH" "$projectpath/" 143 cp "$CUSTOM_RENDER_SOURCE_PATH" "$projectpath/render.cpp"
146 else 144 else
147 echo "Using default heavy_render.cpp" 145 echo "Using default heavy_render.cpp"
148 cp "hvresources/heavy_render.cpp" $projectpath/ 146 cp "hvresources/heavy_render.cpp" "$projectpath/render.cpp"
149 fi 147 fi
150 148
151 echo "Updating files on board..." 149 echo "Updating files on board..."
152 # HvContext* files tend to hang when transferring with rsync because they are very large and -c checksum takes a lot, I guess 150 # HvContext* files tend to hang when transferring with rsync because they are very large and -c checksum takes a lot, I guess
151
152 touch $reference_time_file
153 # Transfer the files
153 rsync -ac --out-format=" %n" --no-t --delete-after --exclude='HvContext*' --exclude=build --exclude=$BBB_PROJECT_NAME "$projectpath"/ "$BBB_NETWORK_TARGET_FOLDER" &&\ 154 rsync -ac --out-format=" %n" --no-t --delete-after --exclude='HvContext*' --exclude=build --exclude=$BBB_PROJECT_NAME "$projectpath"/ "$BBB_NETWORK_TARGET_FOLDER" &&\
154 { [ $NO_UPLOAD -eq 0 ] && scp "$projectpath"/HvContext* $BBB_NETWORK_TARGET_FOLDER; } ||\ 155 { [ $NO_UPLOAD -eq 1 ] || scp "$projectpath"/HvContext* $BBB_NETWORK_TARGET_FOLDER; } ||\
155 { echo "ERROR: while synchronizing files with the BBB. Is the board connected?"; exit 1; } 156 { echo "ERROR: while synchronizing files with the BBB. Is the board connected?"; exit 1; }
156 157
158 # TODO: rsync should upload a list of modified files, so that the corresponding objects can be deleted
157 # TODO: this should be run only when Heavy_bbb.h changes. Otherwise render is recompiled every time for no good reason 159 # TODO: this should be run only when Heavy_bbb.h changes. Otherwise render is recompiled every time for no good reason
158 ssh $BBB_ADDRESS "rm -rf ${BBB_PROJECT_FOLDER}/build/render.*" 160 #ssh $BBB_ADDRESS "rm -rf ${BBB_PROJECT_FOLDER}/build/render.*"
159 161
160 #produce a list of files which content has changed (not just the date) 162 #produce a list of files which content has changed (not just the date)
161 #TODO: could be made faster (perhaps) by backing up the folder locally instead of bbb 163 #TODO: could be made faster (perhaps) by backing up the folder locally instead of bbb
162 # UPDATED_FILES=`rsync -naic --log-format="%f" "$projectpath" "$BBB_BELA_HOME"/source | grep -v "\.$"` 164 # UPDATED_FILES=`rsync -naic --log-format="%f" "$projectpath" "$BBB_BELA_HOME"/source | grep -v "\.$"`
163 # echo "UPDATEDFILES : $UPDATED_FILES" 165 # echo "UPDATEDFILES : $UPDATED_FILES"
164 # exit 2 166 # exit 2
165 # remove old executable and heavy context .o/.d files 167 # remove old executable
166 if [ $NO_UPLOAD -eq 0 ]; then 168 #if [ $NO_UPLOAD -eq 0 ]; then
167 ssh $BBB_ADDRESS "rm -rf "$BBB_PROJECT_FOLDER/$BBB_PROJECT_NAME; 169 # ssh $BBB_ADDRESS "rm -rf "$BBB_PROJECT_FOLDER/$BBB_PROJECT_NAME;
168 fi; 170 #fi;
169 # Make new Bela executable and run 171 # Make new Bela executable and run
170 # It does not look very nice that we type the same things over and over 172 # It does not look very nice that we type the same things over and over
171 # but that is because each line is an ssh session in its own right 173 # but that is because each line is an ssh session in its own right
172 MAKE_COMMAND="make stop -C $BBB_BELA_HOME PROJECT='$BBB_PROJECT_NAME' CL='$COMMAND_ARGS'" 174 MAKE_COMMAND="make stop -C $BBB_BELA_HOME PROJECT='$BBB_PROJECT_NAME' CL='$COMMAND_ARGS'"
173 if [ $RUN_PROJECT -eq 0 ] 175 if [ $RUN_PROJECT -eq 0 ]
174 then 176 then
175 echo "Building project..." 177 echo "Building project..."
176 ssh $BBB_ADDRESS "$MAKE_COMMAND" 178 ssh $BBB_ADDRESS "$MAKE_COMMAND"
177 else 179 else
178 echo "Building and running project..." 180 echo "Building and running project..."
179 if [ $RUN_WITHOUT_SCREEN -eq 1 ] 181 echo "WATCH: $WATCH"
182 if [ $WATCH -eq 1 ]
183 then
184 # try to emulate run_without_screen: run with fifo
185 [ $RUN_WITHOUT_SCREEN -eq 1 ] && { ssh $BBB_ADDRESS "$MAKE_COMMAND runscreenfifo"& BACKGROUND_PROCESS_PID=$!; } ||\
186 { ssh $BBB_ADDRESS "$MAKE_COMMAND runscreen"; }
187 elif [ $RUN_WITHOUT_SCREEN -eq 1 ]
180 then 188 then
181 ssh -t $BBB_ADDRESS "$MAKE_COMMAND run" 189 ssh -t $BBB_ADDRESS "$MAKE_COMMAND run"
182 elif [ $RUN_IN_FOREGROUND -eq 1 ] 190 elif [ $RUN_IN_FOREGROUND -eq 1 ]
183 then 191 then
184 # Run in screen without detaching 192 # Run in screen without detaching
185 ssh -t $BBB_ADDRESS "$MAKE_COMMAND runscreenfg" 193 ssh -t $BBB_ADDRESS "$MAKE_COMMAND runscreenfg"
186 else 194 else
187 # Run in screen and detach 195 # Run in screen and detach
188 ssh -t $BBB_ADDRESS "$MAKE_COMMAND runscreen" 196 ssh $BBB_ADDRESS "$MAKE_COMMAND runscreen"
189 fi 197 fi
190 fi 198 fi
191 } #uploadBuildRun 199 } #uploadBuildRun
192 200
193 uploadBuildRun 201 uploadBuildRun
194 202
195 if [ $WATCH -ne 0 ]; then 203 if [ $WATCH -ne 0 ]; then
196 WAIT_STRING="\rWaiting for changes in $pdpath" 204 BACK_NO_UPLOAD=$NO_UPLOAD
197 while true; do 205 while true
198 printf "$WAIT_STRING " 206 do
199 sleep 0.3 207 echo "Waiting for changes in $pdpath, or press ctrl-c to terminate"
200 printf "$WAIT_STRING. " 208 wait_for_change "$pdpath" "$reference_time_file"
201 sleep 0.3 209 echo "Files changed"
202 printf "$WAIT_STRING.. " 210 # if .pd files did not change, no point in re-uploading
203 sleep 0.3 211 folder_has_changed "$pdpath" "$reference_time_file" "\.pd" &&\
204 printf "$WAIT_STRING..." 212 NO_UPLOAD=$BACK_NO_UPLOAD || NO_UPLOAD=1
205 sleep 0.3 213 uploadBuildRun
206 uploadBuildRun 214 done
207 done;
208 fi; 215 fi;
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 216 #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