]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Check for compiler warnings in test_cext on Windows (#121088)
authorVictor Stinner <vstinner@python.org>
Fri, 28 Jun 2024 12:41:37 +0000 (14:41 +0200)
committerGitHub <noreply@github.com>
Fri, 28 Jun 2024 12:41:37 +0000 (14:41 +0200)
On Windows, test_cext and test_cppext now pass /WX flag to the MSC
compiler to treat all compiler warnings as errors. In verbose mode,
these tests now log the compiler commands to help debugging.

Change Py_BUILD_ASSERT_EXPR implementation on Windows to avoid a
compiler warning about an unnamed structure.

Include/pymacro.h
Lib/test/test_cext/__init__.py
Lib/test/test_cext/setup.py
Lib/test/test_cppext/__init__.py
Lib/test/test_cppext/setup.py

index b388c2a4a663ce2341197be17df6b424bb61db79..a7945ef84a46fcf8d594c4763443ea675ed86457 100644 (file)
@@ -46,7 +46,8 @@
 /* Argument must be a char or an int in [-128, 127] or [0, 255]. */
 #define Py_CHARMASK(c) ((unsigned char)((c) & 0xff))
 
-#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
+#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L \
+     && !defined(_MSC_VER))
 #  define Py_BUILD_ASSERT_EXPR(cond) \
     ((void)sizeof(struct { int dummy; _Static_assert(cond, #cond); }), \
      0)
index ec44b0ce1f8a56f7b8b3964bdf1423fdcf6347ce..54859f9ff7622d13986d3cd86ede568a2b55b3fe 100644 (file)
@@ -86,6 +86,8 @@ class TestExt(unittest.TestCase):
         cmd = [python_exe, '-X', 'dev',
                '-m', 'pip', 'install', '--no-build-isolation',
                os.path.abspath(pkg_dir)]
+        if support.verbose:
+            cmd.append('-v')
         run_cmd('Install', cmd)
 
         # Do a reference run. Until we test that running python
index 383d256c1eb53b92d5cb0a4a2b0c294b9056a42e..19edc5e663c55dccb4e645965562e323a7540ce3 100644 (file)
@@ -11,6 +11,7 @@ from setuptools import setup, Extension
 
 
 SOURCE = 'extension.c'
+
 if not support.MS_WINDOWS:
     # C compiler flags for GCC and clang
     CFLAGS = [
@@ -28,8 +29,11 @@ if not support.MS_WINDOWS:
             '-Werror=declaration-after-statement',
         )
 else:
-    # Don't pass any compiler flag to MSVC
-    CFLAGS = []
+    # MSVC compiler flags
+    CFLAGS = [
+        # Treat all compiler warnings as compiler errors
+        '/WX',
+    ]
 
 
 def main():
index 00a2840d49c77955593f0acb9f6e27eacb458474..efd79448c6610453af07c7cd2eb7aab768891667 100644 (file)
@@ -76,6 +76,8 @@ class TestCPPExt(unittest.TestCase):
         cmd = [python_exe, '-X', 'dev',
                '-m', 'pip', 'install', '--no-build-isolation',
                os.path.abspath(pkg_dir)]
+        if support.verbose:
+            cmd.append('-v')
         run_cmd('Install', cmd)
 
         # Do a reference run. Until we test that running python
index 80b3e0d5212f7bf84431351f3b433c469ec4bcc1..f1848f2fd42a46bf8edc608442d4fb80e90881f6 100644 (file)
@@ -10,6 +10,7 @@ from setuptools import setup, Extension
 
 
 SOURCE = 'extension.cpp'
+
 if not support.MS_WINDOWS:
     # C++ compiler flags for GCC and clang
     CPPFLAGS = [
@@ -19,8 +20,11 @@ if not support.MS_WINDOWS:
         '-Werror',
     ]
 else:
-    # Don't pass any compiler flag to MSVC
-    CPPFLAGS = []
+    # MSVC compiler flags
+    CPPFLAGS = [
+        # Treat all compiler warnings as compiler errors
+        '/WX',
+    ]
 
 
 def main():