diff --git a/mesonpy/__init__.py b/mesonpy/__init__.py index 40b964585..365ad6edf 100644 --- a/mesonpy/__init__.py +++ b/mesonpy/__init__.py @@ -679,8 +679,8 @@ def __init__( # noqa: C901 self._build_dir = pathlib.Path(build_dir).absolute() if build_dir else (self._working_dir / 'build') self._editable_verbose = editable_verbose self._install_dir = self._working_dir / 'install' - self._meson_native_file = self._source_dir / '.mesonpy-native-file.ini' - self._meson_cross_file = self._source_dir / '.mesonpy-cross-file.ini' + self._meson_native_file = self._build_dir / 'meson-python-native-file.ini' + self._meson_cross_file = self._build_dir / 'meson-python-cross-file.ini' self._meson_args: MesonArgs = collections.defaultdict(list) self._env = os.environ.copy() @@ -754,25 +754,18 @@ def __init__( # noqa: C901 [binaries] python = '{sys.executable}' ''') - native_file_mismatch = ( - not self._meson_native_file.exists() - or self._meson_native_file.read_text() != native_file_data - ) - if native_file_mismatch: - try: - self._meson_native_file.write_text(native_file_data) - except OSError: - # if there are permission errors or something else in the source - # directory, put the native file in the working directory instead - # (this won't survive multiple calls -- Meson will have to be reconfigured) - self._meson_native_file = self._working_dir / '.mesonpy-native-file.ini' - self._meson_native_file.write_text(native_file_data) - - # Don't reconfigure if build directory doesn't have meson-private/coredata.data - # (means something went wrong) - # See https://github.com/mesonbuild/meson-python/pull/257#discussion_r1067385517 - has_valid_build_dir = self._build_dir.joinpath('meson-private', 'coredata.dat').is_file() - self._configure(reconfigure=has_valid_build_dir and not native_file_mismatch) + self._meson_native_file.write_text(native_file_data) + + # reconfigure if we have a valid Meson build directory. Meson + # uses the presence of the 'meson-private/coredata.dat' file + # in the build directory as indication that the build + # directory has already been configured and arranges this file + # to be created as late as possible or deleted if something + # goes wrong during setup. + reconfigure = self._build_dir.joinpath('meson-private/coredata.dat').is_file() + + # run meson setup + self._configure(reconfigure=reconfigure) # set version if dynamic (this fetches it from Meson) if self._metadata and 'version' in self._metadata.dynamic: @@ -798,11 +791,7 @@ def _meson(self, *args: str) -> None: return self._proc('meson', *args) def _configure(self, reconfigure: bool = False) -> None: - """Configure Meson project. - - We will try to reconfigure the build directory if possible to avoid - expensive rebuilds. - """ + """Configure Meson project.""" sys_paths = mesonpy._introspection.SYSCONFIG_PATHS setup_args = [ f'--prefix={sys.base_prefix}', @@ -827,13 +816,7 @@ def _configure(self, reconfigure: bool = False) -> None: if reconfigure: setup_args.insert(0, '--reconfigure') - try: - self._meson('setup', *setup_args) - except subprocess.CalledProcessError: - if reconfigure: # if failed reconfiguring, try a normal configure - self._configure() - else: - raise + self._meson('setup', *setup_args) def _validate_metadata(self) -> None: """Check the pyproject.toml metadata and see if there are any issues.""" @@ -1053,10 +1036,6 @@ def sdist(self, directory: Path) -> pathlib.Path: with tarfile.open(meson_dist_path, 'r:gz') as meson_dist, mesonpy._util.create_targz(sdist) as (tar, mtime): for member in meson_dist.getmembers(): - # skip the generated meson native file - if member.name == f'{meson_dist_name}/.mesonpy-native-file.ini': - continue - # calculate the file path in the source directory assert member.name, member.name member_parts = member.name.split('/')