comparison scripts/build_pd_heavy.sh @ 442:6462d0cc8906 prerelease

build_pd_heavy.sh: major refactoring. Safer, nicer, cleaner
author Giulio Moro <giuliomoro@yahoo.it>
date Sun, 19 Jun 2016 00:35:41 +0100
parents e49ae69acbe8
children 2b09be3fb0f2
comparison
equal deleted inserted replaced
441:b596c72f0382 442:6462d0cc8906
7 7
8 trap "{ echo "";exit 0; }" 2 8 trap "{ echo "";exit 0; }" 2
9 9
10 workingdir=".." 10 workingdir=".."
11 verbose="0" 11 verbose="0"
12 render="0"
13 pdpath="" 12 pdpath=""
14 NO_UPLOAD="0" 13 NO_UPLOAD="0"
15 WATCH="0" 14 WATCH="0"
16 FORCE="0" 15 FORCE="0"
17 #make sure the paths have the trailing / . 16 #make sure the paths have the trailing / .
45 44
46 45
47 usage () 46 usage ()
48 { 47 {
49 printf "\nUSAGE: build_pd.sh [[-i input folder containing _main.pd file ]\ 48 printf "\nUSAGE: build_pd.sh [[-i input folder containing _main.pd file ]\
50 [-o output folder for new heavy project .c files (default ../projects/heavy/hvtemp)]\ 49 [-o output folder for new heavy project .c files (default $projectpath)]\
51 [-b bbb path to copy to (default ~/Bela)] | [-h] | [-w|--watch] | [-n|--noupload] | [-r|--release arg]\n" 50 [-b bbb path to copy to (default ~/Bela)] | [-h] | [-w|--watch] | [-n|--noupload] | [-r|--release arg]\n"
52 printf "\nexample: build_pd.sh -i ../projects/heavy/pd/hello-world -o ../projects/heavy/hello-world\n" 51 printf "\nexample: build_pd.sh -i ../projects/heavy/pd/hello-world -o ../projects/heavy/hello-world\n"
53 echo "If --watch is selected, the script will check every 1s for any file that is modified in the source folder, which triggers\ 52 echo "If --watch is selected, the script will check every 1s for any file that is modified in the source folder, which triggers\
54 the building process and runs the process. 53 the building process and runs the process.
55 If --screen is selected, the prompt returns to the user after launching Bela in a screen on the target device. 54 If --screen is selected, the prompt returns to the user after launching Bela in a screen on the target device.
59 " 58 "
60 } 59 }
61 60
62 while [ "$1" != "" ]; do 61 while [ "$1" != "" ]; do
63 case $1 in 62 case $1 in
64 -b | --bbb ) shift 63 -b | --belaPath ) shift
65 BBB_BELA_HOME=$1 64 BBB_BELA_HOME=$1
66 ;; 65 ;;
67 -i | --input ) shift 66 -i | --input ) shift
68 pdpath=$1 67 pdpath=$1
69 ;; 68 ;;
73 -r | --release ) shift 72 -r | --release ) shift
74 release=$1 73 release=$1
75 ;; 74 ;;
76 -v | --verbose ) verbose=1 75 -v | --verbose ) verbose=1
77 ;; 76 ;;
78 -r | --render ) shift
79 render=1
80 ;;
81 -s | --screen ) RUN_WITHOUT_SCREEN="0" 77 -s | --screen ) RUN_WITHOUT_SCREEN="0"
82 ;; 78 ;;
83 -w | --watch ) WATCH=1 79 -w | --watch ) WATCH=1
84 ;; 80 ;;
85 -n | --noupload ) NO_UPLOAD=1 81 -n | --noupload ) NO_UPLOAD=1
86 ;; 82 ;;
87 -h | --help ) usage 83 -h | --help ) usage
88 exit 84 exit
89 ;; 85 ;;
90 * ) usage 86 * ) usage
91 exit 1 87 exit 1
92 esac 88 esac
93 shift 89 shift
94 done 90 done
91
92 [ -z "$ENZIENAUDIO_COM_PATCH_NAME" ] && ENZIENAUDIO_COM_PATCH_NAME=bbb
93 [ "$NO_UPLOAD" -eq 0 ] && [ -z "$pdpath" ] && { echo "Error: a path to the source folder should be provided"; exit 1; }
95 94
96 if [ -z "$release" ] 95 if [ -z "$release" ]
97 then 96 then
98 RELEASE_STRING= 97 RELEASE_STRING=
99 else 98 else
101 fi 100 fi
102 101
103 #create destination folder if it does not exist" 102 #create destination folder if it does not exist"
104 mkdir -p "$projectpath" 103 mkdir -p "$projectpath"
105 104
105 # These files will be cleared from $projectpath before calling uploader.py
106 #TODO: get a reliable, exhaustive, up-to-date list.
107 HEAVY_FILES='Heavy* Hv* Message* Signal*'
106 uploadBuildRun(){ 108 uploadBuildRun(){
107 if [ $NO_UPLOAD -eq 0 ]; then 109 if [ $NO_UPLOAD -eq 0 ]; then
108 # remove old static files to avoid obsolete errors 110 # remove old static files to avoid obsolete errors
111 # make sure the path is not empty, so avoiding to rm -rf / by mistake
112 [ -z $projectpath ] && { echo 'ERROR: $projectpath is empty.'; exit 0; }
109 # use -rf to prevent warnings in case they do not exist 113 # use -rf to prevent warnings in case they do not exist
110 rm -rf "$projectpath"/Hv* "$projectpath"/Message* "$projectpath"/Control* "$projectpath"/Signal* >/dev/null 2>&1 114 for file in $HEAVY_FILES
115 do
116 rm -rf "$projectpath"/$file
117 done
111 118
112 # invoke the online compiler 119 # invoke the online compiler
113 "$BELA_PYTHON27" hvresources/uploader.py "$pdpath"/ -n bbb -g c -o "$projectpath" $RELEASE_STRING; 120 echo "$BELA_PYTHON27" hvresources/uploader.py "$pdpath"/ -n $ENZIENAUDIO_COM_PATCH_NAME -g c -o "$projectpath" $RELEASE_STRING
114 if [ $? -ne 0 ]; then 121 "$BELA_PYTHON27" hvresources/uploader.py "$pdpath"/ -n $ENZIENAUDIO_COM_PATCH_NAME -g c -o "$projectpath" $RELEASE_STRING ||\
115 #echo "ERROR: an error occurred while executing the uploader.py script" 122 { echo "ERROR: an error occurred while executing the uploader.py script"; exit 1; }
116 echo "error"
117 exit 1
118 fi;
119 fi; 123 fi;
120 124
121 echo ""; 125 echo "";
122 #echo "*|*|* Successfully uploaded and converted pd patch into super-fast optimized C code. Brought to you by Heavy! *|*|*"; 126
123 echo ""; 127 # Test that files have been retrieved from the online compiler.
128 # TODO: find a more reliable way of doing this. e.g.: have uploader.py fail with a non-zero error code.
129 for file in $HEAVY_FILES;
130 do
131 ls "$projectpath"/$file >/dev/null 2>&1 || { echo "The online compiler failed, please try again."; exit 1; }
132 done
133 # Apply any Bela-specific patches here
134 cp "hvresources/HvUtils.h" $projectpath/;
124 135
125 BBB_PROJECT_FOLDER=$BBB_PROJECT_HOME"/"$BBB_PROJECT_NAME #make sure there is no trailing slash here 136 BBB_PROJECT_FOLDER=$BBB_PROJECT_HOME"/"$BBB_PROJECT_NAME #make sure there is no trailing slash here
126 BBB_NETWORK_TARGET_FOLDER=$BBB_ADDRESS:$BBB_PROJECT_FOLDER 137 BBB_NETWORK_TARGET_FOLDER=$BBB_ADDRESS:$BBB_PROJECT_FOLDER
127 138
128 # check how to copy/sync render.cpp file... 139 # check how to copy/sync render.cpp file...
129 # don't replace render.cpp file if custom one provided in output folder 140 # check if custom heavy_render.cpp file is provided in the input folder
130 if [ -f $projectpath"/render.cpp" ]; then 141 # TODO: extend this to all non-Pd files
131 echo "Found custom render.cpp file in output folder"; 142 CUSTOM_RENDER_SOURCE_PATH="$pdpath/heavy_render.cpp"
132 ssh -t $BBB_ADDRESS "rm ${BBB_PROJECT_FOLDER}/build/render.*" 143 if [ -f "$CUSTOM_RENDER_SOURCE_PATH" ]; then
144 echo "Found custom heavy_render.cpp file in input folder, using that one instead of the default one.";
145 cp "$CUSTOM_RENDER_SOURCE_PATH" "$projectpath/"
133 else 146 else
134 if [ $render -eq 0 ]; then 147 echo "Using default heavy_render.cpp"
135 cp "hvresources/render.cpp" $projectpath/; 148 cp "hvresources/heavy_render.cpp" $projectpath/
136 fi; 149 fi
137 fi; 150
138 151 echo "Updating files on board..."
139 cp "hvresources/HvUtils.h" $projectpath/; 152 # HvContext* files tend to hang when transferring with rsync because they are very large and -c checksum takes a lot, I guess
140 153 rsync -ac --out-format=" %n" --no-t --delete-after --exclude='HvContext*' --exclude=build --exclude=$BBB_PROJECT_NAME "$projectpath"/ "$BBB_NETWORK_TARGET_FOLDER" &&\
141 echo "updating files on board..." 154 { [ $NO_UPLOAD -eq 0 ] && scp "$projectpath"/HvContext* $BBB_NETWORK_TARGET_FOLDER; } ||\
142 155 { echo "ERROR: while synchronizing files with the BBB. Is the board connected?"; exit 1; }
143 rsync -c -rv --exclude 'HvContext*' "$projectpath"/ "$BBB_NETWORK_TARGET_FOLDER"; 156
144 if [ $NO_UPLOAD -eq 0 ]; then 157 # TODO: this should be run only when Heavy_bbb.h changes. Otherwise render is recompiled every time for no good reason
145 # for whatever reason these big files used to hang when transferring with rsync 158 ssh $BBB_ADDRESS "rm -rf ${BBB_PROJECT_FOLDER}/build/render.*"
146 scp "$projectpath"/HvContext* $BBB_NETWORK_TARGET_FOLDER 159
147 fi;
148
149 if [ $? -ne 0 ]; then
150 echo "";
151 echo ":( :( :( ERROR: while synchronizing files with the BBB. Is the board connected and the correct SD card inserted? :( :( :(";
152 echo "";
153 exit 1;
154 fi;
155 # exit
156 #produce a list of files which content has changed (not just the date) 160 #produce a list of files which content has changed (not just the date)
157 #TODO: could be made faster (perhaps) by backing up the folder locally instead of bbb 161 #TODO: could be made faster (perhaps) by backing up the folder locally instead of bbb
158 # UPDATED_FILES=`rsync -naic --log-format="%f" "$projectpath" "$BBB_BELA_HOME"/source | grep -v "\.$"` 162 # UPDATED_FILES=`rsync -naic --log-format="%f" "$projectpath" "$BBB_BELA_HOME"/source | grep -v "\.$"`
159 # echo "UPDATEDFILES : $UPDATED_FILES" 163 # echo "UPDATEDFILES : $UPDATED_FILES"
160 # exit 2 164 # exit 2
161 # remove old executable and heavy context .o/.d files 165 # remove old executable and heavy context .o/.d files
162 if [ $NO_UPLOAD -eq 0 ]; then 166 if [ $NO_UPLOAD -eq 0 ]; then
163 ssh $BBB_ADDRESS "rm -rf "$BBB_PROJECT_FOLDER/$BBB_PROJECT_NAME; 167 ssh $BBB_ADDRESS "rm -rf "$BBB_PROJECT_FOLDER/$BBB_PROJECT_NAME;
164 fi; 168 fi;
165 # Make new Bela execut/able and run 169 # Make new Bela executable and run
166 # It does not look very nice that we type the same things over and over 170 # It does not look very nice that we type the same things over and over
167 # but that is because each line is an ssh session in its own right 171 # but that is because each line is an ssh session in its own right
168 MAKE_COMMAND="make stop -C $BBB_BELA_HOME PROJECT='$BBB_PROJECT_NAME' CL='$COMMAND_ARGS'" 172 MAKE_COMMAND="make stop -C $BBB_BELA_HOME PROJECT='$BBB_PROJECT_NAME' CL='$COMMAND_ARGS'"
169 if [ $RUN_PROJECT -eq 0 ] 173 if [ $RUN_PROJECT -eq 0 ]
170 then 174 then