[pygobject/91-master: 4/5] setup.py: Fix MSVC builds



commit 4fd6b1f3577aba1ddf8efff8f5cd81a487a50375
Author: Chun-wei Fan <fanchunwei src gnome org>
Date:   Mon Oct 1 15:03:41 2018 +0800

    setup.py: Fix MSVC builds
    
    The distutils C Compiler object for MSVC does not have a compiler
    sub-attribute, so check the compiler type before we try to use that
    sub-attribute.  This will fix builds on MSVC using distutils.
    
    Also, in place of checking the various GCC/CLang compiler flags for
    compile-type warnings we want to look out for, force-include
    msvc_recommended_pragmas.h when we are building with Visual Studio, as
    we are doing in the other GNOME projects, to achive similar effects.

 setup.py | 143 +++++++++++++++++++++++++++++++++------------------------------
 1 file changed, 75 insertions(+), 68 deletions(-)
---
diff --git a/setup.py b/setup.py
index 902aab25..e53ef561 100755
--- a/setup.py
+++ b/setup.py
@@ -217,7 +217,7 @@ def filter_compiler_arguments(compiler, args):
     """
 
     if compiler.compiler_type == "msvc":
-        # TODO
+        # TODO, not much of need for now.
         return []
 
     extra = []
@@ -891,76 +891,83 @@ def add_ext_pkg_config_dep(ext, compiler_type, name):
 
 
 def add_ext_compiler_flags(ext, compiler, _cache={}):
-    cache_key = compiler.compiler[0]
-    if cache_key not in _cache:
-
-        args = [
-            "-Wall",
-            "-Warray-bounds",
-            "-Wcast-align",
-            "-Wdeclaration-after-statement",
-            "-Wduplicated-branches",
-            "-Wextra",
-            "-Wformat=2",
-            "-Wformat-nonliteral",
-            "-Wformat-security",
-            "-Wimplicit-function-declaration",
-            "-Winit-self",
-            "-Wjump-misses-init",
-            "-Wlogical-op",
-            "-Wmissing-declarations",
-            "-Wmissing-format-attribute",
-            "-Wmissing-include-dirs",
-            "-Wmissing-noreturn",
-            "-Wmissing-prototypes",
-            "-Wnested-externs",
-            "-Wnull-dereference",
-            "-Wold-style-definition",
-            "-Wpacked",
-            "-Wpointer-arith",
-            "-Wrestrict",
-            "-Wreturn-type",
-            "-Wshadow",
-            "-Wsign-compare",
-            "-Wstrict-aliasing",
-            "-Wstrict-prototypes",
-            "-Wundef",
-            "-Wunused-but-set-variable",
-            "-Wwrite-strings",
-        ]
-
-        if sys.version_info[:2] != (3, 4):
+    if compiler.compiler_type == "msvc":
+        # MSVC: Just force-include msvc_recommended_pragmas.h so that
+        #       we can look out for compiler warnings that we really
+        #       want to look out for, and filter out those that don't
+        #       really matter to us.
+        ext.extra_compile_args += ['-FImsvc_recommended_pragmas.h']
+    else:
+        cache_key = compiler.compiler[0]
+        if cache_key not in _cache:
+
+            args = [
+                "-Wall",
+                "-Warray-bounds",
+                "-Wcast-align",
+                "-Wdeclaration-after-statement",
+                "-Wduplicated-branches",
+                "-Wextra",
+                "-Wformat=2",
+                "-Wformat-nonliteral",
+                "-Wformat-security",
+                "-Wimplicit-function-declaration",
+                "-Winit-self",
+                "-Wjump-misses-init",
+                "-Wlogical-op",
+                "-Wmissing-declarations",
+                "-Wmissing-format-attribute",
+                "-Wmissing-include-dirs",
+                "-Wmissing-noreturn",
+                "-Wmissing-prototypes",
+                "-Wnested-externs",
+                "-Wnull-dereference",
+                "-Wold-style-definition",
+                "-Wpacked",
+                "-Wpointer-arith",
+                "-Wrestrict",
+                "-Wreturn-type",
+                "-Wshadow",
+                "-Wsign-compare",
+                "-Wstrict-aliasing",
+                "-Wstrict-prototypes",
+                "-Wundef",
+                "-Wunused-but-set-variable",
+                "-Wwrite-strings",
+            ]
+
+            if sys.version_info[:2] != (3, 4):
+                args += [
+                    "-Wswitch-default",
+                ]
+
             args += [
-                "-Wswitch-default",
+                "-Wno-incompatible-pointer-types-discards-qualifiers",
+                "-Wno-missing-field-initializers",
+                "-Wno-unused-parameter",
+                "-Wno-discarded-qualifiers",
+                "-Wno-sign-conversion",
+                "-Wno-cast-function-type",
+                "-Wno-int-conversion",
             ]
 
-        args += [
-            "-Wno-incompatible-pointer-types-discards-qualifiers",
-            "-Wno-missing-field-initializers",
-            "-Wno-unused-parameter",
-            "-Wno-discarded-qualifiers",
-            "-Wno-sign-conversion",
-            "-Wno-cast-function-type",
-            "-Wno-int-conversion",
-        ]
-
-        # silence clang for unused gcc CFLAGS added by Debian
-        args += [
-            "-Wno-unused-command-line-argument",
-        ]
-
-        args += [
-            "-fno-strict-aliasing",
-            "-fvisibility=hidden",
-        ]
-
-        # force GCC to use colors
-        if hasattr(sys.stdout, "isatty") and sys.stdout.isatty():
-            args.append("-fdiagnostics-color")
-
-        _cache[cache_key] = filter_compiler_arguments(compiler, args)
-
-    ext.extra_compile_args += _cache[cache_key]
+            # silence clang for unused gcc CFLAGS added by Debian
+            args += [
+                "-Wno-unused-command-line-argument",
+            ]
+
+            args += [
+                "-fno-strict-aliasing",
+                "-fvisibility=hidden",
+            ]
+
+            # force GCC to use colors
+            if hasattr(sys.stdout, "isatty") and sys.stdout.isatty():
+                args.append("-fdiagnostics-color")
+
+            _cache[cache_key] = filter_compiler_arguments(compiler, args)
+
+        ext.extra_compile_args += _cache[cache_key]
 
 
 du_build_ext = get_command_class("build_ext")


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