1 Synopsis

Capri (abbreviation of CAbal PRIvate) is a wrapper program on top of cabal-install to operate it in project-private mode. In this mode, there is no global or user package databases; only one package database is defined, private to the project, located under the root directory of a project.

Capri is mainly intended for use with projects organized as Cabal packages targeting executables rather than just libraries. Capri is intended for use with Glasgow Haskell Compiler only as it depends on certain its features. It is also recommended to use cabal-install of recent versions (as of July 2010, the most recent version is 0.8.2).

2 Introduction

A situation is possible, when a local (global or user or both) Cabal packages database contains a package of the same name, but of several versions. Over time, other packages may be installed, depending on various versions of that package. Bad things happen when a new package is to be built, depending on other packages which in turn depend on different versions of the package mentioned first.

While such situation may be cured by careful tracing of dependencies, removal of old versions of packages, and rebuilding of new packages, there is a way to avoid it from the beginning. For each package, create a private database of packages it depends upon. This makes practical sense mainly for packages targeting statically linked executables, ensuring a clean build environment. Other than this, private building may be used for test builds of library packages as well, but it is not recommended to use libraries built privately together in other packages.

The Glasgow Haskell Compiler uses the GHC_PACKAGE_PATH environment variable to describe the location of Haskell packages database. A typical configuration of such database consists of global and user databases. Default locations of these databases are known to the compiler even when the variable is not set.

It is however possible to make GHC not to use any of these databases, and point it to an alternative location instead. In order to do this, the variable has to contain a single path, and not to be terminated with a path delimiter (colon or semicolon, depending on Unix/Windows platrorm). This is how project-private build is achieved at GHC level. Cabal-install in turn requires several options to be specified, to restrict itself to using only private packages database to look for installed packages, and the installation directory prefix which is also local to a project.

3 Source Location

4 Commands Summary

$ capri help
This program provides a wrapper over cabal-install to operate in project-private mode.
Usage: capri COMMAND [FLAGS]
or: capri [GLOBAL FLAGS]
Global flags:
-h --help Show this help text
-V --version Print version information
--numeric-version Print just the version number
Commands:
bootstrap Bootstrap private packages configuration
list List packages installed privately
clone Clone package(s) installed publicly into the private packages database
ghc-pkg Invoke the ghc-pkg program to run arbitrary action on private packages
cabal Invoke the cabal-install or Setup.{hs|lhs} program to run arbitrary action on private packages
import Build another package with respect to this package's private packages database and installation path
install Short-cut for cabal install command
configure Short-cut for cabal configure command
build Short-cut for cabal build command
help Help about commands
For more information about a command use
capri COMMAND --help
Typical steps of building Haskell projects with Capri:
capri bootstrap
capri clone
capri configure
capri build
capri install

5 Building Executables with Capri

This chapter covers the general scenario of building executables using Capri. We will call a Cabal package targeting one or more executables, containing its own private package database and build with use of Capri "the project". All other Cabal packages involved in building of the project will be referred to as just "packages".

5.1 Layout of Capri Files

Capri keeps its files under the .capri subdirectory of the project's root directory. Private packages database is located in .capri/packages, and compiled packages are installed in .capri/install subdirectories. Thus, typical location of executables built is .capri/install/bin relative to the project's root.

5.2 Bootstrapping Private Packages Database

Building of a package cannot start with entirely empty packages database: several essential packages have to be installed in order to build the project:

base
ffi
ghc-prim
integer-gmp
rts

It is assumed that some minimal GHC installation exists that contains at least these packages.

The capri bootstrap command created the private packages database and installation directory. Next, it clones the above mentioned packages into the private database. The capri list command may be used to verify that all packages have been installed properly, and the project is ready to build.

5.3 Building and Installation

The easiest way to build a project with Capri is just to type a shortcut command:

capri install

at the shell prompt once the private packages database has been bootstrapped. This results in running cabal install command within the project's top directory, with GHC_PACKAGE_PATH environment variable set properly, and --package-db and --prefix options supplied. If any custom options are needed, another (more flexible) form of this command may be issued:

