Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Make 'install --dry-run' print the latest available version of a package. #1014

Merged
merged 1 commit into from

4 participants

@23Skidoo
Collaborator

Print the latest available version of a package when the solver has picked a different version for some reason. Inspired by Brent Yorgey's highlight-versions tool.

Example of output:

$ cabal install --dry-run repa
Resolving dependencies...
In order, the following would be installed (use -v for more details):
primitive-0.4.1
random-1.0.1.1
QuickCheck-2.4.2 (latest: 2.5)
vector-0.9.1
repa-3.2.1.1
$ cabal install --dry-run repa -v
Reading available packages...
Choosing modular solver.
Resolving dependencies...
In order, the following would be installed:
primitive-0.4.1 (new package)
random-1.0.1.1 (new package)
QuickCheck-2.4.2 (latest: 2.5) (new package)
vector-0.9.1 (new package)
repa-3.2.1.1 (new package)
@23Skidoo 23Skidoo Make 'install --dry-run' print the latest available version of a pack…
…age.

Print the latest available version of a package when the solver has picked a
different version for some reason. Inspired by Brent Yorgey's highlight-versions
tool [1].

Example of output:

$ cabal install --dry-run repa
Resolving dependencies...
In order, the following would be installed (use -v for more details):
primitive-0.4.1
random-1.0.1.1
QuickCheck-2.4.2 (latest: 2.5)
vector-0.9.1
repa-3.2.1.1

$ cabal install --dry-run repa -v
Reading available packages...
Choosing modular solver.
Resolving dependencies...
In order, the following would be installed:
primitive-0.4.1 (new package)
random-1.0.1.1 (new package)
QuickCheck-2.4.2 (latest: 2.5) (new package)
vector-0.9.1 (new package)
repa-3.2.1.1 (new package)

[1] http://byorgey.wordpress.com/2012/08/25/identifying-outdated-packages-in-cabal-install-plans/
0455ff5
@tibbe tibbe merged commit 0455ff5 into from
@dcoutts
Collaborator

Yep, looks good. Thanks.

@kosmikus
Collaborator

Great change. I'm just worried that it might break tools that parse the output of a --dry-run, of which there might be some. That's the main reason why I've in the past tried to maintain the simplicity of output without -v. (In general, I think the extra information that -v prints is nearly always useful and could be turned into the default.)

@23Skidoo
Collaborator

@kosmikus Yes, I was a bit worried about breaking external tools, too. If this proves to be a problem in practice, we can make this -v only.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 25, 2012
  1. @23Skidoo

    Make 'install --dry-run' print the latest available version of a pack…

    23Skidoo authored
    …age.
    
    Print the latest available version of a package when the solver has picked a
    different version for some reason. Inspired by Brent Yorgey's highlight-versions
    tool [1].
    
    Example of output:
    
    $ cabal install --dry-run repa
    Resolving dependencies...
    In order, the following would be installed (use -v for more details):
    primitive-0.4.1
    random-1.0.1.1
    QuickCheck-2.4.2 (latest: 2.5)
    vector-0.9.1
    repa-3.2.1.1
    
    $ cabal install --dry-run repa -v
    Reading available packages...
    Choosing modular solver.
    Resolving dependencies...
    In order, the following would be installed:
    primitive-0.4.1 (new package)
    random-1.0.1.1 (new package)
    QuickCheck-2.4.2 (latest: 2.5) (new package)
    vector-0.9.1 (new package)
    repa-3.2.1.1 (new package)
    
    [1] http://byorgey.wordpress.com/2012/08/25/identifying-outdated-packages-in-cabal-install-plans/
This page is out of date. Refresh to see the latest.
Showing with 26 additions and 5 deletions.
  1. +26 −5 cabal-install/Distribution/Client/Install.hs
