Skip to content

Commit f022da3

Browse files
committed
Inlined function
1 parent 4d1d812 commit f022da3

File tree

3 files changed

+15
-40
lines changed

3 files changed

+15
-40
lines changed

arduino/builder/preprocessor/arduino_preprocessor.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"path/filepath"
2222
"runtime"
2323

24-
"github.com/arduino/arduino-cli/arduino/builder"
2524
"github.com/arduino/arduino-cli/arduino/sketch"
2625
"github.com/arduino/arduino-cli/executils"
2726
"github.com/arduino/arduino-cli/legacy/builder/utils"
@@ -84,6 +83,10 @@ func PreprocessSketchWithArduinoPreprocessor(sk *sketch.Sketch, buildPath *paths
8483
}
8584
result := utils.NormalizeUTF8(commandStdOut)
8685

87-
err = builder.SketchSaveItemCpp(sk.MainFile, result, buildPath.Join("sketch"))
86+
destFile := buildPath.Join(sk.Name + ".ino.cpp")
87+
if err := destFile.WriteFile(result); err != nil {
88+
return normalOut.Bytes(), verboseOut.Bytes(), err
89+
}
90+
8891
return normalOut.Bytes(), verboseOut.Bytes(), err
8992
}

arduino/builder/sketch.go

+10-16
Original file line numberDiff line numberDiff line change
@@ -41,28 +41,22 @@ func (b *Builder) PrepareSketchBuildPath(sourceOverrides map[string]string, buil
4141
if err := buildPath.MkdirAll(); err != nil {
4242
return 0, errors.Wrap(err, tr("unable to create a folder to save the sketch"))
4343
}
44-
if offset, mergedSource, err := b.sketchMergeSources(sourceOverrides); err != nil {
45-
return 0, err
46-
} else if err := SketchSaveItemCpp(b.sketch.MainFile, []byte(mergedSource), buildPath); err != nil {
47-
return 0, err
48-
} else if err := sketchCopyAdditionalFiles(b.sketch, buildPath, sourceOverrides); err != nil {
44+
45+
offset, mergedSource, err := b.sketchMergeSources(sourceOverrides)
46+
if err != nil {
4947
return 0, err
50-
} else {
51-
return offset, nil
5248
}
53-
}
5449

55-
// SketchSaveItemCpp saves a preprocessed .cpp sketch file on disk
56-
func SketchSaveItemCpp(path *paths.Path, contents []byte, buildPath *paths.Path) error {
57-
sketchName := path.Base()
58-
59-
destFile := buildPath.Join(fmt.Sprintf("%s.cpp", sketchName))
50+
destFile := buildPath.Join(b.sketch.Name + ".ino.cpp")
51+
if err := destFile.WriteFile([]byte(mergedSource)); err != nil {
52+
return 0, err
53+
}
6054

61-
if err := destFile.WriteFile(contents); err != nil {
62-
return errors.Wrap(err, tr("unable to save the sketch on disk"))
55+
if err := sketchCopyAdditionalFiles(b.sketch, buildPath, sourceOverrides); err != nil {
56+
return 0, err
6357
}
6458

65-
return nil
59+
return offset, nil
6660
}
6761

6862
// sketchMergeSources merges all the .ino source files included in a sketch to produce

arduino/builder/sketch_test.go

-22
Original file line numberDiff line numberDiff line change
@@ -26,28 +26,6 @@ import (
2626
"github.com/stretchr/testify/require"
2727
)
2828

29-
func TestSaveSketch(t *testing.T) {
30-
sketchName := t.Name() + ".ino" // "TestSaveSketch.ino"
31-
outName := sketchName + ".cpp" // "TestSaveSketch.ino.cpp"
32-
sketchFile := paths.New("testdata", sketchName) // "testdata/TestSaveSketch.ino.cpp"
33-
tmp, err := paths.MkTempDir("", "")
34-
require.NoError(t, err)
35-
defer tmp.RemoveAll()
36-
source, err := sketchFile.ReadFile()
37-
if err != nil {
38-
t.Fatalf("unable to read golden file %s: %v", sketchFile, err)
39-
}
40-
41-
SketchSaveItemCpp(paths.New(sketchName), source, tmp)
42-
43-
out, err := tmp.Join(outName).ReadFile()
44-
if err != nil {
45-
t.Fatalf("unable to read output file %s: %v", outName, err)
46-
}
47-
48-
require.Equal(t, source, out)
49-
}
50-
5129
func TestMergeSketchSources(t *testing.T) {
5230
// borrow the sketch from TestLoadSketchFolder to avoid boilerplate
5331
sk, err := sketch.New(paths.New("testdata", "TestLoadSketchFolder"))

0 commit comments

Comments
 (0)