Skip to content

fix core list --all sometimes crashing #1519

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 6 commits into from
Oct 25, 2021
Merged
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
6 changes: 5 additions & 1 deletion arduino/cores/packagemanager/loader.go
Original file line number Diff line number Diff line change
@@ -145,6 +145,10 @@ func (pm *PackageManager) LoadHardwareFromDirectory(path *paths.Path) []*status.
statuses = append(statuses, errs...)
}
}
// If the Package does not contain Platforms or Tools we remove it since does not contain anything valuable
if len(targetPackage.Platforms) == 0 && len(targetPackage.Tools) == 0 {
delete(pm.Packages, packager)
}
}

return statuses
@@ -262,7 +266,6 @@ func (pm *PackageManager) loadPlatform(targetPackage *cores.Package, platformPat
// case: ARCHITECTURE/VERSION/boards.txt
// let's dive into VERSION directories

platform := targetPackage.GetOrCreatePlatform(architecture)
versionDirs, err := platformPath.ReadDir()
if err != nil {
return status.Newf(codes.FailedPrecondition, tr("reading dir %[1]s: %[2]s"), platformPath, err)
@@ -280,6 +283,7 @@ func (pm *PackageManager) loadPlatform(targetPackage *cores.Package, platformPat
if err != nil {
return status.Newf(codes.FailedPrecondition, tr("invalid version dir %[1]s: %[2]s"), versionDir, err)
}
platform := targetPackage.GetOrCreatePlatform(architecture)
release := platform.GetOrCreateRelease(version)
if err := pm.loadPlatformRelease(release, versionDir); err != nil {
return status.Newf(codes.FailedPrecondition, tr("loading platform release %[1]s: %[2]s"), release, err)
21 changes: 12 additions & 9 deletions commands/core/list.go
Original file line number Diff line number Diff line change
@@ -38,18 +38,22 @@ func GetPlatforms(req *rpc.PlatformListRequest) ([]*rpc.Platform, error) {
for _, platform := range targetPackage.Platforms {
platformRelease := packageManager.GetInstalledPlatformRelease(platform)

// The All flags adds to the list of installed platforms the installable platforms (from the indexes)
// If both All and UpdatableOnly are set All takes precedence
if req.All {
installedVersion := ""
if platformRelease == nil {
if platformRelease == nil { // if the platform is not installed
platformRelease = platform.GetLatestRelease()
} else {
installedVersion = platformRelease.Version.String()
}
rpcPlatform := commands.PlatformReleaseToRPC(platform.GetLatestRelease())
rpcPlatform.Installed = installedVersion
res = append(res, rpcPlatform)
continue
// it could happen, especially with indexes not perfectly compliant with specs that a platform do not contain a valid release
if platformRelease != nil {
rpcPlatform := commands.PlatformReleaseToRPC(platformRelease)
rpcPlatform.Installed = installedVersion
res = append(res, rpcPlatform)
continue
}
}

if platformRelease != nil {
@@ -58,10 +62,9 @@ func GetPlatforms(req *rpc.PlatformListRequest) ([]*rpc.Platform, error) {
return nil, &arduino.PlatformNotFoundError{Platform: platform.String(), Cause: fmt.Errorf(tr("the platform has no releases"))}
}

if req.UpdatableOnly {
if latest == platformRelease {
continue
}
// show only the updatable platforms
if req.UpdatableOnly && latest == platformRelease {
continue
}

rpcPlatform := commands.PlatformReleaseToRPC(platformRelease)
460 changes: 230 additions & 230 deletions i18n/data/en.po

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions test/test_core.py
Original file line number Diff line number Diff line change
@@ -777,3 +777,21 @@ def test_core_list_outdated_core(run_command):
latest_version = semver.parse_version_info(samd_core["latest"])
# Installed version must be older than latest
assert installed_version.compare(latest_version) == -1


def test_core_loading_package_manager(run_command, data_dir):
# Create empty architecture folder (this condition is normally produced by `core uninstall`)
(Path(data_dir) / "packages" / "foovendor" / "hardware" / "fooarch").mkdir(parents=True)

result = run_command(["core", "list", "--all", "--format", "json"])
assert result.ok # this should not make the cli crash


def test_core_index_without_checksum(run_command):
assert run_command(["config", "init", "--dest-dir", "."])
url = "https://raw.githubusercontent.com/keyboardio/ArduinoCore-GD32-Keyboardio/ae5938af2f485910729e7d27aa233032a1cb4734/package_gd32_index.json" # noqa: E501
assert run_command(["config", "add", "board_manager.additional_urls", url])

assert run_command(["core", "update-index"])
result = run_command(["core", "list", "--all"])
assert result.ok # this should not make the cli crash