Skip to content

[3.10] bpo-45221: Fix handling of LDFLAGS and CPPFLAGS options in setup.py (GH-29031) #29037

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

Merged
merged 1 commit into from
Oct 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fixed regression in handling of ``LDFLAGS`` and ``CPPFLAGS`` options
where :meth:`argparse.parse_known_args` could interpret an option as
one of the built-in command line argument, for example ``-h`` for help.
12 changes: 12 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -801,6 +801,18 @@ def add_ldflags_cppflags(self):
if env_val:
parser = argparse.ArgumentParser()
parser.add_argument(arg_name, dest="dirs", action="append")

# To prevent argparse from raising an exception about any
# options in env_val that it mistakes for known option, we
# strip out all double dashes and any dashes followed by a
# character that is not for the option we are dealing with.
#
# Please note that order of the regex is important! We must
# strip out double-dashes first so that we don't end up with
# substituting "--Long" to "-Long" and thus lead to "ong" being
# used for a library directory.
env_val = re.sub(r'(^|\s+)-(-|(?!%s))' % arg_name[1],
' ', env_val)
options, _ = parser.parse_known_args(env_val.split())
if options.dirs:
for directory in reversed(options.dirs):
Expand Down