module Distribution.Simple.Program.Builtin (
builtinPrograms,
ghcProgram,
ghcPkgProgram,
runghcProgram,
ghcjsProgram,
ghcjsPkgProgram,
hmakeProgram,
jhcProgram,
haskellSuiteProgram,
haskellSuitePkgProgram,
uhcProgram,
gccProgram,
arProgram,
stripProgram,
happyProgram,
alexProgram,
hsc2hsProgram,
c2hsProgram,
cpphsProgram,
hscolourProgram,
doctestProgram,
haddockProgram,
greencardProgram,
ldProgram,
tarProgram,
cppProgram,
pkgConfigProgram,
hpcProgram,
) where
import Prelude ()
import Distribution.Compat.Prelude
import Distribution.Simple.Program.GHC
import Distribution.Simple.Program.Find
import Distribution.Simple.Program.Internal
import Distribution.Simple.Program.Run
import Distribution.Simple.Program.Types
import Distribution.Simple.Utils
import Distribution.Verbosity
import Distribution.Version
import qualified Data.Map as Map
builtinPrograms :: [Program]
builtinPrograms :: [Program]
builtinPrograms =
[
Program
ghcProgram
, Program
runghcProgram
, Program
ghcPkgProgram
, Program
ghcjsProgram
, Program
ghcjsPkgProgram
, Program
haskellSuiteProgram
, Program
haskellSuitePkgProgram
, Program
hmakeProgram
, Program
jhcProgram
, Program
uhcProgram
, Program
hpcProgram
, Program
hscolourProgram
, Program
doctestProgram
, Program
haddockProgram
, Program
happyProgram
, Program
alexProgram
, Program
hsc2hsProgram
, Program
c2hsProgram
, Program
cpphsProgram
, Program
greencardProgram
, Program
gccProgram
, Program
arProgram
, Program
stripProgram
, Program
ldProgram
, Program
tarProgram
, Program
pkgConfigProgram
]
ghcProgram :: Program
ghcProgram :: Program
ghcProgram = (String -> Program
simpleProgram String
"ghc") {
programFindVersion :: Verbosity -> String -> IO (Maybe Version)
programFindVersion = String
-> (String -> String) -> Verbosity -> String -> IO (Maybe Version)
findProgramVersion String
"--numeric-version" String -> String
forall a. a -> a
id,
programPostConf :: Verbosity -> ConfiguredProgram -> IO ConfiguredProgram
programPostConf = \Verbosity
_verbosity ConfiguredProgram
ghcProg ->
do let ghcProg' :: ConfiguredProgram
ghcProg' = ConfiguredProgram
ghcProg {
programOverrideEnv :: [(String, Maybe String)]
programOverrideEnv = (String
"LANGUAGE", String -> Maybe String
forall a. a -> Maybe a
Just String
"en")
(String, Maybe String)
-> [(String, Maybe String)] -> [(String, Maybe String)]
forall a. a -> [a] -> [a]
: ConfiguredProgram -> [(String, Maybe String)]
programOverrideEnv ConfiguredProgram
ghcProg
}
affectedVersionRange :: VersionRange
affectedVersionRange = VersionRange -> VersionRange -> VersionRange
intersectVersionRanges
(Version -> VersionRange
laterVersion (Version -> VersionRange) -> Version -> VersionRange
forall a b. (a -> b) -> a -> b
$ [Int] -> Version
mkVersion [Int
7,Int
8,Int
0])
(Version -> VersionRange
earlierVersion (Version -> VersionRange) -> Version -> VersionRange
forall a b. (a -> b) -> a -> b
$ [Int] -> Version
mkVersion [Int
7,Int
8,Int
4])
ConfiguredProgram -> IO ConfiguredProgram
forall (m :: * -> *) a. Monad m => a -> m a
return (ConfiguredProgram -> IO ConfiguredProgram)
-> ConfiguredProgram -> IO ConfiguredProgram
forall a b. (a -> b) -> a -> b
$ ConfiguredProgram
-> (Version -> ConfiguredProgram)
-> Maybe Version
-> ConfiguredProgram
forall b a. b -> (a -> b) -> Maybe a -> b
maybe ConfiguredProgram
ghcProg
(\Version
v -> if Version -> VersionRange -> Bool
withinRange Version
v VersionRange
affectedVersionRange
then ConfiguredProgram
ghcProg' else ConfiguredProgram
ghcProg)
(ConfiguredProgram -> Maybe Version
programVersion ConfiguredProgram
ghcProg),
programNormaliseArgs :: Maybe Version -> PackageDescription -> [String] -> [String]
programNormaliseArgs = Maybe Version -> PackageDescription -> [String] -> [String]
normaliseGhcArgs
}
runghcProgram :: Program
runghcProgram :: Program
runghcProgram = (String -> Program
simpleProgram String
"runghc") {
programFindVersion :: Verbosity -> String -> IO (Maybe Version)
programFindVersion = String
-> (String -> String) -> Verbosity -> String -> IO (Maybe Version)
findProgramVersion String
"--version" ((String -> String) -> Verbosity -> String -> IO (Maybe Version))
-> (String -> String) -> Verbosity -> String -> IO (Maybe Version)
forall a b. (a -> b) -> a -> b
$ \String
str ->
case String -> [String]
words String
str of
(String
_:String
ver:[String]
_) -> String
ver
[String]
_ -> String
""
}
ghcPkgProgram :: Program
ghcPkgProgram :: Program
ghcPkgProgram = (String -> Program
simpleProgram String
"ghc-pkg") {
programFindVersion :: Verbosity -> String -> IO (Maybe Version)
programFindVersion = String
-> (String -> String) -> Verbosity -> String -> IO (Maybe Version)
findProgramVersion String
"--version" ((String -> String) -> Verbosity -> String -> IO (Maybe Version))
-> (String -> String) -> Verbosity -> String -> IO (Maybe Version)
forall a b. (a -> b) -> a -> b
$ \String
str ->
case String -> [String]
words String
str of
(String
_:String
_:String
_:String
_:String
ver:[String]
_) -> String
ver
[String]
_ -> String
""
}
ghcjsProgram :: Program
ghcjsProgram :: Program
ghcjsProgram = (String -> Program
simpleProgram String
"ghcjs") {
programFindVersion :: Verbosity -> String -> IO (Maybe Version)
programFindVersion = String
-> (String -> String) -> Verbosity -> String -> IO (Maybe Version)
findProgramVersion String
"--numeric-ghcjs-version" String -> String
forall a. a -> a
id
}
ghcjsPkgProgram :: Program
ghcjsPkgProgram :: Program
ghcjsPkgProgram = (String -> Program
simpleProgram String
"ghcjs-pkg") {
programFindVersion :: Verbosity -> String -> IO (Maybe Version)
programFindVersion = String
-> (String -> String) -> Verbosity -> String -> IO (Maybe Version)
findProgramVersion String
"--version" ((String -> String) -> Verbosity -> String -> IO (Maybe Version))
-> (String -> String) -> Verbosity -> String -> IO (Maybe Version)
forall a b. (a -> b) -> a -> b
$ \String
str ->
case String -> [String]
words String
str of
(String
_:String
_:String
_:String
_:String
ver:[String]
_) -> String
ver
[String]
_ -> String
""
}
hmakeProgram :: Program
hmakeProgram :: Program
hmakeProgram = (String -> Program
simpleProgram String
"hmake") {
programFindVersion :: Verbosity -> String -> IO (Maybe Version)
programFindVersion = String
-> (String -> String) -> Verbosity -> String -> IO (Maybe Version)
findProgramVersion String
"--version" ((String -> String) -> Verbosity -> String -> IO (Maybe Version))
-> (String -> String) -> Verbosity -> String -> IO (Maybe Version)
forall a b. (a -> b) -> a -> b
$ \String
str ->
case String -> [String]
words String
str of
(String
_:String
ver:[String]
_) -> String
ver
[String]
_ -> String
""
}
jhcProgram :: Program
jhcProgram :: Program
jhcProgram = (String -> Program
simpleProgram String
"jhc") {
programFindVersion :: Verbosity -> String -> IO (Maybe Version)
programFindVersion = String
-> (String -> String) -> Verbosity -> String -> IO (Maybe Version)
findProgramVersion String
"--version" ((String -> String) -> Verbosity -> String -> IO (Maybe Version))
-> (String -> String) -> Verbosity -> String -> IO (Maybe Version)
forall a b. (a -> b) -> a -> b
$ \String
str ->
case String -> [String]
words String
str of
(String
_:String
ver:[String]
_) -> String
ver
[String]
_ -> String
""
}
uhcProgram :: Program
uhcProgram :: Program
uhcProgram = (String -> Program
simpleProgram String
"uhc") {
programFindVersion :: Verbosity -> String -> IO (Maybe Version)
programFindVersion = String
-> (String -> String) -> Verbosity -> String -> IO (Maybe Version)
findProgramVersion String
"--version-dotted" String -> String
forall a. a -> a
id
}
hpcProgram :: Program
hpcProgram :: Program
hpcProgram = (String -> Program
simpleProgram String
"hpc")
{
programFindVersion :: Verbosity -> String -> IO (Maybe Version)
programFindVersion = String
-> (String -> String) -> Verbosity -> String -> IO (Maybe Version)
findProgramVersion String
"version" ((String -> String) -> Verbosity -> String -> IO (Maybe Version))
-> (String -> String) -> Verbosity -> String -> IO (Maybe Version)
forall a b. (a -> b) -> a -> b
$ \String
str ->
case String -> [String]
words String
str of
(String
_ : String
_ : String
_ : String
ver : [String]
_) -> String
ver
[String]
_ -> String
""
}
haskellSuiteProgram :: Program
haskellSuiteProgram :: Program
haskellSuiteProgram = (String -> Program
simpleProgram String
"haskell-suite") {
programFindLocation :: Verbosity -> ProgramSearchPath -> IO (Maybe (String, [String]))
programFindLocation = \Verbosity
_verbosity ProgramSearchPath
_searchPath ->
Maybe (String, [String]) -> IO (Maybe (String, [String]))
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe (String, [String]) -> IO (Maybe (String, [String])))
-> Maybe (String, [String]) -> IO (Maybe (String, [String]))
forall a b. (a -> b) -> a -> b
$ (String, [String]) -> Maybe (String, [String])
forall a. a -> Maybe a
Just (String
"haskell-suite-dummy-location", [])
}
haskellSuitePkgProgram :: Program
haskellSuitePkgProgram :: Program
haskellSuitePkgProgram = (String -> Program
simpleProgram String
"haskell-suite-pkg") {
programFindLocation :: Verbosity -> ProgramSearchPath -> IO (Maybe (String, [String]))
programFindLocation = \Verbosity
_verbosity ProgramSearchPath
_searchPath ->
Maybe (String, [String]) -> IO (Maybe (String, [String]))
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe (String, [String]) -> IO (Maybe (String, [String])))
-> Maybe (String, [String]) -> IO (Maybe (String, [String]))
forall a b. (a -> b) -> a -> b
$ (String, [String]) -> Maybe (String, [String])
forall a. a -> Maybe a
Just (String
"haskell-suite-pkg-dummy-location", [])
}
happyProgram :: Program
happyProgram :: Program
happyProgram = (String -> Program
simpleProgram String
"happy") {
programFindVersion :: Verbosity -> String -> IO (Maybe Version)
programFindVersion = String
-> (String -> String) -> Verbosity -> String -> IO (Maybe Version)
findProgramVersion String
"--version" ((String -> String) -> Verbosity -> String -> IO (Maybe Version))
-> (String -> String) -> Verbosity -> String -> IO (Maybe Version)
forall a b. (a -> b) -> a -> b
$ \String
str ->
case String -> [String]
words String
str of
(String
_:String
_:String
ver:[String]
_) -> String
ver
[String]
_ -> String
""
}
alexProgram :: Program
alexProgram :: Program
alexProgram = (String -> Program
simpleProgram String
"alex") {
programFindVersion :: Verbosity -> String -> IO (Maybe Version)
programFindVersion = String
-> (String -> String) -> Verbosity -> String -> IO (Maybe Version)
findProgramVersion String
"--version" ((String -> String) -> Verbosity -> String -> IO (Maybe Version))
-> (String -> String) -> Verbosity -> String -> IO (Maybe Version)
forall a b. (a -> b) -> a -> b
$ \String
str ->
case String -> [String]
words String
str of
(String
_:String
_:String
ver:[String]
_) -> (Char -> Bool) -> String -> String
forall a. (a -> Bool) -> [a] -> [a]
takeWhile (\Char
x -> Char -> Bool
isDigit Char
x Bool -> Bool -> Bool
|| Char
x Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'.') String
ver
[String]
_ -> String
""
}
gccProgram :: Program
gccProgram :: Program
gccProgram = (String -> Program
simpleProgram String
"gcc") {
programFindVersion :: Verbosity -> String -> IO (Maybe Version)
programFindVersion = String
-> (String -> String) -> Verbosity -> String -> IO (Maybe Version)
findProgramVersion String
"-dumpversion" String -> String
forall a. a -> a
id
}
arProgram :: Program
arProgram :: Program
arProgram = String -> Program
simpleProgram String
"ar"
stripProgram :: Program
stripProgram :: Program
stripProgram = (String -> Program
simpleProgram String
"strip") {
programFindVersion :: Verbosity -> String -> IO (Maybe Version)
programFindVersion = \Verbosity
verbosity ->
String
-> (String -> String) -> Verbosity -> String -> IO (Maybe Version)
findProgramVersion String
"--version" String -> String
stripExtractVersion (Verbosity -> Verbosity
lessVerbose Verbosity
verbosity)
}
hsc2hsProgram :: Program
hsc2hsProgram :: Program
hsc2hsProgram = (String -> Program
simpleProgram String
"hsc2hs") {
programFindVersion :: Verbosity -> String -> IO (Maybe Version)
programFindVersion =
String
-> (String -> String) -> Verbosity -> String -> IO (Maybe Version)
findProgramVersion String
"--version" ((String -> String) -> Verbosity -> String -> IO (Maybe Version))
-> (String -> String) -> Verbosity -> String -> IO (Maybe Version)
forall a b. (a -> b) -> a -> b
$ \String
str ->
case String -> [String]
words String
str of
(String
_:String
_:String
ver:[String]
_) -> String
ver
[String]
_ -> String
""
}
c2hsProgram :: Program
c2hsProgram :: Program
c2hsProgram = (String -> Program
simpleProgram String
"c2hs") {
programFindVersion :: Verbosity -> String -> IO (Maybe Version)
programFindVersion = String
-> (String -> String) -> Verbosity -> String -> IO (Maybe Version)
findProgramVersion String
"--numeric-version" String -> String
forall a. a -> a
id
}
cpphsProgram :: Program
cpphsProgram :: Program
cpphsProgram = (String -> Program
simpleProgram String
"cpphs") {
programFindVersion :: Verbosity -> String -> IO (Maybe Version)
programFindVersion = String
-> (String -> String) -> Verbosity -> String -> IO (Maybe Version)
findProgramVersion String
"--version" ((String -> String) -> Verbosity -> String -> IO (Maybe Version))
-> (String -> String) -> Verbosity -> String -> IO (Maybe Version)
forall a b. (a -> b) -> a -> b
$ \String
str ->
case String -> [String]
words String
str of
(String
_:String
ver:[String]
_) -> String
ver
[String]
_ -> String
""
}
hscolourProgram :: Program
hscolourProgram :: Program
hscolourProgram = (String -> Program
simpleProgram String
"hscolour") {
programFindLocation :: Verbosity -> ProgramSearchPath -> IO (Maybe (String, [String]))
programFindLocation = \Verbosity
v ProgramSearchPath
p -> Verbosity
-> ProgramSearchPath -> String -> IO (Maybe (String, [String]))
findProgramOnSearchPath Verbosity
v ProgramSearchPath
p String
"HsColour",
programFindVersion :: Verbosity -> String -> IO (Maybe Version)
programFindVersion = String
-> (String -> String) -> Verbosity -> String -> IO (Maybe Version)
findProgramVersion String
"-version" ((String -> String) -> Verbosity -> String -> IO (Maybe Version))
-> (String -> String) -> Verbosity -> String -> IO (Maybe Version)
forall a b. (a -> b) -> a -> b
$ \String
str ->
case String -> [String]
words String
str of
(String
_:String
ver:[String]
_) -> String
ver
[String]
_ -> String
""
}
doctestProgram :: Program
doctestProgram :: Program
doctestProgram = (String -> Program
simpleProgram String
"doctest") {
programFindLocation :: Verbosity -> ProgramSearchPath -> IO (Maybe (String, [String]))
programFindLocation = \Verbosity
v ProgramSearchPath
p -> Verbosity
-> ProgramSearchPath -> String -> IO (Maybe (String, [String]))
findProgramOnSearchPath Verbosity
v ProgramSearchPath
p String
"doctest"
, programFindVersion :: Verbosity -> String -> IO (Maybe Version)
programFindVersion = String
-> (String -> String) -> Verbosity -> String -> IO (Maybe Version)
findProgramVersion String
"--version" ((String -> String) -> Verbosity -> String -> IO (Maybe Version))
-> (String -> String) -> Verbosity -> String -> IO (Maybe Version)
forall a b. (a -> b) -> a -> b
$ \String
str ->
case String -> [String]
words String
str of
(String
_:String
_:String
ver:[String]
_) -> String
ver
[String]
_ -> String
""
}
haddockProgram :: Program
haddockProgram :: Program
haddockProgram = (String -> Program
simpleProgram String
"haddock") {
programFindVersion :: Verbosity -> String -> IO (Maybe Version)
programFindVersion = String
-> (String -> String) -> Verbosity -> String -> IO (Maybe Version)
findProgramVersion String
"--version" ((String -> String) -> Verbosity -> String -> IO (Maybe Version))
-> (String -> String) -> Verbosity -> String -> IO (Maybe Version)
forall a b. (a -> b) -> a -> b
$ \String
str ->
case String -> [String]
words String
str of
(String
_:String
_:String
ver:[String]
_) -> (Char -> Bool) -> String -> String
forall a. (a -> Bool) -> [a] -> [a]
takeWhile (Char -> String -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` (Char
'.'Char -> String -> String
forall a. a -> [a] -> [a]
:[Char
'0'..Char
'9'])) String
ver
[String]
_ -> String
"",
programNormaliseArgs :: Maybe Version -> PackageDescription -> [String] -> [String]
programNormaliseArgs = \Maybe Version
_ PackageDescription
_ [String]
args -> [String]
args
}
greencardProgram :: Program
greencardProgram :: Program
greencardProgram = String -> Program
simpleProgram String
"greencard"
ldProgram :: Program
ldProgram :: Program
ldProgram = String -> Program
simpleProgram String
"ld"
tarProgram :: Program
tarProgram :: Program
tarProgram = (String -> Program
simpleProgram String
"tar") {
programPostConf :: Verbosity -> ConfiguredProgram -> IO ConfiguredProgram
programPostConf = \Verbosity
verbosity ConfiguredProgram
tarProg -> do
String
tarHelpOutput <- Verbosity -> ProgramInvocation -> IO String
getProgramInvocationOutput
Verbosity
verbosity (ConfiguredProgram -> [String] -> ProgramInvocation
programInvocation ConfiguredProgram
tarProg [String
"--help"])
IO String -> (IOException -> IO String) -> IO String
forall a. IO a -> (IOException -> IO a) -> IO a
`catchIO` (\IOException
_ -> String -> IO String
forall (m :: * -> *) a. Monad m => a -> m a
return String
"")
let k :: String
k = String
"Supports --format"
v :: String
v = if (String
"--format" String -> String -> Bool
forall a. Eq a => [a] -> [a] -> Bool
`isInfixOf` String
tarHelpOutput) then String
"YES" else String
"NO"
m :: Map String String
m = String -> String -> Map String String -> Map String String
forall k a. Ord k => k -> a -> Map k a -> Map k a
Map.insert String
k String
v (ConfiguredProgram -> Map String String
programProperties ConfiguredProgram
tarProg)
ConfiguredProgram -> IO ConfiguredProgram
forall (m :: * -> *) a. Monad m => a -> m a
return (ConfiguredProgram -> IO ConfiguredProgram)
-> ConfiguredProgram -> IO ConfiguredProgram
forall a b. (a -> b) -> a -> b
$ ConfiguredProgram
tarProg { programProperties :: Map String String
programProperties = Map String String
m }
}
cppProgram :: Program
cppProgram :: Program
cppProgram = String -> Program
simpleProgram String
"cpp"
pkgConfigProgram :: Program
pkgConfigProgram :: Program
pkgConfigProgram = (String -> Program
simpleProgram String
"pkg-config") {
programFindVersion :: Verbosity -> String -> IO (Maybe Version)
programFindVersion = String
-> (String -> String) -> Verbosity -> String -> IO (Maybe Version)
findProgramVersion String
"--version" String -> String
forall a. a -> a
id
}