python: Use one copy of the source tree per Python version.

* lang/python/Makefile.am (copystamp): Create one copy per Python
version.
(all-local): Adapt.
(clean-local): Likewise.
(install-exec-local): Likewise.
* lang/python/tests/run-tests.py: Likewise.
--

Currently, we use one copy of the Python module's source to build for
all Python versions.  This is problematic, because SWIG writes a
wrapper file into the source tree.  Currently, this file works with
both Python 2 and 3, but this is purely by chance.

Improve the situation by creating one copy per Python version so that
SWIG can write version-specific code into each copy.

Signed-off-by: Justus Winter <justus@g10code.com>
This commit is contained in:
Justus Winter 2017-02-13 16:44:53 +01:00
parent 60273e8b2c
commit fe65a26ab5
No known key found for this signature in database
GPG Key ID: DD1A52F9DA8C9020
2 changed files with 24 additions and 17 deletions

View File

@ -47,10 +47,12 @@ COPY_FILES_GPG = \
# For VPATH builds we need to copy some files because Python's # For VPATH builds we need to copy some files because Python's
# distutils are not VPATH-aware. # distutils are not VPATH-aware.
copystamp: $(COPY_FILES) $(COPY_FILES_GPG) data.h config.h copystamp: $(COPY_FILES) $(COPY_FILES_GPG) data.h config.h
if test "$(srcdir)" != "$(builddir)" ; then \ for VERSION in $(PYTHON_VERSIONS); do \
cp -R $(COPY_FILES) . ; \ $(MKDIR_P) python$${VERSION}-gpg/gpg && \
cp -R $(COPY_FILES_GPG) gpg ; \ cp -R $(COPY_FILES) python$${VERSION}-gpg && \
fi cp gpg/version.py python$${VERSION}-gpg/gpg && \
cp -R $(COPY_FILES_GPG) python$${VERSION}-gpg/gpg ; \
done
touch $@ touch $@
data.h: data.h:
@ -60,9 +62,12 @@ config.h:
ln -s "$(top_builddir)/config.h" . ln -s "$(top_builddir)/config.h" .
all-local: copystamp all-local: copystamp
for PYTHON in $(PYTHONS); do \ set $(PYTHONS); for VERSION in $(PYTHON_VERSIONS); do \
PYTHON="$$1" ; shift ; \
cd python$${VERSION}-gpg && \
CFLAGS="$(CFLAGS)" \ CFLAGS="$(CFLAGS)" \
$$PYTHON setup.py build --verbose ; \ $$PYTHON ../setup.py build --verbose ; \
cd .. ; \
done done
dist/gpg-$(VERSION).tar.gz dist/gpg-$(VERSION).tar.gz.asc: copystamp dist/gpg-$(VERSION).tar.gz dist/gpg-$(VERSION).tar.gz.asc: copystamp
@ -89,23 +94,23 @@ CLEANFILES = gpgme.h errors.i gpgme_wrap.c gpg/gpgme.py \
# permissions. # permissions.
clean-local: clean-local:
rm -rf -- build rm -rf -- build
if test "$(srcdir)" != "$(builddir)" ; then \ for VERSION in $(PYTHON_VERSIONS); do \
find . -type d ! -perm -200 -exec chmod u+w {} ';' ; \ find python$${VERSION}-gpg -type d ! -perm -200 -exec chmod u+w {} ';' ; \
for F in $(COPY_FILES); do rm -rf -- `basename $$F` ; done ; \ rm -rf -- python$${VERSION}-gpg ; \
for F in $(COPY_FILES_GPG); do \ done
rm -rf -- gpg/`basename $$F` ; \
done ; \
fi
install-exec-local: install-exec-local:
rm -f install_files.txt rm -f install_files.txt
for PYTHON in $(PYTHONS); do \ set $(PYTHONS); for VERSION in $(PYTHON_VERSIONS); do \
$$PYTHON setup.py install \ PYTHON="$$1" ; shift ; \
cd python$${VERSION}-gpg && \
$$PYTHON ../setup.py install \
--prefix $(DESTDIR)$(prefix) \ --prefix $(DESTDIR)$(prefix) \
--record files.txt \ --record files.txt \
--verbose ; \ --verbose ; \
cat files.txt >> install_files.txt ; \ cat files.txt >> ../install_files.txt ; \
rm files.txt ; \ rm files.txt ; \
cd .. ; \
done done
$(MKDIR_P) $(DESTDIR)$(pythondir)/gpg $(MKDIR_P) $(DESTDIR)$(pythondir)/gpg
mv install_files.txt $(DESTDIR)$(pythondir)/gpg mv install_files.txt $(DESTDIR)$(pythondir)/gpg

View File

@ -69,7 +69,9 @@ for interpreter in args.interpreters:
version = subprocess.check_output( version = subprocess.check_output(
[interpreter, "-c", "import sys; print('{0}.{1}'.format(sys.version_info[0], sys.version_info[1]))"]).strip().decode() [interpreter, "-c", "import sys; print('{0}.{1}'.format(sys.version_info[0], sys.version_info[1]))"]).strip().decode()
builddirs = glob.glob(os.path.join(args.builddir, "..", "build", builddirs = glob.glob(os.path.join(args.builddir, "..",
"python{0}-gpg".format(version),
"build",
"lib*"+version)) "lib*"+version))
assert len(builddirs) == 1, \ assert len(builddirs) == 1, \
"Expected one build directory, got {0}".format(builddirs) "Expected one build directory, got {0}".format(builddirs)