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

env.AddBuildMiddleware() breaks library includes #4738

Open
1 task done
maxgerhardt opened this issue Sep 5, 2023 · 0 comments
Open
1 task done

env.AddBuildMiddleware() breaks library includes #4738

maxgerhardt opened this issue Sep 5, 2023 · 0 comments
Labels
build system ldf Library Dependency Finder

Comments

@maxgerhardt
Copy link
Contributor

maxgerhardt commented Sep 5, 2023

What kind of issue is this?

  • PlatformIO Core.
    If you’ve found a bug, please provide an information below.

Configuration

Operating system: Windows 10 x64

PlatformIO Version (platformio --version): 6.1.12a1

Description of problem

Per documentation it is possible to use env.AddBuildMiddleware(callback, pattern) to modify the compile settings of specific files (SCons objects).

However, even returning env.Object(node), that is without any other options to modify compiler settings, in the callback to this function breaks PlatformIO's ability to identify the library dependencies or at least add the proper include compiler settings to the build of that specific file. Specifically, creating a minimal library MyTestLib in the lib/ folder with one .h and .cpp file implemeting a simple return 42; function and adding #include "MyTestLib.h" to the src/main.cpp will fail compilation if this extra_scripts = pre:test.py is added:

Import("env")

def pass_through(node):
    print("Node '%s'" % (node.name))
    #print("Type: " + str(type(node)))
    # pass through works fine
    #return node
    # wrapped in env.Object() fails, even when not modfying settings
    return env.Object(node)

env.AddBuildMiddleware(pass_through)

Note that return node itself works fine, but that eliminates any possibility to modify compiler settings for just that file.

Steps to Reproduce

  1. Download https://github.com/maxgerhardt/pio-middleware-bug-repro
  2. Open in VSCode
  3. Attempt to compile (--> should fail)
  4. Comment in return node
  5. Build again (--> should work)

Actual Results

Scanning dependencies...
Dependency Graph
|-- MyTestLib (License: Unknown, Path: C:\Users\Max\temp\gran\lib\MyTestLib)
Node 'MyTestLib.cpp'
Node 'main.cpp'
Building in release mode
avr-g++ -o .pio\build\controllino_mega\src\main.cpp.o -c -fno-exceptions -fno-threadsafe-statics -fpermissive -std=gnu++11 -mmcu=atmega2560 -Os -Wall -ffunction-sections -fdata-sections -flto -DPLATFORMIO=60112 -DARDUINO_AVR_MEGA2560 -DF_CPU=16000000L -DARDUINO_ARCH_AVR -DARDUINO=10808 -IC:\Users\Max\.platformio\packages\framework-arduino-avr\cores\arduino -IC:\Users\Max\.platformio\packages\framework-arduino-avr\variants\Controllino_mega src\main.cpp
src\main.cpp:2:10: fatal error: MyTestLib.h: No such file or directory

Expected Results

Should compile fine since no compiler settings were modified (yet), node was just wrapped into an env.Object() like the documentation suggests is possible.

If problems with PlatformIO Build System:

The content of platformio.ini:

[env:controllino_mega]
platform = atmelavr
board = controllino_mega
framework = arduino
extra_scripts = pre:test.py

Source file to reproduce issue:

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

void setup() {
    Serial.begin(9600);
}

void loop() {
    int ret = MyTestLib_Function();
    Serial.println(ret);
    delay(1000);
}

Additional info

Relevant use-case per https://community.platformio.org/t/how-to-use-custom-debug-build-flags-per-file/35593.

@maxgerhardt maxgerhardt changed the title env.AddBuildMiddleware() breaks library finder env.AddBuildMiddleware() breaks library includes Sep 6, 2023
@ivankravets ivankravets added ldf Library Dependency Finder build system labels Sep 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build system ldf Library Dependency Finder
Projects
None yet
Development

No branches or pull requests

2 participants