|
48 | 48 | import mesonpy._compat
|
49 | 49 | import mesonpy._dylib
|
50 | 50 | import mesonpy._elf
|
51 |
| -import mesonpy._introspection |
52 | 51 | import mesonpy._tags
|
53 | 52 | import mesonpy._util
|
54 | 53 | import mesonpy._wheelfile
|
@@ -628,16 +627,13 @@ class Project():
|
628 | 627 | def __init__(
|
629 | 628 | self,
|
630 | 629 | source_dir: Path,
|
631 |
| - working_dir: Path, |
632 |
| - build_dir: Optional[Path] = None, |
| 630 | + build_dir: Path, |
633 | 631 | meson_args: Optional[MesonArgs] = None,
|
634 | 632 | editable_verbose: bool = False,
|
635 | 633 | ) -> None:
|
636 | 634 | self._source_dir = pathlib.Path(source_dir).absolute()
|
637 |
| - self._working_dir = pathlib.Path(working_dir).absolute() |
638 |
| - self._build_dir = pathlib.Path(build_dir).absolute() if build_dir else (self._working_dir / 'build') |
| 635 | + self._build_dir = pathlib.Path(build_dir).absolute() |
639 | 636 | self._editable_verbose = editable_verbose
|
640 |
| - self._install_dir = self._working_dir / 'install' |
641 | 637 | self._meson_native_file = self._build_dir / 'meson-python-native-file.ini'
|
642 | 638 | self._meson_cross_file = self._build_dir / 'meson-python-cross-file.ini'
|
643 | 639 | self._meson_args: MesonArgs = collections.defaultdict(list)
|
@@ -692,7 +688,6 @@ def __init__(
|
692 | 688 |
|
693 | 689 | # make sure the build dir exists
|
694 | 690 | self._build_dir.mkdir(exist_ok=True, parents=True)
|
695 |
| - self._install_dir.mkdir(exist_ok=True, parents=True) |
696 | 691 |
|
697 | 692 | # write the native file
|
698 | 693 | native_file_data = textwrap.dedent(f'''
|
@@ -737,26 +732,15 @@ def _run(self, cmd: Sequence[str]) -> None:
|
737 | 732 |
|
738 | 733 | def _configure(self, reconfigure: bool = False) -> None:
|
739 | 734 | """Configure Meson project."""
|
740 |
| - sys_paths = mesonpy._introspection.SYSCONFIG_PATHS |
741 | 735 | setup_args = [
|
742 |
| - f'--prefix={sys.base_prefix}', |
743 | 736 | os.fspath(self._source_dir),
|
744 | 737 | os.fspath(self._build_dir),
|
745 | 738 | f'--native-file={os.fspath(self._meson_native_file)}',
|
746 |
| - # TODO: Allow configuring these arguments |
| 739 | + # default arguments |
747 | 740 | '-Ddebug=false',
|
748 | 741 | '-Db_ndebug=if-release',
|
749 | 742 | '-Doptimization=2',
|
750 |
| - |
751 |
| - # XXX: This should not be needed, but Meson is using the wrong paths |
752 |
| - # in some scenarios, like on macOS. |
753 |
| - # https://github.com/mesonbuild/meson-python/pull/87#discussion_r1047041306 |
754 |
| - '--python.purelibdir', |
755 |
| - sys_paths['purelib'], |
756 |
| - '--python.platlibdir', |
757 |
| - sys_paths['platlib'], |
758 |
| - |
759 |
| - # user args |
| 743 | + # user arguments |
760 | 744 | *self._meson_args['setup'],
|
761 | 745 | ]
|
762 | 746 | if reconfigure:
|
@@ -795,38 +779,11 @@ def _wheel_builder(self) -> _WheelBuilder:
|
795 | 779 | self._install_plan,
|
796 | 780 | )
|
797 | 781 |
|
798 |
| - def build_commands(self, install_dir: Optional[pathlib.Path] = None) -> Sequence[Sequence[str]]: |
799 |
| - assert self._ninja is not None # help mypy out |
800 |
| - return ( |
801 |
| - (self._ninja, *self._meson_args['compile'],), |
802 |
| - ( |
803 |
| - 'meson', |
804 |
| - 'install', |
805 |
| - '--only-changed', |
806 |
| - '--destdir', |
807 |
| - os.fspath(install_dir or self._install_dir), |
808 |
| - *self._meson_args['install'], |
809 |
| - ), |
810 |
| - ) |
811 |
| - |
812 | 782 | @functools.lru_cache(maxsize=None)
|
813 | 783 | def build(self) -> None:
|
814 |
| - """Trigger the Meson build.""" |
815 |
| - for cmd in self.build_commands(): |
816 |
| - self._run(cmd) |
817 |
| - |
818 |
| - @classmethod |
819 |
| - @contextlib.contextmanager |
820 |
| - def with_temp_working_dir( |
821 |
| - cls, |
822 |
| - source_dir: Path = os.path.curdir, |
823 |
| - build_dir: Optional[Path] = None, |
824 |
| - meson_args: Optional[MesonArgs] = None, |
825 |
| - editable_verbose: bool = False, |
826 |
| - ) -> Iterator[Project]: |
827 |
| - """Creates a project instance pointing to a temporary working directory.""" |
828 |
| - with tempfile.TemporaryDirectory(prefix='.mesonpy-', dir=os.fspath(source_dir)) as tmpdir: |
829 |
| - yield cls(source_dir, tmpdir, build_dir, meson_args, editable_verbose) |
| 784 | + """Build Meson project.""" |
| 785 | + assert self._ninja is not None # help mypy |
| 786 | + self._run([self._ninja, *self._meson_args['compile']]) |
830 | 787 |
|
831 | 788 | @functools.lru_cache()
|
832 | 789 | def _info(self, name: str) -> Dict[str, Any]:
|
@@ -975,18 +932,19 @@ def editable(self, directory: Path) -> pathlib.Path:
|
975 | 932 |
|
976 | 933 |
|
977 | 934 | @contextlib.contextmanager
|
978 |
| -def _project(config_settings: Optional[Dict[Any, Any]]) -> Iterator[Project]: |
| 935 | +def _project(config_settings: Optional[Dict[Any, Any]] = None) -> Iterator[Project]: |
979 | 936 | """Create the project given the given config settings."""
|
980 | 937 |
|
981 | 938 | settings = _validate_config_settings(config_settings or {})
|
982 |
| - meson_args = {name: settings.get(f'{name}-args', []) for name in _MESON_ARGS_KEYS} |
983 |
| - |
984 |
| - with Project.with_temp_working_dir( |
985 |
| - build_dir=settings.get('builddir'), |
986 |
| - meson_args=typing.cast(MesonArgs, meson_args), |
987 |
| - editable_verbose=bool(settings.get('editable-verbose')) |
988 |
| - ) as project: |
989 |
| - yield project |
| 939 | + meson_args = typing.cast(MesonArgs, {name: settings.get(f'{name}-args', []) for name in _MESON_ARGS_KEYS}) |
| 940 | + source_dir = os.path.curdir |
| 941 | + build_dir = settings.get('builddir') |
| 942 | + editable_verbose = bool(settings.get('editable-verbose')) |
| 943 | + |
| 944 | + with contextlib.ExitStack() as ctx: |
| 945 | + if build_dir is None: |
| 946 | + build_dir = ctx.enter_context(tempfile.TemporaryDirectory(prefix='.mesonpy-', dir=source_dir)) |
| 947 | + yield Project(source_dir, build_dir, meson_args, editable_verbose) |
990 | 948 |
|
991 | 949 |
|
992 | 950 | def _parse_version_string(string: str) -> Tuple[int, ...]:
|
|
0 commit comments