diff --git a/chroot/build.py b/chroot/build.py index 4118957..0dd698f 100644 --- a/chroot/build.py +++ b/chroot/build.py @@ -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) diff --git a/config/scheme.py b/config/scheme.py index 3add208..26a9b6a 100644 --- a/config/scheme.py +++ b/config/scheme.py @@ -141,6 +141,7 @@ class PathsSection(DataClass): pkgbuilds: str jumpdrive: str images: str + ccache: str class ProfilesSection(DataClass): diff --git a/config/state.py b/config/state.py index 0ba9215..0e73831 100644 --- a/config/state.py +++ b/config/state.py @@ -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', diff --git a/packages/__init__.py b/packages/__init__.py index 667d2b6..bc0f99a 100644 --- a/packages/__init__.py +++ b/packages/__init__.py @@ -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: