Skip to content

Commit 16cd87b

Browse files
committed
Add support for file:// schema to set local additional URLs
1 parent d0e904c commit 16cd87b

File tree

10 files changed

+59
-75
lines changed

10 files changed

+59
-75
lines changed

cli/cli.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ func createCliCommandTree(cmd *cobra.Command) {
104104
cmd.PersistentFlags().StringVar(&outputFormat, "format", "text", "The output format, can be {text|json}.")
105105
cmd.PersistentFlags().StringVar(&configFile, "config-file", "", "The custom config file (if not specified the default will be used).")
106106
cmd.PersistentFlags().StringSlice("additional-urls", []string{}, "Comma-separated list of additional URLs for the Boards Manager.")
107-
cmd.PersistentFlags().StringSlice("additional-paths", []string{}, "Comma-separated list of additional file paths for the Boards Manager.")
108107
configuration.BindFlags(cmd, configuration.Settings)
109108
}
110109

cli/config/validate.go

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,18 @@ import (
2121
)
2222

2323
var validMap = map[string]reflect.Kind{
24-
"board_manager.additional_urls": reflect.Slice,
25-
"board_manager.additional_paths": reflect.Slice,
26-
"daemon.port": reflect.String,
27-
"directories.data": reflect.String,
28-
"directories.downloads": reflect.String,
29-
"directories.user": reflect.String,
30-
"library.enable_unsafe_install": reflect.Bool,
31-
"logging.file": reflect.String,
32-
"logging.format": reflect.String,
33-
"logging.level": reflect.String,
34-
"sketch.always_export_binaries": reflect.Bool,
35-
"telemetry.addr": reflect.String,
36-
"telemetry.enabled": reflect.Bool,
24+
"board_manager.additional_urls": reflect.Slice,
25+
"daemon.port": reflect.String,
26+
"directories.data": reflect.String,
27+
"directories.downloads": reflect.String,
28+
"directories.user": reflect.String,
29+
"library.enable_unsafe_install": reflect.Bool,
30+
"logging.file": reflect.String,
31+
"logging.format": reflect.String,
32+
"logging.level": reflect.String,
33+
"sketch.always_export_binaries": reflect.Bool,
34+
"telemetry.addr": reflect.String,
35+
"telemetry.enabled": reflect.Bool,
3736
}
3837

