From 921ddb1980e1a8d08f8706a1556896793dafccbe Mon Sep 17 00:00:00 2001 From: Eli Schwartz Date: Tue, 10 Jan 2023 02:06:16 -0500 Subject: dependencies: fix pcap-config which now errors on --version The latest release of libpcap added argument validation to pcap-config, but still doesn't support --version. The next version of libpcap will support --version. Add support for config-tool dependencies which expect to break on --version, to fallback to an option that does not error out or print version info, for sanity checking. --- mesonbuild/dependencies/configtool.py | 12 +++++++++++- mesonbuild/dependencies/misc.py | 8 +++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/mesonbuild/dependencies/configtool.py b/mesonbuild/dependencies/configtool.py index 8b7f1bb..1c8d730 100644 --- a/mesonbuild/dependencies/configtool.py +++ b/mesonbuild/dependencies/configtool.py @@ -31,6 +31,9 @@ class ConfigToolDependency(ExternalDependency): 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 + :skip_version str: The argument to pass to the tool to ignore its version + (if ``version_arg`` fails, but it may start accepting it in the future) + Because some tools are stupid and don't accept --version :returncode_value int: The value of the correct returncode Because some tools are stupid and don't return 0 """ @@ -38,6 +41,7 @@ class ConfigToolDependency(ExternalDependency): tools: T.Optional[T.List[str]] = None tool_name: T.Optional[str] = None version_arg = '--version' + skip_version: T.Optional[str] = None __strip_version = re.compile(r'^[0-9][0-9.]+') def __init__(self, name: str, environment: 'Environment', kwargs: T.Dict[str, T.Any], language: T.Optional[str] = None): @@ -89,7 +93,13 @@ class ConfigToolDependency(ExternalDependency): except (FileNotFoundError, PermissionError): continue if p.returncode != returncode: - continue + if self.skip_version: + # maybe the executable is valid even if it doesn't support --version + p = Popen_safe(tool + [self.skip_version])[0] + if p.returncode != returncode: + continue + else: + continue out = self._sanitize_version(out.strip()) # Some tools, like pcap-config don't supply a version, but also diff --git a/mesonbuild/dependencies/misc.py b/mesonbuild/dependencies/misc.py index d23eeee..07f4e9a 100644 --- a/mesonbuild/dependencies/misc.py +++ b/mesonbuild/dependencies/misc.py @@ -293,13 +293,19 @@ class PcapDependencyConfigTool(ConfigToolDependency): tools = ['pcap-config'] tool_name = 'pcap-config' + # version 1.10.2 added error checking for invalid arguments + # version 1.10.3 will hopefully add actual support for --version + skip_version = '--help' + def __init__(self, name: str, environment: 'Environment', kwargs: T.Dict[str, T.Any]): super().__init__(name, environment, kwargs) if not self.is_found: return self.compile_args = self.get_config_value(['--cflags'], 'compile_args') self.link_args = self.get_config_value(['--libs'], 'link_args') - self.version = self.get_pcap_lib_version() + if self.version is None: + # older pcap-config versions don't support this + self.version = self.get_pcap_lib_version() def get_pcap_lib_version(self) -> T.Optional[str]: # Since we seem to need to run a program to discover the pcap version, -- cgit v1.1