From b853886cb7f6426306a62d1e28c42c6a67b0e8d2 Mon Sep 17 00:00:00 2001 From: Jason2866 <24528715+Jason2866@users.noreply.github.com> Date: Sat, 22 Jun 2024 13:37:20 +0200 Subject: [PATCH] Refactor `strip_flags.py` and `add_c_flags.py` (#21677) * refactor strip-flags.py * refac more readable * make failsafe * move var to top * align --- pio-tools/add_c_flags.py | 19 ++++++++++++------- pio-tools/strip-flags.py | 18 +++++++++--------- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/pio-tools/add_c_flags.py b/pio-tools/add_c_flags.py index 7e51a4fe1..345d4e814 100644 --- a/pio-tools/add_c_flags.py +++ b/pio-tools/add_c_flags.py @@ -1,16 +1,21 @@ Import("env") +build_flags = env['BUILD_FLAGS'] +chip = env.get("BOARD_MCU").lower() + # General options that are passed to the C++ compiler env.Append(CXXFLAGS=["-Wno-volatile"]) # General options that are passed to the C compiler (C only; not C++). env.Append(CFLAGS=["-Wno-discarded-qualifiers", "-Wno-implicit-function-declaration", "-Wno-incompatible-pointer-types"]) - # Remove build flags which are not valid for risc-v -build_flags = env['BUILD_FLAGS'] -chip = env.get("BOARD_MCU").lower() - -if "c" in chip: - build_flags.pop(build_flags.index("-mno-target-align")) - build_flags.pop(build_flags.index("-mtarget-align")) +if chip in ("esp32c2", "esp32c3", "esp32c6", "esp32h2"): + try: + build_flags.pop(build_flags.index("-mno-target-align")) + except: + do_nothing="" + try: + build_flags.pop(build_flags.index("-mtarget-align")) + except: + do_nothing="" \ No newline at end of file diff --git a/pio-tools/strip-flags.py b/pio-tools/strip-flags.py index 714e84a0f..981918273 100644 --- a/pio-tools/strip-flags.py +++ b/pio-tools/strip-flags.py @@ -1,15 +1,15 @@ Import('env') -link_flags = " ".join(env['LINKFLAGS']) +link_flags = env['LINKFLAGS'] build_flags = " ".join(env['BUILD_FLAGS']) if "FIRMWARE_SAFEBOOT" in build_flags: # Crash Recorder is not included in safeboot firmware -> remove Linker wrap - link_flags = link_flags.replace("-Wl,--wrap=panicHandler", "") - link_flags = link_flags.replace("-Wl,--wrap=xt_unhandled_exception", "") - -new_link_flags = link_flags.split() - -env.Replace( - LINKFLAGS=new_link_flags -) + try: + link_flags.pop(link_flags.index("-Wl,--wrap=panicHandler")) + except: + do_nothing="" + try: + link_flags.pop(link_flags.index("-Wl,--wrap=xt_unhandled_exception")) + except: + do_nothing="" \ No newline at end of file