]> Cypherpunks.ru repositories - goredo.git/blobdiff - ifchange.go
Less unnecessary Close()s
[goredo.git] / ifchange.go
index b3df3a8a34881bdffc45ff58f3e545358b6789cc..bfe65f1d6468c6e163825d29b7a866f4a68104d4 100644 (file)
@@ -18,7 +18,6 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 package main
 
 import (
-       "os"
        "path"
        "strings"
 )
@@ -28,18 +27,20 @@ func collectDeps(
        level int,
        deps map[string]map[string]struct{},
        includeSrc bool,
+       seen map[string]struct{},
 ) []string {
        cwd, tgt := cwdAndTgt(path.Join(cwd, tgtOrig))
-       depPath := path.Join(cwd, RedoDir, tgt+DepSuffix)
-       fdDep, err := os.Open(depPath)
-       if err != nil {
+       tgtFull := path.Join(cwd, tgt)
+       if _, ok := seen[tgtFull]; ok {
                return nil
        }
-       depInfo, err := depRead(fdDep)
-       fdDep.Close()
+       depPath := path.Join(cwd, RedoDir, tgt+DepSuffix)
+       depInfo, err := depRead(depPath)
        if err != nil {
                return nil
        }
+       // DepInfoCache[depPath] = depInfo
+       seen[tgtFull] = struct{}{}
        var alwayses []string
        returnReady := false
        tgtRel := cwdMustRel(cwd, tgt)
@@ -56,19 +57,15 @@ func collectDeps(
                        returnReady = true
                }
        }
-       for _, m := range depInfo.ifchanges {
-               dep := m["Target"]
-               if dep == "" {
-                       return alwayses
-               }
-               if dep == tgt {
+       for _, dep := range depInfo.ifchanges {
+               if dep.tgt == tgt {
                        continue
                }
-               if !includeSrc && isSrc(cwd, dep) {
+               if !includeSrc && isSrc(cwd, dep.tgt) {
                        continue
                }
                if !returnReady {
-                       depRel := cwdMustRel(cwd, dep)
+                       depRel := cwdMustRel(cwd, dep.tgt)
                        if m, ok := deps[depRel]; ok {
                                m[tgtRel] = struct{}{}
                        } else {
@@ -76,10 +73,8 @@ func collectDeps(
                                m[tgtRel] = struct{}{}
                                deps[depRel] = m
                        }
-                       alwayses = append(
-                               alwayses,
-                               collectDeps(cwd, dep, level+1, deps, includeSrc)...,
-                       )
+                       alwayses = append(alwayses,
+                               collectDeps(cwd, dep.tgt, level+1, deps, includeSrc, seen)...)
                }
        }
        return alwayses
@@ -90,8 +85,9 @@ func buildDependants(tgts []string) map[string]struct{} {
        tracef(CDebug, "collecting deps")
        seen := map[string]struct{}{}
        deps := map[string]map[string]struct{}{}
+       collectDepsSeen := make(map[string]struct{})
        for _, tgtInitial := range tgts {
-               for _, tgt := range collectDeps(Cwd, tgtInitial, 0, deps, false) {
+               for _, tgt := range collectDeps(Cwd, tgtInitial, 0, deps, false, collectDepsSeen) {
                        if tgt != tgtInitial {
                                seen[tgt] = struct{}{}
                        }
@@ -100,6 +96,7 @@ func buildDependants(tgts []string) map[string]struct{} {
        if len(seen) == 0 {
                return seen
        }
+       collectDepsSeen = nil
 
        levelOrig := Level
        defer func() {
@@ -236,7 +233,7 @@ func ifchange(tgts []string, forced, traced bool) (bool, error) {
                        if err != nil {
                                Jobs.Wait()
                                close(errs)
-                               return false, err
+                               return false, ErrLine(err)
                        }
                }
                if !ood {
@@ -249,7 +246,7 @@ func ifchange(tgts []string, forced, traced bool) (bool, error) {
                if err = runScript(tgt, errs, forced, traced); err != nil {
                        Jobs.Wait()
                        close(errs)
-                       return false, err
+                       return false, ErrLine(err)
                }
        }
        Jobs.Wait()