mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-03 06:31:42 +01:00
Engine split step 6: slot_access.py and its rewrite (slot fields to accessors, trait imports, doc links)
scripts/engine_split/slot_access.py rewrites the slot fields to their accessors (Tracked presets deref through one more *), adds the trait imports, turns s.presets_changed() into presets::presets_changed(s) and points Session::method doc links at the trait methods. Its fix mode applies what cargo check reports; branch mode serves open branches and lists their edits to the moved methods. The definition-span helpers session_state.py uses move to rust_source.py so both scripts share them (session_state.py's output is unchanged). This commit is split plus the fix rounds against cargo check of engine-core, engine, ui-egui and automation (lib and tests). Part of #15710.
This commit is contained in:
1 parent
f314928e1d
commit
3cbd7b155a
279 files changed
+2791
-1924
No files matched your search
@@ -22,10 +22,10 @@ slot read through `preset_store::PresetStoreExt` (`s.preset_store()`, `s.preset_
|
||||
Running either mode twice gives the same result. What it cannot do is printed at the end of
|
||||
every run.
|
||||
"""
|
||||
import argparse, os, re, subprocess, sys
|
||||
import argparse, os, re, sys
|
||||
|
||||
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
||||
from rust_source import git, git_show, mask # noqa: E402
|
||||
from rust_source import edited_definitions, git # noqa: E402
|
||||
|
||||
FIELDS = ["record_tools", "recording", "take", "playing", "playback_stack", "playback_steps", "budget_shared", "batch_depth", "script_depth", "script_steps"]
|
||||
RENAMED = {"recording": "target"}
|
||||
@@ -123,62 +123,11 @@ def split():
|
||||
print(f"session_state split: {n} files rewritten")
|
||||
|
||||
|
||||
HUNK = re.compile(r"^@@ -(\d+)(?:,(\d+))? ")
|
||||
|
||||
|
||||
def definition_lines(src, item):
|
||||
"""1-based (first, last) lines of `item` in `src`, its doc comments and attributes included."""
|
||||
masked = mask(src)
|
||||
kind, name = item.split()
|
||||
m = re.search(rf"^[ \t]*(?:pub(?:\([a-z:]+\))?\s+)?{kind}\s+{re.escape(name)}\b", masked, re.M)
|
||||
if not m:
|
||||
return None
|
||||
i, depth = m.end(), 0
|
||||
while i < len(masked):
|
||||
c = masked[i]
|
||||
if c == "{":
|
||||
depth += 1
|
||||
elif c == "}":
|
||||
depth -= 1
|
||||
if depth == 0:
|
||||
break
|
||||
elif c == ";" and depth == 0:
|
||||
break
|
||||
i += 1
|
||||
lines = src.splitlines()
|
||||
first = src.count("\n", 0, m.start()) + 1
|
||||
while first > 1 and lines[first - 2].lstrip().startswith(("///", "#[")):
|
||||
first -= 1
|
||||
return first, src.count("\n", 0, i) + 1
|
||||
|
||||
|
||||
def moved_edits(base, head):
|
||||
diff = subprocess.run(["git", "diff", "-U0", base, head, "--", "crates/engine/src", SRC], capture_output=True, text=True, check=True).stdout
|
||||
current = None
|
||||
hunks, ranges, paths = {}, {}, {}
|
||||
for line in diff.splitlines():
|
||||
if line.startswith("--- "):
|
||||
path = line[4:].removeprefix("a/")
|
||||
current = path.removeprefix("crates/engine/src/").removeprefix(SRC) if path != "/dev/null" else None
|
||||
if current:
|
||||
paths[current] = path
|
||||
elif line.startswith("+++ "):
|
||||
continue
|
||||
elif current and (h := HUNK.match(line)):
|
||||
start, count = int(h[1]), int(h[2] or 1)
|
||||
# A pure insertion (count 0) sits after `start`.
|
||||
ranges.setdefault(current, []).append((start, start + max(count, 1) - 1) if count else (start, start + 1))
|
||||
elif line.startswith(("+", "-")) and current:
|
||||
hunks.setdefault(current, []).append(line[1:])
|
||||
for old_file, item, new_file in MOVED:
|
||||
name = item.split()[1]
|
||||
named = any(re.search(rf"\b{re.escape(name)}\b", line) for line in hunks.get(old_file, []))
|
||||
inside = False
|
||||
if old_file in ranges and (src := git_show(base, paths[old_file])) is not None:
|
||||
span = definition_lines(src, item)
|
||||
inside = span is not None and any(a <= span[1] and b >= span[0] for a, b in ranges[old_file])
|
||||
if named or inside:
|
||||
REPORT.append(f"NOT DONE: the branch edits {old_file} near `{item}`; that definition is in {SRC}{new_file} now")
|
||||
new_files = {(old_file, item): new_file for old_file, item, new_file in MOVED}
|
||||
for old_file, item in edited_definitions(base, head, list(new_files), ["crates/engine/src/", SRC]):
|
||||
new_file = new_files[(old_file, item)]
|
||||
REPORT.append(f"NOT DONE: the branch edits {old_file} near `{item}`; that definition is in {SRC}{new_file} now")
|
||||
|
||||
|
||||
def branch(base, head):
|
||||
|
||||
Reference in new issue
Block a user