| Cabal-1.2.4.0: A framework for packaging Haskell software | Source code | Contents | Index

Distribution.Simple.Program

Portability | GHC, Hugs
Stability | alpha
Maintainer | Isaac Jones <ijones@syntaxpolice.org>

Contents

Program and functions for constructing them
Configured program and related functions
The collection of unconfigured and configured progams
The collection of configured programs we can run
Programs that Cabal knows about

Description

Explanation: A program is basically a name, a location, and some arguments.

One nice thing about using it is that any program that is registered with Cabal will get some "configure" and ".cabal" helpers like --with-foo-args --foo-path= and extra-foo-args.

There's also good default behavior for trying to find "foo" in PATH, being able to override its location, etc.

There's also a hook for adding programs in a Setup.lhs script. See hookedPrograms in `UserHooks`. This gives a hook user the ability to get the above flags and such so that they don't have to write all the PATH logic inside Setup.lhs.

Synopsis

data Program = Program {

programName :: String
programFindLocation :: (Verbosity -> IO (Maybe FilePath))
programFindVersion :: (Verbosity -> FilePath -> IO (Maybe Version))

}

simpleProgram :: String -> Program
findProgramOnPath :: FilePath -> Verbosity -> IO (Maybe FilePath)
findProgramVersion :: ProgArg -> (String -> String) -> Verbosity -> FilePath -> IO (Maybe Version)

data ConfiguredProgram = ConfiguredProgram {

programId :: String
programVersion :: (Maybe Version)
programArgs :: [ProgArg]
programLocation :: ProgramLocation

}

programPath :: ConfiguredProgram -> FilePath
type ProgArg = String

data ProgramLocation

= UserSpecified {

locationPath :: FilePath

}

| FoundOnSystem {

locationPath :: FilePath

}

rawSystemProgram :: Verbosity -> ConfiguredProgram -> [ProgArg] -> IO ()
rawSystemProgramStdout :: Verbosity -> ConfiguredProgram -> [ProgArg] -> IO String
builtinPrograms :: [Program]
data ProgramConfiguration
emptyProgramConfiguration :: ProgramConfiguration
defaultProgramConfiguration :: ProgramConfiguration
addKnownProgram :: Program -> ProgramConfiguration -> ProgramConfiguration
lookupKnownProgram :: String -> ProgramConfiguration -> Maybe Program
knownPrograms :: ProgramConfiguration -> [(Program, Maybe ConfiguredProgram)]
userSpecifyPath :: String -> FilePath -> ProgramConfiguration -> ProgramConfiguration
userMaybeSpecifyPath :: String -> Maybe FilePath -> ProgramConfiguration -> ProgramConfiguration
userSpecifyArgs :: String -> [ProgArg] -> ProgramConfiguration -> ProgramConfiguration
lookupProgram :: Program -> ProgramConfiguration -> Maybe ConfiguredProgram
updateProgram :: ConfiguredProgram -> ProgramConfiguration -> ProgramConfiguration
configureAllKnownPrograms :: Verbosity -> ProgramConfiguration -> IO ProgramConfiguration
requireProgram :: Verbosity -> Program -> VersionRange -> ProgramConfiguration -> IO (ConfiguredProgram, ProgramConfiguration)
rawSystemProgramConf :: Verbosity -> Program -> ProgramConfiguration -> [ProgArg] -> IO ()
rawSystemProgramStdoutConf :: Verbosity -> Program -> ProgramConfiguration -> [ProgArg] -> IO String
ghcProgram :: Program
ghcPkgProgram :: Program
nhcProgram :: Program
hmakeProgram :: Program
jhcProgram :: Program
hugsProgram :: Program
ffihugsProgram :: Program
ranlibProgram :: Program
arProgram :: Program
happyProgram :: Program
alexProgram :: Program
hsc2hsProgram :: Program
c2hsProgram :: Program
cpphsProgram :: Program
hscolourProgram :: Program
haddockProgram :: Program
greencardProgram :: Program
ldProgram :: Program
tarProgram :: Program
cppProgram :: Program
pfesetupProgram :: Program
pkgConfigProgram :: Program

Program and functions for constructing them

data Program | Source

Represents a program which can be configured.
Constructors

Program |

programName :: String | The simple name of the program, eg. ghc
programFindLocation :: (Verbosity -> IO (Maybe FilePath)) | A function to search for the program if it's location was not specified by the user. Usually this will just be a
programFindVersion :: (Verbosity -> FilePath -> IO (Maybe Version)) | Try to find the version of the program. For many programs this is not possible or is not necessary so it's ok to return Nothing.

simpleProgram :: String -> Program | Source

Make a simple named program.

By default we'll just search for it in the path and not try to find the version name. You can override these behaviours if necessary, eg:

     simpleProgram "foo" { programFindLocation = ... , programFindVersion ... }

findProgramOnPath :: FilePath -> Verbosity -> IO (Maybe FilePath) | Source

Look for a program on the path.

findProgramVersion | Source

:: ProgArg | version args
-> (String -> String) | function to select version number from program output
-> Verbosity |
-> FilePath | location
-> IO (Maybe Version) |
Look for a program and try to find it's version number. It can accept either an absolute path or the name of a program binary, in which case we will look for the program on the path.

Configured program and related functions

data ConfiguredProgram | Source

