diff options
author | Christoph Behle <behlec@gmail.com> | 2018-06-10 21:32:45 +0200 |
---|---|---|
committer | Nirbheek Chauhan <nirbheek.chauhan@gmail.com> | 2018-06-12 00:14:54 +0000 |
commit | 40d121d33ee10004c0018df2f8ec2665569ff2db (patch) | |
tree | fdefbdb24a93ac457467b55746bba65fbcf6b26c /mesonbuild/compilers/c.py | |
parent | bbb893f39e0bf7424a7104dcc15b449c69b9103e (diff) | |
download | meson-40d121d33ee10004c0018df2f8ec2665569ff2db.zip meson-40d121d33ee10004c0018df2f8ec2665569ff2db.tar.gz meson-40d121d33ee10004c0018df2f8ec2665569ff2db.tar.bz2 |
get_define can concatenate string literals.
Added method concatenate_string_literals to CCompiler. Will concatenate
string literals.
Added keyword argument 'concatenate_string_literals' to Compiler.get_define.
If used will apply concatenate_string_literals to its return value.
Diffstat (limited to 'mesonbuild/compilers/c.py')
-rw-r--r-- | mesonbuild/compilers/c.py | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/mesonbuild/compilers/c.py b/mesonbuild/compilers/c.py index 6145574..dc7a9f5 100644 --- a/mesonbuild/compilers/c.py +++ b/mesonbuild/compilers/c.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -import subprocess, os.path +import subprocess, os.path, re from .. import mlog from .. import coredata @@ -934,6 +934,15 @@ class CCompiler(Compiler): code = 'int main(int argc, char **argv) { return 0; }' return self.has_arguments(args, env, code, mode='link') + def concatenate_string_literals(self, s): + pattern = re.compile(r'(?P<pre>.*([^\\]")|^")(?P<str1>([^\\"]|\\.)*)"\s+"(?P<str2>([^\\"]|\\.)*)(?P<post>".*)') + ret = s + m = pattern.match(ret) + while m: + ret = ''.join(m.group('pre', 'str1', 'str2', 'post')) + m = pattern.match(ret) + return ret + class ClangCCompiler(ClangCompiler, CCompiler): def __init__(self, exelist, version, clang_type, is_cross, exe_wrapper=None, **kwargs): CCompiler.__init__(self, exelist, version, is_cross, exe_wrapper, **kwargs) |