]> Cypherpunks.ru repositories - goredo.git/commitdiff
Fix dependencies relative paths determination v0.9.0
authorSergey Matveev <stargrave@stargrave.org>
Sat, 9 Jan 2021 12:42:32 +0000 (15:42 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Sat, 9 Jan 2021 15:07:40 +0000 (18:07 +0300)
README
dep.go
main.go
run.go
t/goredo-deps.t [new file with mode: 0755]
usage.go

diff --git a/README b/README
index a35eab3de85e5246da7c737de1718af811ba3109..d7bae44f77e6f205a5b71d53a7060549810ac968 100644 (file)
--- a/README
+++ b/README
@@ -30,7 +30,7 @@ problems with the authenticity on your side, then build it manually: >
 
     $ git clone git://git.cypherpunks.ru/goredo.git
     $ cd goredo
-    $ git tag -v v0.8.0
+    $ git tag -v v0.9.0
     $ git clone git://git.cypherpunks.ru/gorecfile.git
     $ ( cd gorecfile ; git tag -v v0.4.0 )
     $ echo "replace go.cypherpunks.ru/recfile => `pwd`/gorecfile" >> go.mod
diff --git a/dep.go b/dep.go
index 38d8bb79c200ede2acedeb9ce357fe313211d7c2..df5ae27f2af9737b070b84df719a24f255328d2b 100644 (file)
--- a/dep.go
+++ b/dep.go
@@ -27,13 +27,15 @@ import (
        "io"
        "os"
        "path"
-       "strings"
+       "path/filepath"
 
        "go.cypherpunks.ru/recfile"
        "golang.org/x/crypto/blake2b"
        "golang.org/x/sys/unix"
 )
 
+var DirPrefix string
+
 func recfileWrite(fdDep *os.File, fields ...recfile.Field) error {
        w := recfile.NewWriter(fdDep)
        if _, err := w.RecordStart(); err != nil {
@@ -129,17 +131,22 @@ func writeDeps(fdDep *os.File, tgts []string) error {
                trace(CDebug, "no opened fdDep: %s", tgts)
                return nil
        }
-       ups := []string{}
-       upLevels := strings.Count(os.Getenv(EnvDirPrefix), "/")
-       for i := 0; i < upLevels; i++ {
-               ups = append(ups, "..")
-       }
-       up := path.Join(ups...)
        for _, tgt := range tgts {
                if _, err := os.Stat(tgt); err == nil {
-                       if err = writeDep(fdDep, Cwd, path.Join(up, tgt)); err != nil {
+                       tgtAbs, err := filepath.Abs(tgt)
+                       if err != nil {
+                               panic(err)
+                       }
+                       tgtDir := path.Join(Cwd, DirPrefix)
+                       tgtRel, err := filepath.Rel(tgtDir, tgtAbs)
+                       if err != nil {
+                               panic(err)
+                       }
+                       if err = writeDep(fdDep, tgtDir, tgtRel); err != nil {
                                return err
                        }
+               } else {
+                       trace(CDebug, "skipping dep record, can not stat: %s", tgt)
                }
        }
        return nil
diff --git a/main.go b/main.go
index 1262c57f53c2451a7459384d1f001b0528503ca1..ed82856be37f842e6c66f9a0607d191388cb40ac 100644 (file)
--- a/main.go
+++ b/main.go
@@ -112,6 +112,7 @@ func main() {
                        panic(err)
                }
        }
+       DirPrefix = os.Getenv(EnvDirPrefix)
 
        if *flagStderrKeep {
                mustSetenv(EnvStderrKeep, "1")
@@ -199,7 +200,10 @@ func main() {
        ok := true
        err = nil
        cmdName := path.Base(os.Args[0])
-       trace(CDebug, "[%s] run: %s %s [%s]", BuildUUID, cmdName, tgts, Cwd)
+       trace(
+               CDebug, "[%s] run: %s %s cwd:%s dirprefix:%s",
+               BuildUUID, cmdName, tgts, Cwd, DirPrefix,
+       )
 
 CmdSwitch:
        switch cmdName {
@@ -212,7 +216,9 @@ CmdSwitch:
                }
        case "redo-ifchange":
                ok, err = ifchange(tgts, false, traced)
-               writeDeps(fdDep, tgts)
+               if err == nil {
+                       err = writeDeps(fdDep, tgts)
+               }
        case "redo-ifcreate":
                if fdDep == nil {
                        log.Fatalln("no", EnvDepFd)
diff --git a/run.go b/run.go
index aab8e9a5c7eb4b9d6d1b41acce7939b14681544a..4724870e8a767218584ccb1ae0239034729f9407 100644 (file)
--- a/run.go
+++ b/run.go
@@ -379,7 +379,10 @@ func runScript(tgtOrig string, errs chan error, traced bool) error {
                }
                fdStderr.Truncate(0)
        }
-       shCtx := fmt.Sprintf("sh: %s: %s %s [%s]", tgtOrig, cmdName, args, cwd)
+       shCtx := fmt.Sprintf(
+               "sh: %s: %s %s cwd:%s dirprefix:%s",
+               tgtOrig, cmdName, args, cwd, dirPrefix,
+       )
        trace(CDebug, "%s", shCtx)
 
        Jobs.Add(1)
diff --git a/t/goredo-deps.t b/t/goredo-deps.t
new file mode 100755 (executable)
index 0000000..a0a58d5
--- /dev/null
@@ -0,0 +1,40 @@
+#!/bin/sh
+
+testname=`basename "$0"`
+test_description="Check that the following use-case won't rebuild everytime and has correct dependencies"
+. $SHARNESS_TEST_SRCDIR/sharness.sh
+
+tmp=`mktemp -d`
+trap "rm -fr $tmp" HUP PIPE INT QUIT TERM EXIT
+cd $tmp
+mkdir -p sub
+cat > default.html.do <<EOF
+redo-ifchange \$2.pre
+echo HTML
+cat \$2.pre
+EOF
+cat > default.pre.do <<EOF
+redo-ifchange *.inc \$2.html.in
+echo PRE
+cat \$2.html.in
+EOF
+echo FOOTER > footer.inc
+echo "<html>" > sub/index.html.in
+
+test_expect_success Build "redo sub/index.html"
+stat1=`stat sub/index.html`
+test_expect_success Rebuild "redo-ifchange sub/index.html"
+stat2=`stat sub/index.html`
+test_expect_success "Was not rebuild" '[ "$stat1" = "$stat2" ]'
+
+tgts=`sed -n "s/^Target: //p" sub/.redo/index.html.dep | sort`
+tgts=`echo $tgts`
+tgts_expected="../default.html.do" # .do itself
+tgts_expected="$tgts_expected default.do" # ifcreate
+tgts_expected="$tgts_expected default.html.do" # ifcreate
+tgts_expected="$tgts_expected index.html" # check for user-modification
+tgts_expected="$tgts_expected index.html.do" # ifcreate
+tgts_expected="$tgts_expected index.pre" # source
+test_expect_success "Correct dependencies" '[ "$tgts" = "$tgts_expected" ]'
+
+test_done
index 8f0b0e591d0664cf21dbdd164c82be11565e7367..caa905b9d2509dca720c4031ee7a8ace39f9c07e 100644 (file)
--- a/usage.go
+++ b/usage.go
@@ -26,7 +26,7 @@ import (
 )
 
 const (
-       Version  = "0.8.0"
+       Version  = "0.9.0"
        Warranty = `This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, version 3 of the License.