Skip to content

Commit 02df09c

Browse files
make Linker a method recevier of arduino/builder
1 parent da308d8 commit 02df09c

File tree

3 files changed

+28
-62
lines changed

3 files changed

+28
-62
lines changed

arduino/builder/builder.go

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -155,16 +155,6 @@ func (b *Builder) GetBuildProperties() *properties.Map {
155155
return b.buildProperties
156156
}
157157

158-
// Jobs number of parallel processes
159-
func (b *Builder) Jobs() int {
160-
return b.jobs
161-
}
162-
163-
// CustomBuildProperties returns user provided custom build properties
164-
func (b *Builder) CustomBuildProperties() []string {
165-
return b.customBuildProperties
166-
}
167-
168158
// GetBuildPath returns the build path
169159
func (b *Builder) GetBuildPath() *paths.Path {
170160
return b.buildPath
@@ -175,11 +165,6 @@ func (b *Builder) GetSketchBuildPath() *paths.Path {
175165
return b.sketchBuildPath
176166
}
177167

178-
// GetCoreBuildPath returns the core build path
179-
func (b *Builder) GetCoreBuildPath() *paths.Path {
180-
return b.coreBuildPath
181-
}
182-
183168
// GetLibrariesBuildPath returns the libraries build path
184169
func (b *Builder) GetLibrariesBuildPath() *paths.Path {
185170
return b.librariesBuildPath

arduino/builder/linker.go

Lines changed: 27 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -16,33 +16,28 @@
1616
package builder
1717

1818
import (
19-
"bytes"
2019
"strings"
2120

22-
"github.com/arduino/arduino-cli/arduino/builder/logger"
2321
"github.com/arduino/arduino-cli/arduino/builder/utils"
2422
f "github.com/arduino/arduino-cli/internal/algorithms"
2523
"github.com/arduino/go-paths-helper"
26-
"github.com/arduino/go-properties-orderedmap"
2724
"github.com/pkg/errors"
2825
)
2926

30-
// Linker fixdoc
31-
func Linker(
27+
// Link fixdoc
28+
func (b *Builder) Link(
3229
onlyUpdateCompilationDatabase bool,
3330
sketchObjectFiles, librariesObjectFiles, coreObjectsFiles paths.PathList,
34-
coreArchiveFilePath, buildPath *paths.Path,
35-
buildProperties *properties.Map,
36-
builderLogger *logger.BuilderLogger,
37-
) ([]byte, error) {
38-
verboseInfo := &bytes.Buffer{}
31+
coreArchiveFilePath *paths.Path,
32+
) error {
3933
if onlyUpdateCompilationDatabase {
40-
if builderLogger.Verbose() {
41-
verboseInfo.WriteString(tr("Skip linking of final executable."))
34+
if b.logger.Verbose() {
35+
b.logger.Info(tr("Skip linking of final executable."))
4236
}
43-
return verboseInfo.Bytes(), nil
37+
return nil
4438
}
4539

40+
// TODO can we remove this multiple assignations?
4641
objectFilesSketch := sketchObjectFiles
4742
objectFilesLibraries := librariesObjectFiles
4843
objectFilesCore := coreObjectsFiles
@@ -52,25 +47,19 @@ func Linker(
5247
objectFiles.AddAll(objectFilesLibraries)
5348
objectFiles.AddAll(objectFilesCore)
5449

55-
coreDotARelPath, err := buildPath.RelTo(coreArchiveFilePath)
50+
coreDotARelPath, err := b.buildPath.RelTo(coreArchiveFilePath)
5651
if err != nil {
57-
return nil, errors.WithStack(err)
52+
return errors.WithStack(err)
5853
}
5954

60-
verboseInfoOut, err := link(objectFiles, coreDotARelPath, coreArchiveFilePath, buildProperties, builderLogger)
61-
verboseInfo.Write(verboseInfoOut)
62-
if err != nil {
63-
return verboseInfo.Bytes(), errors.WithStack(err)
55+
if err := b.link(objectFiles, coreDotARelPath, coreArchiveFilePath); err != nil {
56+
return errors.WithStack(err)
6457
}
6558

66-
return verboseInfo.Bytes(), nil
59+
return nil
6760
}
6861

69-
func link(
70-
objectFiles paths.PathList, coreDotARelPath *paths.Path, coreArchiveFilePath *paths.Path, buildProperties *properties.Map,
71-
builderLogger *logger.BuilderLogger,
72-
) ([]byte, error) {
73-
verboseBuffer := &bytes.Buffer{}
62+
func (b *Builder) link(objectFiles paths.PathList, coreDotARelPath *paths.Path, coreArchiveFilePath *paths.Path) error {
7463
wrapWithDoubleQuotes := func(value string) string { return "\"" + value + "\"" }
7564
objectFileList := strings.Join(f.Map(objectFiles.AsStrings(), wrapWithDoubleQuotes), " ")
7665

@@ -83,7 +72,7 @@ func link(
8372
// it may happen that a subdir/spi.o inside the archive may be overwritten by a anotherdir/spi.o
8473
// because thery are both named spi.o.
8574

86-
properties := buildProperties.Clone()
75+
properties := b.buildProperties.Clone()
8776
archives := paths.NewPathList()
8877
for _, object := range objectFiles {
8978
if object.HasSuffix(".a") {
@@ -102,36 +91,36 @@ func link(
10291

10392
command, err := utils.PrepareCommandForRecipe(properties, "recipe.ar.pattern", false)
10493
if err != nil {
105-
return nil, errors.WithStack(err)
94+
return errors.WithStack(err)
10695
}
10796

108-
if verboseInfo, _, _, err := utils.ExecCommand(builderLogger.Verbose(), builderLogger.Stdout(), builderLogger.Stderr(), command, utils.ShowIfVerbose /* stdout */, utils.Show /* stderr */); err != nil {
109-
if builderLogger.Verbose() {
110-
verboseBuffer.WriteString(string(verboseInfo))
97+
if verboseInfo, _, _, err := utils.ExecCommand(b.logger.Verbose(), b.logger.Stdout(), b.logger.Stderr(), command, utils.ShowIfVerbose /* stdout */, utils.Show /* stderr */); err != nil {
98+
if b.logger.Verbose() {
99+
b.logger.Info(string(verboseInfo))
111100
}
112-
return verboseBuffer.Bytes(), errors.WithStack(err)
101+
return errors.WithStack(err)
113102
}
114103
}
115104

116105
objectFileList = strings.Join(f.Map(archives.AsStrings(), wrapWithDoubleQuotes), " ")
117106
objectFileList = "-Wl,--whole-archive " + objectFileList + " -Wl,--no-whole-archive"
118107
}
119108

120-
properties := buildProperties.Clone()
109+
properties := b.buildProperties.Clone()
121110
properties.Set("compiler.c.elf.flags", properties.Get("compiler.c.elf.flags"))
122-
properties.Set("compiler.warning_flags", properties.Get("compiler.warning_flags."+builderLogger.WarningsLevel()))
111+
properties.Set("compiler.warning_flags", properties.Get("compiler.warning_flags."+b.logger.WarningsLevel()))
123112
properties.Set("archive_file", coreDotARelPath.String())
124113
properties.Set("archive_file_path", coreArchiveFilePath.String())
125114
properties.Set("object_files", objectFileList)
126115

127116
command, err := utils.PrepareCommandForRecipe(properties, "recipe.c.combine.pattern", false)
128117
if err != nil {
129-
return verboseBuffer.Bytes(), err
118+
return err
130119
}
131120

132-
verboseInfo, _, _, err := utils.ExecCommand(builderLogger.Verbose(), builderLogger.Stdout(), builderLogger.Stderr(), command, utils.ShowIfVerbose /* stdout */, utils.Show /* stderr */)
133-
if builderLogger.Verbose() {
134-
verboseBuffer.WriteString(string(verboseInfo))
121+
verboseInfo, _, _, err := utils.ExecCommand(b.logger.Verbose(), b.logger.Stdout(), b.logger.Stderr(), command, utils.ShowIfVerbose /* stdout */, utils.Show /* stderr */)
122+
if b.logger.Verbose() {
123+
b.logger.Info(string(verboseInfo))
135124
}
136-
return verboseBuffer.Bytes(), err
125+
return err
137126
}

legacy/builder/builder.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import (
1919
"reflect"
2020
"time"
2121

22-
"github.com/arduino/arduino-cli/arduino/builder"
2322
"github.com/arduino/arduino-cli/arduino/builder/sizer"
2423
"github.com/arduino/arduino-cli/i18n"
2524
"github.com/arduino/arduino-cli/legacy/builder/types"
@@ -142,20 +141,13 @@ func (s *Builder) Run(ctx *types.Context) error {
142141
}),
143142

144143
types.BareCommand(func(ctx *types.Context) error {
145-
verboseInfoOut, err := builder.Linker(
144+
return ctx.Builder.Link(
146145
ctx.OnlyUpdateCompilationDatabase,
147146
ctx.SketchObjectFiles,
148147
ctx.LibrariesObjectFiles,
149148
ctx.CoreObjectsFiles,
150149
ctx.CoreArchiveFilePath,
151-
ctx.Builder.GetBuildPath(),
152-
ctx.Builder.GetBuildProperties(),
153-
ctx.BuilderLogger,
154150
)
155-
if ctx.BuilderLogger.Verbose() {
156-
ctx.BuilderLogger.Info(string(verboseInfoOut))
157-
}
158-
return err
159151
}),
160152

161153
types.BareCommand(func(ctx *types.Context) error {

0 commit comments

Comments
 (0)