bpo-32059: setup.py now also searches the sysroot paths (GH-4452) (#4562)
detect_modules() in setup.py now also searches the sysroot paths when
cross-compiling.
(cherry picked from commit 77f5139954
)
This commit is contained in:
parent
6bce8ace76
commit
04af8ace86
|
@ -0,0 +1,2 @@
|
||||||
|
``detect_modules()`` in ``setup.py`` now also searches the sysroot paths
|
||||||
|
when cross-compiling.
|
44
setup.py
44
setup.py
|
@ -60,6 +60,31 @@ def add_dir_to_list(dirlist, dir):
|
||||||
return
|
return
|
||||||
dirlist.insert(0, dir)
|
dirlist.insert(0, dir)
|
||||||
|
|
||||||
|
def sysroot_paths(make_vars, subdirs):
|
||||||
|
"""Get the paths of sysroot sub-directories.
|
||||||
|
|
||||||
|
* make_vars: a sequence of names of variables of the Makefile where
|
||||||
|
sysroot may be set.
|
||||||
|
* subdirs: a sequence of names of subdirectories used as the location for
|
||||||
|
headers or libraries.
|
||||||
|
"""
|
||||||
|
|
||||||
|
dirs = []
|
||||||
|
for var_name in make_vars:
|
||||||
|
var = sysconfig.get_config_var(var_name)
|
||||||
|
if var is not None:
|
||||||
|
m = re.search(r'--sysroot=([^"]\S*|"[^"]+")', var)
|
||||||
|
if m is not None:
|
||||||
|
sysroot = m.group(1).strip('"')
|
||||||
|
for subdir in subdirs:
|
||||||
|
if os.path.isabs(subdir):
|
||||||
|
subdir = subdir[1:]
|
||||||
|
path = os.path.join(sysroot, subdir)
|
||||||
|
if os.path.isdir(path):
|
||||||
|
dirs.append(path)
|
||||||
|
break
|
||||||
|
return dirs
|
||||||
|
|
||||||
def macosx_sdk_root():
|
def macosx_sdk_root():
|
||||||
"""
|
"""
|
||||||
Return the directory of the current OSX SDK,
|
Return the directory of the current OSX SDK,
|
||||||
|
@ -544,18 +569,23 @@ class PyBuildExt(build_ext):
|
||||||
add_dir_to_list(self.compiler.include_dirs,
|
add_dir_to_list(self.compiler.include_dirs,
|
||||||
sysconfig.get_config_var("INCLUDEDIR"))
|
sysconfig.get_config_var("INCLUDEDIR"))
|
||||||
|
|
||||||
|
system_lib_dirs = ['/lib64', '/usr/lib64', '/lib', '/usr/lib']
|
||||||
|
system_include_dirs = ['/usr/include']
|
||||||
# lib_dirs and inc_dirs are used to search for files;
|
# lib_dirs and inc_dirs are used to search for files;
|
||||||
# if a file is found in one of those directories, it can
|
# if a file is found in one of those directories, it can
|
||||||
# be assumed that no additional -I,-L directives are needed.
|
# be assumed that no additional -I,-L directives are needed.
|
||||||
if not cross_compiling:
|
if not cross_compiling:
|
||||||
lib_dirs = self.compiler.library_dirs + [
|
lib_dirs = self.compiler.library_dirs + system_lib_dirs
|
||||||
'/lib64', '/usr/lib64',
|
inc_dirs = self.compiler.include_dirs + system_include_dirs
|
||||||
'/lib', '/usr/lib',
|
|
||||||
]
|
|
||||||
inc_dirs = self.compiler.include_dirs + ['/usr/include']
|
|
||||||
else:
|
else:
|
||||||
lib_dirs = self.compiler.library_dirs[:]
|
# Add the sysroot paths. 'sysroot' is a compiler option used to
|
||||||
inc_dirs = self.compiler.include_dirs[:]
|
# set the logical path of the standard system headers and
|
||||||
|
# libraries.
|
||||||
|
lib_dirs = (self.compiler.library_dirs +
|
||||||
|
sysroot_paths(('LDFLAGS', 'CC'), system_lib_dirs))
|
||||||
|
inc_dirs = (self.compiler.include_dirs +
|
||||||
|
sysroot_paths(('CPPFLAGS', 'CFLAGS', 'CC'),
|
||||||
|
system_include_dirs))
|
||||||
exts = []
|
exts = []
|
||||||
missing = []
|
missing = []
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue