summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mesonbuild/compilers/detect.py6
-rw-r--r--unittests/failuretests.py19
-rw-r--r--unittests/machinefiletests.py16
3 files changed, 31 insertions, 10 deletions
diff --git a/mesonbuild/compilers/detect.py b/mesonbuild/compilers/detect.py
index 7bd48d10c..d4ad4bade 100644
--- a/mesonbuild/compilers/detect.py
+++ b/mesonbuild/compilers/detect.py
@@ -897,9 +897,13 @@ def _detect_objc_or_objcpp_compiler(env: 'Environment', lang: str, for_machine:
version = _get_gnu_version_from_defines(defines)
comp = objc.GnuObjCCompiler if lang == 'objc' else objcpp.GnuObjCPPCompiler
linker = guess_nix_linker(env, compiler, comp, version, for_machine)
- return comp(
+ c = comp(
ccache, compiler, version, for_machine, is_cross, info,
defines, linker=linker)
+ if not c.compiles('int main(void) { return 0; }', env)[0]:
+ popen_exceptions[join_args(compiler)] = f'GCC was not built with support for {"objective-c" if lang == "objc" else "objective-c++"}'
+ continue
+ return c
if 'clang' in out:
linker = None
defines = _get_clang_compiler_defines(compiler, lang)
diff --git a/unittests/failuretests.py b/unittests/failuretests.py
index 0dd6c5f65..18d0c5e70 100644
--- a/unittests/failuretests.py
+++ b/unittests/failuretests.py
@@ -241,19 +241,26 @@ class FailureTests(BasePlatformTests):
'''
self.assertMesonRaises(code, ".* is not a config-tool dependency")
- def test_objc_cpp_detection(self):
+ def test_objc_detection(self) -> None:
'''
Test that when we can't detect objc or objcpp, we fail gracefully.
'''
env = get_fake_env()
try:
detect_objc_compiler(env, MachineChoice.HOST)
+ except EnvironmentException as e:
+ self.assertRegex(str(e), r"(Unknown compiler|GCC was not built with support)")
+ else:
+ raise unittest.SkipTest('Working objective-c Compiler found, cannot test error.')
+
+ def test_objcpp_detection(self) -> None:
+ env = get_fake_env()
+ try:
detect_objcpp_compiler(env, MachineChoice.HOST)
- except EnvironmentException:
- code = "add_languages('objc')\nadd_languages('objcpp')"
- self.assertMesonRaises(code, "Unknown compiler")
- return
- raise unittest.SkipTest("objc and objcpp found, can't test detection failure")
+ except EnvironmentException as e:
+ self.assertRegex(str(e), r"(Unknown compiler|GCC was not built with support)")
+ else:
+ raise unittest.SkipTest('Working objective-c++ Compiler found, cannot test error.')
def test_subproject_variables(self):
'''
diff --git a/unittests/machinefiletests.py b/unittests/machinefiletests.py
index 803a1797d..e71cd04fe 100644
--- a/unittests/machinefiletests.py
+++ b/unittests/machinefiletests.py
@@ -23,7 +23,7 @@ import mesonbuild.envconfig
import mesonbuild.environment
import mesonbuild.coredata
import mesonbuild.modules.gnome
-
+from mesonbuild import mesonlib
from mesonbuild import machinefile
from mesonbuild.mesonlib import (
@@ -275,7 +275,12 @@ class NativeFileTests(BasePlatformTests):
if not is_real_gnu_compiler(shutil.which('gcc')):
raise SkipTest('Only one compiler found, cannot test.')
return 'gcc', 'gcc'
- self.helper_for_compiler('objc', cb)
+ try:
+ self.helper_for_compiler('objc', cb)
+ except mesonlib.EnvironmentException as e:
+ if 'GCC was not built with support for objective-c' in str(e):
+ raise unittest.SkipTest("GCC doesn't support objective-c, test cannot run")
+ raise
@skip_if_not_language('objcpp')
@skip_if_env_set('OBJCXX')
@@ -288,7 +293,12 @@ class NativeFileTests(BasePlatformTests):
if not is_real_gnu_compiler(shutil.which('g++')):
raise SkipTest('Only one compiler found, cannot test.')
return 'g++', 'gcc'
- self.helper_for_compiler('objcpp', cb)
+ try:
+ self.helper_for_compiler('objcpp', cb)
+ except mesonlib.EnvironmentException as e:
+ if 'GCC was not built with support for objective-c++' in str(e):
+ raise unittest.SkipTest("G++ doesn't support objective-c++, test cannot run")
+ raise
@skip_if_not_language('d')
@skip_if_env_set('DC')