Skip to content

Commit b853886

Browse files
authored
Refactor strip_flags.py and add_c_flags.py (#21677)
* refactor strip-flags.py * refac more readable * make failsafe * move var to top * align
1 parent c96a48b commit b853886

File tree

2 files changed

+21
-16
lines changed

2 files changed

+21
-16
lines changed

pio-tools/add_c_flags.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
11
Import("env")
22

3+
build_flags = env['BUILD_FLAGS']
4+
chip = env.get("BOARD_MCU").lower()
5+
36
# General options that are passed to the C++ compiler
47
env.Append(CXXFLAGS=["-Wno-volatile"])
58

69
# General options that are passed to the C compiler (C only; not C++).
710
env.Append(CFLAGS=["-Wno-discarded-qualifiers", "-Wno-implicit-function-declaration", "-Wno-incompatible-pointer-types"])
811

9-
1012
# Remove build flags which are not valid for risc-v
11-
build_flags = env['BUILD_FLAGS']
12-
chip = env.get("BOARD_MCU").lower()
13-
14-
if "c" in chip:
15-
build_flags.pop(build_flags.index("-mno-target-align"))
16-
build_flags.pop(build_flags.index("-mtarget-align"))
13+
if chip in ("esp32c2", "esp32c3", "esp32c6", "esp32h2"):
14+
try:
15+
build_flags.pop(build_flags.index("-mno-target-align"))
16+
except:
17+
do_nothing=""
18+
try:
19+
build_flags.pop(build_flags.index("-mtarget-align"))
20+
except:
21+
do_nothing=""

pio-tools/strip-flags.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
Import('env')
22

3-
link_flags = " ".join(env['LINKFLAGS'])
3+
link_flags = env['LINKFLAGS']
44
build_flags = " ".join(env['BUILD_FLAGS'])
55

66
if "FIRMWARE_SAFEBOOT" in build_flags:
77
# Crash Recorder is not included in safeboot firmware -> remove Linker wrap
8-
link_flags = link_flags.replace("-Wl,--wrap=panicHandler", "")
9-
link_flags = link_flags.replace("-Wl,--wrap=xt_unhandled_exception", "")
10-
11-
new_link_flags = link_flags.split()
12-
13-
env.Replace(
14-
LINKFLAGS=new_link_flags
15-
)
8+
try:
9+
link_flags.pop(link_flags.index("-Wl,--wrap=panicHandler"))
10+
except:
11+
do_nothing=""
12+
try:
13+
link_flags.pop(link_flags.index("-Wl,--wrap=xt_unhandled_exception"))
14+
except:
15+
do_nothing=""

0 commit comments

Comments
 (0)