module BuildBox.Command.Environment
(
Environment(..)
, getEnvironmentWith
, Platform(..)
, getHostPlatform
, getHostName
, getHostArch
, getHostProcessor
, getHostOS
, getHostRelease
, getVersionGHC
, getVersionGCC)
where
import BuildBox.Build
import BuildBox.Command.System
import BuildBox.Command.File
import BuildBox.Pretty
data Environment
= Environment
{ environmentPlatform :: Platform
, environmentVersions :: [(String, String)] }
deriving (Show, Read)
instance Pretty Environment where
ppr env
= vcat
[ ppr "Environment"
, indents 2
[ ppr $ environmentPlatform env
, indents 2
$ ppr "Versions"
: ( map (\(name, ver) -> ppr name %% ppr ver)
$ environmentVersions env)
]
]
getEnvironmentWith
:: [(String, Build String)]
-> Build Environment
getEnvironmentWith nameGets
= do platform
<- getHostPlatform
versions
<- mapM (\(name, get) -> do
ver <- get
return (name, ver))
$ nameGets
return $ Environment
{ environmentPlatform = platform
, environmentVersions = versions }
data Platform
= Platform
{ platformHostName :: String
, platformHostArch :: String
, platformHostProcessor :: String
, platformHostOS :: String
, platformHostRelease :: String }
deriving (Show, Read)
instance Pretty Platform where
ppr plat
= vcat
[ ppr "Platform"
, indents 2
[ ppr "host: " % (ppr $ platformHostName plat)
, ppr "arch: " % (ppr $ platformHostArch plat)
, ppr "processor: " % (ppr $ platformHostProcessor plat)
, ppr "system: " % (ppr $ platformHostOS plat)
%% (ppr $ platformHostRelease plat) ]]
getHostPlatform :: Build Platform
getHostPlatform
= do name <- getHostName
arch <- getHostArch
processor <- getHostProcessor
os <- getHostOS
release <- getHostRelease
return $ Platform
{ platformHostName = name
, platformHostArch = arch
, platformHostProcessor = processor
, platformHostOS = os
, platformHostRelease = release }
getHostName :: Build String
getHostName
= do check $ HasExecutable "uname"
name <- sesystemq "uname -n"
return $ init name
getHostArch :: Build String
getHostArch
= do check $ HasExecutable "arch"
name <- sesystemq "arch"
return $ init name
getHostProcessor :: Build String
getHostProcessor
= do check $ HasExecutable "uname"
name <- sesystemq "uname -p"
return $ init name
getHostOS :: Build String
getHostOS
= do check $ HasExecutable "uname"
name <- sesystemq "uname -s"
return $ init name
getHostRelease :: Build String
getHostRelease
= do check $ HasExecutable "uname"
str <- sesystemq "uname -r"
return $ init str
getVersionGHC :: FilePath -> Build String
getVersionGHC path
= do check $ HasExecutable path
str <- sesystemq $ path ++ " --version"
return $ init str
getVersionGCC :: FilePath -> Build String
getVersionGCC path
= do check $ HasExecutable path
str <- sesystemq $ path ++ " --version"
return $ head $ lines str