giuliomoro@425
|
1 #!/bin/sh
|
giuliomoro@523
|
2 # This script uploads Pd patches to Enzienaudio's server and compiles them on Bela
|
chris@160
|
3
|
chris@160
|
4 pdpath=""
|
giuliomoro@398
|
5 NO_UPLOAD="0"
|
giuliomoro@203
|
6 WATCH="0"
|
giuliomoro@203
|
7 FORCE="0"
|
giuliomoro@203
|
8 #make sure the paths have the trailing / .
|
giuliomoro@295
|
9 BBB_DEFAULT_PROJECT_NAME="heavyProject"
|
giuliomoro@203
|
10 BELA_PYTHON27=
|
giuliomoro@203
|
11
|
giuliomoro@462
|
12 SCRIPTDIR=$(dirname "$0")
|
giuliomoro@462
|
13 [ -z $SCRIPTDIR ] && SCRIPTDIR="./" || SCRIPTDIR=$SCRIPTDIR/
|
giuliomoro@481
|
14 [ -z $HVRESOURCES_DIR ] && HVRESOURCES_DIR=$SCRIPTDIR/hvresources/
|
giuliomoro@462
|
15 . $SCRIPTDIR.bela_common || { echo "You must be in Bela/scripts to run these scripts" | exit 1; }
|
giuliomoro@447
|
16
|
giuliomoro@511
|
17 projectpath="$SCRIPTDIR/../tmp/heavy/hvtemp/"
|
giuliomoro@511
|
18
|
giuliomoro@203
|
19 if [ -z "$BELA_PYTHON27" ]; then
|
giuliomoro@203
|
20 for PY in python python2.7 ; do
|
giuliomoro@428
|
21 python --version 2>&1 | grep "2\.7" >/dev/null 2>&1
|
giuliomoro@203
|
22 if [ $? -eq 0 ]; then
|
giuliomoro@203
|
23 BELA_PYTHON27=$PY
|
giuliomoro@203
|
24 break;
|
giuliomoro@203
|
25 fi;
|
giuliomoro@203
|
26 done;
|
giuliomoro@203
|
27 fi;
|
giuliomoro@203
|
28
|
giuliomoro@203
|
29 if [ -z "$BELA_PYTHON27" ]; then
|
giuliomoro@203
|
30 echo "It looks like you might not have python2.7 installed. If you do, please specify the path
|
giuliomoro@403
|
31 to your python2.7 executable in the environmental variable \$BELA_PYTHON27"
|
giuliomoro@203
|
32 exit 1;
|
giuliomoro@203
|
33 fi;
|
giuliomoro@203
|
34
|
chris@160
|
35
|
giuliomoro@430
|
36 usage ()
|
chris@160
|
37 {
|
giuliomoro@523
|
38 echo "
|
giuliomoro@523
|
39 USAGE: build_pd.sh [[-i input folder containing _main.pd file ]
|
giuliomoro@523
|
40 [-o output folder for temp heavy project .c files (default $projectpath)]
|
giuliomoro@523
|
41 [-b remote path to copy to (default ~/Bela)] | [-h] | [-w|--watch] | [-n|--noupload] | [-r|--release arg]
|
giuliomoro@523
|
42
|
giuliomoro@523
|
43 example: build_pd.sh -o ../projects/heavy/hello-world ../projects/heavy/pd/hello-world
|
giuliomoro@523
|
44
|
giuliomoro@403
|
45 -r allows to build against a specific Heavy release. Default is the most recent version.
|
giuliomoro@403
|
46 "
|
giuliomoro@523
|
47 build_script_usage
|
chris@160
|
48 }
|
chris@160
|
49
|
giuliomoro@523
|
50
|
giuliomoro@523
|
51 COMMAND_ARGS=
|
giuliomoro@523
|
52 RUN_PROJECT=1
|
giuliomoro@523
|
53 RUN_MODE=foreground
|
giuliomoro@523
|
54
|
giuliomoro@523
|
55 [ $# -lt 2 ] && {
|
giuliomoro@523
|
56 [ -d $1 ] || { usage; exit; }
|
giuliomoro@523
|
57 }
|
giuliomoro@523
|
58 while [ "$2" != "" ]; do
|
chris@160
|
59 case $1 in
|
giuliomoro@523
|
60 -c)
|
giuliomoro@523
|
61 shift
|
giuliomoro@523
|
62 COMMAND_ARGS="$1"
|
giuliomoro@523
|
63 ;;
|
giuliomoro@523
|
64 -b)
|
giuliomoro@523
|
65 RUN_MODE=screen
|
giuliomoro@523
|
66 ;;
|
giuliomoro@523
|
67 -f)
|
giuliomoro@523
|
68 RUN_MODE=foreground
|
giuliomoro@523
|
69 ;;
|
giuliomoro@523
|
70 -s)
|
giuliomoro@523
|
71 RUN_MODE=screenfg
|
giuliomoro@523
|
72 ;;
|
giuliomoro@523
|
73 -n)
|
giuliomoro@523
|
74 RUN_PROJECT=0
|
giuliomoro@523
|
75 ;;
|
giuliomoro@523
|
76 -p)
|
giuliomoro@523
|
77 shift
|
giuliomoro@523
|
78 BBB_PROJECT_NAME="$1"
|
giuliomoro@523
|
79 ;;
|
giuliomoro@523
|
80 --clean)
|
giuliomoro@523
|
81 BBB_MAKEFILE_OPTIONS="$BBB_MAKEFILE_OPTIONS clean"
|
giuliomoro@523
|
82 ;;
|
giuliomoro@523
|
83 -m)
|
giuliomoro@523
|
84 shift
|
giuliomoro@523
|
85 BBB_MAKEFILE_OPTIONS="BBB_MAKEFILE_OPTIONS $1"
|
giuliomoro@523
|
86 ;;
|
giuliomoro@523
|
87 --watch)
|
giuliomoro@523
|
88 WATCH=1
|
giuliomoro@523
|
89 ;;
|
giuliomoro@523
|
90 -o | --output )
|
giuliomoro@523
|
91 shift
|
giuliomoro@523
|
92 projectpath=$1
|
giuliomoro@523
|
93 ;;
|
giuliomoro@523
|
94 -r | --release )
|
giuliomoro@523
|
95 shift
|
giuliomoro@523
|
96 release=$1
|
giuliomoro@523
|
97 ;;
|
giuliomoro@523
|
98 -n | --noupload )
|
giuliomoro@523
|
99 NO_UPLOAD=1
|
giuliomoro@523
|
100 ;;
|
giuliomoro@523
|
101 -h | --help | -\?)
|
giuliomoro@523
|
102 usage
|
giuliomoro@523
|
103 exit
|
giuliomoro@523
|
104 ;;
|
giuliomoro@523
|
105 *)
|
giuliomoro@523
|
106 usage
|
giuliomoro@523
|
107 exit 1
|
chris@160
|
108 esac
|
chris@160
|
109 shift
|
chris@160
|
110 done
|
giuliomoro@523
|
111 pdpath=$1
|
chris@160
|
112
|
giuliomoro@523
|
113 [ "$NO_UPLOAD" -eq 0 ] && [ -z "$pdpath" ] && { echo "Error: a path to the source folder should be provided"; exit 1; }
|
giuliomoro@492
|
114 [ -z "$ENZIENAUDIO_COM_PATCH_NAME" ] && ENZIENAUDIO_COM_PATCH_NAME=bela
|
giuliomoro@442
|
115
|
giuliomoro@439
|
116 if [ -z "$release" ]
|
giuliomoro@403
|
117 then
|
giuliomoro@403
|
118 RELEASE_STRING=
|
giuliomoro@403
|
119 else
|
giuliomoro@403
|
120 RELEASE_STRING="-r $release"
|
giuliomoro@403
|
121 fi
|
chris@190
|
122
|
giuliomoro@523
|
123 #truncated the destination folder if it does not exist"
|
giuliomoro@431
|
124 mkdir -p "$projectpath"
|
giuliomoro@431
|
125
|
giuliomoro@442
|
126 # These files will be cleared from $projectpath before calling uploader.py
|
giuliomoro@442
|
127 #TODO: get a reliable, exhaustive, up-to-date list.
|
giuliomoro@488
|
128 HEAVY_FILES='Heavy* Hv*'
|
giuliomoro@445
|
129
|
giuliomoro@445
|
130 set_date
|
giuliomoro@445
|
131 reference_time_file="$projectpath"/
|
giuliomoro@490
|
132
|
giuliomoro@430
|
133 uploadBuildRun(){
|
giuliomoro@398
|
134 if [ $NO_UPLOAD -eq 0 ]; then
|
giuliomoro@398
|
135 # remove old static files to avoid obsolete errors
|
giuliomoro@442
|
136 # make sure the path is not empty, so avoiding to rm -rf / by mistake
|
giuliomoro@442
|
137 [ -z $projectpath ] && { echo 'ERROR: $projectpath is empty.'; exit 0; }
|
giuliomoro@398
|
138 # use -rf to prevent warnings in case they do not exist
|
giuliomoro@442
|
139 for file in $HEAVY_FILES
|
giuliomoro@442
|
140 do
|
giuliomoro@442
|
141 rm -rf "$projectpath"/$file
|
giuliomoro@442
|
142 done
|
giuliomoro@398
|
143 # invoke the online compiler
|
giuliomoro@523
|
144 echo "$BELA_PYTHON27" $HVRESOURCES_DIR/uploader.py "$pdpath"/ -n $ENZIENAUDIO_COM_PATCH_NAME -g c -o "$projectpath" $RELEASE_STRING
|
giuliomoro@481
|
145 "$BELA_PYTHON27" $HVRESOURCES_DIR/uploader.py "$pdpath"/ -n $ENZIENAUDIO_COM_PATCH_NAME -g c -o "$projectpath" $RELEASE_STRING ||\
|
giuliomoro@442
|
146 { echo "ERROR: an error occurred while executing the uploader.py script"; exit 1; }
|
chris@160
|
147 fi;
|
chris@160
|
148
|
giuliomoro@203
|
149 echo "";
|
giuliomoro@442
|
150
|
giuliomoro@442
|
151 # Test that files have been retrieved from the online compiler.
|
giuliomoro@442
|
152 # TODO: find a more reliable way of doing this. e.g.: have uploader.py fail with a non-zero error code.
|
giuliomoro@442
|
153 for file in $HEAVY_FILES;
|
giuliomoro@442
|
154 do
|
giuliomoro@523
|
155 ls "$projectpath"/$file >/dev/null 2>&1 || {
|
giuliomoro@523
|
156 [ $NO_UPLOAD -eq 0 ] && printf "The online compiler did not return all the files or failed without notice, please try again and/or change HEAVY_FILES to be less strict.\n\n" ||\
|
giuliomoro@523
|
157 printf "Folder $projectpath does not contain a valid Heavy project\n";
|
giuliomoro@523
|
158 exit 1; }
|
giuliomoro@442
|
159 done
|
giuliomoro@481
|
160
|
giuliomoro@442
|
161 # Apply any Bela-specific patches here
|
giuliomoro@481
|
162 cp "$HVRESOURCES_DIR/HvUtils.h" $projectpath/ || exit 1;
|
giuliomoro@203
|
163
|
giuliomoro@398
|
164 BBB_PROJECT_FOLDER=$BBB_PROJECT_HOME"/"$BBB_PROJECT_NAME #make sure there is no trailing slash here
|
giuliomoro@398
|
165 BBB_NETWORK_TARGET_FOLDER=$BBB_ADDRESS:$BBB_PROJECT_FOLDER
|
giuliomoro@398
|
166
|
giuliomoro@203
|
167 # check how to copy/sync render.cpp file...
|
giuliomoro@473
|
168 # check if custom heavy/render.cpp file is provided in the input folder
|
giuliomoro@442
|
169 # TODO: extend this to all non-Pd files
|
giuliomoro@473
|
170 CUSTOM_RENDER_SOURCE_PATH="$pdpath/heavy/render.cpp"
|
giuliomoro@442
|
171 if [ -f "$CUSTOM_RENDER_SOURCE_PATH" ]; then
|
giuliomoro@473
|
172 echo "Found custom heavy/render.cpp file in input folder, using that one instead of the default one.";
|
giuliomoro@479
|
173 cp "$CUSTOM_RENDER_SOURCE_PATH" "$projectpath/render.cpp" || exit 1
|
giuliomoro@398
|
174 else
|
giuliomoro@510
|
175 echo "Using Heavy default render.cpp"
|
giuliomoro@510
|
176 cp "$HVRESOURCES_DIR/render.cpp" "$projectpath/render.cpp" || exit 1
|
giuliomoro@442
|
177 fi
|
giuliomoro@442
|
178
|
giuliomoro@442
|
179 echo "Updating files on board..."
|
giuliomoro@442
|
180 # HvContext* files tend to hang when transferring with rsync because they are very large and -c checksum takes a lot, I guess
|
giuliomoro@445
|
181
|
giuliomoro@445
|
182 touch $reference_time_file
|
giuliomoro@445
|
183 # Transfer the files
|
giuliomoro@492
|
184 rsync -ac --out-format=" %n" --no-t --delete-during --exclude='HvContext_'$ENZIENAUDIO_COM_PATCH_NAME'.*' --exclude=build --exclude=$BBB_PROJECT_NAME "$projectpath"/ "$BBB_NETWORK_TARGET_FOLDER" &&\
|
giuliomoro@445
|
185 { [ $NO_UPLOAD -eq 1 ] || scp "$projectpath"/HvContext* $BBB_NETWORK_TARGET_FOLDER; } ||\
|
giuliomoro@442
|
186 { echo "ERROR: while synchronizing files with the BBB. Is the board connected?"; exit 1; }
|
chris@160
|
187
|
giuliomoro@445
|
188 # TODO: rsync should upload a list of modified files, so that the corresponding objects can be deleted
|
giuliomoro@492
|
189 # TODO: this should be run only when Heavy_bela.h changes. Otherwise render is recompiled every time for no good reason
|
giuliomoro@445
|
190 #ssh $BBB_ADDRESS "rm -rf ${BBB_PROJECT_FOLDER}/build/render.*"
|
chris@190
|
191
|
giuliomoro@203
|
192 #produce a list of files which content has changed (not just the date)
|
giuliomoro@492
|
193 # remove old executable to force re-linking
|
giuliomoro@445
|
194 #if [ $NO_UPLOAD -eq 0 ]; then
|
giuliomoro@445
|
195 # ssh $BBB_ADDRESS "rm -rf "$BBB_PROJECT_FOLDER/$BBB_PROJECT_NAME;
|
giuliomoro@445
|
196 #fi;
|
giuliomoro@442
|
197 # Make new Bela executable and run
|
giuliomoro@203
|
198 # It does not look very nice that we type the same things over and over
|
giuliomoro@203
|
199 # but that is because each line is an ssh session in its own right
|
giuliomoro@329
|
200 MAKE_COMMAND="make stop -C $BBB_BELA_HOME PROJECT='$BBB_PROJECT_NAME' CL='$COMMAND_ARGS'"
|
giuliomoro@203
|
201 if [ $RUN_PROJECT -eq 0 ]
|
giuliomoro@203
|
202 then
|
giuliomoro@203
|
203 echo "Building project..."
|
giuliomoro@329
|
204 ssh $BBB_ADDRESS "$MAKE_COMMAND"
|
giuliomoro@203
|
205 else
|
giuliomoro@523
|
206 case $RUN_MODE in
|
giuliomoro@523
|
207 # Sorry for repeating the options, but "ssh / ssh -t" makes things complicated
|
giuliomoro@523
|
208 foreground)
|
giuliomoro@523
|
209 ssh -t $BBB_ADDRESS "$MAKE_COMMAND run"
|
giuliomoro@523
|
210 ;;
|
giuliomoro@523
|
211 screen)
|
giuliomoro@523
|
212 ssh $BBB_ADDRESS "$MAKE_COMMAND runscreen"
|
giuliomoro@523
|
213 ;;
|
giuliomoro@523
|
214 screenfg)
|
giuliomoro@523
|
215 ssh -t $BBB_ADDRESS "$MAKE_COMMAND runscreenfg"
|
giuliomoro@523
|
216 ;;
|
giuliomoro@523
|
217 *)
|
giuliomoro@523
|
218 echo $RUN_MODE
|
giuliomoro@523
|
219 error
|
giuliomoro@523
|
220 ;;
|
giuliomoro@523
|
221 esac
|
giuliomoro@203
|
222 fi
|
giuliomoro@403
|
223 } #uploadBuildRun
|
giuliomoro@203
|
224
|
giuliomoro@403
|
225 uploadBuildRun
|
giuliomoro@203
|
226
|
giuliomoro@203
|
227 if [ $WATCH -ne 0 ]; then
|
giuliomoro@445
|
228 BACK_NO_UPLOAD=$NO_UPLOAD
|
giuliomoro@445
|
229 while true
|
giuliomoro@445
|
230 do
|
giuliomoro@481
|
231 # actually we are watching multiple paths : $pdpath and $HVRESOURCES_DIR
|
giuliomoro@481
|
232 # so that it is easier to edit hvresources code without risk of being
|
giuliomoro@481
|
233 # overwritten, but we avoid mentioning it to the end user, otherwise they
|
giuliomoro@481
|
234 # get confused.
|
giuliomoro@445
|
235 echo "Waiting for changes in $pdpath, or press ctrl-c to terminate"
|
giuliomoro@481
|
236 while sleep 1
|
giuliomoro@481
|
237 do
|
giuliomoro@481
|
238 folder_has_changed "$pdpath" "$reference_time_file" && {
|
giuliomoro@481
|
239 echo "Content of $pdpath has changed"
|
giuliomoro@481
|
240 break
|
giuliomoro@481
|
241 }
|
giuliomoro@481
|
242 folder_has_changed "$HVRESOURCES_DIR" "$reference_time_file" && {
|
giuliomoro@511
|
243 echo "Content of "$HVRESOURCES_DIR" has changed"
|
giuliomoro@481
|
244 break
|
giuliomoro@481
|
245 }
|
giuliomoro@481
|
246 done
|
giuliomoro@445
|
247 echo "Files changed"
|
giuliomoro@445
|
248 # if .pd files did not change, no point in re-uploading
|
giuliomoro@445
|
249 folder_has_changed "$pdpath" "$reference_time_file" "\.pd" &&\
|
giuliomoro@445
|
250 NO_UPLOAD=$BACK_NO_UPLOAD || NO_UPLOAD=1
|
giuliomoro@445
|
251 uploadBuildRun
|
giuliomoro@445
|
252 done
|
chris@160
|
253 fi;
|