Skip to content

Commit 1499123

Browse files
[skip changelog] Pass path and contents separately to SketchSaveItemCpp
Previously, these two arguments were wrapped together in a sketch.Item, but since all callers build such an item during the call, there is no compelling reason to do it like this. This commit splits the Item parameter into a separate path and contents, which prepares for removing the file contents from sketch.Item later.
1 parent 103dd8d commit 1499123

File tree

5 files changed

+7
-11
lines changed

5 files changed

+7
-11
lines changed

arduino/builder/sketch.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,17 @@ func QuoteCppString(str string) string {
4747
}
4848

4949
// SketchSaveItemCpp saves a preprocessed .cpp sketch file on disk
50-
func SketchSaveItemCpp(item *sketch.Item, destPath string) error {
50+
func SketchSaveItemCpp(path string, contents []byte, destPath string) error {
5151

52-
sketchName := filepath.Base(item.Path)
52+
sketchName := filepath.Base(path)
5353

5454
if err := os.MkdirAll(destPath, os.FileMode(0755)); err != nil {
5555
return errors.Wrap(err, "unable to create a folder to save the sketch")
5656
}
5757

5858
destFile := filepath.Join(destPath, sketchName+".cpp")
5959

60-
if err := ioutil.WriteFile(destFile, item.Source, os.FileMode(0644)); err != nil {
60+
if err := ioutil.WriteFile(destFile, contents, os.FileMode(0644)); err != nil {
6161
return errors.Wrap(err, "unable to save the sketch on disk")
6262
}
6363

arduino/builder/sketch_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import (
2525
"testing"
2626

2727
"github.com/arduino/arduino-cli/arduino/builder"
28-
"github.com/arduino/arduino-cli/arduino/sketch"
2928
"github.com/stretchr/testify/require"
3029
)
3130

@@ -40,7 +39,7 @@ func TestSaveSketch(t *testing.T) {
4039
t.Fatalf("unable to read golden file %s: %v", sketchFile, err)
4140
}
4241

43-
builder.SketchSaveItemCpp(&sketch.Item{Path: sketchName, Source: source}, tmp)
42+
builder.SketchSaveItemCpp(sketchName, source, tmp)
4443

4544
out, err := ioutil.ReadFile(filepath.Join(tmp, outName))
4645
if err != nil {

legacy/builder/container_add_prototypes.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ package builder
1717

1818
import (
1919
bldr "github.com/arduino/arduino-cli/arduino/builder"
20-
"github.com/arduino/arduino-cli/arduino/sketch"
2120
"github.com/arduino/arduino-cli/legacy/builder/constants"
2221
"github.com/arduino/arduino-cli/legacy/builder/i18n"
2322
"github.com/arduino/arduino-cli/legacy/builder/types"
@@ -54,7 +53,7 @@ func (s *ContainerAddPrototypes) Run(ctx *types.Context) error {
5453
}
5554
}
5655

57-
if err := bldr.SketchSaveItemCpp(&sketch.Item{ctx.Sketch.MainFile.Name.String(), []byte(ctx.Source)}, ctx.SketchBuildPath.String()); err != nil {
56+
if err := bldr.SketchSaveItemCpp(ctx.Sketch.MainFile.Name.String(), []byte(ctx.Source), ctx.SketchBuildPath.String()); err != nil {
5857
return i18n.WrapError(err)
5958
}
6059

legacy/builder/container_merge_copy_sketch_files.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ package builder
1717

1818
import (
1919
bldr "github.com/arduino/arduino-cli/arduino/builder"
20-
"github.com/arduino/arduino-cli/arduino/sketch"
2120
"github.com/arduino/arduino-cli/legacy/builder/i18n"
2221
"github.com/arduino/arduino-cli/legacy/builder/types"
2322
"github.com/go-errors/errors"
@@ -34,7 +33,7 @@ func (s *ContainerMergeCopySketchFiles) Run(ctx *types.Context) error {
3433
ctx.LineOffset = offset
3534
ctx.Source = source
3635

37-
if err := bldr.SketchSaveItemCpp(&sketch.Item{ctx.Sketch.MainFile.Name.String(), []byte(ctx.Source)}, ctx.SketchBuildPath.String()); err != nil {
36+
if err := bldr.SketchSaveItemCpp(ctx.Sketch.MainFile.Name.String(), []byte(ctx.Source), ctx.SketchBuildPath.String()); err != nil {
3837
return i18n.WrapError(err)
3938
}
4039

legacy/builder/preprocess_sketch.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import (
2424
"strings"
2525

2626
bldr "github.com/arduino/arduino-cli/arduino/builder"
27-
"github.com/arduino/arduino-cli/arduino/sketch"
2827
"github.com/arduino/arduino-cli/legacy/builder/constants"
2928
"github.com/arduino/arduino-cli/legacy/builder/i18n"
3029
"github.com/arduino/arduino-cli/legacy/builder/types"
@@ -68,7 +67,7 @@ func (s *PreprocessSketchArduino) Run(ctx *types.Context) error {
6867
if ctx.CodeCompleteAt != "" {
6968
err = new(OutputCodeCompletions).Run(ctx)
7069
} else {
71-
err = bldr.SketchSaveItemCpp(&sketch.Item{ctx.Sketch.MainFile.Name.String(), []byte(ctx.Source)}, ctx.SketchBuildPath.String())
70+
err = bldr.SketchSaveItemCpp(ctx.Sketch.MainFile.Name.String(), []byte(ctx.Source), ctx.SketchBuildPath.String())
7271
}
7372

7473
return err

0 commit comments

Comments
 (0)