X-Git-Url: http://www.git.cypherpunks.ru/?p=goredo.git;a=blobdiff_plain;f=sources.go;h=0d361900527ca0aa1710e2daa7c96e8478075871;hp=e321c43b96ef5591596658162a373adc950b8885;hb=cb183690cc59ad772dab941adc3e9b8d5b90fbc0;hpb=5dfe4d08937cc9cb2f39558359ea4df2f1e830b0 diff --git a/sources.go b/sources.go index e321c43..0d36190 100644 --- a/sources.go +++ b/sources.go @@ -21,17 +21,16 @@ import ( "os" "path" "path/filepath" - "strings" ) -func sourcesWalker() ([]string, error) { - tgts, err := targetsWalker(Cwd) - if err != nil { - return nil, err - } - srcs := make(map[string]struct{}, 1<<10) +func sourcesWalker(tgts []string) ([]string, error) { + seen := make(map[string]struct{}, 1<<10) for _, tgt := range tgts { - cwd, f := path.Split(tgt) + tgtAbsPath, err := filepath.Abs(path.Join(Cwd, tgt)) + if err != nil { + panic(err) + } + cwd, f := path.Split(path.Join(Cwd, tgt)) fdDep, err := os.Open(path.Join(cwd, RedoDir, f+DepSuffix)) if err != nil { return nil, err @@ -39,19 +38,27 @@ func sourcesWalker() ([]string, error) { 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)) + depTgt := m["Target"] + depTgtAbsPath, err := filepath.Abs(path.Join(cwd, depTgt)) + if err != nil { + panic(err) + } + if isSrc(cwd, depTgt) { + seen[cwdMustRel(depTgtAbsPath)] = struct{}{} + } else if depTgtAbsPath != tgtAbsPath { + subSrcs, err := sourcesWalker([]string{cwdMustRel(depTgtAbsPath)}) if err != nil { panic(err) } - srcs[cwdMustRel(pth)] = struct{}{} + for _, p := range subSrcs { + seen[p] = struct{}{} + } } } } - tgts = make([]string, 0, len(srcs)) - for tgt := range srcs { - tgts = append(tgts, tgt) + srcs := make([]string, 0, len(seen)) + for p := range seen { + srcs = append(srcs, p) } - return tgts, nil + return srcs, nil }