summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpxinwr <peixing.xin@windriver.com>2021-01-22 00:55:52 (GMT)
committerGitHub <noreply@github.com>2021-01-22 00:55:52 (GMT)
commit5e45f1c8e7bc5f0ab8feba88b9b6e47066203a5c (patch)
tree7cc31c8f804e304d82ccbc56ec269de273551ad6
parent6713e869c4989c04318158b406c30a147ea52904 (diff)
downloadcpython-5e45f1c8e7bc5f0ab8feba88b9b6e47066203a5c.zip
cpython-5e45f1c8e7bc5f0ab8feba88b9b6e47066203a5c.tar.gz
cpython-5e45f1c8e7bc5f0ab8feba88b9b6e47066203a5c.tar.bz2
bpo-31904: setup.py: fix cross-compilation on VxWorks (GH-24191)
Add library search path by wr-cc in add_cross_compiling_paths().
-rw-r--r--Misc/NEWS.d/next/Build/2021-01-11-23-26-00.bpo-31904.ty8f3h.rst1
-rw-r--r--setup.py48
2 files changed, 49 insertions, 0 deletions
diff --git a/Misc/NEWS.d/next/Build/2021-01-11-23-26-00.bpo-31904.ty8f3h.rst b/Misc/NEWS.d/next/Build/2021-01-11-23-26-00.bpo-31904.ty8f3h.rst
new file mode 100644
index 0000000..bc02d0a
--- /dev/null
+++ b/Misc/NEWS.d/next/Build/2021-01-11-23-26-00.bpo-31904.ty8f3h.rst
@@ -0,0 +1 @@
+Add library search path by wr-cc in add_cross_compiling_paths() for VxWorks.
diff --git a/setup.py b/setup.py
index a4d21d4..8445546 100644
--- a/setup.py
+++ b/setup.py
@@ -682,6 +682,51 @@ class PyBuildExt(build_ext):
finally:
os.unlink(tmpfile)
+ def add_wrcc_search_dirs(self):
+ # add library search path by wr-cc, the compiler wrapper
+
+ def convert_mixed_path(path):
+ # convert path like C:\folder1\folder2/folder3/folder4
+ # to msys style /c/folder1/folder2/folder3/folder4
+ drive = path[0].lower()
+ left = path[2:].replace("\\", "/")
+ return "/" + drive + left
+
+ def add_search_path(line):
+ # On Windows building machine, VxWorks does
+ # cross builds under msys2 environment.
+ pathsep = (";" if sys.platform == "msys" else ":")
+ for d in line.strip().split("=")[1].split(pathsep):
+ d = d.strip()
+ if sys.platform == "msys":
+ # On Windows building machine, compiler
+ # returns mixed style path like:
+ # C:\folder1\folder2/folder3/folder4
+ d = convert_mixed_path(d)
+ d = os.path.normpath(d)
+ add_dir_to_list(self.compiler.library_dirs, d)
+
+ cc = sysconfig.get_config_var('CC')
+ tmpfile = os.path.join(self.build_temp, 'wrccpaths')
+ os.makedirs(self.build_temp, exist_ok=True)
+ try:
+ ret = run_command('%s --print-search-dirs >%s' % (cc, tmpfile))
+ if ret:
+ return
+ with open(tmpfile) as fp:
+ # Parse paths in libraries line. The line is like:
+ # On Linux, "libraries: = path1:path2:path3"
+ # On Windows, "libraries: = path1;path2;path3"
+ for line in fp:
+ if not line.startswith("libraries"):
+ continue
+ add_search_path(line)
+ finally:
+ try:
+ os.unlink(tmpfile)
+ except OSError:
+ pass
+
def add_cross_compiling_paths(self):
cc = sysconfig.get_config_var('CC')
tmpfile = os.path.join(self.build_temp, 'ccpaths')
@@ -715,6 +760,9 @@ class PyBuildExt(build_ext):
finally:
os.unlink(tmpfile)
+ if VXWORKS:
+ self.add_wrcc_search_dirs()
+
def add_ldflags_cppflags(self):
# Add paths specified in the environment variables LDFLAGS and
# CPPFLAGS for header and library files.