Skip to content

Commit 0a4319f

Browse files
authored
Merge branch 'arduino:master' into master
2 parents 92800d5 + 65915d8 commit 0a4319f

File tree

60 files changed

+1702
-1426
lines changed

Some content is hidden

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

60 files changed

+1702
-1426
lines changed

arduino/builder/builder.go

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,59 @@
1515

1616
package builder
1717

18-
import "github.com/arduino/arduino-cli/arduino/sketch"
18+
import (
19+
"github.com/arduino/arduino-cli/arduino/sketch"
20+
"github.com/arduino/go-paths-helper"
21+
"github.com/arduino/go-properties-orderedmap"
22+
)
1923

2024
// Builder is a Sketch builder.
2125
type Builder struct {
22-
sketch *sketch.Sketch
26+
sketch *sketch.Sketch
27+
buildProperties *properties.Map
28+
29+
// core related
30+
coreBuildCachePath *paths.Path
2331
}
2432

2533
// NewBuilder creates a sketch Builder.
26-
func NewBuilder(sk *sketch.Sketch) *Builder {
34+
func NewBuilder(
35+
sk *sketch.Sketch,
36+
boardBuildProperties *properties.Map,
37+
buildPath *paths.Path,
38+
optimizeForDebug bool,
39+
coreBuildCachePath *paths.Path,
40+
) *Builder {
41+
buildProperties := properties.NewMap()
42+
if boardBuildProperties != nil {
43+
buildProperties.Merge(boardBuildProperties)
44+
}
45+
46+
if buildPath != nil {
47+
buildProperties.SetPath("build.path", buildPath)
48+
}
49+
if sk != nil {
50+
buildProperties.Set("build.project_name", sk.MainFile.Base())
51+
buildProperties.SetPath("build.source.path", sk.FullPath)
52+
}
53+
if optimizeForDebug {
54+
if debugFlags, ok := buildProperties.GetOk("compiler.optimization_flags.debug"); ok {
55+
buildProperties.Set("compiler.optimization_flags", debugFlags)
56+
}
57+
} else {
58+
if releaseFlags, ok := buildProperties.GetOk("compiler.optimization_flags.release"); ok {
59+
buildProperties.Set("compiler.optimization_flags", releaseFlags)
60+
}
61+
}
62+
2763
return &Builder{
28-
sketch: sk,
64+
sketch: sk,
65+
buildProperties: buildProperties,
66+
coreBuildCachePath: coreBuildCachePath,
2967
}
3068
}
69+
70+
// GetBuildProperties returns the build properties for running this build
71+
func (b *Builder) GetBuildProperties() *properties.Map {
72+
return b.buildProperties
73+
}

arduino/builder/core.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package builder
2+
3+
import "github.com/arduino/go-paths-helper"
4+
5+
// CoreBuildCachePath fixdoc
6+
func (b *Builder) CoreBuildCachePath() *paths.Path {
7+
return b.coreBuildCachePath
8+
}

arduino/builder/detector/detector.go

Lines changed: 39 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -264,16 +264,16 @@ func (l *SketchLibrariesDetector) findIncludes(
264264

265265
if !l.useCachedLibrariesResolution {
266266
sketch := sketch
267-
mergedfile, err := makeSourceFile(sketchBuildPath, librariesBuildPath, sketch, paths.New(sketch.MainFile.Base()+".cpp"))
267+
mergedfile, err := makeSourceFile(sketchBuildPath, sketchBuildPath, paths.New(sketch.MainFile.Base()+".cpp"))
268268
if err != nil {
269269
return errors.WithStack(err)
270270
}
271271
sourceFileQueue.push(mergedfile)
272272

273-
l.queueSourceFilesFromFolder(sketchBuildPath, librariesBuildPath, sourceFileQueue, sketch, sketchBuildPath, false /* recurse */)
273+
l.queueSourceFilesFromFolder(sourceFileQueue, sketchBuildPath, false /* recurse */, sketchBuildPath, sketchBuildPath)
274274
srcSubfolderPath := sketchBuildPath.Join("src")
275275
if srcSubfolderPath.IsDir() {
276-
l.queueSourceFilesFromFolder(sketchBuildPath, librariesBuildPath, sourceFileQueue, sketch, srcSubfolderPath, true /* recurse */)
276+
l.queueSourceFilesFromFolder(sourceFileQueue, srcSubfolderPath, true /* recurse */, sketchBuildPath, sketchBuildPath)
277277
}
278278

279279
for !sourceFileQueue.empty() {
@@ -419,20 +419,21 @@ func (l *SketchLibrariesDetector) findIncludesUntilDone(
419419
}
420420
} else {
421421
for _, sourceDir := range library.SourceDirs() {
422-
l.queueSourceFilesFromFolder(sketchBuildPath, librariesBuildPath, sourceFileQueue, library, sourceDir.Dir, sourceDir.Recurse)
422+
l.queueSourceFilesFromFolder(sourceFileQueue, sourceDir.Dir, sourceDir.Recurse,
423+
library.SourceDir, librariesBuildPath.Join(library.DirName), library.UtilityDir)
423424
}
424425
}
425426
first = false
426427
}
427428
}
428429

429430
func (l *SketchLibrariesDetector) queueSourceFilesFromFolder(
430-
sketchBuildPath *paths.Path,
431-
librariesBuildPath *paths.Path,
432431
sourceFileQueue *uniqueSourceFileQueue,
433-
origin interface{},
434432
folder *paths.Path,
435433
recurse bool,
434+
sourceDir *paths.Path,
435+
buildDir *paths.Path,
436+
extraIncludePath ...*paths.Path,
436437
) error {
437438
sourceFileExtensions := []string{}
438439
for k := range globals.SourceFilesValidExtensions {
@@ -444,7 +445,7 @@ func (l *SketchLibrariesDetector) queueSourceFilesFromFolder(
444445
}
445446

446447
for _, filePath := range filePaths {
447-
sourceFile, err := makeSourceFile(sketchBuildPath, librariesBuildPath, origin, filePath)
448+
sourceFile, err := makeSourceFile(sourceDir, buildDir, filePath, extraIncludePath...)
448449
if err != nil {
449450
return errors.WithStack(err)
450451
}
@@ -537,33 +538,42 @@ func (f *sourceFile) Equals(g *sourceFile) bool {
537538
// given origin. The given path can be absolute, or relative within the
538539
// origin's root source folder
539540
func makeSourceFile(
540-
sketchBuildPath *paths.Path,
541-
librariesBuildPath *paths.Path,
542-
origin interface{},
543-
path *paths.Path,
541+
sourceDir *paths.Path,
542+
buildDir *paths.Path,
543+
sourceFilePath *paths.Path,
544+
extraIncludePath ...*paths.Path,
544545
) (*sourceFile, error) {
545-
res := &sourceFile{}
546-
547-
switch o := origin.(type) {
548-
case *sketch.Sketch:
549-
res.buildRoot = sketchBuildPath
550-
res.sourceRoot = sketchBuildPath
551-
case *libraries.Library:
552-
res.buildRoot = librariesBuildPath.Join(o.DirName)
553-
res.sourceRoot = o.SourceDir
554-
res.extraIncludePath = o.UtilityDir
555-
default:
556-
panic("Unexpected origin for SourceFile: " + fmt.Sprint(origin))
557-
}
558-
559-
if path.IsAbs() {
546+
res := &sourceFile{
547+
buildRoot: buildDir,
548+
sourceRoot: sourceDir,
549+
}
550+
551+
if len(extraIncludePath) > 1 {
552+
panic("only one extra include path allowed")
553+
}
554+
if len(extraIncludePath) > 0 {
555+
res.extraIncludePath = extraIncludePath[0]
556+
}
557+
// switch o := origin.(type) {
558+
// case *sketch.Sketch:
559+
// res.buildRoot = sketchBuildPath
560+
// res.sourceRoot = sketchBuildPath
561+
// case *libraries.Library:
562+
// res.buildRoot = librariesBuildPath.Join(o.DirName)
563+
// res.sourceRoot = o.SourceDir
564+
// res.extraIncludePath = o.UtilityDir
565+
// default:
566+
// panic("Unexpected origin for SourceFile: " + fmt.Sprint(origin))
567+
// }
568+
569+
if sourceFilePath.IsAbs() {
560570
var err error
561-
path, err = res.sourceRoot.RelTo(path)
571+
sourceFilePath, err = res.sourceRoot.RelTo(sourceFilePath)
562572
if err != nil {
563573
return nil, err
564574
}
565575
}
566-
res.relativePath = path
576+
res.relativePath = sourceFilePath
567577
return res, nil
568578
}
569579

arduino/builder/progress/progress.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package progress
2+
3+
// Struct fixdoc
4+
type Struct struct {
5+
Progress float32
6+
StepAmount float32
7+
Parent *Struct
8+
}
9+
10+
// AddSubSteps fixdoc
11+
func (p *Struct) AddSubSteps(steps int) {
12+
p.Parent = &Struct{
13+
Progress: p.Progress,
14+
StepAmount: p.StepAmount,
15+
Parent: p.Parent,
16+
}
17+
if p.StepAmount == 0.0 {
18+
p.StepAmount = 100.0
19+
}
20+
p.StepAmount /= float32(steps)
21+
}
22+
23+
// RemoveSubSteps fixdoc
24+
func (p *Struct) RemoveSubSteps() {
25+
p.Progress = p.Parent.Progress
26+
p.StepAmount = p.Parent.StepAmount
27+
p.Parent = p.Parent.Parent
28+
}
29+
30+
// CompleteStep fixdoc
31+
func (p *Struct) CompleteStep() {
32+
p.Progress += p.StepAmount
33+
}

legacy/builder/types/progress_test.go renamed to arduino/builder/progress/progress_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
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 progress
1717

1818
import (
1919
"fmt"
@@ -23,7 +23,7 @@ import (
2323
)
2424

2525
func TestProgress(t *testing.T) {
26-
p := &ProgressStruct{}
26+
p := &Struct{}
2727
p.AddSubSteps(3)
2828
require.Equal(t, float32(0.0), p.Progress)
2929
require.InEpsilon(t, 33.33333, p.StepAmount, 0.00001)

arduino/builder/sizer.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package builder
2+
3+
import rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
4+
5+
// ExecutableSectionSize represents a section of the executable output file
6+
type ExecutableSectionSize struct {
7+
Name string `json:"name"`
8+
Size int `json:"size"`
9+
MaxSize int `json:"max_size"`
10+
}
11+
12+
// ExecutablesFileSections is an array of ExecutablesFileSection
13+
type ExecutablesFileSections []ExecutableSectionSize
14+
15+
// ToRPCExecutableSectionSizeArray transforms this array into a []*rpc.ExecutableSectionSize
16+
func (s ExecutablesFileSections) ToRPCExecutableSectionSizeArray() []*rpc.ExecutableSectionSize {
17+
res := []*rpc.ExecutableSectionSize{}
18+
for _, section := range s {
19+
res = append(res, &rpc.ExecutableSectionSize{
20+
Name: section.Name,
21+
Size: int64(section.Size),
22+
MaxSize: int64(section.MaxSize),
23+
})
24+
}
25+
return res
26+
}

arduino/builder/sketch.go

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323
"github.com/arduino/arduino-cli/arduino/builder/cpp"
2424
"github.com/arduino/arduino-cli/i18n"
2525
"github.com/arduino/go-paths-helper"
26-
"github.com/arduino/go-properties-orderedmap"
2726

2827
"github.com/pkg/errors"
2928
)
@@ -166,29 +165,3 @@ func writeIfDifferent(source []byte, destPath *paths.Path) error {
166165
// Source and destination are the same, don't write anything
167166
return nil
168167
}
169-
170-
// SetupBuildProperties adds the build properties related to the sketch to the
171-
// default board build properties map.
172-
func (b *Builder) SetupBuildProperties(boardBuildProperties *properties.Map, buildPath *paths.Path, optimizeForDebug bool) *properties.Map {
173-
buildProperties := properties.NewMap()
174-
buildProperties.Merge(boardBuildProperties)
175-
176-
if buildPath != nil {
177-
buildProperties.SetPath("build.path", buildPath)
178-
}
179-
if b.sketch != nil {
180-
buildProperties.Set("build.project_name", b.sketch.MainFile.Base())
181-
buildProperties.SetPath("build.source.path", b.sketch.FullPath)
182-
}
183-
if optimizeForDebug {
184-
if debugFlags, ok := buildProperties.GetOk("compiler.optimization_flags.debug"); ok {
185-
buildProperties.Set("compiler.optimization_flags", debugFlags)
186-
}
187-
} else {
188-
if releaseFlags, ok := buildProperties.GetOk("compiler.optimization_flags.release"); ok {
189-
buildProperties.Set("compiler.optimization_flags", releaseFlags)
190-
}
191-
}
192-
193-
return buildProperties
194-
}

arduino/builder/sketch_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func TestMergeSketchSources(t *testing.T) {
4848
}
4949
mergedSources := strings.ReplaceAll(string(mergedBytes), "%s", pathToGoldenSource)
5050

51-
b := NewBuilder(sk)
51+
b := NewBuilder(sk, nil, nil, false, nil)
5252
offset, source, err := b.sketchMergeSources(nil)
5353
require.Nil(t, err)
5454
require.Equal(t, 2, offset)
@@ -61,7 +61,7 @@ func TestMergeSketchSourcesArduinoIncluded(t *testing.T) {
6161
require.NotNil(t, sk)
6262

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

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

0 commit comments

Comments
 (0)