platformio / platformio/platformio-core

pio-test: global library extra_script.py is executed with an empty project

Open
#3,915 7 comments 0 reactions 1 assignee View on GitHub

@ivankravets is already working on this.

Since Aug 2, 2021.

build system known issue LDF
Dominant language
Python
Stars
9.5k
Forks
905
Avg merge
2d 13h
Merged PRs (30d)
2

Description

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):

PlatformIO Core             5.2.0a3
Python                      3.9.1-final.0
System Type                 linux_x86_64
Description of problem

Globally installed library extra_script.py is executed when running pio-test:

> pio test -e test
Verbose mode can be enabled via `-v, --verbose` option
Collected 1 items

Processing * in test environment
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Building...
TypeError: join() argument must be str, bytes, or os.PathLike object, not 'NoneType':
  File "/home/maxim/.platformio/penv/lib/python3.9/site-packages/platformio/builder/main.py", line 178:
    env.SConscript("$BUILD_SCRIPT")
  File "/home/maxim/.platformio/packages/tool-scons/scons-local-4.1.0/SCons/Script/SConscript.py", line 591:
    return _SConscript(self.fs, *files, **subst_kw)
  File "/home/maxim/.platformio/packages/tool-scons/scons-local-4.1.0/SCons/Script/SConscript.py", line 280:
    exec(compile(scriptdata, scriptname, 'exec'), call_stack[-1].globals)
  File "/home/maxim/.platformio/platforms/native/builder/main.py", line 43:
    target_bin = env.BuildProgram()
  File "/home/maxim/.platformio/packages/tool-scons/scons-local-4.1.0/SCons/Util.py", line 658:
    return self.method(*nargs, **kwargs)
  File "/home/maxim/.platformio/penv/lib/python3.9/site-packages/platformio/builder/tools/platformio.py", line 62:
    env.ProcessProjectDeps()
  File "/home/maxim/.platformio/packages/tool-scons/scons-local-4.1.0/SCons/Util.py", line 658:
    return self.method(*nargs, **kwargs)
  File "/home/maxim/.platformio/penv/lib/python3.9/site-packages/platformio/builder/tools/platformio.py", line 140:
    project_lib_builder = env.ConfigureProjectLibBuilder()
  File "/home/maxim/.platformio/packages/tool-scons/scons-local-4.1.0/SCons/Util.py", line 658:
    return self.method(*nargs, **kwargs)
  File "/home/maxim/.platformio/penv/lib/python3.9/site-packages/platformio/builder/tools/piolib.py", line 1064:
    lib_builders = env.GetLibBuilders()
  File "/home/maxim/.platformio/packages/tool-scons/scons-local-4.1.0/SCons/Util.py", line 658:
    return self.method(*nargs, **kwargs)
  File "/home/maxim/.platformio/penv/lib/python3.9/site-packages/platformio/builder/tools/piolib.py", line 993:
    lb = LibBuilderFactory.new(env, lib_dir)
  File "/home/maxim/.platformio/penv/lib/python3.9/site-packages/platformio/builder/tools/piolib.py", line 61:
    obj = getattr(sys.modules[__name__], clsname)(env, path, verbose=verbose)
  File "/home/maxim/.platformio/penv/lib/python3.9/site-packages/platformio/builder/tools/piolib.py", line 137:
    self.process_extra_options()
  File "/home/maxim/.platformio/penv/lib/python3.9/site-packages/platformio/builder/tools/piolib.py", line 280:
    self.env.SConscript(
  File "/home/maxim/.platformio/packages/tool-scons/scons-local-4.1.0/SCons/Script/SConscript.py", line 591:
    return _SConscript(self.fs, *files, **subst_kw)
  File "/home/maxim/.platformio/packages/tool-scons/scons-local-4.1.0/SCons/Script/SConscript.py", line 280:
    exec(compile(scriptdata, scriptname, 'exec'), call_stack[-1].globals)
  File "/home/maxim/.platformio/lib/BSEC Software Library/extra_script.py", line 5:
    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 '
======================================================================== [FAILED] Took 0.33 seconds ========================================================================

Test    Environment    Status    Duration
------  -------------  --------  ------------
*       test           FAILED    00:00:00.329
================================================================== 1 failed, 0 succeeded in 00:00:00.329 ==================================================================
Steps to Reproduce
  1. Make sure ~/.platformio/lib is empty before the test
  2. pio lib -g install "https://github.com/BoschSensortec/BSEC-Arduino-library.git#v1.6.1480"
  3. Create a dummy project project in some directory
  4. pio test -e test triggers an exception (see above)
If problems with PlatformIO Build System:

The content of platformio.ini:

[env:test]
platform = native
Additional info

As seen in the extra_script of the lib
https://github.com/BoschSensortec/BSEC-Arduino-library/blob/7a9357566c75048331c15b55a4eb20f1de14f36e/extra_script.py

Import('env')
from os.path import join, realpath

env.Append(
    LIBPATH=[realpath(join('src', env.get('BOARD_MCU')))],
    LIBS=['algobsec']
)

As seen in the trace:

File "/home/maxim/.platformio/lib/BSEC Software Library/extra_script.py", line 5:
    LIBPATH=[realpath(join('src', env.get('BOARD_MCU')))],

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?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.