mirror of
https://github.com/mesonbuild/meson.git
synced 2026-11-06 05:16:42 +00:00
search_version: make version regex accept more after hyphen
This change allows the found version number to include additional hyphens and periods after the first hyphen. This is needed to understand `clang --version` in some older Ubuntu versions, which prints: Ubuntu clang version 14.0.0-1ubuntu1.1 This logic also accepts any pre-release version following SemVer 2.0.0 syntax, bullet 9. Fixes: https://github.com/mesonbuild/meson/issues/16286 Signed-off-by: Jonathon Anderson <anderson.jonathonm@gmail.com>
This commit is contained in:
1 parent
0dc920ffc0
commit
70659de447
2 files changed
+10
-1
No files matched your search
@@ -1238,7 +1238,11 @@ def search_version(text: str) -> str:
|
||||
\.\d+ # Period and one or more digits
|
||||
)+ # One or more occurrences
|
||||
(
|
||||
-[a-zA-Z0-9]+ # Hyphen and one or more alphanumeric
|
||||
- # Hyphen
|
||||
[0-9a-zA-Z-]+ # One or more alphanumeric/hyphen
|
||||
(
|
||||
\.[0-9a-zA-Z-]+ # Period and one or more alphanumeric/hyphen
|
||||
)* # Zero or more occurrences
|
||||
)? # Zero or one occurrence
|
||||
)
|
||||
(?!\S) # Must not be followed by non-space char
|
||||
|
||||
@@ -195,6 +195,7 @@ class InternalTests(unittest.TestCase):
|
||||
|
||||
def test_version_number(self):
|
||||
self.assertEqual(search_version('foobar 1.2.3'), '1.2.3')
|
||||
self.assertEqual(search_version('foobar 1.2.3-4and5.6-7-'), '1.2.3-4and5.6-7-')
|
||||
self.assertEqual(search_version('1.2.3'), '1.2.3')
|
||||
self.assertEqual(search_version('foobar 2016.10.28 1.2.3'), '1.2.3')
|
||||
self.assertEqual(search_version('2016.10.28 1.2.3'), '1.2.3')
|
||||
@@ -210,6 +211,10 @@ class InternalTests(unittest.TestCase):
|
||||
self.assertEqual(search_version(r'''(FooBar LLVM-Linux 5.0.0) clang version 21.9.0
|
||||
Target: riscv64-unknown-linux-gnu
|
||||
Thread model: posix'''), '21.9.0')
|
||||
self.assertEqual(search_version(r'''Ubuntu clang version 14.0.0-1ubuntu1.1
|
||||
Target: x86_64-pc-linux-gnu
|
||||
Thread model: posix
|
||||
InstalledDir: /usr/bin'''), '14.0.0-1ubuntu1.1')
|
||||
|
||||
# Literal output of mvn
|
||||
self.assertEqual(search_version(r'''\
|
||||
|
||||
Reference in new issue
Block a user