Skip to content

Commit 137c531

Browse files
committed
Removed redundant SketchLocation field and related subroutines
1 parent 1d79237 commit 137c531

19 files changed

+96
-199
lines changed

commands/compile/compile.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
116116
}
117117
builderCtx.UseCachedLibrariesResolution = req.GetSkipLibrariesDiscovery()
118118
builderCtx.FQBN = fqbn
119-
builderCtx.SketchLocation = sk.FullPath
119+
builderCtx.Sketch = sk
120120
builderCtx.ProgressCB = progressCB
121121

122122
// FIXME: This will be redundant when arduino-builder will be part of the cli

legacy/builder/container_setup.go

-16
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
package builder
1717

1818
import (
19-
sk "github.com/arduino/arduino-cli/arduino/sketch"
2019
"github.com/arduino/arduino-cli/legacy/builder/types"
2120
"github.com/pkg/errors"
2221
)
@@ -48,21 +47,6 @@ func (s *ContainerSetupHardwareToolsLibsSketchAndProps) Run(ctx *types.Context)
4847
ctx.PushProgress()
4948
}
5049

51-
if ctx.SketchLocation != nil {
52-
// get abs path to sketch
53-
sketchLocation, err := ctx.SketchLocation.Abs()
54-
if err != nil {
55-
return errors.WithStack(err)
56-
}
57-
58-
// load sketch
59-
sketch, err := sk.New(sketchLocation)
60-
if err != nil {
61-
return errors.WithStack(err)
62-
}
63-
ctx.SketchLocation = sketch.MainFile
64-
ctx.Sketch = sketch
65-
}
6650
ctx.Progress.CompleteStep()
6751
ctx.PushProgress()
6852

legacy/builder/fail_if_buildpath_equals_sketchpath.go

