comparison scripts/build_pd.sh @ 203:b5d59cf94c64

Better pd_build.sh script, also wrapped in an Automator Task for MacOS
author Giulio Moro <giuliomoro@yahoo.it>
date Fri, 05 Feb 2016 23:46:11 +0000
parents 3b8a28edae41
children 1721296e3e71
comparison
equal deleted inserted replaced
202:6fbf0af23a19 203:b5d59cf94c64
3 # shell script for automatic uploading/compiling of pd patch onto bbb 3 # shell script for automatic uploading/compiling of pd patch onto bbb
4 # Christian Heinrichs 2015 4 # Christian Heinrichs 2015
5 # 5 #
6 # example usage: sh upload-and-compile.sh -f bwg-tests -q -e 6 # example usage: sh upload-and-compile.sh -f bwg-tests -q -e
7 7
8 trap "{ echo "";exit 0; }" SIGINT SIGTERM
9
8 workingdir=".." 10 workingdir=".."
9 verbose="0" 11 verbose="0"
10 render="0" 12 render="0"
11 pdpath="" 13 pdpath=""
12 projectpath="../projects/heavy/hvtemp" 14 WATCH="0"
13 BBB_PATH="~/BeagleRT" 15 FORCE="0"
16 #make sure the paths have the trailing / .
17 projectpath="../projects/heavy/hvtemp/"
18 BBB_PATH="~/BeagleRT/"
14 BBB_ADDRESS="root@192.168.7.2" 19 BBB_ADDRESS="root@192.168.7.2"
15 COMMAND_ARGS= 20 COMMAND_ARGS=
16 RUN_PROJECT=1 21 RUN_PROJECT=1
17 RUN_IN_FOREGROUND=0 22 RUN_IN_FOREGROUND=0
18 RUN_WITHOUT_SCREEN=1 23 RUN_WITHOUT_SCREEN=1
24 BELA_PYTHON27=
25
26 if [ -z "$BELA_PYTHON27" ]; then
27 for PY in python python2.7 ; do
28 python --version 2>&1 | grep "2\.7" &> /dev/null
29 if [ $? -eq 0 ]; then
30 BELA_PYTHON27=$PY
31 break;
32 fi;
33 done;
34 fi;
35
36 if [ -z "$BELA_PYTHON27" ]; then
37 echo "It looks like you might not have python2.7 installed. If you do, please specify the path
38 to your python2.7 executable in the environmental variable $BELA_PYTHON27"
39 exit 1;
40 fi;
41
19 42
20 function usage 43 function usage
21 { 44 {
22 echo " 45 printf "\nUSAGE: build_pd.sh [[-i input folder containing _main.pd file ]\
23 USAGE: build_pd.sh [[-i input folder containing _main.pd file ] [-o output folder for new heavy project .c files (default ../projects/heavy/hvtemp)] [-b bbb path to copy to (default ~/BeagleRT)] | [-h]] 46 [-o output folder for new heavy project .c files (default ../projects/heavy/hvtemp)]\
24 " 47 [-b bbb path to copy to (default ~/BeagleRT)] | [-h] | [-f|--force] | [-w|--watch]\n"
25 echo "example: build_pd.sh -i ../projects/heavy/pd/hello-world -o ../projects/heavy/hello-world" 48 printf "\nexample: build_pd.sh -i ../projects/heavy/pd/hello-world -o ../projects/heavy/hello-world\n"
49 echo "If --watch is selected, the script will check every 1s for any file that is modified in the source folder, which triggers\
50 the building process and runs the process.
51 If --screen is selected, the prompt returns to the user after launching BeagleRT in a screen on the target device.
52 If --screen and --watch are combined, while the process is running in the screen, modifications to the source files will \
53 still trigger a new build."
26 } 54 }
27 55
28 while [ "$1" != "" ]; do 56 while [ "$1" != "" ]; do
29 case $1 in 57 case $1 in
30 -b | --bbb ) shift 58 -b | --bbb ) shift
31 BBB_PATH=$1 59 BBB_PATH=$1
32 ;; 60 ;;
61 -f | --force) FORCE="1"
62 ;;
33 -i | --input ) shift 63 -i | --input ) shift
34 pdpath=$1 64 pdpath=$1
35 ;; 65 ;;
36 -o | --output ) shift 66 -o | --output ) shift
37 projectpath=$1 67 projectpath=$1
38 ;; 68 ;;
39 -v | --verbose ) shift 69 -v | --verbose ) verbose=1
40 verbose=1
41 ;; 70 ;;
42 -r | --render ) shift 71 -r | --render ) shift
43 render=1 72 render=1
73 ;;
74 -s | --screen ) RUN_WITHOUT_SCREEN="0"
75 ;;
76 -w | --watch ) WATCH=1
44 ;; 77 ;;
45 -h | --help ) usage 78 -h | --help ) usage
46 exit 79 exit
47 ;; 80 ;;
48 * ) usage 81 * ) usage
49 exit 1 82 exit 1
50 esac 83 esac
51 shift 84 shift
52 done 85 done
53 86
54 # remove old static files to avoid obsolete errors 87 function hasNotChanged(){
55 rm "$projectpath"/Hv* "$projectpath"/Message* "$projectpath"/Control* "$projectpath"/Signal* &>/dev/null 88 if [ $WATCH -eq 0 ];
56 89 then
57 /usr/bin/python hvresources/uploader.py "$pdpath"/ -n bbb -g c -o "$projectpath"/; 90 echo "Files in the source folder changed since the last build, use --force to force recompiling";
58 if [ $? -ne 0 ]; then 91 exit 0;
59 /usr/local/bin/python hvresources/uploader.py "$pdpath"/ -n bbb -g c -o "$projectpath"/; 92 fi;
93 }
94
95 function checkChanged(){
96 PD_BACKUP_PATH="hvresources/patch_back/"
97 if [ $FORCE -eq 1 ] && [ $WATCH -eq 0 ];
98 then
99 rm -rf $PD_BACKUP_PATH;
100 return;
101 fi;
102 mkdir -p $PD_BACKUP_PATH;
103 # count files that have changed
104 HAS_CHANGED=$(rsync -nac --out-format="%f" "$pdpath" $PD_BACKUP_PATH | grep -v "\/\.$"| wc -l);
105 if [ $HAS_CHANGED -eq 0 ] && [ $FORCE -eq 0 ];
106 then
107 hasNotChanged;
108 return 1;
109 fi;
110 #if we are here and $FORCE==1, it means that $WATCH==1
111 # so let's make sure only the first run get forced:
112 FORCE=0;
113 echo "Files have changed"
114 # otherwise back up the files that have changed
115 rsync -vac "$pdpath" $PD_BACKUP_PATH
116
117 return 0;
118 }
119
120 function checkUploadBuildRun(){
121 checkChanged || return # exits if source files have not changed
122
123 # remove old static files to avoid obsolete errors
124 # use -rf to prevent warnings in case they do not exist
125 rm -rf "$projectpath"/Hv* "$projectpath"/Message* "$projectpath"/Control* "$projectpath"/Signal* &>/dev/null
126
127 # invoke the online compiler
128 "$BELA_PYTHON27" hvresources/uploader.py "$pdpath"/ -n bbb -g c -o "$projectpath";
60 if [ $? -ne 0 ]; then 129 if [ $? -ne 0 ]; then
61 #echo "ERROR: an error occurred while executing the uploader.py script" 130 #echo "ERROR: an error occurred while executing the uploader.py script"
62 echo "error" 131 echo "error"
63 exit 1 132 exit 1
64 fi; 133 fi;
134
135 echo "";
136 #echo "*|*|* Successfully uploaded and converted pd patch into super-fast optimized C code. Brought to you by Heavy! *|*|*";
137 echo "";
138
139 # check how to copy/sync render.cpp file...
140 if [ $render -eq 0 ]; then
141 cp "hvresources/render.cpp" $projectpath/;
142 fi;
143
144 cp "hvresources/HvUtils.h" $projectpath/;
145
146 echo "updating files on board..."
147
148 rsync -c -rv --exclude 'HvContext*' "$projectpath"/ "$BBB_ADDRESS":"$BBB_PATH"/source;
149 # rsync -c -rv "$projectpath"/ "$BBB_ADDRESS":"$BBB_PATH"/source;
150
151 # for whatever reason these big files used to hang when transferring with rsync
152 scp "$projectpath"/HvContext* "$BBB_ADDRESS":"$BBB_PATH"/source;
153
154 if [ $? -ne 0 ]; then
155 echo "";
156 echo ":( :( :( ERROR: while synchronizing files with the BBB. Is the board connected and the correct SD card inserted? :( :( :(";
157 echo "";
158 exit 1;
159 fi;
160 # exit
161 #produce a list of files which content has changed (not just the date)
162 #TODO: could be made faster (perhaps) by backing up the folder locally instead of bbb
163 # UPDATED_FILES=`rsync -naic --log-format="%f" "$projectpath" "$BBB_PATH"/source | grep -v "\.$"`
164 # echo "UPDATEDFILES : $UPDATED_FILES"
165 # exit 2
166 # remove old executable and heavy context .o/.d files
167 ssh $BBB_ADDRESS "rm -rf $BBB_PATH/BeagleRT $BBB_PATH/build/source/HvContext_bbb.d $BBB_PATH/build/source/HvContext_bbb.o $BBB_PATH/build/source/render.o $BBB_PATH/build/source/render.d";
168 SCREEN_NAME=BeagleRT
169 KILL_RUNNING_PROCESS="bash -c 'kill -s 2 \`pidof BeagleRT\` 2>/dev/null; screen -r $SCREEN_NAME -X quit 2>/dev/null; sleep 0.5; exit 0'" #always returns true
170 # Make new BeagleRT executable and run
171 # It does not look very nice that we type the same things over and over
172 # but that is because each line is an ssh session in its own right
173 if [ $RUN_PROJECT -eq 0 ]
174 then
175 echo "Building project..."
176 ssh $BBB_ADDRESS "make all -C $BBB_PATH"
177 else
178 echo "Building and running project..."
179 if [ $RUN_WITHOUT_SCREEN -eq 1 ]
180 then
181 ssh -t $BBB_ADDRESS "make all -C $BBB_PATH && $KILL_RUNNING_PROCESS && $BBB_PATH/BeagleRT $COMMAND_ARGS"
182 elif [ $RUN_IN_FOREGROUND -eq 1 ]
183 then
184 # Run in screen without detaching
185 ssh -t $BBB_ADDRESS "make all -C $BBB_PATH && $KILL_RUNNING_PROCESS && screen -S $SCREEN_NAME $BBB_PATH/BeagleRT $COMMAND_ARGS"
186 else
187 # Run in screen and detach
188 ssh $BBB_ADDRESS "make all -C $BBB_PATH && $KILL_RUNNING_PROCESS && screen -dmS $SCREEN_NAME $BBB_PATH/BeagleRT $COMMAND_ARGS"
189 fi
190 fi
191 } #checkUploadBuildRun
192
193 checkUploadBuildRun
194
195 if [ $WATCH -ne 0 ]; then
196 WAIT_STRING="\rWaiting for changes in $pdpath"
197 while true; do
198 printf "$WAIT_STRING "
199 sleep 0.3
200 printf "$WAIT_STRING. "
201 sleep 0.3
202 printf "$WAIT_STRING.. "
203 sleep 0.3
204 printf "$WAIT_STRING..."
205 sleep 0.3
206 checkUploadBuildRun
207 done;
65 fi; 208 fi;
66 echo "";
67 #echo "*|*|* Successfully uploaded and converted pd patch into super-fast optimized C code. Brought to you by Heavy! *|*|*";
68 echo "";
69
70 # check how to copy/sync render.cpp file...
71 if [ $render -eq 0 ]; then
72 cp "hvresources/render.cpp" $projectpath/;
73 fi;
74
75 cp "hvresources/HvUtils.h" $projectpath/;
76
77 echo "updating files on board..."
78
79 rsync -c -r --exclude 'HvContext*' "$projectpath"/ "$BBB_ADDRESS":"$BBB_PATH"/source;
80
81 scp "$projectpath"/HvContext* "$BBB_ADDRESS":"$BBB_PATH"/source;
82
83 if [ $? -ne 0 ]; then
84 echo "";
85 echo ":( :( :( ERROR: while synchronizing files with the BBB. Is the board connected and the correct SD card inserted? :( :( :(";
86 echo "";
87 exit 1;
88 fi;
89
90 # remove old executable and heavy context .o/.d files
91 ssh $BBB_ADDRESS "rm $BBB_PATH/BeagleRT $BBB_PATH/build/source/HvContext_bbb.d $BBB_PATH/build/source/HvContext_bbb.o $BBB_PATH/build/source/render.o $BBB_PATH/build/source/render.d";
92
93 # Make new BeagleRT executable and run
94 if [ $RUN_PROJECT -eq 0 ]
95 then
96 echo "Building project..."
97 ssh $BBB_ADDRESS "make all -C $BBB_PATH"
98 else
99 echo "Building and running project..."
100
101 if [ $RUN_WITHOUT_SCREEN -ne 0 ]
102 then
103 ssh -t $BBB_ADDRESS "make all -C $BBB_PATH && $BBB_PATH/BeagleRT $COMMAND_ARGS"
104 elif [ $RUN_IN_FOREGROUND -eq 0 ]
105 then
106 ssh $BBB_ADDRESS "make all -C $BBB_PATH && screen -S BeagleRT -d -m $BBB_PATH/BeagleRT $COMMAND_ARGS"
107 else
108 ssh -t $BBB_ADDRESS "make all -C $BBB_PATH && screen -S BeagleRT $BBB_PATH/BeagleRT $COMMAND_ARGS"
109 fi
110 fi
111
112
113
114
115
116
117
118
119 #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 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