Skip to content

Commit

Permalink
Merge pull request #67 from robgonnella/i60-use-relative-paths-in-ard…
Browse files Browse the repository at this point in the history
…ijson

Use relative paths in ardi.json
  • Loading branch information
robgonnella authored Jul 10, 2021
2 parents ae01c71 + 86d2b7a commit 724dbf9
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 17 deletions.
26 changes: 21 additions & 5 deletions v2/cli-wrapper/cli-wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"os"
"path"
"path/filepath"
"sort"
"strings"
"text/tabwriter"
Expand Down Expand Up @@ -279,15 +280,20 @@ func (c *Wrapper) AllBoards() []*BoardWithPort {
func (c *Wrapper) Upload(fqbn, sketchDir, device string) error {
inst := c.getRPCInstance()

resolvedSketch, err := filepath.Abs(sketchDir)
if err != nil {
return errors.New("could not resolve sketch directory")
}

req := &rpc.UploadRequest{
Instance: inst,
Fqbn: fqbn,
SketchPath: sketchDir,
SketchPath: resolvedSketch,
Port: device,
Verbose: c.isVerbose(),
}

_, err := c.cli.Upload(
_, err = c.cli.Upload(
c.ctx,
req,
os.Stdout,
Expand All @@ -310,19 +316,29 @@ type CompileOpts struct {
func (c *Wrapper) Compile(opts CompileOpts) error {
inst := c.getRPCInstance()

exportDir := path.Join(opts.SketchDir, "build")
resolvedSketchPath, err := filepath.Abs(opts.SketchPath)
if err != nil {
return errors.New("could not resolve sketch path")
}

resolvedSketchDir, err := filepath.Abs(opts.SketchDir)
if err != nil {
return errors.New("could not resolve sketch directory")
}

exportDir := path.Join(resolvedSketchDir, "build")

req := &rpc.CompileRequest{
Instance: inst,
Fqbn: opts.FQBN,
SketchPath: opts.SketchPath,
SketchPath: resolvedSketchPath,
ExportDir: exportDir,
BuildProperties: opts.BuildProps,
ShowProperties: opts.ShowProps,
Verbose: c.isVerbose(),
}

_, err := c.cli.Compile(
_, err = c.cli.Compile(
c.ctx,
req,
os.Stdout,
Expand Down
14 changes: 10 additions & 4 deletions v2/cli-wrapper/cli-wrapper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"context"
"fmt"
"path"
"path/filepath"
"testing"

rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
Expand Down Expand Up @@ -293,12 +294,13 @@ func TestCliWrapperTest(t *testing.T) {
inst := &rpc.Instance{Id: int32(1)}
fqbn := "some:fqbn"
sketchDir := "."
resolvedSketchDir, _ := filepath.Abs(sketchDir)
device := "/dev/null"

req := &rpc.UploadRequest{
Instance: inst,
Fqbn: fqbn,
SketchPath: sketchDir,
SketchPath: resolvedSketchDir,
Port: device,
Verbose: false,
}
Expand All @@ -312,18 +314,22 @@ func TestCliWrapperTest(t *testing.T) {

runCliTest("compiles sketches", t, func(env cliTestEnv, st *testing.T) {
inst := &rpc.Instance{Id: int32(1)}
sketchDir := "."
resolvedSketchDir, _ := filepath.Abs(sketchDir)
resolvedSketchPath := path.Join(resolvedSketchDir, "some_sketch.ino")
resolvedBuildDir := path.Join(resolvedSketchDir, "build")

opts := cli.CompileOpts{
FQBN: "some:fqbn",
SketchDir: ".",
SketchDir: sketchDir,
SketchPath: "./some_sketch.ino",
}

req := &rpc.CompileRequest{
Instance: inst,
Fqbn: opts.FQBN,
SketchPath: opts.SketchPath,
ExportDir: path.Join(opts.SketchDir, "build"),
SketchPath: resolvedSketchPath,
ExportDir: resolvedBuildDir,
BuildProperties: opts.BuildProps,
ShowProperties: opts.ShowProps,
Verbose: false,
Expand Down
8 changes: 0 additions & 8 deletions v2/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,14 +262,6 @@ func ProcessSketch(filePath string) (*types.Project, error) {

sketchBaud := ParseSketchBaud(sketchFile)

if sketchFile, err = filepath.Abs(sketchFile); err != nil {
return nil, errors.New("could not resolve sketch file path")
}

if sketchDir, err = filepath.Abs(sketchDir); err != nil {
return nil, errors.New("could not resolve sketch directory")
}

return &types.Project{
Directory: sketchDir,
Sketch: sketchFile,
Expand Down

0 comments on commit 724dbf9

Please sign in to comment.