aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2018-06-05 08:33:36 -0700
committerNirbheek Chauhan <nirbheek.chauhan@gmail.com>2018-06-29 10:56:25 +0000
commitf3a8f9c34d95d862fb4d12869a7b31cea592561f (patch)
treec6670c6aeee48e39874377104d945467366a8443
parent14fe0985f7ac6cce317e355ae457e7cf5fbb8ee4 (diff)
downloadmeson-f3a8f9c34d95d862fb4d12869a7b31cea592561f.zip
meson-f3a8f9c34d95d862fb4d12869a7b31cea592561f.tar.gz
meson-f3a8f9c34d95d862fb4d12869a7b31cea592561f.tar.bz2
Options: treat array option -Dopt= and -Dopt=[] as equivalent
Currently the former will be parsed as [''], while the latter is parsed as [] in python. This makes for some obnoxious special handling depending on what the user passes. This is even more obnoxious since for string type arguments this doesn't require special handling.
-rw-r--r--docs/markdown/Build-options.md3
-rw-r--r--docs/markdown/snippets/empty-array-opts.md5
-rw-r--r--mesonbuild/coredata.py2
-rwxr-xr-xrun_unittests.py20
4 files changed, 30 insertions, 0 deletions
diff --git a/docs/markdown/Build-options.md b/docs/markdown/Build-options.md
index 0093a1b..66c9cb5 100644
--- a/docs/markdown/Build-options.md
+++ b/docs/markdown/Build-options.md
@@ -61,6 +61,9 @@ empty. The `value` parameter specifies the default value of the option
and if it is unset then the values of `choices` will be used as the
default.
+As of 0.47.0 -Dopt= and -Dopt=[] both pass an empty list, before this -Dopt=
+would pass a list with an empty string.
+
This type is available since version 0.44.0
### Features
diff --git a/docs/markdown/snippets/empty-array-opts.md b/docs/markdown/snippets/empty-array-opts.md
new file mode 100644
index 0000000..6d3b05d
--- /dev/null
+++ b/docs/markdown/snippets/empty-array-opts.md
@@ -0,0 +1,5 @@
+## Array options treat -Dopt= and -Dopt=[] as equivalent
+
+Prior to this change passing -Dopt= to an array opt would be interpreted as
+[''] (an array with an empty string), now -Dopt= is the same as -Dopt=[], an
+empty list.
diff --git a/mesonbuild/coredata.py b/mesonbuild/coredata.py
index f075e75..560ebf6 100644
--- a/mesonbuild/coredata.py
+++ b/mesonbuild/coredata.py
@@ -154,6 +154,8 @@ class UserArrayOption(UserOption):
if isinstance(value, str):
if value.startswith('['):
newvalue = ast.literal_eval(value)
+ elif value == '':
+ newvalue = []
else:
if self.shlex_split:
newvalue = shlex.split(value)
diff --git a/run_unittests.py b/run_unittests.py
index 4cfb743..0abe419 100755
--- a/run_unittests.py
+++ b/run_unittests.py
@@ -1786,6 +1786,26 @@ int main(int argc, char **argv) {
changed = get_opt()
self.assertDictEqual(changed, expected)
+ def test_array_option_empty_equivalents(self):
+ """Array options treat -Dopt=[] and -Dopt= as equivalent."""
+ def get_opt():
+ opts = self.introspect('--buildoptions')
+ for x in opts:
+ if x.get('name') == 'list':
+ return x
+ raise Exception(opts)
+
+ expected = {
+ 'name': 'list',
+ 'description': 'list',
+ 'type': 'array',
+ 'value': [],
+ }
+ tdir = os.path.join(self.unit_test_dir, '18 array option')
+ self.init(tdir, extra_args='-Dlist=')
+ original = get_opt()
+ self.assertDictEqual(original, expected)
+
def opt_has(self, name, value):
res = self.introspect('--buildoptions')
found = False