Skip to content

outdated: accept --project-file #5474

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 31, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion Cabal/doc/developing-packages.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1335,7 +1335,16 @@ 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.
(by default, ``cabal.project.freeze``) instead of the package
description file.
``--project-file`` *PROJECTFILE*
:since: 2.4

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. This flag
must only be passed in when ``--new-freeze-file`` is present.
``--simple-output``
Print only the names of outdated dependencies, one per line.
``--exit-code``
Expand Down
24 changes: 15 additions & 9 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 Down Expand Up @@ -60,6 +61,8 @@ 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 @@ -75,13 +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 if newFreezeFile
then depsFromNewFreezeFile verbosity
else depsFromPkgDesc verbosity comp platform
then depsFromNewFreezeFile verbosity mprojectFile
else depsFromPkgDesc verbosity comp platform
debug verbosity $ "Dependencies loaded: "
++ (intercalate ", " $ map display deps)
let outdatedDeps = listOutdated deps pkgIndex
Expand Down Expand Up @@ -123,20 +130,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 -> Maybe FilePath -> IO [Dependency]
depsFromNewFreezeFile verbosity mprojectFile = do
projectRoot <- either throwIO return =<<
findProjectRoot Nothing
{- TODO: Support '--project-file': -} Nothing
findProjectRoot Nothing mprojectFile
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 " ++ distProjectFile distDirLayout "freeze"
return deps

-- | Read the list of dependencies from the package description.
Expand Down
9 changes: 8 additions & 1 deletion cabal-install/Distribution/Client/Setup.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1101,6 +1101,7 @@ 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 @@ -1113,6 +1114,7 @@ defaultOutdatedFlags = OutdatedFlags {
outdatedVerbosity = toFlag normal,
outdatedFreezeFile = mempty,
outdatedNewFreezeFile = mempty,
outdatedProjectFile = mempty,
outdatedSimpleOutput = mempty,
outdatedExitCode = mempty,
outdatedQuiet = mempty,
Expand Down Expand Up @@ -1140,10 +1142,15 @@ outdatedCommand = CommandUI {
trueArg

,option [] ["new-freeze-file"]
"Act on the new-style freeze file"
"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 rather than the default cabal.project.freeze"
outdatedProjectFile (\v flags -> flags { outdatedProjectFile = v })
(reqArgFlag "PROJECTFILE")

,option [] ["simple-output"]
"Only print names of outdated dependencies, one per line"
outdatedSimpleOutput (\v flags -> flags { outdatedSimpleOutput = v })
Expand Down
3 changes: 3 additions & 0 deletions cabal-install/changelog
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
-*-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. 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
Expand Down
10 changes: 10 additions & 0 deletions cabal-testsuite/PackageTests/Outdated/outdated-project-file.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# 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)
# cabal outdated
Outdated dependencies:
base ==3.0.3.2 (latest: 4.0.0.0)
# cabal outdated
cabal: --project-file must only be used with --new-freeze-file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import Test.Cabal.Prelude
main = cabalTest $ withRepo "repo" $ do
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" ["--new-freeze-file", "--project-file", "cabal.project", "--project-file", "variant.project"]
assertOutputContains "base" res
assertOutputDoesNotContain "template-haskell" res

-- Test for erroring on --project-file without --new-freeze-file
fails $ cabal "outdated" ["--project-file", "variant.project"]
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