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, tgtOrig string) (map[DotNodes]bool, error) {
38 cwd, tgt := cwdAndTgt(tgtOrig)
39 depPath := path.Join(cwd, RedoDir, tgt+DepSuffix)
40 fdDep, err := os.Open(depPath)
46 r := recfile.NewReader(fdDep)
50 if errors.Is(err, io.EOF) {
57 data[DotNodes{tgtOrig, cwdMustRel(cwd, m["Target"])}] = true
63 data[DotNodes{tgtOrig, cwdMustRel(cwd, dep)}] = false
67 data, err = dotWalker(data, cwdMustRel(cwd, dep))
76 func dotPrint(tgts []string) error {
77 data := map[DotNodes]bool{}
79 for _, tgt := range tgts {
80 data, err = dotWalker(data, tgt)
85 fmt.Println(`digraph d {
88 splines=false // splines=ortho
89 node[shape=rectangle]`)
90 for nodes, nonexistent := range data {
91 fmt.Printf("\n\t\"%s\" -> \"%s\"", nodes.from, nodes.to)
93 fmt.Print(" [style=dotted]")