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 1 commit
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
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*
Copy link
Member

@hvr hvr Jul 30, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does this interact w/ the --new-freeze-file flag?

and more importantly, what happens if you say

cabal --project-file=foo outdated --project-file=bar --new-freeze-file

or

cabal --project-file=foo outdated --new-freeze-file

?

(i.e. we already have a global --project-file= flag... and it appears you've added a 2nd command-local one?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Last one wins (or it should be). I'll add a test and make sure it's explicitly mentioned in the docs.

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"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something doesn't smell right to me about duplicating the global --project-file= flag as a local outdated sub-command flag. What does this make possible that wasn't possible before?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry, I don't understand this question. Where is the global --project-file flag being defined? outdated doesn't currently accept it:

$ cabal outdated --project-file=foo.project
cabal: unrecognized 'outdated' option `--project-file=foo.project'
$ cabal --version
cabal-install version 2.2.0.0
compiled using version 2.2.0.1 of the Cabal library 

Bear in mind that outdated isn't really a new-style command: it's more like a v1 command that happens to know a little bit about new-style freeze files. new-outdated as outlined in #4831 might be a worthy project, but that's a much bigger task. I think that this patch has a good power-to-weight ratio.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh you're right, I stand corrected. I confused --project-file= to be a global one (like --store-dir=)

Now this is starting to make more sense. But if we're going to migrate to make the new-*-style commands default, then it's also kinda strange to have --project-file= imply a side-effect; rather than have it act like merely setting a property, and requiring an explicit --new-freeze-file; that would feel more consistent to me w/ how --project-file= usually acts.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've gone ahead and implemented that. In the future we'll probably want to remove --new-freeze-file outright; I've made sure that --project-file without it errors out, so that we've got freedom to make that change.

"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