summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJussi Pakkanen <jpakkane@gmail.com>2022-02-09 02:11:30 +0200
committerJussi Pakkanen <jpakkane@gmail.com>2022-02-09 02:11:30 +0200
commitf11c643a82a911f8e9419557dae5d80af9aa3f92 (patch)
treeba6f22ae2342d3888fa1168759c5078f8c916ac2
parentd082204096afd51730f44a75bd02423f74c2e5ae (diff)
downloadmeson-crossenvvar.tar.gz
Properly error out when cross file is missing a compiler.crossenvvar
-rw-r--r--cross/noexes.txt9
-rw-r--r--cross/ubuntu-faketarget.txt13
-rw-r--r--mesonbuild/compilers/detect.py5
-rw-r--r--test cases/common/10 man install/meson.build2
-rw-r--r--unittests/allplatformstests.py2
-rw-r--r--unittests/linuxcrosstests.py8
-rw-r--r--unittests/machinefiletests.py9
7 files changed, 31 insertions, 17 deletions
diff --git a/cross/noexes.txt b/cross/noexes.txt
new file mode 100644
index 000000000..d211f173d
--- /dev/null
+++ b/cross/noexes.txt
@@ -0,0 +1,9 @@
+# A cross file that is missing compilers must lead to
+# an error.
+[binaries]
+
+[target_machine]
+system = 'linux'
+cpu_family = 'mips'
+cpu = 'mips'
+endian = 'little'
diff --git a/cross/ubuntu-faketarget.txt b/cross/ubuntu-faketarget.txt
deleted file mode 100644
index cc43998cc..000000000
--- a/cross/ubuntu-faketarget.txt
+++ /dev/null
@@ -1,13 +0,0 @@
-# This is a setup for compiling a program that runs natively
-# but produces output that runs on a different platform.
-# That is either a cross compiler or something like binutils.
-
-# We don't need to specify any properties or compilers,
-# for we use the native ones and can run the resulting
-# binaries directly.
-
-[target_machine]
-system = 'linux'
-cpu_family = 'mips'
-cpu = 'mips'
-endian = 'little'
diff --git a/mesonbuild/compilers/detect.py b/mesonbuild/compilers/detect.py
index 9216ecfa6..7e6d6556c 100644
--- a/mesonbuild/compilers/detect.py
+++ b/mesonbuild/compilers/detect.py
@@ -240,8 +240,9 @@ def _get_compilers(env: 'Environment', lang: str, for_machine: MachineChoice) ->
# Return value has to be a list of compiler 'choices'
compilers = [comp]
else:
- if not env.machines.matches_build_machine(for_machine):
- raise EnvironmentException(f'{lang!r} compiler binary not defined in cross or native file')
+ # Cross compilers must NEVER EVER be taken from envvars.
+ if env.is_cross_build() and for_machine == MachineChoice.HOST:
+ raise EnvironmentException(f'{lang!r} compiler binary not defined in a cross file')
compilers = [[x] for x in defaults[lang]]
ccache = BinaryTable.detect_compiler_cache()
diff --git a/test cases/common/10 man install/meson.build b/test cases/common/10 man install/meson.build
index 05c52782e..d0f3be880 100644
--- a/test cases/common/10 man install/meson.build
+++ b/test cases/common/10 man install/meson.build
@@ -1,4 +1,4 @@
-project('man install', 'c')
+project('man install')
m1 = install_man('foo.1')
m2 = install_man('bar.2')
m3 = install_man('foo.fr.1', locale: 'fr')
diff --git a/unittests/allplatformstests.py b/unittests/allplatformstests.py
index 60ff12314..6f722c76d 100644
--- a/unittests/allplatformstests.py
+++ b/unittests/allplatformstests.py
@@ -3597,6 +3597,8 @@ class AllPlatformTests(BasePlatformTests):
machinefile = os.path.join(self.builddir, 'machine.txt')
with open(machinefile, 'w', encoding='utf-8') as f:
f.write(textwrap.dedent('''
+ [binaries]
+ c = 'cc'
[properties]
c_stdlib = 'mylibc'
'''))
diff --git a/unittests/linuxcrosstests.py b/unittests/linuxcrosstests.py
index 16f7c2454..0c0355a26 100644
--- a/unittests/linuxcrosstests.py
+++ b/unittests/linuxcrosstests.py
@@ -125,6 +125,14 @@ class LinuxCrossArmTests(BaseLinuxCrossTests):
self.run_tests()
self.assertPathExists(stamp_file)
+ def test_missing_compilers(self):
+ '''
+ Requesting a compiler that is not in the cross file must be an error.
+ '''
+ testdir = os.path.join(self.common_test_dir, '1 trivial')
+ self.meson_cross_files = [os.path.join(self.src_root, 'cross', 'noexes.txt')]
+ with self.assertRaises(subprocess.CalledProcessError, msg='compiler binary not defined in a cross file'):
+ self.init(testdir)
def should_run_cross_mingw_tests():
return shutil.which('x86_64-w64-mingw32-gcc') and not (is_windows() or is_cygwin())
diff --git a/unittests/machinefiletests.py b/unittests/machinefiletests.py
index 0a756b572..a124b64a7 100644
--- a/unittests/machinefiletests.py
+++ b/unittests/machinefiletests.py
@@ -740,7 +740,7 @@ class CrossFileTests(BasePlatformTests):
self.init(testdir, extra_args=['--cross-file=' + name], inprocess=True)
self.wipe()
- def helper_create_cross_file(self, values):
+ def helper_create_cross_file(self, values, *, add_fake_compilers=True):
"""Create a config file as a temporary file.
values should be a nested dictionary structure of {section: {key:
@@ -748,6 +748,13 @@ class CrossFileTests(BasePlatformTests):
"""
filename = os.path.join(self.builddir, f'generated{self.current_config}.config')
self.current_config += 1
+ if add_fake_compilers:
+ if is_windows() and shutil.which('cl'):
+ base = {'binaries': {'c': 'cl', 'cpp': 'cl'}}
+ else:
+ base = {'binaries': {'c': 'cc', 'cpp': 'c++'}}
+ base.update(values)
+ values = base
with open(filename, 'wt', encoding='utf-8') as f:
for section, entries in values.items():
f.write(f'[{section}]\n')