[Python-checkins] bpo-36235: Fix CFLAGS in distutils customize_compiler() (GH-12236) (GH-12348)
Victor Stinner
webhook-mailer at python.org
Fri Mar 15 11:03:53 EDT 2019
https://github.com/python/cpython/commit/6c0e0d141a07cc3fd2441d9df8d762f56bf7edf2
commit: 6c0e0d141a07cc3fd2441d9df8d762f56bf7edf2
branch: 3.7
author: Victor Stinner <vstinner at redhat.com>
committer: GitHub <noreply at github.com>
date: 2019-03-15T16:03:50+01:00
summary:
bpo-36235: Fix CFLAGS in distutils customize_compiler() (GH-12236) (GH-12348)
Fix CFLAGS in customize_compiler() of distutils.sysconfig: when the
CFLAGS environment variable is defined, don't override CFLAGS variable with
the OPT variable anymore.
Initial patch written by David Malcolm.
Co-Authored-By: David Malcolm <dmalcolm at redhat.com>
(cherry picked from commit 86082c22d23285995a32aabb491527c9f5629556)
files:
A Misc/NEWS.d/next/Library/2019-03-08-13-32-21.bpo-36235._M72wU.rst
M Lib/distutils/sysconfig.py
M Lib/distutils/tests/test_sysconfig.py
diff --git a/Lib/distutils/sysconfig.py b/Lib/distutils/sysconfig.py
index 83160f8dcc59..f803a1d13ac8 100644
--- a/Lib/distutils/sysconfig.py
+++ b/Lib/distutils/sysconfig.py
@@ -183,8 +183,8 @@ def customize_compiler(compiler):
_osx_support.customize_compiler(_config_vars)
_config_vars['CUSTOMIZED_OSX_COMPILER'] = 'True'
- (cc, cxx, opt, cflags, ccshared, ldshared, shlib_suffix, ar, ar_flags) = \
- get_config_vars('CC', 'CXX', 'OPT', 'CFLAGS',
+ (cc, cxx, cflags, ccshared, ldshared, shlib_suffix, ar, ar_flags) = \
+ get_config_vars('CC', 'CXX', 'CFLAGS',
'CCSHARED', 'LDSHARED', 'SHLIB_SUFFIX', 'AR', 'ARFLAGS')
if 'CC' in os.environ:
@@ -207,7 +207,7 @@ def customize_compiler(compiler):
if 'LDFLAGS' in os.environ:
ldshared = ldshared + ' ' + os.environ['LDFLAGS']
if 'CFLAGS' in os.environ:
- cflags = opt + ' ' + os.environ['CFLAGS']
+ cflags = cflags + ' ' + os.environ['CFLAGS']
ldshared = ldshared + ' ' + os.environ['CFLAGS']
if 'CPPFLAGS' in os.environ:
cpp = cpp + ' ' + os.environ['CPPFLAGS']
diff --git a/Lib/distutils/tests/test_sysconfig.py b/Lib/distutils/tests/test_sysconfig.py
index fe4a2994e3b0..4bf6a067d4d9 100644
--- a/Lib/distutils/tests/test_sysconfig.py
+++ b/Lib/distutils/tests/test_sysconfig.py
@@ -9,7 +9,7 @@
from distutils import sysconfig
from distutils.ccompiler import get_default_compiler
from distutils.tests import support
-from test.support import TESTFN, run_unittest, check_warnings
+from test.support import TESTFN, run_unittest, check_warnings, swap_item
class SysconfigTestCase(support.EnvironGuard, unittest.TestCase):
def setUp(self):
@@ -78,7 +78,9 @@ def test_srcdir_independent_of_cwd(self):
'not testing if default compiler is not unix')
def test_customize_compiler(self):
os.environ['AR'] = 'my_ar'
- os.environ['ARFLAGS'] = '-arflags'
+ os.environ['CC'] = 'my_cc'
+ os.environ['ARFLAGS'] = '--myarflags'
+ os.environ['CFLAGS'] = '--mycflags'
# make sure AR gets caught
class compiler:
@@ -87,9 +89,14 @@ class compiler:
def set_executables(self, **kw):
self.exes = kw
+ # Make sure that sysconfig._config_vars is initialized
+ sysconfig.get_config_vars()
+
comp = compiler()
- sysconfig.customize_compiler(comp)
- self.assertEqual(comp.exes['archiver'], 'my_ar -arflags')
+ with swap_item(sysconfig._config_vars, 'CFLAGS', '--sysconfig-cflags'):
+ sysconfig.customize_compiler(comp)
+ self.assertEqual(comp.exes['archiver'], 'my_ar --myarflags')
+ self.assertEqual(comp.exes['compiler'], 'my_cc --sysconfig-cflags --mycflags')
def test_parse_makefile_base(self):
self.makefile = TESTFN
diff --git a/Misc/NEWS.d/next/Library/2019-03-08-13-32-21.bpo-36235._M72wU.rst b/Misc/NEWS.d/next/Library/2019-03-08-13-32-21.bpo-36235._M72wU.rst
new file mode 100644
index 000000000000..59df98c101af
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2019-03-08-13-32-21.bpo-36235._M72wU.rst
@@ -0,0 +1,4 @@
+Fix ``CFLAGS`` in ``customize_compiler()`` of ``distutils.sysconfig``: when
+the ``CFLAGS`` environment variable is defined, don't override ``CFLAGS``
+variable with the ``OPT`` variable anymore. Initial patch written by David
+Malcolm.
More information about the Python-checkins
mailing list