# fix_toolchain_path.py (PlatformIO pre-build extra script) # # WORKAROUND for a pioarduino first-install issue on this machine. # # The Xtensa toolchain (toolchain-xtensa-esp-elf) extracts its binaries to a # NESTED folder: # /xtensa-esp-elf/bin/xtensa-esp32s3-elf-gcc.exe (and g++, ar, ld, ...) # but pioarduino's export_paths PATH-injection did not reach the SCons build # environment, so the compiler was invoked by bare name and the shell reported # "'xtensa-esp32s3-elf-gcc' is not recognized as an internal or external command". # # This script finds the toolchain package dir dynamically and prepends its real # bin/ folder to the build PATH. It is a no-op if the bin folder isn't nested # (e.g. after a future clean reinstall that flattens the layout), so it's safe # to leave in place. # # Proper long-term fix (optional): remove ~/.platformio/packages/toolchain-xtensa-esp-elf # and ~/.espressif, then rebuild so pioarduino re-runs idf_tools install cleanly. Import("env") # noqa: F821 (injected by PlatformIO/SCons) from os.path import isdir, join platform = env.PioPlatform() toolchain_pkg = platform.get_package_dir("toolchain-xtensa-esp-elf") if toolchain_pkg: nested_bin = join(toolchain_pkg, "xtensa-esp-elf", "bin") if isdir(nested_bin): env.PrependENVPath("PATH", nested_bin) print("[fix_toolchain_path] Prepended toolchain bin to PATH: %s" % nested_bin) else: print("[fix_toolchain_path] Nested bin not found (layout OK?): %s" % nested_bin) else: print("[fix_toolchain_path] toolchain-xtensa-esp-elf package dir not found")