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.
This commit is contained in:
parent
2997480ee6
commit
90ee43463f
|
@ -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 = '<binary>'
|
||||
|
||||
# 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)
|
||||
|
||||
|
|
Loading…
Reference in New Issue