diff --git a/docker/README.md b/docker/README.md index 150489f5..733d930b 100644 --- a/docker/README.md +++ b/docker/README.md @@ -154,3 +154,11 @@ docker run --rm -it \ -v unittesting-home:/root \ unittesting-local run_tests --tests-dir tests --pattern test_example.py ``` + +## ARM hosts (Apple Silicon, arm64 Linux) + +On an ARM host, the launcher builds and runs a native arm64 image. The +container installs the arm64 build of Sublime Text 4. + +Runs under amd64 emulation (for example `DOCKER_DEFAULT_PLATFORM=linux/amd64`) +are not supported. diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index 27f260b3..07f8f11e 100644 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -1,6 +1,7 @@ #!/bin/bash echo PACKAGE = $PACKAGE +echo ARCHITECTURE = $(uname -m) set -e @@ -84,6 +85,37 @@ write_package_dependency_marker() { printf '%s\n' "$dependency_fingerprint" > "$DEPENDENCY_MARKER_DIR/$PACKAGE.sha256" } +ensure_sublime_text_arch_matches() { + # A cache volume created on a different architecture holds a Sublime Text + # binary that cannot run here, and the bootstrap marker skips reinstall. + local binary="$HOME/sublime_text/sublime_text" + [ -f "$binary" ] || return 0 + + local expected + case "$(uname -m)" in + x86_64) expected=3e ;; + aarch64) expected=b7 ;; + *) return 0 ;; + esac + + # e_machine field of the ELF header (low byte, little-endian). + local actual + actual=$(od -An -tx1 -j18 -N1 "$binary" | tr -d ' \n') + if [ "$actual" != "$expected" ]; then + local found + case "$actual" in + 3e) found=x86_64 ;; + b7) found=aarch64 ;; + *) found="unknown (ELF machine 0x$actual)" ;; + esac + echo "Error: the cache volume has a Sublime Text build for $found," >&2 + echo "but this container runs on $(uname -m)." >&2 + echo "Run ut-run-tests with --refresh-cache, or use a different cache volume." >&2 + exit 1 + fi +} + +ensure_sublime_text_arch_matches sudo sh -e /etc/init.d/xvfb start ensure_git_identity ensure_ci_platform_compat diff --git a/docker/ut-run-tests b/docker/ut-run-tests old mode 100644 new mode 100755 index 6a857f7f..eb467e75 --- a/docker/ut-run-tests +++ b/docker/ut-run-tests @@ -2,4 +2,5 @@ set -euo pipefail SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)" -exec python "$SCRIPT_DIR/run_tests.py" "$@" +PYTHON="$(command -v python3 || command -v python)" +exec "$PYTHON" "$SCRIPT_DIR/run_tests.py" "$@" diff --git a/sbin/install_sublime_text.sh b/sbin/install_sublime_text.sh index 604786b1..5341a718 100644 --- a/sbin/install_sublime_text.sh +++ b/sbin/install_sublime_text.sh @@ -28,10 +28,13 @@ if [ -z $SUBLIME_TEXT_VERSION ]; then fi if [ -z $SUBLIME_TEXT_ARCH ]; then - SUBLIME_TEXT_ARCH=x64 + case "$(uname -m)" in + aarch64|arm64) SUBLIME_TEXT_ARCH=arm64 ;; + *) SUBLIME_TEXT_ARCH=x64 ;; + esac fi -if [ $SUBLIME_TEXT_VERSION -ge 4 ] && [ "$SUBLIME_TEXT_ARCH" != "x64" ]; then +if [ $SUBLIME_TEXT_VERSION -ge 4 ] && [ "$SUBLIME_TEXT_ARCH" != "x64" ] && [ "$SUBLIME_TEXT_ARCH" != "arm64" ]; then echo "wrong value of $SUBLIME_TEXT_ARCH for Sublime Text version $SUBLIME_TEXT_VERSION" exit 1 fi @@ -132,7 +135,7 @@ else echo "installing sublime text $SUBLIME_TEXT_VERSION" for i in {1..20}; do if [ $SUBLIME_TEXT_VERSION -ge 4 ]; then - URL=$(curl -s "$STWEB" | sed -n 's/.*href="\([^"]*_x64\.tar\.xz\)".*/\1/p') + URL=$(curl -s "$STWEB" | sed -n "s/.*href=\"\([^\"]*_${SUBLIME_TEXT_ARCH}\.tar\.xz\)\".*/\1/p") else if [ "$SUBLIME_TEXT_ARCH" = "x64" ]; then URL=$(curl -s "$STWEB" | sed -n 's/.*href="\([^"]*x64\.tar\.bz2\)".*/\1/p')