Skip to content

Commit a97b3ec

Browse files
authored
platform_rows: the rows a platform entry serves, derived from its manifest and checked; mcpp.plugins 0.22.1 (#811)
* platform_rows: openkal-platform's rows, derived from its manifest by tools/platform_rows.py, and the lint's check * mcpp.plugins 0.22.1: mcpplibs.os 0.4.4, so a graph whose openkal is 0.25 holds the plugins
1 parent fde3832 commit a97b3ec

7 files changed

Lines changed: 254 additions & 4 deletions

File tree

‎.github/workflows/validate.yml‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,10 @@ jobs:
558558
# release that republished an old tag would leave no other trace.
559559
- name: Lint duplicate versions
560560
run: lua5.4 tests/check_duplicate_versions.lua pkgs/*/*.lua
561+
# A platform entry's `platform_rows` is derived from the manifest of its newest
562+
# version (mcpp SPEC-013 §14): the list matches it, and a row has one platform.
563+
- name: Platform rows match their manifests, one platform a row
564+
run: python3 tools/platform_rows.py check
561565
- name: Check Quill install hook boundaries
562566
run: lua5.4 tests/check_quill_install.lua
563567
# The compatibility measurement's classifier decides a PUBLISHED figure

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
### Added
1111

12+
- **mcpp.plugins 0.22.1。** 成员经 mcpplibs.os 0.4.4 访问系统:0.4.0 钉住 openkal 0.24.0,与含 openkal 0.25 的依赖图(openkal-platform 0.29)不能协调。包的下限仍为 mcpp 2026.10.30.1;`latest` 指向 0.22.1(mcpp-community/mcpp-plugins#55)。
1213
- **openkal-platform 0.29.0。** 启动机器或创建前缀的运行器声明 `enabled = false`(UEFI、DOS 与新增的宿主行运行器),由项目或本机启用;`x86_64-freebsd-musl`、`aarch64-freebsd-musl` 经 dirun 在 xim 的 FreeBSD 磁盘映像中运行,
1314
`x86_64-windows-musl` 在 x86_64 Linux 上经 Wine 运行;UEFI 运行器传递 `--` 之后的参数,并要求 dirun 0.5.0 与 ovmf 9.2.4-3(其配置陈述 UEFI Shell 的引用规则,含空白的参数作为一个参数到达程序);
1415
okrun 增加宿主 `macos-x86_64` 与 `linux-i686`。版本组随 openkal-musl 0.29.8 与 openkal-uefi 0.11.0;需要 mcpp 2026.11.16.1(mcpplibs/openkal-platform#33)。

‎docs/repository-and-schema.md‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,16 @@ resolves.
8888
- `url`: a string, or a `{ GLOBAL=…, CN=… }` table (this repository uses the table form throughout).
8989
- `sha256`: required, and equal to the digest of the actual downloaded bytes.
9090

91+
`platform_rows` (a platform package's entry; mcpp >= 2026.11.17.1 reads it, an earlier mcpp ignores it): the rows
92+
the platform serves, for the rows mcpp's own target table has no platform for (mcpp SPEC-013 §14) — a row the engine
93+
does not know, a `planned` row, a row no built-in provider serves on the host. A build that names such a row and no
94+
platform takes the one whose entry lists it. The list is derived, never written by hand:
95+
`python3 tools/platform_rows.py write pkgs/<x>/<name>.lua` reads the manifest of the newest version and lists
96+
`[platform] targets`, `[[platform.define]]` and `[[platform.provider]] serves` (a pattern stands for the rows it
97+
matches), and of `[platform.hosted] targets` only the rows the engine does not know or holds as `planned`, so no
98+
entry claims a host's own row. The lint job runs `tools/platform_rows.py check`: every list matches its manifest, and
99+
a row has one platform.
100+
91101
`mcpp` (common keys):
92102

93103
| Key | Description |

‎docs/zh/repository-and-schema.md‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,13 @@ namespace = "mcpplibs", name = "capi.lua" -- 短名仍带点
7272
- `url`:字符串,或 `{ GLOBAL=…, CN=… }` 表(本仓统一使用表形式)。
7373
- `sha256`:必填,等于实际下载字节的摘要。
7474

75+
`platform_rows`(平台包的条目;mcpp >= 2026.11.17.1 读取,更早的 mcpp 忽略):平台服务的行,用于 mcpp 自身的目标表
76+
没有平台的行(mcpp SPEC-013 §14)——引擎不认识的行、`planned` 行、本机没有内置提供者服务的行。构建指名这样的行而没有
77+
指定平台时,采用条目列出它的平台。列表是派生数据,不手写:`python3 tools/platform_rows.py write pkgs/<x>/<name>.lua`
78+
读取最新版本的清单,列出 `[platform] targets`、`[[platform.define]]` 与 `[[platform.provider]] serves`(模式代表它
79+
匹配到的行),`[platform.hosted] targets` 中只列入引擎不认识或登记为 `planned` 的行,所以没有条目认领宿主自己的行。
80+
lint 作业运行 `tools/platform_rows.py check`:每份列表与清单一致,且一行只有一个平台。
81+
7582
`mcpp`(常用键):
7683

7784
| 键 | 说明 |

‎pkgs/m/mcpp.plugins.lua‎

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@
22
-- each member selected by a feature.
33
--
44
-- [dependencies.mcpp]
5-
-- plugins = { version = "0.22.0", features = ["rules-spirv"], host-module = true }
5+
-- plugins = { version = "0.22.1", features = ["rules-spirv"], host-module = true }
66
--
77
-- // build.mcpp
88
-- import mcpp;
99
-- import mcpp.rules.spirv;
1010
--
11+
-- 0.22.1 (package floor mcpp 2026.10.30.1): the members reach the system
12+
-- through mcpplibs.os 0.4.4, so a graph whose openkal is 0.25 (openkal-platform
13+
-- 0.29) holds the plugins; 0.4.0 pinned openkal 0.24.0.
14+
--
1115
-- 0.22.0 (package floor mcpp 2026.10.30.1): dist-web's page is the format's
1216
-- one distributable and a long-lived runner named `web` serves it (emrun); a
1317
-- declined request is a warning; with mcpp 2026.11.16.1 dist-web states the
@@ -671,6 +675,13 @@ package = {
671675

672676
xpm = {
673677
linux = {
678+
["0.22.1"] = {
679+
url = {
680+
GLOBAL = "https://github.com/mcpp-community/mcpp-plugins/archive/refs/tags/v0.22.1.tar.gz",
681+
CN = "https://gitcode.com/mcpp-res/mcpp-plugins/releases/download/0.22.1/mcpp-plugins-0.22.1.tar.gz",
682+
},
683+
sha256 = "ac43e6eb4fb2135bd91b3f8dcd08ceb3c77c24ed116811cd5adbe443458a8650",
684+
},
674685
["0.22.0"] = {
675686
url = {
676687
GLOBAL = "https://github.com/mcpp-community/mcpp-plugins/archive/refs/tags/v0.22.0.tar.gz",
@@ -965,9 +976,16 @@ package = {
965976
},
966977
sha256 = "adf1f9d6691a5d05a8a4a94e83c733ea39caee1510ce2c9af4cb23bebabea9f5",
967978
},
968-
["latest"] = { ref = "0.22.0" },
979+
["latest"] = { ref = "0.22.1" },
969980
},
970981
macosx = {
982+
["0.22.1"] = {
983+
url = {
984+
GLOBAL = "https://github.com/mcpp-community/mcpp-plugins/archive/refs/tags/v0.22.1.tar.gz",
985+
CN = "https://gitcode.com/mcpp-res/mcpp-plugins/releases/download/0.22.1/mcpp-plugins-0.22.1.tar.gz",
986+
},
987+
sha256 = "ac43e6eb4fb2135bd91b3f8dcd08ceb3c77c24ed116811cd5adbe443458a8650",
988+
},
971989
["0.22.0"] = {
972990
url = {
973991
GLOBAL = "https://github.com/mcpp-community/mcpp-plugins/archive/refs/tags/v0.22.0.tar.gz",
@@ -1262,9 +1280,16 @@ package = {
12621280
},
12631281
sha256 = "adf1f9d6691a5d05a8a4a94e83c733ea39caee1510ce2c9af4cb23bebabea9f5",
12641282
},
1265-
["latest"] = { ref = "0.22.0" },
1283+
["latest"] = { ref = "0.22.1" },
12661284
},
12671285
windows = {
1286+
["0.22.1"] = {
1287+
url = {
1288+
GLOBAL = "https://github.com/mcpp-community/mcpp-plugins/archive/refs/tags/v0.22.1.tar.gz",
1289+
CN = "https://gitcode.com/mcpp-res/mcpp-plugins/releases/download/0.22.1/mcpp-plugins-0.22.1.tar.gz",
1290+
},
1291+
sha256 = "ac43e6eb4fb2135bd91b3f8dcd08ceb3c77c24ed116811cd5adbe443458a8650",
1292+
},
12681293
["0.22.0"] = {
12691294
url = {
12701295
GLOBAL = "https://github.com/mcpp-community/mcpp-plugins/archive/refs/tags/v0.22.0.tar.gz",
@@ -1559,7 +1584,7 @@ package = {
15591584
},
15601585
sha256 = "adf1f9d6691a5d05a8a4a94e83c733ea39caee1510ce2c9af4cb23bebabea9f5",
15611586
},
1562-
["latest"] = { ref = "0.22.0" },
1587+
["latest"] = { ref = "0.22.1" },
15631588
},
15641589
},
15651590

‎pkgs/o/openkal-platform.lua‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ package = {
1717
repo = "https://github.com/mcpplibs/openkal-platform",
1818
type = "package",
1919

20+
-- The rows this platform serves, for mcpp's platform column (SPEC-013 §14): derived
21+
-- from the newest version's manifest by tools/platform_rows.py, never written by hand.
22+
platform_rows = { "aarch64-freebsd-musl", "aarch64-openkal", "i686-dos-musl", "i686-linux-musl", "i686-openkal", "x86_64-freebsd-musl", "x86_64-macos", "x86_64-openkal", "x86_64-uefi", "x86_64-windows-musl" },
2023
extensions = {
2124
autoupdate = {
2225
tag = "${version}",

‎tools/platform_rows.py‎

Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
#!/usr/bin/env python3
2+
"""The rows a platform package's entry lists (`platform_rows`, mcpp SPEC-013 §14).
3+
4+
mcpp's target table answers its platform column from the engine's own data; for a
5+
row it has no answer for, it reads the rows that the index's platform entries list.
6+
That list is derived data: it is what the platform's own manifest serves, at the
7+
entry's newest version, and is never written by hand.
8+
9+
platform_rows.py write pkgs/o/openkal-platform.lua [...] derive and write the list
10+
platform_rows.py check [pkgs/*/*.lua ...] every list matches its manifest,
11+
and no row has two platforms
12+
13+
A row is listed when the manifest serves it: `[platform] targets`,
14+
`[[platform.define]] triple`, and `[[platform.provider]] serves`, where a pattern
15+
(`*-linux-musl`) stands for the rows it matches among the platform's own and the
16+
engine's (mcpp's builtin.toml at the release the index's CI pins, $MCPP_VERSION).
17+
`[platform.hosted] targets` are the rows its hosted arrangement applies to once the
18+
platform is chosen, host rows among them; of those, only a row the engine does not
19+
hold or holds as `planned` (`i686-linux-musl`) is listed, so the index never names
20+
a platform for a host's own row.
21+
The manifest is read from the GLOBAL archive of the newest version, at the entry's
22+
`mcpp` path; archives are kept under $PLATFORM_ROWS_CACHE (default
23+
~/.cache/mcpp-index-platform-rows), keyed by sha256.
24+
"""
25+
import fnmatch, hashlib, io, os, re, sys, tarfile, tomllib, urllib.request
26+
from pathlib import Path
27+
28+
CACHE = Path(os.environ.get("PLATFORM_ROWS_CACHE", Path.home() / ".cache" / "mcpp-index-platform-rows"))
29+
ENGINE_ROWS = "https://raw.githubusercontent.com/mcpp-community/mcpp/v{}/modules/toolchain-model/data/builtin.toml"
30+
31+
32+
def mcpp_version() -> str:
33+
if v := os.environ.get("MCPP_VERSION"):
34+
return v
35+
m = re.search(r'^\s*MCPP_VERSION:\s*"([^"]+)"', Path(".github/workflows/validate.yml").read_text(), re.M)
36+
if not m:
37+
raise SystemExit("MCPP_VERSION is neither set nor found in .github/workflows/validate.yml")
38+
return m.group(1)
39+
40+
41+
def engine_rows() -> dict[str, str]:
42+
"""The rows of mcpp's built-in table and their tiers, at the release the index pins."""
43+
version = mcpp_version()
44+
path = CACHE / f"builtin-{version}.toml"
45+
if not path.is_file():
46+
CACHE.mkdir(parents=True, exist_ok=True)
47+
path.write_bytes(urllib.request.urlopen(ENGINE_ROWS.format(version), timeout=60).read())
48+
doc = tomllib.loads(path.read_text())
49+
return {d["triple"]: d.get("tier", "") for d in doc.get("platform", {}).get("define", []) if "triple" in d}
50+
ROWS_LINE = re.compile(r'^(\s*)platform_rows\s*=\s*\{([^}]*)\},?\s*$', re.M)
51+
52+
53+
def lua_field(text: str, key: str) -> str | None:
54+
m = re.search(rf'^\s*{key}\s*=\s*"([^"]*)"', text, re.M)
55+
return m.group(1) if m else None
56+
57+
58+
def newest(text: str) -> tuple[str, str, str] | None:
59+
"""(version, GLOBAL url, sha256) of the newest version under `linux`."""
60+
block = re.search(r'\blinux\s*=\s*\{(.*?)\n\s{8}\},', text, re.S)
61+
if not block:
62+
return None
63+
best = None
64+
for m in re.finditer(r'\["(\d+(?:\.\d+)*)"\]\s*=\s*\{(.*?)sha256\s*=\s*"([0-9a-f]{64})"', block.group(1), re.S):
65+
version, body, sha = m.groups()
66+
url = re.search(r'GLOBAL\s*=\s*"([^"]+)"', body) or re.search(r'url\s*=\s*"([^"]+)"', body)
67+
if not url:
68+
continue
69+
key = tuple(int(x) for x in version.split("."))
70+
if best is None or key > best[0]:
71+
best = (key, version, url.group(1), sha)
72+
return best[1:] if best else None
73+
74+
75+
def archive(url: str, sha: str) -> bytes:
76+
path = CACHE / sha
77+
if path.is_file():
78+
return path.read_bytes()
79+
data = urllib.request.urlopen(url, timeout=120).read()
80+
if hashlib.sha256(data).hexdigest() != sha:
81+
raise SystemExit(f"{url}: sha256 differs from the entry's")
82+
CACHE.mkdir(parents=True, exist_ok=True)
83+
path.write_bytes(data)
84+
return data
85+
86+
87+
def toml_1_0(text: str) -> str:
88+
"""An inline table written over several lines (TOML 1.1) on one line, for tomllib."""
89+
out, depth, quote, comment = [], 0, None, False
90+
for ch in text:
91+
if comment:
92+
if ch == "\n":
93+
comment = False
94+
out.append(" " if depth else ch)
95+
continue
96+
if quote:
97+
out.append(ch)
98+
if ch == quote:
99+
quote = None
100+
continue
101+
if ch in "\"'":
102+
quote = ch
103+
elif ch == "#":
104+
comment = True
105+
continue
106+
elif ch == "{":
107+
depth += 1
108+
elif ch == "}":
109+
depth -= 1
110+
elif ch == "\n" and depth:
111+
ch = " "
112+
out.append(ch)
113+
return re.sub(r",\s*}", " }", "".join(out))
114+
115+
116+
def manifest_rows(data: bytes, pattern: str) -> list[str]:
117+
with tarfile.open(fileobj=io.BytesIO(data)) as tar:
118+
names = [n for n in tar.getnames() if fnmatch.fnmatch(n, pattern)]
119+
if not names:
120+
raise SystemExit(f"no manifest {pattern} in the archive")
121+
text = tar.extractfile(min(names, key=len)).read().decode()
122+
doc = tomllib.loads(toml_1_0(text))
123+
platform = doc.get("platform", {})
124+
rows = set(platform.get("targets", []))
125+
rows |= {d["triple"] for d in platform.get("define", []) if "triple" in d}
126+
engine = engine_rows()
127+
rows |= {r for r in platform.get("hosted", {}).get("targets", []) if engine.get(r, "planned") == "planned"}
128+
known = rows | set(engine)
129+
for p in platform.get("provider", []):
130+
for s in p.get("serves", []):
131+
rows |= {r for r in known if fnmatch.fnmatchcase(r, s)} if any(c in s for c in "*?[") else {s}
132+
return sorted(rows)
133+
134+
135+
def derive(path: Path) -> list[str]:
136+
text = path.read_text()
137+
found = newest(text)
138+
pattern = lua_field(text, "mcpp")
139+
if not found or not pattern:
140+
raise SystemExit(f"{path}: no version with an archive, or no `mcpp` manifest path")
141+
version, url, sha = found
142+
return manifest_rows(archive(url, sha), pattern)
143+
144+
145+
def written(text: str) -> list[str] | None:
146+
m = ROWS_LINE.search(text)
147+
return sorted(re.findall(r'"([^"]+)"', m.group(2))) if m else None
148+
149+
150+
def write(path: Path) -> None:
151+
rows = derive(path)
152+
text = path.read_text()
153+
line = " platform_rows = { " + ", ".join(f'"{r}"' for r in rows) + " },"
154+
if ROWS_LINE.search(text):
155+
text = ROWS_LINE.sub(line, text, count=1)
156+
else:
157+
text = re.sub(r'^(\s*type\s*=\s*"package",\s*)$', lambda m: m.group(1) + "\n" + line, text, count=1, flags=re.M)
158+
path.write_text(text)
159+
print(f"{path}: {len(rows)} rows")
160+
161+
162+
def check(paths: list[Path]) -> int:
163+
claims: dict[str, list[str]] = {}
164+
fail = 0
165+
for path in paths:
166+
text = path.read_text()
167+
listed = written(text)
168+
if listed is None:
169+
continue
170+
name = f"{lua_field(text, 'namespace') or 'mcpp'}.{lua_field(text, 'name')}"
171+
for row in listed:
172+
claims.setdefault(row, []).append(name)
173+
derived = derive(path)
174+
if listed != derived:
175+
print(f"::error file={path}::platform_rows is {listed}; the manifest of the newest version serves {derived} "
176+
f"(tools/platform_rows.py write {path})")
177+
fail = 1
178+
for row, who in sorted(claims.items()):
179+
if len(who) > 1:
180+
print(f"::error::{row} is listed by {', '.join(who)}: a row has one platform")
181+
fail = 1
182+
if not fail:
183+
print(f"platform_rows: {len(claims)} rows, each with one platform and matching its manifest")
184+
return fail
185+
186+
187+
def main(argv: list[str]) -> int:
188+
if len(argv) < 2 or argv[1] not in ("write", "check"):
189+
print(__doc__)
190+
return 2
191+
paths = [Path(a) for a in argv[2:]] or sorted(Path("pkgs").glob("*/*.lua"))
192+
if argv[1] == "write":
193+
for p in paths:
194+
write(p)
195+
return 0
196+
return check(paths)
197+
198+
199+
if __name__ == "__main__":
200+
sys.exit(main(sys.argv))

0 commit comments

Comments
 (0)