Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ExternalProgram: add cmd_array to complete the offering #13845

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/yaml/objects/external_program.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 12 additions & 1 deletion mesonbuild/interpreter/interpreterobjects.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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')
Expand Down
13 changes: 13 additions & 0 deletions test cases/common/26 find program/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,16 @@ 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')
if build_machine.system() != 'cygwin'
assert(prog.cmd_array() != [prog.full_path()])
endif

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
Loading