Skip to content

Commit

Permalink
[skip-changelog] Fixed 'compile --preprocess' output (#2339)
Browse files Browse the repository at this point in the history
  • Loading branch information
cmaglie authored Sep 25, 2023
1 parent 5a4f48b commit 422aa87
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
18 changes: 9 additions & 9 deletions arduino/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}

Expand Down
10 changes: 6 additions & 4 deletions commands/compile/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 422aa87

Please sign in to comment.