Skip to content

Commit 55ee2f5

Browse files
committed
The number of jobs in library detection now follows --jobs flag
1 parent 8afa7d8 commit 55ee2f5

File tree

4 files changed

+14
-6
lines changed

4 files changed

+14
-6
lines changed

internal/arduino/builder/builder.go

+1
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ func (b *Builder) preprocess() error {
321321
b.librariesBuildPath,
322322
b.buildProperties,
323323
b.targetPlatform.Platform.Architecture,
324+
b.jobs,
324325
)
325326
if err != nil {
326327
return err

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

+5-3
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,9 @@ func (l *SketchLibrariesDetector) FindIncludes(
191191
librariesBuildPath *paths.Path,
192192
buildProperties *properties.Map,
193193
platformArch string,
194+
jobs int,
194195
) error {
195-
err := l.findIncludes(ctx, buildPath, buildCorePath, buildVariantPath, sketchBuildPath, sketch, librariesBuildPath, buildProperties, platformArch)
196+
err := l.findIncludes(ctx, buildPath, buildCorePath, buildVariantPath, sketchBuildPath, sketch, librariesBuildPath, buildProperties, platformArch, jobs)
196197
if err != nil && l.onlyUpdateCompilationDatabase {
197198
l.logger.Info(
198199
fmt.Sprintf(
@@ -216,6 +217,7 @@ func (l *SketchLibrariesDetector) findIncludes(
216217
librariesBuildPath *paths.Path,
217218
buildProperties *properties.Map,
218219
platformArch string,
220+
jobs int,
219221
) error {
220222
librariesResolutionCache := buildPath.Join("libraries.cache")
221223
if l.useCachedLibrariesResolution && librariesResolutionCache.Exist() {
@@ -238,7 +240,7 @@ func (l *SketchLibrariesDetector) findIncludes(
238240
}
239241

240242
// Pre-run cache entries
241-
l.preRunner = runner.New(ctx)
243+
l.preRunner = runner.New(ctx, jobs)
242244
for _, entry := range l.cache.EntriesAhead() {
243245
if entry.Compile != nil && entry.CompileTask != nil {
244246
upToDate, _ := entry.Compile.ObjFileIsUpToDate()
@@ -279,7 +281,7 @@ func (l *SketchLibrariesDetector) findIncludes(
279281

280282
// Create a new pre-runner if the previous one was cancelled
281283
if l.preRunner == nil {
282-
l.preRunner = runner.New(ctx)
284+
l.preRunner = runner.New(ctx, jobs)
283285
// Push in the remainder of the queue
284286
for _, sourceFile := range *sourceFileQueue {
285287
l.preRunner.Enqueue(l.gccPreprocessTask(sourceFile, buildProperties))

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

+7-2
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

+1-1
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)