Skip to content

Commit

Permalink
Fix debug command not finding sketch build folder (#1104)
Browse files Browse the repository at this point in the history
  • Loading branch information
silvanocerza committed Dec 9, 2020
1 parent cb5bdba commit 78d1d11
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 4 deletions.
10 changes: 10 additions & 0 deletions arduino/sketches/sketches.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"encoding/json"
"fmt"

"github.com/arduino/arduino-cli/arduino/builder"
"github.com/arduino/go-paths-helper"
"github.com/pkg/errors"
)
Expand Down Expand Up @@ -98,3 +99,12 @@ func (s *Sketch) ExportMetadata() error {
}
return nil
}

// BuildPath returns this Sketch build path in the temp directory of the system.
// Returns an error if the Sketch's FullPath is not set
func (s *Sketch) BuildPath() (*paths.Path, error) {
if s.FullPath == nil {
return nil, fmt.Errorf("sketch path is empty")
}
return builder.GenBuildPath(s.FullPath), nil
}
16 changes: 16 additions & 0 deletions arduino/sketches/sketches_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,19 @@ func TestSketchLoadingFromFolderOrMainFile(t *testing.T) {
require.True(t, sk.FullPath.EquivalentTo(skFolder))
}
}

func TestSketchBuildPath(t *testing.T) {
// Verifies build path is returned if sketch path is set
sketchPath := paths.New("testdata/Sketch1")
sketch, err := NewSketchFromPath(sketchPath)
require.NoError(t, err)
buildPath, err := sketch.BuildPath()
require.NoError(t, err)
require.Contains(t, buildPath.String(), "arduino-sketch-")

// Verifies error is returned if sketch path is not set
sketch = &Sketch{}
buildPath, err = sketch.BuildPath()
require.Nil(t, buildPath)
require.Error(t, err, "sketch path is empty")
}
8 changes: 4 additions & 4 deletions commands/debug/debug_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,10 @@ func getDebugProperties(req *debug.DebugConfigReq, pm *packagemanager.PackageMan
importPath = paths.New(importDir)
} else {
// TODO: Create a function to obtain importPath from sketch
importPath = sketch.FullPath
// Add FQBN (without configs part) to export path
fqbnSuffix := strings.Replace(fqbn.StringWithoutConfig(), ":", ".", -1)
importPath = importPath.Join("build").Join(fqbnSuffix)
importPath, err = sketch.BuildPath()
if err != nil {
return nil, fmt.Errorf("can't find build path for sketch: %v", err)
}
}
if !importPath.Exist() {
return nil, fmt.Errorf("compiled sketch not found in %s", importPath)
Expand Down
2 changes: 2 additions & 0 deletions commands/debug/debug_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ func TestGetCommandLine(t *testing.T) {
Instance: &rpc.Instance{Id: 1},
Fqbn: "arduino-test:samd:arduino_zero_edbg",
SketchPath: sketchPath.String(),
ImportDir: sketchPath.Join("build", "arduino-test.samd.arduino_zero_edbg").String(),
}

goldCommand := fmt.Sprintf("%s/arduino-test/tools/arm-none-eabi-gcc/7-2017q4/bin/arm-none-eabi-gdb%s", dataDir, toolExtension) +
Expand All @@ -72,6 +73,7 @@ func TestGetCommandLine(t *testing.T) {
Fqbn: "arduino-test:samd:mkr1000",
SketchPath: sketchPath.String(),
Interpreter: "mi1",
ImportDir: sketchPath.Join("build", "arduino-test.samd.mkr1000").String(),
}

goldCommand2 := fmt.Sprintf("%s/arduino-test/tools/arm-none-eabi-gcc/7-2017q4/bin/arm-none-eabi-gdb%s", dataDir, toolExtension) +
Expand Down
39 changes: 39 additions & 0 deletions test/test_debug.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# This file is part of arduino-cli.
#
# Copyright 2020 ARDUINO SA (http://www.arduino.cc/)
#
# This software is released under the GNU General Public License version 3,
# which covers the main part of arduino-cli.
# The terms of this license can be found at:
# https://www.gnu.org/licenses/gpl-3.0.en.html
#
# You can be released from the requirements of the above licenses by purchasing
# a commercial license. Buying such a license is mandatory if you want to modify or
# otherwise use the software for commercial activities involving the Arduino
# software without disclosing the source code of your own applications. To purchase
# a commercial license, send an email to license@arduino.cc.


from pathlib import Path


def test_debugger_starts(run_command, data_dir):
# Init the environment explicitly
assert run_command("core update-index")

# Install cores
assert run_command("core install arduino:samd")

# Create sketch for testing
sketch_name = "DebuggerStartTest"
sketch_path = Path(data_dir, sketch_name)
fqbn = "arduino:samd:mkr1000"

assert run_command(f"sketch new {sketch_path}")

# Build sketch
assert run_command(f"compile -b {fqbn} {sketch_path}")

programmer = "atmel_ice"
# Starts debugger
assert run_command(f"debug -b {fqbn} -P {programmer} {sketch_path} --info")

0 comments on commit 78d1d11

Please sign in to comment.