Add the ability to find libraries in sketch folder. by Steve132 · Pull Request #11110 · arduino/Arduino
I'd be very happy if this was finally supported. I hadn't realized that this would be so easy to implement.
This preference is disabled by default in order to avoid breaking past behavior by default (in the exceedingly unlikely case that the user had a libraries directory in their sketch that they did NOT wish to be compiled).
I wonder if this shouldn't just be enabled by default. If this is enabled by default, it really makes it easier to distribute self-contained sketches, without having to instruct recipients to explicitly enable this extra preference.
As you say, it seems rather unlikely that sketches have an existing libraries directory (if they have it, I'd think it would contain libraries intended to be used, originally by copying into the sketchbook libraries dir, which would now just be easier. Some sketches might have modified libraries intended to be included with relative includes rather than through the Arduino-generated include paths, but those would typically be in src/libraries and even if not, such direct includes would still work and not trigger library detection for these libraries).
Going even further, I wonder if we need a visible preference for this at all? If this is just enabled by default, having a preference in preferences.txt (but not shown in the GUI) to disable it just in case could be fine.
This feature is not needed to be implemented in arduino-cli, because the user of arduino-cli could always manually add "--libraries pwd" or similar very easily in their command line build. However, it may be a good idea to add by default as a potential future feature.
I would really want to see this in arduino-cli as well (also enabled by default IMHO), since then a single sketch will end up behaving the same between -cli and the IDE. I suspect that this is similarly easy to implement in arduino-cli, though.
Did you check what the priority of this extra libraries directory will be? IIRC arduino-builder has some code to apply different priorities to different library folders (In particular the platform-specific libraries are treated specially, probably using the order specified on the commandline for other libraries?).
I haven't tested this yet, will do that soon as well.