From 5ba9a8627ac27e04560e7c8b4699050b74c5f907 Mon Sep 17 00:00:00 2001 From: Daniele Nicolodi Date: Wed, 8 Feb 2023 14:24:49 +0100 Subject: [PATCH 1/4] ENH: place native and cross files in the build directory Use a 'meson-python-' prefix to likely avoid any possible name collision. As the build directory is supposed to contain build artefact there is no advantage in using an UNIX hidden file name for these files, and this makes them a little bit more discoverable. Fixes #299. --- mesonpy/__init__.py | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/mesonpy/__init__.py b/mesonpy/__init__.py index 40b964585..c1d71ecb6 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() @@ -759,14 +759,7 @@ def __init__( # noqa: C901 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) + 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) From 060d50790d3b7a323f79328e806a78b34384f86d Mon Sep 17 00:00:00 2001 From: Daniele Nicolodi Date: Wed, 8 Feb 2023 14:28:08 +0100 Subject: [PATCH 2/4] ENH: remove fallback that is never reached Project._meson() calls Project._proc() that translates failures in running the command into a SystemExit exception. --- mesonpy/__init__.py | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/mesonpy/__init__.py b/mesonpy/__init__.py index c1d71ecb6..d37e2995d 100644 --- a/mesonpy/__init__.py +++ b/mesonpy/__init__.py @@ -791,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}', @@ -820,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.""" From ba8ae5bb2584b02eedd36726c153df0fabcc3c49 Mon Sep 17 00:00:00 2001 From: Daniele Nicolodi Date: Wed, 8 Feb 2023 14:32:31 +0100 Subject: [PATCH 3/4] ENH: apply modified configuration options between rebuilds Always pass the '--reconfigure' argument to 'meson setup' if the build directory is a valid Meson build directory. Fixes #300. --- mesonpy/__init__.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/mesonpy/__init__.py b/mesonpy/__init__.py index d37e2995d..40d19a819 100644 --- a/mesonpy/__init__.py +++ b/mesonpy/__init__.py @@ -754,18 +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: - 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: From 3fa0d336953ae64a78fb5cc41526a5035f3fb2e6 Mon Sep 17 00:00:00 2001 From: Daniele Nicolodi Date: Fri, 10 Feb 2023 13:49:14 +0100 Subject: [PATCH 4/4] MAINT: do not skip nonexistent file when building sdist The native file is not intended to be added to version control, thus it should never have be present in the dist archive prepared by Meson. With it moved to the build directory there is no risk of it ever being present. --- mesonpy/__init__.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/mesonpy/__init__.py b/mesonpy/__init__.py index 40d19a819..365ad6edf 100644 --- a/mesonpy/__init__.py +++ b/mesonpy/__init__.py @@ -1036,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('/')