|
14 | 14 | # See the License for the specific language governing permissions and
|
15 | 15 | # limitations under the License.
|
16 | 16 |
|
17 |
| -import glob |
18 |
| -import os.path |
19 |
| -import pathlib |
20 |
| -import shutil |
21 |
| -import sys |
22 |
| - |
23 | 17 | import skbuild
|
24 | 18 | import skbuild.setuptools_wrap
|
25 | 19 | import skbuild.utils
|
26 | 20 | import versioneer
|
27 |
| -from skbuild.command.build_py import build_py as _skbuild_build_py |
28 |
| -from skbuild.command.install import install as _skbuild_install |
29 |
| - |
30 |
| -""" |
31 |
| -Get the project version |
32 |
| -""" |
33 |
| -thefile_path = os.path.abspath(os.path.dirname(__file__)) |
34 |
| - |
35 |
| - |
36 |
| -def cleanup_destination(cmake_manifest): |
37 |
| - """Delete library files from dpctl/ folder before |
38 |
| - letting skbuild copy them over to avoid errors. |
39 |
| - """ |
40 |
| - _to_unlink = [] |
41 |
| - for fn in cmake_manifest: |
42 |
| - bn = os.path.basename(fn) |
43 |
| - # delete |
44 |
| - if "DPCTLSyclInterface" in bn: |
45 |
| - lib_fn = os.path.join("dpctl", bn) |
46 |
| - if os.path.exists(lib_fn): |
47 |
| - _to_unlink.append(lib_fn) |
48 |
| - for fn in _to_unlink: |
49 |
| - pathlib.Path(fn).unlink() |
50 |
| - return cmake_manifest |
51 |
| - |
52 |
| - |
53 |
| -def _patched_copy_file( |
54 |
| - src_file, dest_file, hide_listing=True, preserve_mode=True |
55 |
| -): |
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 |
| -class BuildPyCmd(_skbuild_build_py): |
83 |
| - def copy_file(self, src, dst, preserve_mode=True): |
84 |
| - _patched_copy_file(src, dst, preserve_mode=preserve_mode) |
85 |
| - return (dst, 1) |
86 |
| - |
87 |
| - def build_package_data(self): |
88 |
| - """Copy data files into build directory""" |
89 |
| - for package, src_dir, build_dir, filenames in self.data_files: |
90 |
| - for filename in filenames: |
91 |
| - target = os.path.join(build_dir, filename) |
92 |
| - self.mkpath(os.path.dirname(target)) |
93 |
| - srcfile = os.path.join(src_dir, filename) |
94 |
| - outf, copied = self.copy_file(srcfile, target) |
95 |
| - srcfile = os.path.abspath(srcfile) |
96 |
| - |
97 |
| - |
98 |
| -class InstallCmd(_skbuild_install): |
99 |
| - def run(self): |
100 |
| - ret = super().run() |
101 |
| - if "linux" in sys.platform: |
102 |
| - this_dir = os.path.dirname(os.path.abspath(__file__)) |
103 |
| - dpctl_build_dir = os.path.join(this_dir, self.build_lib, "dpctl") |
104 |
| - dpctl_install_dir = os.path.join(self.install_libbase, "dpctl") |
105 |
| - sofiles = glob.glob( |
106 |
| - os.path.join(dpctl_build_dir, "*DPCTLSyclInterface.so*") |
107 |
| - ) |
108 |
| - # insert actual file at the beginning of the list |
109 |
| - pos = [i for i, fn in enumerate(sofiles) if not os.path.islink(fn)] |
110 |
| - if pos: |
111 |
| - hard_file = sofiles.pop(pos[0]) |
112 |
| - sofiles.insert(0, hard_file) |
113 |
| - for fn in sofiles: |
114 |
| - base_fn = os.path.basename(fn) |
115 |
| - src_file = os.path.join(dpctl_build_dir, base_fn) |
116 |
| - dst_file = os.path.join(dpctl_install_dir, base_fn) |
117 |
| - os.remove(dst_file) |
118 |
| - _patched_copy_file(src_file, dst_file) |
119 |
| - return ret |
120 |
| - |
121 |
| - |
122 |
| -def _get_cmdclass(): |
123 |
| - cmdclass = versioneer.get_cmdclass( |
124 |
| - cmdclass={ |
125 |
| - "build_py": BuildPyCmd, |
126 |
| - "install": InstallCmd, |
127 |
| - } |
128 |
| - ) |
129 |
| - return cmdclass |
130 |
| - |
131 | 21 |
|
132 | 22 | skbuild.setup(
|
133 | 23 | version=versioneer.get_version(),
|
134 |
| - cmdclass=_get_cmdclass(), |
135 | 24 | url="https://github.com/IntelPython/dpctl",
|
136 | 25 | packages=[
|
137 | 26 | "dpctl",
|
@@ -169,5 +58,4 @@ def _get_cmdclass():
|
169 | 58 | ]
|
170 | 59 | },
|
171 | 60 | include_package_data=False,
|
172 |
| - cmake_process_manifest_hook=cleanup_destination, |
173 | 61 | )
|
0 commit comments