diff --git a/internal/runner/run.go b/internal/runner/run.go index c52845b..035a6b4 100644 --- a/internal/runner/run.go +++ b/internal/runner/run.go @@ -15,15 +15,24 @@ type logsWriter struct { outfd int // 0(manual message) 1(stdout) or 2(stderr) } -func (l *logsWriter) Write(data []byte) (len int, err error) { +func (l *logsWriter) Write(data []byte) (written int, err error) { + datalen := len(data) + written = datalen + l.lock.Lock() defer l.lock.Unlock() + for data[datalen-1] == byte('\n') { + datalen-- + } + data = data[:datalen] + *l.logs = append(*l.logs, LogEntry{ Time: time.Now(), Text: string(data), OutFd: l.outfd, }) + return } @@ -53,13 +62,15 @@ func (p *Profile) Run(dir string, outfile string) (logs Logs, exitcode int, err var systime, usrtime time.Duration + fmt.Fprintf(logman, "building %s", p.Name) + // Run commands runcmds: for i, str := range p.Commands { fmt.Fprintf(logman, "[%d/%d] running \"%s\"", i, len(p.Commands), str) - cmd := exec.Command("sh", "-c", str) + cmd := exec.Command("sh", "-c", "exec "+str) cmd.Env = append(cmd.Env, env...) cmd.Stdout = logout cmd.Stderr = logerr @@ -91,7 +102,7 @@ runcmds: packstr := "zip -r - " + strings.Join(p.Output, " ") fmt.Fprintf(logman, "[fin] packing output: \"%s\"", packstr) - packcmd := exec.Command("sh", "-c", packstr) + packcmd := exec.Command("sh", "-c", "exec "+packstr) packcmd.Dir = p.OutputDir packcmd.Stdout = writer packcmd.Stderr = logerr @@ -101,5 +112,7 @@ runcmds: return } + fmt.Fprintf(logman, "output is at %s", outfile) + return }