Skip to content

Commit

Permalink
Package index is now downloaded automatically when is required (#908)
Browse files Browse the repository at this point in the history
* fix wrong assert in other test

* add automatic `core update-index` when `package_insex.json` are not there
  • Loading branch information
umbynos authored Aug 20, 2020
1 parent 3036536 commit 319dede
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
34 changes: 34 additions & 0 deletions cli/instance/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,40 @@ func getInitResponse() (*rpc.InitResp, error) {
resp.PlatformsIndexErrors = rescanResp.PlatformsIndexErrors
}

// Init() succeeded but there were errors loading platform indexes,
// let's rescan and try again
if resp.GetPlatformsIndexErrors() != nil {

// log each error
for _, err := range resp.GetPlatformsIndexErrors() {
logrus.Errorf("Error loading platform index: %v", err)
}

// update platform index
_, err := commands.UpdateIndex(context.Background(),
&rpc.UpdateIndexReq{Instance: resp.GetInstance()}, output.ProgressBar())
if err != nil {
return nil, errors.Wrap(err, "updating the core index")
}

// rescan
rescanResp, err := commands.Rescan(resp.GetInstance().GetId())
if err != nil {
return nil, errors.Wrap(err, "during rescan")
}

// errors persist
if rescanResp.GetPlatformsIndexErrors() != nil {
for _, err := range rescanResp.GetPlatformsIndexErrors() {
logrus.Errorf("Still errors after rescan: %v", err)
}
}

// succeeded, copy over PlatformsIndexErrors in case errors occurred
// during rescan
resp.PlatformsIndexErrors = rescanResp.PlatformsIndexErrors
}

return resp, nil
}

Expand Down
2 changes: 1 addition & 1 deletion test/test_board.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,5 +449,5 @@ def test_board_details_no_flags(run_command):
assert result.ok
result = run_command("board details")
assert not result.ok
assert "Error getting board details: parsing fqbn: invalid fqbn:"
assert "Error getting board details: parsing fqbn: invalid fqbn:" in result.stderr
assert result.stdout == ""
8 changes: 8 additions & 0 deletions test/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,14 @@ def test_core_updateindex_invalid_url(run_command):
assert result.failed


def test_core_install_without_updateindex(run_command):
# Missing "core update-index"
# Download samd core pinned to 1.8.6
result = run_command("core install arduino:[email protected]")
assert result.ok
assert "Updating index: package_index.json downloaded" in result.stdout


@pytest.mark.skipif(
platform.system() == "Windows", reason="core fails with fatal error: bits/c++config.h: No such file or directory",
)
Expand Down

0 comments on commit 319dede

Please sign in to comment.