Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sundry fixes around meson setup handling #301

Merged
merged 4 commits into from
Mar 1, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 16 additions & 37 deletions mesonpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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
dnicolodi marked this conversation as resolved.
Show resolved Hide resolved
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()
FFY00 marked this conversation as resolved.
Show resolved Hide resolved

# 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:
Expand All @@ -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}',
Expand All @@ -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."""
Expand Down Expand Up @@ -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('/')
Expand Down