Commit eb0a3ff0 authored by quasicomputational's avatar quasicomputational Committed by Mikhail Glushenkov

outdated: accept --project-file

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.
parent 9537238f
......@@ -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``
......
......@@ -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)
......@@ -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)
......@@ -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
......@@ -123,11 +126,10 @@ 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) $
......@@ -135,8 +137,8 @@ depsFromNewFreezeFile verbosity = do
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.
......
......@@ -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,
......@@ -1112,7 +1112,7 @@ defaultOutdatedFlags :: OutdatedFlags
defaultOutdatedFlags = OutdatedFlags {
outdatedVerbosity = toFlag normal,
outdatedFreezeFile = mempty,
outdatedNewFreezeFile = mempty,
outdatedProjectFile = mempty,
outdatedSimpleOutput = mempty,
outdatedExitCode = mempty,
outdatedQuiet = mempty,
......@@ -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"
......
-*-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
......
# 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)
import Test.Cabal.Prelude
main = cabalTest $ withRepo "repo" $ do
res <- cabal' "outdated" ["--project-file", "variant.project"]
assertOutputContains "base" res
assertOutputDoesNotContain "template-haskell" res
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