Skip to content

Commit 4d1d812

Browse files
committed
Moved PreprocessSketchWithArduinoPreprocessor into proper place
1 parent 7cff862 commit 4d1d812

File tree

2 files changed

+13
-16
lines changed

2 files changed

+13
-16
lines changed

legacy/builder/preprocess_sketch.go renamed to arduino/builder/preprocessor/arduino_preprocessor.go

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// This file is part of arduino-cli.
22
//
3-
// Copyright 2020 ARDUINO SA (http://www.arduino.cc/)
3+
// Copyright 2023 ARDUINO SA (http://www.arduino.cc/)
44
//
55
// This software is released under the GNU General Public License version 3,
66
// which covers the main part of arduino-cli.
@@ -13,24 +13,25 @@
1313
// Arduino software without disclosing the source code of your own applications.
1414
// To purchase a commercial license, send an email to [email protected].
1515

16-
package builder
16+
package preprocessor
1717

1818
import (
1919
"bytes"
2020
"context"
2121
"path/filepath"
2222
"runtime"
2323

24-
bldr "github.com/arduino/arduino-cli/arduino/builder"
25-
"github.com/arduino/arduino-cli/arduino/builder/preprocessor"
24+
"github.com/arduino/arduino-cli/arduino/builder"
2625
"github.com/arduino/arduino-cli/arduino/sketch"
2726
"github.com/arduino/arduino-cli/executils"
2827
"github.com/arduino/arduino-cli/legacy/builder/utils"
2928
"github.com/arduino/go-paths-helper"
30-
properties "github.com/arduino/go-properties-orderedmap"
29+
"github.com/arduino/go-properties-orderedmap"
3130
"github.com/pkg/errors"
3231
)
3332

33+
// PreprocessSketchWithArduinoPreprocessor performs preprocessing of the arduino sketch
34+
// using arduino-preprocessor (https://github.com/arduino/arduino-preprocessor).
3435
func PreprocessSketchWithArduinoPreprocessor(sk *sketch.Sketch, buildPath *paths.Path, includeFolders paths.PathList, lineOffset int, buildProperties *properties.Map, onlyUpdateCompilationDatabase bool) ([]byte, []byte, error) {
3536
verboseOut := &bytes.Buffer{}
3637
normalOut := &bytes.Buffer{}
@@ -40,7 +41,7 @@ func PreprocessSketchWithArduinoPreprocessor(sk *sketch.Sketch, buildPath *paths
4041

4142
sourceFile := buildPath.Join("sketch", sk.MainFile.Base()+".cpp")
4243
targetFile := buildPath.Join("preproc", "sketch_merged.cpp")
43-
gccStdout, gccStderr, err := preprocessor.GCC(sourceFile, targetFile, includeFolders, buildProperties)
44+
gccStdout, gccStderr, err := GCC(sourceFile, targetFile, includeFolders, buildProperties)
4445
verboseOut.Write(gccStdout)
4546
verboseOut.Write(gccStderr)
4647
if err != nil {
@@ -83,6 +84,6 @@ func PreprocessSketchWithArduinoPreprocessor(sk *sketch.Sketch, buildPath *paths
8384
}
8485
result := utils.NormalizeUTF8(commandStdOut)
8586

86-
err = bldr.SketchSaveItemCpp(sk.MainFile, result, buildPath.Join("sketch"))
87+
err = builder.SketchSaveItemCpp(sk.MainFile, result, buildPath.Join("sketch"))
8788
return normalOut.Bytes(), verboseOut.Bytes(), err
8889
}

legacy/builder/builder.go

+5-9
Original file line numberDiff line numberDiff line change
@@ -138,17 +138,13 @@ func (s *Builder) Run(ctx *types.Context) error {
138138
}
139139

140140
func PreprocessSketch(ctx *types.Context) error {
141-
var normalOutput, verboseOutput []byte
142-
var err error
141+
preprocessorImpl := preprocessor.PreprocessSketchWithCtags
143142
if ctx.UseArduinoPreprocessor {
144-
normalOutput, verboseOutput, err = PreprocessSketchWithArduinoPreprocessor(
145-
ctx.Sketch, ctx.BuildPath, ctx.IncludeFolders, ctx.LineOffset,
146-
ctx.BuildProperties, ctx.OnlyUpdateCompilationDatabase)
147-
} else {
148-
normalOutput, verboseOutput, err = preprocessor.PreprocessSketchWithCtags(
149-
ctx.Sketch, ctx.BuildPath, ctx.IncludeFolders, ctx.LineOffset,
150-
ctx.BuildProperties, ctx.OnlyUpdateCompilationDatabase)
143+
preprocessorImpl = preprocessor.PreprocessSketchWithArduinoPreprocessor
151144
}
145+
normalOutput, verboseOutput, err := preprocessorImpl(
146+
ctx.Sketch, ctx.BuildPath, ctx.IncludeFolders, ctx.LineOffset,
147+
ctx.BuildProperties, ctx.OnlyUpdateCompilationDatabase)
152148
if ctx.Verbose {
153149
ctx.WriteStdout(verboseOutput)
154150
} else {

0 commit comments

Comments
 (0)