Impl. checking PKGBUILD versions from in chroot

This commit is contained in:
Stephen Seo 2023-11-18 19:37:10 +09:00
parent 106adcd27b
commit 9ac2a1e934

View file

@ -755,17 +755,73 @@ def get_pkgbuild_version(
pkgver = None pkgver = None
pkgrel = None pkgrel = None
# TODO maybe sandbox sourcing the PKGBUILD # Setup checking the PKGBUILD from within the chroot.
pkgbuild_output = subprocess.run( chroot_user_path = os.path.join(
( other_state["tmpfs_chroot"]
"/usr/bin/env", if other_state["tmpfs"]
"bash", else other_state["chroot"],
"-c", other_state["USER"],
f"source {os.path.join(pkgdir, 'PKGBUILD')}; echo \"pkgver=$pkgver\"; echo \"pkgrel=$pkgrel\"; echo \"epoch=$epoch\"",
),
capture_output=True,
text=True,
) )
chroot_build_path = os.path.join(chroot_user_path, "build")
chroot_check_pkgbuild_path = os.path.join(chroot_build_path, "PKGBUILD")
chroot_check_sh_path = os.path.join(chroot_build_path, "check.sh")
try:
subprocess.run(
(
"/usr/bin/cp",
os.path.join(pkgdir, "PKGBUILD"),
chroot_check_pkgbuild_path,
),
check=True,
)
except subprocess.CalledProcessError:
log_print(
f'ERROR: Failed to check PKGBUILD (moving PKGBUILD to chroot) for "{pkg}"!',
other_state=other_state,
)
return False, None, None, None
check_pkgbuild_script = """#!/usr/bin/env bash
set -e
source "/build/PKGBUILD"
echo "pkgver=$pkgver"
echo "pkgrel=$pkgrel"
echo "epoch=$epoch"
"""
if not create_executable_script(
chroot_check_sh_path, check_pkgbuild_script
):
log_print(
f'ERROR: Failed to check PKGBUILD (check PKGBUILD setup) for "{pkg}"!',
other_state=other_state,
)
return False, None, None, None
pkgbuild_output = str()
try:
pkgbuild_output = subprocess.run(
(
"/usr/bin/env",
"sudo",
"arch-nspawn",
chroot_user_path,
"/build/check.sh",
),
check=True,
capture_output=True,
text=True,
)
except subprocess.CalledProcessError:
log_print(
f'ERROR: Failed to check PKGBUILD (checking PKGBUILD) for "{pkg}"!',
other_state=other_state,
)
return False, None, None, None
output_ver_re = re.compile( output_ver_re = re.compile(
"^pkgver=([a-zA-Z0-9._+-]+)\\s*$", flags=re.M "^pkgver=([a-zA-Z0-9._+-]+)\\s*$", flags=re.M
) )