8000 Fix setup.py when CC contains -std=c11 option · python/pythoncapi-compat@98228e6 · GitHub
[go: up one dir, main page]

Skip to content

Commit 98228e6

Browse files
committed
Fix setup.py when CC contains -std=c11 option
Fix setup.py when the C compiler command has the "-std=c11" option. Remove "-std=" options from the compiler command.
1 parent a01e63e commit 98228e6

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

tests/setup.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/usr/bin/env python3
22
import os.path
3+
import shlex
34
import sys
5+
import sysconfig
46

57

68
# C++ is only supported on Python 3.6 and newer
@@ -48,6 +50,24 @@ def main():
4850
except ImportError:
4951
from distutils.core import setup, Extension
5052

53+
# gh-105776: When "gcc -std=11" is used as the C++ compiler, -std=c11
54+
# option emits a C++ compiler warning. Remove "-std11" option from the
55+
# CC command.
56+
cmd = (sysconfig.get_config_var('CC') or '')
57+
if cmd is not None:
58+
cmd = shlex.split(cmd)
59+
cmd = [arg for arg in cmd if not arg.startswith('-std=')]
60+
if (sys.version_info >= (3, 8)):
61+
cmd = shlex.join(cmd)
62+
elif (sys.version_info >= (3, 3)):
63+
cmd = ' '.join(shlex.quote(arg) for arg in cmd)
64+
else:
65+
# Python 2.7
66+
import pipes
67+
cmd = ' '.join(pipes.quote(arg) for arg in cmd)
68+
# CC env var overrides sysconfig CC variable in setuptools
69+
os.environ['CC'] = cmd
70+
5171
cflags = ['-I' + SRC_DIR]
5272
cppflags = list(cflags)
5373
if not MSVC:

0 commit comments

Comments
 (0)
0