From 729b344cbb15799116af6123e0d40048f3f5dcdd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Cerveau?= Date: Wed, 30 Oct 2024 15:53:52 +0100 Subject: [PATCH] ExternalProgram: add cmd_array to complete the offfering In case of python and especially in the case of pyInstaller where the python command is meson.exe runpython, it should not be full path to be used but cmd_array. Fixing #13834 --- docs/yaml/objects/external_program.yaml | 5 +++++ mesonbuild/interpreter/interpreterobjects.py | 13 ++++++++++++- test cases/common/26 find program/meson.build | 11 +++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/docs/yaml/objects/external_program.yaml b/docs/yaml/objects/external_program.yaml index 4c24497a9f15..d7f366ef1945 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.7.0 diff --git a/mesonbuild/interpreter/interpreterobjects.py b/mesonbuild/interpreter/interpreterobjects.py index a919102607be..e563f9289fcc 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,16 @@ def _full_path(self) -> str: assert path is not None return path + @noPosargs + @noKwargs + @FeatureNew('ExternalProgram.cmd_array', '1.7.0') + def cmd_array_method(self, args: T.List[TYPE_var], kwargs: TYPE_kwargs) -> 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') diff --git a/test cases/common/26 find program/meson.build b/test cases/common/26 find program/meson.build index a20f6b45a142..5958c6cf3924 100644 --- a/test cases/common/26 find program/meson.build +++ b/test cases/common/26 find program/meson.build @@ -40,3 +40,14 @@ assert(not prog.found(), 'Program should not be found') prog = find_program('test_subdir.py', dirs : ['/nonexistent', meson.current_source_dir() / 'scripts']) assert(prog.found(), 'Program should be found') + +prog = find_program('print-version.py') +assert(prog.cmd_array() != [prog.full_path()]) + +if build_machine.system() == 'windows' + prog = find_program('cmd,exe') + assert(prog.cmd_array() == [prog.full_path()]) +else + prog = find_program('ld') + assert(prog.cmd_array() == [prog.full_path()]) +endif \ No newline at end of file