Skip to content

Visual Studio Code, rebuilt in Rust

Rust
4.3 KB
Raw Blame
#!/bin/bash
# Mirror this checkout to the Mac Studio and run a command there (bash -l, at the mirror root).
# Pushes HEAD to one bare repo on the Studio (git.git, only missing objects travel), points the mirror's index at it,
# runs `git clean` there (drops files deleted here), then copies only the files that differ: the mirror's modified files
# (changed by the new commits, or dirty in an earlier run) and this checkout's files that differ from HEAD or are untracked.
# Ignored files on the Studio (node_modules, out, native/target) survive between runs.
# Each linked worktree gets its own mirror (port-src-<worktree>), first seeded as an APFS clone of port-src-integrate (else port-src).
# Mirrors borrow git.git's objects through objects/info/alternates; git.git was cloned once from GitHub on the Studio.
set -euo pipefail
root=$(git -C "$(dirname "$0")" rev-parse --show-toplevel)
cd "$root"
# Parallel calls from one checkout (studio --lane) share its mirror: one sync at a time, the runs overlap.
sync_lock=/tmp/port-studio-sync-$(basename "$root").lock
until shlock -f "$sync_lock" -p $$; do perl -e 'select(undef, undef, undef, 0.2)'; done
trap 'rm -f "$sync_lock"' EXIT
work=Developer/vscode-gpui-work
name=port-src
if [[ $(git rev-parse --absolute-git-dir) != $(cd "$(git rev-parse --git-common-dir)" && pwd) ]]; then
  name=$name-$(basename "$root")
  # Seed from the integration mirror when it exists: its native/target is the freshest, so a new worktree's first build reuses its dependencies.
  # The Studio's login shell is fish: the seed choice runs in bash.
  # The copied build scripts of app, diff, exthost and files watch the seed's native/vscode_src.rs and keep its VSCODE_SRC: drop them.
  ssh studio "cd ~/$work && bash -c $(printf '%q' "test -d $name || { seed=port-src-integrate; test -d \$seed || seed=port-src; cp -cR \$seed $name; rm -rf $name/native/target/*/build/{app,diff,exthost,files}-*; }")"
fi
head=$(git rev-parse HEAD)
# The Studio repo has no LFS server; the two LFS files are copied below like any other file.
GIT_LFS_SKIP_PUSH=1 git push -qf "studio:$work/git.git" "HEAD:refs/mirror/$name"
stale=$(mktemp)
trap 'rm -f "$stale" "$sync_lock"' EXIT
# A mirror without alternates still has the full .git of the old rsync copy: replace it with a light one.
# A mixed reset moves only the index, so file mtimes and the cargo build stay as they are.
# repointed on every run: a mirror seeded from port-src-integrate or synced before the uplift links the 1.147.0 one.
# A repointed link also drops the build scripts that read upstream: cargo watches the old target's files, which never change, so it keeps their stale VSCODE_SRC.
ssh studio "cd ~/$work/$name && bash -c 'test -f .git/objects/info/alternates || { rm -rf .git && git init -q && echo ~/$work/git.git/objects > .git/objects/info/alternates; }; git reset -q $head && git clean -fdq && { git cat-file -e HEAD:src 2>/dev/null || test -d upstream -a ! -L upstream || test \"\$(readlink upstream)\" = ~/Developer/vscode-ref-1.148.0 || { ln -sfn ~/Developer/vscode-ref-1.148.0 upstream && rm -rf native/target/*/build/{app,diff,exthost,files}-* native/target/*/*/build/{app,diff,exthost,files}-*; }; } && git ls-files -m -z'" > "$stale"
# Diff against HEAD, not the index: staged changes (a merge being resolved) must travel too.
# openrsync has no --ignore-missing-args: leave out files deleted here.
cat "$stale" <(git diff --name-only -z --diff-filter=d HEAD) <(git ls-files -o --exclude-standard -z) | sort -zu | { grep -zvxFf <(git -c core.quotepath=off diff --name-only --diff-filter=D HEAD) || true; } | rsync -az --from0 --files-from=- . "studio:$work/$name/"
git diff --name-only -z --diff-filter=D HEAD | ssh studio "cd ~/$work/$name && xargs -0 rm -f"
rm -f "$sync_lock"
sync_lock=
cmd=$1
# --lane '<cmd>': run a GUI tool in the first free GUI lane (port/tools/gui-lane).
[[ $1 != --lane ]] || cmd="port/tools/gui-lane $(printf '%q' "$2")"
# Builds of parallel sessions run niced (the apps under test in a ui-pair run get the CPU first), in a build slot
# (port/tools/build-slot), and share one sccache: every mirror's dependencies compile once.
ssh studio "cd ~/$work/$name && bash -lc $(printf '%q' "export RUSTC_WRAPPER=sccache SCCACHE_CACHE_SIZE=40G; cargo() { ~/$work/$name/port/tools/build-slot nice -n 15 cargo \"\$@\"; }; export -f cargo; $cmd")"