Skip to content

Commit

Permalink
Disable cabal upgrade and add cabal install --upgrade-dependencies
Browse files Browse the repository at this point in the history
cabal upgrade now gives an error message telling people to use install
or, if they know what they're doing, install --upgrade-dependencies
  • Loading branch information
dcoutts committed May 31, 2010
1 parent bc73fbb commit 0279d0c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 47 deletions.
61 changes: 16 additions & 45 deletions Distribution/Client/Install.hs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ import Distribution.Client.Dependency
, PackageConstraint(..), dependencyConstraints, dependencyTargets
, PackagesPreference(..), PackagesPreferenceDefault(..)
, PackagePreference(..)
, upgradableDependencies
, Progress(..), foldProgress, )
import Distribution.Client.Fetch
( fetchPackage )
Expand Down Expand Up @@ -188,27 +187,28 @@ install verbosity packageDB repos comp conf
| null targets = planLocalPackage verbosity
comp configFlags configExFlags

| otherwise = planRepoPackages PreferLatestForSelected
| otherwise = planRepoPackages defaultPref
comp globalFlags configFlags configExFlags
installFlags targets

defaultPref
| fromFlag (installUpgradeDeps installFlags) = PreferAllLatest
| otherwise = PreferLatestForSelected

upgrade verbosity packageDB repos comp conf
globalFlags configFlags configExFlags installFlags deps =

installWithPlanner verbosity context planner []
upgrade _ _ _ _ _ _ _ _ _ _ = die $
"Use the 'cabal install' command instead of 'cabal upgrade'.\n"
++ "You can install the latest version of a package using 'cabal install'. "
++ "The 'cabal upgrade' command has been removed because people found it "
++ "confusing and it often led to broken packages.\n"
++ "If you want the old upgrade behaviour then use the install command "
++ "with the --upgrade-dependencies flag (but check first with --dry-run "
++ "to see what would happen). This will try to pick the latest versions "
++ "of all dependencies, rather than the usual behaviour of trying to pick "
++ "installed versions of all dependencies. If you do use "
++ "--upgrade-dependencies, it is recommended that you do not upgrade core "
++ "packages (e.g. by using appropriate --constraint= flags)."

where
context :: InstallContext
context = (packageDB, repos, comp, conf,
globalFlags, configFlags, configExFlags, installFlags)

planner :: Planner
planner | null deps = planUpgradePackages
comp configFlags configExFlags
| otherwise = planRepoPackages PreferAllLatest
comp globalFlags configFlags configExFlags
installFlags deps

type Planner = PackageIndex InstalledPackage
-> AvailablePackageDb
Expand Down Expand Up @@ -337,35 +337,6 @@ planRepoPackages defaultPref comp
worldFile = fromFlag $ globalWorldFile globalFlags


planUpgradePackages :: Compiler
-> ConfigFlags
-> ConfigExFlags
-> Planner
planUpgradePackages _comp _configFlags _configExFlags installed
(AvailablePackageDb available _availablePrefs) = die $
"the 'upgrade' command (when used without any package arguments) has "
++ "been disabled in this release. It has been disabled because it has "
++ "frequently led people to accidentally break their set of installed "
++ "packages. It will be re-enabled when it is safer to use.\n"
++ "Below is the list of packages that it would have tried to upgrade. You "
++ "can use the 'install' command to install the ones you want. Note that "
++ "it is generally not recommended to upgrade core packages.\n"
++ unlines [ display pkgid | Dependency pkgid _ <- deps ]

--TODO: improve upgrade so we can re-enable it
-- return $
-- resolveDependenciesWithProgress buildPlatform (compilerId comp)
-- (Just installed) available preferences constraints targets
where
deps = upgradableDependencies installed available
-- preferences = mergePackagePrefs PreferAllLatest availablePrefs configExFlags
-- constraints = [ PackageVersionConstraint name ver
-- | Dependency name ver <- deps ]
-- ++ [ PackageVersionConstraint name ver
-- | Dependency name ver <- configConstraints configFlags ]
-- targets = [ name | Dependency name _ <- deps ]


mergePackagePrefs :: PackagesPreferenceDefault
-> Map.Map PackageName VersionRange
-> ConfigExFlags
Expand Down
11 changes: 10 additions & 1 deletion Distribution/Client/Setup.hs
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ updateCommand = CommandUI {
upgradeCommand :: CommandUI (ConfigFlags, ConfigExFlags, InstallFlags)
upgradeCommand = configureCommand {
commandName = "upgrade",
commandSynopsis = "Upgrades installed packages to the latest available version",
commandSynopsis = "(command disabled, use install instead)",
commandDescription = Nothing,
commandUsage = usagePackages "upgrade",
commandDefaultFlags = (mempty, mempty, mempty),
Expand Down Expand Up @@ -515,6 +515,7 @@ data InstallFlags = InstallFlags {
installHaddockIndex :: Flag PathTemplate,
installDryRun :: Flag Bool,
installReinstall :: Flag Bool,
installUpgradeDeps :: Flag Bool,
installOnly :: Flag Bool,
installRootCmd :: Flag String,
installSummaryFile :: [PathTemplate],
Expand All @@ -530,6 +531,7 @@ defaultInstallFlags = InstallFlags {
installHaddockIndex = Flag docIndexFile,
installDryRun = Flag False,
installReinstall = Flag False,
installUpgradeDeps = Flag False,
installOnly = Flag False,
installRootCmd = mempty,
installSummaryFile = mempty,
Expand Down Expand Up @@ -594,6 +596,11 @@ installOptions showOrParseArgs =
installReinstall (\v flags -> flags { installReinstall = v })
trueArg

, option [] ["upgrade-dependencies"]
"Pick the latest version for all dependencies, rather than trying to pick an installed version."
installUpgradeDeps (\v flags -> flags { installUpgradeDeps = v })
trueArg

, option [] ["root-cmd"]
"Command used to gain root privileges, when installing with --global."
installRootCmd (\v flags -> flags { installRootCmd = v })
Expand Down Expand Up @@ -642,6 +649,7 @@ instance Monoid InstallFlags where
installHaddockIndex = mempty,
installDryRun = mempty,
installReinstall = mempty,
installUpgradeDeps = mempty,
installOnly = mempty,
installRootCmd = mempty,
installSummaryFile = mempty,
Expand All @@ -655,6 +663,7 @@ instance Monoid InstallFlags where
installHaddockIndex = combine installHaddockIndex,
installDryRun = combine installDryRun,
installReinstall = combine installReinstall,
installUpgradeDeps = combine installUpgradeDeps,
installOnly = combine installOnly,
installRootCmd = combine installRootCmd,
installSummaryFile = combine installSummaryFile,
Expand Down
2 changes: 1 addition & 1 deletion Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ mainWorker args = topHandler $
,updateCommand `commandAddAction` updateAction
,listCommand `commandAddAction` listAction
,infoCommand `commandAddAction` infoAction
,upgradeCommand `commandAddAction` upgradeAction
,fetchCommand `commandAddAction` fetchAction
,unpackCommand `commandAddAction` unpackAction
,checkCommand `commandAddAction` checkAction
Expand All @@ -149,6 +148,7 @@ mainWorker args = topHandler $
regVerbosity regDistPref
,wrapperAction testCommand
testVerbosity testDistPref
,upgradeCommand `commandAddAction` upgradeAction
]

wrapperAction :: Monoid flags
Expand Down

0 comments on commit 0279d0c

Please sign in to comment.