Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for issue 777, restoring versioned library symbolic links in installed package on Linux #778

Merged
merged 1 commit into from
Feb 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")
47 changes: 41 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,40 @@ 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):
PokhodenkoSA marked this conversation as resolved.
Show resolved Hide resolved
def run(self):
ret = super().run()
if "linux" in sys.platform:
this_dir = os.path.dirname(os.path.abspath(__file__))
dpctl_build_dir = os.path.join(this_dir, 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)
base_fn = os.path.basename(fn)
src_file = os.path.join(dpctl_build_dir, base_fn)
dst_file = os.path.join(dpctl_install_dir, base_fn)
_patched_copy_file(src_file, dst_file)
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