From a93959248b0d8168c5090bf30d0093e72eb07482 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Fri, 15 Mar 2019 14:57:52 +0100 Subject: [PATCH] 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 (cherry picked from commit 86082c22d23285995a32aabb491527c9f5629556) --- Lib/distutils/sysconfig.py | 6 ++--- Lib/distutils/tests/test_sysconfig.py | 27 ++++++++++++++++++- .../2019-03-08-13-32-21.bpo-36235._M72wU.rst | 4 +++ 3 files changed, 33 insertions(+), 4 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2019-03-08-13-32-21.bpo-36235._M72wU.rst diff --git a/Lib/distutils/sysconfig.py b/Lib/distutils/sysconfig.py index de7da1d41394f0..8f49dac6b12b10 100644 --- a/Lib/distutils/sysconfig.py +++ b/Lib/distutils/sysconfig.py @@ -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') @@ -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'] diff --git a/Lib/distutils/tests/test_sysconfig.py b/Lib/distutils/tests/test_sysconfig.py index eb4d27c39efd0e..2be5d245f9d9d7 100644 --- a/Lib/distutils/tests/test_sysconfig.py +++ b/Lib/distutils/tests/test_sysconfig.py @@ -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): @@ -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') diff --git a/Misc/NEWS.d/next/Library/2019-03-08-13-32-21.bpo-36235._M72wU.rst b/Misc/NEWS.d/next/Library/2019-03-08-13-32-21.bpo-36235._M72wU.rst new file mode 100644 index 00000000000000..59df98c101afca --- /dev/null +++ b/Misc/NEWS.d/next/Library/2019-03-08-13-32-21.bpo-36235._M72wU.rst @@ -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. 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