X-Git-Url: http://www.git.cypherpunks.ru/?a=blobdiff_plain;f=sources.go;h=6a925e24dc6c2b4318da1bf73e7f7afa25a87dd6;hb=a9455044065855ae42d95d939ed0027f7a895b83;hp=3f375a6fe58f666c01a5b190a5c82ee149bf20d5;hpb=e935c1db3ae2ff6d920ff37802774ba2e85629f0;p=goredo.git diff --git a/sources.go b/sources.go index 3f375a6..6a925e2 100644 --- a/sources.go +++ b/sources.go @@ -1,65 +1,53 @@ -/* -goredo -- djb's redo implementation on pure Go -Copyright (C) 2020-2023 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" + "errors" + "io/fs" ) func sourcesWalker( - tgts []string, + tgts []*Tgt, seen map[string]struct{}, seenDeps map[string]struct{}, - srcs map[string]struct{}, + srcs map[string]*Tgt, ) error { for _, tgt := range tgts { - tgtAbsPath := mustAbs(path.Join(Cwd, tgt)) - cwd, f := path.Split(path.Join(Cwd, tgt)) - depPath := path.Join(cwd, RedoDir, f+DepSuffix) - if _, ok := seenDeps[depPath]; ok { + if _, ok := seenDeps[tgt.rel]; ok { continue } - seenDeps[depPath] = struct{}{} - fdDep, err := os.Open(depPath) + seenDeps[tgt.rel] = struct{}{} + dep, err := depRead(tgt) if err != nil { if errors.Is(err, fs.ErrNotExist) { continue } return ErrLine(err) } - depInfo, err := depRead(fdDep) - fdDep.Close() - if err != nil { - return ErrLine(err) - } - for _, m := range depInfo.ifchanges { - depTgt := m["Target"] - depTgtAbsPath := mustAbs(path.Join(cwd, depTgt)) - if _, ok := seen[depTgtAbsPath]; ok { + for _, ifchange := range dep.ifchanges { + if _, ok := seen[ifchange.tgt.rel]; ok { continue } - seen[depTgtAbsPath] = struct{}{} - if isSrc(cwd, depTgt) { - srcs[cwdMustRel(depTgtAbsPath)] = struct{}{} - } else if depTgtAbsPath != tgtAbsPath { + 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( - []string{cwdMustRel(depTgtAbsPath)}, + []*Tgt{ifchange.tgt}, seen, seenDeps, srcs, ); err != nil { return err