Skip to content

Commit e04dbd4

Browse files
angermanhamishmackmaksbotan
authored
Cabal 3.2 support (input-output-hk#86)
* migration to Cabal 3.2 * Use shellFor { tools = ...; } * Fix compilation with Cabal-3.2 * Update cabal.project * Update default.nix generated by plan-to-nix plan-to-nix generated `default.nix` that was incompatible with newer interface of `haskell.nix` repo. * Update compiler to ghc883 Co-authored-by: Hamish Mackenzie <[email protected]> Co-authored-by: Maxim Koltsov <[email protected]>
1 parent 8f8b481 commit e04dbd4

File tree

12 files changed

+154
-91
lines changed

12 files changed

+154
-91
lines changed

.buildkite/build.sh

100755100644
Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#! /usr/bin/env nix-shell
2-
#! nix-shell -I "nixpkgs=channel:nixos-19.09" --pure -i bash -p nix cabal-install ghc git nix-prefetch-git cacert
2+
#! nix-shell -I "nixpkgs=channel:nixos-20.03" --pure -i bash -p nix cabal-install ghc git nix-prefetch-git cacert
33

4-
export NIX_PATH="nixpkgs=channel:nixos-19.09"
4+
export NIX_PATH="nixpkgs=channel:nixos-20.03"
55
index_state="2020-01-10T00:00:00Z"
66
expected_hash="0z2jc4fibfxz88pfgjq3wk5j3v7sn34xkwb8h60hbwfwhhy63vx6"
77

@@ -12,14 +12,17 @@ set -euo pipefail
1212
rm -f .nix-tools.cache
1313

1414
echo "+++ Cabal configure"
15-
cabal new-update "hackage.haskell.org,$index_state"
15+
cabal new-update
1616
cabal new-configure
1717

1818
echo
1919
echo "+++ Run stable version of plan-to-nix"
20-
nix build '(let haskellNix = builtins.fetchTarball "https://github.com/input-output-hk/haskell.nix/archive/master.tar.gz"; in (import (haskellNix + "/nixpkgs") (import haskellNix)).haskell-nix.nix-tools)' -o nt
20+
nix build '(let haskellNix = import (builtins.fetchTarball "https://github.com/input-output-hk/haskell.nix/archive/master.tar.gz") {}; in (import haskellNix.sources.nixpkgs-default haskellNix.nixpkgsArgs).haskell-nix.nix-tools)' -o nt
2121
./nt/bin/plan-to-nix --output .buildkite/nix1 --plan-json dist-newstyle/cache/plan.json
2222

23+
# Replace currently broken plan-to-nix output
24+
cp .buildkite/fixed.nix .buildkite/nix1/default.nix
25+
2326
echo
2427
echo "+++ Build project"
2528
nix build -f .buildkite/nix1 nix-tools.components.exes --no-link
@@ -31,8 +34,8 @@ echo "There are no tests -- https://github.com/input-output-hk/haskell.nix/issue
3134
echo
3235
echo "+++ Add runtime dependencies to PATH"
3336

34-
nix build -f channel:nixos-19.03 nix-prefetch-scripts -o nix-prefetch-scripts
35-
nix build -f channel:nixos-19.03 git -o git
37+
nix build -f channel:nixos-20.03 nix-prefetch-scripts -o nix-prefetch-scripts
38+
nix build -f channel:nixos-20.03 git -o git
3639
export PATH="$PWD/nix-prefetch-scripts/bin:$PWD/git/bin:$PATH"
3740

3841
echo
@@ -45,6 +48,10 @@ rm -f .nix-tools.cache
4548
nix build -f .buildkite/nix1 nix-tools.components.exes.plan-to-nix
4649
./result/bin/plan-to-nix --output .buildkite/nix2 --plan-json dist-newstyle/cache/plan.json
4750

51+
# Add module needed to allow Cabal 3.2 to be installed
52+
sed -i -e 's|modules = \[\]|modules = \[{ nonReinstallablePkgs = \[ "rts" "ghc-heap" "ghc-prim" "integer-gmp" "integer-simple" "base" "deepseq" "array" "ghc-boot-th" "pretty" "template-haskell" "ghcjs-prim" "ghcjs-th" "ghc-boot" "ghc" "Win32" "array" "binary" "bytestring" "containers" "directory" "filepath" "ghc-boot" "ghc-compact" "ghc-prim" "hpc" "mtl" "parsec" "process" "text" "time" "transformers" "unix" "xhtml" "stm" "terminfo" \]; }\]|' \
53+
.buildkite/nix2/default.nix
54+
4855
echo
4956
echo "+++ Build project"
5057

@@ -53,7 +60,10 @@ nix build -f .buildkite/nix2 nix-tools.components.exes --no-link
5360
echo
5461
echo "--- Test index file truncation"
5562

56-
find /nix/store/ -name "*-00-index.tar.gz" -exec nix-store --delete {} \;
63+
shopt -s nullglob
64+
for a in /nix/store/*-00-index.tar.gz; do nix-store --delete $a; done
65+
shopt -u nullglob
66+
5767
nix build -f test/truncate-index.nix --no-link \
5868
--arg nix-tools-path ./.buildkite/nix2 \
5969
--argstr index-state "$index_state" \

.buildkite/fixed.nix

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{ haskellNix ? import (builtins.fetchTarball https://github.com/input-output-hk/haskell.nix/archive/master.tar.gz) {}
2+
, nixpkgs ? haskellNix.sources.nixpkgs-default }:
3+
4+
let
5+
pkgs = import nixpkgs haskellNix.nixpkgsArgs;
6+
7+
pkgSet = pkgs.haskell-nix.mkCabalProjectPkgSet {
8+
plan-pkgs = import ./pkgs.nix;
9+
pkg-def-extras = [];
10+
modules = [{
11+
nonReinstallablePkgs= [ "rts" "ghc-heap" "ghc-prim" "integer-gmp" "integer-simple" "base"
12+
"deepseq" "array" "ghc-boot-th" "pretty" "template-haskell"
13+
# ghcjs custom packages
14+
"ghcjs-prim" "ghcjs-th"
15+
"ghc-boot"
16+
"ghc" "Win32" "array" "binary" "bytestring" "containers"
17+
"directory" "filepath" "ghc-boot" "ghc-compact" "ghc-prim"
18+
# "ghci" "haskeline"
19+
"hpc"
20+
"mtl" "parsec" "process" "text" "time" "transformers"
21+
"unix" "xhtml"
22+
# "stm" "terminfo"
23+
];
24+
}];
25+
};
26+
27+
in
28+
pkgSet.config.hsPkgs

cabal.project

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,13 @@
1-
index-state: 2020-01-10T00:00:00Z
1+
index-state: 2020-05-03T00:00:00Z
22

33
packages: .
44

5-
-- Needs https://github.com/input-output-hk/iohk-nix/commit/6a8c29117eff36ce975e02e01efc8b25d93fcb90#diff-6fb0c6517b547a8baf082d5d2d604842
6-
-- to work with the data-dir issues when building components.
7-
8-
constraints: hnix >= 0.6.1
9-
105
source-repository-package
116
type: git
12-
location: https://github.com/ElvishJerricco/hackage-db.git
13-
tag: 84ca9fc75ad45a71880e938e0d93ea4bde05f5bd
14-
--sha256: 0y3kw1hrxhsqmyx59sxba8npj4ya8dpgjljc21gkgdvdy9628q4c
7+
location: https://github.com/hamishmack/hackage-db.git
8+
tag: f1f528db7b02d90e9953297c716de5e046f3570f
9+
--sha256: 0j86xkpndxn41sy2mchx029zc3isaxh61hdvnakpiflkcmfaji1w
1510

16-
source-repository-package
17-
type: git
18-
location: https://github.com/galenhuntington/haskell-src-meta.git
19-
tag: 109ee29d5fd0f4e23fdd2f80eb122d66341b64a9
20-
--sha256: 08qw6y9br6fy3qkwl9v2kp38msprsq9v1ssym0fsnj2jm0vbnfrx
11+
-- hnix requires hnix-store-core < 0.2, however hnix-store-core-0.1 breaks
12+
-- plan construction.
13+
allow-newer: hnix-store-core

default.nix

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,35 @@
11
{ haskellNixSrc ? builtins.fetchTarball {
2-
url = "https://github.com/input-output-hk/haskell.nix/archive/a84e3b55c642e7aec57c9677158cf446d90e9759.tar.gz";
3-
sha256 = "0qnchf0f8d5k6363mcrqv936wz6zljs06bjvg1i6xmkg31bdj48m";
2+
url = "https://github.com/input-output-hk/haskell.nix/archive/f78841c2d05c6c686d3888131104360944464dc2.tar.gz";
3+
sha256 = "1zwhskx9drd0266kcrxf5vzcgs9vfiiibzkc2h3yarfb2xl7185q";
44
}
5-
, nixpkgs ? haskellNixSrc + "/nixpkgs"
6-
, pkgs ? import nixpkgs (import haskellNixSrc)
7-
, haskellCompiler ? "ghc865"
5+
, nixpkgs ? (import haskellNixSrc {}).sources.nixpkgs-default
6+
, pkgs ? import nixpkgs (import haskellNixSrc {}).nixpkgsArgs
7+
, haskellCompiler ? "ghc883"
88
}:
9-
pkgs.haskell-nix.cabalProject {
10-
src = pkgs.haskell-nix.haskellLib.cleanGit { src = ./.; };
9+
let
10+
project = pkgs.haskell-nix.cabalProject {
11+
src = pkgs.haskell-nix.haskellLib.cleanGit { src = ./.; name = "nix-tools"; };
1112
ghc = pkgs.haskell-nix.compiler.${haskellCompiler};
13+
modules = [{
14+
nonReinstallablePkgs= [ "rts" "ghc-heap" "ghc-prim" "integer-gmp" "integer-simple" "base"
15+
"deepseq" "array" "ghc-boot-th" "pretty" "template-haskell"
16+
# ghcjs custom packages
17+
"ghcjs-prim" "ghcjs-th"
18+
"ghc-boot"
19+
"ghc" "Win32" "array" "binary" "bytestring" "containers"
20+
"directory" "filepath" "ghc-boot" "ghc-compact" "ghc-prim"
21+
# "ghci" "haskeline"
22+
"hpc"
23+
"mtl" "parsec" "process" "text" "time" "transformers"
24+
"unix" "xhtml"
25+
# "stm" "terminfo"
26+
];
27+
}];
28+
};
29+
in
30+
project // {
31+
shell = project.shellFor {
32+
tools = { cabal = "3.2.0.0"; };
33+
};
1234
}
1335

hackage2nix/Main.hs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module Main where
66
import Cabal2Nix
77
import Control.Applicative ( liftA2 )
88
import Control.Monad.Trans.State.Strict
9-
import Crypto.Hash.SHA256 ( hashlazy )
9+
import Crypto.Hash.SHA256 ( hash )
1010
import Data.Aeson
1111
import Data.Aeson.Types ( Pair )
1212
import Data.Aeson.Encode.Pretty
@@ -73,10 +73,10 @@ main = do
7373
createDirectoryIfMissing False (out </> "hackage")
7474

7575
for_ cabalFiles $ \(cabalFile, pname, path) -> do
76-
gpd <- cabal2nix False MinimalDetails src $ InMemory Nothing pname $ BL.toStrict cabalFile
76+
gpd <- cabal2nix False MinimalDetails src $ InMemory Nothing pname $ cabalFile
7777
writeFile (out </> path) $ show $ prettyNix gpd
7878

79-
type GPDWriter = State (Seq (BL.ByteString, String, FilePath))
79+
type GPDWriter = State (Seq (BS.ByteString, String, FilePath))
8080

8181
newtype ApplicativeMonoid f a = ApplicativeMonoid { unApplicativeMonoid :: f a }
8282
instance (Applicative f, Semigroup a) => Sem.Semigroup (ApplicativeMonoid f a) where
@@ -116,7 +116,7 @@ version2json pname vnum (U.VersionData { U.cabalFileRevisions, U.metaFile }) =
116116
revBindingJson
117117
:: PackageName
118118
-> Version
119-
-> BL.ByteString
119+
-> BS.ByteString
120120
-> Integer
121121
-> GPDWriter (Text, Value)
122122
revBindingJson pname vnum cabalFile revNum = do
@@ -127,7 +127,7 @@ revBindingJson pname vnum cabalFile revNum = do
127127
revName = "r" <> fromString (show revNum)
128128
revPath = "." </> "hackage" </> qualifiedName <.> "nix"
129129
prettyPname = fromPretty pname
130-
cabalHash = Base16.encode $ hashlazy cabalFile
130+
cabalHash = Base16.encode $ hash cabalFile
131131
modify' $ mappend $ Seq.singleton
132132
(cabalFile, prettyPname ++ ".cabal", revPath)
133133
return $ revName .= object

lib/Cabal2Nix.hs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ module Cabal2Nix (cabal2nix, gpd2nix, Src(..), CabalFile(..), CabalFileGenerator
66

77
import Distribution.PackageDescription.Parsec (readGenericPackageDescription, parseGenericPackageDescription, runParseResult)
88
import Distribution.Verbosity (normal)
9-
import Distribution.Text (disp)
109
import Distribution.Pretty (pretty)
10+
import Distribution.Utils.ShortText (fromShortText)
1111
import Data.Char (toUpper)
1212
import System.FilePath
1313
import Data.ByteString (ByteString)
@@ -225,24 +225,24 @@ applyMkDefault :: NExpr -> NExpr
225225
applyMkDefault expr = mkSym pkgs @. "lib" @. "mkDefault" @@ expr
226226

227227
instance ToNixExpr PackageIdentifier where
228-
toNix ident = mkNonRecSet [ "name" $= mkStr (fromString (show (disp (pkgName ident))))
229-
, "version" $= mkStr (fromString (show (disp (pkgVersion ident))))]
228+
toNix ident = mkNonRecSet [ "name" $= mkStr (fromString (show (pretty (pkgName ident))))
229+
, "version" $= mkStr (fromString (show (pretty (pkgVersion ident))))]
230230

231231
toNixPackageDescription :: Bool -> CabalDetailLevel -> PackageDescription -> NExpr
232232
toNixPackageDescription isLocal detailLevel pd = mkNonRecSet $
233-
[ "specVersion" $= mkStr (fromString (show (disp (specVersion pd))))
233+
[ "specVersion" $= mkStr (fromString (show (pretty (specVersion pd))))
234234
, "identifier" $= toNix (package pd)
235235
, "license" $= mkStr (fromString (show (pretty (license pd))))
236236

237-
, "copyright" $= mkStr (fromString (copyright pd))
238-
, "maintainer" $= mkStr (fromString (maintainer pd))
239-
, "author" $= mkStr (fromString (author pd))
237+
, "copyright" $= mkStr (fromString (fromShortText (copyright pd)))
238+
, "maintainer" $= mkStr (fromString (fromShortText (maintainer pd)))
239+
, "author" $= mkStr (fromString (fromShortText (author pd)))
240240

241-
, "homepage" $= mkStr (fromString (homepage pd))
242-
, "url" $= mkStr (fromString (pkgUrl pd))
241+
, "homepage" $= mkStr (fromString (fromShortText (homepage pd)))
242+
, "url" $= mkStr (fromString (fromShortText (pkgUrl pd)))
243243

244-
, "synopsis" $= mkStr (fromString (synopsis pd))
245-
, "description" $= mkStr (fromString (description pd))
244+
, "synopsis" $= mkStr (fromString (fromShortText (synopsis pd)))
245+
, "description" $= mkStr (fromString (fromShortText (description pd)))
246246

247247
, "buildType" $= mkStr (fromString (show (pretty (buildType pd))))
248248
] ++
@@ -288,7 +288,7 @@ mkPrivateHackageUrl :: String -> PackageIdentifier -> String
288288
mkPrivateHackageUrl hackageUrl pi' =
289289
hackageUrl <> "/package/" <> pkgNameVersion <> "/" <> pkgNameVersion <> ".tar.gz"
290290
where
291-
pkgNameVersion = unPackageName (pkgName pi') <> "-" <> show (disp (pkgVersion pi'))
291+
pkgNameVersion = unPackageName (pkgName pi') <> "-" <> show (pretty (pkgVersion pi'))
292292

293293
newtype SysDependency = SysDependency { unSysDependency :: String } deriving (Show, Eq, Ord)
294294
newtype BuildToolDependency = BuildToolDependency { unBuildToolDependency :: PackageName } deriving (Show, Eq, Ord)
@@ -302,7 +302,7 @@ toNixGenericPackageDescription isLocal detailLevel gpd = mkNonRecSet
302302
, "package" $= toNixPackageDescription isLocal detailLevel (packageDescription gpd)
303303
, "components" $= components ]
304304
where _packageName :: IsString a => a
305-
_packageName = fromString . show . disp . pkgName . package . packageDescription $ gpd
305+
_packageName = fromString . show . pretty . pkgName . package . packageDescription $ gpd
306306
component :: IsComponent comp => UnqualComponentName -> CondTree ConfVar [Dependency] comp -> Binding NExpr
307307
component unQualName comp
308308
= quoted name $=
@@ -396,13 +396,13 @@ instance ToNixExpr CompilerFlavor where
396396

397397
instance ToNixExpr (VersionRangeF VersionRange) where
398398
toNix AnyVersionF = mkBool True
399-
toNix (ThisVersionF ver) = mkSym "compiler" @. "version" @. "eq" @@ mkStr (fromString (show (disp ver)))
400-
toNix (LaterVersionF ver) = mkSym "compiler" @. "version" @. "gt" @@ mkStr (fromString (show (disp ver)))
401-
toNix (OrLaterVersionF ver) = mkSym "compiler" @. "version" @. "ge" @@ mkStr (fromString (show (disp ver)))
402-
toNix (EarlierVersionF ver) = mkSym "compiler" @. "version" @. "lt" @@ mkStr (fromString (show (disp ver)))
403-
toNix (OrEarlierVersionF ver) = mkSym "compiler" @. "version" @. "le" @@ mkStr (fromString (show (disp ver)))
399+
toNix (ThisVersionF ver) = mkSym "compiler" @. "version" @. "eq" @@ mkStr (fromString (show (pretty ver)))
400+
toNix (LaterVersionF ver) = mkSym "compiler" @. "version" @. "gt" @@ mkStr (fromString (show (pretty ver)))
401+
toNix (OrLaterVersionF ver) = mkSym "compiler" @. "version" @. "ge" @@ mkStr (fromString (show (pretty ver)))
402+
toNix (EarlierVersionF ver) = mkSym "compiler" @. "version" @. "lt" @@ mkStr (fromString (show (pretty ver)))
403+
toNix (OrEarlierVersionF ver) = mkSym "compiler" @. "version" @. "le" @@ mkStr (fromString (show (pretty ver)))
404404
toNix (WildcardVersionF _ver) = mkBool False
405-
-- toNix (MajorBoundVersionF ver) = mkSym "compiler" @. "version" @. "eq" @@ mkStr (fromString (show (disp ver)))
405+
-- toNix (MajorBoundVersionF ver) = mkSym "compiler" @. "version" @. "eq" @@ mkStr (fromString (show (pretty ver)))
406406
toNix (IntersectVersionRangesF v1 v2) = toNix (projectVersionRange v1) $&& toNix (projectVersionRange v2)
407407
toNix x = error $ "ToNixExpr VersionRange for `" ++ show x ++ "` not implemented!"
408408

lib/Stack2nix.hs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ import Data.Text.Prettyprint.Doc.Render.Text (hPutDoc)
2828
import Distribution.Types.PackageId (PackageIdentifier(..))
2929
import Distribution.Nixpkgs.Fetch (DerivationSource(..), Source(..), Hash(..), fetch)
3030
import Distribution.Simple.Utils (shortRelativePath)
31-
import Distribution.Text (Text(..), simpleParse)
31+
import Distribution.Text (simpleParse)
32+
import Distribution.Pretty (Pretty(..))
3233

3334
import Cabal2Nix hiding (Git)
3435
import qualified Cabal2Nix as C2N
@@ -112,8 +113,8 @@ extraDeps2nix pkgs =
112113
| (PackageIdentifier pkg ver, (Just (Right revNo))) <- extraDeps ]
113114
where parsePackageIdentifier :: String -> Maybe PackageIdentifier
114115
parsePackageIdentifier = simpleParse
115-
toText :: Text a => a -> T.Text
116-
toText = fromString . show . disp
116+
toText :: Pretty a => a -> T.Text
117+
toText = fromString . show . pretty
117118

118119
-- | Converts 'PackageFlags' into @{ packageName = { flags = { flagA = BOOL; flagB = BOOL; }; }; }@
119120
flags2nix :: PackageFlags -> [Binding NExpr]

lib/Stack2nix/Stack.hs

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,11 @@ import Data.Monoid (mempty)
2727

2828
import Distribution.Types.PackageName
2929
import Distribution.Types.PackageId
30-
import Distribution.Compat.ReadP hiding (Parser)
3130
import Distribution.Text
31+
import Distribution.Pretty
32+
import Distribution.Parsec
33+
import Distribution.Compat.CharParsing
34+
import Distribution.Parsec.FieldLineStream
3235
import Distribution.Types.Version (nullVersion)
3336

3437
import qualified Data.HashMap.Strict as HM
@@ -101,9 +104,11 @@ newtype CabalRev = CabalRev Int -- cabal revision 0,1,2,...
101104
type URL = String -- Git/Hg/... URL
102105
type Rev = String -- Git revision
103106

104-
instance Text CabalRev where
105-
disp (CabalRev rev) = "r" <> disp rev
106-
parse = char 'r' *> (CabalRev <$> parse)
107+
instance Pretty CabalRev where
108+
pretty (CabalRev rev) = "r" <> pretty rev
109+
110+
instance Parsec CabalRev where
111+
parsec = char 'r' *> (CabalRev <$> integral)
107112

108113
--------------------------------------------------------------------------------
109114
-- Data Types
@@ -148,26 +153,26 @@ data Location
148153

149154
--------------------------------------------------------------------------------
150155
-- Parsers for package indices
151-
sha256Suffix :: ReadP r Sha256
152-
sha256Suffix = string "@sha256:" *> many1 (satisfy (`elem` (['0'..'9']++['a'..'z']++['A'..'Z'])))
156+
sha256Suffix :: ParsecParser Sha256
157+
sha256Suffix = string "@sha256:" *> some (satisfy (`elem` (['0'..'9']++['a'..'z']++['A'..'Z'])))
153158
-- Stack supports optional cabal file size after revision's SHA value,
154159
-- we parse it but it doesn't get used
155-
<* optional (char ',' <* many1 (satisfy isDigit))
156-
157-
revSuffix :: ReadP r CabalRev
158-
revSuffix = string "@rev:" *> (CabalRev . read <$> many1 (satisfy (`elem` ['0'..'9'])))
160+
<* optional (char ',' <* some (satisfy isDigit))
159161

160-
suffix :: ReadP r (Maybe (Either Sha256 CabalRev))
161-
suffix = option Nothing (Just <$> (Left <$> sha256Suffix) +++ (Right <$> revSuffix))
162+
revSuffix :: ParsecParser CabalRev
163+
revSuffix = string "@rev:" *> (CabalRev . read <$> some (satisfy (`elem` ['0'..'9'])))
162164

163-
pkgIndex :: ReadP r Dependency
164-
pkgIndex = PkgIndex <$> parse <*> suffix <* eof
165+
suffix :: ParsecParser (Maybe (Either Sha256 CabalRev))
166+
suffix = option Nothing (Just <$> ((Left <$> sha256Suffix) <|> (Right <$> revSuffix)))
165167

168+
pkgIndex :: ParsecParser Dependency
169+
pkgIndex = PkgIndex <$> parsec <*> suffix <* eof
166170

167171
parsePackageIdentifier :: String -> Maybe (PackageIdentifier, Maybe (Either Sha256 CabalRev))
168-
parsePackageIdentifier input = case readP_to_S pkgIndex input of
169-
[(PkgIndex d rev,"")] -> Just (d, rev)
170-
_ -> Nothing
172+
parsePackageIdentifier input =
173+
case runParsecParser pkgIndex "<parsePackageIdentifier>" (fieldLineStreamFromString input) of
174+
Right (PkgIndex d rev) -> Just (d, rev)
175+
_ -> Nothing
171176

172177
--------------------------------------------------------------------------------
173178
-- JSON/YAML destructors
@@ -209,12 +214,12 @@ instance FromJSON Dependency where
209214
-- to be ./foo-X.Y.Z
210215
parseJSON p = parsePkgIndex p <|> parseLocalPath p <|> parseDVCS p
211216
where parsePkgIndex = withText "Package Index" $ \pi ->
212-
case [pi' | (pi',"") <- readP_to_S pkgIndex (T.unpack pi)] of
217+
case parsePackageIdentifier (T.unpack pi) of
213218
-- Cabal will happily parse "foo" as a packageIdentifier,
214219
-- we however are only interested in those that have a version
215220
-- as well. Any valid version is larger than @nullVersion@, as
216221
-- such we can use that as a filter.
217-
[pi'@(PkgIndex pkgIdent _)] | pkgVersion pkgIdent > nullVersion -> return $ pi'
222+
(Just (pkgIdent, s)) | pkgVersion pkgIdent > nullVersion -> return $ PkgIndex pkgIdent s
218223
_ -> fail $ "invalid package index: " ++ show pi
219224
parseLocalPath = withText "Local Path" $
220225
return . LocalPath . dropTrailingSlash . T.unpack

0 commit comments

Comments
 (0)