]> Cypherpunks.ru repositories - goredo.git/commitdiff
Use more shorter Cwd-relative paths
authorSergey Matveev <stargrave@stargrave.org>
Fri, 6 Oct 2023 07:35:59 +0000 (10:35 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Fri, 6 Oct 2023 18:59:41 +0000 (21:59 +0300)
buildlog.go
dot.go
ifchange.go
main.go
ood.go
run.go
sources.go
targets.go
tgt.go

index 956cf4fdc9aa353b5abfca806e19cc8ae19c56ac..6c5793774beb489a36a14a33ca3c1c8582fb9797 100644 (file)
@@ -93,15 +93,15 @@ func depthPrefix(depth int) string {
 }
 
 func showBuildLogSub(sub *BuildLogJob, depth int) error {
-       if _, ok := buildLogSeen[sub.tgt.a]; ok {
+       if _, ok := buildLogSeen[sub.tgt.rel]; ok {
                return nil
        }
-       buildLogSeen[sub.tgt.a] = struct{}{}
+       buildLogSeen[sub.tgt.rel] = struct{}{}
        dp := depthPrefix(depth)
        fmt.Printf(
                "%s%s%s\n",
                sub.rec["Started"][0], dp,
-               colourize(CRedo, "redo "+sub.tgt.String()),
+               colourize(CRedo, "redo "+sub.tgt.rel),
        )
        if err := showBuildLog(sub.tgt, sub.rec, depth+1); err != nil {
                return err
@@ -114,14 +114,14 @@ func showBuildLogSub(sub *BuildLogJob, depth int) error {
                fmt.Printf(
                        "%s%s%s (code: %d) (%d.%ds)\n\n",
                        sub.rec["Finished"][0], dp,
-                       colourize(CErr, "err "+sub.tgt.String()),
+                       colourize(CErr, "err "+sub.tgt.rel),
                        sub.exitCode, durationSec, durationNsec,
                )
        } else {
                fmt.Printf(
                        "%s%s%s (%d.%ds)\n\n",
                        sub.rec["Finished"][0], dp,
-                       colourize(CRedo, "done "+sub.tgt.String()),
+                       colourize(CRedo, "done "+sub.tgt.rel),
                        durationSec, durationNsec,
                )
        }
@@ -197,7 +197,7 @@ func showBuildLog(tgt *Tgt, buildLogRec map[string][]string, depth int) error {
        subs := make([]*BuildLogJob, 0, len(buildLogRec["Ifchange"]))
        for _, depPath := range buildLogRec["Ifchange"] {
                dep := NewTgt(path.Join(tgt.h, depPath))
-               if dep.a == tgt.a {
+               if dep.rel == tgt.rel {
                        continue
                }
                rec, err := parseBuildLogRec(dep)
diff --git a/dot.go b/dot.go
index 9199f7dd0e43099c010e972911831fdf8fd715bf..0ea2b4ae13fcffb9bd1fc858a329eadb216b8070 100644 (file)
--- a/dot.go
+++ b/dot.go
@@ -52,13 +52,13 @@ func dotWalker(data map[DotNodes]bool, tgt *Tgt) (map[DotNodes]bool, error) {
                }
                switch m["Type"] {
                case DepTypeIfcreate:
-                       data[DotNodes{tgt.String(), NewTgt(m["Target"]).String()}] = true
+                       data[DotNodes{tgt.rel, NewTgt(string(chunk)).rel}] = true
                case DepTypeIfchange:
                        dep = NewTgt(path.Join(tgt.h, m["Target"]))
                        if dep.a == tgt.a {
                                continue
                        }
-                       data[DotNodes{tgt.String(), dep.String()}] = false
+                       data[DotNodes{tgt.rel, dep.rel}] = false
                        if isSrc(dep) {
                                continue
                        }
index c9053712ce4867464c56f5c086caff6436307420..dbe03cfce8311872fd68ed1f1949253762872693 100644 (file)
@@ -133,8 +133,8 @@ RebuildDeps:
        tracef(CDebug, "checking %d dependant targets: %v", len(queueSrc), queueSrc)
        queue := make(map[string]*Tgt)
        for _, tgt := range queueSrc {
-               for _, dep := range deps[tgt.a] {
-                       queue[dep.a] = dep
+               for _, dep := range deps[tgt.rel] {
+                       queue[dep.rel] = dep
                }
        }
 
@@ -163,7 +163,7 @@ RebuildDeps:
                        return nil
                }
                queueSrc = append(queueSrc, tgt)
-               seen[tgt.a] = tgt
+               seen[tgt.rel] = tgt
                jobs++
        }
        Jobs.Wait()
@@ -216,7 +216,7 @@ func ifchange(tgts []*Tgt, forced, traced bool) (bool, error) {
                close(okChecker)
        }()
        for _, tgt := range tgts {
-               if _, ok := seen[tgt.a]; ok {
+               if _, ok := seen[tgt.rel]; ok {
                        tracef(CDebug, "%s was already build as a dependant", tgt)
                        continue
                }
diff --git a/main.go b/main.go
index b36c1b74a9b29911aac0bea85a0ba835705db5f5..0d19119268fb00bbc4f106b3b3bd03a4c6573b7a 100644 (file)
--- a/main.go
+++ b/main.go
@@ -425,7 +425,7 @@ CmdSwitch:
        case CmdNameRedoTargets:
                raws := make([]string, 0, len(tgts))
                for _, tgt := range tgts {
-                       raws = append(raws, tgt.String())
+                       raws = append(raws, tgt.rel)
                }
                if tgtsWasEmpty {
                        raws = []string{Cwd}
@@ -457,11 +457,11 @@ CmdSwitch:
                        }
                        seen := make(map[string]*Tgt)
                        for _, tgt := range tgts {
-                               collectWholeDeps(deps[tgt.a], deps, seen)
+                               collectWholeDeps(deps[tgt.rel], deps, seen)
                        }
                        res = make([]string, 0, len(seen))
                        for _, dep := range seen {
-                               res = append(res, dep.String())
+                               res = append(res, dep.rel)
                        }
                }
                sort.Strings(res)
@@ -471,7 +471,7 @@ CmdSwitch:
        case CmdNameRedoOOD:
                raws := make([]string, 0, len(tgts))
                for _, tgt := range tgts {
-                       raws = append(raws, tgt.String())
+                       raws = append(raws, tgt.rel)
                }
                if tgtsWasEmpty {
                        raws, err = targetsWalker([]string{Cwd})
@@ -496,7 +496,7 @@ CmdSwitch:
                {
                        raws := make([]string, 0, len(tgts))
                        for _, tgt := range tgts {
-                               raws = append(raws, tgt.String())
+                               raws = append(raws, tgt.rel)
                        }
                        if tgtsWasEmpty {
                                raws, err = targetsWalker([]string{Cwd})
@@ -519,7 +519,7 @@ CmdSwitch:
                }
                res := make([]string, 0, len(srcs))
                for _, tgt := range srcs {
-                       res = append(res, tgt.String())
+                       res = append(res, tgt.rel)
                }
                srcs = nil
                sort.Strings(res)
diff --git a/ood.go b/ood.go
index 9a70be41a54bbc95776a632f90453804154a27cb..59bf76c18661202467c830526c8c6ee2abfe80b2 100644 (file)
--- a/ood.go
+++ b/ood.go
@@ -100,12 +100,12 @@ func isOODByBuildUUID(tgt *Tgt) bool {
 func isOOD(tgt *Tgt, level int, seen map[string]*Tgt) (bool, error) {
        indent := strings.Repeat(". ", level)
        tracef(CDebug, "ood: %s%s checking", indent, tgt)
-       ood, cached := OODCache[tgt.a]
+       ood, cached := OODCache[tgt.rel]
        if cached {
                tracef(CDebug, "ood: %s%s -> cached: %v", indent, tgt, ood)
                return ood, nil
        }
-       depInfo := DepInfoCache[tgt.Dep()]
+       depInfo := DepInfoCache[tgt.rel]
        var err error
        if depInfo == nil {
                depInfo, err = depRead(tgt)
@@ -118,24 +118,26 @@ func isOOD(tgt *Tgt, level int, seen map[string]*Tgt) (bool, error) {
                                        ood = true
                                        tracef(CDebug, "ood: %s%s -> no dep: %s", indent, tgt, tgt.Dep())
                                }
-                               OODCache[tgt.a] = ood
+                               OODCache[tgt.rel] = ood
                                return ood, nil
                        }
                        if err != nil {
                                return true, TgtError{tgt, ErrLine(err)}
                        }
                }
-               DepInfoCache[tgt.Dep()] = depInfo
+               if DepInfoCache != nil {
+                       DepInfoCache[tgt.rel] = depInfo
+               }
        }
 
        if depInfo.build == BuildUUID {
                tracef(CDebug, "ood: %s%s -> already built", indent, tgt)
-               OODCache[tgt.a] = false
+               OODCache[tgt.rel] = false
                return false, nil
        }
        if !FileExists(tgt.a) {
                tracef(CDebug, "ood: %s%s -> non-existent", indent, tgt)
-               OODCache[tgt.a] = true
+               OODCache[tgt.rel] = true
                return true, nil
        }
 
@@ -149,7 +151,7 @@ func isOOD(tgt *Tgt, level int, seen map[string]*Tgt) (bool, error) {
 
        for _, dep := range depInfo.ifchanges {
                tracef(CDebug, "ood: %s%s -> %s: checking", indent, tgt, dep.tgt)
-               ood, cached = OODCache[dep.tgt.a]
+               ood, cached = OODCache[dep.tgt.rel]
                if cached {
                        tracef(CDebug, "ood: %s%s -> %s: cached: %v", indent, tgt, dep.tgt, ood)
                        if ood {
@@ -163,7 +165,7 @@ func isOOD(tgt *Tgt, level int, seen map[string]*Tgt) (bool, error) {
                        if errors.Is(err, fs.ErrNotExist) {
                                tracef(CDebug, "ood: %s%s -> %s: not exists", indent, tgt, dep.tgt)
                                ood = true
-                               OODCache[dep.tgt.a] = ood
+                               OODCache[dep.tgt.rel] = ood
                                goto Done
                        }
                        return ood, TgtError{tgt, ErrLine(err)}
@@ -172,7 +174,7 @@ func isOOD(tgt *Tgt, level int, seen map[string]*Tgt) (bool, error) {
                if inode.Size != dep.inode.Size {
                        tracef(CDebug, "ood: %s%s -> %s: size differs", indent, tgt, dep.tgt)
                        ood = true
-                       OODCache[dep.tgt.a] = ood
+                       OODCache[dep.tgt.rel] = ood
                        goto Done
                }
                if InodeTrust != InodeTrustNone && inode.Equals(dep.inode) {
@@ -191,25 +193,25 @@ func isOOD(tgt *Tgt, level int, seen map[string]*Tgt) (bool, error) {
                        if dep.hash != hsh {
                                tracef(CDebug, "ood: %s%s -> %s: hash differs", indent, tgt, dep.tgt)
                                ood = true
-                               OODCache[dep.tgt.a] = ood
+                               OODCache[dep.tgt.rel] = ood
                                goto Done
                        }
                        tracef(CDebug, "ood: %s%s -> %s: same hash", indent, tgt, dep.tgt)
                }
 
-               if dep.tgt.a == tgt.a {
+               if dep.tgt.rel == tgt.rel {
                        tracef(CDebug, "ood: %s%s -> %s: same target", indent, tgt, dep.tgt)
                        continue
                }
                if isSrc(dep.tgt) {
                        tracef(CDebug, "ood: %s%s -> %s: is source", indent, tgt, dep.tgt)
-                       OODCache[dep.tgt.a] = false
+                       OODCache[dep.tgt.rel] = false
                        continue
                }
 
-               if _, ok := seen[dep.tgt.a]; ok {
+               if _, ok := seen[dep.tgt.rel]; ok {
                        tracef(CDebug, "ood: %s%s -> %s: was always built", indent, tgt, dep.tgt)
-                       OODCache[dep.tgt.a] = false
+                       OODCache[dep.tgt.rel] = false
                        continue
                }
 
@@ -227,7 +229,7 @@ func isOOD(tgt *Tgt, level int, seen map[string]*Tgt) (bool, error) {
 
 Done:
        tracef(CDebug, "ood: %s%s: %v", indent, tgt, ood)
-       OODCache[tgt.a] = ood
+       OODCache[tgt.rel] = ood
        return ood, nil
 }
 
diff --git a/run.go b/run.go
index ecf96e22e5428e44eeee29ef6de329d33689c0dd..7fa4deae08c35b428111e5773d5744eca32417cd 100644 (file)
--- a/run.go
+++ b/run.go
@@ -111,7 +111,7 @@ type RunError struct {
 func (e *RunError) Name() string {
        var name string
        if e.DoFile == "" {
-               name = e.Tgt.String()
+               name = e.Tgt.rel
        } else {
                name = fmt.Sprintf("%s (%s)", e.Tgt, e.DoFile)
        }
@@ -350,7 +350,7 @@ func runScript(tgt *Tgt, errs chan error, forced, traced bool) error {
                doFile = NewTgt(path.Join(ups...))
                if strings.HasPrefix(doFile.t, "default.") {
                        basename = basename[:len(basename)-(len(doFile.t)-len("default.")-len(".do"))-1]
-                       runErr.DoFile = doFile.String()
+                       runErr.DoFile = doFile.rel
                }
        }
 
@@ -365,7 +365,7 @@ func runScript(tgt *Tgt, errs chan error, forced, traced bool) error {
        // Prepare command line
        var cmdName string
        var args []string
-       if err = unix.Access(doFile.String(), unix.X_OK); err == nil {
+       if err = unix.Access(doFile.rel, unix.X_OK); err == nil {
                cmdName = doFile.t
                args = make([]string, 0, 3)
        } else {
index acf842b4547904e6ed5812c462e707541acaaf6a..246c124ddfd1ecbc11a8a368a9115d342925045b 100644 (file)
@@ -29,10 +29,10 @@ func sourcesWalker(
        srcs map[string]*Tgt,
 ) error {
        for _, tgt := range tgts {
-               if _, ok := seenDeps[tgt.Dep()]; ok {
+               if _, ok := seenDeps[tgt.rel]; ok {
                        continue
                }
-               seenDeps[tgt.Dep()] = struct{}{}
+               seenDeps[tgt.rel] = struct{}{}
                depInfo, err := depRead(tgt)
                if err != nil {
                        if errors.Is(err, fs.ErrNotExist) {
@@ -41,13 +41,13 @@ func sourcesWalker(
                        return ErrLine(err)
                }
                for _, dep := range depInfo.ifchanges {
-                       if _, ok := seen[dep.tgt.a]; ok {
+                       if _, ok := seen[dep.tgt.rel]; ok {
                                continue
                        }
-                       seen[dep.tgt.a] = struct{}{}
+                       seen[dep.tgt.rel] = struct{}{}
                        if isSrc(dep.tgt) {
-                               srcs[dep.tgt.a] = dep.tgt
-                       } else if dep.tgt.a != tgt.a {
+                               srcs[dep.tgt.rel] = dep.tgt
+                       } else if dep.tgt.rel != tgt.rel {
                                if err := sourcesWalker(
                                        []*Tgt{dep.tgt},
                                        seen, seenDeps, srcs,
index 662612ea976b77f8418abc1d3c1fb4cb51ae541b..8e2668494dca9511b5b9745ba89cca235fbc9e47 100644 (file)
@@ -90,10 +90,10 @@ func collectWholeDeps(
        seen map[string]*Tgt,
 ) {
        for _, tgt := range tgts {
-               if _, exists := seen[tgt.a]; exists {
+               if _, exists := seen[tgt.rel]; exists {
                        continue
                }
-               seen[tgt.a] = tgt
-               collectWholeDeps(deps[tgt.a], deps, seen)
+               seen[tgt.rel] = tgt
+               collectWholeDeps(deps[tgt.rel], deps, seen)
        }
 }
diff --git a/tgt.go b/tgt.go
index e7f3359b09854c0010651995ddf875bb62321ac3..8e454f2c94a884dc85a826e47ba570eaf705c362 100644 (file)
--- a/tgt.go
+++ b/tgt.go
@@ -27,11 +27,6 @@ func cwdMustRel(paths ...string) string {
        return mustRel(Cwd, path.Join(paths...))
 }
 
-func cwdAndTgt(tgt string) (string, string) {
-       cwd, tgt := path.Split(tgt)
-       return mustAbs(cwd), tgt
-}
-
 type Tgt struct {
        // a/h/t resemble zsh'es :a, :h, :t modifiers
        a   string // absolute path