From 2eac5cc1ad4c22d62a0a59f7d7c213014d352b98 Mon Sep 17 00:00:00 2001 From: Silvano Cerza Date: Mon, 22 Mar 2021 16:30:31 +0100 Subject: [PATCH] Fix core name not showing if installed.json is not found --- arduino/cores/packagemanager/loader.go | 8 +++--- test/test_core.py | 38 ++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/arduino/cores/packagemanager/loader.go b/arduino/cores/packagemanager/loader.go index b7aa88f30e1..f2ccc77b8a5 100644 --- a/arduino/cores/packagemanager/loader.go +++ b/arduino/cores/packagemanager/loader.go @@ -172,7 +172,6 @@ func (pm *PackageManager) loadPlatforms(targetPackage *cores.Package, packageDir return fmt.Errorf("loading platform.txt: %w", err) } - platformName := platformProperties.Get("name") version := semver.MustParse(platformProperties.Get("version")) // check if package_bundled_index.json exists @@ -207,9 +206,6 @@ func (pm *PackageManager) loadPlatforms(targetPackage *cores.Package, packageDir } platform := targetPackage.GetOrCreatePlatform(architecture) - if platform.Name == "" { - platform.Name = platformName - } if !isIDEBundled { platform.ManuallyInstalled = true } @@ -289,6 +285,10 @@ func (pm *PackageManager) loadPlatformRelease(platform *cores.PlatformRelease, p return fmt.Errorf("loading %s: %s", platformTxtLocalPath, err) } + if platform.Platform.Name == "" { + platform.Platform.Name = platform.Properties.Get("name") + } + // Create programmers properties if programmersProperties, err := properties.SafeLoad(programmersTxtPath.String()); err == nil { for programmerID, programmerProperties := range programmersProperties.FirstLevelOf() { diff --git a/test/test_core.py b/test/test_core.py index 093ad2f68dc..87bc523d326 100644 --- a/test/test_core.py +++ b/test/test_core.py @@ -469,3 +469,41 @@ def test_core_install_removes_unused_tools(run_command, data_dir): # Verifies tool is uninstalled since it's not used by newer core version assert not tool_path.exists() + + +def test_core_list_with_installed_json(run_command, data_dir): + assert run_command("update") + + # Install core + url = "https://adafruit.github.io/arduino-board-index/package_adafruit_index.json" + assert run_command(f"core update-index --additional-urls={url}") + assert run_command(f"core install adafruit:avr@1.4.13 --additional-urls={url}") + + # Verifies installed core is correctly found and name is set + res = run_command("core list --format json") + assert res.ok + cores = json.loads(res.stdout) + mapped = {core["ID"]: core for core in cores} + assert len(mapped) == 1 + assert "adafruit:avr" in mapped + assert mapped["adafruit:avr"]["Name"] == "Adafruit AVR Boards" + + # Deletes installed.json file, this file stores information about the core, + # that is used mostly when removing package indexes and their cores are still installed; + # this way we don't lose much information about it. + # It might happen that the user has old cores installed before the addition of + # the installed.json file so we need to handle those cases. + installed_json = Path(data_dir, "packages", "adafruit", "hardware", "avr", "1.4.13", "installed.json") + installed_json.unlink() + + # Verifies installed core is still found and name is set + res = run_command("core list --format json") + assert res.ok + cores = json.loads(res.stdout) + mapped = {core["ID"]: core for core in cores} + assert len(mapped) == 1 + assert "adafruit:avr" in mapped + # Name for this core changes since if there's installed.json file we read it from + # platform.txt, turns out that this core has different names used in different files + # thus the change. + assert mapped["adafruit:avr"]["Name"] == "Adafruit Boards"