Created a Python 3 module for simpler building of Python extension modules.

pull/787/head
Jussi Pakkanen 9 years ago
parent 9cf0991a1d
commit 24221d71cc
  1. 8
      mesonbuild/environment.py
  2. 54
      mesonbuild/interpreter.py
  3. 40
      mesonbuild/modules/python3.py
  4. 15
      test cases/python3/2 extmodule/ext/meson.build
  5. 1
      test cases/python3/2 extmodule/meson.build
  6. 4
      test cases/python3/3 cython/libdir/meson.build
  7. 2
      test cases/python3/3 cython/meson.build

@ -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

@ -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.')

@ -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()

@ -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()

@ -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()

@ -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()

@ -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',

Loading…
Cancel
Save