Skip to content

Commit 648039f

Browse files
silvanocerzaumbynos
authored andcommitted
Fix lib upgrade trying to upgrade core bundled libraries (#1580)
1 parent 0951b37 commit 648039f

File tree

5 files changed

+104
-1
lines changed

5 files changed

+104
-1
lines changed

Diff for: commands/lib/upgrade.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func LibraryUpgradeAll(instanceID int32, downloadCB commands.DownloadProgressCB,
2929
return &arduino.InvalidInstanceError{}
3030
}
3131

32-
if err := upgrade(lm, listLibraries(lm, true, true), downloadCB, taskCB); err != nil {
32+
if err := upgrade(lm, listLibraries(lm, true, false), downloadCB, taskCB); err != nil {
3333
return err
3434
}
3535

Diff for: test/test_lib.py

+65
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import simplejson as json
1818
import pytest
19+
import shutil
1920
from git import Repo
2021
from pathlib import Path
2122
import tempfile
@@ -982,3 +983,67 @@ def test_install_git_invalid_library(run_command, data_dir, downloads_dir):
982983
assert res.failed
983984
assert "library not valid" in res.stderr
984985
assert not lib_install_dir.exists()
986+
987+
988+
def test_upgrade_does_not_try_to_upgrade_bundled_core_libraries_in_sketchbook(run_command, data_dir):
989+
test_platform_name = "platform_with_bundled_library"
990+
platform_install_dir = Path(data_dir, "hardware", "arduino-beta-dev", test_platform_name)
991+
platform_install_dir.mkdir(parents=True)
992+
993+
# Install platform in Sketchbook hardware dir
994+
shutil.copytree(
995+
Path(__file__).parent / "testdata" / test_platform_name,
996+
platform_install_dir,
997+
dirs_exist_ok=True,
998+
)
999+
1000+
assert run_command(["update"])
1001+
1002+
# Install latest version of library identical to one
1003+
# bundled with test platform
1004+
assert run_command(["lib", "install", "USBHost"])
1005+
1006+
res = run_command(["lib", "list", "--all", "--format", "json"])
1007+
assert res.ok
1008+
libs = json.loads(res.stdout)
1009+
assert len(libs) == 2
1010+
# Verify both libraries have the same name
1011+
assert libs[0]["library"]["name"] == "USBHost"
1012+
assert libs[1]["library"]["name"] == "USBHost"
1013+
1014+
res = run_command(["lib", "upgrade"])
1015+
assert res.ok
1016+
# Empty output means nothing has been updated as expected
1017+
assert res.stdout == ""
1018+
1019+
1020+
def test_upgrade_does_not_try_to_upgrade_bundled_core_libraries(run_command, data_dir):
1021+
test_platform_name = "platform_with_bundled_library"
1022+
platform_install_dir = Path(data_dir, "packages", "arduino", "hardware", "arch", "4.2.0")
1023+
platform_install_dir.mkdir(parents=True)
1024+
1025+
# Simulate installation of a platform with arduino-cli
1026+
shutil.copytree(
1027+
Path(__file__).parent / "testdata" / test_platform_name,
1028+
platform_install_dir,
1029+
dirs_exist_ok=True,
1030+
)
1031+
1032+
assert run_command(["update"])
1033+
1034+
# Install latest version of library identical to one
1035+
# bundled with test platform
1036+
assert run_command(["lib", "install", "USBHost"])
1037+
1038+
res = run_command(["lib", "list", "--all", "--format", "json"])
1039+
assert res.ok
1040+
libs = json.loads(res.stdout)
1041+
assert len(libs) == 2
1042+
# Verify both libraries have the same name
1043+
assert libs[0]["library"]["name"] == "USBHost"
1044+
assert libs[1]["library"]["name"] == "USBHost"
1045+
1046+
res = run_command(["lib", "upgrade"])
1047+
assert res.ok
1048+
# Empty output means nothing has been updated as expected
1049+
assert res.stdout == ""
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
nessuno.name=Arduino Nessuno
2+
nessuno.vid.0=0x2341
3+
nessuno.pid.0=0x0043
4+
nessuno.vid.1=0x2341
5+
nessuno.pid.1=0x0001
6+
nessuno.vid.2=0x2A03
7+
nessuno.pid.2=0x0043
8+
nessuno.vid.3=0x2341
9+
nessuno.pid.3=0x0243
10+
nessuno.upload.tool=avrdude
11+
nessuno.upload.protocol=arduino
12+
nessuno.upload.maximum_size=32256
13+
nessuno.upload.maximum_data_size=2048
14+
nessuno.upload.speed=115200
15+
nessuno.bootloader.tool=avrdude
16+
nessuno.bootloader.low_fuses=0xFF
17+
nessuno.bootloader.high_fuses=0xDE
18+
nessuno.bootloader.extended_fuses=0xFD
19+
nessuno.bootloader.unlock_bits=0x3F
20+
nessuno.bootloader.lock_bits=0x0F
21+
nessuno.bootloader.file=optiboot/optiboot_atmega328.hex
22+
nessuno.build.mcu=atmega328p
23+
nessuno.build.f_cpu=16000000L
24+
nessuno.build.board=AVR_NESSUNO
25+
nessuno.build.core=arduino
26+
nessuno.build.variant=standard
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name=USBHost
2+
version=0.0.1
3+
author=Arduino
4+
maintainer=Arduino <[email protected]>
5+
sentence=Allows the communication with USB peripherals like mice, keyboards, and thumbdrives. For Arduino MKR1000 and Zero.
6+
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.
7+
category=Other
8+
url=https://www.arduino.cc/en/Reference/USBHost
9+
architectures=samd
10+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
name=Arduino Test Boards
2+
version=4.2.0

0 commit comments

Comments
 (0)