Skip to content

Fix empty name on manually installed platforms without platform.txt #1322

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
Jun 17, 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
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"