# registers `classgraph`. We ask ghc-pkg per store (rather than
# globbing + head -1) so a store that lacks classgraph is skipped
# instead of masking one that has it.
+ #
+ # A single store can register *several* classgraph versions
+ # (e.g. 0.2.0.0 alongside 0.2.1.0). `field classgraph library-dirs`
+ # prints one line per registered version, so we must look at every
+ # line — a `head -1` here would lock onto whichever version sorts
+ # first and silently ignore the rest. We glob for the .so inside
+ # each library-dir rather than reconstructing its name from the
+ # unit-id, so every present build becomes a candidate and the
+ # chooser below can disambiguate.
if [ -n "$GHC_VER" ]; then
for STORE_DIR in "$HOME/.cabal/store/ghc-${GHC_VER}"*; do
[ -d "$STORE_DIR/package.db" ] || continue
# ghc-pkg exits non-zero for stores that don't register classgraph;
# the trailing `|| true` keeps that expected failure from tripping
# `set -euo pipefail` so we go on to probe the remaining stores.
- UNIT=$(ghc-pkg --package-db="$STORE_DIR/package.db" \
- --simple-output field classgraph id 2>/dev/null \
- | tr ' ' '\n' | head -1 || true)
- [ -n "$UNIT" ] || continue
- LIBDIR=$(ghc-pkg --package-db="$STORE_DIR/package.db" \
+ while IFS= read -r LIBDIR; do
+ [ -n "$LIBDIR" ] || continue
+ for so in "$LIBDIR"/libHSclassgraph-*-ghc"${GHC_VER}".so; do
+ [ -f "$so" ] && CANDIDATES+=("$so")
+ done
+ done < <(ghc-pkg --package-db="$STORE_DIR/package.db" \
--simple-output field classgraph library-dirs 2>/dev/null \
- | tr ' ' '\n' | head -1 || true)
- candidate="$LIBDIR/libHS${UNIT}-ghc${GHC_VER}.so"
- [ -f "$candidate" ] && CANDIDATES+=("$candidate")
+ | tr ' ' '\n' || true)
done
fi
fi