diff --git a/yesod/ghcwrapper.hs b/yesod/ghcwrapper.hs index b71b475e..9e8afc53 100644 --- a/yesod/ghcwrapper.hs +++ b/yesod/ghcwrapper.hs @@ -5,37 +5,55 @@ {-# LANGUAGE CPP #-} module Main where -import System.Process (rawSystem, readProcess) -import System.Environment (getArgs) -import Data.Maybe (fromMaybe) 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.Environment (getArgs) +import System.Exit (exitWith, ExitCode(..)) +import System.IO (hPutStrLn, stderr) +import System.Process (rawSystem, readProcess) + #ifdef LDCMD -cmd = lookupGhcInfo "ld command" "ld" +cmd :: Program +cmd = ldProgram outFile = "dist/ldargs.txt" #else #ifdef ARCMD -cmd = lookupGhcInfo "ar command" "ar" +cmd :: Program +cmd = arProgram outFile ="dist/arargs.txt" #else -cmd = return "ghc" +cmd :: Program +cmd = ghcProgram outFile = "dist/ghcargs.txt" #endif #endif -lookupGhcInfo :: String -> String -> IO String -lookupGhcInfo xs d = fmap (fromMaybe d . lookup xs . read) (readProcess "ghc" ["--info"] "") - -passthrough args = do - c <- cmd - rawSystem c args +runProgram :: Program -> [String] -> IO ExitCode +runProgram pgm args = do + (comp, pgmc) <- configCompiler (Just GHC) Nothing Nothing defaultProgramConfiguration silent + pgmc' <- configureProgram silent pgm pgmc + case lookupProgram pgm pgmc' of + Nothing -> do + hPutStrLn stderr ("cannot find program '" ++ programName pgm ++ "'") + return (ExitFailure 1) + Just p -> rawSystem (programPath p) args main = do args <- getArgs e <- doesDirectoryExist "dist" when e $ writeFile outFile (show args ++ "\n") - ex <- passthrough args + ex <- runProgram cmd args exitWith ex + diff --git a/yesod/yesod.cabal b/yesod/yesod.cabal index b6c1d8ce..ef48dff8 100644 --- a/yesod/yesod.cabal +++ b/yesod/yesod.cabal @@ -94,18 +94,21 @@ library executable yesod-ghc-wrapper main-is: ghcwrapper.hs build-depends: - base >= 4 && < 5 + base >= 4 && < 5 + , Cabal >= 1.10 && < 1.16 executable yesod-ld-wrapper main-is: ghcwrapper.hs cpp-options: -DLDCMD build-depends: - base >= 4 && < 5 + base >= 4 && < 5 + , Cabal >= 1.10 && < 1.16 executable yesod-ar-wrapper main-is: ghcwrapper.hs cpp-options: -DARCMD build-depends: - base >= 4 && < 5 + base >= 4 && < 5 + , Cabal >= 1.10 && < 1.16 executable yesod if flag(ghc7)