From 05bd8c2c0920b8a77c6e2837487704a8dfefa300 Mon Sep 17 00:00:00 2001 From: Silvano Cerza Date: Thu, 2 Dec 2021 15:36:44 +0100 Subject: [PATCH] Fix lib upgrade trying to upgrade core bundled libraries --- commands/lib/upgrade.go | 2 +- test/test_lib.py | 65 +++++++++++++++++++ .../platform_with_bundled_library/boards.txt | 26 ++++++++ .../libraries/USBHost/library.properties | 10 +++ .../platform.txt | 2 + 5 files changed, 104 insertions(+), 1 deletion(-) create mode 100644 test/testdata/platform_with_bundled_library/boards.txt create mode 100644 test/testdata/platform_with_bundled_library/libraries/USBHost/library.properties create mode 100644 test/testdata/platform_with_bundled_library/platform.txt diff --git a/commands/lib/upgrade.go b/commands/lib/upgrade.go index ac9a74c0669..3f6c83662e7 100644 --- a/commands/lib/upgrade.go +++ b/commands/lib/upgrade.go @@ -29,7 +29,7 @@ func LibraryUpgradeAll(instanceID int32, downloadCB commands.DownloadProgressCB, return &arduino.InvalidInstanceError{} } - if err := upgrade(lm, listLibraries(lm, true, true), downloadCB, taskCB); err != nil { + if err := upgrade(lm, listLibraries(lm, true, false), downloadCB, taskCB); err != nil { return err } diff --git a/test/test_lib.py b/test/test_lib.py index fb6fccd4c6d..8d89dffd8b7 100644 --- a/test/test_lib.py +++ b/test/test_lib.py @@ -16,6 +16,7 @@ import simplejson as json import pytest +import shutil from git import Repo from pathlib import Path import tempfile @@ -982,3 +983,67 @@ def test_install_git_invalid_library(run_command, data_dir, downloads_dir): assert res.failed assert "library not valid" in res.stderr assert not lib_install_dir.exists() + + +def test_upgrade_does_not_try_to_upgrade_bundled_core_libraries_in_sketchbook(run_command, data_dir): + test_platform_name = "platform_with_bundled_library" + platform_install_dir = Path(data_dir, "hardware", "arduino-beta-dev", test_platform_name) + platform_install_dir.mkdir(parents=True) + + # Install platform in Sketchbook hardware dir + shutil.copytree( + Path(__file__).parent / "testdata" / test_platform_name, + platform_install_dir, + dirs_exist_ok=True, + ) + + assert run_command(["update"]) + + # Install latest version of library identical to one + # bundled with test platform + assert run_command(["lib", "install", "USBHost"]) + + res = run_command(["lib", "list", "--all", "--format", "json"]) + assert res.ok + libs = json.loads(res.stdout) + assert len(libs) == 2 + # Verify both libraries have the same name + assert libs[0]["library"]["name"] == "USBHost" + assert libs[1]["library"]["name"] == "USBHost" + + res = run_command(["lib", "upgrade"]) + assert res.ok + # Empty output means nothing has been updated as expected + assert res.stdout == "" + + +def test_upgrade_does_not_try_to_upgrade_bundled_core_libraries(run_command, data_dir): + test_platform_name = "platform_with_bundled_library" + platform_install_dir = Path(data_dir, "packages", "arduino", "hardware", "arch", "4.2.0") + platform_install_dir.mkdir(parents=True) + + # Simulate installation of a platform with arduino-cli + shutil.copytree( + Path(__file__).parent / "testdata" / test_platform_name, + platform_install_dir, + dirs_exist_ok=True, + ) + + assert run_command(["update"]) + + # Install latest version of library identical to one + # bundled with test platform + assert run_command(["lib", "install", "USBHost"]) + + res = run_command(["lib", "list", "--all", "--format", "json"]) + assert res.ok + libs = json.loads(res.stdout) + assert len(libs) == 2 + # Verify both libraries have the same name + assert libs[0]["library"]["name"] == "USBHost" + assert libs[1]["library"]["name"] == "USBHost" + + res = run_command(["lib", "upgrade"]) + assert res.ok + # Empty output means nothing has been updated as expected + assert res.stdout == "" diff --git a/test/testdata/platform_with_bundled_library/boards.txt b/test/testdata/platform_with_bundled_library/boards.txt new file mode 100644 index 00000000000..4dd9deb08e3 --- /dev/null +++ b/test/testdata/platform_with_bundled_library/boards.txt @@ -0,0 +1,26 @@ +nessuno.name=Arduino Nessuno +nessuno.vid.0=0x2341 +nessuno.pid.0=0x0043 +nessuno.vid.1=0x2341 +nessuno.pid.1=0x0001 +nessuno.vid.2=0x2A03 +nessuno.pid.2=0x0043 +nessuno.vid.3=0x2341 +nessuno.pid.3=0x0243 +nessuno.upload.tool=avrdude +nessuno.upload.protocol=arduino +nessuno.upload.maximum_size=32256 +nessuno.upload.maximum_data_size=2048 +nessuno.upload.speed=115200 +nessuno.bootloader.tool=avrdude +nessuno.bootloader.low_fuses=0xFF +nessuno.bootloader.high_fuses=0xDE +nessuno.bootloader.extended_fuses=0xFD +nessuno.bootloader.unlock_bits=0x3F +nessuno.bootloader.lock_bits=0x0F +nessuno.bootloader.file=optiboot/optiboot_atmega328.hex +nessuno.build.mcu=atmega328p +nessuno.build.f_cpu=16000000L +nessuno.build.board=AVR_NESSUNO +nessuno.build.core=arduino +nessuno.build.variant=standard diff --git a/test/testdata/platform_with_bundled_library/libraries/USBHost/library.properties b/test/testdata/platform_with_bundled_library/libraries/USBHost/library.properties new file mode 100644 index 00000000000..8da1df76113 --- /dev/null +++ b/test/testdata/platform_with_bundled_library/libraries/USBHost/library.properties @@ -0,0 +1,10 @@ +name=USBHost +version=0.0.1 +author=Arduino +maintainer=Arduino +sentence=Allows the communication with USB peripherals like mice, keyboards, and thumbdrives. For Arduino MKR1000 and Zero. +paragraph=The USBHost library allows the board to appear as a USB host, enabling it to communicate with peripherals like USB mice and keyboards. USBHost does not support devices that are connected through USB hubs. This includes some keyboards that have an internal hub. +category=Other +url=https://www.arduino.cc/en/Reference/USBHost +architectures=samd + diff --git a/test/testdata/platform_with_bundled_library/platform.txt b/test/testdata/platform_with_bundled_library/platform.txt new file mode 100644 index 00000000000..682f130ed49 --- /dev/null +++ b/test/testdata/platform_with_bundled_library/platform.txt @@ -0,0 +1,2 @@ +name=Arduino Test Boards +version=4.2.0 \ No newline at end of file