Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow to compare multiple version with version_compare #14105

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions docs/markdown/snippets/multiple_version_compare.md
Original file line number Diff line number Diff line change
@@ -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')
```
6 changes: 6 additions & 0 deletions docs/yaml/elementary/str.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 6 additions & 4 deletions mesonbuild/interpreter/primitives/string.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import typing as T

from ...mesonlib import version_compare
from ...mesonlib import version_compare, version_compare_many
from ...interpreterbase import (
ObjectHolder,
MesonOperator,
Expand Down Expand Up @@ -169,9 +169,11 @@ def underscorify_method(self, args: T.List[TYPE_var], kwargs: TYPE_kwargs) -> st
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:
Expand Down
5 changes: 5 additions & 0 deletions test cases/common/35 string operations/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion test cases/d/11 dub/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion test cases/d/14 dub with deps/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion test cases/osx/3 has function xcode8/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading