]> Cypherpunks.ru repositories - goredo.git/commitdiff
Correct relative dependency paths v1.8.0
authorSergey Matveev <stargrave@stargrave.org>
Fri, 2 Jul 2021 15:56:45 +0000 (18:56 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Fri, 2 Jul 2021 15:56:45 +0000 (18:56 +0300)
dep.go
doc/news.texi
main.go
run.go
t/goredo-deps-after-cd.t [new file with mode: 0755]
usage.go

diff --git a/dep.go b/dep.go
index 0309effc42336c14993a573942b50ac705766075..e1c2aae383944f90741350deee21dae2a8c9b53c 100644 (file)
--- a/dep.go
+++ b/dep.go
@@ -32,7 +32,10 @@ import (
        "lukechampine.com/blake3"
 )
 
-var DirPrefix string
+var (
+       DirPrefix string
+       DepCwd    string
+)
 
 func recfileWrite(fdDep *os.File, fields ...recfile.Field) error {
        w := recfile.NewWriter(fdDep)
@@ -122,7 +125,11 @@ func writeDeps(fdDep *os.File, tgts []string) (err error) {
                if err != nil {
                        panic(err)
                }
-               tgtDir := path.Join(Cwd, DirPrefix)
+               cwd := Cwd
+               if DepCwd != "" && Cwd != DepCwd {
+                       cwd = DepCwd
+               }
+               tgtDir := path.Join(cwd, DirPrefix)
                tgtRel, err := filepath.Rel(tgtDir, tgtAbs)
                if err != nil {
                        panic(err)
index a0ba0768e05969c9c575432a13f4596c88b489c9..4d3eb3c81f47123345dd90797b508519b7327f81 100644 (file)
@@ -1,6 +1,17 @@
 @node News
 @unnumbered News
 
+@anchor{Release 1.8.0}
+@section Release 1.8.0
+@itemize
+@item
+    Fixed possibly wrong relative path record of the dependency, when
+    redo commands are run in different directory from the @file{.do}.
+@item
+    Fixed possible failing in @command{redo-sources} if no @file{.dep}
+    is found.
+@end itemize
+
 @anchor{Release 1.7.0}
 @section Release 1.7.0
 @itemize
diff --git a/main.go b/main.go
index 860d63a5bd43f315a97350ca6efeaf729a332662..3a7088d16431492773e78a07781e54ff85eeef19 100644 (file)
--- a/main.go
+++ b/main.go
@@ -123,6 +123,7 @@ func main() {
                }
        }
        DirPrefix = os.Getenv(EnvDirPrefix)
+       DepCwd = os.Getenv(EnvDepCwd)
 
        if *flagStderrKeep {
                mustSetenv(EnvStderrKeep, "1")
diff --git a/run.go b/run.go
index 1c1b0d7759295786f9e1237975a5a8e18064bd1f..57401ce627a54c83d6bfac2320c00a1ccc06a655 100644 (file)
--- a/run.go
+++ b/run.go
@@ -42,6 +42,7 @@ import (
 const (
        EnvDepFd        = "REDO_DEP_FD"
        EnvDirPrefix    = "REDO_DIRPREFIX"
+       EnvDepCwd       = "REDO_DEP_CWD"
        EnvBuildUUID    = "REDO_BUILD_UUID"
        EnvStderrPrefix = "REDO_STDERR_PREFIX"
        EnvTrace        = "REDO_TRACE"
@@ -421,6 +422,7 @@ func runScript(tgtOrig string, errs chan error, traced bool) error {
                cmd.ExtraFiles = append(cmd.ExtraFiles, fdDep)
                cmd.Env = append(cmd.Env, fmt.Sprintf("%s=%d", EnvDepFd, 3+fdNum))
                fdNum++
+               cmd.Env = append(cmd.Env, fmt.Sprintf("%s=%s", EnvDepCwd, cwd))
 
                defer func() {
                        jsRelease(shCtx, jsToken)
diff --git a/t/goredo-deps-after-cd.t b/t/goredo-deps-after-cd.t
new file mode 100755 (executable)
index 0000000..a4014a1
--- /dev/null
@@ -0,0 +1,25 @@
+#!/bin/sh
+
+testname=`basename "$0"`
+test_description="Check that dependencies have correct relative path after cd"
+. $SHARNESS_TEST_SRCDIR/sharness.sh
+
+tmp=`mktemp -d`
+trap "rm -fr $tmp" HUP PIPE INT QUIT TERM EXIT
+
+cd $tmp
+mkdir -p bin src
+cat > bin/default.do <<EOF
+cd ../src
+redo-ifchange src.go
+echo bla bla bla
+EOF
+echo source code > src/src.go
+
+test_expect_success Build "redo bin/cmd"
+stat1=`stat bin/cmd`
+test_expect_success Rebuild "redo-ifchange bin/cmd"
+stat2=`stat bin/cmd`
+test_expect_success "Was not rebuild" '[ "$stat1" = "$stat2" ]'
+
+test_done
index 56ccf574faf9277932f2b41dc78ea2d983beab7c..985e879095bf8eaefd77cf72f8a312bf18df5eff 100644 (file)
--- a/usage.go
+++ b/usage.go
@@ -24,7 +24,7 @@ import (
 )
 
 const (
-       Version  = "1.7.0"
+       Version  = "1.8.0"
        Warranty = `Copyright (C) 2020-2021 Sergey Matveev
 
 This program is free software: you can redistribute it and/or modify