cartel-0.14.2.0: Specify Cabal files in Haskell

Safe HaskellSafe-Inferred
LanguageHaskell2010

Cartel.Ast

Contents

Description

The Cartel abstract syntax tree

Use this module if you want access to the data constructors in the AST; the functions and values exported through Cartel should be enough for most uses. Use of this module will not violate any invariants; this stuff is in a separate module merely for the sake of tidiness of the documentation in Cartel.

Cabal already has an AST that it uses. Cartel could, perhaps, have re-used these structures. Cartel does not do this for three reasons. First, the Cabal API is a bit untidy, partially because it has to do things that Cartel doesn't have to worry about, but also because the comments in the Cabal modules themselves indicate that the whole thing could use a refactoring. Second, the Cabal developers make no commitment to keep that API stable. Third, the Cartel API tries only to replicate format of the plain-text Cabal file, which will be much more stable than the Cabal API.

Synopsis

Basic types

Blank

class Blank a where Source

Typeclass for things that can be blank. More specifically, blank a results in an item that, when rendered in a Cabal file, is the null string. blank can be useful to indicate that you have no options, and you can also use it in combination with record syntax when you want to specify just a few options.

Methods

blank :: a Source

Repositories

data RepoKind Source

What kind of VCS repository is this?

Constructors

Head

The latest development branch of the repository

This

The sources for this release of this package.

data Vcs Source

Version control systems.

Constructors

Darcs 
Git 
Svn 
Cvs NonEmptyString

The argument String is the named module

Mercurial 
Bazaar 
ArchVcs 
Monotone 

Instances

cvs Source

Arguments

:: NonEmptyString

The named module

-> Vcs 

data Repository Source

A single repository section.

Constructors

Repository 

Fields

repoVcs :: Maybe Vcs

What kind of Vcs this is. This is required.

repoKind :: Maybe RepoKind

The kind of repository (repoHead or repoThis). Required.

repoTag :: String

Repository tag. This is required for the repoThis repository kind and is optional for the repoHead repository kind.

repoLocation :: NonEmptyString

URL for the location of the repository--for example, for a darcs repo this might be http://code.haskell.org/foo/; for git, this might be git://github.com/foo/bar.git.

repoBranch :: String

The repository branch.

repoSubdir :: String

The repository subdirectory.

githubHead Source

Arguments

:: NonEmptyString

The Github account name

-> NonEmptyString

The Github project name within the account

-> Section 

Creates a Section that is a Repository for a Github head. For example, for Cartel, use githubHead "massysett" "cartel".

repository :: Repository -> Section Source

Creates a Section for a repository.

Logicals

data CondLeaf Source

Condition; for use in a CondTree and ultimately in a CondBlock, which implements Cabal's if-then-else feature.

Constructors

OS NonEmptyString

Tests if the current operating system is the given name, case-insensitive

Arch NonEmptyString

Tests if the current architecture is the given name, case-insensitive

Impl Compiler Constraint

Tests for the configured Haskell implementation

CFlag FlagName

Evalutes to the current assignment of the flag of the given name. To get a flag, use makeFlag.

CTrue

Always True

CFalse

Always False

data Logical Source

For use in a CondTree or ConstrTree.

Constructors

Or 
And 

newtype OrEqualTo Source

Whether or equal to comparisions are also true.

Constructors

OrEqualTo Bool 

data VersionComp Source

Expresses comparisons between versions.

data ConstrTree Source

Expresses a tree of constraints. This is how you represent more complex dependency relationships.

data Constraint Source

Expresses any version constraint, including no version constraint.

invert :: Condition -> Condition Source

Like not, which is what I would have named it but for the conflict. Only Conditions have this sort of operation; Cabal does not have a (documented, at least) way to express this for package constraints.

data CondBlock a Source

Conditional blocks. These implement the if-then-else feature of Cabal files. You must have at least one thing to do if the condition is True; the if-false block is optional.

Constructors

CondBlock 

Fields

condIf :: Condition

If this condition is true . . .

ifTrue :: (a, [a])

. . . then do this . . .

ifFalse :: [a]

. . . or if it's false, do this instead.

class LogicTree a where Source

Methods

(&&&) :: a -> a -> a infixr 3 Source

(|||) :: a -> a -> a infixr 2 Source

lt :: Version -> Constraint Source

Less than

gt :: Version -> Constraint Source

Greater than

eq :: Version -> Constraint Source

Equal to

ltEq :: Version -> Constraint Source

Less than or equal to

gtEq :: Version -> Constraint Source

Greater than or equal to

