From 1aa226bff008b5e4f4c403d51a537c703b6b8fdb Mon Sep 17 00:00:00 2001 From: Andrew Hutchings Date: Mon, 31 Jan 2022 14:56:55 +0000 Subject: [PATCH] Backport fixes from wolfcrypt-py * Make wolfSSL a submodule * Fix sdist packaging * Make tox work on all py3 releases and remove pep8 for now --- .gitignore | 1 - .gitmodules | 3 +++ Makefile | 2 +- lib/wolfssl | 1 + setup.py | 5 ----- tox.ini | 3 +-- wolfssl/_build_wolfssl.py | 32 ++++++++++++++++---------------- 7 files changed, 22 insertions(+), 25 deletions(-) create mode 100644 .gitmodules create mode 160000 lib/wolfssl diff --git a/.gitignore b/.gitignore index f21f9f7..3d307ce 100644 --- a/.gitignore +++ b/.gitignore @@ -16,7 +16,6 @@ dist/ downloads/ eggs/ .eggs/ -lib/ lib64/ parts/ sdist/ diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..e35e41e --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "lib/wolfssl"] + path = lib/wolfssl + url = https://github.com/wolfssl/wolfssl diff --git a/Makefile b/Makefile index 848087d..2e4e031 100644 --- a/Makefile +++ b/Makefile @@ -30,13 +30,13 @@ clean: clean-build clean-pyc clean-test ## remove all build, test, coverage and clean-build: ## remove build artifacts - rm -fr lib/ rm -fr build/ rm -fr dist/ rm -fr .eggs/ rm -fr wolfssl/_ffi* find . -name '*.egg-info' -exec rm -fr {} + find . -name '*.egg' -exec rm -f {} + + -cd lib/wolfssl && make clean clean-pyc: ## remove Python file artifacts find . -name '*.pyc' -exec rm -f {} + diff --git a/lib/wolfssl b/lib/wolfssl new file mode 160000 index 0000000..c3513bf --- /dev/null +++ b/lib/wolfssl @@ -0,0 +1 @@ +Subproject commit c3513bf2573c30f6d2df815de216120e92142020 diff --git a/setup.py b/setup.py index ffb3e09..848cf07 100755 --- a/setup.py +++ b/setup.py @@ -27,10 +27,6 @@ from setuptools import setup from setuptools.command.build_ext import build_ext -# Adding src folder to the include path in order to import from wolfssl -package_dir = os.path.dirname(__file__) -sys.path.insert(0, package_dir) - import wolfssl from wolfssl._build_wolfssl import build_wolfssl from wolfssl._build_wolfssl import wolfssl_inc_path, wolfssl_lib_path @@ -90,7 +86,6 @@ setup( license=wolfssl.__license__, packages=["wolfssl"], - package_dir={"":package_dir}, zip_safe=False, cffi_modules=["./wolfssl/_build_ffi.py:ffi"], diff --git a/tox.ini b/tox.ini index 0faa47e..bb31b55 100644 --- a/tox.ini +++ b/tox.ini @@ -1,6 +1,5 @@ [tox] -envlist = py39, pep8 -skipsdist = True +envlist = py3 [testenv] setenv = diff --git a/wolfssl/_build_wolfssl.py b/wolfssl/_build_wolfssl.py index d0a137c..7af7960 100644 --- a/wolfssl/_build_wolfssl.py +++ b/wolfssl/_build_wolfssl.py @@ -34,14 +34,13 @@ def local_path(path): return os.path.abspath(os.path.join(current, path)) -WOLFSSL_GIT_ADDR = "https://github.com/wolfssl/wolfssl.git" -WOLFSSL_SRC_PATH = local_path("lib/wolfssl/src") +WOLFSSL_SRC_PATH = local_path("lib/wolfssl") def wolfssl_inc_path(): wolfssl_path = os.environ.get("USE_LOCAL_WOLFSSL") if wolfssl_path is None: - return local_path("lib/wolfssl/src") + return local_path("lib/wolfssl") else: if os.path.isdir(wolfssl_path) and os.path.exists(wolfssl_path): return wolfssl_path + "/include" @@ -86,20 +85,17 @@ def chdir(new_path, mkdir=False): os.chdir(old_path) -def clone_wolfssl(ref): - """ Clone wolfSSL C library repository - """ - call("git clone --depth=1 --branch={} {} {}".format( - ref, WOLFSSL_GIT_ADDR, WOLFSSL_SRC_PATH)) - - def checkout_ref(ref): """ Ensure that we have the right version """ with chdir(WOLFSSL_SRC_PATH): - current = subprocess.check_output( - ["git", "describe", "--all", "--exact-match"] - ).strip().decode().split('/')[-1] + current = "" + try: + current = subprocess.check_output( + ["git", "describe", "--all", "--exact-match"] + ).strip().decode().split('/')[-1] + except: + pass if current != ref: tags = subprocess.check_output( @@ -119,9 +115,13 @@ def checkout_ref(ref): def ensure_wolfssl_src(ref): """ Ensure that wolfssl sources are presents and up-to-date """ - if not os.path.isdir(WOLFSSL_SRC_PATH): - clone_wolfssl(ref) - return True + if not os.path.isdir("lib"): + os.mkdir("lib") + with chdir("lib"): + subprocess.run(["git", "clone", "--depth=1", "https://github.com/wolfssl/wolfssl"]) + + if not os.path.isdir(os.path.join(WOLFSSL_SRC_PATH, "wolfssl")): + subprocess.run(["git", "submodule", "update", "--init", "--depth=1"]) return checkout_ref(ref)