@@ -20,39 +20,55 @@ function exit-if-ci() {
2020
2121# Copy code-server into VS Code along with its dependencies.
2222function copy-server() {
23+ log " Applying patch"
24+ cd " ${vscodeSourcePath} "
25+ git reset --hard
26+ git clean -fd
27+ git apply " ${rootPath} /scripts/vscode.patch"
28+
2329 local serverPath=" ${vscodeSourcePath} /src/vs/server"
2430 rm -rf " ${serverPath} "
2531 mkdir -p " ${serverPath} "
2632
27- log " Copying server code"
33+ log " Copying code- server code"
2834
29- cp " ${rootPath} " /* .{ts,js} " ${serverPath} "
35+ cp -r " ${rootPath} /src" " ${serverPath} "
36+ cp -r " ${rootPath} /typings" " ${serverPath} "
37+ cp " ${rootPath} /main.js" " ${serverPath} "
3038 cp " ${rootPath} /package.json" " ${serverPath} "
3139 cp " ${rootPath} /yarn.lock" " ${serverPath} "
3240
3341 if [[ -d " ${rootPath} /node_modules" ]] ; then
34- log " Copying dependencies"
42+ log " Copying code-server build dependencies"
3543 cp -r " ${rootPath} /node_modules" " ${serverPath} "
3644 else
37- log " Installing dependencies"
45+ log " Installing code-server build dependencies"
3846 cd " ${serverPath} "
3947 # Ignore scripts to avoid also installing VS Code dependencies which has
4048 # already been done.
4149 yarn --ignore-scripts
4250 rm -r node_modules/@types/node # I keep getting type conflicts
4351 fi
52+
53+ # TODO: Duplicate identifier issue. There must be a better way to fix this.
54+ if [[ " ${target} " == " darwin" ]] ; then
55+ rm " ${serverPath} /node_modules/fsevents/node_modules/safe-buffer/index.d.ts"
56+ fi
4457}
4558
46- # Prepend the nbin loading code which allows the code to find files within
47- # the binary.
59+ # Prepend the nbin shim which enables finding files within the binary.
4860function prepend-loader() {
4961 local filePath=" ${codeServerBuildPath} /${1} " ; shift
50- cat " ${rootPath} /scripts/nbin-loader .js" " ${filePath} " > " ${filePath} .temp"
62+ cat " ${rootPath} /scripts/nbin-shim .js" " ${filePath} " > " ${filePath} .temp"
5163 mv " ${filePath} .temp" " ${filePath} "
5264 # Using : as the delimiter so the escaping here is easier to read.
5365 # ${parameter/pattern/string}, so the pattern is /: (if the pattern starts
5466 # with / it matches all instances) and the string is \\: (results in \:).
55- sed -i " s:{{ROOT_PATH}}:${codeServerBuildPath//:/ \\ : } :g" " ${filePath} "
67+ if [[ " ${target} " == " darwin" ]] ; then
68+ sed -i " " -e " s:{{ROOT_PATH}}:${codeServerBuildPath//:/ \\ : } :g" " ${filePath} "
69+ else
70+ sed -i " s:{{ROOT_PATH}}:${codeServerBuildPath//:/ \\ : } :g" " ${filePath} "
71+ fi
5672}
5773
5874# Copy code-server into VS Code then build it.
@@ -63,10 +79,7 @@ function build-code-server() {
6379 # (basically just want to skip extensions, target our server code, and get
6480 # the same type of build you get with the vscode-linux-x64-min task).
6581 # Something like: yarn gulp "vscode-server-${target}-${arch}-min"
66- cd " ${vscodeSourcePath} "
67- git reset --hard
68- git clean -fd
69- git apply " ${rootPath} /scripts/vscode.patch"
82+ log " Building code-server"
7083 yarn gulp compile-client
7184
7285 rm -rf " ${codeServerBuildPath} "
@@ -78,9 +91,22 @@ function build-code-server() {
7891 node " ${rootPath} /scripts/merge.js" " ${vscodeBuildPath} /resources/app/package.json" " ${rootPath} /scripts/package.json" " ${codeServerBuildPath} /package.json" " ${json} "
7992 node " ${rootPath} /scripts/merge.js" " ${vscodeBuildPath} /resources/app/product.json" " ${rootPath} /scripts/product.json" " ${codeServerBuildPath} /product.json"
8093 cp -r " ${vscodeSourcePath} /out" " ${codeServerBuildPath} "
81- rm -rf " ${codeServerBuildPath} /out/vs/server/node_modules"
94+ rm -rf " ${codeServerBuildPath} /out/vs/server/typings"
95+
96+ # Rebuild to make sure the native modules work since at the moment all the
97+ # pre-built packages are from one Linux system. This means you must build on
98+ # the target system.
99+ log " Installing remote dependencies"
100+ cd " ${vscodeSourcePath} /remote"
101+ if [[ " ${target} " != " linux" ]] ; then
102+ yarn --production --force
103+ fi
82104 cp -r " ${vscodeSourcePath} /remote/node_modules" " ${codeServerBuildPath} "
83105
106+ # Only keep the production dependencies.
107+ cd " ${codeServerBuildPath} /out/vs/server"
108+ yarn --production --ignore-scripts
109+
84110 prepend-loader " out/vs/server/main.js"
85111 prepend-loader " out/bootstrap-fork.js"
86112
@@ -105,11 +131,9 @@ function build-vscode() {
105131 if [[ ! -d " ${vscodeSourcePath} /node_modules" ]] ; then
106132 exit-if-ci
107133 log " Installing VS Code dependencies"
108- yarn
109- # Not entirely sure why but there seem to be problems with native modules.
110- # Also vscode-ripgrep keeps complaining after the rebuild that the
111- # node_modules directory doesn't exist, so we're ignoring that for now.
112- npm rebuild || true
134+ # Not entirely sure why but there seem to be problems with native modules
135+ # so rebuild them.
136+ yarn --force
113137
114138 # Keep just what we need to keep the pre-built archive smaller.
115139 rm -rf " ${vscodeSourcePath} /test"
@@ -138,7 +162,7 @@ function download-vscode() {
138162 cd " ${buildPath} "
139163 if command -v wget & > /dev/null ; then
140164 log " Attempting to download ${tarName} with wget"
141- wget " ${vsSourceUrl} " --quiet
165+ wget " ${vsSourceUrl} " --quiet --output-document " ${tarName} "
142166 else
143167 log " Attempting to download ${tarName} with curl"
144168 curl " ${vsSourceUrl} " --silent --fail --output " ${tarName} "
@@ -152,13 +176,20 @@ function download-vscode() {
152176function prepare-vscode() {
153177 if [[ ! -d " ${vscodeBuildPath} " || ! -d " ${vscodeSourcePath} " ]] ; then
154178 mkdir -p " ${buildPath} "
179+ # TODO: for now everything uses the Linux build and we rebuild the modules.
180+ # This means you must build on the target system.
155181 local tarName=" vstar-${vscodeVersion} -${target} -${arch} .tar.gz"
156- local vsSourceUrl=" https://codesrv-ci.cdr.sh/${tarName} "
182+ local linuxTarName=" vstar-${vscodeVersion} -linux-${arch} .tar.gz"
183+ local linuxVscodeBuildName=" vscode-${vscodeVersion} -linux-${arch} -built"
184+ local vsSourceUrl=" https://codesrv-ci.cdr.sh/${linuxTarName} "
157185 if download-vscode ; then
158186 cd " ${buildPath} "
159187 rm -rf " ${vscodeBuildPath} "
160188 tar -xzf " ${tarName} "
161189 rm " ${tarName} "
190+ if [[ " ${target} " != " linux" ]] ; then
191+ mv " ${linuxVscodeBuildName} " " ${vscodeBuildName} "
192+ fi
162193 elif [[ -n " ${ci} " ]] ; then
163194 log " Pre-built VS Code ${vscodeVersion} -${target} -${arch} does not exist" " error"
164195 exit 1
@@ -199,12 +230,12 @@ function package-task() {
199230 cp " ${vscodeSourcePath} /ThirdPartyNotices.txt" " ${archivePath} "
200231
201232 cd " ${releasePath} "
202- if [[ " ${target} " == " linux" ]] ; then
203- tar -czf " ${binaryName} .tar.gz" " ${binaryName} "
204- log " Archive: ${archivePath} .tar.gz"
205- else
233+ if [[ " ${target} " == " darwin" ]] ; then
206234 zip -r " ${binaryName} .zip" " ${binaryName} "
207235 log " Archive: ${archivePath} .zip"
236+ else
237+ tar -czf " ${binaryName} .tar.gz" " ${binaryName} "
238+ log " Archive: ${archivePath} .tar.gz"
208239 fi
209240}
210241
@@ -221,35 +252,64 @@ function binary-task() {
221252 log " Binary: ${buildPath} /${binaryName} "
222253}
223254
255+ # Check if it looks like we are inside VS Code.
256+ function in-vscode () {
257+ log " Checking if we are inside VS Code"
258+ local dir=" ${1} " ; shift
259+
260+ local maybeVscode
261+ local dirName
262+ maybeVscode=" $( realpath " ${dir} /../../.." ) "
263+ dirName=" $( basename " ${maybeVscode} " ) "
264+
265+ if [[ " ${dirName} " != " vscode" ]] ; then
266+ return 1
267+ fi
268+ if [[ ! -f " ${maybeVscode} /package.json" ]] ; then
269+ return 1
270+ fi
271+ if ! grep ' "name": "code-oss-dev"' " ${maybeVscode} /package.json" --quiet ; then
272+ return 1
273+ fi
274+
275+ return 0
276+ }
277+
278+ function ensure-in-vscode-task() {
279+ if ! in-vscode " ${rootPath} " ; then
280+ log " Not in vscode" " error"
281+ exit 1
282+ fi
283+ exit 0
284+ }
285+
224286function main() {
287+ local relativeRootPath
288+ local rootPath
289+ relativeRootPath=" $( dirname " ${0} " ) /.."
290+ rootPath=" $( realpath " ${relativeRootPath} " ) "
291+
225292 local task=" ${1} " ; shift
293+ if [[ " ${task} " == " ensure-in-vscode" ]] ; then
294+ ensure-in-vscode-task
295+ fi
296+
226297 local codeServerVersion=" ${1} " ; shift
227298 local vscodeVersion=" ${1} " ; shift
228299 local target=" ${1} " ; shift
229300 local arch=" ${1} " ; shift
230301 local ci=" ${CI:- } "
231302
232- local relativeRootPath
233- local rootPath
234- relativeRootPath=" $( dirname " ${0} " ) /.."
235- rootPath=" $( realpath " ${relativeRootPath} " ) "
236-
237303 # This lets you build in a separate directory since building within this
238304 # directory while developing makes it hard to keep developing since compiling
239305 # will compile everything in the build directory as well.
240306 local outPath=" ${OUT:- ${rootPath} } "
241307
242308 # If we're inside a vscode directory, assume we want to develop. In that case
243309 # we should set an OUT directory and not build in this directory.
244- if [[ " ${outPath} " == " ${rootPath} " ]] ; then
245- local maybeVscode
246- local dirName
247- maybeVscode=" $( realpath " ${outPath} /../../.." ) "
248- dirName=" $( basename " ${maybeVscode} " ) "
249- if [[ " ${dirName} " == " vscode" ]] ; then
250- log " Set the OUT environment variable to something outside ${maybeVscode} " " error"
251- exit 1
252- fi
310+ if in-vscode " ${outPath} " ; then
311+ log " Set the OUT environment variable to something outside of VS Code" " error"
312+ exit 1
253313 fi
254314
255315 local releasePath=" ${outPath} /release"
0 commit comments