Skip to content

Commit 7d5a9b5

Browse files
Add options to specify a command to be used to run the executable(s) or test(s)
1 parent c88cabc commit 7d5a9b5

File tree

2 files changed

+95
-71
lines changed

2 files changed

+95
-71
lines changed

bootstrap/src/Fpm.hs

Lines changed: 90 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,15 @@ data Arguments =
8888
{ runRelease :: Bool
8989
, runCompiler :: FilePath
9090
, runFlags :: [String]
91+
, runRunner :: Maybe String
9192
, runTarget :: Maybe String
9293
, runArgs :: Maybe String
9394
}
9495
| Test
9596
{ testRelease :: Bool
9697
, testCompiler :: FilePath
9798
, testFlags :: [String]
99+
, testRunner :: Maybe String
98100
, testTarget :: Maybe String
99101
, testArgs :: Maybe String
100102
}
@@ -161,7 +163,7 @@ start args = case args of
161163
app :: Arguments -> AppSettings -> IO ()
162164
app args settings = case args of
163165
Build{} -> build settings
164-
Run { runTarget = whichOne, runArgs = runArgs } -> do
166+
Run { runTarget = whichOne, runArgs = runArgs, runRunner = runner } -> do
165167
build settings
166168
let buildPrefix = appSettingsBuildPrefix settings
167169
let
@@ -175,76 +177,81 @@ app args settings = case args of
175177
canonicalExecutables <- mapM makeAbsolute executables
176178
case canonicalExecutables of
177179
[] -> putStrLn "No Executables Found"
178-
_ -> case whichOne of
179-
Nothing -> do
180-
exitCodes <- mapM
181-
system
182-
(map
183-
(++ case runArgs of
184-
Nothing -> ""
185-
Just theArgs -> " " ++ theArgs
186-
)
187-
canonicalExecutables
188-
)
189-
forM_
190-
exitCodes
191-
(\exitCode -> when
192-
(case exitCode of
193-
ExitSuccess -> False
194-
_ -> True
195-
)
196-
(exitWith exitCode)
197-
)
198-
Just name -> do
199-
case find (name `isSuffixOf`) canonicalExecutables of
200-
Nothing -> putStrLn "Executable Not Found"
201-
Just specified -> do
202-
exitCode <- case runArgs of
203-
Nothing -> system specified
204-
Just theArgs -> system (specified ++ " " ++ theArgs)
205-
exitWith exitCode
206-
Test { testTarget = whichOne, testArgs = testArgs } -> do
207-
build settings
208-
let buildPrefix = appSettingsBuildPrefix settings
209-
let
210-
executableNames = map
211-
(\Executable { executableSourceDir = sourceDir, executableMainFile = mainFile, executableName = name } ->
212-
sourceDir </> name
213-
)
214-
(appSettingsTests settings)
215-
let executables =
216-
map (buildPrefix </>) $ map (flip (<.>) exe) executableNames
217-
canonicalExecutables <- mapM makeAbsolute executables
218-
case canonicalExecutables of
219-
[] -> putStrLn "No Tests Found"
220-
_ -> case whichOne of
221-
Nothing -> do
222-
exitCodes <- mapM
223-
system
224-
(map
225-
(++ case testArgs of
226-
Nothing -> ""
227-
Just theArgs -> " " ++ theArgs
228-
)
229-
canonicalExecutables
230-
)
231-
forM_
232-
exitCodes
233-
(\exitCode -> when
234-
(case exitCode of
235-
ExitSuccess -> False
236-
_ -> True
237-
)
238-
(exitWith exitCode)
239-
)
240-
Just name -> do
241-
case find (name `isSuffixOf`) canonicalExecutables of
242-
Nothing -> putStrLn "Test Not Found"
243-
Just specified -> do
244-
exitCode <- case testArgs of
245-
Nothing -> system specified
246-
Just theArgs -> system (specified ++ " " ++ theArgs)
247-
exitWith exitCode
180+
_ ->
181+
let commandPrefix = case runner of
182+
Nothing -> ""
183+
Just r -> r ++ " "
184+
commandSufix = case runArgs of
185+
Nothing -> ""
186+
Just a -> " " ++ a
187+
in case whichOne of
188+
Nothing -> do
189+
exitCodes <- mapM
190+
system
191+
(map (\exe -> commandPrefix ++ exe ++ commandSufix)
192+
canonicalExecutables
193+
)
194+
forM_
195+
exitCodes
196+
(\exitCode -> when
197+
(case exitCode of
198+
ExitSuccess -> False
199+
_ -> True
200+
)
201+
(exitWith exitCode)
202+
)
203+
Just name -> do
204+
case find (name `isSuffixOf`) canonicalExecutables of
205+
Nothing -> putStrLn "Executable Not Found"
206+
Just specified -> do
207+
exitCode <- system
208+
(commandPrefix ++ specified ++ commandSufix)
209+
exitWith exitCode
210+
Test { testTarget = whichOne, testArgs = testArgs, testRunner = runner } ->
211+
do
212+
build settings
213+
let buildPrefix = appSettingsBuildPrefix settings
214+
let
215+
executableNames = map
216+
(\Executable { executableSourceDir = sourceDir, executableMainFile = mainFile, executableName = name } ->
217+
sourceDir </> name
218+
)
219+
(appSettingsTests settings)
220+
let executables =
221+
map (buildPrefix </>) $ map (flip (<.>) exe) executableNames
222+
canonicalExecutables <- mapM makeAbsolute executables
223+
case canonicalExecutables of
224+
[] -> putStrLn "No Tests Found"
225+
_ ->
226+
let commandPrefix = case runner of
227+
Nothing -> ""
228+
Just r -> r ++ " "
229+
commandSufix = case testArgs of
230+
Nothing -> ""
231+
Just a -> " " ++ a
232+
in case whichOne of
233+
Nothing -> do
234+
exitCodes <- mapM
235+
system
236+
(map (\exe -> commandPrefix ++ exe ++ commandSufix)
237+
canonicalExecutables
238+
)
239+
forM_
240+
exitCodes
241+
(\exitCode -> when
242+
(case exitCode of
243+
ExitSuccess -> False
244+
_ -> True
245+
)
246+
(exitWith exitCode)
247+
)
248+
Just name -> do
249+
case find (name `isSuffixOf`) canonicalExecutables of
250+
Nothing -> putStrLn "Test Not Found"
251+
Just specified -> do
252+
exitCode <- system
253+
(commandPrefix ++ specified ++ commandSufix)
254+
exitWith exitCode
248255
_ -> putStrLn "Shouldn't be able to get here"
249256

