Skip to content

Commit 71e59de

Browse files
committed
legacy: builder task progress is now transferred via TaskProgress callback
1 parent 9b290d4 commit 71e59de

File tree

6 files changed

+19
-25
lines changed

6 files changed

+19
-25
lines changed

commands/compile/compile.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
132132
builderCtx.PackageManager = pm
133133
builderCtx.FQBN = fqbn
134134
builderCtx.SketchLocation = sk.FullPath
135+
builderCtx.ProgressCB = progressCB
135136

136137
// FIXME: This will be redundant when arduino-builder will be part of the cli
137138
builderCtx.HardwareDirs = configuration.HardwareDirectories(configuration.Settings)

legacy/builder/builder.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323

2424
"github.com/arduino/arduino-cli/arduino/sketch"
2525
"github.com/arduino/arduino-cli/i18n"
26-
"github.com/arduino/arduino-cli/legacy/builder/builder_utils"
2726
"github.com/arduino/arduino-cli/legacy/builder/phases"
2827
"github.com/arduino/arduino-cli/legacy/builder/types"
2928
"github.com/arduino/arduino-cli/legacy/builder/utils"
@@ -195,7 +194,7 @@ func runCommands(ctx *types.Context, commands []types.Command) error {
195194
return errors.WithStack(err)
196195
}
197196
ctx.Progress.CompleteStep()
198-
builder_utils.PrintProgressIfProgressEnabledAndMachineLogger(ctx)
197+
ctx.PushProgress()
199198
}
200199
return nil
201200
}

legacy/builder/builder_utils/utils.go

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"os/exec"
2121
"path/filepath"
2222
"runtime"
23-
"strconv"
2423
"strings"
2524
"sync"
2625

@@ -35,18 +34,6 @@ import (
3534

3635
var tr = i18n.Tr
3736

38-
func PrintProgressIfProgressEnabledAndMachineLogger(ctx *types.Context) {
39-
40-
if !ctx.Progress.PrintEnabled {
41-
return
42-
}
43-
44-
log := ctx.GetLogger()
45-
if log.Name() == "machine" {
46-
log.Println(constants.LOG_LEVEL_INFO, tr("Progress {0}"), strconv.FormatFloat(float64(ctx.Progress.Progress), 'f', 2, 32))
47-
}
48-
}
49-
5037
func CompileFilesRecursive(ctx *types.Context, sourcePath *paths.Path, buildPath *paths.Path, buildProperties *properties.Map, includes []string) (paths.PathList, error) {
5138
objectFiles, err := CompileFiles(ctx, sourcePath, false, buildPath, buildProperties, includes)
5239
if err != nil {
@@ -215,7 +202,7 @@ func compileFilesWithRecipe(ctx *types.Context, sourcePath *paths.Path, sources
215202
queue <- source
216203

217204
ctx.Progress.CompleteStep()
218-
PrintProgressIfProgressEnabledAndMachineLogger(ctx)
205+
ctx.PushProgress()
219206
}
220207
close(queue)
221208
wg.Wait()

legacy/builder/container_setup.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import (
1919
"fmt"
2020

2121
sk "github.com/arduino/arduino-cli/arduino/sketch"
22-
"github.com/arduino/arduino-cli/legacy/builder/builder_utils"
2322
"github.com/arduino/arduino-cli/legacy/builder/types"
2423
"github.com/pkg/errors"
2524
)
@@ -50,7 +49,7 @@ func (s *ContainerSetupHardwareToolsLibsSketchAndProps) Run(ctx *types.Context)
5049
return errors.WithStack(err)
5150
}
5251
ctx.Progress.CompleteStep()
53-
builder_utils.PrintProgressIfProgressEnabledAndMachineLogger(ctx)
52+
ctx.PushProgress()
5453
}
5554

5655
if ctx.SketchLocation != nil {
@@ -78,7 +77,7 @@ func (s *ContainerSetupHardwareToolsLibsSketchAndProps) Run(ctx *types.Context)
7877
ctx.Sketch = sketch
7978
}
8079
ctx.Progress.CompleteStep()
81-
builder_utils.PrintProgressIfProgressEnabledAndMachineLogger(ctx)
80+
ctx.PushProgress()
8281

8382
commands = []types.Command{
8483
&SetupBuildProperties{},
@@ -94,7 +93,7 @@ func (s *ContainerSetupHardwareToolsLibsSketchAndProps) Run(ctx *types.Context)
9493
return errors.WithStack(err)
9594
}
9695
ctx.Progress.CompleteStep()
97-
builder_utils.PrintProgressIfProgressEnabledAndMachineLogger(ctx)
96+
ctx.PushProgress()
9897
}
9998

10099
return nil

legacy/builder/phases/libraries_builder.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ func compileLibraries(ctx *types.Context, libraries libraries.List, buildPath *p
123123
objectFiles.AddAll(libraryObjectFiles)
124124

125125
ctx.Progress.CompleteStep()
126-
builder_utils.PrintProgressIfProgressEnabledAndMachineLogger(ctx)
126+
ctx.PushProgress()
127127
}
128128

129129
return objectFiles, nil

legacy/builder/types/context.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,17 @@ import (
2626
"github.com/arduino/arduino-cli/arduino/libraries/librariesmanager"
2727
"github.com/arduino/arduino-cli/arduino/libraries/librariesresolver"
2828
"github.com/arduino/arduino-cli/arduino/sketch"
29+
"github.com/arduino/arduino-cli/commands"
2930
"github.com/arduino/arduino-cli/legacy/builder/i18n"
3031
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
3132
paths "github.com/arduino/go-paths-helper"
3233
properties "github.com/arduino/go-properties-orderedmap"
3334
)
3435

3536
type ProgressStruct struct {
36-
PrintEnabled bool
37-
Progress float32
38-
StepAmount float32
39-
Parent *ProgressStruct
37+
Progress float32
38+
StepAmount float32
39+
Parent *ProgressStruct
4040
}
4141

4242
func (p *ProgressStruct) AddSubSteps(steps int) {
@@ -144,6 +144,8 @@ type Context struct {
144144

145145
// Dry run, only create progress map
146146
Progress ProgressStruct
147+
// Send progress events to this callback
148+
ProgressCB commands.TaskProgressCB
147149

148150
// Contents of a custom build properties file (line by line)
149151
CustomBuildProperties []string
@@ -254,3 +256,9 @@ func (ctx *Context) GetLogger() i18n.Logger {
254256
func (ctx *Context) SetLogger(l i18n.Logger) {
255257
ctx.logger = l
256258
}
259+
260+
func (ctx *Context) PushProgress() {
261+
if ctx.ProgressCB != nil {
262+
ctx.ProgressCB(&rpc.TaskProgress{Percent: ctx.Progress.Progress})
263+
}
264+
}

0 commit comments

Comments
 (0)