Skip to content

Commit 72c32ca

Browse files
[skip-changelog] legacy: Builder refactorization (part 1...) (#2286)
* Simplified compileFiles * Starting new Builder (part 1/n) * builder: renamed variable and moved dir creation up * builder: made a sketch-prepress function part of Builder * Removed ctx dependency in PreprocessSketchWithArduinoPreprocessor * uniform parameters between preprocesors * Moved PreprocessSketchWithArduinoPreprocessor into proper place * Inlined function * Converted sketchCopyAdditionalFiles into a Builder method * Made SetupBuildProperties a method of the new Builder * Refactor AddAdditionalEntriesToContext cmaglie#32 * refactor AddAdditionalEntriesToContext in a function * use the new function in all the tests * Move the assignaton of LibrariesResolutionResults inside the ResolveLibrary func The ResolveLibrary func is only called by the ContainerFindIncludes * rename bPath to buildPath * cleanup usless tests * remove shadowed variable * Refactor legacy LibrariesLoader command * move LibrariesLoader under arduino/builder * remove usless nil check * remove AddAdditionalEntries func, in favour of initializing them in the compile command * move a check directly in the compile command * create the SketchLibrariesDetector struct * move all the logic of ContainerSetupHardwareToolsLibsSketchAndProps in the compile command * remove container_setup and adjust relative tests * remove LibraryResolver property from context * remove UseCachedLibrariesResolution for context * remove ImportedLibraries from context * remove LibrariesResolutionResults from context * remove LibrariesManager from context * fix regression exceeding 100% status bar * refactor find_includes * refactoring the cmd.Exec in favour of executils * use detector FindIncludes in tests * add comments and make some plubic methods private --------- Co-authored-by: Alessio Perugini <[email protected]>
1 parent d106a67 commit 72c32ca

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1457
-1600
lines changed

Diff for: legacy/builder/types/accessories.go renamed to arduino/builder/builder.go

+10-21
Original file line numberDiff line numberDiff line change
@@ -13,29 +13,18 @@
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 builder
1717

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

20-
type UniqueSourceFileQueue []*SourceFile
21-
22-
func (queue *UniqueSourceFileQueue) Push(value *SourceFile) {
23-
if !queue.Contains(value) {
24-
*queue = append(*queue, value)
25-
}
26-
}
27-
28-
func (queue UniqueSourceFileQueue) Contains(target *SourceFile) bool {
29-
return slices.ContainsFunc(queue, target.Equals)
20+
// Builder is a Sketch builder.
21+
type Builder struct {
22+
sketch *sketch.Sketch
3023
}
3124

32-
func (queue *UniqueSourceFileQueue) Pop() *SourceFile {
33-
old := *queue
34-
x := old[0]
35-
*queue = old[1:]
36-
return x
37-
}
38-
39-
func (queue UniqueSourceFileQueue) Empty() bool {
40-
return len(queue) == 0
25+
// NewBuilder creates a sketch Builder.
26+
func NewBuilder(sk *sketch.Sketch) *Builder {
27+
return &Builder{
28+
sketch: sk,
29+
}
4130
}

Diff for: arduino/builder/compilation_database.go

+14-17
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ import (
1919
"encoding/json"
2020
"fmt"
2121
"os"
22-
"os/exec"
2322

23+
"github.com/arduino/arduino-cli/executils"
2424
"github.com/arduino/go-paths-helper"
2525
)
2626

@@ -67,25 +67,22 @@ func (db *CompilationDatabase) SaveToFile() {
6767
}
6868
}
6969

70-
func dirForCommand(command *exec.Cmd) string {
71-
// This mimics what Cmd.Run also does: Use Dir if specified,
72-
// current directory otherwise
73-
if command.Dir != "" {
74-
return command.Dir
75-
}
76-
dir, err := os.Getwd()
77-
if err != nil {
78-
fmt.Println(tr("Error getting current directory for compilation database: %s", err))
79-
return ""
70+
// Add adds a new CompilationDatabase entry
71+
func (db *CompilationDatabase) Add(target *paths.Path, command *executils.Process) {
72+
commandDir := command.GetDir()
73+
if commandDir == "" {
74+
// This mimics what Cmd.Run also does: Use Dir if specified,
75+
// current directory otherwise
76+
dir, err := os.Getwd()
77+
if err != nil {
78+
fmt.Println(tr("Error getting current directory for compilation database: %s", err))
79+
}
80+
commandDir = dir
8081
}
81-
return dir
82-
}
8382

84-
// Add adds a new CompilationDatabase entry
85-
func (db *CompilationDatabase) Add(target *paths.Path, command *exec.Cmd) {
8683
entry := CompilationCommand{
87-
Directory: dirForCommand(command),
88-
Arguments: command.Args,
84+
Directory: commandDir,
85+
Arguments: command.GetArgs(),
8986
File: target.String(),
9087
}
9188

Diff for: arduino/builder/compilation_database_test.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
package builder
1717

1818
import (
19-
"os/exec"
2019
"testing"
2120

21+
"github.com/arduino/arduino-cli/executils"
2222
"github.com/arduino/go-paths-helper"
2323
"github.com/stretchr/testify/require"
2424
)
@@ -28,7 +28,8 @@ func TestCompilationDatabase(t *testing.T) {
2828
require.NoError(t, err)
2929
defer tmpfile.Remove()
3030

31-
cmd := exec.Command("gcc", "arg1", "arg2")
31+
cmd, err := executils.NewProcess(nil, "gcc", "arg1", "arg2")
32+
require.NoError(t, err)
3233
db := NewCompilationDatabase(tmpfile)
3334
db.Add(paths.New("test"), cmd)
3435
db.SaveToFile()

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

+5
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,8 @@ func ParseString(line string) (string, string, bool) {
106106
i += width
107107
}
108108
}
109+
110+
// WrapWithHyphenI fixdoc
111+
func WrapWithHyphenI(value string) string {
112+
return "\"-I" + value + "\""
113+
}

0 commit comments

Comments
 (0)