Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/scripts/code.sh
3520 views
1
#!/usr/bin/env bash
2
3
set -e
4
5
if [[ "$OSTYPE" == "darwin"* ]]; then
6
realpath() { [[ $1 = /* ]] && echo "$1" || echo "$PWD/${1#./}"; }
7
ROOT=$(dirname "$(dirname "$(realpath "$0")")")
8
else
9
ROOT=$(dirname "$(dirname "$(readlink -f $0)")")
10
# If the script is running in Docker using the WSL2 engine, powershell.exe won't exist
11
if grep -qi Microsoft /proc/version && type powershell.exe > /dev/null 2>&1; then
12
IN_WSL=true
13
fi
14
fi
15
16
function code() {
17
cd "$ROOT"
18
19
if [[ "$OSTYPE" == "darwin"* ]]; then
20
NAME=`node -p "require('./product.json').nameLong"`
21
CODE="./.build/electron/$NAME.app/Contents/MacOS/Electron"
22
else
23
NAME=`node -p "require('./product.json').applicationName"`
24
CODE=".build/electron/$NAME"
25
fi
26
27
# Get electron, compile, built-in extensions
28
if [[ -z "${VSCODE_SKIP_PRELAUNCH}" ]]; then
29
node build/lib/preLaunch.js
30
fi
31
32
# Manage built-in extensions
33
if [[ "$1" == "--builtin" ]]; then
34
exec "$CODE" build/builtin
35
return
36
fi
37
38
# Configuration
39
export NODE_ENV=development
40
export VSCODE_DEV=1
41
export VSCODE_CLI=1
42
export ELECTRON_ENABLE_STACK_DUMPING=1
43
export ELECTRON_ENABLE_LOGGING=1
44
45
DISABLE_TEST_EXTENSION="--disable-extension=vscode.vscode-api-tests"
46
if [[ "$@" == *"--extensionTestsPath"* ]]; then
47
DISABLE_TEST_EXTENSION=""
48
fi
49
50
# Launch Code
51
exec "$CODE" . $DISABLE_TEST_EXTENSION "$@"
52
}
53
54
function code-wsl()
55
{
56
HOST_IP=$(echo "" | powershell.exe -noprofile -Command "& {(Get-NetIPAddress | Where-Object {\$_.InterfaceAlias -like '*WSL*' -and \$_.AddressFamily -eq 'IPv4'}).IPAddress | Write-Host -NoNewline}")
57
export DISPLAY="$HOST_IP:0"
58
59
# in a wsl shell
60
ELECTRON="$ROOT/.build/electron/Code - OSS.exe"
61
if [ -f "$ELECTRON" ]; then
62
local CWD=$(pwd)
63
cd $ROOT
64
export WSLENV=ELECTRON_RUN_AS_NODE/w:VSCODE_DEV/w:$WSLENV
65
local WSL_EXT_ID="ms-vscode-remote.remote-wsl"
66
local WSL_EXT_WLOC=$(echo "" | VSCODE_DEV=1 ELECTRON_RUN_AS_NODE=1 "$ROOT/.build/electron/Code - OSS.exe" "out/cli.js" --locate-extension $WSL_EXT_ID)
67
cd $CWD
68
if [ -n "$WSL_EXT_WLOC" ]; then
69
# replace \r\n with \n in WSL_EXT_WLOC
70
local WSL_CODE=$(wslpath -u "${WSL_EXT_WLOC%%[[:cntrl:]]}")/scripts/wslCode-dev.sh
71
$WSL_CODE "$ROOT" "$@"
72
exit $?
73
else
74
echo "Remote WSL not installed, trying to run VSCode in WSL."
75
fi
76
fi
77
}
78
79
if [ "$IN_WSL" == "true" ] && [ -z "$DISPLAY" ]; then
80
code-wsl "$@"
81
elif [ -f /mnt/wslg/versions.txt ]; then
82
code --disable-gpu "$@"
83
elif [ -f /.dockerenv ]; then
84
# Workaround for https://bugs.chromium.org/p/chromium/issues/detail?id=1263267
85
# Chromium does not release shared memory when streaming scripts
86
# which might exhaust the available resources in the container environment
87
# leading to failed script loading.
88
code --disable-dev-shm-usage "$@"
89
else
90
code "$@"
91
fi
92
93
exit $?
94
95