Replacing files with build middleware

Hi, i need some help :slight_smile:

I am quite new to library creating with platformio and i am running into some issues. I am trying to make a library related to usb ports of stm32 chips since the basic functionality is quite limited atm in stm32duino. So far so good, i have the code almost completed.

Now i need to somehow replace existing files in the framework with my own source files, since the usb library of st expect a certain header and some files to exist. Even if i manually delete the from the package dir the usb library can’t find my headers, so i think i need to do smth with a build middleware. But now i notice if i register my middleware only the nodes of my own library are being shown to the middleware, so i am unable to replace the ones of the framework.

the py:

Import("env")
def replace_node_with_another(node):
    print("node found:")
    print(node)
    return node

env.AddBuildMiddleware(replace_node_with_another)

(This is basically copied from the example)
Output:

Dependency Graph
|-- <USBLibrarySTM32> 0.1.0
|-- <Joystick> 2.1.0
|   |-- <USBLibrarySTM32> 0.1.0
|-- <Mouse> 1.0.1
|   |-- <USBLibrarySTM32> 0.1.0
node found:
D:\Source\Local\DerailingStick\.pio\libdeps\blackpill\USBLibrarySTM32\src\CDC.cpp
node found:
D:\Source\Local\DerailingStick\.pio\libdeps\blackpill\USBLibrarySTM32\src\HID.cpp
node found:
D:\Source\Local\DerailingStick\.pio\libdeps\blackpill\USBLibrarySTM32\src\PluggableUSB.cpp
node found:
D:\Source\Local\DerailingStick\.pio\libdeps\blackpill\USBLibrarySTM32\src\USBCore.cpp
node found:
D:\Source\Local\DerailingStick\.pio\libdeps\blackpill\USBLibrarySTM32\src\USB\usb_device_core.c
node found:
D:\Source\Local\DerailingStick\.pio\libdeps\blackpill\USBLibrarySTM32\src\USB\usb_device_ctlreq.c
node found:
D:\Source\Local\DerailingStick\.pio\libdeps\blackpill\USBLibrarySTM32\src\USB\usb_device_ioreq.c
node found:
D:\Source\Local\DerailingStick\.pio\libdeps\blackpill\USBLibrarySTM32\src\USB\usbd_conf.c
node found:
D:\Source\Local\DerailingStick\.pio\libdeps\blackpill\USBLibrarySTM32\src\USB\usbd_desc.c
node found:
D:\Source\Local\DerailingStick\.pio\libdeps\blackpill\USBLibrarySTM32\src\USB\usbd_ep_conf.c
node found:
D:\Source\Local\DerailingStick\.pio\libdeps\blackpill\USBLibrarySTM32\src\USB\usbd_if.c
Building in release mode
(...)

So is there a better way to do this? or how do i replace framework files with the middleware?
Thanks!