]> Cypherpunks.ru repositories - goredo.git/blobdiff - ood.go
default.do-s must not depend on themselves
[goredo.git] / ood.go
diff --git a/ood.go b/ood.go
index 533ef46ea2f64d6dc6de0b3797ec4f2139a12381..c455a3b01e22c3221f0b9a5eccc72db6b83996d0 100644 (file)
--- a/ood.go
+++ b/ood.go
@@ -23,6 +23,7 @@ import (
        "errors"
        "fmt"
        "io"
+       "log"
        "os"
        "path"
        "path/filepath"
@@ -89,6 +90,21 @@ func isSrc(cwd, tgt string) bool {
        return true
 }
 
+func isOODByBuildUUID(cwd, tgtOrig string) bool {
+       cwd, tgt := cwdAndTgt(path.Join(cwd, tgtOrig))
+       depPath := path.Join(cwd, RedoDir, tgt+DepSuffix)
+       fdDep, err := os.Open(depPath)
+       if err != nil {
+               return true
+       }
+       depInfo, err := depRead(fdDep)
+       fdDep.Close()
+       if err != nil || depInfo.build != BuildUUID {
+               return true
+       }
+       return false
+}
+
 func isOOD(cwd, tgtOrig string, level int, seen map[string]struct{}) (bool, error) {
        indent := strings.Repeat(". ", level)
        trace(CDebug, "ood: %s%s checking", indent, tgtOrig)
@@ -109,6 +125,10 @@ func isOOD(cwd, tgtOrig string, level int, seen map[string]struct{}) (bool, erro
                trace(CDebug, "ood: %s%s -> already built", indent, tgtOrig)
                return false, nil
        }
+       if _, err := os.Stat(path.Join(cwd, tgt)); err != nil && os.IsNotExist(err) {
+               trace(CDebug, "ood: %s%s -> non-existent", indent, tgtOrig)
+               return true, nil
+       }
        ood := false
 
        for _, dep := range depInfo.ifcreates {
@@ -210,6 +230,14 @@ func isOODWithTrace(
        }
        _, ood := OODTgts[p]
        if ood {
+               if !isOODByBuildUUID(cwd, tgtOrig) {
+                       trace(
+                               CDebug,
+                               "ood: %s%s -> already built",
+                               strings.Repeat(". ", level), tgtOrig,
+                       )
+                       return false, nil
+               }
                trace(
                        CDebug,
                        "ood: %s%s true, external decision",
@@ -223,13 +251,13 @@ func isOODWithTrace(
        }
 RecordOODTgt:
        if err = unix.Flock(int(FdOODTgtsLock.Fd()), unix.LOCK_EX); err != nil {
-               panic(err)
+               log.Fatalln(err)
        }
        if _, err = FdOODTgts.Seek(0, io.SeekEnd); err != nil {
-               panic(err)
+               log.Fatalln(err)
        }
        if _, err := FdOODTgts.WriteString(p + "\x00"); err != nil {
-               panic(err)
+               log.Fatalln(err)
        }
        unix.Flock(int(FdOODTgtsLock.Fd()), unix.LOCK_UN)
        return true, nil
@@ -237,10 +265,10 @@ RecordOODTgt:
 
 func oodTgtsClear() {
        if err := unix.Flock(int(FdOODTgtsLock.Fd()), unix.LOCK_EX); err != nil {
-               panic(err)
+               log.Fatalln(err)
        }
        if err := FdOODTgts.Truncate(0); err != nil {
-               panic(err)
+               log.Fatalln(err)
        }
        unix.Flock(int(FdOODTgtsLock.Fd()), unix.LOCK_UN)
 }