@@ -52,43 +52,41 @@ func PreprocessSketchWithCtags(
52
52
defer tmpDir .RemoveAll ()
53
53
ctagsTarget := tmpDir .Join ("sketch_merged.cpp" )
54
54
55
- normalOutput := & bytes.Buffer {}
56
- verboseOutput := & bytes.Buffer {}
55
+ stdout , stderr := & bytes.Buffer {}, & bytes.Buffer {}
57
56
58
57
// Run GCC preprocessor
59
58
sourceFile := buildPath .Join ("sketch" , sketch .MainFile .Base ()+ ".cpp" )
60
59
result , err := GCC (sourceFile , ctagsTarget , includes , buildProperties )
61
- verboseOutput .Write (result .Stdout ())
62
- verboseOutput .Write (result .Stderr ())
63
- normalOutput .Write (result .Stderr ())
60
+ stdout .Write (result .Stdout ())
61
+ stderr .Write (result .Stderr ())
64
62
if err != nil {
65
63
if ! onlyUpdateCompilationDatabase {
66
- return Result {args : result .Args (), stdout : verboseOutput .Bytes (), stderr : normalOutput .Bytes ()}, err
64
+ return Result {args : result .Args (), stdout : stdout .Bytes (), stderr : stderr .Bytes ()}, err
67
65
}
68
66
69
67
// Do not bail out if we are generating the compile commands database
70
- normalOutput .WriteString (fmt .Sprintf ("%s: %s" ,
68
+ stderr .WriteString (fmt .Sprintf ("%s: %s" ,
71
69
tr ("An error occurred adding prototypes" ),
72
70
tr ("the compilation database may be incomplete or inaccurate" )))
73
71
if err := sourceFile .CopyTo (ctagsTarget ); err != nil {
74
- return Result {args : result .Args (), stdout : verboseOutput .Bytes (), stderr : normalOutput .Bytes ()}, err
72
+ return Result {args : result .Args (), stdout : stdout .Bytes (), stderr : stderr .Bytes ()}, err
75
73
}
76
74
}
77
75
78
76
if src , err := ctagsTarget .ReadFile (); err == nil {
79
77
filteredSource := filterSketchSource (sketch , bytes .NewReader (src ), false )
80
78
if err := ctagsTarget .WriteFile ([]byte (filteredSource )); err != nil {
81
- return Result {args : result .Args (), stdout : verboseOutput .Bytes (), stderr : normalOutput .Bytes ()}, err
79
+ return Result {args : result .Args (), stdout : stdout .Bytes (), stderr : stderr .Bytes ()}, err
82
80
}
83
81
} else {
84
- return Result {args : result .Args (), stdout : verboseOutput .Bytes (), stderr : normalOutput .Bytes ()}, err
82
+ return Result {args : result .Args (), stdout : stdout .Bytes (), stderr : stderr .Bytes ()}, err
85
83
}
86
84
87
85
// Run CTags on gcc-preprocessed source
88
86
ctagsOutput , ctagsStdErr , err := RunCTags (ctagsTarget , buildProperties )
89
- verboseOutput .Write (ctagsStdErr )
87
+ stderr .Write (ctagsStdErr )
90
88
if err != nil {
91
- return Result {args : result .Args (), stdout : verboseOutput .Bytes (), stderr : normalOutput .Bytes ()}, err
89
+ return Result {args : result .Args (), stdout : stdout .Bytes (), stderr : stderr .Bytes ()}, err
92
90
}
93
91
94
92
// Parse CTags output
@@ -103,13 +101,13 @@ func PreprocessSketchWithCtags(
103
101
if sourceData , err := sourceFile .ReadFile (); err == nil {
104
102
source = string (sourceData )
105
103
} else {
106
- return Result {args : result .Args (), stdout : verboseOutput .Bytes (), stderr : normalOutput .Bytes ()}, err
104
+ return Result {args : result .Args (), stdout : stdout .Bytes (), stderr : stderr .Bytes ()}, err
107
105
}
108
106
source = strings .ReplaceAll (source , "\r \n " , "\n " )
109
107
source = strings .ReplaceAll (source , "\r " , "\n " )
110
108
sourceRows := strings .Split (source , "\n " )
111
109
if isFirstFunctionOutsideOfSource (firstFunctionLine , sourceRows ) {
112
- return Result {args : result .Args (), stdout : verboseOutput .Bytes (), stderr : normalOutput .Bytes ()}, nil
110
+ return Result {args : result .Args (), stdout : stdout .Bytes (), stderr : stderr .Bytes ()}, nil
113
111
}
114
112
115
113
insertionLine := firstFunctionLine + lineOffset - 1
@@ -135,7 +133,7 @@ func PreprocessSketchWithCtags(
135
133
136
134
// Write back arduino-preprocess output to the sourceFile
137
135
err = sourceFile .WriteFile ([]byte (preprocessedSource ))
138
- return Result {args : result .Args (), stdout : verboseOutput .Bytes (), stderr : normalOutput .Bytes ()}, err
136
+ return Result {args : result .Args (), stdout : stdout .Bytes (), stderr : stderr .Bytes ()}, err
139
137
}
140
138
141
139
func composePrototypeSection (line int , prototypes []* ctags.Prototype ) string {
0 commit comments