Skip to content

Commit 9be2db0

Browse files
return pointer to Result
1 parent 7c81dbf commit 9be2db0

File tree

3 files changed

+25
-23
lines changed

3 files changed

+25
-23
lines changed

Diff for: internal/arduino/builder/internal/preprocessor/arduino_preprocessor.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ import (
3333
func PreprocessSketchWithArduinoPreprocessor(
3434
sk *sketch.Sketch, buildPath *paths.Path, includeFolders paths.PathList,
3535
lineOffset int, buildProperties *properties.Map, onlyUpdateCompilationDatabase bool,
36-
) (Result, error) {
36+
) (*Result, error) {
3737
verboseOut := &bytes.Buffer{}
3838
normalOut := &bytes.Buffer{}
3939
if err := buildPath.Join("preproc").MkdirAll(); err != nil {
40-
return Result{}, err
40+
return nil, err
4141
}
4242

4343
sourceFile := buildPath.Join("sketch", sk.MainFile.Base()+".cpp")
@@ -46,7 +46,7 @@ func PreprocessSketchWithArduinoPreprocessor(
4646
verboseOut.Write(gccResult.Stdout())
4747
verboseOut.Write(gccResult.Stderr())
4848
if err != nil {
49-
return Result{}, err
49+
return nil, err
5050
}
5151

5252
arduiniPreprocessorProperties := properties.NewMap()
@@ -59,18 +59,18 @@ func PreprocessSketchWithArduinoPreprocessor(
5959
arduiniPreprocessorProperties.SetPath("source_file", targetFile)
6060
pattern := arduiniPreprocessorProperties.Get("pattern")
6161
if pattern == "" {
62-
return Result{}, errors.New(tr("arduino-preprocessor pattern is missing"))
62+
return nil, errors.New(tr("arduino-preprocessor pattern is missing"))
6363
}
6464

6565
commandLine := arduiniPreprocessorProperties.ExpandPropsInString(pattern)
6666
parts, err := properties.SplitQuotedString(commandLine, `"'`, false)
6767
if err != nil {
68-
return Result{}, err
68+
return nil, err
6969
}
7070

7171
command, err := paths.NewProcess(nil, parts...)
7272
if err != nil {
73-
return Result{}, err
73+
return nil, err
7474
}
7575
if runtime.GOOS == "windows" {
7676
// chdir in the uppermost directory to avoid UTF-8 bug in clang (https://github.com/arduino/arduino-preprocessor/issues/2)
@@ -81,13 +81,13 @@ func PreprocessSketchWithArduinoPreprocessor(
8181
commandStdOut, commandStdErr, err := command.RunAndCaptureOutput(context.Background())
8282
verboseOut.Write(commandStdErr)
8383
if err != nil {
84-
return Result{args: gccResult.Args(), stdout: verboseOut.Bytes(), stderr: normalOut.Bytes()}, err
84+
return &Result{args: gccResult.Args(), stdout: verboseOut.Bytes(), stderr: normalOut.Bytes()}, err
8585
}
8686
result := utils.NormalizeUTF8(commandStdOut)
8787

8888
destFile := buildPath.Join(sk.MainFile.Base() + ".cpp")
8989
if err := destFile.WriteFile(result); err != nil {
90-
return Result{args: gccResult.Args(), stdout: verboseOut.Bytes(), stderr: normalOut.Bytes()}, err
90+
return &Result{args: gccResult.Args(), stdout: verboseOut.Bytes(), stderr: normalOut.Bytes()}, err
9191
}
92-
return Result{args: gccResult.Args(), stdout: verboseOut.Bytes(), stderr: normalOut.Bytes()}, err
92+
return &Result{args: gccResult.Args(), stdout: verboseOut.Bytes(), stderr: normalOut.Bytes()}, err
9393
}

Diff for: internal/arduino/builder/internal/preprocessor/ctags.go

+10-10
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ var DebugPreprocessor bool
4343
func PreprocessSketchWithCtags(
4444
sketch *sketch.Sketch, buildPath *paths.Path, includes paths.PathList,
4545
lineOffset int, buildProperties *properties.Map, onlyUpdateCompilationDatabase bool,
46-
) (Result, error) {
46+
) (*Result, error) {
4747
// Create a temporary working directory
4848
tmpDir, err := paths.MkTempDir("", "")
4949
if err != nil {
50-
return Result{}, err
50+
return nil, err
5151
}
5252
defer tmpDir.RemoveAll()
5353
ctagsTarget := tmpDir.Join("sketch_merged.cpp")
@@ -61,32 +61,32 @@ func PreprocessSketchWithCtags(
6161
stderr.Write(result.Stderr())
6262
if err != nil {
6363
if !onlyUpdateCompilationDatabase {
64-
return Result{args: result.Args(), stdout: stdout.Bytes(), stderr: stderr.Bytes()}, err
64+
return &Result{args: result.Args(), stdout: stdout.Bytes(), stderr: stderr.Bytes()}, err
6565
}
6666

6767
// Do not bail out if we are generating the compile commands database
6868
stderr.WriteString(fmt.Sprintf("%s: %s",
6969
tr("An error occurred adding prototypes"),
7070
tr("the compilation database may be incomplete or inaccurate")))
7171
if err := sourceFile.CopyTo(ctagsTarget); err != nil {
72-
return Result{args: result.Args(), stdout: stdout.Bytes(), stderr: stderr.Bytes()}, err
72+
return &Result{args: result.Args(), stdout: stdout.Bytes(), stderr: stderr.Bytes()}, err
7373
}
7474
}
7575

7676
if src, err := ctagsTarget.ReadFile(); err == nil {
7777
filteredSource := filterSketchSource(sketch, bytes.NewReader(src), false)
7878
if err := ctagsTarget.WriteFile([]byte(filteredSource)); err != nil {
79-
return Result{args: result.Args(), stdout: stdout.Bytes(), stderr: stderr.Bytes()}, err
79+
return &Result{args: result.Args(), stdout: stdout.Bytes(), stderr: stderr.Bytes()}, err
8080
}
8181
} else {
82-
return Result{args: result.Args(), stdout: stdout.Bytes(), stderr: stderr.Bytes()}, err
82+
return &Result{args: result.Args(), stdout: stdout.Bytes(), stderr: stderr.Bytes()}, err
8383
}
8484

8585
// Run CTags on gcc-preprocessed source
8686
ctagsOutput, ctagsStdErr, err := RunCTags(ctagsTarget, buildProperties)
8787
stderr.Write(ctagsStdErr)
8888
if err != nil {
89-
return Result{args: result.Args(), stdout: stdout.Bytes(), stderr: stderr.Bytes()}, err
89+
return &Result{args: result.Args(), stdout: stdout.Bytes(), stderr: stderr.Bytes()}, err
9090
}
9191

9292
// Parse CTags output
@@ -101,13 +101,13 @@ func PreprocessSketchWithCtags(
101101
if sourceData, err := sourceFile.ReadFile(); err == nil {
102102
source = string(sourceData)
103103
} else {
104-
return Result{args: result.Args(), stdout: stdout.Bytes(), stderr: stderr.Bytes()}, err
104+
return &Result{args: result.Args(), stdout: stdout.Bytes(), stderr: stderr.Bytes()}, err
105105
}
106106
source = strings.ReplaceAll(source, "\r\n", "\n")
107107
source = strings.ReplaceAll(source, "\r", "\n")
108108
sourceRows := strings.Split(source, "\n")
109109
if isFirstFunctionOutsideOfSource(firstFunctionLine, sourceRows) {
110-
return Result{args: result.Args(), stdout: stdout.Bytes(), stderr: stderr.Bytes()}, nil
110+
return &Result{args: result.Args(), stdout: stdout.Bytes(), stderr: stderr.Bytes()}, nil
111111
}
112112

113113
insertionLine := firstFunctionLine + lineOffset - 1
@@ -133,7 +133,7 @@ func PreprocessSketchWithCtags(
133133

134134
// Write back arduino-preprocess output to the sourceFile
135135
err = sourceFile.WriteFile([]byte(preprocessedSource))
136-
return Result{args: result.Args(), stdout: stdout.Bytes(), stderr: stderr.Bytes()}, err
136+
return &Result{args: result.Args(), stdout: stdout.Bytes(), stderr: stderr.Bytes()}, err
137137
}
138138

139139
func composePrototypeSection(line int, prototypes []*ctags.Prototype) string {

Diff for: internal/arduino/builder/preprocess_sketch.go

+6-4
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,13 @@ func (b *Builder) preprocessSketch(includes paths.PathList) error {
2727
b.sketch, b.buildPath, includes, b.lineOffset,
2828
b.buildProperties, b.onlyUpdateCompilationDatabase,
2929
)
30-
if b.logger.Verbose() {
31-
b.logger.WriteStdout(result.Stdout())
30+
if result != nil {
31+
if b.logger.Verbose() {
32+
b.logger.WriteStdout(result.Stdout())
33+
}
34+
b.logger.WriteStdout(result.Stderr())
35+
b.diagnosticStore.Parse(result.Args(), result.Stderr())
3236
}
33-
b.logger.WriteStdout(result.Stderr())
34-
b.diagnosticStore.Parse(result.Args(), result.Stderr())
3537

3638
return err
3739
}

0 commit comments

Comments
 (0)