Skip to content
This repository

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

Merged
merged 1 commit into from over 1 year ago

4 participants

Mikhail Glushenkov Duncan Coutts kosmikus Johan Tibell
Mikhail Glushenkov
Owner

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)
Mikhail Glushenkov 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
Johan Tibell tibbe merged commit 0455ff5 into from August 26, 2012
Johan Tibell tibbe closed this August 26, 2012
Duncan Coutts
Owner

Yep, looks good. Thanks.

kosmikus
Owner

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.)

Mikhail Glushenkov
Owner

@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

Showing 1 unique commit by 1 author.

Aug 26, 2012
Mikhail Glushenkov 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
This page is out of date. Refresh to see the latest.
31  cabal-install/Distribution/Client/Install.hs
@@ -74,6 +74,7 @@ import qualified Distribution.Client.BuildReports.Storage as BuildReports
74 74
          ( storeAnonymous, storeLocal, fromInstallPlan )
75 75
 import qualified Distribution.Client.InstallSymlink as InstallSymlink
76 76
          ( symlinkBinaries )
  77
+import qualified Distribution.Client.PackageIndex as SourcePackageIndex
77 78
 import qualified Distribution.Client.Win32SelfUpgrade as Win32SelfUpgrade
78 79
 import qualified Distribution.Client.World as World
79 80
 import qualified Distribution.InstalledPackageInfo as Installed
@@ -178,7 +179,8 @@ install verbosity packageDBs repos comp conf
178 179
                          comp solver configFlags configExFlags installFlags
179 180
                          installedPkgIndex sourcePkgDb pkgSpecifiers
180 181
 
181  
-    checkPrintPlan verbosity installedPkgIndex installPlan installFlags pkgSpecifiers
  182
+    checkPrintPlan verbosity installedPkgIndex installPlan sourcePkgDb
  183
+      installFlags pkgSpecifiers
182 184
 
183 185
     unless dryRun $ do
184 186
       installPlan' <- performInstallations verbosity
@@ -337,10 +339,12 @@ planPackages comp solver configFlags configExFlags installFlags
337 339
 checkPrintPlan :: Verbosity
338 340
                -> PackageIndex
339 341
                -> InstallPlan
  342
+               -> SourcePackageDb
340 343
                -> InstallFlags
341 344
                -> [PackageSpecifier SourcePackage]
342 345
                -> IO ()
343  
-checkPrintPlan verbosity installed installPlan installFlags pkgSpecifiers = do
  346
+checkPrintPlan verbosity installed installPlan sourcePkgDb
  347
+  installFlags pkgSpecifiers = do
344 348
 
345 349
   -- User targets that are already installed.
346 350
   let preExistingTargets =
@@ -382,7 +386,8 @@ checkPrintPlan verbosity installed installPlan installFlags pkgSpecifiers = do
382 386
   -- We print the install plan if we are in a dry-run or if we are confronted
383 387
   -- with a dangerous install plan.
384 388
   when (dryRun || containsReinstalls && not overrideReinstall) $
385  
-    printPlan (dryRun || breaksPkgs && not overrideReinstall) adaptedVerbosity lPlan
  389
+    printPlan (dryRun || breaksPkgs && not overrideReinstall)
  390
+      adaptedVerbosity lPlan sourcePkgDb
386 391
 
387 392
   -- If the install plan is dangerous, we print various warning messages. In
388 393
   -- particular, if we can see that packages are likely to be broken, we even
@@ -471,8 +476,9 @@ packageStatus installedPkgIndex cpkg =
471 476
 printPlan :: Bool -- is dry run
472 477
           -> Verbosity
473 478
           -> [(ConfiguredPackage, PackageStatus)]
  479
+          -> SourcePackageDb
474 480
           -> IO ()
475  
-printPlan dryRun verbosity plan = case plan of
  481
+printPlan dryRun verbosity plan sourcePkgDb = case plan of
476 482
   []   -> return ()
477 483
   pkgs
478 484
     | verbosity >= Verbosity.verbose -> notice verbosity $ unlines $
@@ -480,12 +486,16 @@ printPlan dryRun verbosity plan = case plan of
480 486
       : map showPkgAndReason pkgs
481 487
     | otherwise -> notice verbosity $ unlines $
482 488
         ("In order, the following " ++ wouldWill ++ " be installed (use -v for more details):")
483  
-      : map (display . packageId) (map fst pkgs)
  489
+      : map showPkg pkgs
484 490
   where
485 491
     wouldWill | dryRun    = "would"
486 492
               | otherwise = "will"
487 493
 
  494
+    showPkg (pkg, _) = display (packageId pkg) ++
  495
+                       showLatest (pkg)
  496
+
488 497
     showPkgAndReason (pkg', pr) = display (packageId pkg') ++
  498
+          showLatest pkg' ++
489 499
           showFlagAssignment (nonDefaultFlags pkg') ++
490 500
           showStanzas (stanzas pkg') ++ " " ++
491 501
           case pr of
@@ -495,6 +505,17 @@ printPlan dryRun verbosity plan = case plan of
495 505
                 []   -> ""
496 506
                 diff -> " changes: "  ++ intercalate ", " (map change diff)
497 507
 
  508
+    showLatest :: ConfiguredPackage -> String
  509
+    showLatest pkg = if pkgVersion /= latestVersion
  510
+                     then (" (latest: " ++ display latestVersion ++ ")")
  511
+                     else ""
  512
+      where
  513
+        pkgVersion    = packageVersion pkg
  514
+        latestVersion =
  515
+          packageVersion . last
  516
+          . SourcePackageIndex.lookupPackageName (packageIndex sourcePkgDb)
  517
+          $ (packageName pkg)
  518
+
498 519
     toFlagAssignment :: [Flag] -> FlagAssignment
499 520
     toFlagAssignment = map (\ f -> (flagName f, flagDefault f))
500 521
 
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.