How to configure syntastic to use build-depends and hs-source-dirs from my test suite in the .cabal file of the package? - haskell

Syntastic works great in my system with hdevtools and hlint. But if I'm editing a file under a test directory, importing packages that are exclusively under the test-suite configuration of the cabal package, it marks my imports as bogus and tells me to include them in my cabal file. The same problem happens with the hs-source-dir, it only finds the ones under the library or executable directory.

There is no silver bullet. You can either set g:syntastic_haskell_hdevtools_args and friends to the proper flags for your project, or write a wrapper script similar to this and point g:syntastic_haskell_hdevtools_exec to it. Syntastic has no built-in support for looking at cabal files.

Related

Intero doesn't find Paths-module when using cabal data files

When I use the data-files feature of cabal, it generates a Paths_pkgname.hs module that lives in the dist/ folder.
However, intero is unable to find this file (or generate it on its own), and I can't find any means to pass an option to hint at its position.
Note: Somewhere else (on SO?) I picked up the trick when using ghci to make a dummy only-for-ghci/Paths_.hs that is only brought into scope through :set -ionly-for-ghci being set in .ghci. This won't apply for intero though, as its invocation in intero.el specificcally instructs it to ignore the .ghci file.
I was only building my project using cabal and nix. It turns out that because Intero is stack-centric, building the project with stack build does indeed put a Paths_.. module in a place where Intero searches.

Hooking up a build tool in Cabal (Haskell)

I was trying to use bnfc tool to generate a bunch of files, like lexer, parser, etc. for me. This works fine. Now I wanted to clean this up a bit by not having to manually compile the bnfc file and having it generate a number of files which clutter my /src folder.
I tried the Cabal mechanism where you list the tool in build-tools field of the .cabal file and mention the files you expect to be generated by extra-source-files field. This worked for me for Alex and Happy as they are recognised as build-tools by Cabal but bnfc isn't. Is there a way I can hook up bnfc or any tool in general with Cabal and have Cabal recognise them as build-tools?
Apparently cabal doesn't know about bnfc (doesn't appear on the list).
Looks like there's no way to do it using just the .cabal file, but there's an example of how to hook up a preprocessor in your Setup.hs in the cabal sources under tests/PackageTests/CustomPreProcess/Setup.hs using the user hook hookedPreProcessors (all hooks are in UserHooks.hs)

How to set cabal extra dirs for all packages in a sandbox

I'm currently working on a Haskell project that uses lots of native code. This means that include files and libraries have to be accessible to cabal. I'm doing that by --extra-lib-dirs and --extra-include-dirs command-line flags.
I'm also using cabal sandboxes feature to avoid global dependency hell.
The trouble is that cabal often needs to reinstall some of my packages and thus rebuilds them, which requires native include files and libraries. So I have to specify --extra-lib-dirs and --extra-include-dirs at the command line when building any of my packages at all, even for those that don't require native code, which is very annoying.
I know I can use extra-lib-dirs and extra-include-dirs in .cabal files, but that ones don't allow relative paths and I prefer not committing files with absolute paths on my computer to a centralized repository.
So I wonder, is there any way to add directories to extra-lib-dirs or extra-include-dirs for all the packages in a sandbox? Or maybe globally for a computer?
You can simply create a local cabal.config in the directory where your sandbox is located. (Don't modify cabal.sandbox.config, as that file is auto-generated.)

Alex, Happy, Cabal, and Re-preprocessing

I am using Alex 3.0.5, Happy 1.18.10, Cabal 1.16.0.2
I have a small compiler project that is built using Cabal. I am exposing the compiler's internals as a library, so I have in the exposed modules section, MyLangLex and MyLangPar. If I delete the .hs files that are generated by Alex and Happy, then running cabal configure, and then cabal build will run Alex and Happy first, generate the files, and then proceed with the build, and everything works as expected. However, if I do not delete these files, Alex and Happy either do not build the files, or they don't put them in the right place. I think Happy runs, because I see a message from Happy; however, when I look at the .hs file that should be generated it is incorrect (doesn't have a change in it), and I can tell for sure that the version of the .hs file that Cabal uses in the build is the wrong one because the behaviour that should have changed does not. I.e. The change to the .y file does not get incorporated into the built program, so I suspect that while Happy is run, Cabal places this file in some temp directory, and then uses the old .hs file, which is still there for the build. But I am not sure about this.
Is the error on my part or is one of the tools misbehaving?
It sounds like you need a "other-modules:" directive in your library section for Lex.x and Par.y:
library
...
build-tools: alex, happy
other-modules: Compiler.RSL.Syntax.Lex, Compiler.RSL.Syntax.Par
The other-modules directive together with build-tools will instruct cabal to use alex and to create Compiler/RSL/Syntax/Lex.hs from the .x file if it doesn't exist (and the same for Par.hs).
Alternatively, add Compiler.RSL.Syntax.Lex to your 'exposed-modules' list. This tells cabal that the Lex.hs file should exist, and so if it doesn't cabal will look for ways to build it using the tools in the build-tools line.

Why cabal tool doesn't use Setup.lhs/Setup.hs?

I've added a putStrLn "Hello" line into main function of my Setup.lhs and was expecting to see it when running cabal configure or cabal build. But i did not.
Then i've compiled Setup.lhs with ghc --make and ran ./Setup configure and the line was shown.
If it's done intentionnaly, i don't see rationale behind this and even need in Setup.lhs file at all. Can you clear these things for me?
You most likely have
build-type: Simple
in your .cabal file. If you select the Simple build type, you essentially promise that your Setup file does nothing but invoke defaultMain, and the cabal binary will not invoke it. If you want to ensure that your Setup file is run every time, then change the line to
build-type: Custom
You also ask about the rationale for requiring the Setup file anyway: actually, it isn't required if you use the Simple build type. The cabal binary will happily configure and install it without. However, it is considered good style to include a Setup file for any package, because it will allow users to install the package who have the Cabal libary available, but not the cabal-install tool (and Hackage enforces the presence of a Setup file for this reason).

Resources