summaryrefslogtreecommitdiff
path: root/mesonbuild
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
parent7c68fe80083fd72a100998578417b223e3704af5 (diff)
downloadmeson-ccdf7f6d34fbcf172ad5362a6ce2959f07d0e1bd.tar.gz
wrap: Add support for local files via only `*_filename`
Diffstat (limited to 'mesonbuild')
-rw-r--r--mesonbuild/interpreter.py2
-rw-r--r--mesonbuild/wrap/wrap.py38
2 files changed, 28 insertions, 12 deletions
diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py
index 48b6bd6e9..0303e6a18 100644
--- a/mesonbuild/interpreter.py
+++ b/mesonbuild/interpreter.py
@@ -2675,7 +2675,7 @@ external dependencies (including libraries) must go to "dependencies".''')
return subproject
subproject_dir_abs = os.path.join(self.environment.get_source_dir(), self.subproject_dir)
- r = wrap.Resolver(subproject_dir_abs, self.coredata.get_builtin_option('wrap_mode'))
+ r = wrap.Resolver(subproject_dir_abs, self.coredata.get_builtin_option('wrap_mode'), current_subproject=self.subproject)
try:
resolved = r.resolve(dirname, method)
except wrap.WrapException as e:
diff --git a/mesonbuild/wrap/wrap.py b/mesonbuild/wrap/wrap.py
index 1715cd317..9d95bff6a 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')