]> Cypherpunks.ru repositories - goredo.git/blobdiff - ifchange.go
default.do-s must not depend on themselves
[goredo.git] / ifchange.go
index 1f2c38194934da44475e97e039fb73601536a5a0..128d1afbef6eaea5fdd1681af86cb1339ec8f738 100644 (file)
@@ -27,6 +27,7 @@ func collectDeps(
        cwd, tgtOrig string,
        level int,
        deps map[string]map[string]struct{},
+       includeSrc bool,
 ) []string {
        cwd, tgt := cwdAndTgt(path.Join(cwd, tgtOrig))
        depPath := path.Join(cwd, RedoDir, tgt+DepSuffix)
@@ -60,7 +61,10 @@ func collectDeps(
                if dep == "" {
                        return alwayses
                }
-               if dep == tgt || isSrc(cwd, dep) {
+               if dep == tgt {
+                       continue
+               }
+               if !includeSrc && isSrc(cwd, dep) {
                        continue
                }
                if !returnReady {
@@ -68,11 +72,14 @@ func collectDeps(
                        if m, ok := deps[depRel]; ok {
                                m[tgtRel] = struct{}{}
                        } else {
-                               m = make(map[string]struct{}, 0)
+                               m = map[string]struct{}{}
                                m[tgtRel] = struct{}{}
                                deps[depRel] = m
                        }
-                       alwayses = append(alwayses, collectDeps(cwd, dep, level+1, deps)...)
+                       alwayses = append(
+                               alwayses,
+                               collectDeps(cwd, dep, level+1, deps, includeSrc)...,
+                       )
                }
        }
        return alwayses
@@ -84,7 +91,7 @@ func buildDependants(tgts []string) map[string]struct{} {
        seen := map[string]struct{}{}
        deps := map[string]map[string]struct{}{}
        for _, tgtInitial := range tgts {
-               for _, tgt := range collectDeps(Cwd, tgtInitial, 0, deps) {
+               for _, tgt := range collectDeps(Cwd, tgtInitial, 0, deps, false) {
                        if tgt != tgtInitial {
                                seen[tgt] = struct{}{}
                        }
@@ -109,7 +116,7 @@ func buildDependants(tgts []string) map[string]struct{} {
        }
        ok := true
        for i := 0; i < len(seen); i++ {
-               ok = ok && isOkRun(<-errs)
+               ok = isOkRun(<-errs) && ok
        }
        Jobs.Wait()
        close(errs)
@@ -156,7 +163,7 @@ RebuildDeps:
                jobs++
        }
        for i := 0; i < jobs; i++ {
-               ok = ok && isOkRun(<-errs)
+               ok = isOkRun(<-errs) && ok
        }
        if !ok {
                trace(CDebug, "dependants failed, skipping them")
@@ -173,7 +180,9 @@ RebuildDeps:
 
 func ifchange(tgts []string, forced, traced bool) (bool, error) {
        jsInit()
-       defer jsAcquire("ifchange exiting")
+       if !IsTopRedo {
+               defer jsAcquire("ifchange exiting")
+       }
        defer Jobs.Wait()
        seen := buildDependants(tgts)
        oodTgtsClear()
@@ -208,7 +217,7 @@ func ifchange(tgts []string, forced, traced bool) (bool, error) {
        }
        ok := true
        for ; jobs > 0; jobs-- {
-               ok = ok && isOkRun(<-errs)
+               ok = isOkRun(<-errs) && ok
        }
        return ok, nil
 }