anyVersion :: Constraint Source

Matches any version at all (in a Cabal file, this is represented as an empty string).

closedOpen Source

Arguments

:: NonEmptyString

Package name

-> Version

Version number for lower bound

-> Version

Version number for upper bound

-> Package

Resulting Package

Creates a package interval that is closed on the left, open on the right. Useful for the common case under the PVP to specify that you depend on a version that is at least a particular version, but less than another version.

closedOpen "bytestring" [0,17] [0,19] ==> bytestring >= 0.17 && < 0.19

apiVersion :: NonEmptyString -> Version -> Package Source

Specifies a particular API version. Useful to lock your package dependencies down to a particular API version.

apiVersion "base" [1] ==> base >= 1 && < 2
apiVersion "base" [1,2] ==> base >= 1.2 && < 1.3
apiVersion "base" [1,2,3] ==> base >= 1.2.3 && < 1.2.4

nextBreaking :: NonEmptyString -> Version -> Package Source

Depends on the version given, up to the next breaking API change.

nextBreaking "base" [4] ==> base >= 4 && < 4.1
nextBreaking "base" [4,1] ==> base >= 4.1 && < 4.2
nextBreaking "base" [4,7,0,0] ==> base >= 4.7.0.0 && < 4.8

nextMajor :: NonEmptyString -> Version -> Package Source

Depends on the version given, up to the next time the first digit increments. Useful for base.

nextBreaking "base" [4] ==> base >= 4 && < 5

exactly :: NonEmptyString -> Version -> Package Source

Depends on exactly this version only.

exactly "base" [4,5,0,0] ==> base ==4.5.0.0

unconstrained Source

Arguments

:: NonEmptyString

Name of package

-> Package 

Allows any version of a package.

condBlock Source

Arguments

:: HasBuildInfo a 
=> Condition

Condition to satisfy

-> (a, [a])

Use these results if condition is true

-> [a]

Use these results if condition if false

-> a 

Builds if statements. For example:

condition (flag "buildExe") (buildable True, []) [buildable False]

A little more complicated:

condition (flag "buildExe" &&& system "windows")
  (buildable True, []) [buildable False]

system :: NonEmptyString -> Condition Source

Operating system; tested against System.Info.os on the target system.

arch :: NonEmptyString -> Condition Source

Argument is matched against System.Info.arch on the target system.

impl :: Compiler -> Constraint -> Condition Source

Tests for the configured Haskell implementation.

flag :: FlagName -> Condition Source

Evaluates to the current assignment of the flag of the given name. Flag names are case insensitive. Testing for flags that have not been introduced with a flag section is an error.

true :: Condition Source

Always true.

false :: Condition Source

Always false.

Versions

type Version = [Word] Source

A version number. The Cabal documentation says this "usually" consists of a sequence of natural numbers separated by dots. Though this suggests that a version number could contain something other than natural numbers, in fact the types in the Cabal library do not allow anything other than numbers and you will get a parse error if you try to use anything else.

Therefore Cartel's Version type only allows a list of Word, as each number cannot be negative. In addition, this list should never be empty. However, this is just a type synonym for a list of Word, so the type system does not enforce the requirement that this list be non-empty.

Packages

data Package Source

A single package, consisting of a package name and an optional set of constraints. Used when specifying buildDepends, buildTools, and pkgConfigDepends.

Some functions exist to ease the creation of a Package. For a package with no version constrains, simply do something like unconstrained "QuickCheck". Common use cases are covered in the functions in the "Package Helpers" section below. For something more complicated, use the functions in the "Logicals" sections above, along with the &&& and ||| combinators, to create your own Constraint and then use it with the package function.

package Source

Arguments

:: NonEmptyString

The name of the package

-> Constraint

Version constraints.

-> Package 

Builds a Package.

Build information

haskell98 :: HasBuildInfo a => a Source

Sets Haskell 98 as the default-language.

Currently not documented in Cabal, see

https://github.com/haskell/cabal/issues/1894

haskell2010 :: HasBuildInfo a => a Source

Sets Haskell 2010 as the default-language.

Currently not documented in Cabal, see

https://github.com/haskell/cabal/issues/1894

data BuildInfoField Source

A single field of build information. This can appear in a Library, Executable, TestSuite, or Benchmark.

Constructors

BuildDepends [Package]

A list of packages needed to build this component

OtherModules [NonEmptyString]

Modules used but not exposed. For libraries, these are hidden modules; for executable, these are auxiliary modules to be linked with the file in the main-is field.

modules can help greatly with maintenance of this field.

