Skip to content

Commit b8f94f5

Browse files
committed
The number of jobs in library detection now follows --jobs flag
1 parent 14a3adb commit b8f94f5

File tree

4 files changed

+14
-6
lines changed

4 files changed

+14
-6
lines changed

internal/arduino/builder/builder.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@ func (b *Builder) preprocess() error {
322322
b.librariesBuildPath,
323323
b.buildProperties,
324324
b.targetPlatform.Platform.Architecture,
325+
b.jobs,
325326
)
326327
if err != nil {
327328
return err

internal/arduino/builder/internal/detector/detector.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,9 @@ func (l *SketchLibrariesDetector) FindIncludes(
209209
librariesBuildPath *paths.Path,
210210
buildProperties *properties.Map,
211211
platformArch string,
212+
jobs int,
212213
) error {
213-
err := l.findIncludes(ctx, buildPath, buildCorePath, buildVariantPath, sketchBuildPath, sketch, librariesBuildPath, buildProperties, platformArch)
214+
err := l.findIncludes(ctx, buildPath, buildCorePath, buildVariantPath, sketchBuildPath, sketch, librariesBuildPath, buildProperties, platformArch, jobs)
214215
if err != nil && l.onlyUpdateCompilationDatabase {
215216
l.logger.Info(
216217
fmt.Sprintf(
@@ -234,6 +235,7 @@ func (l *SketchLibrariesDetector) findIncludes(
234235
librariesBuildPath *paths.Path,
235236
buildProperties *properties.Map,
236237
platformArch string,
238+
jobs int,
237239
) error {
238240
librariesResolutionCache := buildPath.Join("libraries.cache")
239241
if l.useCachedLibrariesResolution && librariesResolutionCache.Exist() {
@@ -256,7 +258,7 @@ func (l *SketchLibrariesDetector) findIncludes(
256258
}
257259

258260
// Pre-run cache entries
259-
l.preRunner = runner.New(ctx)
261+
l.preRunner = runner.New(ctx, jobs)
260262
for _, entry := range l.cache.EntriesAhead() {
261263
if entry.Compile != nil && entry.CompileTask != nil {
262264
upToDate, _ := entry.Compile.ObjFileIsUpToDate()
@@ -307,7 +309,7 @@ func (l *SketchLibrariesDetector) findIncludes(
307309

308310
// Create a new pre-runner if the previous one was cancelled
309311
if l.preRunner == nil {
310-
l.preRunner = runner.New(ctx)
312+
l.preRunner = runner.New(ctx, jobs)
311313
// Push in the remainder of the queue
312314
for _, sourceFile := range *sourceFileQueue {
313315
l.preRunner.Enqueue(l.gccPreprocessTask(sourceFile, buildProperties))

internal/arduino/builder/internal/runner/runner.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ func (cmd *enqueuedCommand) String() string {
4141
return cmd.task.String()
4242
}
4343

44-
func New(inCtx context.Context) *Runner {
44+
// New creates a new Runner with the given number of workers.
45+
// If workers is 0, the number of workers will be the number of available CPUs.
46+
func New(inCtx context.Context, workers int) *Runner {
4547
ctx, cancel := context.WithCancel(inCtx)
4648
queue := make(chan *enqueuedCommand, 1000)
4749
r := &Runner{
@@ -52,7 +54,10 @@ func New(inCtx context.Context) *Runner {
5254
}
5355

5456
// Spawn workers
55-
for i := 0; i < runtime.NumCPU(); i++ {
57+
if workers == 0 {
58+
workers = runtime.NumCPU()
59+
}
60+
for i := 0; i < workers; i++ {
5661
r.wg.Add(1)
5762
go func() {
5863
worker(ctx, queue)

internal/arduino/builder/internal/runner/runner_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import (
2828
func TestRunMultipleTask(t *testing.T) {
2929
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
3030
defer cancel()
31-
r := runner.New(ctx)
31+
r := runner.New(ctx, 0)
3232
r.Enqueue(runner.NewTask("bash", "-c", "sleep 1 ; echo -n 0"))
3333
r.Enqueue(runner.NewTask("bash", "-c", "sleep 2 ; echo -n 1"))
3434
r.Enqueue(runner.NewTask("bash", "-c", "sleep 3 ; echo -n 2"))

0 commit comments

Comments
 (0)