Skip to content

Commit b7bcf00

Browse files
authored
Fix empty name on manually installed platforms without platform.txt (#1322)
1 parent a66fea9 commit b7bcf00

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

arduino/cores/packagemanager/loader.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,14 @@ func (pm *PackageManager) loadPlatformRelease(platform *cores.PlatformRelease, p
320320
}
321321

322322
if platform.Platform.Name == "" {
323-
platform.Platform.Name = platform.Properties.Get("name")
323+
if name, ok := platform.Properties.GetOk("name"); ok {
324+
platform.Platform.Name = name
325+
} else {
326+
// If the platform.txt file doesn't exist for this platform and it's not in any
327+
// package index there is no way of retrieving its name, so we build one using
328+
// the available information, that is the packager name and the architecture.
329+
platform.Platform.Name = fmt.Sprintf("%s-%s", platform.Platform.Package.Name, platform.Platform.Architecture)
330+
}
324331
}
325332

326333
// Create programmers properties

test/test_core.py

+27
Original file line numberDiff line numberDiff line change
@@ -648,3 +648,30 @@ def test_core_list_deprecated_platform_with_installed_json(run_command, httpserv
648648
platforms = json.loads(result.stdout)
649649
assert len(platforms) == 1
650650
assert platforms[0]["deprecated"]
651+
652+
653+
def test_core_list_platform_without_platform_txt(run_command, data_dir):
654+
assert run_command("update")
655+
656+
# Verifies no core is installed
657+
res = run_command("core list --format json")
658+
assert res.ok
659+
cores = json.loads(res.stdout)
660+
assert len(cores) == 0
661+
662+
# Simulates creation of a new core in the sketchbook hardware folder
663+
# without a platforms.txt
664+
test_boards_txt = Path(__file__).parent / "testdata" / "boards.local.txt"
665+
boards_txt = Path(data_dir, "hardware", "some-packager", "some-arch", "boards.txt")
666+
boards_txt.parent.mkdir(parents=True, exist_ok=True)
667+
boards_txt.touch()
668+
boards_txt.write_bytes(test_boards_txt.read_bytes())
669+
670+
# Verifies no core is installed
671+
res = run_command("core list --format json")
672+
assert res.ok
673+
cores = json.loads(res.stdout)
674+
assert len(cores) == 1
675+
core = cores[0]
676+
assert core["id"] == "some-packager:some-arch"
677+
assert core["name"] == "some-packager-some-arch"

0 commit comments

Comments
 (0)