summaryrefslogtreecommitdiff
path: root/mesonbuild/utils
diff options
context:
space:
mode:
authorCharles Brunet <charles.brunet@optelgroup.com>2024-01-11 15:20:14 -0500
committerDylan Baker <dylan@pnwbakers.com>2024-03-15 09:23:46 -0700
commitd08ef2c08bb0120f0ba20dbc10575b7e15577349 (patch)
tree478ea67511d3c685e1426f8008ebc86ab0d866e1 /mesonbuild/utils
parentb1340e9bb1f243e4de8f2d89415a45ade476a3dc (diff)
downloadmeson-d08ef2c08bb0120f0ba20dbc10575b7e15577349.tar.gz
move UserArrayOption.listify_value to mesonlib
This function is used at 3 different places and it does not justify it as being a staticmethod instead of being a free function.
Diffstat (limited to 'mesonbuild/utils')
-rw-r--r--mesonbuild/utils/universal.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/mesonbuild/utils/universal.py b/mesonbuild/utils/universal.py
index 0fb860796..a5383455a 100644
--- a/mesonbuild/utils/universal.py
+++ b/mesonbuild/utils/universal.py
@@ -7,6 +7,7 @@
from __future__ import annotations
from pathlib import Path
import argparse
+import ast
import enum
import sys
import stat
@@ -129,6 +130,7 @@ __all__ = [
'iter_regexin_iter',
'join_args',
'listify',
+ 'listify_array_value',
'partition',
'path_is_in_root',
'pickle_load',
@@ -1435,6 +1437,26 @@ def listify(item: T.Any, flatten: bool = True) -> T.List[T.Any]:
result.append(i)
return result
+def listify_array_value(value: T.Union[str, T.List[str]], shlex_split_args: bool = False) -> T.List[str]:
+ if isinstance(value, str):
+ if value.startswith('['):
+ try:
+ newvalue = ast.literal_eval(value)
+ except ValueError:
+ raise MesonException(f'malformed value {value}')
+ elif value == '':
+ newvalue = []
+ else:
+ if shlex_split_args:
+ newvalue = split_args(value)
+ else:
+ newvalue = [v.strip() for v in value.split(',')]
+ elif isinstance(value, list):
+ newvalue = value
+ else:
+ raise MesonException(f'"{value}" should be a string array, but it is not')
+ assert isinstance(newvalue, list)
+ return newvalue
def extract_as_list(dict_object: T.Dict[_T, _U], key: _T, pop: bool = False) -> T.List[_U]:
'''