From 25f325307d06b90b69276875edb1d9e263f70b8e Mon Sep 17 00:00:00 2001
From: HaskellMouse <rinat.stryungis@serokell.io>
Date: Wed, 28 Jul 2021 10:03:37 +0300
Subject: [PATCH] Fixed a bug with ignoring `cpPkg` and `cpCompiler` fields.

---
 ChangeLog.md               | 2 ++
 src/Stack/Build/Execute.hs | 8 ++++----
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/ChangeLog.md b/ChangeLog.md
index 6dacd54e66..aefa2dba7e 100644
--- a/ChangeLog.md
+++ b/ChangeLog.md
@@ -17,6 +17,8 @@ Bug fixes:
 
 * Ensure that `extra-path` works for case-insensitive `PATH`s on Windows.
   See [rio#237](https://github.com/commercialhaskell/rio/pull/237)
+* Fix handling of overwritten `ghc` and `ghc-pkg` locations.
+  [#5597](https://github.com/commercialhaskell/stack/pull/5597)
 
 ## v2.7.3
 
diff --git a/src/Stack/Build/Execute.hs b/src/Stack/Build/Execute.hs
index 1e381dd217..8fbf4489cd 100644
--- a/src/Stack/Build/Execute.hs
+++ b/src/Stack/Build/Execute.hs
@@ -886,11 +886,11 @@ ensureConfig newConfigCache pkgDir ExecuteEnv {..} announce cabal cabalfp task =
         let programNames =
               case cpWhich cp of
                 Ghc ->
-                  [ "--with-ghc=" ++ toFilePath (cpCompiler cp)
-                  , "--with-ghc-pkg=" ++ toFilePath pkgPath
+                  [ ("ghc", toFilePath (cpCompiler cp))
+                  , ("ghc-pkg", toFilePath pkgPath)
                   ]
-        exes <- forM programNames $ \name -> do
-            mpath <- findExecutable name
+        exes <- forM programNames $ \(name, file) -> do
+            mpath <- findExecutable file
             return $ case mpath of
                 Left _ -> []
                 Right x -> return $ concat ["--with-", name, "=", x]