diff options
Diffstat (limited to 'mesonbuild')
-rw-r--r-- | mesonbuild/environment.py | 8 | ||||
-rw-r--r-- | mesonbuild/interpreter.py | 54 | ||||
-rw-r--r-- | mesonbuild/modules/python3.py | 40 |
3 files changed, 82 insertions, 20 deletions
diff --git a/mesonbuild/environment.py b/mesonbuild/environment.py index e4a55b3..64d9f8b 100644 --- a/mesonbuild/environment.py +++ b/mesonbuild/environment.py @@ -899,3 +899,11 @@ class CrossBuildInfo(): self.config['host_machine']['system'] == detect_system(): return False return True + + +class MachineInfo: + def __init__(self, system, cpu_family, cpu, endian): + self.system = system + self.cpu_family = cpu_family + self.cpu = cpu + self.endian = endian diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py index 382c04c..bfc1453 100644 --- a/mesonbuild/interpreter.py +++ b/mesonbuild/interpreter.py @@ -355,23 +355,27 @@ class BuildMachine(InterpreterObject): def __init__(self, compilers): self.compilers = compilers InterpreterObject.__init__(self) - self.methods.update({'system': self.system_method, - 'cpu_family': self.cpu_family_method, - 'cpu': self.cpu_method, - 'endian': self.endian_method, - }) + self.held_object = environment.MachineInfo(environment.detect_system(), + environment.detect_cpu_family(self.compilers), + environment.detect_cpu(self.compilers), + sys.byteorder) + self.methods.update({'system' : self.system_method, + 'cpu_family' : self.cpu_family_method, + 'cpu' : self.cpu_method, + 'endian' : self.endian_method, + }) def cpu_family_method(self, args, kwargs): - return environment.detect_cpu_family(self.compilers) + return self.held_object.cpu_family def cpu_method(self, args, kwargs): - return environment.detect_cpu(self.compilers) + return self.held_object.cpu def system_method(self, args, kwargs): - return environment.detect_system() + return self.held_object.system def endian_method(self, args, kwargs): - return sys.byteorder + return self.held_object.endian # This class will provide both host_machine and # target_machine @@ -384,23 +388,27 @@ class CrossMachineInfo(InterpreterObject): 'Machine info is currently {}\n'.format(cross_info) + 'but is missing {}.'.format(minimum_cross_info - set(cross_info))) self.info = cross_info - self.methods.update({'system': self.system_method, - 'cpu': self.cpu_method, - 'cpu_family': self.cpu_family_method, - 'endian': self.endian_method, - }) + self.held_object = environment.MachineInfo(cross_info['system'], + cross_info['cpu_family'], + cross_info['cpu'], + cross_info['endian']) + self.methods.update({'system' : self.system_method, + 'cpu' : self.cpu_method, + 'cpu_family' : self.cpu_family_method, + 'endian' : self.endian_method, + }) - def system_method(self, args, kwargs): - return self.info['system'] + def cpu_family_method(self, args, kwargs): + return self.held_object.cpu_family def cpu_method(self, args, kwargs): - return self.info['cpu'] + return self.held_object.cpu - def cpu_family_method(self, args, kwargs): - return self.info['cpu_family'] + def system_method(self, args, kwargs): + return self.held_object.system def endian_method(self, args, kwargs): - return self.info['endian'] + return self.held_object.endian class IncludeDirsHolder(InterpreterObject): def __init__(self, idobj): @@ -1000,6 +1008,10 @@ class ModuleHolder(InterpreterObject): state.man = self.interpreter.build.get_man() state.global_args = self.interpreter.build.global_args state.project_args = self.interpreter.build.projects_args.get(self.interpreter.subproject, {}) + state.build_machine = self.interpreter.builtin['build_machine'].held_object + state.host_machine = self.interpreter.builtin['host_machine'].held_object + state.target_machine = self.interpreter.builtin['target_machine'].held_object + state.interpreter = self.interpreter value = fn(state, args, kwargs) if num_targets != len(self.interpreter.build.targets): raise InterpreterException('Extension module altered internal state illegally.') @@ -1283,6 +1295,8 @@ class Interpreter(InterpreterBase): # FIXME: This is special cased and not ideal: # The first source is our new VapiTarget, the rest are deps self.process_new_values(v.sources[0]) + elif hasattr(v, 'held_object'): + pass else: raise InterpreterException('Module returned a value of unknown type.') diff --git a/mesonbuild/modules/python3.py b/mesonbuild/modules/python3.py new file mode 100644 index 0000000..370e925 --- /dev/null +++ b/mesonbuild/modules/python3.py @@ -0,0 +1,40 @@ +# Copyright 2016-2017 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. +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from .. import coredata, build +from .. import mesonlib +import os + +class Python3Module: + + def extension_module(self, state, args, kwargs): + if 'name_prefix' in kwargs: + raise mesonlib.MesonException('Name_prefix is set automatically, specifying it is forbidden.') + if 'name_suffix' in kwargs: + raise mesonlib.MesonException('Name_suffix is set automatically, specifying it is forbidden.') + host_system = state.host_machine.system + if host_system == 'darwin': + # Default suffix is 'dylib' but Python does not use it for extensions. + suffix = 'so' + elif host_system == 'windows': + # On Windows the extension is pyd for some unexplainable reason. + suffix = 'pyd' + else: + suffix = [] + kwargs['name_prefix'] = '' + kwargs['name_suffix'] = suffix + return state.interpreter.func_shared_module(None, args, kwargs) + +def initialize(): + return Python3Module() |