aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/compilers/cpp.py
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2018-10-09 15:15:39 -0700
committerJussi Pakkanen <jpakkane@gmail.com>2018-11-13 00:40:13 +0200
commitde175aac0051b5625e21aeb5b9864ae7c376f9d7 (patch)
tree0b81d8364ccc058c31f9a89db6f3e1bfefd59f4d /mesonbuild/compilers/cpp.py
parentcecad3b9dbe06945c5131570bec9ce1406f4fb8a (diff)
downloadmeson-de175aac0051b5625e21aeb5b9864ae7c376f9d7.zip
meson-de175aac0051b5625e21aeb5b9864ae7c376f9d7.tar.gz
meson-de175aac0051b5625e21aeb5b9864ae7c376f9d7.tar.bz2
compilers: Use keyword only arguments for compiler interfaces
Because we need to inherit them in some cases, and python's keyword-or-positional arguments make this really painful, especially with inheritance. They do this in two ways: 1) If you want to intercept the arguments you need to check for both a keyword and a positional argument, because you could get either. Then you need to make sure that you only pass one of those down to the next layer. 2) After you do that, if the layer below you decides to do the same thing, but uses the other form (you used keyword by the lower level uses positional or vice versa), then you'll get a TypeError since two layers down got the argument as both a positional and a keyword. All of this is bad. Fortunately python 3.x provides a mechanism to solve this, keyword only arguments. These arguments cannot be based positionally, the interpreter will give us an error in that case. I have made a best effort to do this correctly, and I've verified it with GCC, Clang, ICC, and MSVC, but there are other compilers like Arm and Elbrus that I don't have access to.
Diffstat (limited to 'mesonbuild/compilers/cpp.py')
-rw-r--r--mesonbuild/compilers/cpp.py15
1 files changed, 10 insertions, 5 deletions
diff --git a/mesonbuild/compilers/cpp.py b/mesonbuild/compilers/cpp.py
index e6f5803..7d2000e 100644
--- a/mesonbuild/compilers/cpp.py
+++ b/mesonbuild/compilers/cpp.py
@@ -62,9 +62,11 @@ class CPPCompiler(CCompiler):
# too strict without this and always fails.
return super().get_compiler_check_args() + ['-fpermissive']
- def has_header_symbol(self, hname, symbol, prefix, env, extra_args=None, dependencies=None):
+ def has_header_symbol(self, hname, symbol, prefix, env, *, extra_args=None, dependencies=None):
# Check if it's a C-like symbol
- if super().has_header_symbol(hname, symbol, prefix, env, extra_args, dependencies):
+ if super().has_header_symbol(hname, symbol, prefix, env,
+ extra_args=extra_args,
+ dependencies=dependencies):
return True
# Check if it's a class or a template
if extra_args is None:
@@ -74,7 +76,8 @@ class CPPCompiler(CCompiler):
#include <{header}>
using {symbol};
int main () {{ return 0; }}'''
- return self.compiles(t.format(**fargs), env, extra_args, dependencies)
+ return self.compiles(t.format(**fargs), env, extra_args=extra_args,
+ dependencies=dependencies)
def _test_cpp_std_arg(self, cpp_std_value):
# Test whether the compiler understands a -std=XY argument
@@ -246,11 +249,13 @@ class ElbrusCPPCompiler(GnuCPPCompiler, ElbrusCompiler):
# Elbrus C++ compiler does not have lchmod, but there is only linker warning, not compiler error.
# So we should explicitly fail at this case.
- def has_function(self, funcname, prefix, env, extra_args=None, dependencies=None):
+ def has_function(self, funcname, prefix, env, *, extra_args=None, dependencies=None):
if funcname == 'lchmod':
return False
else:
- return super().has_function(funcname, prefix, env, extra_args, dependencies)
+ return super().has_function(funcname, prefix, env,
+ extra_args=extra_args,
+ dependencies=dependencies)
class IntelCPPCompiler(IntelCompiler, CPPCompiler):