diff options
author | Miloslav Trmač <mitr@redhat.com> | 2015-07-11 03:43:04 +0200 |
---|---|---|
committer | Matěj Cepl <mcepl@cepl.eu> | 2015-10-13 15:52:26 +0200 |
commit | 62dbd41b0b6e3d04a02a3d9d8bd533e6016e6565 (patch) | |
tree | 267667fce9a7adbf9acaef2a9dfe1c7d5e093c8e | |
parent | 4c606090a51c54caadda8a6f0090ccb6737408f0 (diff) | |
download | m2crypto-62dbd41b0b6e3d04a02a3d9d8bd533e6016e6565.tar.gz |
Fix build with SWIG 3.0.5
See analysis and previous patches in
https://github.com/martinpaljak/M2Crypto/issues/60 and
https://github.com/swig/swig/issues/344, in particular this adds the
build machinery to patch
https://github.com/martinpaljak/M2Crypto/issues/60#issuecomment-75735489
Fixes #47
-rw-r--r-- | .gitignore | 8 | ||||
-rw-r--r-- | M2Crypto/__init__.py | 4 | ||||
-rw-r--r-- | M2Crypto/m2.py | 2 | ||||
-rw-r--r-- | MANIFEST.in | 3 | ||||
-rw-r--r-- | SWIG/_lib.i | 4 | ||||
-rw-r--r-- | SWIG/_pkcs7.i | 1 | ||||
-rw-r--r-- | setup.py | 96 |
7 files changed, 54 insertions, 64 deletions
@@ -1,11 +1,13 @@ *.pyc *~ - -M2Crypto.egg-info/ -M2Crypto/__m2crypto*.so SWIG/_m2crypto.py SWIG/_m2crypto_wrap.c build/ +/dist +/M2Crypto/__m2crypto.so +/SWIG/_m2crypto.py +/M2Crypto.egg-info +/EGG-INFO tests/randpool.dat tests/sig.p7 tests/sig.p7s diff --git a/M2Crypto/__init__.py b/M2Crypto/__init__.py index e7acfe7..02f4d28 100644 --- a/M2Crypto/__init__.py +++ b/M2Crypto/__init__.py @@ -19,7 +19,7 @@ Copyright 2008-2011 Heikki Toivonen. All rights reserved. version_info = (0, 21, 1) version = '.'.join([str(_v) for _v in version_info]) -import __m2crypto +import _m2crypto import m2 import ASN1 import AuthCookie @@ -57,4 +57,4 @@ import util encrypt=1 decrypt=0 -__m2crypto.lib_init() +_m2crypto.lib_init() diff --git a/M2Crypto/m2.py b/M2Crypto/m2.py index e4bb695..822143f 100644 --- a/M2Crypto/m2.py +++ b/M2Crypto/m2.py @@ -25,7 +25,7 @@ Portions created by Open Source Applications Foundation (OSAF) are Copyright (C) 2004 OSAF. All Rights Reserved. """ -from __m2crypto import * +from _m2crypto import * lib_init() diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..6c4b3c5 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,3 @@ +include SWIG/*.i +include SWIG/*.def +exclude M2Crypto/_m2crypto.py diff --git a/SWIG/_lib.i b/SWIG/_lib.i index 7df8e0a..90e3514 100644 --- a/SWIG/_lib.i +++ b/SWIG/_lib.i @@ -158,6 +158,7 @@ int ssl_verify_callback(int ok, X509_STORE_CTX *ctx) { int cret; int new_style_callback = 0, warning_raised_exception=0; PyGILState_STATE gilstate; + PyObject *self = NULL; /* bug in SWIG_NewPointerObj as of 3.0.5 */ ssl = (SSL *)X509_STORE_CTX_get_app_data(ctx); @@ -243,6 +244,7 @@ int ssl_verify_callback(int ok, X509_STORE_CTX *ctx) { void ssl_info_callback(const SSL *s, int where, int ret) { PyObject *argv, *retval, *_SSL; PyGILState_STATE gilstate; + PyObject *self = NULL; /* bug in SWIG_NewPointerObj as of 3.0.5 */ gilstate = PyGILState_Ensure(); @@ -262,6 +264,7 @@ DH *ssl_set_tmp_dh_callback(SSL *ssl, int is_export, int keylength) { PyObject *argv, *ret, *_ssl; DH *dh; PyGILState_STATE gilstate; + PyObject *self = NULL; /* bug in SWIG_NewPointerObj as of 3.0.5 */ gilstate = PyGILState_Ensure(); @@ -285,6 +288,7 @@ RSA *ssl_set_tmp_rsa_callback(SSL *ssl, int is_export, int keylength) { PyObject *argv, *ret, *_ssl; RSA *rsa; PyGILState_STATE gilstate; + PyObject *self = NULL; /* bug in SWIG_NewPointerObj as of 3.0.5 */ gilstate = PyGILState_Ensure(); diff --git a/SWIG/_pkcs7.i b/SWIG/_pkcs7.i index 22d791a..20dfbaf 100644 --- a/SWIG/_pkcs7.i +++ b/SWIG/_pkcs7.i @@ -157,6 +157,7 @@ PyObject *smime_read_pkcs7(BIO *bio) { BIO *bcont = NULL; PKCS7 *p7; PyObject *tuple, *_p7, *_BIO; + PyObject *self = NULL; /* bug in SWIG_NewPointerObj as of 3.0.5 */ if (BIO_method_type(bio) == BIO_TYPE_MEM) { /* OpenSSL FAQ explains that this is needed for mem BIO to return EOF, @@ -23,6 +23,8 @@ except ImportError: from distutils.command import build_ext from distutils.core import Extension +from distutils.spawn import find_executable +from distutils.file_util import copy_file class _M2CryptoBuildExt(build_ext.build_ext): @@ -58,9 +60,24 @@ class _M2CryptoBuildExt(build_ext.build_ext): self.swig_opts = ['-I%s' % i for i in self.include_dirs + \ [opensslIncludeDir]] self.swig_opts.append('-includeall') - #self.swig_opts.append('-D__i386__') # Uncomment for early OpenSSL 0.9.7 versions, or on Fedora Core if build fails - #self.swig_opts.append('-DOPENSSL_NO_EC') # Try uncommenting if you can't build with EC disabled - + self.swig_opts.append('-modern') + self.swig_opts.append('-builtin') + + # These two lines are a workaround for + # http://bugs.python.org/issue2624 , hard-coding that we are only + # building a single extension with a known path; a proper patch to + # distutils would be in the run phase, when extension name and path are + # known. + self.swig_opts.append('-outdir') + self.swig_opts.append(os.path.join(self.build_lib, 'M2Crypto')) + + # Fedora does hat tricks. + if platform.linux_distribution()[0] in ['Fedora', 'CentOS']: + if platform.architecture()[0] == '64bit': + self.swig_opts.append('-D__x86_64__') + elif platform.architecture()[0] == '32bit': + self.swig_opts.append('-D__i386__') + self.include_dirs += [os.path.join(self.openssl, opensslIncludeDir), os.path.join(os.getcwd(), 'SWIG')] @@ -74,61 +91,24 @@ class _M2CryptoBuildExt(build_ext.build_ext): self.library_dirs += [os.path.join(self.openssl, opensslLibraryDir)] - -if sys.version_info < (2,4): - - # This copy of swig_sources is from Python 2.2. - - def swig_sources (self, sources): - - """Walk the list of source files in 'sources', looking for SWIG - interface (.i) files. Run SWIG on all that are found, and - return a modified 'sources' list with SWIG source files replaced - by the generated C (or C++) files. - """ - - new_sources = [] - swig_sources = [] - swig_targets = {} - - # XXX this drops generated C/C++ files into the source tree, which - # is fine for developers who want to distribute the generated - # source -- but there should be an option to put SWIG output in - # the temp dir. - - if self.swig_cpp: - target_ext = '.cpp' - else: - target_ext = '.c' - - for source in sources: - (base, ext) = os.path.splitext(source) - if ext == ".i": # SWIG interface file - new_sources.append(base + target_ext) - swig_sources.append(source) - swig_targets[source] = new_sources[-1] - else: - new_sources.append(source) - - if not swig_sources: - return new_sources - - swig = self.find_swig() - swig_cmd = [swig, "-python", "-ISWIG"] - if self.swig_cpp: - swig_cmd.append("-c++") - - swig_cmd += self.swig_opts - - for source in swig_sources: - target = swig_targets[source] - self.announce("swigging %s to %s" % (source, target)) - self.spawn(swig_cmd + ["-o", target, source]) - - return new_sources - - build_ext.build_ext.swig_sources = swig_sources - + def run(self): + '''Overloaded build_ext implementation to allow inplace=1 to work, + which is needed for (python setup.py test).''' + # This is another workaround for http://bugs.python.org/issue2624 + the + # corresponding lack of support in setuptools' test command. Note that + # just using self.inplace in finalize_options() above does not work + # because swig is not rerun if the __m2crypto.so extension exists. + # Again, hard-coding our extension name and location. + build_ext.build_ext.run(self) + if self.inplace: + copy_file(os.path.join(self.build_lib, 'M2Crypto', '_m2crypto.py'), + os.path.join('M2Crypto', '_m2crypto.py'), + verbose=self.verbose, dry_run=self.dry_run) + +if sys.platform == 'darwin': + my_extra_compile_args = ["-Wno-deprecated-declarations"] +else: + my_extra_compile_args = [] m2crypto = Extension(name = 'M2Crypto.__m2crypto', sources = ['SWIG/_m2crypto.i'], |