diff --git a/docs/yaml/objects/external_program.yaml b/docs/yaml/objects/external_program.yaml index 4c24497a9f15..a2cdb873270d 100644 --- a/docs/yaml/objects/external_program.yaml +++ b/docs/yaml/objects/external_program.yaml @@ -56,3 +56,8 @@ methods: ```meson run_command(find_program('foo'), 'arg1', 'arg2') ``` + + - name: cmd_array + returns: list[str] + description: Returns an array containing the command(s) for the program. + since: 1.6.1 diff --git a/mesonbuild/interpreter/interpreterobjects.py b/mesonbuild/interpreter/interpreterobjects.py index a919102607be..faf986637d67 100644 --- a/mesonbuild/interpreter/interpreterobjects.py +++ b/mesonbuild/interpreter/interpreterobjects.py @@ -618,7 +618,8 @@ def __init__(self, ep: _EXTPROG, interpreter: 'Interpreter') -> None: self.methods.update({'found': self.found_method, 'path': self.path_method, 'version': self.version_method, - 'full_path': self.full_path_method}) + 'full_path': self.full_path_method, + 'cmd_array': self.cmd_array_method}) @noPosargs @noKwargs @@ -645,6 +646,19 @@ def _full_path(self) -> str: assert path is not None return path + @noPosargs + @noKwargs + @FeatureNew('ExternalProgram.cmd_array', '1.6.1') + def cmd_array_method(self, args: T.List[TYPE_var], kwargs: TYPE_kwargs) -> T.List[str]: + return self._cmd_array() + + def _cmd_array(self) -> T.List[str]: + if not self.found(): + raise InterpreterException('Unable to get the path of a not-found external program') + cmd = self.held_object.get_command() + assert cmd is not None + return cmd + @noPosargs @noKwargs @FeatureNew('ExternalProgram.version', '0.62.0')