diff options
| author | Patrick Steinhardt <ps@pks.im> | 2025-01-03 15:33:57 +0100 |
|---|---|---|
| committer | Jussi Pakkanen <jpakkane@gmail.com> | 2025-01-08 16:41:31 +0200 |
| commit | a3679a64eec7c312c81d657880f34f015426c7db (patch) | |
| tree | a4cf78de7590a77f8735f07b30cda5fbbe29bb7f /mesonbuild/programs.py | |
| parent | 3b28fbf0d97b53d831c01dfe98634cff3dc8a9ec (diff) | |
| download | meson-a3679a64eec7c312c81d657880f34f015426c7db.tar.gz | |
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 <ps@pks.im>
Diffstat (limited to 'mesonbuild/programs.py')
| -rw-r--r-- | mesonbuild/programs.py | 5 |
1 files changed, 4 insertions, 1 deletions
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) |