Constructors

ConfiguredProgram |

programId :: String | Just the name again
programVersion :: (Maybe Version) | The version of this program, if it is known.
programArgs :: [ProgArg] | Default command-line args for this program. These flags will appear first on the command line, so they can be overridden by subsequent flags.
programLocation :: ProgramLocation | Location of the program. eg. `/usr/bin/ghc-6.4`

Instances

Read ConfiguredProgram
Show ConfiguredProgram

programPath :: ConfiguredProgram -> FilePath | Source

The full path of a configured program.

type ProgArg = String | Source

data ProgramLocation | Source

Where a program was found. Also tells us whether it's specifed by user or not. This includes not just the path, but the program as well.
Constructors

UserSpecified | The user gave the path to this program, eg. --ghc-path=/usr/bin/ghc-6.6

locationPath :: FilePath |

FoundOnSystem | The location of the program, as located by searching PATH.

locationPath :: FilePath |

Instances

Read ProgramLocation
Show ProgramLocation

rawSystemProgram | Source

:: Verbosity | Verbosity
-> ConfiguredProgram | The program to run
-> [ProgArg] | Any extra arguments to add
-> IO () |
Runs the given configured program.

rawSystemProgramStdout | Source

:: Verbosity | Verbosity
-> ConfiguredProgram | The program to run
-> [ProgArg] | Any extra arguments to add
-> IO String |
Runs the given configured program and gets the output.

The collection of unconfigured and configured progams

builtinPrograms :: [Program] | Source

The default list of programs. These programs are typically used internally to Cabal.
The collection of configured programs we can run

data ProgramConfiguration | Source

The configuration is a collection of information about programs. It contains information both about configured programs and also about programs that we are yet to configure.

The idea is that we start from a collection of unconfigured programs and one by one we try to configure them at which point we move them into the configured collection. For unconfigured programs we record not just the `Program` but also any user-provided arguments and location for the program.

Instances

Read ProgramConfiguration
Show ProgramConfiguration

emptyProgramConfiguration :: ProgramConfiguration | Source

defaultProgramConfiguration :: ProgramConfiguration | Source

addKnownProgram :: Program -> ProgramConfiguration -> ProgramConfiguration | Source

Add a known program that we may configure later

lookupKnownProgram :: String -> ProgramConfiguration -> Maybe Program | Source

knownPrograms :: ProgramConfiguration -> [(Program, Maybe ConfiguredProgram)] | Source

userSpecifyPath | Source

:: String | Program name
-> FilePath | user-specified path to the program
-> ProgramConfiguration |
-> ProgramConfiguration |
User-specify this path. Basically override any path information for this program in the configuration. If it's not a known program ignore it.

userMaybeSpecifyPath :: String -> Maybe FilePath -> ProgramConfiguration -> ProgramConfiguration | Source

userSpecifyArgs | Source

:: String | Program name
-> [ProgArg] | user-specified args
-> ProgramConfiguration |
-> ProgramConfiguration |
User-specify the arguments for this program. Basically override any args information for this program in the configuration. If it's not a known program, ignore it..

lookupProgram :: Program -> ProgramConfiguration -> Maybe ConfiguredProgram | Source

Try to find a configured program

updateProgram :: ConfiguredProgram -> ProgramConfiguration -> ProgramConfiguration | Source

Update a configured program in the database.

configureAllKnownPrograms :: Verbosity -> ProgramConfiguration -> IO ProgramConfiguration | Source

Try to configure all the known programs that have not yet been configured.

requireProgram :: Verbosity -> Program -> VersionRange -> ProgramConfiguration -> IO (ConfiguredProgram, ProgramConfiguration) | Source

Check that a program is configured and available to be run. Additionally check that the version of the program number is suitable. For example `AnyVersion` or `orLaterVersion (`Version` [1,0] [])` It raises an exception if the program could not be configured or the version is unsuitable, otherwise it returns the configured program.

rawSystemProgramConf | Source

:: Verbosity | verbosity
-> Program | The program to run
-> ProgramConfiguration | look up the program here
-> [ProgArg] | Any extra arguments to add
-> IO () |
Looks up the given program in the program configuration and runs it.

rawSystemProgramStdoutConf | Source

:: Verbosity | verbosity
-> Program | The program to run
-> ProgramConfiguration | look up the program here
-> [ProgArg] | Any extra arguments to add
-> IO String |
Looks up the given program in the program configuration and runs it.

Programs that Cabal knows about

ghcProgram :: Program | Source

ghcPkgProgram :: Program | Source

nhcProgram :: Program | Source

hmakeProgram :: Program | Source

jhcProgram :: Program | Source

hugsProgram :: Program | Source

ffihugsProgram :: Program | Source

ranlibProgram :: Program | Source

arProgram :: Program | Source

happyProgram :: Program | Source

alexProgram :: Program | Source

hsc2hsProgram :: Program | Source

c2hsProgram :: Program | Source

cpphsProgram :: Program | Source

hscolourProgram :: Program | Source

haddockProgram :: Program | Source

greencardProgram :: Program | Source

ldProgram :: Program | Source

tarProgram :: Program | Source

cppProgram :: Program | Source

pfesetupProgram :: Program | Source

pkgConfigProgram :: Program | Source

Produced by Haddock version 0.9