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