aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Hirsch, Ph.D <scivision@users.noreply.github.com>2019-11-10 09:26:55 -0500
committerMichael Hirsch, Ph.D <scivision@users.noreply.github.com>2020-02-05 13:23:55 -0500
commitc2e6565029779b749dc3423291524115af1b2bd7 (patch)
treed8690f58aa0b70f73f6d7ae2c420aa6f2a71900a
parentdc8d2415836953a8e7fbb06931d34caab1bb2bfb (diff)
downloadmeson-c2e6565029779b749dc3423291524115af1b2bd7.zip
meson-c2e6565029779b749dc3423291524115af1b2bd7.tar.gz
meson-c2e6565029779b749dc3423291524115af1b2bd7.tar.bz2
add meson.get_native_property for native files
This allows Meson native-file [properties] to be used. This avoids the need to call meson from a script file or have a long command line invocation of `meson setup` The method meson.get_native_property('prop', 'fallback') is added. The native file can contain properties like ``` [properties] myprop1 = 'foo' mydir2 = 'lib/custom' ``` Then from within `meson.build` ```meson x1 = meson.get_native_property('myprop1') thedir = meson.get_native_property('mydir2', 'libs') ``` fallback values are optional
-rw-r--r--docs/markdown/snippets/native_property.md16
-rw-r--r--mesonbuild/environment.py1
-rw-r--r--mesonbuild/interpreter.py17
-rw-r--r--mesonbuild/mesonlib.py2
4 files changed, 35 insertions, 1 deletions
diff --git a/docs/markdown/snippets/native_property.md b/docs/markdown/snippets/native_property.md
new file mode 100644
index 0000000..6c49e80
--- /dev/null
+++ b/docs/markdown/snippets/native_property.md
@@ -0,0 +1,16 @@
+## Native file properties
+
+As of Meson 0.53.0, the `--native-file foo.txt` can contain:
+
+* binaries
+* paths
+* properties
+
+which are defined and used the same way as in cross files.
+The `properties` are new for Meson 0.53.0, and are read like:
+
+```meson
+x = meson.get_native_property('foobar', 'foo')
+```
+
+where `foobar` is the property name, and the optional `foo` is the fallback string value. \ No newline at end of file
diff --git a/mesonbuild/environment.py b/mesonbuild/environment.py
index beaff76..554d79b 100644
--- a/mesonbuild/environment.py
+++ b/mesonbuild/environment.py
@@ -538,6 +538,7 @@ class Environment:
coredata.load_configs(self.coredata.config_files))
binaries.build = BinaryTable(config.get('binaries', {}))
paths.build = Directories(**config.get('paths', {}))
+ properties.build = Properties(config.get('properties', {}))
## Read in cross file(s) to override host machine configuration
diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py
index e32e0a1..5e58b0e 100644
--- a/mesonbuild/interpreter.py
+++ b/mesonbuild/interpreter.py
@@ -1845,6 +1845,7 @@ class MesonMain(InterpreterObject):
'version': self.version_method,
'project_name': self.project_name_method,
'get_cross_property': self.get_cross_property_method,
+ 'get_native_property': self.get_native_property_method,
'backend': self.backend_method,
})
@@ -2031,6 +2032,22 @@ class MesonMain(InterpreterObject):
return args[1]
raise InterpreterException('Unknown cross property: %s.' % propname)
+ @noArgsFlattening
+ @permittedKwargs({})
+ def get_native_property_method(self, args, kwargs):
+ 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.build
+ return props[propname]
+ except Exception:
+ if len(args) == 2:
+ return args[1]
+ raise InterpreterException('Unknown native property: %s.' % propname)
+
known_library_kwargs = (
build.known_shlib_kwargs |
diff --git a/mesonbuild/mesonlib.py b/mesonbuild/mesonlib.py
index 85d883b..891e7a1 100644
--- a/mesonbuild/mesonlib.py
+++ b/mesonbuild/mesonlib.py
@@ -1,4 +1,4 @@
-# Copyright 2012-2015 The Meson development team
+# Copyright 2012-2019 The Meson development team
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.