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 # example usage: sh upload-and-compile.sh -f bwg-tests -q -e
|
chris@160
|
7
|
giuliomoro@431
|
8 trap "{ echo "";exit 0; }" 2
|
giuliomoro@203
|
9
|
chris@160
|
10 workingdir=".."
|
chris@160
|
11 verbose="0"
|
chris@160
|
12 pdpath=""
|
giuliomoro@398
|
13 NO_UPLOAD="0"
|
giuliomoro@203
|
14 WATCH="0"
|
giuliomoro@203
|
15 FORCE="0"
|
giuliomoro@203
|
16 #make sure the paths have the trailing / .
|
giuliomoro@431
|
17 projectpath="../tmp/heavy/hvtemp/"
|
giuliomoro@295
|
18 [ -z "$BBB_ADDRESS" ] && BBB_ADDRESS="root@192.168.7.2"
|
giuliomoro@403
|
19 [ -z "$BBB_BELA_HOME" ] && BBB_BELA_HOME="~/Bela/"
|
giuliomoro@295
|
20 [ -z "$BBB_PROJECT_HOME" ] && BBB_PROJECT_HOME="${BBB_BELA_HOME}/projects/"
|
giuliomoro@295
|
21 BBB_DEFAULT_PROJECT_NAME="heavyProject"
|
giuliomoro@295
|
22 [ -z "$BBB_PROJECT_NAME" ] && BBB_PROJECT_NAME=$BBB_DEFAULT_PROJECT_NAME
|
chris@160
|
23 COMMAND_ARGS=
|
chris@160
|
24 RUN_PROJECT=1
|
chris@160
|
25 RUN_IN_FOREGROUND=0
|
chris@160
|
26 RUN_WITHOUT_SCREEN=1
|
giuliomoro@203
|
27 BELA_PYTHON27=
|
giuliomoro@203
|
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@442
|
49 [-o output folder for new heavy project .c files (default $projectpath)]\
|
giuliomoro@403
|
50 [-b bbb 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@203
|
52 echo "If --watch is selected, the script will check every 1s for any file that is modified in the source folder, which triggers\
|
giuliomoro@203
|
53 the building process and runs the 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 -v | --verbose ) verbose=1
|
chris@160
|
76 ;;
|
giuliomoro@203
|
77 -s | --screen ) RUN_WITHOUT_SCREEN="0"
|
giuliomoro@203
|
78 ;;
|
giuliomoro@203
|
79 -w | --watch ) WATCH=1
|
giuliomoro@203
|
80 ;;
|
giuliomoro@442
|
81 -n | --noupload ) NO_UPLOAD=1
|
giuliomoro@398
|
82 ;;
|
chris@160
|
83 -h | --help ) usage
|
chris@160
|
84 exit
|
chris@160
|
85 ;;
|
chris@160
|
86 * ) usage
|
chris@160
|
87 exit 1
|
chris@160
|
88 esac
|
chris@160
|
89 shift
|
chris@160
|
90 done
|
chris@160
|
91
|
giuliomoro@442
|
92 [ -z "$ENZIENAUDIO_COM_PATCH_NAME" ] && ENZIENAUDIO_COM_PATCH_NAME=bbb
|
giuliomoro@442
|
93 [ "$NO_UPLOAD" -eq 0 ] && [ -z "$pdpath" ] && { echo "Error: a path to the source folder should be provided"; exit 1; }
|
giuliomoro@442
|
94
|
giuliomoro@439
|
95 if [ -z "$release" ]
|
giuliomoro@403
|
96 then
|
giuliomoro@403
|
97 RELEASE_STRING=
|
giuliomoro@403
|
98 else
|
giuliomoro@403
|
99 RELEASE_STRING="-r $release"
|
giuliomoro@403
|
100 fi
|
chris@190
|
101
|
giuliomoro@431
|
102 #create destination folder if it does not exist"
|
giuliomoro@431
|
103 mkdir -p "$projectpath"
|
giuliomoro@431
|
104
|
giuliomoro@442
|
105 # These files will be cleared from $projectpath before calling uploader.py
|
giuliomoro@442
|
106 #TODO: get a reliable, exhaustive, up-to-date list.
|
giuliomoro@442
|
107 HEAVY_FILES='Heavy* Hv* Message* Signal*'
|
giuliomoro@430
|
108 uploadBuildRun(){
|
giuliomoro@398
|
109 if [ $NO_UPLOAD -eq 0 ]; then
|
giuliomoro@398
|
110 # remove old static files to avoid obsolete errors
|
giuliomoro@442
|
111 # make sure the path is not empty, so avoiding to rm -rf / by mistake
|
giuliomoro@442
|
112 [ -z $projectpath ] && { echo 'ERROR: $projectpath is empty.'; exit 0; }
|
giuliomoro@398
|
113 # use -rf to prevent warnings in case they do not exist
|
giuliomoro@442
|
114 for file in $HEAVY_FILES
|
giuliomoro@442
|
115 do
|
giuliomoro@442
|
116 rm -rf "$projectpath"/$file
|
giuliomoro@442
|
117 done
|
giuliomoro@203
|
118
|
giuliomoro@398
|
119 # invoke the online compiler
|
giuliomoro@442
|
120 echo "$BELA_PYTHON27" hvresources/uploader.py "$pdpath"/ -n $ENZIENAUDIO_COM_PATCH_NAME -g c -o "$projectpath" $RELEASE_STRING
|
giuliomoro@442
|
121 "$BELA_PYTHON27" hvresources/uploader.py "$pdpath"/ -n $ENZIENAUDIO_COM_PATCH_NAME -g c -o "$projectpath" $RELEASE_STRING ||\
|
giuliomoro@442
|
122 { echo "ERROR: an error occurred while executing the uploader.py script"; exit 1; }
|
chris@160
|
123 fi;
|
chris@160
|
124
|
giuliomoro@203
|
125 echo "";
|
giuliomoro@442
|
126
|
giuliomoro@442
|
127 # Test that files have been retrieved from the online compiler.
|
giuliomoro@442
|
128 # TODO: find a more reliable way of doing this. e.g.: have uploader.py fail with a non-zero error code.
|
giuliomoro@442
|
129 for file in $HEAVY_FILES;
|
giuliomoro@442
|
130 do
|
giuliomoro@442
|
131 ls "$projectpath"/$file >/dev/null 2>&1 || { echo "The online compiler failed, please try again."; exit 1; }
|
giuliomoro@442
|
132 done
|
giuliomoro@442
|
133 # Apply any Bela-specific patches here
|
giuliomoro@442
|
134 cp "hvresources/HvUtils.h" $projectpath/;
|
giuliomoro@203
|
135
|
giuliomoro@398
|
136 BBB_PROJECT_FOLDER=$BBB_PROJECT_HOME"/"$BBB_PROJECT_NAME #make sure there is no trailing slash here
|
giuliomoro@398
|
137 BBB_NETWORK_TARGET_FOLDER=$BBB_ADDRESS:$BBB_PROJECT_FOLDER
|
giuliomoro@398
|
138
|
giuliomoro@203
|
139 # check how to copy/sync render.cpp file...
|
giuliomoro@442
|
140 # check if custom heavy_render.cpp file is provided in the input folder
|
giuliomoro@442
|
141 # TODO: extend this to all non-Pd files
|
giuliomoro@442
|
142 CUSTOM_RENDER_SOURCE_PATH="$pdpath/heavy_render.cpp"
|
giuliomoro@442
|
143 if [ -f "$CUSTOM_RENDER_SOURCE_PATH" ]; then
|
giuliomoro@442
|
144 echo "Found custom heavy_render.cpp file in input folder, using that one instead of the default one.";
|
giuliomoro@442
|
145 cp "$CUSTOM_RENDER_SOURCE_PATH" "$projectpath/"
|
giuliomoro@398
|
146 else
|
giuliomoro@442
|
147 echo "Using default heavy_render.cpp"
|
giuliomoro@442
|
148 cp "hvresources/heavy_render.cpp" $projectpath/
|
giuliomoro@442
|
149 fi
|
giuliomoro@442
|
150
|
giuliomoro@442
|
151 echo "Updating files on board..."
|
giuliomoro@442
|
152 # HvContext* files tend to hang when transferring with rsync because they are very large and -c checksum takes a lot, I guess
|
giuliomoro@442
|
153 rsync -ac --out-format=" %n" --no-t --delete-after --exclude='HvContext*' --exclude=build --exclude=$BBB_PROJECT_NAME "$projectpath"/ "$BBB_NETWORK_TARGET_FOLDER" &&\
|
giuliomoro@442
|
154 { [ $NO_UPLOAD -eq 0 ] && scp "$projectpath"/HvContext* $BBB_NETWORK_TARGET_FOLDER; } ||\
|
giuliomoro@442
|
155 { echo "ERROR: while synchronizing files with the BBB. Is the board connected?"; exit 1; }
|
chris@160
|
156
|
giuliomoro@442
|
157 # TODO: this should be run only when Heavy_bbb.h changes. Otherwise render is recompiled every time for no good reason
|
giuliomoro@442
|
158 ssh $BBB_ADDRESS "rm -rf ${BBB_PROJECT_FOLDER}/build/render.*"
|
chris@190
|
159
|
giuliomoro@203
|
160 #produce a list of files which content has changed (not just the date)
|
giuliomoro@203
|
161 #TODO: could be made faster (perhaps) by backing up the folder locally instead of bbb
|
giuliomoro@295
|
162 # UPDATED_FILES=`rsync -naic --log-format="%f" "$projectpath" "$BBB_BELA_HOME"/source | grep -v "\.$"`
|
giuliomoro@203
|
163 # echo "UPDATEDFILES : $UPDATED_FILES"
|
giuliomoro@203
|
164 # exit 2
|
giuliomoro@398
|
165 # remove old executable and heavy context .o/.d files
|
giuliomoro@398
|
166 if [ $NO_UPLOAD -eq 0 ]; then
|
giuliomoro@398
|
167 ssh $BBB_ADDRESS "rm -rf "$BBB_PROJECT_FOLDER/$BBB_PROJECT_NAME;
|
giuliomoro@398
|
168 fi;
|
giuliomoro@442
|
169 # Make new Bela executable and run
|
giuliomoro@203
|
170 # It does not look very nice that we type the same things over and over
|
giuliomoro@203
|
171 # but that is because each line is an ssh session in its own right
|
giuliomoro@329
|
172 MAKE_COMMAND="make stop -C $BBB_BELA_HOME PROJECT='$BBB_PROJECT_NAME' CL='$COMMAND_ARGS'"
|
giuliomoro@203
|
173 if [ $RUN_PROJECT -eq 0 ]
|
giuliomoro@203
|
174 then
|
giuliomoro@203
|
175 echo "Building project..."
|
giuliomoro@329
|
176 ssh $BBB_ADDRESS "$MAKE_COMMAND"
|
giuliomoro@203
|
177 else
|
giuliomoro@203
|
178 echo "Building and running project..."
|
giuliomoro@203
|
179 if [ $RUN_WITHOUT_SCREEN -eq 1 ]
|
giuliomoro@203
|
180 then
|
giuliomoro@329
|
181 ssh -t $BBB_ADDRESS "$MAKE_COMMAND run"
|
giuliomoro@203
|
182 elif [ $RUN_IN_FOREGROUND -eq 1 ]
|
giuliomoro@203
|
183 then
|
giuliomoro@203
|
184 # Run in screen without detaching
|
giuliomoro@329
|
185 ssh -t $BBB_ADDRESS "$MAKE_COMMAND runscreenfg"
|
giuliomoro@203
|
186 else
|
giuliomoro@203
|
187 # Run in screen and detach
|
giuliomoro@329
|
188 ssh -t $BBB_ADDRESS "$MAKE_COMMAND runscreen"
|
giuliomoro@203
|
189 fi
|
giuliomoro@203
|
190 fi
|
giuliomoro@403
|
191 } #uploadBuildRun
|
giuliomoro@203
|
192
|
giuliomoro@403
|
193 uploadBuildRun
|
giuliomoro@203
|
194
|
giuliomoro@203
|
195 if [ $WATCH -ne 0 ]; then
|
giuliomoro@203
|
196 WAIT_STRING="\rWaiting for changes in $pdpath"
|
giuliomoro@203
|
197 while true; do
|
giuliomoro@203
|
198 printf "$WAIT_STRING "
|
giuliomoro@203
|
199 sleep 0.3
|
giuliomoro@203
|
200 printf "$WAIT_STRING. "
|
giuliomoro@203
|
201 sleep 0.3
|
giuliomoro@203
|
202 printf "$WAIT_STRING.. "
|
giuliomoro@203
|
203 sleep 0.3
|
giuliomoro@203
|
204 printf "$WAIT_STRING..."
|
giuliomoro@203
|
205 sleep 0.3
|
giuliomoro@403
|
206 uploadBuildRun
|
giuliomoro@203
|
207 done;
|
chris@160
|
208 fi;
|
chris@160
|
209 #ssh -t root@192.168.7.2 "kill -s 2 \`pidof heavy_template\` 2>/dev/null; sleep 0.5; rm -f ~/$filename_bbb/Release/source/heavy/HvContext_bbb.? ~/$filename_bbb/Release/heavy_template && make all -C ~/$filename_bbb/Release" &>/dev/null
|