aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/wrap/wrap.py
diff options
context:
space:
mode:
authorDaniel Mensinger <daniel@mensinger-ka.de>2020-03-21 11:51:02 +0100
committerDaniel Mensinger <daniel@mensinger-ka.de>2020-04-25 11:43:42 +0200
commitccdf7f6d34fbcf172ad5362a6ce2959f07d0e1bd (patch)
tree8240592c978bba66142e3a3269085f90adaecc1a /mesonbuild/wrap/wrap.py
parent7c68fe80083fd72a100998578417b223e3704af5 (diff)
downloadmeson-ccdf7f6d34fbcf172ad5362a6ce2959f07d0e1bd.zip
meson-ccdf7f6d34fbcf172ad5362a6ce2959f07d0e1bd.tar.gz
meson-ccdf7f6d34fbcf172ad5362a6ce2959f07d0e1bd.tar.bz2
wrap: Add support for local files via only `*_filename`
Diffstat (limited to 'mesonbuild/wrap/wrap.py')
-rw-r--r--mesonbuild/wrap/wrap.py38
1 files changed, 27 insertions, 11 deletions
diff --git a/mesonbuild/wrap/wrap.py b/mesonbuild/wrap/wrap.py
index 1715cd3..9d95bff 100644
--- a/mesonbuild/wrap/wrap.py
+++ b/mesonbuild/wrap/wrap.py
@@ -27,6 +27,7 @@ import sys
import configparser
import typing as T
+from pathlib import Path
from . import WrapMode
from ..mesonlib import git, GIT, ProgressBar, MesonException
@@ -126,7 +127,7 @@ class PackageDefinition:
raise WrapException(m.format(key, self.basename))
def has_patch(self) -> bool:
- return 'patch_url' in self.values
+ return 'patch_filename' in self.values
def load_wrap(subdir_root: str, packagename: str) -> PackageDefinition:
fname = os.path.join(subdir_root, packagename + '.wrap')
@@ -146,10 +147,12 @@ def get_directory(subdir_root: str, packagename: str):
return wrap, directory
class Resolver:
- def __init__(self, subdir_root: str, wrap_mode=WrapMode.default):
+ def __init__(self, subdir_root: str, wrap_mode=WrapMode.default, current_subproject: str = ''):
self.wrap_mode = wrap_mode
self.subdir_root = subdir_root
+ self.current_subproject = current_subproject
self.cachedir = os.path.join(self.subdir_root, 'packagecache')
+ self.filesdir = os.path.join(self.subdir_root, 'packagefiles')
def resolve(self, packagename: str, method: str) -> str:
self.packagename = packagename
@@ -363,7 +366,9 @@ class Resolver:
hashvalue = h.hexdigest()
return hashvalue, tmpfile.name
- def check_hash(self, what: str, path: str) -> None:
+ def check_hash(self, what: str, path: str, hash_required: bool = True) -> None:
+ if what + '_hash' not in self.wrap.values and not hash_required:
+ return
expected = self.wrap.get(what + '_hash')
h = hashlib.sha256()
with open(path, 'rb') as f:
@@ -393,17 +398,28 @@ class Resolver:
def get_file_internal(self, what: str) -> str:
filename = self.wrap.get(what + '_filename')
- cache_path = os.path.join(self.cachedir, filename)
+ if what + '_url' in self.wrap.values:
+ cache_path = os.path.join(self.cachedir, filename)
- if os.path.exists(cache_path):
- self.check_hash(what, cache_path)
- mlog.log('Using', mlog.bold(self.packagename), what, 'from cache.')
+ if os.path.exists(cache_path):
+ self.check_hash(what, cache_path)
+ mlog.log('Using', mlog.bold(self.packagename), what, 'from cache.')
+ return cache_path
+
+ if not os.path.isdir(self.cachedir):
+ os.mkdir(self.cachedir)
+ self.download(what, cache_path)
return cache_path
+ else:
+ from ..interpreterbase import FeatureNew
+ FeatureNew('Local wrap patch files without {}_url'.format(what), '0.55.0').use(self.current_subproject)
+ path = Path(self.filesdir) / filename
+
+ if not path.exists():
+ raise WrapException('File "{}" does not exist'.format(path))
+ self.check_hash(what, path.as_posix(), hash_required=False)
- if not os.path.isdir(self.cachedir):
- os.mkdir(self.cachedir)
- self.download(what, cache_path)
- return cache_path
+ return path.as_posix()
def apply_patch(self) -> None:
path = self.get_file_internal('patch')