aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2019-10-01 11:02:50 -0700
committerDylan Baker <dylan@pnwbakers.com>2020-05-18 13:53:58 -0700
commitcb6662b57299c3644719593115b2ffb828679c36 (patch)
tree27d15098799552bb16c501eafa7d4e5c807111fe
parente822889754a3f9ba1a1c9d9179dd24d102db3969 (diff)
downloadmeson-cb6662b57299c3644719593115b2ffb828679c36.zip
meson-cb6662b57299c3644719593115b2ffb828679c36.tar.gz
meson-cb6662b57299c3644719593115b2ffb828679c36.tar.bz2
backends: ensure that test executables can be run when passed as arguments
If an executable is passed as an argument to a script in the build directory that it resides in then it will not execute (on *nix) due to a lack of ./. Ie, `foo` must be called as `./foo`. If it is called from a different directory it will work. Ie `../foo` or `bar/foo`. Fixes #5984
-rw-r--r--mesonbuild/backend/backends.py5
-rwxr-xr-xrun_unittests.py25
-rw-r--r--test cases/unit/71 cross test passed/meson.build12
-rw-r--r--test cases/unit/71 cross test passed/script.py7
-rw-r--r--test cases/unit/71 cross test passed/src/main.c6
5 files changed, 44 insertions, 11 deletions
diff --git a/mesonbuild/backend/backends.py b/mesonbuild/backend/backends.py
index 9d527cb..5ef7f44 100644
--- a/mesonbuild/backend/backends.py
+++ b/mesonbuild/backend/backends.py
@@ -810,6 +810,11 @@ class Backend:
cmd_args.append(a)
elif isinstance(a, str):
cmd_args.append(a)
+ elif isinstance(a, build.Executable):
+ p = self.construct_target_rel_path(a, t.workdir)
+ if p == a.get_filename():
+ p = './' + p
+ cmd_args.append(p)
elif isinstance(a, build.Target):
cmd_args.append(self.construct_target_rel_path(a, t.workdir))
else:
diff --git a/run_unittests.py b/run_unittests.py
index 7467107..f8ca253 100755
--- a/run_unittests.py
+++ b/run_unittests.py
@@ -7560,19 +7560,28 @@ class CrossFileTests(BasePlatformTests):
c = '/usr/bin/{}'
ar = '/usr/bin/ar'
strip = '/usr/bin/ar'
+ {}
[properties]
needs_exe_wrapper = {}
- {}
[host_machine]
system = 'linux'
cpu_family = 'x86'
cpu = 'i686'
endian = 'little'
- """.format(cc, needs_exe_wrapper,
- 'exe_wrapper = {}'.format(str(exe_wrapper))
- if exe_wrapper is not None else ''))
+ """.format(cc,
+ 'exe_wrapper = {}'.format(str(exe_wrapper)) if exe_wrapper is not None else '',
+ needs_exe_wrapper))
+
+ def _stub_exe_wrapper(self) -> str:
+ return textwrap.dedent('''\
+ #!/usr/bin/env python3
+ import subprocess
+ import sys
+
+ sys.exit(subprocess.run(sys.argv[1:]).returncode)
+ ''')
def test_needs_exe_wrapper_true(self):
testdir = os.path.join(self.common_test_dir, '1 trivial')
@@ -7599,13 +7608,7 @@ class CrossFileTests(BasePlatformTests):
with tempfile.TemporaryDirectory() as d:
s = Path(d) / 'wrapper.py'
with s.open('wt') as f:
- f.write(textwrap.dedent('''
- #!/usr/bin/env python3
- import subprocess
- import sys
-
- return subprocess.run(sys.argv[1:]).returnncode
- '''))
+ f.write(self._stub_exe_wrapper())
p = Path(d) / 'crossfile'
with p.open('wt') as f:
f.write(self._cross_file_generator(
diff --git a/test cases/unit/71 cross test passed/meson.build b/test cases/unit/71 cross test passed/meson.build
new file mode 100644
index 0000000..cb3bb6d
--- /dev/null
+++ b/test cases/unit/71 cross test passed/meson.build
@@ -0,0 +1,12 @@
+project(
+ 'cross test passed',
+ 'c',
+ version : '>= 0.51'
+)
+
+e = executable('exec', 'src/main.c')
+
+py = import('python').find_installation()
+
+test('root', e)
+test('main', py, args : [meson.current_source_dir() / 'script.py', e])
diff --git a/test cases/unit/71 cross test passed/script.py b/test cases/unit/71 cross test passed/script.py
new file mode 100644
index 0000000..257cd30
--- /dev/null
+++ b/test cases/unit/71 cross test passed/script.py
@@ -0,0 +1,7 @@
+#!/usr/bin/env python3
+
+import subprocess
+import sys
+
+if __name__ == "__main__":
+ sys.exit(subprocess.run(sys.argv[1:]).returncode)
diff --git a/test cases/unit/71 cross test passed/src/main.c b/test cases/unit/71 cross test passed/src/main.c
new file mode 100644
index 0000000..490b4a6
--- /dev/null
+++ b/test cases/unit/71 cross test passed/src/main.c
@@ -0,0 +1,6 @@
+#include <stdio.h>
+
+int main(int argc, char const *argv[])
+{
+ return 0;
+}