HsSourceDirs [NonEmptyString]

Root directories for the module hierarchy

Extensions [NonEmptyString] 
DefaultExtensions [NonEmptyString] 
OtherExtensions [NonEmptyString] 
BuildTools [Package]

Programs needed to build this package, such as c2hs.

Buildable Bool

Is this component buildable?

GHCOptions [NonEmptyString] 
GHCProfOptions [NonEmptyString] 
GHCSharedOptions [NonEmptyString] 
HugsOptions [NonEmptyString] 
Nhc98Options [NonEmptyString] 
Includes [NonEmptyString]

Header files to be included in any compilations via C. Applies to both header files that are already installed on the system and to those coming with the package to be installed.

InstallIncludes [NonEmptyString]

Header files to be installed into $libdir/includes when the package is installed. These files should be found in relative to the top of the source tree or relative to one of the directories listed in include-dirs.

IncludeDirs [NonEmptyString]

List of diretories to search for header files when dealing with C compilations.

CSources [NonEmptyString]

C sources to be compiled and lined with the Haskell files.

ExtraLibraries [NonEmptyString]

Extra libraries to link with.

ExtraLibDirs [NonEmptyString]

Directories to search for libraries.

CCOptions [NonEmptyString]

C Compiler options.

CPPOptions [NonEmptyString]

C Preprocessor options. Undocumented, see https://github.com/haskell/cabal/issues/646

LDOptions [NonEmptyString]

Linker options.

PkgConfigDepends [Package]

List of pkg-config packages needed to build this component.

Frameworks [NonEmptyString]

OS X frameworks.

DefaultLanguage DefaultLanguage 

Instances

Eq BuildInfoField 
Ord BuildInfoField 
Show BuildInfoField 
RenderableIndented BuildInfoField

Contains many lists of items. Items that might contain spaces or other troublesome characters are rendered quoted. In particular, this includes filenames. Items that are highly unlikely to contain troublesome characters (such as compiler options) are not quoted.

Libraries

data LibraryField Source

A field in the Library section of the Cabal file. A Library section can have multiple fields.

Constructors

ExposedModules [NonEmptyString]

Exposed modules. modules can help you generate this, without you having to manually list each module and keep the list up to date.

Exposed Bool

Is the library exposed? GHC can hide libraries.

LibConditional (CondBlock LibraryField)

The Library section can contain conditional blocks.

LibInfo BuildInfoField

The Library section can contain build information.

exposed :: Bool -> LibraryField Source

Whether a library is exposed. GHC can hide libraries.

exposedModules :: [NonEmptyString] -> LibraryField Source

A library's exposed modules. modules can help you generate this, without you having to manually list each module and keep the list up to date.

Executables

data ExecutableField Source

A single field in an Executable section. An Executable section may have multiple fields.

Constructors

ExeConditional (CondBlock ExecutableField)

An Executable section can contain conditional blocks.

ExeInfo BuildInfoField

An Executable section can contain one or more build information fields.

ExeMainIs NonEmptyString

The name of the .hs or .lhs file containing the Main module. Note that it is the .hs filename that must be listed, even if that file is generated using a preprocessor. The source file must be relative to one of the directories listed in hsSourceDirs.

data Executable Source

An entire Executable section.

Constructors

Executable 

Fields

exeName :: NonEmptyString

The name of the executable that Cabal will build.

exeFields :: [ExecutableField]

An executable can contain zero or more ExecutableFields.

executable Source

Arguments

:: NonEmptyString

The name of the executable that Cabal will build.

-> [ExecutableField]

An executable can contain zero or more ExecutableFields.

-> Section 

Builds a Section for executable files.

Test suites

data TestSuiteType Source

What kind of test suite is this?

Constructors

ExitcodeStdio

An exitcode-stdio-1.0 test. The String is the name of the file containing the executable code. In this case, the test-main-is field is required.

Detailed

The detailed-0.9 test. In this case, the test-module field is required.

data TestSuiteField Source

A single field value in a TestSuite section. A single test suite section may contain mulitple fields.

Constructors

TestConditional (CondBlock TestSuiteField)

The TestSuite may contain zero or more conditional blocks.

TestInfo BuildInfoField

The TestSuite may contain zero or more build information fields.

TestMainIs NonEmptyString

The name of the .hs or .lhs file containing the Main module. Note that it is the .hs filename that must be listed, even if that file is generated using a preprocessor. The source file must be relative to one of the directories listed in hsSourceDirs.

This is required when using ExitcodeStdio and disallowed when using Detailed.

