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() {