BuildWrapper is currently NOT maintained anymore. Feel free to fork and take up maintainership!
BuildWrapper is a program designed to help an IDE deal with a Haskell project. It combines several tools under a simple API:
BuildWrapper provides a library and an executable. Intended usage is mostly through the executable. This is how it's used by EclipseFP, the set of Haskell development plugins for the Eclipse IDE. This executable is short-lived, it is not a running server as scion (the project BuildWrapper is an evolution of) or scion-browser. You launch it with parameters, it perform some work, and returns a JSON result. BuildWrapper uses a temporary work folder inside the project to store both a copy of the source files and the result of its operations. In an IDE setting, the content of the temporary folder may contain files representing unsaved data, which allow BuildWrapper to use Cabal and file based operations regardless.
You can run
buildwrapper --help to get a feel for the different options you can call buildwrapper with. You can also run EclipseFP with the debug mode preference on to see the BuildWrapper interaction in an Eclipse console view.
BuildWrapper may fail/crash if cabal-install was built against a different version of Cabal than the version of Cabal that BuildWrapper was built against.
These options are available to all commands.
Synchronize ensures that all the files in the temporary work folder represent the up to date version of the source files. It returns the list of files actually copied from the main folder to the work folder.
buildwrapper synchronize --force=false --tempfolder=.dist-buildwrapper --cabalpath=/home/myuser/.cabal/bin/cabal --cabalfile=/home/myuser/myproject/myproject.cabal --cabalflags= --logcabal=true
Synchronizes only one file.
Updates the content of the file in the work folder. Note that an external tool could also write directly in the work folder.
Runs cabal configure on the project. This command usually is not needed, as the build command will trigger a configure if needed. Returns the errors encountered, if any.
Runs cabal build on the project. Returns the errors encountered, if any, and the files processed during that build.
buildwrapper build --output=true --cabaltarget=Source --tempfolder=.dist-buildwrapper --cabalpath=/home/myuser/.cabal/bin/cabal --cabalfile=/home/myuser/myproject/myproject.cabal --cabalflags= --logcabal=true
Build one file using the GHC API. BuildWrapper takes care of calling the API with the proper flags from the cabal file. Returns the errors encountered during the build, if any. The AST and the build flags used are stored in a hidden file alongside the source file in the work folder. This file, with the .bwinfo extension, is plain JSON and can be parsed by an external tool if need be.
Returns the build flags use to build a particular file
Returns an outline of the file: the top level declarations, the import and export statements. This is generated using haskell-src-exts so the file does not need to be correct in respect to the typechecker, but needs to be valid Haskell syntax. If need be, the file is pre-processed by cpp2hs.
Returns a collection of lexer tokens for a particular file. The tokens have a type assigned to them (documentation, symbols, etc). This is used to provide syntax coloring in an IDE. If need be, the file is pre-processed and the preprocessor tokens are returned in the collection too.
Find all occurrences of the given text in lexer tokens. Only fully matching tokens are retrieved.
Returns the object found at a particular point in a source. Information can include a name, a module, a type, a haddock type code. This uses the generated .bwinfo file to perform the search so does not invoke the GHC API unless necessary (.bwinfo file missing or older than source)
Returns the list of names in scope (GHC API call)
Returns the list of names defined locally to a point in the source (inside the function, say)
Returns the cleaned imports line: the location and import text for the minimal required imports
Returns the list of all package dependencies for all cabal components in the cabal file, with the package database they are registered in
Returns the list of all components of the cabal file (executables, library, test suites)