TestSuiteType TestSuiteType 
TestModule NonEmptyString

The module exporting the tests symbol. This is required when using Detailed and disallowed when using ExitcodeStdio.

testModule :: NonEmptyString -> TestSuiteField Source

The module exporting the tests symbol. This is required when using Detailed and disallowed when using ExitcodeStdio.

data TestSuite Source

An entire test-suite section.

Constructors

TestSuite 

Fields

testSuiteName :: NonEmptyString

The executable name for the resulting test suite

testSuiteFields :: [TestSuiteField]

Zero or more TestSuiteFields.

testSuite Source

Arguments

:: NonEmptyString

The executable name for the resulting test suite

-> [TestSuiteField]

Zero or more TestSuiteFields.

-> Section 

Builds a Section for test suites.

Benchmarks

data BenchmarkType Source

Constructors

BenchExitCode

exitcode-stdio-1.0, currently the only supported benchmark interface.

data BenchmarkField Source

A single field in a Benchmark section.

Constructors

BenchmarkConditional (CondBlock BenchmarkField) 
BenchmarkInfo BuildInfoField 
BenchmarkType BenchmarkType 
BenchmarkMainIs NonEmptyString

The name of the .hs or .lhs file containing the Main module. Note that it is the .hs filename that must be listed, even if that file is generated using a preprocessor. The source file must be relative to one of the directories listed in hsSourceDirs.

data Benchmark Source

An entire Benchmark section.

Constructors

Benchmark 

Fields

benchmarkName :: NonEmptyString

The name of the executable file that will be the benchmark

benchmarkFields :: [BenchmarkField]

Zero or more benchmark fields.

benchmark Source

Arguments

:: NonEmptyString

The name of the executable file that will be the benchmark

-> [BenchmarkField]

Zero or more benchmark fields.

-> Section 

Builds a Section for benchmarks.

Overloaded fields

class HasBuildInfo a where Source

Things that can be an item in a build information field in a Cabal file.

Methods

conditional :: CondBlock a -> a Source

Takes a conditional block and wraps it in the field type.

buildInfo :: BuildInfoField -> a Source

Takes a build information field and wraps it in the field type.

buildDepends :: HasBuildInfo a => [Package] -> a Source

A list of packages needed to build this component

otherModules :: HasBuildInfo a => [NonEmptyString] -> a Source

Modules used but not exposed. For libraries, these are hidden modules; for executable, these are auxiliary modules to be linked with the file in the main-is field.

modules can help greatly with maintenance of this field.

hsSourceDirs :: HasBuildInfo a => [NonEmptyString] -> a Source

Root directories for the module hierarchy

extensions :: HasBuildInfo a => [NonEmptyString] -> a Source

Haskell extensions used by every module. With version 1.22 of the Cabal library, using this field might get you this warning:

