diff --git a/Dockerfile b/Dockerfile index 8821ece..e447933 100644 --- a/Dockerfile +++ b/Dockerfile @@ -29,6 +29,6 @@ RUN pip install -r requirements.txt COPY . . -RUN python -c "import constants; repos='\n'.join(['\n'.join(['', f'[{repo}]', f'Server = file://{constants.CHROOT_PATHS['packages']}/\$arch/\$repo']) for repo in constants.REPOSITORIES]); print(repos)" | tee -a /etc/pacman.conf +RUN python -c "import distro; distro.get_kupfer_local(arch=None,in_chroot=False).repos_config_snippet()" | tee -a /etc/pacman.conf WORKDIR / diff --git a/chroot.py b/chroot.py index 3b3a035..10bb4b4 100644 --- a/chroot.py +++ b/chroot.py @@ -422,8 +422,12 @@ class Chroot: if not os.path.exists(source_path): raise Exception('Source does not exist') if not allow_overlay: - if self.active_mounts: - raise Exception(f'{self.name}: Chroot has submounts active: {self.active_mounts}') + really_active = [] + for mnt in self.active_mounts: + if check_findmnt(self.get_path(mnt)): + really_active.append(mnt) + if really_active: + raise Exception(f'{self.name}: Chroot has submounts active: {really_active}') if os.path.ismount(self.path): raise Exception(f'{self.name}: There is already something mounted at {self.path}, not mounting over it.') if os.path.exists(os.path.join(self.path, 'usr/bin')): diff --git a/distro.py b/distro.py index ea10716..5507085 100644 --- a/distro.py +++ b/distro.py @@ -129,7 +129,7 @@ class Distro: for package in repo.packages: results[package.name] = package - def _repos_config_snippet(self, extra_repos: dict[str, RepoInfo] = {}) -> str: + def repos_config_snippet(self, extra_repos: dict[str, RepoInfo] = {}) -> str: extras = [Repo(name, url_template=info.url_template, arch=self.arch, options=info.options, scan=False) for name, info in extra_repos.items()] return '\n\n'.join(repo.config_snippet() for repo in (list(self.repos.values()) + extras)) @@ -203,7 +203,7 @@ LocalFileSigLevel = Optional # ''' - return header + self._repos_config_snippet(extra_repos) + return header + self.repos_config_snippet(extra_repos) def get_base_distro(arch: str) -> Distro: @@ -223,5 +223,8 @@ def get_kupfer_https(arch: str) -> Distro: return get_kupfer(arch, KUPFER_HTTPS) -def get_kupfer_local(arch: str) -> Distro: - return get_kupfer(arch, f"file://{config.get_path('packages')}/$arch/$repo") +def get_kupfer_local(arch: str = None, in_chroot: bool = True) -> Distro: + if not arch: + arch = config.runtime['arch'] + dir = CHROOT_PATHS['packages'] if in_chroot else config.get_path('packages') + return get_kupfer(arch, f"file://{dir}/$arch/$repo") diff --git a/packages.py b/packages.py index e453d05..54ec2cc 100644 --- a/packages.py +++ b/packages.py @@ -7,7 +7,7 @@ import subprocess from copy import deepcopy from joblib import Parallel, delayed -from constants import REPOSITORIES, CROSSDIRECT_PKGS, QEMU_BINFMT_PKGS, GCC_HOSTSPECS, ARCHES, Arch +from constants import REPOSITORIES, CROSSDIRECT_PKGS, QEMU_BINFMT_PKGS, GCC_HOSTSPECS, ARCHES, Arch, CHROOT_PATHS from config import config from chroot import get_build_chroot, Chroot from ssh import run_ssh_command, scp_put_files @@ -53,12 +53,12 @@ class Package: native_chroot: Chroot, ) -> None: self.path = path - self._loadinfo(CHROOT_PATHS['pkgbuilds'], native_chroot) + self._loadinfo(native_chroot) - def _loadinfo(self, dir, native_chroot: Chroot): + def _loadinfo(self, native_chroot: Chroot): result = native_chroot.run_cmd( makepkg_cmd + ['--printsrcinfo'], - cwd=os.path.join(dir, self.path), + cwd=os.path.join(CHROOT_PATHS['pkgbuilds'], self.path), stdout=subprocess.PIPE, ) lines = result.stdout.decode('utf-8').split('\n') @@ -86,7 +86,8 @@ class Package: self.repo = self.path.split('/')[0] mode = '' - with open(os.path.join(config.get_path('pkgbuilds'), self.path, 'PKGBUILD'), 'r') as file: + logging.debug(config) + with open(os.path.join(native_chroot.get_path(CHROOT_PATHS['pkgbuilds']), self.path, 'PKGBUILD'), 'r') as file: for line in file.read().split('\n'): if line.startswith('_mode='): mode = line.split('=')[1] @@ -630,6 +631,7 @@ def build(paths: list[str], force: bool, arch: Arch): if arch not in ARCHES: raise Exception(f'Unknown architecture "{arch}". Choices: {", ".join(ARCHES)}') enforce_wrap() + config.enforce_config_loaded() repo: dict[str, Package] = discover_packages() if arch != config.runtime['arch']: build_enable_qemu_binfmt(arch, repo=repo) diff --git a/wrapper.py b/wrapper.py index e2172c7..22b82a5 100644 --- a/wrapper.py +++ b/wrapper.py @@ -35,7 +35,7 @@ def wrap_docker(): for argname in ['--config', '-C']: if arg.startswith(argname): done = True - if arg != argname: # arg is longer, assume --arg=value + if arg.strip() != argname: # arg is longer, assume --arg=value offset = 1 else: offset = 2 @@ -119,7 +119,7 @@ def wrap_docker(): '--privileged', ] + _docker_volumes(volumes) + [tag] - kupfer_cmd = ['kupferbootstrap'] + _filter_args(sys.argv[1:]) + kupfer_cmd = ['kupferbootstrap', '--config', '/root/.config/kupfer/kupferbootstrap.toml'] + _filter_args(sys.argv[1:]) cmd = docker_cmd + kupfer_cmd logging.debug('Wrapping in docker:' + repr(cmd))