From a1394bc35f4473f55d6e56afa720c490d3e7f6bd Mon Sep 17 00:00:00 2001 From: Sergey Matveev Date: Fri, 2 Jul 2021 18:56:45 +0300 Subject: [PATCH] Correct relative dependency paths --- dep.go | 11 +++++++++-- doc/news.texi | 11 +++++++++++ main.go | 1 + run.go | 2 ++ t/goredo-deps-after-cd.t | 25 +++++++++++++++++++++++++ usage.go | 2 +- 6 files changed, 49 insertions(+), 3 deletions(-) create mode 100755 t/goredo-deps-after-cd.t diff --git a/dep.go b/dep.go index 0309eff..e1c2aae 100644 --- 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) diff --git a/doc/news.texi b/doc/news.texi index a0ba076..4d3eb3c 100644 --- a/doc/news.texi +++ b/doc/news.texi @@ -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 860d63a..3a7088d 100644 --- 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 1c1b0d7..57401ce 100644 --- 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 index 0000000..a4014a1 --- /dev/null +++ b/t/goredo-deps-after-cd.t @@ -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 < 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 diff --git a/usage.go b/usage.go index 56ccf57..985e879 100644 --- 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 -- 2.44.0