Chroot.run_cmd(): add cwd param, convert packages.setup_sources() to use run_cmd() for makepkg

This commit is contained in:
InsanePrawn 2021-10-23 21:10:54 +02:00
parent 6be94271a2
commit 49e6bf740f
2 changed files with 6 additions and 9 deletions

View file

@ -311,6 +311,7 @@ class Chroot:
outer_env: dict[str, str] = os.environ.copy() | {'QEMU_LD_PREFIX': '/usr/aarch64-linux-gnu'},
attach_tty: str = False,
capture_output: str = False,
cwd: str = None,
fail_inactive: bool = True) -> subprocess.CompletedProcess:
if not self.active and fail_inactive:
raise Exception(f'Chroot {self.name} is inactive, not running command! Hint: pass `fail_inactive=False`')
@ -326,6 +327,8 @@ class Chroot:
if not isinstance(script, str) and isinstance(script, list):
script = ' '.join(script)
if cwd:
script = f"cd {shell_quote(cwd)} && ( {script} )"
cmd = ['chroot', self.path] + env_cmd + [
'/bin/bash',
'-c',

View file

@ -414,19 +414,13 @@ def setup_build_chroot(arch: Arch, extra_packages: list[str] = [], clean_chroot:
def setup_sources(package: Package, chroot: Chroot, pkgbuilds_dir: str = None):
pkgbuilds_dir = pkgbuilds_dir if pkgbuilds_dir else config.get_path('pkgbuilds')
makepkg_setup_args = [
'--config',
os.path.join(chroot.path, 'etc/makepkg.conf'),
'--nobuild',
'--holdver',
'--nodeps',
]
logging.info(f'Setting up sources for {package.path} in {chroot.name}')
result = subprocess.run(
[os.path.join(chroot.path, 'usr/bin/makepkg')] + makepkg_cmd[1:] + makepkg_setup_args,
env=makepkg_cross_env | {'PACMAN_CHROOT': chroot.path},
cwd=os.path.join(pkgbuilds_dir, package.path),
)
result = chroot.run_cmd(makepkg_cmd + makepkg_setup_args, cwd=package.path)
if result.returncode != 0:
raise Exception(f'Failed to check sources for {package.path}')
@ -493,9 +487,9 @@ def build_package(
setup_sources(package, build_root)
makepkg_conf_absolute = os.path.join('/', makepkg_conf_path)
build_cmd = f'cd {package.path} && makepkg --config {makepkg_conf_absolute} --needed --noconfirm --ignorearch {" ".join(makepkg_compile_opts)}'
build_cmd = f'makepkg --config {makepkg_conf_absolute} --needed --noconfirm --ignorearch {" ".join(makepkg_compile_opts)}'
logging.debug(f'Building: Running {build_cmd}')
result = build_root.run_cmd(build_cmd, inner_env=env)
result = build_root.run_cmd(build_cmd, inner_env=env, cwd=package.path)
if result.returncode != 0:
raise Exception(f'Failed to compile package {package.path}')