aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJussi Pakkanen <jpakkane@gmail.com>2016-09-14 20:26:14 +0300
committerJussi Pakkanen <jpakkane@gmail.com>2017-01-09 21:07:23 +0200
commit24221d71ccd341759b008cf1918826910c40247c (patch)
tree16edc7011ba57678fbe8393d7076966dc70564df
parent9cf0991a1d332cb1f492376bf718aa75020519e4 (diff)
downloadmeson-24221d71ccd341759b008cf1918826910c40247c.zip
meson-24221d71ccd341759b008cf1918826910c40247c.tar.gz
meson-24221d71ccd341759b008cf1918826910c40247c.tar.bz2
Created a Python 3 module for simpler building of Python extension modules.
-rw-r--r--mesonbuild/environment.py8
-rw-r--r--mesonbuild/interpreter.py54
-rw-r--r--mesonbuild/modules/python3.py40
-rw-r--r--test cases/python3/2 extmodule/ext/meson.build15
-rw-r--r--test cases/python3/2 extmodule/meson.build1
-rw-r--r--test cases/python3/3 cython/libdir/meson.build4
-rw-r--r--test cases/python3/3 cython/meson.build2
7 files changed, 88 insertions, 36 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()
diff --git a/test cases/python3/2 extmodule/ext/meson.build b/test cases/python3/2 extmodule/ext/meson.build
index 7d67953..d5d8849 100644
--- a/test cases/python3/2 extmodule/ext/meson.build
+++ b/test cases/python3/2 extmodule/ext/meson.build
@@ -1,17 +1,6 @@
-if host_machine.system() == 'darwin'
- # Default suffix is 'dylib' but Python does not use for extensions.
- suffix = 'so'
-elif host_machine.system() == 'windows'
- # On Windows the extension is pyd for some unexplainable reason.
- suffix = 'pyd'
-else
- suffix = []
-endif
-
-pylib = shared_library('tachyon',
+pylib = py3_mod.extension_module('tachyon',
'tachyon_module.c',
dependencies : py3_dep,
- name_prefix : '',
- name_suffix : suffix)
+)
pypathdir = meson.current_build_dir()
diff --git a/test cases/python3/2 extmodule/meson.build b/test cases/python3/2 extmodule/meson.build
index 92a12b2..582a14e 100644
--- a/test cases/python3/2 extmodule/meson.build
+++ b/test cases/python3/2 extmodule/meson.build
@@ -3,6 +3,7 @@ project('Python extension module', 'c',
# Because Windows Python ships only with optimized libs,
# we must build this project the same way.
+py3_mod = import('python3')
py3_dep = dependency('python3', required : false)
if py3_dep.found()
diff --git a/test cases/python3/3 cython/libdir/meson.build b/test cases/python3/3 cython/libdir/meson.build
index 5c0352e..0d015f0 100644
--- a/test cases/python3/3 cython/libdir/meson.build
+++ b/test cases/python3/3 cython/libdir/meson.build
@@ -14,10 +14,8 @@ pyx_c = custom_target('storer_pyx',
command : [cython, '@INPUT@', '-o', '@OUTPUT@'],
)
-slib = shared_library('storer',
+slib = py3_mod.extension_module('storer',
'storer.c', pyx_c,
- name_prefix : '',
- name_suffix : suffix,
dependencies : py3_dep)
pydir = meson.current_build_dir()
diff --git a/test cases/python3/3 cython/meson.build b/test cases/python3/3 cython/meson.build
index 22bbf7a..c6027ac 100644
--- a/test cases/python3/3 cython/meson.build
+++ b/test cases/python3/3 cython/meson.build
@@ -5,6 +5,8 @@ cython = find_program('cython3', required : false)
py3_dep = dependency('python3', required : false)
if cython.found() and py3_dep.found()
+ py3_dep = dependency('python3')
+ py3_mod = import('python3')
subdir('libdir')
test('cython tester',