Skip to content

Commit a4c5511

Browse files
authored
Merge pull request #6538 from phadej/stricter-build-depends-parsec
Disallow spaces around colon in Parsec Dependency
2 parents 320c716 + c6dab7a commit a4c5511

File tree

3 files changed

+38
-10
lines changed

3 files changed

+38
-10
lines changed

Cabal/Distribution/Types/Dependency.hs

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ instance NFData Dependency where rnf = genericRnf
5757

5858
instance Pretty Dependency where
5959
pretty (Dependency name ver sublibs) = pretty name
60-
<+> optionalMonoid
61-
(sublibs /= Set.singleton LMainLibName)
62-
(PP.colon <+> PP.braces prettySublibs)
60+
<<>> optionalMonoid
61+
(sublibs /= Set.singleton LMainLibName)
62+
(PP.colon <<>> PP.braces prettySublibs)
6363
<+> pretty ver
6464
where
6565
optionalMonoid True x = x
@@ -81,12 +81,40 @@ versionGuardMultilibs expr = do
8181
else
8282
expr
8383

84+
-- |
85+
--
86+
-- >>> simpleParsec "mylib:sub" :: Maybe Dependency
87+
-- Just (Dependency (PackageName "mylib") AnyVersion (fromList [LSubLibName (UnqualComponentName "sub")]))
88+
--
89+
-- >>> simpleParsec "mylib:{sub1,sub2}" :: Maybe Dependency
90+
-- Just (Dependency (PackageName "mylib") AnyVersion (fromList [LSubLibName (UnqualComponentName "sub1"),LSubLibName (UnqualComponentName "sub2")]))
91+
--
92+
-- >>> simpleParsec "mylib:{ sub1 , sub2 }" :: Maybe Dependency
93+
-- Just (Dependency (PackageName "mylib") AnyVersion (fromList [LSubLibName (UnqualComponentName "sub1"),LSubLibName (UnqualComponentName "sub2")]))
94+
--
95+
-- >>> simpleParsec "mylib:{ sub1 , sub2 } ^>= 42" :: Maybe Dependency
96+
-- Just (Dependency (PackageName "mylib") (MajorBoundVersion (mkVersion [42])) (fromList [LSubLibName (UnqualComponentName "sub1"),LSubLibName (UnqualComponentName "sub2")]))
97+
--
98+
-- Spaces around colon are not allowed:
99+
--
100+
-- >>> simpleParsec "mylib: sub" :: Maybe Dependency
101+
-- Nothing
102+
--
103+
-- >>> simpleParsec "mylib :sub" :: Maybe Dependency
104+
-- Nothing
105+
--
106+
-- >>> simpleParsec "mylib: {sub1,sub2}" :: Maybe Dependency
107+
-- Nothing
108+
--
109+
-- >>> simpleParsec "mylib :{sub1,sub2}" :: Maybe Dependency
110+
-- Nothing
111+
--
84112
instance Parsec Dependency where
85113
parsec = do
86-
name <- lexemeParsec
114+
name <- parsec
87115

88116
libs <- option [LMainLibName]
89-
$ (char ':' *> spaces *>)
117+
$ (char ':' *>)
90118
$ versionGuardMultilibs
91119
$ pure <$> parseLib name <|> parseMultipleLibs name
92120

Cabal/tests/ParserTests/regressions/issue-5846.format

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ version: 5846
55
library
66
default-language: Haskell2010
77
build-depends:
8-
lib1 : {a, b} -any,
9-
lib2 : {c} -any,
10-
lib3 : {d} >=1,
11-
lib4 : {a, b} >=1
8+
lib1:{a, b} -any,
9+
lib2:{c} -any,
10+
lib3:{d} >=1,
11+
lib4:{a, b} >=1

cabal-testsuite/PackageTests/MultipleLibraries/cabal.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ Preprocessing library 'privatelib' for d-0.1.0.0..
99
Building library 'privatelib' for d-0.1.0.0..
1010
Configuring library for p-0.1.0.0..
1111
cabal: Encountered missing or private dependencies:
12-
d : {privatelib} ==0.1.0.0
12+
d:{privatelib} ==0.1.0.0

0 commit comments

Comments
 (0)