@@ -54,6 +54,8 @@ function check_requirements { # check_requirements <sketchdir> <sdkconfig_path>
5454}
5555
5656function build_sketch { # build_sketch <ide_path> <user_path> <path-to-ino> [extra-options]
57+ local first_only=false
58+
5759 while [ -n " $1 " ]; do
5860 case " $1 " in
5961 -ai )
@@ -92,6 +94,36 @@ function build_sketch { # build_sketch <ide_path> <user_path> <path-to-ino> [ext
9294 shift
9395 debug_level=" DebugLevel=$1 "
9496 ;;
97+ -b )
98+ shift
99+ custom_build_dir=$1
100+ ;;
101+ --first-only )
102+ first_only=true
103+ ;;
104+ -h )
105+ echo " Usage: build_sketch [options]"
106+ echo " "
107+ echo " Build an Arduino sketch for ESP32 targets."
108+ echo " "
109+ echo " Required options:"
110+ echo " -ai <path> Arduino IDE path"
111+ echo " -au <path> Arduino user path"
112+ echo " -s <path> Sketch directory containing .ino file and ci.yml"
113+ echo " -t <target> Target chip (esp32, esp32s2, esp32c3, esp32s3, esp32c6, esp32h2, esp32p4, esp32c5)"
114+ echo " Required unless -fqbn is specified"
115+ echo " "
116+ echo " Optional options:"
117+ echo " -fqbn <fqbn> Fully qualified board name (alternative to -t)"
118+ echo " -o <options> Board options (PSRAM, USBMode, etc.) [default: chip-specific]"
119+ echo " -i <index> Chunk index for parallel builds [default: none]"
120+ echo " -l <file> Log compilation output to JSON file [default: none]"
121+ echo " -d <level> Debug level (DebugLevel=...) [default: none]"
122+ echo " -b <path> Custom build directory [default: \$ ARDUINO_BUILD_DIR or \$ HOME/.arduino/tests/\$ target/\$ sketchname/build.tmp]"
123+ echo " --first-only Build only the first FQBN from ci.yml configurations [default: false]"
124+ echo " -h Show this help message"
125+ exit 0
126+ ;;
95127 * )
96128 break
97129 ;;
@@ -128,7 +160,15 @@ function build_sketch { # build_sketch <ide_path> <user_path> <path-to-ino> [ext
128160
129161 len=$( yq eval " .fqbn.${target} | length" " $sketchdir " /ci.yml 2> /dev/null || echo 0)
130162 if [ " $len " -gt 0 ]; then
131- fqbn=$( yq eval " .fqbn.${target} | sort | @json" " $sketchdir " /ci.yml)
163+ if [ " $first_only " = true ]; then
164+ # Get only the first FQBN from the array (original order)
165+ fqbn=$( yq eval " .fqbn.${target} | .[0]" " $sketchdir " /ci.yml 2> /dev/null)
166+ fqbn=" [\" $fqbn \" ]"
167+ len=1
168+ else
169+ # Build all FQBNs
170+ fqbn=$( yq eval " .fqbn.${target} | sort | @json" " $sketchdir " /ci.yml)
171+ fi
132172 fi
133173 fi
134174
@@ -219,12 +259,14 @@ function build_sketch { # build_sketch <ide_path> <user_path> <path-to-ino> [ext
219259 fi
220260
221261 # The directory that will hold all the artifacts (the build directory) is
222- # provided through:
223- # 1. An env variable called ARDUINO_BUILD_DIR.
224- # 2. Created at the sketch level as "build" in the case of a single
225- # configuration test.
226- # 3. Created at the sketch level as "buildX" where X is the number
227- # of configuration built in case of a multiconfiguration test.
262+ # determined by the following priority:
263+ # 1. Custom build directory via -b flag:
264+ # - If path contains "docs/_static/binaries", use as exact path (for docs builds)
265+ # - Otherwise, append target name to custom directory
266+ # 2. ARDUINO_BUILD_DIR environment variable (if set)
267+ # 3. Default: $HOME/.arduino/tests/$target/$sketchname/build.tmp
268+ #
269+ # For multiple configurations, subsequent builds use .1, .2, etc. suffixes
228270
229271 sketchname=$( basename " $sketchdir " )
230272 local has_requirements
@@ -253,22 +295,34 @@ function build_sketch { # build_sketch <ide_path> <user_path> <path-to-ino> [ext
253295 fi
254296
255297 ARDUINO_CACHE_DIR=" $HOME /.arduino/cache.tmp"
256- if [ -n " $ARDUINO_BUILD_DIR " ]; then
257- build_dir=" $ARDUINO_BUILD_DIR "
258- elif [ " $len " -eq 1 ]; then
259- # build_dir="$sketchdir/build"
260- build_dir=" $HOME /.arduino/tests/$target /$sketchname /build.tmp"
298+
299+ # Determine base build directory
300+ if [ -n " $custom_build_dir " ]; then
301+ # If custom_build_dir contains docs/_static/binaries, use it as exact path
302+ if [[ " $custom_build_dir " == * " docs/_static/binaries" * ]]; then
303+ build_dir_base=" $custom_build_dir "
304+ else
305+ build_dir_base=" $custom_build_dir /$target "
306+ fi
307+ elif [ -n " $ARDUINO_BUILD_DIR " ]; then
308+ build_dir_base=" $ARDUINO_BUILD_DIR "
309+ else
310+ build_dir_base=" $HOME /.arduino/tests/$target /$sketchname /build.tmp"
261311 fi
262312
263313 output_file=" $HOME /.arduino/cli_compile_output.txt"
264314 sizes_file=" $GITHUB_WORKSPACE /cli_compile_$chunk_index .json"
265315
266316 mkdir -p " $ARDUINO_CACHE_DIR "
267317 for i in $( seq 0 $(( len - 1 )) ) ; do
268- if [ " $len " -ne 1 ]; then
269- # build_dir="$sketchdir/build$i"
270- build_dir=" $HOME /.arduino/tests/$target /$sketchname /build$i .tmp"
318+ # Calculate build directory for this configuration
319+ if [ " $i " -eq 0 ]; then
320+ build_dir=" $build_dir_base "
321+ else
322+ build_dir=" ${build_dir_base} .${i} "
271323 fi
324+
325+ # Prepare build directory
272326 rm -rf " $build_dir "
273327 mkdir -p " $build_dir "
274328
0 commit comments