Skip to content

Commit

Permalink
Make newly-added add-source deps override previously installed versions.
Browse files Browse the repository at this point in the history
Fixes haskell#1197.

This patch is a bit large because it includes several related changes:

1) Remove 'installUseSandbox' from 'InstallFlags' and pass 'useSandbox' as an
additional argument instead.

2) Instead of calling 'reinstallAddSourceDeps' from 'installAction', always pass
'SandboxPackageInfo' to 'install'.

3) Set the timestamps of newly-added add-source deps to 0 in the timestamp file.

4) Move the timestamp file update to 'postInstallActions' from
'withModifiedDeps'. This way, the timestamps are updated even when the user runs
'install --only-dependencies' or 'install some-add-source-dep-package-id'.
  • Loading branch information
23Skidoo committed May 17, 2013
1 parent b8309fd commit 4a6af2a
Show file tree
Hide file tree
Showing 7 changed files with 207 additions and 145 deletions.
2 changes: 1 addition & 1 deletion cabal-install/Distribution/Client/Dependency.hs
Expand Up @@ -325,7 +325,7 @@ applySandboxInstallPolicy :: SandboxPackageInfo
-> DepResolverParams
-> DepResolverParams
applySandboxInstallPolicy
(SandboxPackageInfo modifiedDeps otherDeps allSandboxPkgs)
(SandboxPackageInfo modifiedDeps otherDeps allSandboxPkgs _allDeps)
params

