|
31 | 31 | """
|
32 | 32 |
|
33 | 33 | # Import from the Standard Library
|
| 34 | +from binascii import crc32 |
34 | 35 | import inspect
|
35 | 36 | import codecs
|
36 | 37 | import os
|
37 | 38 | from os import getenv
|
38 | 39 | from os.path import abspath, dirname
|
| 40 | +import sys |
39 | 41 |
|
40 | 42 |
|
41 | 43 | #
|
@@ -72,20 +74,30 @@ def get_libgit2_paths():
|
72 | 74 | # Loads the cffi extension
|
73 | 75 | #
|
74 | 76 | def get_ffi():
|
75 |
| - from cffi import FFI |
| 77 | + import cffi |
76 | 78 |
|
77 |
| - ffi = FFI() |
| 79 | + ffi = cffi.FFI() |
78 | 80 |
|
79 | 81 | # Load C definitions
|
80 | 82 | dir_path = dirname(abspath(inspect.getfile(inspect.currentframe())))
|
81 | 83 | decl_path = os.path.join(dir_path, 'decl.h')
|
82 | 84 | with codecs.open(decl_path, 'r', 'utf-8') as header:
|
83 | 85 | ffi.cdef(header.read())
|
84 | 86 |
|
| 87 | + # The modulename |
| 88 | + # Simplified version of what cffi does: remove kwargs and vengine |
| 89 | + preamble = "#include <git2.h>" |
| 90 | + key = [sys.version[:3], cffi.__version__, preamble] + ffi._cdefsources |
| 91 | + key = '\x00'.join(key) |
| 92 | + if sys.version_info >= (3,): |
| 93 | + key = key.encode('utf-8') |
| 94 | + k1 = hex(crc32(key[0::2]) & 0xffffffff).lstrip('0x').rstrip('L') |
| 95 | + k2 = hex(crc32(key[1::2]) & 0xffffffff).lstrip('0').rstrip('L') |
| 96 | + modulename = 'pygit2_cffi_%s%s' % (k1, k2) |
| 97 | + |
85 | 98 | # Load extension module
|
86 | 99 | libgit2_bin, libgit2_include, libgit2_lib = get_libgit2_paths()
|
87 |
| - C = ffi.verify("#include <git2.h>", modulename='pygit2_cffi', |
88 |
| - libraries=["git2"], |
| 100 | + C = ffi.verify(preamble, modulename=modulename, libraries=["git2"], |
89 | 101 | include_dirs=[libgit2_include], library_dirs=[libgit2_lib])
|
90 | 102 |
|
91 | 103 | # Ok
|
|
0 commit comments