Skip to content

Commit b8024c3

Browse files
[skip-changelog] legacy: Builder refactorization (part 2) (#2298)
* remove unused LibraryDir from legacy context * remove unused WatchedLocation from legacy context * remove unused IgnoreSketchFolderNameErrors from legacy context * remove CanUseCachedTools from legacy context * remove UseArduinoPreprocessor from legacy context * make the CoreBuilder command a function * remove the use of context from builder_utils * mvoe types.ProgressStruct in a dedicated pkg * move ExecCommand under arduino/utils * move LogIfVerbose from utils to legacy builder * move some legacy constans in builder package * move builder_utils under arduino/builder/utils pkg * appease golint * move coreBuildCachePath in the arduino Builder * refactor Linker command in a function * refactor SketchBuilder in a function * refactor LibrariesBuilder in a function * refactor Sizer in a function * remove empty file * remove unused struct FailIfBuildPathEqualsSketchPath
1 parent 1c110e9 commit b8024c3

28 files changed

+1166
-853
lines changed

Diff for: arduino/builder/builder.go

+21-3
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,34 @@
1515

1616
package builder
1717

18-
import "github.com/arduino/arduino-cli/arduino/sketch"
18+
import (
19+
"github.com/arduino/arduino-cli/arduino/sketch"
20+
"github.com/arduino/go-paths-helper"
21+
)
22+
23+
// nolint
24+
const (
25+
BuildPropertiesArchiveFile = "archive_file"
26+
BuildPropertiesArchiveFilePath = "archive_file_path"
27+
BuildPropertiesObjectFile = "object_file"
28+
RecipeARPattern = "recipe.ar.pattern"
29+
BuildPropertiesIncludes = "includes"
30+
BuildPropertiesCompilerWarningFlags = "compiler.warning_flags"
31+
Space = " "
32+
)
1933

2034
// Builder is a Sketch builder.
2135
type Builder struct {
2236
sketch *sketch.Sketch
37+
38+
// core related
39+
coreBuildCachePath *paths.Path
2340
}
2441

2542
// NewBuilder creates a sketch Builder.
26-
func NewBuilder(sk *sketch.Sketch) *Builder {
43+
func NewBuilder(sk *sketch.Sketch, coreBuildCachePath *paths.Path) *Builder {
2744
return &Builder{
28-
sketch: sk,
45+
sketch: sk,
46+
coreBuildCachePath: coreBuildCachePath,
2947
}
3048
}

Diff for: arduino/builder/core.go

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package builder
2+
3+
import "github.com/arduino/go-paths-helper"
4+
5+
// CoreBuildCachePath fixdoc
6+
func (b *Builder) CoreBuildCachePath() *paths.Path {
7+
return b.coreBuildCachePath
8+
}

Diff for: arduino/builder/progress/progress.go

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

Diff for: 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)

Diff for: arduino/builder/sizer.go

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package builder
2+
3+
import rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
4+
5+
// ExecutableSectionSize represents a section of the executable output file
6+
type ExecutableSectionSize struct {
7+
Name string `json:"name"`
8+
Size int `json:"size"`
9+
MaxSize int `json:"max_size"`
10+
}
11+
12+
// ExecutablesFileSections is an array of ExecutablesFileSection
13+
type ExecutablesFileSections []ExecutableSectionSize
14+
15+
// ToRPCExecutableSectionSizeArray transforms this array into a []*rpc.ExecutableSectionSize
16+
func (s ExecutablesFileSections) ToRPCExecutableSectionSizeArray() []*rpc.ExecutableSectionSize {
17+
res := []*rpc.ExecutableSectionSize{}
18+
for _, section := range s {
19+
res = append(res, &rpc.ExecutableSectionSize{
20+
Name: section.Name,
21+
Size: int64(section.Size),
22+
MaxSize: int64(section.MaxSize),
23+
})
24+
}
25+
return res
26+
}

Diff for: arduino/builder/sketch_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func TestMergeSketchSources(t *testing.T) {
4848
}
4949
mergedSources := strings.ReplaceAll(string(mergedBytes), "%s", pathToGoldenSource)
5050

51-
b := NewBuilder(sk)
51+
b := NewBuilder(sk, nil)
5252
offset, source, err := b.sketchMergeSources(nil)
5353
require.Nil(t, err)
5454
require.Equal(t, 2, offset)
@@ -61,7 +61,7 @@ func TestMergeSketchSourcesArduinoIncluded(t *testing.T) {
6161
require.NotNil(t, sk)
6262

6363
// ensure not to include Arduino.h when it's already there
64-
b := NewBuilder(sk)
64+
b := NewBuilder(sk, nil)
6565
_, source, err := b.sketchMergeSources(nil)
6666
require.Nil(t, err)
6767
require.Equal(t, 1, strings.Count(source, "<Arduino.h>"))
@@ -76,7 +76,7 @@ func TestCopyAdditionalFiles(t *testing.T) {
7676
sk1, err := sketch.New(paths.New("testdata", t.Name()))
7777
require.Nil(t, err)
7878
require.Equal(t, sk1.AdditionalFiles.Len(), 1)
79-
b1 := NewBuilder(sk1)
79+
b1 := NewBuilder(sk1, nil)
8080

8181
// copy the sketch over, create a fake main file we don't care about it
8282
// but we need it for `SketchLoad` to succeed later

0 commit comments

Comments
 (0)