Blame flags/assertflags.py
|
|
96fbcc5 |
"""
|
|
|
96fbcc5 |
This script asserts that Python config vars with compiler options including
|
|
|
96fbcc5 |
one or more -O flags have the last specified -O flag equal to the script's
|
|
|
96fbcc5 |
first argument.
|
|
|
96fbcc5 |
|
|
|
96fbcc5 |
We use it to check that the debug build (as well as extension modules) was
|
|
|
96fbcc5 |
built with a desired optimization level (usually -Og or -O0).
|
|
|
96fbcc5 |
|
|
|
96fbcc5 |
About -O flags: https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html
|
|
|
96fbcc5 |
"If you use multiple -O options, with or without level numbers,
|
|
|
96fbcc5 |
the last such option is the one that is effective."
|
|
|
96fbcc5 |
"""
|
|
|
96fbcc5 |
|
|
|
96fbcc5 |
import sys
|
|
|
96fbcc5 |
import sysconfig
|
|
|
96fbcc5 |
|
|
|
96fbcc5 |
# The flags that currently don't have the -Og flag on the debug build
|
|
|
96fbcc5 |
# and we consider it OK, because we don't know any better :)
|
|
|
96fbcc5 |
WHITELIST = [
|
|
|
96fbcc5 |
'CONFIGURE_CFLAGS',
|
|
|
96fbcc5 |
'CONFIGURE_CFLAGS_NODIST',
|
|
|
96fbcc5 |
'CONFIG_ARGS',
|
|
|
96fbcc5 |
'OPT',
|
|
|
96fbcc5 |
]
|
|
|
96fbcc5 |
|
|
|
96fbcc5 |
print('Expecting that {} is the last -O flag:\n'.format(sys.argv[1]))
|
|
|
96fbcc5 |
ret = 0
|
|
|
96fbcc5 |
|
|
|
96fbcc5 |
for key, flags in sysconfig.get_config_vars().items():
|
|
|
96fbcc5 |
if key in WHITELIST:
|
|
|
96fbcc5 |
continue
|
|
|
96fbcc5 |
if isinstance(flags, str):
|
|
|
96fbcc5 |
oflags = [f for f in flags.split(' ') if f.startswith('-O')]
|
|
|
96fbcc5 |
if oflags and oflags[-1] != sys.argv[1]:
|
|
|
96fbcc5 |
print('Problem in {} -O flags: {}'.format(key, ' '.join(oflags)))
|
|
|
96fbcc5 |
ret = 1
|
|
|
96fbcc5 |
elif oflags:
|
|
|
96fbcc5 |
print('{} are OK'.format(key))
|
|
|
96fbcc5 |
|
|
|
96fbcc5 |
sys.exit(ret)
|