Skip to content

Commit 31f1d55

Browse files
Do not always print multiple libraries warning
Previously, this warning was always printed when multiple libraries were found for a header filename. #37 reported that this can be confusing for novice users, when for example a platform library overrides a builtin library, which is typically considered "normal" and should not generate a warning. The previous attempt at fixing #37 (which was reverted) would hide the warning in these "normal" cases, but it ended up also hiding the message in cases where it would be relevant (as [reported on the mailing list][1]). Also, if for a single compilation some of these messages are hidden, but others are not, this might cause users to draw incorrect conclusions if they are not aware of the exceptions ("there must be only one library for this header file, since I didn't see any message"). This commit takes a different approach: these messages are only shown when: - The sketch fails to compile. In this case, the message is emitted as a warning, shown in red in the IDE. - Verbose compilation is enabled. In this case, the message is emitted as informational, shown in white in the IDE. This means that these message are either *all* shown, or *none* of them are shown, which should make the behaviour more predictable. There is still a chance that the "normal" messages described in #37 confuse a novice user when there is a compilation error completely unrelated to the chosen libraries, but it is pretty impossible for arduino-builder to know the cause of a failed compilation, so just showing all of these messages on an error seems the best approach. This fixes #37 (again). [1]: https://groups.google.com/a/arduino.cc/d/msg/developers/1kkIqIsbuzU/0-abwr1gBQAJ Signed-off-by: Matthijs Kooijman <[email protected]>
1 parent fc9d4d9 commit 31f1d55

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

Diff for: src/arduino.cc/builder/builder.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ func (s *Builder) Run(ctx *types.Context) error {
116116
mainErr := runCommands(ctx, commands, true)
117117

118118
commands = []types.Command{
119-
&PrintUsedAndNotUsedLibraries{},
119+
&PrintUsedAndNotUsedLibraries{ SketchError: mainErr != nil },
120120

121121
&PrintUsedLibrariesIfVerbose{},
122122
}

Diff for: src/arduino.cc/builder/print_used_and_not_used_libraries.go

+15-5
Original file line numberDiff line numberDiff line change
@@ -36,21 +36,31 @@ import (
3636
"time"
3737
)
3838

39-
type PrintUsedAndNotUsedLibraries struct{}
39+
type PrintUsedAndNotUsedLibraries struct {
40+
// Was there an error while compiling the sketch?
41+
SketchError bool
42+
}
4043

4144
func (s *PrintUsedAndNotUsedLibraries) Run(ctx *types.Context) error {
42-
if ctx.DebugLevel < 0 {
45+
var logLevel string
46+
// Print this message as warning when the sketch didn't compile,
47+
// as info when we're verbose and not all otherwise
48+
if s.SketchError {
49+
logLevel = constants.LOG_LEVEL_WARN
50+
} else if ctx.Verbose {
51+
logLevel = constants.LOG_LEVEL_INFO
52+
} else {
4353
return nil
4454
}
4555

4656
logger := ctx.GetLogger()
4757
libraryResolutionResults := ctx.LibrariesResolutionResults
4858

4959
for header, libResResult := range libraryResolutionResults {
50-
logger.Fprintln(os.Stdout, constants.LOG_LEVEL_WARN, constants.MSG_LIBRARIES_MULTIPLE_LIBS_FOUND_FOR, header)
51-
logger.Fprintln(os.Stdout, constants.LOG_LEVEL_WARN, constants.MSG_LIBRARIES_USED, libResResult.Library.Folder)
60+
logger.Fprintln(os.Stdout, logLevel, constants.MSG_LIBRARIES_MULTIPLE_LIBS_FOUND_FOR, header)
61+
logger.Fprintln(os.Stdout, logLevel, constants.MSG_LIBRARIES_USED, libResResult.Library.Folder)
5262
for _, notUsedLibrary := range libResResult.NotUsedLibraries {
53-
logger.Fprintln(os.Stdout, constants.LOG_LEVEL_WARN, constants.MSG_LIBRARIES_NOT_USED, notUsedLibrary.Folder)
63+
logger.Fprintln(os.Stdout, logLevel, constants.MSG_LIBRARIES_NOT_USED, notUsedLibrary.Folder)
5464
}
5565
}
5666

0 commit comments

Comments
 (0)