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