My program consists of 4 executables, and basically zero library code. My tests work by running the executables with various input files.
"stack test --coverage" apparently doesn't handle executables. OK, fine, but I can't figure out how to do it "by hand", as it were.
I've tried adding -fhpc to my cabal files, and it appears to work:
/home/rlpowell/.stack/programs/x86_64-linux/ghc-8.0.1/lib/ghc-8.0.1/bin/ghc -B/home/rlpowell/.stack/programs/x86_64-linux/ghc-8.0.1/lib/ghc-8.0.1 --make -no-link -fbuilding-cabal-package -O -static -outputdir .stack-work/dist/x86_64-linux/Cabal-1.24.0.0/build/unphone/unphone-tmp -odir .stack-work/dist/x86_64-linux/Cabal-1.24.0.0/build/unphone/unphone-tmp -hidir .stack-work/dist/x86_64-linux/Cabal-1.24.0.0/build/unphone/unphone-tmp -stubdir .stack-work/dist/x86_64-linux/Cabal-1.24.0.0/build/unphone/unphone-tmp -i -i.stack-work/dist/x86_64-linux/Cabal-1.24.0.0/build/unphone/unphone-tmp -iapp -i.stack-work/dist/x86_64-linux/Cabal-1.24.0.0/build/autogen -I.stack-work/dist/x86_64-linux/Cabal-1.24.0.0/build/autogen -I.stack-work/dist/x86_64-linux/Cabal-1.24.0.0/build/unphone/unphone-tmp -optP-include -optP.stack-work/dist/x86_64-linux/Cabal-1.24.0.0/build/autogen/cabal_macros.h -hide-all-packages -no-user-package-db -package-db /home/rlpowell/.stack/snapshots/x86_64-linux/lts-7.4/8.0.1/pkgdb -package-db /dropbox/src/hblog/.stack-work/install/x86_64-linux/lts-7.4/8.0.1/pkgdb -package-db .stack-work/dist/x86_64-linux/Cabal-1.24.0.0/package.conf.inplace -package-id base-4.9.0.0 -package-id directory-1.2.6.2 -package-id filemanip-0.3.6.3-DFENeGbODv96RwGywUxkEu -package-id filepath-1.4.1.0 -package-id hblog-0.1.0.0-5BseEsncIi47yHhFL2tGbM -package-id pcre-heavy-1.0.0.2-ncNpc9J5vG8YMUKvU47xG -package-id pcre-light-0.4.0.4-IQAaYrFkWFB49U9V8o5b8j -package-id unix-2.7.2.0 -XHaskell2010 app/unphone.hs -threaded -Wall -fhpc -Wall -fhpc -ddump-hi -ddump-to-file
but after running the programs thus generated, I can't find a .hpc directory or any .tix files.
On my computer the .hpc files ended up in .stack-work/dist/x86_64-linux/Cabal-1.24.2.0/hpc/ and the .tix file was in the working directory.
This is a bash script I use for testing an executable with no library code:
#!/usr/bin/env bash
stack build --coverage
stack exec tests
while getopts ":r" opt; do
case $opt in
r)
hpc markup --hpcdir=.stack-work/dist/x86_64-linux/Cabal-1.24.2.0/hpc/ --destdir=coverage_markup tests.tix
firefox coverage_markup/hpc_index.html
sleep 120
esac
done
rm -rf coverage_markup
rm tests.tix
Related
I am trying out c2hs, and wanted to compile a small example of a shared library with Cabal to get started.
I have the following relevant section of the cabal file test.cabal:
executable libtest.so
hs-source-dirs: src
main-is: Dummy.hs
other-extensions: ForeignFunctionInterface
build-depends: base
default-language: Haskell2010
ghc-options: -no-hs-main -threaded
build-tools: c2hs
Then the source. src/Dummy.hs:
import Test
main :: IO ()
main = return
In the file src/Test.chs
{-# LANGUAGE ForeignFunctionInterface #-}
import Foreign
import Foreign.C
module Android where
And then when I try to compile (cabal configure && cabal build -v) I get the following error message:
Component build order: executable 'libtest.so'
creating dist/build
creating dist/build/autogen
Building test-0.1.0.0...
Preprocessing executable 'libtest.so' for test-0.1.0.0...
Building executable libtest.so...
creating dist/build/libtest.so
creating dist/build/libtest.so/libtest.so-tmp
/opt/ghc/bin/ghc --make -no-link -fbuilding-cabal-package -O -j8 -static
-outputdir dist/build/libtest.so/libtest.so-tmp -odir dist/build
/libtest.so/libtest.so-tmp -hidir dist/build/libtest.so/libtest.so-tmp-stubdir
dist/build/libtest.so/libtest.so-tmp -i -idist/build/libtest.so/libtest.so-tmp
-isrc -idist/build/autogen -Idist/build/autogen
-Idist/build/libtest.so/libtest.so-tmp
-optP-include -optPdist/build/autogen/cabal_macros.h -hide-all-packages
-package-db dist/package.conf.inplace -package-id
base-4.7.0.1-1a55ebc8256b39ccbff004d48b3eb834 -XHaskell2010
src/Dummy.hs -no-hs-main -threaded
src/Dummy.hs:1:8:
Could not find module ‘Test’
Use -v to see a list of the files searched for.
Please, can you tell me what the cause of the error is? What am I missing?
You need to add Test to the other-modules field.
I'm trying do some web scraping using HXT, but one dependency, hxt-regex-xmlschema-9.2.0, always fails to install. The error is ld: library not found for -lHSparsec-3.1.7-ghc7.8.3. I don't understand why the linking is failing. I have parsec installed - cabal install parsec-3.1.7 worked fine. I'm running OSX 10.10.1, GHC 7.8.3, and gcc 4.9.1.
EDIT: The output from cabal install hxt-regex-xmlschema-9.2.0:
Configuring hxt-regex-xmlschema-9.2.0...
Dependency base ==4.7.0.1: using base-4.7.0.1
Dependency bytestring ==0.10.4.0: using bytestring-0.10.4.0
Dependency hxt-charproperties ==9.2.0.0: using hxt-charproperties-9.2.0.0
Dependency parsec ==3.1.7: using parsec-3.1.7
Dependency text ==1.2.0.3: using text-1.2.0.3
/usr/local/bin/ghc --info
Using Cabal-1.18.1.4 compiled by ghc-7.8
Using compiler: ghc-7.8.3
Using install prefix: /Users/rjayatilleka/.cabal
Binaries installed in: /Users/rjayatilleka/.cabal/bin
Libraries installed in:
/Users/rjayatilleka/.cabal/lib/x86_64-osx-ghc-7.8.3/hxt-regex-xmlschema-9.2.0
Private binaries installed in: /Users/rjayatilleka/.cabal/libexec
Data files installed in:
/Users/rjayatilleka/.cabal/share/x86_64-osx-ghc-7.8.3/hxt-regex-xmlschema-9.2.0
Documentation installed in:
/Users/rjayatilleka/.cabal/share/doc/x86_64-osx-ghc-7.8.3/hxt-regex-xmlschema-9.2.0
Configuration files installed in: /Users/rjayatilleka/.cabal/etc
Using alex version 3.0.5 found on system at: /usr/local/bin/alex
Using ar found on system at: /usr/bin/ar
Using c2hs version 0.17.2 found on system at:
/Users/rjayatilleka/.cabal/bin/c2hs
Using cpphs version 1.18.5 found on system at:
/Users/rjayatilleka/.cabal/bin/cpphs
No ffihugs found
Using gcc version 4.9.1 found on system at: /usr/local/bin/gcc
Using ghc version 7.8.3 found on system at: /usr/local/bin/ghc
Using ghc-pkg version 7.8.3 found on system at: /usr/local/bin/ghc-pkg
No greencard found
Using haddock version 2.14.3 found on system at: /usr/local/bin/haddock
Using happy version 1.18.10 found on system at: /usr/local/bin/happy
No hmake found
Using hpc version 0.67 found on system at: /usr/local/bin/hpc
Using hsc2hs version 0.67 found on system at: /usr/local/bin/hsc2hs
Using hscolour version 1.20 found on system at:
/Users/rjayatilleka/.cabal/bin/HsColour
No hugs found
No jhc found
Using ld found on system at: /usr/bin/ld
No lhc found
No lhc-pkg found
No nhc98 found
Using pkg-config version 0.28 found on system at: /usr/local/bin/pkg-config
Using ranlib found on system at: /usr/bin/ranlib
Using strip found on system at: /usr/bin/strip
Using tar found on system at: /usr/bin/tar
No uhc found
Component build order: library
creating dist/build
creating dist/build/autogen
Building hxt-regex-xmlschema-9.2.0...
Preprocessing library hxt-regex-xmlschema-9.2.0...
Building library...
/usr/local/bin/ghc --info
/usr/local/bin/ghc --info
creating dist/build
/usr/local/bin/ghc --make -fbuilding-cabal-package -O -static -dynamic-too -dynosuf dyn_o -dynhisuf dyn_hi -outputdir dist/build -odir dist/build -hidir dist/build -stubdir dist/build -i -idist/build -isrc -idist/build/autogen -Idist/build/autogen -Idist/build -optP-include -optPdist/build/autogen/cabal_macros.h -package-name hxt-regex-xmlschema-9.2.0 -hide-all-packages -package-db dist/package.conf.inplace -package-id base-4.7.0.1-c64d224738ec7af4085e89ca9c12c37b -package-id bytestring-0.10.4.0-18fe2f3ce284617c82da1702e16772cf -package-id hxt-charproperties-9.2.0.0-36acaa39288f4b2bce2f5dc5cd48c479 -package-id parsec-3.1.7-764aedfe24d8f24850146ae17e380232 -package-id text-1.2.0.3-ebea8c0126422e0e6e5e972676f2f18d -XHaskell2010 Text.Regex.Glob.String Text.Regex.Glob.Generic Text.Regex.Glob.Generic.RegexParser Text.Regex.XMLSchema.String Text.Regex.XMLSchema.Generic Text.Regex.XMLSchema.Generic.Matching Text.Regex.XMLSchema.Generic.RegexParser Text.Regex.XMLSchema.Generic.Regex Text.Regex.XMLSchema.Generic.StringLike -threaded -rtsopts -Wall -fwarn-tabs -funbox-strict-fields
[1 of 9] Compiling Text.Regex.XMLSchema.Generic.StringLike ( src/Text/Regex/XMLSchema/Generic/StringLike.hs, dist/build/Text/Regex/XMLSchema/Generic/StringLike.o )
[2 of 9] Compiling Text.Regex.XMLSchema.Generic.Regex ( src/Text/Regex/XMLSchema/Generic/Regex.hs, dist/build/Text/Regex/XMLSchema/Generic/Regex.o )
[3 of 9] Compiling Text.Regex.XMLSchema.Generic.RegexParser ( src/Text/Regex/XMLSchema/Generic/RegexParser.hs, dist/build/Text/Regex/XMLSchema/Generic/RegexParser.o )
[4 of 9] Compiling Text.Regex.XMLSchema.Generic.Matching ( src/Text/Regex/XMLSchema/Generic/Matching.hs, dist/build/Text/Regex/XMLSchema/Generic/Matching.o )
[5 of 9] Compiling Text.Regex.XMLSchema.Generic ( src/Text/Regex/XMLSchema/Generic.hs, dist/build/Text/Regex/XMLSchema/Generic.o )
[6 of 9] Compiling Text.Regex.XMLSchema.String ( src/Text/Regex/XMLSchema/String.hs, dist/build/Text/Regex/XMLSchema/String.o )
[7 of 9] Compiling Text.Regex.Glob.Generic.RegexParser ( src/Text/Regex/Glob/Generic/RegexParser.hs, dist/build/Text/Regex/Glob/Generic/RegexParser.o )
[8 of 9] Compiling Text.Regex.Glob.Generic ( src/Text/Regex/Glob/Generic.hs, dist/build/Text/Regex/Glob/Generic.o )
[9 of 9] Compiling Text.Regex.Glob.String ( src/Text/Regex/Glob/String.hs, dist/build/Text/Regex/Glob/String.o )
Linking...
/usr/bin/ar -r -s dist/build/libHShxt-regex-xmlschema-9.2.0.a dist/build/Text/Regex/Glob/String.o dist/build/Text/Regex/Glob/Generic.o dist/build/Text/Regex/Glob/Generic/RegexParser.o dist/build/Text/Regex/XMLSchema/String.o dist/build/Text/Regex/XMLSchema/Generic.o dist/build/Text/Regex/XMLSchema/Generic/Matching.o dist/build/Text/Regex/XMLSchema/Generic/RegexParser.o dist/build/Text/Regex/XMLSchema/Generic/Regex.o dist/build/Text/Regex/XMLSchema/Generic/StringLike.o
ar: creating archive dist/build/libHShxt-regex-xmlschema-9.2.0.a
/usr/local/bin/ghc -shared -dynamic -package-name hxt-regex-xmlschema-9.2.0 -no-auto-link-packages -package-db dist/package.conf.inplace -package-id base-4.7.0.1-c64d224738ec7af4085e89ca9c12c37b -package-id bytestring-0.10.4.0-18fe2f3ce284617c82da1702e16772cf -package-id hxt-charproperties-9.2.0.0-36acaa39288f4b2bce2f5dc5cd48c479 -package-id parsec-3.1.7-764aedfe24d8f24850146ae17e380232 -package-id text-1.2.0.3-ebea8c0126422e0e6e5e972676f2f18d dist/build/Text/Regex/Glob/String.dyn_o dist/build/Text/Regex/Glob/Generic.dyn_o dist/build/Text/Regex/Glob/Generic/RegexParser.dyn_o dist/build/Text/Regex/XMLSchema/String.dyn_o dist/build/Text/Regex/XMLSchema/Generic.dyn_o dist/build/Text/Regex/XMLSchema/Generic/Matching.dyn_o dist/build/Text/Regex/XMLSchema/Generic/RegexParser.dyn_o dist/build/Text/Regex/XMLSchema/Generic/Regex.dyn_o dist/build/Text/Regex/XMLSchema/Generic/StringLike.dyn_o -o dist/build/libHShxt-regex-xmlschema-9.2.0-ghc7.8.3.dylib
ld: library not found for -lHSparsec-3.1.7-ghc7.8.3
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Reading available packages...
Choosing modular solver.
Resolving dependencies...
Ready to install hxt-regex-xmlschema-9.2.0
Waiting for install task to finish...
Extracting
/Users/rjayatilleka/.cabal/packages/hackage.haskell.org/hxt-regex-xmlschema/9.2.0/hxt-regex-xmlschema-9.2.0.tar.gz
to
/var/folders/71/k93g7g992nlf9t6mkqbykv600000gn/T/hxt-regex-xmlschema-9.2.0-64074...
Updating hxt-regex-xmlschema.cabal with the latest revision from the index.
creating
/var/folders/71/k93g7g992nlf9t6mkqbykv600000gn/T/hxt-regex-xmlschema-9.2.0-64074/hxt-regex-xmlschema-9.2.0/dist/setup
creating
/var/folders/71/k93g7g992nlf9t6mkqbykv600000gn/T/hxt-regex-xmlschema-9.2.0-64074/hxt-regex-xmlschema-9.2.0/dist
creating
/var/folders/71/k93g7g992nlf9t6mkqbykv600000gn/T/hxt-regex-xmlschema-9.2.0-64074/hxt-regex-xmlschema-9.2.0/dist/setup
/Users/rjayatilleka/.cabal/setup-exe-cache/setup-Cabal-1.18.1.4-ghc-7.8.3
configure --verbose=2 --ghc --prefix=/Users/rjayatilleka/.cabal --user
--constraint=text ==1.2.0.3 --constraint=parsec ==3.1.7
--constraint=hxt-charproperties ==9.2.0.0 --constraint=bytestring ==0.10.4.0
--constraint=base ==4.7.0.1 --disable-tests --disable-benchmarks
creating
/var/folders/71/k93g7g992nlf9t6mkqbykv600000gn/T/hxt-regex-xmlschema-9.2.0-64074/hxt-regex-xmlschema-9.2.0/dist/setup
/Users/rjayatilleka/.cabal/setup-exe-cache/setup-Cabal-1.18.1.4-ghc-7.8.3
build --verbose=2
Failed to install hxt-regex-xmlschema-9.2.0
World file is already up to date.
cabal: Error: some packages failed to install:
hxt-regex-xmlschema-9.2.0 failed during the building phase. The exception was:
ExitFailure 1
Well, I kind of left it for a while, and came back to it now. It worked for some reason. The only thing I can think of is that I upgraded from GHC 7.8.3 to 7.8.4. If anyone comes up with this again, try a different version of GHC.
I've run into the same error for two unrelated packages now, missingpy and monadiccp.
> cabal install -p -v monadiccp
(after some output)
Creating dist/build (and its parents)
/usr/local/haskell/bin/ghc --make -package-name monadiccp-0.7.0 -hide-all-packages -fbuilding-cabal-package -i -idist/build -i. -idist/build/autogen -Idist/build/autogen -Idist/build -Ilib -optP-include -optPdist/build/autogen/cabal_macros.h -odir dist/build -hidir dist/build -stubdir dist/build -package-id Monatron-0.3.1-360ddfdcf06bcd34f1ed9c1f1c375202 -package-id base-4.3.1.0-1554f26e1cc1c87f47464e927dddbd20 -package-id containers-0.4.0.0-8781485edb2ac0db733a9f9c72e27945 -package-id haskell98-1.1.0.1-0a04bcdb24934b6be516a3abfc033021 -package-id mtl-2.0.1.0-91f62d81c946aa60137dcc008e554a3a -package-id pretty-1.0.1.2-6970e62db724fea03caad23f58dd8f86 -package-id random-1.0.0.3-9024b40453c28359a37c49ce4e776f6e -O -XHaskell98 Data.Expr.Sugar Control.CP.SearchTree Control.CP.Transformers Control.CP.ComposableTransformers Control.CP.Solver Control.CP.PriorityQueue Control.CP.Queue Control.CP.FD.Interface Control.CP.FD.OvertonFD.OvertonFD Control.CP.FD.OvertonFD.Sugar Control.CP.EnumTerm Control.CP.FD.Solvers Control.CP.FD.Gecode.CodegenSolver Control.CP.FD.Model Control.CP.FD.Example Data.Expr.Data Data.Expr.Util Data.Linear Control.CP.FD.Gecode.Common Control.CP.FD.OvertonFD.Domain Control.CP.FD.SimpleFD Control.CP.FD.Graph Control.CP.FD.Decompose Control.CP.FD.FD Control.CP.Debug Control.Mixin.Mixin Control.CP.SearchSpec.Language Control.CP.SearchSpec.Generator Language.CPP.Syntax.AST Language.CPP.Pretty
<command line>: cannot satisfy -package-id random-1.0.0.3-9024b40453c28359a37c49ce4e776f6e:
random-1.0.0.3-9024b40453c28359a37c49ce4e776f6e is shadowed by package random-1.0.0.3-15ae8b1458485ee9647f74174e442c33
(use -v for more information)
World file is already up to date.
For missingpy, ghc will work if the -package-id random... is changed to the correct version, but I don't know how to install it after that.
Any workarounds would be much appreciated. I deleted all of ~/.cabal and ~/.ghc, but no luck.
additional info
ghc info is here, [ http://pastebin.com/jk40VPgw ]. This is my SuSE machine, where I built ghc 7.0.4 from source using ghc 6.12, as well as the latest Haskell Platform. (which was made for ghc 7.0.3, but I think that's okay).
also tried this on another machine [ http://pastebin.com/Digntv4K ]. that one had the Haskell Platform installed via system packages I think.
Have you tried cabal-dev? It's probably best if you start from a clean system, install only the Haskell Platform, and then use cabal-dev to sandbox each codebase you're using.
This is an embarrassingly simple problem, but its solution yet eludes me. As the title indicates, I simply want to specify to GHC the location of all my source files. This should be simple; the GHC user guide:
-idirs
This flag appends a colon-separated
list of dirs to the search path.
So, I tried the following invocations:
ghc -isrc/ -v -outputdir build/ --make -Wall Main.hs
ghc -isrc/: -v -outputdir build/ --make -Wall Main.hs
ghc -i:src/: -v -outputdir build/ --make -Wall Main.hs
ghc -i"src/" -v -outputdir build/ --make -Wall Main.hs
ghc -i"src/": -v -outputdir build/ --make -Wall Main.hs
ghc -i:"src/": -v -outputdir build/ --make -Wall Main.hs
On every invocation GHC gave the error: "<no location info>: can't find file: Main.hs"
As you probably could have guessed, Main.hs is located in a subdirectory from the working directory called "src". Just in case it matters, I'm on Windows XP, and I'm using GHC 6.12.2. I'm assuming there is some small problem that I'm just missing.
-i specifies where GHC will search for other source files, other than the ones you specify on the command line. So your Main.hs there will also need a src/ prefix. E.g.
$ ghc -isrc src/Main.hs --make
[1 of 1] Compiling Main ( src/Main.hs, src/Main.o )
Linking src/Main ...
Alternatively, you could use cabal, and have cabal init generate all the build metadata for you.
I'm trying to install the nano-hmac-0.2.0 package (a dependency of a package I want) from Hackage using Cabal and GHC 6.12.1, but it fails with the following error:
Data/Digest/OpenSSL/HMAC.hsc:1:0:
Warning: Module `Prelude' is deprecated:
You are using the old package `base' version 3.x.
Future GHC versions will not support base version 3.x. You
should update your code to use the new base version 4.x.
<no location info>:
Failing due to -Werror.
Sure enough, the package's .cabal file has the following line in it:
ghc-options: -Wall -Werror -O2 -fvia-C
I'd like to be able to override the -Werror option so I can install the package without manually modifying the .cabal file, but can't find a way that will work. In particular, I tried passing --ghc-options to Cabal to stick a -Wwarn in GHC's argument list, like this:
$ cabal install nano-hmac-0.2.0 -v2 --ghc-options='-Wwarn'
This doesn't do what I want, though; the verbose output verifies that -Wwarn is getting added to the beginning of GHC's argument list, but the -Werror from the .cabal file appears later and seems to override it:
/usr/bin/ghc -Wwarn --make -package-name nano-hmac-0.2.0 -hide-all-packages -fbuilding-cabal-package -i -idist/build -i. -idist/build/autogen -Idist/build/autogen -Idist/build -optP-include -optPdist/build/autogen/cabal_macros.h -odir dist/build -hidir dist/build -stubdir dist/build -package-id base-3.0.3.2-0092f5a086872e0cdaf979254933cd43 -package-id bytestring-0.9.1.5-125aff5b9d19ec30231ae2684b8c8577 -O -Wall -Werror -O2 -fvia-C -XForeignFunctionInterface -XBangPatterns -XCPP Data.Digest.OpenSSL.HMAC
I also tried passing --constraint='base >= 4' to Cabal to force it to use a more recent version of base and avoid the warning entirely, but I get the same failure, and I still see the following in the verbose output:
Dependency base ==3.0.3.2: using base-3.0.3.2
Is there a way to get rid of or override the -Werror coming from the .cabal file via the Cabal command line, or am I stuck modifying the .cabal file myself?
Is there a way to get rid of or override the -Werror coming from the .cabal file via the Cabal command line, or am I stuck modifying the .cabal file myself?
Indeed. There's no way in general. You may be able to override package constraints such that the warnings go away, however, in general, you must modify the .cabal file.
These days Hackage prevents people uploading packages with -Werror in their .cabal file, so the issue will go away over time.