Open mcspr opened 3 years ago
Small correction - it also affects normal pio-run and it happens whenever BSEC lib is either in the lib/ of the project or the ~/.platformio/lib
(or any other lib using extraScript: ...
in the library.json which will happen to break with native platform)
Looking at the docs: https://docs.platformio.org/en/latest/librarymanager/config.html#extrascript
Launch extra script before build process
Shouldn't it wait until the lib is picked by builder to call the script? e.g.
diff --git a/platformio/builder/tools/piolib.py b/platformio/builder/tools/piolib.py
index 3849a91b..8e91cc08 100644
--- a/platformio/builder/tools/piolib.py
+++ b/platformio/builder/tools/piolib.py
@@ -273,15 +273,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.realpath(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:
@@ -436,6 +429,14 @@ class LibBuilderBase(object):
self.depend_recursive(lb, lb_search_files)
def build(self):
+ if self.extra_script:
+ with fs.cd(self.path):
+ self.env.SConscriptChdir(1)
+ self.env.SConscript(
+ os.path.realpath(self.extra_script),
+ exports={"env": self.env, "pio_lib_builder": self},
+ )
+
libs = []
for lb in self._depbuilders:
libs.extend(lb.build())
(edit: process flags as it is currently, run extra script in the build())
But, is it an expected behaviour with the global libraries that scripts are executed unconditionally?
Yes, when we look for dependencies we analyze all libraries according to the storage list. Extra scripts are called on each init of a library because "extra script" can change a lot of things in runtime, such as CPPPATH, etc which we need BEFORE deciding should this lirbary be included in a build process.
I forgot you can use lib_ignore
to skip some libs.
I forgot you can use
lib_ignore
to skip some libs.
Hm. This does not work for the case above :/ With the modified .ini:
> pio run -v -e test
Processing test (platform: native; lib_ignore: BSEC Software Library)
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
CALLED
TypeError: join() argument must be str, bytes, or os.PathLike object, not 'NoneType':
...etc...
File "/home/maxim/.platformio/lib/BSEC Software Library/extra_script.py", line 7:
LIBPATH=[realpath(join('src', env.get('BOARD_MCU')))],
File "/usr/lib64/python3.9/posixpath.py", line 90:
genericpath._check_arg_types('join', a, *p)
File "/usr/lib64/python3.9/genericpath.py", line 152:
raise TypeError(f'{funcname}() argument must be str, bytes, or '
I see. Need to think about if it is possible to fix it with minimal effort.
Yes, when we look for dependencies we analyze all libraries according to the storage list. Extra scripts are called on each init of a library because "extra script" can change a lot of things in runtime, such as CPPPATH, etc which we need BEFORE deciding should this lirbary be included in a build process.
Looking at this once again, would this be a valid fix? afaik we can't make the lib compatible through the extra script if platform is not compatible to begin with? (edit: or avoid creating the libbuilder object to begin with, but I got lost in the libbuilder factory)
diff --git a/platformio/builder/tools/piolib.py b/platformio/builder/tools/piolib.py
index 3849a91b..aae76f14 100644
--- a/platformio/builder/tools/piolib.py
+++ b/platformio/builder/tools/piolib.py
@@ -134,7 +134,8 @@ class LibBuilderBase(object):
self.env["SRC_FILTER"] = ""
# process extra options and append to build environment
- self.process_extra_options()
+ if env.IsCompatibleLibBuilder(self):
+ self.process_extra_options()
def __repr__(self):
return "%s(%r)" % (self.__class__, self.path)
In case of BSEC library... it seems to need a correct (?) "platforms" entry in the library.json to denote that it only supports MCU platforms and not the native one, as right now it is just a glob: https://github.com/BoschSensortec/BSEC-Arduino-library/blob/7a9357566c75048331c15b55a4eb20f1de14f36e/library.json#L15
I got around this by adding this at the top of my extra_script.py
(edit: Exit() -> Return())
Import("env")
Import("pio_lib_builder")
if not env.IsCompatibleLibBuilder(pio_lib_builder):
Return()
IMO https://github.com/platformio/platformio-core/issues/3915#issuecomment-851050357 is a good solution. The concept of library compatibility should extend to the compatibility of a library's extra_script.py
Notes
Fixing this issue breaks "mbed" framework. See https://github.com/platformio/platformio-core/runs/5156160446?check_suite_focus=true
Configuration
Operating system: Fedora 33
PlatformIO Version (
platformio --version
):Description of problem
Globally installed library extra_script.py is executed when running pio-test:
Steps to Reproduce
~/.platformio/lib
is empty before the testpio lib -g install "https://github.com/BoschSensortec/BSEC-Arduino-library.git#v1.6.1480"
pio test -e test
triggers an exception (see above)If problems with PlatformIO Build System:
The content of
platformio.ini
:Additional info
As seen in the extra_script of the lib https://github.com/BoschSensortec/BSEC-Arduino-library/blob/7a9357566c75048331c15b55a4eb20f1de14f36e/extra_script.py
As seen in the trace:
It tries to use BOARD_MCU, which is not available with the platform. But, is it an expected behaviour with the global libraries that scripts are executed unconditionally?