|
|
|
@ -1,5 +1,4 @@ |
|
|
|
|
# Copyright 2012-2022 The Meson development team |
|
|
|
|
|
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
|
# you may not use this file except in compliance with the License. |
|
|
|
|
# You may obtain a copy of the License at |
|
|
|
@ -76,14 +75,15 @@ class MesonVersionMismatchException(MesonException): |
|
|
|
|
|
|
|
|
|
class UserOption(T.Generic[_T], HoldableObject): |
|
|
|
|
def __init__(self, description: str, choices: T.Optional[T.Union[str, T.List[_T]]], |
|
|
|
|
yielding: bool): |
|
|
|
|
yielding: bool, |
|
|
|
|
deprecated: T.Union[bool, str, T.Dict[str, str], T.List[str]] = False): |
|
|
|
|
super().__init__() |
|
|
|
|
self.choices = choices |
|
|
|
|
self.description = description |
|
|
|
|
if not isinstance(yielding, bool): |
|
|
|
|
raise MesonException('Value of "yielding" must be a boolean.') |
|
|
|
|
self.yielding = yielding |
|
|
|
|
self.deprecated: T.Union[bool, str, T.Dict[str, str], T.List[str]] = False |
|
|
|
|
self.deprecated = deprecated |
|
|
|
|
|
|
|
|
|
def listify(self, value: T.Any) -> T.List[T.Any]: |
|
|
|
|
return [value] |
|
|
|
@ -102,8 +102,9 @@ class UserOption(T.Generic[_T], HoldableObject): |
|
|
|
|
self.value = self.validate_value(newvalue) |
|
|
|
|
|
|
|
|
|
class UserStringOption(UserOption[str]): |
|
|
|
|
def __init__(self, description: str, value: T.Any, yielding: bool = DEFAULT_YIELDING): |
|
|
|
|
super().__init__(description, None, yielding) |
|
|
|
|
def __init__(self, description: str, value: T.Any, yielding: bool = DEFAULT_YIELDING, |
|
|
|
|
deprecated: T.Union[bool, str, T.Dict[str, str], T.List[str]] = False): |
|
|
|
|
super().__init__(description, None, yielding, deprecated) |
|
|
|
|
self.set_value(value) |
|
|
|
|
|
|
|
|
|
def validate_value(self, value: T.Any) -> str: |
|
|
|
@ -112,8 +113,9 @@ class UserStringOption(UserOption[str]): |
|
|
|
|
return value |
|
|
|
|
|
|
|
|
|
class UserBooleanOption(UserOption[bool]): |
|
|
|
|
def __init__(self, description: str, value, yielding: bool = DEFAULT_YIELDING) -> None: |
|
|
|
|
super().__init__(description, [True, False], yielding) |
|
|
|
|
def __init__(self, description: str, value, yielding: bool = DEFAULT_YIELDING, |
|
|
|
|
deprecated: T.Union[bool, str, T.Dict[str, str], T.List[str]] = False): |
|
|
|
|
super().__init__(description, [True, False], yielding, deprecated) |
|
|
|
|
self.set_value(value) |
|
|
|
|
|
|
|
|
|
def __bool__(self) -> bool: |
|
|
|
@ -131,7 +133,8 @@ class UserBooleanOption(UserOption[bool]): |
|
|
|
|
raise MesonException('Value %s is not boolean (true or false).' % value) |
|
|
|
|
|
|
|
|
|
class UserIntegerOption(UserOption[int]): |
|
|
|
|
def __init__(self, description: str, value: T.Any, yielding: bool = DEFAULT_YIELDING): |
|
|
|
|
def __init__(self, description: str, value: T.Any, yielding: bool = DEFAULT_YIELDING, |
|
|
|
|
deprecated: T.Union[bool, str, T.Dict[str, str], T.List[str]] = False): |
|
|
|
|
min_value, max_value, default_value = value |
|
|
|
|
self.min_value = min_value |
|
|
|
|
self.max_value = max_value |
|
|
|
@ -141,7 +144,7 @@ class UserIntegerOption(UserOption[int]): |
|
|
|
|
if max_value is not None: |
|
|
|
|
c.append('<=' + str(max_value)) |
|
|
|
|
choices = ', '.join(c) |
|
|
|
|
super().__init__(description, choices, yielding) |
|
|
|
|
super().__init__(description, choices, yielding, deprecated) |
|
|
|
|
self.set_value(default_value) |
|
|
|
|
|
|
|
|
|
def validate_value(self, value: T.Any) -> int: |
|
|
|
@ -169,8 +172,9 @@ class OctalInt(int): |
|
|
|
|
return oct(int(self)) |
|
|
|
|
|
|
|
|
|
class UserUmaskOption(UserIntegerOption, UserOption[T.Union[str, OctalInt]]): |
|
|
|
|
def __init__(self, description: str, value: T.Any, yielding: bool = DEFAULT_YIELDING): |
|
|
|
|
super().__init__(description, (0, 0o777, value), yielding) |
|
|
|
|
def __init__(self, description: str, value: T.Any, yielding: bool = DEFAULT_YIELDING, |
|
|
|
|
deprecated: T.Union[bool, str, T.Dict[str, str], T.List[str]] = False): |
|
|
|
|
super().__init__(description, (0, 0o777, value), yielding, deprecated) |
|
|
|
|
self.choices = ['preserve', '0000-0777'] |
|
|
|
|
|
|
|
|
|
def printable_value(self) -> str: |
|
|
|
@ -191,8 +195,9 @@ class UserUmaskOption(UserIntegerOption, UserOption[T.Union[str, OctalInt]]): |
|
|
|
|
|
|
|
|
|
class UserComboOption(UserOption[str]): |
|
|
|
|
def __init__(self, description: str, choices: T.List[str], value: T.Any, |
|
|
|
|
yielding: bool = DEFAULT_YIELDING): |
|
|
|
|
super().__init__(description, choices, yielding) |
|
|
|
|
yielding: bool = DEFAULT_YIELDING, |
|
|
|
|
deprecated: T.Union[bool, str, T.Dict[str, str], T.List[str]] = False): |
|
|
|
|
super().__init__(description, choices, yielding, deprecated) |
|
|
|
|
if not isinstance(self.choices, list): |
|
|
|
|
raise MesonException('Combo choices must be an array.') |
|
|
|
|
for i in self.choices: |
|
|
|
@ -218,8 +223,9 @@ class UserArrayOption(UserOption[T.List[str]]): |
|
|
|
|
def __init__(self, description: str, value: T.Union[str, T.List[str]], |
|
|
|
|
split_args: bool = False, user_input: bool = False, |
|
|
|
|
allow_dups: bool = False, yielding: bool = DEFAULT_YIELDING, |
|
|
|
|
choices: T.Optional[T.List[str]] = None) -> None: |
|
|
|
|
super().__init__(description, choices if choices is not None else [], yielding) |
|
|
|
|
choices: T.Optional[T.List[str]] = None, |
|
|
|
|
deprecated: T.Union[bool, str, T.Dict[str, str], T.List[str]] = False): |
|
|
|
|
super().__init__(description, choices if choices is not None else [], yielding, deprecated) |
|
|
|
|
self.split_args = split_args |
|
|
|
|
self.allow_dups = allow_dups |
|
|
|
|
self.value = self.validate_value(value, user_input=user_input) |
|
|
|
@ -277,8 +283,9 @@ class UserArrayOption(UserOption[T.List[str]]): |
|
|
|
|
class UserFeatureOption(UserComboOption): |
|
|
|
|
static_choices = ['enabled', 'disabled', 'auto'] |
|
|
|
|
|
|
|
|
|
def __init__(self, description: str, value: T.Any, yielding: bool = DEFAULT_YIELDING): |
|
|
|
|
super().__init__(description, self.static_choices, value, yielding) |
|
|
|
|
def __init__(self, description: str, value: T.Any, yielding: bool = DEFAULT_YIELDING, |
|
|
|
|
deprecated: T.Union[bool, str, T.Dict[str, str], T.List[str]] = False): |
|
|
|
|
super().__init__(description, self.static_choices, value, yielding, deprecated) |
|
|
|
|
self.name: T.Optional[str] = None # TODO: Refactor options to all store their name |
|
|
|
|
|
|
|
|
|
def is_enabled(self) -> bool: |
|
|
|
|