Skip to content

Commit 210b727

Browse files
committed
BUG: ensure build options are preserved
Using `pip install -Cbuild-dir=<existing-dir>` used to overwrite the `buildtype` instead of reusing it from the build directory. Now, we don't provide default options if the directory exist.
1 parent 4977b7d commit 210b727

2 files changed

Lines changed: 45 additions & 14 deletions

File tree

mesonpy/__init__.py

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -899,23 +899,33 @@ def _run(self, cmd: Sequence[str]) -> None:
899899

900900
def _configure(self, reconfigure: bool = False) -> None:
901901
"""Configure Meson project."""
902-
setup_args = [
902+
setup_cmd = self._meson + ['setup']
903+
904+
if reconfigure:
905+
setup_cmd.append('--reconfigure')
906+
907+
setup_cmd += [
903908
os.fspath(self._source_dir),
904909
os.fspath(self._build_dir),
905-
# default build options
906-
'-Dbuildtype=release',
907-
'-Db_ndebug=if-release',
908-
'-Db_vscrt=md',
909-
# user build options
910-
*self._meson_args['setup'],
911-
# pass native file last to have it override the python
912-
# interpreter path that may have been specified in user
913-
# provided native files
914-
f'--native-file={os.fspath(self._meson_native_file)}',
915910
]
916-
if reconfigure:
917-
setup_args.insert(0, '--reconfigure')
918-
self._run(self._meson + ['setup', *setup_args])
911+
912+
if not reconfigure:
913+
# default build options
914+
setup_cmd += [
915+
'-Dbuildtype=release',
916+
'-Db_ndebug=if-release',
917+
'-Db_vscrt=md',
918+
]
919+
920+
# user build options
921+
setup_cmd += self._meson_args['setup']
922+
923+
# pass native file last to have it override the python
924+
# interpreter path that may have been specified in user
925+
# provided native files
926+
setup_cmd.append(f'--native-file={os.fspath(self._meson_native_file)}')
927+
928+
self._run(setup_cmd)
919929

920930
@property
921931
def _build_command(self) -> List[str]:

tests/test_project.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,27 @@ def test_invalid_build_dir(package_pure, tmp_path, mocker):
332332
assert '--reconfigure' not in meson.call_args_list[0].args[1]
333333
project.build()
334334

335+
def test_reconfigure_preserves_config(package_simple, tmp_path):
336+
# initial configuration
337+
project = mesonpy.Project(package_simple, tmp_path, meson_args={
338+
'setup': ['-Dbuildtype=debug', '-Dwarning_level=2'],
339+
})
340+
341+
initial_options = {opt['name']: opt['value'] for opt in project._info('intro-buildoptions')}
342+
343+
# reconfiguration with a new option
344+
project = mesonpy.Project(package_simple, tmp_path, meson_args={
345+
'setup': ['-Doptimization=2'],
346+
})
347+
348+
reconfigure_options = {opt['name']: opt['value'] for opt in project._info('intro-buildoptions')}
349+
350+
assert initial_options != reconfigure_options
351+
352+
initial_options['optimization'] = '2'
353+
assert initial_options == reconfigure_options
354+
355+
335356

336357
@pytest.mark.skipif(not os.getenv('CI') or sys.platform != 'win32', reason='requires MSVC')
337358
def test_compiler(venv, package_detect_compiler, tmp_path):

0 commit comments

Comments
 (0)