From 166bb946bdddb803142110835f57e7ac7cb5fd62 Mon Sep 17 00:00:00 2001 From: Jason2866 <24528715+Jason2866@users.noreply.github.com> Date: Mon, 25 May 2026 17:09:36 +0200 Subject: [PATCH] fix pioarduino build (#24789) --- pio-tools/add_c_flags.py | 54 ++++++++++++++++++++++++++++++++++------ 1 file changed, 47 insertions(+), 7 deletions(-) diff --git a/pio-tools/add_c_flags.py b/pio-tools/add_c_flags.py index 2fc0fc155..aacd54fa8 100644 --- a/pio-tools/add_c_flags.py +++ b/pio-tools/add_c_flags.py @@ -1,18 +1,58 @@ Import("env") import json +import re from pathlib import Path build_flags = env['BUILD_FLAGS'] mcu = env.get("BOARD_MCU").lower() -framework_dir = env.PioPlatform().get_package_dir("framework-arduinoespressif32") # Determine IDF version -idf_major = idf_minor = idf_patch = 0 -pkg_json = Path(framework_dir) / "tools" / "esp32-arduino-libs" / "package.json" -with pkg_json.open() as f: - version_str = json.load(f)["version"].split("+")[0] # e.g. "5.5.4" -idf_major, idf_minor, idf_patch = (int(x) for x in version_str.split(".")) +idf_major = idf_minor = idf_patch = None + + +def _detect_idf_version(): + platform = env.PioPlatform() + + def _safe_get_package_dir(package_name): + try: + return platform.get_package_dir(package_name) + except Exception: + return None + + package_dirs = [ + _safe_get_package_dir("framework-arduinoespressif32"), + _safe_get_package_dir("framework-arduinoespressif32-libs"), + ] + pkg_candidates = [] + + for package_dir in package_dirs: + if not package_dir: + continue + package_path = Path(package_dir) + pkg_candidates.extend([ + package_path / "tools" / "esp32-arduino-libs" / "package.json", + package_path / "package.json", + ]) + + for pkg_json in pkg_candidates: + if not pkg_json.is_file(): + continue + try: + with pkg_json.open() as f: + version_str = str(json.load(f).get("version", "")) + match = re.search(r"(\d+)\.(\d+)\.(\d+)", version_str) + if match: + return tuple(int(part) for part in match.groups()) + except Exception: + pass + + return None + + +idf_version = _detect_idf_version() +if idf_version: + idf_major, idf_minor, idf_patch = idf_version # print(f"IDF version: {idf_major}.{idf_minor}.{idf_patch}") # General options that are passed to the C++ compiler @@ -34,7 +74,7 @@ if mcu not in ("esp32", "esp32s2", "esp32s3"): # Remove -DUSE_SHA_ROM when building with IDF versions earlier than v5.5.4, # as it is not supported in Tasmota code. -if (idf_major, idf_minor, idf_patch) < (5, 5, 4): +if idf_version and idf_version < (5, 5, 4): try: build_flags.pop(build_flags.index("-DUSE_SHA_ROM")) print("Removed -DUSE_SHA_ROM from build flags for compatibility with IDF versions earlier than v5.5.4")