bpo-36235: Fix CFLAGS in distutils customize_compiler() (GH-12236) · python/cpython@86082c2 (original) (raw)

3 files changed

lines changed

Original file line number Diff line number Diff line change
@@ -181,8 +181,8 @@ def customize_compiler(compiler):
181 181 _osx_support.customize_compiler(_config_vars)
182 182 _config_vars['CUSTOMIZED_OSX_COMPILER'] = 'True'
183 183
184 - (cc, cxx, opt, cflags, ccshared, ldshared, shlib_suffix, ar, ar_flags) = \
185 -get_config_vars('CC', 'CXX', 'OPT', 'CFLAGS',
184 + (cc, cxx, cflags, ccshared, ldshared, shlib_suffix, ar, ar_flags) = \
185 +get_config_vars('CC', 'CXX', 'CFLAGS',
186 186 'CCSHARED', 'LDSHARED', 'SHLIB_SUFFIX', 'AR', 'ARFLAGS')
187 187
188 188 if 'CC' in os.environ:
@@ -205,7 +205,7 @@ def customize_compiler(compiler):
205 205 if 'LDFLAGS' in os.environ:
206 206 ldshared = ldshared + ' ' + os.environ['LDFLAGS']
207 207 if 'CFLAGS' in os.environ:
208 -cflags = opt + ' ' + os.environ['CFLAGS']
208 +cflags = cflags + ' ' + os.environ['CFLAGS']
209 209 ldshared = ldshared + ' ' + os.environ['CFLAGS']
210 210 if 'CPPFLAGS' in os.environ:
211 211 cpp = cpp + ' ' + os.environ['CPPFLAGS']
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@
9 9 from distutils import sysconfig
10 10 from distutils.ccompiler import get_default_compiler
11 11 from distutils.tests import support
12 -from test.support import TESTFN, run_unittest, check_warnings
12 +from test.support import TESTFN, run_unittest, check_warnings, swap_item
13 13
14 14 class SysconfigTestCase(support.EnvironGuard, unittest.TestCase):
15 15 def setUp(self):
@@ -78,7 +78,9 @@ def test_srcdir_independent_of_cwd(self):
78 78 'not testing if default compiler is not unix')
79 79 def test_customize_compiler(self):
80 80 os.environ['AR'] = 'my_ar'
81 -os.environ['ARFLAGS'] = '-arflags'
81 +os.environ['CC'] = 'my_cc'
82 +os.environ['ARFLAGS'] = '--myarflags'
83 +os.environ['CFLAGS'] = '--mycflags'
82 84
83 85 # make sure AR gets caught
84 86 class compiler:
@@ -87,9 +89,14 @@ class compiler:
87 89 def set_executables(self, **kw):
88 90 self.exes = kw
89 91
92 +# Make sure that sysconfig._config_vars is initialized
93 +sysconfig.get_config_vars()
94 +
90 95 comp = compiler()
91 -sysconfig.customize_compiler(comp)
92 -self.assertEqual(comp.exes['archiver'], 'my_ar -arflags')
96 +with swap_item(sysconfig._config_vars, 'CFLAGS', '--sysconfig-cflags'):
97 +sysconfig.customize_compiler(comp)
98 +self.assertEqual(comp.exes['archiver'], 'my_ar --myarflags')
99 +self.assertEqual(comp.exes['compiler'], 'my_cc --sysconfig-cflags --mycflags')
93 100
94 101 def test_parse_makefile_base(self):
95 102 self.makefile = TESTFN
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
1 +Fix ``CFLAGS`` in ``customize_compiler()`` of ``distutils.sysconfig``: when
2 +the ``CFLAGS`` environment variable is defined, don't override ``CFLAGS``
3 +variable with the ``OPT`` variable anymore. Initial patch written by David
4 +Malcolm.