Mercurial > hg > beaglert
comparison scripts/build_pd_heavy.sh @ 523:42f6af3a5f1d prerelease
build_project and build_pd_heavy mostly done
author | Giulio Moro <giuliomoro@yahoo.it> |
---|---|
date | Thu, 23 Jun 2016 04:31:09 +0100 |
parents | 633ade85e798 |
children | 1ca196e35105 |
comparison
equal
deleted
inserted
replaced
522:a084456960c9 | 523:42f6af3a5f1d |
---|---|
1 #!/bin/sh | 1 #!/bin/sh |
2 | 2 # This script uploads Pd patches to Enzienaudio's server and compiles them on Bela |
3 # shell script for automatic uploading/compiling of pd patch onto bbb | 3 |
4 # Christian Heinrichs 2015 | |
5 # | |
6 | |
7 trap "{ echo "";exit 0; }" 2 | |
8 | |
9 workingdir=".." | |
10 pdpath="" | 4 pdpath="" |
11 NO_UPLOAD="0" | 5 NO_UPLOAD="0" |
12 WATCH="0" | 6 WATCH="0" |
13 FORCE="0" | 7 FORCE="0" |
14 #make sure the paths have the trailing / . | 8 #make sure the paths have the trailing / . |
15 BBB_DEFAULT_PROJECT_NAME="heavyProject" | 9 BBB_DEFAULT_PROJECT_NAME="heavyProject" |
16 COMMAND_ARGS= | |
17 RUN_PROJECT=1 | |
18 RUN_IN_FOREGROUND=0 | |
19 RUN_WITHOUT_SCREEN=1 | |
20 BELA_PYTHON27= | 10 BELA_PYTHON27= |
21 | 11 |
22 SCRIPTDIR=$(dirname "$0") | 12 SCRIPTDIR=$(dirname "$0") |
23 [ -z $SCRIPTDIR ] && SCRIPTDIR="./" || SCRIPTDIR=$SCRIPTDIR/ | 13 [ -z $SCRIPTDIR ] && SCRIPTDIR="./" || SCRIPTDIR=$SCRIPTDIR/ |
24 [ -z $HVRESOURCES_DIR ] && HVRESOURCES_DIR=$SCRIPTDIR/hvresources/ | 14 [ -z $HVRESOURCES_DIR ] && HVRESOURCES_DIR=$SCRIPTDIR/hvresources/ |
43 fi; | 33 fi; |
44 | 34 |
45 | 35 |
46 usage () | 36 usage () |
47 { | 37 { |
48 printf "\nUSAGE: build_pd.sh [[-i input folder containing _main.pd file ]\ | 38 echo " |
49 [-o output folder for temp heavy project .c files (default $projectpath)]\ | 39 USAGE: build_pd.sh [[-i input folder containing _main.pd file ] |
50 [-b remote path to copy to (default ~/Bela)] | [-h] | [-w|--watch] | [-n|--noupload] | [-r|--release arg]\n" | 40 [-o output folder for temp heavy project .c files (default $projectpath)] |
51 printf "\nexample: build_pd.sh -i ../projects/heavy/pd/hello-world -o ../projects/heavy/hello-world\n" | 41 [-b remote path to copy to (default ~/Bela)] | [-h] | [-w|--watch] | [-n|--noupload] | [-r|--release arg] |
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\ | 42 |
53 the building process. | 43 example: build_pd.sh -o ../projects/heavy/hello-world ../projects/heavy/pd/hello-world |
54 If --screen is selected, the prompt returns to the user after launching Bela in a screen on the target device. | 44 |
55 If --screen and --watch are combined, while the process is running in the screen, modifications to the source files will \ | |
56 still trigger a new build. | |
57 -r allows to build against a specific Heavy release. Default is the most recent version. | 45 -r allows to build against a specific Heavy release. Default is the most recent version. |
58 " | 46 " |
47 build_script_usage | |
59 } | 48 } |
60 | 49 |
61 while [ "$1" != "" ]; do | 50 |
51 COMMAND_ARGS= | |
52 RUN_PROJECT=1 | |
53 RUN_MODE=foreground | |
54 | |
55 [ $# -lt 2 ] && { | |
56 [ -d $1 ] || { usage; exit; } | |
57 } | |
58 while [ "$2" != "" ]; do | |
62 case $1 in | 59 case $1 in |
63 -b | --belaPath ) shift | 60 -c) |
64 BBB_BELA_HOME=$1 | 61 shift |
65 ;; | 62 COMMAND_ARGS="$1" |
66 -i | --input ) shift | 63 ;; |
67 pdpath=$1 | 64 -b) |
68 ;; | 65 RUN_MODE=screen |
69 -o | --output ) shift | 66 ;; |
70 projectpath=$1 | 67 -f) |
71 ;; | 68 RUN_MODE=foreground |
72 -r | --release ) shift | 69 ;; |
73 release=$1 | 70 -s) |
74 ;; | 71 RUN_MODE=screenfg |
75 -s | --screen ) RUN_WITHOUT_SCREEN="0" | 72 ;; |
76 ;; | 73 -n) |
77 -w | --watch ) WATCH=1 | 74 RUN_PROJECT=0 |
78 ;; | 75 ;; |
79 -n | --noupload ) NO_UPLOAD=1 | 76 -p) |
80 ;; | 77 shift |
81 -h | --help ) usage | 78 BBB_PROJECT_NAME="$1" |
82 exit | 79 ;; |
83 ;; | 80 --clean) |
84 * ) usage | 81 BBB_MAKEFILE_OPTIONS="$BBB_MAKEFILE_OPTIONS clean" |
85 exit 1 | 82 ;; |
83 -m) | |
84 shift | |
85 BBB_MAKEFILE_OPTIONS="BBB_MAKEFILE_OPTIONS $1" | |
86 ;; | |
87 --watch) | |
88 WATCH=1 | |
89 ;; | |
90 -o | --output ) | |
91 shift | |
92 projectpath=$1 | |
93 ;; | |
94 -r | --release ) | |
95 shift | |
96 release=$1 | |
97 ;; | |
98 -n | --noupload ) | |
99 NO_UPLOAD=1 | |
100 ;; | |
101 -h | --help | -\?) | |
102 usage | |
103 exit | |
104 ;; | |
105 *) | |
106 usage | |
107 exit 1 | |
86 esac | 108 esac |
87 shift | 109 shift |
88 done | 110 done |
89 | 111 pdpath=$1 |
112 | |
113 [ "$NO_UPLOAD" -eq 0 ] && [ -z "$pdpath" ] && { echo "Error: a path to the source folder should be provided"; exit 1; } | |
90 [ -z "$ENZIENAUDIO_COM_PATCH_NAME" ] && ENZIENAUDIO_COM_PATCH_NAME=bela | 114 [ -z "$ENZIENAUDIO_COM_PATCH_NAME" ] && ENZIENAUDIO_COM_PATCH_NAME=bela |
91 [ "$NO_UPLOAD" -eq 0 ] && [ -z "$pdpath" ] && { echo "Error: a path to the source folder should be provided"; exit 1; } | |
92 | 115 |
93 if [ -z "$release" ] | 116 if [ -z "$release" ] |
94 then | 117 then |
95 RELEASE_STRING= | 118 RELEASE_STRING= |
96 else | 119 else |
97 RELEASE_STRING="-r $release" | 120 RELEASE_STRING="-r $release" |
98 fi | 121 fi |
99 | 122 |
100 #create destination folder if it does not exist" | 123 #truncated the destination folder if it does not exist" |
101 mkdir -p "$projectpath" | 124 mkdir -p "$projectpath" |
102 | 125 |
103 # These files will be cleared from $projectpath before calling uploader.py | 126 # These files will be cleared from $projectpath before calling uploader.py |
104 #TODO: get a reliable, exhaustive, up-to-date list. | 127 #TODO: get a reliable, exhaustive, up-to-date list. |
105 HEAVY_FILES='Heavy* Hv*' | 128 HEAVY_FILES='Heavy* Hv*' |
115 # use -rf to prevent warnings in case they do not exist | 138 # use -rf to prevent warnings in case they do not exist |
116 for file in $HEAVY_FILES | 139 for file in $HEAVY_FILES |
117 do | 140 do |
118 rm -rf "$projectpath"/$file | 141 rm -rf "$projectpath"/$file |
119 done | 142 done |
120 | |
121 # invoke the online compiler | 143 # invoke the online compiler |
144 echo "$BELA_PYTHON27" $HVRESOURCES_DIR/uploader.py "$pdpath"/ -n $ENZIENAUDIO_COM_PATCH_NAME -g c -o "$projectpath" $RELEASE_STRING | |
122 "$BELA_PYTHON27" $HVRESOURCES_DIR/uploader.py "$pdpath"/ -n $ENZIENAUDIO_COM_PATCH_NAME -g c -o "$projectpath" $RELEASE_STRING ||\ | 145 "$BELA_PYTHON27" $HVRESOURCES_DIR/uploader.py "$pdpath"/ -n $ENZIENAUDIO_COM_PATCH_NAME -g c -o "$projectpath" $RELEASE_STRING ||\ |
123 { echo "ERROR: an error occurred while executing the uploader.py script"; exit 1; } | 146 { echo "ERROR: an error occurred while executing the uploader.py script"; exit 1; } |
124 fi; | 147 fi; |
125 | 148 |
126 echo ""; | 149 echo ""; |
127 | 150 |
128 # Test that files have been retrieved from the online compiler. | 151 # Test that files have been retrieved from the online compiler. |
129 # TODO: find a more reliable way of doing this. e.g.: have uploader.py fail with a non-zero error code. | 152 # TODO: find a more reliable way of doing this. e.g.: have uploader.py fail with a non-zero error code. |
130 for file in $HEAVY_FILES; | 153 for file in $HEAVY_FILES; |
131 do | 154 do |
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; } | 155 ls "$projectpath"/$file >/dev/null 2>&1 || { |
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" ||\ | |
157 printf "Folder $projectpath does not contain a valid Heavy project\n"; | |
158 exit 1; } | |
133 done | 159 done |
134 | 160 |
135 # Apply any Bela-specific patches here | 161 # Apply any Bela-specific patches here |
136 cp "$HVRESOURCES_DIR/HvUtils.h" $projectpath/ || exit 1; | 162 cp "$HVRESOURCES_DIR/HvUtils.h" $projectpath/ || exit 1; |
137 | 163 |
175 if [ $RUN_PROJECT -eq 0 ] | 201 if [ $RUN_PROJECT -eq 0 ] |
176 then | 202 then |
177 echo "Building project..." | 203 echo "Building project..." |
178 ssh $BBB_ADDRESS "$MAKE_COMMAND" | 204 ssh $BBB_ADDRESS "$MAKE_COMMAND" |
179 else | 205 else |
180 echo "Building and running project..." | 206 case $RUN_MODE in |
181 if [ $WATCH -eq 1 ] | 207 # Sorry for repeating the options, but "ssh / ssh -t" makes things complicated |
182 then | 208 foreground) |
183 # try to emulate run_without_screen: run with fifo | 209 ssh -t $BBB_ADDRESS "$MAKE_COMMAND run" |
184 if [ $RUN_WITHOUT_SCREEN -eq 1 ]; | 210 ;; |
185 then | 211 screen) |
186 ssh $BBB_ADDRESS "$MAKE_COMMAND runscreenfifo" & BACKGROUND_PROCESS_PID=$! | 212 ssh $BBB_ADDRESS "$MAKE_COMMAND runscreen" |
187 # run this in the background, it will be killed anyhow when the process stops. | 213 ;; |
188 # Either with the trap below or in another way | 214 screenfg) |
189 trap "kill $BACKGROUND_PROCESS_PID; exit 0;" 2 9 | 215 ssh -t $BBB_ADDRESS "$MAKE_COMMAND runscreenfg" |
190 # add the line below to the trap if you want to kill the process on the board when you exit the script | 216 ;; |
191 # ssh -o ConnectTimeout 2 $BBB_ADDRESS make --no-print-directory -C $BBB_BELA_HOME stop ; | 217 *) |
192 else | 218 echo $RUN_MODE |
193 ssh $BBB_ADDRESS "$MAKE_COMMAND runscreen" | 219 error |
194 fi | 220 ;; |
195 elif [ $RUN_WITHOUT_SCREEN -eq 1 ] | 221 esac |
196 then | |
197 ssh -t $BBB_ADDRESS "$MAKE_COMMAND run" | |
198 elif [ $RUN_IN_FOREGROUND -eq 1 ] | |
199 then | |
200 # Run in screen without detaching | |
201 ssh -t $BBB_ADDRESS "$MAKE_COMMAND runscreenfg" | |
202 else | |
203 # Run in screen and detach | |
204 ssh $BBB_ADDRESS "$MAKE_COMMAND runscreen" | |
205 fi | |
206 fi | 222 fi |
207 } #uploadBuildRun | 223 } #uploadBuildRun |
208 | 224 |
209 uploadBuildRun | 225 uploadBuildRun |
210 | 226 |