summaryrefslogtreecommitdiffstats
path: root/setup.py
diff options
context:
space:
mode:
authorandrei kulakov <andrei.avk@gmail.com>2021-10-18 18:26:23 (GMT)
committerGitHub <noreply@github.com>2021-10-18 18:26:23 (GMT)
commit6a533a423869e28d9086cf4d79029f59e9eec916 (patch)
tree356e8c2f0c59678b632c0f3a6233c074d2d720e1 /setup.py
parent034f607906de6e375cc9a98cc3b09f6d56f8be10 (diff)
downloadcpython-6a533a423869e28d9086cf4d79029f59e9eec916.zip
cpython-6a533a423869e28d9086cf4d79029f59e9eec916.tar.gz
cpython-6a533a423869e28d9086cf4d79029f59e9eec916.tar.bz2
bpo-45221: Fix handling of LDFLAGS and CPPFLAGS options in setup.py (GH-29031)
Diffstat (limited to 'setup.py')
-rw-r--r--setup.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/setup.py b/setup.py
index 24365ef..5428cbd 100644
--- a/setup.py
+++ b/setup.py
@@ -801,6 +801,18 @@ class PyBuildExt(build_ext):
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):