1 {-# LANGUAGE FlexibleContexts #-}
2 {-# LANGUAGE RankNTypes #-}
4 -----------------------------------------------------------------------------
7 -- Module : Distribution.Simple.Program
8 -- Copyright : Isaac Jones 2006, Duncan Coutts 2007-2009
10 -- Maintainer : cabal-devel@haskell.org
11 -- Portability : portable
13 -- This provides an abstraction which deals with configuring and running
14 -- programs. A 'Program' is a static notion of a known program. A
15 -- 'ConfiguredProgram' is a 'Program' that has been found on the current
16 -- machine and is ready to be run (possibly with some user-supplied default
17 -- args). Configuring a program involves finding its location and if necessary
18 -- finding its version. There is also a 'ProgramDb' type which holds
19 -- configured and not-yet configured programs. It is the parameter to lots of
20 -- actions elsewhere in Cabal that need to look up and run programs. If we had
21 -- a Cabal monad, the 'ProgramDb' would probably be a reader or
22 -- state component of it.
24 -- The module also defines all the known built-in 'Program's and the
25 -- 'defaultProgramDb' which contains them all.
27 -- One nice thing about using it is that any program that is
28 -- registered with Cabal will get some \"configure\" and \".cabal\"
29 -- helpers like --with-foo-args --foo-path= and extra-foo-args.
31 -- There's also good default behavior for trying to find \"foo\" in
32 -- PATH, being able to override its location, etc.
34 -- There's also a hook for adding programs in a Setup.lhs script. See
35 -- hookedPrograms in 'Distribution.Simple.UserHooks'. This gives a
36 -- hook user the ability to get the above flags and such so that they
37 -- don't have to write all the PATH logic inside Setup.lhs.
38 module Distribution
.Simple
.Program
39 ( -- * Program and functions for constructing them
42 , ProgramSearchPathEntry
(..)
44 , findProgramOnSearchPath
45 , defaultProgramSearchPath
48 -- * Configured program and related functions
49 , ConfiguredProgram
(..)
52 , ProgramLocation
(..)
55 , suppressOverrideArgs
57 -- * Program invocations
58 , ProgramInvocation
(..)
59 , emptyProgramInvocation
60 , simpleProgramInvocation
62 , runProgramInvocation
63 , getProgramInvocationOutput
64 , getProgramInvocationLBS
66 -- * The collection of unconfigured and configured programs
69 -- * The collection of configured programs we can run
78 , getProgramSearchPath
79 , setProgramSearchPath
82 , userMaybeSpecifyPath
87 , lookupProgramVersion
90 , configureAllKnownPrograms
93 , requireProgramVersion
98 -- * Programs that Cabal knows about
125 import Distribution
.Compat
.Prelude
128 import Distribution
.Simple
.Errors
129 import Distribution
.Simple
.Program
.Builtin
130 import Distribution
.Simple
.Program
.Db
131 import Distribution
.Simple
.Program
.Find
132 import Distribution
.Simple
.Program
.Run
133 import Distribution
.Simple
.Program
.Types
134 import Distribution
.Simple
.Utils
135 import Distribution
.Verbosity
137 -- | Runs the given configured program.
142 -- ^ The program to run
144 -- ^ Any /extra/ arguments to add
146 runProgram verbosity prog args
=
147 runProgramInvocation verbosity
(programInvocation prog args
)
149 -- | Runs the given configured program and gets the output.
154 -- ^ The program to run
156 -- ^ Any /extra/ arguments to add
158 getProgramOutput verbosity prog args
=
159 getProgramInvocationOutput verbosity
(programInvocation prog args
)
161 -- | Looks up the given program in the program database and runs it.
166 -- ^ The program to run
168 -- ^ look up the program here
170 -- ^ Any /extra/ arguments to add
172 runDbProgram verbosity prog programDb args
=
173 case lookupProgram prog programDb
of
175 dieWithException verbosity
$ ProgramNotFound
(programName prog
)
176 Just configuredProg
-> runProgram verbosity configuredProg args
178 -- | Looks up the given program in the program database and runs it.
183 -- ^ The program to run
185 -- ^ look up the program here
187 -- ^ Any /extra/ arguments to add
189 getDbProgramOutput verbosity prog programDb args
=
190 case lookupProgram prog programDb
of
191 Nothing
-> dieWithException verbosity
$ ProgramNotFound
(programName prog
)
192 Just configuredProg
-> getProgramOutput verbosity configuredProg args