X-Git-Url: http://www.git.cypherpunks.ru/?a=blobdiff_plain;f=sources.go;h=6a925e24dc6c2b4318da1bf73e7f7afa25a87dd6;hb=HEAD;hp=e321c43b96ef5591596658162a373adc950b8885;hpb=609842c96d2bb25c509f3d2949fe26f60ec03a5f;p=goredo.git diff --git a/sources.go b/sources.go index e321c43..6a925e2 100644 --- a/sources.go +++ b/sources.go @@ -1,57 +1,59 @@ -/* -goredo -- djb's redo implementation on pure Go -Copyright (C) 2020-2021 Sergey Matveev - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, version 3 of the License. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . -*/ +// goredo -- djb's redo implementation on pure Go +// Copyright (C) 2020-2024 Sergey Matveev +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, version 3 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . package main import ( - "os" - "path" - "path/filepath" - "strings" + "errors" + "io/fs" ) -func sourcesWalker() ([]string, error) { - tgts, err := targetsWalker(Cwd) - if err != nil { - return nil, err - } - srcs := make(map[string]struct{}, 1<<10) +func sourcesWalker( + tgts []*Tgt, + seen map[string]struct{}, + seenDeps map[string]struct{}, + srcs map[string]*Tgt, +) error { for _, tgt := range tgts { - cwd, f := path.Split(tgt) - fdDep, err := os.Open(path.Join(cwd, RedoDir, f+DepSuffix)) + if _, ok := seenDeps[tgt.rel]; ok { + continue + } + seenDeps[tgt.rel] = struct{}{} + dep, err := depRead(tgt) if err != nil { - return nil, err + if errors.Is(err, fs.ErrNotExist) { + continue + } + return ErrLine(err) } - depInfo, err := depRead(fdDep) - fdDep.Close() - for _, m := range depInfo.ifchanges { - tgt = m["Target"] - if !strings.HasSuffix(tgt, ".do") && isSrc(cwd, tgt) { - pth, err := filepath.Abs(path.Join(cwd, tgt)) - if err != nil { - panic(err) + for _, ifchange := range dep.ifchanges { + if _, ok := seen[ifchange.tgt.rel]; ok { + continue + } + seen[ifchange.tgt.rel] = struct{}{} + if isSrc(ifchange.tgt) { + srcs[ifchange.tgt.rel] = ifchange.tgt + } else if ifchange.tgt.rel != tgt.rel { + if err := sourcesWalker( + []*Tgt{ifchange.tgt}, + seen, seenDeps, srcs, + ); err != nil { + return err } - srcs[cwdMustRel(pth)] = struct{}{} } } } - tgts = make([]string, 0, len(srcs)) - for tgt := range srcs { - tgts = append(tgts, tgt) - } - return tgts, nil + return nil }