Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 4c50868

Browse filesBrowse files
committed
Implementation of Viper replacement library
- Using configmap allows better handling of config types - The CLI "instances" now caches all the configuration at Create-time - Setting are now only accessible via gRPC calls - Helper methods have been implemented to access all key/value pairs
1 parent 1fddba7 commit 4c50868
Copy full SHA for 4c50868

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Dismiss banner
Expand file treeCollapse file tree

69 files changed

+3724
-1259
lines changed

‎commands/instances.go

Copy file name to clipboardExpand all lines: commands/instances.go
+13-12Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ import (
3636
"github.com/arduino/arduino-cli/internal/arduino/resources"
3737
"github.com/arduino/arduino-cli/internal/arduino/sketch"
3838
"github.com/arduino/arduino-cli/internal/arduino/utils"
39-
"github.com/arduino/arduino-cli/internal/cli/configuration"
4039
"github.com/arduino/arduino-cli/internal/i18n"
4140
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
4241
paths "github.com/arduino/go-paths-helper"
@@ -72,7 +71,7 @@ func (s *arduinoCoreServerImpl) Create(ctx context.Context, req *rpc.CreateReque
7271
}
7372

7473
// Setup downloads directory
75-
downloadsDir := configuration.DownloadsDir(s.settings)
74+
downloadsDir := s.settings.DownloadsDir()
7675
if downloadsDir.NotExist() {
7776
err := downloadsDir.MkdirAll()
7877
if err != nil {
@@ -81,8 +80,9 @@ func (s *arduinoCoreServerImpl) Create(ctx context.Context, req *rpc.CreateReque
8180
}
8281

8382
// Setup data directory
84-
dataDir := configuration.DataDir(s.settings)
85-
packagesDir := configuration.PackagesDir(s.settings)
83+
dataDir := s.settings.DataDir()
84+
userPackagesDir := s.settings.UserDir().Join("hardware")
85+
packagesDir := s.settings.PackagesDir()
8686
if packagesDir.NotExist() {
8787
err := packagesDir.MkdirAll()
8888
if err != nil {
@@ -94,7 +94,7 @@ func (s *arduinoCoreServerImpl) Create(ctx context.Context, req *rpc.CreateReque
9494
if err != nil {
9595
return nil, err
9696
}
97-
inst, err := instances.Create(dataDir, packagesDir, downloadsDir, userAgent, config)
97+
inst, err := instances.Create(dataDir, packagesDir, userPackagesDir, downloadsDir, userAgent, config)
9898
if err != nil {
9999
return nil, err
100100
}
@@ -177,7 +177,7 @@ func (s *arduinoCoreServerImpl) Init(req *rpc.InitRequest, stream rpc.ArduinoCor
177177
defaultIndexURL, _ := utils.URLParse(globals.DefaultIndexURL)
178178
allPackageIndexUrls := []*url.URL{defaultIndexURL}
179179
if profile == nil {
180-
for _, u := range s.settings.GetStringSlice("board_manager.additional_urls") {
180+
for _, u := range s.settings.BoardManagerAdditionalUrls() {
181181
URL, err := utils.URLParse(u)
182182
if err != nil {
183183
e := &cmderrors.InitFailedError{
@@ -192,7 +192,7 @@ func (s *arduinoCoreServerImpl) Init(req *rpc.InitRequest, stream rpc.ArduinoCor
192192
}
193193
}
194194

195-
if err := firstUpdate(ctx, s, req.GetInstance(), configuration.DataDir(s.settings), downloadCallback, allPackageIndexUrls); err != nil {
195+
if err := firstUpdate(ctx, s, req.GetInstance(), s.settings.DataDir(), downloadCallback, allPackageIndexUrls); err != nil {
196196
e := &cmderrors.InitFailedError{
197197
Code: codes.InvalidArgument,
198198
Cause: err,
@@ -245,7 +245,7 @@ func (s *arduinoCoreServerImpl) Init(req *rpc.InitRequest, stream rpc.ArduinoCor
245245

246246
// Load Platforms
247247
if profile == nil {
248-
for _, err := range pmb.LoadHardware(s.settings) {
248+
for _, err := range pmb.LoadHardware() {
249249
s := &cmderrors.PlatformLoadingError{Cause: err}
250250
responseError(s.GRPCStatus())
251251
}
@@ -349,7 +349,7 @@ func (s *arduinoCoreServerImpl) Init(req *rpc.InitRequest, stream rpc.ArduinoCor
349349

350350
if profile == nil {
351351
// Add directories of libraries bundled with IDE
352-
if bundledLibsDir := configuration.IDEBuiltinLibrariesDir(s.settings); bundledLibsDir != nil {
352+
if bundledLibsDir := s.settings.IDEBuiltinLibrariesDir(); bundledLibsDir != nil {
353353
lmb.AddLibrariesDir(librariesmanager.LibrariesDir{
354354
Path: bundledLibsDir,
355355
Location: libraries.IDEBuiltIn,
@@ -358,14 +358,14 @@ func (s *arduinoCoreServerImpl) Init(req *rpc.InitRequest, stream rpc.ArduinoCor
358358

359359
// Add libraries directory from config file
360360
lmb.AddLibrariesDir(librariesmanager.LibrariesDir{
361-
Path: configuration.LibrariesDir(s.settings),
361+
Path: s.settings.LibrariesDir(),
362362
Location: libraries.User,
363363
})
364364
} else {
365365
// Load libraries required for profile
366366
for _, libraryRef := range profile.Libraries {
367367
uid := libraryRef.InternalUniqueIdentifier()
368-
libRoot := configuration.ProfilesCacheDir(s.settings).Join(uid)
368+
libRoot := s.settings.ProfilesCacheDir().Join(uid)
369369
libDir := libRoot.Join(libraryRef.Library)
370370

371371
if !libDir.IsDir() {
@@ -548,7 +548,7 @@ func (s *arduinoCoreServerImpl) UpdateIndex(req *rpc.UpdateIndexRequest, stream
548548
Message: &rpc.UpdateIndexResponse_DownloadProgress{DownloadProgress: p},
549549
})
550550
}
551-
indexpath := configuration.DataDir(s.settings)
551+
indexpath := s.settings.DataDir()
552552

553553
urls := []string{globals.DefaultIndexURL}
554554
if !req.GetIgnoreCustomPackageIndexes() {
@@ -614,6 +614,7 @@ func (s *arduinoCoreServerImpl) UpdateIndex(req *rpc.UpdateIndexRequest, stream
614614
downloadCB.Start(u, tr("Downloading index: %s", filepath.Base(URL.Path)))
615615
downloadCB.End(false, tr("Invalid network configuration: %s", err))
616616
failed = true
617+
continue
617618
}
618619

619620
if strings.HasSuffix(URL.Host, "arduino.cc") && strings.HasSuffix(URL.Path, ".json") {

‎commands/internal/instances/instances.go

Copy file name to clipboardExpand all lines: commands/internal/instances/instances.go
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,15 +134,15 @@ func SetLibraryManager(inst *rpc.Instance, lm *librariesmanager.LibrariesManager
134134
}
135135

136136
// Create a new *rpc.Instance ready to be initialized
137-
func Create(dataDir, packagesDir, downloadsDir *paths.Path, extraUserAgent string, downloaderConfig downloader.Config) (*rpc.Instance, error) {
137+
func Create(dataDir, packagesDir, userPackagesDir, downloadsDir *paths.Path, extraUserAgent string, downloaderConfig downloader.Config) (*rpc.Instance, error) {
138138
// Create package manager
139139
userAgent := "arduino-cli/" + version.VersionInfo.VersionString
140140
if extraUserAgent != "" {
141141
userAgent += " " + extraUserAgent
142142
}
143143
tempDir := dataDir.Join("tmp")
144144

145-
pm := packagemanager.NewBuilder(dataDir, packagesDir, downloadsDir, tempDir, userAgent, downloaderConfig).Build()
145+
pm := packagemanager.NewBuilder(dataDir, packagesDir, userPackagesDir, downloadsDir, tempDir, userAgent, downloaderConfig).Build()
146146
lm, _ := librariesmanager.NewBuilder().Build()
147147

148148
instance := &coreInstance{

‎commands/service.go

Copy file name to clipboardExpand all lines: commands/service.go
+10-8Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,28 +19,30 @@ import (
1919
"context"
2020

2121
"github.com/arduino/arduino-cli/internal/cli/configuration"
22+
"github.com/arduino/arduino-cli/internal/i18n"
2223
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
24+
"github.com/arduino/arduino-cli/version"
2325
)
2426

2527
// NewArduinoCoreServer returns an implementation of the ArduinoCoreService gRPC service
2628
// that uses the provided version string.
27-
func NewArduinoCoreServer(version string, settings *configuration.Settings) rpc.ArduinoCoreServiceServer {
28-
return &arduinoCoreServerImpl{
29-
versionString: version,
30-
settings: settings,
31-
}
29+
func NewArduinoCoreServer() rpc.ArduinoCoreServiceServer {
30+
settings := configuration.NewSettings()
31+
32+
// Setup i18n
33+
i18n.Init(settings.Locale())
34+
35+
return &arduinoCoreServerImpl{settings: settings}
3236
}
3337

3438
type arduinoCoreServerImpl struct {
3539
rpc.UnsafeArduinoCoreServiceServer // Force compile error for unimplemented methods
3640

37-
versionString string
38-
3941
// Settings holds configurations of the CLI and the gRPC consumers
4042
settings *configuration.Settings
4143
}
4244

4345
// Version returns the version of the Arduino CLI
4446
func (s *arduinoCoreServerImpl) Version(ctx context.Context, req *rpc.VersionRequest) (*rpc.VersionResponse, error) {
45-
return &rpc.VersionResponse{Version: s.versionString}, nil
47+
return &rpc.VersionResponse{Version: version.VersionInfo.VersionString}, nil
4648
}

‎commands/service_board_list_test.go

Copy file name to clipboardExpand all lines: commands/service_board_list_test.go
+16-8Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,59 +48,67 @@ func TestGetByVidPid(t *testing.T) {
4848
defer ts.Close()
4949

5050
vidPidURL = ts.URL
51-
res, err := apiByVidPid("0xf420", "0XF069", configuration.Init(""))
51+
settings := configuration.NewSettings()
52+
res, err := apiByVidPid("0xf420", "0XF069", settings)
5253
require.Nil(t, err)
5354
require.Len(t, res, 1)
5455
require.Equal(t, "Arduino/Genuino MKR1000", res[0].GetName())
5556
require.Equal(t, "arduino:samd:mkr1000", res[0].GetFqbn())
5657

5758
// wrong vid (too long), wrong pid (not an hex value)
5859

59-
_, err = apiByVidPid("0xfffff", "0xDEFG", configuration.Init(""))
60+
_, err = apiByVidPid("0xfffff", "0xDEFG", settings)
6061
require.NotNil(t, err)
6162
}
6263

6364
func TestGetByVidPidNotFound(t *testing.T) {
65+
settings := configuration.NewSettings()
66+
6467
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
6568
w.WriteHeader(http.StatusNotFound)
6669
}))
6770
defer ts.Close()
6871

6972
vidPidURL = ts.URL
70-
res, err := apiByVidPid("0x0420", "0x0069", configuration.Init(""))
73+
res, err := apiByVidPid("0x0420", "0x0069", settings)
7174
require.NoError(t, err)
7275
require.Empty(t, res)
7376
}
7477

7578
func TestGetByVidPid5xx(t *testing.T) {
79+
settings := configuration.NewSettings()
80+
7681
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
7782
w.WriteHeader(http.StatusInternalServerError)
7883
w.Write([]byte("500 - Ooooops!"))
7984
}))
8085
defer ts.Close()
8186

8287
vidPidURL = ts.URL
83-
res, err := apiByVidPid("0x0420", "0x0069", configuration.Init(""))
88+
res, err := apiByVidPid("0x0420", "0x0069", settings)
8489
require.NotNil(t, err)
8590
require.Equal(t, "the server responded with status 500 Internal Server Error", err.Error())
8691
require.Len(t, res, 0)
8792
}
8893

8994
func TestGetByVidPidMalformedResponse(t *testing.T) {
95+
settings := configuration.NewSettings()
96+
9097
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
9198
fmt.Fprintln(w, "{}")
9299
}))
93100
defer ts.Close()
94101

95102
vidPidURL = ts.URL
96-
res, err := apiByVidPid("0x0420", "0x0069", configuration.Init(""))
103+
res, err := apiByVidPid("0x0420", "0x0069", settings)
97104
require.NotNil(t, err)
98105
require.Equal(t, "wrong format in server response", err.Error())
99106
require.Len(t, res, 0)
100107
}
101108

102109
func TestBoardDetectionViaAPIWithNonUSBPort(t *testing.T) {
103-
items, err := identifyViaCloudAPI(properties.NewMap(), configuration.Init(""))
110+
settings := configuration.NewSettings()
111+
items, err := identifyViaCloudAPI(properties.NewMap(), settings)
104112
require.NoError(t, err)
105113
require.Empty(t, items)
106114
}
@@ -112,7 +120,7 @@ func TestBoardIdentifySorting(t *testing.T) {
112120
defer paths.TempDir().Join("test").RemoveAll()
113121

114122
// We don't really care about the paths in this case
115-
pmb := packagemanager.NewBuilder(dataDir, dataDir, dataDir, dataDir, "test", downloader.GetDefaultConfig())
123+
pmb := packagemanager.NewBuilder(dataDir, dataDir, nil, dataDir, dataDir, "test", downloader.GetDefaultConfig())
116124

117125
// Create some boards with identical VID:PID combination
118126
pack := pmb.GetOrCreatePackage("packager")
@@ -148,7 +156,7 @@ func TestBoardIdentifySorting(t *testing.T) {
148156
pme, release := pm.NewExplorer()
149157
defer release()
150158

151-
settings := configuration.Init("")
159+
settings := configuration.NewSettings()
152160
res, err := identify(pme, &discovery.Port{Properties: idPrefs}, settings)
153161
require.NoError(t, err)
154162
require.NotNil(t, res)

‎commands/service_cache_clean.go

Copy file name to clipboardExpand all lines: commands/service_cache_clean.go
+1-2Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,12 @@ package commands
1818
import (
1919
"context"
2020

21-
"github.com/arduino/arduino-cli/internal/cli/configuration"
2221
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
2322
)
2423

2524
// CleanDownloadCacheDirectory clean the download cache directory (where archives are downloaded).
2625
func (s *arduinoCoreServerImpl) CleanDownloadCacheDirectory(ctx context.Context, req *rpc.CleanDownloadCacheDirectoryRequest) (*rpc.CleanDownloadCacheDirectoryResponse, error) {
27-
cachePath := configuration.DownloadsDir(s.settings)
26+
cachePath := s.settings.DownloadsDir()
2827
err := cachePath.RemoveAll()
2928
if err != nil {
3029
return nil, err

‎commands/service_compile.go

Copy file name to clipboardExpand all lines: commands/service_compile.go
+6-7Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ import (
3232
"github.com/arduino/arduino-cli/internal/arduino/sketch"
3333
"github.com/arduino/arduino-cli/internal/arduino/utils"
3434
"github.com/arduino/arduino-cli/internal/buildcache"
35-
"github.com/arduino/arduino-cli/internal/cli/configuration"
3635
"github.com/arduino/arduino-cli/internal/inventory"
3736
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
3837
paths "github.com/arduino/go-paths-helper"
@@ -67,7 +66,7 @@ func (s *arduinoCoreServerImpl) Compile(req *rpc.CompileRequest, stream rpc.Ardu
6766
ctx := stream.Context()
6867
syncSend := NewSynchronizedSend(stream.Send)
6968

70-
exportBinaries := s.settings.GetBool("sketch.always_export_binaries")
69+
exportBinaries := s.settings.SketchAlwaysExportBinaries()
7170
if e := req.ExportBinaries; e != nil {
7271
exportBinaries = *e
7372
}
@@ -175,8 +174,8 @@ func (s *arduinoCoreServerImpl) Compile(req *rpc.CompileRequest, stream rpc.Ardu
175174
// cache is purged after compilation to not remove entries that might be required
176175

177176
defer maybePurgeBuildCache(
178-
s.settings.GetUint("build_cache.compilations_before_purge"),
179-
s.settings.GetDuration("build_cache.ttl").Abs())
177+
s.settings.GetCompilationsBeforeBuildCachePurge(),
178+
s.settings.GetBuildCacheTTL().Abs())
180179

181180
var coreBuildCachePath *paths.Path
182181
if req.GetBuildCachePath() == "" {
@@ -198,7 +197,7 @@ func (s *arduinoCoreServerImpl) Compile(req *rpc.CompileRequest, stream rpc.Ardu
198197

199198
actualPlatform := buildPlatform
200199
otherLibrariesDirs := paths.NewPathList(req.GetLibraries()...)
201-
otherLibrariesDirs.Add(configuration.LibrariesDir(s.settings))
200+
otherLibrariesDirs.Add(s.settings.LibrariesDir())
202201

203202
var libsManager *librariesmanager.LibrariesManager
204203
if pme.GetProfile() != nil {
@@ -231,9 +230,9 @@ func (s *arduinoCoreServerImpl) Compile(req *rpc.CompileRequest, stream rpc.Ardu
231230
coreBuildCachePath,
232231
int(req.GetJobs()),
233232
req.GetBuildProperties(),
234-
configuration.HardwareDirectories(s.settings),
233+
s.settings.HardwareDirectories(),
235234
otherLibrariesDirs,
236-
configuration.IDEBuiltinLibrariesDir(s.settings),
235+
s.settings.IDEBuiltinLibrariesDir(),
237236
fqbn,
238237
req.GetClean(),
239238
req.GetSourceOverride(),

‎commands/service_debug_test.go

Copy file name to clipboardExpand all lines: commands/service_debug_test.go
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func TestGetCommandLine(t *testing.T) {
3737
sketchPath := paths.New("testdata", "debug", sketch)
3838
require.NoError(t, sketchPath.ToAbs())
3939

40-
pmb := packagemanager.NewBuilder(nil, nil, nil, nil, "test", downloader.GetDefaultConfig())
40+
pmb := packagemanager.NewBuilder(nil, nil, nil, nil, nil, "test", downloader.GetDefaultConfig())
4141
pmb.LoadHardwareFromDirectory(customHardware)
4242
pmb.LoadHardwareFromDirectory(dataDir)
4343

‎commands/service_platform_search_test.go

Copy file name to clipboardExpand all lines: commands/service_platform_search_test.go
+19-5Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import (
1919
"context"
2020
"testing"
2121

22-
"github.com/arduino/arduino-cli/internal/cli/configuration"
2322
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
2423
"github.com/arduino/go-paths-helper"
2524
"github.com/stretchr/testify/require"
@@ -36,9 +35,17 @@ func TestPlatformSearch(t *testing.T) {
3635
err := paths.New("testdata", "platform", "package_index.json").CopyTo(dataDir.Join("package_index.json"))
3736
require.Nil(t, err)
3837

39-
settings := configuration.Init(paths.TempDir().Join("test", "arduino-cli.yaml").String())
40-
srv := NewArduinoCoreServer("", settings)
4138
ctx := context.Background()
39+
srv := NewArduinoCoreServer()
40+
41+
conf, err := paths.TempDir().Join("test", "arduino-cli.yaml").ReadFile()
42+
require.NoError(t, err)
43+
_, err = srv.ConfigurationOpen(ctx, &rpc.ConfigurationOpenRequest{
44+
SettingsFormat: "yaml",
45+
EncodedSettings: string(conf),
46+
})
47+
require.NoError(t, err)
48+
4249
createResp, err := srv.Create(ctx, &rpc.CreateRequest{})
4350
require.NoError(t, err)
4451

@@ -337,9 +344,16 @@ func TestPlatformSearchSorting(t *testing.T) {
337344
err := paths.New("testdata", "platform", "package_index.json").CopyTo(dataDir.Join("package_index.json"))
338345
require.Nil(t, err)
339346

340-
settings := configuration.Init(paths.TempDir().Join("test", "arduino-cli.yaml").String())
341-
srv := NewArduinoCoreServer("", settings)
342347
ctx := context.Background()
348+
srv := NewArduinoCoreServer()
349+
350+
conf, err := paths.TempDir().Join("test", "arduino-cli.yaml").ReadFile()
351+
require.NoError(t, err)
352+
_, err = srv.ConfigurationOpen(ctx, &rpc.ConfigurationOpenRequest{
353+
SettingsFormat: "yaml",
354+
EncodedSettings: string(conf),
355+
})
356+
require.NoError(t, err)
343357

344358
createResp, err := srv.Create(ctx, &rpc.CreateRequest{})
345359
require.NoError(t, err)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.