250257
build :: AppSettings -> IO ()
@@ -419,6 +426,12 @@ runArguments =
419426
"specify an addional argument to pass to the compiler (can appear multiple times)"
420427
)
421428
)
429+
<*> optional
430+
(strOption
431+
(long "runner" <> metavar "RUNNER" <> help
432+
"specify a command to be used to run the executable(s)"
433+
)
434+
)
422435
<*> optional
423436
(strArgument
424437
(metavar "TARGET" <> help "Name of the executable to run")
@@ -448,6 +461,12 @@ testArguments =
448461
"specify an addional argument to pass to the compiler (can appear multiple times)"
449462
)
450463
)
464+
<*> optional
465+
(strOption
466+
(long "runner" <> metavar "RUNNER" <> help
467+
"specify a command to be used to run the test(s)"
468+
)
469+
)
451470
<*> optional
452471
(strArgument (metavar "TARGET" <> help "Name of the test to run"))
453472
<*> optional (strArgument (metavar "ARGS" <> help "Arguments to the test"))

bootstrap/test/Spec.hs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ testHelloWorld =
2222
{ runRelease = False
2323
, runCompiler = "gfortran"
2424
, runFlags = []
25+
, runRunner = Nothing
2526
, runTarget = Nothing
2627
, runArgs = Nothing
2728
}
@@ -32,6 +33,7 @@ testHelloComplex =
3233
{ testRelease = False
3334
, testCompiler = "gfortran"
3435
, testFlags = []
36+
, testRunner = Nothing
3537
, testTarget = Nothing
3638
, testArgs = Nothing
3739
}
@@ -42,6 +44,7 @@ testHelloFpm =
4244
{ runRelease = False
4345
, runCompiler = "gfortran"
4446
, runFlags = []
47+
, runRunner = Nothing
4548
, runTarget = Nothing
4649
, runArgs = Nothing
4750
}
@@ -52,6 +55,7 @@ testCircular =
5255
{ testRelease = False
5356
, testCompiler = "gfortran"
5457
, testFlags = []
58+
, testRunner = Nothing
5559
, testTarget = Nothing
5660
, testArgs = Nothing
5761
}
@@ -70,6 +74,7 @@ testMakefileComplex =
7074
{ runRelease = False
7175
, runCompiler = "gfortran"
7276
, runFlags = []
77+
, runRunner = Nothing
7378
, runTarget = Nothing
7479
, runArgs = Nothing
7580
}

0 commit comments

Comments
 (0)