aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2019-10-01 11:19:08 -0700
committerDylan Baker <dylan@pnwbakers.com>2020-05-18 13:53:58 -0700
commit0ec94ca0629415d4b555e8ef38a5093a65e0539e (patch)
treed8bb83c50d30eaa5f70931018f7458210a1c4489
parentcb6662b57299c3644719593115b2ffb828679c36 (diff)
downloadmeson-0ec94ca0629415d4b555e8ef38a5093a65e0539e.zip
meson-0ec94ca0629415d4b555e8ef38a5093a65e0539e.tar.gz
meson-0ec94ca0629415d4b555e8ef38a5093a65e0539e.tar.bz2
backends: Consider arguments passed to a test when cross compiling
Otherwise a wrapper script which takes an executable as an argument will mistakenly run when that executable is cross compiled. This does not wrap said executable in an exe_wrapper, just skip it. Fixes #5982
-rw-r--r--mesonbuild/backend/backends.py18
-rw-r--r--mesonbuild/mtest.py7
-rwxr-xr-xrun_unittests.py25
-rw-r--r--test cases/unit/72 cross test passed/meson.build (renamed from test cases/unit/71 cross test passed/meson.build)0
-rw-r--r--test cases/unit/72 cross test passed/script.py (renamed from test cases/unit/71 cross test passed/script.py)0
-rw-r--r--test cases/unit/72 cross test passed/src/main.c (renamed from test cases/unit/71 cross test passed/src/main.c)0
-rw-r--r--test cases/unit/73 summary/meson.build (renamed from test cases/unit/72 summary/meson.build)0
-rw-r--r--test cases/unit/73 summary/subprojects/sub/meson.build (renamed from test cases/unit/72 summary/subprojects/sub/meson.build)0
-rw-r--r--test cases/unit/73 summary/subprojects/sub2/meson.build (renamed from test cases/unit/72 summary/subprojects/sub2/meson.build)0
-rw-r--r--test cases/unit/74 wrap file url/meson.build (renamed from test cases/unit/73 wrap file url/meson.build)0
-rw-r--r--test cases/unit/74 wrap file url/subprojects/foo-patch.tar.xz (renamed from test cases/unit/73 wrap file url/subprojects/foo-patch.tar.xz)bin228 -> 228 bytes
-rw-r--r--test cases/unit/74 wrap file url/subprojects/foo.tar.xz (renamed from test cases/unit/73 wrap file url/subprojects/foo.tar.xz)bin216 -> 216 bytes
-rw-r--r--test cases/unit/75 dep files/foo.c (renamed from test cases/unit/74 dep files/foo.c)0
-rw-r--r--test cases/unit/75 dep files/meson.build (renamed from test cases/unit/74 dep files/meson.build)0
-rw-r--r--test cases/unit/76 subdir libdir/meson.build (renamed from test cases/unit/75 subdir libdir/meson.build)0
-rw-r--r--test cases/unit/76 subdir libdir/subprojects/flub/meson.build (renamed from test cases/unit/75 subdir libdir/subprojects/flub/meson.build)0
16 files changed, 39 insertions, 11 deletions
diff --git a/mesonbuild/backend/backends.py b/mesonbuild/backend/backends.py
index 5ef7f44..ceea94a 100644
--- a/mesonbuild/backend/backends.py
+++ b/mesonbuild/backend/backends.py
@@ -119,7 +119,8 @@ class TestSerialisation:
needs_exe_wrapper: bool, is_parallel: bool, cmd_args: T.List[str],
env: build.EnvironmentVariables, should_fail: bool,
timeout: T.Optional[int], workdir: T.Optional[str],
- extra_paths: T.List[str], protocol: TestProtocol, priority: int):
+ extra_paths: T.List[str], protocol: TestProtocol, priority: int,
+ cmd_is_built: bool):
self.name = name
self.project_name = project
self.suite = suite
@@ -138,6 +139,8 @@ class TestSerialisation:
self.protocol = protocol
self.priority = priority
self.needs_exe_wrapper = needs_exe_wrapper
+ self.cmd_is_built = cmd_is_built
+
def get_backend_from_name(backend: str, build: T.Optional[build.Build] = None, interpreter: T.Optional['Interpreter'] = None) -> T.Optional['Backend']:
if backend == 'ninja':
@@ -788,6 +791,15 @@ class Backend:
# E.g. an external verifier or simulator program run on a generated executable.
# Can always be run without a wrapper.
test_for_machine = MachineChoice.BUILD
+
+ # we allow passing compiled executables to tests, which may be cross built.
+ # We need to consider these as well when considering whether the target is cross or not.
+ for a in t.cmd_args:
+ if isinstance(a, build.BuildTarget):
+ if a.for_machine is MachineChoice.HOST:
+ test_for_machine = MachineChoice.HOST
+ break
+
is_cross = self.environment.is_cross_build(test_for_machine)
if is_cross and self.environment.need_exe_wrapper():
exe_wrapper = self.environment.get_exe_wrapper()
@@ -801,6 +813,7 @@ class Backend:
extra_paths = self.determine_windows_extra_paths(exe, extra_bdeps)
else:
extra_paths = []
+
cmd_args = []
for a in unholder(t.cmd_args):
if isinstance(a, build.BuildTarget):
@@ -823,7 +836,8 @@ class Backend:
exe_wrapper, self.environment.need_exe_wrapper(),
t.is_parallel, cmd_args, t.env,
t.should_fail, t.timeout, t.workdir,
- extra_paths, t.protocol, t.priority)
+ extra_paths, t.protocol, t.priority,
+ isinstance(exe, build.Executable))
arr.append(ts)
return arr
diff --git a/mesonbuild/mtest.py b/mesonbuild/mtest.py
index e04d365..8806932 100644
--- a/mesonbuild/mtest.py
+++ b/mesonbuild/mtest.py
@@ -615,14 +615,15 @@ class SingleTestRunner:
# Can not run test on cross compiled executable
# because there is no execute wrapper.
return None
- else:
+ elif self.test.cmd_is_built:
+ # If the command is not built (ie, its a python script),
+ # then we don't check for the exe-wrapper
if not self.test.exe_runner.found():
msg = 'The exe_wrapper defined in the cross file {!r} was not ' \
'found. Please check the command and/or add it to PATH.'
raise TestException(msg.format(self.test.exe_runner.name))
return self.test.exe_runner.get_command() + self.test.fname
- else:
- return self.test.fname
+ return self.test.fname
def run(self) -> TestRun:
cmd = self._get_cmd()
diff --git a/run_unittests.py b/run_unittests.py
index f8ca253..e326aa4 100755
--- a/run_unittests.py
+++ b/run_unittests.py
@@ -4476,7 +4476,7 @@ recommended as it is not supported on some platforms''')
self._run(self.mconf_command + [self.builddir])
def test_summary(self):
- testdir = os.path.join(self.unit_test_dir, '72 summary')
+ testdir = os.path.join(self.unit_test_dir, '73 summary')
out = self.init(testdir)
expected = textwrap.dedent(r'''
Some Subproject 2.0
@@ -4530,7 +4530,7 @@ recommended as it is not supported on some platforms''')
self.assertPathDoesNotExist(os.path.join(self.builddir, prog))
def test_spurious_reconfigure_built_dep_file(self):
- testdir = os.path.join(self.unit_test_dir, '74 dep files')
+ testdir = os.path.join(self.unit_test_dir, '75 dep files')
# Regression test: Spurious reconfigure was happening when build
# directory is inside source directory.
@@ -6630,7 +6630,7 @@ c = ['{0}']
return hashlib.sha256(f.read()).hexdigest()
def test_wrap_with_file_url(self):
- testdir = os.path.join(self.unit_test_dir, '73 wrap file url')
+ testdir = os.path.join(self.unit_test_dir, '74 wrap file url')
source_filename = os.path.join(testdir, 'subprojects', 'foo.tar.xz')
patch_filename = os.path.join(testdir, 'subprojects', 'foo-patch.tar.xz')
wrap_filename = os.path.join(testdir, 'subprojects', 'foo.wrap')
@@ -6721,7 +6721,7 @@ class LinuxCrossArmTests(BaseLinuxCrossTests):
def test_cross_libdir_subproject(self):
# Guard against a regression where calling "subproject"
# would reset the value of libdir to its default value.
- testdir = os.path.join(self.unit_test_dir, '75 subdir libdir')
+ testdir = os.path.join(self.unit_test_dir, '76 subdir libdir')
self.init(testdir, extra_args=['--libdir=fuf'])
for i in self.introspect('--buildoptions'):
if i['name'] == 'libdir':
@@ -7591,7 +7591,7 @@ class CrossFileTests(BasePlatformTests):
f.write(self._cross_file_generator(needs_exe_wrapper=True))
self.init(testdir, extra_args=['--cross-file=' + str(p)])
out = self.run_target('test')
- self.assertRegex(out, r'Skipped:\s*1\n')
+ self.assertRegex(out, r'Skipped:\s*1\s*\n')
def test_needs_exe_wrapper_false(self):
testdir = os.path.join(self.common_test_dir, '1 trivial')
@@ -7609,6 +7609,7 @@ class CrossFileTests(BasePlatformTests):
s = Path(d) / 'wrapper.py'
with s.open('wt') as f:
f.write(self._stub_exe_wrapper())
+ s.chmod(0o774)
p = Path(d) / 'crossfile'
with p.open('wt') as f:
f.write(self._cross_file_generator(
@@ -7617,7 +7618,19 @@ class CrossFileTests(BasePlatformTests):
self.init(testdir, extra_args=['--cross-file=' + str(p)])
out = self.run_target('test')
- self.assertNotRegex(out, r'Skipped:\s*1\n')
+ self.assertNotRegex(out, r'Skipped:\s*1\s*\n')
+
+ def test_cross_exe_passed_no_wrapper(self):
+ testdir = os.path.join(self.unit_test_dir, '72 cross test passed')
+ with tempfile.TemporaryDirectory() as d:
+ p = Path(d) / 'crossfile'
+ with p.open('wt') as f:
+ f.write(self._cross_file_generator(needs_exe_wrapper=True))
+
+ self.init(testdir, extra_args=['--cross-file=' + str(p)])
+ self.build()
+ out = self.run_target('test')
+ self.assertRegex(out, r'Skipped:\s*2\s*\n')
# The test uses mocking and thus requires that the current process is the
# one to run the Meson steps. If we are using an external test executable
diff --git a/test cases/unit/71 cross test passed/meson.build b/test cases/unit/72 cross test passed/meson.build
index cb3bb6d..cb3bb6d 100644
--- a/test cases/unit/71 cross test passed/meson.build
+++ b/test cases/unit/72 cross test passed/meson.build
diff --git a/test cases/unit/71 cross test passed/script.py b/test cases/unit/72 cross test passed/script.py
index 257cd30..257cd30 100644
--- a/test cases/unit/71 cross test passed/script.py
+++ b/test cases/unit/72 cross test passed/script.py
diff --git a/test cases/unit/71 cross test passed/src/main.c b/test cases/unit/72 cross test passed/src/main.c
index 490b4a6..490b4a6 100644
--- a/test cases/unit/71 cross test passed/src/main.c
+++ b/test cases/unit/72 cross test passed/src/main.c
diff --git a/test cases/unit/72 summary/meson.build b/test cases/unit/73 summary/meson.build
index df4540d..df4540d 100644
--- a/test cases/unit/72 summary/meson.build
+++ b/test cases/unit/73 summary/meson.build
diff --git a/test cases/unit/72 summary/subprojects/sub/meson.build b/test cases/unit/73 summary/subprojects/sub/meson.build
index e7d7833..e7d7833 100644
--- a/test cases/unit/72 summary/subprojects/sub/meson.build
+++ b/test cases/unit/73 summary/subprojects/sub/meson.build
diff --git a/test cases/unit/72 summary/subprojects/sub2/meson.build b/test cases/unit/73 summary/subprojects/sub2/meson.build
index 86b9cfd..86b9cfd 100644
--- a/test cases/unit/72 summary/subprojects/sub2/meson.build
+++ b/test cases/unit/73 summary/subprojects/sub2/meson.build
diff --git a/test cases/unit/73 wrap file url/meson.build b/test cases/unit/74 wrap file url/meson.build
index 3bd3b25..3bd3b25 100644
--- a/test cases/unit/73 wrap file url/meson.build
+++ b/test cases/unit/74 wrap file url/meson.build
diff --git a/test cases/unit/73 wrap file url/subprojects/foo-patch.tar.xz b/test cases/unit/74 wrap file url/subprojects/foo-patch.tar.xz
index fdb026c..fdb026c 100644
--- a/test cases/unit/73 wrap file url/subprojects/foo-patch.tar.xz
+++ b/test cases/unit/74 wrap file url/subprojects/foo-patch.tar.xz
Binary files differ
diff --git a/test cases/unit/73 wrap file url/subprojects/foo.tar.xz b/test cases/unit/74 wrap file url/subprojects/foo.tar.xz
index 2ed6ab4..2ed6ab4 100644
--- a/test cases/unit/73 wrap file url/subprojects/foo.tar.xz
+++ b/test cases/unit/74 wrap file url/subprojects/foo.tar.xz
Binary files differ
diff --git a/test cases/unit/74 dep files/foo.c b/test cases/unit/75 dep files/foo.c
index e69de29..e69de29 100644
--- a/test cases/unit/74 dep files/foo.c
+++ b/test cases/unit/75 dep files/foo.c
diff --git a/test cases/unit/74 dep files/meson.build b/test cases/unit/75 dep files/meson.build
index 4829f56..4829f56 100644
--- a/test cases/unit/74 dep files/meson.build
+++ b/test cases/unit/75 dep files/meson.build
diff --git a/test cases/unit/75 subdir libdir/meson.build b/test cases/unit/76 subdir libdir/meson.build
index 5099c91..5099c91 100644
--- a/test cases/unit/75 subdir libdir/meson.build
+++ b/test cases/unit/76 subdir libdir/meson.build
diff --git a/test cases/unit/75 subdir libdir/subprojects/flub/meson.build b/test cases/unit/76 subdir libdir/subprojects/flub/meson.build
index 7bfd2c5..7bfd2c5 100644
--- a/test cases/unit/75 subdir libdir/subprojects/flub/meson.build
+++ b/test cases/unit/76 subdir libdir/subprojects/flub/meson.build