David Eichmann pushed to branch wip/davide/hadrian_avoid_response_files at Glasgow Haskell Compiler / GHC

Commits:

2 changed files:

Changes:

  • hadrian/src/Builder.hs
    ... ... @@ -39,7 +39,6 @@ import Packages
    39 39
     import GHC.IO.Encoding (getFileSystemEncoding)
    
    40 40
     import qualified Data.ByteString as BS
    
    41 41
     import qualified GHC.Foreign as GHC
    
    42
    -import GHC.ResponseFile
    
    43 42
     
    
    44 43
     import GHC.Toolchain (Target(..))
    
    45 44
     import qualified GHC.Toolchain as Toolchain
    
    ... ... @@ -346,7 +345,15 @@ instance H.Builder Builder where
    346 345
     
    
    347 346
                     Haddock BuildPackage -> runHaddock path buildArgs buildInputs
    
    348 347
     
    
    349
    -                Ghc _ _ -> runGhcWithResponse path buildArgs buildInputs buildOptions
    
    348
    +                Ghc _ _ ->
    
    349
    +                  -- Use a response file for ghc invocations to avoid issues with command line
    
    350
    +                  -- size limit on Windows (#26637).
    
    351
    +                  -- NB: we can't put the buildArgs in a response file, because some flags require
    
    352
    +                  -- empty arguments (such as the -dep-suffix flag), but that isn't supported
    
    353
    +                  -- yet due to #26560.
    
    354
    +                  withResponseFileOnWindows
    
    355
    +                    (\buildInputs' -> cmd [path] buildArgs buildInputs' buildOptions)
    
    356
    +                    buildInputs
    
    350 357
     
    
    351 358
                     HsCpp    -> captureStdout
    
    352 359
     
    
    ... ... @@ -380,29 +387,15 @@ instance H.Builder Builder where
    380 387
     
    
    381 388
                     _  -> cmd' [path] buildArgs buildOptions
    
    382 389
     
    
    383
    --- | Invoke @haddock@ given a path to it and a list of arguments. The arguments
    
    384
    --- are passed in a response file.
    
    390
    +-- | Invoke @haddock@ given a path to it and a list of arguments. On windows,
    
    391
    +-- the input file arguments are passed as a response file.
    
    385 392
     runHaddock :: FilePath    -- ^ path to @haddock@
    
    386 393
           -> [String]
    
    387 394
           -> [FilePath]  -- ^ input file paths
    
    388 395
           -> Action ()
    
    389
    -runHaddock haddockPath flagArgs fileInputs = withResponseFile $ \tmp -> do
    
    390
    -    writeFile' tmp $ escapeArgs fileInputs
    
    391
    -    cmd [haddockPath] flagArgs ('@' : tmp)
    
    392
    -
    
    393
    --- | Use a response file for ghc invocations to avoid issues with command line
    
    394
    --- size limit on Windows (#26637).
    
    395
    -runGhcWithResponse :: FilePath -- ^ Path to ghc
    
    396
    -  -> [String] -- ^ Arguments passed on the command line
    
    397
    -  -> [FilePath] -- ^ Input file paths (passed via response file)
    
    398
    -  -> [CmdOption]
    
    399
    -  -> Action ()
    
    400
    -runGhcWithResponse ghcPath buildArgs buildInputs buildOptions = withResponseFile $ \tmp -> do
    
    401
    -  -- We can't put the buildArgs in a response file, because some flags require
    
    402
    -  -- empty arguments (such as the -dep-suffix flag), but that isn't supported
    
    403
    -  -- yet due to #26560.
    
    404
    -  writeFile' tmp (escapeArgs buildInputs)
    
    405
    -  cmd [ghcPath] buildArgs ('@' : tmp) buildOptions
    
    396
    +runHaddock haddockPath flagArgs fileInputs = withResponseFileOnWindows
    
    397
    +  (cmd [haddockPath] flagArgs)
    
    398
    +  fileInputs
    
    406 399
     
    
    407 400
     -- TODO: Some builders are required only on certain platforms. For example,
    
    408 401
     -- 'Objdump' is only required on OpenBSD and AIX. Add support for platform
    

  • hadrian/src/Hadrian/Utilities.hs
    ... ... @@ -14,7 +14,7 @@ module Hadrian.Utilities (
    14 14
     
    
    15 15
         -- * Paths
    
    16 16
         BuildRoot (..), buildRoot, buildRootRules, isGeneratedSource,
    
    17
    -    KeepResponseFiles (..), keepResponseFiles, withResponseFile,
    
    17
    +    KeepResponseFiles (..), keepResponseFiles, withResponseFile, withResponseFileOnWindows,
    
    18 18
     
    
    19 19
         -- * File system operations
    
    20 20
         copyFile, copyFileUntracked, createFileLink, fixFile,
    
    ... ... @@ -48,8 +48,11 @@ import Data.Typeable (TypeRep, typeOf)
    48 48
     import Development.Shake hiding (Normal)
    
    49 49
     import Development.Shake.Classes
    
    50 50
     import Development.Shake.FilePath
    
    51
    +import GHC.ResponseFile (escapeArgs)
    
    51 52
     import System.Environment (lookupEnv)
    
    53
    +import System.Info.Extra (isWindows)
    
    52 54
     import System.IO (hClose, openTempFile)
    
    55
    +import System.IO.Error (isPermissionError)
    
    53 56
     
    
    54 57
     import qualified Data.ByteString        as BS
    
    55 58
     import qualified Control.Exception.Base as IO
    
    ... ... @@ -57,8 +60,7 @@ import qualified Data.HashMap.Strict as Map
    57 60
     import qualified System.Directory.Extra as IO
    
    58 61
     import qualified System.Info.Extra      as IO
    
    59 62
     import qualified System.IO              as IO
    
    60
    -import System.IO.Error (isPermissionError)
    
    61
    -import qualified System.FilePath.Posix as Posix
    
    63
    +import qualified System.FilePath.Posix  as Posix
    
    62 64
     
    
    63 65
     -- | Extract a value from a singleton list, or terminate with an error message
    
    64 66
     -- if the list does not contain exactly one value.
    
    ... ... @@ -328,6 +330,21 @@ keepResponseFiles = do
    328 330
         KeepResponseFiles keep <- userSetting (KeepResponseFiles False)
    
    329 331
         return keep
    
    330 332
     
    
    333
    +-- | Run an action either with command arguments direcly or by, on Windows,
    
    334
    +-- placing those arguments into a response file escaped with @GHC.ResponseFile.escapeArgs@.
    
    335
    +--
    
    336
    +-- With @--keep-response-files@, the file is left on disk (if used)
    
    337
    +withResponseFileOnWindows ::
    
    338
    +    ([String] -> Action a)  -- ^ Action to perform given arguments (of the form @["\@reponseFilePath"]@ on Windows)
    
    339
    +    -> [String]             -- ^ Command arguments
    
    340
    +    -> Action a
    
    341
    +withResponseFileOnWindows action commandArgs = do
    
    342
    +    if isWindows
    
    343
    +        then withResponseFile $ \tmp -> do
    
    344
    +                writeFile' tmp (escapeArgs commandArgs)
    
    345
    +                action ['@' : tmp]
    
    346
    +        else action commandArgs
    
    347
    +
    
    331 348
     -- | Run an action with a response file path.
    
    332 349
     --
    
    333 350
     -- With @--keep-response-files@, the file is left on disk.