Allow passing files to compile/link/run queries.

pull/833/head
Elliott Sales de Andrade 8 years ago
parent 51341ce177
commit f2fed5052d
  1. 11
      mesonbuild/compilers.py
  2. 18
      mesonbuild/interpreter.py

@ -614,10 +614,13 @@ int main () {{ {1}; }}'''
try:
with tempfile.TemporaryDirectory() as tmpdirname:
srcname = os.path.join(tmpdirname,
'testfile.' + self.default_suffix)
with open(srcname, 'w') as ofile:
ofile.write(code)
if isinstance(code, str):
srcname = os.path.join(tmpdirname,
'testfile.' + self.default_suffix)
with open(srcname, 'w') as ofile:
ofile.write(code)
elif isinstance(code, mesonlib.File):
srcname = code.fname
# Extension only matters if running results; '.exe' is
# guaranteed to be executable on every platform.

@ -698,8 +698,12 @@ class CompilerHolder(InterpreterObject):
def run_method(self, args, kwargs):
if len(args) != 1:
raise InterpreterException('Run method takes exactly one positional argument.')
check_stringlist(args)
code = args[0]
if isinstance(code, mesonlib.File):
code = mesonlib.File.from_absolute_file(
code.rel_to_builddir(self.environment.source_dir))
elif not isinstance(code, str):
raise InvalidArguments('Argument must be string or file.')
testname = kwargs.get('name', '')
if not isinstance(testname, str):
raise InterpreterException('Testname argument must be a string.')
@ -819,8 +823,12 @@ class CompilerHolder(InterpreterObject):
def compiles_method(self, args, kwargs):
if len(args) != 1:
raise InterpreterException('compiles method takes exactly one argument.')
check_stringlist(args)
code = args[0]
if isinstance(code, mesonlib.File):
code = mesonlib.File.from_absolute_file(
code.rel_to_builddir(self.environment.source_dir))
elif not isinstance(code, str):
raise InvalidArguments('Argument must be string or file.')
testname = kwargs.get('name', '')
if not isinstance(testname, str):
raise InterpreterException('Testname argument must be a string.')
@ -838,8 +846,12 @@ class CompilerHolder(InterpreterObject):
def links_method(self, args, kwargs):
if len(args) != 1:
raise InterpreterException('links method takes exactly one argument.')
check_stringlist(args)
code = args[0]
if isinstance(code, mesonlib.File):
code = mesonlib.File.from_absolute_file(
code.rel_to_builddir(self.environment.source_dir))
elif not isinstance(code, str):
raise InvalidArguments('Argument must be string or file.')
testname = kwargs.get('name', '')
if not isinstance(testname, str):
raise InterpreterException('Testname argument must be a string.')

Loading…
Cancel
Save