Skip to content

Commit 319dede

Browse files
authored
Package index is now downloaded automatically when is required (#908)
* fix wrong assert in other test * add automatic `core update-index` when `package_insex.json` are not there
1 parent 3036536 commit 319dede

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed

Diff for: cli/instance/instance.go

+34
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,40 @@ func getInitResponse() (*rpc.InitResp, error) {
8080
resp.PlatformsIndexErrors = rescanResp.PlatformsIndexErrors
8181
}
8282

83+
// Init() succeeded but there were errors loading platform indexes,
84+
// let's rescan and try again
85+
if resp.GetPlatformsIndexErrors() != nil {
86+
87+
// log each error
88+
for _, err := range resp.GetPlatformsIndexErrors() {
89+
logrus.Errorf("Error loading platform index: %v", err)
90+
}
91+
92+
// update platform index
93+
_, err := commands.UpdateIndex(context.Background(),
94+
&rpc.UpdateIndexReq{Instance: resp.GetInstance()}, output.ProgressBar())
95+
if err != nil {
96+
return nil, errors.Wrap(err, "updating the core index")
97+
}
98+
99+
// rescan
100+
rescanResp, err := commands.Rescan(resp.GetInstance().GetId())
101+
if err != nil {
102+
return nil, errors.Wrap(err, "during rescan")
103+
}
104+
105+
// errors persist
106+
if rescanResp.GetPlatformsIndexErrors() != nil {
107+
for _, err := range rescanResp.GetPlatformsIndexErrors() {
108+
logrus.Errorf("Still errors after rescan: %v", err)
109+
}
110+
}
111+
112+
// succeeded, copy over PlatformsIndexErrors in case errors occurred
113+
// during rescan
114+
resp.PlatformsIndexErrors = rescanResp.PlatformsIndexErrors
115+
}
116+
83117
return resp, nil
84118
}
85119

Diff for: test/test_board.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -449,5 +449,5 @@ def test_board_details_no_flags(run_command):
449449
assert result.ok
450450
result = run_command("board details")
451451
assert not result.ok
452-
assert "Error getting board details: parsing fqbn: invalid fqbn:"
452+
assert "Error getting board details: parsing fqbn: invalid fqbn:" in result.stderr
453453
assert result.stdout == ""

Diff for: test/test_core.py

+8
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,14 @@ def test_core_updateindex_invalid_url(run_command):
9999
assert result.failed
100100

101101

102+
def test_core_install_without_updateindex(run_command):
103+
# Missing "core update-index"
104+
# Download samd core pinned to 1.8.6
105+
result = run_command("core install arduino:[email protected]")
106+
assert result.ok
107+
assert "Updating index: package_index.json downloaded" in result.stdout
108+
109+
102110
@pytest.mark.skipif(
103111
platform.system() == "Windows", reason="core fails with fatal error: bits/c++config.h: No such file or directory",
104112
)

0 commit comments

Comments
 (0)