Skip to content

Commit

Permalink
Expose constraints that apply to any setup dependency.
Browse files Browse the repository at this point in the history
For example, "setup.Cabal installed" forces cabal to use the installed Cabal
library for all setup scripts.
  • Loading branch information
grayjay authored and ezyang committed Feb 3, 2017
1 parent f9139d7 commit 9aa4b9f
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 5 deletions.
11 changes: 8 additions & 3 deletions Cabal/doc/installing-packages.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1321,9 +1321,14 @@ Miscellaneous options

::

# Example use of the 'setup' qualifier. This constraint
# applies to package bar when it is a dependency of the
# Setup.hs script of package foo.
# Example uses of 'setup' qualifiers.

# This constraint applies to package bar when it is a
# dependency of any Setup.hs script.
$ cabal install --constraint="setup.bar == 1.0"

# This constraint applies to package bar when it is a
# dependency of the Setup.hs script of package foo.
$ cabal install --constraint="foo:setup.bar == 1.0"

.. TODO: Uncomment this example once we decide on a syntax for 'exe'.
Expand Down
10 changes: 10 additions & 0 deletions cabal-install/Distribution/Client/Targets.hs
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,9 @@ data UserConstraintScope =
-- | Scope that applies to the package when it has the specified qualifier.
UserQualified UserQualifier PackageName

-- | Scope that applies to the package when it has a setup qualifier.
| UserAnySetupQualifier PackageName

-- | Scope that applies to the package when it has any qualifier.
| UserAnyQualifier PackageName
deriving (Eq, Show, Generic)
Expand All @@ -733,6 +736,7 @@ fromUserQualifier (UserQualExe name1 name2) = QualExe name1 name2
fromUserConstraintScope :: UserConstraintScope -> ConstraintScope
fromUserConstraintScope (UserQualified q pn) =
ScopeQualified (fromUserQualifier q) pn
fromUserConstraintScope (UserAnySetupQualifier pn) = ScopeAnySetupQualifier pn
fromUserConstraintScope (UserAnyQualifier pn) = ScopeAnyQualifier pn

-- | Version of 'PackageConstraint' that the user can specify on
Expand All @@ -748,6 +752,7 @@ userConstraintPackageName (UserConstraint scope _) = scopePN scope
where
scopePN (UserQualified _ pn) = pn
scopePN (UserAnyQualifier pn) = pn
scopePN (UserAnySetupQualifier pn) = pn

userToPackageConstraint :: UserConstraint -> PackageConstraint
userToPackageConstraint (UserConstraint scope prop) =
Expand Down Expand Up @@ -776,6 +781,11 @@ instance Text UserConstraint where
pn <- parse
return (UserAnyQualifier pn)
+++
do
_ <- Parse.string "setup."
pn <- parse
return (UserAnySetupQualifier pn)
+++
do
-- Qualified name
pn <- parse
Expand Down
5 changes: 3 additions & 2 deletions cabal-install/changelog
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@
* New 'cabal-install' command: 'outdated', for listing outdated
version bounds in a .cabal file or a freeze file (#4207).
* Added qualified constraints for setup dependencies. For example,
--constraint="foo:setup.bar == 1.0" constrains foo's setup dependency
on bar (part of #3502).
--constraint="setup.bar == 1.0" constrains all setup dependencies on
bar, and --constraint="foo:setup.bar == 1.0" constrains foo's setup
dependency on bar (part of #3502).
* Non-qualified constraints, such as --constraint="bar == 1.0", now
only apply to top-level dependencies. They don't constrain setup or
build-tool dependencies. The new syntax --constraint="any.bar == 1.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,7 @@ instance Arbitrary RemoteRepo where

instance Arbitrary UserConstraintScope where
arbitrary = oneof [ UserQualified <$> arbitrary <*> arbitrary
, UserAnySetupQualifier <$> arbitrary
, UserAnyQualifier <$> arbitrary
]

Expand Down
4 changes: 4 additions & 0 deletions cabal-install/tests/UnitTests/Distribution/Client/Targets.hs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ exampleConstraints =
UserConstraint (UserAnyQualifier (pn "directory"))
(PackagePropertyStanzas [TestStanzas]))

, ("setup.Cabal installed",
UserConstraint (UserAnySetupQualifier (pn "Cabal"))
PackagePropertyInstalled)

, ("process:setup.bytestring ==5.2",
UserConstraint (UserQualified (UserQualSetup (pn "process")) (pn "bytestring"))
(PackagePropertyVersion (thisVersion (mkVersion [5, 2]))))
Expand Down

0 comments on commit 9aa4b9f

Please sign in to comment.