Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

legacy: Builder refactorization (part 2...) #2298

Merged
merged 20 commits into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
ac23e58
remove unused LibraryDir from legacy context
alessio-perugini Sep 5, 2023
8c92b30
remove unused WatchedLocation from legacy context
alessio-perugini Sep 5, 2023
2847034
remove unused IgnoreSketchFolderNameErrors from legacy context
alessio-perugini Sep 5, 2023
0b4aee2
remove CanUseCachedTools from legacy context
alessio-perugini Sep 5, 2023
402de11
remove UseArduinoPreprocessor from legacy context
alessio-perugini Sep 5, 2023
e82e52e
make the CoreBuilder command a function
alessio-perugini Sep 6, 2023
b41be55
remove the use of context from builder_utils
alessio-perugini Sep 6, 2023
407bc42
mvoe types.ProgressStruct in a dedicated pkg
alessio-perugini Sep 6, 2023
c3ffb4f
move ExecCommand under arduino/utils
alessio-perugini Sep 6, 2023
a2a9b99
move LogIfVerbose from utils to legacy builder
alessio-perugini Sep 6, 2023
3ab6d54
move some legacy constans in builder package
alessio-perugini Sep 6, 2023
5b6ed66
move builder_utils under arduino/builder/utils pkg
alessio-perugini Sep 6, 2023
f410804
appease golint
alessio-perugini Sep 6, 2023
3bd6c7f
move coreBuildCachePath in the arduino Builder
alessio-perugini Sep 6, 2023
447419d
refactor Linker command in a function
alessio-perugini Sep 7, 2023
a688f45
refactor SketchBuilder in a function
alessio-perugini Sep 7, 2023
a05fa12
refactor LibrariesBuilder in a function
alessio-perugini Sep 7, 2023
70a018f
refactor Sizer in a function
alessio-perugini Sep 7, 2023
d4454f5
remove empty file
alessio-perugini Sep 7, 2023
f57fbeb
remove unused struct FailIfBuildPathEqualsSketchPath
alessio-perugini Sep 7, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions arduino/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,34 @@

package builder

import "github.com/arduino/arduino-cli/arduino/sketch"
import (
"github.com/arduino/arduino-cli/arduino/sketch"
"github.com/arduino/go-paths-helper"
)

// nolint
const (
BuildPropertiesArchiveFile = "archive_file"
BuildPropertiesArchiveFilePath = "archive_file_path"
BuildPropertiesObjectFile = "object_file"
RecipeARPattern = "recipe.ar.pattern"
BuildPropertiesIncludes = "includes"
BuildPropertiesCompilerWarningFlags = "compiler.warning_flags"
Space = " "
)

// Builder is a Sketch builder.
type Builder struct {
sketch *sketch.Sketch

// core related
coreBuildCachePath *paths.Path
}

// NewBuilder creates a sketch Builder.
func NewBuilder(sk *sketch.Sketch) *Builder {
func NewBuilder(sk *sketch.Sketch, coreBuildCachePath *paths.Path) *Builder {
return &Builder{
sketch: sk,
sketch: sk,
coreBuildCachePath: coreBuildCachePath,
}
}
8 changes: 8 additions & 0 deletions arduino/builder/core.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package builder

import "github.com/arduino/go-paths-helper"

// CoreBuildCachePath fixdoc
func (b *Builder) CoreBuildCachePath() *paths.Path {
return b.coreBuildCachePath
}
33 changes: 33 additions & 0 deletions arduino/builder/progress/progress.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package progress

// Struct fixdoc
type Struct struct {
Progress float32
StepAmount float32
Parent *Struct
}

// AddSubSteps fixdoc
func (p *Struct) AddSubSteps(steps int) {
p.Parent = &Struct{
Progress: p.Progress,
StepAmount: p.StepAmount,
Parent: p.Parent,
}
if p.StepAmount == 0.0 {
p.StepAmount = 100.0
}
p.StepAmount /= float32(steps)
}

// RemoveSubSteps fixdoc
func (p *Struct) RemoveSubSteps() {
p.Progress = p.Parent.Progress
p.StepAmount = p.Parent.StepAmount
p.Parent = p.Parent.Parent
}

// CompleteStep fixdoc
func (p *Struct) CompleteStep() {
p.Progress += p.StepAmount
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// Arduino software without disclosing the source code of your own applications.
// To purchase a commercial license, send an email to [email protected].

package types
package progress

import (
"fmt"
Expand All @@ -23,7 +23,7 @@ import (
)

func TestProgress(t *testing.T) {
p := &ProgressStruct{}
p := &Struct{}
p.AddSubSteps(3)
require.Equal(t, float32(0.0), p.Progress)
require.InEpsilon(t, 33.33333, p.StepAmount, 0.00001)
Expand Down
26 changes: 26 additions & 0 deletions arduino/builder/sizer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package builder

import rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"

// ExecutableSectionSize represents a section of the executable output file
type ExecutableSectionSize struct {
Name string `json:"name"`
Size int `json:"size"`
MaxSize int `json:"max_size"`
}

// ExecutablesFileSections is an array of ExecutablesFileSection
type ExecutablesFileSections []ExecutableSectionSize

// ToRPCExecutableSectionSizeArray transforms this array into a []*rpc.ExecutableSectionSize
func (s ExecutablesFileSections) ToRPCExecutableSectionSizeArray() []*rpc.ExecutableSectionSize {
res := []*rpc.ExecutableSectionSize{}
for _, section := range s {
res = append(res, &rpc.ExecutableSectionSize{
Name: section.Name,
Size: int64(section.Size),
MaxSize: int64(section.MaxSize),
})
}
return res
}
6 changes: 3 additions & 3 deletions arduino/builder/sketch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func TestMergeSketchSources(t *testing.T) {
}
mergedSources := strings.ReplaceAll(string(mergedBytes), "%s", pathToGoldenSource)

b := NewBuilder(sk)
b := NewBuilder(sk, nil)
offset, source, err := b.sketchMergeSources(nil)
require.Nil(t, err)
require.Equal(t, 2, offset)
Expand All @@ -61,7 +61,7 @@ func TestMergeSketchSourcesArduinoIncluded(t *testing.T) {
require.NotNil(t, sk)

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

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