X-Git-Url: http://www.git.cypherpunks.ru/?a=blobdiff_plain;f=ifchange.go;h=5c294013f7bf270e7dc89a5c50db0586e3213492;hb=HEAD;hp=9f7f4b572d583c1a5fbdf216f7788e280a7e8431;hpb=3f8ee87bd625a38b57a0a38e3c34bb26fe6e1b8e;p=goredo.git diff --git a/ifchange.go b/ifchange.go index 9f7f4b5..5c29401 100644 --- a/ifchange.go +++ b/ifchange.go @@ -1,19 +1,17 @@ -/* -goredo -- djb's redo implementation on pure Go -Copyright (C) 2020-2023 Sergey Matveev - -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 . -*/ +// goredo -- djb's redo implementation on pure Go +// Copyright (C) 2020-2024 Sergey Matveev +// +// 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 . package main @@ -26,24 +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 } - 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) @@ -51,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 @@ -76,16 +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 } } } + TgtCache = make(map[string]*Tgt) + IfchangeCache = nil if len(seen) == 0 { return seen } @@ -128,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 } } @@ -158,7 +152,7 @@ RebuildDeps: return nil } queueSrc = append(queueSrc, tgt) - seen[tgt.a] = tgt + seen[tgt.rel] = tgt jobs++ } Jobs.Wait() @@ -211,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 }