You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

140 lines
4.5 KiB

  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. # Manually install Poetry and export a pip-compatible `requirements.txt`
  28. # We need a Poetry pre-release as the export command is buggy in < 1.2
  29. TEMP_VENV="$(mktemp -d)"
  30. python3 -m venv "$TEMP_VENV"
  31. source "$TEMP_VENV/bin/activate"
  32. pip install -U pip
  33. pip install poetry==1.2.0
  34. poetry export \
  35. --extras all \
  36. --extras test \
  37. --extras systemd \
  38. -o exported_requirements.txt
  39. deactivate
  40. rm -rf "$TEMP_VENV"
  41. # Use --no-deps to only install pinned versions in exported_requirements.txt,
  42. # and to avoid https://github.com/pypa/pip/issues/9644
  43. dh_virtualenv \
  44. --install-suffix "matrix-synapse" \
  45. --builtin-venv \
  46. --python "$SNAKE" \
  47. --upgrade-pip \
  48. --preinstall="lxml" \
  49. --preinstall="mock" \
  50. --preinstall="wheel" \
  51. --extra-pip-arg="--no-deps" \
  52. --extra-pip-arg="--no-cache-dir" \
  53. --extra-pip-arg="--compile" \
  54. --extras="all,systemd,test" \
  55. --requirements="exported_requirements.txt"
  56. PACKAGE_BUILD_DIR="$(pwd)/debian/matrix-synapse-py3"
  57. VIRTUALENV_DIR="${PACKAGE_BUILD_DIR}${DH_VIRTUALENV_INSTALL_ROOT}/matrix-synapse"
  58. TARGET_PYTHON="${VIRTUALENV_DIR}/bin/python"
  59. case "$DEB_BUILD_OPTIONS" in
  60. *nocheck*)
  61. # Skip running tests if "nocheck" present in $DEB_BUILD_OPTIONS
  62. ;;
  63. *)
  64. # Copy tests to a temporary directory so that we can put them on the
  65. # PYTHONPATH without putting the uninstalled synapse on the pythonpath.
  66. tmpdir=$(mktemp -d)
  67. trap 'rm -r $tmpdir' EXIT
  68. cp -r tests "$tmpdir"
  69. # To avoid pulling in the unbuilt Synapse in the local directory
  70. pushd /
  71. PYTHONPATH="$tmpdir" \
  72. "${TARGET_PYTHON}" -m twisted.trial --reporter=text -j2 tests
  73. popd
  74. ;;
  75. esac
  76. # build the config file
  77. "${TARGET_PYTHON}" "${VIRTUALENV_DIR}/bin/generate_config" \
  78. --config-dir="/etc/matrix-synapse" \
  79. --data-dir="/var/lib/matrix-synapse" |
  80. perl -pe '
  81. # tweak the paths to the tls certs and signing keys
  82. /^tls_.*_path:/ and s/SERVERNAME/homeserver/;
  83. /^signing_key_path:/ and s/SERVERNAME/homeserver/;
  84. # tweak the pid file location
  85. /^pid_file:/ and s#:.*#: "/var/run/matrix-synapse.pid"#;
  86. # tweak the path to the log config
  87. /^log_config:/ and s/SERVERNAME\.log\.config/log.yaml/;
  88. # tweak the path to the media store
  89. /^media_store_path:/ and s#/media_store#/media#;
  90. # remove the server_name setting, which is set in a separate file
  91. /^server_name:/ and $_ = "#\n# This is set in /etc/matrix-synapse/conf.d/server_name.yaml for Debian installations.\n# $_";
  92. # remove the report_stats setting, which is set in a separate file
  93. /^# report_stats:/ and $_ = "";
  94. ' > "${PACKAGE_BUILD_DIR}/etc/matrix-synapse/homeserver.yaml"
  95. # build the log config file
  96. "${TARGET_PYTHON}" "${VIRTUALENV_DIR}/bin/generate_log_config" \
  97. --output-file="${PACKAGE_BUILD_DIR}/etc/matrix-synapse/log.yaml"
  98. # add a dependency on the right version of python to substvars.
  99. PYPKG=$(basename "$SNAKE")
  100. echo "synapse:pydepends=$PYPKG" >> debian/matrix-synapse-py3.substvars
  101. # add a couple of triggers. This is needed so that dh-virtualenv can rebuild
  102. # the venv when the system python changes (see
  103. # https://dh-virtualenv.readthedocs.io/en/latest/tutorial.html#step-2-set-up-packaging-for-your-project)
  104. #
  105. # we do it here rather than the more conventional way of just adding it to
  106. # debian/matrix-synapse-py3.triggers, because we need to add a trigger on the
  107. # right version of python.
  108. cat >>"debian/.debhelper/generated/matrix-synapse-py3/triggers" <<EOF
  109. # triggers for dh-virtualenv
  110. interest-noawait $SNAKE
  111. interest dh-virtualenv-interpreter-update
  112. EOF