Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 0866d99

Browse files
authored
[skip changelog] Improved progress report from Compile (#625)
* legacy: inline compileFilesWithExtensionWithRecipe function This will help for a better progress management in a next commit since now we know in advance how many file will be compiled in this task. * Added missing copyright header * Improved progress report during Compile
1 parent 8252a8e commit 0866d99

File tree

6 files changed

+157
-35
lines changed

6 files changed

+157
-35
lines changed

‎legacy/builder/builder.go‎

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func (s *Builder) Run(ctx *types.Context) error {
9999
&RecipeByPrefixSuffixRunner{Prefix: constants.HOOKS_POSTBUILD, Suffix: constants.HOOKS_PATTERN_SUFFIX},
100100
}
101101

102-
mainErr := runCommands(ctx, commands, true)
102+
mainErr := runCommands(ctx, commands)
103103

104104
commands = []types.Command{
105105
&PrintUsedAndNotUsedLibraries{SketchError: mainErr != nil},
@@ -110,7 +110,7 @@ func (s *Builder) Run(ctx *types.Context) error {
110110

111111
&phases.Sizer{SketchError: mainErr != nil},
112112
}
113-
otherErr := runCommands(ctx, commands, false)
113+
otherErr := runCommands(ctx, commands)
114114

115115
if mainErr != nil {
116116
return mainErr
@@ -128,7 +128,7 @@ func (s *PreprocessSketch) Run(ctx *types.Context) error {
128128
} else {
129129
commands = append(commands, &ContainerAddPrototypes{})
130130
}
131-
return runCommands(ctx, commands, true)
131+
return runCommands(ctx, commands)
132132
}
133133

134134
type Preprocess struct{}
@@ -158,7 +158,7 @@ func (s *Preprocess) Run(ctx *types.Context) error {
158158
&PreprocessSketch{},
159159
}
160160

161-
if err := runCommands(ctx, commands, true); err != nil {
161+
if err := runCommands(ctx, commands); err != nil {
162162
return err
163163
}
164164

@@ -180,22 +180,21 @@ func (s *ParseHardwareAndDumpBuildProperties) Run(ctx *types.Context) error {
180180
&DumpBuildProperties{},
181181
}
182182

183-
return runCommands(ctx, commands, true)
183+
return runCommands(ctx, commands)
184184
}
185185

186-
func runCommands(ctx *types.Context, commands []types.Command, progressEnabled bool) error {
187-
188-
ctx.Progress.PrintEnabled = progressEnabled
189-
ctx.Progress.Progress = 0
186+
func runCommands(ctx *types.Context, commands []types.Command) error {
187+
ctx.Progress.AddSubSteps(len(commands))
188+
defer ctx.Progress.RemoveSubSteps()
190189

191190
for _, command := range commands {
192191
PrintRingNameIfDebug(ctx, command)
193-
ctx.Progress.Steps = 100.0 / float64(len(commands))
194-
builder_utils.PrintProgressIfProgressEnabledAndMachineLogger(ctx)
195192
err := command.Run(ctx)
196193
if err != nil {
197194
return errors.WithStack(err)
198195
}
196+
ctx.Progress.CompleteStep()
197+
builder_utils.PrintProgressIfProgressEnabledAndMachineLogger(ctx)
199198
}
200199
return nil
201200
}

‎legacy/builder/builder_utils/utils.go‎

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ func PrintProgressIfProgressEnabledAndMachineLogger(ctx *types.Context) {
4141

4242
log := ctx.GetLogger()
4343
if log.Name() == "machine" {
44-
log.Println(constants.LOG_LEVEL_INFO, constants.MSG_PROGRESS, strconv.FormatFloat(ctx.Progress.Progress, 'f', 2, 32))
45-
ctx.Progress.Progress += ctx.Progress.Steps
44+
log.Println(constants.LOG_LEVEL_INFO, constants.MSG_PROGRESS, strconv.FormatFloat(float64(ctx.Progress.Progress), 'f', 2, 32))
4645
}
4746
}
4847

@@ -69,33 +68,42 @@ func CompileFilesRecursive(ctx *types.Context, sourcePath *paths.Path, buildPath
6968
}
7069

7170
func CompileFiles(ctx *types.Context, sourcePath *paths.Path, recurse bool, buildPath *paths.Path, buildProperties *properties.Map, includes []string) (paths.PathList, error) {
72-
sObjectFiles, err := compileFilesWithExtensionWithRecipe(ctx, sourcePath, recurse, buildPath, buildProperties, includes, ".S", constants.RECIPE_S_PATTERN)
71+
sSources, err := findFilesInFolder(sourcePath, ".S", recurse)
7372
if err != nil {
7473
return nil, errors.WithStack(err)
7574
}
76-
cObjectFiles, err := compileFilesWithExtensionWithRecipe(ctx, sourcePath, recurse, buildPath, buildProperties, includes, ".c", constants.RECIPE_C_PATTERN)
75+
cSources, err := findFilesInFolder(sourcePath, ".c", recurse)
7776
if err != nil {
7877
return nil, errors.WithStack(err)
7978
}
80-
cppObjectFiles, err := compileFilesWithExtensionWithRecipe(ctx, sourcePath, recurse, buildPath, buildProperties, includes, ".cpp", constants.RECIPE_CPP_PATTERN)
79+
cppSources, err := findFilesInFolder(sourcePath, ".cpp", recurse)
8180
if err != nil {
8281
return nil, errors.WithStack(err)
8382
}
83+
84+
ctx.Progress.AddSubSteps(len(sSources) + len(cSources) + len(cppSources))
85+
defer ctx.Progress.RemoveSubSteps()
86+
87+
sObjectFiles, err := compileFilesWithRecipe(ctx, sourcePath, sSources, buildPath, buildProperties, includes, constants.RECIPE_S_PATTERN)
88+
if err != nil {
89+
return nil, errors.WithStack(err)
90+
}
91+
cObjectFiles, err := compileFilesWithRecipe(ctx, sourcePath, cSources, buildPath, buildProperties, includes, constants.RECIPE_C_PATTERN)
92+
if err != nil {
93+
return nil, errors.WithStack(err)
94+
}
95+
cppObjectFiles, err := compileFilesWithRecipe(ctx, sourcePath, cppSources, buildPath, buildProperties, includes, constants.RECIPE_CPP_PATTERN)
96+
if err != nil {
97+
return nil, errors.WithStack(err)
98+
}
99+
84100
objectFiles := paths.NewPathList()
85101
objectFiles.AddAll(sObjectFiles)
86102
objectFiles.AddAll(cObjectFiles)
87103
objectFiles.AddAll(cppObjectFiles)
88104
return objectFiles, nil
89105
}
90106

91-
func compileFilesWithExtensionWithRecipe(ctx *types.Context, sourcePath *paths.Path, recurse bool, buildPath *paths.Path, buildProperties *properties.Map, includes []string, extension string, recipe string) (paths.PathList, error) {
92-
sources, err := findFilesInFolder(sourcePath, extension, recurse)
93-
if err != nil {
94-
return nil, errors.WithStack(err)
95-
}
96-
return compileFilesWithRecipe(ctx, sourcePath, sources, buildPath, buildProperties, includes, recipe)
97-
}
98-
99107
func findFilesInFolder(sourcePath *paths.Path, extension string, recurse bool) (paths.PathList, error) {
100108
files, err := utils.ReadDirFiltered(sourcePath.String(), utils.FilterFilesWithExtensions(extension))
101109
if err != nil {
@@ -164,11 +172,8 @@ func compileFilesWithRecipe(ctx *types.Context, sourcePath *paths.Path, sources
164172
var errorsList []error
165173
var errorsMux sync.Mutex
166174

167-
ctx.Progress.Steps = ctx.Progress.Steps / float64(len(sources))
168-
169175
queue := make(chan *paths.Path)
170176
job := func(source *paths.Path) {
171-
PrintProgressIfProgressEnabledAndMachineLogger(ctx)
172177
objectFile, err := compileFileWithRecipe(ctx, sourcePath, source, buildPath, buildProperties, includes, recipe)
173178
if err != nil {
174179
errorsMux.Lock()
@@ -206,6 +211,9 @@ func compileFilesWithRecipe(ctx *types.Context, sourcePath *paths.Path, sources
206211
break
207212
}
208213
queue <- source
214+
215+
ctx.Progress.CompleteStep()
216+
PrintProgressIfProgressEnabledAndMachineLogger(ctx)
209217
}
210218
close(queue)
211219
wg.Wait()

‎legacy/builder/container_setup.go‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ import (
2828
type ContainerSetupHardwareToolsLibsSketchAndProps struct{}
2929

3030
func (s *ContainerSetupHardwareToolsLibsSketchAndProps) Run(ctx *types.Context) error {
31+
// total number of steps in this container: 14
32+
ctx.Progress.AddSubSteps(14)
33+
defer ctx.Progress.RemoveSubSteps()
34+
3135
commands := []types.Command{
3236
&AddAdditionalEntriesToContext{},
3337
&FailIfBuildPathEqualsSketchPath{},
@@ -40,15 +44,14 @@ func (s *ContainerSetupHardwareToolsLibsSketchAndProps) Run(ctx *types.Context)
4044
&LibrariesLoader{},
4145
}
4246

43-
ctx.Progress.Steps = ctx.Progress.Steps / float64(len(commands))
44-
4547
for _, command := range commands {
46-
builder_utils.PrintProgressIfProgressEnabledAndMachineLogger(ctx)
4748
PrintRingNameIfDebug(ctx, command)
4849
err := command.Run(ctx)
4950
if err != nil {
5051
return errors.WithStack(err)
5152
}
53+
ctx.Progress.CompleteStep()
54+
builder_utils.PrintProgressIfProgressEnabledAndMachineLogger(ctx)
5255
}
5356

5457
if ctx.SketchLocation != nil {
@@ -69,6 +72,8 @@ func (s *ContainerSetupHardwareToolsLibsSketchAndProps) Run(ctx *types.Context)
6972
ctx.SketchLocation = paths.New(sketch.MainFile.Path)
7073
ctx.Sketch = types.SketchToLegacy(sketch)
7174
}
75+
ctx.Progress.CompleteStep()
76+
builder_utils.PrintProgressIfProgressEnabledAndMachineLogger(ctx)
7277

7378
commands = []types.Command{
7479
&SetupBuildProperties{},
@@ -77,15 +82,14 @@ func (s *ContainerSetupHardwareToolsLibsSketchAndProps) Run(ctx *types.Context)
7782
&AddMissingBuildPropertiesFromParentPlatformTxtFiles{},
7883
}
7984

80-
ctx.Progress.Steps = ctx.Progress.Steps / float64(len(commands))
81-
8285
for _, command := range commands {
83-
builder_utils.PrintProgressIfProgressEnabledAndMachineLogger(ctx)
8486
PrintRingNameIfDebug(ctx, command)
8587
err := command.Run(ctx)
8688
if err != nil {
8789
return errors.WithStack(err)
8890
}
91+
ctx.Progress.CompleteStep()
92+
builder_utils.PrintProgressIfProgressEnabledAndMachineLogger(ctx)
8993
}
9094

9195
return nil

‎legacy/builder/phases/libraries_builder.go‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,13 +143,19 @@ func fixLDFLAGforPrecompiledLibraries(ctx *types.Context, libs libraries.List) e
143143
}
144144

145145
func compileLibraries(ctx *types.Context, libraries libraries.List, buildPath *paths.Path, buildProperties *properties.Map, includes []string) (paths.PathList, error) {
146+
ctx.Progress.AddSubSteps(len(libraries))
147+
defer ctx.Progress.RemoveSubSteps()
148+
146149
objectFiles := paths.NewPathList()
147150
for _, library := range libraries {
148151
libraryObjectFiles, err := compileLibrary(ctx, library, buildPath, buildProperties, includes)
149152
if err != nil {
150153
return nil, errors.WithStack(err)
151154
}
152155
objectFiles = append(objectFiles, libraryObjectFiles...)
156+
157+
ctx.Progress.CompleteStep()
158+
builder_utils.PrintProgressIfProgressEnabledAndMachineLogger(ctx)
153159
}
154160

155161
return objectFiles, nil

‎legacy/builder/types/context.go‎

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
// This file is part of arduino-cli.
2+
//
3+
// Copyright 2020 ARDUINO SA (http://www.arduino.cc/)
4+
//
5+
// This software is released under the GNU General Public License version 3,
6+
// which covers the main part of arduino-cli.
7+
// The terms of this license can be found at:
8+
// https://www.gnu.org/licenses/gpl-3.0.en.html
9+
//
10+
// You can be released from the requirements of the above licenses by purchasing
11+
// a commercial license. Buying such a license is mandatory if you want to
12+
// modify or otherwise use the software for commercial activities involving the
13+
// Arduino software without disclosing the source code of your own applications.
14+
// To purchase a commercial license, send an email to license@arduino.cc.
15+
116
package types
217

318
import (
@@ -16,8 +31,31 @@ import (
1631

1732
type ProgressStruct struct {
1833
PrintEnabled bool
19-
Steps float64
20-
Progress float64
34+
Progress float32
35+
StepAmount float32
36+
Parent *ProgressStruct
37+
}
38+
39+
func (p *ProgressStruct) AddSubSteps(steps int) {
40+
p.Parent = &ProgressStruct{
41+
Progress: p.Progress,
42+
StepAmount: p.StepAmount,
43+
Parent: p.Parent,
44+
}
45+
if p.StepAmount == 0.0 {
46+
p.StepAmount = 100.0
47+
}
48+
p.StepAmount /= float32(steps)
49+
}
50+
51+
func (p *ProgressStruct) RemoveSubSteps() {
52+
p.Progress = p.Parent.Progress
53+
p.StepAmount = p.Parent.StepAmount
54+
p.Parent = p.Parent.Parent
55+
}
56+
57+
func (p *ProgressStruct) CompleteStep() {
58+
p.Progress += p.StepAmount
2159
}
2260

2361
// Context structure
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// This file is part of arduino-cli.
2+
//
3+
// Copyright 2020 ARDUINO SA (http://www.arduino.cc/)
4+
//
5+
// This software is released under the GNU General Public License version 3,
6+
// which covers the main part of arduino-cli.
7+
// The terms of this license can be found at:
8+
// https://www.gnu.org/licenses/gpl-3.0.en.html
9+
//
10+
// You can be released from the requirements of the above licenses by purchasing
11+
// a commercial license. Buying such a license is mandatory if you want to
12+
// modify or otherwise use the software for commercial activities involving the
13+
// Arduino software without disclosing the source code of your own applications.
14+
// To purchase a commercial license, send an email to license@arduino.cc.
15+
16+
package types
17+
18+
import (
19+
"fmt"
20+
"testing"
21+
22+
"github.com/stretchr/testify/require"
23+
)
24+
25+
func TestProgress(t *testing.T) {
26+
p := &ProgressStruct{}
27+
p.AddSubSteps(3)
28+
require.Equal(t, float32(0.0), p.Progress)
29+
require.InEpsilon(t, 33.33333, p.StepAmount, 0.00001)
30+
fmt.Printf("%+v\n", p)
31+
{
32+
p.CompleteStep()
33+
require.InEpsilon(t, 33.33333, p.Progress, 0.00001)
34+
fmt.Printf("%+v\n", p)
35+
36+
p.AddSubSteps(4)
37+
require.InEpsilon(t, 33.33333, p.Progress, 0.00001)
38+
require.InEpsilon(t, 8.33333, p.StepAmount, 0.00001)
39+
fmt.Printf("%+v\n", p)
40+
{
41+
p.CompleteStep()
42+
require.InEpsilon(t, 41.66666, p.Progress, 0.00001)
43+
fmt.Printf("%+v\n", p)
44+
45+
p.CompleteStep()
46+
require.InEpsilon(t, 50.0, p.Progress, 0.00001)
47+
fmt.Printf("%+v\n", p)
48+
49+
p.AddSubSteps(0) // zero steps
50+
fmt.Printf("%+v\n", p)
51+
{
52+
// p.CompleteStep() invalid here
53+
}
54+
p.RemoveSubSteps()
55+
}
56+
p.RemoveSubSteps()
57+
require.InEpsilon(t, 33.33333, p.Progress, 0.00001)
58+
fmt.Printf("%+v\n", p)
59+
60+
p.CompleteStep()
61+
require.InEpsilon(t, 66.66666, p.Progress, 0.00001)
62+
fmt.Printf("%+v\n", p)
63+
}
64+
p.RemoveSubSteps()
65+
require.Equal(t, float32(0.0), p.Progress)
66+
require.Equal(t, float32(0.0), p.StepAmount)
67+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /