From 5cfaa5b79d446e1c63de3948e7558cd00561ea1f Mon Sep 17 00:00:00 2001 From: Paul Kehrer Date: Thu, 21 Feb 2019 09:52:10 +0800 Subject: encode the package version in the shared object (#4756) * encode the package version in the shared object * review feedback * move into build_ffi so the symbol is in all shared objects * review feedback --- src/_cffi_src/utils.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/_cffi_src') diff --git a/src/_cffi_src/utils.py b/src/_cffi_src/utils.py index d3dd18a4..eecd6ea1 100644 --- a/src/_cffi_src/utils.py +++ b/src/_cffi_src/utils.py @@ -4,6 +4,7 @@ from __future__ import absolute_import, division, print_function +import os import sys from distutils.ccompiler import new_compiler from distutils.dist import Distribution @@ -11,6 +12,13 @@ from distutils.dist import Distribution from cffi import FFI +# Load the cryptography __about__ to get the current package version +base_src = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) +about = {} +with open(os.path.join(base_src, "cryptography", "__about__.py")) as f: + exec(f.read(), about) + + def build_ffi_for_binding(module_name, module_prefix, modules, libraries=[], extra_compile_args=[], extra_link_args=[]): """ @@ -55,6 +63,11 @@ def build_ffi_for_binding(module_name, module_prefix, modules, libraries=[], def build_ffi(module_name, cdef_source, verify_source, libraries=[], extra_compile_args=[], extra_link_args=[]): ffi = FFI() + # Always add the CRYPTOGRAPHY_PACKAGE_VERSION to the shared object + cdef_source += "\nstatic const char *const CRYPTOGRAPHY_PACKAGE_VERSION;" + verify_source += '\n#define CRYPTOGRAPHY_PACKAGE_VERSION "{}"'.format( + about["__version__"] + ) ffi.cdef(cdef_source) ffi.set_source( module_name, -- cgit v1.2.3