packages/build: split out init_local_repo() from init_prebuilts(), use in add_file_to_repo()
This commit is contained in:
parent
bf420a73be
commit
57fec8fd91
1 changed files with 35 additions and 24 deletions
|
@ -14,7 +14,7 @@ from binfmt import register as binfmt_register, QEMU_ARCHES
|
||||||
from constants import REPOSITORIES, CROSSDIRECT_PKGS, QEMU_BINFMT_PKGS, GCC_HOSTSPECS, ARCHES, Arch, CHROOT_PATHS, MAKEPKG_CMD
|
from constants import REPOSITORIES, CROSSDIRECT_PKGS, QEMU_BINFMT_PKGS, GCC_HOSTSPECS, ARCHES, Arch, CHROOT_PATHS, MAKEPKG_CMD
|
||||||
from config import config
|
from config import config
|
||||||
from exec.cmd import run_cmd, run_root_cmd
|
from exec.cmd import run_cmd, run_root_cmd
|
||||||
from exec.file import makedir, remove_file
|
from exec.file import makedir, remove_file, symlink
|
||||||
from chroot.build import get_build_chroot, BuildChroot
|
from chroot.build import get_build_chroot, BuildChroot
|
||||||
from distro.distro import BinaryPackage, get_kupfer_https, get_kupfer_local
|
from distro.distro import BinaryPackage, get_kupfer_https, get_kupfer_local
|
||||||
from wrapper import check_programs_wrap, wrap_if_foreign_arch
|
from wrapper import check_programs_wrap, wrap_if_foreign_arch
|
||||||
|
@ -46,31 +46,42 @@ def get_makepkg_env(arch: Optional[Arch] = None):
|
||||||
return env
|
return env
|
||||||
|
|
||||||
|
|
||||||
def init_prebuilts(arch: Arch, dir: str = None):
|
def init_local_repo(repo: str, arch: Arch):
|
||||||
"""Ensure that all `constants.REPOSITORIES` inside `dir` exist"""
|
repo_dir = os.path.join(config.get_package_dir(arch), repo)
|
||||||
prebuilts_dir = dir or config.get_package_dir(arch)
|
|
||||||
makedir(prebuilts_dir)
|
|
||||||
for repo in REPOSITORIES:
|
|
||||||
repo_dir = os.path.join(prebuilts_dir, repo)
|
|
||||||
if not os.path.exists(repo_dir):
|
if not os.path.exists(repo_dir):
|
||||||
logging.info(f"Creating local repo {repo} ({arch})")
|
logging.info(f"Creating local repo {repo} ({arch})")
|
||||||
makedir(repo_dir)
|
makedir(repo_dir)
|
||||||
for ext1 in ['db', 'files']:
|
for ext in ['db', 'files']:
|
||||||
for ext2 in ['', '.tar.xz']:
|
filename_stripped = f'{repo}.{ext}'
|
||||||
if not os.path.exists(os.path.join(prebuilts_dir, repo, f'{repo}.{ext1}{ext2}')):
|
filename = f'{filename_stripped}.tar.xz'
|
||||||
|
if not os.path.exists(os.path.join(repo_dir, filename)):
|
||||||
|
logging.info(f"Initialising local repo {f'{ext} ' if ext != 'db' else ''}db for repo {repo} ({arch})")
|
||||||
result = run_cmd(
|
result = run_cmd(
|
||||||
[
|
[
|
||||||
'tar',
|
'tar',
|
||||||
'-czf',
|
'-czf',
|
||||||
f'{repo}.{ext1}{ext2}',
|
filename,
|
||||||
'-T',
|
'-T',
|
||||||
'/dev/null',
|
'/dev/null',
|
||||||
],
|
],
|
||||||
cwd=os.path.join(prebuilts_dir, repo),
|
cwd=os.path.join(repo_dir),
|
||||||
)
|
)
|
||||||
assert isinstance(result, subprocess.CompletedProcess)
|
assert isinstance(result, subprocess.CompletedProcess)
|
||||||
if result.returncode != 0:
|
if result.returncode != 0:
|
||||||
raise Exception(f'Failed to create local repo {repo}')
|
raise Exception(f'Failed to create local repo {repo}')
|
||||||
|
symlink_path = os.path.join(repo_dir, filename_stripped)
|
||||||
|
if not os.path.islink(symlink_path):
|
||||||
|
if os.path.exists(symlink_path):
|
||||||
|
remove_file(symlink_path)
|
||||||
|
symlink(filename, symlink_path)
|
||||||
|
|
||||||
|
|
||||||
|
def init_prebuilts(arch: Arch):
|
||||||
|
"""Ensure that all `constants.REPOSITORIES` inside `dir` exist"""
|
||||||
|
prebuilts_dir = config.get_path('packages')
|
||||||
|
makedir(prebuilts_dir)
|
||||||
|
for repo in REPOSITORIES:
|
||||||
|
init_local_repo(repo, arch)
|
||||||
|
|
||||||
|
|
||||||
def generate_dependency_chain(package_repo: dict[str, Pkgbuild], to_build: Iterable[Pkgbuild]) -> list[set[Pkgbuild]]:
|
def generate_dependency_chain(package_repo: dict[str, Pkgbuild], to_build: Iterable[Pkgbuild]) -> list[set[Pkgbuild]]:
|
||||||
|
@ -189,7 +200,7 @@ def add_file_to_repo(file_path: str, repo_name: str, arch: Arch):
|
||||||
file_name = os.path.basename(file_path)
|
file_name = os.path.basename(file_path)
|
||||||
target_file = os.path.join(repo_dir, file_name)
|
target_file = os.path.join(repo_dir, file_name)
|
||||||
|
|
||||||
makedir(repo_dir)
|
init_local_repo(repo_name, arch)
|
||||||
if file_path != target_file:
|
if file_path != target_file:
|
||||||
logging.debug(f'moving {file_path} to {target_file} ({repo_dir})')
|
logging.debug(f'moving {file_path} to {target_file} ({repo_dir})')
|
||||||
shutil.copy(
|
shutil.copy(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue