@@ -167,6 +167,7 @@ import Distribution.Solver.Types.Settings
167167import Distribution.Solver.Types.SolverId
168168import Distribution.Solver.Types.SolverPackage
169169import Distribution.Solver.Types.SourcePackage
170+ import Distribution.Solver.Types.Stage
170171
171172import Distribution.ModuleName
172173import Distribution.Package
@@ -219,9 +220,10 @@ import qualified Distribution.Simple.GHC as GHC
219220import qualified Distribution.Simple.GHCJS as GHCJS
220221import qualified Distribution.Simple.InstallDirs as InstallDirs
221222import qualified Distribution.Simple.LocalBuildInfo as Cabal
223+ import qualified Distribution.Simple.PackageIndex as PI
222224import qualified Distribution.Simple.Setup as Cabal
223225import qualified Distribution.Solver.Types.ComponentDeps as CD
224- import Distribution.Solver.Types.Stage
226+ -- import Distribution.Solver.Types.Stage
225227import Distribution.Solver.Types.Toolchain
226228
227229import qualified Distribution.Compat.Graph as Graph
@@ -770,11 +772,38 @@ rebuildInstallPlan
770772 , hookHashes
771773 )
772774 $ do
775+ -- InstalledPackageIndex
776+ -- type InstalledPackageIndex = PackageIndex IPI.InstalledPackageInfo
777+ -- data PackageIndex a = PackageIndex
778+ -- { -- The primary index. Each InstalledPackageInfo record is uniquely identified
779+ -- -- by its UnitId.
780+ -- --
781+ -- unitIdIndex :: !(Map UnitId a)
782+ -- , -- This auxiliary index maps package names (case-sensitively) to all the
783+ -- -- versions and instances of that package. This allows us to find all
784+ -- -- versions satisfying a dependency.
785+ -- --
786+ -- -- It is a three-level index. The first level is the package name,
787+ -- -- the second is the package version and the final level is instances
788+ -- -- of the same package version. These are unique by UnitId
789+ -- -- and are kept in preference order.
790+ -- --
791+ -- -- FIXME: Clarify what "preference order" means. Check that this invariant is
792+ -- -- preserved. See #1463 for discussion.
793+ -- packageIdIndex :: !(Map (PackageName, LibraryName) (Map Version [a]))
794+ -- }
795+ -- deriving (Eq, Generic, Show, Read)
796+ --
797+ -- can probably use fromList $ Map.elems $ on it.
773798 hinstalledPkgIndex <-
774799 getInstalledPackages
775800 verbosity
776801 (hostToolchain toolchains)
777802 corePackageDbs
803+ -- this is an aweful hack, however `getInstalledPackages` is
804+ -- terribly invovled everywhere so we'll have to do with this
805+ -- for now. FIXME!
806+ -- let hinstalledPkgIndex' = PI.fromList $ PI.allPackages hinstalledPkgIndex
778807 binstalledPkgIndex <-
779808 getInstalledPackages
780809 verbosity
@@ -797,6 +826,8 @@ rebuildInstallPlan
797826
798827 liftIO $ do
799828 notice verbosity " Resolving dependencies..."
829+ liftIO $ print (" build compiler" , compilerId $ toolchainCompiler $ buildToolchain toolchains)
830+ liftIO $ print (" host compiler" , compilerId $ toolchainCompiler $ hostToolchain toolchains)
800831 planOrError <-
801832 foldProgress logMsg (pure . Left ) (pure . Right ) $
802833 planPackages
@@ -2275,8 +2306,8 @@ elaborateInstallPlan
22752306 then BuildInplaceOnly OnDisk
22762307 else BuildAndInstall
22772308 elabPackageDbs = projectConfigPackageDBs sharedPackageConfig
2278- elabBuildPackageDBStack = buildAndRegisterDbs
2279- elabRegisterPackageDBStack = buildAndRegisterDbs
2309+ elabBuildPackageDBStack = buildAndRegisterDbs stage
2310+ elabRegisterPackageDBStack = buildAndRegisterDbs stage
22802311
22812312 elabSetupScriptStyle = packageSetupScriptStyle elabPkgDescription
22822313 elabSetupScriptCliVersion =
@@ -2285,19 +2316,25 @@ elaborateInstallPlan
22852316 elabPkgDescription
22862317 libDepGraph
22872318 deps0
2288- elabSetupPackageDBStack = buildAndRegisterDbs
22892319
2290- inplacePackageDbs = corePackageDbs ++ [distPackageDB (compilerId elabCompiler)]
2320+ -- This code is ... a bit nuts. We need to parameterise the DB stack
2321+ -- over the stage. (which is also assigned to elabStage). And now
2322+ -- we have inplace, core, ... other DBStacks, for the Setup however,
2323+ -- we _must_ force it to use the Build stage stack. As that's where
2324+ -- the setup dependencies will be found.
2325+ elabSetupPackageDBStack = buildAndRegisterDbs Build
2326+
2327+ inplacePackageDbs stage = corePackageDbs stage ++ [distPackageDB (compilerId (toolchainCompiler (toolchainFor stage toolchains)))]
22912328
2292- corePackageDbs = storePackageDBStack elabCompiler (projectConfigPackageDBs sharedPackageConfig)
2329+ corePackageDbs stage = storePackageDBStack (toolchainCompiler (toolchainFor stage toolchains)) (projectConfigPackageDBs sharedPackageConfig)
22932330
2294- elabInplaceBuildPackageDBStack = inplacePackageDbs
2295- elabInplaceRegisterPackageDBStack = inplacePackageDbs
2296- elabInplaceSetupPackageDBStack = inplacePackageDbs
2331+ elabInplaceBuildPackageDBStack = inplacePackageDbs stage
2332+ elabInplaceRegisterPackageDBStack = inplacePackageDbs stage
2333+ elabInplaceSetupPackageDBStack = inplacePackageDbs stage
22972334
2298- buildAndRegisterDbs
2299- | shouldBuildInplaceOnly pkg = inplacePackageDbs
2300- | otherwise = corePackageDbs
2335+ buildAndRegisterDbs stage
2336+ | shouldBuildInplaceOnly pkg = inplacePackageDbs stage
2337+ | otherwise = corePackageDbs stage
23012338
23022339 elabPkgDescriptionOverride = descOverride
23032340
@@ -3877,10 +3914,10 @@ setupHsScriptOptions
38773914 -- - if we commit to a Cabal version, the logic in
38783915 Nothing
38793916 else Just elabSetupScriptCliVersion
3880- , -- for Setup.hs, we _always_ want to use the HOST toolchain.
3881- useCompiler = Just (toolchainCompiler $ hostToolchain $ pkgConfigToolchains)
3882- , usePlatform = Just (toolchainPlatform $ hostToolchain $ pkgConfigToolchains)
3883- , useProgramDb = toolchainProgramDb $ hostToolchain $ pkgConfigToolchains
3917+ , -- for Setup.hs, we _always_ want to use the BUILD toolchain.
3918+ useCompiler = Just (toolchainCompiler $ buildToolchain $ pkgConfigToolchains)
3919+ , usePlatform = Just (toolchainPlatform $ buildToolchain $ pkgConfigToolchains)
3920+ , useProgramDb = toolchainProgramDb $ buildToolchain $ pkgConfigToolchains
38843921 , usePackageDB = elabSetupPackageDBStack
38853922 , usePackageIndex = Nothing
38863923 , useDependencies =
0 commit comments