diff --git a/HISTORY.rst b/HISTORY.rst index e463857e..dafe0cae 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -15,6 +15,7 @@ PlatformIO Core 5 - Improved checking of available Internet connection for IPv6-only workstations (`pull #4151 `_) - Better detecting of default PlatformIO project directory on Linux OS (`pull #4158 `_) - Respect disabling debugging server from "platformio.ini" passing an empty value to the `debug_server `__ option +- Run library extra script only at a build process (`issue #3915 `_) 5.2.4 (2021-12-15) ~~~~~~~~~~~~~~~~~~ diff --git a/platformio/builder/tools/piolib.py b/platformio/builder/tools/piolib.py index 3b57c1e7..f50724e7 100644 --- a/platformio/builder/tools/piolib.py +++ b/platformio/builder/tools/piolib.py @@ -285,15 +285,8 @@ class LibBuilderBase(object): return {} def process_extra_options(self): - with fs.cd(self.path): - self.env.ProcessFlags(self.build_flags) - if self.extra_script: - self.env.SConscriptChdir(1) - self.env.SConscript( - os.path.abspath(self.extra_script), - exports={"env": self.env, "pio_lib_builder": self}, - ) - self.env.ProcessUnFlags(self.build_unflags) + self.env.ProcessFlags(self.build_flags) + self.env.ProcessUnFlags(self.build_unflags) def process_dependencies(self): if not self.dependencies: @@ -447,7 +440,15 @@ class LibBuilderBase(object): for lb, lb_search_files in lib_inc_map.items(): self.depend_recursive(lb, lb_search_files) - def build(self): + def build(self): # pylint: disable=too-many-branches + if self.extra_script and not self._is_built: + with fs.cd(self.path): + self.env.SConscriptChdir(1) + self.env.SConscript( + os.path.abspath(self.extra_script), + exports={"env": self.env, "pio_lib_builder": self}, + ) + libs = [] for lb in self._depbuilders: libs.extend(lb.build()) @@ -460,8 +461,8 @@ class LibBuilderBase(object): if self._is_built: return libs - self._is_built = True + self._is_built = True self.env.PrependUnique(CPPPATH=self.get_include_dirs()) if self.lib_ldf_mode == "off":