Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

bugfix: Kill compile processes that generates too much output #2883

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 12, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
bugfix: Kill compile processes that generates too much output
  • Loading branch information
cmaglie committed May 12, 2025
commit a8ed5e676d9d3fcd59ba6b795991db3c8ef7ad50
41 changes: 37 additions & 4 deletions 41 internal/arduino/builder/internal/preprocessor/gcc.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package preprocessor

import (
"bytes"
"context"
"errors"
"fmt"
Expand Down Expand Up @@ -77,10 +78,42 @@ func GCC(
if err != nil {
return Result{}, err
}
stdout, stderr, err := proc.RunAndCaptureOutput(ctx)

// Append gcc arguments to stdout
stdout = append([]byte(fmt.Sprintln(strings.Join(args, " "))), stdout...)
stdout := bytes.NewBuffer(nil)
stderr := bytes.NewBuffer(nil)

return Result{args: proc.GetArgs(), stdout: stdout, stderr: stderr}, err
ctx, cancel := context.WithCancel(ctx)
defer cancel()
count := 0
stderrLimited := writerFunc(func(p []byte) (int, error) {
// Limit the size of the stderr buffer to 100KB
n, err := stderr.Write(p)
count += n
if count > 100*1024 {
cancel()
fmt.Fprintln(stderr, i18n.Tr("Compiler error output has been truncated."))
}
return n, err
})

proc.RedirectStdoutTo(stdout)
proc.RedirectStderrTo(stderrLimited)

// Append gcc arguments to stdout before running the command
fmt.Fprintln(stdout, strings.Join(args, " "))

if err := proc.Start(); err != nil {
return Result{}, err
}

// Wait for the process to finish
err = proc.WaitWithinContext(ctx)

return Result{args: proc.GetArgs(), stdout: stdout.Bytes(), stderr: stderr.Bytes()}, err
}

type writerFunc func(p []byte) (n int, err error)

func (f writerFunc) Write(p []byte) (n int, err error) {
return f(p)
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.