Skip to content

Sourcing built-in libraries when not bundled w/ classic IDE is undocumented or unintended #1565

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
per1234 opened this issue Nov 23, 2021 · 1 comment · Fixed by #1741 or #1817
Closed
Assignees
Labels
conclusion: resolved Issue was resolved priority: high Resolution is a high priority topic: code Related to content of the project itself topic: documentation Related to documentation for the project type: imperfection Perceived defect in any part of project

Comments

@per1234
Copy link
Contributor

per1234 commented Nov 23, 2021

During library discovery, Arduino CLI searches several locations, which are documented here. One of those locations can be the libraries subfolder of the Arduino IDE folder. The documented behavior:

https://arduino.github.io/arduino-cli/dev/sketch-build-process/#location-priority

This location is only used by Arduino CLI when it's located in the Arduino IDE installation folder

(Note this is referring to the classic Arduino IDE only. There is no special behavior when Arduino CLI is bundled with Arduino IDE 2.x)

Although that statement in the documentation is correct in regards to arduino-cli lib list, it turns out arduino-cli compile uses a completely different mechanism:

// Check if Arduino IDE is installed and get it's libraries location.
dataDir := paths.New(configuration.Settings.GetString("directories.Data"))
preferencesTxt := dataDir.Join("preferences.txt")
ideProperties, err := properties.LoadFromPath(preferencesTxt)
if err == nil {
lastIdeSubProperties := ideProperties.SubTree("last").SubTree("ide")
// Preferences can contain records from previous IDE versions. Find the latest one.
var pathVariants []string
for k := range lastIdeSubProperties.AsMap() {
if strings.HasSuffix(k, ".hardwarepath") {
pathVariants = append(pathVariants, k)
}
}
sort.Strings(pathVariants)
ideHardwarePath := lastIdeSubProperties.Get(pathVariants[len(pathVariants)-1])
ideLibrariesPath := filepath.Join(filepath.Dir(ideHardwarePath), "libraries")
builderCtx.BuiltInLibrariesDirs = paths.NewPathList(ideLibrariesPath)
}

The value of an internal data property from the classic Arduino IDE preferences file at {directories.data}/preferences.txt is used to define an additional libraries folder located at:

{last.ide.<*>.hardwarepath}/../libraries

Unlike the completely different mechanism used by arduino-cli lib list, the one used by arduino-cli compile adds the IDE built-in libraries folder even if Arduino CLI is not located inside a classic Arduino IDE installation.

Steps to reproduce

Generate the preferences.txt file

  1. Install a recent version of the classic Arduino IDE (e.g., 1.8.16) if an installation is already present on your computer.
  2. Start the classic IDE in normal mode (not in portable mode).
  3. Exit the classic IDE.

Demonstration of the use of the IDE built-in libraries by Arduino CLI

$ cat ~/AppData/Local/Arduino15/preferences.txt | grep "hardwarepath"
last.ide.1.8.16.hardwarepath=C:\Program Files (x86)\Arduino\hardware

$ which arduino-cli  # Arduino CLI is not bundled with IDE
/c/program-files/arduino/cli/arduino-cli_nightly/arduino-cli

$ arduino-cli version
arduino-cli.exe alpha Version: nightly-20211112 Commit: bf4a784 Date: 2021-11-12T01:26:50Z

$ arduino-cli lib uninstall Ethernet  # Clean up in case you already had the lib installed
$ arduino-cli core install arduino:avr
$ arduino-cli lib list --all Ethernet  # Output is as expected
No libraries installed.

$ mkdir /tmp/SomeEthernetSketch
$ printf "#include <Ethernet.h>\nvoid setup() {}\nvoid loop() {}\n" > /tmp/SomeEthernetSketch/SomeEthernetSketch.ino  # sketch that uses the Ethernet lib
$ arduino-cli compile -b arduino:avr:uno -v /tmp/SomeEthernetSketch
[...]
Using library Ethernet at version 2.0.0 in folder: C:\Program Files (x86)\Arduino\libraries\Ethernet
[...]

Note that, even though lib list doesn't consider the "Ethernet" library to be installed, and Arduino CLI is not bundled with the classic IDE installation, Arduino CLI still uses the classic IDE's built-in "Ethernet" library when compiling.

Recommendations

Since Arduino IDE 2.x does not have libraries built-in to its installation, I think it is best to just remove this capability from Arduino CLI.

If it is to be kept, then it is essential for the following two things to be done:

Additional information

This also occurs when using Arduino IDE 2.x, meaning that compilations in Arduino IDE 2.x use libraries from any installation of the classic Arduino IDE you might happen to have on your system. Although that is very unexpected behavior, it may currently be mitigating the impact of Arduino IDE 2.x not having built-in libraries. However, the built-in library capability will be replaced via a different mechanism in Arduino IDE 2.x. So, if at all, this is only a temporary benefit.

@per1234 per1234 added topic: code Related to content of the project itself topic: documentation Related to documentation for the project type: imperfection Perceived defect in any part of project labels Nov 23, 2021
@per1234 per1234 changed the title Sourcing built-in libraries when not bundled w/ Java IDE is undocumented or unintended Sourcing built-in libraries when not bundled w/ classic IDE is undocumented or unintended Nov 23, 2021
@per1234 per1234 linked a pull request May 31, 2022 that will close this issue
5 tasks
@per1234 per1234 added the conclusion: resolved Issue was resolved label May 31, 2022
@per1234
Copy link
Contributor Author

per1234 commented Jun 20, 2022

Reopening because there was a regression (I bisected to 427af56)

$ cat ~/AppData/Local/Arduino15/preferences.txt | grep "hardwarepath"
last.ide.1.8.19.hardwarepath=C:\Program Files (x86)\Arduino\hardware

$ which arduino-cli  # Arduino CLI is not bundled with IDE
/e/arduino/cli/arduino-cli_nightly/arduino-cli

$ arduino-cli version
arduino-cli.exe  Version: nightly-20220620 Commit: 64bc4dc Date: 2022-06-20T01:34:24Z

$ arduino-cli lib uninstall Ethernet  # Clean up in case you already had the lib installed
Library Ethernet is not installed

$ arduino-cli core install arduino:avr
Platform arduino:[email protected] already installed

$ arduino-cli lib list --all Ethernet  # Output is as expected
Name             Installed Available   Location                    Description
Ethernet         1.0.0     2.0.0       arduino:[email protected] Enables network connection (local and...
 "               2.0.0     -           esp32:[email protected]           -
 "               2.0.0     -           esp8266:[email protected]       -
Ethernet(Edison) 1.0       -           Intel:[email protected]+1.0        -
Ethernet         2.0.0     -           m5stack:[email protected]         -
 "               2.0.0     -           teensy:[email protected]          -


$ mkdir /tmp/SomeEthernetSketch

$ printf "#include <Ethernet.h>\nvoid setup() {}\nvoid loop() {}\n" > /tmp/SomeEthernetSketch/SomeEthernetSketch.ino  # sketch that uses the Ethernet lib

$ arduino-cli compile -b arduino:avr:uno -v /tmp/SomeEthernetSketch

[...]

Using library Ethernet at version 2.0.0 in folder: C:\Program Files (x86)\Arduino\libraries\Ethernet

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
conclusion: resolved Issue was resolved priority: high Resolution is a high priority topic: code Related to content of the project itself topic: documentation Related to documentation for the project type: imperfection Perceived defect in any part of project
Projects
None yet
4 participants