Skip to content

Commit 7afda6b

Browse files
build files
1 parent 2b0cf67 commit 7afda6b

14 files changed

Lines changed: 206 additions & 58 deletions

Makefile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ clean-test: ## remove test and coverage artifacts
4848
rm -fr htmlcov/
4949

5050
lint: ## check style with flake8
51-
flake8 wolfcrypt tests
51+
flake8 wolfssl tests
5252

5353
test: ## run tests quickly with the default Python
5454
py.test tests
@@ -58,18 +58,18 @@ check: test ## run tests quickly with the default Python
5858
test-all: ## run tests on every Python version with tox
5959
tox
6060

61-
check-all: ## run tests on every Python version with tox
61+
check-all: test-all ## run tests on every Python version with tox
6262

6363
coverage: ## check code coverage quickly with the default Python
64-
coverage run --source wolfcrypt -m pytest
64+
coverage run --source wolfssl -m pytest
6565
coverage report -m
6666
coverage html
6767
$(BROWSER) htmlcov/index.html
6868

6969
docs: ## generate Sphinx HTML documentation, including API docs
70-
rm -f docs/wolfcrypt.rst
70+
rm -f docs/wolfssl.rst
7171
rm -f docs/modules.rst
72-
sphinx-apidoc -o docs/ wolfcrypt
72+
sphinx-apidoc -o docs/ wolfssl
7373
$(MAKE) -C docs clean
7474
$(MAKE) -C docs html
7575
$(BROWSER) docs/_build/html/index.html

build_linux_wheels.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ set -x
44

55
docker run \
66
--rm \
7-
-v `pwd`:/wolfcrypt-py \
8-
-w /wolfcrypt-py \
7+
-v `pwd`:/wolfssl-py \
8+
-w /wolfssl-py \
99
wolfssl/manylinux1-x86_64 \
1010
bash -c "manylinux1/build_wheels.sh"

build_mac_os_x_wheels.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ for PYVERSION in 2.7 3.4 3.5 3.6; do
88
python setup.py bdist_wheel
99
pip install -r requirements/test.txt
1010
set +e
11-
pip uninstall -y wolfcrypt
11+
pip uninstall -y wolfssl
1212
set -e
13-
pip install wolfcrypt --no-index -f dist
13+
pip install wolfssl --no-index -f dist
1414
rm -rf tests/__pycache__
1515
py.test tests
1616
deactivate

docs/Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,9 @@ qthelp:
113113
@echo
114114
@echo "Build finished; now you can run "qcollectiongenerator" with the" \
115115
".qhcp project file in $(BUILDDIR)/qthelp, like this:"
116-
@echo "# qcollectiongenerator $(BUILDDIR)/qthelp/wolfcrypt.qhcp"
116+
@echo "# qcollectiongenerator $(BUILDDIR)/qthelp/wolfssl.qhcp"
117117
@echo "To view the help file:"
118-
@echo "# assistant -collectionFile $(BUILDDIR)/qthelp/wolfcrypt.qhc"
118+
@echo "# assistant -collectionFile $(BUILDDIR)/qthelp/wolfssl.qhc"
119119

120120
.PHONY: applehelp
121121
applehelp:
@@ -132,8 +132,8 @@ devhelp:
132132
@echo
133133
@echo "Build finished."
134134
@echo "To view the help file:"
135-
@echo "# mkdir -p $$HOME/.local/share/devhelp/wolfcrypt"
136-
@echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/wolfcrypt"
135+
@echo "# mkdir -p $$HOME/.local/share/devhelp/wolfssl"
136+
@echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/wolfssl"
137137
@echo "# devhelp"
138138

139139
.PHONY: epub

docs/conf.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# -*- coding: utf-8 -*-
22
#
3-
# wolfcrypt documentation build configuration file, created by
3+
# wolfssl documentation build configuration file, created by
44
# sphinx-quickstart on Fri Apr 29 16:47:53 2016.
55
#
66
# This file is execfile()d with the current directory set to its
@@ -12,7 +12,6 @@
1212
# All configuration values have a default; values that are commented out
1313
# serve to show the default.
1414

15-
import sys
1615
import os
1716
import sphinx_rtd_theme
1817

