From 90bfe00f21e86ee44938390d30621b273f958500 Mon Sep 17 00:00:00 2001 From: Joshua Harley Date: Tue, 1 Dec 2020 23:37:56 -0700 Subject: [PATCH 1/3] Add basic support for arduino-cli detection This adds the most basic of support for the environment created from downloading the Arduino SDK via the official [arduino-cli project][1]. It fixes two issues encountered with detection: 1. If `set(ARDUINO_INSTALL_PATH "$env{LOCALAPPDATA}/Arduino15` is used, it will work, however the make system will loudly complain that it is unable to read `lib/version.txt`, however generation will succeed. 2. By default, the cli installation is not detected, so this adds the install path hint of the `$env{LOCALAPPDATA}/Arduino15` path and adds basic detection of `arduino-cli.yaml` which is created from the cli setup process. The Linux update has been validated using Debian Buser running under WSL1 and all tools work as far as I can tell, including detection, build, sizing, and upload. I do not have a Mac available to test, but I am basing the assumption of `$ENV{HOME}/Library/Arduino15` as the install point since that's in the package path as well. Using the tool, running a command like `arduino-cli core install arduino:samd` will download the tooling, the core, and set up the environment. Originally I was detecting `arduino-cli.yaml` as the marker file but under a brand new installation on Linux that file did not exist, but `inventory.yaml` did. I was unable to detect any version information of a matching SDK or arduino-cli version, so the assumption of the file existing was enough to trigger the new flow. [1]: https://github.com/arduino/arduino-cli --- Arduino/System/PackagePathIndex.cmake | 29 ++++++++++++++++++--------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/Arduino/System/PackagePathIndex.cmake b/Arduino/System/PackagePathIndex.cmake index 0ec6986..3723809 100644 --- a/Arduino/System/PackagePathIndex.cmake +++ b/Arduino/System/PackagePathIndex.cmake @@ -19,7 +19,8 @@ function(InitializeArduinoPackagePathList) if (${CMAKE_HOST_APPLE}) - set(install_search_paths "$ENV{HOME}/Applications" /Applications + set(install_search_paths "$ENV{HOME}/Applications" + "$ENV{HOME}/Library/Arduino15" /Applications /Developer/Applications /sw /opt/local) set(install_path_suffixes Arduino.app/Contents/Java Arduino.app/Contents/Resources/Java) @@ -57,6 +58,8 @@ function(InitializeArduinoPackagePathList) DIRECTORY) list(APPEND install_search_paths "${_install_path}") endif() + elseif(EXISTS "$ENV{HOME}/.arduino15/inventory.yaml") + list(APPEND install_search_paths "$ENV{HOME}/.arduino15") endif() endif() @@ -76,7 +79,8 @@ function(InitializeArduinoPackagePathList) set(Prog86Path "ProgramFiles(x86)") set(install_search_paths "$ENV{${Prog86Path}}/Arduino" - "$ENV{ProgramFiles}/Arduino") + "$ENV{ProgramFiles}/Arduino" + "$ENV{LOCALAPPDATA}/Arduino15") set(install_path_suffixes "") file(GLOB package_search_paths "$ENV{LOCALAPPDATA}/Arduino15") @@ -97,7 +101,7 @@ function(InitializeArduinoPackagePathList) # Search for Arduino install path find_path(ARDUINO_INSTALL_PATH - NAMES lib/version.txt + NAMES lib/version.txt inventory.yaml PATH_SUFFIXES ${install_path_suffixes} HINTS ${install_search_paths} NO_DEFAULT_PATH @@ -110,13 +114,18 @@ function(InitializeArduinoPackagePathList) "Use -DARDUINO_INSTALL_PATH= to manually specify the path (OR)\n" "Use -DARDUINO_BOARD_MANAGER_URL= to try downloading\n") elseif(ARDUINO_INSTALL_PATH AND NOT "${ARDUINO_ENABLE_PACKAGE_MANAGER}" - AND "${ARDUINO_BOARD_MANAGER_URL}" STREQUAL "") - message("${ARDUINO_INSTALL_PATH}") - file(READ "${ARDUINO_INSTALL_PATH}/lib/version.txt" _version) - string(REGEX MATCH "[0-9]+\\.[0-9]" _ard_version "${_version}") - if (_version AND "${_ard_version}" VERSION_LESS "1.5") - message(WARNING "${ARDUINO_INSTALL_PATH} may be unsupported version " - "${_version}. Please install newer version!") + AND "${ARDUINO_BOARD_MANAGER_URL}" STREQUAL "") + if (EXISTS "${ARDUINO_INSTALL_PATH}/lib/version.txt") + message("${ARDUINO_INSTALL_PATH}") + file(READ "${ARDUINO_INSTALL_PATH}/lib/version.txt" _version) + string(REGEX MATCH "[0-9]+\\.[0-9]" _ard_version "${_version}") + message("${_ard_version}") + if (_version AND "${_ard_version}" VERSION_LESS "1.5") + message(WARNING "${ARDUINO_INSTALL_PATH} may be unsupported version " + "${_version}. Please install newer version!") + endif() + elseif(EXISTS "${ARDUINO_INSTALL_PATH}/inventory.yaml") + message("arduino-cli found at ${ARDUINO_INSTALL_PATH}") endif() endif() From 318ef56d973bb49a74bfc05374bbb7786ac0f012 Mon Sep 17 00:00:00 2001 From: Joshua Harley Date: Mon, 17 May 2021 19:56:00 -0600 Subject: [PATCH 2/3] Fix registry bug when globbing for sketchbook The existing code fails on Windows installations as it was checking `HKEY_LOCAL_MACHINE` instead of the user defined/customized `HKEY_CURRENT_USER` as the `Personal` registry value only exists in the user registry. Additionally, the `file` command does not seem to resolve the registry directive, so an additional call to `get_filename_component` was added to resolve the directory path. --- Arduino/System/PackagePathIndex.cmake | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Arduino/System/PackagePathIndex.cmake b/Arduino/System/PackagePathIndex.cmake index 3723809..320f216 100644 --- a/Arduino/System/PackagePathIndex.cmake +++ b/Arduino/System/PackagePathIndex.cmake @@ -86,11 +86,14 @@ function(InitializeArduinoPackagePathList) file(GLOB package_search_paths "$ENV{LOCALAPPDATA}/Arduino15") set(package_path_suffixes "") - set(_reg_software "HKEY_LOCAL_MACHINE\\SOFTWARE") + set(_reg_software "HKEY_CURRENT_USER\\SOFTWARE") set(_reg_win "${_reg_software}\\Microsoft\\Windows\\CurrentVersion") set(_reg_explorer "${_reg_win}\\Explorer") + get_filename_component(_reg_documents + "[${_reg_explorer}\\User Shell Folders;Personal]" ABSOLUTE) + file(GLOB sketchbook_search_paths "$ENV{LOCALAPPDATA}/Arduino15" - "[${_reg_explorer}\\User Shell Folders;Personal]/ArduinoData") + "${_reg_documents}/ArduinoData") set(sketchbook_path_suffixes "") else() From 243a076216eb699c8b74a06fbcc2e2dbb179a889 Mon Sep 17 00:00:00 2001 From: Joshua Harley Date: Mon, 17 May 2021 20:02:57 -0600 Subject: [PATCH 3/3] Add support for cli-installed libs without IDE If a library is installed from the Arduino CLI via `arduino-cli lib install ` on Windows, the default location for the installed library is under `Documents/Arduino/Libraries/`. When the IDE is not installed, a preferences file pointing to this location is not created and is not recognized by the build system. This attempts to resolve the issue by detecting a missing sketchbook location and the existance of the `_reg_documents` variable (resolved when setting up package paths) by resolving the location and setting the appropriate `ARDUINO_SKETCHBOOK_PATH` variable, allowing library searches to find libraries installed by the CLI. --- Arduino/System/PackagePathIndex.cmake | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Arduino/System/PackagePathIndex.cmake b/Arduino/System/PackagePathIndex.cmake index 320f216..65c57bc 100644 --- a/Arduino/System/PackagePathIndex.cmake +++ b/Arduino/System/PackagePathIndex.cmake @@ -162,6 +162,18 @@ function(InitializeArduinoPackagePathList) endif() # message("ARDUINO_SKETCHBOOK_PATH:${ARDUINO_SKETCHBOOK_PATH}") + # support arduino-cli package downloads on Windows. Sketchbook path will be + # not found if IDE is not installed, so use the Documents/Arduino as + # additional library lookup paths. This is the expected location when running + # arduino-cli lib install . + if (NOT ARDUINO_SKETCHBOOK_PATH AND _reg_documents) + file(GLOB _reg_doc_lib "${_reg_documents}/Arduino") + if (_reg_doc_lib) + set(ARDUINO_SKETCHBOOK_PATH "${_reg_doc_lib}" + CACHE PATH "Path to Arduino Libraries") + endif() + endif() + # Arduino local package management path if (NOT ARDUINO_PACKAGE_MANAGER_PATH) set(ARDUINO_PACKAGE_MANAGER_PATH