build: single-file bundles build/Rosetta.luau + build/rosetta.lua (tools/bundle.py), terse README with generated format / codec tables
- tools/bundle.py: every module a function in __FILES with a cached __include; requires become __include calls, so only the API and its load-time requires run on require. Rosetta._internal(path) includes any module by its src path. --!native modules get @native on each function (NATIVE re-checked on the bundle); linemaps map bundle lines back to sources (--where). LuaJIT bundle inlines the compat prelude. - tools/build.py: the multi-file trees move to build/_modules (gitignored); each target also writes its bundle. - tools/test.sh: api + docs/example tests also run against both bundles; fails when build/ is stale. - default.project.json mounts build/Rosetta.luau; examples/love loads build/rosetta.lua. - README: one line, install, quick start, doc links, generated format table and codec list (tools/gen_registry.py), licence TODO. DOCS lint checks the generated sections and the links.
This commit is contained in:
1 parent
0bd7b87d2b
commit
bcf6d46fb7
16 files changed
+399611
-210
No files matched your search
+65
-4
@@ -4,9 +4,11 @@
|
||||
# src/Rosetta/Registry.luau a static list (Roblox has no dynamic require): each format's contract metadata, copied
|
||||
# from its init.luau, and a load() that requires the module on first use
|
||||
# docs/FORMATS.md the capability matrix, from each contract's caps
|
||||
# README.md the format table (read / write) and the codec + container list, between the markers
|
||||
# <!-- formats:begin --> / <!-- formats:end --> and <!-- codecs:begin --> / <!-- codecs:end -->
|
||||
# The metadata fields must be one-line literals in the contract table (tools/lint.sh CONTRACT checks the shape):
|
||||
# name = "png", category = "image", extensions = { ... }, mime = { ... }, deps = { ... }, caps = { ... },
|
||||
# --check: exit 1 when either file is out of date (tools/lint.sh runs this).
|
||||
# --check: exit 1 when any of them is out of date (tools/lint.sh runs this).
|
||||
import os, re, sys
|
||||
|
||||
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
@@ -156,21 +158,80 @@ def formats_md(formats):
|
||||
return "\n".join(lines)
|
||||
|
||||
|
||||
LABELS = {"image": "Images", "audio": "Audio", "video": "Video", "model": "3D models", "cad": "CAD", "font": "Fonts",
|
||||
"archive": "Archives", "data": "Data", "vector": "Vector graphics and tile maps", "layered": "Layered images",
|
||||
"subtitle": "Subtitles", "music": "Music", "playlist": "Playlists"}
|
||||
|
||||
|
||||
def module_list(rel):
|
||||
"""[(name, file)] of the modules directly under src/Rosetta/<rel> (Foo.luau or Foo/init.luau)"""
|
||||
d = os.path.join(SRC, rel)
|
||||
out = []
|
||||
for name in sorted(os.listdir(d)) if os.path.isdir(d) else []:
|
||||
p = os.path.join(d, name)
|
||||
f = os.path.join(p, "init.luau") if os.path.isdir(p) else p
|
||||
if os.path.isfile(f) and f.endswith(".luau"):
|
||||
out.append((name[:-5] if name.endswith(".luau") else name, f))
|
||||
return out
|
||||
|
||||
|
||||
def readme_formats(formats):
|
||||
by = {}
|
||||
for c in formats:
|
||||
by.setdefault(c["folder_category"], []).append(c)
|
||||
lines = ["%d formats. Generated from the format contracts by `tools/gen_registry.py`; [docs/FORMATS.md](docs/FORMATS.md)"
|
||||
% len(formats), "adds each format's capabilities.", "",
|
||||
"| Category | Format | Extensions | Read | Write |", "|---|---|---|---|---|"]
|
||||
for cat in CATEGORIES:
|
||||
for c in by.get(cat, []):
|
||||
cd = dict(caps_dict(c["caps"]))
|
||||
lines.append("| %s | %s | %s | %s | %s |" % (
|
||||
LABELS[cat], lua_strings(c["name"])[0], " ".join("." + e for e in lua_strings(c["extensions"])),
|
||||
"yes" if cd.get("decode") == "true" else "-", "yes" if cd.get("encode") == "true" else "-"))
|
||||
return "\n".join(lines)
|
||||
|
||||
|
||||
def readme_codecs():
|
||||
lines = ["Shared by the formats, not loadable on their own (`src/Rosetta/codecs/<domain>/`, `src/Rosetta/containers/`;",
|
||||
"[docs/FORMATS.md](docs/FORMATS.md) describes each). The bundles reach them as `F._internal(\"codecs/video/Mpeg1\")`.",
|
||||
"", "| Domain | Modules |", "|---|---|"]
|
||||
cdir = os.path.join(SRC, "codecs")
|
||||
for domain in sorted(os.listdir(cdir)):
|
||||
if os.path.isdir(os.path.join(cdir, domain)):
|
||||
lines.append("| %s | %s |" % (domain, ", ".join(n for n, _ in module_list("codecs/" + domain))))
|
||||
lines.append("| containers | %s |" % ", ".join(n for n, _ in module_list("containers")))
|
||||
return "\n".join(lines)
|
||||
|
||||
|
||||
def readme(formats, path):
|
||||
"""README.md with its generated sections replaced"""
|
||||
text = open(path, encoding="utf-8").read()
|
||||
for tag, body in (("formats", readme_formats(formats)), ("codecs", readme_codecs())):
|
||||
begin, end = "<!-- %s:begin -->" % tag, "<!-- %s:end -->" % tag
|
||||
m = re.search(re.escape(begin) + r".*?" + re.escape(end), text, re.S)
|
||||
if not m:
|
||||
sys.exit("gen_registry: README.md has no %s ... %s section" % (begin, end))
|
||||
text = text[:m.start()] + begin + "\n" + body + "\n" + end + text[m.end():]
|
||||
return text
|
||||
|
||||
|
||||
def main():
|
||||
formats = scan()
|
||||
readme_path = os.path.join(ROOT, "README.md")
|
||||
outputs = {
|
||||
os.path.join(SRC, "Registry.luau"): registry(formats),
|
||||
os.path.join(ROOT, "docs", "FORMATS.md"): formats_md(formats),
|
||||
readme_path: readme(formats, readme_path),
|
||||
}
|
||||
check = "--check" in sys.argv
|
||||
stale = []
|
||||
for path, text in outputs.items():
|
||||
old = open(path).read() if os.path.exists(path) else None
|
||||
old = open(path, encoding="utf-8").read() if os.path.exists(path) else None
|
||||
if old != text:
|
||||
stale.append(os.path.relpath(path, ROOT))
|
||||
if not check:
|
||||
os.makedirs(os.path.dirname(path), exist_ok=True)
|
||||
with open(path, "w") as f:
|
||||
with open(path, "w", encoding="utf-8") as f:
|
||||
f.write(text)
|
||||
if check:
|
||||
if stale:
|
||||
@@ -178,7 +239,7 @@ def main():
|
||||
sys.exit(1)
|
||||
print("gen_registry: up to date (%d formats)" % len(formats))
|
||||
else:
|
||||
print("gen_registry: %d formats -> src/Rosetta/Registry.luau, docs/FORMATS.md%s" % (
|
||||
print("gen_registry: %d formats -> src/Rosetta/Registry.luau, docs/FORMATS.md, README.md%s" % (
|
||||
len(formats), "" if stale else " (unchanged)"))
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user