Skip to content

Commit bcd1a3e

Browse files
committed
Libs and cores update is now correctly run only on first CLI execution
1 parent ff3302f commit bcd1a3e

File tree

2 files changed

+37
-12
lines changed

2 files changed

+37
-12
lines changed

cli/instance/instance.go

+14-12
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ import (
2020

2121
"github.com/arduino/arduino-cli/cli/output"
2222
"github.com/arduino/arduino-cli/commands"
23+
"github.com/arduino/arduino-cli/configuration"
2324
rpc "github.com/arduino/arduino-cli/rpc/commands"
25+
"github.com/arduino/go-paths-helper"
2426
"github.com/pkg/errors"
2527
"github.com/sirupsen/logrus"
2628
)
@@ -51,9 +53,13 @@ func getInitResponse() (*rpc.InitResp, error) {
5153
return nil, errors.Wrap(err, "creating instance")
5254
}
5355

54-
// Init() succeeded but there were errors loading library indexes,
55-
// let's rescan and try again
56-
if resp.GetLibrariesIndexError() != "" {
56+
// Gets the data directory to verify if library_index.json and package_index.json exist
57+
dataDir := paths.New(configuration.Settings.GetString("directories.data"))
58+
59+
// The library_index.json file doesn't exists, that means the CLI is run for the first time
60+
// so we proceed with the first update that downloads the file
61+
libraryIndex := dataDir.Join("library_index.json")
62+
if libraryIndex.NotExist() {
5763
logrus.Warnf("There were errors loading the library index, trying again...")
5864

5965
// update all indexes
@@ -80,15 +86,11 @@ func getInitResponse() (*rpc.InitResp, error) {
8086
resp.PlatformsIndexErrors = rescanResp.PlatformsIndexErrors
8187
}
8288

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-
89+
// The package_index.json file doesn't exists, that means the CLI is run for the first time,
90+
// similarly to the library update we download that file and all the other package indexes
91+
// from additional_urls
92+
packageIndex := dataDir.Join("package_index.json")
93+
if packageIndex.NotExist() {
9294
// update platform index
9395
_, err := commands.UpdateIndex(context.Background(),
9496
&rpc.UpdateIndexReq{Instance: resp.GetInstance()}, output.ProgressBar())

test/test_compile.py

+23
Original file line numberDiff line numberDiff line change
@@ -538,3 +538,26 @@ def test_compile_with_export_binaries_config(run_command, data_dir, downloads_di
538538
assert (sketch_path / "build" / fqbn.replace(":", ".") / f"{sketch_name}.ino.hex").exists()
539539
assert (sketch_path / "build" / fqbn.replace(":", ".") / f"{sketch_name}.ino.with_bootloader.bin").exists()
540540
assert (sketch_path / "build" / fqbn.replace(":", ".") / f"{sketch_name}.ino.with_bootloader.hex").exists()
541+
542+
543+
def test_compile_with_invalid_url(run_command, data_dir):
544+
# Init the environment explicitly
545+
run_command("core update-index")
546+
547+
# Download latest AVR
548+
run_command("core install arduino:avr")
549+
550+
sketch_name = "CompileWithInvalidURL"
551+
sketch_path = Path(data_dir, sketch_name)
552+
fqbn = "arduino:avr:uno"
553+
554+
# Create a test sketch
555+
assert run_command(f'sketch new "{sketch_path}"')
556+
557+
# Create settings with custom invalid URL
558+
assert run_command("config init --dest-dir . --additional-urls https://example.com/package_example_index.json")
559+
560+
# Verifies compilation fails cause of invalid URL
561+
res = run_command(f'compile -b {fqbn} "{sketch_path}"')
562+
assert res.failed
563+
assert "There were errors loading platform indexes" in res.stderr

0 commit comments

Comments
 (0)