Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 807bd0a

Browse files
committed
Put /usr/local paths after the relative paths in library_dirs and
include_dirs, so installed non-matching shared libraries don't break extension module linking. Fixes issue 10520.
1 parent 1b9df39 commit 807bd0a

1 file changed

Lines changed: 18 additions & 8 deletions

File tree

setup.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,18 @@
2727
_BUILDDIR_COOKIE = "pybuilddir.txt"
2828

2929
def add_dir_to_list(dirlist, dir):
30-
"""Add the directory 'dir' to the list 'dirlist' (at the front) if
30+
"""Add the directory 'dir' to the list 'dirlist' (after any relative
31+
directories) if:
32+
3133
1) 'dir' is not already in 'dirlist'
32-
2) 'dir' actually exists, and is a directory."""
33-
if dir is not None and os.path.isdir(dir) and dir not in dirlist:
34-
dirlist.insert(0, dir)
34+
2) 'dir' actually exists, and is a directory.
35+
"""
36+
if dir is None or not os.path.isdir(dir) or dir in dirlist:
37+
return
38+
for i, path in enumerate(dirlist):
39+
if not os.path.isabs(path):
40+
dirlist.insert(i + 1, dir)
41+
break
3542

3643
def macosx_sdk_root():
3744
"""
@@ -362,7 +369,9 @@ def get_platform(self):
362369
return sys.platform
363370

364371
def detect_modules(self):
365-
# Ensure that /usr/local is always used
372+
# Ensure that /usr/local is always used, but the local build
373+
# directories (i.e. '.' and 'Include') must be first. See issue
374+
# 10520.
366375
add_dir_to_list(self.compiler.library_dirs, '/usr/local/lib')
367376
add_dir_to_list(self.compiler.include_dirs, '/usr/local/include')
368377

@@ -437,9 +446,10 @@ def detect_modules(self):
437446
# This should work on any unixy platform ;-)
438447
# If the user has bothered specifying additional -I and -L flags
439448
# in OPT and LDFLAGS we might as well use them here.
440-
# NOTE: using shlex.split would technically be more correct, but
441-
# also gives a bootstrap problem. Let's hope nobody uses directories
442-
# with whitespace in the name to store libraries.
449+
#
450+
# NOTE: using shlex.split would technically be more correct, but
451+
# also gives a bootstrap problem. Let's hope nobody uses
452+
# directories with whitespace in the name to store libraries.
443453
cflags, ldflags = sysconfig.get_config_vars(
444454
'CFLAGS', 'LDFLAGS')
445455
for item in cflags.split():

0 commit comments

Comments
 (0)