Skip to content

Commit

Permalink
outdated: accept --project-file
Browse files Browse the repository at this point in the history
This doesn't get anywhere near the improvements suggested in #4831,
but it's a very respectable improvement over the status-quo for not
much effort.
  • Loading branch information
quasicomputational authored and 23Skidoo committed Jul 31, 2018
1 parent 9537238 commit eb0a3ff
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 17 deletions.
4 changes: 4 additions & 0 deletions Cabal/doc/developing-packages.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1336,6 +1336,10 @@ The following flags are supported by the ``outdated`` command:
``--new-freeze-file``
Read dependency version bounds from the new-style freeze file
(``cabal.project.freeze``) instead of the package description file.
``--project-file`` *PROJECTFILE*
Read dependendency version bounds from the new-style freeze file
related to the named project file (i.e., ``$PROJECTFILE.freeze``)
instead of the package desctription file.
``--simple-output``
Print only the names of outdated dependencies, one per line.
``--exit-code``
Expand Down
26 changes: 14 additions & 12 deletions cabal-install/Distribution/Client/Outdated.hs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ import Distribution.Package (PackageName, packageVersio
import Distribution.PackageDescription (allBuildDepends)
import Distribution.PackageDescription.Configuration (finalizePD)
import Distribution.Simple.Compiler (Compiler, compilerInfo)
import Distribution.Simple.Setup (fromFlagOrDefault)
import Distribution.Simple.Setup
(fromFlagOrDefault, flagToMaybe)
import Distribution.Simple.Utils
(die', notice, debug, tryFindPackageDesc)
import Distribution.System (Platform)
Expand All @@ -58,8 +59,8 @@ outdated :: Verbosity -> OutdatedFlags -> RepoContext
-> IO ()
outdated verbosity0 outdatedFlags repoContext comp platform = do
let freezeFile = fromFlagOrDefault False (outdatedFreezeFile outdatedFlags)
newFreezeFile = fromFlagOrDefault False
(outdatedNewFreezeFile outdatedFlags)
mprojectFile = flagToMaybe
(outdatedProjectFile outdatedFlags)
simpleOutput = fromFlagOrDefault False
(outdatedSimpleOutput outdatedFlags)
quiet = fromFlagOrDefault False (outdatedQuiet outdatedFlags)
Expand All @@ -79,9 +80,11 @@ outdated verbosity0 outdatedFlags repoContext comp platform = do
let pkgIndex = packageIndex sourcePkgDb
deps <- if freezeFile
then depsFromFreezeFile verbosity
else if newFreezeFile
then depsFromNewFreezeFile verbosity
else depsFromPkgDesc verbosity comp platform
else case mprojectFile of
Just projectFile
-> depsFromNewFreezeFile verbosity projectFile
Nothing
-> depsFromPkgDesc verbosity comp platform
debug verbosity $ "Dependencies loaded: "
++ (intercalate ", " $ map display deps)
let outdatedDeps = listOutdated deps pkgIndex
Expand Down Expand Up @@ -123,20 +126,19 @@ depsFromFreezeFile verbosity = do
return deps

-- | Read the list of dependencies from the new-style freeze file.
depsFromNewFreezeFile :: Verbosity -> IO [Dependency]
depsFromNewFreezeFile verbosity = do
depsFromNewFreezeFile :: Verbosity -> FilePath -> IO [Dependency]
depsFromNewFreezeFile verbosity projectFile = do
projectRoot <- either throwIO return =<<
findProjectRoot Nothing
{- TODO: Support '--project-file': -} Nothing
findProjectRoot Nothing (Just projectFile)
let distDirLayout = defaultDistDirLayout projectRoot
{- TODO: Support dist dir override -} Nothing
projectConfig <- runRebuild (distProjectRootDirectory distDirLayout) $
readProjectLocalFreezeConfig verbosity distDirLayout
let ucnstrs = map fst . projectConfigConstraints . projectConfigShared
$ projectConfig
deps = userConstraintsToDependencies ucnstrs
debug verbosity
"Reading the list of dependencies from the new-style freeze file"
debug verbosity $
"Reading the list of dependencies from the new-style freeze file " ++ projectFile ++ ".freeze"
return deps

-- | Read the list of dependencies from the package description.
Expand Down
15 changes: 10 additions & 5 deletions cabal-install/Distribution/Client/Setup.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1100,7 +1100,7 @@ instance Semigroup IgnoreMajorVersionBumps where
data OutdatedFlags = OutdatedFlags {
outdatedVerbosity :: Flag Verbosity,
outdatedFreezeFile :: Flag Bool,
outdatedNewFreezeFile :: Flag Bool,
outdatedProjectFile :: Flag FilePath,
outdatedSimpleOutput :: Flag Bool,
outdatedExitCode :: Flag Bool,
outdatedQuiet :: Flag Bool,
Expand All @@ -1112,7 +1112,7 @@ defaultOutdatedFlags :: OutdatedFlags
defaultOutdatedFlags = OutdatedFlags {
outdatedVerbosity = toFlag normal,
outdatedFreezeFile = mempty,
outdatedNewFreezeFile = mempty,
outdatedProjectFile = mempty,
outdatedSimpleOutput = mempty,
outdatedExitCode = mempty,
outdatedQuiet = mempty,
Expand Down Expand Up @@ -1140,9 +1140,14 @@ outdatedCommand = CommandUI {
trueArg

,option [] ["new-freeze-file"]
"Act on the new-style freeze file"
outdatedNewFreezeFile (\v flags -> flags { outdatedNewFreezeFile = v })
trueArg
"Act on the new-style freeze file named cabal.project.freeze"
outdatedProjectFile (\_ flags -> flags { outdatedProjectFile = pure "cabal.project" })
(noArg mempty)

,option [] ["project-file"]
"Act on the new-style freeze file named PROJECTFILE.freeze"
outdatedProjectFile (\v flags -> flags { outdatedProjectFile = v })
(reqArgFlag "PROJECTFILE")

,option [] ["simple-output"]
"Only print names of outdated dependencies, one per line"
Expand Down
2 changes: 2 additions & 0 deletions cabal-install/changelog
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
-*-change-log-*-

2.4.0.0 (current development version)
* 'outdated' now accepts '--project-file FILE', which will look for bounds
from the new-style freeze file named FILE.freeze.
* 'new-repl' now accepts a '--build-depends' flag which accepts the
same syntax as is used in .cabal files to add additional dependencies
to the environment when developing in the REPL. It is now usable outside
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# cabal v1-update
Downloading the latest package list from test-local-repo
# cabal outdated
Outdated dependencies:
base ==3.0.3.2 (latest: 4.0.0.0)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import Test.Cabal.Prelude
main = cabalTest $ withRepo "repo" $ do
res <- cabal' "outdated" ["--project-file", "variant.project"]
assertOutputContains "base" res
assertOutputDoesNotContain "template-haskell" res

1 change: 1 addition & 0 deletions cabal-testsuite/PackageTests/Outdated/variant.project
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
packages: .
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
constraints: base == 3.0.3.2

0 comments on commit eb0a3ff

Please sign in to comment.