Skip to content

Commit 49f111c

Browse files
Use cmake_process_manifest_hook setup argument to clean destination folder
Delete DPCTLSyclInterface library shared objects from dpctl/ folder from previous runs. Monkey-patch skbuild.setuptools._copy_file to not follows symbolic links, to ensure that versioned DPCTLSyclInterface ends up as the proper set of symbolic links pointing to a single physical shared object file. If symbolic links are followed, 3 identical copies of the library end up in the installation folder. Downstream dpctl users may end up with several instances of the library in their process space which may end up with errors is statuful functinality (queue manager) is used.
1 parent 1f6b40f commit 49f111c

File tree

1 file changed

+53
-2
lines changed

1 file changed

+53
-2
lines changed

setup.py

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,14 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17+
import os.path
18+
import pathlib
19+
import shutil
20+
21+
import skbuild
22+
import skbuild.setuptools_wrap
23+
import skbuild.utils
1724
from setuptools import find_packages
18-
from skbuild import setup
1925

2026
import versioneer
2127

@@ -29,7 +35,51 @@ def _get_cmdclass():
2935
return cmdclass
3036

3137

32-
setup(
38+
def cleanup_destination(cmake_manifest):
39+
"""Delete library files from dpctl/ folder before
40+
letting skbuild copy them over to avoid errors.
41+
"""
42+
_to_unlink = []
43+
for fn in cmake_manifest:
44+
bn = os.path.basename(fn)
45+
# delete
46+
if "DPCTLSyclInterface" in bn:
47+
lib_fn = os.path.join("dpctl", bn)
48+
if os.path.exists(lib_fn):
49+
_to_unlink.append(lib_fn)
50+
for fn in _to_unlink:
51+
pathlib.Path(fn).unlink()
52+
return cmake_manifest
53+
54+
55+
def _patched_copy_file(src_file, dest_file, hide_listing=True):
56+
"""Copy ``src_file`` to ``dest_file`` ensuring parent directory exists.
57+
58+
By default, message like `creating directory /path/to/package` and
59+
`copying directory /src/path/to/package -> path/to/package` are displayed
60+
on standard output. Setting ``hide_listing`` to False avoids message from
61+
being displayed.
62+
63+
NB: Patched here to not follows symbolic links
64+
"""
65+
# Create directory if needed
66+
dest_dir = os.path.dirname(dest_file)
67+
if dest_dir != "" and not os.path.exists(dest_dir):
68+
if not hide_listing:
69+
print("creating directory {}".format(dest_dir))
70+
skbuild.utils.mkdir_p(dest_dir)
71+
72+
# Copy file
73+
if not hide_listing:
74+
print("copying {} -> {}".format(src_file, dest_file))
75+
shutil.copyfile(src_file, dest_file, follow_symlinks=False)
76+
shutil.copymode(src_file, dest_file, follow_symlinks=False)
77+
78+
79+
skbuild.setuptools_wrap._copy_file = _patched_copy_file
80+
81+
82+
skbuild.setup(
3383
name="dpctl",
3484
version=versioneer.get_version(),
3585
cmdclass=_get_cmdclass(),
@@ -54,4 +104,5 @@ def _get_cmdclass():
54104
"Programming Language :: Python :: 3.8",
55105
"Programming Language :: Python :: 3.9",
56106
],
107+
cmake_process_manifest_hook=cleanup_destination,
57108
)

0 commit comments

Comments
 (0)