11#! /bin/bash
22
3+ if [ -d " $ARDUINO_ESP32_PATH /tools/esp32-arduino-libs" ]; then
4+ SDKCONFIG_DIR=" $ARDUINO_ESP32_PATH /tools/esp32-arduino-libs"
5+ elif [ -d " $GITHUB_WORKSPACE /tools/esp32-arduino-libs" ]; then
6+ SDKCONFIG_DIR=" $GITHUB_WORKSPACE /tools/esp32-arduino-libs"
7+ else
8+ SDKCONFIG_DIR=" tools/esp32-arduino-libs"
9+ fi
10+
311function build_sketch(){ # build_sketch <ide_path> <user_path> <path-to-ino> [extra-options]
412 while [ ! -z " $1 " ]; do
513 case " $1 " in
@@ -81,14 +89,21 @@ function build_sketch(){ # build_sketch <ide_path> <user_path> <path-to-ino> [ex
8189
8290 len=1
8391
92+ if [ -f $sketchdir /ci.json ]; then
93+ fqbn_append=` jq -r ' .fqbn_append' $sketchdir /ci.json`
94+ if [ $fqbn_append == " null" ]; then
95+ fqbn_append=" "
96+ fi
97+ fi
98+
8499 # Default FQBN options if none were passed in the command line.
85100
86- esp32_opts=" PSRAM=enabled,PartitionScheme=huge_app, FlashMode=dio"
87- esp32s2_opts=" PSRAM=enabled,PartitionScheme=huge_app, FlashMode=dio"
88- esp32s3_opts=" PSRAM=opi,USBMode=default,PartitionScheme=huge_app, FlashMode=dio"
89- esp32c3_opts=" PartitionScheme=huge_app, FlashMode=dio"
90- esp32c6_opts=" PartitionScheme=huge_app, FlashMode=dio"
91- esp32h2_opts=" PartitionScheme=huge_app, FlashMode=dio"
101+ esp32_opts=" PSRAM=enabled,FlashMode=dio${fqbn_append : +, $fqbn_append } "
102+ esp32s2_opts=" PSRAM=enabled,FlashMode=dio${fqbn_append : +, $fqbn_append } "
103+ esp32s3_opts=" PSRAM=opi,USBMode=default,FlashMode=dio${fqbn_append : +, $fqbn_append } "
104+ esp32c3_opts=" FlashMode=dio${fqbn_append : +, $fqbn_append } "
105+ esp32c6_opts=" FlashMode=dio${fqbn_append : +, $fqbn_append } "
106+ esp32h2_opts=" FlashMode=dio${fqbn_append : +, $fqbn_append } "
92107
93108 # Select the common part of the FQBN based on the target. The rest will be
94109 # appended depending on the passed options.
@@ -140,16 +155,26 @@ function build_sketch(){ # build_sketch <ide_path> <user_path> <path-to-ino> [ex
140155
141156 sketchname=$( basename $sketchdir )
142157
143- # If the target is listed as false, skip the sketch. Otherwise, include it.
144158 if [ -f $sketchdir /ci.json ]; then
159+ # If the target is listed as false, skip the sketch. Otherwise, include it.
145160 is_target=$( jq -r --arg target $target ' .targets[$target]' $sketchdir /ci.json)
146- else
147- is_target=" true"
148- fi
161+ if [[ " $is_target " == " false" ]]; then
162+ echo " Skipping $sketchname for target $target "
163+ exit 0
164+ fi
149165
150- if [[ " $is_target " == " false" ]]; then
151- echo " Skipping $sketchname for target $target "
152- exit 0
166+ # Check if the sketch requires any configuration options
167+ requirements=$( jq -r ' .requires[]? // empty' $sketchdir /ci.json)
168+ if [[ " $requirements " != " null" ]] || [[ " $requirements " != " " ]]; then
169+ for requirement in $requirements ; do
170+ requirement=$( echo $requirement | xargs)
171+ found_line=$( grep -E " ^$requirement " " $SDKCONFIG_DIR /$target /sdkconfig" )
172+ if [[ " $found_line " == " " ]]; then
173+ echo " Target $target does not meet the requirement $requirement for $sketchname . Skipping."
174+ exit 0
175+ fi
176+ done
177+ fi
153178 fi
154179
155180 ARDUINO_CACHE_DIR=" $HOME /.arduino/cache.tmp"
@@ -259,10 +284,11 @@ function build_sketch(){ # build_sketch <ide_path> <user_path> <path-to-ino> [ex
259284 unset options
260285}
261286
262- function count_sketches(){ # count_sketches <path> [target] [file]
287+ function count_sketches(){ # count_sketches <path> [target] [file] [ignore-requirements]
263288 local path=$1
264289 local target=$2
265- local file=$3
290+ local ignore_requirements=$3
291+ local file=$4
266292
267293 if [ $# -lt 1 ]; then
268294 echo " ERROR: Illegal number of parameters"
@@ -275,7 +301,7 @@ function count_sketches(){ # count_sketches <path> [target] [file]
275301 return 0
276302 fi
277303
278- if [ -n " $file " ]; then
304+ if [ -f " $file " ]; then
279305 local sketches=$( cat $file )
280306 else
281307 local sketches=$( find $path -name * .ino | sort)
@@ -288,16 +314,26 @@ function count_sketches(){ # count_sketches <path> [target] [file]
288314 local sketchname=$( basename $sketch )
289315 if [[ " $sketchdirname .ino" != " $sketchname " ]]; then
290316 continue
291- elif [[ -n $target ]]; then
317+ elif [[ -n $target ]] && [[ -f $sketchdir /ci.json ]] ; then
292318 # If the target is listed as false, skip the sketch. Otherwise, include it.
293- if [ -f $sketchdir /ci.json ]; then
294- is_target=$( jq -r --arg target $target ' .targets[$target]' $sketchdir /ci.json)
295- else
296- is_target=" true"
297- fi
319+ is_target=$( jq -r --arg target $target ' .targets[$target]' $sketchdir /ci.json)
298320 if [[ " $is_target " == " false" ]]; then
299321 continue
300322 fi
323+
324+ if [ " $ignore_requirements " != " 1" ]; then
325+ # Check if the sketch requires any configuration options
326+ requirements=$( jq -r ' .requires[]? // empty' $sketchdir /ci.json)
327+ if [[ " $requirements " != " null" ]] || [[ " $requirements " != " " ]]; then
328+ for requirement in $requirements ; do
329+ requirement=$( echo $requirement | xargs)
330+ found_line=$( grep -E " ^$requirement " $SDKCONFIG_DIR /$target /sdkconfig)
331+ if [[ " $found_line " == " " ]]; then
332+ continue 2
333+ fi
334+ done
335+ fi
336+ fi
301337 fi
302338 echo $sketch >> sketches.txt
303339 sketchnum=$(( $sketchnum + 1 ))
@@ -374,7 +410,7 @@ function build_sketches(){ # build_sketches <ide_path> <user_path> <target> <pat
374410
375411 set +e
376412 if [ -n " $sketches_file " ]; then
377- count_sketches " $path " " $target " " $sketches_file "
413+ count_sketches " $path " " $target " " 0 " " $sketches_file "
378414 local sketchcount=$?
379415 else
380416 count_sketches " $path " " $target "
0 commit comments