@@ -130,7 +130,7 @@ import Stack.Types.GhcPkgId ( GhcPkgId, ghcPkgIdToText )
130130import Stack.Types.GlobalOpts ( GlobalOpts (.. ) )
131131import Stack.Types.Installed
132132 ( InstallLocation (.. ), Installed (.. ), InstalledMap
133- , InstalledLibraryInfo (.. )
133+ , InstalledLibraryInfo (.. ), simpleInstalledLib
134134 )
135135import Stack.Types.IsMutable ( IsMutable (.. ) )
136136import Stack.Types.NamedComponent
@@ -139,8 +139,7 @@ import Stack.Types.NamedComponent
139139 )
140140import Stack.Types.Package
141141 ( LocalPackage (.. ), Package (.. ), installedPackageToGhcPkgId
142- , runMemoizedWith , simpleInstalledLib
143- , toCabalMungedPackageName
142+ , runMemoizedWith , toCabalMungedPackageName
144143 )
145144import Stack.Types.PackageFile ( PackageWarning (.. ) )
146145import Stack.Types.Plan
@@ -164,7 +163,7 @@ getConfigCache ::
164163 -> InstalledMap
165164 -> Bool
166165 -> Bool
167- -> RIO env (Map PackageIdentifier GhcPkgId , ConfigCache )
166+ -> RIO env (Map MungedPackageId GhcPkgId , ConfigCache )
168167getConfigCache ee task installedMap enableTest enableBench = do
169168 let extra =
170169 -- We enable tests if the test suite dependencies are already
@@ -425,7 +424,7 @@ realConfigAndBuild ::
425424 -- ^ (isFinalBuild, buildingFinals)
426425 -> ConfigCache
427426 -> Maybe Curator
428- -> Map PackageIdentifier GhcPkgId
427+ -> Map MungedPackageId GhcPkgId
429428 -- ^ Ids of installed packages that are assumed to be available to build a
430429 -- package's custom @Setup.hs@, given its dependencies specified in its
431430 -- @custom-setup@ stanza of its Cabal file.
@@ -726,27 +725,28 @@ fetchAndMarkInstalledPackage ::
726725 -> PackageIdentifier
727726 -> RIO env Installed
728727fetchAndMarkInstalledPackage ee taskInstallLocation package pkgId = do
729- let ghcPkgIdLoader = fetchGhcPkgIdForLib ee taskInstallLocation package. name
730- -- Only pure the sub-libraries to cache them if we also cache the main
731- -- library (that is, if it exists)
732- if hasBuildableMainLibrary package
728+ let hasMainLibrary = hasBuildableMainLibrary package
729+ subLibs = package. subLibraries
730+ if not hasMainLibrary && null subLibs
733731 then do
734- let foldSubLibToMap subLib mapInMonad = do
735- maybeGhcpkgId <- ghcPkgIdLoader (Just subLib. name)
736- mapInMonad <&> case maybeGhcpkgId of
737- Just v -> Map. insert subLib. name v
738- _ -> id
739- subLibsPkgIds <- foldComponentToAnotherCollection
740- package. subLibraries
741- foldSubLibToMap
742- mempty
743- ghcPkgIdLoader Nothing >>= \ case
744- Nothing -> throwM $ Couldn'tFindPkgId package. name
745- Just ghcPkgId -> pure $ simpleInstalledLib pkgId ghcPkgId subLibsPkgIds
746- else do
747- markExeInstalled taskInstallLocation pkgId -- TODO unify somehow
748- -- with writeFlagCache?
732+ markExeInstalled taskInstallLocation pkgId
733+ -- TODO: Unify the above somehow with writeFlagCache?
749734 pure $ Executable pkgId
735+ else do
736+ ghcPkgId <- if hasMainLibrary
737+ then ghcPkgIdLoader Nothing
738+ else pure Nothing
739+ subLibsPkgIds <-
740+ foldComponentToAnotherCollection subLibs foldSubLibToMap mempty
741+ pure $ simpleInstalledLib pkgId ghcPkgId subLibsPkgIds
742+ where
743+ ghcPkgIdLoader = fetchGhcPkgIdForLib ee taskInstallLocation package. name
744+
745+ foldSubLibToMap subLib mapInMonad = do
746+ maybeGhcpkgId <- ghcPkgIdLoader (Just subLib. name)
747+ mapInMonad <&> case maybeGhcpkgId of
748+ Just v -> Map. insert subLib. name v
749+ _ -> id
750750
751751fetchGhcPkgIdForLib ::
752752 (HasTerm env , HasEnvConfig env )
@@ -755,7 +755,7 @@ fetchGhcPkgIdForLib ::
755755 -> PackageName
756756 -> Maybe Component. StackUnqualCompName
757757 -> RIO env (Maybe GhcPkgId )
758- fetchGhcPkgIdForLib ee installLocation pkgName libName = do
758+ fetchGhcPkgIdForLib ee installLocation pkgName mLibName = do
759759 let baseConfigOpts = ee. baseConfigOpts
760760 (installedPkgDb, installedDumpPkgsTVar) =
761761 case installLocation of
@@ -766,11 +766,9 @@ fetchGhcPkgIdForLib ee installLocation pkgName libName = do
766766 ( baseConfigOpts. localDB
767767 , ee. localDumpPkgs )
768768 let commonLoader = loadInstalledPkg [installedPkgDb] installedDumpPkgsTVar
769- case libName of
770- Nothing -> commonLoader pkgName
771- Just v -> do
772- let mungedName = encodeCompatPackageName $ toCabalMungedPackageName pkgName v
773- commonLoader mungedName
769+ mungedPkgName = toCabalMungedPackageName pkgName mLibName
770+ encodedPkgName = encodeCompatPackageName mungedPkgName
771+ commonLoader encodedPkgName
774772
775773-- | Copy ddump-* files, if we are building finals and a non-empty ddump-dir
776774-- has been specified.
@@ -926,7 +924,7 @@ copyPreCompiled ee task pkgId (PrecompiledCache mlib subLibs exes) = do
926924 pure $ Just $
927925 case mpkgid of
928926 Nothing -> assert False $ Executable pkgId
929- Just pkgid -> simpleInstalledLib pkgId pkgid mempty
927+ _ -> simpleInstalledLib pkgId mpkgid mempty
930928 where
931929 bindir = ee. baseConfigOpts. snapInstallRoot </> bindirSuffix
932930
@@ -1067,8 +1065,8 @@ singleTest topts testsToRun ac ee task installedMap = do
10671065 idMap <- liftIO $ readTVarIO ee. ghcPkgIds
10681066 pure $ Map. lookup (taskProvides task) idMap
10691067 let pkgGhcIdList = case installed of
1070- Just (Library _ libInfo) -> [ libInfo. ghcPkgId]
1071- _ -> []
1068+ Just (Library _ libInfo) -> maybeToList libInfo. mMainGhcPkgId
1069+ _ -> []
10721070 -- doctest relies on template-haskell in QuickCheck-based tests
10731071 thGhcId <-
10741072 case L. find ((== " template-haskell" ) . pkgName . (. packageIdent) . snd )
0 commit comments