Skip to content

Commit 37f6971

Browse files
bpo-36235: Fix CFLAGS in distutils customize_compiler() (GH-12236) (GH-12349)
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> (cherry picked from commit 86082c2)
1 parent b140578 commit 37f6971

File tree

3 files changed

+33
-4
lines changed

3 files changed

+33
-4
lines changed

Lib/distutils/sysconfig.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,8 @@ def customize_compiler(compiler):
171171
_osx_support.customize_compiler(_config_vars)
172172
_config_vars['CUSTOMIZED_OSX_COMPILER'] = 'True'
173173

174-
(cc, cxx, opt, cflags, ccshared, ldshared, so_ext, ar, ar_flags) = \
175-
get_config_vars('CC', 'CXX', 'OPT', 'CFLAGS',
174+
(cc, cxx, cflags, ccshared, ldshared, so_ext, ar, ar_flags) = \
175+
get_config_vars('CC', 'CXX', 'CFLAGS',
176176
'CCSHARED', 'LDSHARED', 'SO', 'AR',
177177
'ARFLAGS')
178178

@@ -196,7 +196,7 @@ def customize_compiler(compiler):
196196
if 'LDFLAGS' in os.environ:
197197
ldshared = ldshared + ' ' + os.environ['LDFLAGS']
198198
if 'CFLAGS' in os.environ:
199-
cflags = opt + ' ' + os.environ['CFLAGS']
199+
cflags = cflags + ' ' + os.environ['CFLAGS']
200200
ldshared = ldshared + ' ' + os.environ['CFLAGS']
201201
if 'CPPFLAGS' in os.environ:
202202
cpp = cpp + ' ' + os.environ['CPPFLAGS']

Lib/distutils/tests/test_sysconfig.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88
import textwrap
99

1010
from distutils import sysconfig
11+
from distutils.ccompiler import get_default_compiler
1112
from distutils.tests import support
12-
from test.test_support import TESTFN
13+
from test.test_support import TESTFN, swap_item
1314

1415
class SysconfigTestCase(support.EnvironGuard,
1516
unittest.TestCase):
@@ -50,6 +51,30 @@ def test_get_python_inc(self):
5051
python_h = os.path.join(inc_dir, "Python.h")
5152
self.assertTrue(os.path.isfile(python_h), python_h)
5253

54+
@unittest.skipUnless(get_default_compiler() == 'unix',
55+
'not testing if default compiler is not unix')
56+
def test_customize_compiler(self):
57+
os.environ['AR'] = 'my_ar'
58+
os.environ['CC'] = 'my_cc'
59+
os.environ['ARFLAGS'] = '--myarflags'
60+
os.environ['CFLAGS'] = '--mycflags'
61+
62+
# make sure AR gets caught
63+
class compiler:
64+
compiler_type = 'unix'
65+
66+
def set_executables(self, **kw):
67+
self.exes = kw
68+
69+
# Make sure that sysconfig._config_vars is initialized
70+
sysconfig.get_config_vars()
71+
72+
comp = compiler()
73+
with swap_item(sysconfig._config_vars, 'CFLAGS', '--sysconfig-cflags'):
74+
sysconfig.customize_compiler(comp)
75+
self.assertEqual(comp.exes['archiver'], 'my_ar --myarflags')
76+
self.assertEqual(comp.exes['compiler'], 'my_cc --sysconfig-cflags --mycflags')
77+
5378
def test_parse_makefile_base(self):
5479
self.makefile = test.test_support.TESTFN
5580
fd = open(self.makefile, 'w')
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