Migrate leftovers to CHROOT_PATHS

This commit is contained in:
InsanePrawn 2022-01-26 16:47:36 +01:00
parent 8ead5c9542
commit a0a5a5a677
5 changed files with 23 additions and 14 deletions

View file

@ -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 /

View file

@ -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')):

View file

@ -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")

View file

@ -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)

View file

@ -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))