2 goredo -- djb's redo implementation on pure Go
3 Copyright (C) 2020-2023 Sergey Matveev <stargrave@stargrave.org>
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, version 3 of the License.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
18 // Dependency DOT graph generation
29 "go.cypherpunks.ru/recfile"
32 type DotNodes struct {
37 func dotWalker(data map[DotNodes]bool, tgt *Tgt) (map[DotNodes]bool, error) {
38 fdDep, err := os.Open(tgt.Dep())
40 return nil, ErrLine(err)
44 r := recfile.NewReader(fdDep)
48 if errors.Is(err, io.EOF) {
51 return nil, ErrLine(err)
55 data[DotNodes{tgt.rel, NewTgt(string(chunk)).rel}] = true
57 dep = NewTgt(path.Join(tgt.h, m["Target"]))
61 data[DotNodes{tgt.rel, dep.rel}] = false
65 data, err = dotWalker(data, dep)
74 func dotPrint(tgts []*Tgt) error {
75 data := map[DotNodes]bool{}
77 for _, tgt := range tgts {
78 data, err = dotWalker(data, tgt)
83 fmt.Println(`digraph d {
86 splines=false // splines=ortho
87 node[shape=rectangle]`)
88 for nodes, nonexistent := range data {
89 fmt.Printf("\n\t\"%s\" -> \"%s\"", nodes.from, nodes.to)
91 fmt.Print(" [style=dotted]")