Skip to content

Commit

Permalink
[skip-changelog] legacy: Builder refactorization (part 2) (#2298)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
alessio-perugini authored Sep 8, 2023
1 parent 1c110e9 commit b8024c3
Show file tree
Hide file tree
Showing 28 changed files with 1,166 additions and 853 deletions.
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

0 comments on commit b8024c3

Please sign in to comment.