Skip to content

Commit

Permalink
Fix empty name on manually installed platforms without platform.txt (a…
Browse files Browse the repository at this point in the history
  • Loading branch information
silvanocerza authored Jun 17, 2021
1 parent a66fea9 commit b7bcf00
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
9 changes: 8 additions & 1 deletion arduino/cores/packagemanager/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 27 additions & 0 deletions test/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit b7bcf00

Please sign in to comment.