Skip to content

Commit

Permalink
tool/*: remove dependency on redo for tooling (#183)
Browse files Browse the repository at this point in the history
  • Loading branch information
shayne committed Aug 8, 2023
1 parent 6f7dbb8 commit 62caf79
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 197 deletions.
6 changes: 3 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ A vsix build can be produced by running `./tool/yarn vsce package --allow-star-a

## Development tools

Following the [Tailscale OSS](https://github.com/tailscale/tailscale) repository, we use a `./tool` directory to manage tool dependencies. Versions are pinned via `*.rev` files in the projects' root and installed via `./tool/redo.sh` using the `*.cmd.do` files also in the project's root.
Following the [Tailscale OSS](https://github.com/tailscale/tailscale) repository, we use a `./tool` directory to manage tool dependencies. Versions are pinned via `*.rev` files in the projects' root and installed on demand.

Flakes are provided for Nix users, with `nix develop` for the environment.

The following tools are available:

- `./tool/node` - [Node](https://nodejs.org/) for future JavaScript tooling
- `./tool/Go` - [Go](https://go.dev/) for tsrelay backend
- `./tool/node` - [Node](https://nodejs.org/) for JavaScript tooling
- `./tool/yarn` - [Yarn](https://yarnpkg.com/) package manager
- `./tool/redo.sh` - [Redo](https://github.com/apenwarr/redo) build/automation tool (for deps)

If available, [direnv](https://direnv.net/) will place these tools in your PATH per our `.envrc` config. Installation instructions for direnv are available [here](https://direnv.net/docs/installation.html).

Expand Down
25 changes: 0 additions & 25 deletions do

This file was deleted.

61 changes: 0 additions & 61 deletions node.cmd.do

This file was deleted.

Empty file removed node.do
Empty file.
62 changes: 55 additions & 7 deletions tool/node
Original file line number Diff line number Diff line change
@@ -1,12 +1,60 @@
#!/bin/sh
#!/usr/bin/env bash
# Run a command with our local node install, rather than any globally installed
# instance.

set -eu
set -euo pipefail

cd $(dirname "$0")/..
./do node.cmd
read -r NODE < node.cmd
cd - > /dev/null
if [[ "${CI:-}" == "true" ]]; then
set -x
fi

exec /usr/bin/env PATH="$(dirname $NODE):$PATH" "$NODE" "$@"
(
if [[ "${CI:-}" == "true" ]]; then
set -x
fi

repo_root="${BASH_SOURCE%/*}/../"
cd "$repo_root"

cachedir="$HOME/.cache/tailscale-node"
tarball="${cachedir}.tar.gz"

read -r want_rev <node.rev

got_rev=""
if [[ -x "${cachedir}/bin/node" ]]; then
got_rev=$("${cachedir}/bin/node" --version)
got_rev="${got_rev#v}" # trim the leading 'v'
fi

if [[ "$want_rev" != "$got_rev" ]]; then
rm -rf "$cachedir" "$tarball"
if [[ -n "${IN_NIX_SHELL:-}" ]]; then
nix_node="$(which -a node | grep /nix/store | head -1)"
nix_node="${nix_node%/bin/node}"
nix_node_rev="${nix_node##*-}"
if [[ "$nix_node_rev" != "$want_rev" ]]; then
echo "Wrong node version in Nix, got $nix_node_rev want $want_rev" >&2
exit 1
fi
ln -sf "$nix_node" "$cachedir"
else
# works for "linux" and "darwin"
OS=$(uname -s | tr A-Z a-z)
ARCH=$(uname -m)
if [ "$ARCH" = "x86_64" ]; then
ARCH="x64"
fi
if [ "$ARCH" = "aarch64" ]; then
ARCH="arm64"
fi
mkdir -p "$cachedir"
curl -f -L -o "$tarball" "https://nodejs.org/dist/v${want_rev}/node-v${want_rev}-${OS}-${ARCH}.tar.gz"
(cd "$cachedir" && tar --strip-components=1 -xf "$tarball")
rm -f "$tarball"
fi
fi
)

export PATH="$HOME/.cache/tailscale-node/bin:$PATH"
exec "$HOME/.cache/tailscale-node/bin/node" "$@"
33 changes: 0 additions & 33 deletions tool/redo.sh

This file was deleted.

47 changes: 39 additions & 8 deletions tool/yarn
Original file line number Diff line number Diff line change
@@ -1,13 +1,44 @@
#!/bin/sh
#!/usr/bin/env bash
# Run a command with our local yarn install, rather than any globally installed
# instance.

set -eu
set -euo pipefail

cd $(dirname "$0")/..
./do yarn.cmd node.cmd
read -r YARN < yarn.cmd
read -r NODE < node.cmd
cd - > /dev/null
if [[ "${CI:-}" == "true" ]]; then
set -x
fi

(
if [[ "${CI:-}" == "true" ]]; then
set -x
fi

repo_root="${BASH_SOURCE%/*}/../"
cd "$repo_root"

./tool/node --version >/dev/null # Ensure node is unpacked and ready

cachedir="$HOME/.cache/tailscale-yarn"
tarball="${cachedir}.tar.gz"

read -r want_rev <yarn.rev

got_rev=""
if [[ -x "${cachedir}/bin/yarn" ]]; then
got_rev=$(PATH="$HOME/.cache/tailscale-node/bin:$PATH" "${cachedir}/bin/yarn" --version)
fi

if [[ "$want_rev" != "$got_rev" ]]; then
rm -rf "$cachedir" "$tarball"
mkdir -p "$cachedir"
curl -f -L -o "$tarball" "https://github.com/yarnpkg/yarn/releases/download/v${want_rev}/yarn-v${want_rev}.tar.gz"
(cd "$cachedir" && tar --strip-components=1 -xf "$tarball")
rm -f "$tarball"
fi
)

# Deliberately not using cachedir here, to keep the environment
# completely pristine for execution of yarn.
export PATH="$HOME/.cache/tailscale-node/bin:$HOME/.cache/tailscale-yarn/bin:$PATH"
exec "$HOME/.cache/tailscale-yarn/bin/yarn" "$@"

exec /usr/bin/env PATH="$(dirname $NODE):$PATH" "$YARN" "$@"
60 changes: 0 additions & 60 deletions yarn.cmd.do

This file was deleted.

0 comments on commit 62caf79

Please sign in to comment.