Skip to content

Fix core name not showing if installed.json is not found #1230

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions arduino/cores/packagemanager/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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() {
Expand Down
38 changes: 38 additions & 0 deletions test/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:[email protected] --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"