Commit 24ac0405 authored by Cristian Maglie's avatar Cristian Maglie

Pass down context in all places where it's needed

parent 240c8b3e
......@@ -251,7 +251,7 @@ func (s *arduinoCoreServerImpl) Init(req *rpc.InitRequest, stream rpc.ArduinoCor
}
} else {
// Load platforms from profile
errs := pmb.LoadHardwareForProfile(profile, true, downloadCallback, taskCallback, s.settings)
errs := pmb.LoadHardwareForProfile(ctx, profile, true, downloadCallback, taskCallback, s.settings)
for _, err := range errs {
s := &cmderrors.PlatformLoadingError{Cause: err}
responseError(s.GRPCStatus())
......@@ -497,13 +497,11 @@ func (s *arduinoCoreServerImpl) UpdateLibrariesIndex(req *rpc.UpdateLibrariesInd
}
// Perform index update
// TODO: pass context
// ctx := stream.Context()
config, err := s.settings.DownloaderConfig()
if err != nil {
return err
}
if err := globals.LibrariesIndexResource.Download(indexDir, downloadCB, config); err != nil {
if err := globals.LibrariesIndexResource.Download(stream.Context(), indexDir, downloadCB, config); err != nil {
resultCB(rpc.IndexUpdateReport_STATUS_FAILED)
return err
}
......@@ -621,7 +619,7 @@ func (s *arduinoCoreServerImpl) UpdateIndex(req *rpc.UpdateIndexRequest, stream
indexResource.SignatureURL, _ = url.Parse(u) // should not fail because we already parsed it
indexResource.SignatureURL.Path += ".sig"
}
if err := indexResource.Download(indexpath, downloadCB, config); err != nil {
if err := indexResource.Download(stream.Context(), indexpath, downloadCB, config); err != nil {
failed = true
result.UpdatedIndexes = append(result.GetUpdatedIndexes(), report(URL, rpc.IndexUpdateReport_STATUS_FAILED))
} else {
......
......@@ -44,6 +44,8 @@ var ErrSketchCannotBeLocatedInBuildPath = errors.New("sketch cannot be located i
// Builder is a Sketch builder.
type Builder struct {
ctx context.Context
sketch *sketch.Sketch
buildProperties *properties.Map
......@@ -198,6 +200,7 @@ func NewBuilder(
diagnosticStore := diagnostics.NewStore()
b := &Builder{
ctx: ctx,
sketch: sk,
buildProperties: buildProperties,
buildPath: buildPath,
......@@ -305,6 +308,7 @@ func (b *Builder) preprocess() error {
b.logIfVerbose(false, tr("Detecting libraries used..."))
err := b.libsDetector.FindIncludes(
b.ctx,
b.buildPath,
b.buildProperties.GetPath("build.core.path"),
b.buildProperties.GetPath("build.variant.path"),
......
......@@ -17,6 +17,7 @@ package detector
import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
......@@ -196,6 +197,7 @@ func (l *SketchLibrariesDetector) appendIncludeFolder(
// FindIncludes todo
func (l *SketchLibrariesDetector) FindIncludes(
ctx context.Context,
buildPath *paths.Path,
buildCorePath *paths.Path,
buildVariantPath *paths.Path,
......@@ -205,7 +207,7 @@ func (l *SketchLibrariesDetector) FindIncludes(
buildProperties *properties.Map,
platformArch string,
) error {
err := l.findIncludes(buildPath, buildCorePath, buildVariantPath, sketchBuildPath, sketch, librariesBuildPath, buildProperties, platformArch)
err := l.findIncludes(ctx, buildPath, buildCorePath, buildVariantPath, sketchBuildPath, sketch, librariesBuildPath, buildProperties, platformArch)
if err != nil && l.onlyUpdateCompilationDatabase {
l.logger.Info(
fmt.Sprintf(
......@@ -220,6 +222,7 @@ func (l *SketchLibrariesDetector) FindIncludes(
}
func (l *SketchLibrariesDetector) findIncludes(
ctx context.Context,
buildPath *paths.Path,
buildCorePath *paths.Path,
buildVariantPath *paths.Path,
......@@ -269,7 +272,7 @@ func (l *SketchLibrariesDetector) findIncludes(
}
for !sourceFileQueue.empty() {
err := l.findIncludesUntilDone(cache, sourceFileQueue, buildProperties, sketchBuildPath, librariesBuildPath, platformArch)
err := l.findIncludesUntilDone(ctx, cache, sourceFileQueue, buildProperties, sketchBuildPath, librariesBuildPath, platformArch)
if err != nil {
cachePath.Remove()
return err
......@@ -297,6 +300,7 @@ func (l *SketchLibrariesDetector) findIncludes(
}
func (l *SketchLibrariesDetector) findIncludesUntilDone(
ctx context.Context,
cache *includeCache,
sourceFileQueue *uniqueSourceFileQueue,
buildProperties *properties.Map,
......@@ -350,7 +354,7 @@ func (l *SketchLibrariesDetector) findIncludesUntilDone(
l.logger.Info(tr("Using cached library dependencies for file: %[1]s", sourcePath))
}
} else {
preprocFirstResult, preprocErr = preprocessor.GCC(sourcePath, targetFilePath, includeFolders, buildProperties)
preprocFirstResult, preprocErr = preprocessor.GCC(ctx, sourcePath, targetFilePath, includeFolders, buildProperties)
if l.logger.Verbose() {
l.logger.WriteStdout(preprocFirstResult.Stdout())
}
......@@ -381,7 +385,7 @@ func (l *SketchLibrariesDetector) findIncludesUntilDone(
// Library could not be resolved, show error
if preprocErr == nil || preprocFirstResult.Stderr() == nil {
// Filename came from cache, so run preprocessor to obtain error to show
result, err := preprocessor.GCC(sourcePath, targetFilePath, includeFolders, buildProperties)
result, err := preprocessor.GCC(ctx, sourcePath, targetFilePath, includeFolders, buildProperties)
if l.logger.Verbose() {
l.logger.WriteStdout(result.Stdout())
}
......
......@@ -31,6 +31,7 @@ import (
// PreprocessSketchWithArduinoPreprocessor performs preprocessing of the arduino sketch
// using arduino-preprocessor (https://github.com/arduino/arduino-preprocessor).
func PreprocessSketchWithArduinoPreprocessor(
ctx context.Context,
sk *sketch.Sketch, buildPath *paths.Path, includeFolders paths.PathList,
lineOffset int, buildProperties *properties.Map, onlyUpdateCompilationDatabase bool,
) (*Result, error) {
......@@ -42,7 +43,7 @@ func PreprocessSketchWithArduinoPreprocessor(
sourceFile := buildPath.Join("sketch", sk.MainFile.Base()+".cpp")
targetFile := buildPath.Join("preproc", "sketch_merged.cpp")
gccResult, err := GCC(sourceFile, targetFile, includeFolders, buildProperties)
gccResult, err := GCC(ctx, sourceFile, targetFile, includeFolders, buildProperties)
verboseOut.Write(gccResult.Stdout())
verboseOut.Write(gccResult.Stderr())
if err != nil {
......@@ -78,7 +79,7 @@ func PreprocessSketchWithArduinoPreprocessor(
}
verboseOut.WriteString(commandLine)
commandStdOut, commandStdErr, err := command.RunAndCaptureOutput(context.Background())
commandStdOut, commandStdErr, err := command.RunAndCaptureOutput(ctx)
verboseOut.Write(commandStdErr)
if err != nil {
return &Result{args: gccResult.Args(), stdout: verboseOut.Bytes(), stderr: normalOut.Bytes()}, err
......
......@@ -41,6 +41,7 @@ var DebugPreprocessor bool
// PreprocessSketchWithCtags performs preprocessing of the arduino sketch using CTags.
func PreprocessSketchWithCtags(
ctx context.Context,
sketch *sketch.Sketch, buildPath *paths.Path, includes paths.PathList,
lineOffset int, buildProperties *properties.Map,
onlyUpdateCompilationDatabase, verbose bool,
......@@ -57,7 +58,7 @@ func PreprocessSketchWithCtags(
// Run GCC preprocessor
sourceFile := buildPath.Join("sketch", sketch.MainFile.Base()+".cpp")
result, err := GCC(sourceFile, ctagsTarget, includes, buildProperties)
result, err := GCC(ctx, sourceFile, ctagsTarget, includes, buildProperties)
stdout.Write(result.Stdout())
stderr.Write(result.Stderr())
if err != nil {
......@@ -84,7 +85,7 @@ func PreprocessSketchWithCtags(
}
// Run CTags on gcc-preprocessed source
ctagsOutput, ctagsStdErr, err := RunCTags(ctagsTarget, buildProperties)
ctagsOutput, ctagsStdErr, err := RunCTags(ctx, ctagsTarget, buildProperties)
if verbose {
stderr.Write(ctagsStdErr)
}
......@@ -179,7 +180,7 @@ func isFirstFunctionOutsideOfSource(firstFunctionLine int, sourceRows []string)
}
// RunCTags performs a run of ctags on the given source file. Returns the ctags output and the stderr contents.
func RunCTags(sourceFile *paths.Path, buildProperties *properties.Map) ([]byte, []byte, error) {
func RunCTags(ctx context.Context, sourceFile *paths.Path, buildProperties *properties.Map) ([]byte, []byte, error) {
ctagsBuildProperties := properties.NewMap()
ctagsBuildProperties.Set("tools.ctags.path", "{runtime.tools.ctags.path}")
ctagsBuildProperties.Set("tools.ctags.cmd.path", "{path}/ctags")
......@@ -202,7 +203,7 @@ func RunCTags(sourceFile *paths.Path, buildProperties *properties.Map) ([]byte,
if err != nil {
return nil, nil, err
}
stdout, stderr, err := proc.RunAndCaptureOutput(context.Background())
stdout, stderr, err := proc.RunAndCaptureOutput(ctx)
// Append ctags arguments to stderr
args := fmt.Sprintln(strings.Join(parts, " "))
......
......@@ -30,6 +30,7 @@ import (
// GCC performs a run of the gcc preprocess (macro/includes expansion). The function outputs the result
// to targetFilePath. Returns the stdout/stderr of gcc if any.
func GCC(
ctx context.Context,
sourceFilePath, targetFilePath *paths.Path,
includes paths.PathList, buildProperties *properties.Map,
) (Result, error) {
......@@ -75,7 +76,7 @@ func GCC(
if err != nil {
return Result{}, err
}
stdout, stderr, err := proc.RunAndCaptureOutput(context.Background())
stdout, stderr, err := proc.RunAndCaptureOutput(ctx)
// Append gcc arguments to stdout
stdout = append([]byte(fmt.Sprintln(strings.Join(args, " "))), stdout...)
......
......@@ -24,6 +24,7 @@ import (
func (b *Builder) preprocessSketch(includes paths.PathList) error {
// In the future we might change the preprocessor
result, err := preprocessor.PreprocessSketchWithCtags(
b.ctx,
b.sketch, b.buildPath, includes, b.lineOffset,
b.buildProperties, b.onlyUpdateCompilationDatabase, b.logger.Verbose(),
)
......
......@@ -16,6 +16,7 @@
package packagemanager
import (
"context"
"fmt"
"net/url"
......@@ -32,7 +33,7 @@ import (
// LoadHardwareForProfile load the hardware platforms for the given profile.
// If installMissing is true then possibly missing tools and platforms will be downloaded and installed.
func (pmb *Builder) LoadHardwareForProfile(p *sketch.Profile, installMissing bool, downloadCB rpc.DownloadProgressCB, taskCB rpc.TaskProgressCB, settings *configuration.Settings) []error {
func (pmb *Builder) LoadHardwareForProfile(ctx context.Context, p *sketch.Profile, installMissing bool, downloadCB rpc.DownloadProgressCB, taskCB rpc.TaskProgressCB, settings *configuration.Settings) []error {
pmb.profile = p
// Load required platforms
......@@ -40,7 +41,7 @@ func (pmb *Builder) LoadHardwareForProfile(p *sketch.Profile, installMissing boo
var platformReleases []*cores.PlatformRelease
indexURLs := map[string]*url.URL{}
for _, platformRef := range p.Platforms {
if platformRelease, err := pmb.loadProfilePlatform(platformRef, installMissing, downloadCB, taskCB, settings); err != nil {
if platformRelease, err := pmb.loadProfilePlatform(ctx, platformRef, installMissing, downloadCB, taskCB, settings); err != nil {
merr = append(merr, fmt.Errorf("%s: %w", tr("loading required platform %s", platformRef), err))
logrus.WithField("platform", platformRef).WithError(err).Debugf("Error loading platform for profile")
} else {
......@@ -68,7 +69,7 @@ func (pmb *Builder) LoadHardwareForProfile(p *sketch.Profile, installMissing boo
return merr
}
func (pmb *Builder) loadProfilePlatform(platformRef *sketch.ProfilePlatformReference, installMissing bool, downloadCB rpc.DownloadProgressCB, taskCB rpc.TaskProgressCB, settings *configuration.Settings) (*cores.PlatformRelease, error) {
func (pmb *Builder) loadProfilePlatform(ctx context.Context, platformRef *sketch.ProfilePlatformReference, installMissing bool, downloadCB rpc.DownloadProgressCB, taskCB rpc.TaskProgressCB, settings *configuration.Settings) (*cores.PlatformRelease, error) {
targetPackage := pmb.packages.GetOrCreatePackage(platformRef.Packager)
platform := targetPackage.GetOrCreatePlatform(platformRef.Architecture)
release := platform.GetOrCreateRelease(platformRef.Version)
......@@ -77,14 +78,14 @@ func (pmb *Builder) loadProfilePlatform(platformRef *sketch.ProfilePlatformRefer
destDir := settings.ProfilesCacheDir().Join(uid)
if !destDir.IsDir() && installMissing {
// Try installing the missing platform
if err := pmb.installMissingProfilePlatform(platformRef, destDir, downloadCB, taskCB); err != nil {
if err := pmb.installMissingProfilePlatform(ctx, platformRef, destDir, downloadCB, taskCB); err != nil {
return nil, err
}
}
return release, pmb.loadPlatformRelease(release, destDir)
}
func (pmb *Builder) installMissingProfilePlatform(platformRef *sketch.ProfilePlatformReference, destDir *paths.Path, downloadCB rpc.DownloadProgressCB, taskCB rpc.TaskProgressCB) error {
func (pmb *Builder) installMissingProfilePlatform(ctx context.Context, platformRef *sketch.ProfilePlatformReference, destDir *paths.Path, downloadCB rpc.DownloadProgressCB, taskCB rpc.TaskProgressCB) error {
// Instantiate a temporary package manager only for platform installation
_ = pmb.tempDir.MkdirAll()
tmp, err := paths.MkTempDir(pmb.tempDir.String(), "")
......@@ -103,7 +104,7 @@ func (pmb *Builder) installMissingProfilePlatform(platformRef *sketch.ProfilePla
}
for _, indexURL := range indexesToDownload {
indexResource := resources.IndexResource{URL: indexURL}
if err := indexResource.Download(tmpPmb.IndexDir, downloadCB, pmb.downloaderConfig); err != nil {
if err := indexResource.Download(ctx, tmpPmb.IndexDir, downloadCB, pmb.downloaderConfig); err != nil {
taskCB(&rpc.TaskProgress{Name: tr("Error downloading %s", indexURL)})
return &cmderrors.FailedDownloadError{Message: tr("Error downloading %s", indexURL), Cause: err}
}
......
......@@ -58,7 +58,7 @@ func (res *IndexResource) IndexFileName() (string, error) {
// Download will download the index and possibly check the signature using the Arduino's public key.
// If the file is in .gz format it will be unpacked first.
func (res *IndexResource) Download(destDir *paths.Path, downloadCB rpc.DownloadProgressCB, config downloader.Config) error {
func (res *IndexResource) Download(ctx context.Context, destDir *paths.Path, downloadCB rpc.DownloadProgressCB, config downloader.Config) error {
// Create destination directory
if err := destDir.MkdirAll(); err != nil {
return &cmderrors.PermissionDeniedError{Message: tr("Can't create data directory %s", destDir), Cause: err}
......@@ -100,7 +100,7 @@ func (res *IndexResource) Download(destDir *paths.Path, downloadCB rpc.DownloadP
defer f.Close()
tmpArchivePath := tmp.Join("archive")
_ = tmpArchivePath.MkdirAll()
if err := extract.Bz2(context.Background(), f, tmpArchivePath.String(), nil); err != nil {
if err := extract.Bz2(ctx, f, tmpArchivePath.String(), nil); err != nil {
return &cmderrors.PermissionDeniedError{Message: tr("Error extracting %s", tmpIndexPath), Cause: err}
}
......
......@@ -16,6 +16,7 @@
package resources
import (
"context"
"crypto"
"encoding/hex"
"fmt"
......@@ -116,6 +117,7 @@ func TestDownloadAndChecksums(t *testing.T) {
}
func TestIndexDownloadAndSignatureWithinArchive(t *testing.T) {
ctx := context.Background()
// Spawn test webserver
mux := http.NewServeMux()
fs := http.FileServer(http.Dir("testdata"))
......@@ -132,7 +134,7 @@ func TestIndexDownloadAndSignatureWithinArchive(t *testing.T) {
destDir, err := paths.MkTempDir("", "")
require.NoError(t, err)
defer destDir.RemoveAll()
err = idxResource.Download(destDir, func(curr *rpc.DownloadProgress) {}, downloader.GetDefaultConfig())
err = idxResource.Download(ctx, destDir, func(curr *rpc.DownloadProgress) {}, downloader.GetDefaultConfig())
require.NoError(t, err)
require.True(t, destDir.Join("package_index.json").Exist())
require.True(t, destDir.Join("package_index.json.sig").Exist())
......@@ -143,7 +145,7 @@ func TestIndexDownloadAndSignatureWithinArchive(t *testing.T) {
invDestDir, err := paths.MkTempDir("", "")
require.NoError(t, err)
defer invDestDir.RemoveAll()
err = invIdxResource.Download(invDestDir, func(curr *rpc.DownloadProgress) {}, downloader.GetDefaultConfig())
err = invIdxResource.Download(ctx, invDestDir, func(curr *rpc.DownloadProgress) {}, downloader.GetDefaultConfig())
require.Error(t, err)
require.Contains(t, err.Error(), "invalid signature")
require.False(t, invDestDir.Join("package_index.json").Exist())
......
......@@ -29,7 +29,7 @@ import (
func GetInstalledBoards(ctx context.Context, srv rpc.ArduinoCoreServiceServer) []string {
inst := instance.CreateAndInit(ctx, srv)
list, _ := srv.BoardListAll(context.Background(), &rpc.BoardListAllRequest{
list, _ := srv.BoardListAll(ctx, &rpc.BoardListAllRequest{
Instance: inst,
SearchArgs: nil,
IncludeHiddenBoards: false,
......@@ -53,7 +53,7 @@ func GetInstalledProgrammers(ctx context.Context, srv rpc.ArduinoCoreServiceServ
SearchArgs: nil,
IncludeHiddenBoards: false,
}
list, _ := srv.BoardListAll(context.Background(), listAllReq)
list, _ := srv.BoardListAll(ctx, listAllReq)
installedProgrammers := make(map[string]string)
for _, board := range list.GetBoards() {
......@@ -149,7 +149,7 @@ func getLibraries(ctx context.Context, srv rpc.ArduinoCoreServiceServer, all boo
func GetInstallableLibs(ctx context.Context, srv rpc.ArduinoCoreServiceServer) []string {
inst := instance.CreateAndInit(ctx, srv)
libs, _ := srv.LibrarySearch(context.Background(), &rpc.LibrarySearchRequest{
libs, _ := srv.LibrarySearch(ctx, &rpc.LibrarySearchRequest{
Instance: inst,
SearchArgs: "", // if no query is specified all the libs are returned
})
......
......@@ -37,7 +37,7 @@ type Fqbn struct {
func (f *Fqbn) AddToCommand(cmd *cobra.Command, srv rpc.ArduinoCoreServiceServer) {
cmd.Flags().StringVarP(&f.fqbn, "fqbn", "b", "", tr("Fully Qualified Board Name, e.g.: arduino:avr:uno"))
cmd.RegisterFlagCompletionFunc("fqbn", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return GetInstalledBoards(context.Background(), srv), cobra.ShellCompDirectiveDefault
return GetInstalledBoards(cmd.Context(), srv), cobra.ShellCompDirectiveDefault
})
cmd.Flags().StringSliceVar(&f.boardOptions, "board-options", []string{},
tr("List of board options separated by commas. Or can be used multiple times for multiple options."))
......@@ -70,7 +70,7 @@ func (f *Fqbn) Set(fqbn string) {
// - the port is not found, in this case nil is returned
// - the FQBN autodetection fail, in this case the function prints an error and
// terminates the execution
func CalculateFQBNAndPort(portArgs *Port, fqbnArg *Fqbn, instance *rpc.Instance, srv rpc.ArduinoCoreServiceServer, defaultFQBN, defaultAddress, defaultProtocol string) (string, *rpc.Port) {
func CalculateFQBNAndPort(ctx context.Context, portArgs *Port, fqbnArg *Fqbn, instance *rpc.Instance, srv rpc.ArduinoCoreServiceServer, defaultFQBN, defaultAddress, defaultProtocol string) (string, *rpc.Port) {
fqbn := fqbnArg.String()
if fqbn == "" {
fqbn = defaultFQBN
......@@ -79,14 +79,14 @@ func CalculateFQBNAndPort(portArgs *Port, fqbnArg *Fqbn, instance *rpc.Instance,
if portArgs == nil || portArgs.address == "" {
feedback.FatalError(&cmderrors.MissingFQBNError{}, feedback.ErrGeneric)
}
fqbn, port := portArgs.DetectFQBN(instance, srv)
fqbn, port := portArgs.DetectFQBN(ctx, instance, srv)
if fqbn == "" {
feedback.FatalError(&cmderrors.MissingFQBNError{}, feedback.ErrGeneric)
}
return fqbn, port
}
port, err := portArgs.GetPort(instance, srv, defaultAddress, defaultProtocol)
port, err := portArgs.GetPort(ctx, instance, srv, defaultAddress, defaultProtocol)
if err != nil {
feedback.Fatal(tr("Error getting port metadata: %v", err), feedback.ErrGeneric)
}
......
......@@ -42,11 +42,11 @@ type Port struct {
func (p *Port) AddToCommand(cmd *cobra.Command, srv rpc.ArduinoCoreServiceServer) {
cmd.Flags().StringVarP(&p.address, "port", "p", "", tr("Upload port address, e.g.: COM3 or /dev/ttyACM2"))
cmd.RegisterFlagCompletionFunc("port", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return f.Map(GetAvailablePorts(context.Background(), srv), (*rpc.Port).GetAddress), cobra.ShellCompDirectiveDefault
return f.Map(GetAvailablePorts(cmd.Context(), srv), (*rpc.Port).GetAddress), cobra.ShellCompDirectiveDefault
})
cmd.Flags().StringVarP(&p.protocol, "protocol", "l", "", tr("Upload port protocol, e.g: serial"))
cmd.RegisterFlagCompletionFunc("protocol", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return f.Map(GetAvailablePorts(context.Background(), srv), (*rpc.Port).GetProtocol), cobra.ShellCompDirectiveDefault
return f.Map(GetAvailablePorts(cmd.Context(), srv), (*rpc.Port).GetProtocol), cobra.ShellCompDirectiveDefault
})
p.timeout.AddToCommand(cmd)
}
......@@ -56,12 +56,12 @@ func (p *Port) AddToCommand(cmd *cobra.Command, srv rpc.ArduinoCoreServiceServer
// This method allows will bypass the discoveries if:
// - a nil instance is passed: in this case the plain port and protocol arguments are returned (even if empty)
// - a protocol is specified: in this case the discoveries are not needed to autodetect the protocol.
func (p *Port) GetPortAddressAndProtocol(instance *rpc.Instance, srv rpc.ArduinoCoreServiceServer, defaultAddress, defaultProtocol string) (string, string, error) {
func (p *Port) GetPortAddressAndProtocol(ctx context.Context, instance *rpc.Instance, srv rpc.ArduinoCoreServiceServer, defaultAddress, defaultProtocol string) (string, string, error) {
if p.protocol != "" || instance == nil {
return p.address, p.protocol, nil
}
port, err := p.GetPort(instance, srv, defaultAddress, defaultProtocol)
port, err := p.GetPort(ctx, instance, srv, defaultAddress, defaultProtocol)
if err != nil {
return "", "", err
}
......@@ -70,7 +70,7 @@ func (p *Port) GetPortAddressAndProtocol(instance *rpc.Instance, srv rpc.Arduino
// GetPort returns the Port obtained by parsing command line arguments.
// The extra metadata for the ports is obtained using the pluggable discoveries.
func (p *Port) GetPort(instance *rpc.Instance, srv rpc.ArduinoCoreServiceServer, defaultAddress, defaultProtocol string) (*rpc.Port, error) {
func (p *Port) GetPort(ctx context.Context, instance *rpc.Instance, srv rpc.ArduinoCoreServiceServer, defaultAddress, defaultProtocol string) (*rpc.Port, error) {
address := p.address
protocol := p.protocol
if address == "" && (defaultAddress != "" || defaultProtocol != "") {
......@@ -88,7 +88,7 @@ func (p *Port) GetPort(instance *rpc.Instance, srv rpc.ArduinoCoreServiceServer,
}
logrus.WithField("port", address).Tracef("Upload port")
ctx, cancel := context.WithCancel(context.Background())
ctx, cancel := context.WithCancel(ctx)
defer cancel()
stream, watcher := commands.BoardListWatchProxyToChan(ctx)
......@@ -131,8 +131,8 @@ func (p *Port) GetSearchTimeout() time.Duration {
// DetectFQBN tries to identify the board connected to the port and returns the
// discovered Port object together with the FQBN. If the port does not match
// exactly 1 board,
func (p *Port) DetectFQBN(inst *rpc.Instance, srv rpc.ArduinoCoreServiceServer) (string, *rpc.Port) {
detectedPorts, err := srv.BoardList(context.Background(), &rpc.BoardListRequest{
func (p *Port) DetectFQBN(ctx context.Context, inst *rpc.Instance, srv rpc.ArduinoCoreServiceServer) (string, *rpc.Port) {
detectedPorts, err := srv.BoardList(ctx, &rpc.BoardListRequest{
Instance: inst,
Timeout: p.timeout.Get().Milliseconds(),
})
......
......@@ -16,8 +16,6 @@
package arguments
import (
"context"
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
"github.com/spf13/cobra"
)
......@@ -37,7 +35,7 @@ func (f *Profile) AddToCommand(cmd *cobra.Command, srv rpc.ArduinoCoreServiceSer
if len(args) > 0 {
sketchProfile = args[0]
}
return GetSketchProfiles(context.Background(), srv, sketchProfile), cobra.ShellCompDirectiveDefault
return GetSketchProfiles(cmd.Context(), srv, sketchProfile), cobra.ShellCompDirectiveDefault
})
}
......
......@@ -33,20 +33,20 @@ type Programmer struct {
func (p *Programmer) AddToCommand(cmd *cobra.Command, srv rpc.ArduinoCoreServiceServer) {
cmd.Flags().StringVarP(&p.programmer, "programmer", "P", "", tr("Programmer to use, e.g: atmel_ice"))
cmd.RegisterFlagCompletionFunc("programmer", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return GetInstalledProgrammers(context.Background(), srv), cobra.ShellCompDirectiveDefault
return GetInstalledProgrammers(cmd.Context(), srv), cobra.ShellCompDirectiveDefault
})
}
// String returns the programmer specified by the user, or the default programmer
// for the given board if defined.
func (p *Programmer) String(inst *rpc.Instance, srv rpc.ArduinoCoreServiceServer, fqbn string) string {
func (p *Programmer) String(ctx context.Context, inst *rpc.Instance, srv rpc.ArduinoCoreServiceServer, fqbn string) string {
if p.programmer != "" {
return p.programmer
}
if inst == nil || fqbn == "" {
return ""
}
details, err := srv.BoardDetails(context.Background(), &rpc.BoardDetailsRequest{
details, err := srv.BoardDetails(ctx, &rpc.BoardDetailsRequest{
Instance: inst,
Fqbn: fqbn,
})
......
......@@ -40,11 +40,12 @@ func initAttachCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
" " + os.Args[0] + " board attach -P atmel_ice",
Args: cobra.MaximumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
ctx := cmd.Context()
sketchPath := ""
if len(args) > 0 {
sketchPath = args[0]
}
runAttachCommand(srv, sketchPath, &port, fqbn.String(), &programmer)
runAttachCommand(ctx, srv, sketchPath, &port, fqbn.String(), &programmer)
},
}
fqbn.AddToCommand(attachCommand, srv)
......@@ -54,11 +55,10 @@ func initAttachCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
return attachCommand
}
func runAttachCommand(srv rpc.ArduinoCoreServiceServer, path string, port *arguments.Port, fqbn string, programmer *arguments.Programmer) {
ctx := context.Background()
func runAttachCommand(ctx context.Context, srv rpc.ArduinoCoreServiceServer, path string, port *arguments.Port, fqbn string, programmer *arguments.Programmer) {
sketchPath := arguments.InitSketchPath(path)
portAddress, portProtocol, _ := port.GetPortAddressAndProtocol(nil, srv, "", "")
portAddress, portProtocol, _ := port.GetPortAddressAndProtocol(ctx, nil, srv, "", "")
newDefaults, err := srv.SetSketchDefaults(ctx, &rpc.SetSketchDefaultsRequest{
SketchPath: sketchPath.String(),
DefaultFqbn: fqbn,
......
......@@ -43,7 +43,7 @@ func initDetailsCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
Example: " " + os.Args[0] + " board details -b arduino:avr:nano",
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
runDetailsCommand(srv, fqbn.String(), showFullDetails, listProgrammers, showProperties)
runDetailsCommand(cmd.Context(), srv, fqbn.String(), showFullDetails, listProgrammers, showProperties)
},
}
......@@ -55,8 +55,7 @@ func initDetailsCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
return detailsCommand
}
func runDetailsCommand(srv rpc.ArduinoCoreServiceServer, fqbn string, showFullDetails, listProgrammers bool, showProperties arguments.ShowProperties) {
ctx := context.Background()
func runDetailsCommand(ctx context.Context, srv rpc.ArduinoCoreServiceServer, fqbn string, showFullDetails, listProgrammers bool, showProperties arguments.ShowProperties) {
inst := instance.CreateAndInit(ctx, srv)
logrus.Info("Executing `arduino-cli board details`")
......@@ -65,7 +64,7 @@ func runDetailsCommand(srv rpc.ArduinoCoreServiceServer, fqbn string, showFullDe
if err != nil {
feedback.Fatal(err.Error(), feedback.ErrBadArgument)
}
res, err := srv.BoardDetails(context.Background(), &rpc.BoardDetailsRequest{
res, err := srv.BoardDetails(ctx, &rpc.BoardDetailsRequest{
Instance: inst,
Fqbn: fqbn,
DoNotExpandBuildProperties: showPropertiesMode == arguments.ShowPropertiesUnexpanded,
......
......@@ -46,7 +46,7 @@ func initListCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
Example: " " + os.Args[0] + " board list --discovery-timeout 10s",
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
runListCommand(srv, watch, timeoutArg.Get().Milliseconds(), fqbn.String())
runListCommand(cmd.Context(), srv, watch, timeoutArg.Get().Milliseconds(), fqbn.String())
},
}
......@@ -57,18 +57,17 @@ func initListCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
}
// runListCommand detects and lists the connected arduino boards
func runListCommand(srv rpc.ArduinoCoreServiceServer, watch bool, timeout int64, fqbn string) {
ctx := context.Background()
func runListCommand(ctx context.Context, srv rpc.ArduinoCoreServiceServer, watch bool, timeout int64, fqbn string) {
inst := instance.CreateAndInit(ctx, srv)
logrus.Info("Executing `arduino-cli board list`")
if watch {
watchList(inst, srv)
watchList(ctx, inst, srv)
return
}
list, err := srv.BoardList(context.Background(), &rpc.BoardListRequest{
list, err := srv.BoardList(ctx, &rpc.BoardListRequest{
Instance: inst,
Timeout: timeout,
Fqbn: fqbn,
......@@ -89,8 +88,8 @@ func runListCommand(srv rpc.ArduinoCoreServiceServer, watch bool, timeout int64,
feedback.PrintResult(listResult{result.NewDetectedPorts(ports)})
}
func watchList(inst *rpc.Instance, srv rpc.ArduinoCoreServiceServer) {
stream, eventsChan := commands.BoardListWatchProxyToChan(context.Background())
func watchList(ctx context.Context, inst *rpc.Instance, srv rpc.ArduinoCoreServiceServer) {
stream, eventsChan := commands.BoardListWatchProxyToChan(ctx)
err := srv.BoardListWatch(&rpc.BoardListWatchRequest{Instance: inst}, stream)
if err != nil {
feedback.Fatal(tr("Error detecting boards: %v", err), feedback.ErrNetwork)
......
......@@ -43,7 +43,7 @@ for a specific board if you specify the board name`),
" " + os.Args[0] + " board listall zero",
Args: cobra.ArbitraryArgs,
Run: func(cmd *cobra.Command, args []string) {
runListAllCommand(args, srv)
runListAllCommand(cmd.Context(), args, srv)
},
}
listAllCommand.Flags().BoolVarP(&showHiddenBoard, "show-hidden", "a", false, tr("Show also boards marked as 'hidden' in the platform"))
......@@ -51,13 +51,12 @@ for a specific board if you specify the board name`),
}
// runListAllCommand list all installed boards
func runListAllCommand(args []string, srv rpc.ArduinoCoreServiceServer) {
ctx := context.Background()
func runListAllCommand(ctx context.Context, args []string, srv rpc.ArduinoCoreServiceServer) {
inst := instance.CreateAndInit(ctx, srv)
logrus.Info("Executing `arduino-cli board listall`")
list, err := srv.BoardListAll(context.Background(), &rpc.BoardListAllRequest{
list, err := srv.BoardListAll(ctx, &rpc.BoardListAllRequest{
Instance: inst,
SearchArgs: args,
IncludeHiddenBoards: showHiddenBoard,
......
......@@ -41,20 +41,19 @@ func initSearchCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
" " + os.Args[0] + " board search zero",
Args: cobra.ArbitraryArgs,
Run: func(cmd *cobra.Command, args []string) {
runSearchCommand(srv, args)
runSearchCommand(cmd.Context(), srv, args)
},
}
searchCommand.Flags().BoolVarP(&showHiddenBoard, "show-hidden", "a", false, tr("Show also boards marked as 'hidden' in the platform"))
return searchCommand
}
func runSearchCommand(srv rpc.ArduinoCoreServiceServer, args []string) {
ctx := context.Background()
func runSearchCommand(ctx context.Context, srv rpc.ArduinoCoreServiceServer, args []string) {
inst := instance.CreateAndInit(ctx, srv)
logrus.Info("Executing `arduino-cli board search`")
res, err := srv.BoardSearch(context.Background(), &rpc.BoardSearchRequest{
res, err := srv.BoardSearch(ctx, &rpc.BoardSearchRequest{
Instance: inst,
SearchArgs: strings.Join(args, " "),
IncludeHiddenBoards: showHiddenBoard,
......
......@@ -50,7 +50,7 @@ func NewCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
Example: " " + os.Args[0] + " burn-bootloader -b arduino:avr:uno -P atmel_ice",
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
runBootloaderCommand(srv)
runBootloaderCommand(cmd.Context(), srv)
},
}
......@@ -65,14 +65,13 @@ func NewCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
return burnBootloaderCommand
}
func runBootloaderCommand(srv rpc.ArduinoCoreServiceServer) {
ctx := context.Background()
func runBootloaderCommand(ctx context.Context, srv rpc.ArduinoCoreServiceServer) {
instance := instance.CreateAndInit(ctx, srv)
logrus.Info("Executing `arduino-cli burn-bootloader`")
// We don't need a Sketch to upload a board's bootloader
discoveryPort, err := port.GetPort(instance, srv, "", "")
discoveryPort, err := port.GetPort(ctx, instance, srv, "", "")
if err != nil {
feedback.Fatal(tr("Error during Upload: %v", err), feedback.ErrGeneric)
}
......@@ -85,7 +84,7 @@ func runBootloaderCommand(srv rpc.ArduinoCoreServiceServer) {
Port: discoveryPort,
Verbose: verbose,
Verify: verify,
Programmer: programmer.String(instance, srv, fqbn.String()),
Programmer: programmer.String(ctx, instance, srv, fqbn.String()),
DryRun: dryRun,
}, stream); err != nil {
errcode := feedback.ErrGeneric
......
......@@ -33,16 +33,16 @@ func initCleanCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
Example: " " + os.Args[0] + " cache clean",
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
runCleanCommand(srv)
runCleanCommand(cmd.Context(), srv)
},
}
return cleanCommand
}
func runCleanCommand(srv rpc.ArduinoCoreServiceServer) {
func runCleanCommand(ctx context.Context, srv rpc.ArduinoCoreServiceServer) {
logrus.Info("Executing `arduino-cli cache clean`")
_, err := srv.CleanDownloadCacheDirectory(context.Background(), &rpc.CleanDownloadCacheDirectoryRequest{})
_, err := srv.CleanDownloadCacheDirectory(ctx, &rpc.CleanDownloadCacheDirectoryRequest{})
if err != nil {
feedback.Fatal(tr("Error cleaning caches: %v", err), feedback.ErrGeneric)
}
......
......@@ -115,7 +115,7 @@ func NewCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
if cmd.Name() != "version" {
updaterMessageChan = make(chan *semver.Version)
go func() {
res, err := srv.CheckForArduinoCLIUpdates(context.Background(), &rpc.CheckForArduinoCLIUpdatesRequest{})
res, err := srv.CheckForArduinoCLIUpdates(ctx, &rpc.CheckForArduinoCLIUpdatesRequest{})
if err != nil {
logrus.Warnf("Error checking for updates: %v", err)
updaterMessageChan <- nil
......
......@@ -16,7 +16,6 @@
package compile
import (
"context"
"encoding/json"
"errors"
"fmt"
......@@ -141,7 +140,7 @@ func NewCommand(srv rpc.ArduinoCoreServiceServer, settings *rpc.Configuration) *
func runCompileCommand(cmd *cobra.Command, args []string, srv rpc.ArduinoCoreServiceServer) {
logrus.Info("Executing `arduino-cli compile`")
ctx := context.Background()
ctx := cmd.Context()
if profileArg.Get() != "" {
if len(libraries) > 0 {
......@@ -178,7 +177,7 @@ func runCompileCommand(cmd *cobra.Command, args []string, srv rpc.ArduinoCoreSer
fqbnArg.Set(profile.GetFqbn())
}
fqbn, port := arguments.CalculateFQBNAndPort(&portArgs, &fqbnArg, inst, srv, sk.GetDefaultFqbn(), sk.GetDefaultPort(), sk.GetDefaultProtocol())
fqbn, port := arguments.CalculateFQBNAndPort(ctx, &portArgs, &fqbnArg, inst, srv, sk.GetDefaultFqbn(), sk.GetDefaultPort(), sk.GetDefaultProtocol())
if keysKeychain != "" || signKey != "" || encryptKey != "" {
arguments.CheckFlagsMandatory(cmd, "keys-keychain", "sign-key", "encrypt-key")
......@@ -274,7 +273,7 @@ func runCompileCommand(cmd *cobra.Command, args []string, srv rpc.ArduinoCoreSer
prog := profile.GetProgrammer()
if prog == "" || programmer.GetProgrammer() != "" {
prog = programmer.String(inst, srv, fqbn)
prog = programmer.String(ctx, inst, srv, fqbn)
}
if prog == "" {
prog = sk.GetDefaultProgrammer()
......
......@@ -39,7 +39,7 @@ func initGetCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
" " + os.Args[0] + " config get board_manager.additional_urls",
Args: cobra.MinimumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
runGetCommand(srv, args)
runGetCommand(cmd.Context(), srv, args)
},
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
ctx := cmd.Context()
......@@ -49,9 +49,8 @@ func initGetCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
return getCommand
}
func runGetCommand(srv rpc.ArduinoCoreServiceServer, args []string) {
func runGetCommand(ctx context.Context, srv rpc.ArduinoCoreServiceServer, args []string) {
logrus.Info("Executing `arduino-cli config get`")
ctx := context.Background()
for _, toGet := range args {
resp, err := srv.SettingsGetValue(ctx, &rpc.SettingsGetValueRequest{Key: toGet})
......
......@@ -39,17 +39,16 @@ func initDownloadCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
" " + os.Args[0] + " core download arduino:samd@1.6.9 # " + tr("download a specific version (in this case 1.6.9)."),
Args: cobra.MinimumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
runDownloadCommand(srv, args)
runDownloadCommand(cmd.Context(), srv, args)
},
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return arguments.GetInstallableCores(context.Background(), srv), cobra.ShellCompDirectiveDefault
return arguments.GetInstallableCores(cmd.Context(), srv), cobra.ShellCompDirectiveDefault
},
}
return downloadCommand
}
func runDownloadCommand(srv rpc.ArduinoCoreServiceServer, args []string) {
ctx := context.Background()
func runDownloadCommand(ctx context.Context, srv rpc.ArduinoCoreServiceServer, args []string) {
inst := instance.CreateAndInit(ctx, srv)
logrus.Info("Executing `arduino-cli core download`")
......
......@@ -45,10 +45,10 @@ func initInstallCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
arguments.CheckFlagsConflicts(cmd, "run-post-install", "skip-post-install")
},
Run: func(cmd *cobra.Command, args []string) {
runInstallCommand(srv, args, scriptFlags, noOverwrite)
runInstallCommand(cmd.Context(), srv, args, scriptFlags, noOverwrite)
},
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return arguments.GetInstallableCores(context.Background(), srv), cobra.ShellCompDirectiveDefault
return arguments.GetInstallableCores(cmd.Context(), srv), cobra.ShellCompDirectiveDefault
},
}
scriptFlags.AddToCommand(installCommand)
......@@ -56,9 +56,8 @@ func initInstallCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
return installCommand
}
func runInstallCommand(srv rpc.ArduinoCoreServiceServer, args []string, scriptFlags arguments.PrePostScriptsFlags, noOverwrite bool) {
func runInstallCommand(ctx context.Context, srv rpc.ArduinoCoreServiceServer, args []string, scriptFlags arguments.PrePostScriptsFlags, noOverwrite bool) {
logrus.Info("Executing `arduino-cli core install`")
ctx := context.Background()
inst := instance.CreateAndInit(ctx, srv)
platformsRefs, err := arguments.ParseReferences(ctx, srv, args)
......
......@@ -38,7 +38,7 @@ func initListCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
Example: " " + os.Args[0] + " core list",
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
runListCommand(srv, all, updatableOnly)
runListCommand(cmd.Context(), srv, all, updatableOnly)
},
}
listCommand.Flags().BoolVar(&updatableOnly, "updatable", false, tr("List updatable platforms."))
......@@ -46,8 +46,7 @@ func initListCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
return listCommand
}
func runListCommand(srv rpc.ArduinoCoreServiceServer, all bool, updatableOnly bool) {
ctx := context.Background()
func runListCommand(ctx context.Context, srv rpc.ArduinoCoreServiceServer, all bool, updatableOnly bool) {
inst := instance.CreateAndInit(ctx, srv)
logrus.Info("Executing `arduino-cli core list`")
List(ctx, srv, inst, all, updatableOnly)
......
......@@ -41,7 +41,7 @@ func initSearchCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
Example: " " + os.Args[0] + " core search MKRZero -a -v",
Args: cobra.ArbitraryArgs,
Run: func(cmd *cobra.Command, args []string) {
runSearchCommand(srv, args, allVersions)
runSearchCommand(cmd.Context(), srv, args, allVersions)
},
}
searchCommand.Flags().BoolVarP(&allVersions, "all", "a", false, tr("Show all available core versions."))
......@@ -52,8 +52,7 @@ func initSearchCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
// indexUpdateInterval specifies the time threshold over which indexes are updated
const indexUpdateInterval = 24 * time.Hour
func runSearchCommand(srv rpc.ArduinoCoreServiceServer, args []string, allVersions bool) {
ctx := context.Background()
func runSearchCommand(ctx context.Context, srv rpc.ArduinoCoreServiceServer, args []string, allVersions bool) {
inst := instance.CreateAndInit(ctx, srv)
stream, res := commands.UpdateIndexStreamResponseToCallbackFunction(ctx, feedback.ProgressBar())
......
......@@ -38,19 +38,18 @@ func initUninstallCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
Example: " " + os.Args[0] + " core uninstall arduino:samd\n",
Args: cobra.MinimumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
runUninstallCommand(srv, args, preUninstallFlags)
runUninstallCommand(cmd.Context(), srv, args, preUninstallFlags)
},
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return arguments.GetUninstallableCores(context.Background(), srv), cobra.ShellCompDirectiveDefault
return arguments.GetUninstallableCores(cmd.Context(), srv), cobra.ShellCompDirectiveDefault
},
}
preUninstallFlags.AddToCommand(uninstallCommand)
return uninstallCommand
}
func runUninstallCommand(srv rpc.ArduinoCoreServiceServer, args []string, preUninstallFlags arguments.PrePostScriptsFlags) {
func runUninstallCommand(ctx context.Context, srv rpc.ArduinoCoreServiceServer, args []string, preUninstallFlags arguments.PrePostScriptsFlags) {
logrus.Info("Executing `arduino-cli core uninstall`")
ctx := context.Background()
inst := instance.CreateAndInit(ctx, srv)
platformsRefs, err := arguments.ParseReferences(ctx, srv, args)
......
......@@ -36,15 +36,14 @@ func initUpdateIndexCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
Example: " " + os.Args[0] + " core update-index",
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
runUpdateIndexCommand(srv)
runUpdateIndexCommand(cmd.Context(), srv)
},
}
return updateIndexCommand
}
func runUpdateIndexCommand(srv rpc.ArduinoCoreServiceServer) {
func runUpdateIndexCommand(ctx context.Context, srv rpc.ArduinoCoreServiceServer) {
logrus.Info("Executing `arduino-cli core update-index`")
ctx := context.Background()
inst := instance.CreateAndInit(ctx, srv)
resp := UpdateIndex(ctx, srv, inst)
......
......@@ -43,16 +43,15 @@ func initUpgradeCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
" # " + tr("upgrade arduino:samd to the latest version") + "\n" +
" " + os.Args[0] + " core upgrade arduino:samd",
Run: func(cmd *cobra.Command, args []string) {
runUpgradeCommand(srv, args, postInstallFlags.DetectSkipPostInstallValue(), postInstallFlags.DetectSkipPreUninstallValue())
runUpgradeCommand(cmd.Context(), srv, args, postInstallFlags.DetectSkipPostInstallValue(), postInstallFlags.DetectSkipPreUninstallValue())
},
}
postInstallFlags.AddToCommand(upgradeCommand)
return upgradeCommand
}
func runUpgradeCommand(srv rpc.ArduinoCoreServiceServer, args []string, skipPostInstall bool, skipPreUninstall bool) {
func runUpgradeCommand(ctx context.Context, srv rpc.ArduinoCoreServiceServer, args []string, skipPostInstall bool, skipPreUninstall bool) {
logrus.Info("Executing `arduino-cli core upgrade`")
ctx := context.Background()
inst := instance.CreateAndInit(ctx, srv)
Upgrade(ctx, srv, inst, args, skipPostInstall, skipPreUninstall)
}
......
......@@ -56,7 +56,7 @@ func NewCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
Example: " " + os.Args[0] + " debug -b arduino:samd:mkr1000 -P atmel_ice /home/user/Arduino/MySketch",
Args: cobra.MaximumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
runDebugCommand(srv, args, &portArgs, &fqbnArg, interpreter, importDir, &programmer, printInfo, &profileArg)
runDebugCommand(cmd.Context(), srv, args, &portArgs, &fqbnArg, interpreter, importDir, &programmer, printInfo, &profileArg)
},
}
......@@ -72,10 +72,9 @@ func NewCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
return debugCommand
}
func runDebugCommand(srv rpc.ArduinoCoreServiceServer, args []string, portArgs *arguments.Port, fqbnArg *arguments.Fqbn,
func runDebugCommand(ctx context.Context, srv rpc.ArduinoCoreServiceServer, args []string, portArgs *arguments.Port, fqbnArg *arguments.Fqbn,
interpreter string, importDir string, programmer *arguments.Programmer, printInfo bool, profileArg *arguments.Profile) {
logrus.Info("Executing `arduino-cli debug`")
ctx := context.Background()
path := ""
if len(args) > 0 {
......@@ -103,11 +102,11 @@ func runDebugCommand(srv rpc.ArduinoCoreServiceServer, args []string, portArgs *
fqbnArg.Set(profile.GetFqbn())
}
fqbn, port := arguments.CalculateFQBNAndPort(portArgs, fqbnArg, inst, srv, sk.GetDefaultFqbn(), sk.GetDefaultPort(), sk.GetDefaultProtocol())
fqbn, port := arguments.CalculateFQBNAndPort(ctx, portArgs, fqbnArg, inst, srv, sk.GetDefaultFqbn(), sk.GetDefaultPort(), sk.GetDefaultProtocol())
prog := profile.GetProgrammer()
if prog == "" || programmer.GetProgrammer() != "" {
prog = programmer.String(inst, srv, fqbn)
prog = programmer.String(ctx, inst, srv, fqbn)
}
if prog == "" {
prog = sk.GetDefaultProgrammer()
......@@ -125,7 +124,7 @@ func runDebugCommand(srv rpc.ArduinoCoreServiceServer, args []string, portArgs *
if printInfo {
if res, err := commands.GetDebugConfig(context.Background(), debugConfigRequested); err != nil {
if res, err := commands.GetDebugConfig(ctx, debugConfigRequested); err != nil {
errcode := feedback.ErrBadArgument
if errors.Is(err, &cmderrors.MissingProgrammerError{}) {
errcode = feedback.ErrMissingProgrammer
......@@ -145,7 +144,7 @@ func runDebugCommand(srv rpc.ArduinoCoreServiceServer, args []string, portArgs *
if err != nil {
feedback.FatalError(err, feedback.ErrBadArgument)
}
if _, err := commands.Debug(context.Background(), debugConfigRequested, in, out, ctrlc); err != nil {
if _, err := commands.Debug(ctx, debugConfigRequested, in, out, ctrlc); err != nil {
errcode := feedback.ErrGeneric
if errors.Is(err, &cmderrors.MissingProgrammerError{}) {
errcode = feedback.ErrMissingProgrammer
......
......@@ -41,7 +41,7 @@ func newDebugCheckCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
Short: tr("Check if the given board/programmer combination supports debugging."),
Example: " " + os.Args[0] + " debug check -b arduino:samd:mkr1000 -P atmel_ice",
Run: func(cmd *cobra.Command, args []string) {
runDebugCheckCommand(srv, &portArgs, &fqbnArg, interpreter, &programmer)
runDebugCheckCommand(cmd.Context(), srv, &portArgs, &fqbnArg, interpreter, &programmer)
},
}
fqbnArg.AddToCommand(debugCheckCommand, srv)
......@@ -51,22 +51,21 @@ func newDebugCheckCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
return debugCheckCommand
}
func runDebugCheckCommand(srv rpc.ArduinoCoreServiceServer, portArgs *arguments.Port, fqbnArg *arguments.Fqbn, interpreter string, programmerArg *arguments.Programmer) {
ctx := context.Background()
func runDebugCheckCommand(ctx context.Context, srv rpc.ArduinoCoreServiceServer, portArgs *arguments.Port, fqbnArg *arguments.Fqbn, interpreter string, programmerArg *arguments.Programmer) {
instance := instance.CreateAndInit(ctx, srv)
logrus.Info("Executing `arduino-cli debug`")
port, err := portArgs.GetPort(instance, srv, "", "")
port, err := portArgs.GetPort(ctx, instance, srv, "", "")
if err != nil {
feedback.FatalError(err, feedback.ErrBadArgument)
}
fqbn := fqbnArg.String()
resp, err := commands.IsDebugSupported(context.Background(), &rpc.IsDebugSupportedRequest{
resp, err := commands.IsDebugSupported(ctx, &rpc.IsDebugSupportedRequest{
Instance: instance,
Fqbn: fqbn,
Port: port,
Interpreter: interpreter,
Programmer: programmerArg.String(instance, srv, fqbn),
Programmer: programmerArg.String(ctx, instance, srv, fqbn),
})
if err != nil {
feedback.FatalError(err, feedback.ErrGeneric)
......
......@@ -42,18 +42,17 @@ func initDepsCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
" " + os.Args[0] + " lib deps AudioZero@1.0.0 # " + tr("for the specific version."),
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
runDepsCommand(srv, args, noOverwrite)
runDepsCommand(cmd.Context(), srv, args, noOverwrite)
},
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return arguments.GetInstalledLibraries(context.Background(), srv), cobra.ShellCompDirectiveDefault
return arguments.GetInstalledLibraries(cmd.Context(), srv), cobra.ShellCompDirectiveDefault
},
}
depsCommand.Flags().BoolVar(&noOverwrite, "no-overwrite", false, tr("Do not try to update library dependencies if already installed."))
return depsCommand
}
func runDepsCommand(srv rpc.ArduinoCoreServiceServer, args []string, noOverwrite bool) {
ctx := context.Background()
func runDepsCommand(ctx context.Context, srv rpc.ArduinoCoreServiceServer, args []string, noOverwrite bool) {
instance := instance.CreateAndInit(ctx, srv)
logrus.Info("Executing `arduino-cli lib deps`")
......
......@@ -39,18 +39,17 @@ func initDownloadCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
" " + os.Args[0] + " lib download AudioZero@1.0.0 # " + tr("for a specific version."),
Args: cobra.MinimumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
runDownloadCommand(srv, args)
runDownloadCommand(cmd.Context(), srv, args)
},
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return arguments.GetInstallableLibs(context.Background(), srv), cobra.ShellCompDirectiveDefault
return arguments.GetInstallableLibs(cmd.Context(), srv), cobra.ShellCompDirectiveDefault
},
}
return downloadCommand
}
func runDownloadCommand(srv rpc.ArduinoCoreServiceServer, args []string) {
func runDownloadCommand(ctx context.Context, srv rpc.ArduinoCoreServiceServer, args []string) {
logrus.Info("Executing `arduino-cli lib download`")
ctx := context.Background()
instance := instance.CreateAndInit(ctx, srv)
refs, err := ParseLibraryReferenceArgsAndAdjustCase(ctx, srv, instance, args)
......
......@@ -45,19 +45,18 @@ func initExamplesCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
Example: " " + os.Args[0] + " lib examples Wire",
Args: cobra.MaximumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
runExamplesCommand(srv, args)
runExamplesCommand(cmd.Context(), srv, args)
},
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return arguments.GetInstalledLibraries(context.Background(), srv), cobra.ShellCompDirectiveDefault
return arguments.GetInstalledLibraries(cmd.Context(), srv), cobra.ShellCompDirectiveDefault
},
}
fqbn.AddToCommand(examplesCommand, srv)
return examplesCommand
}
func runExamplesCommand(srv rpc.ArduinoCoreServiceServer, args []string) {
func runExamplesCommand(ctx context.Context, srv rpc.ArduinoCoreServiceServer, args []string) {
logrus.Info("Executing `arduino-cli lib examples`")
ctx := context.Background()
instance := instance.CreateAndInit(ctx, srv)
name := ""
......
......@@ -52,10 +52,10 @@ func initInstallCommand(srv rpc.ArduinoCoreServiceServer, settings *rpc.Configur
" " + os.Args[0] + " lib install --zip-path /path/to/WiFi101.zip /path/to/ArduinoBLE.zip\n",
Args: cobra.MinimumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
runInstallCommand(srv, args, noDeps, noOverwrite, gitURL, zipPath, useBuiltinLibrariesDir, enableUnsafeInstall)
runInstallCommand(cmd.Context(), srv, args, noDeps, noOverwrite, gitURL, zipPath, useBuiltinLibrariesDir, enableUnsafeInstall)
},
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return arguments.GetInstallableLibs(context.Background(), srv), cobra.ShellCompDirectiveDefault
return arguments.GetInstallableLibs(cmd.Context(), srv), cobra.ShellCompDirectiveDefault
},
}
installCommand.Flags().BoolVar(&noDeps, "no-deps", false, tr("Do not install dependencies."))
......@@ -66,8 +66,7 @@ func initInstallCommand(srv rpc.ArduinoCoreServiceServer, settings *rpc.Configur
return installCommand
}
func runInstallCommand(srv rpc.ArduinoCoreServiceServer, args []string, noDeps bool, noOverwrite bool, gitURL bool, zipPath bool, useBuiltinLibrariesDir bool, enableUnsafeInstall bool) {
ctx := context.Background()
func runInstallCommand(ctx context.Context, srv rpc.ArduinoCoreServiceServer, args []string, noDeps bool, noOverwrite bool, gitURL bool, zipPath bool, useBuiltinLibrariesDir bool, enableUnsafeInstall bool) {
instance := instance.CreateAndInit(ctx, srv)
logrus.Info("Executing `arduino-cli lib install`")
......
......@@ -45,7 +45,7 @@ not listed, they can be listed by adding the --all flag.`),
Example: " " + os.Args[0] + " lib list",
Args: cobra.MaximumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
ctx := context.Background()
ctx := cmd.Context()
instance := instance.CreateAndInit(ctx, srv)
logrus.Info("Executing `arduino-cli lib list`")
List(ctx, srv, instance, args, all, updatable)
......
......@@ -90,7 +90,7 @@ In addition to the fields listed above, QV terms can use these qualifiers:
" " + os.Args[0] + " lib search dependencies=IRremote # " + tr("libraries that depend only on \"IRremote\"") + "\n",
Args: cobra.ArbitraryArgs,
Run: func(cmd *cobra.Command, args []string) {
runSearchCommand(srv, args, namesOnly, omitReleasesDetails)
runSearchCommand(cmd.Context(), srv, args, namesOnly, omitReleasesDetails)
},
}
searchCommand.Flags().BoolVar(&namesOnly, "names", false, tr("Show library names only."))
......@@ -101,8 +101,7 @@ In addition to the fields listed above, QV terms can use these qualifiers:
// indexUpdateInterval specifies the time threshold over which indexes are updated
const indexUpdateInterval = 60 * time.Minute
func runSearchCommand(srv rpc.ArduinoCoreServiceServer, args []string, namesOnly bool, omitReleasesDetails bool) {
ctx := context.Background()
func runSearchCommand(ctx context.Context, srv rpc.ArduinoCoreServiceServer, args []string, namesOnly bool, omitReleasesDetails bool) {
inst := instance.CreateAndInit(ctx, srv)
logrus.Info("Executing `arduino-cli lib search`")
......
......@@ -37,18 +37,17 @@ func initUninstallCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
Example: " " + os.Args[0] + " lib uninstall AudioZero",
Args: cobra.MinimumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
runUninstallCommand(srv, args)
runUninstallCommand(cmd.Context(), srv, args)
},
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return arguments.GetUninstallableLibraries(context.Background(), srv), cobra.ShellCompDirectiveDefault
return arguments.GetUninstallableLibraries(cmd.Context(), srv), cobra.ShellCompDirectiveDefault
},
}
return uninstallCommand
}
func runUninstallCommand(srv rpc.ArduinoCoreServiceServer, args []string) {
func runUninstallCommand(ctx context.Context, srv rpc.ArduinoCoreServiceServer, args []string) {
logrus.Info("Executing `arduino-cli lib uninstall`")
ctx := context.Background()
instance := instance.CreateAndInit(ctx, srv)
refs, err := ParseLibraryReferenceArgsAndAdjustCase(ctx, srv, instance, args)
......
......@@ -36,14 +36,13 @@ func initUpdateIndexCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
Example: " " + os.Args[0] + " lib update-index",
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
runUpdateIndexCommand(srv)
runUpdateIndexCommand(cmd.Context(), srv)
},
}
return updateIndexCommand
}
func runUpdateIndexCommand(srv rpc.ArduinoCoreServiceServer) {
ctx := context.Background()
func runUpdateIndexCommand(ctx context.Context, srv rpc.ArduinoCoreServiceServer) {
inst := instance.CreateAndInit(ctx, srv)
logrus.Info("Executing `arduino-cli lib update-index`")
......
......@@ -38,15 +38,14 @@ func initUpgradeCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
" " + os.Args[0] + " lib upgrade Audio ArduinoJson",
Args: cobra.ArbitraryArgs,
Run: func(cmd *cobra.Command, args []string) {
runUpgradeCommand(srv, args)
runUpgradeCommand(cmd.Context(), srv, args)
},
}
return upgradeCommand
}
func runUpgradeCommand(srv rpc.ArduinoCoreServiceServer, args []string) {
func runUpgradeCommand(ctx context.Context, srv rpc.ArduinoCoreServiceServer, args []string) {
logrus.Info("Executing `arduino-cli lib upgrade`")
ctx := context.Background()
instance := instance.CreateAndInit(ctx, srv)
Upgrade(ctx, srv, instance, args)
}
......
......@@ -66,7 +66,7 @@ func NewCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
if len(args) > 0 {
sketchPath = args[0]
}
runMonitorCmd(srv, &portArgs, &fqbnArg, &profileArg, sketchPath, configs, describe, timestamp, quiet, raw)
runMonitorCmd(cmd.Context(), srv, &portArgs, &fqbnArg, &profileArg, sketchPath, configs, describe, timestamp, quiet, raw)
},
}
portArgs.AddToCommand(monitorCommand, srv)
......@@ -81,12 +81,11 @@ func NewCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
}
func runMonitorCmd(
srv rpc.ArduinoCoreServiceServer,
ctx context.Context, srv rpc.ArduinoCoreServiceServer,
portArgs *arguments.Port, fqbnArg *arguments.Fqbn, profileArg *arguments.Profile, sketchPathArg string,
configs []string, describe, timestamp, quiet, raw bool,
) {
logrus.Info("Executing `arduino-cli monitor`")
ctx := context.Background()
if !feedback.HasConsole() {
quiet = true
......@@ -139,10 +138,10 @@ func runMonitorCmd(
case sketch.GetDefaultFqbn() != "":
fqbn = sketch.GetDefaultFqbn()
default:
fqbn, _ = portArgs.DetectFQBN(inst, srv)
fqbn, _ = portArgs.DetectFQBN(ctx, inst, srv)
}
portAddress, portProtocol, err := portArgs.GetPortAddressAndProtocol(inst, srv, defaultPort, defaultProtocol)
portAddress, portProtocol, err := portArgs.GetPortAddressAndProtocol(ctx, inst, srv, defaultPort, defaultProtocol)
if err != nil {
feedback.FatalError(err, feedback.ErrGeneric)
}
......
......@@ -46,15 +46,14 @@ that can be upgraded. If nothing needs to be updated the output is empty.`),
Example: " " + os.Args[0] + " outdated\n",
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
runOutdatedCommand(srv)
runOutdatedCommand(cmd.Context(), srv)
},
}
return outdatedCommand
}
func runOutdatedCommand(srv rpc.ArduinoCoreServiceServer) {
func runOutdatedCommand(ctx context.Context, srv rpc.ArduinoCoreServiceServer) {
logrus.Info("Executing `arduino-cli outdated`")
ctx := context.Background()
inst := instance.CreateAndInit(ctx, srv)
Outdated(ctx, srv, inst)
}
......
......@@ -43,7 +43,7 @@ func initArchiveCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
" " + os.Args[0] + " archive /home/user/Arduino/MySketch /home/user/MySketchArchive.zip",
Args: cobra.MaximumNArgs(2),
Run: func(cmd *cobra.Command, args []string) {
runArchiveCommand(srv, args, includeBuildDir, overwrite)
runArchiveCommand(cmd.Context(), srv, args, includeBuildDir, overwrite)
},
}
......@@ -53,9 +53,8 @@ func initArchiveCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
return archiveCommand
}
func runArchiveCommand(srv rpc.ArduinoCoreServiceServer, args []string, includeBuildDir bool, overwrite bool) {
func runArchiveCommand(ctx context.Context, srv rpc.ArduinoCoreServiceServer, args []string, includeBuildDir bool, overwrite bool) {
logrus.Info("Executing `arduino-cli sketch archive`")
ctx := context.Background()
sketchPathArg := ""
if len(args) > 0 {
sketchPathArg = args[0]
......
......@@ -38,7 +38,7 @@ func initNewCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
Example: " " + os.Args[0] + " sketch new MultiBlinker",
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
runNewCommand(srv, args, overwrite)
runNewCommand(cmd.Context(), srv, args, overwrite)
},
}
......@@ -47,8 +47,7 @@ func initNewCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
return newCommand
}
func runNewCommand(srv rpc.ArduinoCoreServiceServer, args []string, overwrite bool) {
ctx := context.Background()
func runNewCommand(ctx context.Context, srv rpc.ArduinoCoreServiceServer, args []string, overwrite bool) {
logrus.Info("Executing `arduino-cli sketch new`")
// Trim to avoid issues if user creates a sketch adding the .ino extesion to the name
inputSketchName := args[0]
......
......@@ -41,16 +41,15 @@ func NewCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
Example: " " + os.Args[0] + " update",
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
runUpdateCommand(srv, showOutdated)
runUpdateCommand(cmd.Context(), srv, showOutdated)
},
}
updateCommand.Flags().BoolVar(&showOutdated, "show-outdated", false, tr("Show outdated cores and libraries after index update"))
return updateCommand
}
func runUpdateCommand(srv rpc.ArduinoCoreServiceServer, showOutdated bool) {
func runUpdateCommand(ctx context.Context, srv rpc.ArduinoCoreServiceServer, showOutdated bool) {
logrus.Info("Executing `arduino-cli update`")
ctx := context.Background()
inst := instance.CreateAndInit(ctx, srv)
lib.UpdateIndex(ctx, srv, inst)
......
......@@ -41,15 +41,14 @@ func NewCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
Example: " " + os.Args[0] + " upgrade",
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
runUpgradeCommand(srv, postInstallFlags.DetectSkipPostInstallValue(), postInstallFlags.DetectSkipPreUninstallValue())
runUpgradeCommand(cmd.Context(), srv, postInstallFlags.DetectSkipPostInstallValue(), postInstallFlags.DetectSkipPreUninstallValue())
},
}
postInstallFlags.AddToCommand(upgradeCommand)
return upgradeCommand
}
func runUpgradeCommand(srv rpc.ArduinoCoreServiceServer, skipPostInstall bool, skipPreUninstall bool) {
ctx := context.Background()
func runUpgradeCommand(ctx context.Context, srv rpc.ArduinoCoreServiceServer, skipPostInstall bool, skipPreUninstall bool) {
inst := instance.CreateAndInit(ctx, srv)
logrus.Info("Executing `arduino-cli upgrade`")
lib.Upgrade(ctx, srv, inst, []string{})
......
......@@ -63,7 +63,7 @@ func NewCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
arguments.CheckFlagsConflicts(cmd, "input-file", "input-dir")
},
Run: func(cmd *cobra.Command, args []string) {
runUploadCommand(srv, args, uploadFields)
runUploadCommand(cmd.Context(), srv, args, uploadFields)
},
}
......@@ -81,11 +81,9 @@ func NewCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
return uploadCommand
}
func runUploadCommand(srv rpc.ArduinoCoreServiceServer, args []string, uploadFieldsArgs map[string]string) {
func runUploadCommand(ctx context.Context, srv rpc.ArduinoCoreServiceServer, args []string, uploadFieldsArgs map[string]string) {
logrus.Info("Executing `arduino-cli upload`")
ctx := context.Background()
path := ""
if len(args) > 0 {
path = args[0]
......@@ -116,7 +114,7 @@ func runUploadCommand(srv rpc.ArduinoCoreServiceServer, args []string, uploadFie
defaultFQBN := sketch.GetDefaultFqbn()
defaultAddress := sketch.GetDefaultPort()
defaultProtocol := sketch.GetDefaultProtocol()
fqbn, port := arguments.CalculateFQBNAndPort(&portArgs, &fqbnArg, inst, srv, defaultFQBN, defaultAddress, defaultProtocol)
fqbn, port := arguments.CalculateFQBNAndPort(ctx, &portArgs, &fqbnArg, inst, srv, defaultFQBN, defaultAddress, defaultProtocol)
userFieldRes, err := srv.SupportedUserFields(ctx, &rpc.SupportedUserFieldsRequest{
Instance: inst,
......@@ -179,7 +177,7 @@ func runUploadCommand(srv rpc.ArduinoCoreServiceServer, args []string, uploadFie
prog := profile.GetProgrammer()
if prog == "" || programmer.GetProgrammer() != "" {
prog = programmer.String(inst, srv, fqbn)
prog = programmer.String(ctx, inst, srv, fqbn)
}
if prog == "" {
prog = sketch.GetDefaultProgrammer()
......
......@@ -40,13 +40,13 @@ func NewCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
Example: " " + os.Args[0] + " version",
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
runVersionCommand(srv)
runVersionCommand(cmd.Context(), srv)
},
}
return versionCommand
}
func runVersionCommand(srv rpc.ArduinoCoreServiceServer) {
func runVersionCommand(ctx context.Context, srv rpc.ArduinoCoreServiceServer) {
logrus.Info("Executing `arduino-cli version`")
info := version.VersionInfo
......@@ -58,7 +58,7 @@ func runVersionCommand(srv rpc.ArduinoCoreServiceServer) {
}
latestVersion := ""
res, err := srv.CheckForArduinoCLIUpdates(context.Background(), &rpc.CheckForArduinoCLIUpdatesRequest{})
res, err := srv.CheckForArduinoCLIUpdates(ctx, &rpc.CheckForArduinoCLIUpdatesRequest{})
if err != nil {
feedback.Warning("Failed to check for updates: " + err.Error())
} else {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment