Skip to content

Commit

Permalink
dev: only support watchman (#12252)
Browse files Browse the repository at this point in the history
Maintaining three different ways to watch files leads to unneccessary
bugs. Instead lets pick just one.
  • Loading branch information
keegancsmith committed Jul 17, 2020
1 parent c8c3439 commit 5a1c63b
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 248 deletions.
78 changes: 11 additions & 67 deletions dev/changewatch.sh
@@ -1,73 +1,17 @@
#!/usr/bin/env bash

set -e
unset CDPATH
cd "$(dirname "${BASH_SOURCE[0]}")/.." # cd to repo root dir
GO_DIRS="$(./dev/watchdirs.sh) ${WATCH_ADDITIONAL_GO_DIRS}"

dirs_starstar() {
for i; do echo "'$i/**/*.go'"; done
}
# Wrapper for watchman. To debug which changes it detect set the environment
# variable WATCHMAN_DEBUG=t

dirs_path() {
for i; do echo "-path $i"; done
}
if [ ! -x "$(command -v watchman)" ]; then
echo "Please install watchman. https://facebook.github.io/watchman/docs/install.html"
echo
echo " brew install watchman"
exit 1
fi

useChokidar() {
echo >&2 "Using chokidar."
# eval so the expansion can produce quoted things, and eval can eat the
# quotes, so it doesn't try to expand wildcards.
# shellcheck disable=2046,2086
eval exec chokidar --silent \
$(dirs_starstar $GO_DIRS) \
cmd/frontend/graphqlbackend/schema.graphql \
"'schema/*.json'" \
"'docker-images/grafana/jsonnet/*.jsonnet'" \
"'monitoring/*'" \
"'cmd/symbols/**/*'" \
"'cmd/symbols/.ctags.d/*'" \
-c "'./dev/handle-change.sh {path}'"
}

execInotifywrapper() {
echo >&2 "Using inotifywrapper."
set -e
pushd dev/inotifywrapper
go build
popd
# shellcheck disable=2046,2086
exec dev/inotifywrapper/inotifywrapper $(dirs_path $GO_DIRS) \
-match '\.go$' \
-match 'cmd/frontend/graphqlbackend/schema\.graphql' \
-match 'schema/.*.json' \
-match 'docker-images/grafana/jsonnet/*.jsonnet' \
-match 'monitoring/*' \
-cmd './dev/handle-change.sh'
}

execWatchman() {
echo >&2 "Using watchman."
set -e
pushd dev/watchmanwrapper
go build
popd
exec dev/watchmanwrapper/watchmanwrapper dev/handle-change.sh <<-EOT
["subscribe", ".", "gochangewatch", {
"expression": ["allof",
["not", ["anyof",
["match", ".*"],
["suffix", "_test.go"]]],
["anyof",
["suffix", "go"],
["dirname", "cmd/symbols"],
["dirname", "schema"],
["dirname", "docker-images/grafana/jsonnet"],
["dirname", "monitoring"],
["name", "cmd/frontend/graphqlbackend/schema.graphql", "wholename"]]],
"fields": ["name"]
}]
EOT
}

[ -x "$(command -v watchman)" ] && execWatchman
[ -x "$(command -v inotifywait)" ] && execInotifywrapper

useChokidar
exec go run ./dev/watchmanwrapper dev/handle-change.sh <dev/watchmanwrapper/watch.json
1 change: 0 additions & 1 deletion dev/inotifywrapper/.gitignore

This file was deleted.

174 changes: 0 additions & 174 deletions dev/inotifywrapper/main.go

This file was deleted.

5 changes: 0 additions & 5 deletions dev/watchdirs.sh

This file was deleted.

21 changes: 21 additions & 0 deletions dev/watchmanwrapper/watch.json
@@ -0,0 +1,21 @@
[
"subscribe",
".",
"gochangewatch",
{
"expression": [
"allof",
["not", ["anyof", ["match", ".*"], ["suffix", "_test.go"]]],
[
"anyof",
["suffix", "go"],
["dirname", "cmd/symbols"],
["dirname", "schema"],
["dirname", "docker-images/grafana/jsonnet"],
["dirname", "monitoring"],
["name", "cmd/frontend/graphqlbackend/schema.graphql", "wholename"]
]
],
"fields": ["name"]
}
]
6 changes: 5 additions & 1 deletion doc/dev/local_development.md
Expand Up @@ -76,6 +76,7 @@ Sourcegraph has the following dependencies:
- [SQLite](https://www.sqlite.org/index.html) tools
- [Golang Migrate](https://github.com/golang-migrate/migrate/) (v4.7.0 or higher)
- [Comby](https://github.com/comby-tools/comby/) (v0.11.3 or higher)
- [Watchman](https://facebook.github.io/watchman/)

The following are two recommendations for installing these dependencies:

Expand All @@ -93,7 +94,7 @@ The following are two recommendations for installing these dependencies:
3. Install Go, Node Version Manager, PostgreSQL, Redis, Git, NGINX, golang-migrate, Comby, SQLite tools, and jq with the following command:

```
brew install go yarn redis postgresql git gnu-sed nginx golang-migrate comby sqlite pcre FiloSottile/musl-cross/musl-cross jq
brew install go yarn redis postgresql git gnu-sed nginx golang-migrate comby sqlite pcre FiloSottile/musl-cross/musl-cross jq watchman
```

4. Install the Node Version Manager (`nvm`) using:
Expand Down Expand Up @@ -182,6 +183,9 @@ The following are two recommendations for installing these dependencies:
# install comby (you must rename the extracted binary to `comby` and move the binary into your $PATH)
curl -L https://github.com/comby-tools/comby/releases/download/0.11.3/comby-0.11.3-x86_64-linux.tar.gz | tar xvz
# install watchman (you must put the binary and shared libraries on your $PATH and $LD_LIBRARY_PATH)
curl -L https://github.com/facebook/watchman/releases/download/v2020.07.13.00/watchman-v2020.07.13.00-linux.zip
# nvm (to manage Node.js)
NVM_VERSION="$(curl https://api.github.com/repos/nvm-sh/nvm/releases/latest | jq -r .name)"
curl -L https://raw.githubusercontent.com/nvm-sh/nvm/"$NVM_VERSION"/install.sh -o install-nvm.sh
Expand Down

0 comments on commit 5a1c63b

Please sign in to comment.