Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PLATFORMIO_... environment variable causes a crash #3377

Closed
mcspr opened this issue Feb 13, 2020 · 6 comments
Closed

PLATFORMIO_... environment variable causes a crash #3377

mcspr opened this issue Feb 13, 2020 · 6 comments
Assignees
Labels
Milestone

Comments

@mcspr
Copy link
Contributor

mcspr commented Feb 13, 2020

Configuration

Operating system: Linux

PlatformIO Version (platformio --version):

PlatformIO, version 4.2.0

Description of problem

For example, PLATFORMIO_SRC_BUILD_FLAGS=-DFOO will crash instantly

2763853d8 seems to be the cause

Steps to Reproduce

  1. upgrade to pio 4.2.0
  2. pio run to check that the project works
  3. env PLATFORMIO_SRC_BUILD_FLAGS='-DFOO' pio run will instantly crash

Actual Results

The specific issue is shown by this line:

 File "/home/max/git/platformio-core/platformio/project/config.py", line 276, in getraw
    value += ("" if value == MISSING else "\n") + envvar_value
TypeError: unsupported operand type(s) for +=: 'object' and 'str'

Full traceback:

> env PLATFORMIO_SRC_BUILD_FLAGS='-DFOO' pio run
Can not remove temporary directory `/home/max/Documents/PlatformIO/Projects/sysenv-test/.pio/build`. Please remove it manually to avoid build issues
Error: Traceback (most recent call last):
  File "/home/max/git/platformio-core/platformio/__main__.py", line 102, in main
    cli()  # pylint: disable=no-value-for-parameter
  File "/home/max/.platformio/penv/lib64/python3.8/site-packages/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/home/max/.platformio/penv/lib64/python3.8/site-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/home/max/git/platformio-core/platformio/commands/__init__.py", line 44, in invoke
    return super(PlatformioCLI, self).invoke(ctx)
  File "/home/max/.platformio/penv/lib64/python3.8/site-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/max/.platformio/penv/lib64/python3.8/site-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/max/.platformio/penv/lib64/python3.8/site-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/home/max/.platformio/penv/lib64/python3.8/site-packages/click/decorators.py", line 17, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/home/max/git/platformio-core/platformio/commands/run/command.py", line 128, in cli
    process_env(
  File "/home/max/git/platformio-core/platformio/commands/run/command.py", line 165, in process_env
    print_processing_header(name, config, verbose)
  File "/home/max/git/platformio-core/platformio/commands/run/command.py", line 191, in print_processing_header
    for k, v in config.items(env=env):
  File "/home/max/git/platformio-core/platformio/project/config.py", line 232, in items
    return [(option, self.get(section, option)) for option in self.options(section)]
  File "/home/max/git/platformio-core/platformio/project/config.py", line 232, in <listcomp>
    return [(option, self.get(section, option)) for option in self.options(section)]
  File "/home/max/git/platformio-core/platformio/project/config.py", line 305, in get
    value = self.getraw(section, option, default)
  File "/home/max/git/platformio-core/platformio/project/config.py", line 276, in getraw
    value += ("" if value == MISSING else "\n") + envvar_value
TypeError: unsupported operand type(s) for +=: 'object' and 'str'

============================================================

An unexpected error occurred. Further steps:

* Verify that you have the latest version of PlatformIO using
  `pip install -U platformio` command

* Try to find answer in FAQ Troubleshooting section
  https://docs.platformio.org/page/faq.html

* Report this problem to the developers
  https://github.com/platformio/platformio-core/issues

============================================================

Note about the trace: platformio penv is using git installation

> cat ~/.platformio/penv/lib/python3.8/site-packages/platformio.egg-link
/home/max/git/platformio-core

Expected Results

No crash

If problems with PlatformIO Build System:

The content of platformio.ini:

[env:test]
platform = espressif32
board = esp32dev
framework = arduino

Source file to reproduce issue:

#include <Arduino.h>
void setup() {}
void loop() {}

Additional info

First noticed this here:
https://travis-ci.org/xoseperez/espurna/jobs/649841340#L378

CI script uses PLATFORMIO_ variable to build

@ivankravets ivankravets added this to the 4.2.1 milestone Feb 13, 2020
@ivankravets ivankravets self-assigned this Feb 13, 2020
ivankravets added a commit to ivankravets/espurna that referenced this issue Feb 13, 2020
We would be thankful if you could use a development version of PlatformIO Core. in 99.999% it's very stable but there sometimes the cases which we didn't expect, such as platformio/platformio-core#3377

So, if you will see any issues with PlatformIO Core-dev, please report us and we will fix ASAP. Thanks!
@ivankravets
Copy link
Member

Thanks for the report. This my fault, I didn't cover this use case in a test when multiline system evironment is used :(

See xoseperez/espurna#2146

mcspr pushed a commit to xoseperez/espurna that referenced this issue Feb 14, 2020
We would be thankful if you could use a development version of PlatformIO Core. in 99.999% it's very stable but there sometimes the cases which we didn't expect, such as platformio/platformio-core#3377

So, if you will see any issues with PlatformIO Core-dev, please report us and we will fix ASAP. Thanks!
chenrui333 pushed a commit to Homebrew/homebrew-core that referenced this issue Feb 18, 2020
- [x] Have you followed the [guidelines for contributing](https://github.com/Homebrew/homebrew-core/blob/master/CONTRIBUTING.md)?
- [x] Have you checked that there aren't other open [pull requests](https://github.com/Homebrew/homebrew-core/pulls) for the same formula update/change?
- [x] Have you built your formula locally with `brew install --build-from-source <formula>`, where `<formula>` is the name of the formula you're submitting?
- [x] Is your test running fine `brew test <formula>`, where `<formula>` is the name of the formula you're submitting?
- [x] Does your build pass `brew audit --strict <formula>` (after doing `brew install <formula>`)?

-----

* Improved VSCode template with special ``forceInclude`` field for direct includes via ``-include`` flag ([issue #3379](platformio/platformio-core#3379))
* Improved support of PIO Home on card-sized PC (Raspberry Pi, etc.) ([issue #3313](platformio/platformio-core#3313))
* Froze "marshmallow" dependency to 2.X for Python 2 ([issue #3380](platformio/platformio-core#3380))
* Fixed "TypeError: unsupported operand type(s)" when system environment variable is used by project configuration parser ([issue #3377](platformio/platformio-core#3377))
* Fixed an issue when Library Dependency Finder (LDF) ignores custom "libLDFMode" and "libCompatMode" options in [library.json](http://docs.platformio.org/page/librarymanager/config.html)
* Fixed an issue when generating of compilation database "compile_commands.json" does not work with Python 2.7 ([issue #3378](platformio/platformio-core#3378))

Closes #50367.

Signed-off-by: Rui Chen <chenrui333@gmail.com>
@maksim-pinguin
Copy link

A similar issue is present on version 4.3.4a4 when build_flags are set through extra_configs in platformio.ini. Though the resulting error is a RecurrsionError.

@ivankravets
Copy link
Member

Could you provide a simple project to reproduce this issue?

@maksim-pinguin
Copy link

maksim-pinguin commented May 21, 2020

I just realized that i'm trying to add buildflags. By build_flags = ${env.build_flags}...etc.
Example:
platformio.ini:

...
[platformio]
   extra_configs = 
     credentials.ini

[env]
    build_flags = -DDEBUG
...

credentials.ini

[env]
build_flags = 
    ${env.build_flags}
    -DUSERNAME=user
    -DPASSWORD=pass

@maksim-pinguin
Copy link

So the issue is actually not about the build_flag in particular, it's about the re-referencing.
I'm sorry, about realizing it just now. Should I open a new issue for that?

@ivankravets
Copy link
Member

It’s not a bug. You are referencing to the same scope multiple time and are making infinite recursion.

Change env in credentials to something [wifi] and in main platformio.ini use $wifi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants