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/>.
27 func targetsCollect(root string, tgts map[string]struct{}) error {
28 dir, err := os.Open(root)
34 entries, err := dir.ReadDir(1 << 10)
41 for _, entry := range entries {
45 pth := path.Join(root, entry.Name())
46 if entry.Name() == RedoDir {
47 redoDir, err := os.Open(pth)
51 redoEntries, err := redoDir.ReadDir(0)
56 for _, redoEntry := range redoEntries {
57 name := redoEntry.Name()
58 if strings.HasSuffix(name, DepSuffix) {
59 name = cwdMustRel(root, name)
60 tgts[name[:len(name)-len(DepSuffix)]] = struct{}{}
64 if err = targetsCollect(pth, tgts); err != nil {
73 func targetsWalker(tgts []string) ([]string, error) {
74 tgtsMap := make(map[string]struct{})
75 for _, tgt := range tgts {
76 if err := targetsCollect(mustAbs(tgt), tgtsMap); err != nil {
80 tgts = make([]string, 0, len(tgtsMap))
81 for tgt := range tgtsMap {
82 tgts = append(tgts, tgt)
87 func collectWholeDeps(
89 deps map[string]map[string]*Tgt,
92 for _, tgt := range tgts {
93 if _, exists := seen[tgt.rel]; exists {
97 collectWholeDeps(deps[tgt.rel], deps, seen)