Commit 8ea46d28 authored by Duncan Coutts's avatar Duncan Coutts
Browse files

Move the upgrade action into the Install module

It shares most code anyway.
Also fixes ticket #260 becuase we use the right entry point now.
parent c4eae641
......@@ -10,9 +10,10 @@
--
-- High level interface to package installation.
-----------------------------------------------------------------------------
module Hackage.Install
( install
) where
module Hackage.Install (
install,
upgrade,
) where
import Data.List
( unfoldr )
......@@ -25,7 +26,7 @@ import System.Directory
( getTemporaryDirectory, doesFileExist )
import System.FilePath ((</>),(<.>))
import Hackage.Dependency (resolveDependencies)
import Hackage.Dependency (resolveDependencies, upgradableDependencies)
import Hackage.Fetch (fetchPackage)
-- import qualified Hackage.Info as Info
import qualified Hackage.IndexUtils as IndexUtils
......@@ -99,6 +100,17 @@ install verbosity packageDB repos comp conf configFlags installFlags deps =
planner | null deps = planLocalPackage verbosity comp configFlags
| otherwise = planRepoPackages comp deps
upgrade :: Verbosity
-> PackageDB
-> [Repo]
-> Compiler
-> ProgramConfiguration
-> Cabal.ConfigFlags
-> InstallFlags
-> IO ()
upgrade verbosity packageDB repos comp =
installWithPlanner (planUpgradePackages comp) verbosity packageDB repos comp
type Planner = Maybe (PackageIndex InstalledPackageInfo)
-> PackageIndex AvailablePackage
-> IO (Either [Dependency] (InstallPlan BuildResult))
......@@ -194,6 +206,19 @@ planRepoPackages comp deps installed available = do
return $ resolveDependencies buildOS buildArch (compilerId comp)
installed available deps'
planUpgradePackages :: Compiler
-> Maybe (PackageIndex InstalledPackageInfo)
-> PackageIndex AvailablePackage
-> IO (Either [Dependency] (InstallPlan BuildResult))
planUpgradePackages comp (Just installed) available = return $
resolveDependencies buildOS buildArch (compilerId comp) (Just installed) available
[ UnresolvedDependency dep []
| dep <- upgradableDependencies installed available ]
planUpgradePackages comp _ _ =
die $ display (compilerId comp)
++ " does not track installed packages so cabal cannot figure out what"
++ " packages need to be upgraded."
printDryRun :: Verbosity -> InstallPlan BuildResult -> IO ()
printDryRun verbosity plan = case unfoldr next plan of
[] -> notice verbosity "No packages to be installed."
......
-----------------------------------------------------------------------------
-- |
-- Module : Hackage.Upgrade
-- Copyright : (c) Isaac Potoczny-Jones 2007
-- License : BSD-like
--
-- Maintainer : ijones@syntaxpolice.org
-- Stability : provisional
-- Portability : portable
--
-- High level interface to package upgrade. Gets list of installed packages
-- and if there are any newer versions available, upgrades them.
-----------------------------------------------------------------------------
module Hackage.Upgrade
( upgrade
) where
import qualified Hackage.IndexUtils as IndexUtils
import Hackage.Dependency (upgradableDependencies)
import Hackage.Install (install)
import Hackage.Types (UnresolvedDependency(..), Repo)
import Hackage.Setup (InstallFlags(..))
import Distribution.Simple.Program (ProgramConfiguration)
import Distribution.Simple.Compiler (Compiler, PackageDB)
import Distribution.Simple.Configure (getInstalledPackages)
import Distribution.Verbosity (Verbosity)
import qualified Distribution.Simple.Setup as Cabal
import Data.Monoid (Monoid(..))
upgrade :: Verbosity
-> PackageDB -> [Repo]
-> Compiler
-> ProgramConfiguration
-> Cabal.ConfigFlags
-> InstallFlags
-> IO ()
upgrade verbosity packageDB repos comp conf configFlags installFlags = do
Just installed <- getInstalledPackages verbosity comp packageDB conf
available <- fmap mconcat (mapM (IndexUtils.readRepoIndex verbosity) repos)
let upgradable = upgradableDependencies installed available
install verbosity packageDB repos comp conf configFlags installFlags
[ UnresolvedDependency dep [] | dep <- upgradable ]
......@@ -30,9 +30,8 @@ import Hackage.Config (SavedConfig(..), savedConfigToConfigFlags,
defaultConfigFile, loadConfig, configRepos,
configPackageDB)
import Hackage.List (list)
import Hackage.Install (install)
import Hackage.Install (install, upgrade)
import Hackage.Update (update)
import Hackage.Upgrade (upgrade)
import Hackage.Fetch (fetch)
import Hackage.Check as Check (check)
--import Hackage.Clean (clean)
......
......@@ -55,7 +55,6 @@ Executable cabal
Hackage.Tar
Hackage.Types
Hackage.Update
Hackage.Upgrade
Hackage.Upload
Hackage.Utils
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment