wrap: Add support for local files via only `*_filename`

pull/6818/head
Daniel Mensinger 5 years ago
parent 7c68fe8008
commit ccdf7f6d34
No known key found for this signature in database
GPG Key ID: 54DD94C131E277D4
  1. 2
      mesonbuild/interpreter.py
  2. 38
      mesonbuild/wrap/wrap.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:

@ -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')

Loading…
Cancel
Save