Skip to content

Commit 44775ad

Browse files
sheafMikolaj
authored andcommitted
Shuffle around Distribution.Simple.Program.Types
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.
1 parent 8070ab1 commit 44775ad

File tree

3 files changed

+48
-48
lines changed

3 files changed

+48
-48
lines changed

Cabal/src/Distribution/Simple/Program/Find.hs

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,14 @@ module Distribution.Simple.Program.Find
3333
, findProgramOnSearchPath
3434
, programSearchPathAsPATHVar
3535
, getSystemSearchPath
36+
, simpleProgram
3637
) where
3738

3839
import Distribution.Compat.Prelude
3940
import Prelude ()
4041

4142
import Distribution.Compat.Environment
43+
import Distribution.Simple.Program.Types
4244
import Distribution.Simple.Utils
4345
import Distribution.System
4446
import Distribution.Verbosity
@@ -58,29 +60,6 @@ import System.FilePath as FilePath
5860
import qualified System.Win32 as Win32
5961
#endif
6062

61-
-- | A search path to use when locating executables. This is analogous
62-
-- to the unix @$PATH@ or win32 @%PATH%@ but with the ability to use
63-
-- the system default method for finding executables ('findExecutable' which
64-
-- on unix is simply looking on the @$PATH@ but on win32 is a bit more
65-
-- complicated).
66-
--
67-
-- The default to use is @[ProgSearchPathDefault]@ but you can add extra dirs
68-
-- either before, after or instead of the default, e.g. here we add an extra
69-
-- dir to search after the usual ones.
70-
--
71-
-- > ['ProgramSearchPathDefault', 'ProgramSearchPathDir' dir]
72-
type ProgramSearchPath = [ProgramSearchPathEntry]
73-
74-
data ProgramSearchPathEntry
75-
= -- | A specific dir
76-
ProgramSearchPathDir FilePath
77-
| -- | The system default
78-
ProgramSearchPathDefault
79-
deriving (Eq, Generic, Typeable)
80-
81-
instance Binary ProgramSearchPathEntry
82-
instance Structured ProgramSearchPathEntry
83-
8463
defaultProgramSearchPath :: ProgramSearchPath
8564
defaultProgramSearchPath = [ProgramSearchPathDefault]
8665

@@ -207,3 +186,19 @@ findExecutable prog = do
207186
else return Nothing
208187
_ -> return mExe
209188
#endif
189+
190+
-- | Make a simple named program.
191+
--
192+
-- By default we'll just search for it in the path and not try to find the
193+
-- version name. You can override these behaviours if necessary, eg:
194+
--
195+
-- > (simpleProgram "foo") { programFindLocation = ... , programFindVersion ... }
196+
simpleProgram :: String -> Program
197+
simpleProgram name =
198+
Program
199+
{ programName = name
200+
, programFindLocation = \v p -> findProgramOnSearchPath v p name
201+
, programFindVersion = \_ _ -> return Nothing
202+
, programPostConf = \_ p -> return p
203+
, programNormaliseArgs = \_ _ -> id
204+
}

Cabal/src/Distribution/Simple/Program/Types.hs

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ module Distribution.Simple.Program.Types
2424
Program (..)
2525
, ProgramSearchPath
2626
, ProgramSearchPathEntry (..)
27-
, simpleProgram
2827

2928
-- * Configured program and related functions
3029
, ConfiguredProgram (..)
@@ -39,7 +38,6 @@ import Distribution.Compat.Prelude
3938
import Prelude ()
4039

4140
import Distribution.PackageDescription
42-
import Distribution.Simple.Program.Find
4341
import Distribution.Verbosity
4442
import Distribution.Version
4543

@@ -84,6 +82,29 @@ instance Show Program where
8482

8583
type ProgArg = String
8684

85+
-- | A search path to use when locating executables. This is analogous
86+
-- to the unix @$PATH@ or win32 @%PATH%@ but with the ability to use
87+
-- the system default method for finding executables ('findExecutable' which
88+
-- on unix is simply looking on the @$PATH@ but on win32 is a bit more
89+
-- complicated).
90+
--
91+
-- The default to use is @[ProgSearchPathDefault]@ but you can add extra dirs
92+
-- either before, after or instead of the default, e.g. here we add an extra
93+
-- dir to search after the usual ones.
94+
--
95+
-- > ['ProgramSearchPathDefault', 'ProgramSearchPathDir' dir]
96+
type ProgramSearchPath = [ProgramSearchPathEntry]
97+
98+
data ProgramSearchPathEntry
99+
= -- | A specific dir
100+
ProgramSearchPathDir FilePath
101+
| -- | The system default
102+
ProgramSearchPathDefault
103+
deriving (Eq, Generic, Typeable)
104+
105+
instance Binary ProgramSearchPathEntry
106+
instance Structured ProgramSearchPathEntry
107+
87108
-- | Represents a program which has been configured and is thus ready to be run.
88109
--
89110
-- These are usually made by configuring a 'Program', but if you have to
@@ -145,22 +166,6 @@ programPath = locationPath . programLocation
145166
suppressOverrideArgs :: ConfiguredProgram -> ConfiguredProgram
146167
suppressOverrideArgs prog = prog{programOverrideArgs = []}
147168

148-
-- | Make a simple named program.
149-
--
150-
-- By default we'll just search for it in the path and not try to find the
151-
-- version name. You can override these behaviours if necessary, eg:
152-
--
153-
-- > (simpleProgram "foo") { programFindLocation = ... , programFindVersion ... }
154-
simpleProgram :: String -> Program
155-
simpleProgram name =
156-
Program
157-
{ programName = name
158-
, programFindLocation = \v p -> findProgramOnSearchPath v p name
159-
, programFindVersion = \_ _ -> return Nothing
160-
, programPostConf = \_ p -> return p
161-
, programNormaliseArgs = \_ _ -> id
162-
}
163-
164169
-- | Make a simple 'ConfiguredProgram'.
165170
--
166171
-- > simpleConfiguredProgram "foo" (FoundOnSystem path)

cabal-install/src/Distribution/Client/CmdExec.hs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,13 @@ import Distribution.Simple.GHC
6464
( GhcImplInfo (supportsPkgEnvFiles)
6565
, getImplInfo
6666
)
67+
import Distribution.Simple.Program
68+
( ConfiguredProgram
69+
, programDefaultArgs
70+
, programOverrideEnv
71+
, programPath
72+
, simpleProgram
73+
)
6774
import Distribution.Simple.Program.Db
6875
( configuredPrograms
6976
, modifyProgramSearchPath
@@ -76,13 +83,6 @@ import Distribution.Simple.Program.Run
7683
( programInvocation
7784
, runProgramInvocation
7885
)
79-
import Distribution.Simple.Program.Types
80-
( ConfiguredProgram
81-
, programDefaultArgs
82-
, programOverrideEnv
83-
, programPath
84-
, simpleProgram
85-
)
8686
import Distribution.Simple.Utils
8787
( createDirectoryIfMissingVerbose
8888
, dieWithException

0 commit comments

Comments
 (0)