Skip to content

Instantly share code, notes, and snippets.

@eborden
Last active May 16, 2019 14:43
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save eborden/569fb5de4c2b3de741d7bb643fe7c2d9 to your computer and use it in GitHub Desktop.
Save eborden/569fb5de4c2b3de741d7bb643fe7c2d9 to your computer and use it in GitHub Desktop.
Run ghcid in a monorepo via stack
project=$(basename "$(pwd)")
# build dependencies
build_deps="stack build $project --fast --pedantic --dependencies-only --interleaved-output"
# restart on changes in other packages
restarts=$(find ../. -maxdepth 1 -type d \
-not -name "$project" \
-not -name .stack-work \
-not -name . \
-printf '--restart %s ')
# define expression for testing
if [ -z "$1" ]; then
test_expression="main"
else
test_expression="Test.Hspec.hspec $1.spec"
fi
# define ghci execution command
execute_options="--interleaved-output --ghci-options '-fobject-code +RTS -N'"
execute="stack ghci $project\:lib $project\:spec $execute_options"
stack exec -- ghcid \
--command "$build_deps;$execute" \
--test "$test_expression" \
--restart package.yaml \
$restarts
@eborden
Copy link
Author

eborden commented Apr 4, 2019

This expects a monorepo with a single package depth directory structure

ls
package-1 package-2 package-3
cat package-1/package-1.cabal
name:           package-1
...

@eborden
Copy link
Author

eborden commented Apr 4, 2019

usage:

cd package-1
stack-ghcid
cd package-2
stack-ghcid Some.Module.PathSpec

@eborden
Copy link
Author

eborden commented Apr 4, 2019

Credit to @5outh for starting the ball rolling with basename and $1.spec.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment