From a3679a64eec7c312c81d657880f34f015426c7db Mon Sep 17 00:00:00 2001 From: Patrick Steinhardt Date: Fri, 3 Jan 2025 15:33:57 +0100 Subject: programs: favor version numbers with dots When using `find_program('perl')` we misdetect its version number: Program perl found: YES 40 40 (/usr/bin/perl) This is caused by Perl outputting the version information in a somewhat weird format: $ perl --version This is perl 5, version 40, subversion 0 (v5.40.0) built for x86_64-linux-thread-multi ... The problem here is that our version number detection picks the first match of at one digit followed by at least one more digit and/or dot. Consequently, as "40" matches that regular expression, we'd return its value as the version number. Naturally, the version number detection we perform is best-effort, only, as there is no standardized format used by all programs. That being said, we can do better here by first trying to match a dotted version number so that we'd match the "5.40.0" string, not the "40". And given that most projects use dotted version numbers this should be a strict improvement in cases where we have multiple digits in-text. The old behaviour continues to be used as a fallback though in case we weren't able to match anything to not regress functionality. The new regex also fixes another case: when the version information ends with a trailing dot, like "foo version 1.2.3.", then we'd also have matched that trailing dot. This can be for example the case when version numbers end with ".rc1" or something similar. While we'd ideally include such suffixes into the detected version, that issue is left for another day. Add a couple of tests. Signed-off-by: Patrick Steinhardt --- mesonbuild/programs.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'mesonbuild/programs.py') diff --git a/mesonbuild/programs.py b/mesonbuild/programs.py index 46d00ceca..7f4cec52d 100644 --- a/mesonbuild/programs.py +++ b/mesonbuild/programs.py @@ -122,7 +122,10 @@ class ExternalProgram(mesonlib.HoldableObject): output = o.strip() if not output: output = e.strip() - match = re.search(r'([0-9][0-9\.]+)', output) + + match = re.search(r'([0-9](\.[0-9]+)+)', output) + if not match: + match = re.search(r'([0-9][0-9\.]+)', output) if not match: raise mesonlib.MesonException(f'Could not find a version number in output of {raw_cmd!r}') self.cached_version = match.group(1) -- cgit v1.2.3