Skip to content

Commit 2c19d22

Browse files
authored
Merge branch 'arduino:master' into master
2 parents 0cacb1a + 67f461e commit 2c19d22

File tree

75 files changed

+3581
-1859
lines changed

Some content is hidden

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

75 files changed

+3581
-1859
lines changed

legacy/builder/types/accessories.go renamed to arduino/builder/builder.go

Lines changed: 10 additions & 21 deletions
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 license@arduino.cc.
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
}

arduino/builder/compilation_database.go

Lines changed: 14 additions & 17 deletions
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

arduino/builder/compilation_database_test.go

Lines changed: 3 additions & 2 deletions
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()

arduino/builder/cpp/cpp.go

Lines changed: 5 additions & 0 deletions
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)