2018-12-20 04:33:29 -07:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
|
|
|
# runs dh_virtualenv to build the virtualenv in the build directory,
|
|
|
|
# and then runs the trial tests against the installed synapse.
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
export DH_VIRTUALENV_INSTALL_ROOT=/opt/venvs
|
2019-01-23 04:43:04 -07:00
|
|
|
|
|
|
|
# make sure that the virtualenv links to the specific version of python, by
|
|
|
|
# dereferencing the python3 symlink.
|
|
|
|
#
|
|
|
|
# Otherwise, if somebody tries to install (say) the stretch package on buster,
|
|
|
|
# they will get a confusing error about "No module named 'synapse'", because
|
|
|
|
# python won't look in the right directory. At least this way, the error will
|
|
|
|
# be a *bit* more obvious.
|
|
|
|
#
|
2021-10-22 16:07:23 -06:00
|
|
|
SNAKE=$(readlink -e /usr/bin/python3)
|
2018-12-20 04:33:29 -07:00
|
|
|
|
|
|
|
# try to set the CFLAGS so any compiled C extensions are compiled with the most
|
|
|
|
# generic as possible x64 instructions, so that compiling it on a new Intel chip
|
|
|
|
# doesn't enable features not available on older ones or AMD.
|
|
|
|
#
|
|
|
|
# TODO: add similar things for non-amd64, or figure out a more generic way to
|
|
|
|
# do this.
|
|
|
|
|
2021-10-22 16:07:23 -06:00
|
|
|
case $(dpkg-architecture -q DEB_HOST_ARCH) in
|
2018-12-20 04:33:29 -07:00
|
|
|
amd64)
|
|
|
|
export CFLAGS=-march=x86-64
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2022-04-14 04:03:24 -06:00
|
|
|
# Manually install Poetry and export a pip-compatible `requirements.txt`
|
|
|
|
# We need a Poetry pre-release as the export command is buggy in < 1.2
|
|
|
|
TEMP_VENV="$(mktemp -d)"
|
|
|
|
python3 -m venv "$TEMP_VENV"
|
|
|
|
source "$TEMP_VENV/bin/activate"
|
|
|
|
pip install -U pip
|
2022-09-01 08:11:44 -06:00
|
|
|
pip install poetry==1.2.0
|
2022-05-05 07:51:15 -06:00
|
|
|
poetry export \
|
|
|
|
--extras all \
|
|
|
|
--extras test \
|
|
|
|
--extras systemd \
|
|
|
|
-o exported_requirements.txt
|
2022-04-14 04:03:24 -06:00
|
|
|
deactivate
|
|
|
|
rm -rf "$TEMP_VENV"
|
2018-12-20 04:33:29 -07:00
|
|
|
|
2022-04-14 04:03:24 -06:00
|
|
|
# Use --no-deps to only install pinned versions in exported_requirements.txt,
|
|
|
|
# and to avoid https://github.com/pypa/pip/issues/9644
|
2018-12-20 04:33:29 -07:00
|
|
|
dh_virtualenv \
|
|
|
|
--install-suffix "matrix-synapse" \
|
|
|
|
--builtin-venv \
|
|
|
|
--python "$SNAKE" \
|
2021-07-21 14:25:28 -06:00
|
|
|
--upgrade-pip \
|
2018-12-20 04:33:29 -07:00
|
|
|
--preinstall="lxml" \
|
|
|
|
--preinstall="mock" \
|
Minor cleanup to Debian packaging (#11269)
* Remove unused Vagrant scripts
* Change package Architecture to any
* Preinstall the wheel package when building venvs.
Addresses the following warnings during Debian builds:
Using legacy 'setup.py install' for jaeger-client, since package 'wheel' is not installed.
Using legacy 'setup.py install' for matrix-synapse-ldap3, since package 'wheel' is not installed.
Using legacy 'setup.py install' for opentracing, since package 'wheel' is not installed.
Using legacy 'setup.py install' for psycopg2, since package 'wheel' is not installed.
Using legacy 'setup.py install' for systemd-python, since package 'wheel' is not installed.
Using legacy 'setup.py install' for pympler, since package 'wheel' is not installed.
Using legacy 'setup.py install' for threadloop, since package 'wheel' is not installed.
Using legacy 'setup.py install' for thrift, since package 'wheel' is not installed.
* Allow /etc/default/matrix-synapse to be missing
Per the systemd.exec manpage, prefixing an EnvironmentFile with "-":
> indicates that if the file does not exist, it will not be read and no
> error or warning message is logged.
Signed-off-by: Dan Callahan <danc@element.io>
2021-11-07 14:18:33 -07:00
|
|
|
--preinstall="wheel" \
|
2022-04-14 04:03:24 -06:00
|
|
|
--extra-pip-arg="--no-deps" \
|
2018-12-20 04:33:29 -07:00
|
|
|
--extra-pip-arg="--no-cache-dir" \
|
2019-01-02 00:17:39 -07:00
|
|
|
--extra-pip-arg="--compile" \
|
2022-04-14 04:03:24 -06:00
|
|
|
--extras="all,systemd,test" \
|
|
|
|
--requirements="exported_requirements.txt"
|
2018-12-20 04:33:29 -07:00
|
|
|
|
2022-09-06 12:01:37 -06:00
|
|
|
PACKAGE_BUILD_DIR="$(pwd)/debian/matrix-synapse-py3"
|
2019-01-24 06:39:01 -07:00
|
|
|
VIRTUALENV_DIR="${PACKAGE_BUILD_DIR}${DH_VIRTUALENV_INSTALL_ROOT}/matrix-synapse"
|
|
|
|
TARGET_PYTHON="${VIRTUALENV_DIR}/bin/python"
|
|
|
|
|
2021-04-12 08:27:05 -06:00
|
|
|
case "$DEB_BUILD_OPTIONS" in
|
|
|
|
*nocheck*)
|
|
|
|
# Skip running tests if "nocheck" present in $DEB_BUILD_OPTIONS
|
|
|
|
;;
|
|
|
|
|
|
|
|
*)
|
|
|
|
# Copy tests to a temporary directory so that we can put them on the
|
|
|
|
# PYTHONPATH without putting the uninstalled synapse on the pythonpath.
|
2021-10-22 16:07:23 -06:00
|
|
|
tmpdir=$(mktemp -d)
|
2021-10-18 14:49:09 -06:00
|
|
|
trap 'rm -r $tmpdir' EXIT
|
2021-04-12 08:27:05 -06:00
|
|
|
|
|
|
|
cp -r tests "$tmpdir"
|
2018-12-20 04:33:29 -07:00
|
|
|
|
2022-09-06 12:01:37 -06:00
|
|
|
# To avoid pulling in the unbuilt Synapse in the local directory
|
|
|
|
pushd /
|
|
|
|
|
2021-04-12 08:27:05 -06:00
|
|
|
PYTHONPATH="$tmpdir" \
|
|
|
|
"${TARGET_PYTHON}" -m twisted.trial --reporter=text -j2 tests
|
2018-12-20 04:33:29 -07:00
|
|
|
|
2022-09-06 12:01:37 -06:00
|
|
|
popd
|
|
|
|
|
2021-04-12 08:27:05 -06:00
|
|
|
;;
|
|
|
|
esac
|
2019-01-24 06:39:01 -07:00
|
|
|
|
|
|
|
# build the config file
|
2021-02-26 11:30:54 -07:00
|
|
|
"${TARGET_PYTHON}" "${VIRTUALENV_DIR}/bin/generate_config" \
|
2019-01-24 06:39:01 -07:00
|
|
|
--config-dir="/etc/matrix-synapse" \
|
|
|
|
--data-dir="/var/lib/matrix-synapse" |
|
|
|
|
perl -pe '
|
|
|
|
# tweak the paths to the tls certs and signing keys
|
|
|
|
/^tls_.*_path:/ and s/SERVERNAME/homeserver/;
|
|
|
|
/^signing_key_path:/ and s/SERVERNAME/homeserver/;
|
|
|
|
|
|
|
|
# tweak the pid file location
|
|
|
|
/^pid_file:/ and s#:.*#: "/var/run/matrix-synapse.pid"#;
|
|
|
|
|
|
|
|
# tweak the path to the log config
|
|
|
|
/^log_config:/ and s/SERVERNAME\.log\.config/log.yaml/;
|
|
|
|
|
|
|
|
# tweak the path to the media store
|
|
|
|
/^media_store_path:/ and s#/media_store#/media#;
|
|
|
|
|
|
|
|
# remove the server_name setting, which is set in a separate file
|
|
|
|
/^server_name:/ and $_ = "#\n# This is set in /etc/matrix-synapse/conf.d/server_name.yaml for Debian installations.\n# $_";
|
|
|
|
|
|
|
|
# remove the report_stats setting, which is set in a separate file
|
|
|
|
/^# report_stats:/ and $_ = "";
|
|
|
|
|
|
|
|
' > "${PACKAGE_BUILD_DIR}/etc/matrix-synapse/homeserver.yaml"
|
|
|
|
|
2020-01-03 10:14:00 -07:00
|
|
|
# build the log config file
|
2021-02-26 11:30:54 -07:00
|
|
|
"${TARGET_PYTHON}" "${VIRTUALENV_DIR}/bin/generate_log_config" \
|
2020-01-03 10:14:00 -07:00
|
|
|
--output-file="${PACKAGE_BUILD_DIR}/etc/matrix-synapse/log.yaml"
|
2019-01-23 04:43:04 -07:00
|
|
|
|
|
|
|
# add a dependency on the right version of python to substvars.
|
2021-10-22 16:07:23 -06:00
|
|
|
PYPKG=$(basename "$SNAKE")
|
2019-01-23 04:43:04 -07:00
|
|
|
echo "synapse:pydepends=$PYPKG" >> debian/matrix-synapse-py3.substvars
|
2021-08-03 07:45:21 -06:00
|
|
|
|
|
|
|
|
|
|
|
# add a couple of triggers. This is needed so that dh-virtualenv can rebuild
|
|
|
|
# the venv when the system python changes (see
|
|
|
|
# https://dh-virtualenv.readthedocs.io/en/latest/tutorial.html#step-2-set-up-packaging-for-your-project)
|
|
|
|
#
|
|
|
|
# we do it here rather than the more conventional way of just adding it to
|
|
|
|
# debian/matrix-synapse-py3.triggers, because we need to add a trigger on the
|
|
|
|
# right version of python.
|
|
|
|
cat >>"debian/.debhelper/generated/matrix-synapse-py3/triggers" <<EOF
|
|
|
|
# triggers for dh-virtualenv
|
|
|
|
interest-noawait $SNAKE
|
|
|
|
interest dh-virtualenv-interpreter-update
|
|
|
|
|
|
|
|
EOF
|