Skip to content

Commit a143722

Browse files
committed
legacy: builder task progress is now transferred via TaskProgress callback
1 parent 2cb7fde commit a143722

File tree

14 files changed

+99
-83
lines changed

14 files changed

+99
-83
lines changed

cli/compile/compile.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ func run(cmd *cobra.Command, args []string) {
119119
DryRun: dryRun,
120120
Libraries: libraries,
121121
OptimizeForDebug: optimizeForDebug,
122-
}, os.Stdout, os.Stderr, viper.GetString("logging.level") == "debug")
122+
}, os.Stdout, os.Stderr, nil, viper.GetString("logging.level") == "debug")
123123

124124
if err != nil {
125125
feedback.Errorf("Error during build: %v", err)

commands/compile/compile.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ import (
4343
)
4444

4545
// Compile FIXMEDOC
46-
func Compile(ctx context.Context, req *rpc.CompileReq, outStream, errStream io.Writer, debug bool) (r *rpc.CompileResp, e error) {
46+
func Compile(ctx context.Context, req *rpc.CompileReq, outStream, errStream io.Writer, taskCB commands.TaskProgressCB, debug bool) (r *rpc.CompileResp, e error) {
4747

4848
tags := map[string]string{
4949
"fqbn": req.Fqbn,
@@ -114,6 +114,7 @@ func Compile(ctx context.Context, req *rpc.CompileReq, outStream, errStream io.W
114114
builderCtx.PackageManager = pm
115115
builderCtx.FQBN = fqbn
116116
builderCtx.SketchLocation = sketch.FullPath
117+
builderCtx.ProgressCB = taskCB
117118

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

commands/daemon/daemon.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ func (s *ArduinoCoreServerImpl) Compile(req *rpc.CompileReq, stream rpc.ArduinoC
127127
stream.Context(), req,
128128
utils.FeedStreamTo(func(data []byte) { stream.Send(&rpc.CompileResp{OutStream: data}) }),
129129
utils.FeedStreamTo(func(data []byte) { stream.Send(&rpc.CompileResp{ErrStream: data}) }),
130+
func(p *rpc.TaskProgress) { stream.Send(&rpc.CompileResp{TaskProgress: p}) },
130131
false) // Set debug to false
131132
if err != nil {
132133
return err

go.sum

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03
66
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
77
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
88
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
9+
github.com/arduino/arduino-builder v0.0.0-20200212104243-d59b903f9ee8 h1:QMta31FSrmmLdu9GqHy6gH7rJQ/kOz4chkUA0L25h80=
910
github.com/arduino/board-discovery v0.0.0-20180823133458-1ba29327fb0c h1:agh2JT96G8egU7FEb13L4dq3fnCN7lxXhJ86t69+W7s=
1011
github.com/arduino/board-discovery v0.0.0-20180823133458-1ba29327fb0c/go.mod h1:HK7SpkEax/3P+0w78iRQx1sz1vCDYYw9RXwHjQTB5i8=
1112
github.com/arduino/go-paths-helper v1.0.1 h1:utYXLM2RfFlc9qp/MJTIYp3t6ux/xM6mWjeEb/WLK4Q=

legacy/builder/builder.go

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

2525
bldr "github.com/arduino/arduino-cli/arduino/builder"
26-
"github.com/arduino/arduino-cli/legacy/builder/builder_utils"
2726
"github.com/arduino/arduino-cli/legacy/builder/constants"
2827
"github.com/arduino/arduino-cli/legacy/builder/phases"
2928
"github.com/arduino/arduino-cli/legacy/builder/types"
@@ -194,7 +193,7 @@ func runCommands(ctx *types.Context, commands []types.Command) error {
194193
return errors.WithStack(err)
195194
}
196195
ctx.Progress.CompleteStep()
197-
builder_utils.PrintProgressIfProgressEnabledAndMachineLogger(ctx)
196+
ctx.PushProgress()
198197
}
199198
return nil
200199
}

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

@@ -33,18 +32,6 @@ import (
3332
"github.com/pkg/errors"
3433
)
3534

36-
func PrintProgressIfProgressEnabledAndMachineLogger(ctx *types.Context) {
37-
38-
if !ctx.Progress.PrintEnabled {
39-
return
40-
}
41-
42-
log := ctx.GetLogger()
43-
if log.Name() == "machine" {
44-
log.Println(constants.LOG_LEVEL_INFO, constants.MSG_PROGRESS, strconv.FormatFloat(float64(ctx.Progress.Progress), 'f', 2, 32))
45-
}
46-
}
47-
4835
func CompileFilesRecursive(ctx *types.Context, sourcePath *paths.Path, buildPath *paths.Path, buildProperties *properties.Map, includes []string) (paths.PathList, error) {
4936
objectFiles, err := CompileFiles(ctx, sourcePath, false, buildPath, buildProperties, includes)
5037
if err != nil {
@@ -213,7 +200,7 @@ func compileFilesWithRecipe(ctx *types.Context, sourcePath *paths.Path, sources
213200
queue <- source
214201

215202
ctx.Progress.CompleteStep()
216-
PrintProgressIfProgressEnabledAndMachineLogger(ctx)
203+
ctx.PushProgress()
217204
}
218205
close(queue)
219206
wg.Wait()

legacy/builder/constants/constants.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ const MSG_MISSING_CORE_FOR_BOARD = "Selected board depends on '{0}' core (not in
109109
const MSG_PACKAGE_UNKNOWN = "{0}: Unknown package"
110110
const MSG_PATTERN_MISSING = "{0} pattern is missing"
111111
const MSG_PLATFORM_UNKNOWN = "Platform {0} (package {1}) is unknown"
112-
const MSG_PROGRESS = "Progress {0}"
113112
const MSG_PROP_IN_LIBRARY = "Missing '{0}' from library in {1}"
114113
const MSG_RUNNING_COMMAND = "Ts: {0} - Running: {1}"
115114
const MSG_RUNNING_RECIPE = "Running recipe: {0}"

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
bldr "github.com/arduino/arduino-cli/arduino/builder"
22-
"github.com/arduino/arduino-cli/legacy/builder/builder_utils"
2322
"github.com/arduino/arduino-cli/legacy/builder/types"
2423
"github.com/arduino/go-paths-helper"
2524
"github.com/pkg/errors"
@@ -51,7 +50,7 @@ func (s *ContainerSetupHardwareToolsLibsSketchAndProps) Run(ctx *types.Context)
5150
return errors.WithStack(err)
5251
}
5352
ctx.Progress.CompleteStep()
54-
builder_utils.PrintProgressIfProgressEnabledAndMachineLogger(ctx)
53+
ctx.PushProgress()
5554
}
5655

5756
if ctx.SketchLocation != nil {
@@ -73,7 +72,7 @@ func (s *ContainerSetupHardwareToolsLibsSketchAndProps) Run(ctx *types.Context)
7372
ctx.Sketch = types.SketchToLegacy(sketch)
7473
}
7574
ctx.Progress.CompleteStep()
76-
builder_utils.PrintProgressIfProgressEnabledAndMachineLogger(ctx)
75+
ctx.PushProgress()
7776

7877
commands = []types.Command{
7978
&SetupBuildProperties{},
@@ -89,7 +88,7 @@ func (s *ContainerSetupHardwareToolsLibsSketchAndProps) Run(ctx *types.Context)
8988
return errors.WithStack(err)
9089
}
9190
ctx.Progress.CompleteStep()
92-
builder_utils.PrintProgressIfProgressEnabledAndMachineLogger(ctx)
91+
ctx.PushProgress()
9392
}
9493

9594
return nil

legacy/builder/phases/libraries_builder.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ func compileLibraries(ctx *types.Context, libraries libraries.List, buildPath *p
155155
objectFiles = append(objectFiles, libraryObjectFiles...)
156156

157157
ctx.Progress.CompleteStep()
158-
builder_utils.PrintProgressIfProgressEnabledAndMachineLogger(ctx)
158+
ctx.PushProgress()
159159
}
160160

161161
return objectFiles, nil

legacy/builder/types/context.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,17 @@ import (
2424
"github.com/arduino/arduino-cli/arduino/libraries"
2525
"github.com/arduino/arduino-cli/arduino/libraries/librariesmanager"
2626
"github.com/arduino/arduino-cli/arduino/libraries/librariesresolver"
27+
"github.com/arduino/arduino-cli/commands"
2728
"github.com/arduino/arduino-cli/legacy/builder/i18n"
29+
rpc "github.com/arduino/arduino-cli/rpc/commands"
2830
paths "github.com/arduino/go-paths-helper"
2931
properties "github.com/arduino/go-properties-orderedmap"
3032
)
3133

3234
type ProgressStruct struct {
33-
PrintEnabled bool
34-
Progress float32
35-
StepAmount float32
36-
Parent *ProgressStruct
35+
Progress float32
36+
StepAmount float32
37+
Parent *ProgressStruct
3738
}
3839

3940
func (p *ProgressStruct) AddSubSteps(steps int) {
@@ -138,6 +139,8 @@ type Context struct {
138139

139140
// Dry run, only create progress map
140141
Progress ProgressStruct
142+
// Send progress events to this callback
143+
ProgressCB commands.TaskProgressCB
141144

142145
// Contents of a custom build properties file (line by line)
143146
CustomBuildProperties []string
@@ -212,3 +215,9 @@ func (ctx *Context) GetLogger() i18n.Logger {
212215
func (ctx *Context) SetLogger(l i18n.Logger) {
213216
ctx.logger = l
214217
}
218+
219+
func (ctx *Context) PushProgress() {
220+
if ctx.ProgressCB != nil {
221+
ctx.ProgressCB(&rpc.TaskProgress{PercentCompleted: ctx.Progress.Progress})
222+
}
223+
}

0 commit comments

Comments
 (0)