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