@@ -244,6 +244,14 @@ function build_sketch { # build_sketch <ide_path> <user_path> <path-to-ino> [ext
244244 fi
245245 fi
246246
247+ # Install libraries from ci.json if they exist
248+ install_libs -ai " $ide_path " -s " $sketchdir "
249+ local install_result=$?
250+ if [ $install_result -ne 0 ]; then
251+ echo " ERROR: Library installation failed for $sketchname "
252+ exit $install_result
253+ fi
254+
247255 ARDUINO_CACHE_DIR=" $HOME /.arduino/cache.tmp"
248256 if [ -n " $ARDUINO_BUILD_DIR " ]; then
249257 build_dir=" $ARDUINO_BUILD_DIR "
@@ -558,16 +566,16 @@ function build_sketches { # build_sketches <ide_path> <user_path> <target> <path
558566 continue
559567 fi
560568 echo " "
561- echo " Building Sketch Index $sketchnum - $sketchdirname "
562569
563570 # Install libraries from ci.json if they exist
564571 install_libs -ai " $ide_path " -s " $sketchdir "
565572 local install_result=$?
566573 if [ $install_result -ne 0 ]; then
567- echo " ERROR: Library installation failed for $sketchdirname "
568574 return $install_result
569575 fi
570576
577+ echo " Building Sketch Index $sketchnum - $sketchdirname "
578+
571579 build_sketch " ${args[@]} " -s " $sketchdir " " ${xtra_opts[@]} "
572580 local result=$?
573581 if [ $result -ne 0 ]; then
@@ -611,7 +619,7 @@ function install_libs { # install_libs <ide_path> <sketchdir> [-v]
611619 * )
612620 echo " ERROR: Unknown argument: $1 "
613621 echo " USAGE: install_libs -ai <ide_path> -s <sketchdir> [-v]"
614- return 1
622+ exit 1
615623 ;;
616624 esac
617625 shift
@@ -621,19 +629,19 @@ function install_libs { # install_libs <ide_path> <sketchdir> [-v]
621629 if [ -z " $ide_path " ]; then
622630 echo " ERROR: IDE path not provided"
623631 echo " USAGE: install_libs -ai <ide_path> -s <sketchdir> [-v]"
624- return 1
632+ exit 1
625633 fi
626634
627635 if [ -z " $sketchdir " ]; then
628636 echo " ERROR: Sketch directory not provided"
629637 echo " USAGE: install_libs -ai <ide_path> -s <sketchdir> [-v]"
630- return 1
638+ exit 1
631639 fi
632640
633641 # Check if arduino-cli exists
634642 if [ ! -f " $ide_path /arduino-cli" ]; then
635643 echo " ERROR: arduino-cli not found at $ide_path /arduino-cli"
636- return 1
644+ exit 1
637645 fi
638646
639647 # Check if ci.json exists
@@ -649,7 +657,7 @@ function install_libs { # install_libs <ide_path> <sketchdir> [-v]
649657 return 0
650658 elif [ " $libs_type " != " array" ]; then
651659 echo " ERROR: libs field in ci.json must be an array, found: $libs_type "
652- return 1
660+ exit 1
653661 fi
654662
655663 libs_count=$( jq -r ' .libs | length' " $sketchdir /ci.json" 2> /dev/null)
@@ -684,6 +692,7 @@ function install_libs { # install_libs <ide_path> <sketchdir> [-v]
684692 enable_status=$?
685693 if [ $enable_status -ne 0 ]; then
686694 echo " WARNING: Failed to enable unsafe installs, some libraries may fail to install"
695+ exit $enable_status
687696 fi
688697 else
689698 [ " $verbose " = true ] && echo " Unsafe installs already enabled"
@@ -705,9 +714,6 @@ function install_libs { # install_libs <ide_path> <sketchdir> [-v]
705714 # Capture both stdout and stderr, show only errors
706715 output=$( " $ide_path /arduino-cli" lib install --git-url " $lib " 2>&1 )
707716 install_status=$?
708- if [ $install_status -ne 0 ]; then
709- echo " $output " | grep -E " Error|WARNING|WARN" || echo " $output "
710- fi
711717 fi
712718 else
713719 # Library name (with optional version)
@@ -721,6 +727,7 @@ function install_libs { # install_libs <ide_path> <sketchdir> [-v]
721727 install_status=$?
722728 if [ $install_status -ne 0 ]; then
723729 echo " $output " | grep -E " Error|WARNING|WARN" || echo " $output "
730+ exit $install_status
724731 fi
725732 fi
726733 fi
@@ -732,7 +739,7 @@ function install_libs { # install_libs <ide_path> <sketchdir> [-v]
732739 [ " $verbose " = true ] && echo " Restoring original unsafe install setting..."
733740 " $ide_path /arduino-cli" config set library.enable_unsafe_install false > /dev/null 2>&1
734741 fi
735- return $install_status
742+ exit $install_status
736743 else
737744 [ " $verbose " = true ] && echo " Successfully installed library: $lib "
738745 fi
0 commit comments