diff options
Diffstat (limited to 'bootstrap/src/Fpm.hs')
-rw-r--r-- | bootstrap/src/Fpm.hs | 176 |
1 files changed, 100 insertions, 76 deletions
diff --git a/bootstrap/src/Fpm.hs b/bootstrap/src/Fpm.hs index c23263e..567a098 100644 --- a/bootstrap/src/Fpm.hs +++ b/bootstrap/src/Fpm.hs @@ -91,6 +91,7 @@ data Arguments = { runRelease :: Bool , runCompiler :: FilePath , runFlags :: [String] + , runRunner :: Maybe String , runTarget :: Maybe String , runArgs :: Maybe [String] } @@ -98,6 +99,7 @@ data Arguments = { testRelease :: Bool , testCompiler :: FilePath , testFlags :: [String] + , testRunner :: Maybe String , testTarget :: Maybe String , testArgs :: Maybe [String] } @@ -164,7 +166,7 @@ start args = case args of app :: Arguments -> AppSettings -> IO () app args settings = case args of Build{} -> build settings - Run { runTarget = whichOne, runArgs = runArgs } -> do + Run { runTarget = whichOne, runArgs = runArgs, runRunner = runner } -> do build settings let buildPrefix = appSettingsBuildPrefix settings let @@ -178,78 +180,81 @@ app args settings = case args of canonicalExecutables <- mapM makeAbsolute executables case canonicalExecutables of [] -> putStrLn "No Executables Found" - _ -> case whichOne of - Nothing -> do - exitCodes <- mapM - system - (map - (++ case runArgs of - Nothing -> "" - Just theArgs -> " " ++ (intercalate " " theArgs) - ) - canonicalExecutables - ) - forM_ - exitCodes - (\exitCode -> when - (case exitCode of - ExitSuccess -> False - _ -> True - ) - (exitWith exitCode) - ) - Just name -> do - case find (name `isSuffixOf`) canonicalExecutables of - Nothing -> putStrLn "Executable Not Found" - Just specified -> do - exitCode <- case runArgs of - Nothing -> system specified - Just theArgs -> - system (specified ++ " " ++ (intercalate " " theArgs)) - exitWith exitCode - Test { testTarget = whichOne, testArgs = testArgs } -> do - build settings - let buildPrefix = appSettingsBuildPrefix settings - let - executableNames = map - (\Executable { executableSourceDir = sourceDir, executableMainFile = mainFile, executableName = name } -> - sourceDir </> name - ) - (appSettingsTests settings) - let executables = - map (buildPrefix </>) $ map (flip (<.>) exe) executableNames - canonicalExecutables <- mapM makeAbsolute executables - case canonicalExecutables of - [] -> putStrLn "No Tests Found" - _ -> case whichOne of - Nothing -> do - exitCodes <- mapM - system - (map - (++ case testArgs of - Nothing -> "" - Just theArgs -> " " ++ (intercalate " " theArgs) - ) - canonicalExecutables - ) - forM_ - exitCodes - (\exitCode -> when - (case exitCode of - ExitSuccess -> False - _ -> True - ) - (exitWith exitCode) - ) - Just name -> do - case find (name `isSuffixOf`) canonicalExecutables of - Nothing -> putStrLn "Test Not Found" - Just specified -> do - exitCode <- case testArgs of - Nothing -> system specified - Just theArgs -> - system (specified ++ " " ++ (intercalate " " theArgs)) - exitWith exitCode + _ -> + let commandPrefix = case runner of + Nothing -> "" + Just r -> r ++ " " + commandSufix = case runArgs of + Nothing -> "" + Just a -> " " ++ (intercalate " " a) + in case whichOne of + Nothing -> do + exitCodes <- mapM + system + (map (\exe -> commandPrefix ++ exe ++ commandSufix) + canonicalExecutables + ) + forM_ + exitCodes + (\exitCode -> when + (case exitCode of + ExitSuccess -> False + _ -> True + ) + (exitWith exitCode) + ) + Just name -> do + case find (name `isSuffixOf`) canonicalExecutables of + Nothing -> putStrLn "Executable Not Found" + Just specified -> do + exitCode <- system + (commandPrefix ++ specified ++ commandSufix) + exitWith exitCode + Test { testTarget = whichOne, testArgs = testArgs, testRunner = runner } -> + do + build settings + let buildPrefix = appSettingsBuildPrefix settings + let + executableNames = map + (\Executable { executableSourceDir = sourceDir, executableMainFile = mainFile, executableName = name } -> + sourceDir </> name + ) + (appSettingsTests settings) + let executables = + map (buildPrefix </>) $ map (flip (<.>) exe) executableNames + canonicalExecutables <- mapM makeAbsolute executables + case canonicalExecutables of + [] -> putStrLn "No Tests Found" + _ -> + let commandPrefix = case runner of + Nothing -> "" + Just r -> r ++ " " + commandSufix = case testArgs of + Nothing -> "" + Just a -> " " ++ (intercalate " " a) + in case whichOne of + Nothing -> do + exitCodes <- mapM + system + (map (\exe -> commandPrefix ++ exe ++ commandSufix) + canonicalExecutables + ) + forM_ + exitCodes + (\exitCode -> when + (case exitCode of + ExitSuccess -> False + _ -> True + ) + (exitWith exitCode) + ) + Just name -> do + case find (name `isSuffixOf`) canonicalExecutables of + Nothing -> putStrLn "Test Not Found" + Just specified -> do + exitCode <- system + (commandPrefix ++ specified ++ commandSufix) + exitWith exitCode _ -> putStrLn "Shouldn't be able to get here" build :: AppSettings -> IO () @@ -426,6 +431,12 @@ runArguments = ) <*> optional (strOption + (long "runner" <> metavar "RUNNER" <> help + "specify a command to be used to run the executable(s)" + ) + ) + <*> optional + (strOption (long "target" <> metavar "TARGET" <> help "Name of the executable to run" ) @@ -433,7 +444,9 @@ runArguments = <*> optional (many (strArgument - (metavar "ARGS" <> help "Arguments to the executable(s) (should follow '--')") + ( metavar "ARGS" + <> help "Arguments to the executable(s) (should follow '--')" + ) ) ) @@ -460,11 +473,22 @@ testArguments = ) ) <*> optional - (strOption (long "target" <> metavar "TARGET" <> help "Name of the test to run")) + (strOption + (long "runner" <> metavar "RUNNER" <> help + "specify a command to be used to run the test(s)" + ) + ) + <*> optional + (strOption + (long "target" <> metavar "TARGET" <> help "Name of the test to run" + ) + ) <*> optional (many (strArgument - (metavar "ARGS" <> help "Arguments to the test(s) (should follow '--')") + ( metavar "ARGS" + <> help "Arguments to the test(s) (should follow '--')" + ) ) ) |