8
8
SDKCONFIG_DIR=" tools/esp32-arduino-libs"
9
9
fi
10
10
11
+ function check_requirements(){ # check_requirements <sketchdir> <sdkconfig_path>
12
+ local sketchdir=$1
13
+ local sdkconfig_path=$2
14
+ local has_requirements=1
15
+
16
+ if [ ! -f " $sdkconfig_path " ] || [ ! -f " $sketchdir /ci.json" ]; then
17
+ echo " ERROR: sdkconfig or ci.json not found" 1>&2
18
+ # Return 1 on error to force the sketch to be built and fail. This way the
19
+ # CI will fail and the user will know that the sketch has a problem.
20
+ else
21
+ # Check if the sketch requires any configuration options (AND)
22
+ local requirements=$( jq -r ' .requires[]? // empty' " $sketchdir /ci.json" )
23
+ if [[ " $requirements " != " null" && " $requirements " != " " ]]; then
24
+ for requirement in $requirements ; do
25
+ requirement=$( echo $requirement | xargs)
26
+ found_line=$( grep -E " ^$requirement " " $sdkconfig_path " )
27
+ if [[ " $found_line " == " " ]]; then
28
+ has_requirements=0
29
+ fi
30
+ done
31
+ fi
32
+
33
+ # Check if the sketch requires any configuration options (OR)
34
+ local requirements_or=$( jq -r ' .requires_any[]? // empty' " $sketchdir /ci.json" )
35
+ if [[ " $requirements_or " != " null" && " $requirements_or " != " " ]]; then
36
+ local found=false
37
+ for requirement in $requirements_or ; do
38
+ requirement=$( echo $requirement | xargs)
39
+ found_line=$( grep -E " ^$requirement " " $sdkconfig_path " )
40
+ if [[ " $found_line " != " " ]]; then
41
+ found=true
42
+ break
43
+ fi
44
+ done
45
+ if [[ " $found " == " false" ]]; then
46
+ has_requirements=0
47
+ fi
48
+ fi
49
+ fi
50
+
51
+ echo $has_requirements
52
+ }
53
+
11
54
function build_sketch(){ # build_sketch <ide_path> <user_path> <path-to-ino> [extra-options]
12
55
while [ ! -z " $1 " ]; do
13
56
case " $1 " in
@@ -171,35 +214,10 @@ function build_sketch(){ # build_sketch <ide_path> <user_path> <path-to-ino> [ex
171
214
exit 0
172
215
fi
173
216
174
- # Check if the sketch requires any configuration options (AND)
175
- requirements=$( jq -r ' .requires[]? // empty' $sketchdir /ci.json)
176
- if [[ " $requirements " != " null" && " $requirements " != " " ]]; then
177
- for requirement in $requirements ; do
178
- requirement=$( echo $requirement | xargs)
179
- found_line=$( grep -E " ^$requirement " " $SDKCONFIG_DIR /$target /sdkconfig" )
180
- if [[ " $found_line " == " " ]]; then
181
- echo " Target $target does not meet the requirement $requirement for $sketchname . Skipping."
182
- exit 0
183
- fi
184
- done
185
- fi
186
-
187
- # Check if the sketch excludes any configuration options (OR)
188
- requirements_or=$( jq -r ' .requires_any[]? // empty' $sketchdir /ci.json)
189
- if [[ " $requirements_or " != " null" && " $requirements_or " != " " ]]; then
190
- found=false
191
- for requirement in $requirements_or ; do
192
- requirement=$( echo $requirement | xargs)
193
- found_line=$( grep -E " ^$requirement " " $SDKCONFIG_DIR /$target /sdkconfig" )
194
- if [[ " $found_line " != " " ]]; then
195
- found=true
196
- break
197
- fi
198
- done
199
- if [[ " $found " == " false" ]]; then
200
- echo " Target $target meets none of the requirements in requires_any for $sketchname . Skipping."
201
- exit 0
202
- fi
217
+ local has_requirements=$( check_requirements " $sketchdir " " $SDKCONFIG_DIR /$target /sdkconfig" )
218
+ if [ " $has_requirements " == " 0" ]; then
219
+ echo " Target $target does not meet the requirements for $sketchname . Skipping."
220
+ exit 0
203
221
fi
204
222
fi
205
223
@@ -348,33 +366,9 @@ function count_sketches(){ # count_sketches <path> [target] [file] [ignore-requi
348
366
fi
349
367
350
368
if [ " $ignore_requirements " != " 1" ]; then
351
- # Check if the sketch requires any configuration options (AND)
352
- requirements=$( jq -r ' .requires[]? // empty' $sketchdir /ci.json)
353
- if [[ " $requirements " != " null" && " $requirements " != " " ]]; then
354
- for requirement in $requirements ; do
355
- requirement=$( echo $requirement | xargs)
356
- found_line=$( grep -E " ^$requirement " $SDKCONFIG_DIR /$target /sdkconfig)
357
- if [[ " $found_line " == " " ]]; then
358
- continue 2
359
- fi
360
- done
361
- fi
362
-
363
- # Check if the sketch excludes any configuration options (OR)
364
- requirements_or=$( jq -r ' .requires_any[]? // empty' $sketchdir /ci.json)
365
- if [[ " $requirements_or " != " null" && " $requirements_or " != " " ]]; then
366
- found=false
367
- for requirement in $requirements_or ; do
368
- requirement=$( echo $requirement | xargs)
369
- found_line=$( grep -E " ^$requirement " $SDKCONFIG_DIR /$target /sdkconfig)
370
- if [[ " $found_line " != " " ]]; then
371
- found=true
372
- break
373
- fi
374
- done
375
- if [[ " $found " == " false" ]]; then
376
- continue 2
377
- fi
369
+ local has_requirements=$( check_requirements " $sketchdir " " $SDKCONFIG_DIR /$target /sdkconfig" )
370
+ if [ " $has_requirements " == " 0" ]; then
371
+ continue
378
372
fi
379
373
fi
380
374
fi
@@ -552,6 +546,7 @@ Available commands:
552
546
count: Count sketches.
553
547
build: Build a sketch.
554
548
chunk_build: Build a chunk of sketches.
549
+ check_requirements: Check if target meets sketch requirements.
555
550
"
556
551
557
552
cmd=$1
@@ -569,6 +564,8 @@ case "$cmd" in
569
564
;;
570
565
" chunk_build" ) build_sketches $*
571
566
;;
567
+ " check_requirements" ) check_requirements $*
568
+ ;;
572
569
* )
573
570
echo " ERROR: Unrecognized command"
574
571
echo " $USAGE "
0 commit comments