From 9aa4b9f0ed613376a84c801c0a97ee1469789923 Mon Sep 17 00:00:00 2001 From: Kristen Kozak Date: Sun, 29 Jan 2017 16:10:38 -0800 Subject: [PATCH] Expose constraints that apply to any setup dependency. For example, "setup.Cabal installed" forces cabal to use the installed Cabal library for all setup scripts. --- Cabal/doc/installing-packages.rst | 11 ++++++++--- cabal-install/Distribution/Client/Targets.hs | 10 ++++++++++ cabal-install/changelog | 5 +++-- .../UnitTests/Distribution/Client/ProjectConfig.hs | 1 + .../tests/UnitTests/Distribution/Client/Targets.hs | 4 ++++ 5 files changed, 26 insertions(+), 5 deletions(-) diff --git a/Cabal/doc/installing-packages.rst b/Cabal/doc/installing-packages.rst index ac8abe3bf0d..0df3776c730 100644 --- a/Cabal/doc/installing-packages.rst +++ b/Cabal/doc/installing-packages.rst @@ -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'. diff --git a/cabal-install/Distribution/Client/Targets.hs b/cabal-install/Distribution/Client/Targets.hs index b8f25c71af0..5557f56a618 100644 --- a/cabal-install/Distribution/Client/Targets.hs +++ b/cabal-install/Distribution/Client/Targets.hs @@ -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) @@ -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 @@ -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) = @@ -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 diff --git a/cabal-install/changelog b/cabal-install/changelog index 56a44b025dd..8d402096d79 100644 --- a/cabal-install/changelog +++ b/cabal-install/changelog @@ -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" diff --git a/cabal-install/tests/UnitTests/Distribution/Client/ProjectConfig.hs b/cabal-install/tests/UnitTests/Distribution/Client/ProjectConfig.hs index 7b912940a1a..b938ee3fbf5 100644 --- a/cabal-install/tests/UnitTests/Distribution/Client/ProjectConfig.hs +++ b/cabal-install/tests/UnitTests/Distribution/Client/ProjectConfig.hs @@ -567,6 +567,7 @@ instance Arbitrary RemoteRepo where instance Arbitrary UserConstraintScope where arbitrary = oneof [ UserQualified <$> arbitrary <*> arbitrary + , UserAnySetupQualifier <$> arbitrary , UserAnyQualifier <$> arbitrary ] diff --git a/cabal-install/tests/UnitTests/Distribution/Client/Targets.hs b/cabal-install/tests/UnitTests/Distribution/Client/Targets.hs index 6c4079e1ff2..19d194e6163 100644 --- a/cabal-install/tests/UnitTests/Distribution/Client/Targets.hs +++ b/cabal-install/tests/UnitTests/Distribution/Client/Targets.hs @@ -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]))))