aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/mesonlib.py
diff options
context:
space:
mode:
authorJussi Pakkanen <jpakkane@gmail.com>2017-09-19 21:20:02 +0300
committerGitHub <noreply@github.com>2017-09-19 21:20:02 +0300
commit1556b1bdb0c5f94f2e3f2f0ebc59c8d9afeddc1c (patch)
tree3fb5c9c681bf7071c0765c0f2d55d067a27d70ce /mesonbuild/mesonlib.py
parent9c834a4ecddfa6ba38249be501d0ad1b481e48b1 (diff)
parente553d0807bad5db8290e26954ce7634bc0e181fd (diff)
downloadmeson-1556b1bdb0c5f94f2e3f2f0ebc59c8d9afeddc1c.zip
meson-1556b1bdb0c5f94f2e3f2f0ebc59c8d9afeddc1c.tar.gz
meson-1556b1bdb0c5f94f2e3f2f0ebc59c8d9afeddc1c.tar.bz2
Merge pull request #2264 from jeandet/master
Some refactoring, introduction of listify function.
Diffstat (limited to 'mesonbuild/mesonlib.py')
-rw-r--r--mesonbuild/mesonlib.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/mesonbuild/mesonlib.py b/mesonbuild/mesonlib.py
index d03e5a2..b5a6318 100644
--- a/mesonbuild/mesonlib.py
+++ b/mesonbuild/mesonlib.py
@@ -473,6 +473,26 @@ def replace_if_different(dst, dst_tmp):
else:
os.unlink(dst_tmp)
+
+def listify(*args):
+ '''
+ Returns a list with all args embedded in a list if they are not of type list.
+ This function preserves order.
+ '''
+ if len(args) == 1: # Special case with one single arg
+ return args[0] if type(args[0]) is list else [args[0]]
+ return [item if type(item) is list else [item] for item in args]
+
+
+def extract_as_list(dict_object, *keys, pop = False):
+ '''
+ Extracts all values from given dict_object and listifies them.
+ '''
+ if pop:
+ return listify(*[dict_object.pop(key, []) for key in keys])
+ return listify(*[dict_object.get(key, []) for key in keys])
+
+
def typeslistify(item, types):
'''
Ensure that type(@item) is one of @types or a