Skip to content

Commit 7081b38

Browse files
committed
Fix debug command not finding sketch build folder (#1104)
1 parent ff308cf commit 7081b38

File tree

5 files changed

+71
-4
lines changed

5 files changed

+71
-4
lines changed

Diff for: arduino/sketches/sketches.go

+10
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"encoding/json"
2020
"fmt"
2121

22+
"github.com/arduino/arduino-cli/arduino/builder"
2223
"github.com/arduino/go-paths-helper"
2324
"github.com/pkg/errors"
2425
)
@@ -98,3 +99,12 @@ func (s *Sketch) ExportMetadata() error {
9899
}
99100
return nil
100101
}
102+
103+
// BuildPath returns this Sketch build path in the temp directory of the system.
104+
// Returns an error if the Sketch's FullPath is not set
105+
func (s *Sketch) BuildPath() (*paths.Path, error) {
106+
if s.FullPath == nil {
107+
return nil, fmt.Errorf("sketch path is empty")
108+
}
109+
return builder.GenBuildPath(s.FullPath), nil
110+
}

Diff for: arduino/sketches/sketches_test.go

+16
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,19 @@ func TestSketchLoadingFromFolderOrMainFile(t *testing.T) {
4343
require.True(t, sk.FullPath.EquivalentTo(skFolder))
4444
}
4545
}
46+
47+
func TestSketchBuildPath(t *testing.T) {
48+
// Verifies build path is returned if sketch path is set
49+
sketchPath := paths.New("testdata/Sketch1")
50+
sketch, err := NewSketchFromPath(sketchPath)
51+
require.NoError(t, err)
52+
buildPath, err := sketch.BuildPath()
53+
require.NoError(t, err)
54+
require.Contains(t, buildPath.String(), "arduino-sketch-")
55+
56+
// Verifies error is returned if sketch path is not set
57+
sketch = &Sketch{}
58+
buildPath, err = sketch.BuildPath()
59+
require.Nil(t, buildPath)
60+
require.Error(t, err, "sketch path is empty")
61+
}

Diff for: commands/debug/debug_info.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,10 @@ func getDebugProperties(req *debug.DebugConfigReq, pm *packagemanager.PackageMan
120120
importPath = paths.New(importDir)
121121
} else {
122122
// TODO: Create a function to obtain importPath from sketch
123-
importPath = sketch.FullPath
124-
// Add FQBN (without configs part) to export path
125-
fqbnSuffix := strings.Replace(fqbn.StringWithoutConfig(), ":", ".", -1)
126-
importPath = importPath.Join("build").Join(fqbnSuffix)
123+
importPath, err = sketch.BuildPath()
124+
if err != nil {
125+
return nil, fmt.Errorf("can't find build path for sketch: %v", err)
126+
}
127127
}
128128
if !importPath.Exist() {
129129
return nil, fmt.Errorf("compiled sketch not found in %s", importPath)

Diff for: commands/debug/debug_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ func TestGetCommandLine(t *testing.T) {
5151
Instance: &rpc.Instance{Id: 1},
5252
Fqbn: "arduino-test:samd:arduino_zero_edbg",
5353
SketchPath: sketchPath.String(),
54+
ImportDir: sketchPath.Join("build", "arduino-test.samd.arduino_zero_edbg").String(),
5455
}
5556

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

7779
goldCommand2 := fmt.Sprintf("%s/arduino-test/tools/arm-none-eabi-gcc/7-2017q4/bin/arm-none-eabi-gdb%s", dataDir, toolExtension) +

Diff for: test/test_debug.py

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# This file is part of arduino-cli.
2+
#
3+
# Copyright 2020 ARDUINO SA (http://www.arduino.cc/)
4+
#
5+
# This software is released under the GNU General Public License version 3,
6+
# which covers the main part of arduino-cli.
7+
# The terms of this license can be found at:
8+
# https://www.gnu.org/licenses/gpl-3.0.en.html
9+
#
10+
# You can be released from the requirements of the above licenses by purchasing
11+
# a commercial license. Buying such a license is mandatory if you want to modify or
12+
# otherwise use the software for commercial activities involving the Arduino
13+
# software without disclosing the source code of your own applications. To purchase
14+
# a commercial license, send an email to [email protected].
15+
16+
17+
from pathlib import Path
18+
19+
20+
def test_debugger_starts(run_command, data_dir):
21+
# Init the environment explicitly
22+
assert run_command("core update-index")
23+
24+
# Install cores
25+
assert run_command("core install arduino:samd")
26+
27+
# Create sketch for testing
28+
sketch_name = "DebuggerStartTest"
29+
sketch_path = Path(data_dir, sketch_name)
30+
fqbn = "arduino:samd:mkr1000"
31+
32+
assert run_command(f"sketch new {sketch_path}")
33+
34+
# Build sketch
35+
assert run_command(f"compile -b {fqbn} {sketch_path}")
36+
37+
programmer = "atmel_ice"
38+
# Starts debugger
39+
assert run_command(f"debug -b {fqbn} -P {programmer} {sketch_path} --info")

0 commit comments

Comments
 (0)