[gobject-introspection/ccompiler.msvc.fixes.3-34: 2/2] giscanner/ccompiler.py: Fix macro defines with quotes on MSVC



commit 0755ac2723738640505986ac6fc446b9b40e4d4a
Author: Chun-wei Fan <fanchunwei src gnome org>
Date:   Thu Oct 31 17:27:08 2019 +0800

    giscanner/ccompiler.py: Fix macro defines with quotes on MSVC
    
    When we save the macros to pass to distutils to compile the dumper
    program, the quotes were not properly preserved for Visual Studio
    builds, causing items such as -DG_LOG_DOMAIN to fail as quotes are used
    in there.
    
    When we use quotes in macro definitions, we escape the escape
    character in ccompiler._set_cpp_options() when we are running
    g-ir-scanner with Visual Studio, so that distutils won't be too eager
    to drop those prematurely.

 giscanner/ccompiler.py | 7 +++++++
 1 file changed, 7 insertions(+)
---
diff --git a/giscanner/ccompiler.py b/giscanner/ccompiler.py
index 35549da2..4ad572c3 100644
--- a/giscanner/ccompiler.py
+++ b/giscanner/ccompiler.py
@@ -444,6 +444,13 @@ class CCompiler(object):
                 else:
                     macro_name = macro[:macro_index]
                     macro_value = macro[macro_index + 1:]
+
+                    # Somehow the quotes used in defining
+                    # macros for compiling using distutils
+                    # get dropped for MSVC builds, so
+                    # escape the escape character.
+                    if isinstance(self.compiler, MSVCCompiler):
+                        macro_value = macro_value.replace('\"', '\\\"')
                 macros.append((macro_name, macro_value))
             elif option.startswith('-U'):
                 macros.append((option[len('-U'):],))


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]