From 5ffff08833c151f9a38660a30acfb0357829f8f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= Date: Tue, 10 Sep 2024 17:58:27 +0200 Subject: [PATCH] Do not skip a flag without -O, if the flag is checked explicitly --- flags/assertflags.py | 8 ++++++-- tests.yml | 3 +++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/flags/assertflags.py b/flags/assertflags.py index 6b15d2c..9262a58 100644 --- a/flags/assertflags.py +++ b/flags/assertflags.py @@ -16,6 +16,10 @@ import sysconfig # We will check all flags if none were requested KEYS_TO_CHECK = sys.argv[2:] or list(sysconfig.get_config_vars().keys()) +# For backwards compatibility, if no flags were provided, we assume flags without -O are to be skipped +# But when we provide explicit list of flags, we assert they get the options, +# so we can assert things like "CFLAGS has -O3" vs. "CFLAGS has no -O at all" +NO_FLAG_FAILS = bool(sys.argv[2:]) # The flags that currently don't have the -Og flag on the debug build # and we consider it OK, because we don't know any better :) @@ -35,8 +39,8 @@ for key in KEYS_TO_CHECK: flags = sysconfig.get_config_vars()[key] if isinstance(flags, str): oflags = [f for f in flags.split(' ') if f.startswith('-O')] - if oflags and oflags[-1] != sys.argv[1]: - print('Problem in {} -O flags: {}'.format(key, ' '.join(oflags))) + if (oflags and oflags[-1] != sys.argv[1]) or (not oflags and NO_FLAG_FAILS): + print('Problem in {} -O flags: {}'.format(key, ' '.join(oflags) or '')) ret = 1 elif oflags: print('{} are OK'.format(key)) diff --git a/tests.yml b/tests.yml index ff5b7dc..6f32fa9 100644 --- a/tests.yml +++ b/tests.yml @@ -72,6 +72,9 @@ - debugflags_some: dir: flags run: runuser testuser -c 'python3-debug ./assertflags.py -O0 PY_STDMODULE_CFLAGS' + - optflags_o3: + dir: flags + run: runuser testuser -c 'python3 ./assertflags.py -O3 CFLAGS' - marshalparser_compatibility: dir: marshalparser run: runuser testuser -c 'SAMPLE=10 test_marshalparser_compatibility.sh'