Version 13 (modified by nominolo@…, 6 years ago)

updated description to current implementation

Cabal Configurations Progress

On this page I (Thomas Schilling) will document some of the design decisions and my progress on implementing Cabal configurations. If you have any questions ping me on #haskell or send a mail to me or, better, the cabal-devel mailing list. My nickname is "nominolo", my email is <my_nickname> at gmail.com.

I am working mostly based on the  latest proposal.

.cabal Syntax

Old cabal files still work, but they do not support configurations features. Thus, if you use the new syntax and features, be nice to others and include the following line, so that they get a more useful error messago than "Syntax error". :)

Cabal-version: >= 1.1.7

Here is an example of a .cabal file that uses configurations.

Name: Test1
Version: 0.0.1
Cabal-Version: >= 1.1.7
License: BSD3
-- License-File: LICENSE
Author: Thomas Schilling <notme@nospam.com>
Maintainer: Thomas Schilling <notme@nospam.com>
--Homepage: http://www.example.com/
Synopsis: Test package to test configurations
Description:
        See synopsis.
        .
        Really.
Category: Useless

Flag Debug {
  Description: Enable debug support
  Default:     False
}

Flag NoBuild {
  Description: Inhibit building this package.
  -- defaults to True
}

Library {
  Build-Depends:   base
  Exposed-Modules: Testing.Test1
  Extensions:      CPP

  if flag(debuG) {
    CC-Options: "-DDEBUG"
    GHC-Options: -DDEBUG
  } 

  if flag(NoBuild) {
    Build-Depends: nonexistentpackage
  }
}

Executable test1e {
  Main-is: T1.hs
  Other-modules: Testing.Test1

  if flag(deBug) {
    CC-Options: "-DDEBUG"
    GHC-Options: -DDEBUG
  } 
}

When configuring it with the usual command line, you now get an additional line, showing which flags were chosen:

$ ./Setup.lhs configure
configure: Reading installed packages...
Configuring Test1-0.0.1...
configure: Flags chosen: nobuild=False, debug=False
Setup.lhs: Warning: No license-file field.
configure: Dependency base-any: using base-2.1.1
  [...]

Note that, even though the default for the "nobuild" flag was True, the required dependencies weren't present, so it was forced to False. If you want to force flags to certain values you can do so by giving the --flags or -f flag to configure. Listing the (case-insensitive) name forces it to True, putting a "-" in front of the name forces it to False. For example:

$ ./Setup.lhs configure -fdebug
configure: Reading installed packages...
Configuring Test1-0.0.1...
configure: Flags chosen: nobuild=False, debug=True
Setup.lhs: Warning: No license-file field.
[...]

or

$ ./Setup.lhs configure --flags="-debug nobuild" 
configure: Reading installed packages...
Configuring Test1-0.0.1...
Setup.lhs: At least the following dependencies are missing:
    nonexistentpackage -any
$

Note that if you want to change the configuration of a package, you have to ./Setup.lhs clean first, to make sure everything gets recompiled.

Progress Log

2007-06-24:

Sent all local patches to mailing list for review,

2007-06-14:

Refactorings, also some pretty printing. Interface seems okay now; parseDescription now returns a PreparedPackageDescription? which, given some environmental parameters, can be resolved to an old PackageDescription? (or not, if the dependencies could not be resolved). We probably want a hook for this.

Compatibility mode working.

2007-06-12:

Prototypical implementation up and running. Next step is integrating it with the standart build process. Not sure what the best interface should be.

2007-05-30:

Started modifying the higher levels of the parsing code to incorporate support for conditions. Lot's of cleaning up required. This is when you learn the merits of XML.

2007-05-29:

Not much hacking today; had exam. Parsing and simplifying conditions works.

2007-05-28:

Low-level parsing works. We now have three syntactic categories:

  • Normal properties: fieldname: value
  • If-blocks: 'if' condition '{' ... '}' ['else' '{' ... '}']
  • Sections: sectionname sectionlabel '{' ... '}' where sectionname can currently be only library or executable. Whether or not a label is required is checked at a higher level.

This scheme is backwards compatible. I plan to add a warning when blocks are used but no Cabal-version: > 1.1.7 or equivalent is present.