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