diff --git a/arduino/builder/builder.go b/arduino/builder/builder.go index 69776236508..d2a30b03107 100644 --- a/arduino/builder/builder.go +++ b/arduino/builder/builder.go @@ -155,16 +155,6 @@ func (b *Builder) GetBuildProperties() *properties.Map { return b.buildProperties } -// Jobs number of parallel processes -func (b *Builder) Jobs() int { - return b.jobs -} - -// CustomBuildProperties returns user provided custom build properties -func (b *Builder) CustomBuildProperties() []string { - return b.customBuildProperties -} - // GetBuildPath returns the build path func (b *Builder) GetBuildPath() *paths.Path { return b.buildPath @@ -175,11 +165,6 @@ func (b *Builder) GetSketchBuildPath() *paths.Path { return b.sketchBuildPath } -// GetCoreBuildPath returns the core build path -func (b *Builder) GetCoreBuildPath() *paths.Path { - return b.coreBuildPath -} - // GetLibrariesBuildPath returns the libraries build path func (b *Builder) GetLibrariesBuildPath() *paths.Path { return b.librariesBuildPath diff --git a/arduino/builder/linker.go b/arduino/builder/linker.go index 528e159d0aa..7ae85d15d9b 100644 --- a/arduino/builder/linker.go +++ b/arduino/builder/linker.go @@ -16,33 +16,28 @@ package builder import ( - "bytes" "strings" - "github.com/arduino/arduino-cli/arduino/builder/logger" "github.com/arduino/arduino-cli/arduino/builder/utils" f "github.com/arduino/arduino-cli/internal/algorithms" "github.com/arduino/go-paths-helper" - "github.com/arduino/go-properties-orderedmap" "github.com/pkg/errors" ) -// Linker fixdoc -func Linker( +// Link fixdoc +func (b *Builder) Link( onlyUpdateCompilationDatabase bool, sketchObjectFiles, librariesObjectFiles, coreObjectsFiles paths.PathList, - coreArchiveFilePath, buildPath *paths.Path, - buildProperties *properties.Map, - builderLogger *logger.BuilderLogger, -) ([]byte, error) { - verboseInfo := &bytes.Buffer{} + coreArchiveFilePath *paths.Path, +) error { if onlyUpdateCompilationDatabase { - if builderLogger.Verbose() { - verboseInfo.WriteString(tr("Skip linking of final executable.")) + if b.logger.Verbose() { + b.logger.Info(tr("Skip linking of final executable.")) } - return verboseInfo.Bytes(), nil + return nil } + // TODO can we remove this multiple assignations? objectFilesSketch := sketchObjectFiles objectFilesLibraries := librariesObjectFiles objectFilesCore := coreObjectsFiles @@ -52,25 +47,19 @@ func Linker( objectFiles.AddAll(objectFilesLibraries) objectFiles.AddAll(objectFilesCore) - coreDotARelPath, err := buildPath.RelTo(coreArchiveFilePath) + coreDotARelPath, err := b.buildPath.RelTo(coreArchiveFilePath) if err != nil { - return nil, errors.WithStack(err) + return errors.WithStack(err) } - verboseInfoOut, err := link(objectFiles, coreDotARelPath, coreArchiveFilePath, buildProperties, builderLogger) - verboseInfo.Write(verboseInfoOut) - if err != nil { - return verboseInfo.Bytes(), errors.WithStack(err) + if err := b.link(objectFiles, coreDotARelPath, coreArchiveFilePath); err != nil { + return errors.WithStack(err) } - return verboseInfo.Bytes(), nil + return nil } -func link( - objectFiles paths.PathList, coreDotARelPath *paths.Path, coreArchiveFilePath *paths.Path, buildProperties *properties.Map, - builderLogger *logger.BuilderLogger, -) ([]byte, error) { - verboseBuffer := &bytes.Buffer{} +func (b *Builder) link(objectFiles paths.PathList, coreDotARelPath *paths.Path, coreArchiveFilePath *paths.Path) error { wrapWithDoubleQuotes := func(value string) string { return "\"" + value + "\"" } objectFileList := strings.Join(f.Map(objectFiles.AsStrings(), wrapWithDoubleQuotes), " ") @@ -83,7 +72,7 @@ func link( // it may happen that a subdir/spi.o inside the archive may be overwritten by a anotherdir/spi.o // because thery are both named spi.o. - properties := buildProperties.Clone() + properties := b.buildProperties.Clone() archives := paths.NewPathList() for _, object := range objectFiles { if object.HasSuffix(".a") { @@ -102,14 +91,14 @@ func link( command, err := utils.PrepareCommandForRecipe(properties, "recipe.ar.pattern", false) if err != nil { - return nil, errors.WithStack(err) + return errors.WithStack(err) } - if verboseInfo, _, _, err := utils.ExecCommand(builderLogger.Verbose(), builderLogger.Stdout(), builderLogger.Stderr(), command, utils.ShowIfVerbose /* stdout */, utils.Show /* stderr */); err != nil { - if builderLogger.Verbose() { - verboseBuffer.WriteString(string(verboseInfo)) + if verboseInfo, _, _, err := utils.ExecCommand(b.logger.Verbose(), b.logger.Stdout(), b.logger.Stderr(), command, utils.ShowIfVerbose /* stdout */, utils.Show /* stderr */); err != nil { + if b.logger.Verbose() { + b.logger.Info(string(verboseInfo)) } - return verboseBuffer.Bytes(), errors.WithStack(err) + return errors.WithStack(err) } } @@ -117,21 +106,21 @@ func link( objectFileList = "-Wl,--whole-archive " + objectFileList + " -Wl,--no-whole-archive" } - properties := buildProperties.Clone() + properties := b.buildProperties.Clone() properties.Set("compiler.c.elf.flags", properties.Get("compiler.c.elf.flags")) - properties.Set("compiler.warning_flags", properties.Get("compiler.warning_flags."+builderLogger.WarningsLevel())) + properties.Set("compiler.warning_flags", properties.Get("compiler.warning_flags."+b.logger.WarningsLevel())) properties.Set("archive_file", coreDotARelPath.String()) properties.Set("archive_file_path", coreArchiveFilePath.String()) properties.Set("object_files", objectFileList) command, err := utils.PrepareCommandForRecipe(properties, "recipe.c.combine.pattern", false) if err != nil { - return verboseBuffer.Bytes(), err + return err } - verboseInfo, _, _, err := utils.ExecCommand(builderLogger.Verbose(), builderLogger.Stdout(), builderLogger.Stderr(), command, utils.ShowIfVerbose /* stdout */, utils.Show /* stderr */) - if builderLogger.Verbose() { - verboseBuffer.WriteString(string(verboseInfo)) + verboseInfo, _, _, err := utils.ExecCommand(b.logger.Verbose(), b.logger.Stdout(), b.logger.Stderr(), command, utils.ShowIfVerbose /* stdout */, utils.Show /* stderr */) + if b.logger.Verbose() { + b.logger.Info(string(verboseInfo)) } - return verboseBuffer.Bytes(), err + return err } diff --git a/legacy/builder/builder.go b/legacy/builder/builder.go index a901e5a112d..688a7913b28 100644 --- a/legacy/builder/builder.go +++ b/legacy/builder/builder.go @@ -19,7 +19,6 @@ import ( "reflect" "time" - "github.com/arduino/arduino-cli/arduino/builder" "github.com/arduino/arduino-cli/arduino/builder/sizer" "github.com/arduino/arduino-cli/i18n" "github.com/arduino/arduino-cli/legacy/builder/types" @@ -142,20 +141,13 @@ func (s *Builder) Run(ctx *types.Context) error { }), types.BareCommand(func(ctx *types.Context) error { - verboseInfoOut, err := builder.Linker( + return ctx.Builder.Link( ctx.OnlyUpdateCompilationDatabase, ctx.SketchObjectFiles, ctx.LibrariesObjectFiles, ctx.CoreObjectsFiles, ctx.CoreArchiveFilePath, - ctx.Builder.GetBuildPath(), - ctx.Builder.GetBuildProperties(), - ctx.BuilderLogger, ) - if ctx.BuilderLogger.Verbose() { - ctx.BuilderLogger.Info(string(verboseInfoOut)) - } - return err }), types.BareCommand(func(ctx *types.Context) error {