Skip to content

Commit

Permalink
Improve filtering of rts arguments from stack and cabal cradles
Browse files Browse the repository at this point in the history
Handles the case that the rts flags produced by the cradles are
within a single string.
Before we only allowed the rts flags to occur in the following form:

> ["+RTS", "-H32m","-RTS"]

and now we allow:

> ["+RTS -H32m -RTS"]

and filter the ComponentOptions appropriately.
  • Loading branch information
fendor committed Jun 21, 2020
1 parent 18c8a0c commit d5a600e
Showing 1 changed file with 30 additions and 10 deletions.
40 changes: 30 additions & 10 deletions src/HIE/Bios/Cradle.hs
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ processCabalWrapperArgs args =
-- arguments to the executable.
type GhcProc = (FilePath, [String])

-- generate a fake GHC that can be passed to cabal
-- | Generate a fake GHC that can be passed to cabal
-- when run with --interactive, it will print out its
-- command-line arguments and exit
withCabalWrapperTool :: GhcProc -> FilePath -> (FilePath -> IO a) -> IO a
Expand Down Expand Up @@ -466,14 +466,35 @@ cabalAction work_dir mc l fp = do
removeInteractive :: [String] -> [String]
removeInteractive = filter (/= "--interactive")

-- Strip out any ["+RTS", ..., "-RTS"] sequences in the command string list.
-- | Strip out any ["+RTS", ..., "-RTS"] sequences in the command string list.
data InRTS = OutsideRTS | InsideRTS

-- | Strip out any ["+RTS", ..., "-RTS"] sequences in the command string list.
--
-- >>> removeRTS ["option1", "+RTS -H32m -RTS", "option2"]
-- ["option1", "option2"]
--
-- >>> removeRTS ["option1", "+RTS", "-H32m", "-RTS", "option2"]
-- ["option1", "option2"]
--
-- >>> removeRTS ["option1", "+RTS -H32m"]
-- ["option1"]
--
-- >>> removeRTS ["option1", "+RTS -H32m", "-RTS", "option2"]
-- ["option1", "option2"]
--
-- >>> removeRTS ["option1", "+RTS -H32m", "-H32m -RTS", "option2"]
-- ["option1"] -- "option2" is removed, since the logic doesnt handle this case.
removeRTS :: [String] -> [String]
removeRTS ("+RTS" : xs) =
case dropWhile (/= "-RTS") xs of
[] -> []
(_ : ys) -> removeRTS ys
removeRTS (y:ys) = y : removeRTS ys
removeRTS [] = []
removeRTS = go OutsideRTS
where
go :: InRTS -> [String] -> [String]
go _ [] = []
go OutsideRTS (y:ys)
| "+RTS" `isPrefixOf` y = go (if "-RTS" `isSuffixOf` y then OutsideRTS else InsideRTS) ys
| otherwise = y : go OutsideRTS ys
go InsideRTS (y:ys) = go (if y == "-RTS" then OutsideRTS else InsideRTS) ys


removeVerbosityOpts :: [String] -> [String]
removeVerbosityOpts = filter ((&&) <$> (/= "-v0") <*> (/= "-w"))
Expand All @@ -485,9 +506,8 @@ cabalWorkDir = findFileUpwards isCabal
isCabal name = name == "cabal.project"

------------------------------------------------------------------------
-- Stack Cradle
-- | Stack Cradle
-- Works for by invoking `stack repl` with a wrapper script

stackCradle :: FilePath -> Maybe String -> Cradle a
stackCradle wdir mc =
Cradle
Expand Down

0 comments on commit d5a600e

Please sign in to comment.