diff options
-rwxr-xr-x | environment.py | 5 | ||||
-rwxr-xr-x | interpreter.py | 11 | ||||
-rw-r--r-- | test cases/common/37 has header/meson.build | 11 |
3 files changed, 27 insertions, 0 deletions
diff --git a/environment.py b/environment.py index 1660656..46aa349 100755 --- a/environment.py +++ b/environment.py @@ -109,6 +109,11 @@ class CCompiler(): if pe.returncode != 0: raise EnvironmentException('Executables created by C compiler %s are not runnable.' % self.name_string()) + def has_header(self, hname): + templ = '''#include<%s> +''' + return self.compiles(templ % hname) + def compiles(self, code): suflen = len(self.default_suffix) (fd, srcname) = tempfile.mkstemp(suffix='.'+self.default_suffix) diff --git a/interpreter.py b/interpreter.py index dc5f0e9..438883f 100755 --- a/interpreter.py +++ b/interpreter.py @@ -560,6 +560,7 @@ class CompilerHolder(InterpreterObject): self.methods.update({'compiles': self.compiles_method, 'get_id': self.get_id_method, 'sizeof': self.sizeof_method, + 'has_header': self.has_header_method, }) def get_id_method(self, args, kwargs): @@ -585,6 +586,16 @@ class CompilerHolder(InterpreterObject): if not isinstance(string, str): raise InterpreterException('Argument to compiles() must be a string') return self.compiler.compiles(string) + + def has_header_method(self, args, kwargs): + if len(args) != 1: + raise InterpreterException('has_header method takes exactly one argument.') + string = args[0] + if isinstance(string, nodes.StringStatement): + string = string.value + if not isinstance(string, str): + raise InterpreterException('Argument to has_header() must be a string') + return self.compiler.has_header(string) class MesonMain(InterpreterObject): def __init__(self, build): diff --git a/test cases/common/37 has header/meson.build b/test cases/common/37 has header/meson.build new file mode 100644 index 0000000..bbfce6d --- /dev/null +++ b/test cases/common/37 has header/meson.build @@ -0,0 +1,11 @@ +project('has header', 'c') + +cc = meson.get_compiler('c') + +if cc.has_header('stdio.h') == false + error('Stdio missing.') +endif + +if cc.has_header('ouagadougou.h') + error('Found non-existant header.') +endif |