refactor packages.py code into chroot.generate_makepkg_conf(), use generated conf in check_package_version_built()
This commit is contained in:
parent
1c8fd7eccd
commit
1ba4dcfaec
2 changed files with 22 additions and 9 deletions
13
chroot.py
13
chroot.py
|
@ -11,6 +11,7 @@ from distro import get_kupfer_local
|
|||
from wrapper import enforce_wrap
|
||||
from constants import GCC_HOSTSPECS, CROSSDIRECT_PKGS
|
||||
from glob import glob
|
||||
from generator import generate_makepkg_conf
|
||||
|
||||
BIND_BUILD_DIRS = 'BINDBUILDDIRS'
|
||||
|
||||
|
@ -171,6 +172,18 @@ def mount_crossdirect(native_chroot: str, target_chroot: str, target_arch: str,
|
|||
raise Exception(f'Failed to mount native chroot {native_chroot} to {native_mount}')
|
||||
|
||||
|
||||
def write_cross_makepkg_conf(native_chroot: str, arch: str, target_chroot_relative: str, cross: bool = True) -> str:
|
||||
"""
|
||||
Generate a makepkg_cross_$arch.conf file in `native_chroot`/etc, building for `target_chroot_relative`
|
||||
Returns the absolute (host) path to the makepkg config file.
|
||||
"""
|
||||
makepkg_cross_conf = generate_makepkg_conf(arch, cross=cross, chroot=target_chroot_relative)
|
||||
makepkg_conf_path = os.path.join(native_chroot, 'etc', f'makepkg_cross_{arch}.conf')
|
||||
with open(makepkg_conf_path, 'w') as f:
|
||||
f.write(makepkg_cross_conf)
|
||||
return makepkg_conf_path
|
||||
|
||||
|
||||
@click.command('chroot')
|
||||
@click.argument('type', required=False, default='build')
|
||||
@click.argument('arch', required=False, default=None)
|
||||
|
|
18
packages.py
18
packages.py
|
@ -9,11 +9,10 @@ from joblib import Parallel, delayed
|
|||
|
||||
from constants import REPOSITORIES, CROSSDIRECT_PKGS, GCC_HOSTSPECS
|
||||
from config import config
|
||||
from chroot import create_chroot, run_chroot_cmd, try_install_packages, mount_crossdirect
|
||||
from chroot import create_chroot, run_chroot_cmd, try_install_packages, mount_crossdirect, write_cross_makepkg_conf
|
||||
from distro import get_kupfer_local
|
||||
from wrapper import enforce_wrap, check_programs_wrap
|
||||
from utils import mount, umount
|
||||
from generator import generate_makepkg_conf
|
||||
|
||||
makepkg_env = os.environ.copy() | {
|
||||
'LANG': 'C',
|
||||
|
@ -239,7 +238,7 @@ def generate_dependency_chain(package_repo: dict[str, Package], to_build: list[P
|
|||
if pkg_done:
|
||||
break
|
||||
if type(other_pkg) != Package:
|
||||
logging.fatal('Wtf, this is not a package:' + repr(other_pkg))
|
||||
raise Exception('Not a Package object:' + repr(other_pkg))
|
||||
for dep_name in other_pkg.depends:
|
||||
if dep_name in pkg.names:
|
||||
dep_levels[level].remove(pkg)
|
||||
|
@ -272,11 +271,15 @@ def generate_dependency_chain(package_repo: dict[str, Package], to_build: list[P
|
|||
return list([lvl for lvl in dep_levels[::-1] if lvl])
|
||||
|
||||
|
||||
def check_package_version_built(package: Package) -> bool:
|
||||
def check_package_version_built(package: Package, arch) -> bool:
|
||||
built = True
|
||||
|
||||
config_path = write_cross_makepkg_conf(native_chroot='/', arch=arch, target_chroot_relative=None, cross=False)
|
||||
|
||||
result = subprocess.run(
|
||||
makepkg_cmd + [
|
||||
'--config',
|
||||
config_path,
|
||||
'--nobuild',
|
||||
'--noprepare',
|
||||
'--packagelist',
|
||||
|
@ -387,10 +390,7 @@ def build_package(
|
|||
# mount foreign arch chroot inside native chroot
|
||||
chroot_relative = os.path.join('chroot', os.path.basename(target_chroot))
|
||||
chroot_mount_path = os.path.join(native_chroot, chroot_relative)
|
||||
makepkg_cross_conf = generate_makepkg_conf(arch, cross=True, chroot=chroot_relative)
|
||||
makepkg_conf_path = os.path.join('etc', f'makepkg_cross_{arch}.conf')
|
||||
with open(os.path.join(native_chroot, makepkg_conf_path), 'w') as f:
|
||||
f.write(makepkg_cross_conf)
|
||||
write_cross_makepkg_conf(native_chroot=native_chroot, arch=arch, target_chroot_relative=chroot_relative)
|
||||
os.makedirs(chroot_mount_path)
|
||||
mount(target_chroot, chroot_mount_path)
|
||||
else:
|
||||
|
@ -500,7 +500,7 @@ def cmd_build(paths: list[str], force=False, arch=None):
|
|||
for packages in package_levels:
|
||||
level = set[Package]()
|
||||
for package in packages:
|
||||
if ((not check_package_version_built(package)) or set.intersection(set(package.depends), set(build_names)) or
|
||||
if ((not check_package_version_built(package, arch)) or set.intersection(set(package.depends), set(build_names)) or
|
||||
(force and package.path in paths)):
|
||||
level.add(package)
|
||||
build_names.update(package.names)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue