diff options
-rw-r--r-- | mesonbuild/dependencies/base.py | 23 | ||||
-rw-r--r-- | mesonbuild/dependencies/ui.py | 4 |
2 files changed, 20 insertions, 7 deletions
diff --git a/mesonbuild/dependencies/base.py b/mesonbuild/dependencies/base.py index b347a6a..f03af12 100644 --- a/mesonbuild/dependencies/base.py +++ b/mesonbuild/dependencies/base.py @@ -384,19 +384,32 @@ class NotFoundDependency(Dependency): class ConfigToolDependency(ExternalDependency): - """Class representing dependencies found using a config tool.""" + """Class representing dependencies found using a config tool. + + Takes the following extra keys in kwargs that it uses internally: + :tools List[str]: A list of tool names to use + :version_arg str: The argument to pass to the tool to get it's version + :returncode_value int: The value of the correct returncode + Because some tools are stupid and don't return 0 + """ tools = None tool_name = None + version_arg = '--version' __strip_version = re.compile(r'^[0-9][0-9.]+') def __init__(self, name, environment, kwargs, language: T.Optional[str] = None): super().__init__('config-tool', environment, kwargs, language=language) self.name = name + # You may want to overwrite the class version in some cases self.tools = listify(kwargs.get('tools', self.tools)) + if not self.tool_name: + self.tool_name = self.tools[0] + if 'version_arg' in kwargs: + self.version_arg = kwargs['version_arg'] req_version = kwargs.get('version', None) - tool, version = self.find_config(req_version) + tool, version = self.find_config(req_version, kwargs.get('returncode_value', 0)) self.config = tool self.is_found = self.report_config(version, req_version) if not self.is_found: @@ -415,7 +428,7 @@ class ConfigToolDependency(ExternalDependency): return m.group(0).rstrip('.') return version - def find_config(self, versions=None): + def find_config(self, versions=None, returncode: int = 0): """Helper method that searches for config tool binaries in PATH and returns the one that best matches the given version requirements. """ @@ -444,10 +457,10 @@ class ConfigToolDependency(ExternalDependency): continue tool = potential_bin.get_command() try: - p, out = Popen_safe(tool + ['--version'])[:2] + p, out = Popen_safe(tool + [self.version_arg])[:2] except (FileNotFoundError, PermissionError): continue - if p.returncode != 0: + if p.returncode != returncode: continue out = self._sanitize_version(out.strip()) diff --git a/mesonbuild/dependencies/ui.py b/mesonbuild/dependencies/ui.py index 31f02e5..1cadeb0 100644 --- a/mesonbuild/dependencies/ui.py +++ b/mesonbuild/dependencies/ui.py @@ -79,13 +79,13 @@ class GnuStepDependency(ConfigToolDependency): ['--gui-libs' if 'gui' in self.modules else '--base-libs'], 'link_args')) - def find_config(self, versions=None): + def find_config(self, versions=None, returncode: int = 0): tool = [self.tools[0]] try: p, out = Popen_safe(tool + ['--help'])[:2] except (FileNotFoundError, PermissionError): return (None, None) - if p.returncode != 0: + if p.returncode != returncode: return (None, None) self.config = tool found_version = self.detect_version() |