config: introduce per-arch persisted ccache dir

This commit is contained in:
InsanePrawn 2022-08-29 04:21:37 +02:00
parent c0fd1f51b5
commit 47e74fb415
4 changed files with 17 additions and 1 deletions

View file

@ -132,6 +132,16 @@ class BuildChroot(Chroot):
fail_if_mounted=fail_if_mounted,
)
def mount_ccache(self, user: str = 'kupfer', fail_if_mounted: bool = False):
mount_source = os.path.join(config.file.paths.ccache, self.arch)
mount_dest = os.path.join(f'/home/{user}' if user != 'root' else '/root', '.ccache')
makedir(mount_source)
return self.mount(
absolute_source=mount_source,
relative_destination=mount_dest,
fail_if_mounted=fail_if_mounted,
)
def get_build_chroot(arch: Arch, add_kupfer_repos: bool = True, **kwargs) -> BuildChroot:
name = build_chroot_name(arch)

View file

@ -141,6 +141,7 @@ class PathsSection(DataClass):
pkgbuilds: str
jumpdrive: str
images: str
ccache: str
class ProfilesSection(DataClass):

View file

@ -42,6 +42,7 @@ CONFIG_DEFAULTS_DICT = {
'pkgbuilds': os.path.join('%cache_dir%', 'pkgbuilds'),
'jumpdrive': os.path.join('%cache_dir%', 'jumpdrive'),
'images': os.path.join('%cache_dir%', 'images'),
'ccache': os.path.join('%cache_dir%', 'ccache'),
},
'profiles': {
'current': 'default',

View file

@ -454,6 +454,7 @@ def build_package(
enable_crossdirect: bool = True,
enable_ccache: bool = True,
clean_chroot: bool = False,
build_user: str = 'kupfer',
):
makepkg_compile_opts = ['--holdver']
makepkg_conf_path = 'etc/makepkg.conf'
@ -482,6 +483,7 @@ def build_package(
env = deepcopy(get_makepkg_env(arch))
if enable_ccache:
env['PATH'] = f"/usr/lib/ccache:{env['PATH']}"
native_chroot.mount_ccache(user=build_user)
logging.info('Setting up dependencies for cross-compilation')
# include crossdirect for ccache symlinks and qemu-user
results = native_chroot.try_install_packages(package.depends + CROSSDIRECT_PKGS + [f"{GCC_HOSTSPECS[native_chroot.arch][arch]}-gcc"])
@ -513,6 +515,8 @@ def build_package(
if failed_deps:
raise Exception(f'Dependencies failed to install: {failed_deps}')
if enable_ccache:
build_root.mount_ccache(user=build_user)
setup_git_insecure_paths(build_root)
makepkg_conf_absolute = os.path.join('/', makepkg_conf_path)
setup_sources(package, build_root, makepkg_conf_path=makepkg_conf_absolute)
@ -523,7 +527,7 @@ def build_package(
build_cmd,
inner_env=env,
cwd=os.path.join(CHROOT_PATHS['pkgbuilds'], package.path),
switch_user='kupfer',
switch_user=build_user,
)
assert isinstance(result, subprocess.CompletedProcess)
if result.returncode != 0: