Skip to content

Commit

Permalink
Merge pull request #6538 from phadej/stricter-build-depends-parsec
Browse files Browse the repository at this point in the history
Disallow spaces around colon in Parsec Dependency
  • Loading branch information
phadej authored Feb 14, 2020
2 parents 320c716 + c6dab7a commit a4c5511
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 10 deletions.
38 changes: 33 additions & 5 deletions Cabal/Distribution/Types/Dependency.hs
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ instance NFData Dependency where rnf = genericRnf

instance Pretty Dependency where
pretty (Dependency name ver sublibs) = pretty name
<+> optionalMonoid
(sublibs /= Set.singleton LMainLibName)
(PP.colon <+> PP.braces prettySublibs)
<<>> optionalMonoid
(sublibs /= Set.singleton LMainLibName)
(PP.colon <<>> PP.braces prettySublibs)
<+> pretty ver
where
optionalMonoid True x = x
Expand All @@ -81,12 +81,40 @@ versionGuardMultilibs expr = do
else
expr

-- |
--
-- >>> simpleParsec "mylib:sub" :: Maybe Dependency
-- Just (Dependency (PackageName "mylib") AnyVersion (fromList [LSubLibName (UnqualComponentName "sub")]))
--
-- >>> simpleParsec "mylib:{sub1,sub2}" :: Maybe Dependency
-- Just (Dependency (PackageName "mylib") AnyVersion (fromList [LSubLibName (UnqualComponentName "sub1"),LSubLibName (UnqualComponentName "sub2")]))
--
-- >>> simpleParsec "mylib:{ sub1 , sub2 }" :: Maybe Dependency
-- Just (Dependency (PackageName "mylib") AnyVersion (fromList [LSubLibName (UnqualComponentName "sub1"),LSubLibName (UnqualComponentName "sub2")]))
--
-- >>> simpleParsec "mylib:{ sub1 , sub2 } ^>= 42" :: Maybe Dependency
-- Just (Dependency (PackageName "mylib") (MajorBoundVersion (mkVersion [42])) (fromList [LSubLibName (UnqualComponentName "sub1"),LSubLibName (UnqualComponentName "sub2")]))
--
-- Spaces around colon are not allowed:
--
-- >>> simpleParsec "mylib: sub" :: Maybe Dependency
-- Nothing
--
-- >>> simpleParsec "mylib :sub" :: Maybe Dependency
-- Nothing
--
-- >>> simpleParsec "mylib: {sub1,sub2}" :: Maybe Dependency
-- Nothing
--
-- >>> simpleParsec "mylib :{sub1,sub2}" :: Maybe Dependency
-- Nothing
--
instance Parsec Dependency where
parsec = do
name <- lexemeParsec
name <- parsec

libs <- option [LMainLibName]
$ (char ':' *> spaces *>)
$ (char ':' *>)
$ versionGuardMultilibs
$ pure <$> parseLib name <|> parseMultipleLibs name

Expand Down
8 changes: 4 additions & 4 deletions Cabal/tests/ParserTests/regressions/issue-5846.format
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ version: 5846
library
default-language: Haskell2010
build-depends:
lib1 : {a, b} -any,
lib2 : {c} -any,
lib3 : {d} >=1,
lib4 : {a, b} >=1
lib1:{a, b} -any,
lib2:{c} -any,
lib3:{d} >=1,
lib4:{a, b} >=1
2 changes: 1 addition & 1 deletion cabal-testsuite/PackageTests/MultipleLibraries/cabal.out
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ Preprocessing library 'privatelib' for d-0.1.0.0..
Building library 'privatelib' for d-0.1.0.0..
Configuring library for p-0.1.0.0..
cabal: Encountered missing or private dependencies:
d : {privatelib} ==0.1.0.0
d:{privatelib} ==0.1.0.0

0 comments on commit a4c5511

Please sign in to comment.