|
| 1 | +import Test.Cabal.Prelude |
| 2 | +import Test.Cabal.Script (runghc) |
| 3 | +import Control.Monad.IO.Class |
| 4 | +import Data.List (isInfixOf) |
| 5 | + |
| 6 | +-- When cross-compiling, Cabal passes a --host= flag to configure scripts. |
| 7 | +-- The value should be the original GNU triple (e.g. x86_64-w64-mingw32), |
| 8 | +-- not Cabal's canonical platform string (e.g. x86_64-windows). |
| 9 | +-- |
| 10 | +-- This test uses a fake GHC wrapper that reports "x86_64-w64-mingw32" |
| 11 | +-- as its Target platform (simulating a cross-compiler), then checks |
| 12 | +-- that the configure script receives --host=x86_64-w64-mingw32 |
| 13 | +-- rather than the mangled --host=x86_64-windows. |
| 14 | +main = do |
| 15 | + skipIfWindows "uses sh script as fake ghc" |
| 16 | + setupTest $ recordMode DoNotRecord $ do |
| 17 | + env <- getTestEnv |
| 18 | + let cwd = testCurrentDir env |
| 19 | + fakeGhc = cwd </> "scripts" </> "fake-ghc.sh" |
| 20 | + -- Run Setup.hs configure with our fake cross-compiler. |
| 21 | + -- We call runghc ourselves to bypass the test framework's |
| 22 | + -- --with-ghc which would override ours. |
| 23 | + _ <- liftIO $ runghc |
| 24 | + (testScriptEnv env) |
| 25 | + (Just $ testTmpDir env) |
| 26 | + (testEnvironment env) |
| 27 | + ("." </> "Setup.hs") |
| 28 | + [ "configure" |
| 29 | + , "--distdir", testDistDir env |
| 30 | + , "--with-compiler", fakeGhc |
| 31 | + ] |
| 32 | + -- The configure script writes its arguments to configure-args.txt |
| 33 | + -- in its working directory (dist/build/). |
| 34 | + let argsFile = testDistDir env </> "build" </> "configure-args.txt" |
| 35 | + args <- liftIO $ readFile argsFile |
| 36 | + -- The configure script should receive --host=x86_64-w64-mingw32 |
| 37 | + -- (the original GNU triple), not --host=x86_64-windows. |
| 38 | + unless ("--host=x86_64-w64-mingw32" `isInfixOf` args) $ |
| 39 | + error $ unlines |
| 40 | + [ "Expected --host=x86_64-w64-mingw32 in configure arguments" |
| 41 | + , "but got: " ++ args |
| 42 | + ] |
0 commit comments