Cabal fails to re-link test-suite binary when a library dependency has changed
Describe the bug
Sometimes cabal test doesn't relink the test-suite executable when it should. I can verify this by removing the executable and then re-running cabal test, and I get different results.
To Reproduce I haven't boiled this down to a minimal repro, but I see it quite regularly with Glean (https://hackage.haskell.org/package/glean). I'm hoping the following gives you enough to be able to construct a minimal repro or track down the bug.
Just now I demonstrated the problem as follows:
-
cabal test glean-snapshot-typescript(works) - modify the file
stubs/TestRunner.hsin a way that will make the test fail. This file belongs to a local librarystubsthat is a dependency of theglean-snapshot-typescripttest-suite. -
cabal test glean-snapshot-typescript(works) -
rm $(cabal list-bin glean-snapshot-typescript) -
cabal test glean-snapshot-typescript(fails)
Here is the output from steps 3 onwards, showing that it recompiled the modified source file but didn't re-link the executable:
> cabal test glean-snapshot-typescript
Configuration is affected by the following files:
- cabal.project
Build profile: -w ghc-9.4.7 -O1
In order, the following will be built (use -v for more details):
- glean-0.1.0.0 (lib:stubs) (file glean/github/TestRunner.hs changed)
- glean-0.1.0.0 (lib:util) (dependency rebuilt)
- glean-0.1.0.0 (lib:defaultconfigs) (dependency rebuilt)
- glean-0.1.0.0 (lib:core) (dependency rebuilt)
- glean-0.1.0.0 (lib:typed) (dependency rebuilt)
- glean-0.1.0.0 (lib:schema) (dependency rebuilt)
- glean-0.1.0.0 (lib:backend-api) (dependency rebuilt)
- glean-0.1.0.0 (lib:write) (dependency rebuilt)
- glean-0.1.0.0 (lib:haxl-datasource) (dependency rebuilt)
- glean-0.1.0.0 (lib:db) (dependency rebuilt)
- glean-0.1.0.0 (lib:client-hs) (dependency rebuilt)
- glean-0.1.0.0 (lib:backend-local) (dependency rebuilt)
- glean-0.1.0.0 (lib:lib-derive) (dependency rebuilt)
- glean-0.1.0.0 (lib:lib) (dependency rebuilt)
- glean-0.1.0.0 (lib:test-lib) (dependency rebuilt)
- glean-0.1.0.0 (lib:handler) (dependency rebuilt)
- glean-0.1.0.0 (lib:client-hs-local) (dependency rebuilt)
- glean-0.1.0.0 (lib:indexers) (dependency rebuilt)
- glean-0.1.0.0 (lib:regression-test-lib) (dependency rebuilt)
- glean-0.1.0.0 (test:glean-snapshot-typescript) (dependency rebuilt)
Preprocessing library 'stubs' for glean-0.1.0.0...
Building library 'stubs' for glean-0.1.0.0...
[10 of 11] Compiling TestRunner ( glean/github/TestRunner.hs, dist-newstyle/build/x86_64-linux/ghc-9.4.7/glean-0.1.0.0/l/stubs/build/stubs/TestRunner.o, dist-newstyle/build/x86_64-linux/ghc-9.4.7/glean-0.1.0.0/l/stubs/build/stubs/TestRunner.dyn_o ) [Source file changed]
Preprocessing library 'util' for glean-0.1.0.0...
Building library 'util' for glean-0.1.0.0...
Preprocessing library 'defaultconfigs' for glean-0.1.0.0...
Building library 'defaultconfigs' for glean-0.1.0.0...
Preprocessing library 'core' for glean-0.1.0.0...
Building library 'core' for glean-0.1.0.0...
Preprocessing library 'typed' for glean-0.1.0.0...
Building library 'typed' for glean-0.1.0.0...
Preprocessing library 'schema' for glean-0.1.0.0...
Preprocessing library 'backend-api' for glean-0.1.0.0...
Building library 'backend-api' for glean-0.1.0.0...
Building library 'schema' for glean-0.1.0.0...
Preprocessing library 'write' for glean-0.1.0.0...
Building library 'write' for glean-0.1.0.0...
Preprocessing library 'haxl-datasource' for glean-0.1.0.0...
Building library 'haxl-datasource' for glean-0.1.0.0...
Preprocessing library 'db' for glean-0.1.0.0...
Building library 'db' for glean-0.1.0.0...
Preprocessing library 'client-hs' for glean-0.1.0.0...
Building library 'client-hs' for glean-0.1.0.0...
Preprocessing library 'backend-local' for glean-0.1.0.0...
Building library 'backend-local' for glean-0.1.0.0...
Preprocessing library 'lib-derive' for glean-0.1.0.0...
Building library 'lib-derive' for glean-0.1.0.0...
Preprocessing library 'lib' for glean-0.1.0.0...
Building library 'lib' for glean-0.1.0.0...
Preprocessing library 'test-lib' for glean-0.1.0.0...
Building library 'test-lib' for glean-0.1.0.0...
Preprocessing library 'handler' for glean-0.1.0.0...
Building library 'handler' for glean-0.1.0.0...
Preprocessing library 'client-hs-local' for glean-0.1.0.0...
Building library 'client-hs-local' for glean-0.1.0.0...
Preprocessing library 'indexers' for glean-0.1.0.0...
Building library 'indexers' for glean-0.1.0.0...
Preprocessing library 'regression-test-lib' for glean-0.1.0.0...
Building library 'regression-test-lib' for glean-0.1.0.0...
Preprocessing test suite 'glean-snapshot-typescript' for glean-0.1.0.0...
Building test suite 'glean-snapshot-typescript' for glean-0.1.0.0...
Running 1 test suites...
Test suite glean-snapshot-typescript: RUNNING...
testx
xrefs: I20251017 15:37:07.083879 1524235 Env.hs:65] Using schema from dir:glean/schema/source
I20251017 15:37:07.483327 1524235 Open.hs:493] test/xrefs: opening
I20251017 15:37:07.750891 1524235 ownership.cpp:196] loadOwnershipSets loaded 0 sets, 0 bytes
I20251017 15:37:07.750967 1524235 Open.hs:499] test/xrefs: opened
I20251017 15:37:08.316260 1524235 Open.hs:501] test/xrefs: schema has 1203 predicates
I20251017 15:37:08.338789 1524235 Create.hs:143] test/xrefs: created
I20251017 15:37:08.339215 1524235 Driver.hs:70] Indexing xrefs with scip-typescript
I20251017 15:37:08.339263 1524235 Driver.hs:72] Running command: scip-typescript index --no-progress-bar --cwd /home/simon/code/Glean/glean/lang/typescript/tests/cases/xrefs --output /tmp/glean-scip-5376e891e7f9c792/index.scip
+ /home/simon/code/Glean/glean/lang/typescript/tests/cases/xrefs (134ms)
done /tmp/glean-scip-5376e891e7f9c792/index.scip
I20251017 15:37:10.393586 1524235 Driver.hs:84] Using SCIP from /tmp/glean-scip-5376e891e7f9c792/index.scip
I20251017 15:37:10.397986 1524235 Stats.hs:222] mut_lat: 12us [ 12us] mut_thp: - [ -] ded_thp: - [ -] dup_thp: - [ -] rnm_thp: - [ -] cmt_thp: - [ -] ibk_mis: - [ -] tbi_mis: - [ -] fbi_mis: - [ -] lch_mem: 0B lch_cnt: 0
scip.LowerCaseDisplayNameSymbol : 0 facts
scip.DefinitionLocation : 25 facts
scip.ReferenceLocation : 36 facts
scip.SymbolDisplayName : 0 facts
scip.IsImplemented : 0 facts
I20251017 15:37:10.452319 1524235 CompletePredicates.hs:78] ownership propagation complete: 0 units (0 bytes), 0 sets (0 bytes), 0 owners (0 bytes)
I20251017 15:37:10.480151 1524235 Backup.hs:394] final ownership: 0 units (0 bytes), 0 sets (0 bytes), 1 owners (1.16 kiB), 0 orphan facts
I20251017 15:37:10.480191 1524235 Backup.hs:396] test/xrefs: finalize: optimizing
I20251017 15:37:10.671909 1524235 Open.hs:417] updating schema for: test/xrefs
I20251017 15:37:11.041214 1524235 Open.hs:436] done updating schema for open DBs
I20251017 15:37:11.041271 1524235 Backup.hs:411] test/xrefs: finalize: finished
OK (4.70s)
All 1 tests passed (4.70s)
Test suite glean-snapshot-typescript: PASS
Test suite logged to:
/home/simon/code/Glean/./dist-newstyle/build/x86_64-linux/ghc-9.4.7/glean-0.1.0.0/t/glean-snapshot-typescript/test/glean-0.1.0.0-glean-snapshot-typescript.log
1 of 1 test suites (1 of 1 test cases) passed.
75.24s real 115.39s user 24.00s system 185% cabal test glean-snapshot-typescript
~/code/Glean > rm /home/simon/code/Glean/dist-newstyle/build/x86_64-linux/ghc-9.4.7/glean-0.1.0.0/t/glean-snapshot-typescript/build/glean-snapshot-typescript/glean-snapshot-typescript
removed '/home/simon/code/Glean/dist-newstyle/build/x86_64-linux/ghc-9.4.7/glean-0.1.0.0/t/glean-snapshot-typescript/build/glean-snapshot-typescript/glean-snapshot-typescript'
~/code/Glean > cabal test glean-snapshot-typescript
Configuration is affected by the following files:
- cabal.project
Build profile: -w ghc-9.4.7 -O1
In order, the following will be built (use -v for more details):
- glean-0.1.0.0 (test:glean-snapshot-typescript) (ephemeral targets)
Preprocessing test suite 'glean-snapshot-typescript' for glean-0.1.0.0...
Building test suite 'glean-snapshot-typescript' for glean-0.1.0.0...
[2 of 2] Linking dist-newstyle/build/x86_64-linux/ghc-9.4.7/glean-0.1.0.0/t/glean-snapshot-typescript/build/glean-snapshot-typescript/glean-snapshot-typescript
Running 1 test suites...
Test suite glean-snapshot-typescript: RUNNING...
testx
xrefs: FAIL
Exception: Prelude.undefined
CallStack (from HasCallStack):
undefined, called at glean/github/TestRunner.hs:68:7 in glean-0.1.0.0-inplace-stubs:TestRunner
1 out of 1 tests failed (0.00s)
Test suite glean-snapshot-typescript: FAIL
Test suite logged to:
/home/simon/code/Glean/./dist-newstyle/build/x86_64-linux/ghc-9.4.7/glean-0.1.0.0/t/glean-snapshot-typescript/test/glean-0.1.0.0-glean-snapshot-typescript.log
0 of 1 test suites (0 of 1 test cases) passed.
Error: [Cabal-7125]
Tests failed for test:glean-snapshot-typescript from glean-0.1.0.0.
Expected behavior
cabal test ... performs necessary build steps to bring everything up to date
System information
- Ubuntu 24.04.3 LTS
> cabal --version
cabal-install version 3.14.2.0
compiled using version 3.14.2.0 of the Cabal library
> ghc --version
The Glorious Glasgow Haskell Compilation System, version 9.4.7
Additional context
This is supposedly fixed in GHC version just one step past the one you use in your repro: https://github.com/haskell/cabal/issues/7711#issuecomment-1948000159
Please kindly confirm.
@simonmar: did upgrading GHC help?
@Mikolaj sorry I didn't see the response earlier. It's non-trivial for me to upgrade GHC right now but looking at linked issue I'm fairly sure that is the bug, so I'll close this one and re-open if I see it again. Thanks!
Let's hope it's indeed fixed. Welcome back @simonmar! :)