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 1...) #2286

Merged
merged 29 commits into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
062074d
Simplified compileFiles
cmaglie Aug 28, 2023
1b66c2d
Starting new Builder (part 1/n)
cmaglie Aug 28, 2023
c720bec
builder: renamed variable and moved dir creation up
cmaglie Aug 29, 2023
15e419a
builder: made a sketch-prepress function part of Builder
cmaglie Aug 29, 2023
0fae845
Removed ctx dependency in PreprocessSketchWithArduinoPreprocessor
cmaglie Aug 29, 2023
d325385
uniform parameters between preprocesors
cmaglie Aug 29, 2023
394890b
Moved PreprocessSketchWithArduinoPreprocessor into proper place
cmaglie Aug 29, 2023
b013d16
Inlined function
cmaglie Aug 29, 2023
fccb3b4
Converted sketchCopyAdditionalFiles into a Builder method
cmaglie Aug 29, 2023
1408d7f
Made SetupBuildProperties a method of the new Builder
cmaglie Aug 30, 2023
5534d6d
Refactor AddAdditionalEntriesToContext
alessio-perugini Aug 31, 2023
b86ce45
Refactor legacy LibrariesLoader command
alessio-perugini Aug 31, 2023
341ffe2
move LibrariesLoader under arduino/builder
alessio-perugini Aug 31, 2023
96426b9
remove usless nil check
alessio-perugini Sep 1, 2023
298ebb5
remove AddAdditionalEntries func, in favour of initializing them in t…
alessio-perugini Sep 1, 2023
ea05e2c
move a check directly in the compile command
alessio-perugini Sep 1, 2023
45ee082
create the SketchLibrariesDetector struct
alessio-perugini Sep 1, 2023
1e902cf
move all the logic of ContainerSetupHardwareToolsLibsSketchAndProps i…
alessio-perugini Sep 1, 2023
1c18baf
remove container_setup and adjust relative tests
alessio-perugini Sep 1, 2023
3b829da
remove LibraryResolver property from context
alessio-perugini Sep 1, 2023
e2f7c7b
remove UseCachedLibrariesResolution for context
alessio-perugini Sep 1, 2023
e3e2007
remove ImportedLibraries from context
alessio-perugini Sep 1, 2023
4346e16
remove LibrariesResolutionResults from context
alessio-perugini Sep 1, 2023
161e747
remove LibrariesManager from context
alessio-perugini Sep 1, 2023
3aa1e00
fix regression exceeding 100% status bar
alessio-perugini Sep 1, 2023
27fbcfb
refactor find_includes
alessio-perugini Sep 2, 2023
ea37d54
refactoring the cmd.Exec in favour of executils
alessio-perugini Sep 4, 2023
417e951
use detector FindIncludes in tests
alessio-perugini Sep 5, 2023
bf04109
add comments and make some plubic methods private
alessio-perugini Sep 5, 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
31 changes: 10 additions & 21 deletions legacy/builder/types/accessories.go → arduino/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,18 @@
// 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 builder

import "golang.org/x/exp/slices"
import "github.com/arduino/arduino-cli/arduino/sketch"

type UniqueSourceFileQueue []*SourceFile

func (queue *UniqueSourceFileQueue) Push(value *SourceFile) {
if !queue.Contains(value) {
*queue = append(*queue, value)
}
}

func (queue UniqueSourceFileQueue) Contains(target *SourceFile) bool {
return slices.ContainsFunc(queue, target.Equals)
// Builder is a Sketch builder.
type Builder struct {
sketch *sketch.Sketch
}

func (queue *UniqueSourceFileQueue) Pop() *SourceFile {
old := *queue
x := old[0]
*queue = old[1:]
return x
}

func (queue UniqueSourceFileQueue) Empty() bool {
return len(queue) == 0
// NewBuilder creates a sketch Builder.
func NewBuilder(sk *sketch.Sketch) *Builder {
return &Builder{
sketch: sk,
}
}
31 changes: 14 additions & 17 deletions arduino/builder/compilation_database.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import (
"encoding/json"
"fmt"
"os"
"os/exec"

"github.com/arduino/arduino-cli/executils"
"github.com/arduino/go-paths-helper"
)

Expand Down Expand Up @@ -67,25 +67,22 @@ func (db *CompilationDatabase) SaveToFile() {
}
}

func dirForCommand(command *exec.Cmd) string {
// This mimics what Cmd.Run also does: Use Dir if specified,
// current directory otherwise
if command.Dir != "" {
return command.Dir
}
dir, err := os.Getwd()
if err != nil {
fmt.Println(tr("Error getting current directory for compilation database: %s", err))
return ""
// Add adds a new CompilationDatabase entry
func (db *CompilationDatabase) Add(target *paths.Path, command *executils.Process) {
commandDir := command.GetDir()
if commandDir == "" {
// This mimics what Cmd.Run also does: Use Dir if specified,
// current directory otherwise
dir, err := os.Getwd()
if err != nil {
fmt.Println(tr("Error getting current directory for compilation database: %s", err))
}
commandDir = dir
}
return dir
}

// Add adds a new CompilationDatabase entry
func (db *CompilationDatabase) Add(target *paths.Path, command *exec.Cmd) {
entry := CompilationCommand{
Directory: dirForCommand(command),
Arguments: command.Args,
Directory: commandDir,
Arguments: command.GetArgs(),
File: target.String(),
}

Expand Down
5 changes: 3 additions & 2 deletions arduino/builder/compilation_database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
package builder

import (
"os/exec"
"testing"

"github.com/arduino/arduino-cli/executils"
"github.com/arduino/go-paths-helper"
"github.com/stretchr/testify/require"
)
Expand All @@ -28,7 +28,8 @@ func TestCompilationDatabase(t *testing.T) {
require.NoError(t, err)
defer tmpfile.Remove()

cmd := exec.Command("gcc", "arg1", "arg2")
cmd, err := executils.NewProcess(nil, "gcc", "arg1", "arg2")
require.NoError(t, err)
db := NewCompilationDatabase(tmpfile)
db.Add(paths.New("test"), cmd)
db.SaveToFile()
Expand Down
5 changes: 5 additions & 0 deletions arduino/builder/cpp/cpp.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,8 @@ func ParseString(line string) (string, string, bool) {
i += width
}
}

// WrapWithHyphenI fixdoc
func WrapWithHyphenI(value string) string {
return "\"-I" + value + "\""
}
Loading