Skip to content

Commit 7df8ea2

Browse files
committed
Builder now support parsing of compiler output
1 parent 0bfad0c commit 7df8ea2

File tree

6 files changed

+44
-0
lines changed

6 files changed

+44
-0
lines changed

arduino/builder/builder.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222

2323
"github.com/arduino/arduino-cli/arduino/builder/internal/compilation"
2424
"github.com/arduino/arduino-cli/arduino/builder/internal/detector"
25+
"github.com/arduino/arduino-cli/arduino/builder/internal/diagnostics"
2526
"github.com/arduino/arduino-cli/arduino/builder/internal/logger"
2627
"github.com/arduino/arduino-cli/arduino/builder/internal/progress"
2728
"github.com/arduino/arduino-cli/arduino/cores"
@@ -85,6 +86,10 @@ type Builder struct {
8586
buildOptions *buildOptions
8687

8788
libsDetector *detector.SketchLibrariesDetector
89+
90+
// This is a function used to parse the output of the compiler
91+
// It is used to extract errors and warnings
92+
compilerOutputParser diagnostics.CompilerOutputParserCB
8893
}
8994

9095
// buildArtifacts contains the result of various build

arduino/builder/core.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ func (b *Builder) compileCore() (*paths.Path, paths.PathList, error) {
7676
b.onlyUpdateCompilationDatabase,
7777
b.compilationDatabase,
7878
b.jobs,
79+
b.compilerOutputParser,
7980
b.logger,
8081
b.Progress,
8182
)
@@ -127,6 +128,7 @@ func (b *Builder) compileCore() (*paths.Path, paths.PathList, error) {
127128
b.onlyUpdateCompilationDatabase,
128129
b.compilationDatabase,
129130
b.jobs,
131+
b.compilerOutputParser,
130132
b.logger,
131133
b.Progress,
132134
)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// This file is part of arduino-cli.
2+
//
3+
// Copyright 2023 ARDUINO SA (http://www.arduino.cc/)
4+
//
5+
// This software is released under the GNU General Public License version 3,
6+
// which covers the main part of arduino-cli.
7+
// The terms of this license can be found at:
8+
// https://www.gnu.org/licenses/gpl-3.0.en.html
9+
//
10+
// You can be released from the requirements of the above licenses by purchasing
11+
// a commercial license. Buying such a license is mandatory if you want to
12+
// modify or otherwise use the software for commercial activities involving the
13+
// Arduino software without disclosing the source code of your own applications.
14+
// To purchase a commercial license, send an email to [email protected].
15+
16+
package diagnostics
17+
18+
type CompilerOutputParserCB func(cmdline []string, out []byte)

arduino/builder/internal/utils/utils.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"unicode"
2828

