From d889989ea1f858759749aef13c0054e5700aa296 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Thu, 18 Jan 2018 10:59:35 -0800 Subject: dependnecies: generalize version suffix stripping code This replaces calls to .rstrip('git'), .rstrip('svn') with a regex that takes the leading numbers and dots, and throws away the rest. This also moves the code up to the ConfigToolDepdency level, since these config tools are of various quality and some of them are good, and some are not. This shouldn't affect well behaved tools. This should future proof LLVM against future suffixes (like someone doing something strange like using Mercurial as a VCS). --- mesonbuild/dependencies/base.py | 12 +++++++++++- mesonbuild/dependencies/dev.py | 10 ---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/mesonbuild/dependencies/base.py b/mesonbuild/dependencies/base.py index b0dc161..71494c8 100644 --- a/mesonbuild/dependencies/base.py +++ b/mesonbuild/dependencies/base.py @@ -207,6 +207,7 @@ class ConfigToolDependency(ExternalDependency): tools = None tool_name = None + __strip_version = re.compile(r'^[0-9.]*') def __init__(self, name, environment, language, kwargs): super().__init__('config-tool', environment, language, kwargs) @@ -222,6 +223,15 @@ class ConfigToolDependency(ExternalDependency): return self.version = version + def _sanitize_version(self, version): + """Remove any non-numeric, non-point version suffixes.""" + m = self.__strip_version.match(version) + if m: + # Ensure that there isn't a trailing '.', such as an input like + # `1.2.3.git-1234` + return m.group(0).rstrip('.') + return version + @classmethod def factory(cls, name, environment, language, kwargs, tools, tool_name): """Constructor for use in dependencies that can be found multiple ways. @@ -259,7 +269,7 @@ class ConfigToolDependency(ExternalDependency): if p.returncode != 0: continue - out = out.strip() + out = self._sanitize_version(out.strip()) # Some tools, like pcap-config don't supply a version, but also # dont fail with --version, in that case just assume that there is # only one verison and return it. diff --git a/mesonbuild/dependencies/dev.py b/mesonbuild/dependencies/dev.py index 25316df..c254947 100644 --- a/mesonbuild/dependencies/dev.py +++ b/mesonbuild/dependencies/dev.py @@ -146,16 +146,6 @@ class LLVMDependency(ConfigToolDependency): return self.static = kwargs.get('static', False) - # Currently meson doesn't really attempt to handle pre-release versions, - # so strip the 'svn' off the end, since it will probably cuase problems - # for users who want the patch version. - # - # If LLVM is built from svn then "svn" will be appended to the version - # string, if it's built from a git mirror then "git-" - # will be appended instead. - self.version = self.version.rstrip('svn') - self.version = self.version.split('git')[0] - self.provided_modules = self.get_config_value(['--components'], 'modules') modules = stringlistify(extract_as_list(kwargs, 'modules')) self.check_components(modules) -- cgit v1.1