**EDIT5:** It seems by default the LDF mode chain, only looks at libname.cpp dependencies, so anything not references in this cpp file wont be available, do work with local libraries the way I want you need to change the following setting in platformio.ini:
lib_ldf_mode = deep
I think this whole domain is quite undocumented / unclear and would have loved if there where established best pracises in the main docs of platformio for this kind of setup
Hello, I am struggling getting my project from initial proof of concept to something I am more proud of.
I want all my logic to be testable and not dependent on a specific framework or platform, so I have created a local library called “hal” for my project.
I have struggled back and forth with library.json and extrascript.
I now have the following extrascript
framework = env.get("PIOFRAMEWORK")
print(env.Dump())
if isinstance(framework, list):
framework = framework[0]
else:
framework = "native"
platform = env.get("PIOPLATFORM")
env.Replace(SRC_FILTER=["+<*>", "-<framework*>", "-<platform*>", "+<framework/%s>" % framework, "+<platform/%s>" % platform])
This works as I want however, for some weird reason, whenever I have cpp files in subfolders I get the following error trying to compile my hal_arduino.cpp
2 | #include <EEPROM.h>
| ^~~~~~~~~~
compilation terminated.
*** [.pio/build/d1_mini/lib224/hal/framework/arduino/hal_arduino.cpp.o] Error 1
if I have this include in my lib/hal/hal.cpp it works, iif i have it in lib/hal/hal_blabla.cpp it doesnt, if i have it in subfolder it does not work.
for some reason Arduino.h works to include, but not EEPROM.h from my esp8266 platform.
Any ideas? Any best practices to structure projects with support for multiple platforms and unit testing of classes?
EDIT: flattening it seems to work… so with this script it seems to work, so probably its the subdirs causing the issue…
framework = env.get("PIOFRAMEWORK")
print(env.Dump())
if isinstance(framework, list):
framework = framework[0]
else:
framework = "native"
platform = env.get("PIOPLATFORM")
env.Replace(SRC_FILTER=["+<*>", "-<hal_*>", "-<platform*>", "+<hal_%s>" % framework, "+<hal_%s_%s>" % (framework, platform)])
However, best practices would be nice here, I cant be the only one struggling defining this?
Edit2: Stil does not work, it just didnt pickup my cpp files now so I got linkage errors instead
EDIT3: After hardcoding the src_filter to only care about the files I want for specific build i am back to include EEPROM issue…
2 | #include <EEPROM.h>
| ^~~~~~~~~~
compilation terminated.
*** [.pio/build/d1_mini/lib224/hal/hal_arduino.cpp.o] Error 1```
EDIT4: If I add #include <EEPROM.h> into hal.cpp, including it in hal_arduino.cpp works.... (not very usefull as hal.cpp becomes HW dependent) is ther some sort of "smart dependency scanner" that is messing with me?