@@ -53,6 +53,12 @@ Run the complement test suite on Synapse.
5353 Only build the Docker images. Don't actually run Complement.
5454 Conflicts with -f/--fast.
5555
56+ -e, --editable
57+ Use an editable build of Synapse, rebuilding the image if necessary.
58+ This is suitable for use in development where a fast turn-around time
59+ is important.
60+ Not suitable for use in CI in case the editable environment is impure.
61+
5662For help on arguments to 'go test', run 'go help testflag'.
5763EOF
5864}
@@ -73,6 +79,9 @@ while [ $# -ge 1 ]; do
7379 " --build-only" )
7480 skip_complement_run=1
7581 ;;
82+ " -e" |" --editable" )
83+ use_editable_synapse=1
84+ ;;
7685 * )
7786 # unknown arg: presumably an argument to gotest. break the loop.
7887 break
@@ -96,25 +105,76 @@ if [[ -z "$COMPLEMENT_DIR" ]]; then
96105 echo " Checkout available at 'complement-${COMPLEMENT_REF} '"
97106fi
98107
108+ if [ -n " $use_editable_synapse " ]; then
109+ if [[ -e synapse/synapse_rust.abi3.so ]]; then
110+ # In an editable install, back up the host's compiled Rust module to prevent
111+ # inconvenience; the container will overwrite the module with its own copy.
112+ mv -n synapse/synapse_rust.abi3.so synapse/synapse_rust.abi3.so~host
113+ # And restore it on exit:
114+ synapse_pkg=` realpath synapse`
115+ trap " mv -f '$synapse_pkg /synapse_rust.abi3.so~host' '$synapse_pkg /synapse_rust.abi3.so'" EXIT
116+ fi
117+
118+ editable_mount=" $( realpath .) :/editable-src:z"
119+ if docker inspect complement-synapse-editable & > /dev/null; then
120+ # complement-synapse-editable already exists: see if we can still use it:
121+ # - The Rust module must still be importable; it will fail to import if the Rust source has changed.
122+ # - The Poetry lock file must be the same (otherwise we assume dependencies have changed)
123+
124+ # First set up the module in the right place for an editable installation.
125+ docker run --rm -v $editable_mount --entrypoint ' cp' complement-synapse-editable -- /synapse_rust.abi3.so.bak /editable-src/synapse/synapse_rust.abi3.so
126+
127+ if (docker run --rm -v $editable_mount --entrypoint ' python' complement-synapse-editable -c ' import synapse.synapse_rust' \
128+ && docker run --rm -v $editable_mount --entrypoint ' diff' complement-synapse-editable --brief /editable-src/poetry.lock /poetry.lock.bak); then
129+ skip_docker_build=1
130+ else
131+ echo " Editable Synapse image is stale. Will rebuild."
132+ unset skip_docker_build
133+ fi
134+ fi
135+ fi
136+
99137if [ -z " $skip_docker_build " ]; then
100- # Build the base Synapse image from the local checkout
101- echo_if_github " ::group::Build Docker image: matrixdotorg/synapse"
102- docker build -t matrixdotorg/synapse \
103- --build-arg TEST_ONLY_SKIP_DEP_HASH_VERIFICATION \
104- --build-arg TEST_ONLY_IGNORE_POETRY_LOCKFILE \
105- -f " docker/Dockerfile" .
106- echo_if_github " ::endgroup::"
107-
108- # Build the workers docker image (from the base Synapse image we just built).
109- echo_if_github " ::group::Build Docker image: matrixdotorg/synapse-workers"
110- docker build -t matrixdotorg/synapse-workers -f " docker/Dockerfile-workers" .
111- echo_if_github " ::endgroup::"
112-
113- # Build the unified Complement image (from the worker Synapse image we just built).
114- echo_if_github " ::group::Build Docker image: complement/Dockerfile"
115- docker build -t complement-synapse \
116- -f " docker/complement/Dockerfile" " docker/complement"
117- echo_if_github " ::endgroup::"
138+ if [ -n " $use_editable_synapse " ]; then
139+
140+ # Build a special image designed for use in development with editable
141+ # installs.
142+ docker build -t synapse-editable \
143+ -f " docker/editable.Dockerfile" .
144+
145+ docker build -t synapse-workers-editable \
146+ --build-arg FROM=synapse-editable \
147+ -f " docker/Dockerfile-workers" .
148+
149+ docker build -t complement-synapse-editable \
150+ --build-arg FROM=synapse-workers-editable \
151+ -f " docker/complement/Dockerfile" " docker/complement"
152+
153+ # Prepare the Rust module
154+ docker run --rm -v $editable_mount --entrypoint ' cp' complement-synapse-editable -- /synapse_rust.abi3.so.bak /editable-src/synapse/synapse_rust.abi3.so
155+
156+ else
157+
158+ # Build the base Synapse image from the local checkout
159+ echo_if_github " ::group::Build Docker image: matrixdotorg/synapse"
160+ docker build -t matrixdotorg/synapse \
161+ --build-arg TEST_ONLY_SKIP_DEP_HASH_VERIFICATION \
162+ --build-arg TEST_ONLY_IGNORE_POETRY_LOCKFILE \
163+ -f " docker/Dockerfile" .
164+ echo_if_github " ::endgroup::"
165+
166+ # Build the workers docker image (from the base Synapse image we just built).
167+ echo_if_github " ::group::Build Docker image: matrixdotorg/synapse-workers"
168+ docker build -t matrixdotorg/synapse-workers -f " docker/Dockerfile-workers" .
169+ echo_if_github " ::endgroup::"
170+
171+ # Build the unified Complement image (from the worker Synapse image we just built).
172+ echo_if_github " ::group::Build Docker image: complement/Dockerfile"
173+ docker build -t complement-synapse \
174+ -f " docker/complement/Dockerfile" " docker/complement"
175+ echo_if_github " ::endgroup::"
176+
177+ fi
118178fi
119179
120180if [ -n " $skip_complement_run " ]; then
@@ -123,6 +183,10 @@ if [ -n "$skip_complement_run" ]; then
123183fi
124184
125185export COMPLEMENT_BASE_IMAGE=complement-synapse
186+ if [ -n " $use_editable_synapse " ]; then
187+ export COMPLEMENT_BASE_IMAGE=complement-synapse-editable
188+ export COMPLEMENT_HOST_MOUNTS=" $editable_mount "
189+ fi
126190
127191extra_test_args=()
128192
0 commit comments