aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/compilers.py
diff options
context:
space:
mode:
authorNirbheek Chauhan <nirbheek.chauhan@gmail.com>2016-08-27 19:56:23 +0530
committerJussi Pakkanen <jpakkane@gmail.com>2016-08-27 17:26:23 +0300
commit7830cb61c39fbaf57933ac403dcdf5007667d87d (patch)
tree8f57d828570cc45118d185caa3b13f848d6226f0 /mesonbuild/compilers.py
parentb7392bb2902cc5d666970c5ace7aa5de78d052e3 (diff)
downloadmeson-7830cb61c39fbaf57933ac403dcdf5007667d87d.zip
meson-7830cb61c39fbaf57933ac403dcdf5007667d87d.tar.gz
meson-7830cb61c39fbaf57933ac403dcdf5007667d87d.tar.bz2
Add a new compiler object method: has_members (#723)
* Add a new compiler object method: has_members Identical to 'cc.has_member', except that this takes multiple members and all of them must exist else it returns false. This is useful when you want to verify that a structure has all of a given set of fields. Individually checking each member is horrifying. * Fix typo in exceptions for has_member(s)
Diffstat (limited to 'mesonbuild/compilers.py')
-rw-r--r--mesonbuild/compilers.py19
1 files changed, 12 insertions, 7 deletions
diff --git a/mesonbuild/compilers.py b/mesonbuild/compilers.py
index 58444bb..1c6c1da 100644
--- a/mesonbuild/compilers.py
+++ b/mesonbuild/compilers.py
@@ -902,16 +902,21 @@ int main(int argc, char **argv) {
# directly try to link via main().
return self.links('int main() {{ {0}; }}'.format('__builtin_' + funcname), env, args)
- def has_member(self, typename, membername, prefix, env, extra_args=None):
+ def has_members(self, typename, membernames, prefix, env, extra_args=None):
if extra_args is None:
extra_args = []
- templ = '''%s
-void bar() {
- %s foo;
- foo.%s;
-};
+ templ = '''{0}
+void bar() {{
+ {1} {2};
+ {3}
+}};
'''
- return self.compiles(templ % (prefix, typename, membername), env, extra_args)
+ # Create code that accesses all members
+ members = ''
+ for m in membernames:
+ members += 'foo.{};\n'.format(m)
+ code = templ.format(prefix, typename, 'foo', members)
+ return self.compiles(code, env, extra_args)
def has_type(self, typename, prefix, env, extra_args):
templ = '''%s