Skip to content
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

package-constraints by package file #9462

Closed
Closed
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
8 changes: 6 additions & 2 deletions Cabal-syntax/src/Distribution/CabalSpecVersion.hs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ data CabalSpecVersion
CabalSpecV3_4
| CabalSpecV3_6
| CabalSpecV3_8
-- 3.10: no changes
| -- 3.10 -- 3.11: no changes
CabalSpecV3_12
deriving (Eq, Ord, Show, Read, Enum, Bounded, Typeable, Data, Generic)

instance Binary CabalSpecVersion
Expand All @@ -43,6 +44,7 @@ instance NFData CabalSpecVersion where rnf = genericRnf
--
-- @since 3.0.0.0
showCabalSpecVersion :: CabalSpecVersion -> String
showCabalSpecVersion CabalSpecV3_12 = "3.12"
showCabalSpecVersion CabalSpecV3_8 = "3.8"
showCabalSpecVersion CabalSpecV3_6 = "3.6"
showCabalSpecVersion CabalSpecV3_4 = "3.4"
Expand All @@ -63,13 +65,14 @@ showCabalSpecVersion CabalSpecV1_2 = "1.2"
showCabalSpecVersion CabalSpecV1_0 = "1.0"

cabalSpecLatest :: CabalSpecVersion
cabalSpecLatest = CabalSpecV3_8
cabalSpecLatest = CabalSpecV3_12

-- | Parse 'CabalSpecVersion' from version digits.
--
-- It may fail if for recent versions the version is not exact.
cabalSpecFromVersionDigits :: [Int] -> Maybe CabalSpecVersion
cabalSpecFromVersionDigits v
| v == [3, 12] = Just CabalSpecV3_12
| v == [3, 8] = Just CabalSpecV3_8
| v == [3, 6] = Just CabalSpecV3_6
| v == [3, 4] = Just CabalSpecV3_4
Expand All @@ -92,6 +95,7 @@ cabalSpecFromVersionDigits v

-- | @since 3.4.0.0
cabalSpecToVersionDigits :: CabalSpecVersion -> [Int]
cabalSpecToVersionDigits CabalSpecV3_12 = [3, 12]
cabalSpecToVersionDigits CabalSpecV3_8 = [3, 8]
cabalSpecToVersionDigits CabalSpecV3_6 = [3, 6]
cabalSpecToVersionDigits CabalSpecV3_4 = [3, 4]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ packageDescriptionFieldGrammar
, c (List FSep (Identity (SymbolicPath PackageDir LicenseFile)) (SymbolicPath PackageDir LicenseFile))
, c (List FSep TestedWith (CompilerFlavor, VersionRange))
, c (List VCat FilePathNT String)
, c (List CommaVCat (Identity Dependency) Dependency)
, c FilePathNT
, c CompatLicenseFile
, c CompatFilePath
Expand Down Expand Up @@ -146,6 +147,8 @@ packageDescriptionFieldGrammar =
<*> monoidalFieldAla "extra-source-files" formatExtraSourceFiles L.extraSrcFiles
<*> monoidalFieldAla "extra-tmp-files" (alaList' VCat FilePathNT) L.extraTmpFiles
<*> monoidalFieldAla "extra-doc-files" (alaList' VCat FilePathNT) L.extraDocFiles
<*> monoidalFieldAla "package-constraints" formatDependencyList L.packageConstraints
^^^ availableSince CabalSpecV3_12 []
where
packageIdentifierGrammar =
PackageIdentifier
Expand Down
2 changes: 1 addition & 1 deletion Cabal-syntax/src/Distribution/PackageDescription/Parsec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ goSections specVer = traverse_ process
process (Field (Name pos name) _) =
lift $
parseWarning pos PWTTrailingFields $
"Ignoring trailing fields after sections: " ++ show name
"Ignoring trailing fields after sections: " ++ show name ++ ". Consider moving these fields before any stanzas in your cabal file."
process (Section name args secFields) =
parseSection name args secFields

Expand Down
5 changes: 5 additions & 0 deletions Cabal-syntax/src/Distribution/Types/PackageDescription.hs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ data PackageDescription = PackageDescription
, extraSrcFiles :: [FilePath]
, extraTmpFiles :: [FilePath]
, extraDocFiles :: [FilePath]
, -- default constraints to override unversioned dependencies
packageConstraints :: [Dependency]
}
deriving (Generic, Show, Read, Eq, Ord, Typeable, Data)

Expand Down Expand Up @@ -232,6 +234,7 @@ emptyPackageDescription =
, extraSrcFiles = []
, extraTmpFiles = []
, extraDocFiles = []
, packageConstraints = []
}

