|
3 | 3 | set -eu |
4 | 4 |
|
5 | 5 | WATCHMAN_VERSION="${WATCHMAN_VERSION:-v2026.05.04.00}" |
6 | | -DOWNLOAD_URL="${WATCHMAN_DOWNLOAD_URL:-https://github.com/facebook/watchman/releases/download/${WATCHMAN_VERSION}/watchman-${WATCHMAN_VERSION}-linux.zip}" |
| 6 | +ARCH="$(uname -m)" |
| 7 | +SOURCE_URL="${WATCHMAN_SOURCE_URL:-https://github.com/facebook/watchman/archive/refs/tags/${WATCHMAN_VERSION}.tar.gz}" |
| 8 | + |
| 9 | +if [ -n "${WATCHMAN_DOWNLOAD_URL:-}" ]; then |
| 10 | + INSTALL_METHOD="archive" |
| 11 | + DOWNLOAD_URL="$WATCHMAN_DOWNLOAD_URL" |
| 12 | +else |
| 13 | + case "$ARCH" in |
| 14 | + x86_64|amd64) |
| 15 | + INSTALL_METHOD="archive" |
| 16 | + DOWNLOAD_URL="https://github.com/facebook/watchman/releases/download/${WATCHMAN_VERSION}/watchman-${WATCHMAN_VERSION}-linux.zip" |
| 17 | + ;; |
| 18 | + aarch64|arm64) |
| 19 | + INSTALL_METHOD="source" |
| 20 | + ;; |
| 21 | + *) |
| 22 | + echo "Error: unsupported architecture ${ARCH}." |
| 23 | + echo "Set WATCHMAN_DOWNLOAD_URL to a compatible archive if you need Watchman in this container." |
| 24 | + exit 1 |
| 25 | + ;; |
| 26 | + esac |
| 27 | +fi |
| 28 | + |
7 | 29 | TMPDIR=$(mktemp -d) |
8 | 30 | ARCHIVE_PATH="$TMPDIR/watchman.zip" |
9 | | -EXTRACT_DIR="$TMPDIR/watchman-${WATCHMAN_VERSION}-linux" |
| 31 | +SOURCE_ARCHIVE_PATH="$TMPDIR/watchman.tar.gz" |
10 | 32 |
|
11 | 33 | cleanup() { |
12 | 34 | rm -rf "$TMPDIR" |
13 | 35 | } |
14 | 36 |
|
15 | 37 | trap cleanup EXIT |
16 | 38 |
|
| 39 | +setup_runtime_dir() { |
| 40 | + install -d /usr/local/var/run/watchman |
| 41 | + chmod 2777 /usr/local/var/run/watchman |
| 42 | +} |
| 43 | + |
| 44 | +if [ "$INSTALL_METHOD" = "source" ]; then |
| 45 | + echo "Building Watchman ${WATCHMAN_VERSION} from source for ${ARCH}" |
| 46 | + apt-get update |
| 47 | + DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ |
| 48 | + bash \ |
| 49 | + ca-certificates \ |
| 50 | + cargo \ |
| 51 | + git \ |
| 52 | + python3 \ |
| 53 | + python3-pip |
| 54 | + |
| 55 | + if ! command -v pip >/dev/null 2>&1 && command -v pip3 >/dev/null 2>&1; then |
| 56 | + ln -s "$(command -v pip3)" /usr/local/bin/pip |
| 57 | + fi |
| 58 | + |
| 59 | + curl -fsSL "$SOURCE_URL" -o "$SOURCE_ARCHIVE_PATH" |
| 60 | + tar -xzf "$SOURCE_ARCHIVE_PATH" -C "$TMPDIR" |
| 61 | + |
| 62 | + SOURCE_DIR="$(find "$TMPDIR" -mindepth 1 -maxdepth 1 -type d -name 'watchman-*' | head -n 1 || true)" |
| 63 | + |
| 64 | + if [ -z "$SOURCE_DIR" ]; then |
| 65 | + echo "Error: Watchman source archive did not contain the expected directory" |
| 66 | + exit 1 |
| 67 | + fi |
| 68 | + |
| 69 | + cd "$SOURCE_DIR" |
| 70 | + PIP_BREAK_SYSTEM_PACKAGES=1 python3 build/fbcode_builder/getdeps.py --allow-system-packages install-system-deps --recursive watchman |
| 71 | + PREFIX=/usr/local ./autogen.sh |
| 72 | + |
| 73 | + if [ ! -x built/bin/watchman ] || [ ! -x built/bin/watchmanctl ]; then |
| 74 | + echo "Error: Watchman source build did not produce the expected binaries" |
| 75 | + exit 1 |
| 76 | + fi |
| 77 | + |
| 78 | + install -d /usr/local/bin |
| 79 | + install built/bin/watchman /usr/local/bin/watchman |
| 80 | + install built/bin/watchmanctl /usr/local/bin/watchmanctl |
| 81 | + setup_runtime_dir |
| 82 | + |
| 83 | + if [ -d built/lib ] && find built/lib -mindepth 1 -maxdepth 1 | read -r _; then |
| 84 | + install -d /usr/local/lib |
| 85 | + cp -a built/lib/. /usr/local/lib/ |
| 86 | + fi |
| 87 | + |
| 88 | + if command -v ldconfig >/dev/null 2>&1; then |
| 89 | + ldconfig |
| 90 | + fi |
| 91 | + |
| 92 | + exit 0 |
| 93 | +fi |
| 94 | + |
17 | 95 | echo "Downloading Watchman from: $DOWNLOAD_URL" |
18 | 96 | curl -fsSL "$DOWNLOAD_URL" -o "$ARCHIVE_PATH" |
19 | 97 | unzip -q "$ARCHIVE_PATH" -d "$TMPDIR" |
20 | 98 |
|
21 | | -if [ ! -x "$EXTRACT_DIR/bin/watchman" ]; then |
| 99 | +WATCHMAN_BIN="$(find "$TMPDIR" -path '*/bin/watchman' -type f | head -n 1 || true)" |
| 100 | + |
| 101 | +if [ -z "$WATCHMAN_BIN" ]; then |
| 102 | + echo "Error: Watchman archive did not contain the expected binaries" |
| 103 | + exit 1 |
| 104 | +fi |
| 105 | + |
| 106 | +EXTRACT_DIR="${WATCHMAN_BIN%/bin/watchman}" |
| 107 | + |
| 108 | +if [ ! -x "$EXTRACT_DIR/bin/watchman" ] || [ ! -x "$EXTRACT_DIR/bin/watchmanctl" ]; then |
22 | 109 | echo "Error: Watchman archive did not contain the expected binaries" |
23 | 110 | exit 1 |
24 | 111 | fi |
25 | 112 |
|
26 | 113 | install -d /usr/local/bin /usr/local/lib |
27 | 114 | install "$EXTRACT_DIR/bin/watchman" /usr/local/bin/watchman |
28 | 115 | install "$EXTRACT_DIR/bin/watchmanctl" /usr/local/bin/watchmanctl |
| 116 | +setup_runtime_dir |
29 | 117 | cp -a "$EXTRACT_DIR/lib/." /usr/local/lib/ |
30 | 118 |
|
31 | 119 | if command -v ldconfig >/dev/null 2>&1; then |
|
0 commit comments