• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# coding: utf-8
2from __future__ import unicode_literals, division, absolute_import, print_function
3
4import os
5import platform
6import sys
7import subprocess
8
9
10run_args = [
11    {
12        'name': 'cffi',
13        'kwarg': 'cffi',
14    },
15    {
16        'name': 'openssl',
17        'kwarg': 'openssl',
18    },
19    {
20        'name': 'winlegacy',
21        'kwarg': 'winlegacy',
22    },
23]
24
25
26def _write_env(env, key, value):
27    sys.stdout.write("%s: %s\n" % (key, value))
28    sys.stdout.flush()
29    if sys.version_info < (3,):
30        env[key.encode('utf-8')] = value.encode('utf-8')
31    else:
32        env[key] = value
33
34
35def run(**_):
36    """
37    Runs CI, setting various env vars
38
39    :return:
40        A bool - if the CI ran successfully
41    """
42
43    env = os.environ.copy()
44    options = set(sys.argv[2:])
45
46    newline = False
47    if 'cffi' not in options:
48        _write_env(env, 'OSCRYPTO_USE_CTYPES', 'true')
49        newline = True
50    if 'openssl' in options and sys.platform == 'darwin':
51        mac_version_info = tuple(map(int, platform.mac_ver()[0].split('.')[:2]))
52        if mac_version_info < (10, 15):
53            _write_env(env, 'OSCRYPTO_USE_OPENSSL', '/usr/lib/libcrypto.dylib,/usr/lib/libssl.dylib')
54        else:
55            _write_env(env, 'OSCRYPTO_USE_OPENSSL', '/usr/lib/libcrypto.35.dylib,/usr/lib/libssl.35.dylib')
56        newline = True
57    if 'winlegacy' in options:
58        _write_env(env, 'OSCRYPTO_USE_WINLEGACY', 'true')
59        newline = True
60
61    if newline:
62        sys.stdout.write("\n")
63
64    proc = subprocess.Popen(
65        [
66            sys.executable,
67            'run.py',
68            'ci',
69        ],
70        env=env
71    )
72    proc.communicate()
73    return proc.returncode == 0
74