From 90ee43463f4844b667d26230ef7773f63fcf60dd Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Thu, 22 Jul 2021 12:29:22 +0200 Subject: compilers: allow link tests to use objects from a different compiler In some cases, link tests would like to use objects provided by a compiler for a different language, for example linking a C object file with a C++ compiler. This kind of scenario is what link_language is for, but it is impossible to test that it works with a linker test. This patch implements the required support in the Compiler class. The source code compiler is passed to the Compiler.links method as an argument. --- mesonbuild/compilers/compilers.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'mesonbuild/compilers/compilers.py') diff --git a/mesonbuild/compilers/compilers.py b/mesonbuild/compilers/compilers.py index 157d2a8..3d3e57e 100644 --- a/mesonbuild/compilers/compilers.py +++ b/mesonbuild/compilers/compilers.py @@ -775,8 +775,11 @@ class Compiler(HoldableObject, metaclass=abc.ABCMeta): contents = code else: srcname = code.fname - with open(code.fname, encoding='utf-8') as f: - contents = f.read() + if not is_object(code.fname): + with open(code.fname, encoding='utf-8') as f: + contents = f.read() + else: + contents = '' # Construct the compiler command-line commands = self.compiler_args() @@ -1234,10 +1237,17 @@ class Compiler(HoldableObject, metaclass=abc.ABCMeta): return p.returncode == 0, p.cached def links(self, code: 'mesonlib.FileOrString', env: 'Environment', *, + compiler: T.Optional['Compiler'] = None, extra_args: T.Union[None, T.List[str], CompilerArgs, T.Callable[[CompileCheckMode], T.List[str]]] = None, dependencies: T.Optional[T.List['Dependency']] = None, mode: str = 'compile', disable_cache: bool = False) -> T.Tuple[bool, bool]: + if compiler: + with compiler._build_wrapper(code, env, dependencies=dependencies, want_output=True) as r: + objfile = mesonlib.File.from_absolute_file(r.output_name) + return self.compiles(objfile, env, extra_args=extra_args, + dependencies=dependencies, mode='link', disable_cache=True) + return self.compiles(code, env, extra_args=extra_args, dependencies=dependencies, mode='link', disable_cache=disable_cache) -- cgit v1.1