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

Fix run_targets running scripts from different subdirs. #8526

Merged
merged 1 commit into from
Mar 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions mesonbuild/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -4008,6 +4008,8 @@ def func_run_target(self, node, args, kwargs):
if isinstance(i, dependencies.ExternalProgram) and not i.found():
raise InterpreterException(f'Tried to use non-existing executable {i.name!r}')
cleaned_args.append(i)
if isinstance(cleaned_args[0], str):
cleaned_args[0] = self.func_find_program(node, cleaned_args[0], {})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should do that in custom_target() and generator() too for consistency. And probably if it's a File too. OTOH that would be new features, so for 0.57.2 this is probably enough.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While at it, add_*_script() does some custom lookup in _find_source_script() instead of using find_program() that is subtly not the same thing. IMHO we should remove that code to use fin_program().

And run_command_impl() also does yet another subtly different thing.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll file a separate MR for those.

name = args[0]
if not isinstance(name, str):
raise InterpreterException('First argument must be a string.')
Expand Down
9 changes: 9 additions & 0 deletions run_unittests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2385,6 +2385,15 @@ def test_run_target_files_path(self):
self.run_target('check-env')
self.run_target('check-env-ct')

def test_run_target_subdir(self):
'''
Test that run_targets are run from the correct directory
https://github.com/mesonbuild/meson/issues/957
'''
testdir = os.path.join(self.common_test_dir, '52 run target')
self.init(testdir)
self.run_target('textprinter')

def test_install_introspection(self):
'''
Tests that the Meson introspection API exposes install filenames correctly
Expand Down
2 changes: 2 additions & 0 deletions test cases/common/52 run target/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,5 @@ custom_target('check-env-ct',
'MY_ENV': '1'},
output: 'check-env-ct',
)

run_target('textprinter', command: ['subdir/textprinter.py'])
3 changes: 3 additions & 0 deletions test cases/common/52 run target/subdir/textprinter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env python3

print('I am a script. Being run.')