Skip to content

[2.7] bpo-36235: Fix CFLAGS in distutils customize_compiler() (GH-12236) #12349

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Lib/distutils/sysconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@ def customize_compiler(compiler):
_osx_support.customize_compiler(_config_vars)
_config_vars['CUSTOMIZED_OSX_COMPILER'] = 'True'

(cc, cxx, opt, cflags, ccshared, ldshared, so_ext, ar, ar_flags) = \
get_config_vars('CC', 'CXX', 'OPT', 'CFLAGS',
(cc, cxx, cflags, ccshared, ldshared, so_ext, ar, ar_flags) = \
get_config_vars('CC', 'CXX', 'CFLAGS',
'CCSHARED', 'LDSHARED', 'SO', 'AR',
'ARFLAGS')

Expand All @@ -196,7 +196,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']
Expand Down
27 changes: 26 additions & 1 deletion Lib/distutils/tests/test_sysconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
import textwrap

from distutils import sysconfig
from distutils.ccompiler import get_default_compiler
from distutils.tests import support
from test.test_support import TESTFN
from test.test_support import TESTFN, swap_item

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

@unittest.skipUnless(get_default_compiler() == 'unix',
'not testing if default compiler is not unix')
def test_customize_compiler(self):
os.environ['AR'] = 'my_ar'
os.environ['CC'] = 'my_cc'
os.environ['ARFLAGS'] = '--myarflags'
os.environ['CFLAGS'] = '--mycflags'

# make sure AR gets caught
class compiler:
compiler_type = 'unix'

def set_executables(self, **kw):
self.exes = kw

# Make sure that sysconfig._config_vars is initialized
sysconfig.get_config_vars()

comp = compiler()
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 = test.test_support.TESTFN
fd = open(self.makefile, 'w')
Expand Down
Original file line number Diff line number Diff line change
@@ -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.