Skip to content

Commit 9715450

Browse files
remove Progress from Context
1 parent d3d4ed6 commit 9715450

File tree

11 files changed

+65
-96
lines changed

11 files changed

+65
-96
lines changed

arduino/builder/builder.go

+10
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"fmt"
2121

2222
"github.com/arduino/arduino-cli/arduino/builder/logger"
23+
"github.com/arduino/arduino-cli/arduino/builder/progress"
2324
"github.com/arduino/arduino-cli/arduino/cores"
2425
"github.com/arduino/arduino-cli/arduino/sketch"
2526
"github.com/arduino/go-paths-helper"
@@ -59,6 +60,9 @@ type Builder struct {
5960
// Set to true to skip build and produce only Compilation Database
6061
onlyUpdateCompilationDatabase bool
6162

63+
// Progress of all various steps
64+
Progress *progress.Struct
65+
6266
*BuildOptionsManager
6367
}
6468

@@ -78,6 +82,7 @@ func NewBuilder(
7882
sourceOverrides map[string]string,
7983
onlyUpdateCompilationDatabase bool,
8084
logger *logger.BuilderLogger,
85+
progressStats *progress.Struct,
8186
) (*Builder, error) {
8287
buildProperties := properties.NewMap()
8388
if boardBuildProperties != nil {
@@ -126,6 +131,10 @@ func NewBuilder(
126131
return nil, ErrSketchCannotBeLocatedInBuildPath
127132
}
128133

134+
if progressStats == nil {
135+
progressStats = progress.New(nil)
136+
}
137+
129138
return &Builder{
130139
sketch: sk,
131140
buildProperties: buildProperties,
@@ -140,6 +149,7 @@ func NewBuilder(
140149
clean: clean,
141150
sourceOverrides: sourceOverrides,
142151
onlyUpdateCompilationDatabase: onlyUpdateCompilationDatabase,
152+
Progress: progressStats,
143153
BuildOptionsManager: NewBuildOptionsManager(
144154
hardwareDirs, builtInToolsDirs, otherLibrariesDirs,
145155
builtInLibrariesDirs, buildPath,

arduino/builder/core.go

+3-11
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,10 @@ import (
2424

2525
"github.com/arduino/arduino-cli/arduino/builder/compilation"
2626
"github.com/arduino/arduino-cli/arduino/builder/cpp"
27-
"github.com/arduino/arduino-cli/arduino/builder/progress"
2827
"github.com/arduino/arduino-cli/arduino/builder/utils"
2928
"github.com/arduino/arduino-cli/arduino/cores"
3029
"github.com/arduino/arduino-cli/buildcache"
3130
f "github.com/arduino/arduino-cli/internal/algorithms"
32-
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
3331
"github.com/arduino/go-paths-helper"
3432
"github.com/pkg/errors"
3533
)
@@ -38,7 +36,6 @@ import (
3836
func (b *Builder) BuildCore(
3937
actualPlatform *cores.PlatformRelease,
4038
compilationDatabase *compilation.Database,
41-
progress *progress.Struct, progressCB rpc.TaskProgressCB,
4239
) (paths.PathList, *paths.Path, error) {
4340
if err := b.coreBuildPath.MkdirAll(); err != nil {
4441
return nil, nil, errors.WithStack(err)
@@ -56,11 +53,7 @@ func (b *Builder) BuildCore(
5653
}
5754
}
5855

59-
archiveFile, objectFiles, err := b.compileCore(
60-
actualPlatform,
61-
compilationDatabase,
62-
progress, progressCB,
63-
)
56+
archiveFile, objectFiles, err := b.compileCore(actualPlatform, compilationDatabase)
6457
if err != nil {
6558
return nil, nil, errors.WithStack(err)
6659
}
@@ -71,7 +64,6 @@ func (b *Builder) BuildCore(
7164
func (b *Builder) compileCore(
7265
actualPlatform *cores.PlatformRelease,
7366
compilationDatabase *compilation.Database,
74-
progress *progress.Struct, progressCB rpc.TaskProgressCB,
7567
) (*paths.Path, paths.PathList, error) {
7668
coreFolder := b.buildProperties.GetPath("build.core.path")
7769
variantFolder := b.buildProperties.GetPath("build.variant.path")
@@ -92,7 +84,7 @@ func (b *Builder) compileCore(
9284
compilationDatabase,
9385
b.jobs,
9486
b.logger,
95-
progress, progressCB,
87+
b.Progress,
9688
)
9789
if err != nil {
9890
return nil, nil, errors.WithStack(err)
@@ -143,7 +135,7 @@ func (b *Builder) compileCore(
143135
compilationDatabase,
144136
b.jobs,
145137
b.logger,
146-
progress, progressCB,
138+
b.Progress,
147139
)
148140
if err != nil {
149141
return nil, nil, errors.WithStack(err)

arduino/builder/libraries.go

+9-28
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,10 @@ import (
2121

2222
"github.com/arduino/arduino-cli/arduino/builder/compilation"
2323
"github.com/arduino/arduino-cli/arduino/builder/cpp"
24-
"github.com/arduino/arduino-cli/arduino/builder/progress"
2524
"github.com/arduino/arduino-cli/arduino/builder/utils"
2625
"github.com/arduino/arduino-cli/arduino/cores"
2726
"github.com/arduino/arduino-cli/arduino/libraries"
2827
f "github.com/arduino/arduino-cli/internal/algorithms"
29-
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
3028
"github.com/arduino/go-paths-helper"
3129
"github.com/arduino/go-properties-orderedmap"
3230
"github.com/pkg/errors"
@@ -44,7 +42,6 @@ func (b *Builder) BuildLibraries(
4442
includesFolders paths.PathList,
4543
importedLibraries libraries.List,
4644
compilationDatabase *compilation.Database,
47-
progress *progress.Struct, progressCB rpc.TaskProgressCB,
4845
) (paths.PathList, error) {
4946
includes := f.Map(includesFolders.AsStrings(), cpp.WrapWithHyphenI)
5047
libs := importedLibraries
@@ -53,11 +50,7 @@ func (b *Builder) BuildLibraries(
5350
return nil, errors.WithStack(err)
5451
}
5552

56-
librariesObjectFiles, err := b.compileLibraries(
57-
libs, includes,
58-
compilationDatabase,
59-
progress, progressCB,
60-
)
53+
librariesObjectFiles, err := b.compileLibraries(libs, includes, compilationDatabase)
6154
if err != nil {
6255
return nil, errors.WithStack(err)
6356
}
@@ -124,34 +117,23 @@ func (b *Builder) findExpectedPrecompiledLibFolder(
124117
return nil
125118
}
126119

127-
func (b *Builder) compileLibraries(
128-
libraries libraries.List, includes []string,
129-
compilationDatabase *compilation.Database,
130-
progress *progress.Struct, progressCB rpc.TaskProgressCB,
131-
) (paths.PathList, error) {
132-
progress.AddSubSteps(len(libraries))
133-
defer progress.RemoveSubSteps()
120+
func (b *Builder) compileLibraries(libraries libraries.List, includes []string, compilationDatabase *compilation.Database) (paths.PathList, error) {
121+
b.Progress.AddSubSteps(len(libraries))
122+
defer b.Progress.RemoveSubSteps()
134123

135124
objectFiles := paths.NewPathList()
136125
for _, library := range libraries {
137126
libraryObjectFiles, err := b.compileLibrary(
138127
library, includes,
139128
compilationDatabase,
140-
progress, progressCB,
141129
)
142130
if err != nil {
143131
return nil, errors.WithStack(err)
144132
}
145133
objectFiles.AddAll(libraryObjectFiles)
146134

147-
progress.CompleteStep()
148-
// PushProgress
149-
if progressCB != nil {
150-
progressCB(&rpc.TaskProgress{
151-
Percent: progress.Progress,
152-
Completed: progress.Progress >= 100.0,
153-
})
154-
}
135+
b.Progress.CompleteStep()
136+
b.Progress.PushProgress()
155137
}
156138

157139
return objectFiles, nil
@@ -160,7 +142,6 @@ func (b *Builder) compileLibraries(
160142
func (b *Builder) compileLibrary(
161143
library *libraries.Library, includes []string,
162144
compilationDatabase *compilation.Database,
163-
progress *progress.Struct, progressCB rpc.TaskProgressCB,
164145
) (paths.PathList, error) {
165146
if b.logger.Verbose() {
166147
b.logger.Info(tr(`Compiling library "%[1]s"`, library.Name))
@@ -227,7 +208,7 @@ func (b *Builder) compileLibrary(
227208
compilationDatabase,
228209
b.jobs,
229210
b.logger,
230-
progress, progressCB,
211+
b.Progress,
231212
)
232213
if err != nil {
233214
return nil, errors.WithStack(err)
@@ -258,7 +239,7 @@ func (b *Builder) compileLibrary(
258239
compilationDatabase,
259240
b.jobs,
260241
b.logger,
261-
progress, progressCB,
242+
b.Progress,
262243
)
263244
if err != nil {
264245
return nil, errors.WithStack(err)
@@ -273,7 +254,7 @@ func (b *Builder) compileLibrary(
273254
compilationDatabase,
274255
b.jobs,
275256
b.logger,
276-
progress, progressCB,
257+
b.Progress,
277258
)
278259
if err != nil {
279260
return nil, errors.WithStack(err)

arduino/builder/progress/progress.go

+18
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,19 @@
1515

1616
package progress
1717

18+
import rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
19+
1820
// Struct fixdoc
1921
type Struct struct {
2022
Progress float32
2123
StepAmount float32
2224
Parent *Struct
25+
callback rpc.TaskProgressCB
26+
}
27+
28+
// New fixdoc
29+
func New(callback rpc.TaskProgressCB) *Struct {
30+
return &Struct{callback: callback}
2331
}
2432

2533
// AddSubSteps fixdoc
@@ -46,3 +54,13 @@ func (p *Struct) RemoveSubSteps() {
4654
func (p *Struct) CompleteStep() {
4755
p.Progress += p.StepAmount
4856
}
57+
58+
// PushProgress fixdoc
59+
func (p *Struct) PushProgress() {
60+
if p.callback != nil {
61+
p.callback(&rpc.TaskProgress{
62+
Percent: p.Progress,
63+
Completed: p.Progress >= 100.0,
64+
})
65+
}
66+
}

arduino/builder/sketch.go

+2-5
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,10 @@ import (
2525

2626
"github.com/arduino/arduino-cli/arduino/builder/compilation"
2727
"github.com/arduino/arduino-cli/arduino/builder/cpp"
28-
"github.com/arduino/arduino-cli/arduino/builder/progress"
2928
"github.com/arduino/arduino-cli/arduino/builder/utils"
3029
"github.com/arduino/arduino-cli/arduino/sketch"
3130
"github.com/arduino/arduino-cli/i18n"
3231
f "github.com/arduino/arduino-cli/internal/algorithms"
33-
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
3432
"github.com/arduino/go-paths-helper"
3533
"github.com/marcinbor85/gohex"
3634

@@ -185,7 +183,6 @@ func writeIfDifferent(source []byte, destPath *paths.Path) error {
185183
func (b *Builder) BuildSketch(
186184
includesFolders paths.PathList,
187185
compilationDatabase *compilation.Database,
188-
progress *progress.Struct, progressCB rpc.TaskProgressCB,
189186
) (paths.PathList, error) {
190187
includes := f.Map(includesFolders.AsStrings(), cpp.WrapWithHyphenI)
191188

@@ -199,7 +196,7 @@ func (b *Builder) BuildSketch(
199196
compilationDatabase,
200197
b.jobs,
201198
b.builderLogger,
202-
progress, progressCB,
199+
b.Progress,
203200
)
204201
if err != nil {
205202
return nil, errors.WithStack(err)
@@ -214,7 +211,7 @@ func (b *Builder) BuildSketch(
214211
compilationDatabase,
215212
b.jobs,
216213
b.builderLogger,
217-
progress, progressCB,
214+
b.Progress,
218215
)
219216
if err != nil {
220217
return nil, errors.WithStack(err)

arduino/builder/sketch_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func TestMergeSketchSources(t *testing.T) {
5454

5555
b, err := NewBuilder(
5656
sk, nil, paths.New("testdata"), false, nil, 0, nil,
57-
nil, nil, nil, nil, fqbn, false, nil, false, nil)
57+
nil, nil, nil, nil, fqbn, false, nil, false, nil, nil)
5858
require.NoError(t, err)
5959

6060
offset, source, err := b.sketchMergeSources(nil)
@@ -73,7 +73,7 @@ func TestMergeSketchSourcesArduinoIncluded(t *testing.T) {
7373

7474
// ensure not to include Arduino.h when it's already there
7575
b, err := NewBuilder(sk, nil, paths.New("testdata"), false, nil, 0, nil,
76-
nil, nil, nil, nil, fqbn, false, nil, false, nil)
76+
nil, nil, nil, nil, fqbn, false, nil, false, nil, nil)
7777
require.NoError(t, err)
7878

7979
_, source, err := b.sketchMergeSources(nil)
@@ -95,7 +95,7 @@ func TestCopyAdditionalFiles(t *testing.T) {
9595
require.NoError(t, err)
9696

9797
b1, err := NewBuilder(sk1, nil, paths.New("testdata"), false, nil, 0, nil,
98-
nil, nil, nil, nil, fqbn, false, nil, false, nil)
98+
nil, nil, nil, nil, fqbn, false, nil, false, nil, nil)
9999
require.NoError(t, err)
100100

101101
// copy the sketch over, create a fake main file we don't care about it

arduino/builder/utils/utils.go

+5-13
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ import (
3333
"github.com/arduino/arduino-cli/executils"
3434
"github.com/arduino/arduino-cli/i18n"
3535
f "github.com/arduino/arduino-cli/internal/algorithms"
36-
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
3736
"github.com/arduino/go-paths-helper"
3837
"github.com/arduino/go-properties-orderedmap"
3938
"github.com/pkg/errors"
@@ -358,7 +357,7 @@ func CompileFiles(
358357
compilationDatabase *compilation.Database,
359358
jobs int,
360359
builderLogger *logger.BuilderLogger,
361-
progress *progress.Struct, progressCB rpc.TaskProgressCB,
360+
progress *progress.Struct,
362361
) (paths.PathList, error) {
363362
return compileFiles(
364363
onlyUpdateCompilationDatabase,
@@ -368,7 +367,7 @@ func CompileFiles(
368367
false,
369368
buildPath, buildProperties, includes,
370369
builderLogger,
371-
progress, progressCB,
370+
progress,
372371
)
373372
}
374373

@@ -381,7 +380,7 @@ func CompileFilesRecursive(
381380
compilationDatabase *compilation.Database,
382381
jobs int,
383382
builderLogger *logger.BuilderLogger,
384-
progress *progress.Struct, progressCB rpc.TaskProgressCB,
383+
progress *progress.Struct,
385384
) (paths.PathList, error) {
386385
return compileFiles(
387386
onlyUpdateCompilationDatabase,
@@ -391,7 +390,7 @@ func CompileFilesRecursive(
391390
true,
392391
buildPath, buildProperties, includes,
393392
builderLogger,
394-
progress, progressCB,
393+
progress,
395394
)
396395
}
397396

@@ -406,7 +405,6 @@ func compileFiles(
406405
includes []string,
407406
builderLogger *logger.BuilderLogger,
408407
progress *progress.Struct,
409-
progressCB rpc.TaskProgressCB,
410408
) (paths.PathList, error) {
411409
validExtensions := []string{}
412410
for ext := range globals.SourceFilesValidExtensions {
@@ -483,13 +481,7 @@ func compileFiles(
483481
queue <- source
484482

485483
progress.CompleteStep()
486-
// PushProgress
487-
if progressCB != nil {
488-
progressCB(&rpc.TaskProgress{
489-
Percent: progress.Progress,
490-
Completed: progress.Progress >= 100.0,
491-
})
492-
}
484+
progress.PushProgress()
493485
}
494486
close(queue)
495487
wg.Wait()

0 commit comments

Comments
 (0)