diff options
| author | Victor Stinner <vstinner@redhat.com> | 2019-03-15 14:57:52 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-03-15 14:57:52 +0100 |
| commit | 1078515edfad6bf60085a2611fe24ffd497474ca (patch) | |
| tree | 932b8f39461d9c947d8afa456b6a03f65ebd5958 | |
| parent | f3e20900c492253924944707f390a9c12d7a30fd (diff) | |
| download | python-setuptools-git-1078515edfad6bf60085a2611fe24ffd497474ca.tar.gz | |
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>
| -rw-r--r-- | sysconfig.py | 6 | ||||
| -rw-r--r-- | tests/test_sysconfig.py | 15 |
2 files changed, 14 insertions, 7 deletions
diff --git a/sysconfig.py b/sysconfig.py index 40af493c..a3494670 100644 --- a/sysconfig.py +++ b/sysconfig.py @@ -181,8 +181,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: @@ -205,7 +205,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/tests/test_sysconfig.py b/tests/test_sysconfig.py index fe4a2994..4bf6a067 100644 --- a/tests/test_sysconfig.py +++ b/tests/test_sysconfig.py @@ -9,7 +9,7 @@ import unittest 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 @@ class SysconfigTestCase(support.EnvironGuard, unittest.TestCase): '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 SysconfigTestCase(support.EnvironGuard, unittest.TestCase): 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 |
