Skip to content

Commit

Permalink
Refactor strip_flags.py and add_c_flags.py (#21677)
Browse files Browse the repository at this point in the history
* refactor strip-flags.py

* refac more readable

* make failsafe

* move var to top

* align
  • Loading branch information
Jason2866 authored Jun 22, 2024
1 parent c96a48b commit b853886
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
19 changes: 12 additions & 7 deletions pio-tools/add_c_flags.py
Original file line number Diff line number Diff line change
@@ -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=""
18 changes: 9 additions & 9 deletions pio-tools/strip-flags.py
Original file line number Diff line number Diff line change
@@ -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=""

0 comments on commit b853886

Please sign in to comment.