What is the proper way to remove a dependency? Or more specifically: What do I need to do so PlatformIO removes it from .pio/libdeps/board/ once I have remove it from platformio.ini?
Here’s an example:
platformio.ini:
[env:uno]
platform = atmelavr
board = uno
framework = arduino
This code does not compile as the IRremote library is needed. As expected, the error message is:
src/main.cpp:2:22: fatal error: IRremote.h: No such file or directory
So the following lines are added to platformio.ini:
lib_deps =
4
Now the project successfully builds. So far everything is as expected.
Step 2: Remove the dependency
Now we remove lib_deps from platformio.ini and revert to the initial, invalid configuration. Even though a library dependency is missing, the project still builds successfully.
Cause
The reason is that the library is still present in .pio/libdeps/uno/IRremote_ID4. Neither pio run -t clean nor pio lib update won’t help. The latter one even lists the library even though it is no longer presennt in platformio.ini.
This is surprising because installing a library is automatic and uninstalling is not. If the project is pushed to git and checked out in a different place, it won’t compile. Beginners also seem to struggle regularly with this surprising behaviour as can be witnessed in this forum. The unfortunate result is that PlatformIO appears to be an unreliable tool.
Of course, I understand that I can remove the .pio folder to get rid of the dependency. But isn’t there any better way? Shouldn’t it happen automatically when platformio.ini has been changed and the project is rebuilt? Or at least when the clean target is run?
We plan to introduce new Package Registry soon. So, you will not need to use these magic number more, such as lib_deps = 4. Today, we don’t have unique pair for library dependency. A lot of libraries use the same name which leads a lot of problems.The format will be the next:
lib_deps = @owner/libraryName
or
lib_deps = @owner/libraryName@~1.2.3
If we will have 1:1 information about your dependencies, we can control them properly.
Now 1.5 year later the dependency information is updated but removing a dependency from lib_deps in platformio.ini still doesn’t remove its files from the .pio/libdeps/board/ folder.
Why is it even an issue? You can just delete .pio folder entirely. If I understand correctly, it is like a cache and will be recreated on the next rebuild.