summaryrefslogtreecommitdiff
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
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.
-rw-r--r--mesonbuild/coredata.py27
-rw-r--r--mesonbuild/mcompile.py5
-rw-r--r--mesonbuild/utils/universal.py22
3 files changed, 27 insertions, 27 deletions
diff --git a/mesonbuild/coredata.py b/mesonbuild/coredata.py
index bb481cae9..112310745 100644
--- a/mesonbuild/coredata.py
+++ b/mesonbuild/coredata.py
@@ -20,7 +20,7 @@ from .mesonlib import (
PerMachineDefaultable, default_libdir, default_libexecdir,
default_prefix, default_datadir, default_includedir, default_infodir,
default_localedir, default_mandir, default_sbindir, default_sysconfdir,
- split_args, OptionKey, OptionType, stringlistify,
+ listify_array_value, OptionKey, OptionType, stringlistify,
pickle_load
)
from .wrap import WrapMode
@@ -268,29 +268,8 @@ class UserArrayOption(UserOption[T.List[str]]):
self.allow_dups = allow_dups
self.set_value(value)
- @staticmethod
- def listify_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 option {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')
- return newvalue
-
def listify(self, value: T.Any) -> T.List[T.Any]:
- return self.listify_value(value, self.split_args)
+ return listify_array_value(value, self.split_args)
def validate_value(self, value: T.Union[str, T.List[str]]) -> T.List[str]:
newvalue = self.listify(value)
@@ -364,7 +343,7 @@ class UserStdOption(UserComboOption):
self.choices += gnu_stds_map.keys()
def validate_value(self, value: T.Union[str, T.List[str]]) -> str:
- candidates = UserArrayOption.listify_value(value)
+ candidates = listify_array_value(value)
unknown = [std for std in candidates if std not in self.all_stds]
if unknown:
raise MesonException(f'Unknown {self.lang.upper()} std {unknown}. Possible values are {self.all_stds}.')
diff --git a/mesonbuild/mcompile.py b/mesonbuild/mcompile.py
index 9c2f5e1e8..b07b60a9e 100644
--- a/mesonbuild/mcompile.py
+++ b/mesonbuild/mcompile.py
@@ -16,16 +16,15 @@ from pathlib import Path
from . import mlog
from . import mesonlib
-from .mesonlib import MesonException, RealPathAction, join_args, setup_vsenv
+from .mesonlib import MesonException, RealPathAction, join_args, listify_array_value, setup_vsenv
from mesonbuild.environment import detect_ninja
-from mesonbuild.coredata import UserArrayOption
from mesonbuild import build
if T.TYPE_CHECKING:
import argparse
def array_arg(value: str) -> T.List[str]:
- return UserArrayOption.listify_value(value)
+ return listify_array_value(value)
def validate_builddir(builddir: Path) -> None:
if not (builddir / 'meson-private' / 'coredata.dat').is_file():
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]:
'''