summaryrefslogtreecommitdiff
path: root/internal/engine/plan.go
diff options
context:
space:
mode:
authorLukasz Kasprzak <lukas@labunix.xyz>2026-09-12 12:58:14 +0200
committerLukasz Kasprzak <lukas@labunix.xyz>2026-09-12 12:58:14 +0200
commit24a84671ace373ae331fa83a1ff484990f4dff0e (patch)
treea6b6e3949d7dd241f1d13e079dfb982d758c89a2 /internal/engine/plan.go
parent3b36a48b7ce5a53a9366f3b31f94311f178e2553 (diff)
downloadkrino-24a84671ace373ae331fa83a1ff484990f4dff0e.tar.gz
krino-24a84671ace373ae331fa83a1ff484990f4dff0e.zip
krino: planning — chains, placeholders, conflicts, JSON
Diffstat (limited to 'internal/engine/plan.go')
-rw-r--r--internal/engine/plan.go60
1 files changed, 60 insertions, 0 deletions
diff --git a/internal/engine/plan.go b/internal/engine/plan.go
new file mode 100644
index 0000000..979bec1
--- /dev/null
+++ b/internal/engine/plan.go
@@ -0,0 +1,60 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+package engine
+
+import (
+ "context"
+ "time"
+
+ "krino/internal/plan"
+)
+
+// DirPlan is one directory's plan: the match Result it was built from (for
+// the counts and warnings a front end renders), the chains plan.Build
+// produced from its matched files, and Elapsed (D12), which - unlike
+// Result.Elapsed, stopped inside Match before plan.Build ever runs - spans
+// both Match and Build, so a front end reporting how long planning took is
+// not undercounting it. It lives here, not in internal/plan, because
+// internal/plan must not import internal/engine (engine already imports
+// plan).
+type DirPlan struct {
+ Dir *Dir
+ Chains []plan.Chain
+ Result *Result
+ Elapsed time.Duration
+}
+
+// Plan matches d, then turns every matched file into a chain per spec
+// §7.1. Unmatched files never reach plan.Build: they have no rules, hence
+// no steps, and Result.Unmatched already says they were not matched.
+// Chains keep Match's Rel order, since Matched is already sorted that way
+// and Build's output lines up with its input position for position. claims
+// is the run-scoped claim set (A3): the caller creates one *plan.Claims per
+// run and passes the same instance to every directory's Plan call, so two
+// directories claiming one destination resolve the collision instead of
+// both silently landing on it.
+func (e *Engine) Plan(ctx context.Context, d *Dir, claims *plan.Claims) (*DirPlan, error) {
+ started := time.Now()
+ r, err := e.Match(ctx, d)
+ if err != nil {
+ return nil, err
+ }
+
+ inputs := make([]plan.Input, len(r.Matched))
+ for i, fm := range r.Matched {
+ rules := make([]plan.RuleMatch, len(fm.Rules))
+ for j, rm := range fm.Rules {
+ rules[j] = plan.RuleMatch{
+ Name: rm.Rule.Name,
+ Actions: rm.Rule.Conf.Actions,
+ Settings: rm.Rule.Settings,
+ Captures: rm.Captures,
+ Reasons: rm.Reasons,
+ }
+ }
+ inputs[i] = plan.Input{File: fm.File, Rules: rules}
+ }
+
+ chains := plan.Build(d.Root, inputs, e.Now(), plan.OS{}, claims)
+ return &DirPlan{Dir: d, Chains: chains, Result: r, Elapsed: time.Since(started)}, nil
+}