|
34 | 34 | fi |
35 | 35 | export OS_NAME |
36 | 36 |
|
37 | | -ARDUINO_BUILD_DIR="$HOME/.arduino/build.tmp" |
38 | | -ARDUINO_CACHE_DIR="$HOME/.arduino/cache.tmp" |
39 | | - |
40 | 37 | if [ "$OS_IS_MACOS" == "1" ]; then |
41 | 38 | export ARDUINO_IDE_PATH="/Applications/Arduino.app/Contents/Java" |
42 | 39 | export ARDUINO_USR_PATH="$HOME/Documents/Arduino" |
@@ -81,156 +78,3 @@ if [ ! -d "$ARDUINO_IDE_PATH" ]; then |
81 | 78 | echo "" |
82 | 79 | fi |
83 | 80 |
|
84 | | -function build_sketch(){ # build_sketch <fqbn> <path-to-ino> [extra-options] |
85 | | - if [ "$#" -lt 2 ]; then |
86 | | - echo "ERROR: Illegal number of parameters" |
87 | | - echo "USAGE: build_sketch <fqbn> <path-to-ino> [extra-options]" |
88 | | - return 1 |
89 | | - fi |
90 | | - |
91 | | - local fqbn="$1" |
92 | | - local sketch="$2" |
93 | | - local xtra_opts="$3" |
94 | | - local win_opts="" |
95 | | - if [ "$OS_IS_WINDOWS" == "1" ]; then |
96 | | - local ctags_version=`ls "$ARDUINO_IDE_PATH/tools-builder/ctags/"` |
97 | | - local preprocessor_version=`ls "$ARDUINO_IDE_PATH/tools-builder/arduino-preprocessor/"` |
98 | | - win_opts="-prefs=runtime.tools.ctags.path=$ARDUINO_IDE_PATH/tools-builder/ctags/$ctags_version -prefs=runtime.tools.arduino-preprocessor.path=$ARDUINO_IDE_PATH/tools-builder/arduino-preprocessor/$preprocessor_version" |
99 | | - fi |
100 | | - |
101 | | - #echo "" |
102 | | - #echo "Compiling '"$(basename "$sketch")"' ..." |
103 | | - mkdir -p "$ARDUINO_BUILD_DIR" |
104 | | - mkdir -p "$ARDUINO_CACHE_DIR" |
105 | | - $ARDUINO_IDE_PATH/arduino-builder -compile -logger=human -core-api-version=10810 \ |
106 | | - -fqbn=$fqbn \ |
107 | | - -warnings="all" \ |
108 | | - -tools "$ARDUINO_IDE_PATH/tools-builder" \ |
109 | | - -tools "$ARDUINO_IDE_PATH/tools" \ |
110 | | - -built-in-libraries "$ARDUINO_IDE_PATH/libraries" \ |
111 | | - -hardware "$ARDUINO_IDE_PATH/hardware" \ |
112 | | - -hardware "$ARDUINO_USR_PATH/hardware" \ |
113 | | - -libraries "$ARDUINO_USR_PATH/libraries" \ |
114 | | - -build-cache "$ARDUINO_CACHE_DIR" \ |
115 | | - -build-path "$ARDUINO_BUILD_DIR" \ |
116 | | - $win_opts $xtra_opts "$sketch" |
117 | | -} |
118 | | - |
119 | | -function count_sketches(){ # count_sketches <examples-path> <target-mcu> |
120 | | - local examples="$1" |
121 | | - local target="$2" |
122 | | - rm -rf sketches.txt |
123 | | - if [ ! -d "$examples" ]; then |
124 | | - touch sketches.txt |
125 | | - return 0 |
126 | | - fi |
127 | | - local sketches=$(find $examples -name *.ino) |
128 | | - local sketchnum=0 |
129 | | - for sketch in $sketches; do |
130 | | - local sketchdir=$(dirname $sketch) |
131 | | - local sketchdirname=$(basename $sketchdir) |
132 | | - local sketchname=$(basename $sketch) |
133 | | - if [[ "$sketchdirname.ino" != "$sketchname" ]]; then |
134 | | - continue |
135 | | - elif [[ -f "$sketchdir/.skip.$target" ]]; then |
136 | | - continue |
137 | | - else |
138 | | - echo $sketch >> sketches.txt |
139 | | - sketchnum=$(($sketchnum + 1)) |
140 | | - fi |
141 | | - done |
142 | | - return $sketchnum |
143 | | -} |
144 | | - |
145 | | -function build_sketches(){ # build_sketches <fqbn> <target-mcu> <examples-path> <chunk> <total-chunks> [extra-options] |
146 | | - local fqbn=$1 |
147 | | - local target="$2" |
148 | | - local examples=$3 |
149 | | - local chunk_idex=$4 |
150 | | - local chunks_num=$5 |
151 | | - local xtra_opts=$6 |
152 | | - |
153 | | - if [ "$#" -lt 3 ]; then |
154 | | - echo "ERROR: Illegal number of parameters" |
155 | | - echo "USAGE: build_sketches <fqbn> <target-mcu <examples-path> [<chunk> <total-chunks>] [extra-options]" |
156 | | - return 1 |
157 | | - fi |
158 | | - |
159 | | - if [ "$#" -lt 5 ]; then |
160 | | - chunk_idex="0" |
161 | | - chunks_num="1" |
162 | | - xtra_opts=$4 |
163 | | - fi |
164 | | - |
165 | | - if [ "$chunks_num" -le 0 ]; then |
166 | | - echo "ERROR: Chunks count must be positive number" |
167 | | - return 1 |
168 | | - fi |
169 | | - if [ "$chunk_idex" -ge "$chunks_num" ] && [ "$chunks_num" -ge 2 ]; then |
170 | | - echo "ERROR: Chunk index must be less than chunks count" |
171 | | - return 1 |
172 | | - fi |
173 | | - |
174 | | - set +e |
175 | | - count_sketches "$examples" "$target" |
176 | | - local sketchcount=$? |
177 | | - set -e |
178 | | - local sketches=$(cat sketches.txt) |
179 | | - rm -rf sketches.txt |
180 | | - |
181 | | - local chunk_size=$(( $sketchcount / $chunks_num )) |
182 | | - local all_chunks=$(( $chunks_num * $chunk_size )) |
183 | | - if [ "$all_chunks" -lt "$sketchcount" ]; then |
184 | | - chunk_size=$(( $chunk_size + 1 )) |
185 | | - fi |
186 | | - |
187 | | - local start_index=0 |
188 | | - local end_index=0 |
189 | | - if [ "$chunk_idex" -ge "$chunks_num" ]; then |
190 | | - start_index=$chunk_idex |
191 | | - end_index=$sketchcount |
192 | | - else |
193 | | - start_index=$(( $chunk_idex * $chunk_size )) |
194 | | - if [ "$sketchcount" -le "$start_index" ]; then |
195 | | - echo "Skipping job" |
196 | | - return 0 |
197 | | - fi |
198 | | - |
199 | | - end_index=$(( $(( $chunk_idex + 1 )) * $chunk_size )) |
200 | | - if [ "$end_index" -gt "$sketchcount" ]; then |
201 | | - end_index=$sketchcount |
202 | | - fi |
203 | | - fi |
204 | | - |
205 | | - local start_num=$(( $start_index + 1 )) |
206 | | - echo "Found $sketchcount Sketches for target '$target'"; |
207 | | - echo "Chunk Index : $chunk_idex" |
208 | | - echo "Chunk Count : $chunks_num" |
209 | | - echo "Chunk Size : $chunk_size" |
210 | | - echo "Start Sketch: $start_num" |
211 | | - echo "End Sketch : $end_index" |
212 | | - |
213 | | - local sketchnum=0 |
214 | | - for sketch in $sketches; do |
215 | | - local sketchdir=$(dirname $sketch) |
216 | | - local sketchdirname=$(basename $sketchdir) |
217 | | - local sketchname=$(basename $sketch) |
218 | | - if [ "${sketchdirname}.ino" != "$sketchname" ] \ |
219 | | - || [ -f "$sketchdir/.skip.$target" ]; then |
220 | | - continue |
221 | | - fi |
222 | | - sketchnum=$(($sketchnum + 1)) |
223 | | - if [ "$sketchnum" -le "$start_index" ] \ |
224 | | - || [ "$sketchnum" -gt "$end_index" ]; then |
225 | | - continue |
226 | | - fi |
227 | | - echo "" |
228 | | - echo "Building Sketch Index $(($sketchnum - 1)) - $sketchdirname" |
229 | | - build_sketch "$fqbn" "$sketch" "$xtra_opts" |
230 | | - local result=$? |
231 | | - if [ $result -ne 0 ]; then |
232 | | - return $result |
233 | | - fi |
234 | | - done |
235 | | - return 0 |
236 | | -} |
0 commit comments