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

miss-islington webhook-mailer at python.org
Mon Oct 18 14:49:37 EDT 2021


https://github.com/python/cpython/commit/b1949e0b58714724a3105cad3ad1b61384688da7
commit: b1949e0b58714724a3105cad3ad1b61384688da7
branch: 3.10
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: miss-islington <31488909+miss-islington at users.noreply.github.com>
date: 2021-10-18T11:49:28-07:00
summary:

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



(cherry picked from commit 6a533a423869e28d9086cf4d79029f59e9eec916)


Co-authored-by: andrei kulakov <andrei.avk at gmail.com>

Automerge-Triggered-By: GH:ned-deily

files:
A Misc/NEWS.d/next/Build/2021-10-18-10-25-56.bpo-45221.rnulhf.rst
M setup.py

diff --git a/Misc/NEWS.d/next/Build/2021-10-18-10-25-56.bpo-45221.rnulhf.rst b/Misc/NEWS.d/next/Build/2021-10-18-10-25-56.bpo-45221.rnulhf.rst
new file mode 100644
index 0000000000000..cb981d96f3047
--- /dev/null
+++ b/Misc/NEWS.d/next/Build/2021-10-18-10-25-56.bpo-45221.rnulhf.rst
@@ -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.
diff --git a/setup.py b/setup.py
index a6fcc12b84d0c..74d5cefc60ee3 100644
--- a/setup.py
+++ b/setup.py
@@ -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):



More information about the Python-checkins mailing list