Skip to content

Commit

Permalink
pio_extra_script_helper.py: extracted function
Browse files Browse the repository at this point in the history
  • Loading branch information
MacDada committed Jun 18, 2023
1 parent 6db069f commit b03462e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
1 change: 1 addition & 0 deletions config/nodemcu.ini
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ test_filter = embedded/*
extra_scripts =
post:scripts/pio_post_extra_script.py

; https://docs.platformio.org/en/latest/scripting/examples/platformio_ini_custom_options.html
custom_system_packages =
; Silencing warnings from the (framework) dependencies.
;
Expand Down
19 changes: 19 additions & 0 deletions scripts/pio_extra_script_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,26 @@ def __init__(self, script_globals: dict):
self.env,
]

def get_config_value_as_list(self, name: str) -> list[str]:
"""
https://docs.platformio.org/en/latest/scripting/examples/platformio_ini_custom_options.html
todo: why `env.GetProjectOption()` sometimes returns `str` instead of `list[str]`?
for example `build_src_flags` returns a list,
while my `custom_system_packages` is a string…
https://community.platformio.org/t/custom-platformio-ini-options-as-list-str-not-str/34380
"""
return [
value
for value
in self.get_config_value(name).split('\n')
if value != ''
]

def get_config_value(self, name: str, default: str = ''):
"""
https://docs.platformio.org/en/latest/scripting/examples/platformio_ini_custom_options.html
"""
return self.env.GetProjectOption(name, default=default)

def get_platform(self) -> PlatformBase:
Expand Down
11 changes: 3 additions & 8 deletions scripts/pio_post_extra_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,6 @@
# https://github.com/platformio/platformio-core/issues/1728#issuecomment-403297776
helper.env.Append(CXXFLAGS=['-Wno-volatile'])

helper.mark_packages_as_system([
package
for package
# todo: why it returns string instead of a list?
# for example `build_src_flags` returns a list…
in helper.get_config_value('custom_system_packages').split('\n')
if package != ''
])
helper.mark_packages_as_system(
helper.get_config_value_as_list('custom_system_packages')
)

0 comments on commit b03462e

Please sign in to comment.