Commit 9f72f58c authored by Duncan Coutts's avatar Duncan Coutts

Add cabal install --reinstall flag

to force reinstall of package where we have the exact same
version already installed. Ordinarily we would say that
there is nothing to do as the exact same package version
is already installed. There are some cases where you might
want to do this, eg to rebuild with different compiler
options, or adding/removing components (since we do not
track those indifidually yet, eg docs, profiling libs).
parent 49eb8ee3
......@@ -76,7 +76,8 @@ import Distribution.Simple.InstallDirs
( fromPathTemplate, toPathTemplate
, initialPathTemplateEnv, substPathTemplate )
import Distribution.Package
( PackageIdentifier(..), Package(..), thisPackageVersion )
( PackageIdentifier(..), Package(..), thisPackageVersion
, Dependency(..) )
import qualified Distribution.PackageDescription as PackageDescription
import Distribution.PackageDescription
( PackageDescription, readPackageDescription )
......@@ -118,7 +119,8 @@ install verbosity packageDB repos comp conf configFlags installFlags deps =
where
planner :: Planner
planner | null deps = planLocalPackage verbosity comp configFlags
| otherwise = planRepoPackages PreferLatestForSelected comp deps
| otherwise = planRepoPackages PreferLatestForSelected
comp installFlags deps
upgrade verbosity packageDB repos comp conf configFlags installFlags deps =
installWithPlanner planner
......@@ -126,7 +128,8 @@ upgrade verbosity packageDB repos comp conf configFlags installFlags deps =
where
planner :: Planner
planner | null deps = planUpgradePackages comp
| otherwise = planRepoPackages PreferAllLatest comp deps
| otherwise = planRepoPackages PreferAllLatest
comp installFlags deps
type Planner = Maybe (PackageIndex InstalledPackageInfo)
-> PackageIndex AvailablePackage
......@@ -252,12 +255,20 @@ planLocalPackage verbosity comp configFlags installed available = do
-- | Make an 'InstallPlan' for the given dependencies.
--
planRepoPackages :: PackagesVersionPreference -> Compiler
planRepoPackages :: PackagesVersionPreference -> Compiler -> InstallFlags
-> [UnresolvedDependency] -> Planner
planRepoPackages pref comp deps installed available = do
planRepoPackages pref comp installFlags deps installed available = do
deps' <- IndexUtils.disambiguateDependencies available deps
let installed'
| Cabal.fromFlag (installReinstall installFlags)
= fmap (hideGivenDeps deps') installed
| otherwise = installed
return $ resolveDependenciesWithProgress buildOS buildArch (compilerId comp)
installed available pref deps'
installed' available pref deps'
where
hideGivenDeps pkgs index =
foldr PackageIndex.deletePackageName index
[ name | UnresolvedDependency (Dependency name _) _ <- pkgs ]
planUpgradePackages :: Compiler -> Planner
planUpgradePackages comp (Just installed) available = return $
......
......@@ -211,6 +211,7 @@ instance Monoid ListFlags where
data InstallFlags = InstallFlags {
installDocumentation:: Flag Bool,
installDryRun :: Flag Bool,
installReinstall :: Flag Bool,
installOnly :: Flag Bool,
installRootCmd :: Flag String,
installCabalVersion :: Flag Version,
......@@ -223,6 +224,7 @@ defaultInstallFlags :: InstallFlags
defaultInstallFlags = InstallFlags {
installDocumentation= Flag False,
installDryRun = Flag False,
installReinstall = Flag False,
installOnly = Flag False,
installRootCmd = mempty,
installCabalVersion = mempty,
......@@ -250,6 +252,11 @@ installCommand = configureCommand {
installDryRun (\v flags -> flags { installDryRun = v })
trueArg
, option [] ["reinstall"]
"Install even if it means installing the same version again."
installReinstall (\v flags -> flags { installReinstall = v })
trueArg
, option [] ["root-cmd"]
"Command used to gain root privileges, when installing with --global."
installRootCmd (\v flags -> flags { installRootCmd = v })
......@@ -288,6 +295,7 @@ instance Monoid InstallFlags where
mappend a b = InstallFlags {
installDocumentation= combine installDocumentation,
installDryRun = combine installDryRun,
installReinstall = combine installReinstall,
installOnly = combine installOnly,
installRootCmd = combine installRootCmd,
installCabalVersion = combine installCabalVersion,
......
Markdown is supported
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