Skip to content

Commit c8b77e8

Browse files
author
Massimiliano Pippi
authored
Merge branch 'master' into massi/output-reprise
2 parents 7e6f0c5 + 63da3d8 commit c8b77e8

38 files changed

+184
-136
lines changed

.github/workflows/test.yaml

-5
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,6 @@ jobs:
5858
architecture: 'x64'
5959

6060
- name: Run integration tests
61-
# Since we are investigating issues emerged
62-
# with python integration tests on windows
63-
# this step is disabled for windows-2019
64-
# platform ATM
65-
if: matrix.operating-system != 'windows-2019'
6661
run: |
6762
pip install -r test/requirements.txt
6863
task test-integration

README.md

+19
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ build the source code, run the tests, and contribute your changes to the project
2020

2121
### Get the latest package
2222

23+
#### Using the install script
24+
2325
The easiest way to get the latest version of `arduino-cli` on any supported platform is using the
2426
`install.sh` script:
2527

@@ -34,9 +36,26 @@ for example `~/local/bin`, set the `BINDIR` environment variable like this:
3436
curl -fsSL https://raw.githubusercontent.com/arduino/arduino-cli/master/install.sh | BINDIR=~/local/bin sh
3537
```
3638

39+
#### Using the latest release links
40+
41+
In order to get the latest stable release for your platform use the following links:
42+
43+
- [Linux 64 bit](https://downloads.arduino.cc/arduino-cli/arduino-cli_latest_Linux_64bit.tar.gz)
44+
- [Linux 32 bit](https://downloads.arduino.cc/arduino-cli/arduino-cli_latest_Linux_32bit.tar.gz)
45+
- [Linux ARM 64 bit](https://downloads.arduino.cc/arduino-cli/arduino-cli_latest_Linux_ARM64.tar.gz)
46+
- [Linux ARM 32 bit](https://downloads.arduino.cc/arduino-cli/arduino-cli_latest_Linux_ARMv7.tar.gz)
47+
- [Windows 64 bit](https://downloads.arduino.cc/arduino-cli/arduino-cli_latest_Windows_64bit.zip)
48+
- [Windows 32 bit](https://downloads.arduino.cc/arduino-cli/arduino-cli_latest_Windows_32bit.zip)
49+
- [Mac OSX](https://downloads.arduino.cc/arduino-cli/arduino-cli_latest_macOS_64bit.tar.gz)
50+
51+
These links return a `302: Found` response, redirecting to latest generated builds by replacing `latest` with the latest
52+
available stable release. Once downloaded, place the executable `arduino-cli` into a directory which is in your `PATH`.
53+
3754
**Deprecation notice:** Links in the form `http://downloads.arduino.cc/arduino-cli/arduino-cli-latest-<platform>.tar.bz2`
3855
won't be further updated. That URL will provide arduino-cli 0.3.7-alpha.preview, regardless of further releases.
3956

