interpreter: fix `feature.require` handling of error message

Don't show a blank error when no `error_message` was passed as argument.
pull/9640/head
Benoit Pierre 3 years ago committed by Eli Schwartz
parent 858b114d5c
commit 007c4659c2
  1. 3
      mesonbuild/interpreter/interpreterobjects.py
  2. 2
      test cases/failing/106 feature require.bis/meson.build
  3. 1
      test cases/failing/106 feature require.bis/meson_options.txt
  4. 8
      test cases/failing/106 feature require.bis/test.json

@ -139,7 +139,8 @@ class FeatureOptionHolder(ObjectHolder[coredata.UserFeatureOption]):
assert isinstance(error_message, str)
if self.value == 'enabled':
prefix = f'Feature {self.held_object.name} cannot be enabled'
prefix = prefix + ': ' if error_message else ''
if error_message:
prefix += ': '
raise InterpreterException(prefix + error_message)
return self.as_disabled()

@ -0,0 +1,2 @@
project('no fallback', 'c')
foo = get_option('reqfeature').require(false)

@ -0,0 +1 @@
option('reqfeature', type : 'feature', value : 'enabled', description : 'A required feature')

@ -0,0 +1,8 @@
{
"stdout": [
{
"match": "re",
"line": ".*/meson\\.build:2:0: ERROR: Feature reqfeature cannot be enabled"
}
]
}
Loading…
Cancel
Save