msetup: use more consistent exceptions on exit

- MesonException for errors is clearer than SystemExit('error message')
  and provides meson-formatted "ERROR: ..."

- `raise SystemExit` with no parameter isn't obvious that it intends to
  exit successfully

While clarifying the latter, it was observed to cause
test_preprocessor_checks_CPPFLAGS() failure to be ignored. That test
checks get_define() on both c and cpp compilers, which means we need to
define either CPPFLAGS or both CFLAGS+CXXFLAGS.
pull/11619/head
Xavier Claessens 2 years ago committed by Eli Schwartz
parent ad151d9f11
commit 0418a40e68
No known key found for this signature in database
GPG Key ID: CEB167EFB5722BD6
  1. 21
      mesonbuild/msetup.py
  2. 8
      unittests/allplatformstests.py

@ -165,16 +165,21 @@ class MesonApp:
has_partial_build = os.path.isdir(priv_dir)
if has_valid_build:
if not reconfigure and not wipe:
print('Directory already configured.\n'
'\nJust run your build command (e.g. ninja) and Meson will regenerate as necessary.\n'
print('Directory already configured.\n\n'
'Just run your build command (e.g. ninja) and Meson will regenerate as necessary.\n'
'If ninja fails, run "ninja reconfigure" or "meson setup --reconfigure"\n'
'to force Meson to regenerate.\n'
'\nIf build failures persist, run "meson setup --wipe" to rebuild from scratch\n'
'using the same options as passed when configuring the build.'
'\nTo change option values, run "meson configure" instead.')
raise SystemExit
'to force Meson to regenerate.\n\n'
'If build failures persist, run "meson setup --wipe" to rebuild from scratch\n'
'using the same options as passed when configuring the build.\n'
'To change option values, run "meson configure" instead.')
# FIXME: This returns success and ignores new option values from CLI.
# We should either make this a hard error, or update options and
# return success.
# Note that making this an error would not be backward compatible (and also isn't
# universally agreed on): https://github.com/mesonbuild/meson/pull/4249.
raise SystemExit(0)
elif not has_partial_build and 'MESON_RUNNING_IN_PROJECT_TESTS' not in os.environ:
raise SystemExit(f'Directory is not empty and does not contain a previous build:\n{build_dir}')
raise MesonException(f'Directory is not empty and does not contain a previous build:\n{build_dir}')
return src_dir, build_dir
def generate(self) -> None:

@ -1139,7 +1139,7 @@ class AllPlatformTests(BasePlatformTests):
def test_preprocessor_checks_CPPFLAGS(self):
'''
Test that preprocessor compiler checks read CPPFLAGS and also CFLAGS but
Test that preprocessor compiler checks read CPPFLAGS and also CFLAGS/CXXFLAGS but
not LDFLAGS.
'''
testdir = os.path.join(self.common_test_dir, '132 get define')
@ -1150,11 +1150,13 @@ class AllPlatformTests(BasePlatformTests):
# % and # confuse the MSVC preprocessor
# !, ^, *, and < confuse lcc preprocessor
value = 'spaces and fun@$&()-=_+{}[]:;>?,./~`'
for env_var in ['CPPFLAGS', 'CFLAGS']:
for env_var in [{'CPPFLAGS'}, {'CFLAGS', 'CXXFLAGS'}]:
env = {}
env[env_var] = f'-D{define}="{value}"'
for i in env_var:
env[i] = f'-D{define}="{value}"'
env['LDFLAGS'] = '-DMESON_FAIL_VALUE=cflags-read'
self.init(testdir, extra_args=[f'-D{define}={value}'], override_envvars=env)
self.new_builddir()
def test_custom_target_exe_data_deterministic(self):
testdir = os.path.join(self.common_test_dir, '109 custom target capture')

Loading…
Cancel
Save