Skip to content

Commit c2ee830

Browse files
committed
ENH: copy files into wheel from install directory
1 parent 11af9f7 commit c2ee830

File tree

2 files changed

+32
-25
lines changed

2 files changed

+32
-25
lines changed

mesonpy/__init__.py

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -436,11 +436,6 @@ def _install_path(
436436
if platform.system() == 'Linux' or platform.system() == 'Darwin':
437437
# add .mesonpy.libs to the RPATH of ELF files
438438
if self._is_native(os.fspath(origin)):
439-
# copy ELF to our working directory to avoid Meson having to regenerate the file
440-
new_origin = self._libs_build_dir / pathlib.Path(origin).relative_to(self._build_dir)
441-
os.makedirs(new_origin.parent, exist_ok=True)
442-
shutil.copy2(origin, new_origin)
443-
origin = new_origin
444439
# add our in-wheel libs folder to the RPATH
445440
if platform.system() == 'Linux':
446441
elf = mesonpy._elf.ELF(origin)
@@ -476,30 +471,41 @@ def _wheel_write_metadata(self, whl: mesonpy._wheelfile.WheelFile) -> None:
476471
)
477472

478473
def build(self, directory: Path) -> pathlib.Path:
479-
self._project.build() # ensure project is built
474+
# ensure project is built
475+
self._project.build()
480476

481-
wheel_file = pathlib.Path(directory, f'{self.name}.whl')
482-
with mesonpy._wheelfile.WheelFile(wheel_file, 'w') as whl:
483-
self._wheel_write_metadata(whl)
477+
with tempfile.TemporaryDirectory() as destdir:
478+
# install project in temporary destination directory
479+
installed = self._project.install(destdir)
484480

485-
print('{light_blue}{bold}Copying files to wheel...{reset}'.format(**_STYLES))
486-
with mesonpy._util.cli_counter(sum(len(x) for x in self._wheel_files.values())) as counter:
481+
wheel_file = pathlib.Path(directory, f'{self.name}.whl')
482+
with mesonpy._wheelfile.WheelFile(wheel_file, 'w') as whl:
483+
self._wheel_write_metadata(whl)
487484

488-
root = 'purelib' if self.is_pure else 'platlib'
485+
print('{light_blue}{bold}Copying files to wheel...{reset}'.format(**_STYLES))
486+
with mesonpy._util.cli_counter(sum(len(x) for x in self._wheel_files.values())) as counter:
489487

490-
for path, entries in self._wheel_files.items():
491-
for dst, src in entries:
492-
counter.update(src)
488+
root = 'purelib' if self.is_pure else 'platlib'
493489

494-
if path == root:
495-
pass
496-
elif path == 'mesonpy-libs':
497-
# custom installation path for bundled libraries
498-
dst = pathlib.Path(f'.{self._project.name}.mesonpy.libs', dst)
499-
else:
500-
dst = pathlib.Path(self.data_dir, path, dst)
490+
for path, entries in self._wheel_files.items():
491+
for dst, src in entries:
492+
counter.update(src)
493+
494+
# Install files from installation path into the wheel. This guarantees
495+
# that the installed files had the build path rpath removed by Meson
496+
# during 'meson install' and that directories installed with
497+
# 'install_subdir()' had 'excluded_files' and 'excluded_directories'
498+
# omitted.
499+
src = installed[os.fspath(src)]
500+
501+
if path == root:
502+
pass
503+
elif path == 'mesonpy-libs':
504+
dst = pathlib.Path(f'.{self._project.name}.mesonpy.libs', dst)
505+
else:
506+
dst = pathlib.Path(self.data_dir, path, dst)
501507

502-
self._install_path(whl, src, dst)
508+
self._install_path(whl, src, dst)
503509

504510
return wheel_file
505511

tests/test_project.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def last_two_meson_args():
7676
'dist-args': ('cli-dist',),
7777
'setup-args': ('cli-setup',),
7878
'compile-args': ('cli-compile',),
79-
'install-args': ('cli-install',), # 'meson install' is not called thus we cannot test this
79+
'install-args': ('cli-install',)
8080
}
8181

8282
mesonpy.build_sdist(tmp_path, config_settings)
@@ -86,9 +86,10 @@ def last_two_meson_args():
8686
# sdist: calls to 'meson setup' and 'meson dist'
8787
('config-setup', 'cli-setup'),
8888
('config-dist', 'cli-dist'),
89-
# wheel: calls to 'meson setup' and 'ninja'
89+
# wheel: calls to 'meson setup', 'ninja', and 'meson install'
9090
('config-setup', 'cli-setup'),
9191
('config-compile', 'cli-compile'),
92+
('config-install', 'cli-install'),
9293
]
9394

9495

0 commit comments

Comments
 (0)