From a380904e39ea57e3907c0297b41eb546680b0d3a Mon Sep 17 00:00:00 2001 From: Ɓukasz Hanuszczak Date: Mon, 3 Aug 2015 20:34:12 +0200 Subject: Add GHC path to test runner configuration. --- html-test/run.hs | 68 +++++++++++++++++++++++++++++++++----------------------- 1 file changed, 40 insertions(+), 28 deletions(-) (limited to 'html-test') diff --git a/html-test/run.hs b/html-test/run.hs index 91e692a1..61e00781 100755 --- a/html-test/run.hs +++ b/html-test/run.hs @@ -7,6 +7,9 @@ import Control.Monad import Data.Maybe +import Distribution.Simple.Utils +import Distribution.Verbosity + import System.Console.GetOpt import System.Directory import System.Environment @@ -31,33 +34,19 @@ resDir = rootDir "resources" data Config = Config { cfgHaddockPath :: FilePath + , cfgGhcPath :: FilePath , cfgFiles :: [FilePath] } main :: IO () main = do - Config { .. } <- parseArgs =<< getArgs + Config { .. } <- loadConfig =<< getArgs + return () - env <- Just . (:) ("haddock_datadir", resDir) <$> getEnvironment - handle <- runProcess' cfgHaddockPath $ processConfig - { pcEnv = env - , pcArgs = ["--version"] - } - waitForSuccess "Failed to run `haddock --version`" handle - - handle <- runProcess' cfgHaddockPath $ processConfig - { pcEnv = env - , pcArgs = ["--ghc-version"] - } - waitForSuccess "Failed to run `haddock --ghc-version`" handle - - putStrLn $ "Files to test: " ++ show cfgFiles - - -parseArgs :: [String] -> IO Config -parseArgs args = do +loadConfig :: [String] -> IO Config +loadConfig args = do let (flags, files, errors) = getOpt Permute options args when (not $ null errors) $ do @@ -68,11 +57,35 @@ parseArgs args = do hPutStrLn stderr $ usageInfo "" options exitSuccess + env <- Just . (:) ("haddock_datadir", resDir) <$> getEnvironment + + let cfgHaddockPath = flagsHaddockPath flags + + printVersions env cfgHaddockPath + cfgFiles <- processFileArgs files - let cfgHaddockPath = haddockPath flags + cfgGhcPath <- init <$> rawSystemStdout normal cfgHaddockPath + ["--print-ghc-path"] + putStrLn $ "Files to test: " ++ show cfgFiles return $ Config { .. } + +printVersions :: Maybe [(String, String)] -> FilePath -> IO () +printVersions env haddockPath = do + handle <- runProcess' haddockPath $ processConfig + { pcEnv = env + , pcArgs = ["--version"] + } + waitForSuccess "Failed to run `haddock --version`" handle + + handle <- runProcess' haddockPath $ processConfig + { pcEnv = env + , pcArgs = ["--ghc-version"] + } + waitForSuccess "Failed to run `haddock --ghc-version`" handle + + processFileArgs :: [String] -> IO [FilePath] processFileArgs [] = filter isSourceFile <$> getDirectoryContents srcDir processFileArgs args = pure $ map processFileArg args @@ -103,14 +116,13 @@ options = ] -haddockPath :: [Flag] -> FilePath -haddockPath flags = case mlast [ path | FlagHaddockPath path <- flags ] of - Just path -> path - Nothing -> rootDir "dist" "build" "haddock" "haddock" - - -mlast :: [a] -> Maybe a -mlast = listToMaybe . reverse +flagsHaddockPath :: [Flag] -> FilePath +flagsHaddockPath flags = + case mlast [ path | FlagHaddockPath path <- flags ] of + Just path -> path + Nothing -> rootDir "dist" "build" "haddock" "haddock" + where + mlast = listToMaybe . reverse data ProcessConfig = ProcessConfig -- cgit v1.2.3