Skip to content

Commit f6a717c

Browse files
committed
ENH: copy files into wheel from Meson install directory
1 parent 0802ec4 commit f6a717c

File tree

2 files changed

+39
-31
lines changed

2 files changed

+39
-31
lines changed

mesonpy/__init__.py

Lines changed: 36 additions & 29 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,42 @@ 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
480-
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)
484-
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:
487-
488-
root = 'purelib' if self.is_pure else 'platlib'
489-
490-
for path, entries in self._wheel_files.items():
491-
for dst, src in entries:
492-
counter.update(src)
493-
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)
501-
502-
self._install_path(whl, src, dst)
474+
# ensure project is built
475+
self._project.build()
476+
477+
with tempfile.TemporaryDirectory() as destdir:
478+
# install project in temporary destination directory
479+
installed = self._project.install(destdir)
480+
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)
484+
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:
487+
488+
root = 'purelib' if self.is_pure else 'platlib'
489+
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+
# Custom installation path for bundled libraries.
505+
dst = pathlib.Path(f'.{self._project.name}.mesonpy.libs', dst)
506+
else:
507+
dst = pathlib.Path(self.data_dir, path, dst)
508+
509+
self._install_path(whl, src, dst)
503510

504511
return wheel_file
505512

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)