Skip to content

Commit 40977db

Browse files
committed
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
1 parent 427c42b commit 40977db

File tree

3 files changed

+77
-28
lines changed

3 files changed

+77
-28
lines changed

newt/builder/load.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -158,16 +158,18 @@ func Load(binBasePath string, bspPkg *pkg.BspPackage,
158158
binBasePath,
159159
}
160160

161-
util.StatusMessage(util.VERBOSITY_VERBOSE, "Load command: %s\n",
161+
util.StatusMessage(util.VERBOSITY_DEFAULT, "Load command: %s\n",
162162
strings.Join(cmd, " "))
163163
util.StatusMessage(util.VERBOSITY_VERBOSE, "Environment:\n")
164164
for _, v := range env {
165165
util.StatusMessage(util.VERBOSITY_VERBOSE, "* %s\n", v)
166166
}
167-
if _, err := util.ShellCommand(cmd, env); err != nil {
167+
168+
if err := util.ShellCommandStreamOutput(cmd, env, true, !util.HideLoadCmdOutput); err != nil {
168169
return err
169170
}
170-
util.StatusMessage(util.VERBOSITY_VERBOSE, "Successfully loaded image.\n")
171+
172+
util.StatusMessage(util.VERBOSITY_DEFAULT, "Successfully loaded image.\n")
171173

172174
return nil
173175
}

newt/settings/settings.go

+1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ func processNewtrc(yc ycfg.YCfg) {
5959

6060
util.SkipNewtCompat, _ = yc.GetValBoolDflt("skip_newt_compat", nil, false)
6161
util.SkipSyscfgRepoHash, _ = yc.GetValBoolDflt("skip_syscfg_repo_hash", nil, false)
62+
util.HideLoadCmdOutput, _ = yc.GetValBoolDflt("hide_load_output", nil, false)
6263
}
6364

6465
func readNewtrc() ycfg.YCfg {

util/util.go

+71-25
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ var ShallowCloneDepth int
5252
var logFile *os.File
5353
var SkipNewtCompat bool
5454
var SkipSyscfgRepoHash bool
55+
var HideLoadCmdOutput bool
5556

5657
func ParseEqualsPair(v string) (string, string, error) {
5758
s := strings.Split(v, "=")
@@ -352,38 +353,14 @@ func EnvironAsMap() (map[string]string, error) {
352353
return m, nil
353354
}
354355

355-
// Execute the specified process and block until it completes. Additionally,
356-
// the amount of combined stdout+stderr output to be logged to the debug log
357-
// can be restricted to a maximum number of characters.
358-
//
359-
// @param cmdStrs The "argv" strings of the command to execute.
360-
// @param env Additional key,value pairs to inject into the
361-
// child process's environment. Specify null
362-
// to just inherit the parent environment.
363-
// @param logCmd Whether to log the command being executed.
364-
// @param maxDbgOutputChrs The maximum number of combined stdout+stderr
365-
// characters to write to the debug log.
366-
// Specify -1 for no limit; 0 for no output.
367-
//
368-
// @return []byte Combined stdout and stderr output of process.
369-
// @return error NewtError on failure. Use IsExit() to
370-
// determine if the command failed to execute
371-
// or if it just returned a non-zero exit
372-
// status.
373-
func ShellCommandLimitDbgOutput(
374-
cmdStrs []string, env map[string]string, logCmd bool,
375-
maxDbgOutputChrs int) ([]byte, error) {
356+
func ShellCommandInit(cmdStrs []string, env map[string]string) (*exec.Cmd, error) {
376357

377358
var name string
378359
var args []string
379360

380361
// Escape special characters for Windows.
381362
fixupCmdArgs(cmdStrs)
382363

383-
if logCmd {
384-
LogShellCmd(cmdStrs, env)
385-
}
386-
387364
if ExecuteShell && (runtime.GOOS == "linux" || runtime.GOOS == "darwin") {
388365
cmd := strings.Join(cmdStrs, " ")
389366
name = "/bin/sh"
@@ -418,6 +395,75 @@ func ShellCommandLimitDbgOutput(
418395
cmd.Env = EnvVarsToSlice(m)
419396
}
420397

398+
return cmd, nil
399+
}
400+
401+
// Execute the specified process and block until it completes. Process'
402+
// output will be redirected to the stdout and stderr if output log is enabled
403+
//
404+
// @param cmdStrs The "argv" strings of the command to execute.
405+
// @param env Additional key,value pairs to inject into the
406+
// child process's environment. Specify null
407+
// to just inherit the parent environment.
408+
// @param logCmd Whether to log the command being executed.
409+
// @param maxDbgOutputChrs Whether to log the output of the process
410+
//
411+
// @return error NewtError on failure. Use IsExit() to
412+
// determine if the command failed to execute
413+
// or if it just returned a non-zero exit
414+
// status.
415+
func ShellCommandStreamOutput(
416+
cmdStrs []string, env map[string]string, logCmd bool,
417+
logOutput bool) error {
418+
419+
cmd, err := ShellCommandInit(cmdStrs, env)
420+
if err != nil {
421+
return err
422+
}
423+
424+
if logCmd {
425+
LogShellCmd(cmdStrs, env)
426+
}
427+
428+
if logOutput {
429+
cmd.Stdout = os.Stdout
430+
cmd.Stderr = os.Stderr
431+
}
432+
433+
return cmd.Run()
434+
}
435+
436+
// Execute the specified process and block until it completes. Additionally,
437+
// the amount of combined stdout+stderr output to be logged to the debug log
438+
// can be restricted to a maximum number of characters.
439+
//
440+
// @param cmdStrs The "argv" strings of the command to execute.
441+
// @param env Additional key,value pairs to inject into the
442+
// child process's environment. Specify null
443+
// to just inherit the parent environment.
444+
// @param logCmd Whether to log the command being executed.
445+
// @param maxDbgOutputChrs The maximum number of combined stdout+stderr
446+
// characters to write to the debug log.
447+
// Specify -1 for no limit; 0 for no output.
448+
//
449+
// @return []byte Combined stdout and stderr output of process.
450+
// @return error NewtError on failure. Use IsExit() to
451+
// determine if the command failed to execute
452+
// or if it just returned a non-zero exit
453+
// status.
454+
func ShellCommandLimitDbgOutput(
455+
cmdStrs []string, env map[string]string, logCmd bool,
456+
maxDbgOutputChrs int) ([]byte, error) {
457+
458+
cmd, err := ShellCommandInit(cmdStrs, env)
459+
if err != nil {
460+
return nil, err
461+
}
462+
463+
if logCmd {
464+
LogShellCmd(cmdStrs, env)
465+
}
466+
421467
o, err := cmd.CombinedOutput()
422468

423469
if maxDbgOutputChrs < 0 || len(o) <= maxDbgOutputChrs {

0 commit comments

Comments
 (0)