From af40222f5a3e6fa82207f7ba31c338eb44566ba3 Mon Sep 17 00:00:00 2001 From: Sergey Matveev Date: Fri, 6 Oct 2023 10:35:59 +0300 Subject: [PATCH] Use more shorter Cwd-relative paths --- buildlog.go | 12 ++++++------ dot.go | 4 ++-- ifchange.go | 8 ++++---- main.go | 12 ++++++------ ood.go | 32 +++++++++++++++++--------------- run.go | 6 +++--- sources.go | 12 ++++++------ targets.go | 6 +++--- tgt.go | 5 ----- 9 files changed, 47 insertions(+), 50 deletions(-) diff --git a/buildlog.go b/buildlog.go index 956cf4f..6c57937 100644 --- a/buildlog.go +++ b/buildlog.go @@ -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 9199f7d..0ea2b4a 100644 --- 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 } diff --git a/ifchange.go b/ifchange.go index c905371..dbe03cf 100644 --- a/ifchange.go +++ b/ifchange.go @@ -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 b36c1b7..0d19119 100644 --- 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 9a70be4..59bf76c 100644 --- 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 ecf96e2..7fa4dea 100644 --- 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 { diff --git a/sources.go b/sources.go index acf842b..246c124 100644 --- a/sources.go +++ b/sources.go @@ -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, diff --git a/targets.go b/targets.go index 662612e..8e26684 100644 --- a/targets.go +++ b/targets.go @@ -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 e7f3359..8e454f2 100644 --- 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 -- 2.44.0