diff options
author | Alon Bar-Lev <[email protected]> | 2017-04-01 23:29:52 +0000 |
---|---|---|
committer | Justus Winter <[email protected]> | 2017-04-05 12:48:47 +0000 |
commit | 801d7d8c5dd530d26ad6c4bcc94d986e6e022da4 (patch) | |
tree | a71efd15a76edefcff8ba17c8ea7174e3b3d060a /lang/python/setup.py.in | |
parent | Fix typo. (diff) | |
download | gpgme-801d7d8c5dd530d26ad6c4bcc94d986e6e022da4.tar.gz gpgme-801d7d8c5dd530d26ad6c4bcc94d986e6e022da4.zip |
python: Generate files into build directory
* lang/python/setup.py.in: Generate files within BuildExtFirstHack
adjust build flags at this point instead of global.
* lang/python/Makefile.am: Remove logic of separate source directory per
python version in favor of build directory.
* lang/python/tests/run-tests.py: Adjust build directory location.
--
Generate files into build directory, leaving the source directory clean.
Use the same source directory for multiple python version build. Result
of 'prepare' target is a standard distutil layout that can be used
easily by downstream to build all python targets in-place.
Signed-off-by: Alon Bar-Lev <[email protected]>
Diffstat (limited to 'lang/python/setup.py.in')
-rwxr-xr-x | lang/python/setup.py.in | 48 |
1 files changed, 37 insertions, 11 deletions
diff --git a/lang/python/setup.py.in b/lang/python/setup.py.in index 8ddbf276..6692de6f 100755 --- a/lang/python/setup.py.in +++ b/lang/python/setup.py.in @@ -21,6 +21,7 @@ from distutils.core import setup, Extension import os, os.path, sys import glob +import shutil import subprocess # Out-of-tree build of the gpg bindings. @@ -89,14 +90,6 @@ if not os.path.exists(gpg_error_h): glob.glob(os.path.join(gpg_error_prefix, "include", "*", "gpg-error.h"))[0] -print("Building python gpg module using {} and {}.".format(gpgme_h, gpg_error_h)) - -# Cleanup gpgme.h from deprecated functions and typedefs. -subprocess.check_call([sys.executable, "gpgme-h-clean.py", gpgme_h], - stdout=open("gpgme.h", "w")) -subprocess.check_call([sys.executable, "gpgme-h-clean.py", gpg_error_h], - stdout=open("errors.i", "w")) - define_macros = [] libs = getconfig('libs') @@ -149,14 +142,47 @@ if uname_s.startswith("MINGW32"): # http://stackoverflow.com/questions/12491328/python-distutils-not-include-the-swig-generated-module from distutils.command.build import build class BuildExtFirstHack(build): + + def _generate(self): + print("Building python gpg module using {} and {}.".format(gpgme_h, gpg_error_h)) + + # Cleanup gpgme.h from deprecated functions and typedefs. + # Keep timestamp to avoid rebuild + if not os.path.exists(self.build_base): + os.makedirs(self.build_base) + + for src, dst in ( + (gpgme_h, os.path.join(self.build_base, "gpgme.h")), + (gpg_error_h, os.path.join(self.build_base, "errors.i")) + ): + subprocess.check_call([sys.executable, "gpgme-h-clean.py", src], + stdout=open(dst, "w")) + shutil.copystat(src, dst) + + # Copy due to http://bugs.python.org/issue2624 + # Avoid creating in srcdir + shutil.copy2("gpgme.i", self.build_base) + def run(self): + self._generate() + + # Append generated files via build_base + if not os.path.exists(os.path.join(self.build_lib, "gpg")): + os.makedirs(os.path.join(self.build_lib, "gpg")) + + swig_sources.append(os.path.join(self.build_base, 'gpgme.i')) + swig_opts.extend(['-I' + self.build_base, '-outdir', os.path.join(self.build_lib, 'gpg')]) + include_dirs.append(self.build_base) + self.run_command('build_ext') build.run(self) py3 = [] if sys.version_info.major < 3 else ['-py3'] -swige = Extension("gpg._gpgme", ["gpgme.i", "helpers.c"], - swig_opts = ['-threads', - '-outdir', 'gpg'] + py3 + extra_swig_opts, +swig_sources = ['helpers.c'] +swig_opts = ['-threads'] + py3 + extra_swig_opts +swige = Extension("gpg._gpgme", + sources = swig_sources, + swig_opts = swig_opts, include_dirs = include_dirs, define_macros = define_macros, library_dirs = library_dirs, |