From c0057da133d212dd4e0efeab84e2a34f814c5c83 Mon Sep 17 00:00:00 2001 From: Jussi Pakkanen Date: Sat, 2 Jul 2016 00:00:03 +0300 Subject: [PATCH] Can get arbitrary data from cross file properties. --- manual tests/9 nostdlib/meson.build | 4 ++++ mesonbuild/environment.py | 3 +++ mesonbuild/interpreter.py | 15 +++++++++++++++ test cases/failing/29 no crossprop/meson.build | 3 +++ 4 files changed, 25 insertions(+) create mode 100644 test cases/failing/29 no crossprop/meson.build diff --git a/manual tests/9 nostdlib/meson.build b/manual tests/9 nostdlib/meson.build index 3ef743ebf..9c5f949b2 100644 --- a/manual tests/9 nostdlib/meson.build +++ b/manual tests/9 nostdlib/meson.build @@ -1,5 +1,9 @@ project('own libc', 'c') +# Not related to this test, but could not find a better place for this test. +assert(meson.get_cross_property('nonexisting', 'defaultvalue') == 'defaultvalue', + 'Cross prop getting is broken.') + # A simple project that uses its own libc. # Note that we don't need to specify anything, the flags to use diff --git a/mesonbuild/environment.py b/mesonbuild/environment.py index e1e46138f..3868301de 100644 --- a/mesonbuild/environment.py +++ b/mesonbuild/environment.py @@ -771,6 +771,9 @@ class CrossBuildInfo(): def get_stdlib(self, language): return self.config['properties'][language + '_stdlib'] + def get_properties(self): + return self.config['properties'] + # Wehn compiling a cross compiler we use the native compiler for everything. # But not when cross compiling a cross compiler. def need_cross_compiler(self): diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py index 5281be599..df4cb0d05 100644 --- a/mesonbuild/interpreter.py +++ b/mesonbuild/interpreter.py @@ -866,6 +866,7 @@ class MesonMain(InterpreterObject): 'install_dependency_manifest': self.install_dependency_manifest_method, 'project_version': self.project_version_method, 'project_name' : self.project_name_method, + 'get_cross_property': self.get_cross_property_method, }) def add_install_script_method(self, args, kwargs): @@ -965,6 +966,20 @@ class MesonMain(InterpreterObject): def project_name_method(self, args, kwargs): return self.interpreter.active_projectname + def get_cross_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.cross_info.get_properties() + return props[propname] + except Exception: + if len(args) == 2: + return args[1] + raise InterpreterException('Unknown cross property: %s.' % propname) + class Interpreter(): def __init__(self, build, backend, subproject='', subdir='', subproject_dir='subprojects'): diff --git a/test cases/failing/29 no crossprop/meson.build b/test cases/failing/29 no crossprop/meson.build new file mode 100644 index 000000000..bd3a743d6 --- /dev/null +++ b/test cases/failing/29 no crossprop/meson.build @@ -0,0 +1,3 @@ +project('no crossprop', 'c') + +message(meson.get_cross_property('nonexisting'))