Skip to content

Commit 0ddb024

Browse files
authored
Fix core name not showing if installed.json is not found (#1230)
1 parent 658445c commit 0ddb024

File tree

2 files changed

+42
-4
lines changed

2 files changed

+42
-4
lines changed

Diff for: arduino/cores/packagemanager/loader.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,6 @@ func (pm *PackageManager) loadPlatforms(targetPackage *cores.Package, packageDir
172172
return fmt.Errorf("loading platform.txt: %w", err)
173173
}
174174

175-
platformName := platformProperties.Get("name")
176175
version := semver.MustParse(platformProperties.Get("version"))
177176

178177
// check if package_bundled_index.json exists
@@ -207,9 +206,6 @@ func (pm *PackageManager) loadPlatforms(targetPackage *cores.Package, packageDir
207206
}
208207

209208
platform := targetPackage.GetOrCreatePlatform(architecture)
210-
if platform.Name == "" {
211-
platform.Name = platformName
212-
}
213209
if !isIDEBundled {
214210
platform.ManuallyInstalled = true
215211
}
@@ -289,6 +285,10 @@ func (pm *PackageManager) loadPlatformRelease(platform *cores.PlatformRelease, p
289285
return fmt.Errorf("loading %s: %s", platformTxtLocalPath, err)
290286
}
291287

288+
if platform.Platform.Name == "" {
289+
platform.Platform.Name = platform.Properties.Get("name")
290+
}
291+
292292
// Create programmers properties
293293
if programmersProperties, err := properties.SafeLoad(programmersTxtPath.String()); err == nil {
294294
for programmerID, programmerProperties := range programmersProperties.FirstLevelOf() {

Diff for: test/test_core.py

+38
Original file line numberDiff line numberDiff line change
@@ -469,3 +469,41 @@ def test_core_install_removes_unused_tools(run_command, data_dir):
469469

470470
# Verifies tool is uninstalled since it's not used by newer core version
471471
assert not tool_path.exists()
472+
473+
474+
def test_core_list_with_installed_json(run_command, data_dir):
475+
assert run_command("update")
476+
477+
# Install core
478+
url = "https://adafruit.github.io/arduino-board-index/package_adafruit_index.json"
479+
assert run_command(f"core update-index --additional-urls={url}")
480+
assert run_command(f"core install adafruit:[email protected] --additional-urls={url}")
481+
482+
# Verifies installed core is correctly found and name is set
483+
res = run_command("core list --format json")
484+
assert res.ok
485+
cores = json.loads(res.stdout)
486+
mapped = {core["ID"]: core for core in cores}
487+
assert len(mapped) == 1
488+
assert "adafruit:avr" in mapped
489+
assert mapped["adafruit:avr"]["Name"] == "Adafruit AVR Boards"
490+
491+
# Deletes installed.json file, this file stores information about the core,
492+
# that is used mostly when removing package indexes and their cores are still installed;
493+
# this way we don't lose much information about it.
494+
# It might happen that the user has old cores installed before the addition of
495+
# the installed.json file so we need to handle those cases.
496+
installed_json = Path(data_dir, "packages", "adafruit", "hardware", "avr", "1.4.13", "installed.json")
497+
installed_json.unlink()
498+
499+
# Verifies installed core is still found and name is set
500+
res = run_command("core list --format json")
501+
assert res.ok
502+
cores = json.loads(res.stdout)
503+
mapped = {core["ID"]: core for core in cores}
504+
assert len(mapped) == 1
505+
assert "adafruit:avr" in mapped
506+
# Name for this core changes since if there's installed.json file we read it from
507+
# platform.txt, turns out that this core has different names used in different files
508+
# thus the change.
509+
assert mapped["adafruit:avr"]["Name"] == "Adafruit Boards"

0 commit comments

Comments
 (0)