Can't modify lib_deps in extra script

Hello,

In my platformio, i have a root env where I have defined lib_deps for all my sub env and I want to add some libraries in few sub-env.

I have made an extrascript

Import("env")
libs=env.GetProjectOption("lib_deps")
libs.append("crankyoldgit/IRremoteESP8266@2.7.9")
print(libs)

env.Replace(lib_deps=libs)

but it doesn’t work
libs contains all the librairies but during build IRremoteESP8266 isn’t used.
I think the line "env.Replace(lib_deps=libs) is wrong !

Check out

So you could try

Import("env")
platform = env.PioPlatform()
libs=env.GetProjectOption("lib_deps")
libs.append("crankyoldgit/IRremoteESP8266@2.7.9")
print(libs)
env_section = "env:" + env["PIOENV"]
platform.config.set(env_section, "lib_deps", libs)

Thank you Max,
It works very well

Hi @maxgerhardt ,

I tried this on an “extraScript” called by a library.json but it doesn’t seem to work.
Is it possible to do it from a script called by a library.json ?

Mhh if you’re already inside a library you should try and make PlatformIO include the right libraries by means of dependencies declaration and libLDFMode, at most activating a few macros in an extra script for that selection to happen dynamically if it must. I also had no successs modifying platform.config.set(env_section, "lib_deps", libs) in a library’s extraScript, no matter the construction environment. If the issues remain, try opening a new topic with all info or https://github.com/platformio/platformio-core/issues.

1 Like