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

Allow passing ExternalProgram objects as test() and add_install_script() arguments. #3552

Closed
scontini76 opened this issue May 9, 2018 · 11 comments · Fixed by #7060 or #13494
Closed

Comments

@scontini76
Copy link
Contributor

http://mesonbuild.com/Reference-manual.html#external-program-object states that path() returns an array:

path() which returns an array pointing to the executable (this is an array as opposed to a string because the program might be ['python', 'foo.py'], for example)

but it seems to me that it return a string, as if I try to concatenate it with an array like this:

find_program('my program').path() + ['some', 'other', 'stuff']

I get this error:

Invalid use of addition: must be str, not list

[find_program('my program').path(), 'some', 'other', 'stuff']

works fine.

@nirbheek nirbheek self-assigned this May 9, 2018
@nirbheek nirbheek added the bug label May 9, 2018
@nirbheek
Copy link
Member

nirbheek commented May 9, 2018

Hum, we can't change this now because it would break too many build files, but we could add a new .command(). Not sure what the use-case for that would be, though.

@nirbheek
Copy link
Member

nirbheek commented May 9, 2018

Actually, why are you using .path() at all?

nirbheek added a commit that referenced this issue May 9, 2018
@scontini76
Copy link
Contributor Author

I'm not asking for API change, just to align the documentation to avoid that others go mad trying to figure out why they don't obtain what they are excepting :)

Anyway... I'm using .path() probably because I'm doing something ugly like this:

py3 = find_program('python3')
test('python_pycodestyle', py3,
     workdir: meson.source_root(),
     args: [find_program('pycodestyle').path(), 'python'])

[ many other tests using py3 as interpreter]

I want to test my python code, inside the python directory, against pycodestyle (or other tools like pylint and so on). I want to be sure that I have the tool and I'm going to use it with the right interpreter (sometime I have python2 code, sometime I have python3 code). That way I force the startup script to be interpreted by the correct python version. Maybe there is many simpler ways, that one works absolutely fine for me with parallel installation of python and with linters for both (installed with pip2 and pip3). Previously I was struggling because following the documentation I was doing:

py3 = find_program('python3')
test('python_pycodestyle', py3,
     workdir: meson.source_root(),
     args: find_program('pycodestyle').path() + ['python'])

Hope all that things doesn't looks too silly ;)

@nirbheek
Copy link
Member

nirbheek commented May 9, 2018

Even in your case, when you pass a find_program() object to test() args:, you shouldn't need to use .path(). Passing the object directly should work. Does that not work for you?

@scontini76
Copy link
Contributor Author

I wasn't clever or brave enough to test this way :D but now it doesn't seems to work, look below, maybe I misunderstood your suggestion:

args: find_program('pycodestyle') + ['python']

gives

ERROR: Invalid use of addition: unsupported operand type(s) for +: 'ExternalProgramHolder' and 'list'

args: [find_program('pycodestyle'), 'python']

gives

ERROR: Command line arguments must be strings, files or targets.

@nirbheek
Copy link
Member

nirbheek commented May 9, 2018

Well, that's a bug then, it should work that way. :)

@nirbheek nirbheek changed the title documentation: find_program().path() returns a string not an array Allow passing ExternalProgram objects as test() arguments. May 9, 2018
@nirbheek
Copy link
Member

nirbheek commented May 9, 2018

Also I have updated the documentation in git. It should show up on the main website on the next sync.

@scontini76
Copy link
Contributor Author

Thank you very much for the documentation updates and to indicate me (so quickly) the right way to use find_program() in test()!

@nirbheek nirbheek changed the title Allow passing ExternalProgram objects as test() arguments. Allow passing ExternalProgram objects as test() and add_install_script() arguments. May 9, 2018
dcbaker added a commit to dcbaker/meson that referenced this issue Apr 29, 2020
This adds support for Files, CustomTarget, Indexs of CustomTargets,
ConfigureFiles, ExternalPrograms, and Executables.

Fixes: mesonbuild#1234
Fixes: mesonbuild#3552
Fixes: mesonbuild#6175
dcbaker added a commit to dcbaker/meson that referenced this issue Apr 29, 2020
This adds support for Files, CustomTarget, Indexs of CustomTargets,
ConfigureFiles, ExternalPrograms, and Executables.

Fixes: mesonbuild#1234
Fixes: mesonbuild#3552
Fixes: mesonbuild#6175
dcbaker added a commit to dcbaker/meson that referenced this issue Apr 29, 2020
This adds support for Files, CustomTarget, Indexs of CustomTargets,
ConfigureFiles, ExternalPrograms, and Executables.

Fixes: mesonbuild#1234
Fixes: mesonbuild#3552
Fixes: mesonbuild#6175
dcbaker added a commit to dcbaker/meson that referenced this issue Apr 30, 2020
This adds support for Files, CustomTarget, Indexs of CustomTargets,
ConfigureFiles, ExternalPrograms, and Executables.

Fixes: mesonbuild#1234
Fixes: mesonbuild#3552
Fixes: mesonbuild#6175
@michaelcadilhac
Copy link

In the same vein, the following:

project ('test-test')
echo_exe = find_program ('echo')
py = import('python').find_installation()
test ('test', echo_exe, args : [ py ])

fails with:

meson.build:4:0: ERROR: Command line arguments must be strings, files or targets.

Is this the same problem? Using py.path () solves the problem.

@dcbaker
Copy link
Member

dcbaker commented Nov 16, 2020

Yeah. Can you open a new issue for that?

@eli-schwartz
Copy link
Member

This was wrongly closed, the linked PR only implemented this for add_*_script and not for test().

@eli-schwartz eli-schwartz reopened this Sep 3, 2021
dgibson added a commit to dgibson/meson that referenced this issue Jul 31, 2024
Although it's not especially common, there are certainly cases where it's
useful to pass the path to an external program to a test program.

Fixes: mesonbuild#3552

Signed-off-by: David Gibson <[email protected]>
dgibson added a commit to dgibson/meson that referenced this issue Jul 31, 2024
Although it's not especially common, there are certainly cases where it's
useful to pass the path to an external program to a test program.

Fixes: mesonbuild#3552

Signed-off-by: David Gibson <[email protected]>
dgibson added a commit to dgibson/meson that referenced this issue Aug 25, 2024
Although it's not especially common, there are certainly cases where it's
useful to pass the path to an external program to a test program.

Fixes: mesonbuild#3552

Signed-off-by: David Gibson <[email protected]>
dgibson added a commit to dgibson/meson that referenced this issue Aug 25, 2024
Although it's not especially common, there are certainly cases where it's
useful to pass the path to an external program to a test program.

Fixes: mesonbuild#3552

Signed-off-by: David Gibson <[email protected]>
dgibson added a commit to dgibson/meson that referenced this issue Aug 25, 2024
Although it's not especially common, there are certainly cases where it's
useful to pass the path to an external program to a test program.

Fixes: mesonbuild#3552

Signed-off-by: David Gibson <[email protected]>
dgibson added a commit to dgibson/meson that referenced this issue Aug 27, 2024
Although it's not especially common, there are certainly cases where it's
useful to pass the path to an external program to a test program.

Fixes: mesonbuild#3552

Signed-off-by: David Gibson <[email protected]>
dcbaker pushed a commit that referenced this issue Aug 27, 2024
Although it's not especially common, there are certainly cases where it's
useful to pass the path to an external program to a test program.

Fixes: #3552

Signed-off-by: David Gibson <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants