Chroot.run_cmd(): add cwd
param, convert packages.setup_sources() to use run_cmd() for makepkg
This commit is contained in:
parent
6be94271a2
commit
49e6bf740f
2 changed files with 6 additions and 9 deletions
|
@ -311,6 +311,7 @@ class Chroot:
|
||||||
outer_env: dict[str, str] = os.environ.copy() | {'QEMU_LD_PREFIX': '/usr/aarch64-linux-gnu'},
|
outer_env: dict[str, str] = os.environ.copy() | {'QEMU_LD_PREFIX': '/usr/aarch64-linux-gnu'},
|
||||||
attach_tty: str = False,
|
attach_tty: str = False,
|
||||||
capture_output: str = False,
|
capture_output: str = False,
|
||||||
|
cwd: str = None,
|
||||||
fail_inactive: bool = True) -> subprocess.CompletedProcess:
|
fail_inactive: bool = True) -> subprocess.CompletedProcess:
|
||||||
if not self.active and fail_inactive:
|
if not self.active and fail_inactive:
|
||||||
raise Exception(f'Chroot {self.name} is inactive, not running command! Hint: pass `fail_inactive=False`')
|
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):
|
if not isinstance(script, str) and isinstance(script, list):
|
||||||
script = ' '.join(script)
|
script = ' '.join(script)
|
||||||
|
if cwd:
|
||||||
|
script = f"cd {shell_quote(cwd)} && ( {script} )"
|
||||||
cmd = ['chroot', self.path] + env_cmd + [
|
cmd = ['chroot', self.path] + env_cmd + [
|
||||||
'/bin/bash',
|
'/bin/bash',
|
||||||
'-c',
|
'-c',
|
||||||
|
|
12
packages.py
12
packages.py
|
@ -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):
|
def setup_sources(package: Package, chroot: Chroot, pkgbuilds_dir: str = None):
|
||||||
pkgbuilds_dir = pkgbuilds_dir if pkgbuilds_dir else config.get_path('pkgbuilds')
|
pkgbuilds_dir = pkgbuilds_dir if pkgbuilds_dir else config.get_path('pkgbuilds')
|
||||||
makepkg_setup_args = [
|
makepkg_setup_args = [
|
||||||
'--config',
|
|
||||||
os.path.join(chroot.path, 'etc/makepkg.conf'),
|
|
||||||
'--nobuild',
|
'--nobuild',
|
||||||
'--holdver',
|
'--holdver',
|
||||||
'--nodeps',
|
'--nodeps',
|
||||||
]
|
]
|
||||||
|
|
||||||
logging.info(f'Setting up sources for {package.path} in {chroot.name}')
|
logging.info(f'Setting up sources for {package.path} in {chroot.name}')
|
||||||
result = subprocess.run(
|
result = chroot.run_cmd(makepkg_cmd + makepkg_setup_args, cwd=package.path)
|
||||||
[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),
|
|
||||||
)
|
|
||||||
if result.returncode != 0:
|
if result.returncode != 0:
|
||||||
raise Exception(f'Failed to check sources for {package.path}')
|
raise Exception(f'Failed to check sources for {package.path}')
|
||||||
|
|
||||||
|
@ -493,9 +487,9 @@ def build_package(
|
||||||
setup_sources(package, build_root)
|
setup_sources(package, build_root)
|
||||||
|
|
||||||
makepkg_conf_absolute = os.path.join('/', makepkg_conf_path)
|
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}')
|
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:
|
if result.returncode != 0:
|
||||||
raise Exception(f'Failed to compile package {package.path}')
|
raise Exception(f'Failed to compile package {package.path}')
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue