diff --git a/docs/release.md b/docs/release.md index 4009c9ac..ea4cea64 100644 --- a/docs/release.md +++ b/docs/release.md @@ -54,3 +54,15 @@ release-mode 调试仍可使用调试签名,调试签名包不能作为正式 macOS 桌面包使用 ad-hoc 签名,未配置 Apple Developer ID 或公证;首次使用时 可能需要在系统隐私与安全性设置中允许打开。iOS 需要分发证书与 provisioning, 未配置时不发布不可安装的 IPA。 + +## 在本地检查 Linux 包的 glibc 版本需求 + +解开最终归档后,把包含 `backend/` 的 `Panache` 目录交给脚本,并明确指定要验证的 glibc 上限。例如,在 Debian 13 上验证 2.41 可运行以下命令。 + +```sh +python3 scripts/check-linux-glibc.py /path/to/Panache --max-glibc 2.41 +``` + +脚本使用 GNU `readelf` 读取包内 ELF 的版本需求。退出码 0 表示所有读到的数字 GLIBC 需求都在上限内,1 表示至少一个文件超界,2 表示参数有误,3 表示包或版本信息无法检查,4 表示缺少必需的 Rust 后端,5 表示找不到 `readelf`。无法换算成数字的 GLIBC 需求也会报错。检查通过后,仍需在目标系统上启动桌面程序,验证图形库和真实工具调用。 + +v1.21.0 官方 Linux x64 包以 2.41 为上限时,12 个 ELF 中有两个后端要求 `GLIBC_2.43`。在 Debian 13 从同一提交重建这两个后端后,同一个检查有 0 个文件超界。2.41 仅为这次对照使用的上限。 diff --git a/scripts/check-linux-glibc.py b/scripts/check-linux-glibc.py new file mode 100644 index 00000000..09731aa6 --- /dev/null +++ b/scripts/check-linux-glibc.py @@ -0,0 +1,106 @@ +#!/usr/bin/env python3 +"""Check ELF version requirements in an unpacked Panache Linux release.""" +import argparse +import os +from pathlib import Path +import re +import shutil +import subprocess +import sys + + +BACKENDS = ('backend/handwriting-server', 'backend/panache-mcp') + + +def version(text): + if not re.fullmatch(r'[0-9]+(?:\.[0-9]+)+', text): + raise ValueError(f'expected a numeric version, got {text!r}') + parts = [int(n) for n in text.split('.')] + while len(parts) > 2 and parts[-1] == 0: + parts.pop() + return tuple(parts) + + +def requirements(output): + # readelf also prints names that the object defines or merely lists in .gnu.version. + needs = re.search(r'^Version needs section [^\n]+\n((?:[ \t]+[^\n]+\n?)*)', output, re.M) + block = needs[1] if needs else '' + if not needs and 'No version information found' not in output and not re.search( + r'^Version (?:symbols|definition) section ', output, re.M): + raise ValueError('unrecognized GNU readelf version output') + providers = re.findall(r'\bFile: \S+\s+Cnt: (\d+)', block) + names = re.findall(r'\bName: (\S+)\s+Flags:', block) + count = re.search(r'\(VERNEEDNUM\)\s+(\d+)', output) + if (' ceiling: + print(f'{relative}: requires GLIBC_{highest}') + exceeded += 1 + print(f'{checked} ELF files checked, {exceeded} above the requested ceiling') + return int(bool(exceeded)) + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument('bundle', type=Path, help='unpacked directory containing backend/') + parser.add_argument('--max-glibc', required=True, type=version, metavar='VERSION') + args = parser.parse_args() + tool = shutil.which('readelf') + if not tool: + print('GNU readelf not found', file=sys.stderr) + return 5 + try: + root = args.bundle.resolve(strict=True) + if not root.is_dir(): + raise ValueError('expected an unpacked bundle directory') + missing = [name for name in BACKENDS if not (root / name).exists()] + if missing: + print('missing required backend: ' + ', '.join(missing), file=sys.stderr) + return 4 + if not (root / 'handwriting_app').is_file(): + raise ValueError('missing desktop executable handwriting_app') + return scan(root, tool, args.max_glibc) + except (OSError, ValueError, RuntimeError) as error: + print(error, file=sys.stderr) + return 3 + + +if __name__ == '__main__': + sys.exit(main()) diff --git a/scripts/tests/test_linux_glibc.py b/scripts/tests/test_linux_glibc.py new file mode 100644 index 00000000..f4c1e84b --- /dev/null +++ b/scripts/tests/test_linux_glibc.py @@ -0,0 +1,73 @@ +"""Run on Linux with a C compiler and GNU binutils.""" +import os +from pathlib import Path +import shutil +import subprocess +import sys +import tempfile +import unittest + + +SCRIPT = Path(__file__).resolve().parents[1] / 'check-linux-glibc.py' + + +@unittest.skipUnless(sys.platform.startswith('linux') and shutil.which('cc') and shutil.which('readelf'), + 'requires Linux cc and GNU readelf') +class LinuxGlibcTest(unittest.TestCase): + def setUp(self): + tmp = tempfile.TemporaryDirectory() + self.addCleanup(tmp.cleanup) + self.root = Path(tmp.name) + self.bundle = self.root / 'Panache' + self.backend = self.bundle / 'backend' + self.backend.mkdir(parents=True) + # The provider defines a high version and contains an unrelated version string. + # Only an ELF that imports its function should count against the ceiling. + (self.root / 'provider.c').write_text('const char *probe(void) { return "GLIBC_99.99"; }') + (self.root / 'versions').write_text('GLIBC_2.10 { global: probe; };') + self.provider = self.bundle / 'provider.so' + subprocess.run(['cc', '-shared', '-fPIC', '-nostdlib', 'provider.c', + '-Wl,--version-script=versions', '-o', self.provider], cwd=self.root, check=True) + for rel in ('handwriting_app', 'backend/panache-mcp', 'backend/handwriting-server'): + shutil.copyfile(self.provider, self.bundle / rel) + + def check(self, *args, path=None): + env = os.environ.copy() + if path is not None: + env['PATH'] = path + return subprocess.run([sys.executable, SCRIPT, self.bundle, *args], + capture_output=True, text=True, env=env) + + def test_definition_string_and_real_import(self): + self.assertEqual(self.check('--max-glibc', '2.9').returncode, 0) + (self.root / 'consumer.c').write_text('extern const char *probe(void);' + 'const char *call(void) { return probe(); }') + subprocess.run(['cc', '-shared', '-fPIC', '-nostdlib', 'consumer.c', + self.provider, '-o', self.bundle / 'extra.so'], cwd=self.root, check=True) + result = self.check('--max-glibc', '2.9') + self.assertEqual(result.returncode, 1, result.stderr) + self.assertIn('extra.so: requires GLIBC_2.10', result.stdout) + self.assertEqual(self.check('--max-glibc', '2.10.0').returncode, 0) + + def test_missing_backend(self): + (self.backend / 'panache-mcp').unlink() + result = self.check('--max-glibc', '2.41') + self.assertEqual(result.returncode, 4) + self.assertIn('backend/panache-mcp', result.stderr) + + def test_damaged_elf(self): + (self.backend / 'handwriting-server').write_bytes(b'\x7fELF') + result = self.check('--max-glibc', '2.41') + self.assertEqual(result.returncode, 3) + self.assertIn('backend/handwriting-server', result.stderr) + + def test_missing_tool(self): + self.assertEqual(self.check('--max-glibc', '2.41', path=str(self.root)).returncode, 5) + + def test_ceiling_required_and_numeric(self): + self.assertEqual(self.check().returncode, 2) + self.assertEqual(self.check('--max-glibc', 'latest').returncode, 2) + + +if __name__ == '__main__': + unittest.main()