Skip to content

Commit

Permalink
Fix lib upgrade trying to upgrade core bundled libraries (#1580)
Browse files Browse the repository at this point in the history
  • Loading branch information
silvanocerza committed Dec 3, 2021
1 parent b28e139 commit c5fe48d
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 1 deletion.
2 changes: 1 addition & 1 deletion commands/lib/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
65 changes: 65 additions & 0 deletions test/test_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import simplejson as json
import pytest
import shutil
from git import Repo
from pathlib import Path
import tempfile
Expand Down Expand Up @@ -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 == ""
26 changes: 26 additions & 0 deletions test/testdata/platform_with_bundled_library/boards.txt
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name=USBHost
version=0.0.1
author=Arduino
maintainer=Arduino <info@arduino.cc>
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

2 changes: 2 additions & 0 deletions test/testdata/platform_with_bundled_library/platform.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
name=Arduino Test Boards
version=4.2.0

0 comments on commit c5fe48d

Please sign in to comment.