Skip to content

Commit 86082c2

Browse files
bpo-36235: Fix CFLAGS in distutils customize_compiler() (GH-12236)
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@redhat.com>
1 parent 65f64b1 commit 86082c2

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

Lib/distutils/sysconfig.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,8 @@ def customize_compiler(compiler):
181181
_osx_support.customize_compiler(_config_vars)
182182
_config_vars['CUSTOMIZED_OSX_COMPILER'] = 'True'
183183

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',
186186
'CCSHARED', 'LDSHARED', 'SHLIB_SUFFIX', 'AR', 'ARFLAGS')
187187

188188
if 'CC' in os.environ:
@@ -205,7 +205,7 @@ def customize_compiler(compiler):
205205
if 'LDFLAGS' in os.environ:
206206
ldshared = ldshared + ' ' + os.environ['LDFLAGS']
207207
if 'CFLAGS' in os.environ:
208-
cflags = opt + ' ' + os.environ['CFLAGS']
208+
cflags = cflags + ' ' + os.environ['CFLAGS']
209209
ldshared = ldshared + ' ' + os.environ['CFLAGS']
210210
if 'CPPFLAGS' in os.environ:
211211
cpp = cpp + ' ' + os.environ['CPPFLAGS']

Lib/distutils/tests/test_sysconfig.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from distutils import sysconfig
1010
from distutils.ccompiler import get_default_compiler
1111
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
1313

1414
class SysconfigTestCase(support.EnvironGuard, unittest.TestCase):
1515
def setUp(self):
@@ -78,7 +78,9 @@ def test_srcdir_independent_of_cwd(self):
7878
'not testing if default compiler is not unix')
7979
def test_customize_compiler(self):
8080
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'
8284

8385
# make sure AR gets caught
8486
class compiler:
@@ -87,9 +89,14 @@ class compiler:
8789
def set_executables(self, **kw):
8890
self.exes = kw
8991

92+
# Make sure that sysconfig._config_vars is initialized
93+
sysconfig.get_config_vars()
94+
9095
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')
93100

94101
def test_parse_makefile_base(self):
95102
self.makefile = TESTFN
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff 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.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy