Skip to content

CI built Windows GHC double-escapes in `optP`

Summary

GHCs built by Windows CI double-escapes backslashes in optP flags.

Steps to reproduce

  1. Install the GHC from the windows pipeline in !12878.
  2. cabal build -v3 some project (I suggest piping into | grep -v environment).
  3. You will see the following output:
Running: "C:\ghcup\bin\ghc.exe" ... "-optPdist-newstyle\build\x86_64-windows\ghc-9.11.20240614\deps-0.1.0\build\autogen\cabal_macros.h"
...
MOD FLAGS: optP flags:      ["dist-newstyle\\\\build\\\\x86_64-windows\\\\ghc-9.11.20240614\\\\deps-0.1.0\\\\build\\\\autogen\\\\cabal_macros.h","-include"]

Notice the double escaping. To be precise, the Running: output is printed by showCommandForUser so even if the input command shows one \, there have to be two:

λ: putStrLn $ showCommandForUser "ghc.exe" ["-optPdist-newstyle\\cabal"]
"ghc.exe" "-optPdist-newstyle\cabal"
λ: putStrLn $ showCommandForUser "ghc.exe" ["-optPdist-newstyle\cabal"]
λ| ^C

If you also request Documentation: True in cabal, it is more surprising because you can observe the following:

dist-newstyle\build\x86_64-windows\ghc-9.11.20240614\deps-0.1.0\doc\html\deps\hadAF5B.txt
contents: <<<
...
--optghc=-optPdist-newstyle\\build\\x86_64-windows\\ghc-9.11.20240614\\deps-0.1.0\\build\\autogen\\cabal_macros.h
...
Running: "C:\ghcup\bin\haddock.exe" "@dist-newstyle\build\x86_64-windows\ghc-9.11.20240614\deps-0.1.0\doc\html\deps\hadAF5B.txt"
...
MOD FLAGS: optP flags:      ["dist-newstyle\\build\\x86_64-windows\\ghc-9.11.20240614\\deps-0.1.0\\build\\autogen\\cabal_macros.h","-include"]

So when the flag is given through --optghc it doesn't double-escape.

If I build the GHC here on my Windows machine, it doesn't double-escape the flag, which is even more surprising.

Some more information on how I reached this conclusion can be seen in the bottom of this Cabal PR https://github.com/haskell/cabal/pull/9177.

Expected behavior

Not double-escape backslashes.

Environment

  • GHC version used: Any version from 9.6.5 to GHC-HEAD I have checked it has this problem.

Optional:

  • Operating System: Windows 11
  • System Architecture: x86_64
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information