+2-15
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,8 @@ import (
2323
type FailIfBuildPathEqualsSketchPath struct{}
2424

2525
func (s *FailIfBuildPathEqualsSketchPath) Run(ctx *types.Context) error {
26-
if ctx.BuildPath == nil || ctx.SketchLocation == nil {
27-
return nil
28-
}
29-
30-
buildPath, err := ctx.BuildPath.Abs()
31-
if err != nil {
32-
return errors.WithStack(err)
33-
}
34-
35-
sketchPath, err := ctx.SketchLocation.Abs()
36-
if err != nil {
37-
return errors.WithStack(err)
38-
}
39-
sketchPath = sketchPath.Parent()
40-
26+
buildPath := ctx.BuildPath.Canonical()
27+
sketchPath := ctx.Sketch.FullPath.Canonical()
4128
if buildPath.EqualsTo(sketchPath) {
4229
return errors.New(tr("Sketch cannot be located in build path. Please specify a different build path"))
4330
}

legacy/builder/setup_build_properties.go

+1-8
Original file line numberDiff line numberDiff line change
@@ -109,14 +109,7 @@ func (s *SetupBuildProperties) Run(ctx *types.Context) error {
109109
buildProperties.Set("software", DEFAULT_SOFTWARE)
110110
}
111111

112-
if ctx.SketchLocation != nil {
113-
sourcePath, err := ctx.SketchLocation.Abs()
114-
if err != nil {
115-
return err
116-
}
117-
sourcePath = sourcePath.Parent()
118-
buildProperties.SetPath("build.source.path", sourcePath)
119-
}
112+
buildProperties.SetPath("build.source.path", ctx.Sketch.FullPath)
120113

121114
now := time.Now()
122115
buildProperties.Set("extra.time.utc", strconv.FormatInt(now.Unix(), 10))

legacy/builder/sketch_loader.go

-53
This file was deleted.

legacy/builder/test/builder_test.go

+7-5
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,21 @@ import (
2121
"testing"
2222
"time"
2323

24-
"github.com/arduino/go-paths-helper"
25-
"github.com/sirupsen/logrus"
26-
24+
"github.com/arduino/arduino-cli/arduino/sketch"
2725
"github.com/arduino/arduino-cli/legacy/builder"
2826
"github.com/arduino/arduino-cli/legacy/builder/constants"
2927
"github.com/arduino/arduino-cli/legacy/builder/phases"
3028
"github.com/arduino/arduino-cli/legacy/builder/types"
29+
"github.com/arduino/go-paths-helper"
30+
"github.com/sirupsen/logrus"
3131
"github.com/stretchr/testify/require"
3232
)
3333

3434
func prepareBuilderTestContext(t *testing.T, sketchPath *paths.Path, fqbn string) *types.Context {
35+
sk, err := sketch.New(sketchPath)
36+
require.NoError(t, err)
3537
return &types.Context{
36-
SketchLocation: sketchPath,
38+
Sketch: sk,
3739
FQBN: parseFQBN(t, fqbn),
3840
HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "downloaded_hardware"),
3941
BuiltInToolsDirs: paths.NewPathList("downloaded_tools"),
@@ -261,7 +263,7 @@ func TestBuilderBridgeRedBearLab(t *testing.T) {
261263
func TestBuilderSketchNoFunctions(t *testing.T) {
262264
DownloadCoresAndToolsAndLibraries(t)
263265

264-
ctx := prepareBuilderTestContext(t, paths.New("sketch_no_functions", "main.ino"), "RedBearLab:avr:blend")
266+
ctx := prepareBuilderTestContext(t, paths.New("sketch_no_functions", "sketch_no_functions.ino"), "RedBearLab:avr:blend")
265267
ctx.HardwareDirs = append(ctx.HardwareDirs, paths.New("downloaded_board_manager_stuff"))
266268
ctx.BuiltInToolsDirs = append(ctx.BuiltInToolsDirs, paths.New("downloaded_board_manager_stuff"))
267269

legacy/builder/test/create_build_options_map_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package test
1818
import (
1919
"testing"
2020

21+
"github.com/arduino/arduino-cli/arduino/sketch"
2122
"github.com/arduino/arduino-cli/legacy/builder"
2223
"github.com/arduino/arduino-cli/legacy/builder/types"
2324
"github.com/arduino/go-paths-helper"
@@ -29,7 +30,7 @@ func TestCreateBuildOptionsMap(t *testing.T) {
2930
HardwareDirs: paths.NewPathList("hardware", "hardware2"),
3031
BuiltInToolsDirs: paths.NewPathList("tools"),
3132
OtherLibrariesDirs: paths.NewPathList("libraries"),
32-
SketchLocation: paths.New("sketchLocation"),
33+
Sketch: &sketch.Sketch{FullPath: paths.New("sketchLocation")},
3334
FQBN: parseFQBN(t, "my:nice:fqbn"),
3435
ArduinoAPIVersion: "ideVersion",
3536
Verbose: true,

legacy/builder/test/ctags_runner_test.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func TestCTagsRunner(t *testing.T) {
3636
BuiltInToolsDirs: paths.NewPathList("downloaded_tools"),
3737
BuiltInLibrariesDirs: paths.New("downloaded_libraries"),
3838
OtherLibrariesDirs: paths.NewPathList("libraries"),
39-
SketchLocation: sketchLocation,
39+
Sketch: OpenSketch(t, sketchLocation),
4040
FQBN: parseFQBN(t, "arduino:avr:leonardo"),
4141
ArduinoAPIVersion: "10600",
4242
Verbose: true,
@@ -86,7 +86,7 @@ func TestCTagsRunnerSketchWithClass(t *testing.T) {
8686
BuiltInToolsDirs: paths.NewPathList("downloaded_tools"),
8787
BuiltInLibrariesDirs: paths.New("downloaded_libraries"),
8888
OtherLibrariesDirs: paths.NewPathList("libraries"),
89-
SketchLocation: sketchLocation,
89+
Sketch: OpenSketch(t, sketchLocation),
9090
FQBN: parseFQBN(t, "arduino:avr:leonardo"),
9191
ArduinoAPIVersion: "10600",
9292
Verbose: true,
@@ -134,7 +134,7 @@ func TestCTagsRunnerSketchWithTypename(t *testing.T) {
134134
BuiltInToolsDirs: paths.NewPathList("downloaded_tools"),
135135
BuiltInLibrariesDirs: paths.New("downloaded_libraries"),
136136
OtherLibrariesDirs: paths.NewPathList("libraries"),
137-
SketchLocation: sketchLocation,
137+
Sketch: OpenSketch(t, sketchLocation),
138138
FQBN: parseFQBN(t, "arduino:avr:leonardo"),
139139
ArduinoAPIVersion: "10600",
140140
Verbose: true,
@@ -181,7 +181,7 @@ func TestCTagsRunnerSketchWithNamespace(t *testing.T) {
181181
BuiltInToolsDirs: paths.NewPathList("downloaded_tools"),
182182
BuiltInLibrariesDirs: paths.New("downloaded_libraries"),
183183
OtherLibrariesDirs: paths.NewPathList("libraries"),
184-
SketchLocation: sketchLocation,
184+
Sketch: OpenSketch(t, sketchLocation),
185185
FQBN: parseFQBN(t, "arduino:avr:leonardo"),
186186
ArduinoAPIVersion: "10600",
187187
Verbose: true,
@@ -227,7 +227,7 @@ func TestCTagsRunnerSketchWithTemplates(t *testing.T) {
227227
BuiltInToolsDirs: paths.NewPathList("downloaded_tools"),
228228
BuiltInLibrariesDirs: paths.New("downloaded_libraries"),
229229
OtherLibrariesDirs: paths.NewPathList("libraries"),
230-
SketchLocation: sketchLocation,
230+
Sketch: OpenSketch(t, sketchLocation),
231231
FQBN: parseFQBN(t, "arduino:avr:leonardo"),
232232
ArduinoAPIVersion: "10600",
233233
Verbose: true,

legacy/builder/test/fail_if_buildpath_equals_sketchpath_test.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package test
1818
import (
1919
"testing"
2020

21+
"github.com/arduino/arduino-cli/arduino/sketch"
2122
"github.com/arduino/arduino-cli/legacy/builder"
2223
"github.com/arduino/arduino-cli/legacy/builder/types"
2324
"github.com/arduino/go-paths-helper"
@@ -26,8 +27,8 @@ import (
2627

2728
func TestFailIfBuildPathEqualsSketchPath(t *testing.T) {
2829
ctx := &types.Context{
29-
SketchLocation: paths.New("buildPath/sketch.ino"),
30-
BuildPath: paths.New("buildPath"),
30+
Sketch: &sketch.Sketch{FullPath: paths.New("buildPath")},
31+
BuildPath: paths.New("buildPath"),
3132
}
3233

3334
command := builder.FailIfBuildPathEqualsSketchPath{}
@@ -36,8 +37,8 @@ func TestFailIfBuildPathEqualsSketchPath(t *testing.T) {
3637

3738
func TestFailIfBuildPathEqualsSketchPathSketchPathDiffers(t *testing.T) {
3839
ctx := &types.Context{
39-
SketchLocation: paths.New("sketchPath/sketch.ino"),
40-
BuildPath: paths.New("buildPath"),
40+
Sketch: &sketch.Sketch{FullPath: paths.New("sketchPath")},
41+
BuildPath: paths.New("buildPath"),
4142
}
4243

4344
command := builder.FailIfBuildPathEqualsSketchPath{}

legacy/builder/test/helper.go

+8
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,13 @@ import (
2424
"text/template"
2525

2626
"github.com/arduino/arduino-cli/arduino/libraries"
27+
"github.com/arduino/arduino-cli/arduino/sketch"
2728
"github.com/arduino/arduino-cli/legacy/builder/constants"
2829
"github.com/arduino/arduino-cli/legacy/builder/types"
2930
"github.com/arduino/arduino-cli/legacy/builder/utils"
3031
paths "github.com/arduino/go-paths-helper"
3132
"github.com/stretchr/testify/assert"
33+
"github.com/stretchr/testify/require"
3234
)
3335

3436
func LoadAndInterpolate(t *testing.T, filename string, ctx *types.Context) string {
@@ -75,6 +77,12 @@ func SetupBuildCachePath(t *testing.T, ctx *types.Context) *paths.Path {
7577
return buildCachePath
7678
}
7779

80+
func OpenSketch(t *testing.T, sketchPath *paths.Path) *sketch.Sketch {
81+
sketch, err := sketch.New(sketchPath)
82+
require.NoError(t, err)
83+
return sketch
84+
}
85+
7886
type ByLibraryName []*libraries.Library
7987

8088
func (s ByLibraryName) Len() int {

legacy/builder/test/includes_to_include_folders_test.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func TestIncludesToIncludeFolders(t *testing.T) {
3434
BuiltInToolsDirs: paths.NewPathList("downloaded_tools"),
3535
BuiltInLibrariesDirs: paths.New("downloaded_libraries"),
3636
OtherLibrariesDirs: paths.NewPathList("libraries"),
37-
SketchLocation: paths.New("downloaded_libraries", "Bridge", "examples", "Bridge", "Bridge.ino"),
37+
Sketch: OpenSketch(t, paths.New("downloaded_libraries", "Bridge", "examples", "Bridge", "Bridge.ino")),
3838
FQBN: parseFQBN(t, "arduino:avr:leonardo"),
3939
ArduinoAPIVersion: "10600",
4040
Verbose: true,
@@ -70,7 +70,7 @@ func TestIncludesToIncludeFoldersSketchWithIfDef(t *testing.T) {
7070
BuiltInToolsDirs: paths.NewPathList("downloaded_tools"),
7171
BuiltInLibrariesDirs: paths.New("downloaded_libraries"),
7272
OtherLibrariesDirs: paths.NewPathList("libraries"),
73-
SketchLocation: paths.New("SketchWithIfDef", "SketchWithIfDef.ino"),
73+
Sketch: OpenSketch(t, paths.New("SketchWithIfDef", "SketchWithIfDef.ino")),
7474
FQBN: parseFQBN(t, "arduino:avr:leonardo"),
7575
ArduinoAPIVersion: "10600",
7676
Verbose: true,
@@ -105,7 +105,7 @@ func TestIncludesToIncludeFoldersIRremoteLibrary(t *testing.T) {
105105
BuiltInToolsDirs: paths.NewPathList("downloaded_tools"),
106106
BuiltInLibrariesDirs: paths.New("downloaded_libraries"),
107107
OtherLibrariesDirs: paths.NewPathList("libraries"),
108-
SketchLocation: paths.New("sketch9", "sketch9.ino"),
108+
Sketch: OpenSketch(t, paths.New("sketch9", "sketch9.ino")),
109109
FQBN: parseFQBN(t, "arduino:avr:leonardo"),
110110
ArduinoAPIVersion: "10600",
111111
Verbose: true,
@@ -143,7 +143,7 @@ func TestIncludesToIncludeFoldersANewLibrary(t *testing.T) {
143143
BuiltInToolsDirs: paths.NewPathList("downloaded_tools"),
144144
BuiltInLibrariesDirs: paths.New("downloaded_libraries"),
145145
OtherLibrariesDirs: paths.NewPathList("libraries"),
146-
SketchLocation: paths.New("sketch10", "sketch10.ino"),
146+
Sketch: OpenSketch(t, paths.New("sketch10", "sketch10.ino")),
147147
FQBN: parseFQBN(t, "arduino:avr:leonardo"),
148148
ArduinoAPIVersion: "10600",
149149
Verbose: true,
@@ -177,7 +177,7 @@ func TestIncludesToIncludeFoldersDuplicateLibs(t *testing.T) {
177177
HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "downloaded_hardware", "user_hardware"),
178178
BuiltInToolsDirs: paths.NewPathList("downloaded_tools"),
179179
BuiltInLibrariesDirs: paths.New("downloaded_libraries"),
180-
SketchLocation: paths.New("user_hardware", "my_avr_platform", "avr", "libraries", "SPI", "examples", "BarometricPressureSensor", "BarometricPressureSensor.ino"),
180+
Sketch: OpenSketch(t, paths.New("user_hardware", "my_avr_platform", "avr", "libraries", "SPI", "examples", "BarometricPressureSensor", "BarometricPressureSensor.ino")),
181181
FQBN: parseFQBN(t, "my_avr_platform:avr:custom_yun"),
182182
ArduinoAPIVersion: "10600",
183183
Verbose: true,
@@ -215,7 +215,7 @@ func TestIncludesToIncludeFoldersDuplicateLibsWithConflictingLibsOutsideOfPlatfo
215215
BuiltInToolsDirs: paths.NewPathList("downloaded_tools"),
216216
BuiltInLibrariesDirs: paths.New("downloaded_libraries"),
217217
OtherLibrariesDirs: paths.NewPathList("libraries"),
218-
SketchLocation: paths.New("user_hardware", "my_avr_platform", "avr", "libraries", "SPI", "examples", "BarometricPressureSensor", "BarometricPressureSensor.ino"),
218+
Sketch: OpenSketch(t, paths.New("user_hardware", "my_avr_platform", "avr", "libraries", "SPI", "examples", "BarometricPressureSensor", "BarometricPressureSensor.ino")),
219219
FQBN: parseFQBN(t, "my_avr_platform:avr:custom_yun"),
220220
ArduinoAPIVersion: "10600",
221221
Verbose: true,
@@ -253,7 +253,7 @@ func TestIncludesToIncludeFoldersDuplicateLibs2(t *testing.T) {
253253
BuiltInToolsDirs: paths.NewPathList("downloaded_tools"),
254254
BuiltInLibrariesDirs: paths.New("downloaded_libraries"),
255255
OtherLibrariesDirs: paths.NewPathList("libraries"),
256-
SketchLocation: paths.New("sketch_usbhost", "sketch_usbhost.ino"),
256+
Sketch: OpenSketch(t, paths.New("sketch_usbhost", "sketch_usbhost.ino")),
257257
FQBN: parseFQBN(t, "arduino:samd:arduino_zero_native"),
258258
ArduinoAPIVersion: "10600",
259259
Verbose: true,
@@ -291,7 +291,7 @@ func TestIncludesToIncludeFoldersSubfolders(t *testing.T) {
291291
BuiltInToolsDirs: paths.NewPathList("downloaded_tools"),
292292
BuiltInLibrariesDirs: paths.New("downloaded_libraries"),
293293
OtherLibrariesDirs: paths.NewPathList("libraries"),
294-
SketchLocation: paths.New("sketch_with_subfolders", "sketch_with_subfolders.ino"),
294+
Sketch: OpenSketch(t, paths.New("sketch_with_subfolders", "sketch_with_subfolders.ino")),
295295
FQBN: parseFQBN(t, "arduino:avr:leonardo"),
296296
ArduinoAPIVersion: "10600",
297297
Verbose: true,

legacy/builder/test/load_vid_pid_specific_properties_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func TestLoadVIDPIDSpecificPropertiesWhenNoVIDPIDAreProvided(t *testing.T) {
3131
ctx := &types.Context{
3232
HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "downloaded_hardware"),
3333
BuiltInToolsDirs: paths.NewPathList("downloaded_tools", "./tools_builtin"),
34-
SketchLocation: paths.New("sketch1", "sketch1.ino"),
34+
Sketch: OpenSketch(t, paths.New("sketch1", "sketch1.ino")),
3535
FQBN: parseFQBN(t, "arduino:avr:micro"),
3636
ArduinoAPIVersion: "10600",
3737
}
@@ -61,7 +61,7 @@ func TestLoadVIDPIDSpecificProperties(t *testing.T) {
6161
ctx := &types.Context{
6262
HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "downloaded_hardware"),
6363
BuiltInToolsDirs: paths.NewPathList("downloaded_tools", "./tools_builtin"),
64-
SketchLocation: paths.New("sketch1", "sketch1.ino"),
64+
Sketch: OpenSketch(t, paths.New("sketch1", "sketch1.ino")),
6565
FQBN: parseFQBN(t, "arduino:avr:micro"),
6666
ArduinoAPIVersion: "10600",
6767
}

0 commit comments

Comments
 (0)