@@ -26,7 +26,6 @@ import (
26
26
"strings"
27
27
28
28
"github.com/arduino/arduino-cli/internal/arduino/builder/cpp"
29
- "github.com/arduino/arduino-cli/internal/arduino/builder/internal/diagnosticmanager"
30
29
"github.com/arduino/arduino-cli/internal/arduino/builder/internal/preprocessor/internal/ctags"
31
30
"github.com/arduino/arduino-cli/internal/arduino/sketch"
32
31
"github.com/arduino/arduino-cli/internal/i18n"
@@ -44,12 +43,11 @@ var DebugPreprocessor bool
44
43
func PreprocessSketchWithCtags (
45
44
sketch * sketch.Sketch , buildPath * paths.Path , includes paths.PathList ,
46
45
lineOffset int , buildProperties * properties.Map , onlyUpdateCompilationDatabase bool ,
47
- diagnosticManager * diagnosticmanager.Manager ,
48
- ) ([]byte , []byte , error ) {
46
+ ) (Result , error ) {
49
47
// Create a temporary working directory
50
48
tmpDir , err := paths .MkTempDir ("" , "" )
51
49
if err != nil {
52
- return nil , nil , err
50
+ return Result {} , err
53
51
}
54
52
defer tmpDir .RemoveAll ()
55
53
ctagsTarget := tmpDir .Join ("sketch_merged.cpp" )
@@ -59,38 +57,38 @@ func PreprocessSketchWithCtags(
59
57
60
58
// Run GCC preprocessor
61
59
sourceFile := buildPath .Join ("sketch" , sketch .MainFile .Base ()+ ".cpp" )
62
- gccStdout , gccStderr , err := GCC (sourceFile , ctagsTarget , includes , buildProperties , diagnosticManager )
63
- verboseOutput .Write (gccStdout )
64
- verboseOutput .Write (gccStderr )
65
- normalOutput .Write (gccStderr )
60
+ result , err := GCC (sourceFile , ctagsTarget , includes , buildProperties )
61
+ verboseOutput .Write (result . Stdout () )
62
+ verboseOutput .Write (result . Stderr () )
63
+ normalOutput .Write (result . Stderr () )
66
64
if err != nil {
67
65
if ! onlyUpdateCompilationDatabase {
68
- return normalOutput . Bytes (), verboseOutput .Bytes (), err
66
+ return Result { args : result . Args (), stdout : verboseOutput .Bytes (), stderr : normalOutput . Bytes ()} , err
69
67
}
70
68
71
69
// Do not bail out if we are generating the compile commands database
72
70
normalOutput .WriteString (fmt .Sprintf ("%s: %s" ,
73
71
tr ("An error occurred adding prototypes" ),
74
72
tr ("the compilation database may be incomplete or inaccurate" )))
75
73
if err := sourceFile .CopyTo (ctagsTarget ); err != nil {
76
- return normalOutput . Bytes (), verboseOutput .Bytes (), err
74
+ return Result { args : result . Args (), stdout : verboseOutput .Bytes (), stderr : normalOutput . Bytes ()} , err
77
75
}
78
76
}
79
77
80
78
if src , err := ctagsTarget .ReadFile (); err == nil {
81
79
filteredSource := filterSketchSource (sketch , bytes .NewReader (src ), false )
82
80
if err := ctagsTarget .WriteFile ([]byte (filteredSource )); err != nil {
83
- return normalOutput . Bytes (), verboseOutput .Bytes (), err
81
+ return Result { args : result . Args (), stdout : verboseOutput .Bytes (), stderr : normalOutput . Bytes ()} , err
84
82
}
85
83
} else {
86
- return normalOutput . Bytes (), verboseOutput .Bytes (), err
84
+ return Result { args : result . Args (), stdout : verboseOutput .Bytes (), stderr : normalOutput . Bytes ()} , err
87
85
}
88
86
89
87
// Run CTags on gcc-preprocessed source
90
88
ctagsOutput , ctagsStdErr , err := RunCTags (ctagsTarget , buildProperties )
91
89
verboseOutput .Write (ctagsStdErr )
92
90
if err != nil {
93
- return normalOutput . Bytes (), verboseOutput .Bytes (), err
91
+ return Result { args : result . Args (), stdout : verboseOutput .Bytes (), stderr : normalOutput . Bytes ()} , err
94
92
}
95
93
96
94
// Parse CTags output
@@ -105,13 +103,13 @@ func PreprocessSketchWithCtags(
105
103
if sourceData , err := sourceFile .ReadFile (); err == nil {
106
104
source = string (sourceData )
107
105
} else {
108
- return normalOutput . Bytes (), verboseOutput .Bytes (), err
106
+ return Result { args : result . Args (), stdout : verboseOutput .Bytes (), stderr : normalOutput . Bytes ()} , err
109
107
}
110
108
source = strings .ReplaceAll (source , "\r \n " , "\n " )
111
109
source = strings .ReplaceAll (source , "\r " , "\n " )
112
110
sourceRows := strings .Split (source , "\n " )
113
111
if isFirstFunctionOutsideOfSource (firstFunctionLine , sourceRows ) {
114
- return normalOutput . Bytes (), verboseOutput .Bytes (), nil
112
+ return Result { args : result . Args (), stdout : verboseOutput .Bytes (), stderr : normalOutput . Bytes ()} , nil
115
113
}
116
114
117
115
insertionLine := firstFunctionLine + lineOffset - 1
@@ -137,7 +135,7 @@ func PreprocessSketchWithCtags(
137
135
138
136
// Write back arduino-preprocess output to the sourceFile
139
137
err = sourceFile .WriteFile ([]byte (preprocessedSource ))
140
- return normalOutput . Bytes (), verboseOutput .Bytes (), err
138
+ return Result { args : result . Args (), stdout : verboseOutput .Bytes (), stderr : normalOutput . Bytes ()} , err
141
139
}
142
140
143
141
func composePrototypeSection (line int , prototypes []* ctags.Prototype ) string {
0 commit comments