Skip to content

Commit

Permalink
Implement stack resolver override for Haskell.
Browse files Browse the repository at this point in the history
Closes PaulDance#13.

This patch also bundled some other changes:

- `-Wall` to `--ghc-options -Wall` as this is supposed to be
pased to GHC (stack can't recognize this flag)
- Removed `--trace` as it tends to be verbose and messes up hspec's output.
  • Loading branch information
Javran committed Mar 4, 2021
1 parent 53df178 commit 4c5e11f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ The usual workflow is as such:
* When done for the day, you may run `xr clean` in order to remove all
downloaded exercise submissions.

## Track-specific settings

### Haskell

You can optionally override student's resolver by setting `XR_HASKELL_STACK_RESOLVER` to a valid resolver version.
(e.g. `XR_HASKELL_STACK_RESOLVER=lts-16.21 xr t`)
## Contributing
Expand Down
27 changes: 25 additions & 2 deletions tracks/haskell.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,33 @@
function _override_stack_resolver() {
if [[ -z "$XR_HASKELL_STACK_RESOLVER" ]]; then
return
fi

# See https://docs.haskellstack.org/en/stable/pantry/#snapshot-location for resolver syntax.
# For the purpose of running exercises it's resonable just to allow lts and nightly.
if ! [[ $XR_HASKELL_STACK_RESOLVER =~ '^(lts-[0-9\.]+|nightly-[0-9-]+)$' ]]; then
echo Skipped resolver override as $XR_HASKELL_STACK_RESOLVER is not allowed.
return
fi

if ! stack --resolver="$XR_HASKELL_STACK_RESOLVER" eval '()' >/dev/null 2>/dev/null; then
echo Skipped resolver override as stack cannot recognize $XR_HASKELL_STACK_RESOLVER.
return
fi

echo Overriding resolver to $XR_HASKELL_STACK_RESOLVER.
sed -i 's/resolver: .*/resolver: '"$XR_HASKELL_STACK_RESOLVER"'/' stack.yaml
}

# Runs all the available tests.
function _run_tests() {
stack test -Wall --trace \
_override_stack_resolver
stack test --ghc-options -Wall \
&& hlint .
}

# Just runs any available benchmark, importing still needs to be added.
function _run_benches() {
stack bench -Wall --no-run-tests
_override_stack_resolver
stack bench --ghc-options -Wall --no-run-tests
}

0 comments on commit 4c5e11f

Please sign in to comment.