1
1
#! /bin/bash
2
2
3
- function build_sketch(){ # build_sketch <ide_path> <user_path> <fqbn> <path-to-ino> [extra-options]
4
- if [ " $# " -lt 4 ]; then
5
- echo " ERROR: Illegal number of parameters"
6
- echo " USAGE: ${0} build <ide_path> <user_path> <fqbn> <path-to-ino> [extra-options]"
7
- return 1
3
+ function build_sketch(){ # build_sketch <ide_path> <user_path> <path-to-ino> [extra-options]
4
+ while [ ! -z " $1 " ]; do
5
+ case " $1 " in
6
+ -ai )
7
+ shift
8
+ ide_path=$1
9
+ ;;
10
+ -au )
11
+ shift
12
+ user_path=$1
13
+ ;;
14
+ -t )
15
+ shift
16
+ target=$1
17
+ ;;
18
+ -fqbn )
19
+ shift
20
+ fqbn=$1
21
+ ;;
22
+ -o )
23
+ shift
24
+ options=$1
25
+ ;;
26
+ -s )
27
+ shift
28
+ sketchdir=$1
29
+ ;;
30
+ * )
31
+ break
32
+ ;;
33
+ esac
34
+ shift
35
+ done
36
+
37
+ xtra_opts=$*
38
+
39
+ if [ -z $sketchdir ]; then
40
+ echo " ERROR: Sketch directory not provided"
41
+ echo " $USAGE "
42
+ exit 1
8
43
fi
9
44
10
- local ide_path=$1
11
- local usr_path=$2
12
- local fqbn=$3
13
- local sketch=$4
14
- local xtra_opts=$5
15
- local win_opts=$6
45
+ # No FQBN was passed, try to get it from other options
46
+
47
+ if [ -z $fqbn ]; then
48
+ if [ -z $target ]; then
49
+ echo " ERROR: Unspecified chip"
50
+ echo " $USAGE "
51
+ exit 1
52
+ fi
53
+
54
+ # The options are either stored in the test directory, for a per test
55
+ # customization or passed as parameters. Command line options take
56
+ # precedence. Note that the following logic also falls to the default
57
+ # parameters if no arguments were passed and no file was found.
58
+
59
+ if [ -z $options ] && [ -f $sketchdir /cfg.json ]; then
60
+ # The config file could contain multiple FQBNs for one chip. If
61
+ # that's the case we build one time for every FQBN.
62
+
63
+ len=` jq -r --arg chip $target ' .targets[] | select(.name==$chip) | .fqbn | length' $sketchdir /cfg.json`
64
+ fqbn=` jq -r --arg chip $target ' .targets[] | select(.name==$chip) | .fqbn' $sketchdir /cfg.json`
65
+ else
66
+ # Since we are passing options, we will end up with only one FQBN to
67
+ # build.
68
+
69
+ len=1
70
+
71
+ # Default FQBN options if none were passed in the command line.
72
+
73
+ esp32_opts=" PSRAM=enabled,PartitionScheme=huge_app"
74
+ esp32s2_opts=" PSRAM=enabled,PartitionScheme=huge_app"
75
+ esp32s3_opts=" PSRAM=opi,USBMode=default,PartitionScheme=huge_app"
76
+ esp32c3_opts=" PartitionScheme=huge_app"
77
+
78
+ # Select the common part of the FQBN based on the target. The rest will be
79
+ # appended depending on the passed options.
80
+
81
+ case " $target " in
82
+ " esp32" )
83
+ fqbn=" espressif:esp32:esp32:${options:- $esp32_opts } "
84
+ ;;
85
+ " esp32s2" )
86
+ fqbn=" espressif:esp32:esp32s2:${options:- $esp32s2_opts } "
87
+ ;;
88
+ " esp32c3" )
89
+ fqbn=" espressif:esp32:esp32c3:${options:- $esp32c3_opts } "
90
+ ;;
91
+ " esp32s3" )
92
+ fqbn=" espressif:esp32:esp32s3:${options:- $esp32s3_opts } "
93
+ ;;
94
+ esac
95
+
96
+ # Make it look like a JSON array.
97
+
98
+ fqbn=" [\" $fqbn \" ]"
99
+ fi
100
+ else
101
+ # An FQBN was passed. Make it look like a JSON array.
102
+
103
+ len=1
104
+ fqbn=" [\" $fqbn \" ]"
105
+ fi
106
+
107
+ if [ -z " $fqbn " ]; then
108
+ echo " No FQBN passed or unvalid chip: $target "
109
+ exit 1
110
+ fi
16
111
17
112
ARDUINO_CACHE_DIR=" $HOME /.arduino/cache.tmp"
18
113
if [ -z " $ARDUINO_BUILD_DIR " ]; then
19
- build_dir=" $( dirname $sketch ) /build"
114
+ build_dir=" $sketchdir /build"
20
115
else
21
116
build_dir=" $ARDUINO_BUILD_DIR "
22
117
fi
23
118
24
- echo $sketch
25
-
26
- rm -rf " $build_dir "
27
- mkdir -p " $build_dir "
28
119
mkdir -p " $ARDUINO_CACHE_DIR "
29
- $ide_path /arduino-builder -compile -logger=human -core-api-version=10810 \
30
- -fqbn=$fqbn \
31
- -warnings=" all" \
32
- -tools " $ide_path /tools-builder" \
33
- -tools " $ide_path /tools" \
34
- -built-in-libraries " $ide_path /libraries" \
35
- -hardware " $ide_path /hardware" \
36
- -hardware " $usr_path /hardware" \
37
- -libraries " $usr_path /libraries" \
38
- -build-cache " $ARDUINO_CACHE_DIR " \
39
- -build-path " $build_dir " \
40
- $win_opts $xtra_opts " $sketch "
120
+ for i in ` seq 0 $(( $len - 1 )) `
121
+ do
122
+ rm -rf " $build_dir$i "
123
+ mkdir -p " $build_dir$i "
124
+ currfqbn=` echo $fqbn | jq -r --argjson i $i ' .[$i]' `
125
+ sketchname=$( basename $sketchdir )
126
+ echo " Building $sketchname with FQBN=$currfqbn "
127
+ $ide_path /arduino-builder -compile -logger=human -core-api-version=10810 \
128
+ -fqbn=\" $currfqbn \" \
129
+ -warnings=" all" \
130
+ -tools " $ide_path /tools-builder" \
131
+ -tools " $ide_path /tools" \
132
+ -built-in-libraries " $ide_path /libraries" \
133
+ -hardware " $ide_path /hardware" \
134
+ -hardware " $user_path /hardware" \
135
+ -libraries " $user_path /libraries" \
136
+ -build-cache " $ARDUINO_CACHE_DIR " \
137
+ -build-path " $build_dir$i " \
138
+ $xtra_opts " ${sketchdir} /${sketchname} .ino"
139
+ done
41
140
}
42
141
43
142
function count_sketches(){ # count_sketches <path> [target]
@@ -73,29 +172,63 @@ function count_sketches(){ # count_sketches <path> [target]
73
172
return $sketchnum
74
173
}
75
174
76
- function build_sketches(){ # build_sketches <ide_path> <user_path> <fqbn> <target> <path> <chunk> <total-chunks> [extra-options]
77
- local ide_path=$1
78
- local usr_path=$2
79
- local fqbn=$3
80
- local target=$4
81
- local path=$5
82
- local chunk_idex=$6
83
- local chunks_num=$7
84
- local xtra_opts=$8
85
-
86
- if [ " $# " -lt 7 ]; then
87
- echo " ERROR: Illegal number of parameters"
88
- echo " USAGE: ${0} chunk_build <ide_path> <user_path> <fqbn> <target> <path> [<chunk> <total-chunks>] [extra-options]"
89
- return 1
175
+ function build_sketches(){ # build_sketches <ide_path> <user_path> <target> <path> <chunk> <total-chunks> [extra-options]
176
+
177
+ local args=" "
178
+ while [ ! -z " $1 " ]; do
179
+ case $1 in
180
+ -ai )
181
+ shift
182
+ ide_path=$1
183
+ ;;
184
+ -au )
185
+ shift
186
+ user_path=$1
187
+ ;;
188
+ -t )
189
+ shift
190
+ target=$1
191
+ args+=" -t $target "
192
+ ;;
193
+ -fqbn )
194
+ shift
195
+ fqbn=$1
196
+ args+=" -fqbn $fqbn "
197
+ ;;
198
+ -p )
199
+ shift
200
+ path=$1
201
+ ;;
202
+ -i )
203
+ shift
204
+ chunk_index=$1
205
+ ;;
206
+ -m )
207
+ shift
208
+ chunk_max=$1
209
+ ;;
210
+ * )
211
+ break
212
+ ;;
213
+ esac
214
+ shift
215
+ done
216
+
217
+ local xtra_opts=$*
218
+
219
+ if [ -z $chunk_index ] || [ -z $chunk_max ]; then
220
+ echo " ERROR: Invalid chunk paramters"
221
+ echo " $USAGE "
222
+ exit 1
90
223
fi
91
224
92
- if [ " $chunks_num " -le 0 ]; then
225
+ if [ " $chunk_max " -le 0 ]; then
93
226
echo " ERROR: Chunks count must be positive number"
94
227
return 1
95
228
fi
96
- if [ " $chunk_idex " -ge " $chunks_num " ] && [ " $chunks_num " -ge 2 ] ; then
97
- echo " ERROR: Chunk index must be less than chunks count "
98
- return 1
229
+
230
+ if [ " $chunk_index " -gt " $chunk_max " ] && [ " $chunk_max " -ge 2 ] ; then
231
+ chunk_index= $chunk_max
99
232
fi
100
233
101
234
set +e
@@ -105,51 +238,52 @@ function build_sketches(){ # build_sketches <ide_path> <user_path> <fqbn> <targe
105
238
local sketches=$( cat sketches.txt)
106
239
rm -rf sketches.txt
107
240
108
- local chunk_size=$(( $sketchcount / $chunks_num ))
109
- local all_chunks=$(( $chunks_num * $chunk_size ))
241
+ local chunk_size=$(( $sketchcount / $chunk_max ))
242
+ local all_chunks=$(( $chunk_max * $chunk_size ))
110
243
if [ " $all_chunks " -lt " $sketchcount " ]; then
111
244
chunk_size=$(( $chunk_size + 1 ))
112
245
fi
113
246
114
247
local start_index=0
115
248
local end_index=0
116
- if [ " $chunk_idex " -ge " $chunks_num " ]; then
117
- start_index=$chunk_idex
249
+ if [ " $chunk_index " -ge " $chunk_max " ]; then
250
+ start_index=$chunk_index
118
251
end_index=$sketchcount
119
252
else
120
- start_index=$(( $chunk_idex * $chunk_size ))
253
+ start_index=$(( $chunk_index * $chunk_size ))
121
254
if [ " $sketchcount " -le " $start_index " ]; then
122
255
echo " Skipping job"
123
256
return 0
124
257
fi
125
258
126
- end_index=$(( $(( $chunk_idex + 1 )) * $chunk_size ))
259
+ end_index=$(( $(( $chunk_index + 1 )) * $chunk_size ))
127
260
if [ " $end_index " -gt " $sketchcount " ]; then
128
261
end_index=$sketchcount
129
262
fi
130
263
fi
131
264
132
265
local start_num=$(( $start_index + 1 ))
133
266
echo " Found $sketchcount Sketches for target '$target '" ;
134
- echo " Chunk Index : $chunk_idex "
135
- echo " Chunk Count : $chunks_num "
267
+ echo " Chunk Index : $chunk_index "
268
+ echo " Chunk Count : $chunk_max "
136
269
echo " Chunk Size : $chunk_size "
137
270
echo " Start Sketch: $start_num "
138
271
echo " End Sketch : $end_index "
139
272
140
273
local sketchnum=0
274
+ args+=" -ai $ide_path -au $user_path "
141
275
for sketch in $sketches ; do
142
276
local sketchdir=$( dirname $sketch )
143
277
local sketchdirname=$( basename $sketchdir )
144
- local sketchname=$( basename $sketch )
145
278
sketchnum=$(( $sketchnum + 1 ))
146
279
if [ " $sketchnum " -le " $start_index " ] \
147
280
|| [ " $sketchnum " -gt " $end_index " ]; then
148
281
continue
149
282
fi
150
283
echo " "
151
284
echo " Building Sketch Index $(( $sketchnum - 1 )) - $sketchdirname "
152
- build_sketch " $ide_path " " $usr_path " " $fqbn " " $sketch " " $xtra_opts "
285
+ args+=" -s $sketchdir $xtra_opts "
286
+ build_sketch $args
153
287
local result=$?
154
288
if [ $result -ne 0 ]; then
155
289
return $result
@@ -169,24 +303,21 @@ Available commands:
169
303
cmd=$1
170
304
shift
171
305
if [ -z $cmd ]; then
172
- echo " ERROR: No command supplied"
173
- echo " $USAGE "
174
- exit 2
306
+ echo " ERROR: No command supplied"
307
+ echo " $USAGE "
308
+ exit 2
175
309
fi
176
310
177
311
case " $cmd " in
178
- " count" )
179
- count_sketches $*
312
+ " count" ) count_sketches $*
180
313
;;
181
- " build" )
182
- build_sketch $*
314
+ " build" ) build_sketch $*
183
315
;;
184
- " chunk_build" )
185
- build_sketches $*
316
+ " chunk_build" ) build_sketches $*
186
317
;;
187
- * )
188
- echo " ERROR: Unrecognized command"
189
- echo " $USAGE "
190
- exit 2
318
+ * )
319
+ echo " ERROR: Unrecognized command"
320
+ echo " $USAGE "
321
+ exit 2
191
322
esac
192
323
0 commit comments