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).
This commit is contained in:
parent
e83fb35e41
commit
d889989ea1
|
@ -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.
|
||||
|
|
|
@ -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-<very short sha>"
|
||||
# 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)
|
||||
|
|
Loading…
Reference in New Issue