-- ---------------------------------------------------------------------------
Expand Down Expand Up @@ -488,6 +491,7 @@ instance L.HasBuildInfos PackageDescription where
a22
a23
a24
a25
) =
PackageDescription a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15 a16 a17 a18 a19
<$> (traverse . L.buildInfo) f x1 -- library
Expand All @@ -501,3 +505,4 @@ instance L.HasBuildInfos PackageDescription where
<*> pure a22 -- extra src files
<*> pure a23 -- extra temp files
<*> pure a24 -- extra doc files
<*> pure a25 -- default constraints
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import Distribution.Types.Benchmark.Lens (benchmarkBuildInfo, benchmarkName)
import Distribution.Types.BuildInfo (BuildInfo)
import Distribution.Types.BuildType (BuildType)
import Distribution.Types.ComponentName (ComponentName (..))
import Distribution.Types.Dependency (Dependency (..))
import Distribution.Types.Executable (Executable, exeModules)
import Distribution.Types.Executable.Lens (exeBuildInfo, exeName)
import Distribution.Types.ForeignLib (ForeignLib, foreignLibModules)
Expand Down Expand Up @@ -158,6 +159,10 @@ extraDocFiles :: Lens' PackageDescription [String]
extraDocFiles f s = fmap (\x -> s{T.extraDocFiles = x}) (f (T.extraDocFiles s))
{-# INLINE extraDocFiles #-}

packageConstraints :: Lens' PackageDescription [Dependency]
packageConstraints f s = fmap (\x -> s{T.packageConstraints = x}) (f (T.packageConstraints s))
{-# INLINE packageConstraints #-}

-- | @since 3.0.0.0
allLibraries :: Traversal' PackageDescription Library
allLibraries f pd = mk <$> traverse f (T.library pd) <*> traverse f (T.subLibraries pd)
Expand Down
3 changes: 2 additions & 1 deletion Cabal-tests/tests/ParserTests/regressions/Octree-0.5.expr
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ GenericPackageDescription {
dataDir = ".",
extraSrcFiles = [],
extraTmpFiles = [],
extraDocFiles = []},
extraDocFiles = [],
packageConstraints = []},
gpdScannedVersion = Nothing,
genPackageFlags = [],
condLibrary = Just
Expand Down
3 changes: 2 additions & 1 deletion Cabal-tests/tests/ParserTests/regressions/anynone.expr
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ GenericPackageDescription {
dataDir = ".",
extraSrcFiles = [],
extraTmpFiles = [],
extraDocFiles = []},
extraDocFiles = [],
packageConstraints = []},
gpdScannedVersion = Nothing,
genPackageFlags = [],
condLibrary = Just
Expand Down
3 changes: 2 additions & 1 deletion Cabal-tests/tests/ParserTests/regressions/big-version.expr
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ GenericPackageDescription {
dataDir = ".",
extraSrcFiles = [],
extraTmpFiles = [],
extraDocFiles = []},
extraDocFiles = [],
packageConstraints = []},
gpdScannedVersion = Nothing,
genPackageFlags = [],
condLibrary = Just
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ GenericPackageDescription {
dataDir = ".",
extraSrcFiles = [],
extraTmpFiles = [],
extraDocFiles = []},
extraDocFiles = [],
packageConstraints = []},
gpdScannedVersion = Nothing,
genPackageFlags = [
MkPackageFlag {
Expand Down
3 changes: 2 additions & 1 deletion Cabal-tests/tests/ParserTests/regressions/common.expr
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ GenericPackageDescription {
dataDir = ".",
extraSrcFiles = [],
extraTmpFiles = [],
extraDocFiles = []},
extraDocFiles = [],
packageConstraints = []},
gpdScannedVersion = Nothing,
genPackageFlags = [],
condLibrary = Just
Expand Down
3 changes: 2 additions & 1 deletion Cabal-tests/tests/ParserTests/regressions/common2.expr
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ GenericPackageDescription {
dataDir = ".",
extraSrcFiles = [],
extraTmpFiles = [],
extraDocFiles = []},
extraDocFiles = [],
packageConstraints = []},
gpdScannedVersion = Nothing,
genPackageFlags = [],
condLibrary = Just
Expand Down
3 changes: 2 additions & 1 deletion Cabal-tests/tests/ParserTests/regressions/common3.expr
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ GenericPackageDescription {
dataDir = ".",
extraSrcFiles = [],
extraTmpFiles = [],
extraDocFiles = []},
extraDocFiles = [],
packageConstraints = []},
gpdScannedVersion = Nothing,
genPackageFlags = [],
condLibrary = Just
Expand Down
Loading
Loading