2019-07-03 03:10:17 +03:00
|
|
|
#!/bin/bash
|
2019-08-03 03:26:41 +03:00
|
|
|
set -euox pipefail
|
2019-07-03 03:10:17 +03:00
|
|
|
|
|
|
|
function log() {
|
|
|
|
local message="${1}" ; shift
|
|
|
|
local level="${1:-info}"
|
|
|
|
if [[ "${level}" == "error" ]] ; then
|
|
|
|
>&2 echo "${message}"
|
|
|
|
else
|
|
|
|
echo "${message}"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# Copy code-server into VS Code along with its dependencies.
|
|
|
|
function copy-server() {
|
2019-08-03 03:26:41 +03:00
|
|
|
local serverPath="${sourcePath}/src/vs/server"
|
2019-07-03 03:10:17 +03:00
|
|
|
rm -rf "${serverPath}"
|
|
|
|
mkdir -p "${serverPath}"
|
|
|
|
|
2019-07-12 01:12:52 +03:00
|
|
|
cp -r "${rootPath}/src" "${serverPath}"
|
|
|
|
cp -r "${rootPath}/typings" "${serverPath}"
|
|
|
|
cp "${rootPath}/main.js" "${serverPath}"
|
2019-07-03 03:10:17 +03:00
|
|
|
cp "${rootPath}/package.json" "${serverPath}"
|
|
|
|
cp "${rootPath}/yarn.lock" "${serverPath}"
|
|
|
|
|
|
|
|
if [[ -d "${rootPath}/node_modules" ]] ; then
|
|
|
|
cp -r "${rootPath}/node_modules" "${serverPath}"
|
|
|
|
else
|
2019-07-11 00:29:15 +03:00
|
|
|
# Ignore scripts to avoid also installing VS Code dependencies which has
|
|
|
|
# already been done.
|
2019-08-03 03:26:41 +03:00
|
|
|
cd "${serverPath}" && yarn --ignore-scripts
|
2019-07-03 03:10:17 +03:00
|
|
|
rm -r node_modules/@types/node # I keep getting type conflicts
|
|
|
|
fi
|
2019-07-12 01:12:52 +03:00
|
|
|
|
|
|
|
# TODO: Duplicate identifier issue. There must be a better way to fix this.
|
|
|
|
if [[ "${target}" == "darwin" ]] ; then
|
|
|
|
rm "${serverPath}/node_modules/fsevents/node_modules/safe-buffer/index.d.ts"
|
|
|
|
fi
|
2019-07-03 03:10:17 +03:00
|
|
|
}
|
|
|
|
|
2019-07-12 01:12:52 +03:00
|
|
|
# Prepend the nbin shim which enables finding files within the binary.
|
2019-07-05 19:54:04 +03:00
|
|
|
function prepend-loader() {
|
2019-08-03 03:26:41 +03:00
|
|
|
local filePath="${buildPath}/${1}" ; shift
|
2019-07-12 01:12:52 +03:00
|
|
|
cat "${rootPath}/scripts/nbin-shim.js" "${filePath}" > "${filePath}.temp"
|
2019-07-05 19:54:04 +03:00
|
|
|
mv "${filePath}.temp" "${filePath}"
|
|
|
|
# Using : as the delimiter so the escaping here is easier to read.
|
|
|
|
# ${parameter/pattern/string}, so the pattern is /: (if the pattern starts
|
|
|
|
# with / it matches all instances) and the string is \\: (results in \:).
|
2019-07-12 01:12:52 +03:00
|
|
|
if [[ "${target}" == "darwin" ]] ; then
|
2019-08-03 03:26:41 +03:00
|
|
|
sed -i "" -e "s:{{ROOT_PATH}}:${buildPath//:/\\:}:g" "${filePath}"
|
2019-07-12 01:12:52 +03:00
|
|
|
else
|
2019-08-03 03:26:41 +03:00
|
|
|
sed -i "s:{{ROOT_PATH}}:${buildPath//:/\\:}:g" "${filePath}"
|
2019-07-12 01:12:52 +03:00
|
|
|
fi
|
2019-07-05 19:54:04 +03:00
|
|
|
}
|
|
|
|
|
2019-07-03 03:10:17 +03:00
|
|
|
# Copy code-server into VS Code then build it.
|
|
|
|
function build-code-server() {
|
|
|
|
copy-server
|
2019-08-03 03:26:41 +03:00
|
|
|
local min=""
|
|
|
|
if [[ -n "${minify}" ]] ; then
|
|
|
|
min="-min"
|
|
|
|
yarn gulp minify-vscode --max-old-space-size=32384
|
|
|
|
else
|
|
|
|
yarn gulp optimize-vscode --max-old-space-size=32384
|
|
|
|
fi
|
2019-07-03 03:10:17 +03:00
|
|
|
|
2019-08-03 03:26:41 +03:00
|
|
|
rm -rf "${buildPath}"
|
|
|
|
mkdir -p "${buildPath}"
|
2019-07-03 03:10:17 +03:00
|
|
|
|
2019-08-03 03:26:41 +03:00
|
|
|
# Rebuild to make sure native modules work on the target system.
|
|
|
|
cp "${sourcePath}/remote/"{package.json,yarn.lock,.yarnrc} "${buildPath}"
|
|
|
|
cd "${buildPath}" && yarn --production --force --build-from-source
|
|
|
|
rm "${buildPath}/"{package.json,yarn.lock,.yarnrc}
|
2019-07-03 03:10:17 +03:00
|
|
|
|
2019-07-11 02:10:39 +03:00
|
|
|
local json="{\"codeServerVersion\": \"${codeServerVersion}\"}"
|
2019-08-03 03:26:41 +03:00
|
|
|
cp -r "${sourcePath}/.build/extensions" "${buildPath}"
|
|
|
|
node "${rootPath}/scripts/merge.js" "${sourcePath}/package.json" "${rootPath}/scripts/package.json" "${buildPath}/package.json" "${json}"
|
|
|
|
node "${rootPath}/scripts/merge.js" "${sourcePath}/product.json" "${rootPath}/scripts/product.json" "${buildPath}/product.json"
|
|
|
|
cp -r "${sourcePath}/out-vscode${min}" "${buildPath}/out"
|
2019-07-11 02:10:39 +03:00
|
|
|
|
2019-08-03 03:26:41 +03:00
|
|
|
# Only keep production dependencies for the server.
|
|
|
|
cp "${rootPath}/"{package.json,yarn.lock} "${buildPath}/out/vs/server"
|
|
|
|
cd "${buildPath}/out/vs/server" && yarn --production --ignore-scripts
|
|
|
|
rm "${buildPath}/out/vs/server/"{package.json,yarn.lock}
|
2019-07-12 01:12:52 +03:00
|
|
|
|
2019-07-05 19:54:04 +03:00
|
|
|
prepend-loader "out/vs/server/main.js"
|
|
|
|
prepend-loader "out/bootstrap-fork.js"
|
|
|
|
|
2019-08-03 03:26:41 +03:00
|
|
|
log "Final build: ${buildPath}"
|
2019-07-03 03:10:17 +03:00
|
|
|
}
|
|
|
|
|
2019-08-03 03:26:41 +03:00
|
|
|
# Download and extract a tar from a URL with either curl or wget depending on
|
|
|
|
# which is available.
|
|
|
|
function download-tar() {
|
|
|
|
local url="${1}" ; shift
|
2019-07-03 03:10:17 +03:00
|
|
|
if command -v wget &> /dev/null ; then
|
2019-08-03 03:26:41 +03:00
|
|
|
wget "${url}" --quiet -O - | tar -C "${stagingPath}" -xz
|
2019-07-03 03:10:17 +03:00
|
|
|
else
|
2019-08-03 03:26:41 +03:00
|
|
|
curl "${url}" --silent --fail | tar -C "${stagingPath}" -xz
|
2019-07-03 03:10:17 +03:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2019-08-03 03:26:41 +03:00
|
|
|
# Download a pre-built package. If it doesn't exist and we are in the CI, exit.
|
|
|
|
# Otherwise the return will be whether it existed or not. The pre-built package
|
|
|
|
# is provided to reduce CI build time.
|
|
|
|
function download-pre-built() {
|
|
|
|
local archiveName="${1}" ; shift
|
|
|
|
local url="https://codesrv-ci.cdr.sh/${archiveName}"
|
|
|
|
if ! download-tar "${url}" ; then
|
|
|
|
if [[ -n "${ci}" ]] ; then
|
|
|
|
log "${url} does not exist" "error"
|
2019-07-03 03:10:17 +03:00
|
|
|
exit 1
|
|
|
|
fi
|
2019-08-03 03:26:41 +03:00
|
|
|
return 1
|
2019-07-03 03:10:17 +03:00
|
|
|
fi
|
2019-08-03 03:26:41 +03:00
|
|
|
return 0
|
2019-07-03 03:10:17 +03:00
|
|
|
}
|
|
|
|
|
2019-08-03 03:26:41 +03:00
|
|
|
# Fully build code-server.
|
2019-07-03 03:10:17 +03:00
|
|
|
function build-task() {
|
2019-08-03 03:26:41 +03:00
|
|
|
mkdir -p "${stagingPath}"
|
|
|
|
if [[ ! -d "${sourcePath}" ]] ; then
|
|
|
|
if ! download-pre-built "vscode-${vscodeVersion}.tar.gz" ; then
|
|
|
|
git clone https://github.com/microsoft/vscode --quiet \
|
|
|
|
--branch "${vscodeVersion}" --single-branch --depth=1 \
|
|
|
|
"${sourcePath}"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
cd "${sourcePath}"
|
|
|
|
git reset --hard && git clean -fd
|
|
|
|
git apply "${rootPath}/scripts/vscode.patch"
|
|
|
|
if [[ ! -d "${sourcePath}/node_modules" ]] ; then
|
|
|
|
if [[ -n "${ci}" ]] ; then
|
|
|
|
log "Pre-built VS Code ${vscodeVersion} has no node_modules" "error"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
yarn
|
|
|
|
fi
|
|
|
|
if [[ ! -d "${sourcePath}/.build/extensions" ]] ; then
|
|
|
|
if [[ -n "${ci}" ]] ; then
|
|
|
|
log "Pre-built VS Code ${vscodeVersion} has no built extensions" "error"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
yarn gulp extensions-build-package --max-old-space-size=32384
|
|
|
|
fi
|
2019-07-03 03:10:17 +03:00
|
|
|
build-code-server
|
|
|
|
}
|
|
|
|
|
2019-08-03 03:26:41 +03:00
|
|
|
# Package the binary into a tar or zip for release.
|
2019-07-03 03:10:17 +03:00
|
|
|
function package-task() {
|
2019-07-11 02:10:39 +03:00
|
|
|
local archivePath="${releasePath}/${binaryName}"
|
2019-07-03 03:10:17 +03:00
|
|
|
rm -rf "${archivePath}"
|
|
|
|
mkdir -p "${archivePath}"
|
|
|
|
|
2019-07-11 00:29:15 +03:00
|
|
|
cp "${buildPath}/${binaryName}" "${archivePath}/code-server"
|
2019-07-03 03:10:17 +03:00
|
|
|
cp "${rootPath}/README.md" "${archivePath}"
|
2019-08-03 03:26:41 +03:00
|
|
|
cp "${sourcePath}/LICENSE.txt" "${archivePath}"
|
|
|
|
cp "${sourcePath}/ThirdPartyNotices.txt" "${archivePath}"
|
2019-07-03 03:10:17 +03:00
|
|
|
|
|
|
|
cd "${releasePath}"
|
2019-07-12 01:12:52 +03:00
|
|
|
if [[ "${target}" == "darwin" ]] ; then
|
2019-07-11 02:10:39 +03:00
|
|
|
zip -r "${binaryName}.zip" "${binaryName}"
|
2019-07-08 18:33:58 +03:00
|
|
|
log "Archive: ${archivePath}.zip"
|
2019-07-12 01:12:52 +03:00
|
|
|
else
|
|
|
|
tar -czf "${binaryName}.tar.gz" "${binaryName}"
|
|
|
|
log "Archive: ${archivePath}.tar.gz"
|
2019-07-03 03:10:17 +03:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2019-08-03 03:26:41 +03:00
|
|
|
# Bundle built code into a binary.
|
2019-07-03 03:10:17 +03:00
|
|
|
function binary-task() {
|
|
|
|
# I had trouble getting VS Code to build with the @coder/nbin dependency due
|
|
|
|
# to the types it installs (tons of conflicts), so for now it's a global
|
|
|
|
# dependency.
|
|
|
|
cd "${rootPath}"
|
|
|
|
npm link @coder/nbin
|
2019-08-03 03:26:41 +03:00
|
|
|
node "${rootPath}/scripts/nbin.js" "${buildPath}" "${target}" "${binaryName}"
|
2019-07-03 03:10:17 +03:00
|
|
|
rm node_modules/@coder/nbin
|
2019-07-11 02:33:18 +03:00
|
|
|
log "Binary: ${buildPath}/${binaryName}"
|
2019-07-03 03:10:17 +03:00
|
|
|
}
|
|
|
|
|
2019-07-12 01:12:52 +03:00
|
|
|
# Check if it looks like we are inside VS Code.
|
|
|
|
function in-vscode () {
|
|
|
|
local dir="${1}" ; shift
|
2019-08-03 03:26:41 +03:00
|
|
|
local maybeVsCode
|
2019-07-12 01:12:52 +03:00
|
|
|
local dirName
|
2019-08-03 03:26:41 +03:00
|
|
|
maybeVsCode="$(realpath "${dir}/../../..")"
|
|
|
|
dirName="$(basename "${maybeVsCode}")"
|
2019-07-12 01:12:52 +03:00
|
|
|
if [[ "${dirName}" != "vscode" ]] ; then
|
|
|
|
return 1
|
|
|
|
fi
|
2019-08-03 03:26:41 +03:00
|
|
|
if [[ ! -f "${maybeVsCode}/package.json" ]] ; then
|
2019-07-12 01:12:52 +03:00
|
|
|
return 1
|
|
|
|
fi
|
2019-08-03 03:26:41 +03:00
|
|
|
if ! grep '"name": "code-oss-dev"' "${maybeVsCode}/package.json" --quiet ; then
|
2019-07-12 01:12:52 +03:00
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2019-07-03 03:10:17 +03:00
|
|
|
function main() {
|
2019-07-12 01:12:52 +03:00
|
|
|
local relativeRootPath
|
|
|
|
local rootPath
|
|
|
|
relativeRootPath="$(dirname "${0}")/.."
|
|
|
|
rootPath="$(realpath "${relativeRootPath}")"
|
|
|
|
|
2019-07-03 03:10:17 +03:00
|
|
|
local task="${1}" ; shift
|
2019-07-12 01:12:52 +03:00
|
|
|
if [[ "${task}" == "ensure-in-vscode" ]] ; then
|
2019-08-03 03:26:41 +03:00
|
|
|
if ! in-vscode "${rootPath}"; then
|
|
|
|
log "Not in VS Code" "error"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
exit 0
|
2019-07-12 01:12:52 +03:00
|
|
|
fi
|
|
|
|
|
2019-07-03 03:10:17 +03:00
|
|
|
# This lets you build in a separate directory since building within this
|
|
|
|
# directory while developing makes it hard to keep developing since compiling
|
|
|
|
# will compile everything in the build directory as well.
|
|
|
|
local outPath="${OUT:-${rootPath}}"
|
2019-08-03 03:26:41 +03:00
|
|
|
local releasePath="${outPath}/release"
|
|
|
|
local stagingPath="${outPath}/build"
|
2019-07-03 03:10:17 +03:00
|
|
|
|
2019-08-03 03:26:41 +03:00
|
|
|
# If we're inside a VS Code directory, assume we want to develop. In that case
|
2019-07-11 00:29:15 +03:00
|
|
|
# we should set an OUT directory and not build in this directory.
|
2019-07-12 01:12:52 +03:00
|
|
|
if in-vscode "${outPath}" ; then
|
|
|
|
log "Set the OUT environment variable to something outside of VS Code" "error"
|
|
|
|
exit 1
|
2019-07-11 00:29:15 +03:00
|
|
|
fi
|
|
|
|
|
2019-08-03 03:26:41 +03:00
|
|
|
local vscodeVersion="${1}" ; shift
|
|
|
|
local sourceName="vscode-${vscodeVersion}-source"
|
|
|
|
local sourcePath="${stagingPath}/${sourceName}"
|
|
|
|
|
|
|
|
if [[ "${task}" == "package-prebuilt" ]] ; then
|
|
|
|
local archiveName="vscode-${vscodeVersion}.tar.gz"
|
|
|
|
cd "${stagingPath}"
|
|
|
|
git reset --hard && git clean -xfd -e '.build/extensions' -e 'node_modules'
|
|
|
|
tar -czf "${archiveName}" "${sourceName}"
|
|
|
|
mkdir -p "${releasePath}" && mv -f "${archiveName}" "${releasePath}"
|
|
|
|
exit 0
|
|
|
|
fi
|
2019-07-03 03:10:17 +03:00
|
|
|
|
2019-08-03 03:26:41 +03:00
|
|
|
local ci="${CI:-}"
|
|
|
|
local minify="${MINIFY:-}"
|
|
|
|
local arch="x86_64"
|
|
|
|
local target="linux"
|
|
|
|
local ostype="${OSTYPE:-}"
|
|
|
|
if [[ "${ostype}" == "darwin"* ]] ; then
|
|
|
|
target="darwin"
|
2019-07-03 03:10:17 +03:00
|
|
|
else
|
2019-08-03 03:26:41 +03:00
|
|
|
arch=$(uname -m)
|
2019-07-03 03:10:17 +03:00
|
|
|
fi
|
|
|
|
|
2019-08-03 03:26:41 +03:00
|
|
|
local codeServerVersion="${1}" ; shift
|
|
|
|
local binaryName="code-server${codeServerVersion}-vsc${vscodeVersion}-${target}-${arch}"
|
|
|
|
local buildPath="${stagingPath}/${binaryName}-built"
|
|
|
|
|
2019-07-03 03:10:17 +03:00
|
|
|
"${task}-task" "$@"
|
|
|
|
}
|
|
|
|
|
|
|
|
main "$@"
|