aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mesonbuild/dependencies/hdf5.py7
-rw-r--r--mesonbuild/interpreter.py59
-rw-r--r--mesonbuild/modules/fs.py115
-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
9 files changed, 83 insertions, 124 deletions
diff --git a/mesonbuild/dependencies/hdf5.py b/mesonbuild/dependencies/hdf5.py
index ad28975..5ac60bb 100644
--- a/mesonbuild/dependencies/hdf5.py
+++ b/mesonbuild/dependencies/hdf5.py
@@ -126,8 +126,11 @@ class HDF5ConfigToolDependency(ConfigToolDependency):
if not self.is_found:
return
- args = self.get_config_value(['-show', '-noshlib' if kwargs.get('static', False) else '-shlib'], 'args')
- for arg in args[1:]:
+ # We first need to call the tool with -c to get the compile arguments
+ # and then without -c to get the link arguments.
+ args = self.get_config_value(['-show', '-c'], 'args')[1:]
+ args += self.get_config_value(['-show', '-noshlib' if kwargs.get('static', False) else '-shlib'], 'args')[1:]
+ for arg in args:
if arg.startswith(('-I', '-f', '-D')) or arg == '-pthread':
self.compile_args.append(arg)
elif arg.startswith(('-L', '-l', '-Wl')):
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/mesonbuild/modules/fs.py b/mesonbuild/modules/fs.py
index 44986f8..d0b5e97 100644
--- a/mesonbuild/modules/fs.py
+++ b/mesonbuild/modules/fs.py
@@ -26,9 +26,8 @@ from ..mesonlib import (
MesonException,
path_is_in_root,
)
-from ..interpreterbase import FeatureNew
+from ..interpreterbase import FeatureNew, typed_pos_args, noKwargs, permittedKwargs
-from ..interpreterbase import stringArgs, noKwargs
if T.TYPE_CHECKING:
from ..interpreter import Interpreter, ModuleState
@@ -60,69 +59,57 @@ class FSModule(ExtensionModule):
return path
def _check(self, check: str, state: 'ModuleState', args: T.Sequence[str]) -> ModuleReturnValue:
- if len(args) != 1:
- raise MesonException('fs.{} takes exactly one argument.'.format(check))
test_file = self._resolve_dir(state, args[0])
val = getattr(test_file, check)()
if isinstance(val, Path):
val = str(val)
return ModuleReturnValue(val, [])
- @stringArgs
@noKwargs
@FeatureNew('fs.expanduser', '0.54.0')
- def expanduser(self, state: 'ModuleState', args: T.Sequence[str], kwargs: dict) -> ModuleReturnValue:
- if len(args) != 1:
- raise MesonException('fs.expanduser takes exactly one argument.')
+ @typed_pos_args('fs.expanduser', str)
+ def expanduser(self, state: 'ModuleState', args: T.Tuple[str], kwargs: T.Dict[str, T.Any]) -> ModuleReturnValue:
return ModuleReturnValue(str(Path(args[0]).expanduser()), [])
- @stringArgs
@noKwargs
@FeatureNew('fs.is_absolute', '0.54.0')
- def is_absolute(self, state: 'ModuleState', args: T.Sequence[str], kwargs: dict) -> ModuleReturnValue:
- if len(args) != 1:
- raise MesonException('fs.is_absolute takes exactly one argument.')
+ @typed_pos_args('fs.is_absolute', str)
+ def is_absolute(self, state: 'ModuleState', args: T.Tuple[str], kwargs: T.Dict[str, T.Any]) -> ModuleReturnValue:
return ModuleReturnValue(PurePath(args[0]).is_absolute(), [])
- @stringArgs
@noKwargs
@FeatureNew('fs.as_posix', '0.54.0')
- def as_posix(self, state: 'ModuleState', args: T.Sequence[str], kwargs: dict) -> ModuleReturnValue:
+ @typed_pos_args('fs.as_posix', str)
+ def as_posix(self, state: 'ModuleState', args: T.Tuple[str], kwargs: T.Dict[str, T.Any]) -> ModuleReturnValue:
"""
this function assumes you are passing a Windows path, even if on a Unix-like system
and so ALL '\' are turned to '/', even if you meant to escape a character
"""
- if len(args) != 1:
- raise MesonException('fs.as_posix takes exactly one argument.')
return ModuleReturnValue(PureWindowsPath(args[0]).as_posix(), [])
- @stringArgs
@noKwargs
- def exists(self, state: 'ModuleState', args: T.Sequence[str], kwargs: dict) -> ModuleReturnValue:
+ @typed_pos_args('fs.exists', str)
+ def exists(self, state: 'ModuleState', args: T.Tuple[str], kwargs: T.Dict[str, T.Any]) -> ModuleReturnValue:
return self._check('exists', state, args)
- @stringArgs
@noKwargs
- def is_symlink(self, state: 'ModuleState', args: T.Sequence[str], kwargs: dict) -> ModuleReturnValue:
- if len(args) != 1:
- raise MesonException('fs.is_symlink takes exactly one argument.')
+ @typed_pos_args('fs.is_symlink', str)
+ def is_symlink(self, state: 'ModuleState', args: T.Tuple[str], kwargs: T.Dict[str, T.Any]) -> ModuleReturnValue:
return ModuleReturnValue(self._absolute_dir(state, args[0]).is_symlink(), [])
- @stringArgs
@noKwargs
- def is_file(self, state: 'ModuleState', args: T.Sequence[str], kwargs: dict) -> ModuleReturnValue:
+ @typed_pos_args('fs.is_file', str)
+ def is_file(self, state: 'ModuleState', args: T.Tuple[str], kwargs: T.Dict[str, T.Any]) -> ModuleReturnValue:
return self._check('is_file', state, args)
- @stringArgs
@noKwargs
- def is_dir(self, state: 'ModuleState', args: T.Sequence[str], kwargs: dict) -> ModuleReturnValue:
+ @typed_pos_args('fs.is_dir', str)
+ def is_dir(self, state: 'ModuleState', args: T.Tuple[str], kwargs: T.Dict[str, T.Any]) -> ModuleReturnValue:
return self._check('is_dir', state, args)
- @stringArgs
@noKwargs
- def hash(self, state: 'ModuleState', args: T.Sequence[str], kwargs: dict) -> ModuleReturnValue:
- if len(args) != 2:
- raise MesonException('fs.hash takes exactly two arguments.')
+ @typed_pos_args('fs.hash', str, str)
+ def hash(self, state: 'ModuleState', args: T.Tuple[str, str], kwargs: T.Dict[str, T.Any]) -> ModuleReturnValue:
file = self._resolve_dir(state, args[0])
if not file.is_file():
raise MesonException('{} is not a file and therefore cannot be hashed'.format(file))
@@ -134,11 +121,9 @@ class FSModule(ExtensionModule):
h.update(file.read_bytes())
return ModuleReturnValue(h.hexdigest(), [])
- @stringArgs
@noKwargs
- def size(self, state: 'ModuleState', args: T.Sequence[str], kwargs: dict) -> ModuleReturnValue:
- if len(args) != 1:
- raise MesonException('fs.size takes exactly one argument.')
+ @typed_pos_args('fs.size', str)
+ def size(self, state: 'ModuleState', args: T.Tuple[str], kwargs: T.Dict[str, T.Any]) -> ModuleReturnValue:
file = self._resolve_dir(state, args[0])
if not file.is_file():
raise MesonException('{} is not a file and therefore cannot be sized'.format(file))
@@ -147,11 +132,9 @@ class FSModule(ExtensionModule):
except ValueError:
raise MesonException('{} size could not be determined'.format(args[0]))
- @stringArgs
@noKwargs
- def is_samepath(self, state: 'ModuleState', args: T.Sequence[str], kwargs: dict) -> ModuleReturnValue:
- if len(args) != 2:
- raise MesonException('fs.is_samepath takes exactly two arguments.')
+ @typed_pos_args('fs.is_samepath', str, str)
+ def is_samepath(self, state: 'ModuleState', args: T.Tuple[str, str], kwargs: T.Dict[str, T.Any]) -> ModuleReturnValue:
file1 = self._resolve_dir(state, args[0])
file2 = self._resolve_dir(state, args[1])
if not file1.exists():
@@ -163,67 +146,49 @@ class FSModule(ExtensionModule):
except OSError:
return ModuleReturnValue(False, [])
- @stringArgs
@noKwargs
- def replace_suffix(self, state: 'ModuleState', args: T.Sequence[str], kwargs: dict) -> ModuleReturnValue:
- if len(args) != 2:
- raise MesonException('fs.replace_suffix takes exactly two arguments.')
+ @typed_pos_args('fs.replace_suffix', str, str)
+ def replace_suffix(self, state: 'ModuleState', args: T.Tuple[str, str], kwargs: T.Dict[str, T.Any]) -> ModuleReturnValue:
original = PurePath(args[0])
new = original.with_suffix(args[1])
return ModuleReturnValue(str(new), [])
- @stringArgs
@noKwargs
- def parent(self, state: 'ModuleState', args: T.Sequence[str], kwargs: dict) -> ModuleReturnValue:
- if len(args) != 1:
- raise MesonException('fs.parent takes exactly one argument.')
+ @typed_pos_args('fs.parent', str)
+ def parent(self, state: 'ModuleState', args: T.Tuple[str], kwargs: T.Dict[str, T.Any]) -> ModuleReturnValue:
original = PurePath(args[0])
new = original.parent
return ModuleReturnValue(str(new), [])
- @stringArgs
@noKwargs
- def name(self, state: 'ModuleState', args: T.Sequence[str], kwargs: dict) -> ModuleReturnValue:
- if len(args) != 1:
- raise MesonException('fs.name takes exactly one argument.')
+ @typed_pos_args('fs.name', str)
+ def name(self, state: 'ModuleState', args: T.Tuple[str], kwargs: T.Dict[str, T.Any]) -> ModuleReturnValue:
original = PurePath(args[0])
new = original.name
return ModuleReturnValue(str(new), [])
- @stringArgs
@noKwargs
+ @typed_pos_args('fs.stem', str)
@FeatureNew('fs.stem', '0.54.0')
- def stem(self, state: 'ModuleState', args: T.Sequence[str], kwargs: dict) -> ModuleReturnValue:
- if len(args) != 1:
- raise MesonException('fs.stem takes exactly one argument.')
+ def stem(self, state: 'ModuleState', args: T.Tuple[str], kwargs: T.Dict[str, T.Any]) -> ModuleReturnValue:
original = PurePath(args[0])
new = original.stem
return ModuleReturnValue(str(new), [])
- #@permittedKwargs({'encoding'})
@FeatureNew('fs.read', '0.57.0')
- def read(
- self,
- state: 'ModuleState',
- args: T.Sequence['FileOrString'],
- kwargs: T.Dict[str, T.Any]
- ) -> ModuleReturnValue:
- '''
- Read a file from the source tree and return its value as a decoded
- string. If the encoding is not specified, the file is assumed to be
- utf-8 encoded. Paths must be relative by default (to prevent accidents)
- and are forbidden to be read from the build directory (to prevent build
+ @permittedKwargs({'encoding'})
+ @typed_pos_args('fs.read', (str, File))
+ def read(self, state: 'ModuleState', args: T.Tuple['FileOrString'], kwargs: T.Dict[str, T.Any]) -> ModuleReturnValue:
+ """Read a file from the source tree and return its value as a decoded
+ string.
+
+ If the encoding is not specified, the file is assumed to be utf-8
+ encoded. Paths must be relative by default (to prevent accidents) and
+ are forbidden to be read from the build directory (to prevent build
loops)
- '''
- if len(args) != 1:
- raise MesonException('expected single positional <path> arg')
-
+ """
path = args[0]
- if not isinstance(path, (str, File)):
- raise MesonException(
- '<path> positional argument must be string or files() object')
-
- encoding = kwargs.get('encoding', 'utf-8')
+ encoding: str = kwargs.get('encoding', 'utf-8')
if not isinstance(encoding, str):
raise MesonException('`encoding` parameter must be a string')
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."
- }
- ]
-}