@@ -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
0 commit comments