mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
Engine split step 7: the paint crate (installs per crate, registry order from command_ids.txt, helpers moved down, paint-only helpers moved up, live-stroke traits, admit hook, tooling)
This commit is contained in:
1 parent
1086d71fd9
commit
850e73c5fb
76 files changed
+1311
-939
No files matched your search
@@ -258,6 +258,9 @@ def import_names(crate, files=None):
|
||||
regions = test_regions(lib) if os.path.exists(lib) else {}
|
||||
files = files if files is not None else tree_files(crate_src(crate))
|
||||
own = OWN | {u.split("/")[-1] for u in units(crate)}
|
||||
if os.path.exists(lib):
|
||||
# Modules the crate's root declares itself (beside the moved ones).
|
||||
own |= {d.group(2) for d in MOD_DECL.finditer(mask(read(lib)))}
|
||||
used, in_code = set(), set()
|
||||
for f in files:
|
||||
masked = mask(read(f))
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Move a branch's added or removed command tables into the engine's install list.
|
||||
|
||||
The engine's command tables are listed, in registry order, in `TABLES` in
|
||||
`crates/engine-core/src/install.rs` (`crates/engine/src/install.rs` before the crate split). Before that, `crates/engine/src/cmd.rs` listed them: first as
|
||||
The engine's command tables are listed in `TABLES` in the `install.rs` of the engine crate that
|
||||
holds their module (`crates/engine-<crate>/src/install.rs`, by `crates.tsv`; core's for a module of a
|
||||
crate not cut out yet; `crates/engine/src/install.rs` before the crate split). Before that, `crates/engine/src/cmd.rs` listed them: first as
|
||||
`v.extend(<module>::specs());` lines in `fn build()`, later as `("<name>", <path>),` entries in
|
||||
`SPECS`. A branch that added or removed a table carries that edit in `cmd.rs`. This script applies
|
||||
it to `TABLES`:
|
||||
@@ -19,10 +20,14 @@ would be lost. Per table, compared between BASE and HEAD:
|
||||
Running it twice gives the same result. Anything it cannot place is listed at the end. Edits of
|
||||
inline commands are `table_fragments.py`'s; run both.
|
||||
"""
|
||||
import argparse, re, subprocess, sys
|
||||
import argparse, os, re, subprocess, sys
|
||||
|
||||
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
||||
from engine_cut import units # noqa: E402
|
||||
|
||||
CMD = "crates/engine/src/cmd.rs"
|
||||
INSTALL = "crates/engine-core/src/install.rs"
|
||||
CRATES = ("model", "store", "vector", "paint", "image", "files")
|
||||
INSTALL_BEFORE_SPLIT = "crates/engine/src/install.rs"
|
||||
EXTEND_RE = re.compile(r"^\s*v\.extend\(((?:crate::)?(?:cmd::)?)([a-z0-9_:]+?)::([a-z0-9_]+)\(\)\);", re.M)
|
||||
ENTRY_RE = re.compile(r'^\s*\("([^"]+)",\s*([A-Za-z0-9_:]+)\),', re.M)
|
||||
@@ -60,6 +65,16 @@ def tables(ref):
|
||||
return out
|
||||
|
||||
|
||||
def install_file(path):
|
||||
"""The install.rs that lists the table at `path` (`crate::cmd::<module>::specs` and the like)."""
|
||||
module = path.split("::")[-2] if path.count("::") >= 2 else ""
|
||||
for c in CRATES:
|
||||
f = f"crates/engine-{c}/src/install.rs"
|
||||
if os.path.exists(f) and any(u.split("/")[-1] == module or u == "cmd/table/" + module for u in units(c)):
|
||||
return f
|
||||
return INSTALL
|
||||
|
||||
|
||||
def main():
|
||||
ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
|
||||
ap.add_argument("--base", required=True, help="the branch's merge-base with the old main")
|
||||
@@ -75,40 +90,37 @@ def main():
|
||||
base = dict(tables(a.base))
|
||||
head = tables(a.head)
|
||||
head_names = {n for n, _ in head}
|
||||
text = open(INSTALL).read()
|
||||
start = text.index("const TABLES:")
|
||||
end = text.index("\n];", start)
|
||||
lines = text[start:end].split("\n")
|
||||
header, rows = lines[0], lines[1:]
|
||||
names = lambda: [m.group(1) if (m := ENTRY_RE.match(r)) else None for r in rows]
|
||||
report = []
|
||||
for pos, (name, path) in enumerate(head):
|
||||
if name in base or name in names():
|
||||
continue
|
||||
pred = next((head[k][0] for k in range(pos - 1, -1, -1) if head[k][0] in names()), None)
|
||||
current = names()
|
||||
if pred is not None:
|
||||
at = len(current) - current[::-1].index(pred)
|
||||
else:
|
||||
fragments = [i for i, r in enumerate(rows) if "crate::cmd::table::" in r]
|
||||
if not fragments:
|
||||
report.append(f"UNPLACED {name}: no predecessor in TABLES")
|
||||
files = sorted({INSTALL} | {install_file(p) for _, p in head} | {install_file(p) for p in base.values()})
|
||||
for install in files:
|
||||
text = open(install).read()
|
||||
start = text.index("const TABLES:")
|
||||
end = text.index("\n];", start)
|
||||
lines = text[start:end].split("\n")
|
||||
header, rows = lines[0], lines[1:]
|
||||
names = lambda: [m.group(1) if (m := ENTRY_RE.match(r)) else None for r in rows]
|
||||
for pos, (name, path) in enumerate(head):
|
||||
if install_file(path) != install or name in base or name in names():
|
||||
continue
|
||||
at = fragments[-1] + 1
|
||||
pred = "the last table fragment"
|
||||
rows.insert(at, f' ("{name}", {path}),')
|
||||
report.append(f"added {name} ({path}) after {pred}")
|
||||
for name in base:
|
||||
if name not in head_names and name in names():
|
||||
rows = [r for r, n in zip(rows, names()) if n != name]
|
||||
report.append(f"removed {name}")
|
||||
text = text[:start] + "\n".join([header] + rows) + text[end:]
|
||||
open(INSTALL, "w").write(text)
|
||||
pred = next((head[k][0] for k in range(pos - 1, -1, -1) if head[k][0] in names()), None)
|
||||
current = names()
|
||||
if pred is not None:
|
||||
at = len(current) - current[::-1].index(pred)
|
||||
else:
|
||||
at = len(rows)
|
||||
pred = "the end of the list"
|
||||
rows.insert(at, f' ("{name}", {path}),')
|
||||
report.append(f"added {name} ({path}) to {install} after {pred}")
|
||||
for name in base:
|
||||
if name not in head_names and name in names():
|
||||
rows = [r for r, n in zip(rows, names()) if n != name]
|
||||
report.append(f"removed {name} from {install}")
|
||||
open(install, "w").write(text[:start] + "\n".join([header] + rows) + text[end:])
|
||||
print("\n".join(report) or "nothing to do")
|
||||
if any(r.startswith("added") for r in report):
|
||||
print(
|
||||
"next: run the test `install::order_tests` with PHOTOCRAFT_WRITE_COMMAND_IDS=1 to regenerate "
|
||||
"install/command_ids.txt, and review its diff"
|
||||
"next: add each new command's id to crates/engine/src/install/command_ids.txt after its "
|
||||
"predecessor (it sets the registry order; the top crate's `install::order_tests` checks it)"
|
||||
)
|
||||
return 1 if any(r.startswith("UNPLACED") for r in report) else 0
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
Before the table was split, `crates/engine/src/cmd.rs` held every core command in one `vec![...]`
|
||||
inside `fn build()`. The entries now live in `crates/engine-core/src/cmd/table/<owner>/<menu>.rs`, and
|
||||
`install/command_ids.txt` pins the registry order. A branch that edited the old table carries its
|
||||
`crates/engine/src/install/command_ids.txt` sets the registry order. A branch that edited the old table carries its
|
||||
edits in `cmd.rs`. This script applies them to the fragments:
|
||||
|
||||
python3 scripts/engine_split/table_fragments.py --base <merge-base> --head <branch>
|
||||
@@ -30,7 +30,9 @@ import argparse, os, re, subprocess, sys, tempfile
|
||||
|
||||
CMD = "crates/engine/src/cmd.rs"
|
||||
TABLE = "crates/engine-core/src/cmd/table"
|
||||
IDS = "crates/engine-core/src/install/command_ids.txt"
|
||||
# The fragment directories of every engine crate (`cmd/table/<owner>/`, in core until its crate is cut out).
|
||||
TABLES = sorted(f"{d}/src/cmd/table" for d in (os.path.join("crates", c) for c in os.listdir("crates")) if os.path.basename(d).startswith("engine-") and os.path.isdir(f"{d}/src/cmd/table")) if os.path.isdir("crates") else [TABLE]
|
||||
IDS = "crates/engine/src/install/command_ids.txt"
|
||||
ID_RE = re.compile(r'"([a-zA-Z]+\.[A-Za-z0-9.]+)"')
|
||||
|
||||
|
||||
@@ -92,9 +94,10 @@ class Fragments:
|
||||
|
||||
def __init__(self):
|
||||
self.files = {}
|
||||
for d, _, names in os.walk(TABLE):
|
||||
walks = [(root, d, names) for root in TABLES for d, _, names in os.walk(root)]
|
||||
for root, d, names in walks:
|
||||
for n in names:
|
||||
if n.endswith(".rs") and os.path.dirname(os.path.join(d, n)) != TABLE:
|
||||
if n.endswith(".rs") and os.path.dirname(os.path.join(d, n)) != root:
|
||||
p = os.path.join(d, n)
|
||||
if "vec![" in open(p).read():
|
||||
self.files[p] = open(p).read()
|
||||
|
||||
Reference in new issue
Block a user