arduino-cli icon indicating copy to clipboard operation
arduino-cli copied to clipboard

`lib examples` does not respect bundled versus installed libraries priority

Open JAndrassy opened this issue 3 years ago • 1 comments
trafficstars

In Examples menu a multi-platform library examples are shown instated of bundled library with the same name.

My ArduinoOTA library examples are in Examples menu even when esp8266 board is selected. The esp8266 platform has a bundled ArduinoOTA library. Old IDE has it OK.

OS Linux Mint if it matters

JAndrassy avatar Jan 05 '22 17:01 JAndrassy

I transferred this issue to the Arduino CLI repository because it seems the bug is in this code base:

$ arduino-cli version
arduino-cli.exe  Version: nightly-20220207 Commit: 10107d2 Date: 2022-02-07T01:28:33Z

$ arduino-cli core update-index --additional-urls https://arduino.esp8266.com/stable/package_esp8266com_index.json
Updating index: package_index.json downloaded / 439.91 KiB   23.64% 00m01s
Updating index: package_index.json.sig downloaded
Updating index: package_esp8266com_index.json downloaded85 KiB    0.00%

$ arduino-cli core install --additional-urls https://arduino.esp8266.com/stable/package_esp8266com_index.json esp8266:[email protected]
Downloading packages...
esp8266:[email protected] already downloaded
esp8266:[email protected] already downloaded
esp8266:[email protected] already downloaded
esp8266:[email protected] already downloaded
esp8266:[email protected] already downloaded
Installing esp8266:[email protected]...
esp8266:[email protected] installed
Installing esp8266:[email protected]...
esp8266:[email protected] installed
Installing esp8266:[email protected]...
esp8266:[email protected] installed
Installing esp8266:[email protected]...
esp8266:[email protected] installed
Installing platform esp8266:[email protected]...
Configuring platform....
Platform esp8266:[email protected] installed

$ arduino-cli lib install [email protected]
Downloading [email protected]...
[email protected] downloaded/ 69.86 KiB   68.71%
Installing [email protected]...
Installed [email protected]

$ arduino-cli lib examples --fqbn esp8266:esp8266:generic
Examples for library ArduinoOTA
  - C:\Users\per\Documents\Arduino\libraries\ArduinoOTA\examples\Advanced\OTASketchDownload
  - C:\Users\per\Documents\Arduino\libraries\ArduinoOTA\examples\Advanced\OTASketchDownload_SD
  - C:\Users\per\Documents\Arduino\libraries\ArduinoOTA\examples\Advanced\OTASketchDownloadWifi
  - C:\Users\per\Documents\Arduino\libraries\ArduinoOTA\examples\ATmega_SD
  - C:\Users\per\Documents\Arduino\libraries\ArduinoOTA\examples\OTEthernet
  - C:\Users\per\Documents\Arduino\libraries\ArduinoOTA\examples\OTEthernet_SD
  - C:\Users\per\Documents\Arduino\libraries\ArduinoOTA\examples\SerialWiFiOTA
  - C:\Users\per\Documents\Arduino\libraries\ArduinoOTA\examples\WiFi101_OTA
  - C:\Users\per\Documents\Arduino\libraries\ArduinoOTA\examples\WiFi101_SD_OTA

But this is not the library that is used when compiling for that board:

$ mkdir -p /tmp/ArduinoOTATest

$ echo "#include <ArduinoOTA.h>
> void setup() {}
> void loop() {}" > /tmp/ArduinoOTATest/ArduinoOTATest.ino

$ arduino-cli compile --fqbn esp8266:esp8266:generic -v /tmp/ArduinoOTATest

[...]

Multiple libraries were found for "ArduinoOTA.h"
  Used: C:\Users\per\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.2\libraries\ArduinoOTA
  Not used: C:\Users\per\Documents\Arduino\libraries\ArduinoOTA

The esp8266 platform bundled library is "architecture optimized" for the esp8266 architecture of the esp8266:esp8266:generic:

https://github.com/esp8266/Arduino/blob/3.0.2/libraries/ArduinoOTA/library.properties#L9

architectures=esp8266

This causes it to be given priority by the library dependency resolution system over the sketchbook installed "ArduinoOTA" library, which is only "architecture compatible":

https://github.com/jandrassy/ArduinoOTA/blob/1.0.7/library.properties#L9

architectures=*

As mentioned by jandrassy, Arduino IDE 2.x incorrectly shows the sketchbook installed "ArduinoOTA" library examples in the File > Examples menu, while Arduino IDE 1.8.19 and older correctly show the examples associated with the library that has architecture priority for the currently selected board:

  • Boards of the esp8266:esp8266 platform - the examples of the platform bundled "ArduinoOTA" library: image
  • Boards of any other platform - The examples of the sketchbook installed "ArduinoOTA" library: image

per1234 avatar Feb 07 '22 11:02 per1234