Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 
 
 

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