Skip to content

Commit 2a564ec

Browse files
committed
Update library-dirs parsing (#371)
1 parent 5b53624 commit 2a564ec

File tree

3 files changed

+112
-4
lines changed

3 files changed

+112
-4
lines changed

src/Stack/PackageDump.hs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ import Control.Monad.Catch
3131
import Control.Monad.IO.Class
3232
import Control.Monad.Logger (MonadLogger)
3333
import Control.Monad.Trans.Control
34+
import Data.Attoparsec.Args
35+
import Data.Attoparsec.Text as P
3436
import Data.Binary (Binary)
3537
import Data.Binary.VersionTagged (taggedDecodeOrLoad, taggedEncodeFile, BinarySchema (..))
3638
import Data.ByteString (ByteString)
@@ -46,6 +48,7 @@ import Data.Map (Map)
4648
import qualified Data.Map as Map
4749
import Data.Maybe (catMaybes)
4850
import qualified Data.Set as Set
51+
import qualified Data.Text.Encoding as T
4952
import Data.Typeable (Typeable)
5053
import GHC.Generics (Generic)
5154
import Path
@@ -190,7 +193,7 @@ addProfiling (InstalledCache ref) =
190193
Nothing -> do
191194
let loop [] = return False
192195
loop (dir:dirs) = do
193-
econtents <- tryIO $ getDirectoryContents $ S8.unpack dir
196+
econtents <- tryIO $ getDirectoryContents dir
194197
let contents = either (const []) id econtents
195198
if or [isProfiling content lib
196199
| content <- contents
@@ -235,7 +238,7 @@ addHaddock (InstalledCache ref) =
235238
-- | Dump information for a single package
236239
data DumpPackage profiling haddock = DumpPackage
237240
{ dpGhcPkgId :: !GhcPkgId
238-
, dpLibDirs :: ![ByteString]
241+
, dpLibDirs :: ![FilePath]
239242
, dpLibraries :: ![ByteString]
240243
, dpDepends :: ![GhcPkgId]
241244
, dpHaddockInterfaces :: ![ByteString]
@@ -247,6 +250,7 @@ data DumpPackage profiling haddock = DumpPackage
247250
data PackageDumpException
248251
= MissingSingleField ByteString (Map ByteString [Line])
249252
| MismatchedId PackageName Version GhcPkgId
253+
| Couldn'tParseField ByteString [Line]
250254
deriving Typeable
251255
instance Exception PackageDumpException
252256
instance Show PackageDumpException where
@@ -261,6 +265,8 @@ instance Show PackageDumpException where
261265
show (MismatchedId name version gid) =
262266
"Invalid id/name/version in ghc-pkg dump output: " ++
263267
show (name, version, gid)
268+
show (Couldn'tParseField name ls) =
269+
"Couldn't parse the field " ++ show name ++ " from lines: " ++ show ls
264270

265271
-- | Convert a stream of bytes into a stream of @DumpPackage@s
266272
conduitDumpPackage :: MonadThrow m
@@ -301,14 +307,20 @@ conduitDumpPackage = (=$= CL.catMaybes) $ eachSection $ do
301307
$ throwM $ MismatchedId name version ghcPkgId
302308

303309
-- if a package has no modules, these won't exist
304-
let libDirs = parseM "library-dirs"
310+
let libDirKey = "library-dirs"
311+
libDirs = parseM libDirKey
305312
libraries = parseM "hs-libraries"
306313
haddockInterfaces = parseM "haddock-interfaces"
307314
depends <- mapM parseDepend $ parseM "depends"
308315

316+
libDirPaths <-
317+
case mapM (P.parseOnly (argsParser NoEscaping) . T.decodeUtf8) libDirs of
318+
Left{} -> throwM (Couldn'tParseField libDirKey libDirs)
319+
Right dirs -> return (concat dirs)
320+
309321
return $ Just DumpPackage
310322
{ dpGhcPkgId = ghcPkgId
311-
, dpLibDirs = libDirs
323+
, dpLibDirs = libDirPaths
312324
, dpLibraries = S8.words $ S8.unwords libraries
313325
, dpDepends = catMaybes (depends :: [Maybe GhcPkgId])
314326
, dpHaddockInterfaces = S8.words $ S8.unwords haddockInterfaces

src/test/Stack/PackageDumpSpec.hs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,35 @@ spec = do
112112
, dpProfiling = ()
113113
, dpHaddock = ()
114114
}
115+
it "ghc 7.8.4 (osx)" $ do
116+
hmatrix:_ <- runResourceT
117+
$ CB.sourceFile "test/package-dump/ghc-7.8.4-osx.txt"
118+
$$ conduitDumpPackage
119+
=$ CL.consume
120+
ghcPkgId <- parseGhcPkgId "hmatrix-0.16.1.5-12d5d21f26aa98774cdd8edbc343fbfe"
121+
depends <- mapM parseGhcPkgId
122+
[ "array-0.5.0.0-470385a50d2b78598af85cfe9d988e1b"
123+
, "base-4.7.0.2-918c7ac27f65a87103264a9f51652d63"
124+
, "binary-0.7.1.0-108d06eea2ef05e517f9c1facf10f63c"
125+
, "bytestring-0.10.4.0-78bc8f2c724c765c78c004a84acf6cc3"
126+
, "deepseq-1.3.0.2-0ddc77716bd2515426e1ba39f6788a4f"
127+
, "random-1.1-822c19b7507b6ac1aaa4c66731e775ae"
128+
, "split-0.2.2-34cfb851cc3784e22bfae7a7bddda9c5"
129+
, "storable-complex-0.2.2-e962c368d58acc1f5b41d41edc93da72"
130+
, "vector-0.10.12.3-f4222db607fd5fdd7545d3e82419b307"]
131+
hmatrix `shouldBe` DumpPackage
132+
{ dpGhcPkgId = ghcPkgId
133+
, dpLibDirs =
134+
[ "/Users/alexbiehl/.stack/snapshots/x86_64-osx/lts-2.13/7.8.4/lib/x86_64-osx-ghc-7.8.4/hmatrix-0.16.1.5"
135+
, "/opt/local/lib/"
136+
, "/usr/local/lib/"
137+
, "C:/Program Files/Example/"]
138+
, dpHaddockInterfaces = ["/Users/alexbiehl/.stack/snapshots/x86_64-osx/lts-2.13/7.8.4/doc/html/hmatrix.haddock"]
139+
, dpDepends = depends
140+
, dpLibraries = ["HShmatrix-0.16.1.5"]
141+
, dpProfiling = ()
142+
, dpHaddock = ()
143+
}
115144

116145
it "ghcPkgDump + addProfiling + addHaddock" $ (id :: IO () -> IO ()) $ runNoLoggingT $ do
117146
menv' <- getEnvOverride buildPlatform
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
name: hmatrix
2+
version: 0.16.1.5
3+
id: hmatrix-0.16.1.5-12d5d21f26aa98774cdd8edbc343fbfe
4+
license: BSD3
5+
copyright:
6+
maintainer: Alberto Ruiz
7+
stability: provisional
8+
homepage: https://github.com/albertoruiz/hmatrix
9+
package-url:
10+
synopsis: Numeric Linear Algebra
11+
description: Linear algebra based on BLAS and LAPACK.
12+
.
13+
The package is organized as follows:
14+
.
15+
["Numeric.LinearAlgebra.HMatrix"] Starting point and recommended import module for most applications.
16+
.
17+
["Numeric.LinearAlgebra.Static"] Experimental alternative interface.
18+
.
19+
["Numeric.LinearAlgebra.Devel"] Tools for extending the library.
20+
.
21+
(Other modules are exposed with hidden documentation for backwards compatibility.)
22+
.
23+
Code examples: <http://dis.um.es/~alberto/hmatrix/hmatrix.html>
24+
category: Math
25+
author: Alberto Ruiz
26+
exposed: True
27+
exposed-modules: Data.Packed Data.Packed.Vector Data.Packed.Matrix
28+
Data.Packed.Foreign Data.Packed.ST Data.Packed.Development
29+
Numeric.LinearAlgebra Numeric.LinearAlgebra.LAPACK
30+
Numeric.LinearAlgebra.Algorithms Numeric.Container
31+
Numeric.LinearAlgebra.Util Numeric.LinearAlgebra.Devel
32+
Numeric.LinearAlgebra.Data Numeric.LinearAlgebra.HMatrix
33+
Numeric.LinearAlgebra.Static
34+
hidden-modules: Data.Packed.Internal Data.Packed.Internal.Common
35+
Data.Packed.Internal.Signatures Data.Packed.Internal.Vector
36+
Data.Packed.Internal.Matrix Data.Packed.IO Numeric.Chain
37+
Numeric.Vectorized Numeric.Vector Numeric.Matrix
38+
Data.Packed.Internal.Numeric Data.Packed.Numeric
39+
Numeric.LinearAlgebra.Util.Convolution
40+
Numeric.LinearAlgebra.Util.CG Numeric.LinearAlgebra.Random
41+
Numeric.Conversion Numeric.Sparse
42+
Numeric.LinearAlgebra.Static.Internal
43+
trusted: False
44+
import-dirs: /Users/alexbiehl/.stack/snapshots/x86_64-osx/lts-2.13/7.8.4/lib/x86_64-osx-ghc-7.8.4/hmatrix-0.16.1.5
45+
library-dirs: /Users/alexbiehl/.stack/snapshots/x86_64-osx/lts-2.13/7.8.4/lib/x86_64-osx-ghc-7.8.4/hmatrix-0.16.1.5
46+
/opt/local/lib/ /usr/local/lib/ "C:/Program Files/Example/"
47+
hs-libraries: HShmatrix-0.16.1.5
48+
extra-libraries: blas lapack
49+
extra-ghci-libraries:
50+
include-dirs: /opt/local/include/ /usr/local/include/
51+
includes:
52+
depends: array-0.5.0.0-470385a50d2b78598af85cfe9d988e1b
53+
base-4.7.0.2-918c7ac27f65a87103264a9f51652d63
54+
binary-0.7.1.0-108d06eea2ef05e517f9c1facf10f63c
55+
bytestring-0.10.4.0-78bc8f2c724c765c78c004a84acf6cc3
56+
deepseq-1.3.0.2-0ddc77716bd2515426e1ba39f6788a4f
57+
random-1.1-822c19b7507b6ac1aaa4c66731e775ae
58+
split-0.2.2-34cfb851cc3784e22bfae7a7bddda9c5
59+
storable-complex-0.2.2-e962c368d58acc1f5b41d41edc93da72
60+
vector-0.10.12.3-f4222db607fd5fdd7545d3e82419b307
61+
hugs-options:
62+
cc-options:
63+
ld-options:
64+
framework-dirs:
65+
frameworks: Accelerate
66+
haddock-interfaces: /Users/alexbiehl/.stack/snapshots/x86_64-osx/lts-2.13/7.8.4/doc/html/hmatrix.haddock
67+
haddock-html: /Users/alexbiehl/.stack/snapshots/x86_64-osx/lts-2.13/7.8.4/doc/html

0 commit comments

Comments
 (0)