Skip to content

Commit ba4306f

Browse files
committed
Symlink scripts on post-install and release
1 parent 9e70fe8 commit ba4306f

File tree

3 files changed

+102
-58
lines changed

3 files changed

+102
-58
lines changed

ci/build/build-standalone-release.sh

+7-1
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,14 @@ main() {
2727
ln -s "./bin/code-server" "$RELEASE_PATH/code-server"
2828
ln -s "./lib/node" "$RELEASE_PATH/node"
2929

30-
cd "$RELEASE_PATH"
30+
pushd "$RELEASE_PATH"
3131
yarn --production --frozen-lockfile
32+
popd
33+
34+
pushd "$RELEASE_PATH/lib/vscode"
35+
symlink_bin_script remote-cli/code remote-cli/code-server
36+
symlink_bin_script helpers/browser helpers/browser .sh
37+
popd
3238
}
3339

3440
main "$@"

ci/build/npm-postinstall.sh

+50-26
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,57 @@
11
#!/usr/bin/env sh
22
set -eu
33

4-
# Copied from arch() in ci/lib.sh.
5-
detect_arch() {
6-
case "$(uname -m)" in
7-
aarch64)
8-
echo arm64
9-
;;
10-
x86_64 | amd64)
11-
echo amd64
12-
;;
13-
*)
14-
# This will cause the download to fail, but is intentional
15-
uname -m
16-
;;
4+
# Copied from ../lib.sh. Look there for details.
5+
arch() {
6+
cpu="$(uname -m)"
7+
case "$cpu" in
8+
aarch64) cpu=arm64 ;;
9+
x86_64 | amd64) cpu=amd64 ;;
1710
esac
11+
echo "$cpu"
1812
}
1913

20-
ARCH="${NPM_CONFIG_ARCH:-$(detect_arch)}"
14+
# Copied from ../lib.sh except we do not rename Darwin since the cloud agent
15+
# uses "darwin" in the release names and we do not need to detect Alpine.
16+
os() {
17+
osname=$(uname | tr '[:upper:]' '[:lower:]')
18+
case $osname in
19+
cygwin* | mingw*) osname="windows" ;;
20+
esac
21+
echo "$osname"
22+
}
23+
24+
# Copied from ../lib.sh. Look there for details.
25+
symlink() {
26+
source="$1"
27+
dest="$2"
28+
rm -rf "$dest"
29+
case $OS in
30+
windows) mklink /J "$dest" "$source" ;;
31+
*) ln -s "$source" "$dest" ;;
32+
esac
33+
}
34+
35+
# Copied from ../lib.sh. Look there for details.
36+
symlink_asar() {
37+
symlink node_modules node_modules.asar
38+
}
39+
40+
# Copied from ../lib.sh. Look there for more details.
41+
symlink_bin_script() {
42+
source="$1"
43+
dest="$2"
44+
ext="${1-}"
45+
case $OS in
46+
windows) symlink "$source.cmd" "$dest.cmd" ;;
47+
darwin | macos) symlink "$source-darwin.sh" "$dest$ext" ;;
48+
*) symlink "$source-linux.sh" "$dest$ext" ;;
49+
esac
50+
}
51+
52+
ARCH="${NPM_CONFIG_ARCH:-$(arch)}"
53+
OS="$(os)"
54+
2155
# This is due to an upstream issue with RHEL7/CentOS 7 comptability with node-argon2
2256
# See: https://github.com/cdr/code-server/pull/3422#pullrequestreview-677765057
2357
export npm_config_build_from_source=true
@@ -56,8 +90,6 @@ main() {
5690
;;
5791
esac
5892

59-
OS="$(uname | tr '[:upper:]' '[:lower:]')"
60-
6193
mkdir -p ./lib
6294

6395
if curl -fsSL "https://github.com/coder/cloud-agent/releases/latest/download/cloud-agent-$OS-$ARCH" -o ./lib/coder-cloud-agent; then
@@ -79,22 +111,14 @@ main() {
79111
fi
80112
}
81113

82-
# This is a copy of symlink_asar in ../lib.sh. Look there for details.
83-
symlink_asar() {
84-
rm -rf node_modules.asar
85-
if [ "${WINDIR-}" ]; then
86-
mklink /J node_modules.asar node_modules
87-
else
88-
ln -s node_modules node_modules.asar
89-
fi
90-
}
91-
92114
vscode_yarn() {
93115
echo 'Installing Code dependencies...'
94116
cd lib/vscode
95117
yarn --production --frozen-lockfile --no-default-rc
96118

97119
symlink_asar
120+
symlink_bin_script remote-cli/code remote-cli/code-server
121+
symlink_bin_script helpers/browser helpers/browser .sh
98122

99123
cd extensions
100124
yarn --production --frozen-lockfile

ci/lib.sh

+45-31
Original file line numberDiff line numberDiff line change
@@ -18,35 +18,30 @@ vscode_version() {
1818
}
1919

2020
os() {
21-
local os
22-
os=$(uname | tr '[:upper:]' '[:lower:]')
23-
if [[ $os == "linux" ]]; then
24-
# Alpine's ldd doesn't have a version flag but if you use an invalid flag
25-
# (like --version) it outputs the version to stderr and exits with 1.
26-
local ldd_output
27-
ldd_output=$(ldd --version 2>&1 || true)
28-
if echo "$ldd_output" | grep -iq musl; then
29-
os="alpine"
30-
fi
31-
elif [[ $os == "darwin" ]]; then
32-
os="macos"
33-
fi
34-
echo "$os"
21+
osname=$(uname | tr '[:upper:]' '[:lower:]')
22+
case $osname in
23+
linux)
24+
# Alpine's ldd doesn't have a version flag but if you use an invalid flag
25+
# (like --version) it outputs the version to stderr and exits with 1.
26+
# TODO: Better to check /etc/os-release; see ../install.sh.
27+
ldd_output=$(ldd --version 2>&1 || true)
28+
if echo "$ldd_output" | grep -iq musl; then
29+
osname="alpine"
30+
fi
31+
;;
32+
darwin) osname="macos" ;;
33+
cygwin* | mingw*) osname="windows" ;;
34+
esac
35+
echo "$osname"
3536
}
3637