manylinux1/build_wheels.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ rm -rf dist && mv tmpdist dist
2121
# Install packages and test
2222
for PYBIN in /opt/python/*/bin/; do
2323
"${PYBIN}/pip" install -r requirements/test.txt
24-
"${PYBIN}/pip" install wolfcrypt --no-index -f dist
24+
"${PYBIN}/pip" install wolfssl --no-index -f dist
2525
rm -rf tests/__pycache__
2626
"${PYBIN}/py.test" tests
2727
done

src/wolfssl/__about__.py

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -20,30 +20,29 @@
2020
# along with this program; if not, write to the Free Software
2121
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
2222

23-
# pylint: disable=missing-docstring
24-
25-
METADATA = dict(
26-
__name__="wolfssl",
27-
__version__="0.1.2",
28-
__license__="GPLv2 or Commercial License",
29-
__author__="wolfSSL Inc.",
30-
__author_email__="info@wolfssl.com",
31-
__url__="https://wolfssl.github.io/wolfssl-py",
32-
__description__= \
33-
u"A Python module that encapsulates wolfSSL's C SSL/TLS library.",
34-
__keywords__="security, cryptography, ssl, embedded, embedded ssl",
35-
__classifiers__=[
36-
u"License :: OSI Approved :: GNU General Public License v2 (GPLv2)",
37-
u"License :: Other/Proprietary License",
38-
u"Operating System :: OS Independent",
39-
u"Programming Language :: Python :: 2.7",
40-
u"Programming Language :: Python :: 3.5",
41-
u"Topic :: Security",
42-
u"Topic :: Security :: Cryptography",
43-
u"Topic :: Software Development"
44-
]
45-
)
46-
47-
globals().update(METADATA)
48-
49-
__all__ = list(METADATA.keys())
23+
__title__ = "wolfssl"
24+
__summary__ = "Python module that encapsulates wolfSSL's C SSL/TLS library."
25+
__uri__ = "https://github.com/wolfssl/wolfssl-py"
26+
27+
# When bumping the C library version, reset the POST count to 0
28+
29+
__wolfssl_version__ = "v3.12.2-stable"
30+
31+
# We're using implicit post releases [PEP 440] to bump package version
32+
# while maintaining the C library version intact for better reference.
33+
# https://www.python.org/dev/peps/pep-0440/#implicit-post-releases
34+
#
35+
# MAJOR.MINOR.BUILD-POST
36+
37+
__version__ = __wolfssl_version__[1:].replace("stable", "0")
38+
39+
__author__ = "wolfSSL Inc."
40+
__email__ = "info@wolfssl.com"
41+
42+
__license__ = "GPLv2 or Commercial License"
43+
__copyright__ = "Copyright (C) 2006-2017 wolfSSL Inc"
44+
45+
__all__ = [
46+
"__title__", "__summary__", "__uri__", "__version__", "__wolfssl_version__",
47+
"__author__", "__email__", "__license__", "__copyright__"
48+
]

src/wolfssl/__init__.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
socket, AF_INET, SOCK_STREAM, SOL_SOCKET, SO_TYPE, error as socket_error
2727
)
2828

29+
from wolfssl.__about__ import * # pylint: disable=wildcard-import
30+
2931
try:
3032
from wolfssl._ffi import ffi as _ffi
3133
from wolfssl._ffi import lib as _lib
@@ -45,12 +47,6 @@
4547
WolfSSLMethod as _WolfSSLMethod
4648
)
4749

48-
from wolfssl.__about__ import (
49-
__all__, METADATA
50-
)
51-
52-
globals().update(METADATA)
53-
5450
CERT_NONE = 0
5551
CERT_REQUIRED = 1
5652

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,22 @@
2222

2323
# pylint: disable=missing-docstring, invalid-name
2424

25-
import os
25+
from distutils.util import get_platform
2626
from cffi import FFI
27+
from wolfssl.__about__ import __wolfssl_version__ as version
28+
from wolfssl._build_wolfssl import local_path
2729

2830
ffi = FFI()
2931

30-
_have_options = os.path.exists("/usr/local/include/wolfssl/options.h") \
31-
or os.path.exists("/usr/include/wolfssl/options.h")
32-
3332
ffi.set_source(
3433
"wolfssl._ffi",
3534
"""
3635
#include <wolfssl/options.h>
3736
#include <wolfssl/ssl.h>
38-
""" if _have_options else "#include <wolfssl/ssl.h>",
39-
include_dirs=["/usr/local/include"],
40-
library_dirs=["/usr/local/lib"],
37+
""",
38+
include_dirs=[local_path("lib/wolfssl/src")],
39+
library_dirs=[local_path("lib/wolfssl/{}/{}/lib".format(
40+
get_platform(), version))],
4141
libraries=["wolfssl"],
4242
)
4343

src/wolfssl/_build_wolfssl.py

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
#
4+
# Copyright (C) 2006-2017 wolfSSL Inc.
5+
#
6+
# This file is part of wolfSSL. (formerly known as CyaSSL)
7+
#
8+
# wolfSSL is free software; you can redistribute it and/or modify
9+
# it under the terms of the GNU General Public License as published by
10+
# the Free Software Foundation; either version 2 of the License, or
11+
# (at your option) any later version.
12+
#
13+
# wolfSSL is distributed in the hope that it will be useful,
14+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
# GNU General Public License for more details.
17+
#
18+
# You should have received a copy of the GNU General Public License
19+
# along with this program; if not, write to the Free Software
20+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
21+
22+
import os
23+
import subprocess
24+
from contextlib import contextmanager
25+
from distutils.util import get_platform
26+
27+
28+
def local_path(path):
29+
""" Return path relative to the root of this project
30+
"""
31+
current = os.path.dirname(__file__)
32+
gparent = os.path.dirname(os.path.dirname(current))
33+
return os.path.abspath(os.path.join(gparent, path))
34+
35+
36+
WOLFSSL_GIT_ADDR = "https://github.com/wolfssl/wolfssl.git"
37+
WOLFSSL_SRC_PATH = local_path("lib/wolfssl/src")
38+
39+
40+
def call(cmd):
41+
print("Calling: '{}' from working directory {}".format(cmd, os.getcwd()))
42+
43+
old_env = os.environ["PATH"]
44+
os.environ["PATH"] = "{}:{}".format(WOLFSSL_SRC_PATH, old_env)
45+
subprocess.check_call(cmd, shell=True, env=os.environ)
46+
os.environ["PATH"] = old_env
47+
48+
49+
@contextmanager
50+
def chdir(new_path, mkdir=False):
51+
old_path = os.getcwd()
52+
53+
if mkdir:
54+
try:
55+
os.mkdir(new_path)
56+
except OSError:
57+
pass
58+
59+
try:
60+
yield os.chdir(new_path)
61+
finally:
62+
os.chdir(old_path)
63+
64+
65+
def clone_wolfssl(version):
66+
""" Clone wolfSSL C library repository
67+
"""
68+
call("git clone --depth=1 --branch={} {} {}".format(
69+
version, WOLFSSL_GIT_ADDR, WOLFSSL_SRC_PATH))
70+
71+
72+
def checkout_version(version):
73+
""" Ensure that we have the right version
74+
"""
75+
with chdir(WOLFSSL_SRC_PATH):
76+
current = subprocess.check_output(
77+
["git", "describe", "--all", "--exact-match"]
78+
).strip().decode().split('/')[-1]
79+
80+
if current != version:
81+
tags = subprocess.check_output(
82+
["git", "tag"]
83+
).strip().decode().split("\n")
84+
85+
if version != "master" and version not in tags:
86+
call("git fetch --depth=1 origin tag {}".format(version))
87+
88+
call("git checkout --force {}".format(version))
89+
90+
return True # rebuild needed
91+
92+
return False
93+
94+
95+
def ensure_wolfssl_src(version):
96+
""" Ensure that wolfssl sources are presents and up-to-date
97+
"""
98+
if not os.path.isdir(WOLFSSL_SRC_PATH):
99+
clone_wolfssl(version)
100+
return True
101+
102+
return checkout_version(version)
103+
104+
105+
def make_flags(prefix):
106+
""" Returns compilation flags
107+
"""
108+
flags = []
109+
110+
if get_platform() in ["linux-x86_64", "linux-i686"]:
111+
flags.append("CFLAGS=-fpic")
112+
113+
# install location
114+
flags.append("--prefix={}".format(prefix))
115+
116+
# lib only
117+
flags.append("--disable-shared")
118+
119+
return " ".join(flags)
120+
121+
122+
def make(configure_flags):
123+
""" Create a release of wolfSSL C library
124+
"""
125+
with chdir(WOLFSSL_SRC_PATH):
126+
call("git clean -fdX")
127+
128+
try:
129+
call("./autogen.sh")
130+
except subprocess.CalledProcessError:
131+
call("libtoolize")
132+
call("./autogen.sh")
133+
134+
call("./configure {}".format(configure_flags))
135+
call("make")
136+
call("make install-exec")
137+
138+
139+
def build_wolfssl(version="master"):
140+
prefix = local_path("lib/wolfssl/{}/{}".format(
141+
get_platform(), version))
142+
libfile = os.path.join(prefix, 'lib/libwolfssl.la')
143+
144+
rebuild = ensure_wolfssl_src(version)
145+
146+
if rebuild or not os.path.isfile(libfile):
147+
make(make_flags(prefix))
148+
149+
150+
if __name__ == "__main__":
151+
build_wolfssl()

0 commit comments

Comments
 (0)