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
distutils.sysconfig.customize_compiler() overrides CFLAGS var with OPT var if CFLAGS env var is set #80416
Comments
When a C extension is built by distutils, distutils.sysconfig.customize_compiler() is used to configure compiler flags. Extract of the code:
If the CFLAGS environment variable is set, the 'CFLAGS' configuration variable is overriden with the 'OPT' configuration variable: cflags = opt + ... This bug has been fixed since 2013 in Fedora and RHEL by this patch: RHEL bug report: I converted that patch to a pull request. |
This appears to be a duplicate of bpo-969718. |
After this patch, test_distutils failed if $CPPFLAGS is not empty when building CPython. For example: $ export CPPFLAGS=-DFOO=BAR
$ ./configure
$ make
$ ./python -m test test_distutils
Run tests sequentially
0:00:00 load avg: 0.45 [1/1] test_distutils
test test_distutils failed -- Traceback (most recent call last):
File "/home/yen/Projects/cpython/Lib/distutils/tests/test_sysconfig.py", line 99, in test_customize_compiler
self.assertEqual(comp.exes['compiler'], 'my_cc --sysconfig-cflags --mycflags')
AssertionError: 'my_cc --sysconfig-cflags --mycflags -DFOO=BAR' != 'my_cc --sysconfig-cflags --mycflags'
- my_cc --sysconfig-cflags --mycflags -DFOO=BAR
? + my_cc --sysconfig-cflags --mycflags test_distutils failed == Tests result: FAILURE == 1 test failed: Total duration: 2 sec 192 ms Tested with commit d2fdd1f. This is an issue as Arch Linux uses CPPFLAGS="-D_FORTIFY_SOURCE=2" for creating packages [1]. [1] https://git.archlinux.org/svntogit/packages.git/tree/trunk/makepkg.conf?h=packages/pacman#n39 |
Chih-Hsuan Yen: After this patch, test_distutils failed if $CPPFLAGS is not empty when building CPython. Aha, more sysconfig configuration variables and environment variables should be mocked. I wrote PR 12403 to mock all variables. Would you mind to test and review it? |
STINNER Victor: Thank you very much for that much better fix! I've tested it on Arch Linux. With that patch, test_distutils passes as usual. The pull request looks good, too. Just a question: I think it should be backported to 3.7 and 2.7 branches like #12236? |
Right, I wrote PRs for that. I didn't use GitHub labels because the bot is currently broken. |
Thanks for the review, I merged my PR and the test enhancements. |
Oh, I didn't know the bot is not working for now. Thank you for making the test more robust! |
Oh, the test failed on Python 2.7 on macOS: x86-64 High Sierra 2.7 ====================================================================== Traceback (most recent call last):
File "/Users/buildbot/buildarea/2.7.billenstein-sierra/build/Lib/distutils/tests/test_sysconfig.py", line 134, in test_customize_compiler
'sc_cc -E')
AssertionError: '/usr/bin/clang -E' != 'sc_cc -E' |
Good, my change fixed x86-64 High Sierra 2.7 buildbot: I wrote PR 12764 to forward-port the fix to the master branch. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: