This is an automated email from the ASF dual-hosted git repository.

mgorecki pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-newt.git


The following commit(s) were added to refs/heads/master by this push:
     new 40977dbc builder: Print load commands output on default
40977dbc is described below

commit 40977dbcfc872ee47304f06351f7f0bb734dc165
Author: Michal Gorecki <[email protected]>
AuthorDate: Mon Nov 25 11:44:34 2024 +0100

    builder: Print load commands output on default
    
    Now load command output will be printed on default.
    To disable this add "hide_load_output: 1" to ~/.newt/newtrc.yml
---
 newt/builder/load.go      |  8 ++--
 newt/settings/settings.go |  1 +
 util/util.go              | 96 +++++++++++++++++++++++++++++++++++------------
 3 files changed, 77 insertions(+), 28 deletions(-)

diff --git a/newt/builder/load.go b/newt/builder/load.go
index f437e8d5..106d5992 100644
--- a/newt/builder/load.go
+++ b/newt/builder/load.go
@@ -158,16 +158,18 @@ func Load(binBasePath string, bspPkg *pkg.BspPackage,
                binBasePath,
        }
 
-       util.StatusMessage(util.VERBOSITY_VERBOSE, "Load command: %s\n",
+       util.StatusMessage(util.VERBOSITY_DEFAULT, "Load command: %s\n",
                strings.Join(cmd, " "))
        util.StatusMessage(util.VERBOSITY_VERBOSE, "Environment:\n")
        for _, v := range env {
                util.StatusMessage(util.VERBOSITY_VERBOSE, "* %s\n", v)
        }
-       if _, err := util.ShellCommand(cmd, env); err != nil {
+
+       if err := util.ShellCommandStreamOutput(cmd, env, true, 
!util.HideLoadCmdOutput); err != nil {
                return err
        }
-       util.StatusMessage(util.VERBOSITY_VERBOSE, "Successfully loaded 
image.\n")
+
+       util.StatusMessage(util.VERBOSITY_DEFAULT, "Successfully loaded 
image.\n")
 
        return nil
 }
diff --git a/newt/settings/settings.go b/newt/settings/settings.go
index b894b9bf..675c345b 100644
--- a/newt/settings/settings.go
+++ b/newt/settings/settings.go
@@ -59,6 +59,7 @@ func processNewtrc(yc ycfg.YCfg) {
 
        util.SkipNewtCompat, _ = yc.GetValBoolDflt("skip_newt_compat", nil, 
false)
        util.SkipSyscfgRepoHash, _ = yc.GetValBoolDflt("skip_syscfg_repo_hash", 
nil, false)
+       util.HideLoadCmdOutput, _ = yc.GetValBoolDflt("hide_load_output", nil, 
false)
 }
 
 func readNewtrc() ycfg.YCfg {
diff --git a/util/util.go b/util/util.go
index b1b2101f..5ab9ac1b 100644
--- a/util/util.go
+++ b/util/util.go
@@ -52,6 +52,7 @@ var ShallowCloneDepth int
 var logFile *os.File
 var SkipNewtCompat bool
 var SkipSyscfgRepoHash bool
+var HideLoadCmdOutput bool
 
 func ParseEqualsPair(v string) (string, string, error) {
        s := strings.Split(v, "=")
@@ -352,27 +353,7 @@ func EnvironAsMap() (map[string]string, error) {
        return m, nil
 }
 
-// Execute the specified process and block until it completes.  Additionally,
-// the amount of combined stdout+stderr output to be logged to the debug log
-// can be restricted to a maximum number of characters.
-//
-// @param cmdStrs               The "argv" strings of the command to execute.
-// @param env                   Additional key,value pairs to inject into the
-//                                  child process's environment.  Specify null
-//                                  to just inherit the parent environment.
-// @param logCmd                Whether to log the command being executed.
-// @param maxDbgOutputChrs      The maximum number of combined stdout+stderr
-//                                  characters to write to the debug log.
-//                                  Specify -1 for no limit; 0 for no output.
-//
-// @return []byte               Combined stdout and stderr output of process.
-// @return error                NewtError on failure.  Use IsExit() to
-//                                  determine if the command failed to execute
-//                                  or if it just returned a non-zero exit
-//                                  status.
-func ShellCommandLimitDbgOutput(
-       cmdStrs []string, env map[string]string, logCmd bool,
-       maxDbgOutputChrs int) ([]byte, error) {
+func ShellCommandInit(cmdStrs []string, env map[string]string) (*exec.Cmd, 
error) {
 
        var name string
        var args []string
@@ -380,10 +361,6 @@ func ShellCommandLimitDbgOutput(
        // Escape special characters for Windows.
        fixupCmdArgs(cmdStrs)
 
-       if logCmd {
-               LogShellCmd(cmdStrs, env)
-       }
-
        if ExecuteShell && (runtime.GOOS == "linux" || runtime.GOOS == 
"darwin") {
                cmd := strings.Join(cmdStrs, " ")
                name = "/bin/sh"
@@ -418,6 +395,75 @@ func ShellCommandLimitDbgOutput(
                cmd.Env = EnvVarsToSlice(m)
        }
 
+       return cmd, nil
+}
+
+// Execute the specified process and block until it completes. Process'
+// output will be redirected to the stdout and stderr if output log is enabled
+//
+// @param cmdStrs               The "argv" strings of the command to execute.
+// @param env                   Additional key,value pairs to inject into the
+//                                  child process's environment.  Specify null
+//                                  to just inherit the parent environment.
+// @param logCmd                Whether to log the command being executed.
+// @param maxDbgOutputChrs      Whether to log the output of the process
+//
+// @return error                NewtError on failure.  Use IsExit() to
+//                                  determine if the command failed to execute
+//                                  or if it just returned a non-zero exit
+//                                  status.
+func ShellCommandStreamOutput(
+       cmdStrs []string, env map[string]string, logCmd bool,
+       logOutput bool) error {
+
+       cmd, err := ShellCommandInit(cmdStrs, env)
+       if err != nil {
+               return err
+       }
+
+       if logCmd {
+               LogShellCmd(cmdStrs, env)
+       }
+
+       if logOutput {
+               cmd.Stdout = os.Stdout
+               cmd.Stderr = os.Stderr
+       }
+
+       return cmd.Run()
+}
+
+// Execute the specified process and block until it completes.  Additionally,
+// the amount of combined stdout+stderr output to be logged to the debug log
+// can be restricted to a maximum number of characters.
+//
+// @param cmdStrs               The "argv" strings of the command to execute.
+// @param env                   Additional key,value pairs to inject into the
+//                                  child process's environment.  Specify null
+//                                  to just inherit the parent environment.
+// @param logCmd                Whether to log the command being executed.
+// @param maxDbgOutputChrs      The maximum number of combined stdout+stderr
+//                                  characters to write to the debug log.
+//                                  Specify -1 for no limit; 0 for no output.
+//
+// @return []byte               Combined stdout and stderr output of process.
+// @return error                NewtError on failure.  Use IsExit() to
+//                                  determine if the command failed to execute
+//                                  or if it just returned a non-zero exit
+//                                  status.
+func ShellCommandLimitDbgOutput(
+       cmdStrs []string, env map[string]string, logCmd bool,
+       maxDbgOutputChrs int) ([]byte, error) {
+
+       cmd, err := ShellCommandInit(cmdStrs, env)
+       if err != nil {
+               return nil, err
+       }
+
+       if logCmd {
+               LogShellCmd(cmdStrs, env)
+       }
+
        o, err := cmd.CombinedOutput()
 
        if maxDbgOutputChrs < 0 || len(o) <= maxDbgOutputChrs {

Reply via email to