aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/programs.py
diff options
context:
space:
mode:
authorXavier Claessens <xavier.claessens@collabora.com>2022-06-03 13:44:56 -0400
committerXavier Claessens <xclaesse@gmail.com>2022-06-17 11:53:38 -0400
commitb1649899a2d392bd0a4c3a629614d29aafd73bb9 (patch)
tree9d22337bee9b3f3d9c986d6cd7caed27c3e9b5f0 /mesonbuild/programs.py
parent41860f686f7b3111676f651ea70a59674ca71e48 (diff)
downloadmeson-b1649899a2d392bd0a4c3a629614d29aafd73bb9.zip
meson-b1649899a2d392bd0a4c3a629614d29aafd73bb9.tar.gz
meson-b1649899a2d392bd0a4c3a629614d29aafd73bb9.tar.bz2
ExternalProgram: Make get_version() work without interpreter
Diffstat (limited to 'mesonbuild/programs.py')
-rw-r--r--mesonbuild/programs.py21
1 files changed, 15 insertions, 6 deletions
diff --git a/mesonbuild/programs.py b/mesonbuild/programs.py
index 192c273..458faba 100644
--- a/mesonbuild/programs.py
+++ b/mesonbuild/programs.py
@@ -100,16 +100,25 @@ class ExternalProgram(mesonlib.HoldableObject):
'''Human friendly description of the command'''
return ' '.join(self.command)
- def get_version(self, interpreter: 'Interpreter') -> str:
+ def get_version(self, interpreter: T.Optional['Interpreter'] = None) -> str:
if not self.cached_version:
from . import build
raw_cmd = self.get_command() + ['--version']
- res = interpreter.run_command_impl(interpreter.current_node, (self, ['--version']),
- {'capture': True, 'check': True, 'env': build.EnvironmentVariables()},
- True)
- output = res.stdout.strip()
+ if interpreter:
+ res = interpreter.run_command_impl(interpreter.current_node, (self, ['--version']),
+ {'capture': True,
+ 'check': True,
+ 'env': build.EnvironmentVariables()},
+ True)
+ o, e = res.stdout, res.stderr
+ else:
+ p, o, e = mesonlib.Popen_safe(raw_cmd)
+ if p.returncode != 0:
+ cmd_str = mesonlib.join_args(raw_cmd)
+ raise mesonlib.MesonException(f'Command {cmd_str!r} failed with status {p.returncode}.')
+ output = o.strip()
if not output:
- output = res.stderr.strip()
+ output = e.strip()
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}')