Skip to content

Commit 7d50993

Browse files
mvoe types.ProgressStruct in a dedicated pkg
1 parent af6a641 commit 7d50993

File tree

5 files changed

+40
-38
lines changed

5 files changed

+40
-38
lines changed

arduino/builder/progress/progress.go

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package progress
2+
3+
type Struct struct {
4+
Progress float32
5+
StepAmount float32
6+
Parent *Struct
7+
}
8+
9+
func (p *Struct) AddSubSteps(steps int) {
10+
p.Parent = &Struct{
11+
Progress: p.Progress,
12+
StepAmount: p.StepAmount,
13+
Parent: p.Parent,
14+
}
15+
if p.StepAmount == 0.0 {
16+
p.StepAmount = 100.0
17+
}
18+
p.StepAmount /= float32(steps)
19+
}
20+
21+
func (p *Struct) RemoveSubSteps() {
22+
p.Progress = p.Parent.Progress
23+
p.StepAmount = p.Parent.StepAmount
24+
p.Parent = p.Parent.Parent
25+
}
26+
27+
func (p *Struct) CompleteStep() {
28+
p.Progress += p.StepAmount
29+
}

legacy/builder/types/progress_test.go renamed to arduino/builder/progress/progress_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// Arduino software without disclosing the source code of your own applications.
1414
// To purchase a commercial license, send an email to [email protected].
1515

16-
package types
16+
package progress
1717

