@@ -637,28 +637,45 @@ configureOptsNoDir econfig bco deps isLocal package = concat
637
637
, [" --ghc-option=-fhide-source-paths" | hideSourcePaths cv]
638
638
]
639
639
where
640
+ -- This function parses the GHC options that are providing in the
641
+ -- stack.yaml file. In order to handle RTS arguments correctly, we need
642
+ -- to provide the RTS arguments as a single argument.
640
643
processGhcOptions :: [Text ] -> [String ]
641
- processGhcOptions ( " +RTS " : xs) =
644
+ processGhcOptions args =
642
645
let
643
- (rtsArgs, rest) =
644
- takeRtsArgs xs
646
+ (preRtsArgs, mid) =
647
+ break (" +RTS" == ) args
648
+ (rtsArgs, end) =
649
+ break (" -RTS" == ) mid
650
+ fullRtsArgs =
651
+ case rtsArgs of
652
+ [] ->
653
+ -- This means that we didn't have any RTS args - no
654
+ -- `+RTS` - and therefore no need for a `-RTS`.
655
+ []
656
+ _ ->
657
+ -- In this case, we have some RTS args. `break`
658
+ -- puts the `"-RTS"` string in the `snd` list, so
659
+ -- we want to append it on the end of `rtsArgs`
660
+ -- here.
661
+ --
662
+ -- We're not checking that `-RTS` is the first
663
+ -- element of `end`. This is because the GHC RTS
664
+ -- allows you to omit a trailing -RTS if that's the
665
+ -- last of the arguments. This permits a GHC
666
+ -- options in stack.yaml that matches what you
667
+ -- might pass directly to GHC.
668
+ [T. unwords $ rtsArgs ++ [" -RTS" ]]
669
+ -- We drop the first element from `end`, because it is always
670
+ -- either `"-RTS"` (and we don't want that as a separate
671
+ -- argument) or the list is empty (and `drop _ [] = []`).
672
+ postRtsArgs =
673
+ drop 1 end
674
+ newArgs =
675
+ concat [preRtsArgs, fullRtsArgs, postRtsArgs]
645
676
in
646
- (" --ghc-options=+RTS " ++ rtsArgs) : processGhcOptions rest
647
- processGhcOptions (x : xs) =
648
- [compilerOptionsCabalFlag wc, T. unpack x] ++ processGhcOptions xs
649
- processGhcOptions [] =
650
- []
651
- takeRtsArgs :: [Text ] -> (String , [Text ])
652
- takeRtsArgs (" -RTS" : xs) =
653
- (" -RTS" , xs)
654
- takeRtsArgs (x : xs) =
655
- let
656
- (other, rest) =
657
- takeRtsArgs xs
658
- in
659
- (T. unpack x ++ " " ++ other, rest)
660
- takeRtsArgs [] =
661
- ([] , [] )
677
+ concatMap (\ x -> [compilerOptionsCabalFlag wc, T. unpack x]) newArgs
678
+
662
679
wc = view (actualCompilerVersionL. to whichCompiler) econfig
663
680
cv = view (actualCompilerVersionL. to getGhcVersion) econfig
664
681
0 commit comments