diff --git a/arduino/cores/packagemanager/loader.go b/arduino/cores/packagemanager/loader.go index 7d20935936b..ac1b82e7118 100644 --- a/arduino/cores/packagemanager/loader.go +++ b/arduino/cores/packagemanager/loader.go @@ -320,7 +320,14 @@ func (pm *PackageManager) loadPlatformRelease(platform *cores.PlatformRelease, p } if platform.Platform.Name == "" { - platform.Platform.Name = platform.Properties.Get("name") + if name, ok := platform.Properties.GetOk("name"); ok { + platform.Platform.Name = name + } else { + // If the platform.txt file doesn't exist for this platform and it's not in any + // package index there is no way of retrieving its name, so we build one using + // the available information, that is the packager name and the architecture. + platform.Platform.Name = fmt.Sprintf("%s-%s", platform.Platform.Package.Name, platform.Platform.Architecture) + } } // Create programmers properties diff --git a/test/test_core.py b/test/test_core.py index dbe353bd286..8b255fbe1ec 100644 --- a/test/test_core.py +++ b/test/test_core.py @@ -648,3 +648,30 @@ def test_core_list_deprecated_platform_with_installed_json(run_command, httpserv platforms = json.loads(result.stdout) assert len(platforms) == 1 assert platforms[0]["deprecated"] + + +def test_core_list_platform_without_platform_txt(run_command, data_dir): + assert run_command("update") + + # Verifies no core is installed + res = run_command("core list --format json") + assert res.ok + cores = json.loads(res.stdout) + assert len(cores) == 0 + + # Simulates creation of a new core in the sketchbook hardware folder + # without a platforms.txt + test_boards_txt = Path(__file__).parent / "testdata" / "boards.local.txt" + boards_txt = Path(data_dir, "hardware", "some-packager", "some-arch", "boards.txt") + boards_txt.parent.mkdir(parents=True, exist_ok=True) + boards_txt.touch() + boards_txt.write_bytes(test_boards_txt.read_bytes()) + + # Verifies no core is installed + res = run_command("core list --format json") + assert res.ok + cores = json.loads(res.stdout) + assert len(cores) == 1 + core = cores[0] + assert core["id"] == "some-packager:some-arch" + assert core["name"] == "some-packager-some-arch"