2 goredo -- djb's redo implementation on pure Go
3 Copyright (C) 2020-2024 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
28 type DotNodes struct {
33 func dotWalker(data map[DotNodes]bool, tgt *Tgt) (map[DotNodes]bool, error) {
34 raw, err := os.ReadFile(tgt.dep)
36 return nil, ErrLine(err)
38 _, raw, err = depHeadParse(raw)
40 return nil, ErrLine(err)
46 tgtH, _ := pathSplit(tgt.a)
48 typ, chunk, raw, err = chunkRead(raw)
50 return nil, ErrLine(err)
54 data[DotNodes{tgt.rel, NewTgt(path.Join(tgtH, string(chunk))).rel}] = true
55 case DepTypeIfchange, DepTypeIfchangeNonex:
56 if typ == DepTypeIfchangeNonex {
59 name = string(chunk[InodeLen+HashLen:])
61 dep = NewTgt(path.Join(tgtH, name))
65 data[DotNodes{tgt.rel, dep.rel}] = false
69 data, err = dotWalker(data, dep)
78 func dotPrint(tgts []*Tgt) error {
79 data := map[DotNodes]bool{}
81 for _, tgt := range tgts {
82 data, err = dotWalker(data, tgt)
87 fmt.Println(`digraph d {
90 splines=false // splines=ortho
91 node[shape=rectangle]`)
92 for nodes, nonexistent := range data {
93 fmt.Printf("\n\t\"%s\" -> \"%s\"", nodes.from, nodes.to)
95 fmt.Print(" [style=dotted]")