2929
"github.com/arduino/arduino-cli/arduino/builder/internal/compilation"
30+
"github.com/arduino/arduino-cli/arduino/builder/internal/diagnostics"
3031
"github.com/arduino/arduino-cli/arduino/builder/internal/logger"
3132
"github.com/arduino/arduino-cli/arduino/builder/internal/progress"
3233
"github.com/arduino/arduino-cli/arduino/globals"
@@ -356,6 +357,7 @@ func CompileFiles(
356357
onlyUpdateCompilationDatabase bool,
357358
compilationDatabase *compilation.Database,
358359
jobs int,
360+
compilerOutputParser diagnostics.CompilerOutputParserCB,
359361
builderLogger *logger.BuilderLogger,
360362
progress *progress.Struct,
361363
) (paths.PathList, error) {
@@ -366,6 +368,7 @@ func CompileFiles(
366368
sourceDir,
367369
false,
368370
buildPath, buildProperties, includes,
371+
compilerOutputParser,
369372
builderLogger,
370373
progress,
371374
)
@@ -379,6 +382,7 @@ func CompileFilesRecursive(
379382
onlyUpdateCompilationDatabase bool,
380383
compilationDatabase *compilation.Database,
381384
jobs int,
385+
compilerOutputParser diagnostics.CompilerOutputParserCB,
382386
builderLogger *logger.BuilderLogger,
383387
progress *progress.Struct,
384388
) (paths.PathList, error) {
@@ -389,6 +393,7 @@ func CompileFilesRecursive(
389393
sourceDir,
390394
true,
391395
buildPath, buildProperties, includes,
396+
compilerOutputParser,
392397
builderLogger,
393398
progress,
394399
)
@@ -403,6 +408,7 @@ func compileFiles(
403408
buildPath *paths.Path,
404409
buildProperties *properties.Map,
405410
includes []string,
411+
compilerOutputParser diagnostics.CompilerOutputParserCB,
406412
builderLogger *logger.BuilderLogger,
407413
progress *progress.Struct,
408414
) (paths.PathList, error) {
@@ -437,6 +443,7 @@ func compileFiles(
437443
compilationDatabase,
438444
onlyUpdateCompilationDatabase,
439445
sourceDir, source, buildPath, buildProperties, includes, recipe,
446+
compilerOutputParser,
440447
builderLogger,
441448
)
442449
if builderLogger.Verbose() {
@@ -502,6 +509,7 @@ func compileFileWithRecipe(
502509
buildProperties *properties.Map,
503510
includes []string,
504511
recipe string,
512+
compilerOutputParser diagnostics.CompilerOutputParserCB,
505513
builderLogger *logger.BuilderLogger,
506514
) (*paths.Path, []byte, []byte, []byte, error) {
507515
verboseStdout, verboseInfo, errOut := &bytes.Buffer{}, &bytes.Buffer{}, &bytes.Buffer{}
@@ -552,6 +560,12 @@ func compileFileWithRecipe(
552560
}
553561
errOut.Write(stderr)
554562

563+
// Parse the output of the compiler to gather errors and warnings...
564+
if compilerOutputParser != nil {
565+
compilerOutputParser(command.GetArgs(), stdout)
566+
compilerOutputParser(command.GetArgs(), stderr)
567+
}
568+
555569
// ...and then return the error
556570
if err != nil {
557571
return nil, verboseInfo.Bytes(), verboseStdout.Bytes(), errOut.Bytes(), errors.WithStack(err)

arduino/builder/libraries.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ func (b *Builder) compileLibrary(library *libraries.Library, includes []string)
195195
b.onlyUpdateCompilationDatabase,
196196
b.compilationDatabase,
197197
b.jobs,
198+
b.compilerOutputParser,
198199
b.logger,
199200
b.Progress,
200201
)
@@ -226,6 +227,7 @@ func (b *Builder) compileLibrary(library *libraries.Library, includes []string)
226227
b.onlyUpdateCompilationDatabase,
227228
b.compilationDatabase,
228229
b.jobs,
230+
b.compilerOutputParser,
229231
b.logger,
230232
b.Progress,
231233
)
@@ -241,6 +243,7 @@ func (b *Builder) compileLibrary(library *libraries.Library, includes []string)
241243
b.onlyUpdateCompilationDatabase,
242244
b.compilationDatabase,
243245
b.jobs,
246+
b.compilerOutputParser,
244247
b.logger,
245248
b.Progress,
246249
)

arduino/builder/sketch.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ func (b *Builder) BuildSketch(includesFolders paths.PathList) error {
187187
b.onlyUpdateCompilationDatabase,
188188
b.compilationDatabase,
189189
b.jobs,
190+
b.compilerOutputParser,
190191
b.logger,
191192
b.Progress,
192193
)
@@ -202,6 +203,7 @@ func (b *Builder) BuildSketch(includesFolders paths.PathList) error {
202203
b.onlyUpdateCompilationDatabase,
203204
b.compilationDatabase,
204205
b.jobs,
206+
b.compilerOutputParser,
205207
b.logger,
206208
b.Progress,
207209
)

0 commit comments

Comments
 (0)