Skip to content

Commit 714ea96

Browse files
authored
Update copy-libs.sh
1 parent 64302a7 commit 714ea96

File tree

1 file changed

+117
-146
lines changed

1 file changed

+117
-146
lines changed

tools/copy-libs.sh

Lines changed: 117 additions & 146 deletions
Original file line numberDiff line numberDiff line change
@@ -368,77 +368,6 @@ mkdir -p "$AR_SDK"
368368
AR_PLATFORMIO_PY="$AR_SDK/pioarduino-build.py"
369369
cat configs/pio_start.txt > "$AR_PLATFORMIO_PY"
370370

371-
# Process include directories and implement include path shortening
372-
# This is equivalent to the Python shorthen_includes() function
373-
# We collect shortened include paths and copy all header files to the esp32-arduino-libs
374-
REL_INC="" # Will contain the shortened include paths for Windows
375-
set -- $INCLUDES
376-
377-
for item; do
378-
if [[ "$item" != $PWD ]]; then # Skip current directory
379-
ipath="$item"
380-
fname=`basename "$ipath"`
381-
dname=`basename $(dirname "$ipath")`
382-
383-
# Skip main component from current project
384-
if [[ "$fname" == "main" && "$dname" == $(basename "$PWD") ]]; then
385-
continue
386-
fi
387-
388-
# Find the component root directory by walking up the path
389-
while [[ "$dname" != "components" && "$dname" != "managed_components" && "$dname" != "build" ]]; do
390-
ipath=`dirname "$ipath"`
391-
fname=`basename "$ipath"`
392-
dname=`basename $(dirname "$ipath")`
393-
done
394-
395-
# Skip Arduino component (handled separately)
396-
if [[ "$fname" == "arduino" ]]; then
397-
continue
398-
fi
399-
400-
# Skip config directory
401-
if [[ "$fname" == "config" ]]; then
402-
continue
403-
fi
404-
405-
# Calculate relative path within component
406-
out_sub="${item#*$ipath}"
407-
out_cpath="$AR_SDK/include/$fname$out_sub"
408-
409-
# Add to shortened include paths for Windows (using GCC's -iwithprefix mechanism)
410-
REL_INC+="-iwithprefixbefore $fname$out_sub "
411-
412-
# Copy all header files to the esp32-arduino-libs include directory
413-
# This ensures all headers are available at build time
414-
for f in `find "$item" -name '*.h'`; do
415-
rel_f=${f#*$item}
416-
rel_p=${rel_f%/*}
417-
mkdir -p "$out_cpath$rel_p"
418-
cp -n $f "$out_cpath$rel_p/"
419-
done
420-
for f in `find "$item" -name '*.hpp'`; do
421-
rel_f=${f#*$item}
422-
rel_p=${rel_f%/*}
423-
mkdir -p "$out_cpath$rel_p"
424-
cp -n $f "$out_cpath$rel_p/"
425-
done
426-
for f in `find "$item" -name '*.inc'`; do
427-
rel_f=${f#*$item}
428-
rel_p=${rel_f%/*}
429-
mkdir -p "$out_cpath$rel_p"
430-
cp -n $f "$out_cpath$rel_p/"
431-
done
432-
433-
# Temporary fix for Bluetooth controller header location issue
434-
# See: https://github.com/espressif/esp-idf/commit/dc4731101dd567cc74bbe4d0f03afe52b7db9afb
435-
if [[ "$fname" == "bt" && "$out_sub" == "/include/$IDF_TARGET/include" && -f "$ipath/controller/$IDF_TARGET/esp_bt_cfg.h" ]]; then
436-
mkdir -p "$AR_SDK/include/$fname/controller/$IDF_TARGET"
437-
cp -n "$ipath/controller/$IDF_TARGET/esp_bt_cfg.h" "$AR_SDK/include/$fname/controller/$IDF_TARGET/esp_bt_cfg.h"
438-
fi
439-
fi
440-
done
441-
442371
# Generate ASFLAGS section for assembly compilation
443372
echo " ASFLAGS=[" >> "$AR_PLATFORMIO_PY"
444373

@@ -450,28 +379,38 @@ else
450379
fi
451380

452381
# Add shortened include paths for assembly files only on Windows
453-
# This implements the same logic as the Python shorthen_includes() function
454-
if [[ -n "$REL_INC" ]]; then
382+
if [[ -n "$INCLUDES" ]]; then
455383
echo " # Include path shortening for Windows command line length limits" >> "$AR_PLATFORMIO_PY"
456384
echo " *([" >> "$AR_PLATFORMIO_PY"
457385
echo " \"-iprefix\", join(FRAMEWORK_DIR, \"tools\", \"esp32-arduino-libs\", \"$IDF_TARGET\", \"include\")," >> "$AR_PLATFORMIO_PY"
458386

459-
# Parse the REL_INC string and convert -iwithprefixbefore to -iwithprefix
460-
IFS=' ' read -ra rel_inc_array <<< "$REL_INC"
461-
i=0
462-
while [ $i -lt ${#rel_inc_array[@]} ]; do
463-
if [[ "${rel_inc_array[$i]}" == "-iwithprefixbefore" ]]; then
464-
if [ $((i+1)) -lt ${#rel_inc_array[@]} ]; then
465-
path="${rel_inc_array[$((i+1))]}"
466-
echo " \"-iwithprefix/$path\"," >> "$AR_PLATFORMIO_PY"
467-
i=$((i+2)) # Skip both flag and path
468-
else
469-
i=$((i+1))
387+
# Process includes for Windows shortening
388+
set -- $INCLUDES
389+
for item; do
390+
if [[ "$item" != $PWD ]]; then
391+
ipath="$item"
392+
fname=`basename "$ipath"`
393+
dname=`basename $(dirname "$ipath")`
394+
395+
if [[ "$fname" == "main" && "$dname" == $(basename "$PWD") ]]; then
396+
continue
470397
fi
471-
else
472-
i=$((i+1))
398+
399+
while [[ "$dname" != "components" && "$dname" != "managed_components" && "$dname" != "build" ]]; do
400+
ipath=`dirname "$ipath"`
401+
fname=`basename "$ipath"`
402+
dname=`basename $(dirname "$ipath")`
403+
done
404+
405+
if [[ "$fname" == "arduino" || "$fname" == "config" ]]; then
406+
continue
407+
fi
408+
409+
out_sub="${item#*$ipath}"
410+
echo " \"-iwithprefix/$fname$out_sub\"," >> "$AR_PLATFORMIO_PY"
473411
fi
474412
done
413+
475414
echo " ] if platform.system() == \"Windows\" else [])," >> "$AR_PLATFORMIO_PY"
476415
fi
477416

@@ -522,27 +461,38 @@ for item; do
522461
done
523462

524463
# 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
526-
if [[ -n "$REL_INC" ]]; then
464+
if [[ -n "$INCLUDES" ]]; then
527465
echo " # Include path shortening for Windows command line length limits" >> "$AR_PLATFORMIO_PY"
528466
echo " *([" >> "$AR_PLATFORMIO_PY"
529467
echo " \"-iprefix\", join(FRAMEWORK_DIR, \"tools\", \"esp32-arduino-libs\", \"$IDF_TARGET\", \"include\")," >> "$AR_PLATFORMIO_PY"
530468

531-
IFS=' ' read -ra rel_inc_array <<< "$REL_INC"
532-
i=0
533-
while [ $i -lt ${#rel_inc_array[@]} ]; do
534-
if [[ "${rel_inc_array[$i]}" == "-iwithprefixbefore" ]]; then
535-
if [ $((i+1)) -lt ${#rel_inc_array[@]} ]; then
536-
path="${rel_inc_array[$((i+1))]}"
537-
echo " \"-iwithprefix/$path\"," >> "$AR_PLATFORMIO_PY"
538-
i=$((i+2))
539-
else
540-
i=$((i+1))
469+
# Process includes for Windows shortening
470+
set -- $INCLUDES
471+
for item; do
472+
if [[ "$item" != $PWD ]]; then
473+
ipath="$item"
474+
fname=`basename "$ipath"`
475+
dname=`basename $(dirname "$ipath")`
476+
477+
if [[ "$fname" == "main" && "$dname" == $(basename "$PWD") ]]; then
478+
continue
541479
fi
542-
else
543-
i=$((i+1))
480+
481+
while [[ "$dname" != "components" && "$dname" != "managed_components" && "$dname" != "build" ]]; do
482+
ipath=`dirname "$ipath"`
483+
fname=`basename "$ipath"`
484+
dname=`basename $(dirname "$ipath")`
485+
done
486+
487+
if [[ "$fname" == "arduino" || "$fname" == "config" ]]; then
488+
continue
489+
fi
490+
491+
out_sub="${item#*$ipath}"
492+
echo " \"-iwithprefix/$fname$out_sub\"," >> "$AR_PLATFORMIO_PY"
544493
fi
545494
done
495+
546496
echo " ] if platform.system() == \"Windows\" else [])," >> "$AR_PLATFORMIO_PY"
547497
fi
548498

@@ -575,48 +525,76 @@ echo " '-Wl,-Map=\"%s\"' % join(\"\${BUILD_DIR}\", \"\${PROGNAME}.map\")"
575525
echo " ]," >> "$AR_PLATFORMIO_PY"
576526
echo "" >> "$AR_PLATFORMIO_PY"
577527

578-
# Generate CPPPATH (Include paths for PlatformIO)
579-
# For non-Windows: All include paths go here for best performance
580-
# For Windows: Only Arduino Core paths, framework headers use shortened paths
528+
# Generate CPPPATH exactly like original script for non-Windows, empty for Windows
529+
REL_INC=""
581530
echo " CPPPATH=[" >> "$AR_PLATFORMIO_PY"
582-
echo " join($PIO_SDK, board_config.get(\"build.arduino.memory_type\", (board_config.get(\"build.flash_mode\", \"dio\") + \"_qspi\")), \"include\")," >> "$AR_PLATFORMIO_PY"
583-
echo " join(FRAMEWORK_DIR, \"cores\", board_config.get(\"build.core\"))," >> "$AR_PLATFORMIO_PY"
584531

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
532+
# Process includes exactly like original script
533+
set -- $INCLUDES
534+
for item; do
535+
if [[ "$item" != $PWD ]]; then
536+
ipath="$item"
537+
fname=`basename "$ipath"`
538+
dname=`basename $(dirname "$ipath")`
539+
if [[ "$fname" == "main" && "$dname" == $(basename "$PWD") ]]; then
540+
continue
541+
fi
542+
while [[ "$dname" != "components" && "$dname" != "managed_components" && "$dname" != "build" ]]; do
543+
ipath=`dirname "$ipath"`
544+
fname=`basename "$ipath"`
545+
dname=`basename $(dirname "$ipath")`
546+
done
547+
if [[ "$fname" == "arduino" ]]; then
548+
continue
549+
fi
550+
if [[ "$fname" == "config" ]]; then
551+
continue
552+
fi
619553

554+
out_sub="${item#*$ipath}"
555+
out_cpath="$AR_SDK/include/$fname$out_sub"
556+
REL_INC+="-iwithprefixbefore $fname$out_sub "
557+
558+
# Generate CPPPATH entries exactly like original - only for non-Windows
559+
echo " *([] if platform.system() == \"Windows\" else [" >> "$AR_PLATFORMIO_PY"
560+
if [ "$out_sub" = "" ]; then
561+
echo " join($PIO_SDK, \"include\", \"$fname\")" >> "$AR_PLATFORMIO_PY"
562+
else
563+
pio_sub="${out_sub:1}"
564+
pio_sub=`echo $pio_sub | sed 's/\//\\", \\"/g'`
565+
echo " join($PIO_SDK, \"include\", \"$fname\", \"$pio_sub\")" >> "$AR_PLATFORMIO_PY"
566+
fi
567+
echo " ])," >> "$AR_PLATFORMIO_PY"
568+
569+
# Copy header files exactly like original
570+
for f in `find "$item" -name '*.h'`; do
571+
rel_f=${f#*$item}
572+
rel_p=${rel_f%/*}
573+
mkdir -p "$out_cpath$rel_p"
574+
cp -n $f "$out_cpath$rel_p/"
575+
done
576+
for f in `find "$item" -name '*.hpp'`; do
577+
rel_f=${f#*$item}
578+
rel_p=${rel_f%/*}
579+
mkdir -p "$out_cpath$rel_p"
580+
cp -n $f "$out_cpath$rel_p/"
581+
done
582+
for f in `find "$item" -name '*.inc'`; do
583+
rel_f=${f#*$item}
584+
rel_p=${rel_f%/*}
585+
mkdir -p "$out_cpath$rel_p"
586+
cp -n $f "$out_cpath$rel_p/"
587+
done
588+
# Temporary measure to fix issues caused by https://github.com/espressif/esp-idf/commit/dc4731101dd567cc74bbe4d0f03afe52b7db9afb#diff-1d2ce0d3989a80830fdf230bcaafb3117f32046d16cf46616ac3d55b4df2a988R17
589+
if [[ "$fname" == "bt" && "$out_sub" == "/include/$IDF_TARGET/include" && -f "$ipath/controller/$IDF_TARGET/esp_bt_cfg.h" ]]; then
590+
mkdir -p "$AR_SDK/include/$fname/controller/$IDF_TARGET"
591+
cp -n "$ipath/controller/$IDF_TARGET/esp_bt_cfg.h" "$AR_SDK/include/$fname/controller/$IDF_TARGET/esp_bt_cfg.h"
592+
fi
593+
fi
594+
done
595+
596+
echo " join($PIO_SDK, board_config.get(\"build.arduino.memory_type\", (board_config.get(\"build.flash_mode\", \"dio\") + \"_qspi\")), \"include\")," >> "$AR_PLATFORMIO_PY"
597+
echo " join(FRAMEWORK_DIR, \"cores\", board_config.get(\"build.core\"))" >> "$AR_PLATFORMIO_PY"
620598
echo " ]," >> "$AR_PLATFORMIO_PY"
621599
echo "" >> "$AR_PLATFORMIO_PY"
622600

@@ -632,7 +610,6 @@ for item; do
632610
done
633611

634612
# Strip debug symbols from libraries and copy them to esp32-arduino-libs
635-
# This reduces the size of the final esp32-arduino-libs package
636613
set -- $LD_LIB_FILES
637614
for item; do
638615
"$TOOLCHAIN-strip" -g "$item" # Remove debug symbols
@@ -695,7 +672,6 @@ echo -n "$LD_SCRIPTS" > "$FLAGS_DIR/ld_scripts"
695672
echo -n "$AR_LIBS" > "$FLAGS_DIR/ld_libs"
696673

697674
# Copy ESP32-Camera private header if available
698-
# This is a workaround for missing private headers in the component
699675
if [ -d "managed_components/espressif__esp32-camera/driver/private_include/" ]; then
700676
cp -r "managed_components/espressif__esp32-camera/driver/private_include/cam_hal.h" "$AR_SDK/include/espressif__esp32-camera/driver/include/"
701677
fi
@@ -737,14 +713,10 @@ for lib in "openthread" "espressif__esp-tflite-micro" "bt" "espressif__esp_modem
737713
done
738714

739715
# Handle memory configuration variants
740-
# Different flash/PSRAM configurations may have different libraries and headers
741716
mkdir -p "$AR_SDK/$MEMCONF/include"
742717
mv "$PWD/build/config/sdkconfig.h" "$AR_SDK/$MEMCONF/include/sdkconfig.h"
743-
744-
# Process memory variant files based on configuration
745718
for mem_variant in `jq -c '.mem_variants_files[]' configs/builds.json`; do
746719
skip_file=1
747-
# Check if this variant applies to current target
748720
for file_target in $(echo "$mem_variant" | jq -c '.targets[]' | tr -d '"'); do
749721
if [ "$file_target" == "$IDF_TARGET" ]; then
750722
skip_file=0
@@ -760,6 +732,5 @@ for mem_variant in `jq -c '.mem_variants_files[]' configs/builds.json`; do
760732
done;
761733

762734
# Add ESP-IDF version information to sdkconfig header
763-
# This allows Arduino code to check the IDF version at compile time
764735
echo "#define CONFIG_ARDUINO_IDF_COMMIT \"$IDF_COMMIT\"" >> "$AR_SDK/$MEMCONF/include/sdkconfig.h"
765736
echo "#define CONFIG_ARDUINO_IDF_BRANCH \"$IDF_BRANCH\"" >> "$AR_SDK/$MEMCONF/include/sdkconfig.h"

0 commit comments

Comments
 (0)