cabal2db

Last updated: 2016-03-31 16:22:44 +0100

Upstream URL: git clone http://chriswarbo.net/git/cabal2db.git

Repo

View repository

View issue tracker

Contents of README follows


Build a database of Haskell syntax trees from Cabal packages (local or remote)

Files

dump-hackage

Downloads a given package name from Hackage, and runs <code>dump-package</code> on it.

Usage: <code>dump-hackage my-package-name</code>

dump-package

Takes a directory containing a Haskell package as an argument, sets up a GHC environment with all of its dependencies and runs <code>runAstPlugin</code>.

Usage: <code>dump-package path/to/package/</code>

runAstPlugin

Extracts ASTs from a Cabal package, by compiling it with a special GHC plugin. It’s recommended to use <code>dump-package</code> rather than calling this directly, to ensure all of the correct dependencies are available.

Usage: <code>runAstPlugin path/to/package/</code>

ghcWithPlugin.nix

Instructions for the Nix package manager to set up an environment with all dependencies of a given Haskell package. For example, <code>nix-shell -E 'import ./ghcWithPlugin.nix "foo"'</code> will create a shell environment including the Nix package <code>haskellPackages.foo</code>, hence making that package and its dependencies available to GHC. If <code>haskellPackages.foo</code> doesn’t exist, you can add it using Nix’s override mechanism.

test.sh

Test test suite for these tools. Accepts a regex as argument, to filter which tests are run. Functions beginning with <code>test</code> will be executed once, whilst functions beginning with <code>pkgTest</code> will be executed multiple times, with different package names.

<code>test.sh</code> tries to test with a selection of popular Hackage packages. Before running any tests, these packages are downloaded and built, as a sanity check to make sure any errors we run into are our own and not due to broken external packages. Hence, problems in this phase will be reported, but do not cause the test suite to fail. This cannot be skipped by filtering.

The tests themselves run <code>dump-hackage</code> and ensure the result is valid JSON.

The test script can also be controlled using the following environment variables:

<code>CABAL2DBTESTDIR</code>

If set, this will be used as the path for storing data (command outputs, debug traces, etc.). If not given, a temporary directory will be created. For example:

<pre><code>CABAL2DBTESTDIR=/tmp/foo ./test.sh</code></pre>

This will store data in <code>/tmp/foo/test-data</code>.

<pre><code>CABAL2DBTESTDIR=/tmp/bar ./test.sh CABAL2DBTESTDIR=/tmp/bar ./test.sh</code></pre>

This will run <code>./test.sh</code> twice. The intermediate results of the first run, stored in <code>/tmp/bar/test-data</code>, will be re-used by the second run, speeding up testing considerably.

<code>CABAL2DBCLEANUP</code>

If set, e.g. to <code>1</code>, tells <code>test.sh</code> to delete the <code>test-data</code> directory (and any temporary directories it made, if any) after it’s finished. For example:

<pre><code>CABAL2DBCLEANUP=1 ./test.sh</code></pre>

This will store intermediate results in a temporary directory, and delete that temp directory when it’s finished.

<pre><code>CABAL2DBCLEANUP=1 CABAL2DBTESTDIR=/tmp/foo ./test.sh</code></pre>

This will store intermediate results in <code>/tmp/foo/test-data</code>, and remove that directory (but not <code>/tmp/foo</code>) after it’s finished.

Specifying the same <code>CABAL2DBTESTDIR</code> across multiple invocation, without setting <code>CABAL2DBCLEANUP</code>, will cause the results of the first run to be re-used by subsequent tests.