summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatěj Cepl <mcepl@cepl.eu>2016-07-11 18:38:38 +0200
committerMatěj Cepl <mcepl@cepl.eu>2016-07-11 23:15:42 +0200
commit7b33d81641bbd5e7751e6ab4bef938f88b8bf1f7 (patch)
tree8dddb5f4c3c0a13527202513151f3c02e2dd141d
parent3c6691c31e51ac765298d39f7ee64f085024ce2d (diff)
downloadm2crypto-7b33d81641bbd5e7751e6ab4bef938f88b8bf1f7.tar.gz
Don't swig on the ancient platforms.
Fixes #140
-rw-r--r--MANIFEST.in3
-rw-r--r--setup.py47
2 files changed, 48 insertions, 2 deletions
diff --git a/MANIFEST.in b/MANIFEST.in
index 9a7d09d..1e42a02 100644
--- a/MANIFEST.in
+++ b/MANIFEST.in
@@ -9,4 +9,5 @@ include README.rst
include CHANGES
include epydoc.conf
include LICENCE
-exclude M2Crypto/_m2crypto.py
+include SWIG/_m2crypto_wrap.c
+include M2Crypto/_m2crypto.py
diff --git a/setup.py b/setup.py
index 6f1d6c6..2ed739d 100644
--- a/setup.py
+++ b/setup.py
@@ -14,6 +14,7 @@ import glob
import os
import platform
import string
+import subprocess
import sys
import setuptools
@@ -22,8 +23,11 @@ from distutils.command import build
from distutils.command.clean import clean
from distutils.dir_util import mkpath
from distutils.file_util import copy_file
+from distutils.version import StrictVersion
+
from setuptools.command import build_ext
+REQUIRED_SWIG_VERSION = '2.0.4'
if sys.version_info[:2] <= (2, 6):
# This covers hopefully only RHEL-6 (users of any other 2.6 Pythons
@@ -147,13 +151,54 @@ class _M2CryptoBuildExt(build_ext.build_ext):
os.path.join('M2Crypto', '_m2crypto.py'),
verbose=self.verbose, dry_run=self.dry_run)
+
+def swig_version(req_ver):
+ # type: (str) -> bool
+ """
+ Compare version of the swig with the required version
+
+ @param req_ver: required version as a str (e.g., '2.0.4')
+ @return: Boolean indicating whether the satisfying version of swig
+ has been installed.
+ """
+ ver_str = None
+ IND_VER_LINE = 'SWIG Version '
+
+ try:
+ pid = subprocess.Popen(['swig', '-version'], stdout=subprocess.PIPE)
+ except OSError:
+ return False
+
+ out, _ = pid.communicate()
+ if hasattr(out, 'decode'):
+ out = out.decode('utf8')
+
+ for line in out.split('\n'):
+ line = line.strip()
+ if line.startswith(IND_VER_LINE):
+ ver_str = line.strip()[len(IND_VER_LINE):]
+ break
+
+ if not ver_str:
+ raise OSError('Unknown format of swig -version output:\n%s' % out)
+
+ return StrictVersion(ver_str) >= StrictVersion(req_ver)
+
+
if sys.platform == 'darwin':
my_extra_compile_args = ["-Wno-deprecated-declarations"]
else:
my_extra_compile_args = []
+# Don't try to run swig on the ancient platforms
+if swig_version(REQUIRED_SWIG_VERSION):
+ lib_sources = ['SWIG/_m2crypto.i']
+else:
+ lib_sources = ['SWIG/_m2crypto_wrap.c']
+
+
m2crypto = setuptools.Extension(name='M2Crypto.__m2crypto',
- sources=['SWIG/_m2crypto.i'],
+ sources=lib_sources,
extra_compile_args=['-DTHREADING'],
# Uncomment to build Universal Mac binaries
# extra_link_args =