Repository navigation
Expand file tree
/
Copy pathbootstrap.sh
More file actions
90 lines (81 loc) · 3.82 KB
/
Copy pathbootstrap.sh
File metadata and controls
90 lines (81 loc) · 3.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/env bash
# Checks and installs what Linux needs before scripts/bootstrap.py can run, then runs it. bootstrap.py installs
# llvm-mingw and vcpkg into the checkout and configures the build. It builds nothing; the last lines say how.
#
# 1. Installs the missing host packages with apt (Debian/Ubuntu) or dnf (Fedora): git, curl, python3, ninja,
# and vcpkg's zip/unzip/pkg-config. CMake is pinned in scripts/cmake.version and installed by bootstrap.py.
# 2. Runs scripts/bootstrap.py.
#
# Run it from anywhere: bash bootstrap.sh
set -euo pipefail
if [ "$(uname -s)" != "Linux" ]; then
echo "bootstrap.sh is for Linux. On Windows run bootstrap.bat instead." >&2
exit 1
fi
REPO_ROOT=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)
cd "$REPO_ROOT"
# Everything this script prints also goes to a timestamped log, which bootstrap.py then appends to.
mkdir -p logs
BOOTSTRAP_LOG="${REPO_ROOT}/logs/bootstrap-$(date +%Y%m%d-%H%M%S).log"
exec 3>&1 4>&2
exec > >(tee -a "$BOOTSTRAP_LOG") 2>&1
echo "bootstrap log: ${BOOTSTRAP_LOG}"
log() { echo "==> $*"; }
die() { echo "bootstrap: $*" >&2; exit 1; }
# A running CLion or Rider rewrites its .idea files on exit, which would undo what the bootstrap writes there. A Flatpak
# IDE's sandbox is a bwrap process whose descendants are the IDE. After the IDE closes, only the JetBrains daemon can be
# left behind, so a sandbox counts as running only when it has a descendant other than that daemon.
ide_sandbox_busy() {
local child
for child in $(pgrep -P "$1" 2>/dev/null); do
if [ "$(ps -o comm= -p "$child")" != "jetbrainsd" ] || ide_sandbox_busy "$child"; then
return 0
fi
done
return 1
}
running_ides=""
for sandbox in $(pgrep -f 'bwrap .*-- (rider-wrapper|clion)( |$)' 2>/dev/null); do
if ide_sandbox_busy "$sandbox"; then
running_ides="$running_ides $sandbox"
fi
done
if pgrep -x clion >/dev/null 2>&1 || pgrep -x rider >/dev/null 2>&1 || [ -n "$running_ides" ]; then
die "CLion or Rider is running (${running_ides:-native}). Close it and re-run, so it does not overwrite the .idea files."
fi
# The IDEs run CMake on the host through flatpak-spawn, so closing or killing the IDE does not stop a reload that is
# under way; it keeps writing into build/ and would race the bootstrap's configure.
if pgrep -f -- "${REPO_ROOT}/build/" >/dev/null 2>&1; then
die "A CMake run started by an IDE is still using this checkout's build/. Wait for it to finish, then re-run."
fi
APT_PACKAGES=(git curl tar xz-utils python3 ninja-build zip unzip pkg-config)
DNF_PACKAGES=(git curl tar xz python3 ninja-build zip unzip pkgconf-pkg-config)
if command -v dpkg-query >/dev/null 2>&1; then
missing=()
for pkg in "${APT_PACKAGES[@]}"; do
dpkg-query -W -f='${Status}' "$pkg" 2>/dev/null | grep -q "install ok installed" || missing+=("$pkg")
done
if [ "${#missing[@]}" -eq 0 ]; then
log "host packages already present"
else
log "installing missing packages with apt: ${missing[*]}"
sudo apt-get update
sudo apt-get install -y --no-install-recommends "${missing[@]}"
fi
elif command -v dnf >/dev/null 2>&1; then
missing=()
for pkg in "${DNF_PACKAGES[@]}"; do
rpm -q "$pkg" >/dev/null 2>&1 || missing+=("$pkg")
done
if [ "${#missing[@]}" -eq 0 ]; then
log "host packages already present"
else
log "installing missing packages with dnf: ${missing[*]}"
sudo dnf install -y "${missing[@]}"
fi
else
die "this script installs packages with apt or dnf; on another distro install the equivalents of: ${APT_PACKAGES[*]}, then run python3 scripts/bootstrap.py"
fi
python3 "${REPO_ROOT}/scripts/require_python.py" >/dev/null || die "install a newer python3, then re-run"
exec 1>&3 2>&4 3>&- 4>&-
exec python3 "${REPO_ROOT}/scripts/bootstrap.py" --log "$BOOTSTRAP_LOG"