From e8a7716e251d4bed771d0d0e20c95347170b10d8 Mon Sep 17 00:00:00 2001 From: Javier Sagredo Date: Fri, 19 Jun 2026 01:19:40 +0200 Subject: [PATCH] classgraph-plugin-flag.sh: offer every store-registered version MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit The store can register several classgraph versions in one db (e.g. 0.2.0.0 alongside 0.2.1.0). The discovery code took only `head -1` of ghc-pkg's id/library-dirs output, locking onto whichever version sorted first and reconstructing its .so name — which may not even exist on disk, leaving the store contributing no candidate at all. Iterate over every library-dir ghc-pkg reports and glob for the actual .so in each, so all present builds become candidates and the chooser can disambiguate. Co-Authored-By: Claude Opus 4.8 (1M context) --- classgraph-plugin-flag.sh | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/classgraph-plugin-flag.sh b/classgraph-plugin-flag.sh index a425045..dbb0a70 100755 --- a/classgraph-plugin-flag.sh +++ b/classgraph-plugin-flag.sh @@ -137,21 +137,29 @@ else # 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 -- 2.54.0