cartel-0.18.0.2: Specify Cabal files in Haskell

Safe HaskellSafe
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

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

Eq Vcs Source # 

Methods

(==) :: Vcs -> Vcs -> Bool #

(/=) :: Vcs -> Vcs -> Bool #

Ord Vcs Source # 

Methods

compare :: Vcs -> Vcs -> Ordering #

(<) :: Vcs -> Vcs -> Bool #

(<=) :: Vcs -> Vcs -> Bool #

(>) :: Vcs -> Vcs -> Bool #

(>=) :: Vcs -> Vcs -> Bool #

max :: Vcs -> Vcs -> Vcs #

min :: Vcs -> Vcs -> Vcs #

Show Vcs Source # 

Methods

showsPrec :: Int -> Vcs -> ShowS #

show :: Vcs -> String #

showList :: [Vcs] -> ShowS #

Renderable Vcs Source # 

Methods

render :: Vcs -> String Source #

cvs Source #

Arguments

:: NonEmptyString

The named module

-> Vcs 

lastJust :: Maybe a -> Maybe a -> Maybe a Source #

Takes the last non-Nothing value, or returns Nothing if both values are Nothing.

data Repository Source #

A single repository section. This is an instance of Monoid, so to get a blank Repository section, use mempty.

Constructors

Repository 

Fields

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

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.

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

atLeast :: NonEmptyString -> Version -> Package Source #

Depends on this version, or any greater version.

atLeast "base" [4,5,0,0] ==> version >= 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 Source # 
Ord BuildInfoField Source # 
Show BuildInfoField Source # 
RenderableIndented BuildInfoField Source #

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.

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.

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 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.

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

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.

Minimal complete definition

mainIs

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.

Minimal complete definition

exitcodeStdio

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

data Properties Source #

Global package properties. Is an instance of Monoid so to get a blank Properties use mempty, for example:

properties = mempty
 { name = "mypackage"
 , version = [0,1]
 , cabalVersion = Just (1,10)
 , buildType = Just simple
 -- etc.  Fields you don't supply will be blank.
 }

Many of these fields hold a Maybe type. Values that are Nothing will generate no output in the resulting Cabal file. Other fields are a String type. Empty strings will generate no output in the resulting Cabal file. Other values are lists; empty lists generate no output in the resulting Cabal file.

Constructors

Properties 

Fields

  • name :: String

    The unique name for the package, without the version number.

  • version :: Version

    The package version number, which is always a list of natural numbers.

  • cabalVersion :: Maybe (Word, Word)

    The version of the Cabal specification to use. As of 2016-01-30 I can find no documentation on what these different versions are. cabal init of the cabal-install program version 1.22.6.0 is using 1.10 as the default value here.

  • buildType :: Maybe BuildType
     
  • license :: Maybe License

    The type of license under which the package is distributed

  • licenseFile :: String

    The name of a file or files containing the precise copyright license. The license file will be installed with the package. If you have mulitple license files, use the licenseFiles field instead of, or in addition to, this field.

  • licenseFiles :: [NonEmptyString]
     
  • copyright :: String

    A freeform copyright string, for instance, Copyright: (c) 2006-2007 Joe Bloggs

  • author :: String

    The original author of the package.

  • maintainer :: String

    According to the "Developing Cabal Packages" document, this should simply be an email address.

  • stability :: String

    The stability level of the package, e.g. alpha", experimental, provisional, stable@, etc.

  • homepage :: String

    URL for package homepage.

  • bugReports :: String

    URL where user should send bug reports. This can be a mailto: for mailed bug reports or an http or https URL for an online bug tracking system.

  • packageUrl :: String

    Location of a source bundle for the package. The distribution should be a Cabal package.

  • synopsis :: String

    Very short description of the package, for use in a table of packages.

  • description :: [String]

    Description of the package. This can be several paragraphs.

  • category :: String

    Classification category for Hackage. There is not much of an organizational system to these categories.

  • testedWith :: [(Compiler, Constraint)]

    LIst of compilers and versions against which the package has been tested (or built).

  • dataFiles :: [NonEmptyString]

    List of files to be installed for run-time use by the package. This is useful for packages that have a large amount of static data.

  • dataDir :: String

    The directory where Cabal looks for data files to install, relative to the source directory. By default, Cabal will look in the source directory itself.

  • extraSourceFiles :: [NonEmptyString]

    A list of additional files to be included in source distributions built with setup sdist. As with dataFiles it can include a limited form of * wildcards in file names.

  • extraDocFiles :: [NonEmptyString]

    A list of additional files to be included in source distributions, and also copied to the html directory when Haddock documentation is generated. As with data-files it can use a limited form of * wildcards in file names.

  • extraTmpFiles :: [NonEmptyString]

    A list of additional files or directories to be removed by setup clean. These would typically be additional files created by additional hooks.

Cabal

data Cabal Source #

Represents an entire Cabal file. Is an instance of Monoid so to get a blank Cabal use mempty.

Constructors

Cabal