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

outdated: require --new-freeze-file for --project-file

Now the behaviour doesn't switch on just --project-file's
presence.
parent 0d870746
......@@ -1335,13 +1335,14 @@ The following flags are supported by the ``outdated`` command:
instead of the package description file (``$PACKAGENAME.cabal``).
``--new-freeze-file``
Read dependency version bounds from the new-style freeze file
(``cabal.project.freeze``) instead of the package description file.
This is equivalent to ``--project-file cabal.project``.
(by default, ``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. If multiple ``--project-file``
flags are provided, only the final one is considered.
flags are provided, only the final one is considered. This flag
must be passed in conjunction with ``--new-freeze-file``.
``--simple-output``
Print only the names of outdated dependencies, one per line.
``--exit-code``
......
......@@ -59,6 +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
......@@ -76,15 +78,17 @@ outdated verbosity0 outdatedFlags repoContext comp platform = do
in \pkgname -> pkgname `S.member` minorSet
verbosity = if quiet then silent else verbosity0
when (not newFreezeFile && isJust mprojectFile) $
die' verbosity $
"--project-file must only be used with --new-freeze-file."
sourcePkgDb <- IndexUtils.getSourcePackages verbosity repoContext
let pkgIndex = packageIndex sourcePkgDb
deps <- if freezeFile
then depsFromFreezeFile verbosity
else case mprojectFile of
Just projectFile
-> depsFromNewFreezeFile verbosity projectFile
Nothing
-> depsFromPkgDesc verbosity comp platform
else if newFreezeFile
then depsFromNewFreezeFile verbosity mprojectFile
else depsFromPkgDesc verbosity comp platform
debug verbosity $ "Dependencies loaded: "
++ (intercalate ", " $ map display deps)
let outdatedDeps = listOutdated deps pkgIndex
......@@ -126,10 +130,10 @@ depsFromFreezeFile verbosity = do
return deps
-- | Read the list of dependencies from the new-style freeze file.
depsFromNewFreezeFile :: Verbosity -> FilePath -> IO [Dependency]
depsFromNewFreezeFile verbosity projectFile = do
depsFromNewFreezeFile :: Verbosity -> Maybe FilePath -> IO [Dependency]
depsFromNewFreezeFile verbosity mprojectFile = do
projectRoot <- either throwIO return =<<
findProjectRoot Nothing (Just projectFile)
findProjectRoot Nothing mprojectFile
let distDirLayout = defaultDistDirLayout projectRoot
{- TODO: Support dist dir override -} Nothing
projectConfig <- runRebuild (distProjectRootDirectory distDirLayout) $
......@@ -138,7 +142,7 @@ depsFromNewFreezeFile verbosity projectFile = do
$ projectConfig
deps = userConstraintsToDependencies ucnstrs
debug verbosity $
"Reading the list of dependencies from the new-style freeze file " ++ projectFile ++ ".freeze"
"Reading the list of dependencies from the new-style freeze file " ++ distProjectFile distDirLayout "freeze"
return deps
-- | Read the list of dependencies from the package description.
......
......@@ -1100,6 +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,
......@@ -1112,6 +1113,7 @@ defaultOutdatedFlags :: OutdatedFlags
defaultOutdatedFlags = OutdatedFlags {
outdatedVerbosity = toFlag normal,
outdatedFreezeFile = mempty,
outdatedNewFreezeFile = mempty,
outdatedProjectFile = mempty,
outdatedSimpleOutput = mempty,
outdatedExitCode = mempty,
......@@ -1140,12 +1142,12 @@ outdatedCommand = CommandUI {
trueArg
,option [] ["new-freeze-file"]
"Act on the new-style freeze file named cabal.project.freeze"
outdatedProjectFile (\_ flags -> flags { outdatedProjectFile = pure "cabal.project" })
(noArg mempty)
"Act on the new-style freeze file (default: cabal.project.freeze)"
outdatedNewFreezeFile (\v flags -> flags { outdatedNewFreezeFile = v })
trueArg
,option [] ["project-file"]
"Act on the new-style freeze file named PROJECTFILE.freeze"
"Act on the new-style freeze file named PROJECTFILE.freeze rather than the default cabal.project.freeze"
outdatedProjectFile (\v flags -> flags { outdatedProjectFile = v })
(reqArgFlag "PROJECTFILE")
......
......@@ -2,7 +2,8 @@
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.
from the new-style freeze file named FILE.freeze. This is only
available when `--new-freeze-file` has been passed.
* '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
......
......@@ -7,9 +7,4 @@ base ==3.0.3.2 (latest: 4.0.0.0)
Outdated dependencies:
base ==3.0.3.2 (latest: 4.0.0.0)
# cabal outdated
Outdated dependencies:
base ==3.0.3.2 (latest: 4.0.0.0)
# cabal outdated
Outdated dependencies:
base ==3.0.3.2 (latest: 4.0.0.0)
template-haskell ==2.3.0.0 (latest: 2.4.0.0)
cabal: --project-file must only be used with --new-freeze-file.
import Test.Cabal.Prelude
main = cabalTest $ withRepo "repo" $ do
res <- cabal' "outdated" ["--project-file", "variant.project"]
res <- cabal' "outdated" ["--new-freeze-file", "--project-file", "variant.project"]
assertOutputContains "base" res
assertOutputDoesNotContain "template-haskell" res
-- Test last-one-wins behaviour.
res <- cabal' "outdated" ["--project-file", "cabal.project", "--project-file", "variant.project"]
assertOutputContains "base" res
assertOutputDoesNotContain "template-haskell" res
res <- cabal' "outdated" ["--new-freeze-file", "--project-file", "variant.project"]
res <- cabal' "outdated" ["--new-freeze-file", "--project-file", "cabal.project", "--project-file", "variant.project"]
assertOutputContains "base" res
assertOutputDoesNotContain "template-haskell" res
res <- cabal' "outdated" ["--project-file", "variant.project", "--new-freeze-file"]
assertOutputContains "base" res
assertOutputContains "template-haskell" res
-- Test for erroring on --project-file without --new-freeze-file
fails $ cabal "outdated" ["--project-file", "variant.project"]
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