Skip to content

Commit 231a80b

Browse files
Log some informative progress messages
Before, only commands were logged (in verbose mode). However, all commands look similar and it is not quite clear what happens where. By adding some more informative messages, the commands are logically grouped and it is more clear what is happening exactly, which should also help users understand what is wrong when a command fails. Signed-off-by: Matthijs Kooijman <[email protected]>
1 parent f2d04ca commit 231a80b

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

src/arduino.cc/builder/builder.go

+7
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import (
3434
"arduino.cc/builder/i18n"
3535
"arduino.cc/builder/phases"
3636
"arduino.cc/builder/types"
37+
"arduino.cc/builder/utils"
3738
"os"
3839
"reflect"
3940
"strconv"
@@ -81,25 +82,31 @@ func (s *Builder) Run(ctx *types.Context) error {
8182

8283
&ContainerMergeCopySketchFiles{},
8384

85+
utils.LogIfVerbose(constants.LOG_LEVEL_INFO, "Detecting libraries used..."),
8486
&ContainerFindIncludes{},
8587

8688
&WarnAboutArchIncompatibleLibraries{},
8789

90+
utils.LogIfVerbose(constants.LOG_LEVEL_INFO, "Generating function prototypes..."),
8891
&ContainerAddPrototypes{},
8992

93+
utils.LogIfVerbose(constants.LOG_LEVEL_INFO, "Compiling sketch..."),
9094
&RecipeByPrefixSuffixRunner{Prefix: constants.HOOKS_SKETCH_PREBUILD, Suffix: constants.HOOKS_PATTERN_SUFFIX},
9195
&phases.SketchBuilder{},
9296
&RecipeByPrefixSuffixRunner{Prefix: constants.HOOKS_SKETCH_POSTBUILD, Suffix: constants.HOOKS_PATTERN_SUFFIX},
9397

98+
utils.LogIfVerbose(constants.LOG_LEVEL_INFO, "Compiling libraries..."),
9499
&RecipeByPrefixSuffixRunner{Prefix: constants.HOOKS_LIBRARIES_PREBUILD, Suffix: constants.HOOKS_PATTERN_SUFFIX},
95100
&UnusedCompiledLibrariesRemover{},
96101
&phases.LibrariesBuilder{},
97102
&RecipeByPrefixSuffixRunner{Prefix: constants.HOOKS_LIBRARIES_POSTBUILD, Suffix: constants.HOOKS_PATTERN_SUFFIX},
98103

104+
utils.LogIfVerbose(constants.LOG_LEVEL_INFO, "Compiling core..."),
99105
&RecipeByPrefixSuffixRunner{Prefix: constants.HOOKS_CORE_PREBUILD, Suffix: constants.HOOKS_PATTERN_SUFFIX},
100106
&phases.CoreBuilder{},
101107
&RecipeByPrefixSuffixRunner{Prefix: constants.HOOKS_CORE_POSTBUILD, Suffix: constants.HOOKS_PATTERN_SUFFIX},
102108

109+
utils.LogIfVerbose(constants.LOG_LEVEL_INFO, "Linking everything together..."),
103110
&RecipeByPrefixSuffixRunner{Prefix: constants.HOOKS_LINKING_PRELINK, Suffix: constants.HOOKS_PATTERN_SUFFIX},
104111
&phases.Linker{},
105112
&RecipeByPrefixSuffixRunner{Prefix: constants.HOOKS_LINKING_POSTLINK, Suffix: constants.HOOKS_PATTERN_SUFFIX},

src/arduino.cc/builder/phases/libraries_builder.go

+3
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ func compileLibraries(libraries []*types.Library, buildPath string, buildPropert
8282
}
8383

8484
func compileLibrary(library *types.Library, buildPath string, buildProperties props.PropertiesMap, includes []string, verbose bool, warningsLevel string, logger i18n.Logger) ([]string, error) {
85+
if verbose {
86+
logger.Println(constants.LOG_LEVEL_INFO, "Compiling library \"{0}\"", library.Name)
87+
}
8588
libraryBuildPath := filepath.Join(buildPath, library.Name)
8689

8790
err := utils.EnsureFolderExists(libraryBuildPath)

src/arduino.cc/builder/utils/utils.go

+23
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import (
3333
"arduino.cc/builder/constants"
3434
"arduino.cc/builder/gohasissues"
3535
"arduino.cc/builder/i18n"
36+
"arduino.cc/builder/types"
3637
"crypto/md5"
3738
"encoding/hex"
3839
"io/ioutil"
@@ -366,3 +367,25 @@ func MD5Sum(data []byte) string {
366367
md5sumBytes := md5.Sum(data)
367368
return hex.EncodeToString(md5sumBytes[:])
368369
}
370+
371+
type loggerAction struct {
372+
onlyIfVerbose bool
373+
level string
374+
format string
375+
args []interface{}
376+
}
377+
378+
func (l *loggerAction) Run(ctx *types.Context) error {
379+
if !l.onlyIfVerbose || ctx.Verbose {
380+
ctx.GetLogger().Println(l.level, l.format, l.args...)
381+
}
382+
return nil
383+
}
384+
385+
func LogIfVerbose(level string, format string, args ...interface{}) types.Command {
386+
return &loggerAction{true, level, format, args}
387+
}
388+
389+
func LogThis(level string, format string, args ...interface{}) types.Command {
390+
return &loggerAction{false, level, format, args}
391+
}

0 commit comments

Comments
 (0)