mirror of
https://gitlab.com/kupfer/kupferbootstrap.git
synced 2025-02-22 21:25:43 -05:00
Clean up envs passing for chroots, add crossdirect packages (todo: cleanup)
This commit is contained in:
parent
c9572bed0f
commit
b490cd10ee
3 changed files with 17 additions and 11 deletions
18
chroot.py
18
chroot.py
|
@ -96,14 +96,18 @@ def create_chroot(chroot_name: str,
|
|||
return chroot_path
|
||||
|
||||
|
||||
def run_chroot_cmd(script: str, chroot_path: str, env: dict[str, str] = {}) -> subprocess.CompletedProcess:
|
||||
|
||||
env_cmd = ['/usr/bin/env'] + [f'{shell_quote(key)}={shell_quote(value)}' for key, value in env.items()]
|
||||
def run_chroot_cmd(script: str,
|
||||
chroot_path: str,
|
||||
inner_env: dict[str, str] = {},
|
||||
outer_env: dict[str, str] = os.environ.copy() | {'QEMU_LD_PREFIX': '/usr/aarch64-linux-gnu'}) -> subprocess.CompletedProcess:
|
||||
if outer_env is None:
|
||||
outer_env = os.environ.copy()
|
||||
env_cmd = ['/usr/bin/env'] + [f'{shell_quote(key)}={shell_quote(value)}' for key, value in inner_env.items()]
|
||||
result = subprocess.run(['arch-chroot', chroot_path] + env_cmd + [
|
||||
'/bin/bash',
|
||||
'-c',
|
||||
script,
|
||||
])
|
||||
], env=outer_env)
|
||||
return result
|
||||
|
||||
|
||||
|
@ -146,7 +150,7 @@ def mount_crossdirect(native_chroot: str, target_chroot: str, target_arch: str,
|
|||
|
||||
native_mount = os.path.join(target_chroot, 'native')
|
||||
logging.debug(f'Activating crossdirect in {native_mount}')
|
||||
results = try_install_packages(['crossdirect', gcc], native_chroot)
|
||||
results = try_install_packages(['crossdirect', 'qemu-user-static-bin', 'binfmt-qemu-static-all-arch', gcc], native_chroot)
|
||||
if results[gcc].returncode != 0:
|
||||
logging.debug('Failed to install cross-compiler package {gcc}')
|
||||
if results['crossdirect'].returncode != 0:
|
||||
|
@ -163,7 +167,7 @@ def mount_crossdirect(native_chroot: str, target_chroot: str, target_arch: str,
|
|||
@click.command('chroot')
|
||||
@click.argument('type', required=False, default='build')
|
||||
@click.argument('arch', required=False, default=None)
|
||||
def cmd_chroot(type: str = 'build', arch: str = None):
|
||||
def cmd_chroot(type: str = 'build', arch: str = None, enable_crossdirect=True):
|
||||
chroot_path = ''
|
||||
if type not in ['base', 'build', 'rootfs']:
|
||||
raise Exception('Unknown chroot type: ' + type)
|
||||
|
@ -196,7 +200,7 @@ def cmd_chroot(type: str = 'build', arch: str = None):
|
|||
native_chroot = create_chroot(
|
||||
'build_' + native_arch,
|
||||
native_arch,
|
||||
packages=['base-devel', 'crossdirect'],
|
||||
packages=['base-devel'] + (['crossdirect', 'qemu-user-static-bin', 'binfmt-qemu-static-all-arch'] if enable_crossdirect else []),
|
||||
extra_repos=get_kupfer_local(native_arch).repos,
|
||||
)
|
||||
mount_crossdirect(native_chroot=native_chroot, target_chroot=chroot_path, target_arch=arch)
|
||||
|
|
|
@ -87,3 +87,5 @@ GCC_HOSTSPECS: dict[DistroArch, dict[TargetArch, str]] = {
|
|||
'aarch64': 'aarch64-unknown-linux-gnu',
|
||||
}
|
||||
}
|
||||
|
||||
CROSSDIRECT_PKGS = ['crossdirect', 'qemu-user-static-bin', 'binfmt-qemu-static-all-arch']
|
||||
|
|
|
@ -302,7 +302,7 @@ def setup_build_chroot(arch: str, extra_packages=[]) -> str:
|
|||
chroot_path = create_chroot(
|
||||
chroot_name,
|
||||
arch=arch,
|
||||
packages=list(set(['base-devel', 'git'] + extra_packages)),
|
||||
packages=list(set(['base-devel', 'git', 'ccache'] + extra_packages)),
|
||||
extra_repos=get_kupfer_local(arch).repos,
|
||||
)
|
||||
|
||||
|
@ -370,7 +370,7 @@ def build_package(package: Package, arch: str, repo_dir: str = None, enable_cros
|
|||
logging.info(f'Cross-compiling {package.path}')
|
||||
build_root = native_chroot
|
||||
makepkg_compile_opts += ['--nodeps']
|
||||
env = makepkg_env | {'QEMU_LD_PREFIX': '/usr/aarch64-unknown-linux-gnu'}
|
||||
env = makepkg_env
|
||||
|
||||
logging.info('Setting up dependencies for cross-compilation')
|
||||
try_install_packages(package.depends, native_chroot)
|
||||
|
@ -381,7 +381,7 @@ def build_package(package: Package, arch: str, repo_dir: str = None, enable_cros
|
|||
env = makepkg_env
|
||||
if not foreign_arch:
|
||||
logging.debug('Building for native arch, skipping crossdirect.')
|
||||
elif enable_crossdirect and not package.name == 'crossdirect':
|
||||
elif enable_crossdirect and not package.name in ['crossdirect', 'qemu-user-static-bin', 'binfmt-qemu-static-all-arch']:
|
||||
env['PATH'] = f"/native/usr/lib/crossdirect/{arch}:{env['PATH']}"
|
||||
mount_crossdirect(native_chroot=native_chroot, target_chroot=target_chroot, target_arch=arch)
|
||||
else:
|
||||
|
@ -396,7 +396,7 @@ def build_package(package: Package, arch: str, repo_dir: str = None, enable_cros
|
|||
raise Exception(f'Failed to bind mount pkgdirs to {build_root}/src')
|
||||
|
||||
build_cmd = f'cd /src/{package.path} && echo $PATH && makepkg --needed --noconfirm --ignorearch {" ".join(makepkg_compile_opts)}'
|
||||
result = run_chroot_cmd(build_cmd, chroot_path=build_root, env=env)
|
||||
result = run_chroot_cmd(build_cmd, chroot_path=build_root, inner_env=env)
|
||||
umount_result = umount(src_dir)
|
||||
if umount_result != 0:
|
||||
logging.warning(f'Failed to unmount {src_dir}')
|
||||
|
|
Loading…
Add table
Reference in a new issue