• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!not for running standalone, see .travis.yml
2
3cache_dir=$HOME/.cache
4install_dir=$cache_dir/py3-openssl11
5python_version="3.7.3"
6openssl_version="1.1.1f"
7cpucount=$(nproc --all)
8export PYTHONDONTWRITEBYTECODE=1
9
10#rm -rf $cache_dir/* # uncomment to rebuild
11
12if [[ $($install_dir/bin/python -V) != "Python $python_version" ]] ; then
13  (
14  mkdir -p /tmp/source
15  cd /tmp/source
16  # Compile OpenSSL
17  curl -fLOsS "https://www.openssl.org/source/openssl-$openssl_version.tar.gz"
18  echo "Extracting OpenSSL..."
19  tar xf openssl-$openssl_version.tar.gz
20  cd ./openssl-$openssl_version
21  echo "Compiling OpenSSL $openssl_version..."
22  ./config shared --prefix=$install_dir
23  echo "Running make for OpenSSL..."
24  make -j$cpucount -s
25  echo "Running make install for OpenSSL..."
26  make install_sw >/dev/null
27  export LD_LIBRARY_PATH=$install_dir/lib
28
29  cd /tmp/source
30  sudo apt install -qq --yes libffi-dev
31  # Compile latest Python
32  curl -fLOsS "https://www.python.org/ftp/python/$python_version/Python-$python_version.tar.xz"
33  echo "Extracting Python..."
34  tar xf Python-$python_version.tar.xz
35  cd ./Python-$python_version
36  echo "Compiling Python $python_version..."
37  # Note we are purposefully NOT using optimization flags as they increase compile time 10x
38  conf_flags="--with-openssl=$install_dir --prefix=$install_dir --with-ensurepip=upgrade"
39  CFLAGS=-O1 ./configure $conf_flags > /dev/null
40  make -j$cpucount -s
41  echo "Installing Python..."
42  make altinstall bininstall >/dev/null
43  ln -fs pip3.7 $install_dir/bin/pip3
44  ln -fs pip3 $install_dir/bin/pip
45  ln -fs python3 $install_dir/bin/python
46  # care for CI cache size
47  find $install_dir -type d -name __pycache__ -print0 |xargs -0 rm -rf
48  )
49fi
50
51export LD_LIBRARY_PATH=$install_dir/lib
52export PATH=$install_dir/bin:$PATH
53if [[ $(python -V) != "Python $python_version" ]] ; then
54  echo "Required Python version was not installed into PATH" >&2
55  exit 1
56fi
57if [[ $(python -c 'import ssl; print(ssl.OPENSSL_VERSION)') != OpenSSL\ ${openssl_version}* ]] ; then
58  echo "Required OpenSSL version was not installed into Python" >&2
59  exit 1
60fi
61