Skip to content

Commit

Permalink
Shuffle around Distribution.Simple.Program.Types
Browse files Browse the repository at this point in the history
This commmit removes the dependency of the
Distribution.Simple.Program.Types on Distribution.Simple.Program.Find
by shuffling around a few definitions between the modules.

This makes the "Types" module more self-contained, which means it
can be more easily imported without causing module cycles.
  • Loading branch information
sheaf committed Dec 19, 2023
1 parent feaa338 commit 23fb615
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 48 deletions.
41 changes: 18 additions & 23 deletions Cabal/src/Distribution/Simple/Program/Find.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]

Expand Down Expand Up @@ -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
}
41 changes: 23 additions & 18 deletions Cabal/src/Distribution/Simple/Program/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ module Distribution.Simple.Program.Types
Program (..)
, ProgramSearchPath
, ProgramSearchPathEntry (..)
, simpleProgram

-- * Configured program and related functions
, ConfiguredProgram (..)
Expand All @@ -39,7 +38,6 @@ import Distribution.Compat.Prelude
import Prelude ()

import Distribution.PackageDescription
import Distribution.Simple.Program.Find
import Distribution.Verbosity
import Distribution.Version

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
14 changes: 7 additions & 7 deletions cabal-install/src/Distribution/Client/CmdExec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 23fb615

Please sign in to comment.