Skip to content

Commit ce6c187

Browse files
committed
Defaults to runtime.NumCPU() if specified jobs number is 0
1 parent 0785c72 commit ce6c187

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

Diff for: commands/compile/compile.go

+1-6
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323
"fmt"
2424
"io"
2525
"path/filepath"
26-
"runtime"
2726
"sort"
2827
"strings"
2928

@@ -116,11 +115,7 @@ func Compile(ctx context.Context, req *rpc.CompileReq, outStream, errStream io.W
116115

117116
builderCtx.CoreBuildCachePath = paths.TempDir().Join("arduino-core-cache")
118117

119-
jobs := runtime.NumCPU()
120-
if req.GetJobs() > 0 {
121-
jobs = int(req.GetJobs())
122-
}
123-
builderCtx.Jobs = jobs
118+
builderCtx.Jobs = int(req.GetJobs())
124119

125120
builderCtx.USBVidPid = req.GetVidPid()
126121
builderCtx.WarningsLevel = req.GetWarnings()

Diff for: legacy/builder/builder_utils/utils.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import (
3333
"os"
3434
"os/exec"
3535
"path/filepath"
36+
"runtime"
3637
"strconv"
3738
"strings"
3839
"sync"
@@ -192,7 +193,11 @@ func compileFilesWithRecipe(ctx *types.Context, sourcePath *paths.Path, sources
192193

193194
// Spawn jobs runners
194195
var wg sync.WaitGroup
195-
for i := 0; i < ctx.Jobs; i++ {
196+
jobs := ctx.Jobs
197+
if jobs == 0 {
198+
jobs = runtime.NumCPU()
199+
}
200+
for i := 0; i < jobs; i++ {
196201
wg.Add(1)
197202
go func() {
198203
for source := range queue {

0 commit comments

Comments
 (0)