Skip to content

Commit fa80f1b

Browse files
committed
findGhcPkgField return result for only first package
Fixes error caused when same package is installed both locally and in the Stackage snapshot.
1 parent 4f49c94 commit fa80f1b

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

src/Stack/GhcPkg.hs

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -95,24 +95,26 @@ packageDbFlags pkgDbs =
9595
: map (\x -> ("--package-db=" ++ toFilePath x)) pkgDbs
9696

9797
-- | Get the value of a field of the package.
98-
findGhcPkgField :: (MonadIO m, MonadLogger m, MonadBaseControl IO m, MonadCatch m, MonadThrow m)
99-
=> EnvOverride
100-
-> [Path Abs Dir] -- ^ package databases
101-
-> Text
102-
-> Text
103-
-> m (Maybe Text)
98+
findGhcPkgField
99+
:: (MonadIO m, MonadLogger m, MonadBaseControl IO m, MonadCatch m, MonadThrow m)
100+
=> EnvOverride
101+
-> [Path Abs Dir] -- ^ package databases
102+
-> Text
103+
-> Text
104+
-> m (Maybe Text)
104105
findGhcPkgField menv pkgDbs name field = do
105-
result <- ghcPkg menv pkgDbs ["field", T.unpack name, T.unpack field]
106-
return $ case result of
107-
Left{} -> Nothing
108-
Right lbs ->
109-
case map (stripCR . T.decodeUtf8) (S8.lines lbs) of
110-
[] -> Nothing
111-
(line:lines_) ->
112-
case T.stripPrefix (T.append field ": ") line of
113-
Nothing -> Nothing
114-
Just line' -> Just $ T.intercalate "\n" (line':lines_)
115-
where stripCR t = fromMaybe t (T.stripSuffix "\r" t)
106+
result <-
107+
ghcPkg
108+
menv
109+
pkgDbs
110+
["field", "--simple-output", T.unpack name, T.unpack field]
111+
return $
112+
case result of
113+
Left{} -> Nothing
114+
Right lbs ->
115+
fmap (stripCR . T.decodeUtf8) $ listToMaybe $ S8.lines lbs
116+
where
117+
stripCR t = fromMaybe t (T.stripSuffix "\r" t)
116118

117119
-- | Get the id of the package e.g. @foo-0.0.0-9c293923c0685761dcff6f8c3ad8f8ec@.
118120
findGhcPkgId :: (MonadIO m, MonadLogger m, MonadBaseControl IO m, MonadCatch m, MonadThrow m)

0 commit comments

Comments
 (0)