README | 2 +- dep.go | 23 +++++++++++++++-------- main.go | 10 ++++++++-- run.go | 5 ++++- t/goredo-deps.t | 40 ++++++++++++++++++++++++++++++++++++++++ usage.go | 2 +- diff --git a/README b/README index 9f713d693b166a4800566266734ef2d165c501b5595f966b3d90319d2273488f..f56606eb2a0d8fbfd614b6005aaa73efc8c15b23545f8eba2c036dc9a50fa23d 100644 --- 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 4d7ca236b5b9feea889d5cd049f2dc12c3af10c78ccbc2cc9e53d69f5313ced9..f38a9c0f6b72158d20d54d08b859e87086ba12f1981299dbb06ebef9fd231cba 100644 --- a/dep.go +++ b/dep.go @@ -27,12 +27,14 @@ "fmt" "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) @@ -129,17 +131,22 @@ if fdDep == nil { 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 0216230fc5ed5b59052b012a0916d600aaae337ce34c8f67ce4e73a039f51691..9067dc05319185aa6a016b434cfcc2008a1ae4414a3acefd96f56df87c509add 100644 --- a/main.go +++ b/main.go @@ -112,6 +112,7 @@ if err != nil { panic(err) } } + DirPrefix = os.Getenv(EnvDirPrefix) if *flagStderrKeep { mustSetenv(EnvStderrKeep, "1") @@ -199,7 +200,10 @@ 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 @@ } } 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 1b6bbddc487813b9ad7b7f333239fdee703394c8767cad88caa5dc415d16fa16..d7f227cd168e012a7448ff1625f092792fe49640e463c643eda867195afd605a 100644 --- a/run.go +++ b/run.go @@ -379,7 +379,10 @@ return TgtErr{tgtOrig, err} } 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 index 0000000000000000000000000000000000000000..a1c454bdc4ff28b57352950c2ba50cb76ecfb685b25a8299bccd8846688ec3cd --- /dev/null +++ b/t/goredo-deps.t @@ -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 < default.pre.do < footer.inc +echo "" > 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 diff --git a/usage.go b/usage.go index d44722db3a86e8e0f538bac1249596b790fdad3219893779b2a302fd8258212e..f01619f58cd0d550f3e3fa19c85e06c1661a57b5a6f27925dc8043da7e2b2b09 100644 --- a/usage.go +++ b/usage.go @@ -26,7 +26,7 @@ "strings" ) 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.