bpo-36235: Fix CFLAGS in distutils customize_compiler() (GH-12236) (G… · python/cpython@37f6971 (original) (raw)
3 files changed
lines changed
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -171,8 +171,8 @@ def customize_compiler(compiler): | ||
171 | 171 | _osx_support.customize_compiler(_config_vars) |
172 | 172 | _config_vars['CUSTOMIZED_OSX_COMPILER'] = 'True' |
173 | 173 | |
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', | |
176 | 176 | 'CCSHARED', 'LDSHARED', 'SO', 'AR', |
177 | 177 | 'ARFLAGS') |
178 | 178 | |
@@ -196,7 +196,7 @@ def customize_compiler(compiler): | ||
196 | 196 | if 'LDFLAGS' in os.environ: |
197 | 197 | ldshared = ldshared + ' ' + os.environ['LDFLAGS'] |
198 | 198 | if 'CFLAGS' in os.environ: |
199 | -cflags = opt + ' ' + os.environ['CFLAGS'] | |
199 | +cflags = cflags + ' ' + os.environ['CFLAGS'] | |
200 | 200 | ldshared = ldshared + ' ' + os.environ['CFLAGS'] |
201 | 201 | if 'CPPFLAGS' in os.environ: |
202 | 202 | cpp = cpp + ' ' + os.environ['CPPFLAGS'] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -8,8 +8,9 @@ | ||
8 | 8 | import textwrap |
9 | 9 | |
10 | 10 | from distutils import sysconfig |
11 | +from distutils.ccompiler import get_default_compiler | |
11 | 12 | from distutils.tests import support |
12 | -from test.test_support import TESTFN | |
13 | +from test.test_support import TESTFN, swap_item | |
13 | 14 | |
14 | 15 | class SysconfigTestCase(support.EnvironGuard, |
15 | 16 | unittest.TestCase): |
@@ -50,6 +51,30 @@ def test_get_python_inc(self): | ||
50 | 51 | python_h = os.path.join(inc_dir, "Python.h") |
51 | 52 | self.assertTrue(os.path.isfile(python_h), python_h) |
52 | 53 | |
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 | + | |
53 | 78 | def test_parse_makefile_base(self): |
54 | 79 | self.makefile = test.test_support.TESTFN |
55 | 80 | fd = open(self.makefile, 'w') |
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. |