Skip to content

Commit

Permalink
Closes #777
Browse files Browse the repository at this point in the history
When scikit-build assembles dpctl, it runs cmake with _skbuild/*/cmake-build being
as its build directory, _skbuild/*/cmake-install being its install directory. It then
runs setuptools.setup to execute build_py steps using _skbuild/*/setuptools as its
build_base. Since sycl interface library is registered in package-data, it is copied
from cmake-install (where is has symbolic links) to setuptools (where unpatched
setuptools.command.build_py command follows them).

Then, when running install_lib step, files from _skbuild/*/setuptools/lib/dpctl are
copied into site-packages/dpctl using copy_tree, which also follows symbolic links,
hence turning them into hard links).

This PR transfers logic from pre-scikit-build setup.py to fix hard links as post
setuptools.command.install.run() step).

A test is added to tests/test_service.py to verify that on Linux some of library files
are symbolic links.
  • Loading branch information
oleksandr-pavlyk committed Feb 12, 2022
1 parent 902fa01 commit 440227c
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 6 deletions.
23 changes: 23 additions & 0 deletions dpctl/tests/test_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import os
import os.path
import re
import sys

import pytest

Expand Down Expand Up @@ -129,3 +130,25 @@ def test_dev_utils():
with pytest.raises(ValueError):
with ctx_mngr(log_dir="/not_a_dir"):
dpctl.SyclDevice().parent_device


def test_syclinterface():
install_dir = os.path.dirname(os.path.abspath(dpctl.__file__))
paths = glob.glob(os.path.join(install_dir, "*DPCTLSyclInterface*"))
if "linux" in sys.platform:
assert len(paths) > 1 and any(
[os.path.islink(fn) for fn in paths]
), "All library instances are hard links"
elif sys.platform in ["win32", "cygwin"]:
exts = []
for fn in paths:
_, file_ext = os.path.splitext(fn)
exts.append(file_ext.lower())
assert (
"lib" in exts
), "Installation does not have DPCTLSyclInterface.lib"
assert (
"dll" in exts
), "Installation does not have DPCTLSyclInterface.dll"
else:
raise RuntimeError("Unsupported system")
49 changes: 43 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,18 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import glob
import os.path
import pathlib
import shutil
import sys

import skbuild
import skbuild.setuptools_wrap
import skbuild.utils
from setuptools import find_packages
from skbuild.command.build_py import build_py as _skbuild_build_py
from skbuild.command.install import install as _skbuild_install

import versioneer

Expand All @@ -30,11 +34,6 @@
long_description = file.read()


def _get_cmdclass():
cmdclass = versioneer.get_cmdclass()
return cmdclass


def cleanup_destination(cmake_manifest):
"""Delete library files from dpctl/ folder before
letting skbuild copy them over to avoid errors.
Expand All @@ -52,7 +51,9 @@ def cleanup_destination(cmake_manifest):
return cmake_manifest


def _patched_copy_file(src_file, dest_file, hide_listing=True):
def _patched_copy_file(
src_file, dest_file, hide_listing=True, preserve_mode=True
):
"""Copy ``src_file`` to ``dest_file`` ensuring parent directory exists.
By default, message like `creating directory /path/to/package` and
Expand All @@ -79,6 +80,42 @@ def _patched_copy_file(src_file, dest_file, hide_listing=True):
skbuild.setuptools_wrap._copy_file = _patched_copy_file


class BuildPyCmd(_skbuild_build_py):
def copy_file(self, src, dst, preserve_mode=True):
_patched_copy_file(src, dst, preserve_mode=preserve_mode)
return (dst, 1)


class InstallCmd(_skbuild_install):
def run(self):
ret = super().run()
if "linux" in sys.platform:
dpctl_build_dir = os.path.join(
os.path.dirname(__file__), self.build_lib, "dpctl"
)
dpctl_install_dir = os.path.join(self.install_libbase, "dpctl")
for fn in glob.glob(
os.path.join(dpctl_install_dir, "*DPCTLSyclInterface.so*")
):
os.remove(fn)
shutil.copy(
src=os.path.join(dpctl_build_dir, os.path.basename(fn)),
dst=dpctl_install_dir,
follow_symlinks=False,
)
return ret


def _get_cmdclass():
cmdclass = versioneer.get_cmdclass(
cmdclass={
"build_py": BuildPyCmd,
"install": InstallCmd,
}
)
return cmdclass


skbuild.setup(
name="dpctl",
version=versioneer.get_version(),
Expand Down

0 comments on commit 440227c

Please sign in to comment.