Warning: For packages using 'cabal-version: >= 1.10' the
'extensions' field is deprecated. The new 'default-extensions'
field lists extensions that are used in all modules in the
component, while the 'other-extensions' field lists extensions
that are used in some modules, e.g. via the {-# LANGUAGE #-}
pragma.

defaultExtensions :: HasBuildInfo a => [NonEmptyString] -> a Source

Default extensions. See extensions for details. Currently undocumented, see https://github.com/haskell/cabal/issues/1517

otherExtensions :: HasBuildInfo a => [NonEmptyString] -> a Source

Other extensions. See extensions for details. Currently undocumented, see https://github.com/haskell/cabal/issues/1517

buildTools :: HasBuildInfo a => [Package] -> a Source

Programs needed to build this package, such as c2hs.

buildable :: HasBuildInfo a => Bool -> a Source

Is this component buildable?

includes :: HasBuildInfo a => [NonEmptyString] -> a Source

Header files to be included in any compilations via C. Applies to both header files that are already installed on the system and to those coming with the package to be installed.

installIncludes :: HasBuildInfo a => [NonEmptyString] -> a Source

Header files to be installed into $libdir/includes when the package is installed. These files should be found in relative to the top of the source tree or relative to one of the directories listed in include-dirs.

includeDirs :: HasBuildInfo a => [NonEmptyString] -> a Source

List of diretories to search for header files when dealing with C compilations.

cSources :: HasBuildInfo a => [NonEmptyString] -> a Source

C sources to be compiled and lined with the Haskell files.

extraLibraries :: HasBuildInfo a => [NonEmptyString] -> a Source

Extra libraries to link with.

extraLibDirs :: HasBuildInfo a => [NonEmptyString] -> a Source

Directories to search for libraries.

ccOptions :: HasBuildInfo a => [NonEmptyString] -> a Source

C Compiler options.

cppOptions :: HasBuildInfo a => [NonEmptyString] -> a Source

C Preprocessor options. Undocumented, see https://github.com/haskell/cabal/issues/646

ldOptions :: HasBuildInfo a => [NonEmptyString] -> a Source

Linker options.

pkgConfigDepends :: HasBuildInfo a => [Package] -> a Source

List of pkg-config packages needed to build this component.

frameworks :: HasBuildInfo a => [NonEmptyString] -> a Source

OS X frameworks.

class BuildsExe a where Source

Sections that build executables. These are the Executable, Benchmark, and TestSuite sections.

Methods

mainIs :: NonEmptyString -> a Source

Overloaded function allowing you to use mainIs for an Executable, Benchmark, or TestSuite section.

class BuildsExitcode a where Source

Sections that build executables that can be exitcode-stdio-1.0. These are the Benchmark and TestSuite sections.

Methods

exitcodeStdio :: a Source

Returns a field that is exitcode-stdio-1.0

exitcodeFields Source

Arguments

:: (BuildsExitcode a, BuildsExe a) 
=> NonEmptyString

Value for main-is field

-> [a] 

Builds two fields. The first indicates that this is an exitcode-stdio-1.0 executable; the second is the appropriate main-is field.

Getting module lists

modulesWithExtensions Source

Arguments

:: MonadIO m 
=> [NonEmptyString]

Look for files that have these extensions. fileExtensions covers the most common cases. Files without one of these extensions are ignored. Files and directories that do not begin with an uppercase letter are ignored. (This also ignores files that start with a dot.) Directories with a dot anywhere in the name are ignored.

Do not include the leading dot with the extension. For example, to look for Haskell and literate Haskell files only, use

["hs", "lhs"]
-> FilePath

Start searching within this directory.

-> Betsy m [NonEmptyString]

A list of Haskell modules in the given directory tree. The file contents are not examined; only the file names matter. Returned as a list of dotted names.

Gets all Haskell modules in a given directory tree. Allows you to specify what extensions you are interested in. For this to work best, you will want to keep all your library modules in their own directory, such as lib/. You can also separate executables and test suites this way. hsSourceDirs will then tell Cabal to use these directories.

fileExtensions :: [String] Source

Common extensions of Haskell files and files that are preprocessed into Haskell files. Includes:

  • hs (Haskell)
  • lhs (literate Haskell)
  • gc (greencard)
  • chs (c2hs)
  • hsc (hsc2hs)
  • y and ly (happy)
  • x (alex)
  • cpphs

interestingFile Source

Arguments

:: [String]

Extensions of module files

-> FilePath 
-> Bool 

modulesIO Source

Arguments

:: FilePath

Start searching within this directory.

-> IO [String]

A list of Haskell modules in the given directory tree. The file contents are not examined; only the file names matter. Returned as a list of dotted names.

Gets all Haskell modules in a given directory tree. Only files with one of the extensions listed in fileExtensions are returned. Files and directories that do not begin with an uppercase letter are ignored. (This also ignores files that start with a dot.) Directories with a dot anywhere in the name are ignored.

modulesWithExtensionsIO Source

Arguments

:: [String]

Look for files that have one of these extensions. fileExtensions covers the most common cases. Files without one of these extensions are ignored. Files and directories that do not begin with an uppercase letter are ignored. (This also ignores files that start with a dot.) Directories with a dot anywhere in the name are ignored.

Do not include the leading dot with the extension. For example, to look for Haskell and literate Haskell files only, use

["hs", "lhs"]
-> FilePath

Start searching within this directory.

-> IO [String]

A list of Haskell modules in the given directory tree. The file contents are not examined; only the file names matter. Returned as a list of dotted names.

Gets all Haskell modules in a given directory tree. Allows you to specify what extensions you are interested in.

modulesInDir Source

Arguments

:: [String]

Extensions of module files

-> FilePath 
-> [FilePath]

Stack of directories we're in

-> IO [[String]]

Returns a list of modules in this directory.

processFile Source

Arguments

:: [String]

Extensions of module files

-> FilePath

Search is rooted in this directory

-> [FilePath] 
-> FilePath

Interesting file under investigation

-> IO [[String]] 

Section

data Section Source

A single section in a Cabal file; this may be a source repository, executable, test suite, or benchmark. You build a Section with the repository, executable, testSuite, and benchmark functions.

Properties

Cabal

data Cabal Source

Represents an entire Cabal file.

Constructors

Cabal