]> Repositorios git - classgraph.git/commitdiff
classgraph-plugin-flag.sh: offer every store-registered version
authorJavier Sagredo <[email protected]>
Thu, 18 Jun 2026 23:19:40 +0000 (01:19 +0200)
committerJavier Sagredo <[email protected]>
Thu, 18 Jun 2026 23:19:40 +0000 (01:19 +0200)
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) <[email protected]>
classgraph-plugin-flag.sh

index a425045ae90b826ab68c3935ad8dbb4d3b4b57ea..dbb0a70b21afdac981ab7c9aaaae49dbc520d728 100755 (executable)
@@ -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