setup: Ensure target directory exists with building rust extension
authorCédric Krier <ced@b2ck.com>
Sat, 28 Jan 2023 20:08:57 +0100
changeset 49957 ff4df0954742
parent 49956 2282d8ac0fa9
child 49958 96e526fe5fb0
setup: Ensure target directory exists with building rust extension When the rust extension is the first to be build, the target directory may not exist so the copy fails.
setup.py
--- a/setup.py	Thu Jan 26 00:23:07 2023 +0100
+++ b/setup.py	Sat Jan 28 20:08:57 2023 +0100
@@ -1454,11 +1454,13 @@
         target = [target_dir]
         target.extend(self.name.split('.'))
         target[-1] += DYLIB_SUFFIX
+        target = os.path.join(*target)
+        os.makedirs(os.path.dirname(target), exist_ok=True)
         shutil.copy2(
             os.path.join(
                 self.rusttargetdir, self.dylibname + self.rustdylibsuffix()
             ),
-            os.path.join(*target),
+            target,
         )