build_virtualenv 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #!/bin/bash
  2. #
  3. # runs dh_virtualenv to build the virtualenv in the build directory,
  4. # and then runs the trial tests against the installed synapse.
  5. set -e
  6. export DH_VIRTUALENV_INSTALL_ROOT=/opt/venvs
  7. # make sure that the virtualenv links to the specific version of python, by
  8. # dereferencing the python3 symlink.
  9. #
  10. # Otherwise, if somebody tries to install (say) the stretch package on buster,
  11. # they will get a confusing error about "No module named 'synapse'", because
  12. # python won't look in the right directory. At least this way, the error will
  13. # be a *bit* more obvious.
  14. #
  15. SNAKE=`readlink -e /usr/bin/python3`
  16. # try to set the CFLAGS so any compiled C extensions are compiled with the most
  17. # generic as possible x64 instructions, so that compiling it on a new Intel chip
  18. # doesn't enable features not available on older ones or AMD.
  19. #
  20. # TODO: add similar things for non-amd64, or figure out a more generic way to
  21. # do this.
  22. case `dpkg-architecture -q DEB_HOST_ARCH` in
  23. amd64)
  24. export CFLAGS=-march=x86-64
  25. ;;
  26. esac
  27. # Use --builtin-venv to use the better `venv` module from CPython 3.4+ rather
  28. # than the 2/3 compatible `virtualenv`.
  29. # Pin pip to 20.3.4 to fix breakage in 21.0 on py3.5 (xenial)
  30. dh_virtualenv \
  31. --install-suffix "matrix-synapse" \
  32. --builtin-venv \
  33. --python "$SNAKE" \
  34. --upgrade-pip-to="20.3.4" \
  35. --preinstall="lxml" \
  36. --preinstall="mock" \
  37. --extra-pip-arg="--no-cache-dir" \
  38. --extra-pip-arg="--compile" \
  39. --extras="all,systemd,test"
  40. PACKAGE_BUILD_DIR="debian/matrix-synapse-py3"
  41. VIRTUALENV_DIR="${PACKAGE_BUILD_DIR}${DH_VIRTUALENV_INSTALL_ROOT}/matrix-synapse"
  42. TARGET_PYTHON="${VIRTUALENV_DIR}/bin/python"
  43. # we copy the tests to a temporary directory so that we can put them on the
  44. # PYTHONPATH without putting the uninstalled synapse on the pythonpath.
  45. tmpdir=`mktemp -d`
  46. trap "rm -r $tmpdir" EXIT
  47. cp -r tests "$tmpdir"
  48. PYTHONPATH="$tmpdir" \
  49. "${TARGET_PYTHON}" -B -m twisted.trial --reporter=text -j2 tests
  50. # build the config file
  51. "${TARGET_PYTHON}" -B "${VIRTUALENV_DIR}/bin/generate_config" \
  52. --config-dir="/etc/matrix-synapse" \
  53. --data-dir="/var/lib/matrix-synapse" |
  54. perl -pe '
  55. # tweak the paths to the tls certs and signing keys
  56. /^tls_.*_path:/ and s/SERVERNAME/homeserver/;
  57. /^signing_key_path:/ and s/SERVERNAME/homeserver/;
  58. # tweak the pid file location
  59. /^pid_file:/ and s#:.*#: "/var/run/matrix-synapse.pid"#;
  60. # tweak the path to the log config
  61. /^log_config:/ and s/SERVERNAME\.log\.config/log.yaml/;
  62. # tweak the path to the media store
  63. /^media_store_path:/ and s#/media_store#/media#;
  64. # remove the server_name setting, which is set in a separate file
  65. /^server_name:/ and $_ = "#\n# This is set in /etc/matrix-synapse/conf.d/server_name.yaml for Debian installations.\n# $_";
  66. # remove the report_stats setting, which is set in a separate file
  67. /^# report_stats:/ and $_ = "";
  68. ' > "${PACKAGE_BUILD_DIR}/etc/matrix-synapse/homeserver.yaml"
  69. # build the log config file
  70. "${TARGET_PYTHON}" -B "${VIRTUALENV_DIR}/bin/generate_log_config" \
  71. --output-file="${PACKAGE_BUILD_DIR}/etc/matrix-synapse/log.yaml"
  72. # add a dependency on the right version of python to substvars.
  73. PYPKG=`basename $SNAKE`
  74. echo "synapse:pydepends=$PYPKG" >> debian/matrix-synapse-py3.substvars