From 011a52c6a5142131fbfd5fc8d6d1e63ea58064d7 Mon Sep 17 00:00:00 2001
From: Abdelatif Guettouche <abdelatif.guettouche@espressif.com>
Date: Mon, 27 Jun 2022 14:43:36 +0200
Subject: [PATCH] sketch_utils.sh: Pass the Windows parameters with the extra
 options.

Signed-off-by: Abdelatif Guettouche <abdelatif.guettouche@espressif.com>
---
 .github/scripts/on-push.sh      | 18 +++++++++---------
 .github/scripts/sketch_utils.sh | 17 +++++++----------
 .github/scripts/tests_run.sh    |  6 +++---
 3 files changed, 19 insertions(+), 22 deletions(-)

diff --git a/.github/scripts/on-push.sh b/.github/scripts/on-push.sh
index d607ab5f419..a1d681e97ec 100755
--- a/.github/scripts/on-push.sh
+++ b/.github/scripts/on-push.sh
@@ -23,16 +23,16 @@ function build(){
         args+=" -i $chunk_index -m $chunks_cnt"
         ${BUILD_SKETCHES} ${args}
     else
-        if [ "$OS_IS_WINDOWS" == "1" ]; then
-            local ctags_version=`ls "$ARDUINO_IDE_PATH/tools-builder/ctags/"`
-            local preprocessor_version=`ls "$ARDUINO_IDE_PATH/tools-builder/arduino-preprocessor/"`
-            win_opts="-prefs=runtime.tools.ctags.path=$ARDUINO_IDE_PATH/tools-builder/ctags/$ctags_version
-            -prefs=runtime.tools.arduino-preprocessor.path=$ARDUINO_IDE_PATH/tools-builder/arduino-preprocessor/$preprocessor_version"
-            args+="-w \"${win_opts}\""
-        fi
-
         for sketch in ${sketches}; do
-            ${BUILD_SKETCH} ${args} " -s $(dirname $sketch)"
+            args+=" -s $(dirname $sketch)"
+            if [ "$OS_IS_WINDOWS" == "1" ]; then
+                local ctags_version=`ls "$ARDUINO_IDE_PATH/tools-builder/ctags/"`
+                local preprocessor_version=`ls "$ARDUINO_IDE_PATH/tools-builder/arduino-preprocessor/"`
+                win_opts="-prefs=runtime.tools.ctags.path=$ARDUINO_IDE_PATH/tools-builder/ctags/$ctags_version
+                -prefs=runtime.tools.arduino-preprocessor.path=$ARDUINO_IDE_PATH/tools-builder/arduino-preprocessor/$preprocessor_version"
+                args+=" ${win_opts}"
+            fi
+            ${BUILD_SKETCH} ${args}
         done
     fi
 }
diff --git a/.github/scripts/sketch_utils.sh b/.github/scripts/sketch_utils.sh
index f0e0c21cfe4..f0fe71b3597 100755
--- a/.github/scripts/sketch_utils.sh
+++ b/.github/scripts/sketch_utils.sh
@@ -24,18 +24,14 @@ function build_sketch(){ # build_sketch <ide_path> <user_path> <path-to-ino> [ex
             shift
             target=$1
             ;;
-        -s )
-            shift
-            sketchdir=$1
-            ;;
-        -w )
-            shift
-            win_opts=$1
-            ;;
         -fqbn )
             shift
             fqbn=$1
             ;;
+        -s )
+            shift
+            sketchdir=$1
+            ;;
         -ff )
             shift
             ff_opt=$1
@@ -139,7 +135,8 @@ function build_sketch(){ # build_sketch <ide_path> <user_path> <path-to-ino> [ex
         rm -rf "$build_dir$i"
         mkdir -p "$build_dir$i"
         currfqbn=`echo $fqbn | jq -r --argjson i $i '.[$i]'`
-        echo "Building with FQBN=$currfqbn"
+        sketchname=$(basename $sketchdir)
+        echo "Building $sketchname with FQBN=$currfqbn"
         $ide_path/arduino-builder -compile -logger=human -core-api-version=10810 \
             -fqbn=\"$currfqbn\" \
             -warnings="all" \
@@ -151,7 +148,7 @@ function build_sketch(){ # build_sketch <ide_path> <user_path> <path-to-ino> [ex
             -libraries "$user_path/libraries" \
             -build-cache "$ARDUINO_CACHE_DIR" \
             -build-path "$build_dir$i" \
-            $win_opts $xtra_opts "${sketchdir}/$(basename ${sketchdir}).ino"
+            $xtra_opts "${sketchdir}/${sketchname}.ino"
     done
 }
 
diff --git a/.github/scripts/tests_run.sh b/.github/scripts/tests_run.sh
index dc62396fc26..e8e2dda4777 100755
--- a/.github/scripts/tests_run.sh
+++ b/.github/scripts/tests_run.sh
@@ -6,7 +6,7 @@ function run_test() {
     local options=$3
     local erase_flash=$4
     local sketchdir=$(dirname $sketch)
-    local sketchdirname=$(basename $sketchdir)
+    local sketchname=$(basename $sketchdir)
 
     if [ $options -eq 0 ] && [ -f $sketchdir/cfg.json ]; then
         len=`jq -r --arg chip $target '.targets[] | select(.name==$chip) | .fqbn | length' $sketchdir/cfg.json`
@@ -16,12 +16,12 @@ function run_test() {
 
     for i in `seq 0 $(($len - 1))`
     do
-        echo "Running test: $sketchdirname -- Config: $i"
+        echo "Running test: $sketchname -- Config: $i"
         if [ $erase_flash -eq 1 ]; then
             esptool.py -c $target erase_flash
         fi
 
-        pytest tests --build-dir tests/$sketchdirname/build$i -k test_$sketchdirname --junit-xml=tests/$sketchdirname/$sketchdirname$i.xml
+        pytest tests --build-dir tests/$sketchname/build$i -k test_$sketchname --junit-xml=tests/$sketchname/$sketchname$i.xml
         result=$?
         if [ $result -ne 0 ]; then
             return $result