Skip to content

Commit

Permalink
Added basic support for Win64 compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
gdanezis committed Jan 26, 2015
1 parent d4fbed4 commit 557b4ef
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 9 deletions.
36 changes: 28 additions & 8 deletions pavement.py
@@ -1,6 +1,16 @@
import os.path
import os
import re
import fnmatch


def match_files(directory="petlib", pattern="*.py"):
files = []
for file in os.listdir(directory):
if fnmatch.fnmatch(file, pattern):
files += [os.path.join(directory, file)]
return files


from paver.tasks import task, cmdopts
from paver.easy import sh, needs, pushd
Expand All @@ -16,12 +26,14 @@ def tell(x):
@task
def unit_tests():
tell("Unit tests")
sh('py.test-2.7 -v --doctest-modules --cov-report html --cov petlib petlib/*.py')
files = " ".join(match_files())
sh('py.test-2.7 -v --doctest-modules --cov-report html --cov petlib ' + files)

@task
def test3():
tell("Unit tests for python 3")
sh('py.test-3.4 -v --doctest-modules --cov-report html --cov petlib petlib/*.py')
files = " ".join(match_files())
sh('py.test-3.4 -v --doctest-modules --cov-report html --cov petlib ' + files)

@task
@cmdopts([
Expand Down Expand Up @@ -56,7 +68,8 @@ def lintlib(quiet=False):
def lintexamples(quiet=True):
tell("Run Lint on example code")
sh("pip install %s --upgrade" % get_latest_dist(), capture=quiet)
sh('export PYTHONPATH=$PYHTONPATH:./utils; pylint --rcfile=pylintrc --load-plugins ignoretest examples/*.py', capture=quiet)
files = " ".join(match_files("examples", "*.py"))
sh('export PYTHONPATH=$PYHTONPATH:./utils; pylint --rcfile=pylintrc --load-plugins ignoretest ' + files, capture=quiet)

@needs("lintlib", "lintexamples")
@task
Expand All @@ -81,8 +94,8 @@ def get_latest_dist():
return os.path.join("dist","petlib-%s.tar.gz" % v)


@needs('build')
@task
@needs('build')
def make_env(quiet=True):
tell("Make a virtualenv")
if os.path.exists("test_env"):
Expand All @@ -92,14 +105,21 @@ def make_env(quiet=True):
sh("virtualenv pltest", capture=quiet)


@needs("make_env")
@task
@virtualenv(dir=r"test_env/pltest")
@needs("make_env")
@virtualenv(dir=os.path.join(r"test_env",r"pltest"))
def big_tests(quiet=True):
tell("Run acceptance tests (big examples)")
sh("pip install %s --upgrade" % get_latest_dist(), capture=quiet)
sh("py.test-2.7 -v examples/*.py")

files = " ".join(match_files("examples", "*.py"))
sh("py.test-2.7 -v " + files)

@task
def local_big_tests(quiet=True):
tell("Run acceptance tests (big examples) using local install.")
files = " ".join(match_files("examples", "*.py"))
sh("py.test-2.7 -v " + files)


@needs('unit_tests', 'big_tests')
@task
Expand Down
42 changes: 41 additions & 1 deletion petlib/bindings.py
@@ -1,6 +1,40 @@
#!/usr/bin/env python

import os
import cffi


if os.name == "nt":
# WIN: libraries=["libeay32"], include_dirs=[r"...\pyopenssl"]
# Ensure you compile with a 64bit lib (run vcvarsx86_amd64.bat)
libraries=["libeay32"]
include_dirs=[r"."]
extra_compile_args = []

if "VCINSTALLDIR" not in os.environ:
raise Exception(r"Cannot find the Visual Studio %VCINSTALLDIR% variable. Ensure you ran the appropriate vcvars.bat script.")

if "OPENSSL_CONF" not in os.environ:
raise Exception(r"Cannot find the Visual Studio %OPENSSL_CONF% variable. Ensure you install OpenSSL for Windows.")

openssl_conf = os.environ["OPENSSL_CONF"]
openssl_bin, conf_name = os.path.split(openssl_conf)
openssl_base, bin_name = os.path.split(openssl_bin)
assert bin_name == "bin"
include_dirs += [os.path.join(openssl_base, "include")]
library_dirs = [openssl_base, os.path.join(openssl_base, "lib")]

print("Windows Library directories")
print(library_dirs)

else:
## Asume we are running on a posix system
# LINUX: libraries=["crypto"], extra_compile_args=['-Wno-deprecated-declarations']
libraries=["crypto"]
extra_compile_args=['-Wno-deprecated-declarations']
include_dirs=[]
library_dirs=[]

_FFI = cffi.FFI()

_FFI.cdef("""
Expand Down Expand Up @@ -314,6 +348,7 @@
#define BN_num_bytes(a) ((BN_num_bits(a)+7)/8)
int bn_num_bytes(BIGNUM * a){
return BN_num_bytes(a);
}
Expand All @@ -326,6 +361,7 @@
return sizeof(HMAC_CTX);
}
extern void ERR_load_crypto_strings(void);
extern void OPENSSL_config(void*);
extern void ERR_free_strings(void);
Expand Down Expand Up @@ -356,7 +392,11 @@
}
""", libraries=["crypto"], extra_compile_args=['-Wno-deprecated-declarations'])
""", libraries=libraries,
extra_compile_args=extra_compile_args,
include_dirs=include_dirs,
library_dirs=library_dirs,
ext_package='petlib')

_inited = False

Expand Down
4 changes: 4 additions & 0 deletions setup.py
Expand Up @@ -13,13 +13,16 @@
print("Alter: Not compiling the library -- useful for readthedocs.")
deps = []

import petlib

setup(name='petlib',
version=petlib.VERSION,
description='A library implementing a number of Privacy Enhancing Technologies (PETs)',
author='George Danezis',
author_email='g.danezis@ucl.ac.uk',
url=r'https://pypi.python.org/pypi/petlib/',
packages=['petlib'],
ext_package='petlib',
license="2-clause BSD",
long_description="""A library wrapping Open SSL low-level cryptographic libraries to build Privacy Enhancing Technoloies (PETs)""",
install_requires=[
Expand All @@ -29,5 +32,6 @@
"paver >= 1.2.3",
"pytest-cov >= 1.8.1",
],
zip_safe=False,
ext_modules=deps,
)
Binary file removed utils/ignoretest.pyc
Binary file not shown.

0 comments on commit 557b4ef

Please sign in to comment.