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@549
|
129 check_board_alive
|
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@549
|
136 # make sure the path is not empty, so avoiding to rm -rf / by mistake
|
giuliomoro@549
|
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@549
|
140 do
|
giuliomoro@549
|
141 rm -rf "$projectpath"/$file
|
giuliomoro@549
|
142 done
|
giuliomoro@549
|
143
|
giuliomoro@549
|
144 echo "Invoking the online compiler..."
|
giuliomoro@398
|
145 # invoke the online compiler
|
giuliomoro@481
|
146 "$BELA_PYTHON27" $HVRESOURCES_DIR/uploader.py "$pdpath"/ -n $ENZIENAUDIO_COM_PATCH_NAME -g c -o "$projectpath" $RELEASE_STRING ||\
|
giuliomoro@549
|
147 { echo "ERROR: an error occurred while executing the uploader.py script"; exit $?; }
|
chris@160
|
148 fi;
|
chris@160
|
149
|
giuliomoro@203
|
150 echo "";
|
giuliomoro@442
|
151
|
giuliomoro@442
|
152 # Test that files have been retrieved from the online compiler.
|
giuliomoro@549
|
153 # TODO: skip this now that uplodaer.py returns meaningful exit codes
|
giuliomoro@442
|
154 for file in $HEAVY_FILES;
|
giuliomoro@442
|
155 do
|
giuliomoro@523
|
156 ls "$projectpath"/$file >/dev/null 2>&1 || {
|
giuliomoro@523
|
157 [ $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
|
158 printf "Folder $projectpath does not contain a valid Heavy project\n";
|
giuliomoro@523
|
159 exit 1; }
|
giuliomoro@442
|
160 done
|
giuliomoro@481
|
161
|
giuliomoro@442
|
162 # Apply any Bela-specific patches here
|
giuliomoro@481
|
163 cp "$HVRESOURCES_DIR/HvUtils.h" $projectpath/ || exit 1;
|
giuliomoro@203
|
164
|
giuliomoro@398
|
165 BBB_PROJECT_FOLDER=$BBB_PROJECT_HOME"/"$BBB_PROJECT_NAME #make sure there is no trailing slash here
|
giuliomoro@398
|
166 BBB_NETWORK_TARGET_FOLDER=$BBB_ADDRESS:$BBB_PROJECT_FOLDER
|
giuliomoro@398
|
167
|
giuliomoro@203
|
168 # check how to copy/sync render.cpp file...
|
giuliomoro@473
|
169 # check if custom heavy/render.cpp file is provided in the input folder
|
giuliomoro@442
|
170 # TODO: extend this to all non-Pd files
|
giuliomoro@473
|
171 CUSTOM_RENDER_SOURCE_PATH="$pdpath/heavy/render.cpp"
|
giuliomoro@442
|
172 if [ -f "$CUSTOM_RENDER_SOURCE_PATH" ]; then
|
giuliomoro@473
|
173 echo "Found custom heavy/render.cpp file in input folder, using that one instead of the default one.";
|
giuliomoro@479
|
174 cp "$CUSTOM_RENDER_SOURCE_PATH" "$projectpath/render.cpp" || exit 1
|
giuliomoro@398
|
175 else
|
giuliomoro@510
|
176 echo "Using Heavy default render.cpp"
|
giuliomoro@510
|
177 cp "$HVRESOURCES_DIR/render.cpp" "$projectpath/render.cpp" || exit 1
|
giuliomoro@442
|
178 fi
|
giuliomoro@442
|
179
|
giuliomoro@442
|
180 echo "Updating files on board..."
|
giuliomoro@442
|
181 # HvContext* files tend to hang when transferring with rsync because they are very large and -c checksum takes a lot, I guess
|
giuliomoro@445
|
182
|
giuliomoro@445
|
183 touch $reference_time_file
|
giuliomoro@445
|
184 # Transfer the files
|
giuliomoro@492
|
185 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
|
186 { [ $NO_UPLOAD -eq 1 ] || scp "$projectpath"/HvContext* $BBB_NETWORK_TARGET_FOLDER; } ||\
|
giuliomoro@442
|
187 { echo "ERROR: while synchronizing files with the BBB. Is the board connected?"; exit 1; }
|
chris@160
|
188
|
giuliomoro@445
|
189 # TODO: rsync should upload a list of modified files, so that the corresponding objects can be deleted
|
giuliomoro@492
|
190 # TODO: this should be run only when Heavy_bela.h changes. Otherwise render is recompiled every time for no good reason
|
giuliomoro@445
|
191 #ssh $BBB_ADDRESS "rm -rf ${BBB_PROJECT_FOLDER}/build/render.*"
|
chris@190
|
192
|
giuliomoro@203
|
193 #produce a list of files which content has changed (not just the date)
|
giuliomoro@492
|
194 # remove old executable to force re-linking
|
giuliomoro@445
|
195 #if [ $NO_UPLOAD -eq 0 ]; then
|
giuliomoro@445
|
196 # ssh $BBB_ADDRESS "rm -rf "$BBB_PROJECT_FOLDER/$BBB_PROJECT_NAME;
|
giuliomoro@445
|
197 #fi;
|
giuliomoro@442
|
198 # Make new Bela executable and run
|
giuliomoro@203
|
199 # It does not look very nice that we type the same things over and over
|
giuliomoro@203
|
200 # but that is because each line is an ssh session in its own right
|
giuliomoro@525
|
201 MAKE_COMMAND="make --no-print-directory QUIET=true -C $BBB_BELA_HOME PROJECT='$BBB_PROJECT_NAME' CL='$COMMAND_ARGS' $BBB_MAKEFILE_OPTIONS"
|
giuliomoro@203
|
202 if [ $RUN_PROJECT -eq 0 ]
|
giuliomoro@203
|
203 then
|
giuliomoro@203
|
204 echo "Building project..."
|
giuliomoro@329
|
205 ssh $BBB_ADDRESS "$MAKE_COMMAND"
|
giuliomoro@203
|
206 else
|
giuliomoro@523
|
207 case $RUN_MODE in
|
giuliomoro@523
|
208 # Sorry for repeating the options, but "ssh / ssh -t" makes things complicated
|
giuliomoro@523
|
209 foreground)
|
giuliomoro@523
|
210 ssh -t $BBB_ADDRESS "$MAKE_COMMAND run"
|
giuliomoro@523
|
211 ;;
|
giuliomoro@523
|
212 screen)
|
giuliomoro@523
|
213 ssh $BBB_ADDRESS "$MAKE_COMMAND runscreen"
|
giuliomoro@523
|
214 ;;
|
giuliomoro@523
|
215 screenfg)
|
giuliomoro@523
|
216 ssh -t $BBB_ADDRESS "$MAKE_COMMAND runscreenfg"
|
giuliomoro@523
|
217 ;;
|
giuliomoro@523
|
218 *)
|
giuliomoro@523
|
219 echo $RUN_MODE
|
giuliomoro@523
|
220 error
|
giuliomoro@523
|
221 ;;
|
giuliomoro@523
|
222 esac
|
giuliomoro@203
|
223 fi
|
giuliomoro@403
|
224 } #uploadBuildRun
|
giuliomoro@203
|
225
|
giuliomoro@403
|
226 uploadBuildRun
|
giuliomoro@203
|
227
|
giuliomoro@203
|
228 if [ $WATCH -ne 0 ]; then
|
giuliomoro@445
|
229 BACK_NO_UPLOAD=$NO_UPLOAD
|
giuliomoro@445
|
230 while true
|
giuliomoro@445
|
231 do
|
giuliomoro@481
|
232 # actually we are watching multiple paths : $pdpath and $HVRESOURCES_DIR
|
giuliomoro@481
|
233 # so that it is easier to edit hvresources code without risk of being
|
giuliomoro@481
|
234 # overwritten, but we avoid mentioning it to the end user, otherwise they
|
giuliomoro@481
|
235 # get confused.
|
giuliomoro@445
|
236 echo "Waiting for changes in $pdpath, or press ctrl-c to terminate"
|
giuliomoro@481
|
237 while sleep 1
|
giuliomoro@481
|
238 do
|
giuliomoro@481
|
239 folder_has_changed "$pdpath" "$reference_time_file" && {
|
giuliomoro@481
|
240 echo "Content of $pdpath has changed"
|
giuliomoro@481
|
241 break
|
giuliomoro@481
|
242 }
|
giuliomoro@481
|
243 folder_has_changed "$HVRESOURCES_DIR" "$reference_time_file" && {
|
giuliomoro@511
|
244 echo "Content of "$HVRESOURCES_DIR" has changed"
|
giuliomoro@481
|
245 break
|
giuliomoro@481
|
246 }
|
giuliomoro@481
|
247 done
|
giuliomoro@445
|
248 echo "Files changed"
|
giuliomoro@445
|
249 # if .pd files did not change, no point in re-uploading
|
giuliomoro@445
|
250 folder_has_changed "$pdpath" "$reference_time_file" "\.pd" &&\
|
giuliomoro@445
|
251 NO_UPLOAD=$BACK_NO_UPLOAD || NO_UPLOAD=1
|
giuliomoro@445
|
252 uploadBuildRun
|
giuliomoro@445
|
253 done
|
chris@160
|
254 fi;
|