From b03462e7be477c7a53bd20b0c2f40bc7fc01f20e Mon Sep 17 00:00:00 2001 From: MacDada Date: Sun, 18 Jun 2023 16:03:31 +0200 Subject: [PATCH] pio_extra_script_helper.py: extracted function --- config/nodemcu.ini | 1 + scripts/pio_extra_script_helper.py | 19 +++++++++++++++++++ scripts/pio_post_extra_script.py | 11 +++-------- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/config/nodemcu.ini b/config/nodemcu.ini index 31a8b40..506b8dd 100644 --- a/config/nodemcu.ini +++ b/config/nodemcu.ini @@ -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. ; diff --git a/scripts/pio_extra_script_helper.py b/scripts/pio_extra_script_helper.py index f549106..851073f 100644 --- a/scripts/pio_extra_script_helper.py +++ b/scripts/pio_extra_script_helper.py @@ -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: diff --git a/scripts/pio_post_extra_script.py b/scripts/pio_post_extra_script.py index c047e6d..a0cb807 100644 --- a/scripts/pio_post_extra_script.py +++ b/scripts/pio_post_extra_script.py @@ -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') +)