3738
arch() {
3839
cpu="$(uname -m)"
3940
case "$cpu" in
40-
aarch64)
41-
echo arm64
42-
;;
43-
x86_64 | amd64)
44-
echo amd64
45-
;;
46-
*)
47-
echo "$cpu"
48-
;;
41+
aarch64) cpu=arm64 ;;
42+
x86_64 | amd64) cpu=amd64 ;;
4943
esac
44+
echo "$cpu"
5045
}
5146

5247
# Grabs the most recent ci.yaml github workflow run that was triggered from the
@@ -105,6 +100,18 @@ export OS
105100
# Defaults to release
106101
RELEASE_PATH="${RELEASE_PATH-release}"
107102

103+
# Create a symlink at $2 pointing to $1 on any platform. Anything that
104+
# currently exists at $2 will be deleted.
105+
symlink() {
106+
source="$1"
107+
dest="$2"
108+
rm -rf "$dest"
109+
case $OS in
110+
windows) mklink /J "$dest" "$source" ;;
111+
*) ln -s "$source" "$dest" ;;
112+
esac
113+
}
114+
108115
# VS Code bundles some modules into an asar which is an archive format that
109116
# works like tar. It then seems to get unpacked into node_modules.asar.
110117
#
@@ -113,12 +120,19 @@ RELEASE_PATH="${RELEASE_PATH-release}"
113120
# Code itself but also extensions will look specifically in this directory for
114121
# files (like the ripgrep binary or the oniguruma wasm).
115122
symlink_asar() {
116-
rm -rf node_modules.asar
117-
if [ "${WINDIR-}" ]; then
118-
# mklink takes the link name first.
119-
mklink /J node_modules.asar node_modules
120-
else
121-
# ln takes the link name second.
122-
ln -s node_modules node_modules.asar
123-
fi
123+
symlink node_modules node_modules.asar
124+
}
125+
126+
# Symlink the correct bin script from $source to $dest depending on the
127+
# platform. The extension will be .cmd for Windows otherwise it will be
128+
# whatever is in $3 if it exists.
129+
symlink_bin_script() {
130+
source="$1"
131+
dest="$2"
132+
ext="${1-}"
133+
case $OS in
134+
windows) symlink "$source.cmd" "$dest.cmd" ;;
135+
darwin | macos) symlink "$source-darwin.sh" "$dest$ext" ;;
136+
*) symlink "$source-linux.sh" "$dest$ext" ;;
137+
esac
124138
}

0 commit comments

Comments
 (0)