server/gardening: move local hoogle setup from Makefile to bash script

PR-URL: https://github.com/hasura/graphql-engine-mono/pull/3996
GitOrigin-RevId: ace7f4c13cab6e549aedf4520334c435acac9ab1
This commit is contained in:
Rakesh Emmadi 2022-03-16 16:13:07 +05:30 committed by hasura-bot
parent d203ef940b
commit d7b6585454
3 changed files with 108 additions and 41 deletions

View File

@ -9,11 +9,6 @@ ORMOLU_ARGS = --cabal-default-extensions
ORMOLU = ormolu
ORMOLU_VERSION = $(shell $(ORMOLU) --version | awk 'NR==1 { print $$2 }')
HOOGLE = $(shell command -v hoogle 2> /dev/null)
CABAL_DIST = dist-newstyle
HOOGLE_DATABASE = $(CABAL_DIST)/hge.hoo
HOOGLE_PORT = 1337
# default target
.PHONY: help
## help: prints help message
@ -55,24 +50,3 @@ format-changed: format-hs-changed
.PHONY: check-format
check-format: check-format-hs
.PHONY: check-hoogle
## check-hoogle: Check for hoogle installation
check-hoogle:
@if [ "$(HOOGLE)" = "" ]; then \
echo "ERROR: hoogle not found, please install"; exit 1; \
fi
.PHONY: hoogle-generate
## hoogle-generate: Generate hoogle database
hoogle-generate: check-hoogle
@echo "Generating haddock hoogle files"
cabal haddock all
@echo "Generating hoogle database"
hoogle generate --local=$(CABAL_DIST) --database=$(HOOGLE_DATABASE)
.PHONY: hoogle-server
## hoogle-server: Start local hoogle server an port 8181
hoogle-server: check-hoogle
@echo "Starting local hoogle server. Visit http://localhost:$(HOOGLE_PORT)"
@hoogle server --local --database=$(HOOGLE_DATABASE) --port $(HOOGLE_PORT)

96
scripts/hoogle.sh Executable file
View File

@ -0,0 +1,96 @@
#!/usr/bin/env bash
# A utility script to setup local Hoogle instance.
set -euo pipefail
HOOGLE=hoogle
CABAL=cabal
CABAL_ARGS="--haddock-hoogle"
CABAL_DIST=dist-newstyle
HOOGLE_DATABASE=$CABAL_DIST/hge.hoo
HOOGLE_PORT=1337
PROJECT_ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." >/dev/null 2>&1 && pwd )"
MODE=$1
print_usage() {
cat << EOL
A utility script for setting up local Hoogle instance
Usage: $0 <COMMAND>
Available Commands:
generate
Generate local hoogle database and store it at $HOOGLE_DATABASE
serve [--port INT]
Start local hoogle server. If --port is not provided then the server will run on port $HOOGLE_PORT.
Global flags:
-h, --help Show this help text
EOL
}
die_usage() {
print_usage
exit 1
}
show_help() {
print_usage
exit 0
}
case "${1-}" in
-h)
show_help
;;
--help)
show_help
;;
generate)
;;
serve)
case "${2-}" in
--port)
HOOGLE_PORT="${*:3}"
;;
esac
;;
*)
die_usage
;;
esac
check_hoogle() {
if ! command -v "$HOOGLE" &> /dev/null ; then
echo "ERROR: $HOOGLE not found, Please install."
exit 1
fi
}
if [ "$MODE" = "generate" ]; then
check_hoogle
cd "$PROJECT_ROOT"
echo "Generating haddock hoogle files"
$CABAL haddock $CABAL_ARGS all
echo "Generating hoogle database"
$HOOGLE generate --local=$CABAL_DIST --database=$HOOGLE_DATABASE
elif [ "$MODE" = "serve" ]; then
check_hoogle
cd "$PROJECT_ROOT"
if ! [ -f "$HOOGLE_DATABASE" ]; then
echo "Hoogle database $HOOGLE_DATABASE does not exist. Run '$0 generate' to generate database."
exit 1
fi
echo "Starting local hoogle server. Visit http://localhost:$HOOGLE_PORT"
$HOOGLE server --local --database=$HOOGLE_DATABASE --port $HOOGLE_PORT
else
echo "Invalid command; $MODE"
fi

View File

@ -240,22 +240,19 @@ cabal install hoogle
### Step 2: Generating hoogle database
A Hoogle database is a prebuilt index of a set of packages. Running the following `make`
command in the repository root directory generates and stores the hoogle database for
GraphQL Engine server code in `dist-newstyle/` directory.
```bash
make hoogle-generate
```
A Hoogle database is a prebuilt index of a set of packages. The `hoogle.sh` script in the
top-level `scripts/` directory helps in generating the hoogle database for GraphQL Engine server
code and store it in `dist-newstyle/` directory.
$ scripts/hoogle.sh generate
### Step 3: Running hoogle instance
Running the following `make` command in the repository root directory starts a local hoogle server
with the database generated in `Step 2`.
```bash
make hoogle-server
```
Running the following `hoogle.sh` script command starts a local hoogle server with the database
generated in `Step 2`.
Use `HOOGLE_PORT` variable assignment to specify custom port to start hoogle server.
```bash
make hoogle-server HOOGLE_PORT=8181
```
$ scripts/hoogle.sh serve
Use `--port` option to specify custom port to start hoogle server.
$ scripts/hoogle.sh serve --port 8181