aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mesonbuild/coredata.py15
1 files changed, 11 insertions, 4 deletions
diff --git a/mesonbuild/coredata.py b/mesonbuild/coredata.py
index 211efec..a4ce965 100644
--- a/mesonbuild/coredata.py
+++ b/mesonbuild/coredata.py
@@ -144,7 +144,14 @@ class UserIntegerOption(UserOption[int]):
except ValueError:
raise MesonException('Value string "%s" is not convertible to an integer.' % valuestring)
-class UserUmaskOption(UserIntegerOption, UserOption[T.Union[str, int]]):
+class OctalInt(int):
+ # NinjaBackend.get_user_option_args uses str() to converts it to a command line option
+ # UserUmaskOption.toint() uses int(str, 8) to convert it to an integer
+ # So we need to use oct instead of dec here if we do not want values to be misinterpreted.
+ def __str__(self):
+ return oct(int(self))
+
+class UserUmaskOption(UserIntegerOption, UserOption[T.Union[str, OctalInt]]):
def __init__(self, description: str, value: T.Any, yielding: T.Optional[bool] = None):
super().__init__(description, (0, 0o777, value), yielding)
self.choices = ['preserve', '0000-0777']
@@ -154,12 +161,12 @@ class UserUmaskOption(UserIntegerOption, UserOption[T.Union[str, int]]):
return self.value
return format(self.value, '04o')
- def validate_value(self, value: T.Any) -> T.Union[str, int]:
+ def validate_value(self, value: T.Any) -> T.Union[str, OctalInt]:
if value is None or value == 'preserve':
return 'preserve'
- return super().validate_value(value)
+ return OctalInt(super().validate_value(value))
- def toint(self, valuestring: T.Union[str, int]) -> int:
+ def toint(self, valuestring: T.Union[str, OctalInt]) -> int:
try:
return int(valuestring, 8)
except ValueError as e: