forked from 1jehuang/jcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall_release.sh
More file actions
executable file
·93 lines (78 loc) · 2.7 KB
/
install_release.sh
File metadata and controls
executable file
·93 lines (78 loc) · 2.7 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
91
92
93
#!/usr/bin/env bash
# Install the current release binary into the immutable version store,
# update the stable + current channel symlinks, and point the launcher at current.
#
# Paths after install:
# - ~/.jcode/builds/versions/<hash>/jcode (immutable)
# - ~/.jcode/builds/stable/jcode -> .../versions/<hash>/jcode
# - ~/.jcode/builds/current/jcode -> .../versions/<hash>/jcode
# - ~/.local/bin/jcode -> ~/.jcode/builds/current/jcode (launcher)
set -euo pipefail
repo_root="$(git rev-parse --show-toplevel 2>/dev/null || pwd)"
profile="${JCODE_RELEASE_PROFILE:-release-lto}"
if [[ "${1:-}" == "--fast" ]]; then
profile="release"
shift
fi
if [[ "$#" -gt 0 ]]; then
echo "Usage: $0 [--fast]" >&2
exit 1
fi
case "$profile" in
release-lto)
echo "Building with LTO (this takes a few minutes)..."
;;
release)
echo "Building fast release profile (no LTO)..."
;;
*)
echo "Unsupported profile: $profile (expected: release or release-lto)" >&2
exit 1
;;
esac
cargo build --profile "$profile" --manifest-path "$repo_root/Cargo.toml"
bin="$repo_root/target/$profile/jcode"
if [[ ! -x "$bin" ]]; then
echo "Release binary not found: $bin" >&2
exit 1
fi
hash=""
if command -v git >/dev/null 2>&1; then
if git -C "$repo_root" rev-parse --git-dir >/dev/null 2>&1; then
hash="$(git -C "$repo_root" rev-parse --short HEAD 2>/dev/null || true)"
if [[ -n "${hash}" ]] && [[ -n "$(git -C "$repo_root" status --porcelain 2>/dev/null || true)" ]]; then
hash="${hash}-dirty"
fi
fi
fi
if [[ -z "$hash" ]]; then
hash="$(date +%Y%m%d%H%M%S)"
fi
# Install versioned binary into ~/.jcode/builds/versions/<hash>/
builds_dir="$HOME/.jcode/builds"
version_dir="$builds_dir/versions/$hash"
mkdir -p "$version_dir"
install -m 755 "$bin" "$version_dir/jcode"
# Update stable symlink
stable_dir="$builds_dir/stable"
mkdir -p "$stable_dir"
ln -sfn "$version_dir/jcode" "$stable_dir/jcode"
# Update stable-version marker
printf '%s\n' "$hash" > "$builds_dir/stable-version"
# Update current symlink + marker
current_dir="$builds_dir/current"
mkdir -p "$current_dir"
ln -sfn "$version_dir/jcode" "$current_dir/jcode"
printf '%s\n' "$hash" > "$builds_dir/current-version"
# Update launcher path to current channel
install_dir="${JCODE_INSTALL_DIR:-$HOME/.local/bin}"
mkdir -p "$install_dir"
ln -sfn "$current_dir/jcode" "$install_dir/jcode"
echo "Installed: $version_dir/jcode"
echo "Updated stable symlink: $stable_dir/jcode -> $version_dir/jcode"
echo "Updated current symlink: $current_dir/jcode -> $version_dir/jcode"
echo "Updated launcher symlink: $install_dir/jcode -> $current_dir/jcode"
if ! echo "$PATH" | tr ':' '\n' | grep -qx "$install_dir"; then
echo ""
echo "Tip: add $install_dir to PATH if needed."
fi