57+
#### Using the Github release page
58+
4059
Alternatively you can download one of the pre-built binaries for the supported platforms from the
4160
[release page](https://github.com/arduino/arduino-cli/releases). Once downloaded, place the executable
4261
`arduino-cli` into a directory which is in your `PATH`.

Taskfile.yml

+1-3
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,10 @@ vars:
6363
sh: echo `go list ./... | grep -v legacy | tr '\n' ' '`
6464

6565
# build vars
66-
VERSIONSTRING: "0.3.7-alpha.preview"
6766
COMMIT:
6867
sh: echo ${TRAVIS_COMMIT:-`git log -n 1 --format=%h`}
6968
LDFLAGS: >
70-
-ldflags '-X github.com/arduino/arduino-cli/version.versionString={{.VERSIONSTRING}}
71-
-X github.com/arduino/arduino-cli/version.commit={{.COMMIT}}'
69+
-ldflags '-X github.com/arduino/arduino-cli/version.commit={{.COMMIT}}'
7270
7371
# test vars
7472
GOFLAGS: "-timeout 10m -v -coverpkg=./... -covermode=atomic"

arduino/builder/builder.go

+10-6
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,22 @@ import (
1919
"crypto/md5"
2020
"encoding/hex"
2121
"os"
22-
"path/filepath"
2322
"strings"
2423

24+
"github.com/arduino/go-paths-helper"
2525
"github.com/pkg/errors"
2626
)
2727

28-
// GenBuildPath generates a suitable name for the build folder
29-
func GenBuildPath(sketchPath string) string {
30-
md5SumBytes := md5.Sum([]byte(sketchPath))
28+
// GenBuildPath generates a suitable name for the build folder.
29+
// The sketchPath, if not nil, is also used to furhter differentiate build paths.
30+
func GenBuildPath(sketchPath *paths.Path) *paths.Path {
31+
path := ""
32+
if sketchPath != nil {
33+
path = sketchPath.String()
34+
}
35+
md5SumBytes := md5.Sum([]byte(path))
3136
md5Sum := strings.ToUpper(hex.EncodeToString(md5SumBytes[:]))
32-
33-
return filepath.Join(os.TempDir(), "arduino-sketch-"+md5Sum)
37+
return paths.TempDir().Join("arduino-sketch-" + md5Sum)
3438
}
3539

3640
// EnsureBuildPathExists creates the build path if doesn't already exists.

arduino/builder/builder_test.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"testing"
2424

2525
"github.com/arduino/arduino-cli/arduino/builder"
26+
"github.com/arduino/go-paths-helper"
2627
"github.com/stretchr/testify/assert"
2728
)
2829

@@ -36,7 +37,10 @@ func tmpDirOrDie() string {
3637

3738
func TestGenBuildPath(t *testing.T) {
3839
want := filepath.Join(os.TempDir(), "arduino-sketch-ACBD18DB4CC2F85CEDEF654FCCC4A4D8")
39-
assert.Equal(t, want, builder.GenBuildPath("foo"))
40+
assert.Equal(t, want, builder.GenBuildPath(paths.New("foo")).String())
41+
42+
want = filepath.Join(os.TempDir(), "arduino-sketch-D41D8CD98F00B204E9800998ECF8427E")
43+
assert.Equal(t, want, builder.GenBuildPath(nil).String())
4044
}
4145

4246
func TestEnsureBuildPathExists(t *testing.T) {

cli/board/attach.go

+25-4
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ import (
2727
"github.com/arduino/arduino-cli/cli/output"
2828
"github.com/arduino/arduino-cli/commands/board"
2929
rpc "github.com/arduino/arduino-cli/rpc/commands"
30+
"github.com/arduino/go-paths-helper"
31+
"github.com/sirupsen/logrus"
3032
"github.com/spf13/cobra"
3133
)
3234

@@ -52,18 +54,37 @@ var attachFlags struct {
5254

5355
func runAttachCommand(cmd *cobra.Command, args []string) {
5456
instance := instance.CreateInstance()
55-
var path string
56-
if len(args) > 0 {
57-
path = args[1]
57+
58+
var path *paths.Path
59+
if len(args) > 1 {
60+
path = paths.New(args[1])
61+
} else {
62+
path = initSketchPath(path)
5863
}
64+
5965
_, err := board.Attach(context.Background(), &rpc.BoardAttachReq{
6066
Instance: instance,
6167
BoardUri: args[0],
62-
SketchPath: path,
68+
SketchPath: path.String(),
6369
SearchTimeout: attachFlags.searchTimeout,
6470
}, output.TaskProgress())
6571
if err != nil {
6672
feedback.Errorf("Attach board error: %v", err)
6773
os.Exit(errorcodes.ErrGeneric)
6874
}
6975
}
76+
77+
// initSketchPath returns the current working directory
78+
func initSketchPath(sketchPath *paths.Path) *paths.Path {
79+
if sketchPath != nil {
80+
return sketchPath
81+
}
82+
83+
wd, err := paths.Getwd()
84+
if err != nil {
85+
feedback.Errorf("Couldn't get current working directory: %v", err)
86+
os.Exit(errorcodes.ErrGeneric)
87+
}
88+
logrus.Infof("Reading sketch from dir: %s", wd)
89+
return wd
90+
}

cli/cli.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ func createCliCommandTree(cmd *cobra.Command) {
8282
cmd.AddCommand(version.NewCommand())
8383

8484
cmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "Print the logs on the standard output.")
85-
cmd.PersistentFlags().StringVar(&globals.LogLevel, "log-level", defaultLogLevel, "Messages with this level and above will be logged (default: warn).")
85+
cmd.PersistentFlags().StringVar(&globals.LogLevel, "log-level", defaultLogLevel, "Messages with this level and above will be logged.")
8686
cmd.PersistentFlags().StringVar(&logFile, "log-file", "", "Path to the file where logs will be written.")
8787
cmd.PersistentFlags().StringVar(&logFormat, "log-format", "text", "The output format for the logs, can be [text|json].")
8888
cmd.PersistentFlags().StringVar(&outputFormat, "format", "text", "The output format, can be [text|json].")

cli/core/download.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func runDownloadCommand(cmd *cobra.Command, args []string) {
6464
Version: platformRef.Version,
6565
}
6666
_, err := core.PlatformDownload(context.Background(), platformDownloadreq, output.ProgressBar(),
67-
globals.HTTPClientHeader)
67+
globals.NewHTTPClientHeader())
6868
if err != nil {
6969
feedback.Errorf("Error downloading %s: %v", args[i], err)
7070
os.Exit(errorcodes.ErrNetwork)

cli/core/install.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func runInstallCommand(cmd *cobra.Command, args []string) {
6565
Version: platformRef.Version,
6666
}
6767
_, err := core.PlatformInstall(context.Background(), plattformInstallReq, output.ProgressBar(),
68-
output.TaskProgress(), globals.HTTPClientHeader)
68+
output.TaskProgress(), globals.NewHTTPClientHeader())
6969
if err != nil {
7070
feedback.Errorf("Error during install: %v", err)
7171
os.Exit(errorcodes.ErrGeneric)

cli/core/upgrade.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ func runUpgradeCommand(cmd *cobra.Command, args []string) {
9090
Architecture: platformRef.Architecture,
9191
}
9292

93-
_, err := core.PlatformUpgrade(context.Background(), r, output.ProgressBar(), output.TaskProgress(), globals.HTTPClientHeader)
93+
_, err := core.PlatformUpgrade(context.Background(), r, output.ProgressBar(), output.TaskProgress(), globals.NewHTTPClientHeader())
9494
if err == core.ErrAlreadyLatest {
9595
feedback.Printf("Platform %s is already at the latest version", platformRef)
9696
} else if err != nil {

cli/daemon/daemon.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ const (
4141
func NewCommand() *cobra.Command {
4242
return &cobra.Command{
4343
Use: "daemon",
44-
Short: "Run as a daemon",
44+
Short: fmt.Sprintf("Run as a daemon on port %s", port),
4545
Long: "Running as a daemon the initialization of cores and libraries is done only once.",
4646
Example: " " + os.Args[0] + " daemon",
4747
Args: cobra.NoArgs,

cli/globals/globals.go

+3-5
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ import (
2929
var (
3030
// Debug determines whether to dump debug output to stderr or not
3131
Debug bool
32-
// HTTPClientHeader is the object that will be propagated to configure the clients inside the downloaders
33-
HTTPClientHeader = getHTTPClientHeader()
3432
// VersionInfo contains all info injected during build
3533
VersionInfo = version.NewInfo(filepath.Base(os.Args[0]))
3634
// Config FIXMEDOC
@@ -44,9 +42,9 @@ var (
4442
LogLevel string
4543
)
4644

47-
func getHTTPClientHeader() http.Header {
45+
// NewHTTPClientHeader returns the http.Header object that must be used by the clients inside the downloaders
46+
func NewHTTPClientHeader() http.Header {
4847
userAgentValue := fmt.Sprintf("%s/%s (%s; %s; %s) Commit:%s", VersionInfo.Application,
4948
VersionInfo.VersionString, runtime.GOARCH, runtime.GOOS, runtime.Version(), VersionInfo.Commit)
50-
downloaderHeaders := http.Header{"User-Agent": []string{userAgentValue}}
51-
return downloaderHeaders
49+
return http.Header{"User-Agent": []string{userAgentValue}}
5250
}

cli/instance/instance.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func initInstance() *rpc.InitResp {
3636
logrus.Info("Initializing package manager")
3737
req := packageManagerInitReq()
3838

39-
resp, err := commands.Init(context.Background(), req, output.ProgressBar(), output.TaskProgress(), globals.HTTPClientHeader)
39+
resp, err := commands.Init(context.Background(), req, output.ProgressBar(), output.TaskProgress(), globals.NewHTTPClientHeader())
4040
if err != nil {
4141
feedback.Errorf("Error initializing package manager: %v", err)
4242
os.Exit(errorcodes.ErrGeneric)

cli/lib/download.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func runDownloadCommand(cmd *cobra.Command, args []string) {
6060
Version: library.Version,
6161
}
6262
_, err := lib.LibraryDownload(context.Background(), libraryDownloadReq, output.ProgressBar(),
63-
globals.HTTPClientHeader)
63+
globals.NewHTTPClientHeader())
6464
if err != nil {
6565
feedback.Errorf("Error downloading %s: %v", library, err)
6666
os.Exit(errorcodes.ErrNetwork)

cli/lib/install.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func runInstallCommand(cmd *cobra.Command, args []string) {
6060
Version: library.Version,
6161
}
6262
err := lib.LibraryInstall(context.Background(), libraryInstallReq, output.ProgressBar(),
63-
output.TaskProgress(), globals.HTTPClientHeader)
63+
output.TaskProgress(), globals.NewHTTPClientHeader())
6464
if err != nil {
6565
feedback.Errorf("Error installing %s: %v", library, err)
6666
os.Exit(errorcodes.ErrGeneric)

cli/lib/upgrade.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,13 @@ func runUpgradeCommand(cmd *cobra.Command, args []string) {
5050
instance := instance.CreateInstaceIgnorePlatformIndexErrors()
5151

5252
if len(args) == 0 {
53-
err := lib.LibraryUpgradeAll(instance.Id, output.ProgressBar(), output.TaskProgress(), globals.HTTPClientHeader)
53+
err := lib.LibraryUpgradeAll(instance.Id, output.ProgressBar(), output.TaskProgress(), globals.NewHTTPClientHeader())
5454
if err != nil {
5555
feedback.Errorf("Error upgrading libraries: %v", err)
5656
os.Exit(errorcodes.ErrGeneric)
5757
}
5858
} else {
59-
err := lib.LibraryUpgrade(instance.Id, args, output.ProgressBar(), output.TaskProgress(), globals.HTTPClientHeader)
59+
err := lib.LibraryUpgrade(instance.Id, args, output.ProgressBar(), output.TaskProgress(), globals.NewHTTPClientHeader())
6060
if err != nil {
6161
feedback.Errorf("Error upgrading libraries: %v", err)
6262
os.Exit(errorcodes.ErrGeneric)

client_example/go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/arduino/arduino-cli/client_example
22

3-
go 1.12
3+
go 1.13
44

55
require (
66
github.com/arduino/arduino-cli v0.0.0-20190826141027-35722fda467d

client_example/main.go

+9-4
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,9 @@ func initInstance(client rpc.ArduinoCoreClient) *rpc.Instance {
167167
// the data folder.
168168
initRespStream, err := client.Init(context.Background(), &rpc.InitReq{
169169
Configuration: &rpc.Configuration{
170-
DataDir: dataDir,
170+
DataDir: dataDir,
171+
SketchbookDir: filepath.Join(dataDir, "sketchbook"),
172+
DownloadsDir: filepath.Join(dataDir, "staging"),
171173
},
172174
})
173175
if err != nil {
@@ -368,11 +370,12 @@ func callBoardsDetails(client rpc.ArduinoCoreClient, instance *rpc.Instance) {
368370
}
369371

370372
func callBoardAttach(client rpc.ArduinoCoreClient, instance *rpc.Instance) {
373+
currDir, _ := os.Getwd()
371374
boardattachresp, err := client.BoardAttach(context.Background(),
372375
&rpc.BoardAttachReq{
373376
Instance: instance,
374377
BoardUri: "/dev/ttyACM0",
375-
SketchPath: filepath.Join(dataDir, "hello.ino"),
378+
SketchPath: filepath.Join(currDir, "hello.ino"),
376379
})
377380

378381
if err != nil {
@@ -402,11 +405,12 @@ func callBoardAttach(client rpc.ArduinoCoreClient, instance *rpc.Instance) {
402405
}
403406

404407
func callCompile(client rpc.ArduinoCoreClient, instance *rpc.Instance) {
408+
currDir, _ := os.Getwd()
405409
compRespStream, err := client.Compile(context.Background(),
406410
&rpc.CompileReq{
407411
Instance: instance,
408412
Fqbn: "arduino:samd:mkr1000",
409-
SketchPath: "hello.ino",
413+
SketchPath: filepath.Join(currDir, "hello.ino"),
410414
Verbose: true,
411415
})
412416

@@ -440,11 +444,12 @@ func callCompile(client rpc.ArduinoCoreClient, instance *rpc.Instance) {
440444
}
441445

442446
func callUpload(client rpc.ArduinoCoreClient, instance *rpc.Instance) {
447+
currDir, _ := os.Getwd()
443448
uplRespStream, err := client.Upload(context.Background(),
444449
&rpc.UploadReq{
445450
Instance: instance,
446451
Fqbn: "arduino:samd:mkr1000",
447-
SketchPath: "hello.ino",
452+
SketchPath: filepath.Join(currDir, "hello.ino"),
448453
Port: "/dev/ttyACM0",
449454
Verbose: true,
450455
})

commands/board/list.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ var (
4040
func apiByVidPid(url string) ([]*rpc.BoardListItem, error) {
4141
retVal := []*rpc.BoardListItem{}
4242
req, _ := http.NewRequest("GET", url, nil)
43-
req.Header = globals.HTTPClientHeader
43+
req.Header = globals.NewHTTPClientHeader()
4444
req.Header.Set("Content-Type", "application/json")
4545

4646
if res, err := http.DefaultClient.Do(req); err == nil {
@@ -115,14 +115,16 @@ func List(instanceID int32) ([]*rpc.DetectedPort, error) {
115115
port.IdentificationPrefs.Get("pid"))
116116
items, err := apiByVidPid(url)
117117
if err == ErrNotFound {
118-
// the board couldn't be detected, keep going with the next port
118+
// the board couldn't be detected, print a warning
119119
logrus.Debug("Board not recognized")
120-
continue
121120
} else if err != nil {
122121
// this is bad, bail out
123122
return nil, errors.Wrap(err, "error getting board info from Arduino Cloud")
124123
}
125124

125+
// add a DetectedPort entry in any case: the `Boards` field will
126+
// be empty but the port will be shown anyways (useful for 3rd party
127+
// boards)
126128
b = items
127129
}
128130

commands/compile/compile.go

+7-5
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func Compile(ctx context.Context, req *rpc.CompileReq, outStream, errStream io.W
9595
}
9696

9797
if toolsDir, err := config.BundleToolsDirectories(); err == nil {
98-
builderCtx.ToolsDirs = toolsDir
98+
builderCtx.BuiltInToolsDirs = toolsDir
9999
} else {
100100
return nil, fmt.Errorf("cannot get bundled tools directories: %s", err)
101101
}
@@ -209,10 +209,12 @@ func Compile(ctx context.Context, req *rpc.CompileReq, outStream, errStream io.W
209209

210210
// Copy .elf file to sketch directory
211211
srcElf := paths.New(outputPath[:len(outputPath)-3] + "elf")
212-
dstElf := exportPath.Join(exportFile + ".elf")
213-
logrus.WithField("from", srcElf).WithField("to", dstElf).Debug("copying sketch build output")
214-
if err = srcElf.CopyTo(dstElf); err != nil {
215-
return nil, fmt.Errorf("copying elf file: %s", err)
212+
if srcElf.Exist() {
213+
dstElf := exportPath.Join(exportFile + ".elf")
214+
logrus.WithField("from", srcElf).WithField("to", dstElf).Debug("copying sketch build output")
215+
if err = srcElf.CopyTo(dstElf); err != nil {
216+
return nil, fmt.Errorf("copying elf file: %s", err)
217+
}
216218
}
217219

218220
logrus.Tracef("Compile %s for %s successful", sketch.Name, fqbnIn)

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ go 1.13
55
require (
66
bou.ke/monkey v1.0.1
77
github.com/arduino/board-discovery v0.0.0-20180823133458-1ba29327fb0c
8-
github.com/arduino/go-paths-helper v0.0.0-20190214132331-c3c98d1bf2e1
8+
github.com/arduino/go-paths-helper v1.0.1
99
github.com/arduino/go-properties-orderedmap v0.0.0-20190828172252-05018b28ff6c
1010
github.com/arduino/go-timeutils v0.0.0-20171220113728-d1dd9e313b1b
1111
github.com/arduino/go-win32-utils v0.0.0-20180330194947-ed041402e83b

0 commit comments

Comments
 (0)