2 goredo -- djb's redo implementation on pure Go
3 Copyright (C) 2020-2022 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/>.
28 func targetsCollect(root string, tgts map[string]struct{}) error {
29 root, err := filepath.Abs(root)
33 dir, err := os.Open(root)
39 fis, err := dir.Readdir(1 << 10)
46 for _, fi := range fis {
50 pth := path.Join(root, fi.Name())
51 if fi.Name() == RedoDir {
52 redoDir, err := os.Open(pth)
56 redoFis, err := redoDir.Readdir(0)
60 for _, redoFi := range redoFis {
62 if strings.HasSuffix(name, DepSuffix) {
63 name = cwdMustRel(root, name)
64 tgts[name[:len(name)-len(DepSuffix)]] = struct{}{}
69 if err = targetsCollect(pth, tgts); err != nil {
78 func targetsWalker(tgts []string) ([]string, error) {
79 tgtsMap := map[string]struct{}{}
80 for _, tgt := range tgts {
81 if err := targetsCollect(tgt, tgtsMap); err != nil {
85 tgts = make([]string, 0, len(tgtsMap))
86 for tgt := range tgtsMap {
87 tgts = append(tgts, tgt)
92 func collectWholeDeps(
93 tgts map[string]struct{},
94 deps map[string]map[string]struct{},
95 seen map[string]struct{},
97 for tgt := range tgts {
98 seen[tgt] = struct{}{}
99 collectWholeDeps(deps[tgt], deps, seen)