issue#441: change modulename to include hash of source

This should make it work both for users and developers.
This commit is contained in:
J. David Ibáñez 2014-10-30 19:41:25 +01:00
parent 94f650a41d
commit 8e933c8019
2 changed files with 17 additions and 5 deletions

@ -176,7 +176,7 @@ everytime. Verify yourself if curious:
.. code-block:: sh .. code-block:: sh
$ readelf --dynamic lib/python2.7/site-packages/pygit2-0.21.3-py2.7-linux-x86_64.egg/pygit2_cffi.so | grep PATH $ readelf --dynamic lib/python2.7/site-packages/pygit2-0.21.3-py2.7-linux-x86_64.egg/_pygit2.so | grep PATH
0x000000000000001d (RUNPATH) Library runpath: [/tmp/venv/lib] 0x000000000000001d (RUNPATH) Library runpath: [/tmp/venv/lib]

@ -31,11 +31,13 @@ pygit2 at run-time.
""" """
# Import from the Standard Library # Import from the Standard Library
from binascii import crc32
import inspect import inspect
import codecs import codecs
import os import os
from os import getenv from os import getenv
from os.path import abspath, dirname from os.path import abspath, dirname
import sys
# #
@ -72,9 +74,9 @@ def get_libgit2_paths():
# Loads the cffi extension # Loads the cffi extension
# #
def get_ffi(): def get_ffi():
from cffi import FFI import cffi
ffi = FFI() ffi = cffi.FFI()
# Load C definitions # Load C definitions
dir_path = dirname(abspath(inspect.getfile(inspect.currentframe()))) dir_path = dirname(abspath(inspect.getfile(inspect.currentframe())))
@ -82,10 +84,20 @@ def get_ffi():
with codecs.open(decl_path, 'r', 'utf-8') as header: with codecs.open(decl_path, 'r', 'utf-8') as header:
ffi.cdef(header.read()) ffi.cdef(header.read())
# The modulename
# Simplified version of what cffi does: remove kwargs and vengine
preamble = "#include <git2.h>"
key = [sys.version[:3], cffi.__version__, preamble] + ffi._cdefsources
key = '\x00'.join(key)
if sys.version_info >= (3,):
key = key.encode('utf-8')
k1 = hex(crc32(key[0::2]) & 0xffffffff).lstrip('0x').rstrip('L')
k2 = hex(crc32(key[1::2]) & 0xffffffff).lstrip('0').rstrip('L')
modulename = 'pygit2_cffi_%s%s' % (k1, k2)
# Load extension module # Load extension module
libgit2_bin, libgit2_include, libgit2_lib = get_libgit2_paths() libgit2_bin, libgit2_include, libgit2_lib = get_libgit2_paths()
C = ffi.verify("#include <git2.h>", modulename='pygit2_cffi', C = ffi.verify(preamble, modulename=modulename, libraries=["git2"],
libraries=["git2"],
include_dirs=[libgit2_include], library_dirs=[libgit2_lib]) include_dirs=[libgit2_include], library_dirs=[libgit2_lib])
# Ok # Ok