1 // goredo -- djb's redo implementation on pure Go
2 // Copyright (C) 2020-2024 Sergey Matveev <stargrave@stargrave.org>
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, version 3 of the License.
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
13 // You should have received a copy of the GNU General Public License
14 // along with this program. If not, see <http://www.gnu.org/licenses/>.
25 func targetsCollect(root string, tgts map[string]struct{}) error {
26 dir, err := os.Open(root)
32 entries, err := dir.ReadDir(1 << 10)
39 for _, entry := range entries {
43 pth := path.Join(root, entry.Name())
44 if entry.Name() == RedoDir {
45 redoDir, err := os.Open(pth)
49 redoEntries, err := redoDir.ReadDir(0)
54 for _, redoEntry := range redoEntries {
55 name := redoEntry.Name()
56 if strings.HasSuffix(name, DepSuffix) {
57 name = cwdMustRel(root, name)
58 tgts[name[:len(name)-len(DepSuffix)]] = struct{}{}
62 if err = targetsCollect(pth, tgts); err != nil {
71 func targetsWalker(tgts []string) ([]string, error) {
72 tgtsMap := make(map[string]struct{})
73 for _, tgt := range tgts {
74 if err := targetsCollect(mustAbs(tgt), tgtsMap); err != nil {
78 tgts = make([]string, 0, len(tgtsMap))
79 for tgt := range tgtsMap {
80 tgts = append(tgts, tgt)
85 func collectWholeDeps(
87 deps map[string]map[string]*Tgt,
90 for _, tgt := range tgts {
91 if _, exists := seen[tgt.rel]; exists {
95 collectWholeDeps(deps[tgt.rel], deps, seen)