From 0d15edef7baba7c839530b496ee61f968c3aa7a4 Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Tue, 18 Oct 2016 16:39:25 -0700 Subject: [PATCH] Update installedPkgs with internal deps. Signed-off-by: Edward Z. Yang --- Cabal/Distribution/Simple/Build.hs | 23 +++++++++++++++++----- Cabal/Distribution/Types/LocalBuildInfo.hs | 8 +++++++- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/Cabal/Distribution/Simple/Build.hs b/Cabal/Distribution/Simple/Build.hs index 4f09984c9ce..6d6437c1bc0 100644 --- a/Cabal/Distribution/Simple/Build.hs +++ b/Cabal/Distribution/Simple/Build.hs @@ -41,6 +41,7 @@ import qualified Distribution.Simple.JHC as JHC import qualified Distribution.Simple.LHC as LHC import qualified Distribution.Simple.UHC as UHC import qualified Distribution.Simple.HaskellSuite as HaskellSuite +import qualified Distribution.Simple.PackageIndex as Index import qualified Distribution.Simple.Build.Macros as Build.Macros import qualified Distribution.Simple.Build.PathsModule as Build.PathsModule @@ -49,6 +50,7 @@ import qualified Distribution.Simple.Program.HcPkg as HcPkg import Distribution.Simple.Compiler hiding (Flag) import Distribution.PackageDescription hiding (Flag) import qualified Distribution.InstalledPackageInfo as IPI +import Distribution.InstalledPackageInfo (InstalledPackageInfo) import qualified Distribution.ModuleName as ModuleName import Distribution.Simple.Setup @@ -69,6 +71,7 @@ import Distribution.Verbosity import Distribution.Compat.Graph (IsNode(..)) +import Control.Monad import qualified Data.Set as Set import Data.List ( intersect ) import System.FilePath ( (), (<.>), takeDirectory ) @@ -96,7 +99,7 @@ build pkg_descr lbi flags suffixes = do internalPackageDB <- createInternalPackageDB verbosity lbi distPref - for_ componentsToBuild $ \target -> do + (\f -> foldM_ f (installedPkgs lbi) componentsToBuild) $ \index target -> do let comp = targetComponent target clbi = targetCLBI target initialBuildSteps distPref pkg_descr lbi clbi verbosity @@ -104,10 +107,13 @@ build pkg_descr lbi flags suffixes = do progs' = addInternalBuildTools pkg_descr lbi bi (withPrograms lbi) lbi' = lbi { withPrograms = progs', - withPackageDB = withPackageDB lbi ++ [internalPackageDB] + withPackageDB = withPackageDB lbi ++ [internalPackageDB], + installedPkgs = index } - buildComponent verbosity (buildNumJobs flags) pkg_descr + mb_ipi <- buildComponent verbosity (buildNumJobs flags) pkg_descr lbi' suffixes comp clbi distPref + return (maybe index (Index.insert `flip` index) mb_ipi) + return () where distPref = fromFlag (buildDistPref flags) verbosity = fromFlag (buildVerbosity flags) @@ -178,7 +184,7 @@ buildComponent :: Verbosity -> Component -> ComponentLocalBuildInfo -> FilePath - -> IO () + -> IO (Maybe InstalledPackageInfo) buildComponent verbosity numJobs pkg_descr lbi suffixes comp@(CLib lib) clbi distPref = do preprocessComponent pkg_descr comp lbi clbi False verbosity suffixes @@ -195,7 +201,8 @@ buildComponent verbosity numJobs pkg_descr lbi suffixes -- Don't register inplace if we're only building a single component; -- it's not necessary because there won't be any subsequent builds -- that need to tag us - when (not (oneComponentRequested (componentEnabledSpec lbi))) $ do + if (not (oneComponentRequested (componentEnabledSpec lbi))) + then do -- Register the library in-place, so exes can depend -- on internally defined libraries. pwd <- getCurrentDirectory @@ -206,6 +213,8 @@ buildComponent verbosity numJobs pkg_descr lbi suffixes debug verbosity $ "Registering inplace:\n" ++ (IPI.showInstalledPackageInfo installedPkgInfo) registerPackage verbosity (compiler lbi) (withPrograms lbi) HcPkg.MultiInstance (withPackageDB lbi) installedPkgInfo + return (Just installedPkgInfo) + else return Nothing buildComponent verbosity numJobs pkg_descr lbi suffixes comp@(CExe exe) clbi _ = do @@ -215,6 +224,7 @@ buildComponent verbosity numJobs pkg_descr lbi suffixes let ebi = buildInfo exe exe' = exe { buildInfo = addExtraCSources ebi extras } buildExe verbosity numJobs pkg_descr lbi exe' clbi + return Nothing buildComponent verbosity numJobs pkg_descr lbi suffixes @@ -227,6 +237,7 @@ buildComponent verbosity numJobs pkg_descr lbi suffixes let ebi = buildInfo exe exe' = exe { buildInfo = addExtraCSources ebi extras } buildExe verbosity numJobs pkg_descr lbi exe' clbi + return Nothing buildComponent verbosity numJobs pkg_descr lbi0 suffixes @@ -253,6 +264,7 @@ buildComponent verbosity numJobs pkg_descr lbi0 suffixes let ebi = buildInfo exe exe' = exe { buildInfo = addExtraCSources ebi extras } buildExe verbosity numJobs pkg_descr lbi exe' exeClbi + return Nothing -- Can't depend on test suite buildComponent _ _ _ _ _ @@ -271,6 +283,7 @@ buildComponent verbosity numJobs pkg_descr lbi suffixes let ebi = buildInfo exe exe' = exe { buildInfo = addExtraCSources ebi extras } buildExe verbosity numJobs pkg_descr lbi exe' exeClbi + return Nothing buildComponent _ _ _ _ _ diff --git a/Cabal/Distribution/Types/LocalBuildInfo.hs b/Cabal/Distribution/Types/LocalBuildInfo.hs index b9b58d6373a..035da1c6d0e 100644 --- a/Cabal/Distribution/Types/LocalBuildInfo.hs +++ b/Cabal/Distribution/Types/LocalBuildInfo.hs @@ -112,7 +112,13 @@ data LocalBuildInfo = LocalBuildInfo { installedPkgs :: InstalledPackageIndex, -- ^ All the info about the installed packages that the -- current package depends on (directly or indirectly). - -- Does NOT include internal dependencies. + -- The copy saved on disk does NOT include internal + -- dependencies (because we just don't have enough + -- information at this point to have an + -- 'InstalledPackageInfo' for an internal dep), but we + -- will often update it with the internal dependencies; + -- see for example 'Distribution.Simple.Build.build'. + -- (This admonition doesn't apply for per-component builds.) pkgDescrFile :: Maybe FilePath, -- ^ the filename containing the .cabal file, if available localPkgDescr :: PackageDescription,