use Cabal to determine program locations
This commit is contained in:
parent
0c60da3472
commit
c097d289f8
@ -5,37 +5,55 @@
|
|||||||
{-# LANGUAGE CPP #-}
|
{-# LANGUAGE CPP #-}
|
||||||
module Main where
|
module Main where
|
||||||
|
|
||||||
import System.Process (rawSystem, readProcess)
|
|
||||||
import System.Environment (getArgs)
|
|
||||||
import Data.Maybe (fromMaybe)
|
|
||||||
import Control.Monad (when)
|
import Control.Monad (when)
|
||||||
import System.Exit (exitWith)
|
import Data.Maybe (fromMaybe)
|
||||||
|
|
||||||
|
import Distribution.Compiler (CompilerFlavor(..))
|
||||||
|
import Distribution.Simple.Configure (configCompiler)
|
||||||
|
import Distribution.Simple.Program (defaultProgramConfiguration, programPath, ghcProgram,
|
||||||
|
ldProgram, arProgram)
|
||||||
|
import Distribution.Simple.Program.Db (lookupProgram, configureProgram)
|
||||||
|
import Distribution.Simple.Program.Types (Program(..))
|
||||||
|
import Distribution.Verbosity (silent)
|
||||||
|
|
||||||
import System.Directory (doesDirectoryExist)
|
import System.Directory (doesDirectoryExist)
|
||||||
|
import System.Environment (getArgs)
|
||||||
|
import System.Exit (exitWith, ExitCode(..))
|
||||||
|
import System.IO (hPutStrLn, stderr)
|
||||||
|
import System.Process (rawSystem, readProcess)
|
||||||
|
|
||||||
|
|
||||||
#ifdef LDCMD
|
#ifdef LDCMD
|
||||||
cmd = lookupGhcInfo "ld command" "ld"
|
cmd :: Program
|
||||||
|
cmd = ldProgram
|
||||||
outFile = "dist/ldargs.txt"
|
outFile = "dist/ldargs.txt"
|
||||||
#else
|
#else
|
||||||
#ifdef ARCMD
|
#ifdef ARCMD
|
||||||
cmd = lookupGhcInfo "ar command" "ar"
|
cmd :: Program
|
||||||
|
cmd = arProgram
|
||||||
outFile ="dist/arargs.txt"
|
outFile ="dist/arargs.txt"
|
||||||
#else
|
#else
|
||||||
cmd = return "ghc"
|
cmd :: Program
|
||||||
|
cmd = ghcProgram
|
||||||
outFile = "dist/ghcargs.txt"
|
outFile = "dist/ghcargs.txt"
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
lookupGhcInfo :: String -> String -> IO String
|
runProgram :: Program -> [String] -> IO ExitCode
|
||||||
lookupGhcInfo xs d = fmap (fromMaybe d . lookup xs . read) (readProcess "ghc" ["--info"] "")
|
runProgram pgm args = do
|
||||||
|
(comp, pgmc) <- configCompiler (Just GHC) Nothing Nothing defaultProgramConfiguration silent
|
||||||
passthrough args = do
|
pgmc' <- configureProgram silent pgm pgmc
|
||||||
c <- cmd
|
case lookupProgram pgm pgmc' of
|
||||||
rawSystem c args
|
Nothing -> do
|
||||||
|
hPutStrLn stderr ("cannot find program '" ++ programName pgm ++ "'")
|
||||||
|
return (ExitFailure 1)
|
||||||
|
Just p -> rawSystem (programPath p) args
|
||||||
|
|
||||||
main = do
|
main = do
|
||||||
args <- getArgs
|
args <- getArgs
|
||||||
e <- doesDirectoryExist "dist"
|
e <- doesDirectoryExist "dist"
|
||||||
when e $ writeFile outFile (show args ++ "\n")
|
when e $ writeFile outFile (show args ++ "\n")
|
||||||
ex <- passthrough args
|
ex <- runProgram cmd args
|
||||||
exitWith ex
|
exitWith ex
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -94,18 +94,21 @@ library
|
|||||||
executable yesod-ghc-wrapper
|
executable yesod-ghc-wrapper
|
||||||
main-is: ghcwrapper.hs
|
main-is: ghcwrapper.hs
|
||||||
build-depends:
|
build-depends:
|
||||||
base >= 4 && < 5
|
base >= 4 && < 5
|
||||||
|
, Cabal >= 1.10 && < 1.16
|
||||||
|
|
||||||
executable yesod-ld-wrapper
|
executable yesod-ld-wrapper
|
||||||
main-is: ghcwrapper.hs
|
main-is: ghcwrapper.hs
|
||||||
cpp-options: -DLDCMD
|
cpp-options: -DLDCMD
|
||||||
build-depends:
|
build-depends:
|
||||||
base >= 4 && < 5
|
base >= 4 && < 5
|
||||||
|
, Cabal >= 1.10 && < 1.16
|
||||||
executable yesod-ar-wrapper
|
executable yesod-ar-wrapper
|
||||||
main-is: ghcwrapper.hs
|
main-is: ghcwrapper.hs
|
||||||
cpp-options: -DARCMD
|
cpp-options: -DARCMD
|
||||||
build-depends:
|
build-depends:
|
||||||
base >= 4 && < 5
|
base >= 4 && < 5
|
||||||
|
, Cabal >= 1.10 && < 1.16
|
||||||
|
|
||||||
executable yesod
|
executable yesod
|
||||||
if flag(ghc7)
|
if flag(ghc7)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user