Skip to content

Commit

Permalink
DRAFT
Browse files Browse the repository at this point in the history
  • Loading branch information
cmaglie committed Mar 26, 2024
1 parent cdcec9b commit 666e833
Show file tree
Hide file tree
Showing 44 changed files with 2,528 additions and 1,274 deletions.
18 changes: 9 additions & 9 deletions commands/instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import (
"github.com/arduino/arduino-cli/internal/arduino/resources"
"github.com/arduino/arduino-cli/internal/arduino/sketch"
"github.com/arduino/arduino-cli/internal/arduino/utils"
"github.com/arduino/arduino-cli/internal/cli/configuration"
"github.com/arduino/arduino-cli/internal/i18n"
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
paths "github.com/arduino/go-paths-helper"
Expand Down Expand Up @@ -72,7 +71,7 @@ func (s *arduinoCoreServerImpl) Create(ctx context.Context, req *rpc.CreateReque
}

// Setup downloads directory
downloadsDir := configuration.DownloadsDir(s.settings)
downloadsDir := s.settings.DownloadsDir()
if downloadsDir.NotExist() {
err := downloadsDir.MkdirAll()
if err != nil {
Expand All @@ -81,8 +80,8 @@ func (s *arduinoCoreServerImpl) Create(ctx context.Context, req *rpc.CreateReque
}

// Setup data directory
dataDir := configuration.DataDir(s.settings)
packagesDir := configuration.PackagesDir(s.settings)
dataDir := s.settings.DataDir()
packagesDir := s.settings.PackagesDir()
if packagesDir.NotExist() {
err := packagesDir.MkdirAll()
if err != nil {
Expand Down Expand Up @@ -192,7 +191,7 @@ func (s *arduinoCoreServerImpl) Init(req *rpc.InitRequest, stream rpc.ArduinoCor
}
}

if err := firstUpdate(ctx, s, req.GetInstance(), configuration.DataDir(s.settings), downloadCallback, allPackageIndexUrls); err != nil {
if err := firstUpdate(ctx, s, req.GetInstance(), s.settings.DataDir(), downloadCallback, allPackageIndexUrls); err != nil {
e := &cmderrors.InitFailedError{
Code: codes.InvalidArgument,
Cause: err,
Expand Down Expand Up @@ -349,7 +348,7 @@ func (s *arduinoCoreServerImpl) Init(req *rpc.InitRequest, stream rpc.ArduinoCor

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

// Add libraries directory from config file
lmb.AddLibrariesDir(librariesmanager.LibrariesDir{
Path: configuration.LibrariesDir(s.settings),
Path: s.settings.LibrariesDir(),
Location: libraries.User,
})
} else {
// Load libraries required for profile
for _, libraryRef := range profile.Libraries {
uid := libraryRef.InternalUniqueIdentifier()
libRoot := configuration.ProfilesCacheDir(s.settings).Join(uid)
libRoot := s.settings.ProfilesCacheDir().Join(uid)
libDir := libRoot.Join(libraryRef.Library)

if !libDir.IsDir() {
Expand Down Expand Up @@ -548,7 +547,7 @@ func (s *arduinoCoreServerImpl) UpdateIndex(req *rpc.UpdateIndexRequest, stream
Message: &rpc.UpdateIndexResponse_DownloadProgress{DownloadProgress: p},
})
}
indexpath := configuration.DataDir(s.settings)
indexpath := s.settings.DataDir()

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

if strings.HasSuffix(URL.Host, "arduino.cc") && strings.HasSuffix(URL.Path, ".json") {
Expand Down
10 changes: 4 additions & 6 deletions commands/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,25 @@ import (

"github.com/arduino/arduino-cli/internal/cli/configuration"
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
"github.com/arduino/arduino-cli/version"
)

// NewArduinoCoreServer returns an implementation of the ArduinoCoreService gRPC service
// that uses the provided version string.
func NewArduinoCoreServer(version string, settings *configuration.Settings) rpc.ArduinoCoreServiceServer {
func NewArduinoCoreServer() rpc.ArduinoCoreServiceServer {
return &arduinoCoreServerImpl{
versionString: version,
settings: settings,
settings: configuration.NewSettings(),
}
}

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

versionString string

// Settings holds configurations of the CLI and the gRPC consumers
settings *configuration.Settings
}

// Version returns the version of the Arduino CLI
func (s *arduinoCoreServerImpl) Version(ctx context.Context, req *rpc.VersionRequest) (*rpc.VersionResponse, error) {
return &rpc.VersionResponse{Version: s.versionString}, nil
return &rpc.VersionResponse{Version: version.VersionInfo.VersionString}, nil
}
3 changes: 1 addition & 2 deletions commands/service_cache_clean.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,12 @@ package commands
import (
"context"

"github.com/arduino/arduino-cli/internal/cli/configuration"
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
)

// CleanDownloadCacheDirectory clean the download cache directory (where archives are downloaded).
func (s *arduinoCoreServerImpl) CleanDownloadCacheDirectory(ctx context.Context, req *rpc.CleanDownloadCacheDirectoryRequest) (*rpc.CleanDownloadCacheDirectoryResponse, error) {
cachePath := configuration.DownloadsDir(s.settings)
cachePath := s.settings.DownloadsDir()
err := cachePath.RemoveAll()
if err != nil {
return nil, err
Expand Down
13 changes: 6 additions & 7 deletions commands/service_compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import (
"github.com/arduino/arduino-cli/internal/arduino/sketch"
"github.com/arduino/arduino-cli/internal/arduino/utils"
"github.com/arduino/arduino-cli/internal/buildcache"
"github.com/arduino/arduino-cli/internal/cli/configuration"
"github.com/arduino/arduino-cli/internal/inventory"
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
paths "github.com/arduino/go-paths-helper"
Expand Down Expand Up @@ -67,7 +66,7 @@ func (s *arduinoCoreServerImpl) Compile(req *rpc.CompileRequest, stream rpc.Ardu
ctx := stream.Context()
syncSend := NewSynchronizedSend(stream.Send)

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

defer maybePurgeBuildCache(
s.settings.GetUint("build_cache.compilations_before_purge"),
s.settings.GetDuration("build_cache.ttl").Abs())
s.settings.GetCompilationsBeforeBuildCachePurge(),
s.settings.GetBuildCacheTTL().Abs())

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

actualPlatform := buildPlatform
otherLibrariesDirs := paths.NewPathList(req.GetLibraries()...)
otherLibrariesDirs.Add(configuration.LibrariesDir(s.settings))
otherLibrariesDirs.Add(s.settings.LibrariesDir())

var libsManager *librariesmanager.LibrariesManager
if pme.GetProfile() != nil {
Expand Down Expand Up @@ -231,9 +230,9 @@ func (s *arduinoCoreServerImpl) Compile(req *rpc.CompileRequest, stream rpc.Ardu
coreBuildCachePath,
int(req.GetJobs()),
req.GetBuildProperties(),
configuration.HardwareDirectories(s.settings),
s.settings.HardwareDirectories(),
otherLibrariesDirs,
configuration.IDEBuiltinLibrariesDir(s.settings),
s.settings.IDEBuiltinLibrariesDir(),
fqbn,
req.GetClean(),
req.GetSourceOverride(),
Expand Down
24 changes: 19 additions & 5 deletions commands/service_platform_search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"context"
"testing"

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

settings := configuration.Init(paths.TempDir().Join("test", "arduino-cli.yaml").String())
srv := NewArduinoCoreServer("", settings)
ctx := context.Background()
srv := NewArduinoCoreServer()

conf, err := paths.TempDir().Join("test", "arduino-cli.yaml").ReadFile()
require.NoError(t, err)
_, err = srv.ConfigurationOpen(ctx, &rpc.ConfigurationOpenRequest{
Format: "yaml",
EncodedSettings: string(conf),
})
require.NoError(t, err)

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

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

settings := configuration.Init(paths.TempDir().Join("test", "arduino-cli.yaml").String())
srv := NewArduinoCoreServer("", settings)
ctx := context.Background()
srv := NewArduinoCoreServer()

conf, err := paths.TempDir().Join("test", "arduino-cli.yaml").ReadFile()
require.NoError(t, err)
_, err = srv.ConfigurationOpen(ctx, &rpc.ConfigurationOpenRequest{
Format: "yaml",
EncodedSettings: string(conf),
})
require.NoError(t, err)

createResp, err := srv.Create(ctx, &rpc.CreateRequest{})
require.NoError(t, err)
Expand Down
Loading

0 comments on commit 666e833

Please sign in to comment.