diff options
author | Xavier Claessens <xavier.claessens@collabora.com> | 2023-09-04 08:49:39 -0400 |
---|---|---|
committer | Nirbheek Chauhan <nirbheek.chauhan@gmail.com> | 2023-09-05 09:05:24 +0530 |
commit | fe9af72684f85d709ce45096534aa51854a6da9b (patch) | |
tree | 0b41f1df5e985a9943bc7f3d321f47786a7e9291 /mesonbuild/wrap | |
parent | f07476a89677f5c87a62b6756b76a0e8ebc4bceb (diff) | |
download | meson-fe9af72684f85d709ce45096534aa51854a6da9b.zip meson-fe9af72684f85d709ce45096534aa51854a6da9b.tar.gz meson-fe9af72684f85d709ce45096534aa51854a6da9b.tar.bz2 |
wrap: Use MESON_PACKAGE_CACHE_DIR as default packagecache path
Allow packagecache to contain already extracted directory to match what
some distro does with Cargo source packages in /usr/share/cargo/registry.
Note that there is no need to lock the cache directory because we
download into a temporary name and atomically rename afterward. It means
we could be downloading the same file twice, but at least integrity is
guaranteed.
Fixes: #12211
Diffstat (limited to 'mesonbuild/wrap')
-rw-r--r-- | mesonbuild/wrap/wrap.py | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/mesonbuild/wrap/wrap.py b/mesonbuild/wrap/wrap.py index c857050..941da3d 100644 --- a/mesonbuild/wrap/wrap.py +++ b/mesonbuild/wrap/wrap.py @@ -289,7 +289,7 @@ class Resolver: def __post_init__(self) -> None: self.subdir_root = os.path.join(self.source_dir, self.subdir) - self.cachedir = os.path.join(self.subdir_root, 'packagecache') + self.cachedir = os.environ.get('MESON_PACKAGE_CACHE_DIR') or os.path.join(self.subdir_root, 'packagecache') self.wraps: T.Dict[str, PackageDefinition] = {} self.netrc: T.Optional[netrc] = None self.provided_deps: T.Dict[str, PackageDefinition] = {} @@ -462,7 +462,17 @@ class Resolver: if not os.path.isdir(self.dirname): raise WrapException('Path already exists but is not a directory') else: - if self.wrap.type == 'file': + # Check first if we have the extracted directory in our cache. This can + # happen for example when MESON_PACKAGE_CACHE_DIR=/usr/share/cargo/registry + # on distros that ships Rust source code. + # TODO: We don't currently clone git repositories into the cache + # directory, but we should to avoid cloning multiple times the same + # repository. In that case, we could do something smarter than + # copy_tree() here. + cached_directory = os.path.join(self.cachedir, self.directory) + if os.path.isdir(cached_directory): + self.copy_tree(cached_directory, self.dirname) + elif self.wrap.type == 'file': self.get_file() else: self.check_can_download() |