Harden signed feeds and RelWithDebInfo releases
Modular container CI / release-build (push) Has been cancelled
Modular container CI / release-build (push) Has been cancelled
This commit is contained in:
21 files changed
+243
-40
No files matched your search
@@ -10,6 +10,7 @@ import os
|
||||
from pathlib import Path
|
||||
import re
|
||||
import shutil
|
||||
import subprocess
|
||||
import tempfile
|
||||
from types import ModuleType
|
||||
from typing import Any, NoReturn
|
||||
@@ -23,6 +24,7 @@ SEMVER = re.compile(
|
||||
r"(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$"
|
||||
)
|
||||
TOKEN = re.compile(r"^[A-Za-z0-9][A-Za-z0-9._-]{0,255}$")
|
||||
RELEASE_BUILD_TYPE = "RelWithDebInfo"
|
||||
|
||||
|
||||
def fail(message: str) -> NoReturn:
|
||||
@@ -51,6 +53,38 @@ def load_json_object(path: Path, label: str) -> dict[str, Any]:
|
||||
return value
|
||||
|
||||
|
||||
def require_debug_information(root: Path) -> None:
|
||||
readelf = shutil.which("readelf")
|
||||
if readelf is None:
|
||||
fail("readelf is required to verify RelWithDebInfo artifacts")
|
||||
for path in sorted(root.rglob("*")):
|
||||
if path.is_symlink() or not path.is_file():
|
||||
continue
|
||||
try:
|
||||
with path.open("rb") as stream:
|
||||
is_elf = stream.read(4) == b"\x7fELF"
|
||||
except OSError as error:
|
||||
fail(f"cannot inspect {path}: {error}")
|
||||
if not is_elf:
|
||||
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()
|
||||
fail(f"readelf failed for {path.relative_to(root)}: {message}")
|
||||
if re.search(r"\]\s+\.(?:z)?debug_info\s", completed.stdout) is None:
|
||||
fail(
|
||||
f"ELF {path.relative_to(root)} has no debug information; "
|
||||
f"expected a {RELEASE_BUILD_TYPE} artifact"
|
||||
)
|
||||
|
||||
|
||||
def main() -> None:
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("--registry", type=Path, default=Path("components.json"))
|
||||
@@ -65,6 +99,9 @@ def main() -> None:
|
||||
parser.add_argument("--source-tree-hash", required=True)
|
||||
parser.add_argument("--abi-hash")
|
||||
parser.add_argument("--build-dependencies", type=Path)
|
||||
parser.add_argument(
|
||||
"--build-type", choices=(RELEASE_BUILD_TYPE,), required=True
|
||||
)
|
||||
parser.add_argument("--platform", default="linux")
|
||||
parser.add_argument("--architecture", default="x86_64")
|
||||
parser.add_argument(
|
||||
@@ -122,6 +159,7 @@ def main() -> None:
|
||||
package_root = arguments.package_root.resolve(strict=True)
|
||||
if package_root.is_symlink() or not package_root.is_dir():
|
||||
fail("--package-root must be a real directory")
|
||||
require_debug_information(package_root)
|
||||
output = arguments.output.resolve()
|
||||
output.mkdir(parents=True, exist_ok=True)
|
||||
epoch_value = os.environ.get("SOURCE_DATE_EPOCH", "0")
|
||||
@@ -152,6 +190,7 @@ def main() -> None:
|
||||
"activation": definition["activation"],
|
||||
"dependencies": definition["dependencies"],
|
||||
"buildDependencies": build_dependencies,
|
||||
"buildType": arguments.build_type,
|
||||
"platform": arguments.platform,
|
||||
"architecture": arguments.architecture,
|
||||
"toolchainContract": arguments.toolchain_contract,
|
||||
|
||||
Reference in new issue
Block a user