Darwin x86_64 fails during tests with out-of-memory
While debugging the odd test failure issues on macOS (x86_64) with @mpickering we came up with the following test-program (against 8.10.5), that illustrates the issue:
module Main where
import Outputable
import GHC.IO
import SysTools.Process
import Data.List ( isInfixOf, isPrefixOf )
import Data.IORef
import System.IO
import System.Process
import System.Environment
import Exception
-- See Note [Run-time linker info].
getCompilerInfo' :: String -> IO String
getCompilerInfo' pgm = do
let -- Try to grab the info from the process output.
parseCompilerInfo _stdo stde _exitc
-- Regular GCC
| any ("gcc version" `isInfixOf`) stde =
return "GCC"
-- Regular clang
| any ("clang version" `isInfixOf`) stde =
return "Clang"
-- FreeBSD clang
| any ("FreeBSD clang version" `isInfixOf`) stde =
return "Clang"
-- Xcode 5.1 clang
| any ("Apple LLVM version 5.1" `isPrefixOf`) stde =
return "AppleClang51"
-- Xcode 5 clang
| any ("Apple LLVM version" `isPrefixOf`) stde =
return "AppleClang"
-- Xcode 4.1 clang
| any ("Apple clang version" `isPrefixOf`) stde =
return "AppleClang"
-- Unknown compiler.
| otherwise = fail $ "invalid -v output, or compiler is unsupported (" ++ pgm ++ "): " ++ unlines stde
-- Process the executable call
catchIO (do
(exitc, stdo, stde) <- do
env <- getEnvironment
readCreateProcessWithExitCode ((proc pgm ["-v"]) { env = Just env }) ""
env <- show <$> getEnvironment
print $ length env
-- Split the output by lines to make certain kinds
-- of processing easier.
parseCompilerInfo (lines stdo) (lines stde) exitc
)
(\err -> do
print $ "Warning:\nCouldn't figure out C compiler information!\nMake sure you're using GNU gcc, or clang\n" ++ show err
return "UnknownCC"
)
main = do
print =<< getCompilerInfo' "clang"
main
fundamentally the issue appears to be due to the large ENV in a nix shell and readCreateProcessWithExitCode
not handling large env strings. Notabley the lengh of the show on env is 29299
.