]> Cypherpunks.ru repositories - goredo.git/blobdiff - ifchange.go
Download link for 2.6.2 release
[goredo.git] / ifchange.go
index c9053712ce4867464c56f5c086caff6436307420..5c294013f7bf270e7dc89a5c50db0586e3213492 100644 (file)
@@ -1,19 +1,17 @@
-/*
-goredo -- djb's redo implementation on pure Go
-Copyright (C) 2020-2023 Sergey Matveev <stargrave@stargrave.org>
-
-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.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program.  If not, see <http://www.gnu.org/licenses/>.
-*/
+// goredo -- djb's redo implementation on pure Go
+// Copyright (C) 2020-2024 Sergey Matveev <stargrave@stargrave.org>
+//
+// 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.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 package main
 
@@ -26,25 +24,21 @@ func collectDeps(
        level int,
        deps map[string]map[string]*Tgt,
        includeSrc bool,
-       seen map[string]struct{},
 ) []*Tgt {
-       if _, ok := seen[tgt.a]; ok {
+       if _, ok := DepCache[tgt.rel]; ok {
                return nil
        }
-       depInfo, err := depRead(tgt)
+       dep, err := depRead(tgt)
        if err != nil {
                return nil
        }
-       DepInfoCache[tgt.Dep()] = depInfo
-       seen[tgt.a] = struct{}{}
+       DepCache[tgt.rel] = dep
        var alwayses []*Tgt
        returnReady := false
-       if depInfo.always {
-               if depInfo.build == BuildUUID {
-                       tracef(
-                               CDebug, "ood: %s%s always, but already build",
-                               strings.Repeat(". ", level), tgt,
-                       )
+       if dep.always {
+               if dep.build == BuildUUID {
+                       tracef(CDebug, "ood: %s%s always, but already build",
+                               strings.Repeat(". ", level), tgt)
                        returnReady = true
                } else {
                        tracef(CDebug, "ood: %s%s always", strings.Repeat(". ", level), tgt)
@@ -52,21 +46,21 @@ func collectDeps(
                        returnReady = true
                }
        }
-       for _, dep := range depInfo.ifchanges {
-               if dep.tgt.a == tgt.a {
+       for _, ifchange := range dep.ifchanges {
+               if ifchange.tgt.rel == tgt.rel {
                        continue
                }
-               if !includeSrc && isSrc(dep.tgt) {
+               if !includeSrc && isSrc(ifchange.tgt) {
                        continue
                }
                if !returnReady {
-                       if m, ok := deps[dep.tgt.a]; ok {
-                               m[tgt.a] = tgt
+                       if m, ok := deps[ifchange.tgt.rel]; ok {
+                               m[tgt.rel] = tgt
                        } else {
-                               deps[dep.tgt.a] = map[string]*Tgt{tgt.a: tgt}
+                               deps[ifchange.tgt.rel] = map[string]*Tgt{tgt.rel: tgt}
                        }
                        alwayses = append(alwayses,
-                               collectDeps(dep.tgt, level+1, deps, includeSrc, seen)...)
+                               collectDeps(ifchange.tgt, level+1, deps, includeSrc)...)
                }
        }
        return alwayses
@@ -77,20 +71,15 @@ func buildDependants(tgts []*Tgt) map[string]*Tgt {
        tracef(CDebug, "collecting deps")
        seen := make(map[string]*Tgt)
        deps := make(map[string]map[string]*Tgt)
-       {
-               collectDepsSeen := make(map[string]struct{})
-               for _, tgtInitial := range tgts {
-                       for _, tgt := range collectDeps(tgtInitial, 0, deps, false, collectDepsSeen) {
-                               if tgt.a != tgtInitial.a {
-                                       seen[tgt.a] = tgt
-                               }
+       for _, tgtInitial := range tgts {
+               for _, tgt := range collectDeps(tgtInitial, 0, deps, false) {
+                       if tgt.rel != tgtInitial.rel {
+                               seen[tgt.rel] = tgt
                        }
                }
-               InodeCache = make(map[string][]*Inode)
        }
-       TgtCache = nil
-       HashCache = nil
-       InodeCache = nil
+       TgtCache = make(map[string]*Tgt)
+       IfchangeCache = nil
        if len(seen) == 0 {
                return seen
        }
@@ -133,8 +122,8 @@ RebuildDeps:
        tracef(CDebug, "checking %d dependant targets: %v", len(queueSrc), queueSrc)
        queue := make(map[string]*Tgt)
        for _, tgt := range queueSrc {
-               for _, dep := range deps[tgt.a] {
-                       queue[dep.a] = dep
+               for _, dep := range deps[tgt.rel] {
+                       queue[dep.rel] = dep
                }
        }
 
@@ -163,7 +152,7 @@ RebuildDeps:
                        return nil
                }
                queueSrc = append(queueSrc, tgt)
-               seen[tgt.a] = tgt
+               seen[tgt.rel] = tgt
                jobs++
        }
        Jobs.Wait()
@@ -216,7 +205,7 @@ func ifchange(tgts []*Tgt, forced, traced bool) (bool, error) {
                close(okChecker)
        }()
        for _, tgt := range tgts {
-               if _, ok := seen[tgt.a]; ok {
+               if _, ok := seen[tgt.rel]; ok {
                        tracef(CDebug, "%s was already build as a dependant", tgt)
                        continue
                }