-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathupdate-version-symlinks
executable file
·45 lines (40 loc) · 1.52 KB
/
update-version-symlinks
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#! /usr/bin/env bash
#
# Run this script to update local symlinks after changing the tree-sitter
# version in the file 'tree-sitter-version'.
#
# This facilitates development that requires switching between different
# tree-sitter versions. The compiled tree-sitter libraries and binaries
# go into a versioned folder e.g. tree-sitter-0.22.6 and are therefore
# preserved when switching back and forth between versions.
#
# If the user wishes to install the tree-sitter CLI or runtime library
# elsewhere than the default 'tree-sitter/', they can do so by passing the
# '--prefix' option. In this case, the symlinks we create here become
# irrelevant.
#
set -eu
if [[ ! -e tree-sitter-version ]]; then
cp tree-sitter-version.default tree-sitter-version
fi
version=$(cat tree-sitter-version)
echo "Updating symlinks 'downloads/tree-sitter' and 'tree-sitter'"
mkdir -p downloads
(
cd downloads
rm -f tree-sitter
ln -s tree-sitter-"$version" tree-sitter
)
if [[ -d tree-sitter ]] && [[ ! -L tree-sitter ]]; then
# The issue is that we want to be able to use two different versions of
# the tree-sitter CLI. To make this convenient, the 'tree-sitter' folder
# is now a symlink to the versioned folder name.
echo "*** Your tree-sitter installation is old. Removing it."
rm -rf tree-sitter
fi
# Remove the symlink and set it to the new install folder.
# It allows us to use this script to switch tree-sitter versions without
# rebuilding everything.
rm -f tree-sitter
ln -s tree-sitter-"$version" tree-sitter
mkdir -p tree-sitter-"$version"