aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2021-02-25 14:24:17 -0800
committerDylan Baker <dylan@pnwbakers.com>2021-02-26 15:31:15 -0800
commit219535aad426e9678fcab4887c1fdce321d2ba05 (patch)
treef017acad35a3a365e8d5e3585dd1e2a671ee269b
parent2d8d21d5bc9a914a81e91437ff3fda45582b588c (diff)
downloadmeson-219535aad426e9678fcab4887c1fdce321d2ba05.zip
meson-219535aad426e9678fcab4887c1fdce321d2ba05.tar.gz
meson-219535aad426e9678fcab4887c1fdce321d2ba05.tar.bz2
interpreter: Clean up and simplify/optimize get_(external|cross)_property
These are both way more compilcated than they needed to be, this is a much simpler implementation, and is shared between cross and external properies.
-rw-r--r--mesonbuild/interpreter.py59
-rw-r--r--test cases/failing/111 no build get_external_property/meson.build3
-rw-r--r--test cases/failing/111 no build get_external_property/test.json7
-rw-r--r--test cases/failing/28 no crossprop/test.json2
-rw-r--r--test cases/failing/99 no host get_external_property/meson.build (renamed from test cases/failing/99 no native prop/meson.build)0
-rw-r--r--test cases/failing/99 no host get_external_property/test.json7
-rw-r--r--test cases/failing/99 no native prop/test.json7
7 files changed, 38 insertions, 47 deletions
diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py
index ea65bc6..0225de4 100644
--- a/mesonbuild/interpreter.py
+++ b/mesonbuild/interpreter.py
@@ -25,7 +25,7 @@ from .mesonlib import FileMode, MachineChoice, OptionKey, Popen_safe, listify, e
from .dependencies import ExternalProgram
from .dependencies import InternalDependency, Dependency, NotFoundDependency, DependencyException
from .depfile import DepFile
-from .interpreterbase import InterpreterBase
+from .interpreterbase import InterpreterBase, typed_pos_args
from .interpreterbase import check_stringlist, flatten, noPosargs, noKwargs, stringArgs, permittedKwargs, noArgsFlattening
from .interpreterbase import InterpreterException, InvalidArguments, InvalidCode, SubdirDoneRequest
from .interpreterbase import InterpreterObject, MutableInterpreterObject, Disabler, disablerIfNotFound
@@ -1922,7 +1922,7 @@ class Summary:
mlog.log(*line, sep=list_sep)
class MesonMain(InterpreterObject):
- def __init__(self, build, interpreter):
+ def __init__(self, build: 'build.Build', interpreter: 'Interpreter'):
InterpreterObject.__init__(self)
self.build = build
self.interpreter = interpreter
@@ -2244,51 +2244,32 @@ class MesonMain(InterpreterObject):
def project_name_method(self, args, kwargs):
return self.interpreter.active_projectname
+ def __get_external_property_impl(self, propname: str, fallback: T.Optional[object], machine: MachineChoice) -> object:
+ """Shared implementation for get_cross_property and get_external_property."""
+ try:
+ return self.interpreter.environment.properties[machine][propname]
+ except KeyError:
+ if fallback is not None:
+ return fallback
+ raise InterpreterException(f'Unknown property for {machine.get_lower_case_name()} machine: {propname}')
+
@noArgsFlattening
@permittedKwargs({})
@FeatureDeprecated('meson.get_cross_property', '0.58.0', 'Use meson.get_external_property() instead')
- def get_cross_property_method(self, args, kwargs) -> str:
- if len(args) < 1 or len(args) > 2:
- raise InterpreterException('Must have one or two arguments.')
- propname = args[0]
- if not isinstance(propname, str):
- raise InterpreterException('Property name must be string.')
- try:
- props = self.interpreter.environment.properties.host
- return props[propname]
- except Exception:
- if len(args) == 2:
- return args[1]
- raise InterpreterException('Unknown cross property: %s.' % propname)
+ @typed_pos_args('meson.get_cross_property', str, optargs=[object])
+ def get_cross_property_method(self, args: T.Tuple[str, T.Optional[object]], kwargs: T.Dict[str, T.Any]) -> object:
+ propname, fallback = args
+ return self.__get_external_property_impl(propname, fallback, MachineChoice.HOST)
@noArgsFlattening
@permittedKwargs({'native'})
@FeatureNew('meson.get_external_property', '0.54.0')
- def get_external_property_method(self, args: T.Sequence[str], kwargs: dict) -> str:
- if len(args) < 1 or len(args) > 2:
- raise InterpreterException('Must have one or two positional arguments.')
- propname = args[0]
- if not isinstance(propname, str):
- raise InterpreterException('Property name must be string.')
+ @typed_pos_args('meson.get_external_property', str, optargs=[object])
+ def get_external_property_method(self, args: T.Tuple[str, T.Optional[object]], kwargs: T.Dict[str, T.Any]) -> object:
+ propname, fallback = args
+ machine = self.interpreter.machine_from_native_kwarg(kwargs)
+ return self.__get_external_property_impl(propname, fallback, machine)
- def _get_native() -> str:
- try:
- props = self.interpreter.environment.properties.build
- return props[propname]
- except Exception:
- if len(args) == 2:
- return args[1]
- raise InterpreterException('Unknown native property: %s.' % propname)
- if 'native' in kwargs:
- if kwargs['native']:
- return _get_native()
- else:
- return self.get_cross_property_method(args, {})
- else: # native: not specified
- if self.build.environment.is_cross_build():
- return self.get_cross_property_method(args, kwargs)
- else:
- return _get_native()
@permittedKwargs({'native'})
@FeatureNew('meson.has_external_property', '0.58.0')
diff --git a/test cases/failing/111 no build get_external_property/meson.build b/test cases/failing/111 no build get_external_property/meson.build
new file mode 100644
index 0000000..8a4215c
--- /dev/null
+++ b/test cases/failing/111 no build get_external_property/meson.build
@@ -0,0 +1,3 @@
+project('missing property')
+
+message(meson.get_external_property('nonexisting', native : true))
diff --git a/test cases/failing/111 no build get_external_property/test.json b/test cases/failing/111 no build get_external_property/test.json
new file mode 100644
index 0000000..8b004be
--- /dev/null
+++ b/test cases/failing/111 no build get_external_property/test.json
@@ -0,0 +1,7 @@
+{
+ "stdout": [
+ {
+ "line": "test cases/failing/111 no build get_external_property/meson.build:3:0: ERROR: Unknown property for build machine: nonexisting"
+ }
+ ]
+}
diff --git a/test cases/failing/28 no crossprop/test.json b/test cases/failing/28 no crossprop/test.json
index a186a68..6fb9dce 100644
--- a/test cases/failing/28 no crossprop/test.json
+++ b/test cases/failing/28 no crossprop/test.json
@@ -1,7 +1,7 @@
{
"stdout": [
{
- "line": "test cases/failing/28 no crossprop/meson.build:3:0: ERROR: Unknown cross property: nonexisting."
+ "line": "test cases/failing/28 no crossprop/meson.build:3:0: ERROR: Unknown property for host machine: nonexisting"
}
]
}
diff --git a/test cases/failing/99 no native prop/meson.build b/test cases/failing/99 no host get_external_property/meson.build
index c956754..c956754 100644
--- a/test cases/failing/99 no native prop/meson.build
+++ b/test cases/failing/99 no host get_external_property/meson.build
diff --git a/test cases/failing/99 no host get_external_property/test.json b/test cases/failing/99 no host get_external_property/test.json
new file mode 100644
index 0000000..44b5245
--- /dev/null
+++ b/test cases/failing/99 no host get_external_property/test.json
@@ -0,0 +1,7 @@
+{
+ "stdout": [
+ {
+ "line": "test cases/failing/99 no host get_external_property/meson.build:3:0: ERROR: Unknown property for host machine: nonexisting"
+ }
+ ]
+}
diff --git a/test cases/failing/99 no native prop/test.json b/test cases/failing/99 no native prop/test.json
deleted file mode 100644
index 8c320d9..0000000
--- a/test cases/failing/99 no native prop/test.json
+++ /dev/null
@@ -1,7 +0,0 @@
-{
- "stdout": [
- {
- "line": "test cases/failing/99 no native prop/meson.build:3:0: ERROR: Unknown native property: nonexisting."
- }
- ]
-}