Windows: Prevent SameFileError when rpathing (#34332)

This commit is contained in:
John W. Parent 2022-12-07 19:58:44 -05:00 committed by GitHub
parent ab6499ce1e
commit aed77efb9a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2278,10 +2278,17 @@ def add_rpath(self, *paths):
""" """
self._addl_rpaths = self._addl_rpaths | set(paths) self._addl_rpaths = self._addl_rpaths | set(paths)
def _link(self, path, dest): def _link(self, path, dest_dir):
"""Perform link step of simulated rpathing, installing
simlinks of file in path to the dest_dir
location. This method deliberately prevents
the case where a path points to a file inside the dest_dir.
This is because it is both meaningless from an rpath
perspective, and will cause an error when Developer
mode is not enabled"""
file_name = os.path.basename(path) file_name = os.path.basename(path)
dest_file = os.path.join(dest, file_name) dest_file = os.path.join(dest_dir, file_name)
if os.path.exists(dest): if os.path.exists(dest_dir) and not dest_file == path:
try: try:
symlink(path, dest_file) symlink(path, dest_file)
# For py2 compatibility, we have to catch the specific Windows error code # For py2 compatibility, we have to catch the specific Windows error code
@ -2295,7 +2302,7 @@ def _link(self, path, dest):
"Linking library %s to %s failed, " % (path, dest_file) + "already linked." "Linking library %s to %s failed, " % (path, dest_file) + "already linked."
if already_linked if already_linked
else "library with name %s already exists at location %s." else "library with name %s already exists at location %s."
% (file_name, dest) % (file_name, dest_dir)
) )
pass pass
else: else: