diff options
author | Dylan Baker <dylan@pnwbakers.com> | 2022-12-21 09:55:26 -0800 |
---|---|---|
committer | Eli Schwartz <eschwartz93@gmail.com> | 2023-02-15 22:58:50 -0500 |
commit | 3589815eb9dd8402deabedcd4492f33e04870c56 (patch) | |
tree | a039f474889d4be7b639dfacabb5d0b1163d80e4 /mesonbuild | |
parent | a3098fbfa32ae4ff654f0da45bcfcd9aa7893b5f (diff) | |
download | meson-3589815eb9dd8402deabedcd4492f33e04870c56.zip meson-3589815eb9dd8402deabedcd4492f33e04870c56.tar.gz meson-3589815eb9dd8402deabedcd4492f33e04870c56.tar.bz2 |
interpreter: add a feature.enable_auto_if
It's always been strange to me we don't have an opposite method of the
`disable_auto_if` method, but I've been pressed to find a case where we
_need_ one, because `disable_auto_if` can't be logically contorted to
work. I finally found the case where they're not equivalent: when you
don't want to convert to a boolean:
```meson
f = get_option('feat').disable_auto_if(not foo)
g = get_option('feat').enable_auto_if(foo)
dep1 = dependency('foo', required : f)
dep2 = dependency('foo', required : g)
```
Diffstat (limited to 'mesonbuild')
-rw-r--r-- | mesonbuild/interpreter/interpreterobjects.py | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/mesonbuild/interpreter/interpreterobjects.py b/mesonbuild/interpreter/interpreterobjects.py index 538d134..a750da9 100644 --- a/mesonbuild/interpreter/interpreterobjects.py +++ b/mesonbuild/interpreter/interpreterobjects.py @@ -41,7 +41,6 @@ if T.TYPE_CHECKING: separator: str - def extract_required_kwarg(kwargs: 'kwargs.ExtractRequired', subproject: 'SubProject', feature_check: T.Optional[FeatureCheckBase] = None, @@ -97,6 +96,7 @@ class FeatureOptionHolder(ObjectHolder[coredata.UserFeatureOption]): 'auto': self.auto_method, 'require': self.require_method, 'disable_auto_if': self.disable_auto_if_method, + 'enable_auto_if': self.enable_auto_if_method, }) @property @@ -108,6 +108,11 @@ class FeatureOptionHolder(ObjectHolder[coredata.UserFeatureOption]): disabled.value = 'disabled' return disabled + def as_enabled(self) -> coredata.UserFeatureOption: + enabled = copy.deepcopy(self.held_object) + enabled.value = 'enabled' + return enabled + @noPosargs @noKwargs def enabled_method(self, args: T.List[TYPE_var], kwargs: TYPE_kwargs) -> bool: @@ -152,6 +157,12 @@ class FeatureOptionHolder(ObjectHolder[coredata.UserFeatureOption]): def disable_auto_if_method(self, args: T.Tuple[bool], kwargs: TYPE_kwargs) -> coredata.UserFeatureOption: return copy.deepcopy(self.held_object) if self.value != 'auto' or not args[0] else self.as_disabled() + @FeatureNew('feature_option.enable_auto_if()', '1.1.0') + @noKwargs + @typed_pos_args('feature_option.enable_auto_if', bool) + 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) + class RunProcess(MesonInterpreterObject): |