= addPreferences [ PackageInstalledPreference n PreferInstalled
Expand Down
50 changes: 39 additions & 11 deletions cabal-install/Distribution/Client/Install.hs
Expand Up @@ -29,6 +29,7 @@ module Distribution.Client.Install (

import Data.List
( unfoldr, nub, sort, (\\) )
import qualified Data.Set as S
import Data.Maybe
( isJust, fromMaybe, maybeToList )
import Control.Exception as Exception
Expand Down Expand Up @@ -66,7 +67,10 @@ import Distribution.Client.Setup
, ConfigExFlags(..), InstallFlags(..) )
import Distribution.Client.Config
( defaultCabalDir )
import Distribution.Client.Sandbox.Types ( SandboxPackageInfo(..), isUseSandbox )
import Distribution.Client.Sandbox.Timestamp
( withUpdateTimestamps )
import Distribution.Client.Sandbox.Types
( SandboxPackageInfo(..), UseSandbox(..), isUseSandbox )
import Distribution.Client.Tar (extractTarGzFile)
import Distribution.Client.Types as Source
import Distribution.Client.BuildReports.Types
Expand Down Expand Up @@ -120,7 +124,8 @@ import Distribution.Version
import Distribution.Simple.Utils as Utils
( notice, info, warn, debugNoWrap, die, intercalate, withTempDirectory )
import Distribution.Client.Utils
( numberOfProcessors, inDir, mergeBy, MergeResult(..) )
( numberOfProcessors, inDir, mergeBy, MergeResult(..)
, tryCanonicalizePath )
import Distribution.System
( Platform, OS(Windows), buildOS )
import Distribution.Text
Expand Down Expand Up @@ -154,6 +159,7 @@ install
-> Compiler
-> Platform
-> ProgramConfiguration
-> UseSandbox
-> Maybe SandboxPackageInfo
-> GlobalFlags
-> ConfigFlags
Expand All @@ -162,7 +168,7 @@ install
-> HaddockFlags
-> [UserTarget]
-> IO ()
install verbosity packageDBs repos comp platform conf mSandboxPkgInfo
install verbosity packageDBs repos comp platform conf useSandbox mSandboxPkgInfo
globalFlags configFlags configExFlags installFlags haddockFlags
userTargets0 = do

Expand All @@ -173,7 +179,7 @@ install verbosity packageDBs repos comp platform conf mSandboxPkgInfo
processInstallPlan verbosity args installContext installPlan
where
args :: InstallArgs
args = (packageDBs, repos, comp, platform, conf, mSandboxPkgInfo,
args = (packageDBs, repos, comp, platform, conf, useSandbox, mSandboxPkgInfo,
globalFlags, configFlags, configExFlags, installFlags,
haddockFlags)

Expand All @@ -192,6 +198,7 @@ type InstallArgs = ( PackageDBStack
, Compiler
, Platform
, ProgramConfiguration
, UseSandbox
, Maybe SandboxPackageInfo
, GlobalFlags
, ConfigFlags
Expand All @@ -203,7 +210,7 @@ type InstallArgs = ( PackageDBStack
makeInstallContext :: Verbosity -> InstallArgs -> Maybe [UserTarget]
-> IO InstallContext
makeInstallContext verbosity
(packageDBs, repos, comp, _, conf,_,
(packageDBs, repos, comp, _, conf,_,_,
globalFlags, _, _, _, _) mUserTargets = do

installedPkgIndex <- getInstalledPackages verbosity comp packageDBs conf
Expand Down Expand Up @@ -233,7 +240,7 @@ makeInstallContext verbosity
makeInstallPlan :: Verbosity -> InstallArgs -> InstallContext
-> IO (Progress String String InstallPlan)
makeInstallPlan verbosity
(_, _, comp, platform, _, mSandboxPkgInfo,
(_, _, comp, platform, _, _, mSandboxPkgInfo,
_, configFlags, configExFlags, installFlags,
_)
(installedPkgIndex, sourcePkgDb,
Expand All @@ -251,7 +258,7 @@ processInstallPlan :: Verbosity -> InstallArgs -> InstallContext
-> InstallPlan
-> IO ()
processInstallPlan verbosity
args@(_,_, _, _, _, _, _, _, _, installFlags, _)
args@(_,_, _, _, _, _, _, _, _, _, installFlags, _)
(installedPkgIndex, sourcePkgDb,
userTargets, pkgSpecifiers) installPlan = do
checkPrintPlan verbosity installedPkgIndex installPlan sourcePkgDb
Expand Down Expand Up @@ -618,8 +625,8 @@ postInstallActions :: Verbosity
-> InstallPlan
-> IO ()
postInstallActions verbosity
(packageDBs, _, comp, platform, conf, _, globalFlags, configFlags
, _, installFlags, _)
(packageDBs, _, comp, platform, conf, useSandbox, mSandboxPkgInfo
,globalFlags, configFlags, _, installFlags, _)
targets installPlan = do

unless oneShot $
Expand All @@ -643,6 +650,9 @@ postInstallActions verbosity

printBuildFailures installPlan

updateSandboxTimestampsFile useSandbox mSandboxPkgInfo
comp platform installPlan

where
reportingLevel = fromFlag (installBuildReports installFlags)
logsDir = fromFlag (globalLogsDir globalFlags)
Expand Down Expand Up @@ -795,6 +805,24 @@ printBuildFailures plan =
InstallFailed e -> " failed during the final install step."
++ " The exception was:\n " ++ show e

-- | If we're working inside a sandbox and some add-source deps were installed,
-- update the timestamps of those deps.
updateSandboxTimestampsFile :: UseSandbox -> Maybe SandboxPackageInfo
-> Compiler -> Platform -> InstallPlan
-> IO ()
updateSandboxTimestampsFile (UseSandbox sandboxDir)
(Just (SandboxPackageInfo _ _ _ allAddSourceDeps))
comp platform installPlan =
withUpdateTimestamps sandboxDir (compilerId comp) platform $ \_ -> do
let allInstalled = [ pkg | InstallPlan.Installed pkg _
<- InstallPlan.toList installPlan ]
allSrcPkgs = [ pkg | ConfiguredPackage pkg _ _ _ <- allInstalled ]
allPaths = [ pth | LocalUnpackedPackage pth
<- map packageSource allSrcPkgs]
allPathsCanonical <- mapM tryCanonicalizePath allPaths
return $! filter (`S.member` allAddSourceDeps) allPathsCanonical

updateSandboxTimestampsFile _ _ _ _ _ = return ()

-- ------------------------------------------------------------
-- * Actually do the installations
Expand All @@ -815,7 +843,7 @@ performInstallations :: Verbosity
-> InstallPlan
-> IO InstallPlan
performInstallations verbosity
(packageDBs, _, comp, _, conf,_,
(packageDBs, _, comp, _, conf, useSandbox, _,
globalFlags, configFlags, configExFlags, installFlags, haddockFlags)
installedPkgIndex installPlan = do

Expand Down Expand Up @@ -921,7 +949,7 @@ performInstallations verbosity

miscOptions = InstallMisc {
rootCmd = if fromFlag (configUserInstall configFlags)
|| isUseSandbox (installUseSandbox installFlags)
|| (isUseSandbox useSandbox)
then Nothing -- ignore --root-cmd if --user
-- or working inside a sandbox.
else flagToMaybe (installRootCmd installFlags),
Expand Down

0 comments on commit 4a6af2a

Please sign in to comment.