capri cabal -- install <any options and parameters>

Note the double hyphen after cabal: anything following it will never be treated as options, and will be passed to the cabal-install program.

Although the install command covers package configuration and building, two more shortcut commands are available: capri configure and capri build.

5.4 Cloning Already Compiled Packages

Cloning was mentioned earlier in the Bootstrapping paragraph. Any of the packages installed in the global or user package database can be "cloned" into the private packages database of the project.

Technically cloning is equivalent to running the ghc-pkg describe <package-name> command piping its standard output to the ghc-pkg register command while the first command runs with GHC_PACKAGE_PATH set to access the global and user package databases, and the second runs with GHC_PACKAGE_PATH set to access the project private packages database.

5.5 Importing Local Source Packages

Cabal-install is capable of automatic chasing project dependencies, downloading, compiling, and installing their code. If however a package the project depends upon is not on Hackage or any other repository known to Cabal-install, the only way to bring it into the scope of the project's private package database is to manually compile it. This however should be done with respect to the project's private package configuration: all additional dependencies should be looked up in and installed into the project's packages database as well.

The capri import command serves this purpose. Its typical syntax is

capri import directory [-- command options]

The command is equivalent to running the <tt>cabal install in the other package's directory, but with GHC_PACKAGE_PATH set to the project's packages database, also supplying the --package-db and --prefix options as needed.

Simply typing capri install directory without any additional options results in execution of cabal install in directory. Note however that if double hyphen is used, command line parameters to the right of it should contain a command (configure, install, etc.)

6 Advanced Topics

6.1 Running ghc-pkg and cabal-install

The paragraphs above described shortcut commands (e. g. capri install or capri list) which execute cabal-install or ghc-pkg programs with predefined set of options. For more complex tasks such as manual unregistering of packages, or building the project with specific options, capri has two commands that allow running cabal-install or ghc-pkg with any parameters, ensuring at the same time that the project's private package database and installation prefix are addressed correctly.

These commands are capri ghc-pkg and capri cabal. Their syntax is similar:

capri [cabal|ghc-pkg] -- commands and options

Note the use of the double hyphen. It separates command line arguments that capri tries to interpret as options from command line arguments that will be passed to the program (<tt>cabal-install or ghc-pkg) to run.

This can be illustrated by these examples (compare the output, only few top lines shown):

$ capri cabal --help
capri cabal -- <cabal or Setup command options>
-h --help Show this help text
-D --omit-package-db Omit the --package-db option for cabal commands that do
not understand it
-P --omit-prefix Omit the --prefix option for cabal commands that do not
understand it
-S --setup Use the Setup.{hs|lhs} installation program instead of
Cabal-install
..........................

vs.

$ capri cabal -- --help
This program is the command line interface to the Haskell Cabal infrastructure.
See http://www.haskell.org/cabal/ for more information.
Usage: cabal COMMAND [FLAGS]
or: cabal [GLOBAL FLAGS]
Global flags:
-h --help Show this help text
-V --version Print version information
--numeric-version Print just the version number
..........................

For example, if a particular package needs to be installed into the project's private packages database, and it can be downloaded by cabal-install, the following command will do:

capri cabal -- install package-name

If a package needs to be unregistered from the project's private packages database, use this command:

capri ghc-pkg -- unregister

and the --force option may be supplied as well.

Both cabal-install and ghc-pkg will be run with the GHC_PACKAGE_PATH environment variable set to the project's packages database. The capri cabal command has two additional options, -D and -P. Use them to omit the --package-db and --prefix options that would normally be passed to cabal-install: some of its commands do not understand these options, e. g.:

capri -DP cabal -- check

since cabal check would fail if any of these options appeared on its command line.

6.2 Running Setup.{hs|lhs} Instead of Cabal-Install

Capri commands import and cabal have additional option, -S or --setup. If used, capri will execute runghc Setup instead of cabal. This may pose a chicken-and-egg problem: typical Setup program needs the Cabal library to be in scope; Cabal itself has dependencies with their own Setup programs. So this option is not expected to be used frequently, perhaps in some marginal cases, mostly for buildability testing.