Description
#1276 added a nice new "Library Name Priority" feature where the library dependency system uses the similarity of the library name
value and the filename of an #include
directive as one of the factors in deciding which library to use when multiple matching matching libraries are installed. This was released with Arduino CLI 0.18.2 (and the Arduino IDE 1.8.14 and 2.0.0-beta.6 releases which use it).
Unfortunately, this change resulted in some platform bundled libraries which had previously been correctly correctly chosen no longer being given priority over the general purpose libraries from Arduino Library Manager.
An example:
$ arduino-cli version
arduino-cli.exe alpha Version: 0.18.2 Commit: 7b5a22a4 Date: 2021-05-10T14:30:17Z
$ arduino-cli lib install SD
$ arduino-cli core update-index --additional-urls https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json
$ arduino-cli core install esp32:esp32 --additional-urls https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json
$ mkdir /tmp/FooSketch
$ printf "#include <SD.h>\nvoid setup(){}\nvoid loop(){}" > /tmp/FooSketch/FooSketch.ino
$ arduino-cli compile --fqbn esp32:esp32:esp32 /tmp/FooSketch
In file included from C:\Users\per\Documents\Arduino\libraries\SD\src/utility/Sd2Card.h:26:0,
from C:\Users\per\Documents\Arduino\libraries\SD\src/utility/SdFat.h:29,
from C:\Users\per\Documents\Arduino\libraries\SD\src/SD.h:20,
from C:\Users\per\AppData\Local\Temp\FooSketch\FooSketch.ino:1:
C:\Users\per\Documents\Arduino\libraries\SD\src/utility/Sd2PinMap.h:524:2: error: #error Architecture or board not supported.
#error Architecture or board not supported.
^
Multiple libraries were found for "SD.h"
Used: C:\Users\per\Documents\Arduino\libraries\SD
Not used: C:\Users\per\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.6\libraries\SD
Error during build: exit status 1
You can see that the esp32:esp32
platform's bundled library, which is written specifically for ESP32 architecture, was not chosen, contrary to the expected behavior. The reason can be seen in the library's library.properties
metadata file here:
https://github.com/espressif/arduino-esp32/blob/1.0.6/libraries/SD/library.properties#L1
name=SD(esp32)
While the general purpose library's metadata is a perfect match for the SD.h
file of the #include
directive:
https://github.com/arduino-libraries/SD/blob/1.2.4/library.properties#L1
name=SD
The reason the names of some platform bundled libraries have these suffixes is to workaround a bug which caused libraries to be considered perpetually updatable by the the Arduino IDE's Library Manager when they had the same name as the platform bundled library:
arduino/Arduino#4189
This bug was fixed in Arduino IDE 1.8.6, ~3 years ago, but there was never a reason for the platform authors to change them back to their proper values.
Once this unexpected state of affairs was revealed, it was decided that the best approach would be to revert the change (#1290) and make a 0.18.3 release of Arduino CLI (accompanied by Arduino IDE 1.8.15 and 2.0.0-beta.7) in order to allow time for the maintainers of affected projects to prepare. The "Library Name Priority" feature will be added back in the next release of Arduino CLI and the IDEs. In order to ensure platform bundled libraries get the correct priority, the only necessary change is simply to change the library.properties name
values to match the primary header file after any spaces have been replaced by _
:
--- a/library.properties
+++ b/library.properties
@@ -1,4 +1,4 @@
-name=SD(esp32)
+name=SD
version=1.0.5
author=Arduino, SparkFun
maintainer=Arduino <[email protected]>
Standalone libraries should not be affected by this feature because the Library Manager installation folder name is determined by the name
value, and thus their dependency resolution priority was already dependent on the name.