aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild
diff options
context:
space:
mode:
authorXavier Claessens <xavier.claessens@collabora.com>2018-05-13 10:36:58 -0400
committerNirbheek Chauhan <nirbheek.chauhan@gmail.com>2018-06-06 20:02:37 +0000
commit58a9555ddf49d851a7eb56874df1d0b3f498e53e (patch)
treed931badd6ffbe14f8fc5a67039003225b9e621c1 /mesonbuild
parent64bfc6cf7b6439578191e75cbc05bb96de1c70e2 (diff)
downloadmeson-58a9555ddf49d851a7eb56874df1d0b3f498e53e.zip
meson-58a9555ddf49d851a7eb56874df1d0b3f498e53e.tar.gz
meson-58a9555ddf49d851a7eb56874df1d0b3f498e53e.tar.bz2
UserArrayOption: Small cleanup in value parsing
It is nicer to early raise exception if the value from meson_options.txt is not a string in "[]" format than duplicating the parser code for both cases. Also it was checking for duplicated items only in the user_input case, but we should also check for dups in the default value from meson_options.txt.
Diffstat (limited to 'mesonbuild')
-rw-r--r--mesonbuild/coredata.py25
1 files changed, 12 insertions, 13 deletions
diff --git a/mesonbuild/coredata.py b/mesonbuild/coredata.py
index 93a3d2f..aaadfcb 100644
--- a/mesonbuild/coredata.py
+++ b/mesonbuild/coredata.py
@@ -148,15 +148,10 @@ class UserArrayOption(UserOption):
# options). Users can put their input in as a comma separated
# string, but for defining options in meson_options.txt the format
# should match that of a combo
- if not user_input:
- if isinstance(value, str):
- if not value.startswith('['):
- raise MesonException('Valuestring does not define an array: ' + value)
- newvalue = ast.literal_eval(value)
- else:
- newvalue = value
- else:
- assert isinstance(value, str)
+ if not user_input and isinstance(value, str) and not value.startswith('['):
+ raise MesonException('Value does not define an array: ' + value)
+
+ if isinstance(value, str):
if value.startswith('['):
newvalue = ast.literal_eval(value)
else:
@@ -164,11 +159,15 @@ class UserArrayOption(UserOption):
newvalue = shlex.split(value)
else:
newvalue = [v.strip() for v in value.split(',')]
- if len(set(newvalue)) != len(newvalue):
- mlog.log(mlog.red('DEPRECATION:'), '''Duplicated values in an array type is deprecated.
-This will become a hard error in the future.''')
- if not isinstance(newvalue, list):
+ elif isinstance(value, list):
+ newvalue = value
+ else:
raise MesonException('"{0}" should be a string array, but it is not'.format(str(newvalue)))
+
+ if len(set(newvalue)) != len(newvalue):
+ msg = 'Duplicated values in array option "%s" is deprecated. ' \
+ 'This will become a hard error in the future.' % (self.name)
+ mlog.log(mlog.red('DEPRECATION:'), msg)
for i in newvalue:
if not isinstance(i, str):
raise MesonException('String array element "{0}" is not a string.'.format(str(newvalue)))