aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/modules
diff options
context:
space:
mode:
authorJussi Pakkanen <jpakkane@gmail.com>2017-01-09 16:36:00 -0500
committerGitHub <noreply@github.com>2017-01-09 16:36:00 -0500
commit34caf6471c0fad8823ce145d3d38afb81ee181ba (patch)
tree17d4a5db37d2df3c3748ec767701f74882fa912e /mesonbuild/modules
parent9cf0991a1d332cb1f492376bf718aa75020519e4 (diff)
parent6ac9a8e738dae97c64308da83949931fb726bbe7 (diff)
downloadmeson-34caf6471c0fad8823ce145d3d38afb81ee181ba.zip
meson-34caf6471c0fad8823ce145d3d38afb81ee181ba.tar.gz
meson-34caf6471c0fad8823ce145d3d38afb81ee181ba.tar.bz2
Merge pull request #787 from mesonbuild/py3module
Created a Python 3 module for simpler building of Python extension mo…
Diffstat (limited to 'mesonbuild/modules')
-rw-r--r--mesonbuild/modules/__init__.py7
-rw-r--r--mesonbuild/modules/gnome.py3
-rw-r--r--mesonbuild/modules/i18n.py9
-rw-r--r--mesonbuild/modules/modtest.py3
-rw-r--r--mesonbuild/modules/pkgconfig.py6
-rw-r--r--mesonbuild/modules/python3.py49
-rw-r--r--mesonbuild/modules/qt4.py3
-rw-r--r--mesonbuild/modules/qt5.py3
-rw-r--r--mesonbuild/modules/rpm.py3
-rw-r--r--mesonbuild/modules/windows.py7
10 files changed, 79 insertions, 14 deletions
diff --git a/mesonbuild/modules/__init__.py b/mesonbuild/modules/__init__.py
index 16cada0..c7f24d4 100644
--- a/mesonbuild/modules/__init__.py
+++ b/mesonbuild/modules/__init__.py
@@ -6,6 +6,13 @@ from ..mesonlib import MesonException
_found_programs = {}
+class ExtensionModule:
+ def __init__(self):
+ self.snippets = set() # List of methods that operate only on the interpreter.
+
+ def is_snippet(self, funcname):
+ return funcname in self.snippets
+
def find_program(program_name, target_name):
if program_name in _found_programs:
return _found_programs[program_name]
diff --git a/mesonbuild/modules/gnome.py b/mesonbuild/modules/gnome.py
index ad34640..47fa68e 100644
--- a/mesonbuild/modules/gnome.py
+++ b/mesonbuild/modules/gnome.py
@@ -29,6 +29,7 @@ from .. import compilers
from .. import interpreter
from . import GResourceTarget, GResourceHeaderTarget, GirTarget, TypelibTarget, VapiTarget
from . import find_program, get_include_args
+from . import ExtensionModule
# gresource compilation is broken due to the way
@@ -57,7 +58,7 @@ def gir_has_extra_lib_arg():
pass
return _gir_has_extra_lib_arg
-class GnomeModule:
+class GnomeModule(ExtensionModule):
gir_dep = None
@staticmethod
diff --git a/mesonbuild/modules/i18n.py b/mesonbuild/modules/i18n.py
index fa52463..5738cb3 100644
--- a/mesonbuild/modules/i18n.py
+++ b/mesonbuild/modules/i18n.py
@@ -12,13 +12,14 @@
# See the License for the specific language governing permissions and
# limitations under the License.
+import sys
+import shutil
+
from os import path
from .. import coredata, mesonlib, build
from ..mesonlib import MesonException
from . import ModuleReturnValue
-
-import sys
-import shutil
+from . import ExtensionModule
PRESET_ARGS = {
'glib': [
@@ -46,7 +47,7 @@ PRESET_ARGS = {
]
}
-class I18nModule:
+class I18nModule(ExtensionModule):
def merge_file(self, state, args, kwargs):
podir = kwargs.pop('po_dir', None)
diff --git a/mesonbuild/modules/modtest.py b/mesonbuild/modules/modtest.py
index dc347e2..3e11b70 100644
--- a/mesonbuild/modules/modtest.py
+++ b/mesonbuild/modules/modtest.py
@@ -13,8 +13,9 @@
# limitations under the License.
from . import ModuleReturnValue
+from . import ExtensionModule
-class TestModule:
+class TestModule(ExtensionModule):
def print_hello(self, state, args, kwargs):
print('Hello from a Meson module')
diff --git a/mesonbuild/modules/pkgconfig.py b/mesonbuild/modules/pkgconfig.py
index 38358f3..c558d48 100644
--- a/mesonbuild/modules/pkgconfig.py
+++ b/mesonbuild/modules/pkgconfig.py
@@ -12,14 +12,16 @@
# See the License for the specific language governing permissions and
# limitations under the License.
+import os
+
from .. import build
from .. import mesonlib
from .. import mlog
from . import ModuleReturnValue
+from . import ExtensionModule
-import os
-class PkgConfigModule:
+class PkgConfigModule(ExtensionModule):
def _get_lname(self, l, msg, pcfile):
# Nothing special
diff --git a/mesonbuild/modules/python3.py b/mesonbuild/modules/python3.py
new file mode 100644
index 0000000..53e28c4
--- /dev/null
+++ b/mesonbuild/modules/python3.py
@@ -0,0 +1,49 @@
+# 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.
+
+import sys
+from .. import mesonlib, dependencies
+
+from . import ExtensionModule
+from mesonbuild.modules import ModuleReturnValue
+
+class Python3Module(ExtensionModule):
+ def __init__(self):
+ super().__init__()
+ self.snippets.add('extension_module')
+
+ def extension_module(self, interpreter, 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 interpreter.func_shared_module(None, args, kwargs)
+
+ def find_python(self, state, args, kwargs):
+ py3 = dependencies.ExternalProgram('python3', sys.executable, silent=True)
+ return ModuleReturnValue(py3, [py3])
+
+def initialize():
+ return Python3Module()
diff --git a/mesonbuild/modules/qt4.py b/mesonbuild/modules/qt4.py
index 6759270..9a9ec04 100644
--- a/mesonbuild/modules/qt4.py
+++ b/mesonbuild/modules/qt4.py
@@ -17,10 +17,11 @@ from .. import mlog
from .. import build
from ..mesonlib import MesonException, Popen_safe
from ..dependencies import Qt4Dependency
+from . import ExtensionModule
import xml.etree.ElementTree as ET
from . import ModuleReturnValue
-class Qt4Module():
+class Qt4Module(ExtensionModule):
tools_detected = False
def _detect_tools(self, env):
diff --git a/mesonbuild/modules/qt5.py b/mesonbuild/modules/qt5.py
index 53f1cb5..cb5c261 100644
--- a/mesonbuild/modules/qt5.py
+++ b/mesonbuild/modules/qt5.py
@@ -17,10 +17,11 @@ from .. import mlog
from .. import build
from ..mesonlib import MesonException, Popen_safe
from ..dependencies import Qt5Dependency
+from . import ExtensionModule
import xml.etree.ElementTree as ET
from . import ModuleReturnValue
-class Qt5Module():
+class Qt5Module(ExtensionModule):
tools_detected = False
def _detect_tools(self, env):
diff --git a/mesonbuild/modules/rpm.py b/mesonbuild/modules/rpm.py
index a696db9..bd8a3c4 100644
--- a/mesonbuild/modules/rpm.py
+++ b/mesonbuild/modules/rpm.py
@@ -21,10 +21,11 @@ import datetime
from .. import mlog
from . import GirTarget, TypelibTarget
from . import ModuleReturnValue
+from . import ExtensionModule
import os
-class RPMModule:
+class RPMModule(ExtensionModule):
def generate_spec_template(self, state, args, kwargs):
compiler_deps = set()
diff --git a/mesonbuild/modules/windows.py b/mesonbuild/modules/windows.py
index 8574dbe..8203789 100644
--- a/mesonbuild/modules/windows.py
+++ b/mesonbuild/modules/windows.py
@@ -12,14 +12,15 @@
# See the License for the specific language governing permissions and
# limitations under the License.
+import os
+
from .. import mesonlib, dependencies, build
from ..mesonlib import MesonException
from . import get_include_args
from . import ModuleReturnValue
+from . import ExtensionModule
-import os
-
-class WindowsModule:
+class WindowsModule(ExtensionModule):
def detect_compiler(self, compilers):
for l in ('c', 'cpp'):