From 328ef564d1fcfb21b41fbd521243f0f2cf283780 Mon Sep 17 00:00:00 2001 From: parsonsmatt Date: Wed, 23 Jun 2021 08:29:24 -0600 Subject: [PATCH 1/4] Failing test --- stack.yaml | 1 + test/integration/tests/5180-ghc-rts-flags/Main.hs | 4 ++++ .../tests/5180-ghc-rts-flags/files/files.cabal | 11 +++++++++++ .../tests/5180-ghc-rts-flags/files/src/Lib.hs | 4 ++++ .../tests/5180-ghc-rts-flags/files/stack.yaml | 6 ++++++ 5 files changed, 26 insertions(+) create mode 100644 test/integration/tests/5180-ghc-rts-flags/Main.hs create mode 100644 test/integration/tests/5180-ghc-rts-flags/files/files.cabal create mode 100644 test/integration/tests/5180-ghc-rts-flags/files/src/Lib.hs create mode 100644 test/integration/tests/5180-ghc-rts-flags/files/stack.yaml diff --git a/stack.yaml b/stack.yaml index 04ecfa25d3..d0d28f65cb 100644 --- a/stack.yaml +++ b/stack.yaml @@ -8,6 +8,7 @@ docker: #repo: fpco/alpine-haskell-stack:8.10.4 repo: fpco/alpine-haskell-stack@sha256:1024fe4b3b082a8df64d00e8563b3151220ed90af09604a8f7e1d44040500c30 + nix: # --nix on the command-line to enable. packages: diff --git a/test/integration/tests/5180-ghc-rts-flags/Main.hs b/test/integration/tests/5180-ghc-rts-flags/Main.hs new file mode 100644 index 0000000000..e61b083aa4 --- /dev/null +++ b/test/integration/tests/5180-ghc-rts-flags/Main.hs @@ -0,0 +1,4 @@ +import StackTest + +main :: IO () +main = stack ["build"] diff --git a/test/integration/tests/5180-ghc-rts-flags/files/files.cabal b/test/integration/tests/5180-ghc-rts-flags/files/files.cabal new file mode 100644 index 0000000000..8f21c6b6bd --- /dev/null +++ b/test/integration/tests/5180-ghc-rts-flags/files/files.cabal @@ -0,0 +1,11 @@ +name: files +version: 0.1.0.0 +build-type: Simple +cabal-version: >=1.10 + +library + hs-source-dirs: src + exposed-modules: Lib + build-depends: base >= 4.7 && < 5, mtl + default-language: Haskell2010 + diff --git a/test/integration/tests/5180-ghc-rts-flags/files/src/Lib.hs b/test/integration/tests/5180-ghc-rts-flags/files/src/Lib.hs new file mode 100644 index 0000000000..7685c7c4bf --- /dev/null +++ b/test/integration/tests/5180-ghc-rts-flags/files/src/Lib.hs @@ -0,0 +1,4 @@ +module Lib where + +main :: IO () +main = putStrLn "hello world" diff --git a/test/integration/tests/5180-ghc-rts-flags/files/stack.yaml b/test/integration/tests/5180-ghc-rts-flags/files/stack.yaml new file mode 100644 index 0000000000..70de001e51 --- /dev/null +++ b/test/integration/tests/5180-ghc-rts-flags/files/stack.yaml @@ -0,0 +1,6 @@ +resolver: lts-14.27 +packages: +- . + +ghc-options: + "$locals": +RTS -A128M -RTS From 8735064ee4898816f273f78d66d188f2a0584e0d Mon Sep 17 00:00:00 2001 From: parsonsmatt Date: Wed, 23 Jun 2021 09:20:54 -0600 Subject: [PATCH 2/4] Fix single test --- src/Stack/Types/Build.hs | 24 ++++++++++++++++++- .../tests/5180-ghc-rts-flags/Main.hs | 4 +++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/Stack/Types/Build.hs b/src/Stack/Types/Build.hs index e92c2bf988..d27172976e 100644 --- a/src/Stack/Types/Build.hs +++ b/src/Stack/Types/Build.hs @@ -629,7 +629,7 @@ configureOptsNoDir econfig bco deps isLocal package = concat flagNameString name) (Map.toList flags) , map T.unpack $ packageCabalConfigOpts package - , concatMap (\x -> [compilerOptionsCabalFlag wc, T.unpack x]) (packageGhcOptions package) + , processGhcOptions (packageGhcOptions package) , map ("--extra-include-dirs=" ++) (configExtraIncludeDirs config) , map ("--extra-lib-dirs=" ++) (configExtraLibDirs config) , maybe [] (\customGcc -> ["--with-gcc=" ++ toFilePath customGcc]) (configOverrideGccPath config) @@ -637,6 +637,28 @@ configureOptsNoDir econfig bco deps isLocal package = concat , ["--ghc-option=-fhide-source-paths" | hideSourcePaths cv] ] where + processGhcOptions :: [Text] -> [String] + processGhcOptions ("+RTS" : xs) = + let + (rtsArgs, rest) = + takeRtsArgs xs + in + ("--ghc-options=+RTS " ++ rtsArgs) : processGhcOptions rest + processGhcOptions (x : xs) = + [compilerOptionsCabalFlag wc, T.unpack x] ++ processGhcOptions xs + processGhcOptions [] = + [] + takeRtsArgs :: [Text] -> (String, [Text]) + takeRtsArgs ("-RTS" : xs) = + ("-RTS", xs) + takeRtsArgs (x : xs) = + let + (other, rest) = + takeRtsArgs xs + in + (T.unpack x ++ " " ++ other, rest) + takeRtsArgs [] = + ([], []) wc = view (actualCompilerVersionL.to whichCompiler) econfig cv = view (actualCompilerVersionL.to getGhcVersion) econfig diff --git a/test/integration/tests/5180-ghc-rts-flags/Main.hs b/test/integration/tests/5180-ghc-rts-flags/Main.hs index e61b083aa4..e13dcd9ae4 100644 --- a/test/integration/tests/5180-ghc-rts-flags/Main.hs +++ b/test/integration/tests/5180-ghc-rts-flags/Main.hs @@ -1,4 +1,6 @@ import StackTest main :: IO () -main = stack ["build"] +main = do + stack ["clean"] + stack ["build"] From 564527abd8be380cc9f0ca45c7646972641b0160 Mon Sep 17 00:00:00 2001 From: parsonsmatt Date: Wed, 23 Jun 2021 09:22:28 -0600 Subject: [PATCH 3/4] Add changelog note --- ChangeLog.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ChangeLog.md b/ChangeLog.md index b9f6a1103d..4f461e9607 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -29,7 +29,7 @@ Bug fixes: [pantry#33](https://github.com/commercialhaskell/pantry/issues/33) * When building the sanity check for a new GHC install, make sure to clear `GHC_PACKAGE_PATH`. - +* Specifying GHC RTS flags in the `stack.yaml` no longer fails with an error. [#5568](https://github.com/commercialhaskell/stack/pull/5568) ## v2.7.1 From a42fb5121958d6506620d6eadaccf3c278b98b53 Mon Sep 17 00:00:00 2001 From: parsonsmatt Date: Mon, 28 Jun 2021 07:24:10 -0600 Subject: [PATCH 4/4] Faster implementation --- src/Stack/Types/Build.hs | 55 ++++++++++++------- stack.yaml | 1 - .../tests/5180-ghc-rts-flags/files/stack.yaml | 2 +- 3 files changed, 37 insertions(+), 21 deletions(-) diff --git a/src/Stack/Types/Build.hs b/src/Stack/Types/Build.hs index d27172976e..e4a6c684ec 100644 --- a/src/Stack/Types/Build.hs +++ b/src/Stack/Types/Build.hs @@ -637,28 +637,45 @@ configureOptsNoDir econfig bco deps isLocal package = concat , ["--ghc-option=-fhide-source-paths" | hideSourcePaths cv] ] where + -- This function parses the GHC options that are providing in the + -- stack.yaml file. In order to handle RTS arguments correctly, we need + -- to provide the RTS arguments as a single argument. processGhcOptions :: [Text] -> [String] - processGhcOptions ("+RTS" : xs) = + processGhcOptions args = let - (rtsArgs, rest) = - takeRtsArgs xs + (preRtsArgs, mid) = + break ("+RTS" ==) args + (rtsArgs, end) = + break ("-RTS" ==) mid + fullRtsArgs = + case rtsArgs of + [] -> + -- This means that we didn't have any RTS args - no + -- `+RTS` - and therefore no need for a `-RTS`. + [] + _ -> + -- In this case, we have some RTS args. `break` + -- puts the `"-RTS"` string in the `snd` list, so + -- we want to append it on the end of `rtsArgs` + -- here. + -- + -- We're not checking that `-RTS` is the first + -- element of `end`. This is because the GHC RTS + -- allows you to omit a trailing -RTS if that's the + -- last of the arguments. This permits a GHC + -- options in stack.yaml that matches what you + -- might pass directly to GHC. + [T.unwords $ rtsArgs ++ ["-RTS"]] + -- We drop the first element from `end`, because it is always + -- either `"-RTS"` (and we don't want that as a separate + -- argument) or the list is empty (and `drop _ [] = []`). + postRtsArgs = + drop 1 end + newArgs = + concat [preRtsArgs, fullRtsArgs, postRtsArgs] in - ("--ghc-options=+RTS " ++ rtsArgs) : processGhcOptions rest - processGhcOptions (x : xs) = - [compilerOptionsCabalFlag wc, T.unpack x] ++ processGhcOptions xs - processGhcOptions [] = - [] - takeRtsArgs :: [Text] -> (String, [Text]) - takeRtsArgs ("-RTS" : xs) = - ("-RTS", xs) - takeRtsArgs (x : xs) = - let - (other, rest) = - takeRtsArgs xs - in - (T.unpack x ++ " " ++ other, rest) - takeRtsArgs [] = - ([], []) + concatMap (\x -> [compilerOptionsCabalFlag wc, T.unpack x]) newArgs + wc = view (actualCompilerVersionL.to whichCompiler) econfig cv = view (actualCompilerVersionL.to getGhcVersion) econfig diff --git a/stack.yaml b/stack.yaml index d0d28f65cb..04ecfa25d3 100644 --- a/stack.yaml +++ b/stack.yaml @@ -8,7 +8,6 @@ docker: #repo: fpco/alpine-haskell-stack:8.10.4 repo: fpco/alpine-haskell-stack@sha256:1024fe4b3b082a8df64d00e8563b3151220ed90af09604a8f7e1d44040500c30 - nix: # --nix on the command-line to enable. packages: diff --git a/test/integration/tests/5180-ghc-rts-flags/files/stack.yaml b/test/integration/tests/5180-ghc-rts-flags/files/stack.yaml index 70de001e51..30e82f3a00 100644 --- a/test/integration/tests/5180-ghc-rts-flags/files/stack.yaml +++ b/test/integration/tests/5180-ghc-rts-flags/files/stack.yaml @@ -3,4 +3,4 @@ packages: - . ghc-options: - "$locals": +RTS -A128M -RTS + "$locals": -j8 +RTS -s -A128M