]> Cypherpunks.ru repositories - goredo.git/blobdiff - run.go
Relative paths to targets in outside directories
[goredo.git] / run.go
diff --git a/run.go b/run.go
index e40ad1d5d5e4b65a262ea385b4a0e10df3274fa6..589889e3db6edbf62f51f626e5f9ed04394323fd 100644 (file)
--- a/run.go
+++ b/run.go
@@ -21,7 +21,6 @@ package main
 
 import (
        "bufio"
-       "encoding/hex"
        "errors"
        "flag"
        "fmt"
@@ -29,12 +28,14 @@ import (
        "os"
        "os/exec"
        "path"
+       "path/filepath"
        "strings"
        "sync"
        "syscall"
        "time"
 
        "go.cypherpunks.ru/recfile"
+       "go.cypherpunks.ru/tai64n"
        "golang.org/x/sys/unix"
 )
 
@@ -62,7 +63,8 @@ var (
        StderrPrefix string
        Jobs         sync.WaitGroup
 
-       flagTrace        = flag.Bool("x", false, fmt.Sprintf("trace current target (sh -x) (set %s=1 for all others)", EnvTrace))
+       flagTrace        = flag.Bool("x", false, "trace (sh -x) current targets")
+       flagTraceAll     = flag.Bool("xx", false, fmt.Sprintf("trace (sh -x) all targets (%s=1)", EnvTrace))
        flagStderrKeep   = flag.Bool("logs", false, fmt.Sprintf("keep job's stderr (%s=1)", EnvStderrKeep))
        flagStderrSilent = flag.Bool("silent", false, fmt.Sprintf("do not print job's stderr (%s=1)", EnvStderrSilent))
 )
@@ -305,13 +307,22 @@ func runScript(tgtOrig string, errs chan error, traced bool) error {
        }
 
        // Temporary file for stdout
-       fdStdout, err := tempfile(cwd, tgt)
+       fdStdout, err := tempfile(cwdOrig, tgt)
        if err != nil {
                cleanup()
                return TgtErr{tgtOrig, err}
        }
        tmpPath := fdStdout.Name() + ".3" // and for $3
-       args = append(args, tgt, basename, path.Base(tmpPath))
+       tmpPathRel, err := filepath.Rel(cwd, tmpPath)
+       if err != nil {
+               panic(err)
+       }
+       args = append(
+               args,
+               path.Join(dirPrefix, tgt),
+               path.Join(dirPrefix, basename),
+               tmpPathRel,
+       )
 
        cmd := exec.Command(cmdName, args...)
        cmd.Dir = cwd
@@ -409,7 +420,7 @@ func runScript(tgtOrig string, errs chan error, traced bool) error {
                go func() {
                        scanner := bufio.NewScanner(stderr)
                        var line string
-                       ts := new(TAI64N)
+                       ts := new(tai64n.TAI64N)
                        for scanner.Scan() {
                                line = scanner.Text()
                                if strings.HasPrefix(line, childStderrPrefix) {
@@ -418,9 +429,9 @@ func runScript(tgtOrig string, errs chan error, traced bool) error {
                                        continue
                                }
                                if fdStderr != nil {
-                                       tai64nNow(ts)
+                                       tai64n.FromTime(time.Now(), ts)
                                        LogMutex.Lock()
-                                       fmt.Fprintf(fdStderr, "@%s %s\n", hex.EncodeToString(ts[:]), line)
+                                       fmt.Fprintf(fdStderr, "%s %s\n", ts.Encode(), line)
                                        LogMutex.Unlock()
                                }
                                if StderrSilent {