From 422aa87f40bfff9b826fd619fa3b3923b11e5f69 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Mon, 25 Sep 2023 16:49:49 +0200 Subject: [PATCH] [skip-changelog] Fixed 'compile --preprocess' output (#2339) --- arduino/builder/builder.go | 18 +++++++++--------- commands/compile/compile.go | 10 ++++++---- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/arduino/builder/builder.go b/arduino/builder/builder.go index e65f744ab0c..8f00d00a4c7 100644 --- a/arduino/builder/builder.go +++ b/arduino/builder/builder.go @@ -243,10 +243,17 @@ func (b *Builder) ImportedLibraries() libraries.List { } // Preprocess fixdoc -func (b *Builder) Preprocess() error { +func (b *Builder) Preprocess() ([]byte, error) { b.Progress.AddSubSteps(6) defer b.Progress.RemoveSubSteps() - return b.preprocess() + + if err := b.preprocess(); err != nil { + return nil, err + } + + // Return arduino-preprocessed source + preprocessedSketch, err := b.sketchBuildPath.Join(b.sketch.MainFile.Base() + ".cpp").ReadFile() + return preprocessedSketch, err } func (b *Builder) preprocess() error { @@ -303,13 +310,6 @@ func (b *Builder) preprocess() error { b.Progress.CompleteStep() b.Progress.PushProgress() - // Output arduino-preprocessed source - preprocessedSketch, err := b.sketchBuildPath.Join(b.sketch.MainFile.Base() + ".cpp").ReadFile() - if err != nil { - return err - } - b.logger.WriteStdout(preprocessedSketch) - return nil } diff --git a/commands/compile/compile.go b/commands/compile/compile.go index b04e4cd4914..69b040216b8 100644 --- a/commands/compile/compile.go +++ b/commands/compile/compile.go @@ -240,11 +240,13 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream if req.GetPreprocess() { // Just output preprocessed source code and exit - compileErr := sketchBuilder.Preprocess() - if compileErr != nil { - compileErr = &arduino.CompileFailedError{Message: compileErr.Error()} + preprocessedSketch, err := sketchBuilder.Preprocess() + if err != nil { + err = &arduino.CompileFailedError{Message: err.Error()} + return r, err } - return r, compileErr + _, err = outStream.Write(preprocessedSketch) + return r, err } defer func() {