From b1649899a2d392bd0a4c3a629614d29aafd73bb9 Mon Sep 17 00:00:00 2001 From: Xavier Claessens Date: Fri, 3 Jun 2022 13:44:56 -0400 Subject: [PATCH] ExternalProgram: Make get_version() work without interpreter --- mesonbuild/programs.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/mesonbuild/programs.py b/mesonbuild/programs.py index 192c27375..458fabac9 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}')