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