Verify debug information in SDK release artifacts
Modular container CI / release-build (push) Has been cancelled

This commit is contained in:
faumaray committed 2026-08-01 18:07:06 +03:00
1 parent 8ac39621fd
commit 8212f13a19
2 files changed
+88

No files matched your search

@@ -18,6 +18,7 @@ ROOT = Path(__file__).resolve().parents[2]
PACKAGE = ROOT / "scripts" / "package-component.py"
PUBLISH = ROOT / "scripts" / "publish-component-release.py"
VERIFY = ROOT / "scripts" / "verify-locked-component-feeds.py"
VERIFY_RELWITHDEBINFO = ROOT / "scripts" / "verify-relwithdebinfo.py"
class IndependentComponentReleaseTests(unittest.TestCase):
@@ -111,12 +112,29 @@ class IndependentComponentReleaseTests(unittest.TestCase):
)
with self.assertRaisesRegex(SystemExit, "has no debug information"):
module.require_debug_information(package_root)
rejected = subprocess.run(
[str(VERIFY_RELWITHDEBINFO), "--root", str(package_root)],
check=False,
text=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
self.assertNotEqual(rejected.returncode, 0)
self.assertIn("has no debug information", rejected.stderr)
subprocess.run(
[compiler, "-O2", "-g", str(source), "-o", str(executable)],
check=True,
)
module.require_debug_information(package_root)
accepted = subprocess.run(
[str(VERIFY_RELWITHDEBINFO), "--root", str(package_root)],
check=False,
text=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
self.assertEqual(accepted.returncode, 0, accepted.stderr)
def package(self, component: str, package_id: str, version: str) -> tuple[Path, Path]:
package_root = self.root / f"stage-{component}"
+70
View File
@@ -0,0 +1,70 @@
#!/usr/bin/env python3
"""Reject release trees containing ELF files without debug information."""
from __future__ import annotations
import argparse
import os
from pathlib import Path
import re
import shutil
import subprocess
DEBUG_SECTION = re.compile(r"\]\s+\.(?:z)?debug_info\s")
def is_elf(path: Path) -> bool:
with path.open("rb") as stream:
return stream.read(4) == b"\x7fELF"
def verify(root: Path) -> int:
readelf = shutil.which("readelf")
if readelf is None:
raise ValueError("readelf is required")
verified = 0
for path in sorted(root.rglob("*")):
if path.is_symlink() or not path.is_file() or not is_elf(path):
continue
completed = subprocess.run(
[readelf, "-SW", os.fspath(path)],
check=False,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True,
env={**os.environ, "LC_ALL": "C"},
)
if completed.returncode != 0:
message = completed.stderr.strip() or completed.stdout.strip()
raise ValueError(
f"readelf failed for {path.relative_to(root)}: {message}"
)
if DEBUG_SECTION.search(completed.stdout) is None:
raise ValueError(
f"ELF {path.relative_to(root)} has no debug information; "
"expected a RelWithDebInfo artifact"
)
verified += 1
if verified == 0:
raise ValueError("release tree contains no ELF files to verify")
return verified
def main() -> int:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--root", required=True, type=Path)
arguments = parser.parse_args()
try:
root = arguments.root.resolve(strict=True)
if root.is_symlink() or not root.is_dir():
raise ValueError("--root must be a real directory")
verified = verify(root)
except (OSError, ValueError) as error:
parser.error(str(error))
print(f"verified debug information in {verified} ELF files")
return 0
if __name__ == "__main__":
raise SystemExit(main())