Refactor `strip_flags.py` and `add_c_flags.py` (#21677)

* refactor strip-flags.py

* refac more readable

* make failsafe

* move var to top

* align
This commit is contained in:
Jason2866 2024-06-22 13:37:20 +02:00 committed by GitHub
parent c96a48b9e1
commit b853886cb7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 21 additions and 16 deletions

View File

@ -1,16 +1,21 @@
Import("env") Import("env")
build_flags = env['BUILD_FLAGS']
chip = env.get("BOARD_MCU").lower()
# General options that are passed to the C++ compiler # General options that are passed to the C++ compiler
env.Append(CXXFLAGS=["-Wno-volatile"]) env.Append(CXXFLAGS=["-Wno-volatile"])
# General options that are passed to the C compiler (C only; not C++). # 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"]) env.Append(CFLAGS=["-Wno-discarded-qualifiers", "-Wno-implicit-function-declaration", "-Wno-incompatible-pointer-types"])
# Remove build flags which are not valid for risc-v # Remove build flags which are not valid for risc-v
build_flags = env['BUILD_FLAGS'] if chip in ("esp32c2", "esp32c3", "esp32c6", "esp32h2"):
chip = env.get("BOARD_MCU").lower() try:
if "c" in chip:
build_flags.pop(build_flags.index("-mno-target-align")) build_flags.pop(build_flags.index("-mno-target-align"))
except:
do_nothing=""
try:
build_flags.pop(build_flags.index("-mtarget-align")) build_flags.pop(build_flags.index("-mtarget-align"))
except:
do_nothing=""

View File

@ -1,15 +1,15 @@
Import('env') Import('env')
link_flags = " ".join(env['LINKFLAGS']) link_flags = env['LINKFLAGS']
build_flags = " ".join(env['BUILD_FLAGS']) build_flags = " ".join(env['BUILD_FLAGS'])
if "FIRMWARE_SAFEBOOT" in build_flags: if "FIRMWARE_SAFEBOOT" in build_flags:
# Crash Recorder is not included in safeboot firmware -> remove Linker wrap # Crash Recorder is not included in safeboot firmware -> remove Linker wrap
link_flags = link_flags.replace("-Wl,--wrap=panicHandler", "") try:
link_flags = link_flags.replace("-Wl,--wrap=xt_unhandled_exception", "") link_flags.pop(link_flags.index("-Wl,--wrap=panicHandler"))
except:
new_link_flags = link_flags.split() do_nothing=""
try:
env.Replace( link_flags.pop(link_flags.index("-Wl,--wrap=xt_unhandled_exception"))
LINKFLAGS=new_link_flags except:
) do_nothing=""