Add feature.to_string()

This was previously accepted in
https://github.com/mesonbuild/meson/pull/6922, but the author never came
around to finish it, so here is everything that should be needed to add
the feature.
pull/12086/head
Tristan Partin 2 years ago
parent 14892eb849
commit ae70f25e23
  1. 3
      docs/markdown/snippets/feature_to_string.md
  2. 5
      docs/yaml/objects/feature.yaml
  3. 7
      mesonbuild/interpreter/interpreterobjects.py
  4. 3
      test cases/common/192 feature option/meson.build

@ -0,0 +1,3 @@
## Features now have a `to_string()` method
The method will return one of `auto`, `enabled`, or `disabled`.

@ -163,3 +163,8 @@ methods:
type: str
default: "''"
description: The error message to print if the check fails
- name: to_string
returns: str
since: 1.3.0
description: Returns the value of the feature option as a string.

@ -102,6 +102,7 @@ class FeatureOptionHolder(ObjectHolder[coredata.UserFeatureOption]):
'enable_auto_if': self.enable_auto_if_method,
'disable_if': self.disable_if_method,
'enable_if': self.enable_if_method,
'to_string': self.to_string_method,
})
@property
@ -197,6 +198,12 @@ class FeatureOptionHolder(ObjectHolder[coredata.UserFeatureOption]):
def enable_auto_if_method(self, args: T.Tuple[bool], kwargs: TYPE_kwargs) -> coredata.UserFeatureOption:
return self.as_enabled() if self.value == 'auto' and args[0] else copy.deepcopy(self.held_object)
@FeatureNew('feature_option.to_string()', '1.3.0')
@noKwargs
@noPosargs
def to_string_method(self, args: T.List[TYPE_var], kwargs: TYPE_kwargs) -> str:
return self.held_object.value
class RunProcess(MesonInterpreterObject):

@ -22,6 +22,7 @@ assert(required_opt.disable_auto_if(true).enabled(), 'Should be enabled option')
assert(required_opt.disable_auto_if(false).enabled(), 'Should be enabled option')
assert(required_opt.enable_auto_if(true).enabled(), 'Should be enabled option')
assert(required_opt.enable_auto_if(false).enabled(), 'Should be enabled option')
assert(required_opt.to_string() == 'enabled', 'Should be enabled option')
assert(not optional_opt.enabled(), 'Should be auto option')
assert(not optional_opt.disabled(), 'Should be auto option')
@ -37,6 +38,7 @@ assert(optional_opt.disable_auto_if(true).disabled(), 'Should be disabled auto o
assert(optional_opt.disable_auto_if(false).auto(), 'Should be auto option')
assert(optional_opt.enable_auto_if(true).enabled(), 'Should be disabled auto option')
assert(optional_opt.enable_auto_if(false).auto(), 'Should be auto option')
assert(optional_opt.to_string() == 'auto', 'Should be auto option')
assert(not disabled_opt.enabled(), 'Should be disabled option')
assert(disabled_opt.disabled(), 'Should be disabled option')
@ -51,6 +53,7 @@ assert(disabled_opt.disable_auto_if(true).disabled(), 'Should be disabled option
assert(disabled_opt.disable_auto_if(false).disabled(), 'Should be disabled option')
assert(disabled_opt.enable_auto_if(true).disabled(), 'Should be disabled option')
assert(disabled_opt.enable_auto_if(false).disabled(), 'Should be disabled option')
assert(disabled_opt.to_string() == 'disabled', 'Should be disabled option')
dep = dependency('threads', required : required_opt)
assert(dep.found(), 'Should find required "threads" dep')

Loading…
Cancel
Save