mirror of
https://github.com/mesonbuild/meson.git
synced 2026-11-06 05:16:42 +00:00
allow to compare multiple version with version_compare
This commit is contained in:
1 parent
aecff97e18
commit
6ee583e119
7 files changed
+28
-7
No files matched your search
@@ -0,0 +1,8 @@
|
||||
## `version_compare` now accept multiple compare strings
|
||||
|
||||
Is it now possible to compare version against multiple values, to check for
|
||||
a range of version for instance.
|
||||
|
||||
```meson
|
||||
'1.5'.version_compare('>=1', '<2')
|
||||
```
|
||||
@@ -306,6 +306,12 @@ methods:
|
||||
|
||||
It is best to be unambiguous and specify the full revision level to compare.
|
||||
|
||||
*Since 1.8.0* multiple versions can be compared:
|
||||
|
||||
```meson
|
||||
'3.6'.version_compare('>=3', '<4.0') == true
|
||||
```
|
||||
|
||||
posargs:
|
||||
compare_string:
|
||||
type: str
|
||||
|
||||
@@ -7,7 +7,7 @@ import os
|
||||
|
||||
import typing as T
|
||||
|
||||
from ...mesonlib import version_compare
|
||||
from ...mesonlib import version_compare, version_compare_many
|
||||
from ...interpreterbase import (
|
||||
ObjectHolder,
|
||||
MesonOperator,
|
||||
@@ -169,9 +169,11 @@ class StringHolder(ObjectHolder[str]):
|
||||
return re.sub(r'[^a-zA-Z0-9]', '_', self.held_object)
|
||||
|
||||
@noKwargs
|
||||
@typed_pos_args('str.version_compare', str)
|
||||
def version_compare_method(self, args: T.Tuple[str], kwargs: TYPE_kwargs) -> bool:
|
||||
return version_compare(self.held_object, args[0])
|
||||
@typed_pos_args('str.version_compare', varargs=str, min_varargs=1)
|
||||
def version_compare_method(self, args: T.Tuple[T.List[str]], kwargs: TYPE_kwargs) -> bool:
|
||||
if len(args[0]) > 1:
|
||||
FeatureNew.single_use('version_compare() with multiple arguments', '1.8.0', self.subproject, location=self.current_node)
|
||||
return version_compare_many(self.held_object, args[0])[0]
|
||||
|
||||
@staticmethod
|
||||
def _op_div(this: str, other: str) -> str:
|
||||
|
||||
@@ -79,6 +79,11 @@ assert(not version_number.version_compare('!=1.2.8'), 'Version_compare neq broke
|
||||
assert(version_number.version_compare('<2.0'), 'Version_compare major less broken')
|
||||
assert(version_number.version_compare('>0.9'), 'Version_compare major greater broken')
|
||||
|
||||
assert(version_number.version_compare('>1.2', '<1.3'))
|
||||
assert(not version_number.version_compare('>1.2', '>1.3'))
|
||||
assert(not version_number.version_compare('<1.2', '<1.3'))
|
||||
assert(version_number.version_compare('>1.0', '>1.2'))
|
||||
|
||||
assert(' spaces tabs '.strip() == 'spaces tabs', 'Spaces and tabs badly stripped')
|
||||
assert('''
|
||||
multiline string '''.strip() == '''multiline string''', 'Newlines badly stripped')
|
||||
|
||||
@@ -6,7 +6,7 @@ if not dub_exe.found()
|
||||
endif
|
||||
|
||||
dub_ver = dub_exe.version()
|
||||
if dub_ver.version_compare('>1.31.1') and dub_ver.version_compare('<1.35.0')
|
||||
if dub_ver.version_compare('>1.31.1', '<1.35.0')
|
||||
error('MESON_SKIP_TEST: Incompatible Dub version ' + dub_ver)
|
||||
endif
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ if not dub_exe.found()
|
||||
endif
|
||||
|
||||
dub_ver = dub_exe.version()
|
||||
if dub_ver.version_compare('>1.31.1') and dub_ver.version_compare('<1.35.0')
|
||||
if dub_ver.version_compare('>1.31.1', '<1.35.0')
|
||||
error('MESON_SKIP_TEST: Incompatible Dub version')
|
||||
endif
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ sdk_args = ['-isysroot', '/Applications/Xcode.app/Contents/Developer/Platforms/M
|
||||
args_10_12 = ['-mmacosx-version-min=10.13'] + sdk_args
|
||||
|
||||
# Test requires XCode 8 which has the MacOSX 10.12 SDK
|
||||
if cc.version().version_compare('>=8.0') and cc.version().version_compare('<8.1')
|
||||
if cc.version().version_compare('>=8.0', '<8.1')
|
||||
if cc.has_function('clock_gettime', args : args_10_11, prefix : '#include <time.h>')
|
||||
error('Should not have found clock_gettime via <time.h> when targeting Mac OS X 10.11')
|
||||
endif
|
||||
|
||||
Reference in new issue
Block a user