From 8da22877641740774b048939b2052da12c4666f7 Mon Sep 17 00:00:00 2001 From: Alessio Perugini Date: Tue, 12 Sep 2023 18:03:54 +0200 Subject: [PATCH] make PrintUsedLibraries a method recevier of arduino/builder --- arduino/builder/libraries.go | 34 ++++++++++++ legacy/builder/builder.go | 3 +- .../print_used_libraries_if_verbose.go | 54 ------------------- 3 files changed, 35 insertions(+), 56 deletions(-) delete mode 100644 legacy/builder/print_used_libraries_if_verbose.go diff --git a/arduino/builder/libraries.go b/arduino/builder/libraries.go index fcd896fb9d9..2c33073b0ba 100644 --- a/arduino/builder/libraries.go +++ b/arduino/builder/libraries.go @@ -17,6 +17,7 @@ package builder import ( "strings" + "time" "github.com/arduino/arduino-cli/arduino/builder/compilation" "github.com/arduino/arduino-cli/arduino/builder/cpp" @@ -343,3 +344,36 @@ func (b *Builder) WarnAboutArchIncompatibleLibraries( } } } + +// PrintUsedLibraries fixdoc +// TODO here we can completly remove this part as it's duplicated in what we can +// read in the gRPC response +func (b *Builder) PrintUsedLibraries(importedLibraries libraries.List) { + if !b.logger.Verbose() || len(importedLibraries) == 0 { + return + } + + for _, library := range importedLibraries { + legacy := "" + if library.IsLegacy { + legacy = tr("(legacy)") + } + if library.Version.String() == "" { + b.logger.Info( + tr("Using library %[1]s in folder: %[2]s %[3]s", + library.Name, + library.InstallDir, + legacy)) + } else { + b.logger.Info( + tr("Using library %[1]s at version %[2]s in folder: %[3]s %[4]s", + library.Name, + library.Version, + library.InstallDir, + legacy)) + } + } + + // TODO Why is this here? + time.Sleep(100 * time.Millisecond) +} diff --git a/legacy/builder/builder.go b/legacy/builder/builder.go index 751317e4524..5bfaa8ff9de 100644 --- a/legacy/builder/builder.go +++ b/legacy/builder/builder.go @@ -211,8 +211,7 @@ func (s *Builder) Run(ctx *types.Context) error { }), types.BareCommand(func(ctx *types.Context) error { - infoOut, _ := PrintUsedLibrariesIfVerbose(ctx.BuilderLogger.Verbose(), ctx.SketchLibrariesDetector.ImportedLibraries()) - ctx.BuilderLogger.Info(string(infoOut)) + ctx.Builder.PrintUsedLibraries(ctx.SketchLibrariesDetector.ImportedLibraries()) return nil }), diff --git a/legacy/builder/print_used_libraries_if_verbose.go b/legacy/builder/print_used_libraries_if_verbose.go deleted file mode 100644 index 1ae369d30a2..00000000000 --- a/legacy/builder/print_used_libraries_if_verbose.go +++ /dev/null @@ -1,54 +0,0 @@ -// This file is part of arduino-cli. -// -// Copyright 2020 ARDUINO SA (http://www.arduino.cc/) -// -// This software is released under the GNU General Public License version 3, -// which covers the main part of arduino-cli. -// The terms of this license can be found at: -// https://www.gnu.org/licenses/gpl-3.0.en.html -// -// You can be released from the requirements of the above licenses by purchasing -// a commercial license. Buying such a license is mandatory if you want to -// modify or otherwise use the software for commercial activities involving the -// Arduino software without disclosing the source code of your own applications. -// To purchase a commercial license, send an email to license@arduino.cc. - -package builder - -import ( - "bytes" - "time" - - "github.com/arduino/arduino-cli/arduino/libraries" -) - -func PrintUsedLibrariesIfVerbose(verbose bool, importedLibraries libraries.List) ([]byte, error) { - if !verbose || len(importedLibraries) == 0 { - return nil, nil - } - - infoBuf := &bytes.Buffer{} - for _, library := range importedLibraries { - legacy := "" - if library.IsLegacy { - legacy = tr("(legacy)") - } - if library.Version.String() == "" { - infoBuf.WriteString( - tr("Using library %[1]s in folder: %[2]s %[3]s", - library.Name, - library.InstallDir, - legacy)) - } else { - infoBuf.WriteString( - tr("Using library %[1]s at version %[2]s in folder: %[3]s %[4]s", - library.Name, - library.Version, - library.InstallDir, - legacy)) - } - } - - time.Sleep(100 * time.Millisecond) - return infoBuf.Bytes(), nil -}