View
31 cabal-install/Distribution/Client/Install.hs
@@ -74,6 +74,7 @@ import qualified Distribution.Client.BuildReports.Storage as BuildReports
( storeAnonymous, storeLocal, fromInstallPlan )
import qualified Distribution.Client.InstallSymlink as InstallSymlink
( symlinkBinaries )
+import qualified Distribution.Client.PackageIndex as SourcePackageIndex
import qualified Distribution.Client.Win32SelfUpgrade as Win32SelfUpgrade
import qualified Distribution.Client.World as World
import qualified Distribution.InstalledPackageInfo as Installed
@@ -178,7 +179,8 @@ install verbosity packageDBs repos comp conf
comp solver configFlags configExFlags installFlags
installedPkgIndex sourcePkgDb pkgSpecifiers
- checkPrintPlan verbosity installedPkgIndex installPlan installFlags pkgSpecifiers
+ checkPrintPlan verbosity installedPkgIndex installPlan sourcePkgDb
+ installFlags pkgSpecifiers
unless dryRun $ do
installPlan' <- performInstallations verbosity
@@ -337,10 +339,12 @@ planPackages comp solver configFlags configExFlags installFlags
checkPrintPlan :: Verbosity
-> PackageIndex
-> InstallPlan
+ -> SourcePackageDb
-> InstallFlags
-> [PackageSpecifier SourcePackage]
-> IO ()
-checkPrintPlan verbosity installed installPlan installFlags pkgSpecifiers = do
+checkPrintPlan verbosity installed installPlan sourcePkgDb
+ installFlags pkgSpecifiers = do
-- User targets that are already installed.
let preExistingTargets =
@@ -382,7 +386,8 @@ checkPrintPlan verbosity installed installPlan installFlags pkgSpecifiers = do
-- We print the install plan if we are in a dry-run or if we are confronted
-- with a dangerous install plan.
when (dryRun || containsReinstalls && not overrideReinstall) $
- printPlan (dryRun || breaksPkgs && not overrideReinstall) adaptedVerbosity lPlan
+ printPlan (dryRun || breaksPkgs && not overrideReinstall)
+ adaptedVerbosity lPlan sourcePkgDb
-- If the install plan is dangerous, we print various warning messages. In
-- particular, if we can see that packages are likely to be broken, we even
@@ -471,8 +476,9 @@ packageStatus installedPkgIndex cpkg =
printPlan :: Bool -- is dry run
-> Verbosity
-> [(ConfiguredPackage, PackageStatus)]
+ -> SourcePackageDb
-> IO ()
-printPlan dryRun verbosity plan = case plan of
+printPlan dryRun verbosity plan sourcePkgDb = case plan of
[] -> return ()
pkgs
| verbosity >= Verbosity.verbose -> notice verbosity $ unlines $
@@ -480,12 +486,16 @@ printPlan dryRun verbosity plan = case plan of
: map showPkgAndReason pkgs
| otherwise -> notice verbosity $ unlines $
("In order, the following " ++ wouldWill ++ " be installed (use -v for more details):")
- : map (display . packageId) (map fst pkgs)
+ : map showPkg pkgs
where
wouldWill | dryRun = "would"
| otherwise = "will"
+ showPkg (pkg, _) = display (packageId pkg) ++
+ showLatest (pkg)
+
showPkgAndReason (pkg', pr) = display (packageId pkg') ++
+ showLatest pkg' ++
showFlagAssignment (nonDefaultFlags pkg') ++
showStanzas (stanzas pkg') ++ " " ++
case pr of
@@ -495,6 +505,17 @@ printPlan dryRun verbosity plan = case plan of
[] -> ""
diff -> " changes: " ++ intercalate ", " (map change diff)
+ showLatest :: ConfiguredPackage -> String
+ showLatest pkg = if pkgVersion /= latestVersion
+ then (" (latest: " ++ display latestVersion ++ ")")
+ else ""
+ where
+ pkgVersion = packageVersion pkg
+ latestVersion =
+ packageVersion . last
+ . SourcePackageIndex.lookupPackageName (packageIndex sourcePkgDb)
+ $ (packageName pkg)
+
toFlagAssignment :: [Flag] -> FlagAssignment
toFlagAssignment = map (\ f -> (flagName f, flagDefault f))
Something went wrong with that request. Please try again.