Skip to content

Library dependency finder ignores build_src_flags #4253

@mcspr

Description

@mcspr
  • Feature Request.
    Start by telling us what problem you’re trying to solve. Often a solution
    already exists! Don’t send pull requests to implement new features without first getting our
    support. Sometimes we leave features out on purpose to keep the project small.

Configuration

Operating system: Fedora 36

PlatformIO Version (platformio --version): PlatformIO Core, version 6.0.0a2

Description of problem

MCVE of the currently not working code is at https://github.com/mcspr/pio-scan-deps
Latest action run reproduces the error below https://github.com/mcspr/pio-scan-deps/runs/6246889310

The project is:

> tree
.
├── platformio.ini
├── src
│   ├── extra.cpp
│   ├── extra.h
│   └── main.cpp
└── vendor
    └── testlib
        ├── library.json
        └── src
            ├── testlib.cpp
            └── testlib.h

Where extra.cpp conditionally includes a local library

#if THIS_IS_A_TEST
#include <testlib.h>
... the rest of the module's code ...
#endif

When lib_ldf_mode = deep+ is set, PIO scanner will ignore the testlib.h
GCC still picks it up, though, resulting in a failed build

> env PLATFORMIO_BUILD_FLAGS="-DTHIS_IS_A_TEST=1" pio run -s
> env PLATFORMIO_SRC_BUILD_FLAGS="-DTHIS_IS_A_TEST=1" pio run -s
src/extra.cpp:4:10: fatal error: testlib.h: No such file or directory

*****************************************************************
* Looking for testlib.h dependency? Check our library registry!
*
* CLI  > platformio lib search "header:testlib.h"
* Web  > https://registry.platformio.org/search?q=header:testlib.h
*
*****************************************************************

    4 | #include <testlib.h>
      |          ^~~~~~~~~~~
compilation terminated.
*** [.pio/build/d1_mini/src/extra.cpp.o] Error 1

While I have noticed that examples in documentation only mention the build_flags = ... as a way to modify the dependency scanner behaviour...
I am not really sure whether this was intentional that project build flags are ignored?
Should the scanner do a 2nd pass with the project dependencies, while using the flags provided in the src_build_flags?

Steps to Reproduce

See the repo

If problems with PlatformIO Build System:

The content of platformio.ini:

[env]
platform = espressif8266
framework = arduino
build_flags = -g
lib_ldf_mode = deep+
lib_extra_dirs =
    vendor

[env:d1_mini]
board = d1_mini

Source file to reproduce issue:

// src/main.cpp

#include <Arduino.h>
#include "extra.h"

void setup() {
#if THIS_IS_A_TEST
    test();
#endif
}

void loop() {
}
// src/extra.cpp

#include <Arduino.h>

#if THIS_IS_A_TEST
#include <testlib.h>

void test() {
}
#endif
// src/extra.h

#pragma once

void test();

Plus, a dummy library consisting of lib/testlib/src/testlib.h and lib/testlib/src/testlib.cpp. Both are empty.

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions