Skip to content

Commit 0db7e4d

Browse files
committed
Ensure a compatible ghc version is being used for doctests
1 parent 04ac8eb commit 0db7e4d

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

scripts/doctest.sh

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,32 @@
22

33
set -euo pipefail
44

5-
# Install doctest's Cabal integration
6-
cabal install doctest --flag cabal-doctest --ignore-project --overwrite-policy=always
5+
# Packages to run doctests for; defaults to all packages if none are specified
6+
PACKAGES=("$@")
7+
8+
# Install doctest's Cabal integration, if it's not present already
9+
if [[ -z "$(type -t cabal-doctest)" ]]
10+
then
11+
cabal install doctest --flag cabal-doctest --ignore-project --overwrite-policy=always
12+
fi
13+
14+
# Ensure doctest and PATH are using the same ghc version
15+
16+
getExecutablePath()
17+
{
18+
"$1" -package-env - -e 'import System.Environment' -e 'putStrLn =<< getExecutablePath'
19+
}
20+
21+
default_ghc=$(type -p ghc)
22+
doctest_ghc=$(doctest --info | ghc -e 'interact $ maybe "" id . lookup "ghc" . read')
23+
24+
if [[ "$(getExecutablePath "$default_ghc")" != "$(getExecutablePath "$doctest_ghc")" ]]
25+
then
26+
echo "Incompatible GHC's:" >&2
27+
echo " Default ghc: $(getExecutablePath "$default_ghc")" >&2
28+
echo " Doctest ghc: $(getExecutablePath "$doctest_ghc")" >&2
29+
exit 1
30+
fi
731

832
# Ensure the cabal-doctest executable can be found
933
PATH=$(cabal path --installdir):$PATH
@@ -21,9 +45,10 @@ cardano-ledger-api:lib:cardano-ledger-api --build-depends=cardano-ledger-babbage
2145
EOF
2246

2347
# Run the doctests for some or all packages
24-
cabal-targets.hs "$@" |
48+
cabal-targets.hs "${PACKAGES[@]}" |
2549
sort | join -t' ' -a1 -j1 - "$EXTRA_ARGS" |
2650
while read -ra ARGS
2751
do
52+
echo "***** cabal doctest ${ARGS[0]} *****"
2853
cabal doctest --repl-options='-w -Wdefault' "${ARGS[@]}"
2954
done

0 commit comments

Comments
 (0)