Skip to content
Merged
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## Changes in 0.39.5
- When rendering build dependencies in a Cabal file, Hpack no longer excludes
the reference to the main library from the shorthand syntax such as
`my-package:{my-package,my-library1,mylibrary2}`.

## Changes in 0.39.4
- Remove upper on `crypton`

Expand Down
4 changes: 2 additions & 2 deletions hpack.cabal

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
spec-version: 0.36.0
name: hpack
version: 0.39.4
version: 0.39.5
synopsis: A modern format for Haskell packages
description: See the README at <https://github.com/sol/hpack#readme>
author: Simon Hengel <sol@typeful.net>
Expand Down
17 changes: 11 additions & 6 deletions src/Hpack/Syntax/Dependencies.hs
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,15 @@ parseDependency :: Fail.MonadFail m => String -> Text -> m (String, DependencyVe
parseDependency subject = fmap fromCabal . cabalParse subject . T.unpack
where
fromCabal :: D.Dependency -> (String, DependencyVersion)
fromCabal d = (toName (D.depPkgName d) (DependencySet.toList $ D.depLibraries d), DependencyVersion Nothing . versionConstraintFromCabal $ D.depVerRange d)
fromCabal (D.Dependency pkgName verRange libraries) =
(depName, DependencyVersion Nothing $ versionConstraintFromCabal verRange)
where
depName :: String
depName = prettyShow pkgName <> case DependencySet.toList libraries of
[D.LMainLibName] -> ""
[D.LSubLibName name] -> ":" <> prettyShow name
xs -> ":{" <> intercalate "," (map renderComponent xs) <> "}"

toName :: D.PackageName -> [D.LibraryName] -> String
toName package components = prettyShow package <> case components of
[D.LMainLibName] -> ""
[D.LSubLibName lib] -> ":" <> prettyShow lib
xs -> ":{" <> (intercalate "," $ map prettyShow [name | D.LSubLibName name <- xs]) <> "}"
renderComponent :: D.LibraryName -> String
renderComponent D.LMainLibName = prettyShow pkgName
renderComponent (D.LSubLibName name) = prettyShow name
3 changes: 3 additions & 0 deletions test/Hpack/Syntax/DependenciesSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ spec = do
it "accepts dependencies with multiple subcomponents" $ do
parseDependency "dependency" "foo:{bar,baz}" `shouldReturn` ("foo:{bar,baz}", DependencyVersion Nothing AnyVersion)

it "accepts dependencies with multiple subcomponents including the main library" $ do
parseDependency "dependency" "foo:{foo,bar,baz}" `shouldReturn` ("foo:{foo,bar,baz}", DependencyVersion Nothing AnyVersion)

describe "fromValue" $ do
context "when parsing Dependencies" $ do
context "with a scalar" $ do
Expand Down
Loading