find_program: add a version() method to match the one for dependencies · mesonbuild/meson@0f2f87a (original) (raw)
File tree
4 files changed
lines changed
- test cases/common/26 find program
4 files changed
lines changed
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
1 | +## found programs now have a version method | |
2 | + | |
3 | +The return value of [[find_program]] can now check the exact version of the | |
4 | +found program, independent of the minimum version requirement. This can be used | |
5 | +e.g. to perform different actions depending on the exact version detected. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -24,6 +24,14 @@ methods: | ||
24 | 24 | run_command(find_program('foo'), 'arg1', 'arg2') |
25 | 25 | ``` |
26 | 26 | |
27 | +- name: version | |
28 | +returns: str | |
29 | +since: 0.62.0 | |
30 | +description: | | |
31 | + The version number as a string, for example `1.2.8`. | |
32 | + | |
33 | + `unknown` if the program cannot determine the version via a `--version` argument. | |
34 | + | |
27 | 35 | - name: full_path |
28 | 36 | returns: str |
29 | 37 | since: 0.55.0 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -516,6 +516,7 @@ def __init__(self, ep: ExternalProgram, interpreter: 'Interpreter') -> None: | ||
516 | 516 | super().__init__(ep, interpreter) |
517 | 517 | self.methods.update({'found': self.found_method, |
518 | 518 | 'path': self.path_method, |
519 | +'version': self.version_method, | |
519 | 520 | 'full_path': self.full_path_method}) |
520 | 521 | |
521 | 522 | @noPosargs |
@@ -543,6 +544,17 @@ def _full_path(self) -> str: | ||
543 | 544 | assert path is not None |
544 | 545 | return path |
545 | 546 | |
547 | +@noPosargs | |
548 | +@noKwargs | |
549 | +@FeatureNew('ExternalProgram.version', '0.62.0') | |
550 | +def version_method(self, args: T.List[TYPE_var], kwargs: TYPE_kwargs) -> str: | |
551 | +if not self.found(): | |
552 | +raise InterpreterException('Unable to get the version of a not-found external program') | |
553 | +try: | |
554 | +return self.held_object.get_version(self.interpreter) | |
555 | +except MesonException: | |
556 | +return 'unknown' | |
557 | + | |
546 | 558 | def found(self) -> bool: |
547 | 559 | return self.held_object.found() |
548 | 560 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -25,6 +25,9 @@ assert(not prog.found(), 'Version should be too old') | ||
25 | 25 | prog = find_program('print-version.py', version : '>=1.0') |
26 | 26 | assert(prog.found(), 'Program version should match') |
27 | 27 | |
28 | +prog = find_program('print-version.py') | |
29 | +assert(prog.version() == '1.0', 'Program version should be detectable') | |
30 | + | |
28 | 31 | prog = find_program('print-version-with-prefix.py', version : '>=1.0') |
29 | 32 | assert(prog.found(), 'Program version should match') |
30 | 33 |