Skip to content

Commit

Permalink
Options: treat array option -Dopt= and -Dopt=[] as equivalent
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dcbaker authored and nirbheek committed Jun 29, 2018
1 parent 14fe098 commit f3a8f9c
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 0 deletions.
3 changes: 3 additions & 0 deletions docs/markdown/Build-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions docs/markdown/snippets/empty-array-opts.md
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 2 additions & 0 deletions mesonbuild/coredata.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ def validate_value(self, value, user_input=True):
if isinstance(value, str):
if value.startswith('['):
newvalue = ast.literal_eval(value)
elif value == '':
newvalue = []
else:
if self.shlex_split:
newvalue = shlex.split(value)
Expand Down
20 changes: 20 additions & 0 deletions run_unittests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1786,6 +1786,26 @@ def get_opt():
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
Expand Down

0 comments on commit f3a8f9c

Please sign in to comment.