Skip to content

Commit 6a533a4

Browse files
authored
bpo-45221: Fix handling of LDFLAGS and CPPFLAGS options in setup.py (GH-29031)
1 parent 034f607 commit 6a533a4

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fixed regression in handling of ``LDFLAGS`` and ``CPPFLAGS`` options
2+
where :meth:`argparse.parse_known_args` could interpret an option as
3+
one of the built-in command line argument, for example ``-h`` for help.

setup.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -801,6 +801,18 @@ def add_ldflags_cppflags(self):
801801
if env_val:
802802
parser = argparse.ArgumentParser()
803803
parser.add_argument(arg_name, dest="dirs", action="append")
804+
805+
# To prevent argparse from raising an exception about any
806+
# options in env_val that it mistakes for known option, we
807+
# strip out all double dashes and any dashes followed by a
808+
# character that is not for the option we are dealing with.
809+
#
810+
# Please note that order of the regex is important! We must
811+
# strip out double-dashes first so that we don't end up with
812+
# substituting "--Long" to "-Long" and thus lead to "ong" being
813+
# used for a library directory.
814+
env_val = re.sub(r'(^|\s+)-(-|(?!%s))' % arg_name[1],
815+
' ', env_val)
804816
options, _ = parser.parse_known_args(env_val.split())
805817
if options.dirs:
806818
for directory in reversed(options.dirs):

0 commit comments

Comments
 (0)