@@ -371,7 +371,7 @@ cat configs/pio_start.txt > "$AR_PLATFORMIO_PY"
371371# Process include directories and implement include path shortening
372372# This is equivalent to the Python shorthen_includes() function
373373# We collect shortened include paths and copy all header files to the esp32-arduino-libs
374- REL_INC=" " # Will contain the shortened include paths
374+ REL_INC=" " # Will contain the shortened include paths for Windows
375375set -- $INCLUDES
376376
377377for item; do
@@ -406,7 +406,7 @@ for item; do
406406 out_sub=" ${item#* $ipath } "
407407 out_cpath=" $AR_SDK /include/$fname$out_sub "
408408
409- # Add to shortened include paths (using GCC's -iwithprefix mechanism)
409+ # Add to shortened include paths for Windows (using GCC's -iwithprefix mechanism)
410410 REL_INC+=" -iwithprefixbefore $fname$out_sub "
411411
412412 # Copy all header files to the esp32-arduino-libs include directory
@@ -449,18 +449,21 @@ else
449449 echo " \" -march=rv32imc\" ," >> " $AR_PLATFORMIO_PY " # RISC-V architecture
450450fi
451451
452- # Add shortened include paths for assembly files using esp32-arduino-libs structure
452+ # Add shortened include paths for assembly files only on Windows
453453# This implements the same logic as the Python shorthen_includes() function
454454if [[ -n " $REL_INC " ]]; then
455- echo " \" -iprefix\" , join(FRAMEWORK_DIR, \" tools\" , \" esp32-arduino-libs\" , \" $IDF_TARGET \" , \" include\" )," >> " $AR_PLATFORMIO_PY "
455+ echo " # Include path shortening for Windows command line length limits" >> " $AR_PLATFORMIO_PY "
456+ echo " *([" >> " $AR_PLATFORMIO_PY "
457+ echo " \" -iprefix\" , join(FRAMEWORK_DIR, \" tools\" , \" esp32-arduino-libs\" , \" $IDF_TARGET \" , \" include\" )," >> " $AR_PLATFORMIO_PY "
458+
456459 # Parse the REL_INC string and convert -iwithprefixbefore to -iwithprefix
457460 IFS=' ' read -ra rel_inc_array <<< " $REL_INC"
458461 i=0
459462 while [ $i -lt ${# rel_inc_array[@]} ]; do
460463 if [[ " ${rel_inc_array[$i]} " == " -iwithprefixbefore" ]]; then
461464 if [ $(( i+ 1 )) -lt ${# rel_inc_array[@]} ]; then
462465 path=" ${rel_inc_array[$((i+1))]} "
463- echo " \" -iwithprefix/$path \" ," >> " $AR_PLATFORMIO_PY "
466+ echo " \" -iwithprefix/$path \" ," >> " $AR_PLATFORMIO_PY "
464467 i=$(( i+ 2 )) # Skip both flag and path
465468 else
466469 i=$(( i+ 1 ))
@@ -469,6 +472,7 @@ if [[ -n "$REL_INC" ]]; then
469472 i=$(( i+ 1 ))
470473 fi
471474 done
475+ echo " ] if platform.system() == \" Windows\" else [])," >> " $AR_PLATFORMIO_PY "
472476fi
473477
474478echo " ]," >> " $AR_PLATFORMIO_PY "
@@ -510,24 +514,27 @@ echo " \"$last_item\"" >> "$AR_PLATFORMIO_PY"
510514echo " ]," >> " $AR_PLATFORMIO_PY "
511515echo " " >> " $AR_PLATFORMIO_PY "
512516
513- # Generate CCFLAGS (Common C/C++ compiler flags) with shortened include paths
517+ # Generate CCFLAGS (Common C/C++ compiler flags) with shortened include paths only on Windows
514518echo " CCFLAGS=[" >> " $AR_PLATFORMIO_PY "
515519set -- $PIO_CC_FLAGS
516520for item; do
517521 echo " \" $item \" ," >> " $AR_PLATFORMIO_PY "
518522done
519523
520- # Add shortened include paths for C/C++ compilation using esp32-arduino-libs structure
521- # This is the core of the include path shortening mechanism
524+ # Add shortened include paths for C/C++ compilation only on Windows
525+ # This is the core of the include path shortening mechanism for Windows command line limits
522526if [[ -n " $REL_INC " ]]; then
523- echo " \" -iprefix\" , join(FRAMEWORK_DIR, \" tools\" , \" esp32-arduino-libs\" , \" $IDF_TARGET \" , \" include\" )," >> " $AR_PLATFORMIO_PY "
527+ echo " # Include path shortening for Windows command line length limits" >> " $AR_PLATFORMIO_PY "
528+ echo " *([" >> " $AR_PLATFORMIO_PY "
529+ echo " \" -iprefix\" , join(FRAMEWORK_DIR, \" tools\" , \" esp32-arduino-libs\" , \" $IDF_TARGET \" , \" include\" )," >> " $AR_PLATFORMIO_PY "
530+
524531 IFS=' ' read -ra rel_inc_array <<< " $REL_INC"
525532 i=0
526533 while [ $i -lt ${# rel_inc_array[@]} ]; do
527534 if [[ " ${rel_inc_array[$i]} " == " -iwithprefixbefore" ]]; then
528535 if [ $(( i+ 1 )) -lt ${# rel_inc_array[@]} ]; then
529536 path=" ${rel_inc_array[$((i+1))]} "
530- echo " \" -iwithprefix/$path \" ," >> " $AR_PLATFORMIO_PY "
537+ echo " \" -iwithprefix/$path \" ," >> " $AR_PLATFORMIO_PY "
531538 i=$(( i+ 2 ))
532539 else
533540 i=$(( i+ 1 ))
@@ -536,6 +543,7 @@ if [[ -n "$REL_INC" ]]; then
536543 i=$(( i+ 1 ))
537544 fi
538545 done
546+ echo " ] if platform.system() == \" Windows\" else [])," >> " $AR_PLATFORMIO_PY "
539547fi
540548
541549echo " \" -MMD\" " >> " $AR_PLATFORMIO_PY " # Generate dependency files
@@ -568,10 +576,47 @@ echo " ]," >> "$AR_PLATFORMIO_PY"
568576echo " " >> " $AR_PLATFORMIO_PY "
569577
570578# Generate CPPPATH (Include paths for PlatformIO)
571- # Only include Arduino Core paths, not framework headers (those use shortened paths)
579+ # For non-Windows: All include paths go here for best performance
580+ # For Windows: Only Arduino Core paths, framework headers use shortened paths
572581echo " CPPPATH=[" >> " $AR_PLATFORMIO_PY "
573582echo " join($PIO_SDK , board_config.get(\" build.arduino.memory_type\" , (board_config.get(\" build.flash_mode\" , \" dio\" ) + \" _qspi\" )), \" include\" )," >> " $AR_PLATFORMIO_PY "
574- echo " join(FRAMEWORK_DIR, \" cores\" , board_config.get(\" build.core\" ))" >> " $AR_PLATFORMIO_PY "
583+ echo " join(FRAMEWORK_DIR, \" cores\" , board_config.get(\" build.core\" ))," >> " $AR_PLATFORMIO_PY "
584+
585+ # Add full include paths for non-Windows platforms (better performance)
586+ if [[ -n " $INCLUDES " ]]; then
587+ echo " # Full include paths for better performance on non-Windows platforms" >> " $AR_PLATFORMIO_PY "
588+ echo " *([] if platform.system() == \" Windows\" else [" >> " $AR_PLATFORMIO_PY "
589+
590+ set -- $INCLUDES
591+ for item; do
592+ if [[ " $item " != $PWD ]]; then
593+ # Skip Arduino and config directories (handled separately)
594+ ipath=" $item "
595+ fname=` basename " $ipath " `
596+ dname=` basename $( dirname " $ipath " ) `
597+
598+ if [[ " $fname " == " main" && " $dname " == $( basename " $PWD " ) ]]; then
599+ continue
600+ fi
601+
602+ # Find component root
603+ while [[ " $dname " != " components" && " $dname " != " managed_components" && " $dname " != " build" ]]; do
604+ ipath=` dirname " $ipath " `
605+ fname=` basename " $ipath " `
606+ dname=` basename $( dirname " $ipath " ) `
607+ done
608+
609+ if [[ " $fname " == " arduino" || " $fname " == " config" ]]; then
610+ continue
611+ fi
612+
613+ echo " \" $item \" ," >> " $AR_PLATFORMIO_PY "
614+ fi
615+ done
616+
617+ echo " ])," >> " $AR_PLATFORMIO_PY "
618+ fi
619+
575620echo " ]," >> " $AR_PLATFORMIO_PY "
576621echo " " >> " $AR_PLATFORMIO_PY "
577622
0 commit comments