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