1818
import (
1919
"fmt"
@@ -23,7 +23,7 @@ import (
2323
)
2424

2525
func TestProgress(t *testing.T) {
26-
p := &ProgressStruct{}
26+
p := &Struct{}
2727
p.AddSubSteps(3)
2828
require.Equal(t, float32(0.0), p.Progress)
2929
require.InEpsilon(t, 33.33333, p.StepAmount, 0.00001)

legacy/builder/builder_utils/utils.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ import (
2626
"sync"
2727

2828
"github.com/arduino/arduino-cli/arduino/builder"
29+
"github.com/arduino/arduino-cli/arduino/builder/progress"
2930
bUtils "github.com/arduino/arduino-cli/arduino/builder/utils"
3031
"github.com/arduino/arduino-cli/arduino/globals"
3132
"github.com/arduino/arduino-cli/executils"
3233
"github.com/arduino/arduino-cli/i18n"
3334
"github.com/arduino/arduino-cli/legacy/builder/constants"
34-
"github.com/arduino/arduino-cli/legacy/builder/types"
3535
"github.com/arduino/arduino-cli/legacy/builder/utils"
3636
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
3737
"github.com/arduino/go-paths-helper"
@@ -79,7 +79,7 @@ func CompileFiles(
7979
stdoutWriter, stderrWriter io.Writer,
8080
verboseInfoFn func(msg string),
8181
verboseStdoutFn, verboseStderrFn func(data []byte),
82-
progress *types.ProgressStruct, progressCB rpc.TaskProgressCB,
82+
progress *progress.Struct, progressCB rpc.TaskProgressCB,
8383
) (paths.PathList, error) {
8484
return compileFiles(
8585
onlyUpdateCompilationDatabase,
@@ -108,7 +108,7 @@ func CompileFilesRecursive(
108108
stdoutWriter, stderrWriter io.Writer,
109109
verboseInfoFn func(msg string),
110110
verboseStdoutFn, verboseStderrFn func(data []byte),
111-
progress *types.ProgressStruct, progressCB rpc.TaskProgressCB,
111+
progress *progress.Struct, progressCB rpc.TaskProgressCB,
112112
) (paths.PathList, error) {
113113
return compileFiles(
114114
onlyUpdateCompilationDatabase,
@@ -139,7 +139,7 @@ func compileFiles(
139139
stdoutWriter, stderrWriter io.Writer,
140140
verboseInfoFn func(msg string),
141141
verboseStdoutFn, verboseStderrFn func(data []byte),
142-
progress *types.ProgressStruct,
142+
progress *progress.Struct,
143143
progressCB rpc.TaskProgressCB,
144144
) (paths.PathList, error) {
145145
validExtensions := []string{}

legacy/builder/phases/core_builder.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ import (
2525

2626
"github.com/arduino/arduino-cli/arduino/builder"
2727
"github.com/arduino/arduino-cli/arduino/builder/cpp"
28+
"github.com/arduino/arduino-cli/arduino/builder/progress"
2829
"github.com/arduino/arduino-cli/arduino/cores"
2930
"github.com/arduino/arduino-cli/buildcache"
3031
"github.com/arduino/arduino-cli/i18n"
3132
f "github.com/arduino/arduino-cli/internal/algorithms"
3233
"github.com/arduino/arduino-cli/legacy/builder/builder_utils"
3334
"github.com/arduino/arduino-cli/legacy/builder/constants"
34-
"github.com/arduino/arduino-cli/legacy/builder/types"
3535
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
3636
"github.com/arduino/go-paths-helper"
3737
"github.com/arduino/go-properties-orderedmap"
@@ -54,7 +54,7 @@ func CoreBuilder(
5454
stdoutWriter, stderrWriter io.Writer,
5555
verboseInfoFn func(msg string),
5656
verboseStdoutFn, verboseStderrFn func(data []byte),
57-
progress *types.ProgressStruct, progressCB rpc.TaskProgressCB,
57+
progress *progress.Struct, progressCB rpc.TaskProgressCB,
5858
) (paths.PathList, *paths.Path, *paths.Path, error) {
5959
if err := coreBuildPath.MkdirAll(); err != nil {
6060
return nil, nil, coreBuildCachePath, errors.WithStack(err)
@@ -101,7 +101,7 @@ func compileCore(
101101
stdoutWriter, stderrWriter io.Writer,
102102
verboseInfoFn func(msg string),
103103
verboseStdoutFn, verboseStderrFn func(data []byte),
104-
progress *types.ProgressStruct, progressCB rpc.TaskProgressCB,
104+
progress *progress.Struct, progressCB rpc.TaskProgressCB,
105105
) (*paths.Path, paths.PathList, error) {
106106
coreFolder := buildProperties.GetPath("build.core.path")
107107
variantFolder := buildProperties.GetPath("build.variant.path")

legacy/builder/types/context.go

+2-29
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424

2525
"github.com/arduino/arduino-cli/arduino/builder"
2626
"github.com/arduino/arduino-cli/arduino/builder/detector"
27+
"github.com/arduino/arduino-cli/arduino/builder/progress"
2728
"github.com/arduino/arduino-cli/arduino/cores"
2829
"github.com/arduino/arduino-cli/arduino/cores/packagemanager"
2930
"github.com/arduino/arduino-cli/arduino/sketch"
@@ -32,34 +33,6 @@ import (
3233
properties "github.com/arduino/go-properties-orderedmap"
3334
)
3435

35-
type ProgressStruct struct {
36-
Progress float32
37-
StepAmount float32
38-
Parent *ProgressStruct
39-
}
40-
41-
func (p *ProgressStruct) AddSubSteps(steps int) {
42-
p.Parent = &ProgressStruct{
43-
Progress: p.Progress,
44-
StepAmount: p.StepAmount,
45-
Parent: p.Parent,
46-
}
47-
if p.StepAmount == 0.0 {
48-
p.StepAmount = 100.0
49-
}
50-
p.StepAmount /= float32(steps)
51-
}
52-
53-
func (p *ProgressStruct) RemoveSubSteps() {
54-
p.Progress = p.Parent.Progress
55-
p.StepAmount = p.Parent.StepAmount
56-
p.Parent = p.Parent.Parent
57-
}
58-
59-
func (p *ProgressStruct) CompleteStep() {
60-
p.Progress += p.StepAmount
61-
}
62-
6336
// Context structure
6437
type Context struct {
6538
Builder *builder.Builder
@@ -105,7 +78,7 @@ type Context struct {
10578
Verbose bool
10679

10780
// Dry run, only create progress map
108-
Progress ProgressStruct
81+
Progress progress.Struct
10982
// Send progress events to this callback
11083
ProgressCB rpc.TaskProgressCB
11184

0 commit comments

Comments
 (0)