build_virtualenv 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. dh_virtualenv \
  30. --install-suffix "matrix-synapse" \
  31. --builtin-venv \
  32. --setuptools \
  33. --python "$SNAKE" \
  34. --upgrade-pip \
  35. --preinstall="lxml" \
  36. --preinstall="mock" \
  37. --extra-pip-arg="--no-cache-dir" \
  38. --extra-pip-arg="--compile" \
  39. --extras="all"
  40. # we copy the tests to a temporary directory so that we can put them on the
  41. # PYTHONPATH without putting the uninstalled synapse on the pythonpath.
  42. tmpdir=`mktemp -d`
  43. trap "rm -r $tmpdir" EXIT
  44. cp -r tests "$tmpdir"
  45. PYTHONPATH="$tmpdir" \
  46. debian/matrix-synapse-py3/opt/venvs/matrix-synapse/bin/python \
  47. -B -m twisted.trial --reporter=text -j2 tests
  48. # add a dependency on the right version of python to substvars.
  49. PYPKG=`basename $SNAKE`
  50. echo "synapse:pydepends=$PYPKG" >> debian/matrix-synapse-py3.substvars