Mercurial
comparison hg-web/dev.sh @ 222:a8d6435dc021 hg-web
[hg-web] Run local stack through Bazel
| author | MrJuneJune <me@mrjunejune.com> |
|---|---|
| date | Sun, 02 Aug 2026 09:07:36 -0700 |
| parents | |
| children | c5129452493e |
comparison
equal
deleted
inserted
replaced
| 221:ce7f4400c2de | 222:a8d6435dc021 |
|---|---|
| 1 #!/usr/bin/env bash | |
| 2 set -euo pipefail | |
| 3 | |
| 4 if [[ -n "${RUNFILES_DIR:-}" ]]; then | |
| 5 source "$RUNFILES_DIR/bazel_tools/tools/bash/runfiles/runfiles.bash" | |
| 6 elif [[ -n "${RUNFILES_MANIFEST_FILE:-}" ]]; then | |
| 7 runfiles_library="$( | |
| 8 grep -sm1 '^bazel_tools/tools/bash/runfiles/runfiles.bash ' \ | |
| 9 "$RUNFILES_MANIFEST_FILE" | cut -d' ' -f2- | |
| 10 )" | |
| 11 source "$runfiles_library" | |
| 12 elif [[ -d "$0.runfiles" ]]; then | |
| 13 RUNFILES_DIR="$0.runfiles" | |
| 14 export RUNFILES_DIR | |
| 15 source "$RUNFILES_DIR/bazel_tools/tools/bash/runfiles/runfiles.bash" | |
| 16 elif [[ -f "$0.runfiles_manifest" ]]; then | |
| 17 RUNFILES_MANIFEST_FILE="$0.runfiles_manifest" | |
| 18 export RUNFILES_MANIFEST_FILE | |
| 19 runfiles_library="$( | |
| 20 grep -sm1 '^bazel_tools/tools/bash/runfiles/runfiles.bash ' \ | |
| 21 "$RUNFILES_MANIFEST_FILE" | cut -d' ' -f2- | |
| 22 )" | |
| 23 source "$runfiles_library" | |
| 24 else | |
| 25 echo "Bazel runfiles are unavailable." >&2 | |
| 26 exit 1 | |
| 27 fi | |
| 28 | |
| 29 workspace="${BUILD_WORKSPACE_DIRECTORY:-}" | |
| 30 if [[ -z "$workspace" || ! -d "$workspace/.hg" ]]; then | |
| 31 echo "Run this target from the Zenbu workspace." >&2 | |
| 32 exit 1 | |
| 33 fi | |
| 34 | |
| 35 server="$(rlocation _main/hg-web/hg_web_server)" | |
| 36 runfiles_workspace="$(dirname "$(dirname "$server")")" | |
| 37 hg_pid="" | |
| 38 server_pid="" | |
| 39 | |
| 40 cleanup() { | |
| 41 trap - EXIT INT TERM | |
| 42 for pid in "$server_pid" "$hg_pid"; do | |
| 43 if [[ -n "$pid" ]] && kill -0 "$pid" 2>/dev/null; then | |
| 44 kill "$pid" 2>/dev/null || true | |
| 45 fi | |
| 46 done | |
| 47 for pid in "$server_pid" "$hg_pid"; do | |
| 48 if [[ -n "$pid" ]]; then | |
| 49 wait "$pid" 2>/dev/null || true | |
| 50 fi | |
| 51 done | |
| 52 } | |
| 53 | |
| 54 trap cleanup EXIT | |
| 55 trap 'exit 130' INT TERM | |
| 56 | |
| 57 hg --repository "$workspace" serve \ | |
| 58 --address 127.0.0.1 \ | |
| 59 --port 4444 \ | |
| 60 --accesslog - \ | |
| 61 --errorlog - & | |
| 62 hg_pid=$! | |
| 63 | |
| 64 ( | |
| 65 cd "$runfiles_workspace" | |
| 66 exec "$server" | |
| 67 ) & | |
| 68 server_pid=$! | |
| 69 | |
| 70 echo "hg-web: http://127.0.0.1:6970" | |
| 71 echo "Mercurial wire endpoint: http://127.0.0.1:6970/repo" | |
| 72 echo "Press Ctrl-C to stop both servers." | |
| 73 | |
| 74 set +e | |
| 75 wait -n "$hg_pid" "$server_pid" | |
| 76 status=$? | |
| 77 set -e | |
| 78 exit "$status" |