From 40d121d33ee10004c0018df2f8ec2665569ff2db Mon Sep 17 00:00:00 2001 From: Christoph Behle Date: Sun, 10 Jun 2018 21:32:45 +0200 Subject: 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. --- mesonbuild/compilers/c.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'mesonbuild/compilers') 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
.*([^\\]")|^")(?P([^\\"]|\\.)*)"\s+"(?P([^\\"]|\\.)*)(?P".*)')
+        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)
-- 
cgit v1.1