]> Cypherpunks.ru repositories - goredo.git/blobdiff - sources.go
Refactor target paths, less CPU, less memory, more clarity
[goredo.git] / sources.go
index 95b8e4e5bcfb54d7611f4c5e0a29ea1b0dae40a1..acf842b4547904e6ed5812c462e707541acaaf6a 100644 (file)
@@ -20,24 +20,20 @@ package main
 import (
        "errors"
        "io/fs"
-       "path"
 )
 
 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.Dep()]; ok {
                        continue
                }
-               seenDeps[depPath] = struct{}{}
-               depInfo, err := depRead(depPath)
+               seenDeps[tgt.Dep()] = struct{}{}
+               depInfo, err := depRead(tgt)
                if err != nil {
                        if errors.Is(err, fs.ErrNotExist) {
                                continue
@@ -45,16 +41,15 @@ func sourcesWalker(
                        return ErrLine(err)
                }
                for _, dep := range depInfo.ifchanges {
-                       depTgtAbsPath := mustAbs(path.Join(cwd, dep.tgt))
-                       if _, ok := seen[depTgtAbsPath]; ok {
+                       if _, ok := seen[dep.tgt.a]; ok {
                                continue
                        }
-                       seen[depTgtAbsPath] = struct{}{}
-                       if isSrc(cwd, dep.tgt) {
-                               srcs[cwdMustRel(depTgtAbsPath)] = struct{}{}
-                       } else if depTgtAbsPath != tgtAbsPath {
+                       seen[dep.tgt.a] = struct{}{}
+                       if isSrc(dep.tgt) {
+                               srcs[dep.tgt.a] = dep.tgt
+                       } else if dep.tgt.a != tgt.a {
                                if err := sourcesWalker(
-                                       []string{cwdMustRel(depTgtAbsPath)},
+                                       []*Tgt{dep.tgt},
                                        seen, seenDeps, srcs,
                                ); err != nil {
                                        return err