diff --git a/Cabal/src/Distribution/Simple/Program/Find.hs b/Cabal/src/Distribution/Simple/Program/Find.hs index 806c9125968..73506949e49 100644 --- a/Cabal/src/Distribution/Simple/Program/Find.hs +++ b/Cabal/src/Distribution/Simple/Program/Find.hs @@ -33,12 +33,14 @@ module Distribution.Simple.Program.Find , findProgramOnSearchPath , programSearchPathAsPATHVar , getSystemSearchPath + , simpleProgram ) where import Distribution.Compat.Prelude import Prelude () import Distribution.Compat.Environment +import Distribution.Simple.Program.Types import Distribution.Simple.Utils import Distribution.System import Distribution.Verbosity @@ -58,29 +60,6 @@ import System.FilePath as FilePath import qualified System.Win32 as Win32 #endif --- | A search path to use when locating executables. This is analogous --- to the unix @$PATH@ or win32 @%PATH%@ but with the ability to use --- the system default method for finding executables ('findExecutable' which --- on unix is simply looking on the @$PATH@ but on win32 is a bit more --- complicated). --- --- The default to use is @[ProgSearchPathDefault]@ but you can add extra dirs --- either before, after or instead of the default, e.g. here we add an extra --- dir to search after the usual ones. --- --- > ['ProgramSearchPathDefault', 'ProgramSearchPathDir' dir] -type ProgramSearchPath = [ProgramSearchPathEntry] - -data ProgramSearchPathEntry - = -- | A specific dir - ProgramSearchPathDir FilePath - | -- | The system default - ProgramSearchPathDefault - deriving (Eq, Generic, Typeable) - -instance Binary ProgramSearchPathEntry -instance Structured ProgramSearchPathEntry - defaultProgramSearchPath :: ProgramSearchPath defaultProgramSearchPath = [ProgramSearchPathDefault] @@ -207,3 +186,19 @@ findExecutable prog = do else return Nothing _ -> return mExe #endif + +-- | 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 ... } +simpleProgram :: String -> Program +simpleProgram name = + Program + { programName = name + , programFindLocation = \v p -> findProgramOnSearchPath v p name + , programFindVersion = \_ _ -> return Nothing + , programPostConf = \_ p -> return p + , programNormaliseArgs = \_ _ -> id + } diff --git a/Cabal/src/Distribution/Simple/Program/Types.hs b/Cabal/src/Distribution/Simple/Program/Types.hs index 2186b23fc01..30f35b57a7a 100644 --- a/Cabal/src/Distribution/Simple/Program/Types.hs +++ b/Cabal/src/Distribution/Simple/Program/Types.hs @@ -24,7 +24,6 @@ module Distribution.Simple.Program.Types Program (..) , ProgramSearchPath , ProgramSearchPathEntry (..) - , simpleProgram -- * Configured program and related functions , ConfiguredProgram (..) @@ -39,7 +38,6 @@ import Distribution.Compat.Prelude import Prelude () import Distribution.PackageDescription -import Distribution.Simple.Program.Find import Distribution.Verbosity import Distribution.Version @@ -84,6 +82,29 @@ instance Show Program where type ProgArg = String +-- | A search path to use when locating executables. This is analogous +-- to the unix @$PATH@ or win32 @%PATH%@ but with the ability to use +-- the system default method for finding executables ('findExecutable' which +-- on unix is simply looking on the @$PATH@ but on win32 is a bit more +-- complicated). +-- +-- The default to use is @[ProgSearchPathDefault]@ but you can add extra dirs +-- either before, after or instead of the default, e.g. here we add an extra +-- dir to search after the usual ones. +-- +-- > ['ProgramSearchPathDefault', 'ProgramSearchPathDir' dir] +type ProgramSearchPath = [ProgramSearchPathEntry] + +data ProgramSearchPathEntry + = -- | A specific dir + ProgramSearchPathDir FilePath + | -- | The system default + ProgramSearchPathDefault + deriving (Eq, Generic, Typeable) + +instance Binary ProgramSearchPathEntry +instance Structured ProgramSearchPathEntry + -- | Represents a program which has been configured and is thus ready to be run. -- -- These are usually made by configuring a 'Program', but if you have to @@ -145,22 +166,6 @@ programPath = locationPath . programLocation suppressOverrideArgs :: ConfiguredProgram -> ConfiguredProgram suppressOverrideArgs prog = prog{programOverrideArgs = []} --- | 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 ... } -simpleProgram :: String -> Program -simpleProgram name = - Program - { programName = name - , programFindLocation = \v p -> findProgramOnSearchPath v p name - , programFindVersion = \_ _ -> return Nothing - , programPostConf = \_ p -> return p - , programNormaliseArgs = \_ _ -> id - } - -- | Make a simple 'ConfiguredProgram'. -- -- > simpleConfiguredProgram "foo" (FoundOnSystem path) diff --git a/cabal-install/src/Distribution/Client/CmdExec.hs b/cabal-install/src/Distribution/Client/CmdExec.hs index 3a3dd306d8a..20a1ee9756e 100644 --- a/cabal-install/src/Distribution/Client/CmdExec.hs +++ b/cabal-install/src/Distribution/Client/CmdExec.hs @@ -64,6 +64,13 @@ import Distribution.Simple.GHC ( GhcImplInfo (supportsPkgEnvFiles) , getImplInfo ) +import Distribution.Simple.Program + ( ConfiguredProgram + , programDefaultArgs + , programOverrideEnv + , programPath + , simpleProgram + ) import Distribution.Simple.Program.Db ( configuredPrograms , modifyProgramSearchPath @@ -76,13 +83,6 @@ import Distribution.Simple.Program.Run ( programInvocation , runProgramInvocation ) -import Distribution.Simple.Program.Types - ( ConfiguredProgram - , programDefaultArgs - , programOverrideEnv - , programPath - , simpleProgram - ) import Distribution.Simple.Utils ( createDirectoryIfMissingVerbose , dieWithException