Platformio-core: Library Dependency Finder includes commented out libraries

Created on 15 Jun 2020  路  5Comments  路  Source: platformio/platformio-core

Configuration

Operating system: Windows 10 x64

PlatformIO Version : PlatformIO, version 4.3.4 + VS Code 1.46.0

Description of problem

I've found what I think is a bug. If I comment out an #include with library in one-line block comment (e.g. /*#include <EEPROM.h>*/), the library gets removed from Dependecy graph. This is correct behavior.

However, if I comment the #include with a multiline block comment like this:

/*
 #include <EEPROM.h>
*/

then the library still ends up in dependency graph, gets compiled etc.

Steps to Reproduce

  1. Create a simple project. I used an Arduino framework for Arduino Uno board. Leave all settings as default.
  2. Try the following code in main.cpp:
#include <Arduino.h>

/* #include <EEPROM.h> */

void setup() {
  // put your setup code here, to run once:
}

void loop() {
  // put your main code here, to run repeatedly:
}
  1. Build. The output includes lines
Scanning dependencies...
No dependencies
  1. Now try another code (only 2 newlines added):
#include <Arduino.h>

/* 
#include <EEPROM.h> 
*/

void setup() {
  // put your setup code here, to run once:
}

void loop() {
  // put your main code here, to run repeatedly:
}
  1. Build. This time the library gets included in build:
Scanning dependencies...
Dependency Graph
|-- <EEPROM> 2.0

Expected Results

In both cases the library should not be included in build.

Additional info

I'm using PIO from VS Code and installed all stuff via VS Code.

bug build system lib

All 5 comments

I've also tried enabling "chain+" mode in platformio.ini, but this did not change anything

Could it be similar behavior when the include is 'disabled' via #ifdef wrappers?

For example:

#ifdef USE_LIB_FOO
#include <foo>
#else
#include <bar>
#endif

AFAIK, since default search mode is chain, ifdefs are not supposed to work anyway (only in "chain+" or "deep+" modes). Comments, however, are.

@TD-er not sure if this help, but I created a quick test and I've added lib_ldf_mode = chain+ to platform.ini.

main.cpp:

#include <Arduino.h>

#ifdef USE_LITTLEFS
#include <FS.h>
#include <LittleFS.h>
#else
#include <FS.h>
#endif

void setup() {
  // put your setup code here, to run once:
}

void loop() {
  // put your main code here, to run repeatedly:
}

platform.ini file:

[env:d1_mini]
platform = espressif8266
board = d1_mini
framework = arduino
build_flags = -D USE_LITTLEFS
lib_ldf_mode = chain+

result:
image

platform.ini:

[env:d1_mini]
platform = espressif8266
board = d1_mini
framework = arduino
build_flags = -D NOT_USE_LITTLEFS; this has changed
lib_ldf_mode = chain+

image

I hope this helps 馃檪

Just for reference: docs.platformio.org - ldf-mode

I will try to use the chain+ mode.
But in the past I have also looked into this and then the chain+ mode (or the deep(+) mode) had some issues. Sadly I don't remember what those were.

Was this page helpful?
0 / 5 - 0 ratings