Skip to content

Commit 4346e16

Browse files
alessio-peruginicmaglie
authored andcommitted
remove LibrariesResolutionResults from context
1 parent e3e2007 commit 4346e16

File tree

5 files changed

+39
-68
lines changed

5 files changed

+39
-68
lines changed

arduino/builder/libraries.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ package builder
1818
import (
1919
"bytes"
2020
"fmt"
21+
"strings"
22+
"time"
2123

2224
"github.com/arduino/arduino-cli/arduino/cores"
2325
"github.com/arduino/arduino-cli/arduino/libraries"
@@ -125,6 +127,37 @@ func (l *SketchLibrariesDetector) UseCachedLibrariesResolution() bool {
125127
return l.useCachedLibrariesResolution
126128
}
127129

130+
// PrintUsedAndNotUsedLibraries todo
131+
func (l *SketchLibrariesDetector) PrintUsedAndNotUsedLibraries(sketchError bool) {
132+
// Print this message:
133+
// - as warning, when the sketch didn't compile
134+
// - as info, when verbose is on
135+
// - otherwise, output nothing
136+
if !sketchError && !l.verbose {
137+
return
138+
}
139+
140+
res := ""
141+
for header, libResResult := range l.librariesResolutionResults {
142+
if len(libResResult.NotUsedLibraries) == 0 {
143+
continue
144+
}
145+
res += fmt.Sprintln(tr(`Multiple libraries were found for "%[1]s"`, header))
146+
res += fmt.Sprintln(" " + tr("Used: %[1]s", libResResult.Library.InstallDir))
147+
for _, notUsedLibrary := range libResResult.NotUsedLibraries {
148+
res += fmt.Sprintln(" " + tr("Not used: %[1]s", notUsedLibrary.InstallDir))
149+
}
150+
}
151+
res = strings.TrimSpace(res)
152+
if sketchError {
153+
l.verboseWarnFn(res)
154+
} else {
155+
l.verboseInfoFn(res)
156+
}
157+
// todo why?? should we remove this?
158+
time.Sleep(100 * time.Millisecond)
159+
}
160+
128161
// AppendIncludeFolder todo should rename this, probably after refactoring the
129162
// container_find_includes command.
130163
//func (l *SketchLibrariesDetector) AppendIncludeFolder(ctx *types.Context, cache *includeCache, sourceFilePath *paths.Path, include string, folder *paths.Path) {

legacy/builder/builder.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,10 @@ func (s *Builder) Run(ctx *types.Context) error {
109109

110110
var otherErr error
111111
commands = []types.Command{
112-
&PrintUsedAndNotUsedLibraries{SketchError: mainErr != nil},
112+
types.BareCommand(func(ctx *types.Context) error {
113+
ctx.SketchLibrariesDetector.PrintUsedAndNotUsedLibraries(mainErr != nil)
114+
return nil
115+
}),
113116

114117
&PrintUsedLibrariesIfVerbose{},
115118

legacy/builder/print_used_and_not_used_libraries.go

Lines changed: 0 additions & 59 deletions
This file was deleted.

legacy/builder/types/context.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,8 @@ type Context struct {
102102
WarningsLevel string
103103

104104
// Libraries handling
105-
LibrariesManager *librariesmanager.LibrariesManager
106-
LibrariesResolutionResults map[string]LibraryResolutionResult
107-
IncludeFolders paths.PathList
105+
LibrariesManager *librariesmanager.LibrariesManager
106+
IncludeFolders paths.PathList
108107

109108
// C++ Parsing
110109
LineOffset int

legacy/builder/types/types.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,6 @@ func (f *SourceFile) DepfilePath() *paths.Path {
9595
return f.buildRoot.Join(f.relativePath.String() + ".d")
9696
}
9797

98-
type LibraryResolutionResult struct {
99-
Library *libraries.Library
100-
NotUsedLibraries []*libraries.Library
101-
}
102-
10398
type Command interface {
10499
Run(ctx *Context) error
105100
}

0 commit comments

Comments
 (0)