Skip to content

Commit 11390f8

Browse files
Ensure we copy actual file before symlinks
Add implementation of build_package_data method for the subclass The one in the parent class started using os.stat which requires follow_symlinks=False to work with symolic links this project works with
1 parent cd6e804 commit 11390f8

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

setup.py

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,23 @@ def copy_file(self, src, dst, preserve_mode=True):
8585
_patched_copy_file(src, dst, preserve_mode=preserve_mode)
8686
return (dst, 1)
8787

88+
def make_writable(self, target):
89+
import stat
90+
91+
mod = os.stat(target, follow_symlinks=False).st_mode | stat.S_IWRITE
92+
os.chmod(target, mod)
93+
94+
def build_package_data(self):
95+
"""Copy data files into build directory"""
96+
for package, src_dir, build_dir, filenames in self.data_files:
97+
for filename in filenames:
98+
target = os.path.join(build_dir, filename)
99+
self.mkpath(os.path.dirname(target))
100+
srcfile = os.path.join(src_dir, filename)
101+
outf, copied = self.copy_file(srcfile, target)
102+
self.make_writable(target)
103+
srcfile = os.path.abspath(srcfile)
104+
88105

89106
class InstallCmd(_skbuild_install):
90107
def run(self):
@@ -93,13 +110,19 @@ def run(self):
93110
this_dir = os.path.dirname(os.path.abspath(__file__))
94111
dpctl_build_dir = os.path.join(this_dir, self.build_lib, "dpctl")
95112
dpctl_install_dir = os.path.join(self.install_libbase, "dpctl")
96-
for fn in glob.glob(
97-
os.path.join(dpctl_install_dir, "*DPCTLSyclInterface.so*")
98-
):
99-
os.remove(fn)
113+
sofiles = glob.glob(
114+
os.path.join(dpctl_build_dir, "*DPCTLSyclInterface.so*")
115+
)
116+
# insert actual file at the beginning of the list
117+
pos = [i for i, fn in enumerate(sofiles) if not os.path.islink(fn)]
118+
if pos:
119+
hard_file = sofiles.pop(pos[0])
120+
sofiles.insert(0, hard_file)
121+
for fn in sofiles:
100122
base_fn = os.path.basename(fn)
101123
src_file = os.path.join(dpctl_build_dir, base_fn)
102124
dst_file = os.path.join(dpctl_install_dir, base_fn)
125+
os.remove(dst_file)
103126
_patched_copy_file(src_file, dst_file)
104127
return ret
105128

0 commit comments

Comments
 (0)