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
@@ -176,35 +219,10 @@ function build_sketch(){ # build_sketch <ide_path> <user_path> <path-to-ino> [ex
176
219
exit 0
177
220
fi
178
221
179
- # Check if the sketch requires any configuration options (AND)
180
- requirements=$( jq -r ' .requires[]? // empty' $sketchdir /ci.json)
181
- if [[ " $requirements " != " null" && " $requirements " != " " ]]; then
182
- for requirement in $requirements ; do
183
- requirement=$( echo $requirement | xargs)
184
- found_line=$( grep -E " ^$requirement " " $SDKCONFIG_DIR /$target /sdkconfig" )
185
- if [[ " $found_line " == " " ]]; then
186
- echo " Target $target does not meet the requirement $requirement for $sketchname . Skipping."
187
- exit 0
188
- fi
189
- done
190
- fi
191
-
192
- # Check if the sketch excludes any configuration options (OR)
193
- requirements_or=$( jq -r ' .requires_any[]? // empty' $sketchdir /ci.json)
194
- if [[ " $requirements_or " != " null" && " $requirements_or " != " " ]]; then
195
- found=false
196
- for requirement in $requirements_or ; do
197
- requirement=$( echo $requirement | xargs)
198
- found_line=$( grep -E " ^$requirement " " $SDKCONFIG_DIR /$target /sdkconfig" )
199
- if [[ " $found_line " != " " ]]; then
200
- found=true
201
- break
202
- fi
203
- done
204
- if [[ " $found " == " false" ]]; then
205
- echo " Target $target meets none of the requirements in requires_any for $sketchname . Skipping."
206
- exit 0
207
- fi
222
+ local has_requirements=$( check_requirements " $sketchdir " " $SDKCONFIG_DIR /$target /sdkconfig" )
223
+ if [ " $has_requirements " == " 0" ]; then
224
+ echo " Target $target does not meet the requirements for $sketchname . Skipping."
225
+ exit 0
208
226
fi
209
227
fi
210
228
@@ -353,33 +371,9 @@ function count_sketches(){ # count_sketches <path> [target] [file] [ignore-requi
353
371
fi
354
372
355
373
if [ " $ignore_requirements " != " 1" ]; then
356
- # Check if the sketch requires any configuration options (AND)
357
- requirements=$( jq -r ' .requires[]? // empty' $sketchdir /ci.json)
358
- if [[ " $requirements " != " null" && " $requirements " != " " ]]; then
359
- for requirement in $requirements ; do
360
- requirement=$( echo $requirement | xargs)
361
- found_line=$( grep -E " ^$requirement " $SDKCONFIG_DIR /$target /sdkconfig)
362
- if [[ " $found_line " == " " ]]; then
363
- continue 2
364
- fi
365
- done
366
- fi
367
-
368
- # Check if the sketch excludes any configuration options (OR)
369
- requirements_or=$( jq -r ' .requires_any[]? // empty' $sketchdir /ci.json)
370
- if [[ " $requirements_or " != " null" && " $requirements_or " != " " ]]; then
371
- found=false
372
- for requirement in $requirements_or ; do
373
- requirement=$( echo $requirement | xargs)
374
- found_line=$( grep -E " ^$requirement " $SDKCONFIG_DIR /$target /sdkconfig)
375
- if [[ " $found_line " != " " ]]; then
376
- found=true
377
- break
378
- fi
379
- done
380
- if [[ " $found " == " false" ]]; then
381
- continue 2
382
- fi
374
+ local has_requirements=$( check_requirements " $sketchdir " " $SDKCONFIG_DIR /$target /sdkconfig" )
375
+ if [ " $has_requirements " == " 0" ]; then
376
+ continue
383
377
fi
384
378
fi
385
379
fi
@@ -557,6 +551,7 @@ Available commands:
557
551
count: Count sketches.
558
552
build: Build a sketch.
559
553
chunk_build: Build a chunk of sketches.
554
+ check_requirements: Check if target meets sketch requirements.
560
555
"
561
556
562
557
cmd=$1
@@ -574,6 +569,8 @@ case "$cmd" in
574
569
;;
575
570
" chunk_build" ) build_sketches $*
576
571
;;
572
+ " check_requirements" ) check_requirements $*
573
+ ;;
577
574
* )
578
575
echo " ERROR: Unrecognized command"
579
576
echo " $USAGE "
0 commit comments