add a jenkinsfile for building wheels (#3636)

* add a jenkinsfile for building wheels

* remove scripts we don't need now

* still do the list of installed items on the mac builder

* build 2.6, don't bother with 2.7 ucs4 on mac, simplify batch
diff --git a/.jenkins/Jenkinsfile-cryptography-wheel-builder b/.jenkins/Jenkinsfile-cryptography-wheel-builder
new file mode 100644
index 0000000..55429ca
--- /dev/null
+++ b/.jenkins/Jenkinsfile-cryptography-wheel-builder
@@ -0,0 +1,127 @@
+def configs = [
+    [
+        label: 'windows',
+        versions: ['py26', 'py27', 'py33', 'py34', 'py35', 'py36'],
+    ],
+    [
+        label: 'windows64',
+        versions: ['py26', 'py27', 'py33', 'py34', 'py35', 'py36'],
+    ],
+    [
+        label: 'sierra',
+        versions: ['py26', 'py27', 'py34', 'py35', 'py36'],
+    ],
+]
+
+
+def build(version, label) {
+    try {
+        timeout(time: 30, unit: 'MINUTES') {
+            if (label.contains("windows")) {
+                def pythonPath = [
+                    py26: "C:\\Python26\\python.exe",
+                    py27: "C:\\Python27\\python.exe",
+                    py33: "C:\\Python33\\python.exe",
+                    py34: "C:\\Python34\\python.exe",
+                    py35: "C:\\Python35\\python.exe",
+                    py36: "C:\\Python36\\python.exe"
+                ]
+                if (version == "py35" || version == "py36") {
+                    opensslPaths = [
+                        "windows": [
+                            "include": "C:\\OpenSSL-Win32-2015\\include",
+                            "lib": "C:\\OpenSSL-Win32-2015\\lib"
+                        ],
+                        "windows64": [
+                            "include": "C:\\OpenSSL-Win64-2015\\include",
+                            "lib": "C:\\OpenSSL-Win64-2015\\lib"
+                        ]
+                    ]
+                } else {
+                    opensslPaths = [
+                        "windows": [
+                            "include": "C:\\OpenSSL-Win32-2010\\include",
+                            "lib": "C:\\OpenSSL-Win32-2010\\lib"
+                        ],
+                        "windows64": [
+                            "include": "C:\\OpenSSL-Win64-2010\\include",
+                            "lib": "C:\\OpenSSL-Win64-2010\\lib"
+                        ]
+                    ]
+                }
+                bat """
+                    wmic qfe
+                    @set PATH="C:\\Python27";"C:\\Python27\\Scripts";%PATH%
+                    @set PYTHON="${pythonPath[version]}"
+
+                    @set INCLUDE="${opensslPaths[label]['include']}";%INCLUDE%
+                    @set LIB="${opensslPaths[label]['lib']}";%LIB%
+                    virtualenv -p %PYTHON% .release
+                    call .release\\Scripts\\activate
+                    pip install wheel virtualenv
+                    pip wheel cryptography --wheel-dir=wheelhouse --no-binary cryptography
+                    pip install -f wheelhouse cryptography --no-index
+                    python -c "from cryptography.hazmat.backends.openssl.backend import backend;print('Loaded: ' + backend.openssl_version_text());print('Linked Against: ' + backend._ffi.string(backend._lib.OPENSSL_VERSION_TEXT).decode('ascii'))"
+                """
+            } else if (label.contains("sierra")) {
+                def pythonPath = [
+                    py26: "python2.6",
+                    py27: "/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7",
+                    py34: "/Library/Frameworks/Python.framework/Versions/3.4/bin/python3.4",
+                    py35: "/Library/Frameworks/Python.framework/Versions/3.5/bin/python3.5",
+                    py36: "/Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6",
+                ]
+                ansiColor {
+                    sh """#!/usr/bin/env bash
+                        set -xe
+                        # output the list of things we've installed as a point in time check of how up
+                        # to date the builder is
+                        /usr/sbin/system_profiler SPInstallHistoryDataType
+
+                        # Jenkins logs in as a non-interactive shell, so we don't even have /usr/local/bin in PATH
+                        export PATH="/usr/local/bin:\${PATH}"
+                        export PATH="/Users/jenkins/.pyenv/shims:\${PATH}"
+
+                        printenv
+
+                        virtualenv .venv -p ${pythonPath[version]}
+                        source .venv/bin/activate
+                        pip install -U wheel # upgrade wheel to latest before we use it to build the wheel
+                        # -mmacosx-version-min=10.9 can be remove when https://github.com/pyca/cryptography/issues/3635 is resolved
+                        CRYPTOGRAPHY_SUPPRESS_LINK_FLAGS="1" LDFLAGS="/usr/local/opt/openssl@1.1/lib/libcrypto.a /usr/local/opt/openssl@1.1/lib/libssl.a" CFLAGS="-I/usr/local/opt/openssl@1.1/include -mmacosx-version-min=10.9" pip wheel cryptography --wheel-dir=wheelhouse --no-binary cryptography
+                        pip install -f wheelhouse cryptography --no-index
+                        python -c "from cryptography.hazmat.backends.openssl.backend import backend;print('Loaded: ' + backend.openssl_version_text());print('Linked Against: ' + backend._ffi.string(backend._lib.OPENSSL_VERSION_TEXT).decode('ascii'))"
+                        otool -L `find .venv -name '_openssl*.so'`
+                        lipo -info `find .venv -name '*.so'`
+                        otool -L `find .venv -name '_openssl*.so'` | grep -vG "libcrypto\\|libssl"
+                    """
+                }
+            }
+            archiveArtifacts artifacts: "wheelhouse/cryptography*.whl"
+        }
+    } finally {
+        deleteDir()
+    }
+
+}
+
+def builders = [:]
+for (config in configs) {
+    def label = config["label"]
+    def versions = config["versions"]
+
+    for (_version in versions) {
+        def version = _version
+
+        def combinedName = "${label}-${version}"
+        builders[combinedName] = {
+            node(label) {
+                stage(combinedName) {
+                    build(version, label)
+                }
+            }
+        }
+    }
+}
+
+parallel builders
diff --git a/.jenkins/mac-wheel.sh b/.jenkins/mac-wheel.sh
deleted file mode 100644
index 0db7a7b..0000000
--- a/.jenkins/mac-wheel.sh
+++ /dev/null
@@ -1,71 +0,0 @@
-#!/bin/bash -xe
-
-# output the list of things we've installed as a point in time check of how up
-# to date the builder is
-/usr/sbin/system_profiler SPInstallHistoryDataType
-# Jenkins logs in as a non-interactive shell, so we don't even have
-# /usr/local/bin in PATH
-export PATH=/usr/local/bin:$PATH
-# pyenv is nothing but trouble with non-interactive shells so we can't
-# eval "$(pyenv init -)"
-export PATH="/Users/jenkins/.pyenv/shims:${PATH}"
-
-# TODO: upgrade wheel builder VM and run it on El Cap with python.org Pythons.
-if [[ "${label}" == "10.10" ]]; then
-    case "${TOXENV}" in
-        py26)
-            PYTHON=/usr/bin/python2.6
-            ;;
-        py27)
-            PYTHON=/usr/bin/python2.7
-            ;;
-        py27u)
-            PYTHON=python2.7
-            ;;
-        py33)
-            PYTHON=python3.3
-            ;;
-        py34)
-            PYTHON=python3.4
-            ;;
-        py35)
-            PYTHON=python3.5
-            ;;
-        py36)
-            PYTHON=python3.6
-            ;;
-        pypy)
-            PYTHON=pypy
-            ;;
-    esac
-else
-    case "${TOXENV}" in
-        py27)
-            PYTHON=/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7
-            ;;
-        py33)
-            PYTHON=/Library/Frameworks/Python.framework/Versions/3.3/bin/python3.3
-            ;;
-        py34)
-            PYTHON=/Library/Frameworks/Python.framework/Versions/3.4/bin/python3.4
-            ;;
-        py35)
-            PYTHON=/Library/Frameworks/Python.framework/Versions/3.5/bin/python3.5
-            ;;
-        py36)
-            PYTHON=/Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6
-            ;;
-    esac
-fi
-printenv
-
-virtualenv .venv -p $PYTHON
-source .venv/bin/activate
-# upgrade wheel to latest before we use it to build the wheel
-pip install -U wheel
-CRYPTOGRAPHY_SUPPRESS_LINK_FLAGS="1" LDFLAGS="/usr/local/opt/openssl@1.1/lib/libcrypto.a /usr/local/opt/openssl@1.1/lib/libssl.a" CFLAGS="-I/usr/local/opt/openssl@1.1/include" pip wheel cryptography --wheel-dir=wheelhouse --no-use-wheel
-pip install -f wheelhouse cryptography --no-index
-python -c "from cryptography.hazmat.backends.openssl.backend import backend;print('Loaded: ' + backend.openssl_version_text());print('Linked Against: ' + backend._ffi.string(backend._lib.OPENSSL_VERSION_TEXT).decode('ascii'))"
-otool -L `find .venv -name '_openssl*.so'`
-lipo -info `find .venv -name '*.so'`
-otool -L `find .venv -name '_openssl*.so'` | grep -vG "libcrypto\|libssl"
diff --git a/.jenkins/windows-wheel.bat b/.jenkins/windows-wheel.bat
deleted file mode 100644
index 78b3000..0000000
--- a/.jenkins/windows-wheel.bat
+++ /dev/null
@@ -1,56 +0,0 @@
-wmic qfe
-@set PATH="C:\Python27";"C:\Python27\Scripts";%PATH%
-SET
-if "%TOXENV%" == "py26" (
-    @set PYTHON="C:\Python26\python.exe"
-)
-if "%TOXENV%" == "py27" (
-    @set PYTHON="C:\Python27\python.exe"
-)
-if "%TOXENV%" == "py33" (
-    @set PYTHON="C:\Python33\python.exe"
-)
-if "%TOXENV%" == "py34" (
-    @set PYTHON="C:\Python34\python.exe"
-)
-if "%TOXENV%" == "py35" (
-    @set PYTHON="C:\Python35\python.exe"
-)
-if "%TOXENV%" == "py36" (
-    @set PYTHON="C:\Python36\python.exe"
-)
-
-@set py35orabove=true
-
-if not "%TOXENV%" == "py35" (
-    if not "%TOXENV%" == "py36" (
-        @set py35orabove=false
-    )
-)
-
-if "%py35orabove%" == "true" (
-    if %label% == windows (
-        @set INCLUDE="C:\OpenSSL-Win32-2015\include";%INCLUDE%
-        @set LIB="C:\OpenSSL-Win32-2015\lib";%LIB%
-    ) else (
-        @set INCLUDE="C:\OpenSSL-Win64-2015\include";%INCLUDE%
-        @set LIB="C:\OpenSSL-Win64-2015\lib";%LIB%
-    )
-) else (
-    if %label% == windows (
-        @set INCLUDE="C:\OpenSSL-Win32-2010\include";%INCLUDE%
-        @set LIB="C:\OpenSSL-Win32-2010\lib";%LIB%
-    ) else (
-        @set INCLUDE="C:\OpenSSL-Win64-2010\include";%INCLUDE%
-        @set LIB="C:\OpenSSL-Win64-2010\lib";%LIB%
-    )
-)
-
-virtualenv -p %PYTHON% .release
-call .release\Scripts\activate
-pip install wheel virtualenv
-pip wheel cryptography --wheel-dir=wheelhouse --no-use-wheel
-for %%x in (wheelhouse\*.whl) do (
-   pip install %%x
-)
-python -c "from cryptography.hazmat.backends.openssl.backend import backend;print('Loaded: ' + backend.openssl_version_text());print('Linked Against: ' + backend._ffi.string(backend._lib.OPENSSL_VERSION_TEXT).decode('ascii'))"