Skip to content

Commit fafcb55

Browse files
mpickeringsheaf
authored andcommitted
Revert "cabal-install configureCompiler: configure progdb"
This reverts commit 8bdda9c. In configureCompiler the call to configureAllKnownPrograms was too eager. When called it selected the version of tools from PATH (such as alex), and then when a package was configured these tools were passed using `--with-alex` options to configure, which meant that the build-tool-depends versions were not used. (See #10692) Why was this call introduced in the first place? Because configureCompiler would a different result depending on whether: * It is run for the first time, the `ProgramDb` will contain unconfigured programs. * It is run subsequently, `ProgramDb` is read from disk, it does not contain unconfigured programs. Reverting this commit rexposes the bug that the serialised ProgramDb will not contain UnconfiguredPrograms (in the case where reconfiguring is avoided). However, there are no code paths which require this logic in `cabal-install` currently. The configuration phase happens again each time that `Cabal` is called, with a populated `ProgramDb`. We will fix this before the next major `cabal-install` release, but it would not be suitable to backport. In the future we will fix this properly by refactoring `configureCompiler` so that `ProgramDb` is not serialised. The general approach will be to make `configCompilerEx` return a pair of configured programs (`ghc` and `ghc-pkg`) and expose an additional function from `Cabal` which uses these two programs to perform the modifications to the `ProgramDb` which `configCompilerEx` performs. Also see #2238 and #9840 Fixes #10692
1 parent 529bd1f commit fafcb55

File tree

3 files changed

+53
-8
lines changed

3 files changed

+53
-8
lines changed

cabal-install/src/Distribution/Client/ProjectPlanning.hs

+45-6
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,7 @@ configureCompiler
484484
let fileMonitorCompiler = newFileMonitor $ distProjectCacheFile "compiler"
485485

486486
progsearchpath <- liftIO $ getSystemSearchPath
487+
487488
rerunIfChanged
488489
verbosity
489490
fileMonitorCompiler
@@ -499,7 +500,7 @@ configureCompiler
499500
let extraPath = fromNubList packageConfigProgramPathExtra
500501
progdb <- liftIO $ prependProgramSearchPath verbosity extraPath [] defaultProgramDb
501502
let progdb' = userSpecifyPaths (Map.toList (getMapLast packageConfigProgramPaths)) progdb
502-
(comp, plat, progdb'') <-
503+
result@(_, _, progdb'') <-
503504
liftIO $
504505
Cabal.configCompilerEx
505506
hcFlavor
@@ -516,17 +517,55 @@ configureCompiler
516517
-- programs it cares about, and those are the ones we monitor here.
517518
monitorFiles (programsMonitorFiles progdb'')
518519

519-
-- Configure the unconfigured programs in the program database,
520-
-- as we can't serialise unconfigured programs.
521-
-- See also #2241 and #9840.
522-
finalProgDb <- liftIO $ configureAllKnownPrograms verbosity progdb''
520+
-- Note: There is currently a bug here: we are dropping unconfigured
521+
-- programs from the 'ProgramDb' when we re-use the cache created by
522+
-- 'rerunIfChanged'.
523+
--
524+
-- See Note [Caching the result of configuring the compiler]
523525

524-
return (comp, plat, finalProgDb)
526+
return result
525527
where
526528
hcFlavor = flagToMaybe projectConfigHcFlavor
527529
hcPath = flagToMaybe projectConfigHcPath
528530
hcPkg = flagToMaybe projectConfigHcPkg
529531

532+
{- Note [Caching the result of configuring the compiler]
533+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
534+
We can't straightforwardly cache anything that contains a 'ProgramDb', because
535+
the 'Binary' instance for 'ProgramDb' discards all unconfigured programs.
536+
See that instance, as well as 'restoreProgramDb', for a few more details.
537+
538+
This means that if we try to cache the result of configuring the compiler (which
539+
contains a 'ProgramDb'):
540+
541+
- On the first run, we will obtain a 'ProgramDb' which may contain several
542+
unconfigured programs. In particular, configuring GHC will add tools such
543+
as `ar` and `ld` as unconfigured programs to the 'ProgramDb', with custom
544+
logic for finding their location based on the location of the GHC binary.
545+
- On subsequent runs, if we use the cache created by 'rerunIfChanged', we will
546+
deserialise the 'ProgramDb' from disk, which means it won't include any
547+
unconfigured programs, which might mean we are unable to find 'ar' or 'ld'.
548+
549+
This is not currently a huge problem because, in the Cabal library, we eagerly
550+
re-run the configureCompiler step (thus recovering any lost information), but
551+
this is wasted work that we should stop doing in Cabal, given that cabal-install
552+
has already figured out all the necessary information about the compiler.
553+
554+
To fix this bug, we can't simply eagerly configure all unconfigured programs,
555+
as was originally attempted, for a couple of reasons:
556+
557+
- it does more work than necessary, by configuring programs that we may not
558+
end up needing,
559+
- it means that we prioritise system executables for built-in build tools
560+
(such as `alex` and `happy`), instead of using the proper version for a
561+
package or package component, as specified by a `build-tool-depends` stanza
562+
or by package-level `extra-prog-path` arguments.
563+
This lead to bug reports #10633 and #10692.
564+
565+
See #9840 for more information about the problems surrounding the lossly
566+
Binary ProgramDb instance.
567+
-}
568+
530569
------------------------------------------------------------------------------
531570

532571
-- * Deciding what to do: making an 'ElaboratedInstallPlan'

cabal-testsuite/PackageTests/ExtraProgPath/setup.out

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
# cabal v2-build
2-
Warning: cannot determine version of <ROOT>/pkg-config :
3-
""
42
Configuration is affected by the following files:
53
- cabal.project
4+
Warning: cannot determine version of <ROOT>/pkg-config :
5+
""
6+
Warning: cannot determine version of <ROOT>/pkg-config :
7+
""
68
Resolving dependencies...
79
Error: [Cabal-7107]
810
Could not resolve dependencies:

changelog.d/pr-10731

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
synopsis: Fix regression where build-tool-depends are not used
2+
packages: cabal-install
3+
prs: #10731
4+
issues: #10633 #10692

0 commit comments

Comments
 (0)