3938
func typeOf(key string) (reflect.Kind, error) {

commands/daemon/testdata/arduino-cli.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ board_manager:
22
additional_urls:
33
- http://foobar.com
44
- http://example.com
5-
additional_paths: []
65

76
daemon:
87
port: "50051"

commands/instances.go

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -202,24 +202,6 @@ func UpdateIndex(ctx context.Context, req *rpc.UpdateIndexReq, downloadCB Downlo
202202

203203
indexpath := paths.New(configuration.Settings.GetString("directories.Data"))
204204

205-
for _, x := range configuration.Settings.GetStringSlice("board_manager.additional_paths") {
206-
logrus.Info("JSON PATH: ", x)
207-
208-
pathJSON, _ := paths.New(x).Abs()
209-
210-
if _, err := packageindex.LoadIndexNoSign(pathJSON); err != nil {
211-
return nil, fmt.Errorf("invalid package index in %s: %s", pathJSON, err)
212-
}
213-
214-
fi, _ := os.Stat(x)
215-
downloadCB(&rpc.DownloadProgress{
216-
File: "Updating index: " + pathJSON.Base(),
217-
TotalSize: fi.Size(),
218-
})
219-
downloadCB(&rpc.DownloadProgress{Completed: true})
220-
221-
}
222-
223205
urls := []string{globals.DefaultIndexURL}
224206
urls = append(urls, configuration.Settings.GetStringSlice("board_manager.additional_urls")...)
225207
for _, u := range urls {
@@ -230,6 +212,26 @@ func UpdateIndex(ctx context.Context, req *rpc.UpdateIndexReq, downloadCB Downlo
230212
continue
231213
}
232214

215+
if URL.Scheme == "file" {
216+
path := paths.New(URL.Path)
217+
pathJSON, err := path.Abs()
218+
if err != nil {
219+
return nil, fmt.Errorf("can't get absolute path of %v: %w", path, err)
220+
}
221+
222+
if _, err := packageindex.LoadIndexNoSign(pathJSON); err != nil {
223+
return nil, fmt.Errorf("invalid package index in %s: %s", pathJSON, err)
224+
}
225+
226+
fi, _ := os.Stat(URL.Path)
227+
downloadCB(&rpc.DownloadProgress{
228+
File: "Updating index: " + pathJSON.Base(),
229+
TotalSize: fi.Size(),
230+
})
231+
downloadCB(&rpc.DownloadProgress{Completed: true})
232+
continue
233+
}
234+
233235
logrus.WithField("url", URL).Print("Updating index")
234236

235237
var tmp *paths.Path
@@ -665,16 +667,21 @@ func createInstance(ctx context.Context, getLibOnly bool) (*createInstanceResult
665667
continue
666668
}
667669

668-
if err := res.Pm.LoadPackageIndex(URL); err != nil {
669-
res.PlatformIndexErrors = append(res.PlatformIndexErrors, err.Error())
670-
}
671-
}
670+
if URL.Scheme == "file" {
671+
path := paths.New(URL.Path)
672+
pathJSON, err := path.Abs()
673+
if err != nil {
674+
return nil, fmt.Errorf("can't get absolute path of %v: %w", path, err)
675+
}
672676

673-
for _, x := range configuration.Settings.GetStringSlice("board_manager.additional_paths") {
674-
pathJSON, _ := paths.New(x).Abs()
677+
_, err = res.Pm.LoadPackageIndexFromFile(pathJSON)
678+
if err != nil {
679+
res.PlatformIndexErrors = append(res.PlatformIndexErrors, err.Error())
680+
}
681+
continue
682+
}
675683

676-
_, err := res.Pm.LoadPackageIndexFromFile(pathJSON)
677-
if err != nil {
684+
if err := res.Pm.LoadPackageIndex(URL); err != nil {
678685
res.PlatformIndexErrors = append(res.PlatformIndexErrors, err.Error())
679686
}
680687
}

configuration/configuration.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ func BindFlags(cmd *cobra.Command, settings *viper.Viper) {
7676
settings.BindPFlag("logging.file", cmd.Flag("log-file"))
7777
settings.BindPFlag("logging.format", cmd.Flag("log-format"))
7878
settings.BindPFlag("board_manager.additional_urls", cmd.Flag("additional-urls"))
79-
settings.BindPFlag("board_manager.additional_paths", cmd.Flag("additional-paths"))
8079
}
8180

8281
// getDefaultArduinoDataDir returns the full path to the default arduino folder

configuration/configuration_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ func TestInit(t *testing.T) {
8989
require.Equal(t, "text", settings.GetString("logging.format"))
9090

9191
require.Empty(t, settings.GetStringSlice("board_manager.additional_urls"))
92-
require.Empty(t, settings.GetStringSlice("board_manager.additional_paths"))
9392

9493
require.NotEmpty(t, settings.GetString("directories.Data"))
9594
require.NotEmpty(t, settings.GetString("directories.Downloads"))

configuration/defaults.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ func SetDefaults(settings *viper.Viper) {
3333

3434
// Boards Manager
3535
settings.SetDefault("board_manager.additional_urls", []string{})
36-
settings.SetDefault("board_manager.additional_paths", []string{})
3736

3837
// arduino directories
3938
settings.SetDefault("directories.Data", getDefaultArduinoDataDir())

docs/configuration.md

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
- `board_manager`
44
- `additional_urls` - the URLs to any additional Boards Manager package index files needed for your boards platforms.
5-
- `additional_paths` - the absolute file paths to any additional Boards Manager package index files needed for your
6-
boards platforms.
75
- `daemon` - options related to running Arduino CLI as a [gRPC] server.
86
- `port` - TCP port used for gRPC client connections.
97
- `directories` - directories used by Arduino CLI.
@@ -68,12 +66,6 @@ Setting an additional Boards Manager URL using the `ARDUINO_BOARD_MANAGER_ADDITI
6866
$ export ARDUINO_BOARD_MANAGER_ADDITIONAL_URLS=https://downloads.arduino.cc/packages/package_staging_index.json
6967
```
7068

71-
Setting an additional Boards Manager file using the `ARDUINO_BOARD_MANAGER_ADDITIONAL_PATHS` environment variable:
72-
73-
```sh
74-
$ export ARDUINO_BOARD_MANAGER_ADDITIONAL_PATHS=/path/to/your/package_staging_index.json
75-
```
76-
7769
### Configuration file
7870

7971
[`arduino-cli config init`][arduino-cli config init] creates or updates a configuration file with the current
@@ -136,21 +128,6 @@ Doing the same using a TOML format file:
136128
additional_urls = [ "https://downloads.arduino.cc/packages/package_staging_index.json" ]
137129
```
138130

139-
Setting an additional Boards Manager File using a YAML format configuration file:
140-
141-
```yaml
142-
board_manager:
143-
additional_paths:
144-
- /path/to/your/package_staging_index.json
145-
```
146-
147-
Doing the same using a TOML format file:
148-
149-
```toml
150-
[board_manager]
151-
additional_paths = [ "/path/to/your/package_staging_index.json" ]
152-
```
153-
154131
[grpc]: https://grpc.io
155132
[sketchbook directory]: sketch-specification.md#sketchbook
156133
[arduino cli lib install]: commands/arduino-cli_lib_install.md

docs/getting-started.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -183,12 +183,12 @@ For example, to add the NRF52832 core, edit the configuration file and change th
183183

184184
```yaml
185185
board_manager:
186-
additional_paths:
187-
- /absolute/path/to/your/package_nrf52832_index.json
186+
additional_urls:
187+
- https://arduino.esp8266.com/stable/package_esp8266com_index.json
188+
- file:///absolute/path/to/your/package_nrf52832_index.json
188189
```
189190

190-
From now on, commands supporting custom cores will automatically use the additional URL and additional paths from the
191-
configuration file:
191+
From now on, commands supporting custom cores will automatically use the additional URL from the configuration file:
192192

193193
```sh
194194
$ arduino-cli core update-index
@@ -214,14 +214,13 @@ ID Version Name
214214
esp8266:esp8266 2.5.2 esp8266
215215
```
216216

217-
The same applies to the additional package index file provided by file paths. Use the `--additional-paths` option, that
218-
has to be specified every time and for every command that operates on a 3rd party platform core, for example:
217+
The same applies to the additional package index file provided by file paths:
219218

220219
```sh
221-
$ arduino-cli core update-index --additional-paths /absolute/path/to/your/package_esp8266com_index.json
220+
$ arduino-cli core update-index --additional-urls file:///absolute/path/to/your/package_esp8266com_index.json
222221
Updating index: package_esp8266com_index.json downloaded
223222
224-
$ arduino-cli core search esp8266 --additional-paths /absolute/path/to/your/package_esp8266com_index.json
223+
$ arduino-cli core search esp8266 --additional-urls file:///absolute/path/to/your/package_esp8266com_index.json
225224
ID Version Name
226225
esp8266:esp8266 2.5.2 esp8266
227226
```

test/test_core.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,3 +353,10 @@ def ordered(obj):
353353
return obj
354354

355355
assert ordered(installed_json) == ordered(expected_installed_json)
356+
357+
358+
def test_core_update_with_local_url(run_command):
359+
test_index = Path(__file__).parent / "testdata" / "test_index.json"
360+
res = run_command(f'core update-index --additional-urls="file://{test_index}"')
361+
assert res.ok
362+
assert "Updating index: test_index.json downloaded" in res.stdout

0 commit comments

Comments
 (0)