aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/interpreter/compiler.py
diff options
context:
space:
mode:
authorPaolo Bonzini <pbonzini@redhat.com>2021-07-22 12:01:01 +0200
committerPaolo Bonzini <pbonzini@redhat.com>2021-09-07 14:18:33 +0200
commit8596b3bcd12371ad16e5ffbd3e34953603cd1484 (patch)
tree8a4682d857ef92b827ad6806458a60e7c0b94257 /mesonbuild/interpreter/compiler.py
parent90ee43463f4844b667d26230ef7773f63fcf60dd (diff)
downloadmeson-8596b3bcd12371ad16e5ffbd3e34953603cd1484.zip
meson-8596b3bcd12371ad16e5ffbd3e34953603cd1484.tar.gz
meson-8596b3bcd12371ad16e5ffbd3e34953603cd1484.tar.bz2
interpreter: detect and pass compiler to be used for linker tests
Allow using the links method to test that the C++ driver (e.g. g++) can be used to link C objects. One usecase is that the C compiler's libsanitizer might not be compatible with the one included by the C++ driver. This is theoretically backwards-incompatible, but it should be treated as a bugfix in my opinion. There is no way in Meson to compile a .c file with the C++ driver as part of a build target, therefore there would be no reason to do something like meson.get_compiler(meson.get_compiler('cpp').links(files('main.c')). Fixes: #7703
Diffstat (limited to 'mesonbuild/interpreter/compiler.py')
-rw-r--r--mesonbuild/interpreter/compiler.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/mesonbuild/interpreter/compiler.py b/mesonbuild/interpreter/compiler.py
index 54f4bee..b76e7f8 100644
--- a/mesonbuild/interpreter/compiler.py
+++ b/mesonbuild/interpreter/compiler.py
@@ -11,6 +11,7 @@ from .. import coredata
from .. import dependencies
from .. import mesonlib
from .. import mlog
+from ..compilers import SUFFIX_TO_LANG
from ..compilers.compilers import CompileCheckMode
from ..interpreterbase import (ObjectHolder, noPosargs, noKwargs,
FeatureNew, disablerIfNotFound,
@@ -454,13 +455,27 @@ class CompilerHolder(ObjectHolder['Compiler']):
@typed_kwargs('compiler.links', *_COMPILES_KWS)
def links_method(self, args: T.Tuple['mesonlib.FileOrString'], kwargs: 'CompileKW') -> bool:
code = args[0]
+ compiler = None
if isinstance(code, mesonlib.File):
code = mesonlib.File.from_absolute_file(
code.rel_to_builddir(self.environment.source_dir))
+ suffix = code.suffix
+ if suffix not in self.compiler.file_suffixes:
+ for_machine = self.compiler.for_machine
+ clist = self.interpreter.coredata.compilers[for_machine]
+ if suffix not in SUFFIX_TO_LANG:
+ # just pass it to the compiler driver
+ mlog.warning(f'Unknown suffix for test file {code}')
+ elif SUFFIX_TO_LANG[suffix] not in clist:
+ mlog.warning(f'Passed {SUFFIX_TO_LANG[suffix]} source to links method, not specified for {for_machine.get_lower_case_name()} machine.')
+ else:
+ compiler = clist[SUFFIX_TO_LANG[suffix]]
+
testname = kwargs['name']
extra_args = functools.partial(self._determine_args, kwargs['no_builtin_args'], kwargs['include_directories'], kwargs['args'])
deps, msg = self._determine_dependencies(kwargs['dependencies'])
result, cached = self.compiler.links(code, self.environment,
+ compiler=compiler,
extra_args=extra_args,
dependencies=deps)
cached_msg = mlog.blue('(cached)') if cached else ''